The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
completed openapi spec
Steven Tey085e294738f9
diff --git a/lib/auth.ts b/lib/auth.tsindex c357079698..80333e9d38 100644--- a/lib/auth.ts+++ b/lib/auth.ts@@ -299,6 +299,14 @@ const withLinksAuth =if (!success) {return res.status(429).end("Too many requests.");}+ await prisma.token.update({+ where: {+ hashedKey,+ },+ data: {+ lastUsed: new Date(),+ },+ });session = {user: {id: user.id,diff --git a/package.json b/package.jsonindex fbff9aba4d..f07c408d90 100644--- a/package.json+++ b/package.json@@ -64,6 +64,7 @@"node-html-parser": "^6.1.4","nodemailer": "^6.9.3","npm": "^9.1.2",+ "openapi-types": "^12.1.3","prisma": "^5.2.0","punycode": "^2.3.0","react": "^18.2.0",diff --git a/pages/api/index.ts b/pages/api/index.tsindex 2c6b6b5420..cc8eaa1758 100644--- a/pages/api/index.ts+++ b/pages/api/index.ts@@ -1,8 +1,11 @@import { NextResponse } from "next/server";+import { OpenAPIV3 } from "openapi-types";export const runtime = "edge";-export default async function handler() {+export default async function handler(): Promise<+ NextResponse<OpenAPIV3.Document>+> {return NextResponse.json({openapi: "3.0.3",info: {@@ -26,6 +29,412 @@ export default async function handler() {description: "Staging API",},],- paths: {},+ paths: {+ "/links": {+ get: {+ description:+ "Allows to retrieve the list of links of the authenticated user or project. The list will be paginated and the provided query parameters allow filtering the returned projects.",+ operationId: "getLinks",+ security: [+ {+ bearerToken: [],+ },+ ],+ summary: "Retrieve a list of links",+ parameters: [+ {+ name: "slug",+ description:+ "The slug for the project to retrieve links for. E.g. for app.dub.co/vercel, the slug is 'vercel'.",+ in: "query",+ required: true,+ schema: {+ description:+ "The slug for the project to retrieve links for. E.g. for app.dub.co/vercel, the slug is 'vercel'.",+ type: "string",+ },+ },+ {+ name: "domain",+ description:+ "The domain to filter the links by. E.g. 'vercel.fyi' or 'stey.me'. If not provided, all links for the project will be returned.",+ in: "query",+ required: false,+ schema: {+ description:+ "The domain to filter the links by. E.g. 'vercel.fyi' or 'stey.me'. If not provided, all links for the project will be returned.",+ type: "string",+ },+ },+ {+ name: "tagId",+ description: "The tag ID to filter the links by.",+ in: "query",+ required: false,+ schema: {+ description: "The tag ID to filter the links by.",+ type: "string",+ },+ },+ {+ name: "search",+ description:+ "The search term to filter the links by. The search term will be matched against the short link slug and the destination url.",+ in: "query",+ required: false,+ schema: {+ description:+ "The search term to filter the links by. The search term will be matched against the short link slug and the destination url.",+ type: "string",+ },+ },+ {+ name: "sort",+ description:+ "The field to sort the links by. The default is 'createdAt', and sort order is always descending.",+ in: "query",+ required: false,+ schema: {+ default: "createdAt",+ description:+ "The field to sort the links by. The default is 'createdAt', and sort order is always descending.",+ type: "string",+ enum: ["createdAt", "clicks", "lastClicked"],+ },+ },+ {+ name: "page",+ description:+ "The page number for pagination (each page contains 100 links).",+ in: "query",+ required: false,+ schema: {+ description:+ "The page number for pagination (each page contains 100 links).",+ type: "number",+ },+ },+ {+ name: "userId",+ description: "The user ID to filter the links by.",+ in: "query",+ required: false,+ schema: {+ description: "The user ID to filter the links by.",+ type: "string",+ },+ },+ {+ name: "showArchived",+ description:+ "Whether to include archived links in the response. Defaults to false if not provided.",+ in: "query",+ required: false,+ schema: {+ description:+ "Whether to include archived links in the response. Defaults to false if not provided.",+ type: "boolean",+ enum: [true, false],+ },+ },+ ],+ responses: {+ "200": {+ description: "A list of links",+ content: {+ "application/json": {+ schema: {+ type: "array",+ items: {+ $ref: "#/components/schemas/Link",+ },+ },+ },+ },+ },+ },+ },+ post: {+ description:+ "Allows to create a new link for the authenticated user or project.",+ operationId: "createLink",+ security: [+ {+ bearerToken: [],+ },+ ],+ summary: "Create a new link",+ parameters: [+ {+ name: "slug",+ description:+ "The slug for the project to retrieve links for. E.g. for app.dub.co/vercel, the slug is 'vercel'.",+ in: "query",+ required: true,+ schema: {+ description:+ "The slug for the project to retrieve links for. E.g. for app.dub.co/vercel, the slug is 'vercel'.",+ type: "string",+ },+ },+ ],+ requestBody: {+ description: "The link to create.",+ required: true,+ content: {+ "application/json": {+ schema: {+ $ref: "#/components/schemas/Link",+ },+ },+ },+ },+ responses: {+ "200": {+ description: "The created link",+ content: {+ "application/json": {+ schema: {+ $ref: "#/components/schemas/Link",+ },+ },+ },+ },+ },+ },+ },+ "/links/{key}": {+ delete: {+ description:+ "Allows to delete a link for the authenticated user or project.",+ operationId: "deleteLink",+ security: [+ {+ bearerToken: [],+ },+ ],+ summary: "Delete a link",+ parameters: [+ {+ name: "slug",+ description:+ "The slug for the project to retrieve links for. E.g. for app.dub.co/vercel, the slug is 'vercel'.",+ in: "query",+ required: true,+ schema: {+ description:+ "The slug for the project to retrieve links for. E.g. for app.dub.co/vercel, the slug is 'vercel'.",+ type: "string",+ },+ },+ {+ name: "key",+ description:+ "The key of the link to delete. E.g. for dub.sh/github, the key is 'github'.",+ in: "path",+ required: true,+ schema: {+ description:+ "The key of the link to delete. E.g. for dub.sh/github, the key is 'github'.",+ type: "string",+ },+ },+ {+ name: "domain",+ description:+ "The domain of the link to delete. E.g. for dub.sh/github, the domain is 'dub.sh'.",+ in: "query",+ required: true,+ schema: {+ description:+ "The domain of the link to delete. E.g. for dub.sh/github, the domain is 'dub.sh'.",+ type: "string",+ },+ },+ ],+ responses: {+ "200": {+ description: "The deleted link",+ content: {+ "application/json": {+ schema: {+ $ref: "#/components/schemas/Link",+ },+ },+ },+ },+ },+ },+ },+ },+ components: {+ schemas: {+ Link: {+ type: "object",+ properties: {+ id: {+ type: "string",+ format: "cuid",+ description: "The unique ID of the short link.",+ },+ domain: {+ type: "string",+ description: "The domain of the short link.",+ },+ key: {+ type: "string",+ description: "The short link slug.",+ },+ url: {+ type: "string",+ description: "The destination URL of the short link.",+ },+ archived: {+ type: "boolean",+ description: "Whether the short link is archived.",+ default: false,+ },+ expiresAt: {+ type: "string",+ format: "date-time",+ description: "The date and time when the short link will expire.",+ nullable: true,+ },+ password: {+ type: "string",+ description:+ "The password required to access the destination URL of the short link.",+ nullable: true,+ },+ proxy: {+ type: "boolean",+ description:+ "Whether the short link uses Custom Social Media Cards feature.",+ default: false,+ },+ title: {+ 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.",+ nullable: true,+ },+ description: {+ 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.",+ nullable: true,+ },+ image: {+ 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.",+ nullable: true,+ },+ utm_source: {+ type: "string",+ description: "The UTM source of the short link.",+ nullable: true,+ },+ utm_medium: {+ type: "string",+ description: "The UTM medium of the short link.",+ nullable: true,+ },+ utm_campaign: {+ type: "string",+ description: "The UTM campaign of the short link.",+ nullable: true,+ },+ utm_term: {+ type: "string",+ description: "The UTM term of the short link.",+ nullable: true,+ },+ utm_content: {+ type: "string",+ description: "The UTM content of the short link.",+ nullable: true,+ },+ rewrite: {+ type: "boolean",+ description: "Whether the short link uses link cloaking.",+ default: false,+ },+ ios: {+ type: "string",+ description:+ "The iOS destination URL for the short link for iOS device targeting.",+ nullable: true,+ },+ android: {+ type: "string",+ description:+ "The Android destination URL for the short link for Android device targeting.",+ nullable: true,+ },+ geo: {+ type: "object",+ description: "Geo targeting information for the short link.",+ additionalProperties: {+ type: "string",+ format: "uri",+ },+ 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,+ },+ lastClicked: {+ type: "string",+ format: "date-time",+ description:+ "The date and time when the short link was last clicked.",+ nullable: true,+ },+ createdAt: {+ type: "string",+ format: "date-time",+ description: "The date and time when the short link was created.",+ },+ updatedAt: {+ type: "string",+ format: "date-time",+ description:+ "The date and time when the short link was last updated.",+ },+ tagId: {+ type: "string",+ format: "cuid",+ description:+ "The unique id of the tag assigned to the short link.",+ nullable: true,+ },+ comments: {+ type: "string",+ description: "The comments for the short link.",+ nullable: true,+ },+ },+ },+ },+ },});}diff --git a/pages/api/links/[key]/index.ts b/pages/api/links/[key]/index.tsindex 18c692c955..bd3009d933 100644--- a/pages/api/links/[key]/index.ts+++ b/pages/api/links/[key]/index.ts@@ -100,9 +100,7 @@ export default withLinksAuth(// DELETE /api/links/:key – delete a link} else if (req.method === "DELETE") {const response = await deleteLink(domain || "dub.sh", oldKey);- return res.status(200).json({- message: `Link deleted.`,- });+ return res.status(200).json(response[0]);} else {res.setHeader("Allow", ["GET", "PUT", "DELETE"]);return res.status(405).end(`Method ${req.method} Not Allowed`);diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex dd80649638..fbe52d6701 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -22,7 +22,7 @@ export default withLinksAuth(domain?: string;tagId?: string;search?: string;- sort?: "createdAt" | "clicks";+ sort?: "createdAt" | "clicks" | "lastClicked";page?: string;userId?: string;showArchived?: string;diff --git a/yarn.lock b/yarn.lockindex 13a79f0fa1..8889875026 100644--- a/yarn.lock+++ b/yarn.lock@@ -8841,6 +8841,11 @@ open@^8.0.0:is-docker "^2.1.1"is-wsl "^2.2.0"+openapi-types@^12.1.3:+ version "12.1.3"+ resolved "https://registry.yarnpkg.com/openapi-types/-/openapi-types-12.1.3.tgz#471995eb26c4b97b7bd356aacf7b91b73e777dd3"+ integrity sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==+version "5.4.3"resolved "https://registry.yarnpkg.com/openid-client/-/openid-client-5.4.3.tgz#c75d2f6d07a25d383a72c8ff34605a36b7e2cd73"