Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Beautify API while making sure it's backwards compatible

Steven Tey0877cd5b600f
diff --git a/apps/docs/api-reference/endpoint/bulk-create-links.mdx b/apps/docs/api-reference/endpoint/bulk-create-links.mdx
index 7147c3d0c9..9addf10f93 100644
--- a/apps/docs/api-reference/endpoint/bulk-create-links.mdx
+++ b/apps/docs/api-reference/endpoint/bulk-create-links.mdx
@@ -1,5 +1,5 @@
---
-openapi: post /projects/{slug}/links/bulk
+openapi: post /links/bulk
---
<Note>
@@ -17,7 +17,7 @@ openapi: post /projects/{slug}/links/bulk
<RequestExample>
```bash cURL
curl --request POST \
- --url https://api.dub.co/projects/{slug}/links/bulk \
+ --url https://api.dub.co/links/bulk?projectSlug={YOUR_PROJECT_SLUG} \
--header 'Authorization: Bearer {YOUR_TOKEN}' \
--header 'Content-Type: application/json' \
--data '[
diff --git a/apps/docs/api-reference/endpoint/create-a-new-link.mdx b/apps/docs/api-reference/endpoint/create-a-new-link.mdx
index ecb7957b98..d752d6cbaf 100644
--- a/apps/docs/api-reference/endpoint/create-a-new-link.mdx
+++ b/apps/docs/api-reference/endpoint/create-a-new-link.mdx
@@ -1,3 +1,3 @@
---
-openapi: post /projects/{slug}/links
+openapi: post /links
---
diff --git a/apps/docs/api-reference/endpoint/delete-a-link.mdx b/apps/docs/api-reference/endpoint/delete-a-link.mdx
index 6c7fc3582d..28a49707db 100644
--- a/apps/docs/api-reference/endpoint/delete-a-link.mdx
+++ b/apps/docs/api-reference/endpoint/delete-a-link.mdx
@@ -1,3 +1,3 @@
---
-openapi: delete /projects/{slug}/links/{linkId}
+openapi: delete /links/{linkId}
---
diff --git a/apps/docs/api-reference/endpoint/edit-a-link.mdx b/apps/docs/api-reference/endpoint/edit-a-link.mdx
index 2db00c24e1..3af562c88b 100644
--- a/apps/docs/api-reference/endpoint/edit-a-link.mdx
+++ b/apps/docs/api-reference/endpoint/edit-a-link.mdx
@@ -1,3 +1,3 @@
---
-openapi: put /projects/{slug}/links/{linkId}
+openapi: put /links/{linkId}
---
diff --git a/apps/docs/api-reference/endpoint/retrieve-a-link.mdx b/apps/docs/api-reference/endpoint/retrieve-a-link.mdx
index b60d428dd9..4a41ed4585 100644
--- a/apps/docs/api-reference/endpoint/retrieve-a-link.mdx
+++ b/apps/docs/api-reference/endpoint/retrieve-a-link.mdx
@@ -1,3 +1,3 @@
---
-openapi: get /projects/{slug}/links/info
+openapi: get /links/info
---
diff --git a/apps/docs/api-reference/endpoint/retrieve-a-list-of-links.mdx b/apps/docs/api-reference/endpoint/retrieve-a-list-of-links.mdx
index b55a9c429c..093490f4cf 100644
--- a/apps/docs/api-reference/endpoint/retrieve-a-list-of-links.mdx
+++ b/apps/docs/api-reference/endpoint/retrieve-a-list-of-links.mdx
@@ -1,3 +1,3 @@
---
-openapi: get /projects/{slug}/links
+openapi: get /links
---
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
new file mode 100644
index 0000000000..3ffe01e11a
--- /dev/null
+++ b/apps/docs/openapi.json
@@ -0,0 +1,867 @@
+{
+ "openapi": "3.0.3",
+ "info": {
+ "title": "Dub.co API",
+ "description": "Dub is an open-source link management tool for modern marketing teams to create, share, and track short links.",
+ "contact": {
+ "email": "[email protected]",
+ "name": "Dub.co Support",
+ "url": "https://dub.co/help"
+ },
+ "version": "0.0.1"
+ },
+ "servers": [
+ {
+ "url": "https://api.dub.co",
+ "description": "Production API"
+ }
+ ],
+ "paths": {
+ "/links": {
+ "get": {
+ "description": "Retrieve a list of links for the authenticated project. The list will be paginated and the provided query parameters allow filtering the returned links.",
+ "operationId": "getLinks",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Retrieve a list of links",
+ "parameters": [
+ {
+ "name": "projectSlug",
+ "description": "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "in": "query",
+ "required": true,
+ "schema": {
+ "description": "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "type": "string"
+ }
+ },
+ {
+ "name": "domain",
+ "description": "The domain to filter the links by. E.g. 'ac.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. 'ac.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": "Create a new link for the authenticated project.",
+ "operationId": "createLink",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Create a new link",
+ "parameters": [
+ {
+ "name": "projectSlug",
+ "description": "The slug for the project to create links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "in": "query",
+ "required": true,
+ "schema": {
+ "description": "The slug for the project to create links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "description": "Details of the link to create.",
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/LinkBody",
+ "required": ["domain", "url"]
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "The created link",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Link"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/links/info": {
+ "get": {
+ "description": "Retrieve the info for a link from their domain and key.",
+ "operationId": "getLinkInfo",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Retrieve a link",
+ "parameters": [
+ {
+ "name": "projectSlug",
+ "description": "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "in": "query",
+ "required": true,
+ "schema": {
+ "description": "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "type": "string"
+ }
+ },
+ {
+ "name": "domain",
+ "description": "The domain of the link to retrieve. E.g. for dub.sh/github, the domain is 'dub.sh'.",
+ "in": "query",
+ "required": true,
+ "schema": {
+ "description": "The domain of the link to retrieve. E.g. for dub.sh/github, the domain is 'dub.sh'.",
+ "type": "string"
+ }
+ },
+ {
+ "name": "key",
+ "description": "The key of the link to retrieve. E.g. for dub.sh/github, the key is 'github'.",
+ "in": "query",
+ "required": true,
+ "schema": {
+ "description": "The key of the link to retrieve. E.g. for dub.sh/github, the key is 'github'.",
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "The retrieved link",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Link"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/links/{linkId}": {
+ "put": {
+ "description": "Edit link for the authenticated project.",
+ "operationId": "editLink",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Edit a link",
+ "parameters": [
+ {
+ "name": "projectSlug",
+ "description": "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "in": "query",
+ "required": true,
+ "schema": {
+ "description": "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "type": "string"
+ }
+ },
+ {
+ "name": "linkId",
+ "description": "The id of the link to edit. You can get this via the getLinkInfo endpoint.",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "description": "The id of the link to edit. You can get this via the getLinkInfo endpoint.",
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "description": "Details of the link to edit.",
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/LinkBody"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "The edited link",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Link"
+ }
+ }
+ }
+ }
+ }
+ },
+ "delete": {
+ "description": "Delete a link for the authenticated project.",
+ "operationId": "deleteLink",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Delete a link",
+ "parameters": [
+ {
+ "name": "projectSlug",
+ "description": "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "in": "query",
+ "required": true,
+ "schema": {
+ "description": "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "type": "string"
+ }
+ },
+ {
+ "name": "linkId",
+ "description": "The id of the link to delete. You can get this via the `getLinkInfo` endpoint.",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "description": "The id of the link to delete. You can get this via the `getLinkInfo` endpoint.",
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "The deleted link",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Link"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/links/bulk": {
+ "post": {
+ "description": "Bulk create up to 100 links for the authenticated project.",
+ "operationId": "bulkCreateLinks",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Bulk create links",
+ "parameters": [
+ {
+ "name": "projectSlug",
+ "description": "The slug for the project to create links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "in": "query",
+ "required": true,
+ "schema": {
+ "description": "The slug for the project to create links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "description": "Details of the links to create.",
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/LinkBody"
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "The created links",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/Link"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/projects": {
+ "get": {
+ "description": "Retrieve a list of projects for the authenticated user.",
+ "operationId": "getProjects",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Retrieve a list of projects",
+ "responses": {
+ "200": {
+ "description": "A list of projects",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/Project"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/projects/{slug}": {
+ "get": {
+ "description": "Retrieve a project for the authenticated user.",
+ "operationId": "getProject",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Retrieve a project",
+ "parameters": [
+ {
+ "name": "slug",
+ "description": "The slug for the project to retrieve. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "description": "The slug for the project to retrieve. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "The retrieved project",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ProjectDetails"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/projects/{slug}/tags": {
+ "get": {
+ "description": "Retrieve a list of tags for the authenticated project.",
+ "operationId": "getTags",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Retrieve a list of tags",
+ "parameters": [
+ {
+ "name": "slug",
+ "description": "The slug for the project to retrieve tags for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "description": "The slug for the project to retrieve tags for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "A list of tags",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/Tag"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "post": {
+ "description": "Create a new tag for the authenticated project.",
+ "operationId": "createTag",
+ "security": [
+ {
+ "bearerToken": []
+ }
+ ],
+ "summary": "Create a new tag",
+ "parameters": [
+ {
+ "name": "slug",
+ "description": "The slug for the project to create tags for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "description": "The slug for the project to create tags for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "description": "Details of the tag to create.",
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "tag": {
+ "type": "string",
+ "description": "The name of the tag to create."
+ }
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "The created tag",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Tag"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "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": {
+ "domain": {
+ "type": "string",
+ "description": "The domain of the short link."
+ },
+ "key": {
+ "type": "string",
+ "description": "The short link slug. If not provided, a random 7-character slug will be generated."
+ },
+ "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.",
+ "default": null,
+ "nullable": true
+ },
+ "password": {
+ "type": "string",
+ "description": "The password required to access the destination URL 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": {
+ "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.",
+ "default": null,
+ "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.",
+ "default": null,
+ "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.",
+ "default": null,
+ "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.",
+ "default": null,
+ "nullable": true
+ },
+ "android": {
+ "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 in JSON format {[COUNTRY]: \"https://example.com\" }. Learn more: https://dub.sh/geo",
+ "additionalProperties": {
+ "type": "string",
+ "format": "uri"
+ },
+ "default": null,
+ "nullable": true
+ },
+ "publicStats": {
+ "type": "boolean",
+ "description": "Whether the short link's stats are publicly accessible.",
+ "default": false
+ },
+ "tagId": {
+ "type": "string",
+ "format": "cuid",
+ "description": "The unique id of the tag assigned to the short link.",
+ "default": null,
+ "nullable": true
+ },
+ "comments": {
+ "type": "string",
+ "description": "The comments for the short link.",
+ "default": null,
+ "nullable": true
+ }
+ }
+ },
+ "LinkResponse": {
+ "type": "object",
+ "properties": {
+ "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
+ },
+ "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."
+ },
+ "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
+ }
+ }
+ },
+ "Project": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "format": "cuid",
+ "description": "The unique ID of the project."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the project."
+ },
+ "slug": {
+ "type": "string",
+ "description": "The slug of the project."
+ },
+ "logo": {
+ "type": "string",
+ "description": "The logo of the project.",
+ "default": null,
+ "nullable": true
+ },
+ "usage": {
+ "type": "number",
+ "description": "The usage of the project.",
+ "default": 0,
+ "readOnly": true
+ },
+ "usageLimit": {
+ "type": "number",
+ "description": "The usage limit of the project.",
+ "default": 0,
+ "readOnly": true
+ },
+ "plan": {
+ "type": "string",
+ "description": "The plan of the project.",
+ "default": "free",
+ "readOnly": true
+ },
+ "stripeId": {
+ "type": "string",
+ "description": "The Stripe ID of the project.",
+ "default": null,
+ "nullable": true,
+ "readOnly": true
+ },
+ "billingCycleStart": {
+ "type": "number",
+ "description": "The date and time when the billing cycle starts for the project.",
+ "default": null,
+ "nullable": true,
+ "readOnly": true
+ },
+ "createdAt": {
+ "type": "string",
+ "format": "date-time",
+ "description": "The date and time when the project was created.",
+ "readOnly": true
+ }
+ }
+ },
+ "ProjectDetails": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/Project"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "users": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "role": {
+ "type": "string",
+ "description": "The role of the authenticated user in the project."
+ }
+ },
+ "description": "The role of the authenticated user in the project."
+ },
+ "description": "The role of the authenticated user in the project."
+ },
+ "domains": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "slug": {
+ "type": "string",
+ "description": "The domain of the project."
+ }
+ },
+ "description": "The domains of the project."
+ },
+ "description": "The domains of the project."
+ }
+ }
+ }
+ ]
+ },
+ "Tag": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "format": "cuid",
+ "description": "The unique ID of the tag."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the tag."
+ },
+ "color": {
+ "type": "string",
+ "description": "The color of the tag."
+ }
+ }
+ }
+ },
+ "securitySchemes": {
+ "bearerToken": {
+ "type": "http",
+ "description": "Default authentication mechanism",
+ "scheme": "bearer"
+ }
+ }
+ }
+}
diff --git a/apps/web/app/api/projects/[slug]/(old)/links/[linkId]/archive/route.ts b/apps/web/app/api/projects/[slug]/(old)/links/[linkId]/archive/route.ts
new file mode 100644
index 0000000000..45d0a5ddd2
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/(old)/links/[linkId]/archive/route.ts
@@ -0,0 +1 @@
+export * from "../../../../../../links/[linkId]/archive/route";
diff --git a/apps/web/app/api/projects/[slug]/(old)/links/[linkId]/route.ts b/apps/web/app/api/projects/[slug]/(old)/links/[linkId]/route.ts
new file mode 100644
index 0000000000..646ac7362c
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/(old)/links/[linkId]/route.ts
@@ -0,0 +1 @@
+export * from "../../../../../links/[linkId]/route";
diff --git a/apps/web/app/api/projects/[slug]/(old)/links/bulk/route.ts b/apps/web/app/api/projects/[slug]/(old)/links/bulk/route.ts
new file mode 100644
index 0000000000..ad137e8c19
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/(old)/links/bulk/route.ts
@@ -0,0 +1 @@
+export * from "../../../../../links/bulk/route";
diff --git a/apps/web/app/api/projects/[slug]/(old)/links/count/route.ts b/apps/web/app/api/projects/[slug]/(old)/links/count/route.ts
new file mode 100644
index 0000000000..3c65d1831b
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/(old)/links/count/route.ts
@@ -0,0 +1 @@
+export * from "../../../../../links/count/route";
diff --git a/apps/web/app/api/projects/[slug]/(old)/links/exists/route.ts b/apps/web/app/api/projects/[slug]/(old)/links/exists/route.ts
new file mode 100644
index 0000000000..953c6e5ed6
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/(old)/links/exists/route.ts
@@ -0,0 +1 @@
+export * from "../../../../../links/exists/route";
diff --git a/apps/web/app/api/projects/[slug]/(old)/links/info/route.ts b/apps/web/app/api/projects/[slug]/(old)/links/info/route.ts
new file mode 100644
index 0000000000..ff2607cd00
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/(old)/links/info/route.ts
@@ -0,0 +1 @@
+export * from "../../../../../links/info/route";
diff --git a/apps/web/app/api/projects/[slug]/(old)/links/random/route.ts b/apps/web/app/api/projects/[slug]/(old)/links/random/route.ts
new file mode 100644
index 0000000000..817dd5667e
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/(old)/links/random/route.ts
@@ -0,0 +1 @@
+export * from "../../../../../links/random/route";
diff --git a/apps/web/app/api/projects/[slug]/(old)/links/route.ts b/apps/web/app/api/projects/[slug]/(old)/links/route.ts
new file mode 100644
index 0000000000..029081b277
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/(old)/links/route.ts
@@ -0,0 +1 @@
+export * from "../../../../links/route";
diff --git a/apps/web/app/api/projects/[slug]/links/[linkId]/archive/route.ts b/apps/web/app/api/projects/[slug]/links/[linkId]/archive/route.ts
deleted file mode 100644
index 45f8a09eae..0000000000
--- a/apps/web/app/api/projects/[slug]/links/[linkId]/archive/route.ts
+++ /dev/null
@@ -1 +0,0 @@
-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.ts
deleted file mode 100644
index e8d96006df..0000000000
--- a/apps/web/app/api/projects/[slug]/links/[linkId]/route.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../../../../links/[linkId]/route";
diff --git a/apps/web/app/api/projects/[slug]/links/bulk/route.ts b/apps/web/app/api/projects/[slug]/links/bulk/route.ts
deleted file mode 100644
index 60859cceed..0000000000
--- a/apps/web/app/api/projects/[slug]/links/bulk/route.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../../../../links/bulk/route";
diff --git a/apps/web/app/api/projects/[slug]/links/count/route.ts b/apps/web/app/api/projects/[slug]/links/count/route.ts
deleted file mode 100644
index 9323ac6eed..0000000000
--- a/apps/web/app/api/projects/[slug]/links/count/route.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../../../../links/count/route";
diff --git a/apps/web/app/api/projects/[slug]/links/exists/route.ts b/apps/web/app/api/projects/[slug]/links/exists/route.ts
deleted file mode 100644
index ed3baf39a0..0000000000
--- a/apps/web/app/api/projects/[slug]/links/exists/route.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../../../../links/exists/route";
diff --git a/apps/web/app/api/projects/[slug]/links/info/route.ts b/apps/web/app/api/projects/[slug]/links/info/route.ts
deleted file mode 100644
index f9b4660eb4..0000000000
--- a/apps/web/app/api/projects/[slug]/links/info/route.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../../../../links/info/route";
diff --git a/apps/web/app/api/projects/[slug]/links/random/route.ts b/apps/web/app/api/projects/[slug]/links/random/route.ts
deleted file mode 100644
index 4b8030b4e5..0000000000
--- a/apps/web/app/api/projects/[slug]/links/random/route.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../../../../links/random/route";
diff --git a/apps/web/app/api/projects/[slug]/links/route.ts b/apps/web/app/api/projects/[slug]/links/route.ts
deleted file mode 100644
index a4f0031546..0000000000
--- a/apps/web/app/api/projects/[slug]/links/route.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../../../links/route";
diff --git a/apps/web/app/api/route.ts b/apps/web/app/api/route.ts
index e4a7bd141d..b21624ad91 100644
--- a/apps/web/app/api/route.ts
+++ b/apps/web/app/api/route.ts
@@ -25,73 +25,7 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
},
],
paths: {
- "/projects": {
- get: {
- description:
- "Retrieve a list of projects for the authenticated user.",
- operationId: "getProjects",
- security: [
- {
- bearerToken: [],
- },
- ],
- summary: "Retrieve a list of projects",
- responses: {
- "200": {
- description: "A list of projects",
- content: {
- "application/json": {
- schema: {
- type: "array",
- items: {
- $ref: "#/components/schemas/Project",
- },
- },
- },
- },
- },
- },
- },
- },
- "/projects/{slug}": {
- get: {
- description: "Retrieve a project for the authenticated user.",
- operationId: "getProject",
- security: [
- {
- bearerToken: [],
- },
- ],
- summary: "Retrieve a project",
- parameters: [
- {
- name: "slug",
- description:
- "The slug for the project to retrieve. E.g. for app.dub.co/acme, the slug is 'acme'.",
- in: "path",
- required: true,
- schema: {
- description:
- "The slug for the project to retrieve. E.g. for app.dub.co/acme, the slug is 'acme'.",
- type: "string",
- },
- },
- ],
- responses: {
- "200": {
- description: "The retrieved project",
- content: {
- "application/json": {
- schema: {
- $ref: "#/components/schemas/ProjectDetails",
- },
- },
- },
- },
- },
- },
- },
- "/projects/{slug}/links": {
+ "/links": {
get: {
description:
"Retrieve a list of links for the authenticated project. The list will be paginated and the provided query parameters allow filtering the returned links.",
@@ -104,14 +38,14 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
summary: "Retrieve a list of links",
parameters: [
{
- name: "slug",
+ name: "projectSlug",
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
- in: "path",
+ "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ in: "query",
required: true,
schema: {
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
type: "string",
},
},
@@ -226,14 +160,14 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
summary: "Create a new link",
parameters: [
{
- name: "slug",
+ name: "projectSlug",
description:
- "The slug for the project to create links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
- in: "path",
+ "The slug for the project to create links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ in: "query",
required: true,
schema: {
description:
- "The slug for the project to create links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project to create links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
type: "string",
},
},
@@ -264,7 +198,7 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
},
},
},
- "/projects/{slug}/links/info": {
+ "/links/info": {
get: {
description:
"Retrieve the info for a link from their domain and key.",
@@ -277,14 +211,14 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
summary: "Retrieve a link",
parameters: [
{
- name: "slug",
+ name: "projectSlug",
description:
- "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
- in: "path",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ in: "query",
required: true,
schema: {
description:
- "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
type: "string",
},
},
@@ -327,7 +261,7 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
},
},
},
- "/projects/{slug}/links/{linkId}": {
+ "/links/{linkId}": {
put: {
description: "Edit link for the authenticated project.",
operationId: "editLink",
@@ -339,14 +273,14 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
summary: "Edit a link",
parameters: [
{
- name: "slug",
+ name: "projectSlug",
description:
- "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
- in: "path",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ in: "query",
required: true,
schema: {
description:
- "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
type: "string",
},
},
@@ -398,14 +332,14 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
summary: "Delete a link",
parameters: [
{
- name: "slug",
+ name: "projectSlug",
description:
- "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
- in: "path",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ in: "query",
required: true,
schema: {
description:
- "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
type: "string",
},
},
@@ -436,7 +370,7 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
},
},
},
- "/projects/{slug}/links/bulk": {
+ "/links/bulk": {
post: {
description:
"Bulk create up to 100 links for the authenticated project.",
@@ -449,14 +383,14 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
summary: "Bulk create links",
parameters: [
{
- name: "slug",
+ name: "projectSlug",
description:
- "The slug for the project to create links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
- in: "path",
+ "The slug for the project to create links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ in: "query",
required: true,
schema: {
description:
- "The slug for the project to create links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project to create links for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
type: "string",
},
},
@@ -492,6 +426,72 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
},
},
},
+ "/projects": {
+ get: {
+ description:
+ "Retrieve a list of projects for the authenticated user.",
+ operationId: "getProjects",
+ security: [
+ {
+ bearerToken: [],
+ },
+ ],
+ summary: "Retrieve a list of projects",
+ responses: {
+ "200": {
+ description: "A list of projects",
+ content: {
+ "application/json": {
+ schema: {
+ type: "array",
+ items: {
+ $ref: "#/components/schemas/Project",
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ "/projects/{slug}": {
+ get: {
+ description: "Retrieve a project for the authenticated user.",
+ operationId: "getProject",
+ security: [
+ {
+ bearerToken: [],
+ },
+ ],
+ summary: "Retrieve a project",
+ parameters: [
+ {
+ name: "slug",
+ description:
+ "The slug for the project to retrieve. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ in: "path",
+ required: true,
+ schema: {
+ description:
+ "The slug for the project to retrieve. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
+ type: "string",
+ },
+ },
+ ],
+ responses: {
+ "200": {
+ description: "The retrieved project",
+ content: {
+ "application/json": {
+ schema: {
+ $ref: "#/components/schemas/ProjectDetails",
+ },
+ },
+ },
+ },
+ },
+ },
+ },
"/projects/{slug}/tags": {
get: {
description: "Retrieve a list of tags for the authenticated project.",
@@ -506,12 +506,12 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
{
name: "slug",
description:
- "The slug for the project to retrieve tags for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project to retrieve tags for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
in: "path",
required: true,
schema: {
description:
- "The slug for the project to retrieve tags for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project to retrieve tags for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
type: "string",
},
},
@@ -545,12 +545,12 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
{
name: "slug",
description:
- "The slug for the project to create tags for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project to create tags for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
in: "path",
required: true,
schema: {
description:
- "The slug for the project to create tags for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project to create tags for. E.g. for app.dub.co/acme, the projectSlug is 'acme'.",
type: "string",
},
},
diff --git a/apps/web/emails/upgrade-email.tsx b/apps/web/emails/upgrade-email.tsx
index 1a67f0bc73..23cbb2380f 100644
--- a/apps/web/emails/upgrade-email.tsx
+++ b/apps/web/emails/upgrade-email.tsx
@@ -97,7 +97,7 @@ export default function UpgradeEmail({
◆ Unlimited tags
</Text>
<Text className="ml-1 text-sm leading-4 text-black">
- ◆ API access (coming soon)
+ ◆ API access
</Text>
{plan === "Enterprise" && (
<Text className="ml-1 text-sm leading-4 text-black">
diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.ts
index 4ac065c03a..be9a078950 100644
--- a/apps/web/lib/auth/index.ts
+++ b/apps/web/lib/auth/index.ts
@@ -72,7 +72,8 @@ export const withAuth =
{ params }: { params: Record<string, string> | undefined },
) => {
const searchParams = getSearchParams(req.url);
- const { slug, linkId } = params || {};
+ const { linkId } = params || {};
+ const slug = params?.slug || searchParams.projectSlug;
const domain = params?.domain || searchParams.domain;
let session: Session | undefined;
@@ -98,9 +99,9 @@ export const withAuth =
});
}
- if (!slug && url.pathname.includes("/links/")) {
+ if (!slug && url.pathname.includes("/links")) {
return new Response(
- "API access is only available for projects with custom domains.",
+ "API access is only available for projects with custom domains. Did you forget to include a `projectSlug` query parameter?",
{
status: 403,
},
diff --git a/apps/web/lib/swr/use-links-count.ts b/apps/web/lib/swr/use-links-count.ts
index d445f6697e..c5c844f378 100644
--- a/apps/web/lib/swr/use-links-count.ts
+++ b/apps/web/lib/swr/use-links-count.ts
@@ -1,5 +1,6 @@
-import { fetcher, getQueryString } from "@dub/utils";
-import { useParams, usePathname, useSearchParams } from "next/navigation";
+import { fetcher } from "@dub/utils";
+import { useRouterStuff } from "@dub/ui";
+import { useParams } from "next/navigation";
import useSWR from "swr";
export default function useLinksCount({
@@ -7,20 +8,14 @@ export default function useLinksCount({
}: {
groupBy?: "domain" | "tagId";
} = {}) {
- const pathname = usePathname();
const { slug } = useParams() as { slug?: string };
- const searchParams = useSearchParams();
+ const { getQueryString } = useRouterStuff();
const { data, error } = useSWR<any>(
- `/api${slug ? `/projects/${slug}` : ""}/links/count${
- // only include query params if we're on the project links page
- pathname === `/${slug}` || pathname === "/links"
- ? getQueryString({
- searchParams,
- ...(groupBy && { groupBy }),
- })
- : ""
- }`,
+ `/api/links/count${getQueryString({
+ ...(slug && { projectSlug: slug }),
+ ...(groupBy && { groupBy }),
+ })}`,
fetcher,
{
dedupingInterval: 30000,
diff --git a/apps/web/lib/swr/use-links.ts b/apps/web/lib/swr/use-links.ts
index 79009f4c4e..e3f12a98c8 100644
--- a/apps/web/lib/swr/use-links.ts
+++ b/apps/web/lib/swr/use-links.ts
@@ -1,21 +1,20 @@
-import { fetcher, getQueryString } from "@dub/utils";
+import { fetcher } from "@dub/utils";
+import { useRouterStuff } from "@dub/ui";
import { type Link as LinkProps } from "@prisma/client";
import useSWR from "swr";
import { UserProps } from "../types";
-import { useParams, useSearchParams } from "next/navigation";
+import { useParams } from "next/navigation";
export default function useLinks() {
const { slug } = useParams() as { slug?: string };
- const searchParams = useSearchParams();
+ const { getQueryString } = useRouterStuff();
const { data: links, isValidating } = useSWR<
(LinkProps & {
user: UserProps;
})[]
>(
- `/api${slug ? `/projects/${slug}` : ""}/links${getQueryString({
- searchParams,
- })}`,
+ `/api/links${getQueryString(slug ? { projectSlug: slug } : undefined)}`,
fetcher,
{
dedupingInterval: 20000,
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index 422140b311..996820ab76 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -19,7 +19,6 @@ import {
cn,
deepEqual,
getApexDomain,
- getQueryString,
getUrlWithoutUTMParams,
isValidUrl,
linkConstructor,
@@ -116,9 +115,9 @@ function AddEditLinkModal({
!keyError
) {
fetch(
- `/api${
- slug ? `/projects/${slug}` : ""
- }/links/exists?domain=${domain}&key=${debouncedKey}`,
+ `/api/links/exists?domain=${domain}&key=${debouncedKey}${
+ slug ? `&projectSlug=${slug}` : ""
+ }`,
).then(async (res) => {
if (res.status === 200) {
const exists = await res.json();
@@ -132,7 +131,7 @@ function AddEditLinkModal({
setKeyError(null);
setGeneratingKey(true);
const res = await fetch(
- `/api${slug ? `/projects/${slug}` : ""}/links/random?domain=${domain}`,
+ `/api/links/random?domain=${domain}${slug ? `&projectSlug=${slug}` : ""}`,
);
const key = await res.json();
setData((prev) => ({ ...prev, key }));
@@ -227,12 +226,12 @@ function AddEditLinkModal({
if (props?.key) {
return {
method: "PUT",
- url: `/api${slug ? `/projects/${slug}` : ""}/links/${props.id}`,
+ url: `/api/links/${props.id}${slug ? `?projectSlug=${slug}` : ""}`,
};
} else {
return {
method: "POST",
- url: `/api${slug ? `/projects/${slug}` : ""}/links`,
+ url: `/api/links${slug ? `?projectSlug=${slug}` : ""}`,
};
}
}, [props, slug, domain]);
@@ -352,24 +351,12 @@ function AddEditLinkModal({
va.track("Created Link", {
type: slug ? "Custom Domain" : "Default Domain",
});
- await Promise.all([
- mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith(
- `/api${slug ? `/projects/${slug}` : ""}/links`,
- ),
- ),
- mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith(
- `/api${slug ? `/projects/${slug}` : ""}/links/count`,
- ),
- undefined,
- { revalidate: true },
- ),
- ]);
+ await mutate(
+ (key) =>
+ typeof key === "string" && key.startsWith("/api/links"),
+ undefined,
+ { revalidate: true },
+ );
// for welcome page, redirect to links page after adding a link
if (pathname === "/welcome") {
await router.push("/links");
diff --git a/apps/web/ui/modals/archive-link-modal.tsx b/apps/web/ui/modals/archive-link-modal.tsx
index d81920da51..bd320307ba 100644
--- a/apps/web/ui/modals/archive-link-modal.tsx
+++ b/apps/web/ui/modals/archive-link-modal.tsx
@@ -1,11 +1,6 @@
import { BlurImage } from "@/ui/shared/blur-image";
import { Button, Modal } from "@dub/ui";
-import {
- GOOGLE_FAVICON_URL,
- getApexDomain,
- getQueryString,
- linkConstructor,
-} from "@dub/utils";
+import { GOOGLE_FAVICON_URL, getApexDomain, linkConstructor } from "@dub/utils";
import { type Link as LinkProps } from "@prisma/client";
import { useParams, useSearchParams } from "next/navigation";
import {
@@ -31,7 +26,6 @@ function ArchiveLinkModal({
}) {
const params = useParams() as { slug?: string };
const { slug } = params;
- const searchParams = useSearchParams();
const [archiving, setArchiving] = useState(false);
const apexDomain = getApexDomain(props.url);
@@ -74,9 +68,9 @@ function ArchiveLinkModal({
e.preventDefault();
setArchiving(true);
fetch(
- `/api${slug ? `/projects/${slug}` : ""}/links/${
- props.id
- }/archive`,
+ `/api/links/${props.id}/archive${
+ slug ? `?projectSlug=${slug}` : ""
+ }`,
{
method: archived ? "POST" : "DELETE",
headers: {
@@ -85,24 +79,12 @@ function ArchiveLinkModal({
},
).then(async (res) => {
if (res.status === 200) {
- await Promise.all([
- mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith(
- `/api${slug ? `/projects/${slug}/links` : "/links"}`,
- ),
- ),
- mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith(
- `/api${slug ? `/projects/${slug}` : ""}/links/count`,
- ),
- undefined,
- { revalidate: true },
- ),
- ]);
+ await mutate(
+ (key) =>
+ typeof key === "string" && key.startsWith("/api/links"),
+ undefined,
+ { revalidate: true },
+ );
setShowArchiveLinkModal(false);
toast.success(
`Successfully ${archived ? "archived" : "unarchived"} link!`,
diff --git a/apps/web/ui/modals/delete-link-modal.tsx b/apps/web/ui/modals/delete-link-modal.tsx
index 75a3d9c75e..707c7cbb0b 100644
--- a/apps/web/ui/modals/delete-link-modal.tsx
+++ b/apps/web/ui/modals/delete-link-modal.tsx
@@ -1,11 +1,6 @@
import { BlurImage } from "@/ui/shared/blur-image";
import { Button, Modal } from "@dub/ui";
-import {
- GOOGLE_FAVICON_URL,
- getApexDomain,
- getQueryString,
- linkConstructor,
-} from "@dub/utils";
+import { GOOGLE_FAVICON_URL, getApexDomain, linkConstructor } from "@dub/utils";
import { type Link as LinkProps } from "@prisma/client";
import { useParams, useSearchParams } from "next/navigation";
import {
@@ -67,34 +62,19 @@ function DeleteLinkModal({
onSubmit={async (e) => {
e.preventDefault();
setDeleting(true);
- fetch(
- `/api${slug ? `/projects/${slug}/links` : "/links"}/${props.id}`,
- {
- method: "DELETE",
- headers: {
- "Content-Type": "application/json",
- },
+ fetch(`/api/links/${props.id}${slug ? `?projectSlug=${slug}` : ""}`, {
+ method: "DELETE",
+ headers: {
+ "Content-Type": "application/json",
},
- ).then(async (res) => {
+ }).then(async (res) => {
if (res.status === 200) {
- await Promise.all([
- mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith(
- `/api${slug ? `/projects/${slug}` : ""}/links`,
- ),
- ),
- mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith(
- `/api${slug ? `/projects/${slug}` : ""}/links/count`,
- ),
- undefined,
- { revalidate: true },
- ),
- ]);
+ await mutate(
+ (key) =>
+ typeof key === "string" && key.startsWith("/api/links"),
+ undefined,
+ { revalidate: true },
+ );
setShowDeleteLinkModal(false);
toast.success("Successfully deleted shortlink!");
} else {
diff --git a/apps/web/ui/modals/provider.tsx b/apps/web/ui/modals/provider.tsx
index b4aa7c16c5..294712a123 100644
--- a/apps/web/ui/modals/provider.tsx
+++ b/apps/web/ui/modals/provider.tsx
@@ -9,8 +9,7 @@ import { useImportBitlyModal } from "@/ui/modals/import-bitly-modal";
import { useImportShortModal } from "@/ui/modals/import-short-modal";
import { useUpgradePlanModal } from "@/ui/modals/upgrade-plan-modal";
import { useAcceptInviteModal } from "@/ui/modals/accept-invite-modal";
-import { getQueryString } from "@dub/utils";
-import { useParams, useSearchParams } from "next/navigation";
+import { useParams } from "next/navigation";
import {
Dispatch,
ReactNode,
@@ -56,7 +55,6 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
const params = useParams() as { slug?: string };
const { slug } = params;
- const searchParams = useSearchParams();
// special link polling setup to poll links as they're being created (for bitly import)
const [pollLinks, setPollLinks] = useState(false);
@@ -65,20 +63,11 @@ 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${getQueryString({
- searchParams,
- })}`,
- );
- mutate(`/api/projects/${slug}/tags`);
- mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith(
- `/api${slug ? `/projects/${slug}` : ""}/links/count`,
- ),
+ (key) => typeof key === "string" && key.startsWith("/api/links"),
undefined,
{ revalidate: true },
);
+ mutate(`/api/projects/${slug}/tags`);
}, 500);
setTimeout(() => {
setPollLinks(false);
diff --git a/apps/web/ui/projects/project-card.tsx b/apps/web/ui/projects/project-card.tsx
index 79cac92d71..1bb5f9f14b 100644
--- a/apps/web/ui/projects/project-card.tsx
+++ b/apps/web/ui/projects/project-card.tsx
@@ -21,7 +21,7 @@ export default function ProjectCard({
primaryDomain,
}: ProjectWithDomainProps) {
const { data: count } = useSWR<number>(
- `/api${slug ? `/projects/${slug}` : ""}/links/count`,
+ `/api/links/count?projectSlug=${slug}`,
fetcher,
);
return (
diff --git a/apps/web/ui/stats/link-preview.tsx b/apps/web/ui/stats/link-preview.tsx
index 2346b89cfb..77469af101 100644
--- a/apps/web/ui/stats/link-preview.tsx
+++ b/apps/web/ui/stats/link-preview.tsx
@@ -30,9 +30,9 @@ export default function LinkPreviewTooltip({
}
>(
key
- ? `/api${
- slug ? `/projects/${slug}` : ""
- }/links/info?domain=${domain}&key=${key}`
+ ? `/api/links/info?domain=${domain}&key=${key}${
+ slug ? `&projectSlug=${slug}` : ""
+ }`
: `/api/projects/${slug}/domains/${domain}`,
fetcher,
{
diff --git a/packages/ui/src/hooks/use-router-stuff.ts b/packages/ui/src/hooks/use-router-stuff.ts
index 77abe783f0..24600b37cc 100644
--- a/packages/ui/src/hooks/use-router-stuff.ts
+++ b/packages/ui/src/hooks/use-router-stuff.ts
@@ -6,6 +6,15 @@ export default function useRouterStuff() {
const searchParams = useSearchParams();
const searchParamsObj = Object.fromEntries(searchParams);
+ const getQueryString = (kv?: Record<string, string>) => {
+ const newParams = new URLSearchParams(searchParams);
+ if (kv) {
+ Object.entries(kv).forEach(([k, v]) => newParams.set(k, v));
+ }
+ const queryString = newParams.toString();
+ return queryString.length > 0 ? `?${queryString}` : "";
+ };
+
const queryParams = ({
set,
del,
@@ -46,5 +55,6 @@ export default function useRouterStuff() {
searchParams,
searchParamsObj,
queryParams,
+ getQueryString,
};
}
diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts
index 0f966cad6b..227fbe5319 100644
--- a/packages/utils/src/index.ts
+++ b/packages/utils/src/index.ts
@@ -3,7 +3,6 @@ import { clsx, type ClassValue } from "clsx";
import ms from "ms";
import { customAlphabet } from "nanoid";
import { Metadata } from "next";
-import { ReadonlyURLSearchParams } from "next/navigation";
import { twMerge } from "tailwind-merge";
import {
HOME_DOMAIN,
@@ -352,21 +351,6 @@ export const getSearchParams = (url: string) => {
return params;
};
-export const getQueryString = ({
- searchParams,
- groupBy,
-}: {
- searchParams: URLSearchParams | ReadonlyURLSearchParams | null;
- groupBy?: "domain" | "tagId";
-}) => {
- const newSearchParams = new URLSearchParams(searchParams?.toString());
- if (groupBy) {
- newSearchParams.set("groupBy", groupBy);
- }
- const queryString = newSearchParams.toString();
- return queryString.length > 0 ? `?${queryString}` : "";
-};
-
export const truncate = (str: string | null, length: number) => {
if (!str || str.length <= length) return str;
return `${str.slice(0, length - 3)}...`;