@unkey/api
Version:
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@unkey/api* API.
116 lines • 6.26 kB
JavaScript
;
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Ratelimit = void 0;
const ratelimitDeleteOverride_js_1 = require("../funcs/ratelimitDeleteOverride.js");
const ratelimitGetOverride_js_1 = require("../funcs/ratelimitGetOverride.js");
const ratelimitLimit_js_1 = require("../funcs/ratelimitLimit.js");
const ratelimitListOverrides_js_1 = require("../funcs/ratelimitListOverrides.js");
const ratelimitMultiLimit_js_1 = require("../funcs/ratelimitMultiLimit.js");
const ratelimitSetOverride_js_1 = require("../funcs/ratelimitSetOverride.js");
const sdks_js_1 = require("../lib/sdks.js");
const fp_js_1 = require("../types/fp.js");
class Ratelimit extends sdks_js_1.ClientSDK {
/**
* Delete ratelimit override
*
* @remarks
* Permanently remove a rate limit override. Affected identifiers immediately revert to the namespace default.
*
* Use this to remove temporary overrides, reset identifiers to standard limits, or clean up outdated rules.
*
* **Important:** Deletion is immediate and permanent. The override cannot be recovered and must be recreated if needed again.
*
* **Permissions:** Requires `ratelimit.*.delete_override` or `ratelimit.<namespace_id>.delete_override`
*/
async deleteOverride(request, options) {
return (0, fp_js_1.unwrapAsync)((0, ratelimitDeleteOverride_js_1.ratelimitDeleteOverride)(this, request, options));
}
/**
* Get ratelimit override
*
* @remarks
* Retrieve the configuration of a specific rate limit override by its identifier.
*
* Use this to inspect override configurations, audit rate limiting policies, or debug rate limiting behavior.
*
* **Important:** The identifier must match exactly as specified when creating the override, including wildcard patterns.
*
* **Permissions:** Requires `ratelimit.*.read_override` or `ratelimit.<namespace_id>.read_override`
*/
async getOverride(request, options) {
return (0, fp_js_1.unwrapAsync)((0, ratelimitGetOverride_js_1.ratelimitGetOverride)(this, request, options));
}
/**
* Apply rate limiting
*
* @remarks
* Check and enforce rate limits for any identifier (user ID, IP address, API client, etc.).
*
* Use this for rate limiting beyond API keys - limit users by ID, IPs by address, or any custom identifier. Supports namespace organization, variable costs, and custom overrides.
*
* **Response Codes**: Rate limit checks return HTTP 200 regardless of whether the limit is exceeded — check the `success` field in the response to determine if the request should be allowed. A 429 may be returned if the workspace exceeds its API rate limit. Other 4xx responses indicate auth, namespace existence/deletion, or validation errors (e.g., 410 Gone for deleted namespaces). 5xx responses indicate server errors.
*
* **Required Permissions**
*
* Your root key must have one of the following permissions:
* - `ratelimit.*.limit` (to check limits in any namespace)
* - `ratelimit.<namespace_id>.limit` (to check limits in a specific namespace)
*/
async limit(request, options) {
return (0, fp_js_1.unwrapAsync)((0, ratelimitLimit_js_1.ratelimitLimit)(this, request, options));
}
/**
* List ratelimit overrides
*
* @remarks
* Retrieve a paginated list of all rate limit overrides in a namespace.
*
* Use this to audit rate limiting policies, build admin dashboards, or manage override configurations.
*
* **Important:** Results are paginated. Use the cursor parameter to retrieve additional pages when more results are available.
*
* **Permissions:** Requires `ratelimit.*.read_override` or `ratelimit.<namespace_id>.read_override`
*/
async listOverrides(request, options) {
return (0, fp_js_1.unwrapAsync)((0, ratelimitListOverrides_js_1.ratelimitListOverrides)(this, request, options));
}
/**
* Apply multiple rate limit checks
*
* @remarks
* Check and enforce multiple rate limits in a single request for any identifiers (user IDs, IP addresses, API clients, etc.).
*
* Use this to efficiently check multiple rate limits at once. Each rate limit check is independent and returns its own result with a top-level `passed` indicator showing if all checks succeeded.
*
* **Response Codes**: Rate limit checks return HTTP 200 regardless of whether limits are exceeded — check the `passed` field to see if all limits passed, or the `success` field in each individual result. A 429 may be returned if the workspace exceeds its API rate limit. Other 4xx responses indicate auth, namespace existence/deletion, or validation errors (e.g., 410 Gone for deleted namespaces). 5xx responses indicate server errors.
*
* **Required Permissions**
*
* Your root key must have one of the following permissions:
* - `ratelimit.*.limit` (to check limits in any namespace)
* - `ratelimit.<namespace_id>.limit` (to check limits in all specific namespaces being checked)
*/
async multiLimit(request, options) {
return (0, fp_js_1.unwrapAsync)((0, ratelimitMultiLimit_js_1.ratelimitMultiLimit)(this, request, options));
}
/**
* Set ratelimit override
*
* @remarks
* Create or update a custom rate limit for specific identifiers, bypassing the namespace default.
*
* Use this to create premium tiers with higher limits, apply stricter limits to specific users, or implement emergency throttling.
*
* **Important:** Overrides take effect immediately and completely replace the default limit for matching identifiers. Use wildcard patterns (e.g., `premium_*`) to match multiple identifiers.
*
* **Permissions:** Requires `ratelimit.*.set_override` or `ratelimit.<namespace_id>.set_override`
*/
async setOverride(request, options) {
return (0, fp_js_1.unwrapAsync)((0, ratelimitSetOverride_js_1.ratelimitSetOverride)(this, request, options));
}
}
exports.Ratelimit = Ratelimit;
//# sourceMappingURL=ratelimit.js.map