@zayne-labs/callapi 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/error-lBRMiMeF.d.cts +17 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +9 -8
- package/dist/cjs/options/index.cjs +1 -1
- package/dist/cjs/options/index.cjs.map +1 -1
- package/dist/cjs/options/index.d.cts +9 -9
- package/dist/cjs/{index-DnZtIr3r.d.cts → plugins-Ds-irdHk.d.cts} +110 -123
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/cjs/utils/index.cjs.map +1 -1
- package/dist/cjs/utils/index.d.cts +9 -1
- package/dist/esm/chunk-G7B7UXHI.js +1 -0
- package/dist/esm/chunk-G7B7UXHI.js.map +1 -0
- package/dist/esm/chunk-VT637KNN.js +1 -0
- package/dist/esm/chunk-VT637KNN.js.map +1 -0
- package/dist/esm/error-lBRMiMeF.d.ts +17 -0
- package/dist/esm/index.d.ts +9 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/options/index.d.ts +9 -9
- package/dist/esm/options/index.js +1 -1
- package/dist/esm/options/index.js.map +1 -1
- package/dist/esm/{index-DnZtIr3r.d.ts → plugins-Ds-irdHk.d.ts} +110 -123
- package/dist/esm/utils/index.d.ts +9 -1
- package/dist/esm/utils/index.js +1 -1
- package/package.json +3 -3
- package/dist/esm/chunk-62WNJ6T4.js +0 -1
- package/dist/esm/chunk-62WNJ6T4.js.map +0 -1
- package/dist/esm/chunk-OCGFLXP6.js +0 -1
- package/dist/esm/chunk-OCGFLXP6.js.map +0 -1
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
type AnyString = string & {
|
|
2
|
+
z_placeholder?: never;
|
|
3
|
+
};
|
|
4
|
+
type AnyNumber = number & {
|
|
5
|
+
z_placeholder?: never;
|
|
6
|
+
};
|
|
7
|
+
type AnyFunction<TResult = any> = (...args: any[]) => TResult;
|
|
8
|
+
type UnmaskType<TValue> = {
|
|
9
|
+
_: TValue;
|
|
10
|
+
}["_"];
|
|
11
|
+
type Awaitable<TValue> = Promise<TValue> | TValue;
|
|
12
|
+
type CommonRequestHeaders = "Access-Control-Allow-Credentials" | "Access-Control-Allow-Headers" | "Access-Control-Allow-Methods" | "Access-Control-Allow-Origin" | "Access-Control-Expose-Headers" | "Access-Control-Max-Age" | "Age" | "Allow" | "Cache-Control" | "Clear-Site-Data" | "Content-Disposition" | "Content-Encoding" | "Content-Language" | "Content-Length" | "Content-Location" | "Content-Range" | "Content-Security-Policy-Report-Only" | "Content-Security-Policy" | "Cookie" | "Cross-Origin-Embedder-Policy" | "Cross-Origin-Opener-Policy" | "Cross-Origin-Resource-Policy" | "Date" | "ETag" | "Expires" | "Last-Modified" | "Location" | "Permissions-Policy" | "Pragma" | "Retry-After" | "Save-Data" | "Sec-CH-Prefers-Color-Scheme" | "Sec-CH-Prefers-Reduced-Motion" | "Sec-CH-UA-Arch" | "Sec-CH-UA-Bitness" | "Sec-CH-UA-Form-Factor" | "Sec-CH-UA-Full-Version-List" | "Sec-CH-UA-Full-Version" | "Sec-CH-UA-Mobile" | "Sec-CH-UA-Model" | "Sec-CH-UA-Platform-Version" | "Sec-CH-UA-Platform" | "Sec-CH-UA-WoW64" | "Sec-CH-UA" | "Sec-Fetch-Dest" | "Sec-Fetch-Mode" | "Sec-Fetch-Site" | "Sec-Fetch-User" | "Sec-GPC" | "Server-Timing" | "Server" | "Service-Worker-Navigation-Preload" | "Set-Cookie" | "Strict-Transport-Security" | "Timing-Allow-Origin" | "Trailer" | "Transfer-Encoding" | "Upgrade" | "Vary" | "Warning" | "WWW-Authenticate" | "X-Content-Type-Options" | "X-DNS-Prefetch-Control" | "X-Frame-Options" | "X-Permitted-Cross-Domain-Policies" | "X-Powered-By" | "X-Robots-Tag" | "X-XSS-Protection" | AnyString;
|
|
13
|
+
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
|
|
14
|
+
type CommonContentTypes = "application/epub+zip" | "application/gzip" | "application/json" | "application/ld+json" | "application/octet-stream" | "application/ogg" | "application/pdf" | "application/rtf" | "application/vnd.ms-fontobject" | "application/wasm" | "application/xhtml+xml" | "application/xml" | "application/zip" | "audio/aac" | "audio/mpeg" | "audio/ogg" | "audio/opus" | "audio/webm" | "audio/x-midi" | "font/otf" | "font/ttf" | "font/woff" | "font/woff2" | "image/avif" | "image/bmp" | "image/gif" | "image/jpeg" | "image/png" | "image/svg+xml" | "image/tiff" | "image/webp" | "image/x-icon" | "model/gltf-binary" | "model/gltf+json" | "text/calendar" | "text/css" | "text/csv" | "text/html" | "text/javascript" | "text/plain" | "video/3gpp" | "video/3gpp2" | "video/av1" | "video/mp2t" | "video/mp4" | "video/mpeg" | "video/ogg" | "video/webm" | "video/x-msvideo" | AnyString;
|
|
15
|
+
|
|
1
16
|
type ValueOrFunctionResult<TValue> = TValue | (() => TValue);
|
|
2
17
|
/**
|
|
3
18
|
* Bearer Or Token authentication
|
|
@@ -9,13 +24,13 @@ type ValueOrFunctionResult<TValue> = TValue | (() => TValue);
|
|
|
9
24
|
* `auth: Token some-auth-token`,
|
|
10
25
|
*/
|
|
11
26
|
type BearerOrTokenAuth = {
|
|
12
|
-
type?:
|
|
13
|
-
bearer?: never;
|
|
14
|
-
token?: ValueOrFunctionResult<string | null>;
|
|
15
|
-
} | {
|
|
16
|
-
type?: never;
|
|
27
|
+
type?: "Bearer";
|
|
17
28
|
bearer?: ValueOrFunctionResult<string | null>;
|
|
18
29
|
token?: never;
|
|
30
|
+
} | {
|
|
31
|
+
type?: "Token";
|
|
32
|
+
bearer?: never;
|
|
33
|
+
token?: ValueOrFunctionResult<string | null>;
|
|
19
34
|
};
|
|
20
35
|
/**
|
|
21
36
|
* Basic auth
|
|
@@ -47,67 +62,13 @@ type CustomAuth = {
|
|
|
47
62
|
};
|
|
48
63
|
type Auth = BearerOrTokenAuth | BasicAuth | CustomAuth;
|
|
49
64
|
|
|
50
|
-
type AnyString = string & {
|
|
51
|
-
z_placeholder?: never;
|
|
52
|
-
};
|
|
53
|
-
type AnyNumber = number & {
|
|
54
|
-
z_placeholder?: never;
|
|
55
|
-
};
|
|
56
|
-
type AnyObject = Record<string, any>;
|
|
57
|
-
type AnyFunction<TResult = any> = (...args: any[]) => TResult;
|
|
58
|
-
type UnmaskType<TValue> = {
|
|
59
|
-
_: TValue;
|
|
60
|
-
}["_"];
|
|
61
|
-
type Awaitable<TValue> = Promise<TValue> | TValue;
|
|
62
|
-
type CommonRequestHeaders = "Access-Control-Allow-Credentials" | "Access-Control-Allow-Headers" | "Access-Control-Allow-Methods" | "Access-Control-Allow-Origin" | "Access-Control-Expose-Headers" | "Access-Control-Max-Age" | "Age" | "Allow" | "Cache-Control" | "Clear-Site-Data" | "Content-Disposition" | "Content-Encoding" | "Content-Language" | "Content-Length" | "Content-Location" | "Content-Range" | "Content-Security-Policy-Report-Only" | "Content-Security-Policy" | "Cookie" | "Cross-Origin-Embedder-Policy" | "Cross-Origin-Opener-Policy" | "Cross-Origin-Resource-Policy" | "Date" | "ETag" | "Expires" | "Last-Modified" | "Location" | "Permissions-Policy" | "Pragma" | "Retry-After" | "Save-Data" | "Sec-CH-Prefers-Color-Scheme" | "Sec-CH-Prefers-Reduced-Motion" | "Sec-CH-UA-Arch" | "Sec-CH-UA-Bitness" | "Sec-CH-UA-Form-Factor" | "Sec-CH-UA-Full-Version-List" | "Sec-CH-UA-Full-Version" | "Sec-CH-UA-Mobile" | "Sec-CH-UA-Model" | "Sec-CH-UA-Platform-Version" | "Sec-CH-UA-Platform" | "Sec-CH-UA-WoW64" | "Sec-CH-UA" | "Sec-Fetch-Dest" | "Sec-Fetch-Mode" | "Sec-Fetch-Site" | "Sec-Fetch-User" | "Sec-GPC" | "Server-Timing" | "Server" | "Service-Worker-Navigation-Preload" | "Set-Cookie" | "Strict-Transport-Security" | "Timing-Allow-Origin" | "Trailer" | "Transfer-Encoding" | "Upgrade" | "Vary" | "Warning" | "WWW-Authenticate" | "X-Content-Type-Options" | "X-DNS-Prefetch-Control" | "X-Frame-Options" | "X-Permitted-Cross-Domain-Policies" | "X-Powered-By" | "X-Robots-Tag" | "X-XSS-Protection" | AnyString;
|
|
63
|
-
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token" | AnyString} ${string}`;
|
|
64
|
-
type CommonContentTypes = "application/epub+zip" | "application/gzip" | "application/json" | "application/ld+json" | "application/octet-stream" | "application/ogg" | "application/pdf" | "application/rtf" | "application/vnd.ms-fontobject" | "application/wasm" | "application/xhtml+xml" | "application/xml" | "application/zip" | "audio/aac" | "audio/mpeg" | "audio/ogg" | "audio/opus" | "audio/webm" | "audio/x-midi" | "font/otf" | "font/ttf" | "font/woff" | "font/woff2" | "image/avif" | "image/bmp" | "image/gif" | "image/jpeg" | "image/png" | "image/svg+xml" | "image/tiff" | "image/webp" | "image/x-icon" | "model/gltf-binary" | "model/gltf+json" | "text/calendar" | "text/css" | "text/csv" | "text/html" | "text/javascript" | "text/plain" | "video/3gpp" | "video/3gpp2" | "video/av1" | "video/mp2t" | "video/mp4" | "video/mpeg" | "video/ogg" | "video/webm" | "video/x-msvideo" | AnyString;
|
|
65
|
-
|
|
66
|
-
type PluginInitContext<TMoreOptions extends AnyObject = DefaultMoreOptions> = {
|
|
67
|
-
initURL: string;
|
|
68
|
-
options: CombinedCallApiExtraOptions<DefaultDataType, DefaultDataType, ResultModeUnion, TMoreOptions>;
|
|
69
|
-
request: CallApiRequestOptionsForHooks;
|
|
70
|
-
};
|
|
71
|
-
type PluginInitResult = Partial<Omit<PluginInitContext, "request"> & {
|
|
72
|
-
request: CallApiRequestOptions;
|
|
73
|
-
}>;
|
|
74
|
-
type CreateExtraOptions<TMoreOptions> = (...params: never[]) => TMoreOptions;
|
|
75
|
-
type CallApiPlugin<TMoreOptions extends AnyObject = DefaultMoreOptions> = {
|
|
76
|
-
/**
|
|
77
|
-
* @description Defines additional options that can be passed to callApi
|
|
78
|
-
*/
|
|
79
|
-
createExtraOptions?: CreateExtraOptions<TMoreOptions>;
|
|
80
|
-
/**
|
|
81
|
-
* @description A description for the plugin
|
|
82
|
-
*/
|
|
83
|
-
description?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Hooks / Interceptors for the plugin
|
|
86
|
-
*/
|
|
87
|
-
hooks?: InterceptorsOrInterceptorArray;
|
|
88
|
-
/**
|
|
89
|
-
* @description A unique id for the plugin
|
|
90
|
-
*/
|
|
91
|
-
id: string;
|
|
92
|
-
/**
|
|
93
|
-
* @description A function that will be called when the plugin is
|
|
94
|
-
* initialized. This will be called before the any
|
|
95
|
-
* of the other internal functions.
|
|
96
|
-
*/
|
|
97
|
-
init?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;
|
|
98
|
-
/**
|
|
99
|
-
* @description A name for the plugin
|
|
100
|
-
*/
|
|
101
|
-
name: string;
|
|
102
|
-
/**
|
|
103
|
-
* @description A version for the plugin
|
|
104
|
-
*/
|
|
105
|
-
version?: string;
|
|
106
|
-
};
|
|
107
|
-
declare const definePlugin: <TMoreOptions extends AnyObject = {}, TPlugin extends AnyFunction<CallApiPlugin<TMoreOptions>> | CallApiPlugin<TMoreOptions> = CallApiPlugin<TMoreOptions>>(plugin: TPlugin) => TPlugin;
|
|
108
|
-
|
|
109
65
|
type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => boolean | Promise<boolean>;
|
|
110
66
|
interface RetryOptions<TErrorData> {
|
|
67
|
+
/**
|
|
68
|
+
* @description Keeps track of the number of times the request has already been retried
|
|
69
|
+
* @deprecated This property is used internally to track retries. Please abstain from modifying it.
|
|
70
|
+
*/
|
|
71
|
+
readonly "~retryCount"?: number;
|
|
111
72
|
/**
|
|
112
73
|
* @description Number of allowed retry attempts on HTTP errors
|
|
113
74
|
* @default 0
|
|
@@ -117,10 +78,6 @@ interface RetryOptions<TErrorData> {
|
|
|
117
78
|
* @description Callback whose return value determines if a request should be retried or not
|
|
118
79
|
*/
|
|
119
80
|
retryCondition?: RetryCondition<TErrorData>;
|
|
120
|
-
/**
|
|
121
|
-
* @description Keeps track of the number of times the request has already been retried
|
|
122
|
-
*/
|
|
123
|
-
retryCount?: number;
|
|
124
81
|
/**
|
|
125
82
|
* @description Delay between retries in milliseconds
|
|
126
83
|
* @default 1000
|
|
@@ -148,39 +105,9 @@ interface RetryOptions<TErrorData> {
|
|
|
148
105
|
retryStrategy?: "exponential" | "linear";
|
|
149
106
|
}
|
|
150
107
|
|
|
151
|
-
type ToQueryStringFn = {
|
|
152
|
-
(params: CallApiConfig["query"]): string | null;
|
|
153
|
-
(params: Required<CallApiConfig>["query"]): string;
|
|
154
|
-
};
|
|
155
|
-
declare const toQueryString: ToQueryStringFn;
|
|
156
|
-
declare const getResponseType: <TResponse>(response: Response, parser?: Required<CallApiExtraOptions>["responseParser"]) => {
|
|
157
|
-
arrayBuffer: () => Promise<TResponse>;
|
|
158
|
-
blob: () => Promise<TResponse>;
|
|
159
|
-
formData: () => Promise<TResponse>;
|
|
160
|
-
json: () => Promise<Record<string, unknown> | TResponse>;
|
|
161
|
-
stream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
|
162
|
-
text: () => Promise<TResponse>;
|
|
163
|
-
};
|
|
164
|
-
type ErrorObjectUnion<TErrorData = unknown> = PossibleHTTPError<TErrorData> | PossibleJavaScriptError;
|
|
165
|
-
declare const isHTTPError: <TErrorData>(error: ErrorObjectUnion<TErrorData> | null) => error is PossibleHTTPError<TErrorData>;
|
|
166
|
-
type ErrorDetails<TErrorResponse> = {
|
|
167
|
-
defaultErrorMessage: string;
|
|
168
|
-
errorData: TErrorResponse;
|
|
169
|
-
response: Response;
|
|
170
|
-
};
|
|
171
|
-
type ErrorOptions = {
|
|
172
|
-
cause?: unknown;
|
|
173
|
-
};
|
|
174
|
-
declare class HTTPError<TErrorResponse = Record<string, unknown>> extends Error {
|
|
175
|
-
errorData: ErrorDetails<TErrorResponse>["errorData"];
|
|
176
|
-
isHTTPError: boolean;
|
|
177
|
-
name: "HTTPError";
|
|
178
|
-
response: ErrorDetails<TErrorResponse>["response"];
|
|
179
|
-
constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
|
|
180
|
-
}
|
|
181
|
-
declare const isHTTPErrorInstance: <TErrorResponse>(error: unknown) => error is HTTPError<TErrorResponse>;
|
|
182
|
-
|
|
183
108
|
declare const fetchSpecificKeys: ("headers" | "body" | "cache" | "credentials" | "integrity" | "keepalive" | "method" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window")[];
|
|
109
|
+
declare const defaultRetryMethods: ("GET" | "POST")[];
|
|
110
|
+
declare const defaultRetryStatusCodes: Required<BaseCallApiConfig>["retryStatusCodes"];
|
|
184
111
|
|
|
185
112
|
type FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], "body" | "headers" | "method">;
|
|
186
113
|
interface CallApiRequestOptions extends Pick<RequestInit, FetchSpecificKeysUnion> {
|
|
@@ -204,47 +131,49 @@ interface CallApiRequestOptionsForHooks extends Omit<CallApiRequestOptions, "hea
|
|
|
204
131
|
interface Register {
|
|
205
132
|
}
|
|
206
133
|
type DefaultDataType = unknown;
|
|
207
|
-
|
|
134
|
+
type DefaultMoreOptions = NonNullable<unknown>;
|
|
135
|
+
type WithMoreOptions<TMoreOptions = DefaultMoreOptions> = {
|
|
136
|
+
options: CombinedCallApiExtraOptions & Partial<TMoreOptions>;
|
|
137
|
+
};
|
|
138
|
+
interface Interceptors<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> {
|
|
208
139
|
/**
|
|
209
|
-
* @description Interceptor that will be called when any error occurs within the request/response
|
|
140
|
+
* @description Interceptor that will be called when any error occurs within the request/response lifecycle, regardless of whether the error is from the api or not.
|
|
210
141
|
* It is basically a combination of `onRequestError` and `onResponseError` interceptors
|
|
211
142
|
*/
|
|
212
|
-
onError?: (context: ErrorContext<TErrorData>) => Awaitable<unknown>;
|
|
143
|
+
onError?: (context: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
213
144
|
/**
|
|
214
145
|
* @description Interceptor that will be called just before the request is made, allowing for modifications or additional operations.
|
|
215
146
|
*/
|
|
216
|
-
onRequest?: (context: RequestContext) => Awaitable<unknown>;
|
|
147
|
+
onRequest?: (context: RequestContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
217
148
|
/**
|
|
218
149
|
* @description Interceptor that will be called when an error occurs during the fetch request.
|
|
219
150
|
*/
|
|
220
|
-
onRequestError?: (context: RequestErrorContext) => Awaitable<unknown>;
|
|
151
|
+
onRequestError?: (context: RequestErrorContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
221
152
|
/**
|
|
222
153
|
* @description Interceptor that will be called when any response is received from the api, whether successful or not
|
|
223
154
|
*/
|
|
224
|
-
onResponse?: (context: ResponseContext<TData, TErrorData>) => Awaitable<unknown>;
|
|
155
|
+
onResponse?: (context: ResponseContext<TData, TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
225
156
|
/**
|
|
226
157
|
* @description Interceptor that will be called when an error response is received from the api.
|
|
227
158
|
*/
|
|
228
|
-
onResponseError?: (context: ResponseErrorContext<TErrorData>) => Awaitable<unknown>;
|
|
159
|
+
onResponseError?: (context: ResponseErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
229
160
|
/**
|
|
230
161
|
* @description Interceptor that will be called when a request is retried.
|
|
231
162
|
*/
|
|
232
|
-
onRetry?: (response: ErrorContext<TErrorData>) => Awaitable<unknown>;
|
|
163
|
+
onRetry?: (response: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
233
164
|
/**
|
|
234
165
|
* @description Interceptor that will be called when a successful response is received from the api.
|
|
235
166
|
*/
|
|
236
|
-
onSuccess?: (context: SuccessContext<TData>) => Awaitable<unknown>;
|
|
167
|
+
onSuccess?: (context: SuccessContext<TData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
237
168
|
}
|
|
238
|
-
type InterceptorsOrInterceptorArray<TData = DefaultDataType, TErrorData = DefaultDataType> = {
|
|
239
|
-
[Key in keyof Interceptors<TData, TErrorData>]: Interceptors<TData, TErrorData>[Key] | Array<Interceptors<TData, TErrorData>[Key]>;
|
|
169
|
+
type InterceptorsOrInterceptorArray<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> = {
|
|
170
|
+
[Key in keyof Interceptors<TData, TErrorData, TMoreOptions>]: Interceptors<TData, TErrorData, TMoreOptions>[Key] | Array<Interceptors<TData, TErrorData, TMoreOptions>[Key]>;
|
|
240
171
|
};
|
|
241
172
|
type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
|
|
242
|
-
type CallApiPluginArray<TMoreOptions extends AnyObject> = Array<CallApiPlugin<TMoreOptions>>;
|
|
243
|
-
type DefaultMoreOptions = NonNullable<unknown>;
|
|
244
173
|
type Meta = Register extends {
|
|
245
174
|
meta?: infer TMeta extends Record<string, unknown>;
|
|
246
175
|
} ? TMeta : never;
|
|
247
|
-
type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion,
|
|
176
|
+
type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = InterceptorsOrInterceptorArray<TData, TErrorData> & Partial<InferPluginOptions<TPluginArray>> & RetryOptions<TErrorData> & {
|
|
248
177
|
/**
|
|
249
178
|
* @description Authorization header value.
|
|
250
179
|
*/
|
|
@@ -336,7 +265,7 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
|
336
265
|
/**
|
|
337
266
|
* @description An array of CallApi plugins. It allows you to extend the behavior of the library.
|
|
338
267
|
*/
|
|
339
|
-
plugins?:
|
|
268
|
+
plugins?: TPluginArray | ((context: PluginInitContext) => TPluginArray);
|
|
340
269
|
/**
|
|
341
270
|
* @description Query parameters to append to the URL.
|
|
342
271
|
*/
|
|
@@ -377,18 +306,18 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
|
377
306
|
timeout?: number;
|
|
378
307
|
};
|
|
379
308
|
declare const optionsEnumToExtendFromBase: "plugins"[];
|
|
380
|
-
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion,
|
|
309
|
+
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = ExtraOptions<TData, TErrorData, TResultMode, TPluginArray> & {
|
|
381
310
|
/**
|
|
382
311
|
* @description Options that should extend the base options.
|
|
383
312
|
*/
|
|
384
|
-
extend?: Pick<ExtraOptions<TData, TErrorData, TResultMode,
|
|
313
|
+
extend?: Pick<ExtraOptions<TData, TErrorData, TResultMode, TPluginArray>, (typeof optionsEnumToExtendFromBase)[number]>;
|
|
385
314
|
};
|
|
386
315
|
declare const optionsEnumToOmitFromBase: ("dedupeKey" | "extend")[];
|
|
387
|
-
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion,
|
|
388
|
-
type CombinedCallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion,
|
|
389
|
-
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion,
|
|
390
|
-
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion,
|
|
391
|
-
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion,
|
|
316
|
+
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBasePluginArray extends CallApiPlugin[] = CallApiPlugin[]> = Omit<CallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBasePluginArray>, (typeof optionsEnumToOmitFromBase)[number]>;
|
|
317
|
+
type CombinedCallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = BaseCallApiExtraOptions<TData, TErrorData, TResultMode, TPluginArray> & CallApiExtraOptions<TData, TErrorData, TResultMode, TPluginArray>;
|
|
318
|
+
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = CallApiExtraOptions<TData, TErrorData, TResultMode, TPluginArray> & CallApiRequestOptions;
|
|
319
|
+
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBasePluginArray extends CallApiPlugin[] = CallApiPlugin[]> = BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBasePluginArray> & CallApiRequestOptions;
|
|
320
|
+
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = [initURL: string, config?: CallApiConfig<TData, TErrorData, TResultMode, TPluginArray>];
|
|
392
321
|
type RequestContext = UnmaskType<{
|
|
393
322
|
options: CombinedCallApiExtraOptions;
|
|
394
323
|
request: CallApiRequestOptionsForHooks;
|
|
@@ -471,4 +400,62 @@ type ResultModeUnion = {
|
|
|
471
400
|
}[keyof ResultModeMap] | undefined;
|
|
472
401
|
type GetCallApiResult<TData, TErrorData, TResultMode> = TErrorData extends false ? ResultModeMap<TData, TErrorData>["onlySuccessWithException"] : undefined extends TResultMode ? ResultModeMap<TData, TErrorData>["all"] : TResultMode extends NonNullable<ResultModeUnion> ? ResultModeMap<TData, TErrorData>[TResultMode] : never;
|
|
473
402
|
|
|
474
|
-
|
|
403
|
+
type ToQueryStringFn = {
|
|
404
|
+
(params: CallApiConfig["query"]): string | null;
|
|
405
|
+
(params: Required<CallApiConfig>["query"]): string;
|
|
406
|
+
};
|
|
407
|
+
declare const toQueryString: ToQueryStringFn;
|
|
408
|
+
declare const getResponseType: <TResponse>(response: Response, parser?: Required<CallApiExtraOptions>["responseParser"]) => {
|
|
409
|
+
arrayBuffer: () => Promise<TResponse>;
|
|
410
|
+
blob: () => Promise<TResponse>;
|
|
411
|
+
formData: () => Promise<TResponse>;
|
|
412
|
+
json: () => Promise<Record<string, unknown> | TResponse>;
|
|
413
|
+
stream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
|
414
|
+
text: () => Promise<TResponse>;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ? TParam : never;
|
|
418
|
+
type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = TPluginArray extends Array<infer TPlugin extends CallApiPlugin> ? TPlugin["createExtraOptions"] extends (...params: never[]) => infer TResult ? UnionToIntersection<TResult> : NonNullable<unknown> : NonNullable<unknown>;
|
|
419
|
+
type PluginInitContext = {
|
|
420
|
+
initURL: string;
|
|
421
|
+
options: CombinedCallApiExtraOptions;
|
|
422
|
+
request: CallApiRequestOptionsForHooks;
|
|
423
|
+
};
|
|
424
|
+
type PluginInitResult = Partial<Omit<PluginInitContext, "request"> & {
|
|
425
|
+
request: CallApiRequestOptions;
|
|
426
|
+
}>;
|
|
427
|
+
type CallApiPlugin = {
|
|
428
|
+
/**
|
|
429
|
+
* @description Defines additional options that can be passed to callApi
|
|
430
|
+
*/
|
|
431
|
+
createExtraOptions?: (...params: never[]) => unknown;
|
|
432
|
+
/**
|
|
433
|
+
* @description A description for the plugin
|
|
434
|
+
*/
|
|
435
|
+
description?: string;
|
|
436
|
+
/**
|
|
437
|
+
* Hooks / Interceptors for the plugin
|
|
438
|
+
*/
|
|
439
|
+
hooks?: InterceptorsOrInterceptorArray;
|
|
440
|
+
/**
|
|
441
|
+
* @description A unique id for the plugin
|
|
442
|
+
*/
|
|
443
|
+
id: string;
|
|
444
|
+
/**
|
|
445
|
+
* @description A function that will be called when the plugin is
|
|
446
|
+
* initialized. This will be called before the any
|
|
447
|
+
* of the other internal functions.
|
|
448
|
+
*/
|
|
449
|
+
init?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;
|
|
450
|
+
/**
|
|
451
|
+
* @description A name for the plugin
|
|
452
|
+
*/
|
|
453
|
+
name: string;
|
|
454
|
+
/**
|
|
455
|
+
* @description A version for the plugin
|
|
456
|
+
*/
|
|
457
|
+
version?: string;
|
|
458
|
+
};
|
|
459
|
+
declare const definePlugin: <TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin> = CallApiPlugin>(plugin: TPlugin) => TPlugin;
|
|
460
|
+
|
|
461
|
+
export { type BaseCallApiConfig as B, type CallApiPlugin as C, type DefaultDataType as D, type ErrorContext as E, type GetCallApiResult as G, type Interceptors as I, type PluginInitContext as P, type ResultModeUnion as R, type SuccessContext as S, type CallApiConfig as a, type BaseCallApiExtraOptions as b, type CallApiExtraOptions as c, definePlugin as d, type PossibleJavaScriptError as e, type PossibleHTTPError as f, type CallApiParameters as g, type CallApiRequestOptions as h, type CallApiRequestOptionsForHooks as i, type CallApiResultErrorVariant as j, type CallApiResultSuccessVariant as k, type CombinedCallApiExtraOptions as l, type InterceptorsOrInterceptorArray as m, type PossibleJavascriptErrorNames as n, type Register as o, type RequestContext as p, type RequestErrorContext as q, type ResponseContext as r, type ResponseErrorContext as s, toQueryString as t, defaultRetryMethods as u, defaultRetryStatusCodes as v };
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { f as PossibleHTTPError, e as PossibleJavaScriptError } from '../plugins-Ds-irdHk.js';
|
|
2
|
+
export { u as defaultRetryMethods, v as defaultRetryStatusCodes, t as toQueryString } from '../plugins-Ds-irdHk.js';
|
|
3
|
+
import { H as HTTPError } from '../error-lBRMiMeF.js';
|
|
4
|
+
|
|
5
|
+
type ErrorObjectUnion<TErrorData = unknown> = PossibleHTTPError<TErrorData> | PossibleJavaScriptError;
|
|
6
|
+
declare const isHTTPError: <TErrorData>(error: ErrorObjectUnion<TErrorData> | null) => error is PossibleHTTPError<TErrorData>;
|
|
7
|
+
declare const isHTTPErrorInstance: <TErrorResponse>(error: unknown) => error is HTTPError<TErrorResponse>;
|
|
8
|
+
|
|
9
|
+
export { isHTTPError, isHTTPErrorInstance };
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{defaultRetryMethods,defaultRetryStatusCodes,isHTTPError,isHTTPErrorInstance,toQueryString}from"../chunk-G7B7UXHI.js";//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/callapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.5",
|
|
5
5
|
"description": "A lightweight wrapper over fetch with quality of life improvements like built-in request cancellation, retries, interceptors and more",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"size-limit": [
|
|
63
63
|
{
|
|
64
64
|
"path": "./src/index.ts",
|
|
65
|
-
"limit": "3.
|
|
65
|
+
"limit": "3.6 kb"
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
68
|
"path": "./src/options/index.ts",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
{
|
|
72
72
|
"path": "./src/utils/index.ts",
|
|
73
|
-
"limit": "
|
|
73
|
+
"limit": "600 b"
|
|
74
74
|
}
|
|
75
75
|
],
|
|
76
76
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getFetchImpl as e,splitBaseConfig as r,isFunction as t,isPlainObject as o,isString as s,isArray as n,toQueryString as a,splitConfig as i,combineHooks as l,defaultRetryMethods as u,defaultRetryStatusCodes as c,waitUntil as d,executeHooks as p,mergeAndResolveHeaders as y,getResponseData as f,HTTPError as g,resolveSuccessResult as m,resolveErrorResult as w,isHTTPErrorInstance as R}from"./chunk-OCGFLXP6.js";var q=e=>e,E=(e,r)=>async t=>{if("sequential"!==r){if("parallel"===r){const r=[...e];await Promise.all(r.map((e=>e?.(t))))}}else for(const r of e)await(r?.(t))},h={onError:new Set,onRequest:new Set,onRequestError:new Set,onResponse:new Set,onResponseError:new Set,onRetry:new Set,onSuccess:new Set},S=async e=>{const{initURL:r,options:n,request:a}=e,i=structuredClone(h),l=()=>{for(const e of Object.keys(h)){const r=n[e];i[e].add(r)}},u=e=>{for(const r of Object.keys(h)){const t=e[r];i[r].add(t)}};"mainHooksBeforePlugins"===n.mergedHooksExecutionOrder&&l();const c=e=>e?t(e)?e({initURL:r,options:n,request:a}):e:[],d=[...c(n.plugins),...c(n.extend?.plugins)];let p=r,y=n,f=a;const g=async e=>{if(!e)return;const t=await e({initURL:r,options:n,request:a});o(t)&&(s(t.initURL)&&(p=t.initURL),o(t.request)&&(f=t.request),o(t.options)&&(y=t.options))};for(const e of d)await g(e.init),e.hooks&&u(e.hooks);n.mergedHooksExecutionOrder&&"mainHooksAfterPlugins"!==n.mergedHooksExecutionOrder||l();const m={};for(const[e,r]of Object.entries(i)){const t=[...r].flat(),o=E(t,n.mergedHooksExecutionMode);m[e]=o}return{resolvedHooks:m,resolvedOptions:y,resolvedRequestOptions:f,url:p}},b=(e,r,t)=>"cancel"===t.dedupeStrategy||"defer"===t.dedupeStrategy?`${t.fullURL}-${JSON.stringify({options:t,request:r})}`:null,O=(e,r,t)=>{if(t&&"cancel"===r.dedupeStrategy){const e=r.dedupeKey?`Duplicate request detected - Aborting previous request with key '${r.dedupeKey}' as a new request was initiated`:`Duplicate request detected - Aborting previous request to '${r.fullURL}' as a new request with identical options was initiated`,o=new DOMException(e,"AbortError");t.controller.abort(o)}},M=(r,t,o,s)=>{const n=e(t.customFetchImpl);return s&&"defer"===t.dedupeStrategy?s.responsePromise:n(r,o)},k=(e,r)=>{const t=e.retryCount??0;return{getDelay:()=>"exponential"===e.retryStrategy?((e,r)=>{const t=r.retryMaxDelay??1e4,o=(r.retryDelay??1e3)*2**e;return Math.min(o,t)})(t,e):(e=>e.retryDelay??1e3)(e),shouldAttemptRetry:async()=>{const o=await(e.retryCondition?.(r))??!0,s=(e.retryAttempts??0)>t&&o;if("HTTPError"!==r.error.name)return s;const n=!!r.request.method&&e.retryMethods?.includes(r.request.method);return!!r.response?.status&&e.retryStatusCodes?.includes(r.response.status)&&n&&s}}},$=(e,r,t)=>{const o=((e,r)=>{if(!r)return e;let t=e;if(n(r)){const e=t.split("/").filter((e=>e.startsWith(":")));for(const[o,s]of e.entries()){const e=r[o];t=t.replace(s,e)}return t}for(const[e,o]of Object.entries(r))t=t.replace(`:${e}`,String(o));return t})(e,r);return((e,r)=>{if(!r)return e;const t=a(r);return 0===t?.length?e:e.endsWith("?")?`${e}${t}`:e.includes("?")?`${e}&${t}`:`${e}?${t}`})(o,t)},x=(...e)=>AbortSignal.any(e.filter(Boolean)),D=e=>AbortSignal.timeout(e),A=(e={})=>{const[s,n]=r(e),{body:a,headers:q,signal:E,...H}=s,L=new Map,U=async(...e)=>{const[r,s={}]=e,[A,v]=i(s),{body:C=a,headers:P,signal:j=E,...T}=A,F={};for(const e of Object.keys(h)){const r=l(n[e],v[e]);F[e]=r}const K={baseURL:"",bodySerializer:JSON.stringify,dedupeStrategy:"cancel",defaultErrorMessage:"Failed to fetch data from server!",mergedHooksExecutionMode:"parallel",mergedHooksExecutionOrder:"mainHooksAfterPlugins",responseType:"json",resultMode:"all",retryAttempts:0,retryDelay:1e3,retryMaxDelay:1e4,retryMethods:u,retryStatusCodes:c,retryStrategy:"linear",...n,...v,...F},{resolvedHooks:z,resolvedOptions:B,resolvedRequestOptions:G,url:I}=await S({initURL:r,options:K,request:{...H,...T}}),J=`${B.baseURL}${$(I,B.params,B.query)}`,N={...B,...z,fullURL:J,initURL:r},V={body:o(C)?N.bodySerializer(C):C,method:"GET",...G},W=new AbortController,X=null!=N.timeout?D(N.timeout):null,Q=x(W.signal,X,j),Y={signal:Q,...V},Z=N.dedupeKey??b(0,Y,N);null!==Z&&await d(.1);const _=null!==Z?L:null,ee=_?.get(Z);O(0,N,ee);try{await p(N.onRequest({options:N,request:Y})),Y.headers=y({auth:N.auth,baseHeaders:q??P,body:C,headers:Y.headers});const e=M(J,N,Y,ee);_?.set(Z,{controller:W,responsePromise:e});const r=await e,t="defer"===N.dedupeStrategy||N.cloneResponse;if(!r.ok){const e=await f(t?r.clone():r,N.responseType,N.responseParser,N.responseErrorValidator);throw new g({defaultErrorMessage:N.defaultErrorMessage,errorData:e,response:r})}const o=await f(t?r.clone():r,N.responseType,N.responseParser,N.responseValidator);return await p(N.onSuccess({data:o,options:N,request:Y,response:N.cloneResponse?r.clone():r}),N.onResponse({data:o,error:null,options:N,request:Y,response:N.cloneResponse?r.clone():r})),await m({data:o,response:r,resultMode:N.resultMode})}catch(e){const{apiDetails:o,generalErrorResult:n,resolveCustomErrorInfo:a}=w({defaultErrorMessage:N.defaultErrorMessage,error:e,resultMode:N.resultMode}),i={error:o.error,options:N,request:Y,response:o.response},{getDelay:l,shouldAttemptRetry:u}=k(N,i);if(!Q.aborted&&await u()){await p(N.onRetry(i));const e=l();await d(e);const t={...s,retryCount:(N.retryCount??0)+1};return await U(r,t)}const c=t(N.throwOnError)?N.throwOnError(i):N.throwOnError,y=()=>{if(c)throw o.error};if(R(e)){const{response:r}=e,t=n.error;return await p(N.onResponseError({error:t,options:N,request:Y,response:N.cloneResponse?r.clone():r}),N.onError({error:t,options:N,request:Y,response:N.cloneResponse?r.clone():r}),N.onResponse({data:null,error:t,options:N,request:Y,response:N.cloneResponse?r.clone():r})),y(),n}if(e instanceof DOMException&&"AbortError"===e.name){const{message:r,name:t}=e;return console.error(`${t}:`,r),y(),n}if(e instanceof DOMException&&"TimeoutError"===e.name){const r=`Request timed out after ${N.timeout}ms`;return console.error(`${e.name}:`,r),y(),a({message:r})}const f=n.error;return await p(N.onRequestError({error:f,options:N,request:Y}),N.onError({error:f,options:N,request:Y,response:null})),y(),n}finally{_?.delete(Z)}};return U.create=A,U},H=A();export{H as callApi,x as createCombinedSignal,A as createFetchClient,k as createRetryStrategy,D as createTimeoutSignal,q as definePlugin,b as generateDedupeKey,O as handleRequestCancelDedupe,M as handleRequestDeferDedupe,h as hooksEnum,S as initializePlugins,$ as mergeUrlWithParamsAndQuery};//# sourceMappingURL=chunk-62WNJ6T4.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins.ts","../../src/dedupe.ts","../../src/retry.ts","../../src/url.ts","../../src/utils/polyfills.ts","../../src/createFetchClient.ts"],"names":["callApi"],"mappings":";AAiEa,IAAA,YAAA,GAAe,CAM3B,MACI,KAAA;AACJ,EAAO,OAAA,MAAA;AACR;AAEA,IAAM,gBAAA,GAAmB,CACxB,KAAA,EACA,wBACI,KAAA;AACJ,EAAA,OAAO,OAAO,GAAiC,KAAA;AAC9C,IAAA,IAAI,6BAA6B,YAAc,EAAA;AAC9C,MAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AAEzB,QAAA,MAAM,OAAO,GAAG,CAAA;AAAA;AAGjB,MAAA;AAAA;AAGD,IAAA,IAAI,6BAA6B,UAAY,EAAA;AAC5C,MAAM,MAAA,SAAA,GAAY,CAAC,GAAG,KAAK,CAAA;AAE3B,MAAM,MAAA,OAAA,CAAQ,IAAI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AEnB,QAAO,OAAA,sBAAA,CAAuB,EAAE,OAAA,EAAS,CAAA;AAAA;AAG1C,MAAA,MAAM,0BAA2B,kBAA0D,CAAA,KAAA;AAE3F,MAAM,MAAA,YAAA;AAAA;AAAA,QAEL,QAAQ,cAAe,CAAA;AAAA,UACtB,KAAO,EAAA,uBAAA;AAAA,UACP,OAAA;AAAA,UACA;AAAA,SACA,CAAA;AAAA;AAAA,QAGD,QAAQ,OAAQ,CAAA;AAAA,UACf,KAAO,EAAA,uBAAA;AAAA,UACP,OAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAU,EAAA;AAAA,SACV;AAAA,OACF;AAEA,MAAmB,kBAAA,EAAA;AAEnB,MAAO,OAAA,kBAAA;AAAA,KAGN,SAAA;AACD,MAAA,uBAAA,EAAyB,OAAO,SAAS,CAAA;AAAA;AAC1C,GACD;AAEA,EAAAA,SAAQ,MAAS,GAAA,iBAAA;AAEjB,EAAOA,OAAAA,QAAAA;AACR;AAEO,IAAM,UAAU,iBAAkB","file":"chunk-62WNJ6T4.js","sourcesContent":["import type {\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n\tCombinedCallApiExtraOptions,\n\tDefaultDataType,\n\tDefaultMoreOptions,\n\tExtraOptions,\n\tInterceptors,\n\tInterceptorsOrInterceptorArray,\n\tResultModeUnion,\n} from \"./types\";\nimport { isFunction, isPlainObject, isString } from \"./utils/type-guards\";\nimport type { AnyFunction, AnyObject, Awaitable } from \"./utils/type-helpers\";\n\nexport type PluginInitContext<TMoreOptions extends AnyObject = DefaultMoreOptions> = {\n\tinitURL: string;\n\toptions: CombinedCallApiExtraOptions<DefaultDataType, DefaultDataType, ResultModeUnion, TMoreOptions>;\n\trequest: CallApiRequestOptionsForHooks;\n};\n\nexport type PluginInitResult = Partial<\n\tOmit<PluginInitContext, \"request\"> & { request: CallApiRequestOptions }\n>;\n\ntype CreateExtraOptions<TMoreOptions> = (...params: never[]) => TMoreOptions;\n\nexport type CallApiPlugin<TMoreOptions extends AnyObject = DefaultMoreOptions> = {\n\t/**\n\t * @description Defines additional options that can be passed to callApi\n\t */\n\tcreateExtraOptions?: CreateExtraOptions<TMoreOptions>;\n\n\t/**\n\t * @description A description for the plugin\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Hooks / Interceptors for the plugin\n\t */\n\thooks?: InterceptorsOrInterceptorArray;\n\n\t/**\n\t * @description A unique id for the plugin\n\t */\n\tid: string;\n\n\t/**\n\t * @description A function that will be called when the plugin is\n\t * initialized. This will be called before the any\n\t * of the other internal functions.\n\t */\n\tinit?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;\n\n\t/**\n\t * @description A name for the plugin\n\t */\n\tname: string;\n\n\t/**\n\t * @description A version for the plugin\n\t */\n\tversion?: string;\n};\n\nexport const definePlugin = <\n\tTMoreOptions extends AnyObject = DefaultMoreOptions,\n\tTPlugin extends\n\t\t| AnyFunction<CallApiPlugin<TMoreOptions>>\n\t\t| CallApiPlugin<TMoreOptions> = CallApiPlugin<TMoreOptions>,\n>(\n\tplugin: TPlugin\n) => {\n\treturn plugin;\n};\n\nconst createMergedHook = (\n\thooks: Array<AnyFunction<Awaitable<unknown>> | undefined>,\n\tmergedHooksExecutionMode: CombinedCallApiExtraOptions[\"mergedHooksExecutionMode\"]\n) => {\n\treturn async (ctx: Record<string, unknown>) => {\n\t\tif (mergedHooksExecutionMode === \"sequential\") {\n\t\t\tfor (const hook of hooks) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop -- This is necessary in this case\n\t\t\t\tawait hook?.(ctx);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tif (mergedHooksExecutionMode === \"parallel\") {\n\t\t\tconst hookArray = [...hooks];\n\n\t\t\tawait Promise.all(hookArray.map((uniqueHook) => uniqueHook?.(ctx)));\n\t\t}\n\t};\n};\n\n// prettier-ignore\ntype HookRegistries = {\n\t[Key in keyof Interceptors]: Set<Interceptors[Key]>;\n};\n\nexport const hooksEnum = {\n\tonError: new Set(),\n\tonRequest: new Set(),\n\tonRequestError: new Set(),\n\tonResponse: new Set(),\n\tonResponseError: new Set(),\n\tonRetry: new Set(),\n\tonSuccess: new Set(),\n} satisfies HookRegistries;\n\nexport const initializePlugins = async (context: PluginInitContext) => {\n\tconst { initURL, options, request } = context;\n\n\tconst hookRegistries = structuredClone(hooksEnum);\n\n\tconst addMainHooks = () => {\n\t\tfor (const key of Object.keys(hooksEnum)) {\n\t\t\tconst mainHook = options[key as keyof Interceptors] as never;\n\n\t\t\thookRegistries[key as keyof Interceptors].add(mainHook);\n\t\t}\n\t};\n\n\tconst addPluginHooks = (pluginHooks: InterceptorsOrInterceptorArray) => {\n\t\tfor (const key of Object.keys(hooksEnum)) {\n\t\t\tconst pluginHook = pluginHooks[key as keyof Interceptors] as never;\n\n\t\t\thookRegistries[key as keyof Interceptors].add(pluginHook);\n\t\t}\n\t};\n\n\tif (options.mergedHooksExecutionOrder === \"mainHooksBeforePlugins\") {\n\t\taddMainHooks();\n\t}\n\n\tconst getPluginArray = (plugins: ExtraOptions[\"plugins\"]) => {\n\t\tif (!plugins) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn isFunction(plugins) ? plugins({ initURL, options, request }) : plugins;\n\t};\n\n\tconst resolvedPlugins = [\n\t\t...getPluginArray(options.plugins),\n\t\t...getPluginArray(options.extend?.plugins),\n\t];\n\n\tlet resolvedUrl = initURL;\n\tlet resolvedOptions = options;\n\tlet resolvedRequestOptions = request;\n\n\tconst executePluginInit = async (pluginInit: CallApiPlugin[\"init\"]) => {\n\t\tif (!pluginInit) return;\n\n\t\tconst initResult = await pluginInit({ initURL, options, request });\n\n\t\tif (!isPlainObject(initResult)) return;\n\n\t\tif (isString(initResult.initURL)) {\n\t\t\tresolvedUrl = initResult.initURL;\n\t\t}\n\n\t\tif (isPlainObject(initResult.request)) {\n\t\t\tresolvedRequestOptions = initResult.request;\n\t\t}\n\n\t\tif (isPlainObject(initResult.options)) {\n\t\t\tresolvedOptions = initResult.options;\n\t\t}\n\t};\n\n\tfor (const plugin of resolvedPlugins) {\n\t\t// eslint-disable-next-line no-await-in-loop -- Await is necessary in this case.\n\t\tawait executePluginInit(plugin.init);\n\n\t\tif (!plugin.hooks) continue;\n\n\t\taddPluginHooks(plugin.hooks);\n\t}\n\n\tif (\n\t\t!options.mergedHooksExecutionOrder ||\n\t\toptions.mergedHooksExecutionOrder === \"mainHooksAfterPlugins\"\n\t) {\n\t\taddMainHooks();\n\t}\n\n\tconst resolvedHooks = {} as Required<Interceptors>;\n\n\tfor (const [key, hookRegistry] of Object.entries(hookRegistries)) {\n\t\tconst flattenedHookArray = [...hookRegistry].flat();\n\n\t\tconst mergedHook = createMergedHook(flattenedHookArray, options.mergedHooksExecutionMode);\n\n\t\tresolvedHooks[key as keyof Interceptors] = mergedHook;\n\t}\n\n\treturn {\n\t\tresolvedHooks,\n\t\tresolvedOptions,\n\t\tresolvedRequestOptions,\n\t\turl: resolvedUrl,\n\t};\n};\n","import type { CallApiExtraOptions, CallApiRequestOptions } from \"./types\";\nimport { getFetchImpl } from \"./utils/common\";\n\nexport const generateDedupeKey = (\n\tfullURL: string,\n\trequest: CallApiRequestOptions,\n\toptions: CallApiExtraOptions\n) => {\n\tconst shouldHaveDedupeKey = options.dedupeStrategy === \"cancel\" || options.dedupeStrategy === \"defer\";\n\n\tif (!shouldHaveDedupeKey) {\n\t\treturn null;\n\t}\n\n\treturn `${options.fullURL}-${JSON.stringify({ options, request })}`;\n};\n\ntype RequestInfo = { controller: AbortController; responsePromise: Promise<Response> };\n\nexport type RequestInfoCache = Map<string | null, RequestInfo>;\n\nexport const handleRequestCancelDedupe = (\n\tfullURL: string,\n\toptions: CallApiExtraOptions,\n\tprevRequestInfo: RequestInfo | undefined\n) => {\n\tconst shouldCancelRequest = prevRequestInfo && options.dedupeStrategy === \"cancel\";\n\n\tif (shouldCancelRequest) {\n\t\tconst message = options.dedupeKey\n\t\t\t? `Duplicate request detected - Aborting previous request with key '${options.dedupeKey}' as a new request was initiated`\n\t\t\t: `Duplicate request detected - Aborting previous request to '${options.fullURL}' as a new request with identical options was initiated`;\n\n\t\tconst reason = new DOMException(message, \"AbortError\");\n\n\t\tprevRequestInfo.controller.abort(reason);\n\t}\n};\n\nexport const handleRequestDeferDedupe = (\n\tfullURL: string,\n\toptions: CallApiExtraOptions,\n\trequest: CallApiRequestOptions,\n\tprevRequestInfo: RequestInfo | undefined\n) => {\n\tconst fetchApi = getFetchImpl(options.customFetchImpl);\n\n\tconst shouldUsePromiseFromCache = prevRequestInfo && options.dedupeStrategy === \"defer\";\n\n\tconst responsePromise = shouldUsePromiseFromCache\n\t\t? prevRequestInfo.responsePromise\n\t\t: fetchApi(fullURL, request as RequestInit);\n\n\treturn responsePromise;\n};\n","/* eslint-disable ts-eslint/consistent-type-definitions -- I need to use interfaces for the sake of user overrides */\n\nimport type { ErrorContext } from \"./types\";\nimport type { AnyNumber, AnyString } from \"./utils/type-helpers\";\n\ntype RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => boolean | Promise<boolean>;\n\nexport interface RetryOptions<TErrorData> {\n\t/**\n\t * @description Number of allowed retry attempts on HTTP errors\n\t * @default 0\n\t */\n\tretryAttempts?: number;\n\n\t/**\n\t * @description Callback whose return value determines if a request should be retried or not\n\t */\n\tretryCondition?: RetryCondition<TErrorData>;\n\n\t/**\n\t * @description Keeps track of the number of times the request has already been retried\n\t */\n\tretryCount?: number;\n\n\t/**\n\t * @description Delay between retries in milliseconds\n\t * @default 1000\n\t */\n\tretryDelay?: number;\n\n\t/**\n\t * @description Maximum delay in milliseconds. Only applies to exponential strategy\n\t * @default 10000\n\t */\n\tretryMaxDelay?: number;\n\n\t/**\n\t * HTTP methods that are allowed to retry\n\t * @default [\"GET\", \"POST\"]\n\t */\n\tretryMethods?: Array<\"GET\" | \"POST\" | AnyString>;\n\n\t/**\n\t * @description HTTP status codes that trigger a retry\n\t * @default [409, 425, 429, 500, 502, 503, 504]\n\t */\n\tretryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;\n\n\t/**\n\t * @description Strategy to use when retrying\n\t * @default \"linear\"\n\t */\n\tretryStrategy?: \"exponential\" | \"linear\";\n}\n\nconst getLinearDelay = <TErrorData>(options: RetryOptions<TErrorData>) => options.retryDelay ?? 1000;\n\nconst getExponentialDelay = <TErrorData>(\n\tcurrentAttemptCount: number,\n\toptions: RetryOptions<TErrorData>\n) => {\n\tconst maxDelay = options.retryMaxDelay ?? 10000;\n\n\tconst exponentialDelay = (options.retryDelay ?? 1000) * 2 ** currentAttemptCount;\n\n\treturn Math.min(exponentialDelay, maxDelay);\n};\n\nexport const createRetryStrategy = <TErrorData>(\n\toptions: RetryOptions<TErrorData>,\n\tctx: ErrorContext<TErrorData>\n) => {\n\tconst currentRetryCount = options.retryCount ?? 0;\n\n\treturn {\n\t\tgetDelay: () => {\n\t\t\tif (options.retryStrategy === \"exponential\") {\n\t\t\t\treturn getExponentialDelay(currentRetryCount, options);\n\t\t\t}\n\n\t\t\treturn getLinearDelay(options);\n\t\t},\n\n\t\tshouldAttemptRetry: async () => {\n\t\t\tconst customRetryCondition = (await options.retryCondition?.(ctx)) ?? true;\n\n\t\t\tconst maxRetryAttempts = options.retryAttempts ?? 0;\n\n\t\t\tconst baseRetryCondition = maxRetryAttempts > currentRetryCount && customRetryCondition;\n\n\t\t\tif (ctx.error.name !== \"HTTPError\") {\n\t\t\t\treturn baseRetryCondition;\n\t\t\t}\n\n\t\t\tconst includesMethod =\n\t\t\t\t// eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow\n\t\t\t\t!!ctx.request.method && options.retryMethods?.includes(ctx.request.method);\n\n\t\t\tconst includesCodes =\n\t\t\t\t// eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow\n\t\t\t\t!!ctx.response?.status && options.retryStatusCodes?.includes(ctx.response.status);\n\n\t\t\treturn includesCodes && includesMethod && baseRetryCondition;\n\t\t},\n\t};\n};\n","import type { CallApiConfig, CallApiExtraOptions } from \"./types\";\nimport { toQueryString } from \"./utils\";\nimport { isArray } from \"./utils/type-guards\";\n\nconst slash = \"/\";\nconst column = \":\";\nconst mergeUrlWithParams = (url: string, params: CallApiExtraOptions[\"params\"]) => {\n\tif (!params) {\n\t\treturn url;\n\t}\n\n\tlet newUrl = url;\n\n\tif (isArray(params)) {\n\t\tconst matchedParamArray = newUrl.split(slash).filter((param) => param.startsWith(column));\n\n\t\tfor (const [index, matchedParam] of matchedParamArray.entries()) {\n\t\t\tconst realParam = params[index] as string;\n\t\t\tnewUrl = newUrl.replace(matchedParam, realParam);\n\t\t}\n\n\t\treturn newUrl;\n\t}\n\n\tfor (const [key, value] of Object.entries(params)) {\n\t\tnewUrl = newUrl.replace(`${column}${key}`, String(value));\n\t}\n\n\treturn newUrl;\n};\n\nconst questionMark = \"?\";\nconst ampersand = \"&\";\nconst mergeUrlWithQuery = (url: string, query: CallApiConfig[\"query\"]): string => {\n\tif (!query) {\n\t\treturn url;\n\t}\n\n\tconst queryString = toQueryString(query);\n\n\tif (queryString?.length === 0) {\n\t\treturn url;\n\t}\n\n\tif (url.endsWith(questionMark)) {\n\t\treturn `${url}${queryString}`;\n\t}\n\n\tif (url.includes(questionMark)) {\n\t\treturn `${url}${ampersand}${queryString}`;\n\t}\n\n\treturn `${url}${questionMark}${queryString}`;\n};\n\nexport const mergeUrlWithParamsAndQuery = (\n\turl: string,\n\tparams: CallApiExtraOptions[\"params\"],\n\tquery: CallApiExtraOptions[\"query\"]\n) => {\n\tconst urlWithMergedParams = mergeUrlWithParams(url, params);\n\n\treturn mergeUrlWithQuery(urlWithMergedParams, query);\n};\n","// prettier-ignore\nexport const createCombinedSignal = (...signals: Array<AbortSignal | null | undefined>) => AbortSignal.any(signals.filter(Boolean));\n\nexport const createTimeoutSignal = (milliseconds: number) => AbortSignal.timeout(milliseconds);\n","import {\n\ttype RequestInfoCache,\n\tgenerateDedupeKey,\n\thandleRequestCancelDedupe,\n\thandleRequestDeferDedupe,\n} from \"./dedupe\";\nimport { hooksEnum, initializePlugins } from \"./plugins\";\nimport { createRetryStrategy } from \"./retry\";\nimport type {\n\tBaseCallApiConfig,\n\tCallApiConfig,\n\tCallApiParameters,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n\tCombinedCallApiExtraOptions,\n\tDefaultDataType,\n\tDefaultMoreOptions,\n\tGetCallApiResult,\n\tInterceptors,\n\tPossibleHTTPError,\n\tPossibleJavaScriptError,\n\tResultModeUnion,\n} from \"./types\";\nimport { mergeUrlWithParamsAndQuery } from \"./url\";\nimport {\n\tHTTPError,\n\tcombineHooks,\n\texecuteHooks,\n\tgetResponseData,\n\tisHTTPErrorInstance,\n\tmergeAndResolveHeaders,\n\tresolveErrorResult,\n\tresolveSuccessResult,\n\tsplitBaseConfig,\n\tsplitConfig,\n\twaitUntil,\n} from \"./utils/common\";\nimport { defaultRetryMethods, defaultRetryStatusCodes } from \"./utils/constants\";\nimport { createCombinedSignal, createTimeoutSignal } from \"./utils/polyfills\";\nimport { isFunction, isPlainObject } from \"./utils/type-guards\";\nimport type { AnyObject } from \"./utils/type-helpers\";\n\nexport const createFetchClient = <\n\tTBaseData = DefaultDataType,\n\tTBaseErrorData = DefaultDataType,\n\tTBaseResultMode extends ResultModeUnion = ResultModeUnion,\n\tTBaseMoreOptions extends AnyObject = DefaultMoreOptions,\n>(\n\tbaseConfig: BaseCallApiConfig<\n\t\tTBaseData,\n\t\tTBaseErrorData,\n\t\tTBaseResultMode,\n\t\tTBaseMoreOptions\n\t> = {} as never\n) => {\n\tconst [baseFetchConfig, baseExtraOptions] = splitBaseConfig(baseConfig);\n\n\tconst {\n\t\tbody: baseBody,\n\t\theaders: baseHeaders,\n\t\tsignal: baseSignal,\n\t\t...restOfBaseFetchConfig\n\t} = baseFetchConfig;\n\n\tconst $RequestInfoCache = new Map() satisfies RequestInfoCache;\n\n\tconst callApi = async <\n\t\tTData = TBaseData,\n\t\tTErrorData = TBaseErrorData,\n\t\tTResultMode extends ResultModeUnion = TBaseResultMode,\n\t\tTMoreOptions extends AnyObject = TBaseMoreOptions,\n\t>(\n\t\t...parameters: CallApiParameters<TData, TErrorData, TResultMode, TMoreOptions>\n\t): Promise<GetCallApiResult<TData, TErrorData, TResultMode>> => {\n\t\tconst [initURL, config = {}] = parameters;\n\n\t\tconst [fetchConfig, extraOptions] = splitConfig(config);\n\n\t\tconst { body = baseBody, headers, signal = baseSignal, ...restOfFetchConfig } = fetchConfig;\n\n\t\tconst initCombinedHooks = {} as Required<Interceptors>;\n\n\t\tfor (const key of Object.keys(hooksEnum)) {\n\t\t\tconst combinedHook = combineHooks(\n\t\t\t\tbaseExtraOptions[key as keyof Interceptors],\n\t\t\t\textraOptions[key as keyof Interceptors]\n\t\t\t);\n\n\t\t\tinitCombinedHooks[key as keyof Interceptors] = combinedHook as never;\n\t\t}\n\n\t\t// == Default Extra Options\n\t\tconst defaultExtraOptions = {\n\t\t\tbaseURL: \"\",\n\t\t\tbodySerializer: JSON.stringify,\n\t\t\tdedupeStrategy: \"cancel\",\n\t\t\tdefaultErrorMessage: \"Failed to fetch data from server!\",\n\t\t\tmergedHooksExecutionMode: \"parallel\",\n\t\t\tmergedHooksExecutionOrder: \"mainHooksAfterPlugins\",\n\t\t\tresponseType: \"json\",\n\t\t\tresultMode: \"all\",\n\t\t\tretryAttempts: 0,\n\t\t\tretryDelay: 1000,\n\t\t\tretryMaxDelay: 10000,\n\t\t\tretryMethods: defaultRetryMethods,\n\t\t\tretryStatusCodes: defaultRetryStatusCodes,\n\t\t\tretryStrategy: \"linear\",\n\n\t\t\t...baseExtraOptions,\n\t\t\t...extraOptions,\n\n\t\t\t...initCombinedHooks,\n\t\t} satisfies CombinedCallApiExtraOptions;\n\n\t\tconst { resolvedHooks, resolvedOptions, resolvedRequestOptions, url } = await initializePlugins({\n\t\t\tinitURL,\n\t\t\toptions: defaultExtraOptions,\n\t\t\trequest: { ...restOfBaseFetchConfig, ...restOfFetchConfig },\n\t\t});\n\n\t\tconst fullURL = `${resolvedOptions.baseURL}${mergeUrlWithParamsAndQuery(url, resolvedOptions.params, resolvedOptions.query)}`;\n\n\t\tconst options = {\n\t\t\t...resolvedOptions,\n\t\t\t...resolvedHooks,\n\t\t\tfullURL,\n\t\t\tinitURL,\n\t\t} satisfies CombinedCallApiExtraOptions as typeof defaultExtraOptions & typeof resolvedHooks;\n\n\t\t// == Default Request Options\n\t\tconst defaultRequestOptions = {\n\t\t\tbody: isPlainObject(body) ? options.bodySerializer(body) : body,\n\t\t\tmethod: \"GET\",\n\n\t\t\t...resolvedRequestOptions,\n\t\t} satisfies CallApiRequestOptions;\n\n\t\tconst newFetchController = new AbortController();\n\n\t\tconst timeoutSignal = options.timeout != null ? createTimeoutSignal(options.timeout) : null;\n\n\t\tconst combinedSignal = createCombinedSignal(newFetchController.signal, timeoutSignal, signal);\n\n\t\tconst request = {\n\t\t\tsignal: combinedSignal,\n\t\t\t...defaultRequestOptions,\n\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\tconst dedupeKey = options.dedupeKey ?? generateDedupeKey(fullURL, request, options);\n\n\t\t// == Add a small delay to ensure proper request deduplication when multiple requests with the same key start simultaneously.\n\t\t// == This gives time for the cache to be updated with the previous request info before the next request checks it.\n\t\tdedupeKey !== null && (await waitUntil(0.1));\n\n\t\t// == This ensures cache operations only occur when key is available\n\t\tconst $RequestInfoCacheOrNull = dedupeKey !== null ? $RequestInfoCache : null;\n\n\t\tconst prevRequestInfo = $RequestInfoCacheOrNull?.get(dedupeKey);\n\n\t\thandleRequestCancelDedupe(fullURL, options, prevRequestInfo);\n\n\t\ttry {\n\t\t\tawait executeHooks(options.onRequest({ options, request }));\n\n\t\t\t// == Apply determined headers after onRequest incase they were modified\n\t\t\trequest.headers = mergeAndResolveHeaders({\n\t\t\t\tauth: options.auth,\n\t\t\t\tbaseHeaders: baseHeaders ?? headers,\n\t\t\t\tbody,\n\t\t\t\theaders: request.headers,\n\t\t\t});\n\n\t\t\tconst responsePromise = handleRequestDeferDedupe(fullURL, options, request, prevRequestInfo);\n\n\t\t\t$RequestInfoCacheOrNull?.set(dedupeKey, { controller: newFetchController, responsePromise });\n\n\t\t\tconst response = await responsePromise;\n\n\t\t\t// == Also clone response when dedupeStrategy is set to \"defer\", to avoid error thrown from reading response.(whatever) more than once\n\t\t\tconst shouldCloneResponse = options.dedupeStrategy === \"defer\" || options.cloneResponse;\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst errorData = await getResponseData<TErrorData>(\n\t\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\t\toptions.responseType,\n\t\t\t\t\toptions.responseParser,\n\t\t\t\t\toptions.responseErrorValidator\n\t\t\t\t);\n\n\t\t\t\t// == Push all error handling responsibilities to the catch block if not retrying\n\t\t\t\tthrow new HTTPError({\n\t\t\t\t\tdefaultErrorMessage: options.defaultErrorMessage,\n\t\t\t\t\terrorData,\n\t\t\t\t\tresponse,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst successData = await getResponseData<TData>(\n\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\toptions.responseType,\n\t\t\t\toptions.responseParser,\n\t\t\t\toptions.responseValidator\n\t\t\t);\n\n\t\t\tawait executeHooks(\n\t\t\t\toptions.onSuccess({\n\t\t\t\t\tdata: successData as never,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t\tresponse: options.cloneResponse ? response.clone() : response,\n\t\t\t\t}),\n\n\t\t\t\toptions.onResponse({\n\t\t\t\t\tdata: successData,\n\t\t\t\t\terror: null,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t\tresponse: options.cloneResponse ? response.clone() : response,\n\t\t\t\t})\n\t\t\t);\n\n\t\t\treturn await resolveSuccessResult({\n\t\t\t\tdata: successData,\n\t\t\t\tresponse,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t});\n\n\t\t\t// == Exhaustive Error handling\n\t\t} catch (error) {\n\t\t\tconst { apiDetails, generalErrorResult, resolveCustomErrorInfo } = resolveErrorResult({\n\t\t\t\tdefaultErrorMessage: options.defaultErrorMessage,\n\t\t\t\terror,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t});\n\n\t\t\tconst errorContext = {\n\t\t\t\terror: apiDetails.error as never,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse: apiDetails.response,\n\t\t\t};\n\n\t\t\tconst { getDelay, shouldAttemptRetry } = createRetryStrategy(options, errorContext);\n\n\t\t\tconst shouldRetry = !combinedSignal.aborted && (await shouldAttemptRetry());\n\n\t\t\tif (shouldRetry) {\n\t\t\t\tawait executeHooks(options.onRetry(errorContext));\n\n\t\t\t\tconst delay = getDelay();\n\n\t\t\t\tawait waitUntil(delay);\n\n\t\t\t\tconst updatedOptions = {\n\t\t\t\t\t...config,\n\t\t\t\t\tretryCount: (options.retryCount ?? 0) + 1,\n\t\t\t\t} satisfies CallApiConfig<TData, TErrorData, TResultMode>;\n\n\t\t\t\treturn await callApi(initURL, updatedOptions);\n\t\t\t}\n\n\t\t\tconst shouldThrowOnError = isFunction(options.throwOnError)\n\t\t\t\t? options.throwOnError(errorContext)\n\t\t\t\t: options.throwOnError;\n\n\t\t\t// eslint-disable-next-line unicorn/consistent-function-scoping -- False alarm: this function is depends on this scope\n\t\t\tconst handleThrowOnError = () => {\n\t\t\t\tif (!shouldThrowOnError) return;\n\n\t\t\t\t// eslint-disable-next-line ts-eslint/only-throw-error -- It's fine to throw this\n\t\t\t\tthrow apiDetails.error;\n\t\t\t};\n\n\t\t\tif (isHTTPErrorInstance<TErrorData>(error)) {\n\t\t\t\tconst { response } = error;\n\n\t\t\t\tconst possibleHttpError = (generalErrorResult as { error: PossibleHTTPError<TErrorData> })\n\t\t\t\t\t.error;\n\n\t\t\t\tawait executeHooks(\n\t\t\t\t\toptions.onResponseError({\n\t\t\t\t\t\terror: possibleHttpError,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\trequest,\n\t\t\t\t\t\tresponse: options.cloneResponse ? response.clone() : response,\n\t\t\t\t\t}),\n\n\t\t\t\t\toptions.onError({\n\t\t\t\t\t\terror: possibleHttpError,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\trequest,\n\t\t\t\t\t\tresponse: options.cloneResponse ? response.clone() : response,\n\t\t\t\t\t}),\n\n\t\t\t\t\toptions.onResponse({\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: possibleHttpError,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\trequest,\n\t\t\t\t\t\tresponse: options.cloneResponse ? response.clone() : response,\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\thandleThrowOnError();\n\n\t\t\t\treturn generalErrorResult;\n\t\t\t}\n\n\t\t\tif (error instanceof DOMException && error.name === \"AbortError\") {\n\t\t\t\tconst { message, name } = error;\n\n\t\t\t\tconsole.error(`${name}:`, message);\n\n\t\t\t\thandleThrowOnError();\n\n\t\t\t\treturn generalErrorResult;\n\t\t\t}\n\n\t\t\tif (error instanceof DOMException && error.name === \"TimeoutError\") {\n\t\t\t\tconst message = `Request timed out after ${options.timeout}ms`;\n\n\t\t\t\tconsole.error(`${error.name}:`, message);\n\n\t\t\t\thandleThrowOnError();\n\n\t\t\t\treturn resolveCustomErrorInfo({ message });\n\t\t\t}\n\n\t\t\tconst possibleJavascriptError = (generalErrorResult as { error: PossibleJavaScriptError }).error;\n\n\t\t\tawait executeHooks(\n\t\t\t\t// == At this point only the request errors exist, so the request error interceptor is called\n\t\t\t\toptions.onRequestError({\n\t\t\t\t\terror: possibleJavascriptError,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t}),\n\n\t\t\t\t// == Also call the onError interceptor\n\t\t\t\toptions.onError({\n\t\t\t\t\terror: possibleJavascriptError,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t\tresponse: null,\n\t\t\t\t})\n\t\t\t);\n\n\t\t\thandleThrowOnError();\n\n\t\t\treturn generalErrorResult;\n\n\t\t\t// == Removing the now unneeded AbortController from store\n\t\t} finally {\n\t\t\t$RequestInfoCacheOrNull?.delete(dedupeKey);\n\t\t}\n\t};\n\n\tcallApi.create = createFetchClient;\n\n\treturn callApi;\n};\n\nexport const callApi = createFetchClient();\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=e=>Array.isArray(e),r=e=>{if(!(e=>"object"==typeof e&&null!==e)(e))return!1;const r=Object.getPrototypeOf(e);return(null==r||r===Object.prototype||null===Object.getPrototypeOf(r))&&!(Symbol.toStringTag in e)},t=e=>"function"==typeof e,o=e=>"string"==typeof e,n=e=>t(e)?e():e,s=e=>{if(void 0!==e){if(o(e)||null===e)return{Authorization:`Bearer ${e}`};switch(e.type){case"Basic":{const r=n(e.username),t=n(e.password);if(void 0===r||void 0===t)return;return{Authorization:`Basic ${globalThis.btoa(`${r}:${t}`)}`}}case"Custom":{const r=n(e.value);if(void 0===r)return;return{Authorization:`${n(e.prefix)} ${r}`}}default:{const r=n(e.bearer),t=n(e.token);return"token"in e&&void 0!==t?{Authorization:`Token ${t}`}:void 0!==r&&{Authorization:`Bearer ${r}`}}}}},a=["extend","dedupeKey"],i=["body","integrity","method","headers","signal","cache","redirect","window","credentials","keepalive","referrer","priority","mode","referrerPolicy"],l={408:"Request Timeout",409:"Conflict",425:"Too Early",429:"Too Many Requests",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout"},c=["GET","POST"],u=Object.keys(l).map(Number),p=(e,r)=>{const t={},o=new Set(r);for(const[r,n]of Object.entries(e))o.has(r)||(t[r]=n);return t},f=(e,r)=>{const t={},o=new Set(r);for(const[r,n]of Object.entries(e))o.has(r)&&(t[r]=n);return t},d=e=>[f(e,i),p(e,[...i,...a])],y=e=>[f(e,i),p(e,i)],m=e=>!e||r(e)?e:Object.fromEntries(e),h=e=>e?new URLSearchParams(e).toString():(console.error("toQueryString:","No query params provided!"),null),b=e=>{const{auth:t,baseHeaders:n,body:a,headers:i}=e;if(!Boolean(n||i||a||t))return;const l={...s(t),...m(n),...m(i)};return o(c=a)&&c.includes("=")?(l["Content-Type"]="application/x-www-form-urlencoded",l):((r(a)||o(a)&&a.startsWith("{"))&&(l["Content-Type"]="application/json",l.Accept="application/json"),l);var c},T=(r,t)=>e(r)?[r,t].flat():t??r,g=e=>{if(e)return e;if("undefined"!=typeof globalThis&&t(globalThis.fetch))return globalThis.fetch;throw new Error("No fetch implementation found")},E=(...e)=>Promise.all(e),w=async(e,r,t,o)=>{const n=((e,r)=>({arrayBuffer:()=>e.arrayBuffer(),blob:()=>e.blob(),formData:()=>e.formData(),json:async()=>{if(r){const t=await e.text();return r(t)}return e.json()},stream:()=>e.body,text:()=>e.text()}))(e,t);if(!Object.hasOwn(n,r))throw new Error(`Invalid response type: ${r}`);const s=await n[r]();return o?o(s):s},v=e=>{const{data:r,response:t,resultMode:o}=e,n={data:r,error:null,response:t};if(!o)return n;return{all:n,onlyError:n.error,onlyResponse:n.response,onlySuccess:n.data,onlySuccessWithException:n.data}[o]},S=e=>{const{defaultErrorMessage:r,error:t,message:o,resultMode:n}=e;let s={data:null,error:{errorData:t,message:o??t.message,name:t.name},response:null};if(P(t)){const{errorData:e,message:o=r,name:n,response:a}=t;s={data:null,error:{errorData:e,message:o,name:n},response:a}}return{apiDetails:s,generalErrorResult:{all:s,onlyError:s.error,onlyResponse:s.response,onlySuccess:s.data,onlySuccessWithException:s.data}[n??"all"],resolveCustomErrorInfo:({message:r})=>S({...e,message:r}).generalErrorResult}},j=e=>r(e)&&"HTTPError"===e.name,O=class extends Error{errorData;isHTTPError=!0;name="HTTPError";response;constructor(e,r){const{defaultErrorMessage:t,errorData:o,response:n}=e;super(o?.message??t,r),this.errorData=o,this.response=n,Error.captureStackTrace(this,this.constructor)}},P=e=>e instanceof O||r(e)&&"HTTPError"===e.name&&!0===e.isHTTPError,x=e=>{if(0===e)return;const{promise:r,resolve:t}=(()=>{let e,r;return{promise:new Promise(((t,o)=>{r=t,e=o})),reject:e,resolve:r}})();return setTimeout(t,e),r};export{O as HTTPError,T as combineHooks,c as defaultRetryMethods,u as defaultRetryStatusCodes,E as executeHooks,g as getFetchImpl,w as getResponseData,e as isArray,t as isFunction,j as isHTTPError,P as isHTTPErrorInstance,r as isPlainObject,o as isString,b as mergeAndResolveHeaders,S as resolveErrorResult,v as resolveSuccessResult,d as splitBaseConfig,y as splitConfig,h as toQueryString,x as waitUntil};//# sourceMappingURL=chunk-OCGFLXP6.js.map
|