/** * @omnifolio/rate-governor * * Types for the rate limiter. */ /** Configuration for a rate limit rule */ export interface RateLimitConfig { /** Maximum requests allowed in the time window */ limit: number; /** Time window in milliseconds */ windowMs: number; /** Block duration after exceeding limit (in ms). If omitted, client is not blocked — just throttled until window resets. */ blockDuration?: number; /** Human-readable message returned when rate limited */ message?: string; } /** Result of a rate limit check */ export interface RateLimitResult { /** Whether the request is allowed */ success: boolean; /** Remaining requests in the current window */ remaining: number; /** Seconds until the client can retry (only set when rate limited) */ retryAfter?: number; /** Standard rate-limit headers to attach to the HTTP response */ headers: Record; } /** Internal record stored per identifier */ export interface RateLimitRecord { count: number; resetTime: number; blocked: boolean; blockUntil?: number; } /** Stats about the in-memory rate limit store */ export interface RateLimitStats { totalClients: number; blockedClients: number; } /** * Optional async adapter for distributed (Redis) storage. * * Implement this interface to plug in any Redis client (Upstash, ioredis, etc.) * so rate limits are shared across multiple server instances. */ export interface RedisAdapter { /** Atomically increment a key and set TTL. Returns the new count, or null on failure. */ incrWithExpire(key: string, ttlSeconds: number): Promise; /** Get a JSON value by key */ get(key: string): Promise; /** Set a JSON value with TTL in seconds */ set(key: string, value: T, ttlSeconds: number): Promise; } //# sourceMappingURL=types.d.ts.map