@mrboombastic/mailerlite-api-v2-node
Version:
[MailerLite API v2](https://developers.mailerlite.com/docs/getting-started-with-mailerlite-api) [Node.js](https://nodejs.org/en/) SDK. It is mostly a thin wrapper on [axios](https://github.com/axios/axios) that provides [authentication](https://developers
42 lines (41 loc) • 1.42 kB
TypeScript
import type { AxiosResponse, AxiosError } from "axios";
import type { RateLimitHeaders, RateLimitError, RateLimitOptions } from "./types/index.js";
export declare class RateLimitHandler {
private rateLimitRetryAttempts;
private rateLimitRetryDelay;
private onRateLimitHit?;
private onRateLimitRetry?;
constructor(options?: RateLimitOptions);
/**
* Parse rate limit headers from API response
*/
parseRateLimitHeaders(response: AxiosResponse): RateLimitHeaders | null;
/**
* Check if the error is a rate limit error (429 status)
*/
isRateLimitError(error: AxiosError): boolean;
/**
* Create a RateLimitError from an AxiosError
*/
createRateLimitError(error: AxiosError): RateLimitError;
/**
* Handle rate limit by waiting and retrying
*/
handleRateLimit(error: AxiosError, retryFn: () => Promise<any>, attempt?: number): Promise<any>;
/**
* Check if we're approaching rate limit and should slow down
*/
shouldThrottle(response: AxiosResponse): boolean;
/**
* Calculate suggested delay to avoid hitting rate limits
*/
getThrottleDelay(response: AxiosResponse): number;
/**
* Utility function to sleep for a given number of milliseconds
*/
private sleep;
/**
* Log rate limit information for debugging
*/
logRateLimitInfo(response: AxiosResponse): void;
}