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