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.

update workspace ID implementation and docs

Steven Tey07b7160c845d
diff --git a/apps/docs/api-reference/tokens.mdx b/apps/docs/api-reference/tokens.mdx
index cb1df9d589..84619bec72 100644
--- a/apps/docs/api-reference/tokens.mdx
+++ b/apps/docs/api-reference/tokens.mdx
@@ -7,8 +7,51 @@ icon: key
API keys on Dub.co allow other apps to access your workspace programmatically. This is useful for integrating Dub with other tools and services.
-Each API key is tied to a specific workspace.
+Each API key is tied to a specific workspace – meaning you can use it to access that workspace's resources without having to worry about "leaking" access to other workspaces. You also no longer need to pass your [workspace ID](https://dub.co/help/article/how-to-get-workspace-id) in your API requests.
-## Types of API keys
+<Tip>Dub API keys are prefixed with `dub_` for easy identification.</Tip>
+
+## API key permissions
+
+You can create 3 types of API keys on Dub.co:
+
+1. **All permissions** – This API key will have full access to all resources.
+2. **Read only** – This API key will have read-only access to all resources.
+3. **Restricted** – This API key will have restricted access to some resources:
+ - [Links](/data-model#links)
+ - [Analytics](/api-reference/endpoint/retrieve-analytics)
+ - [Workspaces](/data-model#workspace)
+ - [Domains](/data-model#domains)
+ - [Tags](/data-model#tags)
+ - API Keys
+
+Depending on your use case, you might want to use one of these 3 options to limit the scope of the API key and improve security.
## Machine users
+
+On Dub, you can create API keys that are associated with a "Machine user". This is particularly helpful when you don't want to associate the API key with a particular user in your workspace, to avoid security risks in involving turnover or changes in project ownership.
+
+These machine users will show up on your workspace's **People** tab, but will not contribute to your workspace's user count.
+
+<Frame>
+ <img
+ src="/images/machine-user.png"
+ alt="Machine user on Dub"
+ width="1468"
+ height="249"
+ />
+</Frame>
+
+<Tip>
+ If you delete an API key associated with a machine user, the machine user will
+ be deleted. Vice versa, if you delete a machine user, their corresponding API
+ key will be deleted as well.
+</Tip>
+
+## How to create an API key
+
+You can create an API key by following these steps:
+
+<Steps>
+ <Step title="Create an API key">sad</Step>
+</Steps>
diff --git a/apps/docs/data-model.mdx b/apps/docs/data-model.mdx
index d42afe7b17..08a09e5e7e 100644
--- a/apps/docs/data-model.mdx
+++ b/apps/docs/data-model.mdx
@@ -17,7 +17,7 @@ Within Dub, all data belongs to a [**Workspace**](#workspace). Within a workspac
[Workspaces](https://dub.co/help/article/what-is-a-workspace) is the defacto way of organizing your links and working with your team on Dub. You can think of a Dub workspace like a workspace on Slack or Discord – it's a shared space where you can [invite your team members](https://dub.co/help/article/how-to-invite-teammates) to collaborate on links.
-When interacting with Dub's API, you will also need to specify the [Workspace ID](/api-reference/introduction#workspace-id) to perform any operation. You can find the workspace ID under the **General** settings page of your workspace.
+When interacting with Dub's API, you'll also need to create a [workspace API key](/api-reference/tokens) to authenticate your requests.
<Accordion title="Workspace model">
<WorkspaceResponse />
diff --git a/apps/docs/images/machine-user.png b/apps/docs/images/machine-user.png
new file mode 100644
index 0000000000..994524570c
Binary files /dev/null and b/apps/docs/images/machine-user.png differ
diff --git a/apps/docs/sdks/typescript/overview.mdx b/apps/docs/sdks/typescript/overview.mdx
index 9e11206029..a8f05b00c4 100644
--- a/apps/docs/sdks/typescript/overview.mdx
+++ b/apps/docs/sdks/typescript/overview.mdx
@@ -41,9 +41,11 @@ The SDK constructor accepts an options object with the following properties:
dashboard](https://app.dub.co/settings/tokens).
</ParamField>
-<ParamField body="workspaceId" type="string" required>
- The id of the workspace you want to interact with. [Learn how to get your
- Workspace ID on Dub?](https://dub.co/help/article/how-to-get-workspace-id)
+<ParamField body="workspaceId" type="string">
+ The [unique ID of the
+ workspace](https://dub.co/help/article/how-to-get-workspace-id) you want to
+ interact with. Learn how to get your Workspace ID on Dub. Deprecated in favor
+ of [workspace API keys](/api-reference/tokens).
</ParamField>
<ParamField body="projectSlug" type="string">
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts
index d17733bb55..f5f3ccf966 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts
@@ -155,6 +155,7 @@ export const DELETE = withWorkspace(
}),
]);
+ // delete the user if it's a machine user
if (projectUser.user.isMachine) {
await prisma.user.delete({
where: {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
index bab3621e1d..12f837faac 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
@@ -171,7 +171,7 @@ export default function WorkspaceBillingClient() {
title="Teammates"
unit="users"
tooltip="Number of users added to your workspace."
- usage={users?.length}
+ usage={users?.filter((user) => !user.isMachine).length}
usageLimit={usersLimit}
numberOnly
/>
diff --git a/apps/web/lib/api/tokens/scopes.ts b/apps/web/lib/api/tokens/scopes.ts
index f2cf9af343..a71af2e031 100644
--- a/apps/web/lib/api/tokens/scopes.ts
+++ b/apps/web/lib/api/tokens/scopes.ts
@@ -21,62 +21,56 @@ export type Scope = (typeof availableScopes)[number];
export const resourcePermissions = [
{
- name: "Workspaces",
- key: "workspaces",
- description: "Read, update, and delete workspaces",
+ name: "Links",
+ key: "links",
+ description: "Create, read, update, and delete links",
betaFeature: false,
permissions: [
{
permission: "Read",
- scope: "workspaces.read",
- description: "Read workspaces",
+ scope: "links.read",
+ description: "Read links",
roles: ["owner", "member"],
},
{
permission: "Write",
- scope: "workspaces.write",
- description: "Update and delete workspaces",
- roles: ["owner"],
+ scope: "links.write",
+ description: "Update and delete links",
+ roles: ["owner", "member"],
},
],
},
{
- name: "Links",
- key: "links",
- description: "Create, read, update, and delete links",
+ name: "Analytics",
+ key: "analytics",
+ description: "Read analytics",
betaFeature: false,
permissions: [
{
permission: "Read",
- scope: "links.read",
- description: "Read links",
- roles: ["owner", "member"],
- },
- {
- permission: "Write",
- scope: "links.write",
- description: "Update and delete links",
+ scope: "analytics.read",
+ description: "Read analytics and events",
roles: ["owner", "member"],
},
],
},
{
- name: "Tags",
- key: "tags",
- description: "Create, read, update, and delete tags",
+ name: "Workspaces",
+ key: "workspaces",
+ description: "Read, update, and delete workspaces",
betaFeature: false,
permissions: [
{
permission: "Read",
- scope: "tags.read",
- description: "Read tags",
+ scope: "workspaces.read",
+ description: "Read workspaces",
roles: ["owner", "member"],
},
{
permission: "Write",
- scope: "tags.write",
- description: "Update and delete tags",
- roles: ["owner", "member"],
+ scope: "workspaces.write",
+ description: "Update and delete workspaces",
+ roles: ["owner"],
},
],
},
@@ -101,35 +95,41 @@ export const resourcePermissions = [
],
},
{
- name: "API Keys",
- key: "tokens",
- description: "Create, read, update, and delete API keys",
+ name: "Tags",
+ key: "tags",
+ description: "Create, read, update, and delete tags",
betaFeature: false,
permissions: [
{
permission: "Read",
- scope: "tokens.read",
- description: "Read tokens",
+ scope: "tags.read",
+ description: "Read tags",
roles: ["owner", "member"],
},
{
permission: "Write",
- scope: "tokens.write",
- description: "Update and delete tokens",
+ scope: "tags.write",
+ description: "Update and delete tags",
roles: ["owner", "member"],
},
],
},
{
- name: "Analytics",
- key: "analytics",
- description: "Read analytics",
+ name: "API Keys",
+ key: "tokens",
+ description: "Create, read, update, and delete API keys",
betaFeature: false,
permissions: [
{
permission: "Read",
- scope: "analytics.read",
- description: "Read analytics and events",
+ scope: "tokens.read",
+ description: "Read tokens",
+ roles: ["owner", "member"],
+ },
+ {
+ permission: "Write",
+ scope: "tokens.write",
+ description: "Update and delete tokens",
roles: ["owner", "member"],
},
],
diff --git a/apps/web/lib/openapi/index.ts b/apps/web/lib/openapi/index.ts
index b678347e7a..b51f06c9a5 100644
--- a/apps/web/lib/openapi/index.ts
+++ b/apps/web/lib/openapi/index.ts
@@ -72,7 +72,7 @@ export const document = createDocument({
"x-speakeasy-globals-hidden": true,
name: "workspaceId",
in: "query",
- required: true,
+ deprecated: true,
schema: {
type: "string",
},
diff --git a/apps/web/ui/workspaces/workspace-id.tsx b/apps/web/ui/workspaces/workspace-id.tsx
index 1a1f856806..de0124084f 100644
--- a/apps/web/ui/workspaces/workspace-id.tsx
+++ b/apps/web/ui/workspaces/workspace-id.tsx
@@ -13,7 +13,7 @@ export default function WorkspaceId() {
<div className="flex flex-col space-y-3">
<h2 className="text-xl font-medium">Workspace ID</h2>
<p className="text-sm text-gray-500">
- {`You'll need this ID to interact with the ${process.env.NEXT_PUBLIC_APP_NAME} API.`}
+ Unique ID of your workspace on Dub.
</p>
</div>
{id ? (