The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
withAuth project → workspace
Steven Tey269304759d13
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.tsindex eb238f4b8d..fcaf912170 100644--- a/apps/web/app/api/domains/[domain]/route.ts+++ b/apps/web/app/api/domains/[domain]/route.ts@@ -10,9 +10,9 @@ import prisma from "@/lib/prisma";import { DUB_PROJECT_ID, isDubDomain } from "@dub/utils";import { NextResponse } from "next/server";-// GET /api/domains/[domain] – get a project's domain-export const GET = withAuth(async ({ domain, project }) => {- if (isDubDomain(domain) && project.id !== DUB_PROJECT_ID) {+// GET /api/domains/[domain] – get a workspace's domain+export const GET = withAuth(async ({ domain, workspace }) => {+ if (isDubDomain(domain) && workspace.id !== DUB_PROJECT_ID) {return new Response("Domain does not belong to workspace.", {status: 403,});@@ -41,8 +41,8 @@ export const GET = withAuth(async ({ domain, project }) => {});});-// PUT /api/domains/[domain] – edit a project's domain-export const PUT = withAuth(async ({ req, project, domain }) => {+// PUT /api/domains/[domain] – edit a workspace's domain+export const PUT = withAuth(async ({ req, workspace, domain }) => {const {slug: newDomain,target,@@ -52,7 +52,7 @@ export const PUT = withAuth(async ({ req, project, domain }) => {archived,} = await req.json();- if (isDubDomain(domain) && project.id !== DUB_PROJECT_ID) {+ if (isDubDomain(domain) && workspace.id !== DUB_PROJECT_ID) {return new Response("Domain does not belong to workspace.", {status: 403,});@@ -80,7 +80,7 @@ export const PUT = withAuth(async ({ req, project, domain }) => {slug: newDomain,}),// same logic as the redis part above- ...(project.plan !== "free" &&+ ...(workspace.plan !== "free" &&(target? {target,@@ -98,7 +98,7 @@ export const PUT = withAuth(async ({ req, project, domain }) => {primary &&prisma.domain.updateMany({where: {- projectId: project.id,+ projectId: workspace.id,primary: true,},data: {@@ -112,22 +112,22 @@ export const PUT = withAuth(async ({ req, project, domain }) => {await setRootDomain({id: response[0].id,domain,- ...(project.plan !== "free" && {+ ...(workspace.plan !== "free" && {url: target,}),rewrite: type === "rewrite",...(newDomain !== domain && {newDomain,}),- projectId: project.id,+ projectId: workspace.id,});return NextResponse.json(response);});-// DELETE /api/domains/[domain] - delete a project's domain-export const DELETE = withAuth(async ({ domain, project }) => {- if (isDubDomain(domain) && project.id !== DUB_PROJECT_ID) {+// DELETE /api/domains/[domain] - delete a workspace's domain+export const DELETE = withAuth(async ({ domain, workspace }) => {+ if (isDubDomain(domain) && workspace.id !== DUB_PROJECT_ID) {return new Response("Domain does not belong to workspace.", {status: 403,});diff --git a/apps/web/app/api/domains/default/route.ts b/apps/web/app/api/domains/default/route.tsindex 790dd79a5b..b5f50acbc3 100644--- a/apps/web/app/api/domains/default/route.ts+++ b/apps/web/app/api/domains/default/route.ts@@ -5,10 +5,10 @@ import { DUB_DOMAINS_ARRAY } from "@dub/utils";import { NextResponse } from "next/server";// GET /api/domains/default - get default domains-export const GET = withAuth(async ({ project }) => {+export const GET = withAuth(async ({ workspace }) => {const defaultDomains = await prisma.defaultDomains.findUnique({where: {- projectId: project.id,+ projectId: workspace.id,},select: {dubsh: true,@@ -37,14 +37,14 @@ const updateDefaultDomainsSchema = z.object({});// PUT /api/domains/default - edit default domains-export const PUT = withAuth(async ({ req, project }) => {+export const PUT = withAuth(async ({ req, workspace }) => {const { defaultDomains } = await updateDefaultDomainsSchema.parseAsync(await req.json(),);const response = await prisma.defaultDomains.update({where: {- projectId: project.id,+ projectId: workspace.id,},data: {dubsh: defaultDomains.includes("dub.sh"),diff --git a/apps/web/app/api/domains/route.ts b/apps/web/app/api/domains/route.tsindex 1a63c83886..96fc20ef61 100644--- a/apps/web/app/api/domains/route.ts+++ b/apps/web/app/api/domains/route.ts@@ -8,11 +8,11 @@ import { withAuth } from "@/lib/auth";import prisma from "@/lib/prisma";import { NextResponse } from "next/server";-// GET /api/domains – get all domains for a project-export const GET = withAuth(async ({ project }) => {+// GET /api/domains – get all domains for a workspace+export const GET = withAuth(async ({ workspace }) => {const domains = await prisma.domain.findMany({where: {- projectId: project.id,+ projectId: workspace.id,},select: {slug: true,@@ -29,14 +29,14 @@ export const GET = withAuth(async ({ project }) => {});// POST /api/domains - add a domain-export const POST = withAuth(async ({ req, project }) => {+export const POST = withAuth(async ({ req, workspace }) => {const { slug: domain, primary, archived, target, type } = await req.json();- if (project.domains.length >= project.domainsLimit) {+ if (workspace.domains.length >= workspace.domainsLimit) {return new Response(exceededLimitError({- plan: project.plan,- limit: project.domainsLimit,+ plan: workspace.plan,+ limit: workspace.domainsLimit,type: "domains",}),{ status: 403 },@@ -66,15 +66,15 @@ export const POST = withAuth(async ({ req, project }) => {slug: domain,target,type,- projectId: project.id,- primary: primary || project.domains.length === 0,+ projectId: workspace.id,+ primary: primary || workspace.domains.length === 0,archived,},}),primary &&prisma.domain.updateMany({where: {- projectId: project.id,+ projectId: workspace.id,primary: true,},data: {@@ -86,8 +86,8 @@ export const POST = withAuth(async ({ req, project }) => {await setRootDomain({id: response[0].id,domain,- projectId: project.id,- ...(project.plan !== "free" && {+ projectId: workspace.id,+ ...(workspace.plan !== "free" && {url: target,}),rewrite: type === "rewrite",diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tsindex 24f2a8b674..4d5d0fb1a1 100644--- a/apps/web/app/api/links/[linkId]/route.ts+++ b/apps/web/app/api/links/[linkId]/route.ts@@ -44,7 +44,7 @@ export const GET = withAuth(async ({ headers, link }) => {});// PUT /api/links/[linkId] – update a link-export const PUT = withAuth(async ({ req, headers, project, link }) => {+export const PUT = withAuth(async ({ req, headers, workspace, link }) => {if (!link) {throw new DubApiError({code: "not_found",@@ -72,7 +72,7 @@ export const PUT = withAuth(async ({ req, headers, project, link }) => {code,} = await processLink({payload: updatedLink as LinkWithTagIdsProps,- project,+ workspace,// if domain and key are the same, we don't need to check if the key existsskipKeyChecks:link.domain === updatedLink.domain &&diff --git a/apps/web/app/api/links/count/route.ts b/apps/web/app/api/links/count/route.tsindex 8bead10a38..0be72b826a 100644--- a/apps/web/app/api/links/count/route.ts+++ b/apps/web/app/api/links/count/route.ts@@ -3,13 +3,13 @@ import { withAuth } from "@/lib/auth";import { getLinksCountQuerySchema } from "@/lib/zod/schemas/links";import { NextResponse } from "next/server";-// GET /api/links/count – get the number of links for a project-export const GET = withAuth(async ({ headers, searchParams, project }) => {+// GET /api/links/count – get the number of links for a workspace+export const GET = withAuth(async ({ headers, searchParams, workspace }) => {const { userId, ...params } = getLinksCountQuerySchema.parse(searchParams);const count = await getLinksCount({searchParams: params,- projectId: project.id,+ workspaceId: workspace.id,userId,});diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.tsindex 90be9353eb..9f551e6e98 100644--- a/apps/web/app/api/links/route.ts+++ b/apps/web/app/api/links/route.ts@@ -1,5 +1,5 @@import { DubApiError, ErrorCodes } from "@/lib/api/errors";-import { addLink, getLinksForProject, processLink } from "@/lib/api/links";+import { addLink, getLinksForWorkspace, processLink } from "@/lib/api/links";import { withAuth } from "@/lib/auth";import { qstash } from "@/lib/cron";import { LinkWithTagIdsProps } from "@/lib/types";@@ -11,8 +11,8 @@ import {import { APP_DOMAIN_WITH_NGROK, LOCALHOST_IP } from "@dub/utils";import { NextResponse } from "next/server";-// GET /api/links – get all links for a project-export const GET = withAuth(async ({ headers, searchParams, project }) => {+// GET /api/links – get all links for a workspace+export const GET = withAuth(async ({ headers, searchParams, workspace }) => {const {domain,tagId,@@ -25,8 +25,8 @@ export const GET = withAuth(async ({ headers, searchParams, project }) => {withTags,} = getLinksQuerySchema.parse(searchParams);- const response = await getLinksForProject({- projectId: project.id,+ const response = await getLinksForWorkspace({+ projectId: workspace.id,domain,tagId,tagIds,@@ -44,7 +44,7 @@ export const GET = withAuth(async ({ headers, searchParams, project }) => {// POST /api/links – create a new linkexport const POST = withAuth(- async ({ req, headers, session, project }) => {+ async ({ req, headers, session, workspace }) => {let bodyRaw;try {bodyRaw = await req.json();@@ -71,7 +71,7 @@ export const POST = withAuth(const { link, error, code } = await processLink({payload: body as LinkWithTagIdsProps,- project,+ workspace,...(session && { userId: session.user.id }),});diff --git a/apps/web/app/api/links/sync/route.ts b/apps/web/app/api/links/sync/route.tsindex 2aeffbd5e4..50baabb292 100644--- a/apps/web/app/api/links/sync/route.ts+++ b/apps/web/app/api/links/sync/route.ts@@ -6,7 +6,7 @@ import { SimpleLinkProps } from "@/lib/types";import { NextResponse } from "next/server";// POST /api/links/sync – sync user's publicly created links to their accounts-export const POST = withAuth(async ({ req, session, project }) => {+export const POST = withAuth(async ({ req, session, workspace }) => {let links: SimpleLinkProps[] = [];try {links = await req.json();@@ -38,11 +38,11 @@ export const POST = withAuth(async ({ req, session, project }) => {return new Response("No links created.", { status: 400 });}- if (project.linksUsage + unclaimedLinks.length > project.linksLimit) {+ if (workspace.linksUsage + unclaimedLinks.length > workspace.linksLimit) {return new Response(exceededLimitError({- plan: project.plan,- limit: project.linksLimit,+ plan: workspace.plan,+ limit: workspace.linksLimit,type: "links",}),{ status: 403 },@@ -58,7 +58,7 @@ export const POST = withAuth(async ({ req, session, project }) => {},data: {userId: session.user.id,- projectId: project.id,+ projectId: workspace.id,publicStats: false,},}),@@ -66,7 +66,7 @@ export const POST = withAuth(async ({ req, session, project }) => {unclaimedLinks.map((link) => ({...link!,userId: session.user.id,- projectId: project.id,+ projectId: workspace.id,publicStats: false,})),),diff --git a/apps/web/app/api/tags/route.ts b/apps/web/app/api/tags/route.tsindex 419281191e..71fcef56b4 100644--- a/apps/web/app/api/tags/route.ts+++ b/apps/web/app/api/tags/route.ts@@ -6,10 +6,10 @@ import { COLORS_LIST, randomBadgeColor } from "@/ui/links/tag-badge";import { NextResponse } from "next/server";// GET /api/tags - get all tags for a workspace-export const GET = withAuth(async ({ project, headers }) => {+export const GET = withAuth(async ({ workspace, headers }) => {const tags = await prisma.tag.findMany({where: {- projectId: project.id,+ projectId: workspace.id,},select: {id: true,@@ -23,20 +23,20 @@ export const GET = withAuth(async ({ project, headers }) => {return NextResponse.json(tags, { headers });});-// POST /api/workspaces/[idOrSlug]/tags - create a tag for a project-export const POST = withAuth(async ({ req, project, headers }) => {+// POST /api/workspaces/[idOrSlug]/tags - create a tag for a workspace+export const POST = withAuth(async ({ req, workspace, headers }) => {const tagsCount = await prisma.tag.count({where: {- projectId: project.id,+ projectId: workspace.id,},});- if (tagsCount >= project.tagsLimit) {+ if (tagsCount >= workspace.tagsLimit) {throw new DubApiError({code: "exceeded_limit",message: exceededLimitError({- plan: project.plan,- limit: project.tagsLimit,+ plan: workspace.plan,+ limit: workspace.tagsLimit,type: "tags",}),});@@ -46,7 +46,7 @@ export const POST = withAuth(async ({ req, project, headers }) => {const existingTag = await prisma.tag.findFirst({where: {- projectId: project.id,+ projectId: workspace.id,name: tag,},});@@ -65,7 +65,7 @@ export const POST = withAuth(async ({ req, project, headers }) => {color && COLORS_LIST.map(({ color }) => color).includes(color)? color: randomBadgeColor(),- projectId: project.id,+ projectId: workspace.id,},});diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/manage/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/manage/route.tsindex 5938fcc6b7..f3af82b48d 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/manage/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/manage/route.ts@@ -4,13 +4,13 @@ import { APP_DOMAIN } from "@dub/utils";import { NextResponse } from "next/server";// POST /api/workspaces/[idOrSlug]/billing/manage - create a Stripe billing portal session-export const POST = withAuth(async ({ project }) => {- if (!project.stripeId) {+export const POST = withAuth(async ({ workspace }) => {+ if (!workspace.stripeId) {return new Response("No Stripe customer ID", { status: 400 });}const { url } = await stripe.billingPortal.sessions.create({- customer: project.stripeId,- return_url: `${APP_DOMAIN}/${project.slug}/settings/billing`,+ customer: workspace.stripeId,+ return_url: `${APP_DOMAIN}/${workspace.slug}/settings/billing`,});return NextResponse.json(url);});diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.tsindex 9c8d47c34f..9ecdb257f2 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts@@ -3,7 +3,7 @@ import { stripe } from "@/lib/stripe";import { APP_DOMAIN } from "@dub/utils";import { NextResponse } from "next/server";-export const POST = withAuth(async ({ req, project, session }) => {+export const POST = withAuth(async ({ req, workspace, session }) => {let { plan, period, baseUrl, comparePlans } = await req.json();if (!plan || !period) {@@ -16,17 +16,17 @@ export const POST = withAuth(async ({ req, project, session }) => {lookup_keys: [`${plan}_${period}`],});- const subscription = project.stripeId+ const subscription = workspace.stripeId? await stripe.subscriptions.list({- customer: project.stripeId,+ customer: workspace.stripeId,status: "active",}): null;// if the user already has a subscription, create billing portal to upgrade- if (project.stripeId && subscription && subscription.data.length > 0) {+ if (workspace.stripeId && subscription && subscription.data.length > 0) {const { url } = await stripe.billingPortal.sessions.create({- customer: project.stripeId,+ customer: workspace.stripeId,return_url: `${baseUrl}?upgrade=${plan}`,flow_data: comparePlans? {@@ -57,7 +57,7 @@ export const POST = withAuth(async ({ req, project, session }) => {const stripeSession = await stripe.checkout.sessions.create({customer_email: session.user.email,billing_address_collection: "required",- success_url: `${APP_DOMAIN}/${project.slug}/settings/billing?success=true`,+ success_url: `${APP_DOMAIN}/${workspace.slug}/settings/billing?success=true`,cancel_url: `${baseUrl}?upgrade=${plan}`,line_items: [{ price: prices.data[0].id, quantity: 1 }],automatic_tax: {@@ -68,7 +68,7 @@ export const POST = withAuth(async ({ req, project, session }) => {},mode: "subscription",allow_promotion_codes: true,- client_reference_id: project.id,+ client_reference_id: workspace.id,});return NextResponse.json(stripeSession);diff --git a/apps/web/app/api/workspaces/[idOrSlug]/import/bitly/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/import/bitly/route.tsindex 64828e0d70..d6c287aa9f 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/import/bitly/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/import/bitly/route.ts@@ -7,9 +7,9 @@ import { redis } from "@/lib/upstash";import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";import { NextResponse } from "next/server";-// GET /api/workspaces/[idOrSlug]/import/bitly – get all bitly groups for a project-export const GET = withAuth(async ({ project }) => {- const accessToken = await redis.get(`import:bitly:${project.id}`);+// GET /api/workspaces/[idOrSlug]/import/bitly – get all bitly groups for a workspace+export const GET = withAuth(async ({ workspace }) => {+ const accessToken = await redis.get(`import:bitly:${workspace.id}`);if (!accessToken) {return new Response("No Bitly access token found", { status: 400 });}@@ -49,13 +49,13 @@ export const GET = withAuth(async ({ project }) => {});// POST /api/workspaces/[idOrSlug]/import/bitly - create job to import links from bitly-export const POST = withAuth(async ({ req, project, session }) => {+export const POST = withAuth(async ({ req, workspace, session }) => {const { selectedDomains, selectedGroupTags } = await req.json();- // check if there are domains that are not in the project- // if yes, add them to the project+ // check if there are domains that are not in the workspace+ // if yes, add them to the workspaceconst domainsNotInProject = selectedDomains.filter(- ({ domain }) => !project.domains?.find((d) => d.slug === domain),+ ({ domain }) => !workspace.domains?.find((d) => d.slug === domain),);if (domainsNotInProject.length > 0) {await Promise.allSettled([@@ -64,7 +64,7 @@ export const POST = withAuth(async ({ req, project, session }) => {slug: domain,target: null,type: "redirect",- projectId: project.id,+ projectId: workspace.id,primary: false,})),skipDuplicates: true,@@ -96,7 +96,7 @@ export const POST = withAuth(async ({ req, project, session }) => {qstash.publishJSON({url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/bitly`,body: {- projectId: project.id,+ projectId: workspace.id,userId: session?.user?.id,bitlyGroup,domains,diff --git a/apps/web/app/api/workspaces/[idOrSlug]/import/rebrandly/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/import/rebrandly/route.tsindex 5af3bfea8d..0d9e6f4d68 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/import/rebrandly/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/import/rebrandly/route.ts@@ -6,9 +6,9 @@ import { redis } from "@/lib/upstash";import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";import { NextResponse } from "next/server";-// GET /api/workspaces/[idOrSlug]/import/rebrandly – get all Rebrandly domains for a project-export const GET = withAuth(async ({ project }) => {- const accessToken = await redis.get(`import:rebrandly:${project.id}`);+// GET /api/workspaces/[idOrSlug]/import/rebrandly – get all Rebrandly domains for a workspace+export const GET = withAuth(async ({ workspace }) => {+ const accessToken = await redis.get(`import:rebrandly:${workspace.id}`);if (!accessToken) {return new Response("No Rebrandly access token found", { status: 400 });}@@ -58,20 +58,20 @@ export const GET = withAuth(async ({ project }) => {});// PUT /api/workspaces/[idOrSlug]/import/rebrandly - save Rebrandly API key-export const PUT = withAuth(async ({ req, project }) => {+export const PUT = withAuth(async ({ req, workspace }) => {const { apiKey } = await req.json();- const response = await redis.set(`import:rebrandly:${project.id}`, apiKey);+ const response = await redis.set(`import:rebrandly:${workspace.id}`, apiKey);return NextResponse.json(response);});// POST /api/workspaces/[idOrSlug]/import/rebrandly - create job to import links from Rebrandly-export const POST = withAuth(async ({ req, project, session }) => {+export const POST = withAuth(async ({ req, workspace, session }) => {const { selectedDomains, importTags } = await req.json();- // check if there are domains that are not in the project- // if yes, add them to the project+ // check if there are domains that are not in the workspace+ // if yes, add them to the workspaceconst domainsNotInProject = selectedDomains.filter(- ({ domain }) => !project.domains?.find((d) => d.slug === domain),+ ({ domain }) => !workspace.domains?.find((d) => d.slug === domain),);if (domainsNotInProject.length > 0) {await Promise.allSettled([@@ -80,7 +80,7 @@ export const POST = withAuth(async ({ req, project, session }) => {slug: domain,target: null,type: "redirect",- projectId: project.id,+ projectId: workspace.id,primary: false,})),skipDuplicates: true,@@ -94,7 +94,7 @@ export const POST = withAuth(async ({ req, project, session }) => {qstash.publishJSON({url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/rebrandly`,body: {- projectId: project.id,+ projectId: workspace.id,userId: session?.user?.id,domainId: id,domain,diff --git a/apps/web/app/api/workspaces/[idOrSlug]/import/short/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/import/short/route.tsindex 7933f5c971..5cd0befbf0 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/import/short/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/import/short/route.ts@@ -6,9 +6,9 @@ import { redis } from "@/lib/upstash";import { APP_DOMAIN_WITH_NGROK, fetchWithTimeout } from "@dub/utils";import { NextResponse } from "next/server";-// GET /api/workspaces/[idOrSlug]/import/short – get all short.io domains for a project-export const GET = withAuth(async ({ project }) => {- const accessToken = await redis.get(`import:short:${project.id}`);+// GET /api/workspaces/[idOrSlug]/import/short – get all short.io domains for a workspace+export const GET = withAuth(async ({ workspace }) => {+ const accessToken = await redis.get(`import:short:${workspace.id}`);if (!accessToken) {return new Response("No Short.io access token found", { status: 400 });}@@ -52,20 +52,20 @@ export const GET = withAuth(async ({ project }) => {});// PUT /api/workspaces/[idOrSlug]/import/short - save Short.io API key-export const PUT = withAuth(async ({ req, project }) => {+export const PUT = withAuth(async ({ req, workspace }) => {const { apiKey } = await req.json();- const response = await redis.set(`import:short:${project.id}`, apiKey);+ const response = await redis.set(`import:short:${workspace.id}`, apiKey);return NextResponse.json(response);});// POST /api/workspaces/[idOrSlug]/import/short - create job to import links from Short.io-export const POST = withAuth(async ({ req, project, session }) => {+export const POST = withAuth(async ({ req, workspace, session }) => {const { selectedDomains, importTags } = await req.json();- // check if there are domains that are not in the project- // if yes, add them to the project+ // check if there are domains that are not in the workspace+ // if yes, add them to the workspaceconst domainsNotInProject = selectedDomains.filter(- ({ domain }) => !project.domains?.find((d) => d.slug === domain),+ ({ domain }) => !workspace.domains?.find((d) => d.slug === domain),);if (domainsNotInProject.length > 0) {await Promise.allSettled([@@ -74,7 +74,7 @@ export const POST = withAuth(async ({ req, project, session }) => {slug: domain,target: null,type: "redirect",- projectId: project.id,+ projectId: workspace.id,primary: false,})),skipDuplicates: true,@@ -88,7 +88,7 @@ export const POST = withAuth(async ({ req, project, session }) => {qstash.publishJSON({url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/short`,body: {- projectId: project.id,+ projectId: workspace.id,userId: session?.user?.id,domainId: id,domain,diff --git a/apps/web/app/api/workspaces/[idOrSlug]/invites/reset/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/invites/reset/route.tsindex ae2170a865..1eb2aa3172 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/invites/reset/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/invites/reset/route.ts@@ -4,7 +4,7 @@ import { nanoid } from "@dub/utils";import { NextResponse } from "next/server";export const POST = withAuth(- async ({ project }) => {+ async ({ workspace }) => {const response = await prisma.project.update({where: {id: project.id,diff --git a/apps/web/app/api/workspaces/[idOrSlug]/invites/route.tsx b/apps/web/app/api/workspaces/[idOrSlug]/invites/route.tsxindex 29eff497ee..5bc146448b 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/invites/route.tsx+++ b/apps/web/app/api/workspaces/[idOrSlug]/invites/route.tsx@@ -9,11 +9,11 @@ const emailInviteSchema = z.object({email: z.string().email(),});-// GET /api/workspaces/[idOrSlug]/invites – get invites for a specific project-export const GET = withAuth(async ({ project }) => {+// GET /api/workspaces/[idOrSlug]/invites – get invites for a specific workspace+export const GET = withAuth(async ({ workspace }) => {const invites = await prisma.projectInvite.findMany({where: {- projectId: project.id,+ projectId: workspace.id,},select: {email: true,@@ -25,14 +25,14 @@ export const GET = withAuth(async ({ project }) => {// POST /api/workspaces/[idOrSlug]/invites – invite a teammateexport const POST = withAuth(- async ({ req, project, session }) => {+ async ({ req, workspace, session }) => {const { email } = emailInviteSchema.parse(await req.json());const [alreadyInTeam, projectUserCount, projectInviteCount] =await Promise.all([prisma.projectUsers.findFirst({where: {- projectId: project.id,+ projectId: workspace.id,user: {email,},@@ -40,12 +40,12 @@ export const POST = withAuth(}),prisma.projectUsers.count({where: {- projectId: project.id,+ projectId: workspace.id,},}),prisma.projectInvite.count({where: {- projectId: project.id,+ projectId: workspace.id,},}),]);@@ -57,12 +57,12 @@ export const POST = withAuth(});}- if (projectUserCount + projectInviteCount >= project.usersLimit) {+ if (projectUserCount + projectInviteCount >= workspace.usersLimit) {throw new DubApiError({code: "exceeded_limit",message: exceededLimitError({- plan: project.plan,- limit: project.usersLimit,+ plan: workspace.plan,+ limit: workspace.usersLimit,type: "users",}),});@@ -70,7 +70,7 @@ export const POST = withAuth(await inviteUser({email,- project,+ workspace,session,});@@ -83,13 +83,13 @@ export const POST = withAuth(// DELETE /api/workspaces/[idOrSlug]/invites – delete a pending inviteexport const DELETE = withAuth(- async ({ searchParams, project }) => {+ async ({ searchParams, workspace }) => {const { email } = emailInviteSchema.parse(searchParams);const response = await prisma.projectInvite.delete({where: {email_projectId: {email,- projectId: project.id,+ projectId: workspace.id,},},});diff --git a/apps/web/app/api/workspaces/[idOrSlug]/logo/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/logo/route.tsindex a1afbea702..15afd2d63e 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/logo/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/logo/route.ts@@ -8,15 +8,15 @@ const uploadLogoSchema = z.object({image: z.string().url(),});-// POST /api/workspaces/[idOrSlug]/logo – upload a new project logo+// POST /api/workspaces/[idOrSlug]/logo – upload a new workspace logoexport const POST = withAuth(- async ({ req, project }) => {+ async ({ req, workspace }) => {const { image } = uploadLogoSchema.parse(await req.json());- const { url } = await storage.upload(`logos/${project.id}`, image);+ const { url } = await storage.upload(`logos/${workspace.id}`, image);const response = await prisma.project.update({- where: { id: project.id },+ where: { id: workspace.id },data: { logo: url },});diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.tsindex 0ee955339f..5edd2bd62b 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts@@ -23,11 +23,11 @@ const updateProjectSchema = z.object({});// GET /api/workspaces/[idOrSlug] – get a specific workspace by id or slug-export const GET = withAuth(async ({ project, headers }) => {+export const GET = withAuth(async ({ workspace, headers }) => {return NextResponse.json({- ...project,- id: `ws_${project.id}`,+ ...workspace,+ id: `ws_${workspace.id}`,},{ headers },);@@ -35,7 +35,7 @@ export const GET = withAuth(async ({ project, headers }) => {// PUT /api/workspaces/[idOrSlug] – update a specific workspace by id or slugexport const PUT = withAuth(- async ({ req, project }) => {+ async ({ req, workspace }) => {try {const { name, slug } = await updateProjectSchema.parseAsync(await req.json(),@@ -43,7 +43,7 @@ export const PUT = withAuth(const response = await prisma.project.update({where: {- slug: project.slug,+ slug: workspace.slug,},data: {...(name && { name }),@@ -69,8 +69,8 @@ export const PUT = withAuth(// DELETE /api/workspaces/[idOrSlug] – delete a specific projectexport const DELETE = withAuth(- async ({ project }) => {- const response = await deleteWorkspace(project);+ async ({ workspace }) => {+ const response = await deleteWorkspace(workspace);return NextResponse.json(response);},{diff --git a/apps/web/app/api/workspaces/[idOrSlug]/saml/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/saml/route.tsindex 33f3064df8..9345387c56 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/saml/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/saml/route.ts@@ -23,12 +23,12 @@ const deleteSAMLConnectionSchema = z.object({clientSecret: z.string().min(1),});-// GET /api/workspaces/[idOrSlug]/saml – get SAML connections for a specific project-export const GET = withAuth(async ({ project }) => {+// GET /api/workspaces/[idOrSlug]/saml – get SAML connections for a specific workspace+export const GET = withAuth(async ({ workspace }) => {const { apiController } = await jackson();const connections = await apiController.getConnections({- tenant: project.id,+ tenant: workspace.id,product: "Dub",});@@ -46,7 +46,7 @@ export const GET = withAuth(async ({ project }) => {// POST /api/workspaces/[idOrSlug]/saml – create a new SAML connectionexport const POST = withAuth(- async ({ req, project }) => {+ async ({ req, workspace }) => {const { metadataUrl, encodedRawMetadata } =createSAMLConnectionSchema.parse(await req.json());@@ -57,7 +57,7 @@ export const POST = withAuth(metadataUrl: metadataUrl!,defaultRedirectUrl: `${process.env.NEXTAUTH_URL}/auth/saml`,redirectUrl: process.env.NEXTAUTH_URL as string,- tenant: project.id,+ tenant: workspace.id,product: "Dub",});diff --git a/apps/web/app/api/workspaces/[idOrSlug]/scim/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/scim/route.tsindex 47c3dbcc57..2e4790be7a 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/scim/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/scim/route.ts@@ -14,12 +14,12 @@ const deleteDirectorySchema = z.object({});// GET /api/workspaces/[idOrSlug]/scim – get all SCIM directories-export const GET = withAuth(async ({ project }) => {+export const GET = withAuth(async ({ workspace }) => {const { directorySyncController } = await jackson();const { data, error } =await directorySyncController.directories.getByTenantAndProduct(- project.id,+ workspace.id,"Dub",);if (error) {@@ -36,7 +36,7 @@ export const GET = withAuth(async ({ project }) => {// POST /api/workspaces/[idOrSlug]/scim – create a new SCIM directoryexport const POST = withAuth(- async ({ req, project }) => {+ async ({ req, workspace }) => {const { provider = "okta-scim-v2", currentDirectoryId } =createDirectorySchema.parse(await req.json());@@ -45,7 +45,7 @@ export const POST = withAuth(const [data, _] = await Promise.all([directorySyncController.directories.create({name: "Dub SCIM Directory",- tenant: project.id,+ tenant: workspace.id,product: "Dub",type: provider,}),diff --git a/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/users/route.tsindex 813fdd45c4..0e58fcf508 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts@@ -18,11 +18,11 @@ const removeUserSchema = z.object({userId: z.string().min(1),});-// GET /api/workspaces/[idOrSlug]/users – get users for a specific project-export const GET = withAuth(async ({ project }) => {+// GET /api/workspaces/[idOrSlug]/users – get users for a specific workspace+export const GET = withAuth(async ({ workspace }) => {const users = await prisma.projectUsers.findMany({where: {- projectId: project.id,+ projectId: workspace.id,},select: {role: true,@@ -45,14 +45,14 @@ export const GET = withAuth(async ({ project }) => {);});-// PUT /api/workspaces/[idOrSlug]/users – update a user's role for a specific project+// PUT /api/workspaces/[idOrSlug]/users – update a user's role for a specific workspaceexport const PUT = withAuth(- async ({ req, project }) => {+ async ({ req, workspace }) => {const { userId, role } = updateRoleSchema.parse(await req.json());const response = await prisma.projectUsers.update({where: {userId_projectId: {- projectId: project.id,+ projectId: workspace.id,userId,},},@@ -67,15 +67,15 @@ export const PUT = withAuth(},);-// DELETE /api/workspaces/[idOrSlug]/users – remove a user from a project+// DELETE /api/workspaces/[idOrSlug]/users – remove a user from a workspaceexport const DELETE = withAuth(- async ({ searchParams, project, session }) => {+ async ({ searchParams, workspace, session }) => {const { userId } = removeUserSchema.parse(searchParams);const projectUser = await prisma.projectUsers.findUnique({where: {userId_projectId: {- projectId: project.id,+ projectId: workspace.id,userId,},},@@ -99,7 +99,7 @@ export const DELETE = withAuth(const response = await prisma.projectUsers.delete({where: {userId_projectId: {- projectId: project.id,+ projectId: workspace.id,userId,},},diff --git a/apps/web/emails/project-invite.tsx b/apps/web/emails/workspace-invite.tsxsimilarity index 72%rename from apps/web/emails/project-invite.tsxrename to apps/web/emails/workspace-invite.tsxindex 8c2348a5d0..fb04b49a20 100644--- a/apps/web/emails/project-invite.tsx+++ b/apps/web/emails/workspace-invite.tsx@@ -14,26 +14,26 @@ import {} from "@react-email/components";import Footer from "./components/footer";-export default function ProjectInvite({+export default function WorkspaceInvite({email = "[email protected]",appName = "Dub.co",url = "http://localhost:8888/api/auth/callback/email?callbackUrl=http%3A%2F%2Fapp.localhost%3A3000%2Flogin&token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&[email protected]",- projectName = "Acme",- projectUser = "Brendon Urie",- projectUserEmail = "[email protected]",+ workspaceName = "Acme",+ workspaceUser = "Brendon Urie",+ workspaceUserEmail = "[email protected]",}: {email: string;appName: string;url: string;- projectName: string;- projectUser: string | null;- projectUserEmail: string | null;+ workspaceName: string;+ workspaceUser: string | null;+ workspaceUserEmail: string | null;}) {return (<Html><Head /><Preview>- Join {projectName} on {appName}+ Join {workspaceName} on {appName}</Preview><Tailwind><Body className="mx-auto my-auto bg-white font-sans">@@ -48,24 +48,24 @@ export default function ProjectInvite({/></Section><Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">- Join {projectName} on {appName}+ Join {workspaceName} on {appName}</Heading>- {projectUser && projectUserEmail ? (+ {workspaceUser && workspaceUserEmail ? (<Text className="text-sm leading-6 text-black">- <strong>{projectUser}</strong> (+ <strong>{workspaceUser}</strong> (<LinkclassName="text-blue-600 no-underline"- href={`mailto:${projectUserEmail}`}+ href={`mailto:${workspaceUserEmail}`}>- {projectUserEmail}+ {workspaceUserEmail}</Link>- ) has invited you to join the <strong>{projectName}</strong>{" "}- project on {appName}!+ ) has invited you to join the <strong>{workspaceName}</strong>{" "}+ workspace on {appName}!</Text>) : (<Text className="text-sm leading-6 text-black">- You have been invited to join the <strong>{projectName}</strong>{" "}- project on {appName}!+ You have been invited to join the{" "}+ <strong>{workspaceName}</strong> workspace on {appName}!</Text>)}<Section className="mb-8 text-center">@@ -73,7 +73,7 @@ export default function ProjectInvite({className="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"href={url}>- Join Project+ Join Workspace</Link></Section><Text className="text-sm leading-6 text-black">diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.tsindex 3485d6a12b..73a2130beb 100644--- a/apps/web/lib/api/links.ts+++ b/apps/web/lib/api/links.ts@@ -34,7 +34,7 @@ import {} from "../types";import z from "../zod";-export async function getLinksForProject({+export async function getLinksForWorkspace({projectId,domain,tagId,@@ -118,11 +118,11 @@ export async function getLinksForProject({export async function getLinksCount({searchParams,- projectId,+ workspaceId,userId,}: {searchParams: z.infer<typeof getLinksCountQuerySchema>;- projectId: string;+ workspaceId: string;userId?: string | null;}) {const { groupBy, search, domain, tagId, tagIds, showArchived, withTags } =@@ -131,7 +131,7 @@ export async function getLinksCount({const combinedTagIds = combineTagIds({ tagId, tagIds });const linksWhere = {- projectId,+ projectId: workspaceId,archived: showArchived ? undefined : false,...(userId && { userId }),...(search && {@@ -205,11 +205,11 @@ export async function getLinksCount({export async function keyChecks({domain,key,- project,+ workspace,}: {domain: string;key: string;- project?: WorkspaceProps;+ workspace?: WorkspaceProps;}) {const link = await checkIfKeyExists(domain, key);if (link) {@@ -230,7 +230,7 @@ export async function keyChecks({};}- if (key.length <= 3 && (!project || project.plan === "free")) {+ if (key.length <= 3 && (!workspace || workspace.plan === "free")) {return {error: `You can only use keys that are 3 characters or less on a Pro plan and above. Upgrade to Pro to register a ${key.length}-character key.`,code: "forbidden",@@ -238,7 +238,7 @@ export async function keyChecks({}if ((await isReservedUsername(key)) &&- (!project || project.plan === "free")+ (!workspace || workspace.plan === "free")) {return {error:@@ -269,13 +269,13 @@ export function processKey(key: string) {export async function processLink({payload,- project,+ workspace,userId,bulk = false,skipKeyChecks = false, // only skip when key doesn't change (e.g. when editing a link)}: {payload: LinkWithTagIdsProps;- project?: WorkspaceProps;+ workspace?: WorkspaceProps;userId?: string;bulk?: boolean;skipKeyChecks?: boolean;@@ -314,7 +314,7 @@ export async function processLink({}// free plan restrictions- if (!project || project.plan === "free") {+ if (!workspace || workspace.plan === "free") {if (proxy || password || rewrite || expiresAt || ios || android || geo) {return {link: payload,@@ -325,9 +325,9 @@ export async function processLink({}}- // if domain is not defined, set it to the project's primary domain+ // if domain is not defined, set it to the workspace's primary domainif (!domain) {- domain = project?.domains?.find((d) => d.primary)?.slug || SHORT_DOMAIN;+ domain = workspace?.domains?.find((d) => d.primary)?.slug || SHORT_DOMAIN;}// checks for default short domain@@ -364,8 +364,8 @@ export async function processLink({};}- // else, check if the domain belongs to the project- } else if (!project?.domains?.find((d) => d.slug === domain)) {+ // else, check if the domain belongs to the workspace+ } else if (!workspace?.domains?.find((d) => d.slug === domain)) {return {link: payload,error: "Domain does not belong to workspace.",@@ -386,7 +386,7 @@ export async function processLink({}key = processedKey;- const response = await keyChecks({ domain, key, project });+ const response = await keyChecks({ domain, key, workspace });if (response.error) {return {link: payload,@@ -419,7 +419,7 @@ export async function processLink({select: {id: true,},- where: { projectId: project?.id, id: { in: tagIds } },+ where: { projectId: workspace?.id, id: { in: tagIds } },});if (tags.length !== tagIds.length) {@@ -477,8 +477,8 @@ export async function processLink({domain,key,url: processedUrl,- // make sure projectId is set to the current project- projectId: project?.id || null,+ // make sure projectId is set to the current workspace+ projectId: workspace?.id || null,// if userId is passed, set it (we don't change the userId if it's already set, e.g. when editing a link)...(userId && {userId,@@ -691,7 +691,7 @@ export async function propagateBulkLinkChanges(await Promise.all([// update Redispipeline.exec(),- // update links usage for project+ // update links usage for workspaceprisma.project.update({where: {id: links[0].projectId!, // this will always be presentdiff --git a/apps/web/lib/api/users.ts b/apps/web/lib/api/users.tsindex 731f33e25e..b65661fb9c 100644--- a/apps/web/lib/api/users.ts+++ b/apps/web/lib/api/users.ts@@ -4,23 +4,23 @@ import { WorkspaceProps } from "@/lib/types";import { TWO_WEEKS_IN_SECONDS } from "@dub/utils";import { randomBytes } from "crypto";import { sendEmail } from "emails";-import ProjectInvite from "emails/project-invite";+import WorkspaceInvite from "emails/workspace-invite";import { DubApiError } from "./errors";export async function inviteUser({email,- project,+ workspace,session,}: {email: string;- project: WorkspaceProps;+ workspace: WorkspaceProps;session?: Session;}) {// same method of generating a token as next-authconst token = randomBytes(32).toString("hex");const expires = new Date(Date.now() + TWO_WEEKS_IN_SECONDS * 1000);- // create a project invite record and a verification request token that lasts for a week+ // create a workspace invite record and a verification request token that lasts for a week// here we use a try catch to account for the case where the user has already been invited// for which `prisma.projectInvite.create()` will throw a unique constraint errortry {@@ -28,7 +28,7 @@ export async function inviteUser({data: {email,expires,- projectId: project.id,+ projectId: workspace.id,},});} catch (error) {@@ -49,7 +49,7 @@ export async function inviteUser({});const params = new URLSearchParams({- callbackUrl: `${process.env.NEXTAUTH_URL}/${project.slug}`,+ callbackUrl: `${process.env.NEXTAUTH_URL}/${workspace.slug}`,email,token,});@@ -57,15 +57,15 @@ export async function inviteUser({const url = `${process.env.NEXTAUTH_URL}/api/auth/callback/email?${params}`;return await sendEmail({- subject: `You've been invited to join a project on ${process.env.NEXT_PUBLIC_APP_NAME}`,+ subject: `You've been invited to join a workspace on ${process.env.NEXT_PUBLIC_APP_NAME}`,email,- react: ProjectInvite({+ react: WorkspaceInvite({email,appName: process.env.NEXT_PUBLIC_APP_NAME as string,url,- projectName: project.name,- projectUser: session?.user.name || null,- projectUserEmail: session?.user.email || null,+ workspaceName: workspace.name,+ workspaceUser: session?.user.name || null,+ workspaceUserEmail: session?.user.email || null,}),});}diff --git a/apps/web/lib/api/workspaces.ts b/apps/web/lib/api/workspaces.tsindex 3ce53ab298..8ca8005395 100644--- a/apps/web/lib/api/workspaces.ts+++ b/apps/web/lib/api/workspaces.ts@@ -7,12 +7,12 @@ import { WorkspaceProps } from "../types";import { redis } from "../upstash";export async function deleteWorkspace(- project: Pick<WorkspaceProps, "id" | "slug" | "stripeId" | "logo">,+ workspace: Pick<WorkspaceProps, "id" | "slug" | "stripeId" | "logo">,) {const [customDomains, defaultDomainLinks] = await Promise.all([prisma.domain.findMany({where: {- projectId: project.id,+ projectId: workspace.id,},select: {slug: true,@@ -20,7 +20,7 @@ export async function deleteWorkspace(}),prisma.link.findMany({where: {- projectId: project.id,+ projectId: workspace.id,domain: {in: DUB_DOMAINS_ARRAY,},@@ -51,11 +51,11 @@ export async function deleteWorkspace(pipeline.hdel(domain, ...links);});- // delete all domains, links, and uploaded images associated with the project+ // delete all domains, links, and uploaded images associated with the workspaceconst deleteDomainsLinksResponse = await Promise.allSettled([...customDomains.map(({ slug }) =>deleteDomainAndLinks(slug, {- // here, we don't need to delete in prisma because we're deleting the project later and have onDelete: CASCADE set+ // here, we don't need to delete in prisma because we're deleting the workspace later and have onDelete: CASCADE setskipPrismaDelete: true,}),),@@ -70,15 +70,15 @@ export async function deleteWorkspace(]);const deleteWorkspaceResponse = await Promise.all([- // delete project logo if it's a custom logo stored in R2- project.logo?.startsWith(process.env.STORAGE_BASE_URL as string) &&- storage.delete(`logos/${project.id}`),+ // delete workspace logo if it's a custom logo stored in R2+ workspace.logo?.startsWith(process.env.STORAGE_BASE_URL as string) &&+ storage.delete(`logos/${workspace.id}`),// if they have a Stripe subscription, cancel it- project.stripeId && cancelSubscription(project.stripeId),- // delete the project+ workspace.stripeId && cancelSubscription(workspace.stripeId),+ // delete the workspaceprisma.project.delete({where: {- slug: project.slug,+ slug: workspace.slug,},}),]);@@ -90,12 +90,12 @@ export async function deleteWorkspace(}export async function deleteWorkspaceAdmin(- project: Pick<WorkspaceProps, "id" | "slug" | "stripeId" | "logo">,+ workspace: Pick<WorkspaceProps, "id" | "slug" | "stripeId" | "logo">,) {const [customDomains, _] = await Promise.all([prisma.domain.findMany({where: {- projectId: project.id,+ projectId: workspace.id,},select: {slug: true,@@ -103,7 +103,7 @@ export async function deleteWorkspaceAdmin(}),prisma.link.updateMany({where: {- projectId: project.id,+ projectId: workspace.id,domain: {in: DUB_DOMAINS_ARRAY,},@@ -115,26 +115,26 @@ export async function deleteWorkspaceAdmin(}),]);- // delete all domains, links, and uploaded images associated with the project+ // delete all domains, links, and uploaded images associated with the workspaceconst deleteDomainsLinksResponse = await Promise.allSettled([...customDomains.map(({ slug }) =>deleteDomainAndLinks(slug, {- // here, we don't need to delete in prisma because we're deleting the project later and have onDelete: CASCADE set+ // here, we don't need to delete in prisma because we're deleting the workspace later and have onDelete: CASCADE setskipPrismaDelete: true,}),),]);const deleteWorkspaceResponse = await Promise.all([- // delete project logo if it's a custom logo stored in R2- project.logo?.startsWith(process.env.STORAGE_BASE_URL as string) &&- storage.delete(`logos/${project.id}`),+ // delete workspace logo if it's a custom logo stored in R2+ workspace.logo?.startsWith(process.env.STORAGE_BASE_URL as string) &&+ storage.delete(`logos/${workspace.id}`),// if they have a Stripe subscription, cancel it- project.stripeId && cancelSubscription(project.stripeId),- // delete the project+ workspace.stripeId && cancelSubscription(workspace.stripeId),+ // delete the workspaceprisma.project.delete({where: {- slug: project.slug,+ slug: workspace.slug,},}),]);diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.tsindex d10330d26f..f0888f10d1 100644--- a/apps/web/lib/auth/index.ts+++ b/apps/web/lib/auth/index.ts@@ -47,7 +47,7 @@ interface WithAuthHandler {searchParams,headers,session,- project,+ workspace,domain,link,}: {@@ -56,7 +56,7 @@ interface WithAuthHandler {searchParams: Record<string, string>;headers?: Record<string, string>;session: Session;- project: WorkspaceProps;+ workspace: WorkspaceProps;domain: string;link?: LinkProps;}): Promise<Response>;@@ -78,7 +78,7 @@ export const withAuth = (needNotExceededClicks, // if the action needs the user to not have exceeded their clicks usageneedNotExceededLinks, // if the action needs the user to not have exceeded their links usageallowAnonymous, // special case for /api/links (POST /api/links) – allow no session- allowSelf, // special case for removing yourself from a project+ allowSelf, // special case for removing yourself from a workspaceskipLinkChecks, // special case for /api/links/exists – skip link checks}: {requiredPlan?: Array<PlanProps>;@@ -222,7 +222,7 @@ export const withAuth = (}}- let [project, link] = (await Promise.all([+ let [workspace, link] = (await Promise.all([prisma.project.findUnique({where: {id: id || undefined,@@ -285,19 +285,19 @@ export const withAuth = (})),])) as [WorkspaceProps, LinkProps | undefined];- if (!project || !project.users) {- // project doesn't exist+ if (!workspace || !workspace.users) {+ // workspace doesn't existthrow new DubApiError({code: "not_found",message: "Workspace not found.",});}- // prevent unauthorized access to domains that don't belong to the project+ // prevent unauthorized access to domains that don't belong to the workspaceif (domain &&!isDubDomain(domain) &&- !project.domains.find((d) => d.slug === domain)+ !workspace.domains.find((d) => d.slug === domain)) {throw new DubApiError({code: "forbidden",@@ -305,13 +305,13 @@ export const withAuth = (});}- // project exists but user is not part of it- if (project.users.length === 0) {+ // workspace exists but user is not part of it+ if (workspace.users.length === 0) {const pendingInvites = await prisma.projectInvite.findUnique({where: {email_projectId: {email: session.user.email,- projectId: project.id,+ projectId: workspace.id,},},select: {@@ -336,9 +336,9 @@ export const withAuth = (}}- // project role checks+ // workspace role checksif (- !requiredRole.includes(project.users[0].role) &&+ !requiredRole.includes(workspace.users[0].role) &&!(allowSelf && searchParams.userId === session.user.id)) {throw new DubApiError({@@ -348,12 +348,12 @@ export const withAuth = (}// clicks usage overage checks- if (needNotExceededClicks && project.usage > project.usageLimit) {+ if (needNotExceededClicks && workspace.usage > workspace.usageLimit) {throw new DubApiError({code: "forbidden",message: exceededLimitError({- plan: project.plan,- limit: project.usageLimit,+ plan: workspace.plan,+ limit: workspace.usageLimit,type: "clicks",}),});@@ -362,21 +362,21 @@ export const withAuth = (// links usage overage checksif (needNotExceededLinks &&- project.linksUsage > project.linksLimit &&- (project.plan === "free" || project.plan === "pro")+ workspace.linksUsage > workspace.linksLimit &&+ (workspace.plan === "free" || workspace.plan === "pro")) {throw new DubApiError({code: "forbidden",message: exceededLimitError({- plan: project.plan,- limit: project.linksLimit,+ plan: workspace.plan,+ limit: workspace.linksLimit,type: "links",}),});}// plan checks- if (!requiredPlan.includes(project.plan)) {+ if (!requiredPlan.includes(workspace.plan)) {throw new DubApiError({code: "forbidden",message: "Unauthorized: Need higher plan.",@@ -386,7 +386,7 @@ export const withAuth = (// analytics API checksconst url = new URL(req.url || "", API_DOMAIN);if (- project.plan === "free" &&+ workspace.plan === "free" &&apiKey &&url.pathname.includes("/analytics")) {@@ -416,8 +416,8 @@ export const withAuth = (}}- // make sure the link is owned by the project- if (!link || link.projectId !== project?.id) {+ // make sure the link is owned by the workspace+ if (!link || link.projectId !== workspace?.id) {throw new DubApiError({code: "not_found",message: "Link not found.",@@ -431,7 +431,7 @@ export const withAuth = (searchParams,headers,session,- project,+ workspace,domain,link,});