The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update the customer in webhook event
Kiran K7ddf37270440
diff --git a/apps/web/app/api/customers/[id]/route.ts b/apps/web/app/api/customers/[id]/route.tsindex 129a3f7672..658f3fc5ed 100644--- a/apps/web/app/api/customers/[id]/route.ts+++ b/apps/web/app/api/customers/[id]/route.ts@@ -91,7 +91,7 @@ export const DELETE = withWorkspace(const { id: externalId } = params;try {- const customer = await prisma.customer.delete({+ await prisma.customer.delete({where: {projectId_externalId: {projectId: workspace.id,@@ -101,7 +101,7 @@ export const DELETE = withWorkspace(});return NextResponse.json({- id: customer.externalId,+ externalId,});} catch (error) {if (error.code === "P2025") {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 b85538062d..bfc1dbbca7 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@@ -127,10 +127,12 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {data: transformSaleEventData({...saleData,link,- customerId: customer.externalId,+ customerId: customer.id,+ customerExternalId: customer.externalId,customerName: customer.name,customerEmail: customer.email,customerAvatar: customer.avatar,+ customerCreatedAt: customer.createdAt,}),}),);diff --git a/apps/web/app/api/stripe/connect/webhook/customer-created.ts b/apps/web/app/api/stripe/connect/webhook/customer-created.tsindex 08d83a2f36..5631553242 100644--- a/apps/web/app/api/stripe/connect/webhook/customer-created.ts+++ b/apps/web/app/api/stripe/connect/webhook/customer-created.ts@@ -113,10 +113,12 @@ export async function customerCreated(event: Stripe.Event) {data: transformLeadEventData({...leadData,link,- customerId: customer.externalId,+ customerId: customer.id,+ customerExternalId: customer.externalId,customerName: customer.name,customerEmail: customer.email,customerAvatar: customer.avatar,+ customerCreatedAt: customer.createdAt,}),}),);diff --git a/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts b/apps/web/app/api/stripe/connect/webhook/invoice-paid.tsindex 3f5ef81008..2cbe7fb1c6 100644--- a/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts+++ b/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts@@ -110,10 +110,12 @@ export async function invoicePaid(event: Stripe.Event) {data: transformSaleEventData({...saleData,link,- customerId: customer.externalId,+ customerId: customer.id,+ customerExternalId: customer.externalId,customerName: customer.name,customerEmail: customer.email,customerAvatar: customer.avatar,+ customerCreatedAt: customer.createdAt,}),}),);diff --git a/apps/web/app/api/track/lead/route.ts b/apps/web/app/api/track/lead/route.tsindex 918edb467e..0883672eda 100644--- a/apps/web/app/api/track/lead/route.ts+++ b/apps/web/app/api/track/lead/route.ts@@ -121,10 +121,12 @@ export const POST = withWorkspaceEdge(...clickData,link,eventName,- customerId: customer.externalId,+ customerId: customer.id,+ customerExternalId: customer.externalId,customerName: customer.name,customerEmail: customer.email,customerAvatar: customer.avatar,+ customerCreatedAt: customer.createdAt,});await sendWorkspaceWebhookOnEdge({diff --git a/apps/web/app/api/track/sale/route.ts b/apps/web/app/api/track/sale/route.tsindex dba0bdbf47..307560cecf 100644--- a/apps/web/app/api/track/sale/route.ts+++ b/apps/web/app/api/track/sale/route.ts@@ -112,10 +112,12 @@ export const POST = withWorkspaceEdge(invoiceId,amount,currency,- customerId: customer.externalId,+ customerId: customer.id,+ customerExternalId: customer.externalId,customerName: customer.name,customerEmail: customer.email,customerAvatar: customer.avatar,+ customerCreatedAt: customer.createdAt,});await sendWorkspaceWebhookOnEdge({diff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.tsindex d1591cedaf..932e2d348f 100644--- a/apps/web/lib/analytics/get-events.ts+++ b/apps/web/lib/analytics/get-events.ts@@ -168,12 +168,14 @@ const getCustomersMap = async (customerIds: string[]) => {return customers.reduce((acc, customer) => {acc[customer.id] = CustomerSchema.parse({- id: customer.externalId ?? customer.id,+ id: customer.id,+ externalId: customer.externalId,name: customer.name || "",email: customer.email || "",avatar:customer.avatar ||`https://api.dicebear.com/7.x/micah/svg?seed=${customer.id}`,+ createdAt: customer.createdAt,});return acc;},diff --git a/apps/web/lib/openapi/customers/delete-customer.ts b/apps/web/lib/openapi/customers/delete-customer.tsindex f9a5ebed58..f4dfa97746 100644--- a/apps/web/lib/openapi/customers/delete-customer.ts+++ b/apps/web/lib/openapi/customers/delete-customer.ts@@ -9,14 +9,14 @@ export const deleteCustomer: ZodOpenApiOperationObject = {summary: "Delete a customer",description: "Delete a customer from a workspace.",requestParams: {- path: CustomerSchema.pick({ id: true }),+ path: CustomerSchema.pick({ externalId: true }),},responses: {"200": {description: "The customer was deleted.",content: {"application/json": {- schema: CustomerSchema.pick({ id: true }),+ schema: CustomerSchema.pick({ externalId: true }),},},},diff --git a/apps/web/lib/openapi/customers/get-customer.ts b/apps/web/lib/openapi/customers/get-customer.tsindex c8105b0575..42254c8202 100644--- a/apps/web/lib/openapi/customers/get-customer.ts+++ b/apps/web/lib/openapi/customers/get-customer.ts@@ -8,7 +8,7 @@ export const getCustomer: ZodOpenApiOperationObject = {summary: "Get a customer",description: "Get a customer by externalID for the authenticated workspace.",requestParams: {- path: CustomerSchema.pick({ id: true }),+ path: CustomerSchema.pick({ externalId: true }),},responses: {"200": {diff --git a/apps/web/lib/openapi/customers/update-customer.ts b/apps/web/lib/openapi/customers/update-customer.tsindex 5e02dde2a9..64ee8f9841 100644--- a/apps/web/lib/openapi/customers/update-customer.ts+++ b/apps/web/lib/openapi/customers/update-customer.ts@@ -12,7 +12,7 @@ export const updateCustomer: ZodOpenApiOperationObject = {summary: "Update a customer",description: "Update a customer for the authenticated workspace.",requestParams: {- path: CustomerSchema.pick({ id: true }),+ path: CustomerSchema.pick({ externalId: true }),},requestBody: {content: {diff --git a/apps/web/lib/webhook/schemas.ts b/apps/web/lib/webhook/schemas.tsindex 3caaf72bc5..2ccbd75f8d 100644--- a/apps/web/lib/webhook/schemas.ts+++ b/apps/web/lib/webhook/schemas.ts@@ -1,15 +1,9 @@import z from "@/lib/zod";import { clickEventSchema } from "../zod/schemas/clicks";+import { CustomerSchema } from "../zod/schemas/customers";import { linkEventSchema } 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(),currency: z.string(),diff --git a/apps/web/lib/webhook/transform.ts b/apps/web/lib/webhook/transform.tsindex 00682d3cd2..1b2c98d1e6 100644--- a/apps/web/lib/webhook/transform.ts+++ b/apps/web/lib/webhook/transform.ts@@ -55,11 +55,13 @@ export const transformLeadEventData = (data: any) => {...lead,customer: {id: lead.customerId,+ externalId: lead.customerExternalId,name: lead.customerName,email: lead.customerEmail,avatar:lead.customerAvatar ||`https://api.dicebear.com/7.x/micah/svg?seed=${lead.customerId}`,+ createdAt: lead.customerCreatedAt,},click: {...lead,@@ -79,9 +81,11 @@ export const transformSaleEventData = (data: any) => {...sale,customer: {id: sale.customerId,+ externalId: sale.customerExternalId,name: sale.customerName,email: sale.customerEmail,avatar: sale.customerAvatar,+ createdAt: sale.customerCreatedAt,},sale: {amount: sale.amount,