Skip to content

Commit 8d3fc5c

Browse files
committed
feat: add Shopify orders create webhook payload and event classes
1 parent 23acf11 commit 8d3fc5c

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Identifier, Name, Schema} from "@code0-tech/hercules";
2+
import {schemaForWebhook} from "shopify-webhook-schemas";
3+
import { z } from "zod";
4+
5+
const schema = schemaForWebhook("2026-04", "orders/create");
6+
const ShopifyOrdersCreatePayloadSchema = z.fromJSONSchema(schema);
7+
8+
@Identifier("ShopifyOrdersCreateWebhookPayload")
9+
@Name({ code: "en-US", content: "ShopifyOrdersCreateWebhookPayload" })
10+
@Schema(ShopifyOrdersCreatePayloadSchema)
11+
export class ShopifyOrdersCreateWebhookPayload {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {DisplayIcon, DisplayMessage, EventSetting, Identifier, Rest, Signature} from "@code0-tech/hercules";
2+
3+
@Identifier("ShopifyOrdersCreateWebhook")
4+
@DisplayIcon("simple:shopify")
5+
@DisplayMessage({ code: "en-US", content: "Shopify orders create on ${httpURL}" })
6+
@Signature("<A extends REST_AUTH_TYPE>(httpSchema: HTTP_SCHEMA, httpURL: HTTP_URL, httpMethod: HTTP_METHOD, httpAuth: A, httpAuthValue: REST_AUTH_VALUE<A>, input_schema?: ShopifyOrdersCreateWebhookPayload): REST_ADAPTER_INPUT<ShopifyOrdersCreateWebhookPayload>")
7+
@EventSetting({
8+
identifier: "input_schema",
9+
hidden: true
10+
})
11+
@EventSetting({
12+
identifier: "httpMethod",
13+
hidden: true,
14+
defaultValue: "POST"
15+
})
16+
@EventSetting({
17+
identifier: "httpSchema",
18+
hidden: true,
19+
defaultValue: "application/json"
20+
})
21+
export class ShopifyOrdersCreateWebhook extends Rest {}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {Action, CodeZeroEvent} from "@code0-tech/hercules";
2+
import {ShopifyOrdersCreateWebhookPayload} from "./data_types/shopifyOrdersCreateWebhookPayload.ts";
3+
import {ShopifyOrdersCreateWebhook} from "./events/shopifyOrdersCreateWebhook.ts";
4+
5+
const action = new Action(
6+
process.env.ACTION_ID ?? "shopify-action",
7+
process.env.VERSION ?? "1.0.0",
8+
process.env.AQUILA_URL ?? "127.0.0.1:8081",
9+
"code0-tech",
10+
"simple:shopify",
11+
"",
12+
[{code: "en-US", content: "Shopify"}],
13+
[]
14+
)
15+
16+
action.registerDataTypeClass(ShopifyOrdersCreateWebhookPayload)
17+
action.registerEventClass(ShopifyOrdersCreateWebhook)
18+
19+
action.on(CodeZeroEvent.connected, () => {
20+
console.log("Connected to aquila");
21+
});
22+
23+
action.on(CodeZeroEvent.error, (error: Error) => {
24+
console.error("Stream error:", error.message);
25+
console.log("Attempting to reconnect in 5s...");
26+
setTimeout(() => {
27+
action.connect(process.env.AUTH_TOKEN ?? "your_auth_token_here").catch((err: unknown) => {
28+
console.error("Reconnect failed:", err);
29+
});
30+
}, 5000);
31+
});
32+
33+
action.connect(process.env.AUTH_TOKEN ?? "your_auth_token_here").catch((err: unknown) => {
34+
console.error("Failed to connect:", err);
35+
process.exit(1);
36+
});
37+
38+
action.on(CodeZeroEvent.moduleUpdated, (message: any) => {
39+
console.dir(message, {depth: null});
40+
console.dir(action.configs.values(), {depth: null})
41+
})
42+
43+
export {action};

0 commit comments

Comments
 (0)