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.

some cleanup

Kiran K564252750780
diff --git a/apps/web/app/api/track/sale/route.ts b/apps/web/app/api/track/sale/route.ts
index 38ddbd7320..c4d3ea7c3b 100644
--- a/apps/web/app/api/track/sale/route.ts
+++ b/apps/web/app/api/track/sale/route.ts
@@ -2,7 +2,7 @@ import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspaceEdge } from "@/lib/auth/workspace-edge";
import { prismaEdge } from "@/lib/prisma/edge";
import { getLeadEvent, recordSale } from "@/lib/tinybird";
-import { trackSaleRequestSchema } from "@/lib/zod/schemas";
+import { clickEventSchemaTB, trackSaleRequestSchema } from "@/lib/zod/schemas";
import { nanoid } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
@@ -50,15 +50,16 @@ export const POST = withWorkspaceEdge(
return;
}
- // const clickData = clickEventSchemaTB
- // .omit({ timestamp: true })
- // .parse(leadEvent.data[0]);
+ const clickData = clickEventSchemaTB
+ .omit({ timestamp: true })
+ .parse(leadEvent.data[0]);
await recordSale({
- ...leadEvent.data[0],
+ ...clickData,
+ customer_id: customer.id,
event_id: nanoid(16),
payment_processor: paymentProcessor,
- product_id: productId || "",
+ product_id: productId,
invoice_id: invoiceId,
amount,
currency,
diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.ts
index f8c715979b..ff033b9c6f 100644
--- a/apps/web/lib/zod/schemas/leads.ts
+++ b/apps/web/lib/zod/schemas/leads.ts
@@ -14,7 +14,6 @@ export const trackLeadRequestSchema = z.object({
customerId: z
.string()
.max(100)
- .nullish()
.describe(
"This is the unique identifier for the customer in the client's app. This is used to track the customer's journey.",
),
diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.ts
index fcbc0330c6..0d65806240 100644
--- a/apps/web/lib/zod/schemas/sales.ts
+++ b/apps/web/lib/zod/schemas/sales.ts
@@ -4,8 +4,8 @@ import { clickEventSchemaTB } from "./clicks";
export const trackSaleRequestSchema = z.object({
customerId: z.string(),
paymentProcessor: z.enum(["stripe", "shopify", "paddle"]),
- productId: z.string().nullable(),
- invoiceId: z.string(),
+ productId: z.string().nullish(),
+ invoiceId: z.string().nullish(),
amount: z.number().int().positive().default(0),
currency: z.string().default("usd"),
recurring: z.boolean().default(false),
@@ -22,8 +22,8 @@ export const saleEventSchemaTB = clickEventSchemaTB
event_id: z.string(),
customer_id: z.string(),
payment_processor: z.string(),
- product_id: z.string(),
- invoice_id: z.string(),
+ product_id: z.string().nullable().default(""),
+ invoice_id: z.string().nullable().default(""),
amount: z.number(),
currency: z.string(),
recurring: z.number(),