@zayne-labs/callapi 1.7.2 → 1.7.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/README.md +1 -1
- package/dist/cjs/{error-By05WYGj.d.cts → common-BUhBcx_C.d.cts} +246 -231
- package/dist/cjs/index.cjs +223 -210
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -4
- package/dist/cjs/utils/index.cjs +5 -2
- package/dist/cjs/utils/index.cjs.map +1 -1
- package/dist/cjs/utils/index.d.cts +2 -3
- package/dist/esm/{chunk-IAT2JZPC.js → chunk-G4FFGADM.js} +13 -13
- package/dist/esm/chunk-G4FFGADM.js.map +1 -0
- package/dist/esm/{error-By05WYGj.d.ts → common-BUhBcx_C.d.ts} +246 -231
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +110 -92
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/index.d.ts +2 -3
- package/dist/esm/utils/index.js +1 -1
- package/package.json +2 -2
- package/dist/esm/chunk-IAT2JZPC.js.map +0 -1
package/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<h1 align="center">CallApi - Advanced Fetch Client</h1>
|
2
2
|
|
3
3
|
<p align="center">
|
4
|
-
<img src="https://
|
4
|
+
<img src="https://res.cloudinary.com/djvestif4/image/upload/v1745621399/call-api/logo_unyvnx.jpg" alt="CallApi Logo" width="30%">
|
5
5
|
</p>
|
6
6
|
|
7
7
|
<p align="center">
|
@@ -65,6 +65,58 @@ type CommonRequestHeaders = "Access-Control-Allow-Credentials" | "Access-Control
|
|
65
65
|
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
|
66
66
|
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;
|
67
67
|
|
68
|
+
type ErrorDetails<TErrorResponse> = {
|
69
|
+
defaultErrorMessage: string;
|
70
|
+
errorData: TErrorResponse;
|
71
|
+
response: Response;
|
72
|
+
};
|
73
|
+
type ErrorOptions = {
|
74
|
+
cause?: unknown;
|
75
|
+
};
|
76
|
+
declare class HTTPError<TErrorResponse = Record<string, unknown>> {
|
77
|
+
cause: ErrorOptions["cause"];
|
78
|
+
errorData: ErrorDetails<TErrorResponse>["errorData"];
|
79
|
+
isHTTPError: boolean;
|
80
|
+
message: string;
|
81
|
+
name: "HTTPError";
|
82
|
+
response: ErrorDetails<TErrorResponse>["response"];
|
83
|
+
constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
|
84
|
+
}
|
85
|
+
type PossibleJavaScriptError = UnmaskType<{
|
86
|
+
errorData: DOMException | Error | SyntaxError | TypeError;
|
87
|
+
message: string;
|
88
|
+
name: "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | (`${string}Error` & {});
|
89
|
+
}>;
|
90
|
+
type PossibleHTTPError<TErrorData> = UnmaskType<{
|
91
|
+
errorData: TErrorData;
|
92
|
+
message: string;
|
93
|
+
name: "HTTPError";
|
94
|
+
}>;
|
95
|
+
|
96
|
+
type StreamProgressEvent = {
|
97
|
+
/**
|
98
|
+
* Current chunk of data being streamed
|
99
|
+
*/
|
100
|
+
chunk: Uint8Array;
|
101
|
+
/**
|
102
|
+
* Progress in percentage
|
103
|
+
*/
|
104
|
+
progress: number;
|
105
|
+
/**
|
106
|
+
* Total size of data in bytes
|
107
|
+
*/
|
108
|
+
totalBytes: number;
|
109
|
+
/**
|
110
|
+
* Amount of data transferred so far
|
111
|
+
*/
|
112
|
+
transferredBytes: number;
|
113
|
+
};
|
114
|
+
declare global {
|
115
|
+
interface ReadableStream<R> {
|
116
|
+
[Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
68
120
|
/**
|
69
121
|
* The Standard Schema interface.
|
70
122
|
* @see https://github.com/standard-schema/standard-schema
|
@@ -233,151 +285,215 @@ interface UrlOptions<TSchemas extends CallApiSchemas> {
|
|
233
285
|
query?: InferSchemaResult<TSchemas["query"], Query>;
|
234
286
|
}
|
235
287
|
|
236
|
-
type
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
288
|
+
type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ? TParam : never;
|
289
|
+
type InferSchema<TResult> = TResult extends StandardSchemaV1 ? InferSchemaResult<TResult, NonNullable<unknown>> : TResult;
|
290
|
+
type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<InferSchema<ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>>>>;
|
291
|
+
type PluginInitContext<TMoreOptions = DefaultMoreOptions> = Prettify<SharedHookContext<TMoreOptions> & {
|
292
|
+
initURL: InitURL | undefined;
|
293
|
+
}>;
|
294
|
+
type PluginInitResult = Partial<Omit<PluginInitContext, "request"> & {
|
295
|
+
request: CallApiRequestOptions;
|
296
|
+
}>;
|
297
|
+
type PluginHooksWithMoreOptions<TMoreOptions = DefaultMoreOptions> = HooksOrHooksArray<never, never, TMoreOptions>;
|
298
|
+
type PluginHooks<TData = never, TErrorData = never, TMoreOptions = DefaultMoreOptions> = HooksOrHooksArray<TData, TErrorData, TMoreOptions>;
|
299
|
+
interface CallApiPlugin {
|
243
300
|
/**
|
244
|
-
*
|
245
|
-
* @default 0
|
301
|
+
* Defines additional options that can be passed to callApi
|
246
302
|
*/
|
247
|
-
|
303
|
+
createExtraOptions?: (...params: never[]) => unknown;
|
248
304
|
/**
|
249
|
-
*
|
305
|
+
* A description for the plugin
|
250
306
|
*/
|
251
|
-
|
307
|
+
description?: string;
|
252
308
|
/**
|
253
|
-
*
|
254
|
-
* @default 1000
|
309
|
+
* Hooks / Interceptors for the plugin
|
255
310
|
*/
|
256
|
-
|
311
|
+
hooks?: PluginHooks;
|
257
312
|
/**
|
258
|
-
*
|
259
|
-
* @default 10000
|
313
|
+
* A unique id for the plugin
|
260
314
|
*/
|
261
|
-
|
315
|
+
id: string;
|
262
316
|
/**
|
263
|
-
*
|
264
|
-
* @default ["GET", "POST"]
|
317
|
+
* A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.
|
265
318
|
*/
|
266
|
-
|
319
|
+
init?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;
|
267
320
|
/**
|
268
|
-
*
|
269
|
-
* @default [409, 425, 429, 500, 502, 503, 504]
|
321
|
+
* A name for the plugin
|
270
322
|
*/
|
271
|
-
|
323
|
+
name: string;
|
272
324
|
/**
|
273
|
-
*
|
274
|
-
* @default "linear"
|
325
|
+
* A version for the plugin
|
275
326
|
*/
|
276
|
-
|
327
|
+
version?: string;
|
277
328
|
}
|
329
|
+
declare const definePlugin: <TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>>(plugin: TPlugin) => TPlugin;
|
330
|
+
type Plugins<TPluginArray extends CallApiPlugin[]> = TPluginArray;
|
278
331
|
|
279
332
|
type DefaultDataType = unknown;
|
280
333
|
type DefaultMoreOptions = NonNullable<unknown>;
|
281
334
|
type DefaultPluginArray = CallApiPlugin[];
|
282
335
|
type DefaultThrowOnError = boolean;
|
283
336
|
|
284
|
-
type
|
285
|
-
|
286
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
287
|
-
blob: () => Promise<Blob>;
|
288
|
-
formData: () => Promise<FormData>;
|
289
|
-
json: () => Promise<TResponse>;
|
290
|
-
stream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
291
|
-
text: () => Promise<string>;
|
337
|
+
type WithMoreOptions<TMoreOptions = DefaultMoreOptions> = {
|
338
|
+
options: CombinedCallApiExtraOptions & Partial<TMoreOptions>;
|
292
339
|
};
|
293
|
-
type
|
294
|
-
|
295
|
-
|
296
|
-
|
340
|
+
type Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> = {
|
341
|
+
/**
|
342
|
+
* Hook that will be called when any error occurs within the request/response lifecycle, regardless of whether the error is from the api or not.
|
343
|
+
* It is basically a combination of `onRequestError` and `onResponseError` hooks
|
344
|
+
*/
|
345
|
+
onError?: (context: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
346
|
+
/**
|
347
|
+
* Hook that will be called just before the request is made, allowing for modifications or additional operations.
|
348
|
+
*/
|
349
|
+
onRequest?: (context: Prettify<RequestContext & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
|
350
|
+
/**
|
351
|
+
* Hook that will be called when an error occurs during the fetch request.
|
352
|
+
*/
|
353
|
+
onRequestError?: (context: Prettify<RequestErrorContext & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
|
354
|
+
/**
|
355
|
+
* Hook that will be called when upload stream progress is tracked
|
356
|
+
*/
|
357
|
+
onRequestStream?: (context: Prettify<RequestStreamContext & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
|
358
|
+
/**
|
359
|
+
* Hook that will be called when any response is received from the api, whether successful or not
|
360
|
+
*/
|
361
|
+
onResponse?: (context: ResponseContext<TData, TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
362
|
+
/**
|
363
|
+
* Hook that will be called when an error response is received from the api.
|
364
|
+
*/
|
365
|
+
onResponseError?: (context: Prettify<ResponseErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
|
366
|
+
/**
|
367
|
+
* Hook that will be called when download stream progress is tracked
|
368
|
+
*/
|
369
|
+
onResponseStream?: (context: Prettify<ResponseStreamContext & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
|
370
|
+
/**
|
371
|
+
* Hook that will be called when a request is retried.
|
372
|
+
*/
|
373
|
+
onRetry?: (response: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
374
|
+
/**
|
375
|
+
* Hook that will be called when a successful response is received from the api.
|
376
|
+
*/
|
377
|
+
onSuccess?: (context: Prettify<SuccessContext<TData> & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
|
297
378
|
};
|
298
|
-
type
|
299
|
-
|
300
|
-
|
379
|
+
type HooksOrHooksArray<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> = {
|
380
|
+
[Key in keyof Hooks<TData, TErrorData, TMoreOptions>]: Hooks<TData, TErrorData, TMoreOptions>[Key] | Array<Hooks<TData, TErrorData, TMoreOptions>[Key]>;
|
381
|
+
};
|
382
|
+
type SharedHookContext<TMoreOptions = DefaultMoreOptions> = {
|
301
383
|
/**
|
302
|
-
*
|
384
|
+
* Config object passed to createFetchClient
|
303
385
|
*/
|
304
|
-
|
386
|
+
baseConfig: BaseCallApiExtraOptions & CallApiRequestOptions;
|
305
387
|
/**
|
306
|
-
*
|
388
|
+
* Config object passed to the callApi instance
|
307
389
|
*/
|
308
|
-
|
390
|
+
config: CallApiExtraOptions & CallApiRequestOptions;
|
309
391
|
/**
|
310
|
-
*
|
392
|
+
* Merged options consisting of extra options from createFetchClient, the callApi instance and default options.
|
393
|
+
*
|
311
394
|
*/
|
312
|
-
|
395
|
+
options: CombinedCallApiExtraOptions & Partial<TMoreOptions>;
|
313
396
|
/**
|
314
|
-
*
|
397
|
+
* Merged request consisting of request options from createFetchClient, the callApi instance and default request options.
|
315
398
|
*/
|
316
|
-
|
399
|
+
request: CallApiRequestOptionsForHooks;
|
317
400
|
};
|
318
|
-
type
|
401
|
+
type RequestContext = UnmaskType<SharedHookContext>;
|
402
|
+
type ResponseContext<TData, TErrorData> = UnmaskType<Prettify<SharedHookContext & {
|
403
|
+
data: TData;
|
404
|
+
error: null;
|
405
|
+
response: Response;
|
406
|
+
}> | Prettify<SharedHookContext & {
|
407
|
+
data: null;
|
408
|
+
error: PossibleHTTPError<TErrorData>;
|
409
|
+
response: Response;
|
410
|
+
}>>;
|
411
|
+
type SuccessContext<TData> = UnmaskType<Prettify<SharedHookContext & {
|
412
|
+
data: TData;
|
413
|
+
response: Response;
|
414
|
+
}>>;
|
415
|
+
type RequestErrorContext = UnmaskType<Prettify<SharedHookContext & {
|
416
|
+
error: PossibleJavaScriptError;
|
417
|
+
response: null;
|
418
|
+
}>>;
|
419
|
+
type ResponseErrorContext<TErrorData> = UnmaskType<Prettify<SharedHookContext & {
|
420
|
+
error: PossibleHTTPError<TErrorData>;
|
421
|
+
response: Response;
|
422
|
+
}>>;
|
423
|
+
type ErrorContext<TErrorData> = UnmaskType<Prettify<SharedHookContext & {
|
424
|
+
error: PossibleHTTPError<TErrorData>;
|
425
|
+
response: Response;
|
426
|
+
}> | Prettify<SharedHookContext & {
|
427
|
+
error: PossibleJavaScriptError;
|
428
|
+
response: null;
|
429
|
+
}>>;
|
430
|
+
type RequestStreamContext = UnmaskType<Prettify<SharedHookContext & {
|
319
431
|
event: StreamProgressEvent;
|
320
|
-
options: CombinedCallApiExtraOptions;
|
321
|
-
request: CallApiRequestOptionsForHooks;
|
322
432
|
requestInstance: Request;
|
323
|
-
}
|
324
|
-
type ResponseStreamContext = {
|
433
|
+
}>>;
|
434
|
+
type ResponseStreamContext = UnmaskType<Prettify<SharedHookContext & {
|
325
435
|
event: StreamProgressEvent;
|
326
|
-
options: CombinedCallApiExtraOptions;
|
327
|
-
request: CallApiRequestOptionsForHooks;
|
328
436
|
response: Response;
|
329
|
-
}
|
330
|
-
declare global {
|
331
|
-
interface ReadableStream<R> {
|
332
|
-
[Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
|
333
|
-
}
|
334
|
-
}
|
437
|
+
}>>;
|
335
438
|
|
336
|
-
type
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
request: CallApiRequestOptionsForHooks;
|
439
|
+
type Parser = (responseString: string) => Awaitable<Record<string, unknown>>;
|
440
|
+
declare const getResponseType: <TResponse>(response: Response, parser?: Parser) => {
|
441
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
442
|
+
blob: () => Promise<Blob>;
|
443
|
+
formData: () => Promise<FormData>;
|
444
|
+
json: () => Promise<TResponse>;
|
445
|
+
stream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
446
|
+
text: () => Promise<string>;
|
345
447
|
};
|
346
|
-
type
|
347
|
-
|
348
|
-
|
349
|
-
|
448
|
+
type InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;
|
449
|
+
type ResponseTypeUnion = keyof InitResponseTypeMap | null;
|
450
|
+
type ResponseTypeMap<TResponse> = {
|
451
|
+
[Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>>;
|
452
|
+
};
|
453
|
+
type GetResponseType<TResponse, TResponseType extends ResponseTypeUnion, TComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType] : never;
|
454
|
+
|
455
|
+
type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;
|
456
|
+
interface RetryOptions<TErrorData> {
|
350
457
|
/**
|
351
|
-
*
|
458
|
+
* Keeps track of the number of times the request has already been retried
|
459
|
+
* @deprecated This property is used internally to track retries. Please abstain from modifying it.
|
352
460
|
*/
|
353
|
-
|
461
|
+
readonly ["~retryCount"]?: number;
|
354
462
|
/**
|
355
|
-
*
|
463
|
+
* Number of allowed retry attempts on HTTP errors
|
464
|
+
* @default 0
|
356
465
|
*/
|
357
|
-
|
466
|
+
retryAttempts?: number;
|
358
467
|
/**
|
359
|
-
*
|
468
|
+
* Callback whose return value determines if a request should be retried or not
|
360
469
|
*/
|
361
|
-
|
470
|
+
retryCondition?: RetryCondition<TErrorData>;
|
362
471
|
/**
|
363
|
-
*
|
472
|
+
* Delay between retries in milliseconds
|
473
|
+
* @default 1000
|
364
474
|
*/
|
365
|
-
|
475
|
+
retryDelay?: number;
|
366
476
|
/**
|
367
|
-
*
|
477
|
+
* Maximum delay in milliseconds. Only applies to exponential strategy
|
478
|
+
* @default 10000
|
368
479
|
*/
|
369
|
-
|
480
|
+
retryMaxDelay?: number;
|
370
481
|
/**
|
371
|
-
*
|
482
|
+
* HTTP methods that are allowed to retry
|
483
|
+
* @default ["GET", "POST"]
|
372
484
|
*/
|
373
|
-
|
485
|
+
retryMethods?: Method[];
|
374
486
|
/**
|
375
|
-
*
|
487
|
+
* HTTP status codes that trigger a retry
|
488
|
+
* @default [409, 425, 429, 500, 502, 503, 504]
|
376
489
|
*/
|
377
|
-
|
490
|
+
retryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;
|
491
|
+
/**
|
492
|
+
* Strategy to use when retrying
|
493
|
+
* @default "linear"
|
494
|
+
*/
|
495
|
+
retryStrategy?: "exponential" | "linear";
|
378
496
|
}
|
379
|
-
declare const definePlugin: <TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>>(plugin: TPlugin) => TPlugin;
|
380
|
-
type Plugins<TPluginArray extends CallApiPlugin[]> = TPluginArray;
|
381
497
|
|
382
498
|
type ModifiedRequestInit = RequestInit & {
|
383
499
|
duplex?: "half";
|
@@ -467,7 +583,7 @@ type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorD
|
|
467
583
|
resultMode: "onlySuccessWithException";
|
468
584
|
} : TErrorData extends false | undefined ? {
|
469
585
|
resultMode?: "onlySuccessWithException";
|
470
|
-
} :
|
586
|
+
} : null extends TResultMode ? {
|
471
587
|
resultMode?: TResultMode;
|
472
588
|
} : {
|
473
589
|
resultMode: TResultMode;
|
@@ -478,51 +594,6 @@ type CallApiRequestOptions<TSchemas extends CallApiSchemas = DefaultMoreOptions>
|
|
478
594
|
type CallApiRequestOptionsForHooks<TSchemas extends CallApiSchemas = DefaultMoreOptions> = Omit<CallApiRequestOptions<TSchemas>, "headers"> & {
|
479
595
|
headers?: Record<string, string | undefined>;
|
480
596
|
};
|
481
|
-
type WithMoreOptions<TMoreOptions = DefaultMoreOptions> = {
|
482
|
-
options: CombinedCallApiExtraOptions & Partial<TMoreOptions>;
|
483
|
-
};
|
484
|
-
interface Interceptors<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> {
|
485
|
-
/**
|
486
|
-
* 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.
|
487
|
-
* It is basically a combination of `onRequestError` and `onResponseError` interceptors
|
488
|
-
*/
|
489
|
-
onError?: (context: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
490
|
-
/**
|
491
|
-
* Interceptor that will be called just before the request is made, allowing for modifications or additional operations.
|
492
|
-
*/
|
493
|
-
onRequest?: (context: RequestContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
494
|
-
/**
|
495
|
-
* Interceptor that will be called when an error occurs during the fetch request.
|
496
|
-
*/
|
497
|
-
onRequestError?: (context: RequestErrorContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
498
|
-
/**
|
499
|
-
* Interceptor that will be called when upload stream progress is tracked
|
500
|
-
*/
|
501
|
-
onRequestStream?: (context: RequestStreamContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
502
|
-
/**
|
503
|
-
* Interceptor that will be called when any response is received from the api, whether successful or not
|
504
|
-
*/
|
505
|
-
onResponse?: (context: ResponseContext<TData, TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
506
|
-
/**
|
507
|
-
* Interceptor that will be called when an error response is received from the api.
|
508
|
-
*/
|
509
|
-
onResponseError?: (context: ResponseErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
510
|
-
/**
|
511
|
-
* Interceptor that will be called when download stream progress is tracked
|
512
|
-
*/
|
513
|
-
onResponseStream?: (context: ResponseStreamContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
514
|
-
/**
|
515
|
-
* Interceptor that will be called when a request is retried.
|
516
|
-
*/
|
517
|
-
onRetry?: (response: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
518
|
-
/**
|
519
|
-
* Interceptor that will be called when a successful response is received from the api.
|
520
|
-
*/
|
521
|
-
onSuccess?: (context: SuccessContext<TData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
522
|
-
}
|
523
|
-
type InterceptorsOrInterceptorArray<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> = {
|
524
|
-
[Key in keyof Interceptors<TData, TErrorData, TMoreOptions>]: Interceptors<TData, TErrorData, TMoreOptions>[Key] | Array<Interceptors<TData, TErrorData, TMoreOptions>[Key]>;
|
525
|
-
};
|
526
597
|
type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
|
527
598
|
type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = DefaultMoreOptions> = {
|
528
599
|
/**
|
@@ -569,7 +640,7 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
569
640
|
* If true, forces the calculation of the total byte size from the request or response body, in case the content-length header is not present or is incorrect.
|
570
641
|
* @default false
|
571
642
|
*/
|
572
|
-
|
643
|
+
forceCalculateStreamSize?: boolean | {
|
573
644
|
request?: boolean;
|
574
645
|
response?: boolean;
|
575
646
|
};
|
@@ -578,14 +649,14 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
578
649
|
*/
|
579
650
|
readonly fullURL?: string;
|
580
651
|
/**
|
581
|
-
* Defines the mode in which the
|
652
|
+
* Defines the mode in which the composed hooks are executed".
|
582
653
|
* - If set to "parallel", main and plugin hooks will be executed in parallel.
|
583
654
|
* - If set to "sequential", the plugin hooks will be executed first, followed by the main hook.
|
584
655
|
* @default "parallel"
|
585
656
|
*/
|
586
657
|
mergedHooksExecutionMode?: "parallel" | "sequential";
|
587
658
|
/**
|
588
|
-
* - Controls what order in which the
|
659
|
+
* - Controls what order in which the composed hooks execute
|
589
660
|
* @default "mainHooksAfterPlugins"
|
590
661
|
*/
|
591
662
|
mergedHooksExecutionOrder?: "mainHooksAfterPlugins" | "mainHooksBeforePlugins";
|
@@ -594,7 +665,7 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
594
665
|
*/
|
595
666
|
plugins?: Plugins<TPluginArray>;
|
596
667
|
/**
|
597
|
-
* Custom function to parse the response string
|
668
|
+
* Custom function to parse the response string
|
598
669
|
*/
|
599
670
|
responseParser?: (responseString: string) => Awaitable<Record<string, unknown>>;
|
600
671
|
/**
|
@@ -626,27 +697,44 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
626
697
|
* Custom validation functions for response validation
|
627
698
|
*/
|
628
699
|
validators?: CallApiValidators<TData, TErrorData>;
|
629
|
-
} &
|
630
|
-
declare const optionsEnumToExtendFromBase: ("plugins" | "schemas" | "validators")[];
|
700
|
+
} & HooksOrHooksArray<TData, TErrorData, Partial<InferPluginOptions<TPluginArray>>> & Partial<InferPluginOptions<TPluginArray>> & MetaOption<TSchemas> & RetryOptions<TErrorData> & ResultModeOption<TErrorData, TResultMode> & UrlOptions<TSchemas>;
|
631
701
|
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = DefaultMoreOptions> = ExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> & {
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
702
|
+
plugins?: Plugins<TPluginArray> | ((context: {
|
703
|
+
basePlugins: Plugins<TPluginArray>;
|
704
|
+
}) => Plugins<TPluginArray>);
|
705
|
+
schemas?: TSchemas | ((context: {
|
706
|
+
baseSchemas: TSchemas;
|
707
|
+
}) => TSchemas);
|
708
|
+
validators?: CallApiValidators<TData, TErrorData> | ((context: {
|
709
|
+
baseValidators: CallApiValidators<TData, TErrorData>;
|
710
|
+
}) => CallApiValidators<TData, TErrorData>);
|
636
711
|
};
|
637
|
-
declare const optionsEnumToOmitFromBase:
|
712
|
+
declare const optionsEnumToOmitFromBase: "dedupeKey"[];
|
638
713
|
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]> & {
|
639
714
|
/**
|
640
|
-
*
|
715
|
+
* Specifies which configuration parts should skip automatic merging between base and main configs.
|
716
|
+
* Use this when you need manual control over how configs are combined.
|
641
717
|
*
|
642
|
-
*
|
718
|
+
* @values
|
719
|
+
* - "all" - Disables automatic merging for both request and options
|
720
|
+
* - "options" - Disables automatic merging of options only
|
721
|
+
* - "request" - Disables automatic merging of request only
|
643
722
|
*
|
644
|
-
*
|
645
|
-
*
|
723
|
+
* @example
|
724
|
+
* ```ts
|
725
|
+
* const client = createFetchClient((ctx) => ({
|
726
|
+
* skipAutoMergeFor: "options",
|
727
|
+
*
|
728
|
+
* // Now you can manually merge options in your config function
|
729
|
+
* ...ctx.options,
|
730
|
+
* }));
|
731
|
+
* ```
|
646
732
|
*/
|
647
|
-
|
733
|
+
skipAutoMergeFor?: "all" | "options" | "request";
|
648
734
|
};
|
649
|
-
type
|
735
|
+
type CombinedExtraOptionsWithoutHooks = Omit<BaseCallApiExtraOptions & CallApiExtraOptions, keyof Hooks>;
|
736
|
+
interface CombinedCallApiExtraOptions extends CombinedExtraOptionsWithoutHooks, Hooks {
|
737
|
+
}
|
650
738
|
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: {
|
651
739
|
initURL: string;
|
652
740
|
options: CallApiExtraOptions;
|
@@ -657,63 +745,6 @@ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TR
|
|
657
745
|
initURL: InferSchemaResult<TSchemas["initURL"], InitURL>,
|
658
746
|
config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>
|
659
747
|
];
|
660
|
-
type RequestContext = UnmaskType<{
|
661
|
-
options: CombinedCallApiExtraOptions;
|
662
|
-
request: CallApiRequestOptionsForHooks;
|
663
|
-
}>;
|
664
|
-
type ResponseContext<TData, TErrorData> = UnmaskType<{
|
665
|
-
data: TData;
|
666
|
-
error: null;
|
667
|
-
options: CombinedCallApiExtraOptions;
|
668
|
-
request: CallApiRequestOptionsForHooks;
|
669
|
-
response: Response;
|
670
|
-
} | {
|
671
|
-
data: null;
|
672
|
-
error: PossibleHTTPError<TErrorData>;
|
673
|
-
options: CombinedCallApiExtraOptions;
|
674
|
-
request: CallApiRequestOptionsForHooks;
|
675
|
-
response: Response;
|
676
|
-
}>;
|
677
|
-
type SuccessContext<TData> = UnmaskType<{
|
678
|
-
data: TData;
|
679
|
-
options: CombinedCallApiExtraOptions;
|
680
|
-
request: CallApiRequestOptionsForHooks;
|
681
|
-
response: Response;
|
682
|
-
}>;
|
683
|
-
type PossibleJavascriptErrorNames = "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | (`${string}Error` & DefaultMoreOptions);
|
684
|
-
type PossibleJavaScriptError = UnmaskType<{
|
685
|
-
errorData: DOMException | Error | SyntaxError | TypeError;
|
686
|
-
message: string;
|
687
|
-
name: PossibleJavascriptErrorNames;
|
688
|
-
}>;
|
689
|
-
type PossibleHTTPError<TErrorData> = UnmaskType<{
|
690
|
-
errorData: TErrorData;
|
691
|
-
message: string;
|
692
|
-
name: "HTTPError";
|
693
|
-
}>;
|
694
|
-
type RequestErrorContext = UnmaskType<{
|
695
|
-
error: PossibleJavaScriptError;
|
696
|
-
options: CombinedCallApiExtraOptions;
|
697
|
-
request: CallApiRequestOptionsForHooks;
|
698
|
-
response: null;
|
699
|
-
}>;
|
700
|
-
type ResponseErrorContext<TErrorData> = UnmaskType<{
|
701
|
-
error: PossibleHTTPError<TErrorData>;
|
702
|
-
options: CombinedCallApiExtraOptions;
|
703
|
-
request: CallApiRequestOptionsForHooks;
|
704
|
-
response: Response;
|
705
|
-
}>;
|
706
|
-
type ErrorContext<TErrorData> = UnmaskType<{
|
707
|
-
error: PossibleHTTPError<TErrorData>;
|
708
|
-
options: CombinedCallApiExtraOptions;
|
709
|
-
request: CallApiRequestOptionsForHooks;
|
710
|
-
response: Response;
|
711
|
-
} | {
|
712
|
-
error: PossibleJavaScriptError;
|
713
|
-
options: CombinedCallApiExtraOptions;
|
714
|
-
request: CallApiRequestOptionsForHooks;
|
715
|
-
response: null;
|
716
|
-
}>;
|
717
748
|
type CallApiResultSuccessVariant<TData> = {
|
718
749
|
data: TData;
|
719
750
|
error: null;
|
@@ -738,24 +769,8 @@ type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TRespo
|
|
738
769
|
onlySuccess: CallApiResultErrorVariant<TComputedErrorData>["data"] | CallApiResultSuccessVariant<TComputedData>["data"];
|
739
770
|
onlySuccessWithException: CallApiResultSuccessVariant<TComputedData>["data"];
|
740
771
|
}>;
|
741
|
-
type ResultModeUnion = keyof ResultModeMap |
|
742
|
-
type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = TErrorData extends false | undefined ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] :
|
772
|
+
type ResultModeUnion = keyof ResultModeMap | null;
|
773
|
+
type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = TErrorData extends false | undefined ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : null 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;
|
743
774
|
type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
|
744
775
|
|
745
|
-
type
|
746
|
-
defaultErrorMessage: string;
|
747
|
-
errorData: TErrorResponse;
|
748
|
-
response: Response;
|
749
|
-
};
|
750
|
-
type ErrorOptions = {
|
751
|
-
cause?: unknown;
|
752
|
-
};
|
753
|
-
declare class HTTPError<TErrorResponse = Record<string, unknown>> extends Error {
|
754
|
-
errorData: ErrorDetails<TErrorResponse>["errorData"];
|
755
|
-
isHTTPError: boolean;
|
756
|
-
name: "HTTPError";
|
757
|
-
response: ErrorDetails<TErrorResponse>["response"];
|
758
|
-
constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
|
759
|
-
}
|
760
|
-
|
761
|
-
export { type ResponseContext as A, type BaseCallApiConfig as B, type CallApiPlugin as C, type DefaultPluginArray as D, type ErrorContext as E, type ResponseErrorContext as F, 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, getDefaultOptions as j, type RetryOptions as k, type BaseCallApiExtraOptions as l, type CallApiExtraOptions as m, type PossibleJavaScriptError as n, type PossibleHTTPError as o, type CallApiRequestOptions as p, type CallApiRequestOptionsForHooks as q, type CallApiResultErrorVariant as r, type CallApiResultSuccessVariant as s, type CombinedCallApiExtraOptions as t, type Interceptors as u, type InterceptorsOrInterceptorArray as v, type PossibleJavascriptErrorNames as w, type Register as x, type RequestContext as y, type RequestErrorContext as z };
|
776
|
+
export { type CallApiRequestOptions as A, type BaseCallApiConfig as B, type CallApiPlugin as C, type DefaultPluginArray as D, type ErrorContext as E, type CallApiRequestOptionsForHooks as F, type CallApiResultErrorVariant as G, HTTPError as H, type InferSchemaResult as I, type CallApiResultSuccessVariant as J, type CombinedCallApiExtraOptions as K, type Register as L, type PluginInitContext as P, type ResultModeUnion as R, type SharedHookContext 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 PluginHooks as j, type PluginHooksWithMoreOptions as k, getDefaultOptions as l, type RetryOptions as m, type PossibleHTTPError as n, type PossibleJavaScriptError as o, type Hooks as p, type HooksOrHooksArray as q, type RequestContext as r, type RequestErrorContext as s, type RequestStreamContext as t, type ResponseContext as u, type ResponseErrorContext as v, type ResponseStreamContext as w, type SuccessContext as x, type BaseCallApiExtraOptions as y, type CallApiExtraOptions as z };
|