UNPKG

@mornya/restful-libs

Version:

The project of wrapped library for RESTful API processing module.

33 lines (32 loc) 1.77 kB
import { type AxiosRequestConfig as BaseAxiosRequestConfig, type AxiosError } from 'axios'; import { type AxiosCacheInstance, type CacheRequestConfig, type CacheAxiosResponse, type InternalCacheRequestConfig } from 'axios-cache-interceptor'; import AxiosRetry from 'axios-retry'; export interface AxiosRequestConfig extends CacheRequestConfig { ignoreCancel?: boolean; ignoreResponseCallback?: boolean; } export interface AxiosResponse<R = any, D = any> extends CacheAxiosResponse<R, D> { } export type { AxiosError }; export type Option = { isShowLog?: boolean; isLogFullResponse?: boolean; truncateLogThreshold?: number; isThrowsOnError?: boolean; isCancelDuplicateRequests?: boolean; resolveRequestURL?: Record<string, string> | null; requestsThreshold?: number; onAuthorize?(config: BaseAxiosRequestConfig): string | void; onRequest?<T = InternalCacheRequestConfig>(config: T, currReqs: number): T | Promise<T>; onResponse?<T = AxiosResponse>(response: T, currReqs: number): T | Promise<T>; onRequestError?(error: AxiosError, currReqs: number): void; onResponseError?(error: AxiosError, currReqs: number): void; onInvalidate?(which: string, error: AxiosError): void; }; export { AxiosRetry }; export declare function getInstance(instanceOption?: Option): AxiosCacheInstance; export declare function reset(): Promise<void>; export declare function restApi<T = any>(requestConfig: AxiosRequestConfig): Promise<AxiosResponse<T> | null>; export declare function restApis<T = any>(requestConfigs: AxiosRequestConfig[]): Promise<AxiosResponse<T>[] | null>; export declare function cancelAllRequests(message?: string): void; export declare function isCancelled(error: AxiosError | string | unknown): boolean;