The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
More types / processLink cleanup
Tim Wilsona6958317dd44
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tsindex 264f6b865f..dce88c747b 100644--- a/apps/web/app/api/links/[linkId]/route.ts+++ b/apps/web/app/api/links/[linkId]/route.ts@@ -55,6 +55,7 @@ export const PUT = withAuth(async ({ req, headers, project, link }) => {const body = updateLinkBodySchema.parse(await req.json());+ // Add body onto existing link but maintain NewLinkProps form for processLinkconst updatedLink = {...link,expiresAt:@@ -97,7 +98,7 @@ export const PUT = withAuth(async ({ req, headers, project, link }) => {// link is guaranteed to exist because if not we will return 404domain: link!.domain,key: link!.key,- updatedLink: processedLink as any, // TODO: fix types+ updatedLink: processedLink,}),qstash.publishJSON({url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/event`,diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.tsindex 822243a327..f235523bdb 100644--- a/apps/web/lib/api/links.ts+++ b/apps/web/lib/api/links.ts@@ -292,19 +292,24 @@ export function processKey(key: string) {return key;}-export async function processLink({+export async function processLink<T extends Record<string, any>>({payload,project,userId,bulk = false,skipKeyChecks = false, // only skip when key doesn't change (e.g. when editing a link)}: {- payload: NewLinkProps;+ payload: NewLinkProps & T;project?: ProjectProps;userId?: string;bulk?: boolean;skipKeyChecks?: boolean;-}) {+}): Promise<{+ link: NewLinkProps & T;+ error?: string | null;+ code?: string;+ status?: number;+}> {let {domain,key,@@ -530,7 +535,7 @@ export async function processLink({...(userId && {userId,}),- } as ProcessedLinkProps,+ } as NewLinkProps & T,error: null,};}@@ -736,7 +741,8 @@ export async function editLink({}: {domain?: string;key: string;- updatedLink: LinkProps & ProcessedLinkProps;+ updatedLink: ProcessedLinkProps &+ Pick<LinkProps, "id" | "clicks" | "lastClicked" | "updatedAt">;}) {let {id,