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.

improve the validation

Kiran K17b0b9a93776
diff --git a/apps/web/app/api/track/customer/route.ts b/apps/web/app/api/track/customer/route.ts
index 7104a59535..b758d49c66 100644
--- a/apps/web/app/api/track/customer/route.ts
+++ b/apps/web/app/api/track/customer/route.ts
@@ -56,9 +56,9 @@ export const POST = withWorkspaceEdge(
await recordCustomer({
workspace_id: workspace.id,
customer_id: customer.id,
- name: customerName,
- email: customerEmail,
- avatar: customerAvatar,
+ name: customerName || "",
+ email: customerEmail || "",
+ avatar: customerAvatar || "",
});
const response = trackCustomerResponsetSchema.parse({
diff --git a/apps/web/app/api/track/lead/route.ts b/apps/web/app/api/track/lead/route.ts
index 5da756c16a..0a048e5937 100644
--- a/apps/web/app/api/track/lead/route.ts
+++ b/apps/web/app/api/track/lead/route.ts
@@ -80,9 +80,9 @@ export const POST = withWorkspaceEdge(
recordCustomer({
workspace_id: workspace.id,
customer_id: customer.id,
- name: customerName,
- email: customerEmail,
- avatar: customerAvatar,
+ name: customerName || "",
+ email: customerEmail || "",
+ avatar: customerAvatar || "",
}),
recordLead({
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index 1339e3279e..694caefeda 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -17,8 +17,8 @@ export const trackCustomerResponsetSchema = z.object({
export const customersMetadataSchema = z.object({
workspace_id: z.string(),
customer_id: z.string(),
- name: z.string().nullable().default(""),
- email: z.string().nullable().default(""),
- avatar: z.string().nullable().default(""),
+ name: z.string().default(""),
+ email: z.string().default(""),
+ avatar: z.string().default(""),
deleted: z.number().default(0),
});
diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.ts
index 1fb7dc6d49..3503008666 100644
--- a/apps/web/lib/zod/schemas/leads.ts
+++ b/apps/web/lib/zod/schemas/leads.ts
@@ -2,17 +2,26 @@ import z from "@/lib/zod";
import { clickEventSchemaTB } from "./clicks";
export const trackLeadRequestSchema = z.object({
- clickId: z.string({ required_error: "clickId is required" }),
+ // Required
+ clickId: z
+ .string({ required_error: "clickId is required" })
+ .trim()
+ .min(1, "clickId is required"),
eventName: z
.string({ required_error: "eventName is required" })
- .min(1)
+ .trim()
+ .min(1, "eventName is required")
.max(50),
customerId: z
- .string()
+ .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)