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.

fix /api/track/sale

Kiran K158f5433ad55
diff --git a/apps/web/app/api/track/sale/route.ts b/apps/web/app/api/track/sale/route.ts
index 62b9c3f4dd..0aeb05f81c 100644
--- a/apps/web/app/api/track/sale/route.ts
+++ b/apps/web/app/api/track/sale/route.ts
@@ -1,7 +1,7 @@
import { parseRequestBody } from "@/lib/api/utils";
import { withSessionEdge } from "@/lib/auth/session-edge";
import { getLeadEvent, recordSale } from "@/lib/tinybird";
-import { trackSaleEventSchema } from "@/lib/zod/schemas";
+import { trackSaleRequestSchema } from "@/lib/zod/schemas";
import { nanoid } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
@@ -21,11 +21,11 @@ export const POST = withSessionEdge(async ({ req }) => {
recurringIntervalCount,
refunded,
metadata,
- } = trackSaleEventSchema.parse(await parseRequestBody(req));
+ } = trackSaleRequestSchema.parse(await parseRequestBody(req));
waitUntil(
(async () => {
- const leadEvent = await getLeadEvent({ customerId });
+ const leadEvent = await getLeadEvent({ customer_id: customerId });
if (!leadEvent || leadEvent.data.length === 0) {
return;
diff --git a/apps/web/lib/tinybird/get-lead-event.ts b/apps/web/lib/tinybird/get-lead-event.ts
index a32a4d8283..a407d82a1a 100644
--- a/apps/web/lib/tinybird/get-lead-event.ts
+++ b/apps/web/lib/tinybird/get-lead-event.ts
@@ -5,7 +5,7 @@ import { tb } from "./client";
export const getLeadEvent = tb.buildPipe({
pipe: "get_lead_event",
parameters: z.object({
- customerId: z.string(),
+ customer_id: z.string(),
}),
data: leadEventSchemaTB,
});
diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.ts
index 0476174112..4b6ea047a8 100644
--- a/apps/web/lib/zod/schemas/sales.ts
+++ b/apps/web/lib/zod/schemas/sales.ts
@@ -1,7 +1,7 @@
import z from "@/lib/zod";
import { clickEventSchemaTB } from "./clicks";
-export const trackSaleEventSchema = z.object({
+export const trackSaleRequestSchema = z.object({
customerId: z.string(),
paymentProcessor: z.enum(["stripe", "shopify", "paddle"]),
productId: z.string(),
@@ -11,7 +11,10 @@ export const trackSaleEventSchema = z.object({
recurringInterval: z.enum(["month", "year"]).default("month"),
recurringIntervalCount: z.number().int().positive().default(1),
refunded: z.boolean().default(false),
- metadata: z.record(z.unknown()).nullish(),
+ metadata: z
+ .record(z.unknown())
+ .nullish()
+ .transform((val) => (val ? JSON.stringify(val) : "")),
});
export const saleEventSchemaTB = clickEventSchemaTB.omit({ url: true }).and(
@@ -26,9 +29,6 @@ export const saleEventSchemaTB = clickEventSchemaTB.omit({ url: true }).and(
recurring_interval: z.enum(["month", "year"]).default("month"),
recurring_interval_count: z.number().int().positive().default(1),
refunded: z.boolean().default(false),
- metadata: z
- .record(z.unknown())
- .nullish()
- .transform((val) => (val ? JSON.stringify(val) : "")),
+ metadata: z.string().default(""),
}),
);
diff --git a/packages/tinybird/endpoints/get_lead_event.pipe b/packages/tinybird/endpoints/get_lead_event.pipe
new file mode 100644
index 0000000000..d04285c643
--- /dev/null
+++ b/packages/tinybird/endpoints/get_lead_event.pipe
@@ -0,0 +1,11 @@
+DESCRIPTION >
+ Get lead event
+
+TOKEN "browser_endpoint_read_5885" READ
+
+NODE endpoint
+DESCRIPTION >
+ undefined
+
+SQL >
+ % SELECT * FROM dub_lead_events WHERE customer_id = {{ customer_id }} LIMIT 1
\ No newline at end of file