The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improve the schema
Kiran Kf5b39bdf8d2c
diff --git a/apps/web/lib/api/partners/transform-partner.ts b/apps/web/lib/api/partners/transform-partner.tsdeleted file mode 100644index 969d6f2a42..0000000000--- a/apps/web/lib/api/partners/transform-partner.ts+++ /dev/null@@ -1,30 +0,0 @@-import {- EnrolledPartnerSchema,- EnrolledPartnerSchemaExtended,-} from "@/lib/zod/schemas/partners";-import { getPrettyUrl } from "@dub/utils";-import { z } from "zod";--// TODO: This is nice to have but ideally response types should be the same-// across all partners endpoints, so we're not using this for now.-export const transformPartner = (- partner:- | z.infer<typeof EnrolledPartnerSchema>- | z.infer<typeof EnrolledPartnerSchemaExtended>,-) => {- return {- ...partner,- website: partner.website ? getPrettyUrl(partner.website) : null,- youtube: partner.youtube- ? `https://www.youtube.com/@${partner.youtube}`- : null,- twitter: partner.twitter ? `https://x.com/${partner.twitter}` : null,- linkedin: partner.linkedin- ? `https://www.linkedin.com/in/${partner.linkedin}`- : null,- instagram: partner.instagram- ? `https://www.instagram.com/${partner.instagram}`- : null,- tiktok: partner.tiktok ? `https://www.tiktok.com/@${partner.tiktok}` : null,- };-};diff --git a/apps/web/lib/swr/use-partners.ts b/apps/web/lib/swr/use-partners.tsindex eb2e82eb93..d40ab38768 100644--- a/apps/web/lib/swr/use-partners.ts+++ b/apps/web/lib/swr/use-partners.ts@@ -2,10 +2,10 @@ import { fetcher } from "@dub/utils";import useSWR, { SWRConfiguration } from "swr";import { z } from "zod";import { EnrolledPartnerProps } from "../types";-import { partnersQuerySchema } from "../zod/schemas/partners";+import { partnersQuerySchemaExtended } from "../zod/schemas/partners";import useWorkspace from "./use-workspace";-const partialQuerySchema = partnersQuerySchema.partial();+const partialQuerySchema = partnersQuerySchemaExtended.partial();export default function usePartners({diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex 875288307b..4bb61618c8 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -49,7 +49,7 @@ import {import { createOAuthAppSchema, oAuthAppSchema } from "./zod/schemas/oauth";import {createPartnerSchema,- EnrolledPartnerSchemaExtended,+ EnrolledPartnerBasicSchema,PartnerSchema,} from "./zod/schemas/partners";import {@@ -411,9 +411,7 @@ export type PartnerProfileCustomerProps = z.infer<export type PartnerProfileLinkProps = z.infer<typeof PartnerProfileLinkSchema>;-export type EnrolledPartnerProps = z.infer<- typeof EnrolledPartnerSchemaExtended->;+export type EnrolledPartnerProps = z.infer<typeof EnrolledPartnerBasicSchema>;export type DiscountProps = z.infer<typeof DiscountSchema>;diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.tsindex 89fc3583b0..5c003d2df9 100644--- a/apps/web/lib/zod/schemas/partners.ts+++ b/apps/web/lib/zod/schemas/partners.ts@@ -116,7 +116,7 @@ export const partnersQuerySchemaExtended = partnersQuerySchema.merge(}),);-export const partnersExportQuerySchema = partnersQuerySchema+export const partnersExportQuerySchema = partnersQuerySchemaExtended.omit({ page: true, pageSize: true }).merge(z.object({@@ -127,7 +127,7 @@ export const partnersExportQuerySchema = partnersQuerySchema}),);-export const partnersCountQuerySchema = partnersQuerySchema+export const partnersCountQuerySchema = partnersQuerySchemaExtended.omit({sortBy: true,sortOrder: true,@@ -252,6 +252,73 @@ export const PartnerSchema = z}).merge(PartnerOnlinePresenceSchema);+// Used externally by GET+POST /api/partners and partner.enrolled webhook+export const EnrolledPartnerSchema = PartnerSchema.pick({+ id: true,+ name: true,+ email: true,+ image: true,+ description: true,+ country: true,+ website: true,+ youtube: true,+ twitter: true,+ linkedin: true,+ instagram: true,+ tiktok: true,+ paypalEmail: true,+ stripeConnectId: true,+ payoutsEnabledAt: true,+ createdAt: true,+})+ .merge(+ ProgramEnrollmentSchema.pick({+ status: true,+ programId: true,+ tenantId: true,+ links: true,+ }),+ )+ .extend({+ clicks: z+ .number()+ .default(0)+ .describe("The total number of clicks on the partner's links."),+ leads: z+ .number()+ .default(0)+ .describe("The total number of leads generated by the partner's links."),+ sales: z+ .number()+ .default(0)+ .describe("The total number of sales generated by the partner's links."),+ saleAmount: z+ .number()+ .default(0)+ .describe(+ "The total amount of sales (in cents) generated by the partner's links.",+ ),+ totalCommissions: z+ .number()+ .default(0)+ .describe(+ "The total commissions paid to the partner for their referrals.",+ ),+ netRevenue: z+ .number()+ .default(0)+ .describe("The total net revenue generated by the partner."),+ earnings: z+ .number()+ .default(0)+ .describe(+ "DEPRECATED: The total earnings/commissions accrued by the partner's links.",+ )+ .openapi({+ deprecated: true,+ }),+ });+export const EnrolledPartnerBasicSchema = PartnerSchema.pick({id: true,name: true,@@ -273,75 +340,29 @@ export const EnrolledPartnerBasicSchema = PartnerSchema.pick({.merge(PartnerOnlinePresenceSchema).merge(ProgramEnrollmentSchema.pick({+ status: true,programId: true,tenantId: true,links: true,- status: true,}),).extend({- clickRewardId: z.string().nullish(),- leadRewardId: z.string().nullish(),- saleRewardId: z.string().nullish(),- discountId: z.string().nullish(),applicationId: z.string().nullish().describe("If the partner submitted an application to join the program, this is the ID of the application.",),+ clickRewardId: z.string().nullish(),+ leadRewardId: z.string().nullish(),+ saleRewardId: z.string().nullish(),+ discountId: z.string().nullish(),bannedAt: z.date().nullish(),bannedReason: z.enum(Object.keys(BAN_PARTNER_REASONS) as [PartnerBannedReason]).nullish(),});-// Used externally by GET+POST /api/partners and partner.enrolled webhook-export const EnrolledPartnerSchema = EnrolledPartnerBasicSchema.extend({- clicks: z- .number()- .nullish()- .default(0)- .describe("The total number of clicks on the partner's links."),- leads: z- .number()- .nullish()- .default(0)- .describe("The total number of leads generated by the partner's links."),- sales: z- .number()- .nullish()- .default(0)- .describe("The total number of sales generated by the partner's links."),- saleAmount: z- .number()- .nullish()- .default(0)- .describe(- "The total amount of sales (in cents) generated by the partner's links.",- ),- totalCommissions: z- .number()- .nullish()- .default(0)- .describe("The total commissions paid to the partner for their referrals."),- netRevenue: z- .number()- .nullish()- .default(0)- .describe("The total net revenue generated by the partner."),- earnings: z- .number()- .nullish()- .default(0)- .describe(- "DEPRECATED: The total earnings/commissions accrued by the partner's links.",- )- .openapi({- deprecated: true,- }),-});-export const LeaderboardPartnerSchema = z.object({id: z.string(),name: z.string(),diff --git a/apps/web/scripts/cal/backfill-referral-links.ts b/apps/web/scripts/cal/backfill-referral-links.tsindex 339524803f..0781538b3e 100644--- a/apps/web/scripts/cal/backfill-referral-links.ts+++ b/apps/web/scripts/cal/backfill-referral-links.ts@@ -1,3 +1,5 @@+// @ts-nocheck+import { prisma } from "@dub/prisma";import "dotenv-flow/config";import * as fs from "fs";