Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@unkey/icons": "workspace:^",
"@unkey/id": "workspace:^",
"@unkey/keys": "workspace:^",
"@unkey/ratelimit": "^2.0.0-canary.0",
"@unkey/ratelimit": "^2.0.0",
"@unkey/rbac": "workspace:^",
"@unkey/resend": "workspace:^",
"@unkey/schema": "workspace:^",
Expand Down
13 changes: 5 additions & 8 deletions apps/docs/libraries/ts/ratelimit/override/get-override.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,22 @@ How many requests may pass in a given window.
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.getOverride({
identifier:"user.example",
identifier:"user.example",
namespaceName: "email.outbound"
});

```
```
```ts
const override = await unkey.getOverride({
identifier:"user.example",
namespaceId: "rlns_1234",
identifier:"user.example",
namespaceId: "rlns_1234",
});
```
</RequestExample>
Expand All @@ -77,4 +74,4 @@ const override = await unkey.getOverride({
}
}
```
</ResponseExample>
</ResponseExample>
13 changes: 5 additions & 8 deletions apps/docs/libraries/ts/ratelimit/override/list-overrides.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ How many requests may pass in a given window.
The window duration in milliseconds.
</ParamField>

<ParamField body="async" type="boolean" optional>
Async will return a response immediately, lowering latency at the cost of accuracy.
</ParamField>

</Expandable>
</ResponseField>
Expand All @@ -61,16 +58,16 @@ The cursor to use for pagination

<RequestExample>
```ts
const overrides = await unkey.listOverrides({
const overrides = await unkey.listOverrides({
namespaceName: "email.outbound"
});
```

```ts
const overrides = await unkey.listOverrides({
nameSpaceId:"rlns_12345",
const overrides = await unkey.listOverrides({
nameSpaceId:"rlns_12345",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix property name casing in example.
The example uses nameSpaceId, but the correct parameter key is namespaceId (lowercase “s”). Please update to match the API.

});
```
```
</RequestExample>


Expand All @@ -93,4 +90,4 @@ const overrides = await unkey.listOverrides({
}
```

</ResponseExample>
</ResponseExample>
2 changes: 0 additions & 2 deletions apps/docs/libraries/ts/ratelimit/override/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ async function handler(request) {
limit: 10,
duration: 60000,
namespaceName: "email.outbound",
async: true
})
if (override.error){
// handle the error here
Expand All @@ -45,4 +44,3 @@ There are four main functions to interact with overrides:
- [getOverride](/libraries/ts/ratelimit/override/get-override) Gets a ratelimit override.
- [deleteOverride](/libraries/ts/ratelimit/override/delete-override) Deletes an override.
- [listOverrides](/libraries/ts/ratelimit/override/list-overrides) Lists all overrides for a namnespace.

17 changes: 7 additions & 10 deletions apps/docs/libraries/ts/ratelimit/override/set-override.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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
Expand All @@ -30,9 +30,6 @@ The id of the namespace. Either namespaceId or namespaceName must be provided
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
Expand All @@ -53,13 +50,13 @@ const override = await unkey.setOverride({
namespaceName: "email.outbound",
async: true
})
```
```

```ts
const override = await unkey.setOverride({
identifier: "user_123",
limit: 5,
duration: 50000,
identifier: "user_123",
limit: 5,
duration: 50000,
namespaceId: "rlns_1234",
async: false
})
Expand All @@ -68,9 +65,9 @@ const override = await unkey.setOverride({

<ResponseExample>
```ts
{
{
result: {
overrideId: 'rlor_12345'
overrideId: 'rlor_12345'
}
}
```
Expand Down
36 changes: 1 addition & 35 deletions apps/docs/libraries/ts/ratelimit/ratelimit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,11 @@ title: "Ratelimit"
description: "Serverless ratelimiting"
---

> ( Globally consistent, fast ) - choose two

`@unkey/ratelimit` is a library for fast global ratelimiting in serverless functions.


**TLDR:**
```ts
const { success } = await unkey.limit("my-user-id")
if (!success){
// reject request
}
// handle request
```


<Card icon="github" title="github.com/unkeyed/sdks/tree/main/ts/ratelimit" href="https://github.com/unkeyed/sdks/tree/main/ts/ratelimit"/>
<Card icon="github" title="github.com/unkeyed/sdks/tree/main/ratelimit/ts" href="https://github.com/unkeyed/sdks/tree/main/ratelimit/ts"/>


## Install
Expand Down Expand Up @@ -58,7 +47,6 @@ const unkey = new Ratelimit({
namespace: "my-app",
limit: 10,
duration: "30s",
async: true
})
```

Expand Down Expand Up @@ -232,28 +220,6 @@ Expensive requests may use up more resources. You can specify a cost to the requ

</ParamField>

<ParamField body="async" type="boolean" default={false}>
Do not wait for a response from the origin. Faster but less accurate.

We observe a 97%+ accuracy when using `async` mode with significantly lower latency.
</ParamField>


<ParamField body="meta" type=" Record<string, string | number | boolean | null>;">
Record arbitrary data about this request. This does not affect the limit itself but can help you debug later.
</ParamField>

<ParamField body="resources" type="Array<{
type: string;
id: string;
name?: string;
meta?: Record<string, string | number | boolean | null>;
}>">
Specify which resources this request would access and we'll create a papertrail for you.

See [app.unkey.com/audit](https://app.unkey.com/audit) for details.
</ParamField>


</Expandable>

Expand Down
Loading
Loading