/** * Production-grade rate limiter for Wildberries Seller API. * * Wildberries enforces rate limits *per API category* (each host has its own * budget), not as one global pool. A single shared limiter therefore both * over-throttles cheap categories and under-protects strict ones. Use one * {@link RateLimiter} instance per category via {@link RateLimiterPool}. * * Per-instance rules (token bucket): * - N requests per minute (token bucket, configurable per category) * - Minimum interval between requests (configurable per category) * - HTTP 409 = PENALTY: 5-10 tokens deducted. Must read * X-Ratelimit-Retry-After header and wait that duration. */ export declare class RateLimiter { private tokens; private readonly maxTokens; private readonly refillRate; private lastRefill; private lastRequest; private readonly minInterval; constructor(maxTokensPerMinute?: number, minIntervalMs?: number); private refill; /** * Wait until a request can be made, respecting both token bucket * and minimum interval constraints. */ acquire(): Promise; /** * Handle a 409 penalty response. * Reads X-Ratelimit-Remaining and X-Ratelimit-Retry-After headers. * Returns the number of milliseconds to wait. */ handlePenalty(headers: Headers): number; /** Deduct penalty tokens (5-10 on 409) */ applyPenalty(count?: number): void; private log; private sleep; get availableTokens(): number; } /** Per-category rate limit configuration. */ export interface RateLimitConfig { /** Max requests per minute (token bucket size + refill). */ rpm: number; /** Minimum milliseconds between two consecutive requests. */ minIntervalMs: number; } /** * Holds one {@link RateLimiter} per key (API category host, or a finer-grained * per-endpoint key for endpoints with their own strict caps). Limiters are * created lazily from `configs[key]`, falling back to `fallback` for unknown * keys. This keeps 409 penalties and token budgets isolated per category, * matching how Wildberries actually meters requests. */ export declare class RateLimiterPool { private readonly configs; private readonly fallback; private readonly limiters; constructor(configs?: Record, fallback?: RateLimitConfig); /** Get (or lazily create) the limiter for a key. */ for(key: string): RateLimiter; /** Number of distinct limiters created so far (for testing/introspection). */ get size(): number; } //# sourceMappingURL=rate-limiter.d.ts.map