The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update openapi spec
Steven Tey1122555d9c2f
diff --git a/docs/api-reference/endpoint/edit-a-link.mdx b/docs/api-reference/endpoint/edit-a-link.mdxnew file mode 100644index 0000000000..98d7e2e9ec--- /dev/null+++ b/docs/api-reference/endpoint/edit-a-link.mdx@@ -0,0 +1,3 @@+---+openapi: put /links/{key}+---diff --git a/docs/mint.json b/docs/mint.jsonindex a5b4de6957..5bafe46744 100644--- a/docs/mint.json+++ b/docs/mint.json@@ -57,6 +57,7 @@"pages": ["api-reference/endpoint/create-a-new-link","api-reference/endpoint/retrieve-a-link",+ "api-reference/endpoint/edit-a-link","api-reference/endpoint/delete-a-link","api-reference/endpoint/retrieve-a-list-of-links"]diff --git a/lib/api/links.ts b/lib/api/links.tsindex 530b4bcb42..2a1551791c 100644--- a/lib/api/links.ts+++ b/lib/api/links.ts@@ -271,11 +271,11 @@ export async function addLink(link: LinkProps) {}export async function editLink({- domain: oldDomain,+ domain: oldDomain = "dub.sh",key: oldKey,updatedLink,}: {- domain: string;+ domain?: string;key: string;updatedLink: LinkProps;}) {@@ -308,13 +308,16 @@ export async function editLink({const { utm_source, utm_medium, utm_campaign, utm_term, utm_content } =getParamsFromURL(url);+ // exclude fields that should not be updated+ const { id: _, clicks, lastClicked, updatedAt, ...rest } = updatedLink;+const [response, ...effects] = await Promise.all([prisma.link.update({where: {id,},data: {- ...updatedLink,+ ...rest,key,title: truncate(title, 120),description: truncate(description, 240),@@ -325,7 +328,6 @@ export async function editLink({utm_term,utm_content,geo: geo || undefined,- updatedAt: new Date(),},}),// only upload image to cloudinary if proxy is true and there's an image@@ -384,10 +386,10 @@ export async function editLink({}export async function deleteLink({- domain,+ domain = "dub.sh",key,}: {- domain: string;+ domain?: string;key: string;}) {return await Promise.all([diff --git a/package.json b/package.jsonindex d9fdeb5ad6..d543828d66 100644--- a/package.json+++ b/package.json@@ -71,7 +71,7 @@"react-colorful": "^5.6.1","react-dom": "^18.2.0","react-dom-confetti": "^0.2.0",- "react-email": "^1.9.4",+ "react-email": "^1.9.5","react-highlight-words": "^0.20.0","react-medium-image-zoom": "^5.1.7","react-parallax-tilt": "^1.7.70",@@ -93,7 +93,7 @@"topojson-client": "^3.1.0","unsplash-js": "^7.0.18","use-debounce": "^8.0.4",- "vaul": "^0.6.0"+ "vaul": "^0.6.8"},"devDependencies": {"@trivago/prettier-plugin-sort-imports": "^4.0.0",diff --git a/pages/api/index.ts b/pages/api/index.tsindex e21cbd788e..3f1fc51484 100644--- a/pages/api/index.ts+++ b/pages/api/index.ts@@ -181,6 +181,7 @@ export default async function handler(): Promise<"application/json": {schema: {$ref: "#/components/schemas/LinkBody",+ required: ["domain", "url"],},},},@@ -320,7 +321,7 @@ export default async function handler(): Promise<},responses: {"200": {- description: "The created link",+ description: "The edited link",content: {"application/json": {schema: {@@ -396,21 +397,36 @@ export default async function handler(): Promise<components: {schemas: {Link: {+ allOf: [+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ format: "cuid",+ description: "The unique ID of the short link.",+ },+ },+ },+ {+ $ref: "#/components/schemas/LinkBody",+ },+ {+ $ref: "#/components/schemas/LinkResponse",+ },+ ],+ },+ LinkBody: {type: "object",properties: {- id: {- type: "string",- format: "cuid",- description: "The unique ID of the short link.",- readOnly: true,- },domain: {type: "string",description: "The domain of the short link.",},key: {type: "string",- description: "The short link slug.",+ description:+ "The short link slug. If not provided, a random 7-character slug will be generated.",},url: {type: "string",@@ -462,36 +478,6 @@ export default async function handler(): Promise<default: null,nullable: true,},- utm_source: {- type: "string",- description: "The UTM source of the short link.",- default: null,- nullable: true,- },- utm_medium: {- type: "string",- description: "The UTM medium of the short link.",- default: null,- nullable: true,- },- utm_campaign: {- type: "string",- description: "The UTM campaign of the short link.",- default: null,- nullable: true,- },- utm_term: {- type: "string",- description: "The UTM term of the short link.",- default: null,- nullable: true,- },- utm_content: {- type: "string",- description: "The UTM content of the short link.",- default: null,- nullable: true,- },rewrite: {type: "boolean",description: "Whether the short link uses link cloaking.",@@ -521,50 +507,12 @@ export default async function handler(): Promise<default: null,nullable: true,},- userId: {- type: "string",- format: "cuid",- description: "The user ID of the creator of the short link.",- },- projectId: {- type: "string",- format: "cuid",- description: "The project ID of the short link.",- },publicStats: {type: "boolean",description:"Whether the short link's stats are publicly accessible.",default: false,},- clicks: {- type: "number",- description: "The number of clicks on the short link.",- default: 0,- readOnly: true,- },- lastClicked: {- type: "string",- format: "date-time",- description:- "The date and time when the short link was last clicked.",- default: null,- nullable: true,- readOnly: true,- },- createdAt: {- type: "string",- format: "date-time",- description: "The date and time when the short link was created.",- readOnly: true,- },- updatedAt: {- type: "string",- format: "date-time",- description:- "The date and time when the short link was last updated.",- readOnly: true,- },tagId: {type: "string",format: "cuid",@@ -581,119 +529,78 @@ export default async function handler(): Promise<},},},- LinkBody: {+ LinkResponse: {type: "object",properties: {- domain: {- type: "string",- description: "The domain of the short link.",- },- url: {- type: "string",- description: "The destination URL of the short link.",- },- key: {- type: "string",- description:- "The short link slug. If not provided, a random 7-character slug will be generated.",- },- archived: {- type: "boolean",- description: "Whether the short link is archived.",- default: false,- },- expiresAt: {+ utm_source: {type: "string",- format: "date-time",- description: "The date and time when the short link will expire.",+ description: "The UTM source of the short link.",default: null,nullable: true,},- password: {+ utm_medium: {type: "string",- description:- "The password required to access the destination URL of the short link.",+ description: "The UTM medium of the short link.",default: null,nullable: true,},- proxy: {- type: "boolean",- description:- "Whether the short link uses Custom Social Media Cards feature.",- default: false,- },- title: {+ utm_campaign: {type: "string",- description:- "The title of the short link generated via api.dub.co/metatags. Will be used for Custom Social Media Cards if `proxy` is true.",+ description: "The UTM campaign of the short link.",default: null,nullable: true,},- description: {+ utm_term: {type: "string",- description:- "The description of the short link generated via api.dub.co/metatags. Will be used for Custom Social Media Cards if `proxy` is true.",+ description: "The UTM term of the short link.",default: null,nullable: true,},- image: {+ utm_content: {type: "string",- description:- "The image of the short link generated via api.dub.co/metatags. Will be used for Custom Social Media Cards if `proxy` is true.",+ description: "The UTM content of the short link.",default: null,nullable: true,},- rewrite: {- type: "boolean",- description: "Whether the short link uses link cloaking.",- default: false,- },- ios: {+ userId: {type: "string",- description:- "The iOS destination URL for the short link for iOS device targeting.",- default: null,- nullable: true,+ format: "cuid",+ description: "The user ID of the creator of the short link.",},- android: {+ projectId: {type: "string",- description:- "The Android destination URL for the short link for Android device targeting.",- default: null,- nullable: true,- },- geo: {- type: "object",- description: "Geo targeting information for the short link.",- additionalProperties: {- type: "string",- format: "uri",- },- default: null,- nullable: true,+ format: "cuid",+ description: "The project ID of the short link.",},- publicStats: {- type: "boolean",- description:- "Whether the short link's stats are publicly accessible.",- default: false,+ clicks: {+ type: "number",+ description: "The number of clicks on the short link.",+ default: 0,+ readOnly: true,},- tagId: {+ lastClicked: {type: "string",- format: "cuid",+ format: "date-time",description:- "The unique id of the tag assigned to the short link.",+ "The date and time when the short link was last clicked.",default: null,nullable: true,+ readOnly: true,},- comments: {+ createdAt: {type: "string",- description: "The comments for the short link.",- default: null,- nullable: true,+ format: "date-time",+ description: "The date and time when the short link was created.",+ readOnly: true,+ },+ updatedAt: {+ type: "string",+ format: "date-time",+ description:+ "The date and time when the short link was last updated.",+ readOnly: true,},},- required: ["domain", "url"],},},securitySchemes: {diff --git a/pages/api/links/[key]/index.ts b/pages/api/links/[key]/index.tsindex 139f2738e9..54b68d695b 100644--- a/pages/api/links/[key]/index.ts+++ b/pages/api/links/[key]/index.ts@@ -28,24 +28,25 @@ export default withLinksAuth(return res.status(304).end("No fields to update.");}- let { key, url, rewrite } = req.body;+ const updatedLink = {+ ...link,+ ...req.body,+ };++ let { key, url, rewrite } = updatedLink;// for default dub.sh links (not part of a project)if (!project) {- if (key) {- 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.");- }+ 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.");}- if (url) {- const domainBlacklisted = await isBlacklistedDomain(url);- if (domainBlacklisted) {- return res.status(422).end("Invalid url.");- }+ const domainBlacklisted = await isBlacklistedDomain(url);+ if (domainBlacklisted) {+ return res.status(422).end("Invalid url.");}if (rewrite) {return res@@ -54,21 +55,16 @@ export default withLinksAuth(}}- if (key) {- key = processKey(key);- if (!key) {- return res.status(422).end("Invalid key.");- }+ key = processKey(key);+ if (!key) {+ return res.status(422).end("Invalid key.");}const [response, invalidFavicon] = await Promise.allSettled([editLink({- domain: domain || "dub.sh",+ domain,key: link!.key, // link is guaranteed to exist because if not we will return 404,- updatedLink: {- ...link,- ...req.body,- },+ updatedLink,}),...(!project && url? [@@ -102,7 +98,7 @@ export default withLinksAuth(// DELETE /api/links/:key – delete a link} else if (req.method === "DELETE") {const response = await deleteLink({- domain: domain || "dub.sh",+ domain,key: link!.key, // link is guaranteed to exist because if not we will return 404});return res.status(200).json(response[0]);diff --git a/yarn.lock b/yarn.lockindex 8889875026..97847ed853 100644--- a/yarn.lock+++ b/yarn.lock@@ -1492,17 +1492,16 @@resolved "https://registry.npmjs.org/@juggle/resize-observer/-/resize-observer-3.4.0.tgz"integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==-"@manypkg/[email protected]":- version "2.1.0"- resolved "https://registry.yarnpkg.com/@manypkg/find-root/-/find-root-2.1.0.tgz#555072fde526f3986e5a02200440f7f7746ed6ce"- integrity sha512-NEYRVlZCJYhRTqQURhv+WBpDcvmsp/M423Wcdvggv8lYJYD4GtqnTMLrQaTjA10fYt/PIc3tSdwV+wxJnWqPfQ==+"@manypkg/[email protected]":+ version "2.2.1"+ resolved "https://registry.yarnpkg.com/@manypkg/find-root/-/find-root-2.2.1.tgz#a7cffffdb06407967daa31f89952ebef108b27cf"+ integrity sha512-34NlypD5mmTY65cFAK7QPgY5Tzt0qXR4ZRXdg97xAlkiLuwXUPBEXy5Hsqzd+7S2acsLxUz6Cs50rlDZQr4xUA==dependencies:- "@manypkg/tools" "^1.0.0"- "@types/node" "^12.7.1"+ "@manypkg/tools" "^1.1.0"find-up "^4.1.0"fs-extra "^8.1.0"-"@manypkg/tools@^1.0.0":+"@manypkg/tools@^1.1.0":version "1.1.0"resolved "https://registry.yarnpkg.com/@manypkg/tools/-/tools-1.1.0.tgz#730b4c0df78be7f0ce232a417f3c26023884a55c"integrity sha512-SkAyKAByB9l93Slyg8AUHGuM2kjvWioUTCckT/03J09jYnfEzMO/wSXmEhnKGYs6qx9De8TH4yJCl0Y9lRgnyQ==@@ -3930,11 +3929,6 @@resolved "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz"integrity sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==-"@types/node@^12.7.1":- version "12.20.55"- resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"- integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==-"@types/normalize-package-data@^2.4.0":version "2.4.1"resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"@@ -5922,10 +5916,10 @@ framer-motion@^10.12.12:optionalDependencies:"@emotion/is-prop-valid" "^0.8.2"- version "11.1.0"- resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.0.tgz#5784b102104433bb0e090f48bfc4a30742c357ed"- integrity sha512-0rcTq621PD5jM/e0a3EJoGC/1TC5ZBCERW82LQuwfGnCa1V8w7dpYH1yNu+SLb6E5dkeCBzKEyLGlFrnr+dUyw==+ version "11.1.1"+ resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d"+ integrity sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==dependencies:graceful-fs "^4.2.0"jsonfile "^6.0.1"@@ -9495,20 +9489,20 @@ [email protected], react-dom@^18.2.0:loose-envify "^1.1.0"scheduler "^0.23.0"-react-email@^1.9.4:- version "1.9.4"- resolved "https://registry.yarnpkg.com/react-email/-/react-email-1.9.4.tgz#72000e79454ff013563dddc1dff22c8b1207fa29"- integrity sha512-DNUQb7xzAlMga2ZppG57bnWhJnqOEcTYzxNvLA4IVCiYJkgPNVukFMOZVG2OuQ0W8ddiF6bLZBKDZHnnIenbpw==+react-email@^1.9.5:+ version "1.9.5"+ resolved "https://registry.yarnpkg.com/react-email/-/react-email-1.9.5.tgz#3f47a9fae82d59f5be7f81e289ed2b6ab89a9360"+ integrity sha512-c2ubADlAGKAsfmQRDQd0s3/o+wUW/WCVhwiZo+RkUgsP35RhzDBQisFfxHEX8trjNf0eSv4R9g3ASmRF1vAP8A==dependencies:"@commander-js/extra-typings" "9.4.1"- "@manypkg/find-root" "2.1.0"+ "@manypkg/find-root" "2.2.1""@octokit/rest" "19.0.7""@react-email/render" "0.0.6"chokidar "3.5.3"commander "9.4.1"detect-package-manager "2.0.1"esbuild "0.16.4"- fs-extra "11.1.0"+ fs-extra "11.1.1"glob "8.0.3"log-symbols "4.1.0"normalize-path "3.0.0"@@ -11096,10 +11090,10 @@ validate-npm-package-name@^5.0.0:dependencies:builtins "^5.0.0"-vaul@^0.6.0:- version "0.6.0"- resolved "https://registry.yarnpkg.com/vaul/-/vaul-0.6.0.tgz#bba81ee29ffc4c1cd9eb4f6f163b218e6d00c3d1"- integrity sha512-KLGrHya93SWH9xbWRNxXifj645ydCUe0KBiGCOBlIHsFRK6hnOr1qmrNqVG2G+fnxIp4DwDdHWOmcx5gNvHsCA==+vaul@^0.6.8:+ version "0.6.8"+ resolved "https://registry.yarnpkg.com/vaul/-/vaul-0.6.8.tgz#633bb2a0e352adb73f84c497d516c93673d4f01e"+ integrity sha512-Fn7Pe8Zm/jqyIf8Nn/iBMoBzQ3L49xB2vXj7Kp8W7RCMRDg33X5rCp/K80g1Q35VNtKP8AgmFSM7lbticurXKA==dependencies:"@radix-ui/react-dialog" "^1.0.4"