The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Improve externalId DX
Steven Tey7233f6f17706
diff --git a/apps/docs/sdks/typescript/links/get.mdx b/apps/docs/sdks/typescript/links/get.mdxindex b7418af8fc..a6c4f81bb9 100644--- a/apps/docs/sdks/typescript/links/get.mdx+++ b/apps/docs/sdks/typescript/links/get.mdx@@ -8,12 +8,12 @@ import LinkResponse from "/snippets/link-response.mdx";## Arguments-<ParamField body="domain" type="string" required>+<ParamField body="domain" type="string">The domain of the link to retrieve. E.g. for `d.to/github`, the domain is`d.to`.</ParamField>-<ParamField body="key" type="string" required>+<ParamField body="key" type="string">The key of the link to retrieve. E.g. for `d.to/github`, the key is `github`.</ParamField>diff --git a/apps/web/app/api/links/info/route.ts b/apps/web/app/api/links/info/route.tsindex 6a8c91f3e3..8e15d1600d 100644--- a/apps/web/app/api/links/info/route.ts+++ b/apps/web/app/api/links/info/route.ts@@ -14,12 +14,18 @@ export const GET = withWorkspace(async ({ headers, searchParams, link }) => {throw new DubApiError({code: "bad_request",message:- "You must provide a domain and key, or linkId or externalId to retrieve a link.",+ "You must provide a domain and a key or a linkId or an externalId to retrieve a link.",docUrl: "https://dub.co/docs/api-reference/endpoint/retrieve-a-link",});}if (!link) {+ if (externalId && !externalId.startsWith("ext_")) {+ throw new DubApiError({+ code: "bad_request",+ message: "Invalid externalId. Did you forget to prefix it with `ext_`?",+ });+ }throw new DubApiError({code: "not_found",message: "Link not found.",diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.tsindex a0c26854c0..0235612897 100644--- a/apps/web/lib/zod/schemas/links.ts+++ b/apps/web/lib/zod/schemas/links.ts@@ -138,6 +138,8 @@ export const createLinkBodySchema = z.object({.string().min(1).max(255)+ // remove `ext_` prefix if user passes it+ .transform((v) => (v?.startsWith("ext_") ? v.slice(4) : v)).nullish().describe("This is the ID of the link in your database. If set, it can be used to identify the link in the future. Must be prefixed with `ext_` when passed as a query parameter.",@@ -418,7 +420,7 @@ export const getLinkInfoQuerySchema = domainKeySchema.partial().merge(.string().optional().describe(- "This is the ID of the link in the your database. Must be prefixed with `ext_`. when provided.",+ "This is the ID of the link in the your database. Must be prefixed with `ext_` when passed as a query parameter.",).openapi({ example: "ext_123456" }),}),