axios-retryer
Version:
axios-retryer is an advanced Axios request manager offering intelligent retry logic with token refresh, concurrency control, priority queuing, and a flexible plugin architecture, all built with TypeScript for robust HTTP client integrations.
60 lines (59 loc) • 2.51 kB
TypeScript
import './global-axios-augmentation';
export { type RetryMode, type RetryHooks, type RetryManagerOptions, type RetryStrategy, type RequestStore, type RetryPlugin, type AxiosRetryerBackoffType, type AxiosRetryerRequestPriority, type AxiosRetryerMetrics, RETRY_MODES, AXIOS_RETRYER_REQUEST_PRIORITIES, AXIOS_RETRYER_BACKOFF_TYPES, } from './types';
export { RetryManager } from './core/RetryManager';
export { QueueFullError } from './core/errors/QueueFullError';
export { DefaultRetryStrategy } from './core/strategies/DefaultRetryStrategy';
export type { TokenRefreshPluginOptions } from './plugins/TokenRefreshPlugin/types/';
import { RetryManager } from './core/RetryManager';
import type { RetryManagerOptions, RetryStrategy, AxiosRetryerBackoffType } from './types';
/**
* Creates a new RetryManager instance with the given options.
* Functional alternative to using the `new RetryManager()` constructor.
*
* @param options Configuration options for the retry manager
* @returns A configured RetryManager instance
*
* @example
* ```typescript
* const retryer = createRetryer({ retries: 3, debug: true });
* retryer.axiosInstance.get('/api/data').then(response => console.log(response.data));
* ```
*/
export declare function createRetryer(options?: RetryManagerOptions): RetryManager;
/**
* Interface for creating a custom retry strategy
*/
export interface RetryStrategyConfig {
/**
* Custom function to determine if an error is retryable
*/
isRetryable?: (error: any) => boolean;
/**
* Custom function to determine if a request should be retried
*/
shouldRetry?: (error: any, attempt: number, maxRetries: number) => boolean;
/**
* Custom function to calculate the delay between retry attempts
*/
getDelay?: (attempt: number, maxRetries: number, backoffType?: AxiosRetryerBackoffType) => number;
}
/**
* Creates a custom retry strategy with the given configuration.
* Functional alternative to implementing the RetryStrategy interface directly.
*
* @param config Configuration for the retry strategy
* @returns A RetryStrategy implementation
*
* @example
* ```typescript
* const customStrategy = createRetryStrategy({
* isRetryable: (error) => error.response?.status >= 500,
* getDelay: (attempt) => attempt * 1000 // linear backoff
* });
*
* const retryer = createRetryer({
* retryStrategy: customStrategy
* });
* ```
*/
export declare function createRetryStrategy(config?: RetryStrategyConfig): RetryStrategy;