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.

improve api key

Steven Teye28895115eab
diff --git a/apps/docs/api-reference/introduction.mdx b/apps/docs/api-reference/introduction.mdx
index 622cba003d..a502081470 100644
--- a/apps/docs/api-reference/introduction.mdx
+++ b/apps/docs/api-reference/introduction.mdx
@@ -29,7 +29,7 @@ Authentication to Dub.co's API is performed via the Authorization header with a
Authorization: Bearer <Your-Token>
```
-Learn more about [how to get your API key](/docs/api-reference/tokens).
+Learn more about [how to get your API key](/api-reference/tokens).
## Response Codes
diff --git a/apps/docs/api-reference/rate-limits.mdx b/apps/docs/api-reference/rate-limits.mdx
index de2c8b7c86..60eae6a265 100644
--- a/apps/docs/api-reference/rate-limits.mdx
+++ b/apps/docs/api-reference/rate-limits.mdx
@@ -14,10 +14,19 @@ Dub's API rate limiting is in conformance with the [IETF standard](https://datat
| `X-RateLimit-Reset` | The time at which the current rate limit window resets in UTC epoch seconds. |
| `Retry-After` | The number of seconds to wait before retrying the request again. |
-Dub's API is capped at **600 requests per minute** per user.
+Dub's API is capped at **600 requests per minute** per user on the Free plan, with elevated limits for [Pro plan](https://dub.co/help/article/pro-plan) and above.
This is implemented to ensure a fair usage policy so that excessive use by a single user does not adversely affect the performance and usage of the API by others.
You'll receive a `429 Too Many Requests` response code if the rate limit is exceeded.
## Rate limits by plan
+
+Depending on your Dub.co plan, you can expect the following rate limits:
+
+| Plan | Rate limit |
+| ----------------------------------------------------- | -------------------------------------------------------------------- |
+| Free | 600 requests per minute |
+| [Pro](https://dub.co/help/article/pro-plan) | 3,000 requests per minute |
+| [Business](https://dub.co/help/article/business-plan) | 6,000 requests per minute |
+| [Enterprise](https://dub.co/enterprise) | Custom – [reach out to sales](https://dub.co/enterprise) for details |
diff --git a/apps/docs/api-reference/tokens.mdx b/apps/docs/api-reference/tokens.mdx
index 2668d1c586..cb1df9d589 100644
--- a/apps/docs/api-reference/tokens.mdx
+++ b/apps/docs/api-reference/tokens.mdx
@@ -5,4 +5,10 @@ description: "Learn how to get your Dub.co API key."
icon: key
---
-Dub.co's API is organized around workspaces.
+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.
+
+## Types of API keys
+
+## Machine users
diff --git a/apps/web/lib/api/tokens/scopes.ts b/apps/web/lib/api/tokens/scopes.ts
index fcf4e32af6..f2cf9af343 100644
--- a/apps/web/lib/api/tokens/scopes.ts
+++ b/apps/web/lib/api/tokens/scopes.ts
@@ -179,3 +179,21 @@ export const scopeMapping = {
"tags.write": ["tags.write", "tags.read"],
"domains.write": ["domains.write", "domains.read"],
};
+
+export const scopePresets = [
+ {
+ value: "all_access",
+ label: "All",
+ description: "This API key will have full access to all resources",
+ },
+ {
+ value: "read_only",
+ label: "Read Only",
+ description: "This API key will have read-only access to all resources",
+ },
+ {
+ value: "restricted",
+ label: "Restricted",
+ description: "This API key will have restricted access to some resources",
+ },
+];
diff --git a/apps/web/ui/modals/add-edit-token-modal.tsx b/apps/web/ui/modals/add-edit-token-modal.tsx
index a3511d9537..23b8871a30 100644
--- a/apps/web/ui/modals/add-edit-token-modal.tsx
+++ b/apps/web/ui/modals/add-edit-token-modal.tsx
@@ -1,6 +1,11 @@
-import { Scope, resourcePermissions } from "@/lib/api/tokens/scopes";
+import {
+ Scope,
+ resourcePermissions,
+ scopePresets,
+} from "@/lib/api/tokens/scopes";
import useWorkspace from "@/lib/swr/use-workspace";
import {
+ AnimatedSizeContainer,
BlurImage,
Button,
ButtonProps,
@@ -12,8 +17,6 @@ import {
RadioGroupItem,
} from "@dub/ui";
import { ToggleGroup } from "@dub/ui/src/toggle-group";
-import { SWIPE_REVEAL_ANIMATION_SETTINGS } from "@dub/utils";
-import { motion } from "framer-motion";
import {
Dispatch,
FormEvent,
@@ -205,17 +208,9 @@ function AddEditTokenModal({
<div className="flex flex-col gap-2">
<h2 className="text-sm font-medium text-gray-900">Permissions</h2>
- <span className="text-sm text-gray-500">
- These permissions apply when the API key is used to make requests
- to Dub APIs.
- </span>
<div className="flex">
<ToggleGroup
- options={[
- { value: "all_access", label: "All" },
- { value: "read_only", label: "Read Only" },
- { value: "restricted", label: "Restricted" },
- ]}
+ options={scopePresets}
selected={preset}
selectAction={(value: ScopePreset) => {
setPreset(value);
@@ -232,58 +227,60 @@ function AddEditTokenModal({
</div>
</div>
- {preset === "restricted" && (
- <motion.div
- className="flex flex-col divide-y text-sm"
- {...SWIPE_REVEAL_ANIMATION_SETTINGS}
- >
- {resourcePermissions
- .filter(
- // filter out beta features
- (resource) => !resource.betaFeature || betaTester,
- )
- .map((resource) => (
- <div
- className="flex items-center justify-between py-4"
- key={resource.key}
- >
- <div className="flex items-center gap-1.5 text-gray-500">
- <p>{resource.name}</p>
- <InfoTooltip content={resource.description} />
- </div>
- <div>
- <RadioGroup
- defaultValue={scopes[resource.key] || ""}
- className="flex gap-4"
- onValueChange={(v: Scope) => {
- setData({
- ...data,
- scopes: {
- ...scopes,
- [resource.key]: v,
- },
- });
- }}
- >
- <div className="flex items-center space-x-2">
- <RadioGroupItem value="" />
- <div>None</div>
- </div>
- {resource.permissions.map((permission) => (
- <div
- className="flex items-center space-x-2"
- key={permission.scope}
- >
- <RadioGroupItem value={permission.scope} />
- <div>{permission.permission}</div>
+ <AnimatedSizeContainer height>
+ <div className="p-1 pt-0 text-sm text-gray-500">
+ {scopePresets.find((p) => p.value === preset)?.description}
+ </div>
+ {preset === "restricted" && (
+ <div className="flex flex-col divide-y text-sm">
+ {resourcePermissions
+ .filter(
+ // filter out beta features
+ (resource) => !resource.betaFeature || betaTester,
+ )
+ .map((resource) => (
+ <div
+ className="flex items-center justify-between py-4"
+ key={resource.key}
+ >
+ <div className="flex items-center gap-1.5 text-gray-500">
+ <p>{resource.name}</p>
+ <InfoTooltip content={resource.description} />
+ </div>
+ <div>
+ <RadioGroup
+ defaultValue={scopes[resource.key] || ""}
+ className="flex gap-4"
+ onValueChange={(v: Scope) => {
+ setData({
+ ...data,
+ scopes: {
+ ...scopes,
+ [resource.key]: v,
+ },
+ });
+ }}
+ >
+ <div className="flex items-center space-x-2">
+ <RadioGroupItem value="" />
+ <div>None</div>
</div>
- ))}
- </RadioGroup>
+ {resource.permissions.map((permission) => (
+ <div
+ className="flex items-center space-x-2"
+ key={permission.scope}
+ >
+ <RadioGroupItem value={permission.scope} />
+ <div>{permission.permission}</div>
+ </div>
+ ))}
+ </RadioGroup>
+ </div>
</div>
- </div>
- ))}
- </motion.div>
- )}
+ ))}
+ </div>
+ )}
+ </AnimatedSizeContainer>
<Button
text={token ? "Save changes" : "Create API key"}