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.

Add transformWebhookCustomer

Steven Tey53fdca048467
diff --git a/apps/web/lib/webhook/transform.ts b/apps/web/lib/webhook/transform.ts
index 98484470a6..5d8531eaa1 100644
--- a/apps/web/lib/webhook/transform.ts
+++ b/apps/web/lib/webhook/transform.ts
@@ -5,6 +5,7 @@ import {
import { Webhook } from "@dub/prisma/client";
import { nanoid, toCamelCase } from "@dub/utils";
import { ExpandedLink, transformLink } from "../api/links/utils/transform-link";
+import { generateRandomName } from "../names";
import { WebhookTrigger } from "../types";
import z from "../zod";
import { clickEventSchema, clickEventSchemaTB } from "../zod/schemas/clicks";
@@ -47,6 +48,17 @@ export const transformClickEventData = (
});
};
+const transformWebhookCustomer = (customer: any) => {
+ return {
+ ...customer,
+ name: customer.name || customer.email || generateRandomName(),
+ country: undefined,
+ avatar:
+ customer.avatar ||
+ `https://api.dicebear.com/9.x/notionists/svg?seed=${customer.id}`,
+ };
+};
+
export const transformLeadEventData = (data: any) => {
const lead = Object.fromEntries(
Object.entries(data).map(([key, value]) => [toCamelCase(key), value]),
@@ -56,13 +68,7 @@ export const transformLeadEventData = (data: any) => {
return leadWebhookEventSchema.parse({
...lead,
- customer: {
- ...customer,
- country: undefined,
- avatar:
- customer.avatar ||
- `https://api.dicebear.com/9.x/micah/svg?seed=${customer.id}`,
- },
+ customer: transformWebhookCustomer(customer),
click: {
...lead,
id: lead.clickId,
@@ -82,13 +88,7 @@ export const transformSaleEventData = (data: any) => {
return saleWebhookEventSchema.parse({
...sale,
- customer: {
- ...customer,
- country: undefined,
- avatar:
- customer.avatar ||
- `https://api.dicebear.com/9.x/micah/svg?seed=${customer.id}`,
- },
+ customer: transformWebhookCustomer(customer),
sale: {
amount: sale.amount,
currency: sale.currency,