UNPKG

@alba-cars/common-modules

Version:

A package containing DTOs, validation classes and common modules and interfaces for Alba Cars

63 lines (62 loc) 2.25 kB
interface ApiRequestOptions extends RequestInit { headers?: Record<string, string>; query?: Record<string, any>; timeout?: number; signal?: AbortSignal; isRetry?: boolean; } type RequestInterceptor = (config: RequestInit & { url: string; options: ApiRequestOptions; }) => Promise<RequestInit & { url: string; options: ApiRequestOptions; }> | (RequestInit & { url: string; options: ApiRequestOptions; }); type ResponseInterceptor = (response: Response, requestConfig: RequestInit & { url: string; options: ApiRequestOptions; }) => Promise<Response> | Response; type ResponseErrorInterceptor = (error: any, requestConfig: RequestInit & { url: string; options: ApiRequestOptions; }) => Promise<any> | any; declare class InterceptorManager { private requestInterceptors; private responseInterceptors; private responseErrorInterceptors; addRequestInterceptor(interceptor: RequestInterceptor): number; addResponseInterceptor(interceptor: ResponseInterceptor): number; addResponseErrorInterceptor(interceptor: ResponseErrorInterceptor): number; removeRequestInterceptor(index: number): void; removeResponseInterceptor(index: number): void; removeResponseErrorInterceptor(index: number): void; clearRequestInterceptors(): void; clearResponseInterceptors(): void; clearResponseErrorInterceptors(): void; clearAllInterceptors(): void; applyRequestInterceptors(config: RequestInit & { url: string; options: ApiRequestOptions; }): Promise<RequestInit & { url: string; options: ApiRequestOptions; }>; applyResponseInterceptors(response: Response, requestConfig: RequestInit & { url: string; options: ApiRequestOptions; }): Promise<Response>; applyResponseErrorInterceptors(error: any, requestConfig: RequestInit & { url: string; options: ApiRequestOptions; }): Promise<any>; retryRequest<T>(config: RequestInit & { url: string; options: ApiRequestOptions; }): Promise<T>; } export declare const interceptors: InterceptorManager; export declare function apiRequest<T>(endpoint: string, options?: ApiRequestOptions): Promise<T>; export {};