The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
remove deprecated fields from track/lead and track/sale response
Steven Tey847343c6b489
diff --git a/apps/web/lib/api/conversions/track-lead.ts b/apps/web/lib/api/conversions/track-lead.tsindex c16d9a899b..056de00ee7 100644--- a/apps/web/lib/api/conversions/track-lead.ts+++ b/apps/web/lib/api/conversions/track-lead.ts@@ -29,12 +29,12 @@ type TrackLeadParams = z.input<typeof trackLeadRequestSchema> & {export const trackLead = async ({clickId,eventName,- eventQuantity,customerExternalId,customerName,customerEmail,customerAvatar,mode,+ eventQuantity,metadata,rawBody,workspace,@@ -84,6 +84,14 @@ export const trackLead = async ({},);+ const finalCustomerId = createId({ prefix: "cus_" });+ const finalCustomerName =+ customerName || customerEmail || generateRandomName();+ const finalCustomerAvatar =+ customerAvatar && !isStored(customerAvatar)+ ? `${R2_URL}/customers/${finalCustomerId}/avatar_${nanoid(7)}`+ : customerAvatar;+// if this is the first time we're tracking this lead event for this customer// we can proceed with the lead tracking processif (ok) {@@ -167,14 +175,6 @@ export const trackLead = async ({: basePayload;};- const finalCustomerId = createId({ prefix: "cus_" });- const finalCustomerName =- customerName || customerEmail || generateRandomName();- const finalCustomerAvatar =- customerAvatar && !isStored(customerAvatar)- ? `${R2_URL}/customers/${finalCustomerId}/avatar_${nanoid(7)}`- : customerAvatar;-// if the customer doesn't exist in our MySQL DB yet, create itif (!customer) {customer = await prisma.customer.create({@@ -325,29 +325,15 @@ export const trackLead = async ({);}- // edge case (shouldn't happen): if the customer is not found- // and for some reason the externalCustomerId+EventName combo was cached on Redis- // throw an error- if (!customer) {- throw new DubApiError({- code: "not_found",- message: `Customer not found for externalId: ${customerExternalId}`,- });- }-- const lead = trackLeadResponseSchema.parse({+ return trackLeadResponseSchema.parse({click: {id: clickId,},- customer,+ customer: customer ?? {+ name: finalCustomerName,+ email: customerEmail || null,+ avatar: finalCustomerAvatar || null,+ externalId: customerExternalId,+ },});-- return {- ...lead,- // for backwards compatibility – will remove soon- clickId,- customerName: customer.name,- customerEmail: customer.email,- customerAvatar: customer.avatar,- };};diff --git a/apps/web/lib/api/conversions/track-sale.ts b/apps/web/lib/api/conversions/track-sale.tsindex 896fb71606..99c5d449b1 100644--- a/apps/web/lib/api/conversions/track-sale.ts+++ b/apps/web/lib/api/conversions/track-sale.ts@@ -262,7 +262,7 @@ export const trackSale = async ({})(),);- const sale = trackSaleResponseSchema.parse({+ return trackSaleResponseSchema.parse({eventName,customer,sale: {@@ -273,14 +273,4 @@ export const trackSale = async ({metadata,},});-- return {- ...sale,- // for backwards compatibility – will remove soon- amount,- currency,- invoiceId,- paymentProcessor,- metadata,- };};diff --git a/apps/web/tests/tracks/track-lead-client.test.ts b/apps/web/tests/tracks/track-lead-client.test.tsindex e115bd3aad..0c0896219f 100644--- a/apps/web/tests/tracks/track-lead-client.test.ts+++ b/apps/web/tests/tracks/track-lead-client.test.ts@@ -45,14 +45,10 @@ describe("POST /track/lead/client", async () => {expect(response.status).toEqual(200);expect(leadResponse).toStrictEqual({- clickId,- customerName: customer.name,- customerEmail: customer.email,- customerAvatar: customer.avatar,- customer: customer,click: {id: clickId,},+ customer: customer,});});});diff --git a/apps/web/tests/tracks/track-lead.test.ts b/apps/web/tests/tracks/track-lead.test.tsindex e1fb5b7bc8..40075ab126 100644--- a/apps/web/tests/tracks/track-lead.test.ts+++ b/apps/web/tests/tracks/track-lead.test.ts@@ -16,10 +16,6 @@ const expectValidLeadResponse = ({}) => {expect(response.status).toEqual(200);expect(response.data).toStrictEqual({- clickId,- customerName: customer.name,- customerEmail: customer.email,- customerAvatar: customer.avatar,click: {id: clickId,},diff --git a/apps/web/tests/tracks/track-sale-client.test.ts b/apps/web/tests/tracks/track-sale-client.test.tsindex 6a9235894c..4209df39b5 100644--- a/apps/web/tests/tracks/track-sale-client.test.ts+++ b/apps/web/tests/tracks/track-sale-client.test.ts@@ -52,11 +52,6 @@ describe("POST /track/sale/client", async () => {invoiceId: sale.invoiceId,metadata: null,},- amount: sale.amount,- currency: sale.currency,- paymentProcessor: sale.paymentProcessor,- metadata: null,- invoiceId: sale.invoiceId,});});});diff --git a/apps/web/tests/tracks/track-sale.test.ts b/apps/web/tests/tracks/track-sale.test.tsindex e330a3dc60..986808076f 100644--- a/apps/web/tests/tracks/track-sale.test.ts+++ b/apps/web/tests/tracks/track-sale.test.ts@@ -30,11 +30,6 @@ const expectValidSaleResponse = (invoiceId: sale.invoiceId,metadata: null,},- amount: sale.amount,- currency: sale.currency,- paymentProcessor: sale.paymentProcessor,- metadata: null,- invoiceId: sale.invoiceId,});};