import { FastifyRequest, FastifyReply } from 'fastify'; import { b as RateLimitInfo, c as RateLimitStats, R as RateLimitOptions } from '../../types-96yYCapM.js'; import '../../types-BK5pGTGr.js'; /** * A rate-limiter instance that can be registered directly as a Fastify * `onRequest` hook: * * ```ts * const limiter = createRateLimiter({ maxRequests: 100 }) * app.addHook('onRequest', limiter) * // or on a single route: * app.get('/api/data', { onRequest: limiter }, handler) * ``` */ interface FastifyRateLimiterInstance { (request: FastifyRequest, reply: FastifyReply): 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 a Fastify `onRequest` hook. * * @example * ```ts * import Fastify from 'fastify' * import { createRateLimiter } from 'rate-shield/fastify' * * const app = Fastify({ trustProxy: true }) * const limiter = createRateLimiter({ maxRequests: 100, windowMs: 60_000 }) * * app.addHook('onRequest', limiter) * ``` */ declare const createRateLimiter: (options?: RateLimitOptions) => FastifyRateLimiterInstance; /** * Default key generator for Fastify. * Respects `trustProxy` config — when enabled, `request.ip` already * reflects the real client IP from X-Forwarded-For. * Falls back to raw X-Forwarded-For header when trustProxy is off. */ declare const extractIp: (req: FastifyRequest) => string; declare const createFixedRateLimiter: (options?: Omit, "strategy">) => FastifyRateLimiterInstance; declare const createSlidingRateLimiter: (options?: Omit, "strategy">) => FastifyRateLimiterInstance; /** * Limiter whose key is prefixed with the endpoint name for per-route isolation. * * @example * ```ts * app.post('/api/login', { * onRequest: createEndpointRateLimiter('/api/login', { maxRequests: 5 }) * }, loginHandler) * ``` */ declare const createEndpointRateLimiter: (endpoint: string, options?: RateLimitOptions) => FastifyRateLimiterInstance; declare const createSlidingEndpointRateLimiter: (endpoint: string, options?: Omit, "strategy">) => FastifyRateLimiterInstance; export { type FastifyRateLimiterInstance, createEndpointRateLimiter, createFixedRateLimiter, createRateLimiter, createSlidingEndpointRateLimiter, createSlidingRateLimiter, extractIp };