The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Refactor to `customerExternalId` to be more verbose
Steven Tey3ad08d18e731
diff --git a/apps/web/app/(ee)/api/track/lead/route.ts b/apps/web/app/(ee)/api/track/lead/route.tsindex 9f216717dd..016e90283e 100644--- a/apps/web/app/(ee)/api/track/lead/route.ts+++ b/apps/web/app/(ee)/api/track/lead/route.ts@@ -34,7 +34,8 @@ export const POST = withWorkspace(clickId,eventName,eventQuantity,- externalId,+ customerExternalId: newExternalId,+ externalId: oldExternalId, // deprecated (but we'll support it for backwards compatibility)customerId: oldCustomerId, // deprecated (but we'll support it for backwards compatibility)customerName,customerEmail,@@ -44,13 +45,14 @@ export const POST = withWorkspace(} = trackLeadRequestSchema.extend({// add backwards compatibility+ customerExternalId: z.string().nullish(),externalId: z.string().nullish(),customerId: z.string().nullish(),}).parse(body);const stringifiedEventName = eventName.toLowerCase().replace(" ", "-");- const customerExternalId = externalId || oldCustomerId;+ const customerExternalId = newExternalId || oldExternalId || oldCustomerId;const customerId = createId({ prefix: "cus_" });const finalCustomerName =customerName || customerEmail || generateRandomName();diff --git a/apps/web/app/(ee)/api/track/sale/route.ts b/apps/web/app/(ee)/api/track/sale/route.tsindex d927b3a5dc..f261160679 100644--- a/apps/web/app/(ee)/api/track/sale/route.ts+++ b/apps/web/app/(ee)/api/track/sale/route.ts@@ -30,7 +30,8 @@ export const POST = withWorkspace(const body = await parseRequestBody(req);let {- externalId,+ customerExternalId: newExternalId,+ externalId: oldExternalId, // deprecatedcustomerId: oldCustomerId, // deprecatedpaymentProcessor,invoiceId,@@ -42,6 +43,7 @@ export const POST = withWorkspace(} = trackSaleRequestSchema.extend({// add backwards compatibility+ customerExternalId: z.string().nullish(),externalId: z.string().nullish(),customerId: z.string().nullish(),})@@ -63,7 +65,7 @@ export const POST = withWorkspace(}}- const customerExternalId = externalId || oldCustomerId;+ const customerExternalId = newExternalId || oldExternalId || oldCustomerId;if (!customerExternalId) {throw new DubApiError({diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.tsindex c301b27a07..d4f2e19879 100644--- a/apps/web/lib/zod/schemas/leads.ts+++ b/apps/web/lib/zod/schemas/leads.ts@@ -21,7 +21,7 @@ export const trackLeadRequestSchema = z.object({"The name of the lead event to track. Can also be used as a unique identifier to associate a given lead event for a customer for a subsequent sale event (via the `leadEventName` prop in `/track/sale`).",).openapi({ example: "Sign up" }),- externalId: z+ customerExternalId: z.string().trim().max(100)@@ -70,6 +70,13 @@ export const trackLeadRequestSchema = z.object({.describe("Additional metadata to be stored with the lead event. Max 10,000 characters.",),+ externalId: z+ .string()+ .trim()+ .max(100)+ .nullish()+ .describe("Deprecated. Use `customerExternalId` instead.")+ .openapi({ deprecated: true }),});export const trackLeadResponseSchema = z.object({diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.tsindex 223b5f6602..7b12e64b6e 100644--- a/apps/web/lib/zod/schemas/sales.ts+++ b/apps/web/lib/zod/schemas/sales.ts@@ -5,7 +5,7 @@ import { commonDeprecatedEventFields } from "./deprecated";import { linkEventSchema } from "./links";export const trackSaleRequestSchema = z.object({- externalId: z+ customerExternalId: z.string().trim().max(100)@@ -63,6 +63,13 @@ export const trackSaleRequestSchema = z.object({.describe("Additional metadata to be stored with the sale event. Max 10,000 characters when stringified.",),+ externalId: z+ .string()+ .trim()+ .max(100)+ .nullish()+ .describe("Deprecated. Use `customerExternalId` instead.")+ .openapi({ deprecated: true }),});export const trackSaleResponseSchema = z.object({