@zayne-labs/callapi 1.7.8 → 1.7.12
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/esm/{chunk-DLKKYMSL.js → chunk-SJZKYDA4.js} +89 -53
- package/dist/esm/chunk-SJZKYDA4.js.map +1 -0
- package/dist/esm/{common-8-vDWsfT.d.ts → common-CUR8HxVd.d.ts} +120 -136
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +84 -102
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/package.json +1 -1
- package/dist/esm/chunk-DLKKYMSL.js.map +0 -1
@@ -1,4 +1,20 @@
|
|
1
|
+
type AnyString = string & {
|
2
|
+
z_placeholder?: never;
|
3
|
+
};
|
4
|
+
type AnyFunction<TResult = unknown> = (...args: any) => TResult;
|
5
|
+
type Prettify<TObject> = NonNullable<unknown> & {
|
6
|
+
[Key in keyof TObject]: TObject[Key];
|
7
|
+
};
|
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);
|
17
|
+
type ValidAuthValue = ValueOrFunctionResult<Awaitable<string | null | undefined>>;
|
2
18
|
/**
|
3
19
|
* Bearer Or Token authentication
|
4
20
|
*
|
@@ -10,20 +26,20 @@ type ValueOrFunctionResult<TValue> = TValue | (() => TValue);
|
|
10
26
|
*/
|
11
27
|
type BearerOrTokenAuth = {
|
12
28
|
type?: "Bearer";
|
13
|
-
bearer?:
|
29
|
+
bearer?: ValidAuthValue;
|
14
30
|
token?: never;
|
15
31
|
} | {
|
16
32
|
type?: "Token";
|
17
33
|
bearer?: never;
|
18
|
-
token?:
|
34
|
+
token?: ValidAuthValue;
|
19
35
|
};
|
20
36
|
/**
|
21
37
|
* Basic auth
|
22
38
|
*/
|
23
39
|
type BasicAuth = {
|
24
40
|
type: "Basic";
|
25
|
-
username:
|
26
|
-
password:
|
41
|
+
username: ValidAuthValue;
|
42
|
+
password: ValidAuthValue;
|
27
43
|
};
|
28
44
|
/**
|
29
45
|
* Custom auth
|
@@ -42,81 +58,13 @@ type BasicAuth = {
|
|
42
58
|
*/
|
43
59
|
type CustomAuth = {
|
44
60
|
type: "Custom";
|
45
|
-
prefix:
|
46
|
-
value:
|
61
|
+
prefix: ValidAuthValue;
|
62
|
+
value: ValidAuthValue;
|
47
63
|
};
|
48
64
|
type Auth = BearerOrTokenAuth | BasicAuth | CustomAuth;
|
49
65
|
|
50
66
|
declare const fetchSpecificKeys: (keyof RequestInit | "duplex")[];
|
51
67
|
|
52
|
-
type AnyString = string & {
|
53
|
-
z_placeholder?: never;
|
54
|
-
};
|
55
|
-
type AnyNumber = number & {
|
56
|
-
z_placeholder?: never;
|
57
|
-
};
|
58
|
-
type AnyFunction<TResult = unknown> = (...args: any) => TResult;
|
59
|
-
type Prettify<TObject> = NonNullable<unknown> & {
|
60
|
-
[Key in keyof TObject]: TObject[Key];
|
61
|
-
};
|
62
|
-
type UnmaskType<TValue> = {
|
63
|
-
_: TValue;
|
64
|
-
}["_"];
|
65
|
-
type Awaitable<TValue> = Promise<TValue> | TValue;
|
66
|
-
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;
|
67
|
-
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
|
68
|
-
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;
|
69
|
-
|
70
|
-
type ErrorDetails<TErrorResponse> = {
|
71
|
-
defaultErrorMessage: CallApiExtraOptions["defaultErrorMessage"];
|
72
|
-
errorData: TErrorResponse;
|
73
|
-
response: Response;
|
74
|
-
};
|
75
|
-
type ErrorOptions = {
|
76
|
-
cause?: unknown;
|
77
|
-
};
|
78
|
-
declare class HTTPError<TErrorResponse = Record<string, unknown>> extends Error {
|
79
|
-
errorData: ErrorDetails<TErrorResponse>["errorData"];
|
80
|
-
isHTTPError: boolean;
|
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
|
-
|
120
68
|
/**
|
121
69
|
* The Standard Schema interface.
|
122
70
|
* @see https://github.com/standard-schema/standard-schema
|
@@ -334,6 +282,90 @@ type DefaultMoreOptions = NonNullable<unknown>;
|
|
334
282
|
type DefaultPluginArray = CallApiPlugin[];
|
335
283
|
type DefaultThrowOnError = boolean;
|
336
284
|
|
285
|
+
type Parser = (responseString: string) => Awaitable<Record<string, unknown>>;
|
286
|
+
declare const getResponseType: <TResponse>(response: Response, parser: Parser) => {
|
287
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
288
|
+
blob: () => Promise<Blob>;
|
289
|
+
formData: () => Promise<FormData>;
|
290
|
+
json: () => Promise<TResponse>;
|
291
|
+
stream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
292
|
+
text: () => Promise<string>;
|
293
|
+
};
|
294
|
+
type InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;
|
295
|
+
type ResponseTypeUnion = keyof InitResponseTypeMap | null;
|
296
|
+
type ResponseTypeMap<TResponse> = {
|
297
|
+
[Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>>;
|
298
|
+
};
|
299
|
+
type GetResponseType<TResponse, TResponseType extends ResponseTypeUnion, TComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType] : never;
|
300
|
+
type CallApiResultSuccessVariant<TData> = {
|
301
|
+
data: TData;
|
302
|
+
error: null;
|
303
|
+
response: Response;
|
304
|
+
};
|
305
|
+
type CallApiResultErrorVariant<TErrorData> = {
|
306
|
+
data: null;
|
307
|
+
error: PossibleHTTPError<TErrorData>;
|
308
|
+
response: Response;
|
309
|
+
} | {
|
310
|
+
data: null;
|
311
|
+
error: PossibleJavaScriptError;
|
312
|
+
response: null;
|
313
|
+
};
|
314
|
+
type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>, TComputedErrorData = GetResponseType<TErrorData, TResponseType>> = UnmaskType<{
|
315
|
+
all: CallApiResultSuccessVariant<TComputedData> | CallApiResultErrorVariant<TComputedErrorData>;
|
316
|
+
allWithException: CallApiResultSuccessVariant<TComputedData>;
|
317
|
+
onlySuccess: CallApiResultErrorVariant<TComputedErrorData>["data"] | CallApiResultSuccessVariant<TComputedData>["data"];
|
318
|
+
onlySuccessWithException: CallApiResultSuccessVariant<TComputedData>["data"];
|
319
|
+
}>;
|
320
|
+
type ResultModeUnion = keyof ResultModeMap | null;
|
321
|
+
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> ? ResultModeMap<TData, TErrorData, TResponseType>[TResultMode] : never;
|
322
|
+
type ErrorDetails<TErrorResponse> = {
|
323
|
+
defaultErrorMessage: CallApiExtraOptions["defaultErrorMessage"];
|
324
|
+
errorData: TErrorResponse;
|
325
|
+
response: Response;
|
326
|
+
};
|
327
|
+
declare class HTTPError<TErrorResponse = Record<string, unknown>> extends Error {
|
328
|
+
errorData: ErrorDetails<TErrorResponse>["errorData"];
|
329
|
+
isHTTPError: boolean;
|
330
|
+
name: "HTTPError";
|
331
|
+
response: ErrorDetails<TErrorResponse>["response"];
|
332
|
+
constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
|
333
|
+
}
|
334
|
+
type PossibleJavaScriptError = UnmaskType<{
|
335
|
+
errorData: DOMException | Error | SyntaxError | TypeError;
|
336
|
+
message: string;
|
337
|
+
name: "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | (`${string}Error` & {});
|
338
|
+
}>;
|
339
|
+
type PossibleHTTPError<TErrorData> = Prettify<UnmaskType<{
|
340
|
+
errorData: TErrorData;
|
341
|
+
message: string;
|
342
|
+
name: "HTTPError";
|
343
|
+
}>>;
|
344
|
+
|
345
|
+
type StreamProgressEvent = {
|
346
|
+
/**
|
347
|
+
* Current chunk of data being streamed
|
348
|
+
*/
|
349
|
+
chunk: Uint8Array;
|
350
|
+
/**
|
351
|
+
* Progress in percentage
|
352
|
+
*/
|
353
|
+
progress: number;
|
354
|
+
/**
|
355
|
+
* Total size of data in bytes
|
356
|
+
*/
|
357
|
+
totalBytes: number;
|
358
|
+
/**
|
359
|
+
* Amount of data transferred so far
|
360
|
+
*/
|
361
|
+
transferredBytes: number;
|
362
|
+
};
|
363
|
+
declare global {
|
364
|
+
interface ReadableStream<R> {
|
365
|
+
[Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
|
366
|
+
}
|
367
|
+
}
|
368
|
+
|
337
369
|
type WithMoreOptions<TMoreOptions = DefaultMoreOptions> = {
|
338
370
|
options: CombinedCallApiExtraOptions & Partial<TMoreOptions>;
|
339
371
|
};
|
@@ -370,7 +402,7 @@ type Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions =
|
|
370
402
|
/**
|
371
403
|
* Hook that will be called when a request is retried.
|
372
404
|
*/
|
373
|
-
onRetry?: (response:
|
405
|
+
onRetry?: (response: RetryContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
374
406
|
/**
|
375
407
|
* Hook that will be called when a successful response is received from the api.
|
376
408
|
*/
|
@@ -420,6 +452,9 @@ type ResponseErrorContext<TErrorData> = UnmaskType<Prettify<SharedHookContext &
|
|
420
452
|
error: PossibleHTTPError<TErrorData>;
|
421
453
|
response: Response;
|
422
454
|
}>>;
|
455
|
+
type RetryContext<TErrorData> = UnmaskType<Prettify<ErrorContext<TErrorData> & {
|
456
|
+
retryAttemptCount: number;
|
457
|
+
}>>;
|
423
458
|
type ErrorContext<TErrorData> = UnmaskType<Prettify<SharedHookContext & {
|
424
459
|
error: PossibleHTTPError<TErrorData>;
|
425
460
|
response: Response;
|
@@ -436,59 +471,22 @@ type ResponseStreamContext = UnmaskType<Prettify<SharedHookContext & {
|
|
436
471
|
response: Response;
|
437
472
|
}>>;
|
438
473
|
|
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>;
|
447
|
-
};
|
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
|
-
type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>, TComputedErrorData = GetResponseType<TErrorData, TResponseType>> = UnmaskType<{
|
455
|
-
all: CallApiResultSuccessVariant<TComputedData> | CallApiResultErrorVariant<TComputedErrorData>;
|
456
|
-
allWithException: CallApiResultSuccessVariant<TComputedData>;
|
457
|
-
allWithoutResponse: CallApiResultSuccessVariant<TComputedData>["data" | "error"] | CallApiResultErrorVariant<TComputedErrorData>["data" | "error"];
|
458
|
-
onlyError: CallApiResultSuccessVariant<TComputedData>["error"] | CallApiResultErrorVariant<TComputedErrorData>["error"];
|
459
|
-
onlyResponse: CallApiResultErrorVariant<TComputedErrorData>["response"] | CallApiResultSuccessVariant<TComputedData>["response"];
|
460
|
-
onlyResponseWithException: CallApiResultSuccessVariant<TComputedData>["response"];
|
461
|
-
onlySuccess: CallApiResultErrorVariant<TComputedErrorData>["data"] | CallApiResultSuccessVariant<TComputedData>["data"];
|
462
|
-
onlySuccessWithException: CallApiResultSuccessVariant<TComputedData>["data"];
|
463
|
-
}>;
|
464
|
-
type ResultModeUnion = keyof ResultModeMap | null;
|
465
|
-
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;
|
466
|
-
|
467
|
-
declare const defaultRetryStatusCodesLookup: {
|
468
|
-
408: "Request Timeout";
|
469
|
-
409: "Conflict";
|
470
|
-
425: "Too Early";
|
471
|
-
429: "Too Many Requests";
|
472
|
-
500: "Internal Server Error";
|
473
|
-
502: "Bad Gateway";
|
474
|
-
503: "Service Unavailable";
|
475
|
-
504: "Gateway Timeout";
|
476
|
-
};
|
477
|
-
|
478
474
|
type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;
|
479
|
-
type InnerRetryKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, "~
|
480
|
-
type InnerRetryOptions<TErrorData> =
|
475
|
+
type InnerRetryKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, "~retryAttemptCount" | "retry">;
|
476
|
+
type InnerRetryOptions<TErrorData> = {
|
481
477
|
[Key in InnerRetryKeys<TErrorData> as Key extends `retry${infer TRest}` ? Uncapitalize<TRest> extends "attempts" ? never : Uncapitalize<TRest> : Key]?: RetryOptions<TErrorData>[Key];
|
482
478
|
} & {
|
483
479
|
attempts: NonNullable<RetryOptions<TErrorData>["retryAttempts"]>;
|
484
|
-
}
|
485
|
-
type RetryStatusCodes = UnmaskType<Array<keyof typeof defaultRetryStatusCodesLookup | AnyNumber>>;
|
480
|
+
};
|
486
481
|
interface RetryOptions<TErrorData> {
|
487
482
|
/**
|
488
483
|
* Keeps track of the number of times the request has already been retried
|
489
484
|
* @deprecated This property is used internally to track retries. Please abstain from modifying it.
|
490
485
|
*/
|
491
486
|
readonly ["~retryAttemptCount"]?: number;
|
487
|
+
/**
|
488
|
+
* All retry options in a single object instead of separate properties
|
489
|
+
*/
|
492
490
|
retry?: InnerRetryOptions<TErrorData>;
|
493
491
|
/**
|
494
492
|
* Number of allowed retry attempts on HTTP errors
|
@@ -517,7 +515,7 @@ interface RetryOptions<TErrorData> {
|
|
517
515
|
/**
|
518
516
|
* HTTP status codes that trigger a retry
|
519
517
|
*/
|
520
|
-
retryStatusCodes?:
|
518
|
+
retryStatusCodes?: number[];
|
521
519
|
/**
|
522
520
|
* Strategy to use when retrying
|
523
521
|
* @default "linear"
|
@@ -712,10 +710,10 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
|
|
712
710
|
basePlugins: Plugins<TPluginArray>;
|
713
711
|
}) => Plugins<TPluginArray>);
|
714
712
|
schemas?: TSchemas | ((context: {
|
715
|
-
baseSchemas: TSchemas;
|
713
|
+
baseSchemas: TSchemas | undefined;
|
716
714
|
}) => TSchemas);
|
717
715
|
validators?: CallApiValidators<TData, TErrorData> | ((context: {
|
718
|
-
baseValidators: CallApiValidators<TData, TErrorData
|
716
|
+
baseValidators: CallApiValidators<TData, TErrorData> | undefined;
|
719
717
|
}) => CallApiValidators<TData, TErrorData>);
|
720
718
|
};
|
721
719
|
declare const optionsEnumToOmitFromBase: "dedupeKey"[];
|
@@ -754,20 +752,6 @@ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TR
|
|
754
752
|
initURL: InferSchemaResult<TSchemas["initURL"], InitURL>,
|
755
753
|
config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>
|
756
754
|
];
|
757
|
-
type CallApiResultSuccessVariant<TData> = {
|
758
|
-
data: TData;
|
759
|
-
error: null;
|
760
|
-
response: Response;
|
761
|
-
};
|
762
|
-
type CallApiResultErrorVariant<TErrorData> = {
|
763
|
-
data: null;
|
764
|
-
error: PossibleHTTPError<TErrorData>;
|
765
|
-
response: Response;
|
766
|
-
} | {
|
767
|
-
data: null;
|
768
|
-
error: PossibleJavaScriptError;
|
769
|
-
response: null;
|
770
|
-
};
|
771
755
|
type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
|
772
756
|
|
773
|
-
export { type
|
757
|
+
export { type CallApiExtraOptions as A, type BaseCallApiConfig as B, type CallApiPlugin as C, type DefaultPluginArray as D, type ErrorContext as E, type CallApiRequestOptions as F, type CallApiRequestOptionsForHooks as G, HTTPError as H, type InferSchemaResult as I, type CombinedCallApiExtraOptions as J, type Register as K, 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, type RetryOptions as l, type PossibleHTTPError as m, type PossibleJavaScriptError as n, type CallApiResultErrorVariant as o, type CallApiResultSuccessVariant as p, type Hooks as q, type HooksOrHooksArray as r, type RequestContext as s, type RequestErrorContext as t, type RequestStreamContext as u, type ResponseContext as v, type ResponseErrorContext as w, type ResponseStreamContext as x, type SuccessContext as y, type BaseCallApiExtraOptions as z };
|
package/dist/esm/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
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 './common-
|
2
|
-
export {
|
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 './common-CUR8HxVd.js';
|
2
|
+
export { z as BaseCallApiExtraOptions, A as CallApiExtraOptions, F as CallApiRequestOptions, G as CallApiRequestOptionsForHooks, o as CallApiResultErrorVariant, p as CallApiResultSuccessVariant, J as CombinedCallApiExtraOptions, E as ErrorContext, H as HTTPError, q as Hooks, r as HooksOrHooksArray, j as PluginHooks, k as PluginHooksWithMoreOptions, P as PluginInitContext, m as PossibleHTTPError, n as PossibleJavaScriptError, K as Register, s as RequestContext, t as RequestErrorContext, u as RequestStreamContext, v as ResponseContext, w as ResponseErrorContext, x as ResponseStreamContext, l as RetryOptions, S as SharedHookContext, y as SuccessContext, i as definePlugin } from './common-CUR8HxVd.js';
|
3
3
|
|
4
4
|
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>(initBaseConfig?: 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>;
|
5
5
|
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>;
|