/** * @file Rate Limiter * @version 1.0.0 * @status STABLE - DO NOT MODIFY WITHOUT TESTS * @lastModified 2024-06-07 * * Simple in-memory rate limiter to prevent API abuse * * IMPORTANT: * - Keep memory usage reasonable * - Use sliding window algorithm for accurate rate limiting * * Functionality: * - Request rate limiting * - Different limits for different operations * - Sliding window algorithm */ interface RateLimitOptions { windowMs: number; maxRequests: number; } export declare class RateLimiter { private limits; private buckets; /** * Create a new rate limiter */ constructor(); /** * Set a rate limit for a specific operation * @param operation Operation name * @param options Rate limit options */ setLimit(operation: string, options: RateLimitOptions): void; /** * Check if an operation for a specific identity is rate limited * @param operation Operation name * @param identity Identity string (e.g., IP, user ID) * @returns True if the operation is allowed, false if rate limited */ isAllowed(operation: string, identity: string): boolean; /** * Check if an operation is allowed and record it * @param operation Operation name * @param identity Identity string * @returns True if allowed, false if rate limited */ consume(operation: string, identity: string): boolean; /** * Get remaining requests for an operation and identity * @param operation Operation name * @param identity Identity string * @returns Number of remaining requests in the current window */ getRemainingRequests(operation: string, identity: string): number; /** * Reset rate limit for an operation and identity * @param operation Operation name * @param identity Identity string */ reset(operation: string, identity: string): void; /** * Clean up old entries to prevent memory leaks */ private cleanup; } export declare const rateLimiter: RateLimiter; export {};