import type { Plugin } from './app'; import type { Context } from './http'; /** A rate-limit counter store: record a hit, report the count + reset time. */ export interface RateLimitStore { /** * Record a hit for `key` in a `windowMs` window; returns the running count and * milliseconds until the window resets. * * @param key - the bucket key identifying the client * @param windowMs - length of the fixed window, in milliseconds */ hit(key: string, windowMs: number): { count: number; resetMs: number; } | Promise<{ count: number; resetMs: number; }>; } /** * In-memory fixed-window counter, one window per key — the default * {@link rateLimit} store. Counts live in a single process and vanish on * restart, so it only limits per instance; use a shared store (e.g. Redis) * to enforce one limit across several instances. * * @returns a {@link RateLimitStore} backed by an in-process map */ export declare function memoryRateLimitStore(): RateLimitStore; /** Options for {@link rateLimit}. */ export interface RateLimitOptions { /** Max requests permitted per window; the next request in the same window gets `429`. Required. */ limit: number; /** Length of the fixed window, in milliseconds; the count resets once it elapses. Required. */ windowMs: number; /** Bucket key for a request. Default: the `X-Forwarded-For` header, else `"global"`. */ keyBy?: (ctx: Context) => string; /** Counter store. Default: an in-memory fixed window. */ store?: RateLimitStore; } /** * Plugin: limit how many requests a client may make in a time window, replying * `429 Too Many Requests` (with `Retry-After`) once the limit is exceeded. Every * response carries `X-RateLimit-Limit`/`X-RateLimit-Remaining`. Bucket clients * with `keyBy` (default: the `X-Forwarded-For` header); swap the in-memory * counter for a shared `store` (e.g. Redis) in a multi-instance deployment. * * ```ts * const app = await createApp({ * plugins: [rateLimit({ limit: 100, windowMs: 60_000 })], * }) * ``` * * @param options - `limit` and `windowMs` are required; `keyBy` and `store` * default to per-`X-Forwarded-For` bucketing and an in-memory fixed window * @returns a plugin that enforces the limit with `429` and rate-limit headers */ export declare function rateLimit(options: RateLimitOptions): Plugin; //# sourceMappingURL=rate-limit.d.ts.map