The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Handle stringified webhook metadata payloads (#3642)
Kiran K56680885565e
diff --git a/apps/web/lib/webhook/schemas.ts b/apps/web/lib/webhook/schemas.tsindex eca63a664c..c67e5c8efc 100644--- a/apps/web/lib/webhook/schemas.ts+++ b/apps/web/lib/webhook/schemas.ts@@ -22,13 +22,30 @@ export const clickWebhookEventSchema = z.object({link: linkEventSchema,});+const coerceJsonString = (val: unknown) => {+ if (typeof val === "string") {+ try {+ return JSON.parse(val);+ } catch {+ return val;+ }+ }++ return val;+};++const metadataSchema = z.preprocess(+ coerceJsonString,+ z.record(z.string(), z.any()).nullish().default(null),+);+export const leadWebhookEventSchema = z.object({eventName: z.string(),customer: CustomerSchema,click: clickEventSchema,link: linkEventSchema,partner: WebhookPartnerSchema.nullish(),- metadata: z.record(z.string(), z.any()).nullable().default(null),+ metadata: metadataSchema,});export const saleWebhookEventSchema = z.object({@@ -38,7 +55,7 @@ export const saleWebhookEventSchema = z.object({link: linkEventSchema,sale: webhookSaleSchema,partner: WebhookPartnerSchema.nullish(),- metadata: z.record(z.string(), z.any()).nullable().default(null),+ metadata: metadataSchema,});// Schema of the payload sent to the webhook endpoint by Dub