@zayne-labs/callapi 1.6.18 → 1.6.21
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 +12 -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-XHBTRTHK.js} +7 -3
- package/dist/esm/chunk-XHBTRTHK.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 +6 -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,10 @@ var defaultExtraOptions = {
|
|
|
221
222
|
retryStatusCodes: defaultRetryStatusCodes,
|
|
222
223
|
retryStrategy: "linear"
|
|
223
224
|
};
|
|
225
|
+
var defaultRequestOptions = {
|
|
226
|
+
method: "GET"
|
|
227
|
+
};
|
|
228
|
+
var getDefaultOptions = () => defaultExtraOptions;
|
|
224
229
|
|
|
225
230
|
// src/utils/common.ts
|
|
226
231
|
var omitKeys = (initialObject, keysToOmit) => {
|
|
@@ -391,7 +396,7 @@ var getPluginArray = (plugins) => {
|
|
|
391
396
|
return plugins;
|
|
392
397
|
};
|
|
393
398
|
var initializePlugins = async (context) => {
|
|
394
|
-
const { baseConfig, config,
|
|
399
|
+
const { baseConfig, config, initURL, options, request } = context;
|
|
395
400
|
const hookRegistries = structuredClone(hooksEnum);
|
|
396
401
|
const addMainHooks = () => {
|
|
397
402
|
for (const key of Object.keys(hooksEnum)) {
|
|
@@ -420,7 +425,6 @@ var initializePlugins = async (context) => {
|
|
|
420
425
|
const initResult = await pluginInit({
|
|
421
426
|
baseConfig,
|
|
422
427
|
config,
|
|
423
|
-
defaultOptions,
|
|
424
428
|
initURL,
|
|
425
429
|
options,
|
|
426
430
|
request
|
|
@@ -522,15 +526,13 @@ var createRetryStrategy = (ctx) => {
|
|
|
522
526
|
if (ctx.error.name !== "HTTPError") {
|
|
523
527
|
return baseRetryCondition;
|
|
524
528
|
}
|
|
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
529
|
const includesMethod = (
|
|
528
530
|
// eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow
|
|
529
|
-
!!ctx.request.method &&
|
|
531
|
+
!!ctx.request.method && ctx.options.retryMethods?.includes(ctx.request.method)
|
|
530
532
|
);
|
|
531
533
|
const includesCodes = (
|
|
532
534
|
// eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow
|
|
533
|
-
!!ctx.response?.status &&
|
|
535
|
+
!!ctx.response?.status && ctx.options.retryStatusCodes?.includes(ctx.response.status)
|
|
534
536
|
);
|
|
535
537
|
return includesCodes && includesMethod && baseRetryCondition;
|
|
536
538
|
};
|
|
@@ -615,7 +617,6 @@ var createFetchClient = (baseConfig = {}) => {
|
|
|
615
617
|
const [initURL, config = {}] = parameters;
|
|
616
618
|
const [fetchOptions, extraOptions] = splitConfig(config);
|
|
617
619
|
const resolvedBaseConfig = isFunction(baseConfig) ? baseConfig({
|
|
618
|
-
defaultOptions: defaultExtraOptions,
|
|
619
620
|
initURL: initURL.toString(),
|
|
620
621
|
options: extraOptions,
|
|
621
622
|
request: fetchOptions
|
|
@@ -635,13 +636,13 @@ var createFetchClient = (baseConfig = {}) => {
|
|
|
635
636
|
...extraOptions
|
|
636
637
|
};
|
|
637
638
|
const mergedRequestOptions = {
|
|
639
|
+
...defaultRequestOptions,
|
|
638
640
|
...baseFetchOptions,
|
|
639
641
|
...fetchOptions
|
|
640
642
|
};
|
|
641
643
|
const { resolvedHooks, resolvedOptions, resolvedRequestOptions, url } = await initializePlugins({
|
|
642
644
|
baseConfig: resolvedBaseConfig,
|
|
643
645
|
config,
|
|
644
|
-
defaultOptions: defaultExtraOptions,
|
|
645
646
|
initURL,
|
|
646
647
|
options: mergedExtraOptions,
|
|
647
648
|
request: mergedRequestOptions
|
|
@@ -803,6 +804,7 @@ var defineParameters = (...parameters) => {
|
|
|
803
804
|
callApi,
|
|
804
805
|
createFetchClient,
|
|
805
806
|
defineParameters,
|
|
806
|
-
definePlugin
|
|
807
|
+
definePlugin,
|
|
808
|
+
getDefaultOptions
|
|
807
809
|
});
|
|
808
810
|
//# sourceMappingURL=index.cjs.map
|