1+ import { Action , CodeZeroEvent } from "@code0-tech/hercules" ;
2+ import { WooCommerceOrderCreatedWebhookPayload } from "./data_types/wooCommerceOrderCreatedWebhookPayload.ts" ;
3+ import { WooCommerceOrderUpdatedWebhookPayload } from "./data_types/wooCommerceOrderUpdatedWebhookPayload.ts" ;
4+ import { WooCommerceOrderCreatedWebhook } from "./events/wooCommerceOrderCreatedWebhook.ts" ;
5+ import { WooCommerceOrderUpdatedWebhook } from "./events/wooCommerceOrderUpdatedWebhook.ts" ;
6+
7+ const action = new Action (
8+ process . env . ACTION_ID ?? "woocommerce-action" ,
9+ process . env . VERSION ?? "1.0.0" ,
10+ process . env . AQUILA_URL ?? "127.0.0.1:8081" ,
11+ "code0-tech" ,
12+ "simple:woo" ,
13+ "" ,
14+ [ { code : "en-US" , content : "Woocommerce" } ] ,
15+ [ ]
16+ )
17+
18+ action . registerDataTypeClass ( WooCommerceOrderCreatedWebhookPayload )
19+ action . registerDataTypeClass ( WooCommerceOrderUpdatedWebhookPayload )
20+ action . registerEventClass ( WooCommerceOrderCreatedWebhook )
21+ action . registerEventClass ( WooCommerceOrderUpdatedWebhook )
22+
23+ action . on ( CodeZeroEvent . connected , ( ) => {
24+ console . log ( "Connected to aquila" ) ;
25+ } ) ;
26+
27+ action . on ( CodeZeroEvent . error , ( error : Error ) => {
28+ console . error ( "Stream error:" , error . message ) ;
29+ console . log ( "Attempting to reconnect in 5s..." ) ;
30+ setTimeout ( ( ) => {
31+ action . connect ( process . env . AUTH_TOKEN ?? "your_auth_token_here" ) . catch ( ( err : unknown ) => {
32+ console . error ( "Reconnect failed:" , err ) ;
33+ } ) ;
34+ } , 5000 ) ;
35+ } ) ;
36+
37+ action . connect ( process . env . AUTH_TOKEN ?? "your_auth_token_here" ) . catch ( ( err : unknown ) => {
38+ console . error ( "Failed to connect:" , err ) ;
39+ process . exit ( 1 ) ;
40+ } ) ;
41+
42+ action . on ( CodeZeroEvent . moduleUpdated , ( message : any ) => {
43+ console . dir ( message , { depth : null } ) ;
44+ console . dir ( action . configs . values ( ) , { depth : null } )
45+ } )
46+
47+ export { action } ;
0 commit comments