@zayne-labs/callapi 1.6.16 → 1.6.18

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.
@@ -115,77 +115,25 @@ interface CallApiValidators<TData = unknown, TErrorData = unknown> {
115
115
  }
116
116
  type InferSchemaResult<TSchema, TData> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TData;
117
117
 
118
- /**
119
- * @description Makes a type required if TSchema type is undefined or if the output type of TSchema contains undefined, otherwise keeps it as is
120
- */
121
- type MakeSchemaOptionRequired<TSchema extends StandardSchemaV1 | undefined, TObject> = undefined extends TSchema ? TObject : undefined extends InferSchemaResult<TSchema, NonNullable<unknown>> ? TObject : Required<TObject>;
122
- type JsonPrimitive = boolean | number | string | null | undefined;
123
- type SerializableObject = Record<keyof object, unknown>;
124
- type SerializableArray = Array<JsonPrimitive | SerializableArray | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableArray | SerializableObject>;
125
- type Body = UnmaskType<RequestInit["body"] | SerializableArray | SerializableObject>;
126
- type BodyOption<TSchemas extends CallApiSchemas> = MakeSchemaOptionRequired<TSchemas["body"], {
118
+ type Params = UnmaskType<Record<string, boolean | number | string> | Array<boolean | number | string>>;
119
+ type Query = UnmaskType<Record<string, boolean | number | string>>;
120
+ type InitURL = UnmaskType<string | URL>;
121
+ interface UrlOptions<TSchemas extends CallApiSchemas> {
127
122
  /**
128
- * Body of the request, can be a object or any other supported body type.
123
+ * URL to be used in the request.
129
124
  */
130
- body?: InferSchemaResult<TSchemas["body"], Body>;
131
- }>;
132
- type Method = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
133
- type MethodOption<TSchemas extends CallApiSchemas> = MakeSchemaOptionRequired<TSchemas["method"], {
125
+ readonly initURL?: string;
134
126
  /**
135
- * HTTP method for the request.
136
- * @default "GET"
127
+ * Parameters to be appended to the URL (i.e: /:id)
137
128
  */
138
- method?: InferSchemaResult<TSchemas["method"], Method>;
139
- }>;
140
- type Headers = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | RequestInit["headers"]>;
141
- type HeadersOption<TSchemas extends CallApiSchemas> = MakeSchemaOptionRequired<TSchemas["headers"], {
129
+ params?: InferSchemaResult<TSchemas["params"], Params>;
142
130
  /**
143
- * Headers to be used in the request.
131
+ * Query parameters to append to the URL.
144
132
  */
145
- headers?: InferSchemaResult<TSchemas["headers"], Headers>;
146
- }>;
147
- interface Register {
133
+ query?: InferSchemaResult<TSchemas["query"], Query>;
148
134
  }
149
- type GlobalMeta = Register extends {
150
- meta?: infer TMeta extends Record<string, unknown>;
151
- } ? TMeta : never;
152
- type MetaOption<TSchemas extends CallApiSchemas> = {
153
- /**
154
- * - An optional field you can fill with additional information,
155
- * to associate with the request, typically used for logging or tracing.
156
- *
157
- * - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
158
- *
159
- * @example
160
- * ```ts
161
- * const callMainApi = callApi.create({
162
- * baseURL: "https://main-api.com",
163
- * onResponseError: ({ response, options }) => {
164
- * if (options.meta?.userId) {
165
- * console.error(`User ${options.meta.userId} made an error`);
166
- * }
167
- * },
168
- * });
169
- *
170
- * const response = await callMainApi({
171
- * url: "https://example.com/api/data",
172
- * meta: { userId: "123" },
173
- * });
174
- * ```
175
- */
176
- meta?: InferSchemaResult<TSchemas["meta"], GlobalMeta>;
177
- };
178
- type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorData extends false ? {
179
- resultMode: "onlySuccessWithException";
180
- } : TErrorData extends false | undefined ? {
181
- resultMode?: "onlySuccessWithException";
182
- } : undefined extends TResultMode ? {
183
- resultMode?: TResultMode;
184
- } : {
185
- resultMode: TResultMode;
186
- };
187
135
 
188
- type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => boolean | Promise<boolean>;
136
+ type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;
189
137
  interface RetryOptions<TErrorData> {
190
138
  /**
191
139
  * Keeps track of the number of times the request has already been retried
@@ -215,12 +163,12 @@ interface RetryOptions<TErrorData> {
215
163
  * HTTP methods that are allowed to retry
216
164
  * @default ["GET", "POST"]
217
165
  */
218
- retryMethods?: Method[];
166
+ retryMethods?: Method[] | ((context: ErrorContext<TErrorData>) => Method[]);
219
167
  /**
220
168
  * HTTP status codes that trigger a retry
221
169
  * @default [409, 425, 429, 500, 502, 503, 504]
222
170
  */
223
- retryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;
171
+ retryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber> | ((context: ErrorContext<TErrorData>) => Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>);
224
172
  /**
225
173
  * Strategy to use when retrying
226
174
  * @default "linear"
@@ -255,6 +203,7 @@ type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersect
255
203
  type PluginInitContext<TMoreOptions = DefaultMoreOptions> = WithMoreOptions<TMoreOptions> & {
256
204
  baseConfig: BaseCallApiExtraOptions & CallApiRequestOptions;
257
205
  config: CallApiExtraOptions & CallApiRequestOptions;
206
+ defaultOptions: CallApiExtraOptions;
258
207
  initURL: InitURL | undefined;
259
208
  options: CombinedCallApiExtraOptions;
260
209
  request: CallApiRequestOptionsForHooks;
@@ -296,8 +245,76 @@ declare const definePlugin: <TPlugin extends CallApiPlugin | AnyFunction<CallApi
296
245
  type Plugins<TPluginArray extends CallApiPlugin[]> = TPluginArray;
297
246
 
298
247
  declare const fetchSpecificKeys: ("body" | "cache" | "credentials" | "headers" | "integrity" | "keepalive" | "method" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window")[];
299
- declare const defaultRetryMethods: ("GET" | "POST")[];
300
- declare const defaultRetryStatusCodes: Required<BaseCallApiExtraOptions>["retryStatusCodes"];
248
+
249
+ /**
250
+ * @description Makes a type required if TSchema type is undefined or if the output type of TSchema contains undefined, otherwise keeps it as is
251
+ */
252
+ type MakeSchemaOptionRequired<TSchema extends StandardSchemaV1 | undefined, TObject> = undefined extends TSchema ? TObject : undefined extends InferSchemaResult<TSchema, NonNullable<unknown>> ? TObject : Required<TObject>;
253
+ type JsonPrimitive = boolean | number | string | null | undefined;
254
+ type SerializableObject = Record<keyof object, unknown>;
255
+ type SerializableArray = Array<JsonPrimitive | SerializableArray | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableArray | SerializableObject>;
256
+ type Body = UnmaskType<RequestInit["body"] | SerializableArray | SerializableObject>;
257
+ type BodyOption<TSchemas extends CallApiSchemas> = MakeSchemaOptionRequired<TSchemas["body"], {
258
+ /**
259
+ * Body of the request, can be a object or any other supported body type.
260
+ */
261
+ body?: InferSchemaResult<TSchemas["body"], Body>;
262
+ }>;
263
+ type Method = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
264
+ type MethodOption<TSchemas extends CallApiSchemas> = MakeSchemaOptionRequired<TSchemas["method"], {
265
+ /**
266
+ * HTTP method for the request.
267
+ * @default "GET"
268
+ */
269
+ method?: InferSchemaResult<TSchemas["method"], Method>;
270
+ }>;
271
+ type Headers = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | RequestInit["headers"]>;
272
+ type HeadersOption<TSchemas extends CallApiSchemas> = MakeSchemaOptionRequired<TSchemas["headers"], {
273
+ /**
274
+ * Headers to be used in the request.
275
+ */
276
+ headers?: InferSchemaResult<TSchemas["headers"], Headers>;
277
+ }>;
278
+ interface Register {
279
+ }
280
+ type GlobalMeta = Register extends {
281
+ meta?: infer TMeta extends Record<string, unknown>;
282
+ } ? TMeta : never;
283
+ type MetaOption<TSchemas extends CallApiSchemas> = {
284
+ /**
285
+ * - An optional field you can fill with additional information,
286
+ * to associate with the request, typically used for logging or tracing.
287
+ *
288
+ * - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * const callMainApi = callApi.create({
293
+ * baseURL: "https://main-api.com",
294
+ * onResponseError: ({ response, options }) => {
295
+ * if (options.meta?.userId) {
296
+ * console.error(`User ${options.meta.userId} made an error`);
297
+ * }
298
+ * },
299
+ * });
300
+ *
301
+ * const response = await callMainApi({
302
+ * url: "https://example.com/api/data",
303
+ * meta: { userId: "123" },
304
+ * });
305
+ * ```
306
+ */
307
+ meta?: InferSchemaResult<TSchemas["meta"], GlobalMeta>;
308
+ };
309
+ type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorData extends false ? {
310
+ resultMode: "onlySuccessWithException";
311
+ } : TErrorData extends false | undefined ? {
312
+ resultMode?: "onlySuccessWithException";
313
+ } : undefined extends TResultMode ? {
314
+ resultMode?: TResultMode;
315
+ } : {
316
+ resultMode: TResultMode;
317
+ };
301
318
 
302
319
  type FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], "body" | "headers" | "method">;
303
320
  type CallApiRequestOptions<TSchemas extends CallApiSchemas = DefaultMoreOptions> = BodyOption<TSchemas> & HeadersOption<TSchemas> & MethodOption<TSchemas> & Pick<RequestInit, FetchSpecificKeysUnion>;
@@ -448,13 +465,15 @@ declare const optionsEnumToOmitFromBase: ("dedupeKey" | "extend")[];
448
465
  type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions> = Omit<Partial<CallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>>, (typeof optionsEnumToOmitFromBase)[number]>;
449
466
  type CombinedCallApiExtraOptions = BaseCallApiExtraOptions & CallApiExtraOptions;
450
467
  type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions> = (CallApiRequestOptions<TBaseSchemas> & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>) | ((context: {
468
+ defaultOptions: CallApiExtraOptions;
451
469
  initURL: string;
452
470
  options: CallApiExtraOptions;
453
471
  request: CallApiRequestOptions;
454
472
  }) => CallApiRequestOptions<TBaseSchemas> & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>);
473
+ type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = DefaultMoreOptions> = CallApiRequestOptions<TSchemas> & CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>;
455
474
  type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = DefaultMoreOptions> = [
456
475
  initURL: InferSchemaResult<TSchemas["initURL"], InitURL>,
457
- config?: CallApiRequestOptions<TSchemas> & CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>
476
+ config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>
458
477
  ];
459
478
  type RequestContext = UnmaskType<{
460
479
  options: CombinedCallApiExtraOptions;
@@ -539,24 +558,7 @@ type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TRespo
539
558
  }>;
540
559
  type ResultModeUnion = keyof ResultModeMap | undefined;
541
560
  type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = TErrorData extends false | undefined ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : ResultModeUnion | undefined extends TResultMode ? TThrowOnError extends true ? ResultModeMap<TData, TErrorData, TResponseType>["allWithException"] : ResultModeMap<TData, TErrorData, TResponseType>["all"] : TResultMode extends NonNullable<ResultModeUnion> ? TResultMode extends "onlySuccess" ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : TResultMode extends "onlyResponse" ? ResultModeMap<TData, TErrorData, TResponseType>["onlyResponseWithException"] : ResultModeMap<TData, TErrorData, TResponseType>[TResultMode] : never;
542
-
543
- type Params = UnmaskType<Record<string, boolean | number | string> | Array<boolean | number | string>>;
544
- type Query = UnmaskType<Record<string, boolean | number | string>>;
545
- type InitURL = UnmaskType<string | URL>;
546
- interface UrlOptions<TSchemas extends CallApiSchemas> {
547
- /**
548
- * URL to be used in the request.
549
- */
550
- readonly initURL?: string;
551
- /**
552
- * Parameters to be appended to the URL (i.e: /:id)
553
- */
554
- params?: InferSchemaResult<TSchemas["params"], Params>;
555
- /**
556
- * Query parameters to append to the URL.
557
- */
558
- query?: InferSchemaResult<TSchemas["query"], Query>;
559
- }
561
+ type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
560
562
 
561
563
  type ErrorDetails<TErrorResponse> = {
562
564
  defaultErrorMessage: string;
@@ -574,4 +576,4 @@ declare class HTTPError<TErrorResponse = Record<string, unknown>> extends Error
574
576
  constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
575
577
  }
576
578
 
577
- export { type AnyString as A, type BaseCallApiConfig as B, type CallApiPlugin as C, type DefaultPluginArray as D, type ExtraOptions as E, type Interceptors as F, type GetCallApiResult as G, HTTPError as H, type InferSchemaResult as I, type PossibleJavascriptErrorNames as J, type Register as K, type RequestContext as L, type MetaOption as M, type RequestErrorContext as N, type ResponseContext as O, type PossibleJavaScriptError as P, type ResponseErrorContext as Q, type ResultModeUnion as R, type SerializableArray as S, type SuccessContext as T, type UrlOptions as U, defaultRetryMethods as V, defaultRetryStatusCodes as W, type ResponseTypeUnion as a, type CallApiSchemas as b, type SerializableObject as c, type CommonContentTypes as d, type CommonRequestHeaders as e, type Auth as f, type Awaitable as g, type CombinedCallApiExtraOptions as h, type CallApiRequestOptionsForHooks as i, type CallApiValidators as j, type InterceptorsOrInterceptorArray as k, type RetryOptions as l, type ResultModeOption as m, type DefaultDataType as n, type DefaultThrowOnError as o, type DefaultMoreOptions as p, type CallApiParameters as q, definePlugin as r, type PluginInitContext as s, type BaseCallApiExtraOptions as t, type CallApiExtraOptions as u, type PossibleHTTPError as v, type CallApiRequestOptions as w, type CallApiResultErrorVariant as x, type CallApiResultSuccessVariant as y, type ErrorContext as z };
579
+ export { type ResponseErrorContext as A, type BaseCallApiConfig as B, type CallApiPlugin as C, type DefaultPluginArray as D, type ErrorContext as E, HTTPError as H, type InferSchemaResult as I, type PluginInitContext as P, type ResultModeUnion as R, type SuccessContext as S, type ResponseTypeUnion as a, type CallApiSchemas as b, type CallApiConfig as c, type CallApiResult as d, type DefaultDataType as e, type DefaultThrowOnError as f, type DefaultMoreOptions as g, type CallApiParameters as h, definePlugin as i, type RetryOptions as j, type BaseCallApiExtraOptions as k, type CallApiExtraOptions as l, type PossibleJavaScriptError as m, type PossibleHTTPError as n, type CallApiRequestOptions as o, type CallApiRequestOptionsForHooks as p, type CallApiResultErrorVariant as q, type CallApiResultSuccessVariant as r, type CombinedCallApiExtraOptions as s, type Interceptors as t, type InterceptorsOrInterceptorArray as u, type PossibleJavascriptErrorNames as v, type Register as w, type RequestContext as x, type RequestErrorContext as y, type ResponseContext as z };
@@ -1,118 +1,10 @@
1
- import { R as ResultModeUnion, a as ResponseTypeUnion, C as CallApiPlugin, D as DefaultPluginArray, b as CallApiSchemas, I as InferSchemaResult, S as SerializableArray, c as SerializableObject, d as CommonContentTypes, e as CommonRequestHeaders, A as AnyString, f as Auth, g as Awaitable, P as PossibleJavaScriptError, h as CombinedCallApiExtraOptions, i as CallApiRequestOptionsForHooks, j as CallApiValidators, k as InterceptorsOrInterceptorArray, M as MetaOption, l as RetryOptions, m as ResultModeOption, U as UrlOptions, E as ExtraOptions, G as GetCallApiResult, n as DefaultDataType, o as DefaultThrowOnError, p as DefaultMoreOptions, B as BaseCallApiConfig, q as CallApiParameters } from './error-BokQ-iQX.js';
2
- export { t as BaseCallApiExtraOptions, u as CallApiExtraOptions, w as CallApiRequestOptions, x as CallApiResultErrorVariant, y as CallApiResultSuccessVariant, z as ErrorContext, H as HTTPError, F as Interceptors, s as PluginInitContext, v as PossibleHTTPError, J as PossibleJavascriptErrorNames, K as Register, L as RequestContext, N as RequestErrorContext, O as ResponseContext, Q as ResponseErrorContext, T as SuccessContext, r as definePlugin } from './error-BokQ-iQX.js';
3
- import * as _standard_schema_spec from '@standard-schema/spec';
1
+ import { R as ResultModeUnion, a as ResponseTypeUnion, C as CallApiPlugin, D as DefaultPluginArray, b as CallApiSchemas, I as InferSchemaResult, c as CallApiConfig, d as CallApiResult, e as DefaultDataType, f as DefaultThrowOnError, g as DefaultMoreOptions, B as BaseCallApiConfig, h as CallApiParameters } from './error-DH3yCjyX.js';
2
+ export { k as BaseCallApiExtraOptions, l as CallApiExtraOptions, o as CallApiRequestOptions, p as CallApiRequestOptionsForHooks, q as CallApiResultErrorVariant, r as CallApiResultSuccessVariant, s as CombinedCallApiExtraOptions, E as ErrorContext, H as HTTPError, t as Interceptors, u as InterceptorsOrInterceptorArray, P as PluginInitContext, n as PossibleHTTPError, m as PossibleJavaScriptError, v as PossibleJavascriptErrorNames, w as Register, x as RequestContext, y as RequestErrorContext, z as ResponseContext, A as ResponseErrorContext, j as RetryOptions, S as SuccessContext, i as definePlugin } from './error-DH3yCjyX.js';
3
+ import '@standard-schema/spec';
4
4
 
5
- declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions>(baseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>) => <TData = InferSchemaResult<TBaseSchemas["data"], TBaseData>, TErrorData = InferSchemaResult<TBaseSchemas["errorData"], TBaseErrorData>, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends boolean = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, TPluginArray extends CallApiPlugin[] = TBasePluginArray, TSchemas extends CallApiSchemas = TBaseSchemas>(initURL: InferSchemaResult<TSchemas["initURL"], string | URL>, config?: ((undefined extends TSchemas["body"] ? {
6
- body?: InferSchemaResult<TSchemas["body"], BodyInit | SerializableArray | SerializableObject | null | undefined> | undefined;
7
- } : undefined extends InferSchemaResult<TSchemas["body"], {}> ? {
8
- body?: InferSchemaResult<TSchemas["body"], BodyInit | SerializableArray | SerializableObject | null | undefined> | undefined;
9
- } : Required<{
10
- body?: InferSchemaResult<TSchemas["body"], BodyInit | SerializableArray | SerializableObject | null | undefined> | undefined;
11
- }>) & (undefined extends TSchemas["headers"] ? {
12
- headers?: InferSchemaResult<TSchemas["headers"], Record<"Authorization", `Basic ${string}` | `Bearer ${string}` | `Token ${string}`> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | HeadersInit | undefined> | undefined;
13
- } : undefined extends InferSchemaResult<TSchemas["headers"], {}> ? {
14
- headers?: InferSchemaResult<TSchemas["headers"], Record<"Authorization", `Basic ${string}` | `Bearer ${string}` | `Token ${string}`> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | HeadersInit | undefined> | undefined;
15
- } : Required<{
16
- headers?: InferSchemaResult<TSchemas["headers"], Record<"Authorization", `Basic ${string}` | `Bearer ${string}` | `Token ${string}`> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | HeadersInit | undefined> | undefined;
17
- }>) & (undefined extends TSchemas["method"] ? {
18
- method?: InferSchemaResult<TSchemas["method"], AnyString | "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE"> | undefined;
19
- } : undefined extends InferSchemaResult<TSchemas["method"], {}> ? {
20
- method?: InferSchemaResult<TSchemas["method"], AnyString | "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE"> | undefined;
21
- } : Required<{
22
- method?: InferSchemaResult<TSchemas["method"], AnyString | "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE"> | undefined;
23
- }>) & Pick<RequestInit, "cache" | "credentials" | "integrity" | "keepalive" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window"> & {
24
- auth?: string | Auth | null;
25
- baseURL?: string;
26
- bodySerializer?: (bodyData: Record<string, unknown>) => string;
27
- cloneResponse?: boolean;
28
- customFetchImpl?: (input: string | Request | URL, init?: RequestInit) => Promise<Response>;
29
- dedupeKey?: string;
30
- dedupeStrategy?: "cancel" | "defer" | "none";
31
- defaultErrorMessage?: string;
32
- readonly fullURL?: string;
33
- mergedHooksExecutionMode?: "parallel" | "sequential";
34
- mergedHooksExecutionOrder?: "mainHooksAfterPlugins" | "mainHooksBeforePlugins";
35
- plugins?: TPluginArray | undefined;
36
- responseParser?: (responseString: string) => Awaitable<Record<string, unknown>>;
37
- responseType?: TResponseType | undefined;
38
- resultMode?: TResultMode | undefined;
39
- schemas?: TSchemas | undefined;
40
- throwOnError?: TThrowOnError | ((context: {
41
- error: PossibleJavaScriptError;
42
- options: CombinedCallApiExtraOptions;
43
- request: CallApiRequestOptionsForHooks;
44
- response: null;
45
- } | {
46
- error: {
47
- errorData: TErrorData;
48
- message: string;
49
- name: "HTTPError";
50
- };
51
- options: CombinedCallApiExtraOptions;
52
- request: CallApiRequestOptionsForHooks;
53
- response: Response;
54
- }) => TThrowOnError) | undefined;
55
- timeout?: number;
56
- validators?: CallApiValidators<TData, TErrorData> | undefined;
57
- } & InterceptorsOrInterceptorArray<TData, TErrorData, {}> & Partial<((ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>> extends infer T ? T extends ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>> ? T extends _standard_schema_spec.StandardSchemaV1<unknown, unknown> ? InferSchemaResult<T, {}> : T : never : never) extends infer T_1 ? T_1 extends (ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>> extends infer T_2 ? T_2 extends ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>> ? T_2 extends _standard_schema_spec.StandardSchemaV1<unknown, unknown> ? InferSchemaResult<T_2, {}> : T_2 : never : never) ? T_1 extends unknown ? (param: T_1) => void : never : never : never) extends (param: infer TParam) => void ? TParam : never> & MetaOption<TSchemas> & RetryOptions<TErrorData> & ResultModeOption<TErrorData, TResultMode> & UrlOptions<TSchemas> & {
58
- extend?: Pick<ExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>, "plugins" | "schemas" | "validators"> | undefined;
59
- }) | undefined) => Promise<GetCallApiResult<InferSchemaResult<TSchemas["data"], TData>, InferSchemaResult<TSchemas["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>>;
60
- declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = {}>(initURL: InferSchemaResult<TSchemas["initURL"], string | URL>, config?: ((undefined extends TSchemas["body"] ? {
61
- body?: InferSchemaResult<TSchemas["body"], BodyInit | SerializableArray | SerializableObject | null | undefined> | undefined;
62
- } : undefined extends InferSchemaResult<TSchemas["body"], {}> ? {
63
- body?: InferSchemaResult<TSchemas["body"], BodyInit | SerializableArray | SerializableObject | null | undefined> | undefined;
64
- } : Required<{
65
- body?: InferSchemaResult<TSchemas["body"], BodyInit | SerializableArray | SerializableObject | null | undefined> | undefined;
66
- }>) & (undefined extends TSchemas["headers"] ? {
67
- headers?: InferSchemaResult<TSchemas["headers"], Record<"Authorization", `Basic ${string}` | `Bearer ${string}` | `Token ${string}`> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | HeadersInit | undefined> | undefined;
68
- } : undefined extends InferSchemaResult<TSchemas["headers"], {}> ? {
69
- headers?: InferSchemaResult<TSchemas["headers"], Record<"Authorization", `Basic ${string}` | `Bearer ${string}` | `Token ${string}`> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | HeadersInit | undefined> | undefined;
70
- } : Required<{
71
- headers?: InferSchemaResult<TSchemas["headers"], Record<"Authorization", `Basic ${string}` | `Bearer ${string}` | `Token ${string}`> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | HeadersInit | undefined> | undefined;
72
- }>) & (undefined extends TSchemas["method"] ? {
73
- method?: InferSchemaResult<TSchemas["method"], AnyString | "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE"> | undefined;
74
- } : undefined extends InferSchemaResult<TSchemas["method"], {}> ? {
75
- method?: InferSchemaResult<TSchemas["method"], AnyString | "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE"> | undefined;
76
- } : Required<{
77
- method?: InferSchemaResult<TSchemas["method"], AnyString | "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE"> | undefined;
78
- }>) & Pick<RequestInit, "cache" | "credentials" | "integrity" | "keepalive" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window"> & {
79
- auth?: string | Auth | null;
80
- baseURL?: string;
81
- bodySerializer?: (bodyData: Record<string, unknown>) => string;
82
- cloneResponse?: boolean;
83
- customFetchImpl?: (input: string | Request | URL, init?: RequestInit) => Promise<Response>;
84
- dedupeKey?: string;
85
- dedupeStrategy?: "cancel" | "defer" | "none";
86
- defaultErrorMessage?: string;
87
- readonly fullURL?: string;
88
- mergedHooksExecutionMode?: "parallel" | "sequential";
89
- mergedHooksExecutionOrder?: "mainHooksAfterPlugins" | "mainHooksBeforePlugins";
90
- plugins?: TPluginArray | undefined;
91
- responseParser?: (responseString: string) => Awaitable<Record<string, unknown>>;
92
- responseType?: TResponseType | undefined;
93
- resultMode?: TResultMode | undefined;
94
- schemas?: TSchemas | undefined;
95
- throwOnError?: TThrowOnError | ((context: {
96
- error: PossibleJavaScriptError;
97
- options: CombinedCallApiExtraOptions;
98
- request: CallApiRequestOptionsForHooks;
99
- response: null;
100
- } | {
101
- error: {
102
- errorData: TErrorData;
103
- message: string;
104
- name: "HTTPError";
105
- };
106
- options: CombinedCallApiExtraOptions;
107
- request: CallApiRequestOptionsForHooks;
108
- response: Response;
109
- }) => TThrowOnError) | undefined;
110
- timeout?: number;
111
- validators?: CallApiValidators<TData, TErrorData> | undefined;
112
- } & InterceptorsOrInterceptorArray<TData, TErrorData, {}> & Partial<((ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>> extends infer T ? T extends ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>> ? T extends _standard_schema_spec.StandardSchemaV1<unknown, unknown> ? InferSchemaResult<T, {}> : T : never : never) extends infer T_1 ? T_1 extends (ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>> extends infer T_2 ? T_2 extends ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>> ? T_2 extends _standard_schema_spec.StandardSchemaV1<unknown, unknown> ? InferSchemaResult<T_2, {}> : T_2 : never : never) ? T_1 extends unknown ? (param: T_1) => void : never : never : never) extends (param: infer TParam) => void ? TParam : never> & MetaOption<TSchemas> & RetryOptions<TErrorData> & ResultModeOption<TErrorData, TResultMode> & UrlOptions<TSchemas> & {
113
- extend?: Pick<ExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>, "plugins" | "schemas" | "validators"> | undefined;
114
- }) | undefined) => Promise<GetCallApiResult<InferSchemaResult<TSchemas["data"], TData>, InferSchemaResult<TSchemas["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>>;
5
+ declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions>(baseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>) => <TData = InferSchemaResult<TBaseSchemas["data"], TBaseData>, TErrorData = InferSchemaResult<TBaseSchemas["errorData"], TBaseErrorData>, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends boolean = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, TPluginArray extends CallApiPlugin[] = TBasePluginArray, TSchemas extends CallApiSchemas = TBaseSchemas>(initURL: InferSchemaResult<TSchemas["initURL"], string | URL>, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> | undefined) => CallApiResult<InferSchemaResult<TSchemas["data"], TData>, InferSchemaResult<TSchemas["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
6
+ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = {}>(initURL: InferSchemaResult<TSchemas["initURL"], string | URL>, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> | undefined) => CallApiResult<InferSchemaResult<TSchemas["data"], TData>, InferSchemaResult<TSchemas["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
115
7
 
116
8
  declare const defineParameters: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = DefaultMoreOptions>(...parameters: CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>) => CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>;
117
9
 
118
- export { CallApiParameters, CallApiPlugin, CallApiRequestOptionsForHooks, CallApiSchemas, CombinedCallApiExtraOptions, InferSchemaResult, InterceptorsOrInterceptorArray, PossibleJavaScriptError, ResultModeUnion, callApi, createFetchClient, defineParameters };
10
+ export { CallApiParameters, CallApiPlugin, CallApiSchemas, InferSchemaResult, ResultModeUnion, callApi, createFetchClient, defineParameters };
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { splitConfig, isFunction, splitBaseConfig, combineHooks, mergeAndResolveHeaders, isPlainObject, executeHooks, HTTPError, resolveErrorResult, waitUntil, isHTTPErrorInstance, defaultRetryStatusCodes, defaultRetryMethods, omitKeys, isString, isArray, toQueryString, getFetchImpl } from './chunk-JG2BPHMX.js';
2
- export { HTTPError } from './chunk-JG2BPHMX.js';
1
+ import { splitConfig, isFunction, defaultExtraOptions, splitBaseConfig, combineHooks, mergeAndResolveHeaders, isPlainObject, executeHooks, HTTPError, resolveErrorResult, isHTTPErrorInstance, waitUntil, omitKeys, isString, isArray, toQueryString, getFetchImpl } from './chunk-KLMWU6K5.js';
2
+ export { HTTPError } from './chunk-KLMWU6K5.js';
3
3
 
4
4
  // src/dedupe.ts
5
5
  var createDedupeStrategy = async (context) => {
@@ -74,7 +74,7 @@ var getPluginArray = (plugins) => {
74
74
  return plugins;
75
75
  };
76
76
  var initializePlugins = async (context) => {
77
- const { baseConfig, config, initURL, options, request } = context;
77
+ const { baseConfig, config, defaultOptions, initURL, options, request } = context;
78
78
  const hookRegistries = structuredClone(hooksEnum);
79
79
  const addMainHooks = () => {
80
80
  for (const key of Object.keys(hooksEnum)) {
@@ -103,6 +103,7 @@ var initializePlugins = async (context) => {
103
103
  const initResult = await pluginInit({
104
104
  baseConfig,
105
105
  config,
106
+ defaultOptions,
106
107
  initURL,
107
108
  options,
108
109
  request
@@ -189,28 +190,30 @@ var getExponentialDelay = (currentAttemptCount, options) => {
189
190
  const exponentialDelay = (options.retryDelay ?? 1e3) * 2 ** currentAttemptCount;
190
191
  return Math.min(exponentialDelay, maxDelay);
191
192
  };
192
- var createRetryStrategy = (options, ctx) => {
193
- const currentRetryCount = options["~retryCount"] ?? 0;
193
+ var createRetryStrategy = (ctx) => {
194
+ const currentRetryCount = ctx.options["~retryCount"] ?? 0;
194
195
  const getDelay = () => {
195
- if (options.retryStrategy === "exponential") {
196
- return getExponentialDelay(currentRetryCount, options);
196
+ if (ctx.options.retryStrategy === "exponential") {
197
+ return getExponentialDelay(currentRetryCount, ctx.options);
197
198
  }
198
- return getLinearDelay(options);
199
+ return getLinearDelay(ctx.options);
199
200
  };
200
201
  const shouldAttemptRetry = async () => {
201
- const customRetryCondition = await options.retryCondition?.(ctx) ?? true;
202
- const maxRetryAttempts = options.retryAttempts ?? 0;
202
+ const customRetryCondition = await ctx.options.retryCondition?.(ctx) ?? true;
203
+ const maxRetryAttempts = ctx.options.retryAttempts ?? 0;
203
204
  const baseRetryCondition = maxRetryAttempts > currentRetryCount && customRetryCondition;
204
205
  if (ctx.error.name !== "HTTPError") {
205
206
  return baseRetryCondition;
206
207
  }
208
+ const resolvedRetryMethods = isFunction(ctx.options.retryMethods) ? ctx.options.retryMethods(ctx) : ctx.options.retryMethods;
209
+ const resolvedRetryStatusCodes = isFunction(ctx.options.retryStatusCodes) ? ctx.options.retryStatusCodes(ctx) : ctx.options.retryStatusCodes;
207
210
  const includesMethod = (
208
211
  // eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow
209
- !!ctx.request.method && options.retryMethods?.includes(ctx.request.method)
212
+ !!ctx.request.method && resolvedRetryMethods?.includes(ctx.request.method)
210
213
  );
211
214
  const includesCodes = (
212
215
  // eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow
213
- !!ctx.response?.status && options.retryStatusCodes?.includes(ctx.response.status)
216
+ !!ctx.response?.status && resolvedRetryStatusCodes?.includes(ctx.response.status)
214
217
  );
215
218
  return includesCodes && includesMethod && baseRetryCondition;
216
219
  };
@@ -294,45 +297,35 @@ var createFetchClient = (baseConfig = {}) => {
294
297
  const callApi2 = async (...parameters) => {
295
298
  const [initURL, config = {}] = parameters;
296
299
  const [fetchOptions, extraOptions] = splitConfig(config);
297
- const resolvedBaseConfig = isFunction(baseConfig) ? baseConfig({ initURL: initURL.toString(), options: extraOptions, request: fetchOptions }) : baseConfig;
300
+ const resolvedBaseConfig = isFunction(baseConfig) ? baseConfig({
301
+ defaultOptions: defaultExtraOptions,
302
+ initURL: initURL.toString(),
303
+ options: extraOptions,
304
+ request: fetchOptions
305
+ }) : baseConfig;
298
306
  const [baseFetchOptions, baseExtraOptions] = splitBaseConfig(resolvedBaseConfig);
299
- const initCombinedHooks = {};
300
307
  for (const key of Object.keys(hooksEnum)) {
301
- const combinedHook = combineHooks(
308
+ combineHooks(
302
309
  baseExtraOptions[key],
303
310
  extraOptions[key]
304
311
  );
305
- initCombinedHooks[key] = combinedHook;
306
312
  }
307
- const defaultExtraOptions = {
308
- baseURL: "",
309
- bodySerializer: JSON.stringify,
310
- dedupeStrategy: "cancel",
311
- defaultErrorMessage: "Failed to fetch data from server!",
312
- mergedHooksExecutionMode: "parallel",
313
- mergedHooksExecutionOrder: "mainHooksAfterPlugins",
314
- responseType: "json",
315
- resultMode: "all",
316
- retryAttempts: 0,
317
- retryDelay: 1e3,
318
- retryMaxDelay: 1e4,
319
- retryMethods: defaultRetryMethods,
320
- retryStatusCodes: defaultRetryStatusCodes,
321
- retryStrategy: "linear",
313
+ const mergedExtraOptions = {
314
+ ...defaultExtraOptions,
322
315
  ...baseExtraOptions,
323
- ...extraOptions,
324
- ...initCombinedHooks
316
+ ...extraOptions
325
317
  };
326
- const defaultRequestOptions = {
318
+ const mergedRequestOptions = {
327
319
  ...baseFetchOptions,
328
320
  ...fetchOptions
329
321
  };
330
322
  const { resolvedHooks, resolvedOptions, resolvedRequestOptions, url } = await initializePlugins({
331
323
  baseConfig: resolvedBaseConfig,
332
324
  config,
325
+ defaultOptions: defaultExtraOptions,
333
326
  initURL,
334
- options: defaultExtraOptions,
335
- request: defaultRequestOptions
327
+ options: mergedExtraOptions,
328
+ request: mergedRequestOptions
336
329
  });
337
330
  const fullURL = `${resolvedOptions.baseURL}${mergeUrlWithParamsAndQuery(url, resolvedOptions.params, resolvedOptions.query)}`;
338
331
  const options = {
@@ -365,7 +358,6 @@ var createFetchClient = (baseConfig = {}) => {
365
358
  await executeHooks(options.onRequest({ options, request }));
366
359
  request.headers = mergeAndResolveHeaders({
367
360
  auth: options.auth,
368
- baseHeaders: baseFetchOptions.headers,
369
361
  body: request.body,
370
362
  headers: request.headers
371
363
  });
@@ -423,9 +415,11 @@ var createFetchClient = (baseConfig = {}) => {
423
415
  request,
424
416
  response: apiDetails.response
425
417
  };
426
- const { getDelay, shouldAttemptRetry } = createRetryStrategy(options, errorContext);
427
- const shouldRetry = !combinedSignal.aborted && await shouldAttemptRetry();
428
- if (shouldRetry) {
418
+ const shouldThrowOnError = isFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError;
419
+ const handleRetry = async () => {
420
+ const { getDelay, shouldAttemptRetry } = createRetryStrategy(errorContext);
421
+ const shouldRetry = !combinedSignal.aborted && await shouldAttemptRetry();
422
+ if (!shouldRetry) return;
429
423
  await executeHooks(options.onRetry(errorContext));
430
424
  const delay = getDelay();
431
425
  await waitUntil(delay);
@@ -433,9 +427,8 @@ var createFetchClient = (baseConfig = {}) => {
433
427
  ...config,
434
428
  "~retryCount": (options["~retryCount"] ?? 0) + 1
435
429
  };
436
- return await callApi2(initURL, updatedOptions);
437
- }
438
- const shouldThrowOnError = isFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError;
430
+ return callApi2(initURL, updatedOptions);
431
+ };
439
432
  const handleThrowOnError = () => {
440
433
  if (!shouldThrowOnError) return;
441
434
  throw apiDetails.error;
@@ -446,18 +439,21 @@ var createFetchClient = (baseConfig = {}) => {
446
439
  options.onError(errorContext),
447
440
  options.onResponse({ ...errorContext, data: null })
448
441
  );
442
+ await handleRetry();
449
443
  handleThrowOnError();
450
444
  return getErrorResult();
451
445
  }
452
446
  if (error instanceof DOMException && error.name === "AbortError") {
453
447
  const { message, name } = error;
454
448
  console.error(`${name}:`, message);
449
+ await handleRetry();
455
450
  handleThrowOnError();
456
451
  return getErrorResult();
457
452
  }
458
453
  if (error instanceof DOMException && error.name === "TimeoutError") {
459
454
  const message = `Request timed out after ${options.timeout}ms`;
460
455
  console.error(`${error.name}:`, message);
456
+ await handleRetry();
461
457
  handleThrowOnError();
462
458
  return getErrorResult({ message });
463
459
  }
@@ -467,6 +463,7 @@ var createFetchClient = (baseConfig = {}) => {
467
463
  // == Also call the onError interceptor
468
464
  options.onError(errorContext)
469
465
  );
466
+ await handleRetry();
470
467
  handleThrowOnError();
471
468
  return getErrorResult();
472
469
  } finally {