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.

remove /track/customer

Steven Teya257e66ee408
diff --git a/apps/web/app/api/track/customer/route.ts b/apps/web/app/api/track/customer/route.ts
deleted file mode 100644
index b970678592..0000000000
--- a/apps/web/app/api/track/customer/route.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import { createId, parseRequestBody } from "@/lib/api/utils";
-import { withWorkspaceEdge } from "@/lib/auth/workspace-edge";
-import { generateRandomName } from "@/lib/names";
-import {
- trackCustomerRequestSchema,
- trackCustomerResponseSchema,
-} from "@/lib/zod/schemas/customers";
-import { prismaEdge } from "@dub/prisma/edge";
-import { NextResponse } from "next/server";
-
-export const runtime = "edge";
-
-// POST /api/track/customer – Track a customer object (Deprecated)
-export const POST = withWorkspaceEdge(
- async ({ req, workspace }) => {
- const {
- customerId: externalId,
- customerName,
- customerEmail,
- customerAvatar,
- } = trackCustomerRequestSchema.parse(await parseRequestBody(req));
-
- const finalCustomerName =
- customerName || customerEmail || generateRandomName();
-
- const customer = await prismaEdge.customer.upsert({
- where: {
- projectId_externalId: {
- projectId: workspace.id,
- externalId,
- },
- },
- create: {
- id: createId({ prefix: "cus_" }),
- name: finalCustomerName,
- email: customerEmail,
- avatar: customerAvatar,
- externalId,
- projectId: workspace.id,
- projectConnectId: workspace.stripeConnectId,
- },
- update: {
- name: finalCustomerName,
- email: customerEmail,
- avatar: customerAvatar,
- },
- });
-
- const response = trackCustomerResponseSchema.parse({
- customerId: customer.externalId,
- customerName: customer.name,
- customerEmail: customer.email,
- customerAvatar: customer.avatar,
- });
-
- return NextResponse.json(response);
- },
- {
- requiredAddOn: "conversion",
- requiredPermissions: ["conversions.write"],
- },
-);
diff --git a/apps/web/lib/openapi/track/customer.ts b/apps/web/lib/openapi/track/customer.ts
deleted file mode 100644
index d0a07699fe..0000000000
--- a/apps/web/lib/openapi/track/customer.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { openApiErrorResponses } from "@/lib/openapi/responses";
-import {
- trackCustomerRequestSchema,
- trackCustomerResponseSchema,
-} from "@/lib/zod/schemas/customers";
-import { ZodOpenApiOperationObject } from "zod-openapi";
-
-export const trackCustomer: ZodOpenApiOperationObject = {
- operationId: "trackCustomer",
- "x-speakeasy-name-override": "customer",
- summary: "Track a customer",
- description: "Track a customer for an authenticated workspace.",
- requestBody: {
- content: {
- "application/json": {
- schema: trackCustomerRequestSchema,
- },
- },
- },
- responses: {
- "200": {
- description: "A customer was tracked.",
- content: {
- "application/json": {
- schema: trackCustomerResponseSchema,
- },
- },
- },
- ...openApiErrorResponses,
- },
- tags: ["Track"],
- security: [{ token: [] }],
- deprecated: true,
-};
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index e8c7b22ade..08f62e7e30 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -16,7 +16,6 @@ import {
customerActivityResponseSchema,
customerActivitySchema,
CustomerSchema,
- trackCustomerResponseSchema,
} from "./zod/schemas/customers";
import { dashboardSchema } from "./zod/schemas/dashboard";
import { integrationSchema } from "./zod/schemas/integration";
@@ -316,8 +315,6 @@ export type WebhookCacheProps = Pick<
"id" | "url" | "secret" | "triggers"
>;
-export type TrackCustomerResponse = z.infer<typeof trackCustomerResponseSchema>;
-
export type TrackLeadResponse = z.infer<typeof trackLeadResponseSchema>;
export type TrackSaleResponse = z.infer<typeof trackSaleResponseSchema>;
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index 73e1704593..fa46ebff53 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -39,43 +39,6 @@ export const CustomerSchema = z.object({
country: z.string().nullish().describe("Country of the customer."),
});
-export const trackCustomerRequestSchema = z.object({
- // 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)
- .optional()
- .describe("Name of the customer in the client's app."),
- customerEmail: z
- .string()
- .email()
- .max(100)
- .optional()
- .describe("Email of the customer in the client's app."),
- customerAvatar: z
- .string()
- .max(100)
- .optional()
- .describe("Avatar of the customer in the client's app."),
-});
-
-export const trackCustomerResponseSchema = z.object({
- customerId: z.string(),
- customerName: z.string().nullable(),
- customerEmail: z.string().nullable(),
- customerAvatar: z.string().nullable(),
-});
-
export const CUSTOMERS_MAX_PAGE_SIZE = 100;
export const customersQuerySchema = z
diff --git a/apps/web/tests/tracks/track-customer.test.ts b/apps/web/tests/tracks/track-customer.test.ts
deleted file mode 100644
index e139fc6edd..0000000000
--- a/apps/web/tests/tracks/track-customer.test.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import { TrackCustomerResponse } from "@/lib/types";
-import { randomCustomer } from "tests/utils/helpers";
-import { describe, expect, test } from "vitest";
-import { IntegrationHarness } from "../utils/integration";
-
-describe("POST /track/customer", async () => {
- const h = new IntegrationHarness();
- const { http } = await h.init();
- const customer = randomCustomer();
-
- test("create a new customer", async () => {
- const response = await http.post<TrackCustomerResponse>({
- path: "/track/customer",
- body: {
- customerId: customer.id,
- },
- });
-
- expect(response.status).toEqual(200);
- expect(response.data).toStrictEqual({
- customerId: customer.id,
- customerName: expect.any(String),
- customerEmail: null,
- customerAvatar: null,
- });
- });
-
- test("update an existing customer", async () => {
- const updatedCustomer = {
- customerName: "David",
- customerEmail: "[email protected]",
- customerAvatar: "https://example.com/david.png",
- };
-
- const response = await http.post<TrackCustomerResponse>({
- path: "/track/customer",
- body: {
- customerId: customer.id,
- ...updatedCustomer,
- },
- });
-
- expect(response.status).toEqual(200);
- expect(response.data).toStrictEqual({
- customerId: customer.id,
- ...updatedCustomer,
- });
- });
-});