@zayne-labs/callapi 1.6.18 → 1.6.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{error-DH3yCjyX.d.cts → error-DIHsfUiJ.d.cts} +22 -5
- package/dist/cjs/index.cjs +8 -10
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/utils/index.d.cts +1 -1
- package/dist/esm/{chunk-KLMWU6K5.js → chunk-V7AOCZ3M.js} +4 -3
- package/dist/esm/chunk-V7AOCZ3M.js.map +1 -0
- package/dist/esm/{error-DH3yCjyX.d.ts → error-DIHsfUiJ.d.ts} +22 -5
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +5 -10
- 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-KLMWU6K5.js.map +0 -1
|
@@ -163,12 +163,12 @@ interface RetryOptions<TErrorData> {
|
|
|
163
163
|
* HTTP methods that are allowed to retry
|
|
164
164
|
* @default ["GET", "POST"]
|
|
165
165
|
*/
|
|
166
|
-
retryMethods?: Method[]
|
|
166
|
+
retryMethods?: Method[];
|
|
167
167
|
/**
|
|
168
168
|
* HTTP status codes that trigger a retry
|
|
169
169
|
* @default [409, 425, 429, 500, 502, 503, 504]
|
|
170
170
|
*/
|
|
171
|
-
retryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber
|
|
171
|
+
retryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;
|
|
172
172
|
/**
|
|
173
173
|
* Strategy to use when retrying
|
|
174
174
|
* @default "linear"
|
|
@@ -203,7 +203,6 @@ type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersect
|
|
|
203
203
|
type PluginInitContext<TMoreOptions = DefaultMoreOptions> = WithMoreOptions<TMoreOptions> & {
|
|
204
204
|
baseConfig: BaseCallApiExtraOptions & CallApiRequestOptions;
|
|
205
205
|
config: CallApiExtraOptions & CallApiRequestOptions;
|
|
206
|
-
defaultOptions: CallApiExtraOptions;
|
|
207
206
|
initURL: InitURL | undefined;
|
|
208
207
|
options: CombinedCallApiExtraOptions;
|
|
209
208
|
request: CallApiRequestOptionsForHooks;
|
|
@@ -245,6 +244,25 @@ declare const definePlugin: <TPlugin extends CallApiPlugin | AnyFunction<CallApi
|
|
|
245
244
|
type Plugins<TPluginArray extends CallApiPlugin[]> = TPluginArray;
|
|
246
245
|
|
|
247
246
|
declare const fetchSpecificKeys: ("body" | "cache" | "credentials" | "headers" | "integrity" | "keepalive" | "method" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window")[];
|
|
247
|
+
declare const getDefaultOptions: () => {
|
|
248
|
+
baseURL: string;
|
|
249
|
+
bodySerializer: {
|
|
250
|
+
(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
|
|
251
|
+
(value: any, replacer?: (number | string)[] | null, space?: string | number): string;
|
|
252
|
+
};
|
|
253
|
+
dedupeStrategy: "cancel";
|
|
254
|
+
defaultErrorMessage: string;
|
|
255
|
+
mergedHooksExecutionMode: "parallel";
|
|
256
|
+
mergedHooksExecutionOrder: "mainHooksAfterPlugins";
|
|
257
|
+
responseType: "json";
|
|
258
|
+
resultMode: "all";
|
|
259
|
+
retryAttempts: number;
|
|
260
|
+
retryDelay: number;
|
|
261
|
+
retryMaxDelay: number;
|
|
262
|
+
retryMethods: ("GET" | "POST")[];
|
|
263
|
+
retryStatusCodes: (AnyNumber | 409 | 425 | 429 | 500 | 502 | 503 | 504)[];
|
|
264
|
+
retryStrategy: "linear";
|
|
265
|
+
};
|
|
248
266
|
|
|
249
267
|
/**
|
|
250
268
|
* @description Makes a type required if TSchema type is undefined or if the output type of TSchema contains undefined, otherwise keeps it as is
|
|
@@ -465,7 +483,6 @@ declare const optionsEnumToOmitFromBase: ("dedupeKey" | "extend")[];
|
|
|
465
483
|
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]>;
|
|
466
484
|
type CombinedCallApiExtraOptions = BaseCallApiExtraOptions & CallApiExtraOptions;
|
|
467
485
|
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;
|
|
469
486
|
initURL: string;
|
|
470
487
|
options: CallApiExtraOptions;
|
|
471
488
|
request: CallApiRequestOptions;
|
|
@@ -576,4 +593,4 @@ declare class HTTPError<TErrorResponse = Record<string, unknown>> extends Error
|
|
|
576
593
|
constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
|
|
577
594
|
}
|
|
578
595
|
|
|
579
|
-
export { type
|
|
596
|
+
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 };
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -24,7 +24,8 @@ __export(index_exports, {
|
|
|
24
24
|
callApi: () => callApi,
|
|
25
25
|
createFetchClient: () => createFetchClient,
|
|
26
26
|
defineParameters: () => defineParameters,
|
|
27
|
-
definePlugin: () => definePlugin
|
|
27
|
+
definePlugin: () => definePlugin,
|
|
28
|
+
getDefaultOptions: () => getDefaultOptions
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(index_exports);
|
|
30
31
|
|
|
@@ -221,6 +222,7 @@ var defaultExtraOptions = {
|
|
|
221
222
|
retryStatusCodes: defaultRetryStatusCodes,
|
|
222
223
|
retryStrategy: "linear"
|
|
223
224
|
};
|
|
225
|
+
var getDefaultOptions = () => defaultExtraOptions;
|
|
224
226
|
|
|
225
227
|
// src/utils/common.ts
|
|
226
228
|
var omitKeys = (initialObject, keysToOmit) => {
|
|
@@ -391,7 +393,7 @@ var getPluginArray = (plugins) => {
|
|
|
391
393
|
return plugins;
|
|
392
394
|
};
|
|
393
395
|
var initializePlugins = async (context) => {
|
|
394
|
-
const { baseConfig, config,
|
|
396
|
+
const { baseConfig, config, initURL, options, request } = context;
|
|
395
397
|
const hookRegistries = structuredClone(hooksEnum);
|
|
396
398
|
const addMainHooks = () => {
|
|
397
399
|
for (const key of Object.keys(hooksEnum)) {
|
|
@@ -420,7 +422,6 @@ var initializePlugins = async (context) => {
|
|
|
420
422
|
const initResult = await pluginInit({
|
|
421
423
|
baseConfig,
|
|
422
424
|
config,
|
|
423
|
-
defaultOptions,
|
|
424
425
|
initURL,
|
|
425
426
|
options,
|
|
426
427
|
request
|
|
@@ -522,15 +523,13 @@ var createRetryStrategy = (ctx) => {
|
|
|
522
523
|
if (ctx.error.name !== "HTTPError") {
|
|
523
524
|
return baseRetryCondition;
|
|
524
525
|
}
|
|
525
|
-
const resolvedRetryMethods = isFunction(ctx.options.retryMethods) ? ctx.options.retryMethods(ctx) : ctx.options.retryMethods;
|
|
526
|
-
const resolvedRetryStatusCodes = isFunction(ctx.options.retryStatusCodes) ? ctx.options.retryStatusCodes(ctx) : ctx.options.retryStatusCodes;
|
|
527
526
|
const includesMethod = (
|
|
528
527
|
// eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow
|
|
529
|
-
!!ctx.request.method &&
|
|
528
|
+
!!ctx.request.method && ctx.options.retryMethods?.includes(ctx.request.method)
|
|
530
529
|
);
|
|
531
530
|
const includesCodes = (
|
|
532
531
|
// eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow
|
|
533
|
-
!!ctx.response?.status &&
|
|
532
|
+
!!ctx.response?.status && ctx.options.retryStatusCodes?.includes(ctx.response.status)
|
|
534
533
|
);
|
|
535
534
|
return includesCodes && includesMethod && baseRetryCondition;
|
|
536
535
|
};
|
|
@@ -615,7 +614,6 @@ var createFetchClient = (baseConfig = {}) => {
|
|
|
615
614
|
const [initURL, config = {}] = parameters;
|
|
616
615
|
const [fetchOptions, extraOptions] = splitConfig(config);
|
|
617
616
|
const resolvedBaseConfig = isFunction(baseConfig) ? baseConfig({
|
|
618
|
-
defaultOptions: defaultExtraOptions,
|
|
619
617
|
initURL: initURL.toString(),
|
|
620
618
|
options: extraOptions,
|
|
621
619
|
request: fetchOptions
|
|
@@ -641,7 +639,6 @@ var createFetchClient = (baseConfig = {}) => {
|
|
|
641
639
|
const { resolvedHooks, resolvedOptions, resolvedRequestOptions, url } = await initializePlugins({
|
|
642
640
|
baseConfig: resolvedBaseConfig,
|
|
643
641
|
config,
|
|
644
|
-
defaultOptions: defaultExtraOptions,
|
|
645
642
|
initURL,
|
|
646
643
|
options: mergedExtraOptions,
|
|
647
644
|
request: mergedRequestOptions
|
|
@@ -803,6 +800,7 @@ var defineParameters = (...parameters) => {
|
|
|
803
800
|
callApi,
|
|
804
801
|
createFetchClient,
|
|
805
802
|
defineParameters,
|
|
806
|
-
definePlugin
|
|
803
|
+
definePlugin,
|
|
804
|
+
getDefaultOptions
|
|
807
805
|
});
|
|
808
806
|
//# sourceMappingURL=index.cjs.map
|