/** * Rate Limiter - SMI-730, SMI-1013, SMI-1189 * * Token bucket algorithm for rate limiting API endpoints and adapters. * Prevents abuse and DoS attacks with configurable limits and windows. * * Features: * - Token bucket algorithm for smooth rate limiting * - Per-IP and per-user limits * - Configurable limits and windows * - In-memory storage (Redis-compatible interface) * - Graceful degradation on errors * - Request queue for waiting when rate limited (SMI-1013) * - Configurable timeout for queued requests (SMI-1013) */ import type { RateLimitConfig, RateLimitMetrics, RateLimitResult, RateLimitStorage, TokenBucket } from './types.js'; /** * Rate Limiter using Token Bucket Algorithm * * @example * ```typescript * const limiter = new RateLimiter({ * maxTokens: 100, * refillRate: 100 / 60, * windowMs: 60000, * }) * * const result = await limiter.checkLimit('user:123') * if (result.allowed) { * // Process request * } else { * // Return 429 Too Many Requests * } * ``` */ export declare class RateLimiter { private readonly config; private readonly storage; private readonly metricsManager; private readonly queueManager; constructor(config: RateLimitConfig, storage?: RateLimitStorage); /** * Try to consume a token without queuing (internal method) */ private tryConsumeToken; /** * Check if a request is allowed under rate limit */ checkLimit(key: string, cost?: number): Promise; /** * Wait for a token to become available (SMI-1013) */ waitForToken(key: string, cost?: number): Promise; /** * Get queue status for a key (SMI-1013) */ getQueueStatus(key?: string): { totalQueued: number; queues: Map; } | number; /** * Clear queue for a key (SMI-1013) */ clearQueue(key?: string): void; /** * Reset rate limit for a key */ reset(key: string): Promise; /** * Get current state for a key */ getState(key: string): Promise; /** * Get metrics for a specific key or all keys */ getMetrics(key?: string): Map | RateLimitMetrics | undefined; /** * Reset metrics for a specific key or all keys */ resetMetrics(key?: string): void; /** * Dispose of resources */ dispose(): void; } //# sourceMappingURL=RateLimiter.d.ts.map