- Added cache strategies: NetworkFirst, CacheFirst, StaleWhileRevalidate, NetworkOnly, and CacheOnly. - Introduced InterceptorManager for managing request, response, and error interceptors. - Developed RetryManager for handling request retries with customizable backoff strategies. - Implemented RequestDeduplicator to prevent simultaneous identical requests. - Created timeout utilities for handling request timeouts. - Enhanced WebrequestClient to support global interceptors, caching, and retry logic. - Added convenience methods for common HTTP methods (GET, POST, PUT, DELETE) with JSON handling. - Established a fetch-compatible webrequest function for seamless integration. - Defined core type structures for caching, retry options, interceptors, and web request configurations.
32 lines
674 B
TypeScript
32 lines
674 B
TypeScript
/**
|
|
* Interceptor type definitions
|
|
*/
|
|
|
|
/**
|
|
* Request interceptor
|
|
* Transforms the request before it's sent
|
|
*/
|
|
export type TRequestInterceptor = (
|
|
request: Request,
|
|
) => Request | Promise<Request>;
|
|
|
|
/**
|
|
* Response interceptor
|
|
* Transforms the response after it's received
|
|
*/
|
|
export type TResponseInterceptor = (
|
|
response: Response,
|
|
) => Response | Promise<Response>;
|
|
|
|
/**
|
|
* Error interceptor
|
|
* Handles errors during request/response processing
|
|
*/
|
|
export type TErrorInterceptor = (error: Error) => Error | Promise<Error>;
|
|
|
|
export interface IInterceptors {
|
|
request?: TRequestInterceptor[];
|
|
response?: TResponseInterceptor[];
|
|
error?: TErrorInterceptor[];
|
|
}
|