The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Minor updates
Steven Tey9eb9565c4a58
diff --git a/apps/web/app/api/links-app/[linkId]/archive/route.ts b/apps/web/app/api/links/[linkId]/archive/route.tssimilarity index 100%rename from apps/web/app/api/links-app/[linkId]/archive/route.tsrename to apps/web/app/api/links/[linkId]/archive/route.tsdiff --git a/apps/web/app/api/links-app/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tssimilarity index 100%rename from apps/web/app/api/links-app/[linkId]/route.tsrename to apps/web/app/api/links/[linkId]/route.tsdiff --git a/apps/web/app/api/links-app/route.ts b/apps/web/app/api/links/route.tssimilarity index 100%rename from apps/web/app/api/links-app/route.tsrename to apps/web/app/api/links/route.tsdiff --git a/apps/web/app/api/projects/[slug]/links/[linkId]/archive/route.ts b/apps/web/app/api/projects/[slug]/links/[linkId]/archive/route.tsindex 5d3e353290..45f8a09eae 100644--- a/apps/web/app/api/projects/[slug]/links/[linkId]/archive/route.ts+++ b/apps/web/app/api/projects/[slug]/links/[linkId]/archive/route.ts@@ -1 +1 @@-export * from "../../../../../links-app/[linkId]/archive/route";+export * from "../../../../../links/[linkId]/archive/route";diff --git a/apps/web/app/api/projects/[slug]/links/[linkId]/route.ts b/apps/web/app/api/projects/[slug]/links/[linkId]/route.tsindex 220562f1b5..e8d96006df 100644--- a/apps/web/app/api/projects/[slug]/links/[linkId]/route.ts+++ b/apps/web/app/api/projects/[slug]/links/[linkId]/route.ts@@ -1 +1 @@-export * from "../../../../links-app/[linkId]/route";+export * from "../../../../links/[linkId]/route";diff --git a/apps/web/app/api/projects/[slug]/links/route.ts b/apps/web/app/api/projects/[slug]/links/route.tsindex 0bac60cc29..a4f0031546 100644--- a/apps/web/app/api/projects/[slug]/links/route.ts+++ b/apps/web/app/api/projects/[slug]/links/route.ts@@ -1 +1 @@-export * from "../../../links-app/route";+export * from "../../../links/route";diff --git a/apps/web/app/app.dub.co/(dashboard)/settings/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/settings/layout.tsxindex 65654ae530..926a4d5053 100644--- a/apps/web/app/app.dub.co/(dashboard)/settings/layout.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/settings/layout.tsx@@ -11,10 +11,10 @@ export default function PersonalSettingsLayout({name: "General",segment: null,},- // {- // name: "API Keys",- // segment: "tokens",- // },+ {+ name: "API Keys",+ segment: "tokens",+ },];return <SettingsLayout tabs={tabs}>{children}</SettingsLayout>;diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsxindex 59060a033b..bfe974f170 100644--- a/apps/web/app/layout.tsx+++ b/apps/web/app/layout.tsx@@ -11,8 +11,8 @@ export default function RootLayout({children: React.ReactNode;}) {return (- <html lang="en">- <body className={cn(satoshi.variable, inter.variable)}>+ <html lang="en" className={cn(satoshi.variable, inter.variable)}>+ <body><Providers>{children}</Providers></body></html>diff --git a/apps/web/lib/swr/use-links.ts b/apps/web/lib/swr/use-links.tsindex eac151c628..313fe8a7d6 100644--- a/apps/web/lib/swr/use-links.ts+++ b/apps/web/lib/swr/use-links.ts@@ -13,7 +13,7 @@ export default function useLinks() {user: UserProps;})[]>(- `/api${slug ? `/projects/${slug}/links` : "/links-app"}${getQueryString({+ `/api${slug ? `/projects/${slug}/links` : "/links"}${getQueryString({searchParams,})}`,fetcher,diff --git a/apps/web/pages/api/links/[key]/index.ts b/apps/web/pages/api/links/[key]/index.tsdeleted file mode 100644index ea2ef2ea7a..0000000000--- a/apps/web/pages/api/links/[key]/index.ts+++ /dev/null@@ -1,112 +0,0 @@-import { deleteLink, editLink, processKey } from "@/lib/api/links";-import { withLinksAuth } from "@/lib/auth/links";-import { isBlacklistedDomain, isBlacklistedKey } from "@/lib/edge-config";-import { GOOGLE_FAVICON_URL, getApexDomain, log } from "@dub/utils";--export const config = {- api: {- bodyParser: {- sizeLimit: "1500kb",- },- },-};--export default withLinksAuth(- async (req, res, session, project, domain, link) => {- // GET /api/links/:key – get a link- if (req.method === "GET") {- return res.status(200).json(link);-- // PUT /api/links/:key – edit a link- } else if (req.method === "PUT") {- // if request body is empty or not a valid json- if (!req.body || typeof req.body !== "object") {- return res.status(400).end("Missing or invalid request body.");- }- if (Object.keys(req.body).length === 0) {- return res.status(304).end("No fields to update.");- }-- const updatedLink = {- ...link,- ...req.body,- };-- let { key, url, rewrite } = updatedLink;-- // for default dub.sh links (not part of a project)- if (!project) {- if (key.includes("/")) {- return res.status(422).end("Key cannot contain '/'.");- }- const keyBlacklisted = await isBlacklistedKey(key);- if (keyBlacklisted) {- return res.status(422).end("Invalid key.");- }- const domainBlacklisted = await isBlacklistedDomain(url);- if (domainBlacklisted) {- return res.status(422).end("Invalid url.");- }- if (rewrite) {- return res- .status(403)- .end("You can only use link cloaking on a custom domain.");- }- }-- key = processKey(key);- if (!key) {- return res.status(422).end("Invalid key.");- }-- const [response, invalidFavicon] = await Promise.allSettled([- editLink({- domain,- key: link!.key, // link is guaranteed to exist because if not we will return 404,- updatedLink,- }),- ...(!project && url- ? [- fetch(`${GOOGLE_FAVICON_URL}${getApexDomain(url)}`).then(- (res) => !res.ok,- ),- ]- : []),- // @ts-ignore- ]).then((results) => results.map((result) => result.value));-- if (response === null) {- return res.status(409).end("Key already exists.");- }-- if (!project && invalidFavicon) {- await log({- message: `*${- session.user.email- }* edited a link (dub.sh/${key}) to the ${url} ${- invalidFavicon- ? " but it has an invalid favicon :thinking_face:"- : ""- }`,- type: "links",- mention: true,- });- }- return res.status(200).json(response);-- // DELETE /api/links/:key – delete a link- } else if (req.method === "DELETE") {- const response = await deleteLink({- domain,- key: link!.key, // link is guaranteed to exist because if not we will return 404- });- return res.status(200).json(response[0]);- } else {- res.setHeader("Allow", ["GET", "PUT", "DELETE"]);- return res.status(405).end(`Method ${req.method} Not Allowed`);- }- },- {- needNotExceededUsage: true,- },-);diff --git a/apps/web/pages/api/links/index.ts b/apps/web/pages/api/links/index.tsdeleted file mode 100644index 7b5e77b6f4..0000000000--- a/apps/web/pages/api/links/index.ts+++ /dev/null@@ -1,146 +0,0 @@-import {- addLink,- getLinksForProject,- getRandomKey,- processKey,-} from "@/lib/api/links";-import { withLinksAuth } from "@/lib/auth/links";-import { isBlacklistedDomain, isBlacklistedKey } from "@/lib/edge-config";-import {- DUB_PROJECT_ID,- GOOGLE_FAVICON_URL,- getApexDomain,- log,-} from "@dub/utils";--export const config = {- api: {- bodyParser: {- sizeLimit: "1500kb",- },- },-};--export default withLinksAuth(- async (req, res, session, project) => {- // GET /api/links – get all links for a project- // if no project, get all dub.sh links for user- if (req.method === "GET") {- const { domain, tagId, search, sort, page, userId, showArchived } =- req.query as {- domain?: string;- tagId?: string;- search?: string;- sort?: "createdAt" | "clicks" | "lastClicked";- page?: string;- userId?: string;- showArchived?: string;- };- const response = await getLinksForProject({- projectId: project?.id || DUB_PROJECT_ID,- domain,- tagId,- search,- sort,- page,- userId: project?.id ? userId : session.user.id,- showArchived: showArchived === "true" ? true : false,- });- return res.status(200).json(response);-- // POST /api/links – create a new link- } else if (req.method === "POST") {- let { domain, key, url, rewrite, geo } = req.body;- if (!url) {- return res.status(400).end("Missing destination url.");- }- if (!domain) {- return res.status(400).end("Missing short link domain.");- }-- if (!key) {- key = await getRandomKey(domain);- }-- // if it's not a custom project, do some filtering- if (!project) {- if (key.includes("/")) {- return res.status(422).end("Key cannot contain '/'.");- }- const keyBlacklisted = await isBlacklistedKey(key);- if (keyBlacklisted) {- return res.status(422).end("Invalid key.");- }- const domainBlacklisted = await isBlacklistedDomain(url);- if (domainBlacklisted) {- return res.status(422).end("Invalid url.");- }- if (rewrite) {- return res- .status(403)- .end("You can only use link cloaking on a custom domain.");- }- }-- // free plan restrictions- if (!project || project.plan === "free") {- if (geo) {- return res- .status(403)- .end("You can only use geo targeting on a Pro plan.");- }- }-- key = processKey(key);- if (!key) {- return res.status(422).end("Invalid key.");- }-- const [response, invalidFavicon] = await Promise.allSettled([- addLink({- ...req.body,- key,- projectId: project?.id || DUB_PROJECT_ID,- userId: session.user.id,- }),- ...(!project- ? [- fetch(`${GOOGLE_FAVICON_URL}${getApexDomain(url)}`).then(- (res) => !res.ok,- ),- ]- : []),- // @ts-ignore- ]).then((results) => results.map((result) => result.value));-- if (response === null) {- return res- .status(409)- .end("Duplicate key: this short link already exists.");- }-- if (!project && invalidFavicon) {- await log({- message: `*${- session.user.email- }* created a new link (dub.sh/${key}) for ${url} ${- invalidFavicon- ? " but it has an invalid favicon :thinking_face:"- : ""- }`,- type: "links",- mention: true,- });- }-- return res.status(200).json(response);- } else {- res.setHeader("Allow", ["GET", "POST"]);- return res.status(405).end(`Method ${req.method} Not Allowed`);- }- },- {- needNotExceededUsage: true,- excludeGet: true,- },-);diff --git a/apps/web/ui/domains/domain-configuration.tsx b/apps/web/ui/domains/domain-configuration.tsxindex ce28fd64d5..cc3a286c7d 100644--- a/apps/web/ui/domains/domain-configuration.tsx+++ b/apps/web/ui/domains/domain-configuration.tsx@@ -114,9 +114,9 @@ export default function DomainConfiguration({<DnsRecordinstructions={`To configure your ${recordType === "A" ? "apex domain" : "subdomain"- } <code>- ${recordType === "A" ? domainJson.apexName : domainJson.name}- </code>, set the following ${recordType} record on your DNS provider to+ } <code>${+ recordType === "A" ? domainJson.apexName : domainJson.name+ }</code>, set the following ${recordType} record on your DNS provider tocontinue:`}records={[{diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsxindex b564e9ec21..c04e5f47cc 100644--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx@@ -227,14 +227,12 @@ function AddEditLinkModal({if (props?.key) {return {method: "PUT",- url: `/api${slug ? `/projects/${slug}/links` : "/links-app"}/${- props.id- }`,+ url: `/api${slug ? `/projects/${slug}` : ""}/links/${props.id}`,};} else {return {method: "POST",- url: `/api${slug ? `/projects/${slug}/links` : "/links-app"}`,+ url: `/api${slug ? `/projects/${slug}` : ""}/links`,};}}, [props, slug, domain]);@@ -357,9 +355,7 @@ function AddEditLinkModal({(key) =>typeof key === "string" &&key.startsWith(- `/api${- slug ? `/projects/${slug}/links` : "/links-app"- }`,+ `/api${slug ? `/projects/${slug}` : ""}/links`,),),mutate(diff --git a/apps/web/ui/modals/archive-link-modal.tsx b/apps/web/ui/modals/archive-link-modal.tsxindex 4de79abb01..d81920da51 100644--- a/apps/web/ui/modals/archive-link-modal.tsx+++ b/apps/web/ui/modals/archive-link-modal.tsx@@ -74,7 +74,7 @@ function ArchiveLinkModal({e.preventDefault();setArchiving(true);fetch(- `/api${slug ? `/projects/${slug}/links` : "/links-app"}/${+ `/api${slug ? `/projects/${slug}` : ""}/links/${props.id}/archive`,{@@ -90,9 +90,7 @@ function ArchiveLinkModal({(key) =>typeof key === "string" &&key.startsWith(- `/api${- slug ? `/projects/${slug}/links` : "/links-app"- }`,+ `/api${slug ? `/projects/${slug}/links` : "/links"}`,),),mutate(diff --git a/apps/web/ui/modals/delete-link-modal.tsx b/apps/web/ui/modals/delete-link-modal.tsxindex 12cca2fccc..75a3d9c75e 100644--- a/apps/web/ui/modals/delete-link-modal.tsx+++ b/apps/web/ui/modals/delete-link-modal.tsx@@ -68,9 +68,7 @@ function DeleteLinkModal({e.preventDefault();setDeleting(true);fetch(- `/api${slug ? `/projects/${slug}/links` : "/links-app"}/${- props.id- }`,+ `/api${slug ? `/projects/${slug}/links` : "/links"}/${props.id}`,{method: "DELETE",headers: {@@ -84,7 +82,7 @@ function DeleteLinkModal({(key) =>typeof key === "string" &&key.startsWith(- `/api${slug ? `/projects/${slug}/links` : "/links-app"}`,+ `/api${slug ? `/projects/${slug}` : ""}/links`,),),mutate(diff --git a/apps/web/ui/modals/provider.tsx b/apps/web/ui/modals/provider.tsxindex 8be2d5f134..b4aa7c16c5 100644--- a/apps/web/ui/modals/provider.tsx+++ b/apps/web/ui/modals/provider.tsx@@ -65,9 +65,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {// if pollLinks is true, start polling links endpoint every 500 ms (stop after 20 seconds)const pollingInterval = setInterval(() => {mutate(- `/api${- slug ? `/projects/${slug}/links` : "/links-app"- }${getQueryString({+ `/api${slug ? `/projects/${slug}` : ""}/links${getQueryString({searchParams,})}`,);diff --git a/packages/tailwind-config/package.json b/packages/tailwind-config/package.jsonindex 22e2476687..c21f8ba09a 100644--- a/packages/tailwind-config/package.json+++ b/packages/tailwind-config/package.json@@ -1,7 +1,7 @@{"name": "@dub/tailwind-config","description": "Tailwindcss config for Dub.co",- "version": "0.0.0",+ "version": "0.0.2","main": "index.ts","types": "index.ts","devDependencies": {diff --git a/packages/ui/package.json b/packages/ui/package.jsonindex 1b5b836823..89ae60b5c8 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -1,7 +1,7 @@{"name": "@dub/ui","description": "UI components for Dub.co",- "version": "0.0.12",+ "version": "0.0.13","sideEffects": false,"main": "./dist/index.js","module": "./dist/index.mjs",diff --git a/packages/utils/package.json b/packages/utils/package.jsonindex 824b62c5f2..af9ca36024 100644--- a/packages/utils/package.json+++ b/packages/utils/package.json@@ -1,7 +1,7 @@{"name": "@dub/utils","description": "Utility functions and constants for Dub.co",- "version": "0.0.5",+ "version": "0.0.6","sideEffects": false,"main": "./dist/index.js","module": "./dist/index.mjs",