The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
remove transformDoamin
Steven Tey0d36249449f7
diff --git a/apps/web/app/api/domains/[domain]/transfer/route.ts b/apps/web/app/api/domains/[domain]/transfer/route.tsindex 091db5149d..1255b0009f 100644--- a/apps/web/app/api/domains/[domain]/transfer/route.ts+++ b/apps/web/app/api/domains/[domain]/transfer/route.ts@@ -1,7 +1,6 @@import { getAnalytics } from "@/lib/analytics/get-analytics";import { setRootDomain } from "@/lib/api/domains";import { getDomain } from "@/lib/api/domains/get-domain";-import { transformDomain } from "@/lib/api/domains/transform-domain";import { DubApiError } from "@/lib/api/errors";import { withWorkspace } from "@/lib/auth";import { qstash } from "@/lib/cron";@@ -118,11 +117,6 @@ export const POST = withWorkspace(domain,domainCreatedAt: domainRecord.createdAt,projectId: newWorkspaceId,- ...(newWorkspace.plan !== "free" &&- domainRecord.target && {- url: domainRecord.target,- }),- rewrite: domainRecord.type === "rewrite",}),prisma.project.update({where: { id: workspace.id },@@ -158,7 +152,7 @@ export const POST = withWorkspace(},});- return NextResponse.json(transformDomain(domainResponse), { headers });+ return NextResponse.json(domainResponse, { headers });},{ requiredRole: ["owner"] },);diff --git a/apps/web/app/api/domains/route.ts b/apps/web/app/api/domains/route.tsindex 881ebd1a9c..0ef772f294 100644--- a/apps/web/app/api/domains/route.ts+++ b/apps/web/app/api/domains/route.ts@@ -1,6 +1,5 @@import { addDomainToVercel, validateDomain } from "@/lib/api/domains";import { createDomain } from "@/lib/api/domains/create-domain";-import { transformDomain } from "@/lib/api/domains/transform-domain";import { DubApiError, exceededLimitError } from "@/lib/api/errors";import { parseRequestBody } from "@/lib/api/utils";import { withWorkspace } from "@/lib/auth";@@ -27,16 +26,7 @@ export const GET = withWorkspace(async ({ workspace }) => {},});- const result = domains.map((domain) => {- const domainRecord = transformDomain(domain);-- return {- ...domainRecord,- url: domainRecord.target,- };- });-- return NextResponse.json(result);+ return NextResponse.json(domains);});// POST /api/domains - add a domaindiff --git a/apps/web/lib/api/domains/create-domain.ts b/apps/web/lib/api/domains/create-domain.tsindex bcdfc1b19e..d0fc29ffc5 100644--- a/apps/web/lib/api/domains/create-domain.ts+++ b/apps/web/lib/api/domains/create-domain.ts@@ -2,9 +2,6 @@ import { prisma } from "@/lib/prisma";import { WorkspaceProps } from "@/lib/types";import z from "@/lib/zod";import { createDomainBodySchema } from "@/lib/zod/schemas/domains";-import { DubApiError, ErrorCodes } from "../errors";-import { createLink, processLink } from "../links";-import { getDomain } from "./get-domain";type CreateDomainInput = z.infer<typeof createDomainBodySchema> & {workspace: WorkspaceProps;@@ -13,75 +10,18 @@ type CreateDomainInput = z.infer<typeof createDomainBodySchema> & {};export const createDomain = async (input: CreateDomainInput) => {- const {- slug,- workspace,- placeholder,- type,- target,- expiredUrl,- userId,- noindex,- } = input;+ const { slug, workspace, placeholder, expiredUrl } = input;// Add domain to the workspace- const domain = await prisma.domain.create({+ return await prisma.domain.create({data: {slug: slug,projectId: workspace.id,primary: workspace.domains.length === 0,...(placeholder && { placeholder }),+ ...(workspace.plan !== "free" && {+ expiredUrl,+ }),},});-- workspace.domains.push({- slug: domain.slug,- primary: domain.primary,- });-- // Process the domain link- const { link, error, code } = await processLink({- payload: {- id: domain.id,- domain: domain.slug,- key: "_root",- createdAt: domain.createdAt,- archived: false,- proxy: false,- publicStats: false,- trackConversion: false,- ...(workspace.plan === "free"- ? {- url: "",- expiredUrl: null,- rewrite: false,- noindex: false,- }- : {- url: target || "",- expiredUrl: expiredUrl || null,- rewrite: type === "rewrite",- noindex,- }),- },- workspace,- userId: userId,- skipKeyChecks: true,- });-- if (error != null) {- throw new DubApiError({- code: code as ErrorCodes,- message: error,- });- }-- // Create a link for the domain- await createLink(link);-- // Return the domain record- return await getDomain({- slug: domain.slug,- workspaceId: workspace.id,- });};diff --git a/apps/web/lib/api/domains/get-domain.ts b/apps/web/lib/api/domains/get-domain.tsindex 51bddcfe2a..c4bf0b90a5 100644--- a/apps/web/lib/api/domains/get-domain.ts+++ b/apps/web/lib/api/domains/get-domain.ts@@ -1,6 +1,5 @@import { prisma } from "@/lib/prisma";import { DubApiError } from "../errors";-import { transformDomain } from "./transform-domain";type GetDomainInput =| {@@ -38,5 +37,5 @@ export const getDomain = async (input: GetDomainInput) => {});}- return transformDomain(domain);+ return domain;};diff --git a/apps/web/lib/api/domains/update-domain.ts b/apps/web/lib/api/domains/update-domain.tsindex a6dc61849d..984d44f039 100644--- a/apps/web/lib/api/domains/update-domain.ts+++ b/apps/web/lib/api/domains/update-domain.ts@@ -1,10 +1,7 @@import { prisma } from "@/lib/prisma";-import { NewLinkProps, WorkspaceProps } from "@/lib/types";+import { WorkspaceProps } from "@/lib/types";import z from "@/lib/zod";import { updateDomainBodySchema } from "@/lib/zod/schemas/domains";-import { DubApiError, ErrorCodes } from "../errors";-import { processLink, updateLink } from "../links";-import { getDomain } from "./get-domain";type UpdateDomainInput = z.infer<typeof updateDomainBodySchema> & {newSlug?: string;@@ -12,20 +9,10 @@ type UpdateDomainInput = z.infer<typeof updateDomainBodySchema> & {};export const updateDomain = async (input: UpdateDomainInput) => {- const {- slug,- newSlug,- workspace,- placeholder,- type,- target,- expiredUrl,- archived,- noindex,- } = input;+ const { slug, newSlug, workspace, placeholder, expiredUrl, archived } = input;// Update domain- const domain = await prisma.domain.update({+ return await prisma.domain.update({where: {slug,},@@ -33,6 +20,9 @@ export const updateDomain = async (input: UpdateDomainInput) => {slug: newSlug,archived,...(placeholder && { placeholder }),+ ...(workspace.plan != "free" && {+ expiredUrl,+ }),},include: {links: {@@ -40,51 +30,4 @@ export const updateDomain = async (input: UpdateDomainInput) => {},},});-- const link = domain.links[0];-- const updatedLink = {- ...link,- expiresAt:- link.expiresAt instanceof Date- ? link.expiresAt.toISOString()- : link.expiresAt,- geo: link.geo as NewLinkProps["geo"],- ...(workspace.plan != "free" && {- ...("type" in input && { rewrite: type === "rewrite" }),- ...("target" in input && { url: target || "" }),- ...("expiredUrl" in input && { expiredUrl }),- ...("noindex" in input && { noindex }),- }),- };-- const {- link: processedLink,- error,- code,- } = await processLink({- payload: updatedLink,- workspace,- skipKeyChecks: true,- });-- if (error != null) {- throw new DubApiError({- code: code as ErrorCodes,- message: error,- });- }-- // Update the link- await updateLink({- oldDomain: link.domain,- oldKey: link.key,- updatedLink: processedLink,- });-- // Return the domain record- return await getDomain({- slug: domain.slug,- workspaceId: workspace.id,- });};diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.tsindex 2c41509ab5..49370ff3cf 100644--- a/apps/web/lib/zod/schemas/domains.ts+++ b/apps/web/lib/zod/schemas/domains.ts@@ -19,10 +19,6 @@ export const DomainSchema = z.object({.boolean().describe("Whether the domain is archived.").default(false),- noindex: z- .boolean()- .describe("Prevent search engines from indexing the domain.")- .default(false),placeholder: z.string().describe(@@ -37,18 +33,6 @@ export const DomainSchema = z.object({"The URL to redirect to when a link under this domain has expired.",).openapi({ example: "https://acme.com/expired" }),- target: z- .string()- .nullish()- .describe(- "The page your users will get redirected to when they visit your domain.",- )- .openapi({ example: "https://acme.com/landing" }),- type: z- .string()- .describe("The type of redirect to use for this domain.")- .openapi({ enum: ["redirect", "rewrite"] }),- clicks: z.number().describe("The number of clicks on the domain.").default(0),createdAt: z.date().describe("The date the domain was created."),updatedAt: z.date().describe("The date the domain was last updated."),});@@ -59,18 +43,6 @@ export const createDomainBodySchema = z.object({.min(1, "slug cannot be empty.").describe("Name of the domain.").openapi({ example: "acme.com" }),- type: z- .enum(["redirect", "rewrite"])- .optional()- .default("redirect")- .describe("The type of redirect to use for this domain.")- .openapi({ example: "redirect" }),- target: parseUrlSchema- .nullish()- .describe(- "The page your users will get redirected to when they visit your domain.",- )- .openapi({ example: "https://acme.com/landing" }),expiredUrl: parseUrlSchema.nullish().describe(@@ -85,14 +57,6 @@ export const createDomainBodySchema = z.object({"Whether to archive this domain. `false` will unarchive a previously archived domain.",).openapi({ example: false }),- noindex: z- .boolean()- .optional()- .default(false)- .describe(- "Prevent search engines from indexing the domain. Defaults to `false`.",- )- .openapi({ example: false }),placeholder: parseUrlSchema.nullish().default("https://dub.co/help/article/what-is-dub")