Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

to `click.id` for lead and sale event

Kiran Kc183cbf04c8c
diff --git a/apps/web/lib/webhook/schemas.ts b/apps/web/lib/webhook/schemas.ts
index f4f114d411..316054783f 100644
--- a/apps/web/lib/webhook/schemas.ts
+++ b/apps/web/lib/webhook/schemas.ts
@@ -2,6 +2,20 @@ import z from "@/lib/zod";
import { LinkSchema } from "../zod/schemas/links";
import { WEBHOOK_TRIGGERS } from "./constants";
+const customerSchema = z.object({
+ id: z.string(),
+ name: z.string().nullable(),
+ email: z.string().nullable(),
+ avatar: z.string().nullable(),
+});
+
+const saleSchema = z.object({
+ amount: z.number(),
+ paymentProcessor: z.string(),
+ invoiceId: z.string().nullable(),
+ currency: z.string(),
+});
+
export const linkEventSchema = LinkSchema.omit({
tags: true,
tagId: true,
@@ -26,32 +40,30 @@ export const clickEventSchema = z.object({
link: linkEventSchema,
});
-const customerSchema = z.object({
- id: z.string(),
- name: z.string().nullable(),
- email: z.string().nullable(),
- avatar: z.string().nullable(),
-});
-
export const leadEventSchema = z.object({
eventName: z.string(),
customer: customerSchema,
- click: clickEventSchema.omit({ link: true, timestamp: true }),
+ click: clickEventSchema
+ .omit({ link: true, timestamp: true, clickId: true })
+ .and(
+ z.object({
+ id: z.string(),
+ }),
+ ),
link: linkEventSchema,
});
-const saleSchema = z.object({
- amount: z.number(),
- paymentProcessor: z.string(),
- invoiceId: z.string().nullable(),
- currency: z.string(),
-});
-
export const saleEventSchema = z.object({
eventName: z.string(),
customer: customerSchema,
sale: saleSchema,
- click: clickEventSchema.omit({ link: true, timestamp: true }),
+ click: clickEventSchema
+ .omit({ link: true, timestamp: true, clickId: true })
+ .and(
+ z.object({
+ id: z.string(),
+ }),
+ ),
link: linkEventSchema,
});
diff --git a/apps/web/lib/webhook/transform.ts b/apps/web/lib/webhook/transform.ts
index 8f35611757..a3b9f25a5e 100644
--- a/apps/web/lib/webhook/transform.ts
+++ b/apps/web/lib/webhook/transform.ts
@@ -67,6 +67,7 @@ export const transformLeadEventData = (data: any) => {
},
click: {
...lead,
+ id: lead.clickId,
qr: lead.qr === 1,
bot: lead.bot === 1,
},
@@ -97,6 +98,7 @@ export const transformSaleEventData = (data: any) => {
},
click: {
...sale,
+ id: sale.clickId,
qr: sale.qr === 1,
bot: sale.bot === 1,
},