UNPKG

@mcp-consultant-tools/powerplatform-data

Version:

MCP server for PowerPlatform data CRUD operations (operational use)

108 lines 2.78 kB
/** * Rate Limiter Module * * Implements rate limiting with exponential backoff for PowerPlatform API calls. * Prevents API throttling errors (429) and manages concurrent request limits. */ export interface RateLimiterOptions { maxRequestsPerMinute?: number; maxConcurrentRequests?: number; retryAttempts?: number; initialBackoffMs?: number; maxBackoffMs?: number; backoffMultiplier?: number; } export interface RequestQueueItem<T> { fn: () => Promise<T>; resolve: (value: T) => void; reject: (error: any) => void; retryCount: number; } /** * Rate Limiter Class */ export declare class RateLimiter { private options; private requestTimestamps; private activeRequests; private queue; private processing; constructor(options?: RateLimiterOptions); /** * Execute a function with rate limiting */ execute<T>(fn: () => Promise<T>): Promise<T>; /** * Process the request queue */ private processQueue; /** * Execute a single request with retry logic */ private executeRequest; /** * Check if we can make a request without exceeding rate limits */ private canMakeRequest; /** * Record a request timestamp */ private recordRequest; /** * Remove timestamps older than 1 minute */ private cleanupOldTimestamps; /** * Calculate backoff time for retry */ private calculateBackoff; /** * Check if error is a rate limit error */ private isRateLimitError; /** * Sleep helper */ private sleep; /** * Get current rate limiter stats */ getStats(): { activeRequests: number; queuedRequests: number; requestsLastMinute: number; maxRequestsPerMinute: number; maxConcurrentRequests: number; utilizationPercentage: number; }; /** * Wait until rate limiter has capacity */ waitForCapacity(): Promise<void>; /** * Clear the queue */ clearQueue(): void; /** * Reset rate limiter */ reset(): void; /** * Update rate limiter options */ updateOptions(options: Partial<RateLimiterOptions>): void; } export declare const rateLimiter: RateLimiter; /** * Helper function to wrap API calls with rate limiting */ export declare function withRateLimit<T>(fn: () => Promise<T>): Promise<T>; /** * Batch execution with rate limiting * Processes an array of functions with rate limiting */ export declare function batchExecute<T>(fns: (() => Promise<T>)[], options?: { onProgress?: (completed: number, total: number) => void; onError?: (error: any, index: number) => void; }): Promise<T[]>; //# sourceMappingURL=rate-limiter.d.ts.map