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
3 changes: 3 additions & 0 deletions apps/api/src/pkg/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export const zEnv = z.object({
}),
RL_10_60s: cloudflareRatelimiter,
RL_30_60s: cloudflareRatelimiter,
RL_50_60s: cloudflareRatelimiter,
RL_200_60s: cloudflareRatelimiter,
RL_600_60s: cloudflareRatelimiter,
RL_1_10s: cloudflareRatelimiter,
RL_500_10s: cloudflareRatelimiter,
RL_200_10s: cloudflareRatelimiter,
});
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/pkg/hono/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function newApp() {
bearerFormat: "root key",
type: "http",
scheme: "bearer",
"x-speakeasy-example": "UNKEY_ROOT_KEY",
});
return app;
}
Expand Down
8 changes: 7 additions & 1 deletion apps/api/src/pkg/ratelimit/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ export class AgentRatelimiter implements RateLimiter {
success: res.success,
source: "cloudflare",
});
return Ok({ pass: res.success, reset: -1, current: -1, remaining: -1, triggered: null });
return Ok({
pass: res.success,
reset: -1,
current: -1,
remaining: -1,
triggered: res.success ? null : req.name,
});
}
}
} catch (err) {
Expand Down
86 changes: 86 additions & 0 deletions apps/api/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,35 @@ type = "ratelimit"
namespace_id = "99003060"
simple = { limit = 30, period = 60}

[[unsafe.bindings]]
name = "RL_50_60s"
type = "ratelimit"
namespace_id = "99005060"
simple = { limit = 50, period = 60}


[[unsafe.bindings]]
name = "RL_200_60s"
type = "ratelimit"
namespace_id = "990020060"
simple = { limit = 200, period = 60}


[[unsafe.bindings]]
name = "RL_600_60s"
type = "ratelimit"
namespace_id = "990060060"
simple = { limit = 600, period = 60}



[[unsafe.bindings]]
name = "RL_1_10s"
type = "ratelimit"
namespace_id = "9900110"
simple = { limit = 1, period = 10}

Comment on lines +79 to +84
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix namespace_id format inconsistency

The namespace_id for RL_1_10s doesn't follow the established 9-digit format used by other rate limiters. It should be 99000110 (9 digits) instead of 9900110 (7 digits) to maintain consistency with the pattern 9900{limit}{duration}.

Apply this fix:

  [[unsafe.bindings]]
  name = "RL_1_10s"
  type = "ratelimit"
- namespace_id = "9900110"
+ namespace_id = "99000110"
  simple = { limit = 1, period = 10}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[[unsafe.bindings]]
name = "RL_1_10s"
type = "ratelimit"
namespace_id = "9900110"
simple = { limit = 1, period = 10}
[[unsafe.bindings]]
name = "RL_1_10s"
type = "ratelimit"
namespace_id = "99000110"
simple = { limit = 1, period = 10}


[[unsafe.bindings]]
name = "RL_500_10s"
type = "ratelimit"
Expand Down Expand Up @@ -119,12 +142,33 @@ type = "ratelimit"
namespace_id = "99003060"
simple = { limit = 30, period = 60}

[[env.preview.unsafe.bindings]]
name = "RL_50_60s"
type = "ratelimit"
namespace_id = "99005060"
simple = { limit = 50, period = 60}


[[env.preview.unsafe.bindings]]
name = "RL_200_60s"
type = "ratelimit"
namespace_id = "990020060"
simple = { limit = 200, period = 60}

[[env.preview.unsafe.bindings]]
name = "RL_600_60s"
type = "ratelimit"
namespace_id = "990060060"
simple = { limit = 600, period = 60}


[[env.canary.unsafe.bindings]]
name = "RL_1_10s"
type = "ratelimit"
namespace_id = "9900110"
simple = { limit = 1, period = 10}

Comment on lines +165 to +170
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Move misplaced binding to correct environment section

The RL_1_10s binding is incorrectly placed under env.canary.unsafe.bindings within the preview environment section. It should be under env.preview.unsafe.bindings.

Move this binding to the preview environment section, just before the existing RL_500_10s binding.


[[env.preview.unsafe.bindings]]
name = "RL_500_10s"
type = "ratelimit"
Expand Down Expand Up @@ -178,12 +222,33 @@ type = "ratelimit"
namespace_id = "99003060"
simple = { limit = 30, period = 60}

[[env.canary.unsafe.bindings]]
name = "RL_50_60s"
type = "ratelimit"
namespace_id = "99005060"
simple = { limit = 50, period = 60}


[[env.canary.unsafe.bindings]]
name = "RL_200_60s"
type = "ratelimit"
namespace_id = "990020060"
simple = { limit = 200, period = 60}

[[env.canary.unsafe.bindings]]
name = "RL_600_60s"
type = "ratelimit"
namespace_id = "990060060"
simple = { limit = 600, period = 60}


[[env.canary.unsafe.bindings]]
name = "RL_1_10s"
type = "ratelimit"
namespace_id = "9900110"
simple = { limit = 1, period = 10}


[[env.canary.unsafe.bindings]]
name = "RL_500_10s"
type = "ratelimit"
Expand Down Expand Up @@ -240,12 +305,33 @@ type = "ratelimit"
namespace_id = "99003060"
simple = { limit = 30, period = 60}


[[env.production.unsafe.bindings]]
name = "RL_50_60s"
type = "ratelimit"
namespace_id = "99005060"
simple = { limit = 50, period = 60}

[[env.production.unsafe.bindings]]
name = "RL_200_60s"
type = "ratelimit"
namespace_id = "990020060"
simple = { limit = 200, period = 60}

[[env.production.unsafe.bindings]]
name = "RL_600_60s"
type = "ratelimit"
namespace_id = "990060060"
simple = { limit = 600, period = 60}


[[env.production.unsafe.bindings]]
name = "RL_1_10s"
type = "ratelimit"
namespace_id = "9900110"
simple = { limit = 1, period = 10}


[[env.production.unsafe.bindings]]
name = "RL_500_10s"
type = "ratelimit"
Expand Down
29 changes: 24 additions & 5 deletions packages/api/src/openapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,14 @@ export interface components {
/**
* @description Unkey allows you to refill remaining verifications on a key on a regular interval.
* @example {
* "interval": "daily",
* "amount": 10
* "interval": "monthly",
* "amount": 10,
* "refillDay": 10
* }
*/
refill?: {
/**
* @description Determines the rate at which verifications will be refilled.
* @description Determines the rate at which verifications will be refilled. When 'daily' is set for 'interval' 'refillDay' will be set to null.
* @example daily
* @enum {string}
*/
Expand All @@ -374,6 +375,12 @@ export interface components {
* @example 100
*/
amount: number;
/**
* @description The day verifications will refill each month, when interval is set to 'monthly'. Value is not zero-indexed making 1 the first day of the month. If left blank it will default to the first day of the month. When 'daily' is set for 'interval' 'refillDay' will be set to null.
* @default 1
* @example 15
*/
refillDay?: number | null;
/**
* @description The unix timestamp in miliseconds when the key was last refilled.
* @example 100
Expand Down Expand Up @@ -1057,8 +1064,9 @@ export interface operations {
/**
* @description Unkey enables you to refill verifications for each key at regular intervals.
* @example {
* "interval": "daily",
* "amount": 100
* "interval": "monthly",
* "amount": 100,
* "refillDay": 15
* }
*/
refill?: {
Expand All @@ -1069,6 +1077,11 @@ export interface operations {
interval: "daily" | "monthly";
/** @description The number of verifications to refill for each occurrence is determined individually for each key. */
amount: number;
/**
* @description The day of the month, when we will refill the remaining verifications. To refill on the 15th of each month, set 'refillDay': 15.
* If the day does not exist, for example you specified the 30th and it's february, we will refill them on the last day of the month instead.
*/
refillDay?: number;
};
/**
* @description Unkey comes with per-key fixed-window ratelimiting out of the box.
Expand Down Expand Up @@ -1365,6 +1378,8 @@ export interface operations {
interval: "daily" | "monthly";
/** @description The amount of verifications to refill for each occurrence is determined individually for each key. */
amount: number;
/** @description The day verifications will refill each month, when interval is set to 'monthly' */
refillDay?: number;
} | null;
/**
* @description Set if key is enabled or disabled. If disabled, the key cannot be used to verify.
Expand Down Expand Up @@ -2765,6 +2780,8 @@ export interface operations {
interval: "daily" | "monthly";
/** @description The number of verifications to refill for each occurrence is determined individually for each key. */
amount: number;
/** @description The day verifications will refill each month, when interval is set to 'monthly' */
refillDay?: number;
};
/**
* @description Unkey comes with per-key ratelimiting out of the box.
Expand Down Expand Up @@ -2977,6 +2994,8 @@ export interface operations {
interval: "daily" | "monthly";
/** @description The number of verifications to refill for each occurrence is determined individually for each key. */
amount: number;
/** @description The day verifications will refill each month, when interval is set to 'monthly' */
refillDay?: number;
};
/**
* @description Unkey comes with per-key fixed-window ratelimiting out of the box.
Expand Down