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.

remove deprecated customer fields

Steven Tey331f70bb1f1a
diff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.ts
index ddfbf6abe9..e66f5b1b53 100644
--- a/apps/web/lib/analytics/get-events.ts
+++ b/apps/web/lib/analytics/get-events.ts
@@ -72,26 +72,6 @@ export const getEvents = async (params: EventsFilters) => {
return null;
}
- let customer: z.infer<typeof customerSchema> = {
- id: "",
- name: "",
- email: "",
- avatar: "",
- };
-
- if (evt.event === "lead" || evt.event === "sale") {
- customer = customersMap[evt.customer_id];
- if (!customer) {
- console.log("customer not found", evt.customer_id);
- customer = customerSchema.parse({
- id: evt.customer_id,
- name: "Deleted Customer",
- email: "[email protected]",
- avatar: `https://api.dicebear.com/7.x/micah/svg?seed=${evt.customer_id}`,
- });
- }
- }
-
const eventData = {
...evt,
// use link domain & key from mysql instead of tinybird
@@ -109,7 +89,12 @@ export const getEvents = async (params: EventsFilters) => {
? {
eventId: evt.event_id,
eventName: evt.event_name,
- customer,
+ customer: customersMap[evt.customer_id] ?? {
+ id: evt.customer_id,
+ name: "Deleted Customer",
+ email: "[email protected]",
+ avatar: `https://api.dicebear.com/7.x/micah/svg?seed=${evt.customer_id}`,
+ },
...(evt.event === "sale"
? {
sale: {
@@ -119,11 +104,6 @@ export const getEvents = async (params: EventsFilters) => {
},
}
: {}),
- // backwards compatibility for old events
- customer_id: customer.id,
- customer_name: customer.name,
- customer_email: customer.email,
- customer_avatar: customer.avatar,
}
: {}),
};
diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.ts
index c79e4e8d46..f73fb39399 100644
--- a/apps/web/lib/zod/schemas/leads.ts
+++ b/apps/web/lib/zod/schemas/leads.ts
@@ -79,6 +79,7 @@ export const leadEventSchemaTB = clickEventSchemaTB
}),
);
+// response from tinybird endpoint
export const leadEventEnrichedSchema = z.object({
event: z.literal("lead"),
timestamp: z.string(),
@@ -99,6 +100,7 @@ export const leadEventEnrichedSchema = z.object({
ip: z.string().nullable(),
});
+// response from dub api
export const leadEventResponseSchema = z
.object({
event: z.literal("lead"),
@@ -109,18 +111,6 @@ export const leadEventResponseSchema = z
click: clickEventSchema,
link: linkEventSchema,
customer: customerSchema,
- customer_name: z
- .string()
- .describe("Deprecated. Use `customer.name` instead.")
- .openapi({ deprecated: true }),
- customer_email: z
- .string()
- .describe("Deprecated. Use `customer.email` instead.")
- .openapi({ deprecated: true }),
- customer_avatar: z
- .string()
- .describe("Deprecated. Use `customer.avatar` instead.")
- .openapi({ deprecated: true }),
})
.merge(commonDeprecatedEventFields)
.openapi({ ref: "LeadEvent" });
diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.ts
index 8f57aa7e56..adabddf858 100644
--- a/apps/web/lib/zod/schemas/sales.ts
+++ b/apps/web/lib/zod/schemas/sales.ts
@@ -82,6 +82,7 @@ export const saleEventSchemaTB = clickEventSchemaTB
}),
);
+// response from tinybird endpoint
export const saleEventEnrichedSchema = z.object({
event: z.literal("sale"),
timestamp: z.string(),
@@ -105,6 +106,7 @@ export const saleEventEnrichedSchema = z.object({
ip: z.string().nullable(),
});
+// response from dub api
export const saleEventResponseSchema = z
.object({
event: z.literal("sale"),
@@ -120,18 +122,6 @@ export const saleEventResponseSchema = z
invoiceId: true,
paymentProcessor: true,
}),
- customer_name: z
- .string()
- .describe("Deprecated. Use `customer.name` instead.")
- .openapi({ deprecated: true }),
- customer_email: z
- .string()
- .describe("Deprecated. Use `customer.email` instead.")
- .openapi({ deprecated: true }),
- customer_avatar: z
- .string()
- .describe("Deprecated. Use `customer.avatar` instead.")
- .openapi({ deprecated: true }),
saleAmount: z
.number()
.describe("Deprecated. Use `sale.amount` instead.")