The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add field descriptions
Kiran Kcb5548c946ac
diff --git a/apps/web/app/api/track/lead/route.ts b/apps/web/app/api/track/lead/route.tsindex 47a5996691..eba1918ac9 100644--- a/apps/web/app/api/track/lead/route.ts+++ b/apps/web/app/api/track/lead/route.ts@@ -9,7 +9,6 @@ import {trackLeadResponseSchema,} from "@/lib/zod/schemas/leads";import { nanoid } from "@dub/utils";-import { Customer } from "@prisma/client";import { NextResponse } from "next/server";export const runtime = "edge";@@ -42,32 +41,28 @@ export const POST = withWorkspaceEdge(.parse(clickEvent.data[0]);// Find customer or create if not exists- let customer: null | Customer = null;-- if (externalId && workspace.stripeConnectId) {- customer = await prismaEdge.customer.upsert({- where: {- projectId_externalId: {- projectId: workspace.id,- externalId,- },- },- create: {- id: nanoid(16),- name: customerName, // TODO: Generate random name if not provided- email: customerEmail,- avatar: customerAvatar,- externalId,+ const customer = await prismaEdge.customer.upsert({+ where: {+ projectId_externalId: {projectId: workspace.id,- projectConnectId: workspace.stripeConnectId,- },- update: {- name: customerName,- email: customerEmail,- avatar: customerAvatar,+ externalId,},- });- }+ },+ create: {+ id: nanoid(16),+ name: customerName, // TODO: Generate random name if not provided+ email: customerEmail,+ avatar: customerAvatar,+ externalId,+ projectId: workspace.id,+ projectConnectId: workspace.stripeConnectId,+ },+ update: {+ name: customerName,+ email: customerEmail,+ avatar: customerAvatar,+ },+ });if (!customer) {throw new DubApiError({@@ -90,7 +85,7 @@ export const POST = withWorkspaceEdge(event_id: nanoid(16),event_name: eventName,customer_id: customer.id,- metadata,+ metadata: metadata ? JSON.stringify(metadata) : "",}),]);@@ -101,7 +96,7 @@ export const POST = withWorkspaceEdge(customerEmail,customerAvatar,customerId: externalId,- metadata: metadata ? JSON.parse(metadata) : null,+ metadata,});return NextResponse.json(response, { status: 201 });diff --git a/apps/web/lib/api/errors.ts b/apps/web/lib/api/errors.tsindex 0f69d2f734..1ea7f133ea 100644--- a/apps/web/lib/api/errors.ts+++ b/apps/web/lib/api/errors.ts@@ -118,7 +118,7 @@ export function fromZodError(error: ZodError): ErrorResponse {}export function handleApiError(error: any): ErrorResponse & { status: number } {- console.error("API error occurred", error, JSON.stringify(error, null, 2));+ console.error("API error occurred", JSON.stringify(error, null, 2));// Zod errorsif (error instanceof ZodError) {diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.tsindex 97cacb5bb6..2181d1dbb9 100644--- a/apps/web/lib/zod/schemas/customers.ts+++ b/apps/web/lib/zod/schemas/customers.ts@@ -1,10 +1,36 @@import z from "@/lib/zod";export const trackCustomerRequestSchema = z.object({- customerId: z.string({ required_error: "customerId is required" }),- customerName: z.string().nullish().default(null),- customerEmail: z.string().email().nullish().default(null),- customerAvatar: z.string().url().nullish().default(null),+ // Required+ customerId: z+ .string({ required_error: "customerId is required" })+ .trim()+ .min(1, "customerId is required")+ .max(100)+ .describe(+ "This is the unique identifier for the customer in the client's app. This is used to track the customer's journey.",+ ),++ // Optional+ customerName: z+ .string()+ .max(100)+ .nullish()+ .default(null)+ .describe("Name of the customer in the client's app."),+ customerEmail: z+ .string()+ .email()+ .max(100)+ .nullish()+ .default(null)+ .describe("Email of the customer in the client's app."),+ customerAvatar: z+ .string()+ .max(100)+ .nullish()+ .default(null)+ .describe("Avatar of the customer in the client's app."),});export const trackCustomerResponseSchema = z.object({diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.tsindex 3503008666..b51e791db4 100644--- a/apps/web/lib/zod/schemas/leads.ts+++ b/apps/web/lib/zod/schemas/leads.ts@@ -27,30 +27,25 @@ export const trackLeadRequestSchema = z.object({.max(100).nullish().default(null)- .describe(- "This is the name of the customer in the client's app. This is used to track the customer's journey.",- ),+ .describe("Name of the customer in the client's app."),customerEmail: z.string().email().max(100).nullish().default(null)- .describe(- "This is the email of the customer in the client's app. This is used to track the customer's journey.",- ),+ .describe("Email of the customer in the client's app."),customerAvatar: z.string().max(100).nullish().default(null)- .describe(- "This is the avatar of the customer in the client's app. This is used to track the customer's journey.",- ),+ .describe("Avatar of the customer in the client's app."),metadata: z.record(z.unknown()).nullish()- .transform((val) => (val ? JSON.stringify(val) : "")),+ .default(null)+ .describe("Additional metadata to be stored with the lead event"),});export const trackLeadResponseSchema = z.object({diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.tsindex 9d20fd3dfd..814b6745a8 100644--- a/apps/web/lib/zod/schemas/sales.ts+++ b/apps/web/lib/zod/schemas/sales.ts@@ -6,14 +6,35 @@ export const trackSaleRequestSchema = z.object({customerId: z.string({ required_error: "customerId is required" }).trim()- .min(1, "customerId is required"),- amount: z.number({ required_error: "amount is required" }).int().positive(),- paymentProcessor: z.enum(["stripe", "shopify", "paddle"]),+ .min(1, "customerId is required")+ .max(100)+ .describe(+ "This is the unique identifier for the customer in the client's app. This is used to track the customer's journey.",+ ),+ amount: z+ .number({ required_error: "amount is required" })+ .int()+ .positive()+ .describe("The amount of the sale. Should be passed in cents."),+ paymentProcessor: z+ .enum(["stripe", "shopify", "paddle"])+ .describe("The payment processor via which the sale was made."),// Optional- invoiceId: z.string().nullish().default(null),- currency: z.string().default("usd"),- metadata: z.record(z.unknown()).nullish().default(null),+ invoiceId: z+ .string()+ .nullish()+ .default(null)+ .describe("The invoice ID of the sale."),+ currency: z+ .string()+ .default("usd")+ .describe("The currency of the sale. Accepts ISO 4217 currency codes."),+ metadata: z+ .record(z.unknown())+ .nullish()+ .default(null)+ .describe("Additional metadata to be stored with the sale event."),});export const trackSaleResponseSchema = z.object({diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prismaindex d46cf6251f..9c312e5668 100644--- a/apps/web/prisma/schema.prisma+++ b/apps/web/prisma/schema.prisma@@ -313,7 +313,7 @@ model Customer {externalId String?project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)projectId String- projectConnectId String+ projectConnectId String?stripeCustomerId String? @uniquecreatedAt DateTime @default(now())