-
Notifications
You must be signed in to change notification settings - Fork 610
feat: Add override methods and docs #2728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f9b8870
added overide methods to ratelimit sdk
6b79bed
[autofix.ci] apply automated fixes
autofix-ci[bot] 9782f16
new docs
f8cd989
Merge branch 'eng-1339-custom-override-update-sdk' of https://github.…
11b8dae
Merge branch 'main' of https://github.com/unkeyed/unkey into eng-1339…
09bfa6f
Override sdk docs
862b142
fmt
f1930da
changed to getters fixed docs
2441ddb
Merge branch 'main' of https://github.com/unkeyed/unkey into eng-1339…
116bc92
Merge branch 'main' of https://github.com/unkeyed/unkey into eng-1339…
1dd6d0d
PR change
2c82e56
pr changes
095d993
Merge branch 'main' into eng-1339-custom-override-update-sdk
MichaelUnkey e34d8b4
Update list-overrides.mdx
MichaelUnkey 3d02281
Update set-override.mdx
MichaelUnkey 4ff86e6
Merge branch 'main' of https://github.com/unkeyed/unkey into eng-1339…
65fcd4d
Merge branch 'eng-1339-custom-override-update-sdk' of https://github.…
89a2782
pr changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
apps/docs/libraries/ts/sdk/ratelimits/overrides/delete-override.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| title: "Delete Override" | ||
| description: "Deletes an override" | ||
| --- | ||
|
|
||
| ## Request | ||
| <ParamField body="identifier" type="string" required> | ||
| Identifier of your user, this can be their userId, an email, an ip or anything else. Wildcards ( * ) can be used to match multiple identifiers, More info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules | ||
| </ParamField> | ||
|
|
||
| <Warning> | ||
| Either `namespaceId` or `namespaceName` is required. Not both. | ||
| </Warning> | ||
|
|
||
| <ParamField body="namespaceId" type="string"> | ||
| The id of the namespace. Either namespaceId or namespaceName must be provided | ||
| </ParamField> | ||
|
|
||
| <ParamField body="namespaceName" type="string"> | ||
| Namespaces group different limits together for better analytics. You might have a namespace for your public API and one for internal tRPC routes. Wildcards can also be used, more info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules | ||
| </ParamField> | ||
|
|
||
|
|
||
| ## Response | ||
|
|
||
| No response, but if no error is returned the override has been deleted successfully. | ||
|
|
||
|
|
||
| <RequestExample> | ||
|
|
||
| ```ts | ||
| await unkey.ratelimit.deleteOverride({ | ||
| identifier: "user_123", | ||
| namespaceName: "email.outbound", | ||
| }) | ||
| ``` | ||
| ```ts | ||
| await unkey.ratelimit.deleteOverride({ | ||
| identifier: "user_123", | ||
| namespaceId: "rlns_1234", | ||
| }) | ||
| ``` | ||
|
|
||
| </RequestExample> | ||
|
|
||
|
|
||
79 changes: 79 additions & 0 deletions
79
apps/docs/libraries/ts/sdk/ratelimits/overrides/get-override.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| --- | ||
| title: "Get Override" | ||
| description: "Gets a ratelimit override" | ||
| --- | ||
|
|
||
| ## Request | ||
| <ParamField body="identifier" type="string" required> | ||
| Identifier of your user, this can be their userId, an email, an ip or anything else. Wildcards ( * ) can be used to match multiple identifiers, More info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules | ||
| </ParamField> | ||
|
|
||
| <Warning> | ||
| Either `namespaceId` or `namespaceName` is required. Not both. | ||
| </Warning> | ||
|
|
||
| <ParamField body="namespaceId" type="string"> | ||
| The id of the namespace. Either namespaceId or namespaceName must be provided | ||
| </ParamField> | ||
|
|
||
| <ParamField body="namespaceName" type="string"> | ||
| Namespaces group different limits together for better analytics. You might have a namespace for your public API and one for internal tRPC routes. Wildcards can also be used, more info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules | ||
| </ParamField> | ||
|
|
||
|
|
||
| ## Response | ||
|
|
||
| <ResponseField name="result"> | ||
| <Expandable title="properties" defaultOpen> | ||
|
|
||
| <ParamField body="id" type="string" required> | ||
| Identifier of the override requested | ||
| </ParamField> | ||
|
|
||
| <ParamField body="identifier" type="string" required> | ||
| Identifier of your user, this can be their userId, an email, an ip or anything else. Wildcards ( * ) can be used to match multiple identifiers, More info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules | ||
| </ParamField> | ||
|
|
||
| <ParamField body="limit" type="number" required> | ||
| How many requests may pass in a given window. | ||
| </ParamField> | ||
|
|
||
| <ParamField body="duration" type="number" required> | ||
| The window duration in milliseconds. | ||
| </ParamField> | ||
|
|
||
| <ParamField body="async" type="boolean"> | ||
| Async will return a response immediately, lowering latency at the cost of accuracy. | ||
| </ParamField> | ||
| </Expandable> | ||
| </ResponseField > | ||
|
|
||
|
|
||
| <RequestExample> | ||
| ```ts | ||
| const override = await unkey.ratelimit.getOverride({ | ||
| identifier:"user.example", | ||
| nameSpaceId:"rlns_12345", | ||
| }); | ||
| ``` | ||
| ```ts | ||
| const override = await unkey.ratelimit.getOverride({ | ||
| identifier:"user.example", | ||
| namespaceName: "email.outbound" | ||
| }); | ||
| ``` | ||
| </RequestExample> | ||
|
|
||
| <ResponseExample> | ||
| ```ts | ||
| { | ||
| result: { | ||
| id: "rlor_4567", | ||
| identifier: "user.example", | ||
| limit: 10, | ||
| duration: 60000, | ||
| async: false | ||
| } | ||
| } | ||
| ``` | ||
| </ResponseExample> |
95 changes: 95 additions & 0 deletions
95
apps/docs/libraries/ts/sdk/ratelimits/overrides/list-overrides.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| --- | ||
| title: "List Overrides" | ||
| description: "Lists all overrides" | ||
| --- | ||
|
|
||
| ## Request | ||
|
|
||
| <Warning> | ||
| Either `namespaceId` or `namespaceName` is required. Not both. | ||
| </Warning> | ||
|
|
||
| <ParamField body="namespaceId" type="string"> | ||
| The id of the namespace. Either namespaceId or namespaceName must be provided | ||
| </ParamField> | ||
|
|
||
| <ParamField body="namespaceName" type="string"> | ||
| Namespaces group different limits together for better analytics. You might have a namespace for your public API and one for internal tRPC routes. Wildcards can also be used, more info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules | ||
| </ParamField> | ||
|
|
||
| ## Response | ||
|
|
||
| <ResponseField name="result"> | ||
| <Expandable title="properties" defaultOpen> | ||
|
|
||
| <ResponseField name="overrides" type="Array" required> | ||
|
|
||
| <Expandable> | ||
| <ParamField body="id" type="string" required> | ||
| Identifier of the override requested | ||
| </ParamField> | ||
|
|
||
| <ParamField body="identifier" type="string" required> | ||
| Identifier of your user, this can be their userId, an email, an ip or anything else. Wildcards ( * ) can be used to match multiple identifiers, More info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules | ||
| </ParamField> | ||
|
|
||
| <ParamField body="limit" type="number" required> | ||
| How many requests may pass in a given window. | ||
| </ParamField> | ||
|
|
||
| <ParamField body="duration" type="number" required> | ||
| The window duration in milliseconds. | ||
| </ParamField> | ||
|
|
||
| <ParamField body="async" type="boolean"> | ||
| Async will return a response immediately, lowering latency at the cost of accuracy. | ||
| </ParamField> | ||
|
|
||
| </Expandable> | ||
| </ResponseField> | ||
|
|
||
| <ResponseField name="total" type="number" required> | ||
| The total number of overrides | ||
| </ResponseField> | ||
| <ResponseField name="cursor" type="string"> | ||
| The cursor to use for pagination | ||
| </ResponseField> | ||
| </Expandable> | ||
|
|
||
| </ResponseField> | ||
|
|
||
|
|
||
| <RequestExample> | ||
|
|
||
| ```ts | ||
| const overrides = await unkey.ratelimit.listOverrides({ | ||
| nameSpaceId:"rlns_12345", | ||
| }); | ||
| ``` | ||
| ```ts | ||
| const overrides = await unkey.ratelimit.listOverrides({ | ||
| namespaceName: "email.outbound" | ||
| }); | ||
| ``` | ||
| </RequestExample> | ||
|
|
||
| <ResponseExample> | ||
| ```ts | ||
| { | ||
| result: { | ||
| overrides: [ | ||
| { | ||
| id: 'rlor_1234', | ||
| identifier: 'customer_123', | ||
| limit: 10, | ||
| duration: 50000, | ||
| async: false | ||
| } | ||
| ], | ||
| total: 1, | ||
| cursor: 'rlor_1234' | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </ResponseExample> |
80 changes: 80 additions & 0 deletions
80
apps/docs/libraries/ts/sdk/ratelimits/overrides/set-override.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| --- | ||
| title: "Set Override" | ||
| description: "Sets an override for a ratelimit" | ||
| --- | ||
|
|
||
| ## Request | ||
|
|
||
|
|
||
| <ParamField body="identifier" type="string" required> | ||
| Identifier of your user, this can be their userId, an email, an ip or anything else. Wildcards ( * ) can be used to match multiple identifiers, More info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules | ||
| </ParamField> | ||
|
|
||
| <ParamField body="limit" type="number" required> | ||
| How many requests may pass in a given window. | ||
| </ParamField> | ||
|
|
||
| <ParamField body="duration" type="number" required> | ||
| The window duration in milliseconds. | ||
| </ParamField> | ||
|
|
||
| <Warning> | ||
| Either `namespaceId` or `namespaceName` is required. Not both. | ||
| </Warning> | ||
|
|
||
| <ParamField body="namespaceId" type="string"> | ||
| The id of the namespace. Either namespaceId or namespaceName must be provided | ||
| </ParamField> | ||
|
|
||
| <ParamField body="namespaceName" type="string"> | ||
| Namespaces group different limits together for better analytics. You might have a namespace for your public API and one for internal tRPC routes. Wildcards can also be used, more info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules | ||
| </ParamField> | ||
|
|
||
| <ParamField body="async" type="boolean" default="false"> | ||
| Async will return a response immediately, lowering latency at the cost of accuracy. | ||
| </ParamField> | ||
|
|
||
|
|
||
| ## Response | ||
|
|
||
| <ResponseField name="result"> | ||
| <Expandable title="properties" defaultOpen> | ||
| <ResponseField name="overrideId" type="string" required> | ||
| The id of the override that was set. | ||
| </ResponseField> | ||
| </Expandable> | ||
| </ResponseField> | ||
| <RequestExample> | ||
|
|
||
| ```ts | ||
| const override = await unkey.ratelimit.setOverride({ | ||
| identifier: "user_123", | ||
| limit: 10, | ||
| duration: 60000, | ||
| namespaceId: "rlns_1234", | ||
| async: true | ||
| }) | ||
| ``` | ||
| ```ts | ||
| const override = await unkey.ratelimit.setOverride({ | ||
| identifier: "user_123", | ||
| limit: 10, | ||
| duration: 60000, | ||
| namespaceName: "email.outbound", | ||
| async: true | ||
| }) | ||
| ``` | ||
|
|
||
| </RequestExample> | ||
|
|
||
| <ResponseExample> | ||
| ```ts | ||
| { | ||
| result: { | ||
| overrideId: 'rlor_12345' | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </ResponseExample> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { Unkey } from "@unkey/api"; | ||
| import { version } from "../package.json"; | ||
|
|
||
| export type OverrideConfig = { | ||
| /** | ||
| * @default https://api.unkey.dev | ||
| */ | ||
| baseUrl?: string; | ||
|
|
||
| /** | ||
| * The unkey root key. You can create one at https://unkey.dev/app/settings/root-keys | ||
| * | ||
| * Make sure the root key has permissions to use overrides. | ||
| */ | ||
| rootKey: string; | ||
|
|
||
| /** | ||
| * | ||
| * By default telemetry data is enabled, and sends: | ||
| * runtime (Node.js / Edge) | ||
| * platform (Node.js / Vercel / AWS) | ||
| * SDK version | ||
| */ | ||
| disableTelemetry?: boolean; | ||
| }; | ||
|
|
||
| export class Overrides { | ||
| private readonly unkey: Unkey; | ||
|
|
||
| constructor(config: OverrideConfig) { | ||
| this.unkey = new Unkey({ | ||
| baseUrl: config.baseUrl, | ||
| rootKey: config.rootKey, | ||
| disableTelemetry: config.disableTelemetry, | ||
| wrapperSdkVersion: `@unkey/ratelimit@${version}`, | ||
| }); | ||
| } | ||
|
|
||
| public get getOverride() { | ||
| return this.unkey.ratelimits.getOverride; | ||
| } | ||
| public get setOverride() { | ||
| return this.unkey.ratelimits.setOverride; | ||
| } | ||
| public get deleteOverride() { | ||
| return this.unkey.ratelimits.deleteOverride; | ||
| } | ||
| public get listOverrides() { | ||
| return this.unkey.ratelimits.listOverrides; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.