import { Context, Next } from 'koa'; import { b as RateLimitInfo, c as RateLimitStats, R as RateLimitOptions } from '../../types-96yYCapM.js'; import '../../types-BK5pGTGr.js'; /** * A rate-limiter instance that works as Koa middleware: * * ```ts * const limiter = createRateLimiter({ maxRequests: 100 }) * app.use(limiter) * ``` */ interface KoaRateLimiterInstance { (ctx: Context, next: Next): Promise; destroy(): void | Promise; reset(key: string): void | Promise; resetAll(): void | Promise; getInfo(key: string): Promise; getStats(): Promise; } /** * Create a rate-limiter instance that works as Koa middleware. * * @example * ```ts * import Koa from 'koa' * import { createRateLimiter } from 'rate-shield/koa' * * const app = new Koa({ proxy: true }) * const limiter = createRateLimiter({ maxRequests: 100, windowMs: 60_000 }) * * app.use(limiter) * ``` */ declare const createRateLimiter: (options?: RateLimitOptions) => KoaRateLimiterInstance; /** * Default key generator for Koa. * `ctx.ip` respects X-Forwarded-For when `app.proxy = true` is set. */ declare const extractIp: (ctx: Context) => string; /** * User-scoped key: `user:` when `ctx.state.user` is set by auth middleware, * otherwise falls back to `ip:
`. */ declare const buildUserKey: (ctx: Context) => string; declare const createFixedRateLimiter: (options?: Omit, "strategy">) => KoaRateLimiterInstance; declare const createSlidingRateLimiter: (options?: Omit, "strategy">) => KoaRateLimiterInstance; /** * Rate limiter keyed by `ctx.state.user.id` (or `._id`), * falling back to the client IP when unauthenticated. */ declare const createUserRateLimiter: (options?: RateLimitOptions) => KoaRateLimiterInstance; declare const createSlidingUserRateLimiter: (options?: Omit, "strategy">) => KoaRateLimiterInstance; declare const createEndpointRateLimiter: (endpoint: string, options?: RateLimitOptions) => KoaRateLimiterInstance; declare const createSlidingEndpointRateLimiter: (endpoint: string, options?: Omit, "strategy">) => KoaRateLimiterInstance; export { type KoaRateLimiterInstance, buildUserKey, createEndpointRateLimiter, createFixedRateLimiter, createRateLimiter, createSlidingEndpointRateLimiter, createSlidingRateLimiter, createSlidingUserRateLimiter, createUserRateLimiter, extractIp };