MCPcopy
hub / github.com/triggerdotdev/trigger.dev / createWebhookEventSource

Function createWebhookEventSource

integrations/shopify/src/webhooks.ts:73–198  ·  view source on GitHub ↗
(integration: Shopify)

Source from the content-addressed store, hash-verified

71}
72
73export function createWebhookEventSource(integration: Shopify) {
74 return new WebhookSource({
75 id: "shopify",
76 schemas: {
77 params: z.object({
78 topic: WebhookTopicSchema,
79 // disabled for now, doesn't seem useful and complicates things
80 // fields: z.string().array().optional(),
81 }),
82 // config: z.record(z.string().array()),
83 },
84 version: "0.1.0",
85 integration,
86 key: (params) => params.topic,
87 crud: {
88 create: async ({ io, ctx }) => {
89 try {
90 const webhook = await io.integration.rest.Webhook.save("create-webhook", {
91 fromData: {
92 address: ctx.url,
93 topic: ctx.params.topic,
94 // fields: ctx.params.fields,
95 },
96 });
97
98 if (!webhook.id) {
99 throw new Error(
100 "Failed to create webhook. Ensure your Shopfiy client configuration is correct. Have you set the correct access scopes? Are you using the primary myshopify.com domain?"
101 );
102 }
103
104 const clientSecret = await io.integration.runTask(
105 "get-client-secret",
106 async (client) => client.config.apiSecretKey
107 );
108
109 await io.store.job.set("set-id", "webhook-id", webhook.id);
110 await io.store.job.set("set-secret", "webhook-secret", clientSecret);
111 } catch (error) {
112 if (error instanceof Error) {
113 await io.logger.error(`Failed to create webhook: ${error.message}`);
114 } else {
115 await io.logger.error("Failed to create webhook", { rawError: error });
116 }
117 throw error;
118 }
119 },
120 delete: async ({ io, ctx }) => {
121 const webhookId = await io.store.job.get<number>("get-webhook-id", "webhook-id");
122
123 if (!webhookId) {
124 throw new Error("Missing webhook ID for delete operation.");
125 }
126
127 try {
128 await io.integration.rest.Webhook.delete("delete-webhook", {
129 id: webhookId,
130 });

Callers 1

#sourceMethod · 0.90

Calls 10

registerJobNamespaceFunction · 0.90
verifyRequestSignatureFunction · 0.90
saveMethod · 0.80
parseMethod · 0.80
jsonMethod · 0.80
errorMethod · 0.65
deleteMethod · 0.65
runTaskMethod · 0.45
setMethod · 0.45
sendEventMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…