The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
chore: Update sales schema to use numbers for recurring and refunded fields
Kiran Kfb6c8e80928f
diff --git a/apps/web/app/api/campaigns/webhooks/stripe/route.ts b/apps/web/app/api/campaigns/webhooks/stripe/route.tsindex 0e4000194c..d7fe9f2414 100644--- a/apps/web/app/api/campaigns/webhooks/stripe/route.ts+++ b/apps/web/app/api/campaigns/webhooks/stripe/route.ts@@ -69,16 +69,15 @@ async function checkoutSessionCompleted(event: Stripe.Event) {await recordSale({...leadEvent.data[0],- timestamp: new Date(Date.now()).toISOString(),event_id: nanoid(16),payment_processor: "stripe",product_id: "",amount: charge.amount_total || 0,currency: charge.currency || "usd",- recurring: true, // TODO: Update this+ recurring: 1, // TODO: Update thisrecurring_interval: "month", // TODO: Update thisrecurring_interval_count: 1, // TODO: Update this- refunded: false,+ refunded: 0,metadata: JSON.stringify({charge,}),diff --git a/apps/web/app/api/track/sale/route.ts b/apps/web/app/api/track/sale/route.tsindex 8690f75c24..472c37d9a3 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 { 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";@@ -31,17 +31,22 @@ export const POST = withSessionEdge(async ({ req }) => {return;}+ const clickData = clickEventSchemaTB+ .omit({ timestamp: true })+ .parse(leadEvent.data[0]);+await recordSale({- ...leadEvent.data[0], // TODO: need to omit `timestamp` so we can let Tinybird auto-generate it on insert+ ...clickData,+ customer_id: customerId,event_id: nanoid(16),payment_processor: paymentProcessor,product_id: productId,amount,currency,- recurring,+ recurring: recurring ? 1 : 0,recurring_interval: recurringInterval,recurring_interval_count: recurringIntervalCount,- refunded,+ refunded: refunded ? 1 : 0,metadata: metadata ? JSON.stringify(metadata) : "",});})(),diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.tsindex ece470dd2b..d631885c57 100644--- a/apps/web/lib/zod/schemas/customers.ts+++ b/apps/web/lib/zod/schemas/customers.ts@@ -2,9 +2,9 @@ import z from "@/lib/zod";export const trackCustomerRequestSchema = z.object({customerId: z.string({ required_error: "customerId is required" }),- customerName: z.string().nullish().default(""),- customerEmail: z.string().email().nullish().default(""),- customerAvatar: z.string().url().nullish().default(""),+ customerName: z.string().nullish(),+ customerEmail: z.string().email().nullish(),+ customerAvatar: z.string().url().nullish(),});export const customersMetadataSchema = z.object({diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.tsindex ef95056d0f..dd2f60e813 100644--- a/apps/web/lib/zod/schemas/sales.ts+++ b/apps/web/lib/zod/schemas/sales.ts@@ -24,10 +24,10 @@ export const saleEventSchemaTB = clickEventSchemaTBproduct_id: z.string(),amount: z.number().int().positive(),currency: z.string(),- recurring: z.boolean(),+ recurring: z.number(),recurring_interval: z.string(),recurring_interval_count: z.number().int().positive(),- refunded: z.boolean(),+ refunded: z.number(),metadata: z.string(),}),);