import { Request, Response, NextFunction } from 'express'; import { b as RateLimitInfo, c as RateLimitStats, R as RateLimitOptions } from '../../types-96yYCapM.js'; import '../../types-BK5pGTGr.js'; interface RateLimiterInstance { /** Use directly as Express middleware: `app.use(limiter)` */ (req: Request, res: Response, next: NextFunction): void; /** * Stop the background cleanup timer, remove the process `exit` listener, * and destroy all store state. Safe to call multiple times. */ destroy(): void | Promise; /** Clear all tracking and block data for a single key. */ reset(key: string): void | Promise; /** Clear all state — equivalent to restarting the limiter. */ resetAll(): void | Promise; /** * Current rate-limit snapshot for a key. * Returns `null` if the key has never made a request. */ getInfo(key: string): Promise; /** Aggregate runtime stats for this instance. */ getStats(): Promise; } /** * Create a rate-limiter instance that works as Express middleware. * * @example * ```ts * import { createRateLimiter } from 'rate-shield/express' * * const limiter = createRateLimiter({ maxRequests: 100, windowMs: 60_000 }) * app.use(limiter) * ``` */ declare const createRateLimiter: (options?: RateLimitOptions) => RateLimiterInstance; /** Default key generator: real client IP, proxy-aware via X-Forwarded-For. */ declare const extractIp: (req: Request) => string; /** * User-scoped key: `user:` when `req.user` is set by auth middleware, * otherwise falls back to `ip:
`. */ declare const buildUserKey: (req: Request) => string; /** * Fixed-window limiter with progressive blocking. * Alias for `createRateLimiter({ strategy: 'fixed', …options })`. */ declare const createFixedRateLimiter: (options?: Omit, "strategy">) => RateLimiterInstance; /** * @deprecated Renamed to createFixedRateLimiter. Will be removed in v2. */ declare const createProgressiveRateLimiter: (options?: Omit, "strategy">) => RateLimiterInstance; /** * Sliding-window limiter with progressive blocking. * Alias for `createRateLimiter({ strategy: 'sliding', …options })`. */ declare const createSlidingRateLimiter: (options?: Omit, "strategy">) => RateLimiterInstance; /** * Rate limiter keyed by authenticated user ID (`req.user.id` or `req.user._id`), * falling back to the client IP when unauthenticated. * * Requires auth middleware that populates `req.user` before this runs. */ declare const createUserRateLimiter: (options?: RateLimitOptions) => RateLimiterInstance; /** * Sliding-window, user-scoped limiter. */ declare const createSlidingUserRateLimiter: (options?: Omit, "strategy">) => RateLimiterInstance; /** * Limiter whose key is prefixed with the endpoint name, giving each route its * own independent counter even for the same IP or user. * * @example * ```ts * // key = "/api/login:203.0.113.5" * app.post('/api/login', createEndpointRateLimiter('/api/login', { maxRequests: 5 })) * ``` */ declare const createEndpointRateLimiter: (endpoint: string, options?: RateLimitOptions) => RateLimiterInstance; /** * Sliding-window, endpoint-scoped limiter. * * @example * ```ts * app.post('/api/forgot-password', * createSlidingEndpointRateLimiter('/api/forgot-password', { maxRequests: 3 })) * ``` */ declare const createSlidingEndpointRateLimiter: (endpoint: string, options?: Omit, "strategy">) => RateLimiterInstance; export { type RateLimiterInstance, buildUserKey, createEndpointRateLimiter, createFixedRateLimiter, createProgressiveRateLimiter, createRateLimiter, createSlidingEndpointRateLimiter, createSlidingRateLimiter, createSlidingUserRateLimiter, createUserRateLimiter, extractIp };