/** * Token bucket rate limiter for API requests * Implements a classic token bucket algorithm with configurable rate and burst capacity */ /** * Configuration options for the rate limiter */ export interface RateLimiterConfig { /** Maximum requests per second (tokens added per second) */ requestsPerSecond: number; /** Maximum burst capacity (bucket size) */ burstCapacity?: number; } /** * Default rate limiter configuration * Conservative default suitable for most API rate limits */ export declare const DEFAULT_RATE_LIMITER_CONFIG: Required; /** * Token bucket rate limiter * * The token bucket algorithm works as follows: * - Tokens are added to the bucket at a fixed rate (requestsPerSecond) * - Each request consumes one token * - If no tokens are available, the request waits until one becomes available * - The bucket has a maximum capacity (burstCapacity) to allow short bursts */ export declare class RateLimiter { private tokens; private lastRefillTime; private readonly requestsPerSecond; private readonly burstCapacity; private pendingQueue; private scheduledTimeout; constructor(config?: RateLimiterConfig); /** * Refill tokens based on elapsed time */ private refillTokens; /** * Calculate wait time until a token is available */ private getWaitTimeMs; /** * Schedule processing of the queue if not already scheduled */ private scheduleProcessing; /** * Process the pending queue */ private processQueue; /** * Acquire a token, waiting if necessary * Returns a promise that resolves when a token is acquired */ acquire(): Promise; /** * Try to acquire a token without waiting * Returns true if a token was acquired, false otherwise */ tryAcquire(): boolean; /** * Get the current number of available tokens */ getAvailableTokens(): number; /** * Get the current queue length */ getQueueLength(): number; /** * Reset the rate limiter to initial state */ reset(): void; } //# sourceMappingURL=rate-limiter.d.ts.map