The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update schema
Kiran Kff9731a24566
diff --git a/apps/web/app/api/stripe/connect/webhook/checkout-session-completed.ts b/apps/web/app/api/stripe/connect/webhook/checkout-session-completed.tsindex 43ce114f5a..68e219937c 100644--- a/apps/web/app/api/stripe/connect/webhook/checkout-session-completed.ts+++ b/apps/web/app/api/stripe/connect/webhook/checkout-session-completed.ts@@ -114,8 +114,11 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {sendLinkWebhook("sale.created", {linkId,data: {- ...customer,...saleData,+ customerId: customer.id,+ customerName: customer.name,+ customerEmail: customer.email,+ customerAvatar: customer.avatar,},});})(),diff --git a/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts b/apps/web/app/api/stripe/connect/webhook/invoice-paid.tsindex e2f68a915c..5001eee39d 100644--- a/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts+++ b/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts@@ -98,8 +98,11 @@ export async function invoicePaid(event: Stripe.Event) {sendLinkWebhook("sale.created", {linkId,data: {- ...customer,...saleData,+ customerId: customer.id,+ customerName: customer.name,+ customerEmail: customer.email,+ customerAvatar: customer.avatar,},});})(),diff --git a/apps/web/app/api/track/sale/route.ts b/apps/web/app/api/track/sale/route.tsindex a39b4fa77b..883fbaff03 100644--- a/apps/web/app/api/track/sale/route.ts+++ b/apps/web/app/api/track/sale/route.ts@@ -117,6 +117,10 @@ export const POST = withWorkspaceEdge(data: {...response,...clickData,+ customerId: customer.id,+ customerName: customer.name,+ customerEmail: customer.email,+ customerAvatar: customer.avatar,},}),);diff --git a/apps/web/lib/webhook/schemas.ts b/apps/web/lib/webhook/schemas.tsindex 45911262e3..f383312da9 100644--- a/apps/web/lib/webhook/schemas.ts+++ b/apps/web/lib/webhook/schemas.ts@@ -1,7 +1,7 @@import z from "@/lib/zod";export const clickSchema = z.object({- clickId: z.string(),+ id: z.string(),aliasLinkId: z.string(),url: z.string(),ip: z.string(),@@ -28,5 +28,29 @@ export const clickSchema = z.object({refererUrl: z.string(),timestamp: z.string(),identityHash: z.string(),- link: z.object({ id: z.string(), url: z.string() }),+ link: z.object({ id: z.string() }),+});++export const leadSchema = z.object({+ eventName: z.string(),+ customerId: z.string(),+ customerName: z.string(),+ customerEmail: z.string().nullable(),+ customerAvatar: z.string().nullable(),+ click: clickSchema.partial(),+ link: z.object({ id: z.string() }),+});++export const saleSchema = z.object({+ eventName: z.string(),+ customerId: z.string(),+ customerName: z.string(),+ customerEmail: z.string().nullable(),+ customerAvatar: z.string().nullable(),+ amount: z.number(),+ paymentProcessor: z.string(),+ invoiceId: z.string().nullable(),+ currency: z.string(),+ click: clickSchema.partial(),+ link: z.object({ id: z.string() }),});diff --git a/apps/web/lib/webhook/transform.ts b/apps/web/lib/webhook/transform.tsindex 3d3083cc44..d97b77ac53 100644--- a/apps/web/lib/webhook/transform.ts+++ b/apps/web/lib/webhook/transform.ts@@ -1,7 +1,7 @@import { toCamelCase } from "@dub/utils";import type { Webhook } from "@prisma/client";import { LinkSchema } from "../zod/schemas/links";-import { clickSchema } from "./schemas";+import { clickSchema, leadSchema, saleSchema } from "./schemas";interface TransformWebhookPropsextends Pick<Webhook, "id" | "name" | "url" | "secret" | "triggers"> {@@ -37,6 +37,7 @@ export const transformClick = (data: any) => {return clickSchema.parse({...click,+ id: click.clickId,link: {id: click.linkId,url: click.url,@@ -49,7 +50,18 @@ export const transformLead = (data: any) => {Object.entries(data).map(([key, value]) => [toCamelCase(key), value]),);- return lead;+ return leadSchema.parse({+ ...lead,+ click: {+ ...lead,+ id: lead.clickId,+ qr: lead.qr === 1,+ bot: lead.bot === 1,+ },+ link: {+ id: lead.linkId,+ },+ });};export const transformSale = (data: any) => {@@ -57,5 +69,16 @@ export const transformSale = (data: any) => {Object.entries(data).map(([key, value]) => [toCamelCase(key), value]),);- return sale;+ return saleSchema.parse({+ ...sale,+ click: {+ ...sale,+ id: sale.clickId,+ qr: sale.qr === 1,+ bot: sale.bot === 1,+ },+ link: {+ id: sale.linkId,+ },+ });};