@zayne-labs/callapi 1.3.5 → 1.3.7
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/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/options/index.cjs.map +1 -1
- package/dist/cjs/options/index.d.cts +1 -1
- package/dist/cjs/{plugins-Ds-irdHk.d.cts → plugins-jILLQxo1.d.cts} +114 -116
- package/dist/cjs/utils/index.d.cts +2 -2
- package/dist/esm/{chunk-G7B7UXHI.js → chunk-36I75IJA.js} +1 -1
- package/dist/esm/chunk-36I75IJA.js.map +1 -0
- package/dist/esm/chunk-YWY7SE3F.js +1 -0
- package/dist/esm/chunk-YWY7SE3F.js.map +1 -0
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/options/index.d.ts +1 -1
- package/dist/esm/options/index.js +1 -1
- package/dist/esm/{plugins-Ds-irdHk.d.ts → plugins-jILLQxo1.d.ts} +114 -116
- package/dist/esm/utils/index.d.ts +2 -2
- package/dist/esm/utils/index.js +1 -1
- package/package.json +1 -1
- package/dist/esm/chunk-G7B7UXHI.js.map +0 -1
- package/dist/esm/chunk-VT637KNN.js +0 -1
- package/dist/esm/chunk-VT637KNN.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins.ts","../../src/dedupe.ts","../../src/retry.ts","../../src/url.ts","../../src/utils/polyfills.ts","../../src/createFetchClient.ts"],"names":["callApi"],"mappings":";AA0Ea,IAAA,YAAA,GAAe,CAC3B,MACI,KAAA;AACJ,EAAO,OAAA,MAAA;AACR;AAEA,IAAM,gBAAA,GAAmB,CACxB,KAAA,EACA,wBACI,KAAA;AACJ,EAAA,OAAO,OAAO,GAAiC,KAAA;AAC9C,IAAA,IAAI,6BAA6B,YAAc,EAAA;AAC9C,MAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AAEzB,QAAA,MAA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AA,EAAG,KAAM,CAAA,IAAI,KAAK,OAAO,CAAA;AAEvC,QAAmB,kBAAA,EAAA;AAEnB,QAAO,OAAA,cAAA,CAAe,EAAE,OAAA,EAAS,CAAA;AAAA;AAGlC,MAAM,MAAA,YAAA;AAAA;AAAA,QAEL,OAAA,CAAQ,eAAe,YAAY,CAAA;AAAA;AAAA,QAGnC,OAAA,CAAQ,QAAQ,wBAAwB;AAAA,OACzC;AAEA,MAAmB,kBAAA,EAAA;AAEnB,MAAA,OAAO,cAAe,EAAA;AAAA,KAGrB,SAAA;AACD,MAAyB,wBAAA,EAAA;AAAA;AAC1B,GACD;AAEA,EAAAA,SAAQ,MAAS,GAAA,iBAAA;AAEjB,EAAOA,OAAAA,QAAAA;AACR;AAEa,IAAA,OAAA,GAAU,iBAAkB,CAAA,EAAE","file":"chunk-YWY7SE3F.js","sourcesContent":["import type {\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n\tCombinedCallApiExtraOptions,\n\tDefaultMoreOptions,\n\tExtraOptions,\n\tInterceptors,\n\tInterceptorsOrInterceptorArray,\n\tWithMoreOptions,\n} from \"./types\";\nimport { isFunction, isPlainObject, isString } from \"./utils/type-guards\";\nimport type { AnyFunction, Awaitable } from \"./utils/type-helpers\";\n\ntype UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends (\n\tparam: infer TParam\n) => void\n\t? TParam\n\t: never;\n\nexport type InferPluginOptions<TPluginArray extends CallApiPlugin[]> =\n\tTPluginArray extends Array<infer TPlugin extends CallApiPlugin>\n\t\t? TPlugin[\"createExtraOptions\"] extends (...params: never[]) => infer TResult\n\t\t\t? UnionToIntersection<TResult>\n\t\t\t: NonNullable<unknown>\n\t\t: NonNullable<unknown>;\n\nexport type PluginInitContext<TMoreOptions = DefaultMoreOptions> = WithMoreOptions<TMoreOptions> & {\n\tinitURL: string;\n\toptions: CombinedCallApiExtraOptions;\n\trequest: CallApiRequestOptionsForHooks;\n};\n\nexport type PluginInitResult = Partial<\n\tOmit<PluginInitContext, \"request\"> & { request: CallApiRequestOptions }\n>;\n\nexport type CallApiPlugin = {\n\t/**\n\t * Defines additional options that can be passed to callApi\n\t */\n\tcreateExtraOptions?: (...params: never[]) => unknown;\n\n\t/**\n\t * A description for the plugin\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Hooks / Interceptors for the plugin\n\t */\n\thooks?: InterceptorsOrInterceptorArray;\n\n\t/**\n\t * A unique id for the plugin\n\t */\n\tid: string;\n\n\t/**\n\t * A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.\n\t */\n\tinit?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;\n\n\t/**\n\t * A name for the plugin\n\t */\n\tname: string;\n\n\t/**\n\t * A version for the plugin\n\t */\n\tversion?: string;\n};\n\n// eslint-disable-next-line perfectionist/sort-union-types -- Let the first one be first\nexport const definePlugin = <TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin> = CallApiPlugin>(\n\tplugin: TPlugin\n) => {\n\treturn plugin;\n};\n\nconst createMergedHook = (\n\thooks: Array<AnyFunction<Awaitable<unknown>> | undefined>,\n\tmergedHooksExecutionMode: CombinedCallApiExtraOptions[\"mergedHooksExecutionMode\"]\n) => {\n\treturn async (ctx: Record<string, unknown>) => {\n\t\tif (mergedHooksExecutionMode === \"sequential\") {\n\t\t\tfor (const hook of hooks) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop -- This is necessary in this case\n\t\t\t\tawait hook?.(ctx);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tif (mergedHooksExecutionMode === \"parallel\") {\n\t\t\tconst hookArray = [...hooks];\n\n\t\t\tawait Promise.all(hookArray.map((uniqueHook) => uniqueHook?.(ctx)));\n\t\t}\n\t};\n};\n\n// prettier-ignore\ntype HookRegistries = {\n\t[Key in keyof Interceptors]: Set<Interceptors[Key]>;\n};\n\nexport const hooksEnum = {\n\tonError: new Set(),\n\tonRequest: new Set(),\n\tonRequestError: new Set(),\n\tonResponse: new Set(),\n\tonResponseError: new Set(),\n\tonRetry: new Set(),\n\tonSuccess: new Set(),\n} satisfies HookRegistries;\n\nexport const initializePlugins = async (context: PluginInitContext) => {\n\tconst { initURL, options, request } = context;\n\n\tconst hookRegistries = structuredClone(hooksEnum);\n\n\tconst addMainHooks = () => {\n\t\tfor (const key of Object.keys(hooksEnum)) {\n\t\t\tconst mainHook = options[key as keyof Interceptors] as never;\n\n\t\t\thookRegistries[key as keyof Interceptors].add(mainHook);\n\t\t}\n\t};\n\n\tconst addPluginHooks = (pluginHooks: InterceptorsOrInterceptorArray) => {\n\t\tfor (const key of Object.keys(hooksEnum)) {\n\t\t\tconst pluginHook = pluginHooks[key as keyof Interceptors] as never;\n\n\t\t\thookRegistries[key as keyof Interceptors].add(pluginHook);\n\t\t}\n\t};\n\n\tif (options.mergedHooksExecutionOrder === \"mainHooksBeforePlugins\") {\n\t\taddMainHooks();\n\t}\n\n\tconst getPluginArray = (plugins: ExtraOptions[\"plugins\"]) => {\n\t\tif (!plugins) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn isFunction(plugins) ? plugins({ initURL, options, request }) : plugins;\n\t};\n\n\tconst resolvedPlugins = [\n\t\t...getPluginArray(options.plugins),\n\t\t...getPluginArray(options.extend?.plugins),\n\t];\n\n\tlet resolvedUrl = initURL;\n\tlet resolvedOptions = options;\n\tlet resolvedRequestOptions = request;\n\n\tconst executePluginInit = async (pluginInit: CallApiPlugin[\"init\"]) => {\n\t\tif (!pluginInit) return;\n\n\t\tconst initResult = await pluginInit({ initURL, options, request });\n\n\t\tif (!isPlainObject(initResult)) return;\n\n\t\tif (isString(initResult.initURL)) {\n\t\t\tresolvedUrl = initResult.initURL;\n\t\t}\n\n\t\tif (isPlainObject(initResult.request)) {\n\t\t\tresolvedRequestOptions = initResult.request;\n\t\t}\n\n\t\tif (isPlainObject(initResult.options)) {\n\t\t\tresolvedOptions = initResult.options;\n\t\t}\n\t};\n\n\tfor (const plugin of resolvedPlugins) {\n\t\t// eslint-disable-next-line no-await-in-loop -- Await is necessary in this case.\n\t\tawait executePluginInit(plugin.init);\n\n\t\tif (!plugin.hooks) continue;\n\n\t\taddPluginHooks(plugin.hooks);\n\t}\n\n\tif (\n\t\t!options.mergedHooksExecutionOrder ||\n\t\toptions.mergedHooksExecutionOrder === \"mainHooksAfterPlugins\"\n\t) {\n\t\taddMainHooks();\n\t}\n\n\tconst resolvedHooks = {} as Required<Interceptors>;\n\n\tfor (const [key, hookRegistry] of Object.entries(hookRegistries)) {\n\t\tconst flattenedHookArray = [...hookRegistry].flat();\n\n\t\tconst mergedHook = createMergedHook(flattenedHookArray, options.mergedHooksExecutionMode);\n\n\t\tresolvedHooks[key as keyof Interceptors] = mergedHook;\n\t}\n\n\treturn {\n\t\tresolvedHooks,\n\t\tresolvedOptions,\n\t\tresolvedRequestOptions,\n\t\turl: resolvedUrl,\n\t};\n};\n","import type { CallApiExtraOptions, CallApiRequestOptions } from \"./types\";\nimport { getFetchImpl, waitUntil } from \"./utils/common\";\n\ntype RequestInfo = {\n\tcontroller: AbortController;\n\tresponsePromise: Promise<Response>;\n};\n\nexport type RequestInfoCache = Map<string | null, RequestInfo>;\n\ntype DedupeContext = {\n\t$RequestInfoCache: RequestInfoCache;\n\tnewFetchController: AbortController;\n\toptions: CallApiExtraOptions;\n\trequest: CallApiRequestOptions;\n};\n\nexport const createDedupeStrategy = async (context: DedupeContext) => {\n\tconst { $RequestInfoCache, newFetchController, options, request } = context;\n\n\tconst generateDedupeKey = () => {\n\t\tconst shouldHaveDedupeKey =\n\t\t\toptions.dedupeStrategy === \"cancel\" || options.dedupeStrategy === \"defer\";\n\n\t\tif (!shouldHaveDedupeKey) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn `${options.fullURL}-${JSON.stringify({ options, request })}`;\n\t};\n\n\tconst dedupeKey = options.dedupeKey ?? generateDedupeKey();\n\n\t// == This is to ensure cache operations only occur when key is available\n\tconst $RequestInfoCacheOrNull = dedupeKey !== null ? $RequestInfoCache : null;\n\n\t/******\n\t * == Add a small delay to the execution to ensure proper request deduplication when multiple requests with the same key start simultaneously.\n\t * == This gives time for the cache to be updated with the previous request info before the next request checks it.\n\t ******/\n\tif (dedupeKey !== null) {\n\t\tawait waitUntil(0.1);\n\t}\n\n\tconst prevRequestInfo = $RequestInfoCacheOrNull?.get(dedupeKey);\n\n\tconst handleRequestCancelDedupeStrategy = () => {\n\t\tconst shouldCancelRequest = prevRequestInfo && options.dedupeStrategy === \"cancel\";\n\n\t\tif (shouldCancelRequest) {\n\t\t\tconst message = options.dedupeKey\n\t\t\t\t? `Duplicate request detected - Aborting previous request with key '${options.dedupeKey}' as a new request was initiated`\n\t\t\t\t: `Duplicate request detected - Aborting previous request to '${options.fullURL}' as a new request with identical options was initiated`;\n\n\t\t\tconst reason = new DOMException(message, \"AbortError\");\n\n\t\t\tprevRequestInfo.controller.abort(reason);\n\t\t}\n\t};\n\n\tconst handleRequestDeferDedupeStrategy = () => {\n\t\tconst fetchApi = getFetchImpl(options.customFetchImpl);\n\n\t\tconst shouldUsePromiseFromCache = prevRequestInfo && options.dedupeStrategy === \"defer\";\n\n\t\tconst responsePromise = shouldUsePromiseFromCache\n\t\t\t? prevRequestInfo.responsePromise\n\t\t\t: fetchApi(options.fullURL as NonNullable<typeof options.fullURL>, request as RequestInit);\n\n\t\t$RequestInfoCacheOrNull?.set(dedupeKey, { controller: newFetchController, responsePromise });\n\n\t\treturn responsePromise;\n\t};\n\n\tconst removeDedupeKeyFromCache = () => $RequestInfoCacheOrNull?.delete(dedupeKey);\n\n\treturn {\n\t\thandleRequestCancelDedupeStrategy,\n\t\thandleRequestDeferDedupeStrategy,\n\t\tremoveDedupeKeyFromCache,\n\t};\n};\n","/* eslint-disable ts-eslint/consistent-type-definitions -- I need to use interfaces for the sake of user overrides */\n\nimport type { ErrorContext } from \"./types\";\nimport type { AnyNumber, AnyString } from \"./utils/type-helpers\";\n\ntype RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => boolean | Promise<boolean>;\n\nexport interface RetryOptions<TErrorData> {\n\t/**\n\t * Keeps track of the number of times the request has already been retried\n\t * @deprecated This property is used internally to track retries. Please abstain from modifying it.\n\t */\n\treadonly \"~retryCount\"?: number;\n\n\t/**\n\t * Number of allowed retry attempts on HTTP errors\n\t * @default 0\n\t */\n\tretryAttempts?: number;\n\n\t/**\n\t * Callback whose return value determines if a request should be retried or not\n\t */\n\tretryCondition?: RetryCondition<TErrorData>;\n\n\t/**\n\t * Delay between retries in milliseconds\n\t * @default 1000\n\t */\n\tretryDelay?: number;\n\n\t/**\n\t * Maximum delay in milliseconds. Only applies to exponential strategy\n\t * @default 10000\n\t */\n\tretryMaxDelay?: number;\n\n\t/**\n\t * HTTP methods that are allowed to retry\n\t * @default [\"GET\", \"POST\"]\n\t */\n\tretryMethods?: Array<\"GET\" | \"POST\" | AnyString>;\n\n\t/**\n\t * HTTP status codes that trigger a retry\n\t * @default [409, 425, 429, 500, 502, 503, 504]\n\t */\n\tretryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;\n\n\t/**\n\t * Strategy to use when retrying\n\t * @default \"linear\"\n\t */\n\tretryStrategy?: \"exponential\" | \"linear\";\n}\n\nconst getLinearDelay = <TErrorData>(options: RetryOptions<TErrorData>) => options.retryDelay ?? 1000;\n\nconst getExponentialDelay = <TErrorData>(\n\tcurrentAttemptCount: number,\n\toptions: RetryOptions<TErrorData>\n) => {\n\tconst maxDelay = options.retryMaxDelay ?? 10000;\n\n\tconst exponentialDelay = (options.retryDelay ?? 1000) * 2 ** currentAttemptCount;\n\n\treturn Math.min(exponentialDelay, maxDelay);\n};\n\nexport const createRetryStrategy = <TErrorData>(\n\toptions: RetryOptions<TErrorData>,\n\tctx: ErrorContext<TErrorData>\n) => {\n\tconst currentRetryCount = options[\"~retryCount\"] ?? 0;\n\n\treturn {\n\t\tgetDelay: () => {\n\t\t\tif (options.retryStrategy === \"exponential\") {\n\t\t\t\treturn getExponentialDelay(currentRetryCount, options);\n\t\t\t}\n\n\t\t\treturn getLinearDelay(options);\n\t\t},\n\n\t\tshouldAttemptRetry: async () => {\n\t\t\tconst customRetryCondition = (await options.retryCondition?.(ctx)) ?? true;\n\n\t\t\tconst maxRetryAttempts = options.retryAttempts ?? 0;\n\n\t\t\tconst baseRetryCondition = maxRetryAttempts > currentRetryCount && customRetryCondition;\n\n\t\t\tif (ctx.error.name !== \"HTTPError\") {\n\t\t\t\treturn baseRetryCondition;\n\t\t\t}\n\n\t\t\tconst includesMethod =\n\t\t\t\t// eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow\n\t\t\t\t!!ctx.request.method && options.retryMethods?.includes(ctx.request.method);\n\n\t\t\tconst includesCodes =\n\t\t\t\t// eslint-disable-next-line no-implicit-coercion -- Boolean doesn't narrow\n\t\t\t\t!!ctx.response?.status && options.retryStatusCodes?.includes(ctx.response.status);\n\n\t\t\treturn includesCodes && includesMethod && baseRetryCondition;\n\t\t},\n\t};\n};\n","import type { CallApiConfig, CallApiExtraOptions } from \"./types\";\nimport { toQueryString } from \"./utils\";\nimport { isArray } from \"./utils/type-guards\";\n\nconst slash = \"/\";\nconst column = \":\";\nconst mergeUrlWithParams = (url: string, params: CallApiExtraOptions[\"params\"]) => {\n\tif (!params) {\n\t\treturn url;\n\t}\n\n\tlet newUrl = url;\n\n\tif (isArray(params)) {\n\t\tconst matchedParamArray = newUrl.split(slash).filter((param) => param.startsWith(column));\n\n\t\tfor (const [index, matchedParam] of matchedParamArray.entries()) {\n\t\t\tconst realParam = params[index] as string;\n\t\t\tnewUrl = newUrl.replace(matchedParam, realParam);\n\t\t}\n\n\t\treturn newUrl;\n\t}\n\n\tfor (const [key, value] of Object.entries(params)) {\n\t\tnewUrl = newUrl.replace(`${column}${key}`, String(value));\n\t}\n\n\treturn newUrl;\n};\n\nconst questionMark = \"?\";\nconst ampersand = \"&\";\nconst mergeUrlWithQuery = (url: string, query: CallApiConfig[\"query\"]): string => {\n\tif (!query) {\n\t\treturn url;\n\t}\n\n\tconst queryString = toQueryString(query);\n\n\tif (queryString?.length === 0) {\n\t\treturn url;\n\t}\n\n\tif (url.endsWith(questionMark)) {\n\t\treturn `${url}${queryString}`;\n\t}\n\n\tif (url.includes(questionMark)) {\n\t\treturn `${url}${ampersand}${queryString}`;\n\t}\n\n\treturn `${url}${questionMark}${queryString}`;\n};\n\nexport const mergeUrlWithParamsAndQuery = (\n\turl: string,\n\tparams: CallApiExtraOptions[\"params\"],\n\tquery: CallApiExtraOptions[\"query\"]\n) => {\n\tconst urlWithMergedParams = mergeUrlWithParams(url, params);\n\n\treturn mergeUrlWithQuery(urlWithMergedParams, query);\n};\n","// prettier-ignore\nexport const createCombinedSignal = (...signals: Array<AbortSignal | null | undefined>) => AbortSignal.any(signals.filter(Boolean));\n\nexport const createTimeoutSignal = (milliseconds: number) => AbortSignal.timeout(milliseconds);\n","import { type RequestInfoCache, createDedupeStrategy } from \"./dedupe\";\nimport { HTTPError, resolveErrorResult } from \"./error\";\nimport { type CallApiPlugin, hooksEnum, initializePlugins } from \"./plugins\";\nimport { createRetryStrategy } from \"./retry\";\nimport type {\n\tBaseCallApiConfig,\n\tCallApiConfig,\n\tCallApiParameters,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n\tCombinedCallApiExtraOptions,\n\tDefaultDataType,\n\tGetCallApiResult,\n\tInterceptors,\n\tResultModeUnion,\n} from \"./types\";\nimport { mergeUrlWithParamsAndQuery } from \"./url\";\nimport {\n\tcombineHooks,\n\texecuteHooks,\n\tgetResponseData,\n\tmergeAndResolveHeaders,\n\tresolveSuccessResult,\n\tsplitBaseConfig,\n\tsplitConfig,\n\twaitUntil,\n} from \"./utils/common\";\nimport { defaultRetryMethods, defaultRetryStatusCodes } from \"./utils/constants\";\nimport { createCombinedSignal, createTimeoutSignal } from \"./utils/polyfills\";\nimport { isFunction, isHTTPErrorInstance, isPlainObject } from \"./utils/type-guards\";\n\nexport const createFetchClient = <\n\tTBaseData = DefaultDataType,\n\tTBaseErrorData = DefaultDataType,\n\tTBaseResultMode extends ResultModeUnion = ResultModeUnion,\n\tTBasePluginArray extends CallApiPlugin[] = CallApiPlugin[],\n>(\n\tbaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBasePluginArray>\n) => {\n\tconst [baseFetchConfig, baseExtraOptions] = splitBaseConfig(baseConfig ?? {});\n\n\tconst $RequestInfoCache: RequestInfoCache = new Map();\n\n\tconst callApi = async <\n\t\tTData = TBaseData,\n\t\tTErrorData = TBaseErrorData,\n\t\tTResultMode extends ResultModeUnion = TBaseResultMode,\n\t\tTPluginArray extends CallApiPlugin[] = TBasePluginArray,\n\t>(\n\t\t...parameters: CallApiParameters<TData, TErrorData, TResultMode, TPluginArray>\n\t): Promise<GetCallApiResult<TData, TErrorData, TResultMode>> => {\n\t\tconst [initURL, config = {} as never] = parameters;\n\n\t\tconst [fetchConfig, extraOptions] = splitConfig(config);\n\n\t\tconst initCombinedHooks = {} as Required<Interceptors>;\n\n\t\tfor (const key of Object.keys(hooksEnum)) {\n\t\t\tconst combinedHook = combineHooks(\n\t\t\t\tbaseExtraOptions[key as keyof Interceptors],\n\t\t\t\textraOptions[key as keyof Interceptors]\n\t\t\t);\n\n\t\t\tinitCombinedHooks[key as keyof Interceptors] = combinedHook as never;\n\t\t}\n\n\t\t// == Default Extra Options\n\t\tconst defaultExtraOptions = {\n\t\t\tbaseURL: \"\",\n\t\t\tbodySerializer: JSON.stringify,\n\t\t\tdedupeStrategy: \"cancel\",\n\t\t\tdefaultErrorMessage: \"Failed to fetch data from server!\",\n\t\t\tmergedHooksExecutionMode: \"parallel\",\n\t\t\tmergedHooksExecutionOrder: \"mainHooksAfterPlugins\",\n\t\t\tresponseType: \"json\",\n\t\t\tresultMode: \"all\",\n\t\t\tretryAttempts: 0,\n\t\t\tretryDelay: 1000,\n\t\t\tretryMaxDelay: 10000,\n\t\t\tretryMethods: defaultRetryMethods,\n\t\t\tretryStatusCodes: defaultRetryStatusCodes,\n\t\t\tretryStrategy: \"linear\",\n\n\t\t\t...baseExtraOptions,\n\t\t\t...extraOptions,\n\n\t\t\t...initCombinedHooks,\n\t\t} satisfies CombinedCallApiExtraOptions;\n\n\t\tconst body = fetchConfig.body ?? baseFetchConfig.body;\n\n\t\t// == Default Request Options\n\t\tconst defaultRequestOptions = {\n\t\t\tbody: isPlainObject(body) ? defaultExtraOptions.bodySerializer(body) : body,\n\t\t\tmethod: \"GET\",\n\n\t\t\t...baseFetchConfig,\n\t\t\t...fetchConfig,\n\n\t\t\theaders: mergeAndResolveHeaders({\n\t\t\t\tauth: defaultExtraOptions.auth,\n\t\t\t\tbaseHeaders: baseFetchConfig.headers,\n\t\t\t\tbody,\n\t\t\t\theaders: fetchConfig.headers,\n\t\t\t}),\n\n\t\t\tsignal: fetchConfig.signal ?? baseFetchConfig.signal,\n\t\t} satisfies CallApiRequestOptions;\n\n\t\tconst { resolvedHooks, resolvedOptions, resolvedRequestOptions, url } = await initializePlugins({\n\t\t\tinitURL,\n\t\t\toptions: defaultExtraOptions,\n\t\t\trequest: defaultRequestOptions,\n\t\t});\n\n\t\tconst fullURL = `${resolvedOptions.baseURL}${mergeUrlWithParamsAndQuery(url, resolvedOptions.params, resolvedOptions.query)}`;\n\n\t\tconst options = {\n\t\t\t...resolvedOptions,\n\t\t\t...resolvedHooks,\n\t\t\tfullURL,\n\t\t\tinitURL,\n\t\t} satisfies CombinedCallApiExtraOptions as typeof defaultExtraOptions & typeof resolvedHooks;\n\n\t\tconst newFetchController = new AbortController();\n\n\t\tconst timeoutSignal = options.timeout != null ? createTimeoutSignal(options.timeout) : null;\n\n\t\tconst combinedSignal = createCombinedSignal(\n\t\t\tresolvedRequestOptions.signal,\n\t\t\ttimeoutSignal,\n\t\t\tnewFetchController.signal\n\t\t);\n\n\t\tconst request = {\n\t\t\t...resolvedRequestOptions,\n\t\t\tsignal: combinedSignal,\n\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\tconst {\n\t\t\thandleRequestCancelDedupeStrategy,\n\t\t\thandleRequestDeferDedupeStrategy,\n\t\t\tremoveDedupeKeyFromCache,\n\t\t} = await createDedupeStrategy({ $RequestInfoCache, newFetchController, options, request });\n\n\t\thandleRequestCancelDedupeStrategy();\n\n\t\ttry {\n\t\t\tawait executeHooks(options.onRequest({ options, request }));\n\n\t\t\t// == Apply determined headers again after onRequest incase they were modified\n\t\t\trequest.headers = mergeAndResolveHeaders({\n\t\t\t\tauth: options.auth,\n\t\t\t\tbaseHeaders: baseFetchConfig.headers,\n\t\t\t\tbody,\n\t\t\t\theaders: request.headers,\n\t\t\t});\n\n\t\t\tconst response = await handleRequestDeferDedupeStrategy();\n\n\t\t\t// == Also clone response when dedupeStrategy is set to \"defer\", to avoid error thrown from reading response.(whatever) more than once\n\t\t\tconst shouldCloneResponse = options.dedupeStrategy === \"defer\" || options.cloneResponse;\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst errorData = await getResponseData<TErrorData>(\n\t\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\t\toptions.responseType,\n\t\t\t\t\toptions.responseParser,\n\t\t\t\t\toptions.responseErrorValidator\n\t\t\t\t);\n\n\t\t\t\t// == Push all error handling responsibilities to the catch block if not retrying\n\t\t\t\tthrow new HTTPError({\n\t\t\t\t\tdefaultErrorMessage: options.defaultErrorMessage,\n\t\t\t\t\terrorData,\n\t\t\t\t\tresponse,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst successData = await getResponseData<TData>(\n\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\toptions.responseType,\n\t\t\t\toptions.responseParser,\n\t\t\t\toptions.responseValidator\n\t\t\t);\n\n\t\t\tconst successContext = {\n\t\t\t\tdata: successData as never,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse: options.cloneResponse ? response.clone() : response,\n\t\t\t};\n\n\t\t\tawait executeHooks(\n\t\t\t\toptions.onSuccess(successContext),\n\n\t\t\t\toptions.onResponse({ ...successContext, error: null })\n\t\t\t);\n\n\t\t\treturn await resolveSuccessResult({\n\t\t\t\tdata: successContext.data,\n\t\t\t\tresponse: successContext.response,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t});\n\n\t\t\t// == Exhaustive Error handling\n\t\t} catch (error) {\n\t\t\tconst { errorVariantDetails, getErrorResult } = resolveErrorResult({\n\t\t\t\tcloneResponse: options.cloneResponse,\n\t\t\t\tdefaultErrorMessage: options.defaultErrorMessage,\n\t\t\t\terror,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t});\n\n\t\t\tconst errorContext = {\n\t\t\t\terror: errorVariantDetails.error as never,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t};\n\n\t\t\tconst errorContextWithResponse = {\n\t\t\t\t...errorContext,\n\t\t\t\tresponse: errorVariantDetails.response as NonNullable<typeof errorVariantDetails.response>,\n\t\t\t};\n\n\t\t\tconst { getDelay, shouldAttemptRetry } = createRetryStrategy(options, errorContextWithResponse);\n\n\t\t\tconst shouldRetry = !combinedSignal.aborted && (await shouldAttemptRetry());\n\n\t\t\tif (shouldRetry) {\n\t\t\t\tawait executeHooks(options.onRetry(errorContextWithResponse));\n\n\t\t\t\tconst delay = getDelay();\n\n\t\t\t\tawait waitUntil(delay);\n\n\t\t\t\t// prettier-ignore\n\t\t\t\tconst updatedOptions = {...config, \"~retryCount\": (options[\"~retryCount\"] ?? 0) + 1} satisfies CallApiConfig<TData, TErrorData, TResultMode>\n\n\t\t\t\treturn await callApi(initURL, updatedOptions);\n\t\t\t}\n\n\t\t\tconst shouldThrowOnError = isFunction(options.throwOnError)\n\t\t\t\t? options.throwOnError(errorContextWithResponse)\n\t\t\t\t: options.throwOnError;\n\n\t\t\t// eslint-disable-next-line unicorn/consistent-function-scoping -- False alarm: this function is depends on this scope\n\t\t\tconst handleThrowOnError = () => {\n\t\t\t\tif (!shouldThrowOnError) return;\n\n\t\t\t\t// eslint-disable-next-line ts-eslint/only-throw-error -- It's fine to throw this\n\t\t\t\tthrow errorVariantDetails.error;\n\t\t\t};\n\n\t\t\tif (isHTTPErrorInstance<TErrorData>(error)) {\n\t\t\t\tawait executeHooks(\n\t\t\t\t\toptions.onResponseError(errorContextWithResponse),\n\n\t\t\t\t\toptions.onError(errorContextWithResponse),\n\n\t\t\t\t\toptions.onResponse({ ...errorContextWithResponse, data: null })\n\t\t\t\t);\n\n\t\t\t\thandleThrowOnError();\n\n\t\t\t\treturn getErrorResult();\n\t\t\t}\n\n\t\t\tif (error instanceof DOMException && error.name === \"AbortError\") {\n\t\t\t\tconst { message, name } = error;\n\n\t\t\t\tconsole.error(`${name}:`, message);\n\n\t\t\t\thandleThrowOnError();\n\n\t\t\t\treturn getErrorResult();\n\t\t\t}\n\n\t\t\tif (error instanceof DOMException && error.name === \"TimeoutError\") {\n\t\t\t\tconst message = `Request timed out after ${options.timeout}ms`;\n\n\t\t\t\tconsole.error(`${error.name}:`, message);\n\n\t\t\t\thandleThrowOnError();\n\n\t\t\t\treturn getErrorResult({ message });\n\t\t\t}\n\n\t\t\tawait executeHooks(\n\t\t\t\t// == At this point only the request errors exist, so the request error interceptor is called\n\t\t\t\toptions.onRequestError(errorContext),\n\n\t\t\t\t// == Also call the onError interceptor\n\t\t\t\toptions.onError(errorContextWithResponse)\n\t\t\t);\n\n\t\t\thandleThrowOnError();\n\n\t\t\treturn getErrorResult();\n\n\t\t\t// == Removing the now unneeded AbortController from store\n\t\t} finally {\n\t\t\tremoveDedupeKeyFromCache();\n\t\t}\n\t};\n\n\tcallApi.create = createFetchClient;\n\n\treturn callApi;\n};\n\nexport const callApi = createFetchClient({});\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as ResultModeUnion, C as CallApiPlugin,
|
|
2
|
-
export { b as BaseCallApiExtraOptions, c as CallApiExtraOptions, g as CallApiParameters, h as CallApiRequestOptions, i as CallApiRequestOptionsForHooks, j as CallApiResultErrorVariant, k as CallApiResultSuccessVariant, l as CombinedCallApiExtraOptions, E as ErrorContext, I as Interceptors, m as InterceptorsOrInterceptorArray, P as PluginInitContext, f as PossibleHTTPError, e as PossibleJavaScriptError, n as PossibleJavascriptErrorNames, o as Register, p as RequestContext, q as RequestErrorContext, r as ResponseContext, s as ResponseErrorContext, S as SuccessContext, d as definePlugin } from './plugins-
|
|
1
|
+
import { R as ResultModeUnion, C as CallApiPlugin, a as CallApiConfig, G as GetCallApiResult, B as BaseCallApiConfig } from './plugins-jILLQxo1.js';
|
|
2
|
+
export { b as BaseCallApiExtraOptions, c as CallApiExtraOptions, g as CallApiParameters, h as CallApiRequestOptions, i as CallApiRequestOptionsForHooks, j as CallApiResultErrorVariant, k as CallApiResultSuccessVariant, l as CombinedCallApiExtraOptions, E as ErrorContext, I as Interceptors, m as InterceptorsOrInterceptorArray, P as PluginInitContext, f as PossibleHTTPError, e as PossibleJavaScriptError, n as PossibleJavascriptErrorNames, o as Register, p as RequestContext, q as RequestErrorContext, r as ResponseContext, s as ResponseErrorContext, S as SuccessContext, d as definePlugin } from './plugins-jILLQxo1.js';
|
|
3
3
|
export { H as HTTPError } from './error-lBRMiMeF.js';
|
|
4
4
|
|
|
5
5
|
declare const createFetchClient: <TBaseData = unknown, TBaseErrorData = unknown, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBasePluginArray extends CallApiPlugin[] = CallApiPlugin[]>(baseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBasePluginArray>) => {
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{callApi,createFetchClient,definePlugin}from"./chunk-
|
|
1
|
+
export{callApi,createFetchClient,definePlugin}from"./chunk-YWY7SE3F.js";export{HTTPError}from"./chunk-36I75IJA.js";//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DefaultDataType, R as ResultModeUnion, C as CallApiPlugin, a as CallApiConfig,
|
|
1
|
+
import { D as DefaultDataType, R as ResultModeUnion, C as CallApiPlugin, a as CallApiConfig, G as GetCallApiResult, B as BaseCallApiConfig } from '../plugins-jILLQxo1.js';
|
|
2
2
|
|
|
3
3
|
type CallApiConfigWithRequiredURL<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = CallApiConfig<TData, TErrorData, TResultMode, TPluginArray> & {
|
|
4
4
|
initURL: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{hooksEnum as e,initializePlugins as r,mergeUrlWithParamsAndQuery as o,createTimeoutSignal as t,createCombinedSignal as s,createDedupeStrategy as a,createRetryStrategy as n,createFetchClient as i}from"../chunk-YWY7SE3F.js";import{splitBaseConfig as l,splitConfig as u,combineHooks as d,mergeAndResolveHeaders as c,isPlainObject as p,defaultRetryStatusCodes as y,defaultRetryMethods as h,executeHooks as f,getResponseData as m,HTTPError as g,resolveSuccessResult as w,resolveErrorResult as R,waitUntil as E,isFunction as M,isHTTPErrorInstance as b}from"../chunk-36I75IJA.js";var q=q=>{const[D,S]=l(q??{}),O=new Map,k=async i=>{const{initURL:l,...q}=i,[C,v]=u(q),x={};for(const r of Object.keys(e)){const e=d(S[r],v[r]);x[r]=e}const A={baseURL:"",bodySerializer:JSON.stringify,dedupeStrategy:"cancel",defaultErrorMessage:"Failed to fetch data from server!",mergedHooksExecutionMode:"parallel",mergedHooksExecutionOrder:"mainHooksAfterPlugins",responseType:"json",resultMode:"all",retryAttempts:0,retryDelay:1e3,retryMaxDelay:1e4,retryMethods:h,retryStatusCodes:y,retryStrategy:"linear",...S,...v,...x},H=C.body??D.body,L={body:p(H)?A.bodySerializer(H):H,method:"GET",...D,...C,headers:c({auth:A.auth,baseHeaders:D.headers,body:H,headers:C.headers}),signal:C.signal??D.signal},{resolvedHooks:U,resolvedOptions:$,resolvedRequestOptions:T,url:j}=await r({initURL:l,options:A,request:L}),F=`${$.baseURL}${o(j,$.params,$.query)}`,I={...$,...U,fullURL:F,initURL:l},P=new AbortController,V=null!=I.timeout?t(I.timeout):null,z=s(T.signal,V,P.signal),J={...T,signal:z},{handleRequestCancelDedupeStrategy:Y,handleRequestDeferDedupeStrategy:G,removeDedupeKeyFromCache:K}=await a({$RequestInfoCache:O,newFetchController:P,options:I,request:J});Y();try{await f(I.onRequest({options:I,request:J})),J.headers=c({auth:I.auth,baseHeaders:D.headers,body:H,headers:J.headers});const e=await G(),r="defer"===I.dedupeStrategy||I.cloneResponse;if(!e.ok){const o=await m(r?e.clone():e,I.responseType,I.responseParser,I.responseErrorValidator);throw new g({defaultErrorMessage:I.defaultErrorMessage,errorData:o,response:e})}const o={data:await m(r?e.clone():e,I.responseType,I.responseParser,I.responseValidator),options:I,request:J,response:I.cloneResponse?e.clone():e};return await f(I.onSuccess(o),I.onResponse({...o,error:null})),await w({data:o.data,response:o.response,resultMode:I.resultMode})}catch(e){const{errorVariantDetails:r,getErrorResult:o}=R({cloneResponse:I.cloneResponse,defaultErrorMessage:I.defaultErrorMessage,error:e,resultMode:I.resultMode}),t={error:r.error,options:I,request:J},s={...t,response:r.response},{getDelay:a,shouldAttemptRetry:l}=n(I,s);if(!z.aborted&&await l()){await f(I.onRetry(s));const e=a();await E(e);const r={...i,"~retryCount":(I["~retryCount"]??0)+1};return await k(r)}const u=M(I.throwOnError)?I.throwOnError(s):I.throwOnError,d=()=>{if(u)throw r.error};if(b(e))return await f(I.onResponseError(s),I.onError(s),I.onResponse({...s,data:null})),d(),o();if(e instanceof DOMException&&"AbortError"===e.name){const{message:r,name:t}=e;return console.error(`${t}:`,r),d(),o()}if(e instanceof DOMException&&"TimeoutError"===e.name){const r=`Request timed out after ${I.timeout}ms`;return console.error(`${e.name}:`,r),d(),o({message:r})}return await f(I.onRequestError(t),I.onError(s)),d(),o()}finally{K()}};return k.create=i,k},D=q(),S=e=>e;export{D as callApiWithOptions,q as createFetchClientWithOptions,S as defineOptions};//# sourceMappingURL=index.js.map
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
type AnyString = string & {
|
|
2
|
-
z_placeholder?: never;
|
|
3
|
-
};
|
|
4
|
-
type AnyNumber = number & {
|
|
5
|
-
z_placeholder?: never;
|
|
6
|
-
};
|
|
7
|
-
type AnyFunction<TResult = any> = (...args: any[]) => TResult;
|
|
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
|
-
|
|
16
1
|
type ValueOrFunctionResult<TValue> = TValue | (() => TValue);
|
|
17
2
|
/**
|
|
18
3
|
* Bearer Or Token authentication
|
|
@@ -62,48 +47,34 @@ type CustomAuth = {
|
|
|
62
47
|
};
|
|
63
48
|
type Auth = BearerOrTokenAuth | BasicAuth | CustomAuth;
|
|
64
49
|
|
|
65
|
-
type
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* @default ["GET", "POST"]
|
|
94
|
-
*/
|
|
95
|
-
retryMethods?: Array<"GET" | "POST" | AnyString>;
|
|
96
|
-
/**
|
|
97
|
-
* @description HTTP status codes that trigger a retry
|
|
98
|
-
* @default [409, 425, 429, 500, 502, 503, 504]
|
|
99
|
-
*/
|
|
100
|
-
retryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;
|
|
101
|
-
/**
|
|
102
|
-
* @description Strategy to use when retrying
|
|
103
|
-
* @default "linear"
|
|
104
|
-
*/
|
|
105
|
-
retryStrategy?: "exponential" | "linear";
|
|
106
|
-
}
|
|
50
|
+
type AnyString = string & {
|
|
51
|
+
z_placeholder?: never;
|
|
52
|
+
};
|
|
53
|
+
type AnyNumber = number & {
|
|
54
|
+
z_placeholder?: never;
|
|
55
|
+
};
|
|
56
|
+
type AnyFunction<TResult = any> = (...args: any[]) => TResult;
|
|
57
|
+
type UnmaskType<TValue> = {
|
|
58
|
+
_: TValue;
|
|
59
|
+
}["_"];
|
|
60
|
+
type Awaitable<TValue> = Promise<TValue> | TValue;
|
|
61
|
+
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;
|
|
62
|
+
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
|
|
63
|
+
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;
|
|
64
|
+
|
|
65
|
+
type ToQueryStringFn = {
|
|
66
|
+
(params: CallApiConfig["query"]): string | null;
|
|
67
|
+
(params: Required<CallApiConfig>["query"]): string;
|
|
68
|
+
};
|
|
69
|
+
declare const toQueryString: ToQueryStringFn;
|
|
70
|
+
declare const getResponseType: <TResponse>(response: Response, parser?: Required<CallApiExtraOptions>["responseParser"]) => {
|
|
71
|
+
arrayBuffer: () => Promise<TResponse>;
|
|
72
|
+
blob: () => Promise<TResponse>;
|
|
73
|
+
formData: () => Promise<TResponse>;
|
|
74
|
+
json: () => Promise<Record<string, unknown> | TResponse>;
|
|
75
|
+
stream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
|
76
|
+
text: () => Promise<TResponse>;
|
|
77
|
+
};
|
|
107
78
|
|
|
108
79
|
declare const fetchSpecificKeys: ("headers" | "body" | "cache" | "credentials" | "integrity" | "keepalive" | "method" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window")[];
|
|
109
80
|
declare const defaultRetryMethods: ("GET" | "POST")[];
|
|
@@ -112,15 +83,15 @@ declare const defaultRetryStatusCodes: Required<BaseCallApiConfig>["retryStatusC
|
|
|
112
83
|
type FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], "body" | "headers" | "method">;
|
|
113
84
|
interface CallApiRequestOptions extends Pick<RequestInit, FetchSpecificKeysUnion> {
|
|
114
85
|
/**
|
|
115
|
-
*
|
|
86
|
+
* Optional body of the request, can be a object or any other supported body type.
|
|
116
87
|
*/
|
|
117
88
|
body?: Record<string, unknown> | RequestInit["body"];
|
|
118
89
|
/**
|
|
119
|
-
*
|
|
90
|
+
* Headers to be used in the request.
|
|
120
91
|
*/
|
|
121
92
|
headers?: Record<"Authorization", CommonAuthorizationHeaders> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | RequestInit["headers"];
|
|
122
93
|
/**
|
|
123
|
-
*
|
|
94
|
+
* HTTP method for the request.
|
|
124
95
|
* @default "GET"
|
|
125
96
|
*/
|
|
126
97
|
method?: "DELETE" | "GET" | "PATCH" | "POST" | "PUT" | AnyString;
|
|
@@ -137,32 +108,32 @@ type WithMoreOptions<TMoreOptions = DefaultMoreOptions> = {
|
|
|
137
108
|
};
|
|
138
109
|
interface Interceptors<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> {
|
|
139
110
|
/**
|
|
140
|
-
*
|
|
111
|
+
* 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.
|
|
141
112
|
* It is basically a combination of `onRequestError` and `onResponseError` interceptors
|
|
142
113
|
*/
|
|
143
114
|
onError?: (context: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
144
115
|
/**
|
|
145
|
-
*
|
|
116
|
+
* Interceptor that will be called just before the request is made, allowing for modifications or additional operations.
|
|
146
117
|
*/
|
|
147
118
|
onRequest?: (context: RequestContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
148
119
|
/**
|
|
149
|
-
*
|
|
120
|
+
* Interceptor that will be called when an error occurs during the fetch request.
|
|
150
121
|
*/
|
|
151
122
|
onRequestError?: (context: RequestErrorContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
152
123
|
/**
|
|
153
|
-
*
|
|
124
|
+
* Interceptor that will be called when any response is received from the api, whether successful or not
|
|
154
125
|
*/
|
|
155
126
|
onResponse?: (context: ResponseContext<TData, TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
156
127
|
/**
|
|
157
|
-
*
|
|
128
|
+
* Interceptor that will be called when an error response is received from the api.
|
|
158
129
|
*/
|
|
159
130
|
onResponseError?: (context: ResponseErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
160
131
|
/**
|
|
161
|
-
*
|
|
132
|
+
* Interceptor that will be called when a request is retried.
|
|
162
133
|
*/
|
|
163
134
|
onRetry?: (response: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
164
135
|
/**
|
|
165
|
-
*
|
|
136
|
+
* Interceptor that will be called when a successful response is received from the api.
|
|
166
137
|
*/
|
|
167
138
|
onSuccess?: (context: SuccessContext<TData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
|
|
168
139
|
}
|
|
@@ -173,36 +144,36 @@ type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit)
|
|
|
173
144
|
type Meta = Register extends {
|
|
174
145
|
meta?: infer TMeta extends Record<string, unknown>;
|
|
175
146
|
} ? TMeta : never;
|
|
176
|
-
type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> =
|
|
147
|
+
type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = {
|
|
177
148
|
/**
|
|
178
|
-
*
|
|
149
|
+
* Authorization header value.
|
|
179
150
|
*/
|
|
180
151
|
auth?: string | Auth | null;
|
|
181
152
|
/**
|
|
182
|
-
*
|
|
153
|
+
* Base URL to be prepended to all request URLs
|
|
183
154
|
*/
|
|
184
155
|
baseURL?: string;
|
|
185
156
|
/**
|
|
186
|
-
*
|
|
157
|
+
* Custom function to serialize the body object into a string.
|
|
187
158
|
*/
|
|
188
159
|
bodySerializer?: (bodyData: Record<string, unknown>) => string;
|
|
189
160
|
/**
|
|
190
|
-
*
|
|
161
|
+
* Whether or not to clone the response, so response.json() and the like, can be read again else where.
|
|
191
162
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/clone
|
|
192
163
|
* @default false
|
|
193
164
|
*/
|
|
194
165
|
cloneResponse?: boolean;
|
|
195
166
|
/**
|
|
196
|
-
*
|
|
167
|
+
* Custom fetch implementation
|
|
197
168
|
*/
|
|
198
169
|
customFetchImpl?: FetchImpl;
|
|
199
170
|
/**
|
|
200
|
-
*
|
|
171
|
+
* Custom request key to be used to identify a request in the fetch deduplication strategy.
|
|
201
172
|
* @default the full request url + string formed from the request options
|
|
202
173
|
*/
|
|
203
174
|
dedupeKey?: string;
|
|
204
175
|
/**
|
|
205
|
-
*
|
|
176
|
+
* Defines the deduplication strategy for the request, can be set to "none" | "defer" | "cancel".
|
|
206
177
|
* - If set to "cancel", the previous pending request with the same request key will be cancelled and lets the new request through.
|
|
207
178
|
* - If set to "defer", all new request with the same request key will be share the same response, until the previous one is completed.
|
|
208
179
|
* - If set to "none", deduplication is disabled.
|
|
@@ -210,32 +181,32 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
|
210
181
|
*/
|
|
211
182
|
dedupeStrategy?: "cancel" | "defer" | "none";
|
|
212
183
|
/**
|
|
213
|
-
*
|
|
184
|
+
* Default error message to use if none is provided from a response.
|
|
214
185
|
* @default "Failed to fetch data from server!"
|
|
215
186
|
*/
|
|
216
187
|
defaultErrorMessage?: string;
|
|
217
188
|
/**
|
|
218
|
-
*
|
|
189
|
+
* Resolved request URL
|
|
219
190
|
*/
|
|
220
191
|
readonly fullURL?: string;
|
|
221
192
|
/**
|
|
222
|
-
*
|
|
193
|
+
* URL to be used in the request.
|
|
223
194
|
*/
|
|
224
195
|
readonly initURL?: string;
|
|
225
196
|
/**
|
|
226
|
-
*
|
|
197
|
+
* Defines the mode in which the merged hooks are executed, can be set to "parallel" | "sequential".
|
|
227
198
|
* - If set to "parallel", main and plugin hooks will be executed in parallel.
|
|
228
199
|
* - If set to "sequential", the plugin hooks will be executed first, followed by the main hook.
|
|
229
200
|
* @default "parallel"
|
|
230
201
|
*/
|
|
231
202
|
mergedHooksExecutionMode?: "parallel" | "sequential";
|
|
232
203
|
/**
|
|
233
|
-
*
|
|
204
|
+
* - Controls what order in which the merged hooks execute
|
|
234
205
|
* @default "mainHooksLast"
|
|
235
206
|
*/
|
|
236
207
|
mergedHooksExecutionOrder?: "mainHooksAfterPlugins" | "mainHooksBeforePlugins";
|
|
237
208
|
/**
|
|
238
|
-
*
|
|
209
|
+
* - An optional field you can fill with additional information,
|
|
239
210
|
* to associate with the request, typically used for logging or tracing.
|
|
240
211
|
*
|
|
241
212
|
* - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
|
|
@@ -259,37 +230,37 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
|
259
230
|
*/
|
|
260
231
|
meta?: Meta;
|
|
261
232
|
/**
|
|
262
|
-
*
|
|
233
|
+
* Params to be appended to the URL (i.e: /:id)
|
|
263
234
|
*/
|
|
264
235
|
params?: Record<string, boolean | number | string> | Array<boolean | number | string>;
|
|
265
236
|
/**
|
|
266
|
-
*
|
|
237
|
+
* An array of CallApi plugins. It allows you to extend the behavior of the library.
|
|
267
238
|
*/
|
|
268
239
|
plugins?: TPluginArray | ((context: PluginInitContext) => TPluginArray);
|
|
269
240
|
/**
|
|
270
|
-
*
|
|
241
|
+
* Query parameters to append to the URL.
|
|
271
242
|
*/
|
|
272
243
|
query?: Record<string, boolean | number | string>;
|
|
273
244
|
/**
|
|
274
|
-
*
|
|
245
|
+
* Custom function to validate the response error data, stemming from the api.
|
|
275
246
|
* This only runs if the api actually sends back error status codes, else it will be ignored, in which case you should only use the `responseValidator` option.
|
|
276
247
|
*/
|
|
277
248
|
responseErrorValidator?: (data: unknown) => TErrorData;
|
|
278
249
|
/**
|
|
279
|
-
*
|
|
250
|
+
* Custom function to parse the response string into a object.
|
|
280
251
|
*/
|
|
281
252
|
responseParser?: (responseString: string) => Awaitable<Record<string, unknown>>;
|
|
282
253
|
/**
|
|
283
|
-
*
|
|
254
|
+
* Expected response type, affects how response is parsed
|
|
284
255
|
* @default "json"
|
|
285
256
|
*/
|
|
286
257
|
responseType?: keyof ReturnType<typeof getResponseType>;
|
|
287
258
|
/**
|
|
288
|
-
*
|
|
259
|
+
* Custom function to validate the response data.
|
|
289
260
|
*/
|
|
290
261
|
responseValidator?: (data: unknown) => TData;
|
|
291
262
|
/**
|
|
292
|
-
*
|
|
263
|
+
* Mode of the result, can influence how results are handled or returned.
|
|
293
264
|
* Can be set to "all" | "onlySuccess" | "onlyError" | "onlyResponse".
|
|
294
265
|
* @default "all"
|
|
295
266
|
*/
|
|
@@ -301,22 +272,22 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
|
301
272
|
*/
|
|
302
273
|
throwOnError?: boolean | ((context: ErrorContext<TErrorData>) => boolean);
|
|
303
274
|
/**
|
|
304
|
-
*
|
|
275
|
+
* Request timeout in milliseconds
|
|
305
276
|
*/
|
|
306
277
|
timeout?: number;
|
|
307
|
-
}
|
|
278
|
+
} & InterceptorsOrInterceptorArray<TData, TErrorData> & Partial<InferPluginOptions<TPluginArray>> & RetryOptions<TErrorData>;
|
|
308
279
|
declare const optionsEnumToExtendFromBase: "plugins"[];
|
|
309
280
|
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = ExtraOptions<TData, TErrorData, TResultMode, TPluginArray> & {
|
|
310
281
|
/**
|
|
311
|
-
*
|
|
282
|
+
* Options that should extend the base options.
|
|
312
283
|
*/
|
|
313
284
|
extend?: Pick<ExtraOptions<TData, TErrorData, TResultMode, TPluginArray>, (typeof optionsEnumToExtendFromBase)[number]>;
|
|
314
285
|
};
|
|
315
286
|
declare const optionsEnumToOmitFromBase: ("dedupeKey" | "extend")[];
|
|
316
287
|
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBasePluginArray extends CallApiPlugin[] = CallApiPlugin[]> = Omit<CallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBasePluginArray>, (typeof optionsEnumToOmitFromBase)[number]>;
|
|
317
288
|
type CombinedCallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = BaseCallApiExtraOptions<TData, TErrorData, TResultMode, TPluginArray> & CallApiExtraOptions<TData, TErrorData, TResultMode, TPluginArray>;
|
|
318
|
-
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = CallApiExtraOptions<TData, TErrorData, TResultMode, TPluginArray
|
|
319
|
-
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBasePluginArray extends CallApiPlugin[] = CallApiPlugin[]> = BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBasePluginArray
|
|
289
|
+
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = CallApiRequestOptions & CallApiExtraOptions<TData, TErrorData, TResultMode, TPluginArray>;
|
|
290
|
+
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBasePluginArray extends CallApiPlugin[] = CallApiPlugin[]> = CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBasePluginArray>;
|
|
320
291
|
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TPluginArray extends CallApiPlugin[] = CallApiPlugin[]> = [initURL: string, config?: CallApiConfig<TData, TErrorData, TResultMode, TPluginArray>];
|
|
321
292
|
type RequestContext = UnmaskType<{
|
|
322
293
|
options: CombinedCallApiExtraOptions;
|
|
@@ -400,23 +371,52 @@ type ResultModeUnion = {
|
|
|
400
371
|
}[keyof ResultModeMap] | undefined;
|
|
401
372
|
type GetCallApiResult<TData, TErrorData, TResultMode> = TErrorData extends false ? ResultModeMap<TData, TErrorData>["onlySuccessWithException"] : undefined extends TResultMode ? ResultModeMap<TData, TErrorData>["all"] : TResultMode extends NonNullable<ResultModeUnion> ? ResultModeMap<TData, TErrorData>[TResultMode] : never;
|
|
402
373
|
|
|
403
|
-
type
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
374
|
+
type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => boolean | Promise<boolean>;
|
|
375
|
+
interface RetryOptions<TErrorData> {
|
|
376
|
+
/**
|
|
377
|
+
* Keeps track of the number of times the request has already been retried
|
|
378
|
+
* @deprecated This property is used internally to track retries. Please abstain from modifying it.
|
|
379
|
+
*/
|
|
380
|
+
readonly "~retryCount"?: number;
|
|
381
|
+
/**
|
|
382
|
+
* Number of allowed retry attempts on HTTP errors
|
|
383
|
+
* @default 0
|
|
384
|
+
*/
|
|
385
|
+
retryAttempts?: number;
|
|
386
|
+
/**
|
|
387
|
+
* Callback whose return value determines if a request should be retried or not
|
|
388
|
+
*/
|
|
389
|
+
retryCondition?: RetryCondition<TErrorData>;
|
|
390
|
+
/**
|
|
391
|
+
* Delay between retries in milliseconds
|
|
392
|
+
* @default 1000
|
|
393
|
+
*/
|
|
394
|
+
retryDelay?: number;
|
|
395
|
+
/**
|
|
396
|
+
* Maximum delay in milliseconds. Only applies to exponential strategy
|
|
397
|
+
* @default 10000
|
|
398
|
+
*/
|
|
399
|
+
retryMaxDelay?: number;
|
|
400
|
+
/**
|
|
401
|
+
* HTTP methods that are allowed to retry
|
|
402
|
+
* @default ["GET", "POST"]
|
|
403
|
+
*/
|
|
404
|
+
retryMethods?: Array<"GET" | "POST" | AnyString>;
|
|
405
|
+
/**
|
|
406
|
+
* HTTP status codes that trigger a retry
|
|
407
|
+
* @default [409, 425, 429, 500, 502, 503, 504]
|
|
408
|
+
*/
|
|
409
|
+
retryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;
|
|
410
|
+
/**
|
|
411
|
+
* Strategy to use when retrying
|
|
412
|
+
* @default "linear"
|
|
413
|
+
*/
|
|
414
|
+
retryStrategy?: "exponential" | "linear";
|
|
415
|
+
}
|
|
416
416
|
|
|
417
417
|
type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ? TParam : never;
|
|
418
418
|
type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = TPluginArray extends Array<infer TPlugin extends CallApiPlugin> ? TPlugin["createExtraOptions"] extends (...params: never[]) => infer TResult ? UnionToIntersection<TResult> : NonNullable<unknown> : NonNullable<unknown>;
|
|
419
|
-
type PluginInitContext = {
|
|
419
|
+
type PluginInitContext<TMoreOptions = DefaultMoreOptions> = WithMoreOptions<TMoreOptions> & {
|
|
420
420
|
initURL: string;
|
|
421
421
|
options: CombinedCallApiExtraOptions;
|
|
422
422
|
request: CallApiRequestOptionsForHooks;
|
|
@@ -426,11 +426,11 @@ type PluginInitResult = Partial<Omit<PluginInitContext, "request"> & {
|
|
|
426
426
|
}>;
|
|
427
427
|
type CallApiPlugin = {
|
|
428
428
|
/**
|
|
429
|
-
*
|
|
429
|
+
* Defines additional options that can be passed to callApi
|
|
430
430
|
*/
|
|
431
431
|
createExtraOptions?: (...params: never[]) => unknown;
|
|
432
432
|
/**
|
|
433
|
-
*
|
|
433
|
+
* A description for the plugin
|
|
434
434
|
*/
|
|
435
435
|
description?: string;
|
|
436
436
|
/**
|
|
@@ -438,21 +438,19 @@ type CallApiPlugin = {
|
|
|
438
438
|
*/
|
|
439
439
|
hooks?: InterceptorsOrInterceptorArray;
|
|
440
440
|
/**
|
|
441
|
-
*
|
|
441
|
+
* A unique id for the plugin
|
|
442
442
|
*/
|
|
443
443
|
id: string;
|
|
444
444
|
/**
|
|
445
|
-
*
|
|
446
|
-
* initialized. This will be called before the any
|
|
447
|
-
* of the other internal functions.
|
|
445
|
+
* A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.
|
|
448
446
|
*/
|
|
449
447
|
init?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;
|
|
450
448
|
/**
|
|
451
|
-
*
|
|
449
|
+
* A name for the plugin
|
|
452
450
|
*/
|
|
453
451
|
name: string;
|
|
454
452
|
/**
|
|
455
|
-
*
|
|
453
|
+
* A version for the plugin
|
|
456
454
|
*/
|
|
457
455
|
version?: string;
|
|
458
456
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as PossibleHTTPError, e as PossibleJavaScriptError } from '../plugins-
|
|
2
|
-
export { u as defaultRetryMethods, v as defaultRetryStatusCodes, t as toQueryString } from '../plugins-
|
|
1
|
+
import { f as PossibleHTTPError, e as PossibleJavaScriptError } from '../plugins-jILLQxo1.js';
|
|
2
|
+
export { u as defaultRetryMethods, v as defaultRetryStatusCodes, t as toQueryString } from '../plugins-jILLQxo1.js';
|
|
3
3
|
import { H as HTTPError } from '../error-lBRMiMeF.js';
|
|
4
4
|
|
|
5
5
|
type ErrorObjectUnion<TErrorData = unknown> = PossibleHTTPError<TErrorData> | PossibleJavaScriptError;
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{defaultRetryMethods,defaultRetryStatusCodes,isHTTPError,isHTTPErrorInstance,toQueryString}from"../chunk-
|
|
1
|
+
export{defaultRetryMethods,defaultRetryStatusCodes,isHTTPError,isHTTPErrorInstance,toQueryString}from"../chunk-36I75IJA.js";//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/callapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.7",
|
|
5
5
|
"description": "A lightweight wrapper over fetch with quality of life improvements like built-in request cancellation, retries, interceptors and more",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|