@zayne-labs/callapi 1.12.2 → 1.12.3

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/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/result.ts","../src/hooks.ts","../src/stream.ts","../src/dedupe.ts","../src/middlewares.ts","../src/plugins.ts","../src/refetch.ts","../src/retry.ts","../src/createFetchClient.ts"],"sourcesContent":["import { extraOptionDefaults } from \"./constants/defaults\";\nimport type { CallApiExtraOptions } from \"./types/common\";\nimport type { ThrowOnErrorBoolean } from \"./types/conditional-types\";\nimport type { DefaultDataType, DefaultThrowOnError } from \"./types/default-types\";\nimport type {\n\tAnyString,\n\tAwaitable,\n\tDistributiveOmit,\n\tNoInferUnMasked,\n\tPrettify,\n\tUnmaskType,\n} from \"./types/type-helpers\";\nimport { omitKeys } from \"./utils/common\";\nimport type { HTTPError, ValidationError } from \"./utils/external/error\";\nimport { isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/external/guards\";\n\nexport type ResponseType = \"blob\" | \"json\" | \"text\";\n\nexport type ResponseParser<TData> = (text: string) => Awaitable<TData>;\n\nexport const getResponseType = <TData>(response: Response, responseParser: ResponseParser<TData>) => ({\n\tarrayBuffer: () => response.arrayBuffer(),\n\tblob: () => response.blob(),\n\tformData: () => response.formData(),\n\tjson: async (): Promise<TData> => {\n\t\tconst text = await response.text();\n\t\treturn responseParser(text);\n\t},\n\tstream: () => response.body,\n\ttext: () => response.text(),\n});\n\ntype InitResponseTypeMap<TData = unknown> = ReturnType<typeof getResponseType<TData>>;\n\ntype ResponseTypeUnion = keyof InitResponseTypeMap;\n\ntype ResponseTypePlaceholder = null;\n\nexport type ResponseTypeType = ResponseTypePlaceholder | ResponseTypeUnion;\n\nexport type ResponseTypeMap<TData> = {\n\t[Key in keyof InitResponseTypeMap<TData>]: Awaited<ReturnType<InitResponseTypeMap<TData>[Key]>>;\n};\n\nexport type GetResponseType<\n\tTData,\n\tTResponseType extends ResponseTypeType,\n\tTComputedResponseTypeMap extends ResponseTypeMap<TData> = ResponseTypeMap<TData>,\n> =\n\tnull extends TResponseType ? TComputedResponseTypeMap[\"json\"]\n\t: TResponseType extends NonNullable<ResponseTypeType> ? TComputedResponseTypeMap[TResponseType]\n\t: never;\n\nconst textTypes = new Set([\"image/svg\", \"application/xml\", \"application/xhtml\", \"application/html\"]);\nconst JSON_REGEX = /^application\\/(?:[\\w!#$%&*.^`~-]*\\+)?json(;.+)?$/i;\n\nconst detectResponseType = (response: Response): Extract<ResponseTypeType, \"blob\" | \"json\" | \"text\"> => {\n\tconst initContentType = response.headers.get(\"content-type\");\n\n\tif (!initContentType) {\n\t\treturn extraOptionDefaults.responseType;\n\t}\n\n\tconst contentType = initContentType.split(\";\")[0] ?? \"\";\n\n\tif (JSON_REGEX.test(contentType)) {\n\t\treturn \"json\";\n\t}\n\n\tif (textTypes.has(contentType) || contentType.startsWith(\"text/\")) {\n\t\treturn \"text\";\n\t}\n\n\treturn \"blob\";\n};\n\nexport const resolveResponseData = async (options: {\n\tresponse: Response;\n\tresponseParser: CallApiExtraOptions[\"responseParser\"];\n\tresponseType: CallApiExtraOptions[\"responseType\"];\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n}) => {\n\tconst { response, responseParser, responseType, resultMode } = options;\n\n\t// == If the result mode is set to `fetchApi`, then don't try to resolve the responseData and just return null\n\tif (resultMode === \"fetchApi\") {\n\t\treturn null;\n\t}\n\n\tconst selectedParser = responseParser ?? extraOptionDefaults.responseParser;\n\tconst selectedResponseType = responseType ?? detectResponseType(response);\n\n\tconst RESPONSE_TYPE_LOOKUP = getResponseType(response, selectedParser);\n\n\tif (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, selectedResponseType)) {\n\t\tthrow new Error(`Invalid response type: ${selectedResponseType}`);\n\t}\n\n\treturn RESPONSE_TYPE_LOOKUP[selectedResponseType]();\n};\n\nexport type CallApiResultSuccessVariant<TData> = {\n\tdata: NoInferUnMasked<TData>;\n\terror: null;\n\tresponse: Response;\n};\nexport type PossibleJavaScriptError = UnmaskType<{\n\terrorData: false;\n\tmessage: string;\n\tname: \"AbortError\" | \"Error\" | \"SyntaxError\" | \"TimeoutError\" | \"TypeError\" | AnyString;\n\toriginalError: DOMException | Error | SyntaxError | TypeError;\n}>;\n\nexport type PossibleHTTPError<TErrorData> = UnmaskType<{\n\terrorData: NoInferUnMasked<TErrorData>;\n\tmessage: string;\n\tname: \"HTTPError\";\n\toriginalError: HTTPError;\n}>;\n\nexport type PossibleValidationError = UnmaskType<{\n\terrorData: ValidationError[\"errorData\"];\n\tissueCause: ValidationError[\"issueCause\"];\n\tmessage: string;\n\tname: \"ValidationError\";\n\toriginalError: ValidationError;\n}>;\n\nexport type CallApiResultErrorVariant<TErrorData> =\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleHTTPError<TErrorData>;\n\t\t\tresponse: Response;\n\t }\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleJavaScriptError;\n\t\t\tresponse: Response | null;\n\t }\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleValidationError;\n\t\t\tresponse: Response | null;\n\t };\n\nexport type CallApiResultSuccessOrErrorVariant<TData, TError> =\n\t| CallApiResultErrorVariant<TError>\n\t| CallApiResultSuccessVariant<TData>;\n\ntype GetCallApiResult<\n\tTThrowOnError extends ThrowOnErrorBoolean,\n\tTResultWithException extends CallApiResultSuccessVariant<unknown>,\n\tTResultWithoutException extends CallApiResultSuccessOrErrorVariant<unknown, unknown>,\n> = TThrowOnError extends true ? TResultWithException : TResultWithoutException;\n\nexport type ResultModeMap<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError,\n\tTComputedResult extends GetCallApiResult<\n\t\tTThrowOnError,\n\t\tCallApiResultSuccessVariant<TData>,\n\t\tCallApiResultSuccessOrErrorVariant<TData, TErrorData>\n\t> = GetCallApiResult<\n\t\tTThrowOnError,\n\t\tCallApiResultSuccessVariant<TData>,\n\t\tCallApiResultSuccessOrErrorVariant<TData, TErrorData>\n\t>,\n> = UnmaskType<{\n\tall: TComputedResult;\n\tfetchApi: TComputedResult[\"response\"];\n\tonlyData: TComputedResult[\"data\"];\n\tonlyResponse: TComputedResult[\"response\"];\n\twithoutResponse: Prettify<DistributiveOmit<TComputedResult, \"response\">>;\n}>;\n\ntype ResultModePlaceholder = null;\n\ntype ResultModeUnion = keyof ResultModeMap;\n\n// FIXME - Revisit this idea later. Take inspirations from how zod does it with pick({}) and omit({d})\n// type ResultModeObject = { data?: boolean; error?: boolean; response?: boolean };\n\nexport type ResultModeType = ResultModePlaceholder | ResultModeUnion;\n\nexport type InferCallApiResult<\n\tTData,\n\tTErrorData,\n\tTResultMode extends ResultModeType,\n\tTThrowOnError extends ThrowOnErrorBoolean,\n\tTComputedResultModeMapWithException extends ResultModeMap<TData, TErrorData, true> = ResultModeMap<\n\t\tTData,\n\t\tTErrorData,\n\t\ttrue\n\t>,\n\tTComputedResultModeMapWithoutException extends ResultModeMap<TData, TErrorData, TThrowOnError> =\n\t\tResultModeMap<TData, TErrorData, TThrowOnError>,\n> =\n\tTErrorData extends false ? TComputedResultModeMapWithException[\"onlyData\"]\n\t: TErrorData extends false | undefined ? TComputedResultModeMapWithException[\"onlyData\"]\n\t: ResultModePlaceholder extends TResultMode ? TComputedResultModeMapWithoutException[\"all\"]\n\t: TResultMode extends ResultModeUnion ? TComputedResultModeMapWithoutException[TResultMode]\n\t: never;\n\ntype SuccessInfo = Pick<CallApiExtraOptions, \"resultMode\"> & {\n\tresponse: Response;\n};\n\ntype LazyResultModeMap = {\n\t[key in keyof ResultModeMap]: () => ResultModeMap[key];\n};\n\nconst getResultModeMap = (details: ResultModeMap[\"all\"]): LazyResultModeMap => {\n\treturn {\n\t\tall: () => details,\n\t\tfetchApi: () => details.response,\n\t\tonlyData: () => details.data,\n\t\tonlyResponse: () => details.response,\n\t\twithoutResponse: () => omitKeys(details, [\"response\"]),\n\t};\n};\n\ntype SuccessResult = CallApiResultSuccessVariant<unknown> | null;\n\n// The return statement is casted due to a design limitation in ts.\n// LINK - See https://www.zhenghao.io/posts/type-functions for more info\nexport const resolveSuccessResult = (data: unknown, info: SuccessInfo): SuccessResult => {\n\tconst { response, resultMode } = info;\n\n\tconst details = {\n\t\tdata,\n\t\terror: null,\n\t\tresponse,\n\t} satisfies CallApiResultSuccessVariant<unknown>;\n\n\tconst resultModeMap = getResultModeMap(details);\n\n\tconst successResult = resultModeMap[resultMode ?? \"all\"]();\n\n\treturn successResult as SuccessResult;\n};\n\nexport type ErrorInfo = Omit<SuccessInfo, \"response\">\n\t& Pick<CallApiExtraOptions, \"cloneResponse\"> & {\n\t\tmessage?: string;\n\t};\n\nexport type ErrorResult = {\n\terrorDetails: CallApiResultErrorVariant<unknown>;\n\terrorResult: CallApiResultErrorVariant<unknown> | null;\n};\n\nexport const resolveErrorResult = (error: unknown, info: ErrorInfo): ErrorResult => {\n\tconst { cloneResponse, message: customErrorMessage, resultMode } = info;\n\n\tlet errorDetails = {\n\t\tdata: null,\n\t\terror: {\n\t\t\terrorData: false,\n\t\t\tmessage: customErrorMessage ?? (error as Error).message,\n\t\t\tname: (error as Error).name,\n\t\t\toriginalError: error as Error,\n\t\t},\n\t\tresponse: null,\n\t} satisfies CallApiResultErrorVariant<unknown> as CallApiResultErrorVariant<unknown>;\n\n\tif (isValidationErrorInstance(error)) {\n\t\tconst { errorData, message, response } = error;\n\n\t\terrorDetails = {\n\t\t\tdata: null,\n\t\t\terror: {\n\t\t\t\terrorData,\n\t\t\t\tissueCause: error.issueCause,\n\t\t\t\tmessage,\n\t\t\t\tname: \"ValidationError\",\n\t\t\t\toriginalError: error,\n\t\t\t},\n\t\t\tresponse,\n\t\t};\n\t}\n\n\tif (isHTTPErrorInstance<never>(error)) {\n\t\tconst { errorData, message, name, response } = error;\n\n\t\terrorDetails = {\n\t\t\tdata: null,\n\t\t\terror: { errorData, message, name, originalError: error },\n\t\t\tresponse: cloneResponse ? response.clone() : response,\n\t\t};\n\t}\n\n\tconst resultModeMap = getResultModeMap(errorDetails);\n\n\tconst errorResult = resultModeMap[resultMode ?? \"all\"]() as never;\n\n\treturn { errorDetails, errorResult };\n};\n\nexport const getCustomizedErrorResult = (\n\terrorResult: ErrorResult[\"errorResult\"],\n\tcustomErrorInfo: { message: string | undefined }\n): ErrorResult[\"errorResult\"] => {\n\tif (!errorResult) {\n\t\treturn null;\n\t}\n\n\tconst { message = errorResult.error.message } = customErrorInfo;\n\n\treturn {\n\t\t...errorResult,\n\t\terror: {\n\t\t\t...errorResult.error,\n\t\t\tmessage,\n\t\t} satisfies NonNullable<ErrorResult[\"errorResult\"]>[\"error\"] as never,\n\t};\n};\n","import type { RefetchFn } from \"./refetch\";\nimport {\n\tresolveErrorResult,\n\ttype CallApiResultErrorVariant,\n\ttype CallApiResultSuccessVariant,\n\ttype ErrorInfo,\n\ttype PossibleHTTPError,\n\ttype PossibleJavaScriptError,\n\ttype PossibleValidationError,\n} from \"./result\";\nimport type { StreamProgressEvent } from \"./stream\";\nimport type {\n\tBaseCallApiConfig,\n\tCallApiConfig,\n\tCallApiContext,\n\tCallApiExtraOptions,\n\tCallApiRequestOptions,\n} from \"./types/common\";\nimport type { DefaultCallApiContext } from \"./types/default-types\";\nimport type {\n\tAnyFunction,\n\tAwaitable,\n\tCommonRequestHeaders,\n\tDistributiveOmit,\n\tPrettify,\n} from \"./types/type-helpers\";\n\nexport type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, \"headers\"> & {\n\theaders: Partial<Record<\"Authorization\" | \"Content-Type\" | CommonRequestHeaders, string>>;\n};\n\nexport type CallApiExtraOptionsForHooks<TCallApiContext extends CallApiContext = DefaultCallApiContext> =\n\tHooks\n\t\t& Omit<CallApiExtraOptions<TCallApiContext>, keyof Hooks> & {\n\t\t\trefetch: RefetchFn;\n\t\t};\n\nexport interface Hooks<TCallApiContext extends CallApiContext = DefaultCallApiContext> {\n\t/**\n\t * Hook called when any error occurs within the request/response lifecycle.\n\t *\n\t * This is a unified error handler that catches both request errors (network failures,\n\t * timeouts, etc.) and response errors (HTTP error status codes). It's essentially\n\t * a combination of `onRequestError` and `onResponseError` hooks.\n\t *\n\t * @param context - Error context containing error details, request info, and response (if available)\n\t * @returns Promise or void - Hook can be async or sync\n\t */\n\tonError?: (context: ErrorContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called before the HTTP request is sent and before any internal processing of the request object begins.\n\t *\n\t * This is the ideal place to modify request headers, add authentication,\n\t * implement request logging, or perform any setup before the network call.\n\t *\n\t * @param context - Request context with mutable request object and configuration\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonRequest?: (context: RequestContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when an error occurs during the fetch request itself.\n\t *\n\t * This handles network-level errors like connection failures, timeouts,\n\t * DNS resolution errors, or other issues that prevent getting an HTTP response.\n\t * Note that HTTP error status codes (4xx, 5xx) are handled by `onResponseError`.\n\t *\n\t * @param context - Request error context with error details and null response\n\t * @returns Promise or void - Hook can be async or sync\n\t */\n\tonRequestError?: (context: RequestErrorContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called just before the HTTP request is sent and after the request has been processed.\n\t *\n\t * @param context - Request context with mutable request object and configuration\n\t */\n\tonRequestReady?: (context: RequestContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called during upload stream progress tracking.\n\t *\n\t * This hook is triggered when uploading data (like file uploads) and provides\n\t * progress information about the upload. Useful for implementing progress bars\n\t * or upload status indicators.\n\t *\n\t * @param context - Request stream context with progress event and request instance\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonRequestStream?: (context: RequestStreamContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when any HTTP response is received from the API.\n\t *\n\t * This hook is triggered for both successful (2xx) and error (4xx, 5xx) responses.\n\t * It's useful for response logging, metrics collection, or any processing that\n\t * should happen regardless of response status.\n\t *\n\t * @param context - Response context with either success data or error information\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonResponse?: (context: ResponseContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when an HTTP error response (4xx, 5xx) is received from the API.\n\t *\n\t * This handles server-side errors where an HTTP response was successfully received\n\t * but indicates an error condition. Different from `onRequestError` which handles\n\t * network-level failures.\n\t *\n\t * @param context - Response error context with HTTP error details and response\n\t * @returns Promise or void - Hook can be async or sync\n\t */\n\tonResponseError?: (context: ResponseErrorContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called during download stream progress tracking.\n\t *\n\t * This hook is triggered when downloading data (like file downloads) and provides\n\t * progress information about the download. Useful for implementing progress bars\n\t * or download status indicators.\n\t *\n\t * @param context - Response stream context with progress event and response\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonResponseStream?: (context: ResponseStreamContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when a request is being retried.\n\t *\n\t * This hook is triggered before each retry attempt, providing information about\n\t * the previous failure and the current retry attempt number. Useful for implementing\n\t * custom retry logic, exponential backoff, or retry logging.\n\t *\n\t * @param context - Retry context with error details and retry attempt count\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonRetry?: (context: RetryContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when a successful response (2xx status) is received from the API.\n\t *\n\t * This hook is triggered only for successful responses and provides access to\n\t * the parsed response data. Ideal for success logging, caching, or post-processing\n\t * of successful API responses.\n\t *\n\t * @param context - Success context with parsed response data and response object\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonSuccess?: (context: SuccessContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when a validation error occurs.\n\t *\n\t * This hook is triggered when request or response data fails validation against\n\t * a defined schema. It provides access to the validation error details and can\n\t * be used for custom error handling, logging, or fallback behavior.\n\t *\n\t * @param context - Validation error context with error details and response (if available)\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonValidationError?: (context: ValidationErrorContext<TCallApiContext>) => Awaitable<unknown>;\n}\n\nexport type HooksOrHooksArray<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> = {\n\t[Key in keyof Hooks<TCallApiContext>]:\n\t\t| Hooks<TCallApiContext>[Key]\n\t\t// eslint-disable-next-line perfectionist/sort-union-types -- I need arrays to be last\n\t\t| Array<Hooks<TCallApiContext>[Key]>;\n};\n\nexport interface HookConfigOptions {\n\t/**\n\t * Controls the execution mode of all composed hooks (main + plugin hooks).\n\t *\n\t * - **\"parallel\"**: All hooks execute simultaneously via Promise.all() for better performance\n\t * - **\"sequential\"**: All hooks execute one by one in registration order via await in a loop\n\t *\n\t * This affects how ALL hooks execute together, regardless of their source (main or plugin).\n\t *\n\t * @default \"parallel\"\n\t */\n\thooksExecutionMode?: \"parallel\" | \"sequential\";\n}\n\nexport type RequestContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = {\n\t/**\n\t * Base configuration object passed to createFetchClient.\n\t *\n\t * Contains the foundational configuration that applies to all requests\n\t * made by this client instance, such as baseURL, default headers, and\n\t * global options.\n\t */\n\tbaseConfig: Exclude<BaseCallApiConfig, AnyFunction>;\n\n\t/**\n\t * Instance-specific configuration object passed to the callApi instance.\n\t *\n\t * Contains configuration specific to this particular API call, which\n\t * can override or extend the base configuration.\n\t */\n\tconfig: CallApiConfig;\n\n\t/**\n\t * Merged options combining base config, instance config, and default options.\n\t *\n\t * This is the final resolved configuration that will be used for the request,\n\t * with proper precedence applied (instance > base > defaults).\n\t */\n\toptions: CallApiExtraOptionsForHooks<TCallApiContext>;\n\n\t/**\n\t * Merged request object ready to be sent.\n\t *\n\t * Contains the final request configuration including URL, method, headers,\n\t * body, and other fetch options. This object can be modified in onRequest\n\t * hooks to customize the outgoing request.\n\t */\n\trequest: CallApiRequestOptionsForHooks;\n};\n\nexport type SuccessContext<\n\tTCallApiContext extends Pick<CallApiContext, \"Data\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = DistributiveOmit<CallApiResultSuccessVariant<TCallApiContext[\"Data\"]>, \"error\">\n\t& RequestContext<TCallApiContext>;\n\nexport type ResponseContext<\n\tTCallApiContext extends Pick<CallApiContext, \"Data\" | \"ErrorData\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = RequestContext<TCallApiContext>\n\t& (\n\t\t| Prettify<CallApiResultSuccessVariant<TCallApiContext[\"Data\"]>>\n\t\t| Prettify<\n\t\t\t\tExtract<\n\t\t\t\t\tCallApiResultErrorVariant<TCallApiContext[\"ErrorData\"]>,\n\t\t\t\t\t{ error: PossibleHTTPError<TCallApiContext[\"ErrorData\"]> }\n\t\t\t\t>\n\t\t >\n\t);\n\nexport type RequestStreamContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = RequestContext<TCallApiContext> & {\n\tevent: StreamProgressEvent;\n\trequestInstance: Request;\n};\n\nexport type ResponseStreamContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = RequestContext<TCallApiContext> & {\n\tevent: StreamProgressEvent;\n\tresponse: Response;\n};\n\nexport type ErrorContext<\n\tTCallApiContext extends Pick<CallApiContext, \"ErrorData\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = DistributiveOmit<CallApiResultErrorVariant<TCallApiContext[\"ErrorData\"]>, \"data\">\n\t& RequestContext<TCallApiContext>;\n\nexport type ValidationErrorContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = Extract<ErrorContext<TCallApiContext>, { error: PossibleValidationError }>\n\t& RequestContext<TCallApiContext>;\n\nexport type RequestErrorContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = Extract<ErrorContext<TCallApiContext>, { error: PossibleJavaScriptError }>\n\t& RequestContext<TCallApiContext>;\n\nexport type ResponseErrorContext<\n\tTCallApiContext extends Pick<CallApiContext, \"ErrorData\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = Extract<ErrorContext<TCallApiContext>, { error: PossibleHTTPError<TCallApiContext[\"ErrorData\"]> }>\n\t& RequestContext<TCallApiContext>;\n\nexport type RetryContext<\n\tTCallApiContext extends Pick<CallApiContext, \"ErrorData\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = ErrorContext<TCallApiContext> & {\n\tretryAttemptCount: number;\n};\n\ntype HookRegistries = Required<{\n\t[Key in keyof Hooks]: Set<Hooks[Key]>;\n}>;\n\nexport const getHookRegistriesAndKeys = () => {\n\tconst hookRegistries: HookRegistries = {\n\t\tonError: new Set(),\n\t\tonRequest: new Set(),\n\t\tonRequestError: new Set(),\n\t\tonRequestReady: new Set(),\n\t\tonRequestStream: new Set(),\n\t\tonResponse: new Set(),\n\t\tonResponseError: new Set(),\n\t\tonResponseStream: new Set(),\n\t\tonRetry: new Set(),\n\t\tonSuccess: new Set(),\n\t\tonValidationError: new Set(),\n\t};\n\n\tconst hookRegistryKeys = Object.keys(hookRegistries) as Array<keyof Hooks>;\n\n\treturn { hookRegistries, hookRegistryKeys };\n};\n\nexport const composeHooksFromArray = (\n\thooksArray: Array<Hooks[keyof Hooks] | undefined>,\n\thooksExecutionMode: NonNullable<CallApiExtraOptionsForHooks[\"hooksExecutionMode\"]>\n) => {\n\tconst composedHook = async (ctx: unknown) => {\n\t\tswitch (hooksExecutionMode) {\n\t\t\tcase \"parallel\": {\n\t\t\t\tawait Promise.all(hooksArray.map((hook) => hook?.(ctx as never)));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"sequential\": {\n\t\t\t\tfor (const hook of hooksArray) {\n\t\t\t\t\t// eslint-disable-next-line no-await-in-loop -- This is necessary in this case\n\t\t\t\t\tawait hook?.(ctx as never);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\thooksExecutionMode satisfies never;\n\t\t\t}\n\t\t}\n\t};\n\n\treturn composedHook;\n};\n\nexport const executeHooks = async (...hookResultsOrPromise: Array<Awaitable<unknown>>) => {\n\tawait Promise.all(hookResultsOrPromise);\n};\n\nexport type ExecuteHookInfo = {\n\terrorInfo: ErrorInfo;\n\tshouldThrowOnError: boolean | undefined;\n};\n\nexport const executeHooksInCatchBlock = async (\n\thookResultsOrPromise: Array<Awaitable<unknown>>,\n\thookInfo: ExecuteHookInfo\n) => {\n\tconst { errorInfo, shouldThrowOnError } = hookInfo;\n\n\ttry {\n\t\tawait Promise.all(hookResultsOrPromise);\n\n\t\treturn null;\n\t} catch (hookError) {\n\t\tif (shouldThrowOnError) {\n\t\t\tthrow hookError;\n\t\t}\n\n\t\tconst { errorResult } = resolveErrorResult(hookError, errorInfo);\n\n\t\treturn errorResult;\n\t}\n};\n","import {\n\texecuteHooks,\n\ttype RequestContext,\n\ttype RequestStreamContext,\n\ttype ResponseStreamContext,\n} from \"./hooks\";\nimport { isReadableStream } from \"./utils/guards\";\n\nexport type StreamProgressEvent = {\n\t/**\n\t * Current chunk of data being streamed\n\t */\n\tchunk: Uint8Array;\n\t/**\n\t * Progress in percentage\n\t */\n\tprogress: number;\n\t/**\n\t * Total size of data in bytes\n\t */\n\ttotalBytes: number;\n\t/**\n\t * Amount of data transferred so far\n\t */\n\ttransferredBytes: number;\n};\n\nconst createProgressEvent = (options: {\n\tchunk: Uint8Array;\n\ttotalBytes: number;\n\ttransferredBytes: number;\n}): StreamProgressEvent => {\n\tconst { chunk, totalBytes, transferredBytes } = options;\n\n\treturn {\n\t\tchunk,\n\t\tprogress: Math.round((transferredBytes / totalBytes) * 100) || 0,\n\t\ttotalBytes,\n\t\ttransferredBytes,\n\t};\n};\n\nconst calculateTotalBytesFromBody = async (\n\trequestBody: Request[\"body\"] | null,\n\texistingTotalBytes: number\n) => {\n\tlet totalBytes = existingTotalBytes;\n\n\tif (!requestBody) {\n\t\treturn totalBytes;\n\t}\n\n\tfor await (const chunk of requestBody) {\n\t\ttotalBytes += chunk.byteLength;\n\t}\n\n\treturn totalBytes;\n};\n\ntype ToStreamableRequestContext = RequestContext;\n\nexport const toStreamableRequest = async (\n\tcontext: ToStreamableRequestContext\n): Promise<Request | RequestInit> => {\n\tconst { baseConfig, config, options, request } = context;\n\n\tif (!options.onRequestStream || !isReadableStream(request.body)) {\n\t\treturn request as RequestInit;\n\t}\n\n\tconst requestInstance = new Request(\n\t\toptions.fullURL as NonNullable<typeof options.fullURL>,\n\t\t{ ...request, duplex: \"half\" } as RequestInit\n\t);\n\n\tconst contentLength = requestInstance.headers.get(\"content-length\");\n\n\tlet totalBytes = Number(contentLength ?? 0);\n\n\t// == If no content length is present, we read the total bytes from the body\n\tif (!contentLength && options.forcefullyCalculateRequestStreamSize) {\n\t\ttotalBytes = await calculateTotalBytesFromBody(requestInstance.clone().body, totalBytes);\n\t}\n\n\tlet transferredBytes = 0;\n\n\tconst stream = new ReadableStream({\n\t\tstart: async (controller) => {\n\t\t\tconst body = requestInstance.body;\n\n\t\t\tif (!body) return;\n\n\t\t\tconst requestStreamContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tevent: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\trequestInstance,\n\t\t\t} satisfies RequestStreamContext;\n\n\t\t\tawait executeHooks(options.onRequestStream?.(requestStreamContext));\n\n\t\t\tfor await (const chunk of body) {\n\t\t\t\ttransferredBytes += chunk.byteLength;\n\n\t\t\t\ttotalBytes = Math.max(totalBytes, transferredBytes);\n\n\t\t\t\tawait executeHooks(\n\t\t\t\t\toptions.onRequestStream?.({\n\t\t\t\t\t\t...requestStreamContext,\n\t\t\t\t\t\tevent: createProgressEvent({ chunk, totalBytes, transferredBytes }),\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t}\n\n\t\t\tcontroller.close();\n\t\t},\n\t});\n\n\treturn new Request(requestInstance, { body: stream, duplex: \"half\" } as RequestInit);\n};\n\ntype StreamableResponseContext = RequestContext & { response: Response };\n\nexport const toStreamableResponse = (context: StreamableResponseContext): Response => {\n\tconst { baseConfig, config, options, request, response } = context;\n\n\tif (!options.onResponseStream || !response.body) {\n\t\treturn response;\n\t}\n\n\tconst contentLength = response.headers.get(\"content-length\");\n\n\tlet totalBytes = Number(contentLength ?? 0);\n\n\tlet transferredBytes = 0;\n\n\tconst stream = new ReadableStream({\n\t\tstart: async (controller) => {\n\t\t\tconst body = response.body;\n\n\t\t\tif (!body) return;\n\n\t\t\tconst responseStreamContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tevent: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse,\n\t\t\t} satisfies ResponseStreamContext;\n\n\t\t\tawait executeHooks(options.onResponseStream?.(responseStreamContext));\n\n\t\t\tfor await (const chunk of body) {\n\t\t\t\ttransferredBytes += chunk.byteLength;\n\n\t\t\t\ttotalBytes = Math.max(totalBytes, transferredBytes);\n\n\t\t\t\tawait executeHooks(\n\t\t\t\t\toptions.onResponseStream?.({\n\t\t\t\t\t\t...responseStreamContext,\n\t\t\t\t\t\tevent: createProgressEvent({ chunk, totalBytes, transferredBytes }),\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t}\n\n\t\t\tcontroller.close();\n\t\t},\n\t});\n\n\treturn new Response(stream, response);\n};\n","import { extraOptionDefaults } from \"./constants/defaults\";\nimport type { RequestContext } from \"./hooks\";\nimport { toStreamableRequest, toStreamableResponse } from \"./stream\";\nimport type { AnyString, Awaitable, UnmaskType } from \"./types/type-helpers\";\nimport { waitFor } from \"./utils/common\";\nimport { isFunction } from \"./utils/guards\";\n\ntype RequestInfo = {\n\tcontroller: AbortController;\n\tresponsePromise: Awaitable<Response>;\n};\n\n/**\n * Cache that stores active request information for deduplication within a specific scope.\n *\n * Maps deduplication keys to their corresponding request information, including the abort controller\n * and response promise. A `null` key represents requests that don't participate in deduplication.\n *\n * **Internal Usage:**\n * This type is primarily used internally by the deduplication system. You typically won't need to\n * interact with it directly unless you're building custom deduplication logic or debugging.\n *\n * @example\n * ```ts\n * // This is handled internally, but conceptually:\n * const cache: RequestInfoCache = new Map([\n * [\"user-123\", { controller: abortController, responsePromise: fetchPromise }],\n * [\"config\", { controller: abortController2, responsePromise: fetchPromise2 }],\n * ]);\n * ```\n */\nexport type RequestInfoCache = Map<string | null, RequestInfo>;\n\n/**\n * Global cache that manages multiple request info caches, organized by scope keys.\n *\n * This enables the global deduplication feature by maintaining separate cache namespaces\n * for different scope keys. Each scope key gets its own `RequestInfoCache` instance.\n *\n * **Cache Lifecycle:**\n * - Caches are created on-demand when first accessed\n * - Automatic cleanup occurs when no references remain\n * - Each scope key maintains independent deduplication state\n *\n * **Memory Considerations:**\n * - Each scope key creates a separate cache instance\n * - Consider the number of different scope keys in your application\n * - Caches are cleaned up automatically when clients are garbage collected\n *\n * @example\n * ```ts\n * // This is managed internally, but conceptually:\n * const globalCache: GlobalRequestInfoCache = new Map([\n * [\"user-service\", new Map([...])], // Cache for user service requests\n * [\"analytics\", new Map([...])], // Cache for analytics requests\n * [\"default\", new Map([...])] // Default cache scope\n * ]);\n * ```\n */\nexport type GlobalRequestInfoCache = Map<DedupeOptions[\"dedupeCacheScopeKey\"], RequestInfoCache>;\n\ntype DedupeContext = RequestContext & {\n\t$GlobalRequestInfoCache: GlobalRequestInfoCache;\n\t$LocalRequestInfoCache: RequestInfoCache;\n\tnewFetchController: AbortController;\n};\n\nexport const createDedupeStrategy = async (context: DedupeContext) => {\n\tconst {\n\t\t$GlobalRequestInfoCache,\n\t\t$LocalRequestInfoCache,\n\t\tbaseConfig,\n\t\tconfig,\n\t\tnewFetchController,\n\t\toptions: globalOptions,\n\t} = context;\n\n\tconst dedupeStrategy = globalOptions.dedupeStrategy ?? extraOptionDefaults.dedupeStrategy;\n\n\tconst resolvedDedupeStrategy = isFunction(dedupeStrategy) ? dedupeStrategy(context) : dedupeStrategy;\n\n\tconst getDedupeKey = () => {\n\t\tconst shouldHaveDedupeKey =\n\t\t\tresolvedDedupeStrategy === \"cancel\" || resolvedDedupeStrategy === \"defer\";\n\n\t\tif (!shouldHaveDedupeKey) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst dedupeKey = globalOptions.dedupeKey ?? extraOptionDefaults.dedupeKey;\n\n\t\tconst resolvedDedupeKey = isFunction(dedupeKey) ? dedupeKey(context) : dedupeKey;\n\n\t\treturn resolvedDedupeKey;\n\t};\n\n\tconst getDedupeCacheScopeKey = () => {\n\t\tconst dedupeCacheScopeKey =\n\t\t\tglobalOptions.dedupeCacheScopeKey ?? extraOptionDefaults.dedupeCacheScopeKey;\n\n\t\tconst resolvedDedupeCacheScopeKey =\n\t\t\tisFunction(dedupeCacheScopeKey) ? dedupeCacheScopeKey(context) : dedupeCacheScopeKey;\n\n\t\treturn resolvedDedupeCacheScopeKey;\n\t};\n\n\tconst dedupeKey = getDedupeKey();\n\n\tconst getRequestInfoCache = () => {\n\t\tif (!dedupeKey) return;\n\n\t\tconst dedupeCacheScope = globalOptions.dedupeCacheScope ?? extraOptionDefaults.dedupeCacheScope;\n\n\t\tconst dedupeCacheScopeKey = getDedupeCacheScopeKey();\n\n\t\tconst $RequestInfoCache =\n\t\t\tdedupeCacheScope === \"global\" ?\n\t\t\t\t($GlobalRequestInfoCache.get(dedupeCacheScopeKey)\n\t\t\t\t?? $GlobalRequestInfoCache.set(dedupeCacheScopeKey, new Map()).get(dedupeCacheScopeKey))\n\t\t\t:\t$LocalRequestInfoCache;\n\n\t\treturn {\n\t\t\tdelete: () => $RequestInfoCache?.delete(dedupeKey),\n\t\t\tget: () => $RequestInfoCache?.get(dedupeKey),\n\t\t\tset: (value: RequestInfo) => $RequestInfoCache?.set(dedupeKey, value),\n\t\t};\n\t};\n\n\tconst $RequestInfoCache = getRequestInfoCache();\n\n\t/**\n\t * Force sequential execution of parallel requests to enable proper cache-based deduplication.\n\t *\n\t * Problem: When Promise.all([callApi(url), callApi(url)]) executes, both requests\n\t * start synchronously and reach this point before either can populate the cache.\n\t *\n\t * Why `await Promise.resolve()` fails:\n\t * - All microtasks in a batch resolve together at the next microtask checkpoint\n\t * - Both requests resume execution simultaneously after the await\n\t * - Both check `prevRequestInfo` at the same time → both see empty cache\n\t * - Both proceed to populate cache → deduplication fails\n\t *\n\t * Why `wait new Promise(()=> setTimeout(resolve, number))` works:\n\t * - Each setTimeout creates a separate task in the task queue\n\t * - Tasks execute sequentially, not simultaneously\n\t * - Request 1's task runs first: checks cache (empty) → continues → populates cache\n\t * - Request 2's task runs after: checks cache (populated) → uses cached promise\n\t * - Deduplication succeeds\n\t *\n\t * IMPORTANT: The delay must be non-zero. setTimeout(fn, 0) fails because JavaScript engines\n\t * may optimize zero-delay timers by batching them together, causing all requests to resume\n\t * simultaneously (same problem as microtasks). Any non-zero value (even 0.0000000001) forces\n\t * proper sequential task queue scheduling, ensuring each request gets its own task slot.\n\t */\n\tif (dedupeKey !== null) {\n\t\tawait waitFor(0.01);\n\t}\n\n\tconst prevRequestInfo = $RequestInfoCache?.get();\n\n\tconst getAbortErrorMessage = () => {\n\t\tif (globalOptions.dedupeKey) {\n\t\t\treturn `Duplicate request detected - Aborted previous request with key '${dedupeKey}'`;\n\t\t}\n\n\t\treturn `Duplicate request detected - Aborted previous request to '${globalOptions.fullURL}'`;\n\t};\n\n\tconst handleRequestCancelStrategy = () => {\n\t\tconst shouldCancelRequest = prevRequestInfo && resolvedDedupeStrategy === \"cancel\";\n\n\t\tif (!shouldCancelRequest) return;\n\n\t\tconst message = getAbortErrorMessage();\n\n\t\tconst reason = new DOMException(message, \"AbortError\");\n\n\t\tprevRequestInfo.controller.abort(reason);\n\t};\n\n\tconst handleRequestDeferStrategy = async (deferContext: {\n\t\tfetchApi: NonNullable<DedupeContext[\"options\"][\"customFetchImpl\"]>;\n\t\toptions: DedupeContext[\"options\"];\n\t\trequest: DedupeContext[\"request\"];\n\t}) => {\n\t\t// == Local options and request are needed so that transformations are applied can be applied to both from call site\n\t\tconst { fetchApi, options: localOptions, request: localRequest } = deferContext;\n\n\t\tconst shouldUsePromiseFromCache = prevRequestInfo && resolvedDedupeStrategy === \"defer\";\n\n\t\tconst streamableContext = {\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\toptions: localOptions,\n\t\t\trequest: localRequest,\n\t\t} satisfies RequestContext;\n\n\t\tconst streamableRequest = await toStreamableRequest(streamableContext);\n\n\t\tconst responsePromise =\n\t\t\tshouldUsePromiseFromCache ?\n\t\t\t\tprevRequestInfo.responsePromise\n\t\t\t:\tfetchApi(localOptions.fullURL as NonNullable<typeof localOptions.fullURL>, streamableRequest);\n\n\t\t$RequestInfoCache?.set({ controller: newFetchController, responsePromise });\n\n\t\treturn toStreamableResponse({ ...streamableContext, response: await responsePromise });\n\t};\n\n\tconst removeDedupeKeyFromCache = () => {\n\t\t$RequestInfoCache?.delete();\n\t};\n\n\treturn {\n\t\tgetAbortErrorMessage,\n\t\thandleRequestCancelStrategy,\n\t\thandleRequestDeferStrategy,\n\t\tremoveDedupeKeyFromCache,\n\t\tresolvedDedupeStrategy,\n\t};\n};\n\ntype DedupeStrategyUnion = UnmaskType<\"cancel\" | \"defer\" | \"none\">;\n\nexport type DedupeOptions = {\n\t/**\n\t * Controls the scope of request deduplication caching.\n\t *\n\t * - `\"global\"`: Shares deduplication cache across all `createFetchClient` instances with the same `dedupeCacheScopeKey`.\n\t * Useful for applications with multiple API clients that should share deduplication state.\n\t * - `\"local\"`: Limits deduplication to requests within the same `createFetchClient` instance.\n\t * Provides better isolation and is recommended for most use cases.\n\t *\n\t *\n\t * **Real-world Scenarios:**\n\t * - Use `\"global\"` when you have multiple API clients (user service, auth service, etc.) that might make overlapping requests\n\t * - Use `\"local\"` (default) for single-purpose clients or when you want strict isolation between different parts of your app\n\t *\n\t * @example\n\t * ```ts\n\t * // Local scope - each client has its own deduplication cache\n\t * const userClient = createFetchClient({ baseURL: \"/api/users\" });\n\t * const postClient = createFetchClient({ baseURL: \"/api/posts\" });\n\t * // These clients won't share deduplication state\n\t *\n\t * // Global scope - share cache across related clients\n\t * const userClient = createFetchClient({\n\t * baseURL: \"/api/users\",\n\t * dedupeCacheScope: \"global\",\n\t * });\n\t * const postClient = createFetchClient({\n\t * baseURL: \"/api/posts\",\n\t * dedupeCacheScope: \"global\",\n\t * });\n\t * // These clients will share deduplication state\n\t * ```\n\t *\n\t * @default \"local\"\n\t */\n\tdedupeCacheScope?: \"global\" | \"local\";\n\n\t/**\n\t * Unique namespace for the global deduplication cache when using `dedupeCacheScope: \"global\"`.\n\t *\n\t * This creates logical groupings of deduplication caches. All instances with the same key\n\t * will share the same cache namespace, allowing fine-grained control over which clients\n\t * share deduplication state.\n\t *\n\t * **Best Practices:**\n\t * - Use descriptive names that reflect the logical grouping (e.g., \"user-service\", \"analytics-api\")\n\t * - Keep scope keys consistent across related API clients\n\t * - Consider using different scope keys for different environments (dev, staging, prod)\n\t * - Avoid overly broad scope keys that might cause unintended cache sharing\n\t *\n\t * **Cache Management:**\n\t * - Each scope key maintains its own independent cache\n\t * - Caches are automatically cleaned up when no references remain\n\t * - Consider the memory implications of multiple global scopes\n\t *\n\t * @example\n\t * ```ts\n\t * // Group related API clients together\n\t * const userClient = createFetchClient({\n\t * baseURL: \"/api/users\",\n\t * dedupeCacheScope: \"global\",\n\t * dedupeCacheScopeKey: \"user-service\"\n\t * });\n\t * const profileClient = createFetchClient({\n\t * baseURL: \"/api/profiles\",\n\t * dedupeCacheScope: \"global\",\n\t * dedupeCacheScopeKey: \"user-service\" // Same scope - will share cache\n\t * });\n\t *\n\t * // Separate analytics client with its own cache\n\t * const analyticsClient = createFetchClient({\n\t * baseURL: \"/api/analytics\",\n\t * dedupeCacheScope: \"global\",\n\t * dedupeCacheScopeKey: \"analytics-service\" // Different scope\n\t * });\n\t *\n\t * // Environment-specific scoping\n\t * const apiClient = createFetchClient({\n\t * dedupeCacheScope: \"global\",\n\t * dedupeCacheScopeKey: `api-${process.env.NODE_ENV}` // \"api-development\", \"api-production\", etc.\n\t * });\n\t * ```\n\t *\n\t * @default \"default\"\n\t */\n\tdedupeCacheScopeKey?: \"default\" | AnyString | ((context: RequestContext) => string | undefined);\n\n\t/**\n\t * Custom key generator for request deduplication.\n\t *\n\t * Override the default key generation strategy to control exactly which requests\n\t * are considered duplicates. The default key combines URL, method, body, and\n\t * relevant headers (excluding volatile ones like 'Date', 'Authorization', etc.).\n\t *\n\t * **Default Key Generation:**\n\t * The auto-generated key includes:\n\t * - Full request URL (including query parameters)\n\t * - HTTP method (GET, POST, etc.)\n\t * - Request body (for POST/PUT/PATCH requests)\n\t * - Stable headers (excludes Date, Authorization, User-Agent, etc.)\n\t *\n\t * **Custom Key Best Practices:**\n\t * - Include only the parts of the request that should affect deduplication\n\t * - Avoid including volatile data (timestamps, random IDs, etc.)\n\t * - Consider performance - simpler keys are faster to compute and compare\n\t * - Ensure keys are deterministic for the same logical request\n\t * - Use consistent key formats across your application\n\t *\n\t * **Performance Considerations:**\n\t * - Function-based keys are computed on every request - keep them lightweight\n\t * - String keys are fastest but least flexible\n\t * - Consider caching expensive key computations if needed\n\t *\n\t * @example\n\t * ```ts\n\t * import { callApi } from \"@zayne-labs/callapi\";\n\t *\n\t * // Simple static key - useful for singleton requests\n\t * const config = callApi(\"/api/config\", {\n\t * dedupeKey: \"app-config\",\n\t * dedupeStrategy: \"defer\" // Share the same config across all requests\n\t * });\n\t *\n\t * // URL and method only - ignore headers and body\n\t * const userData = callApi(\"/api/user/123\", {\n\t * dedupeKey: (context) => `${context.options.method}:${context.options.fullURL}`\n\t * });\n\t *\n\t * // Include specific headers in deduplication\n\t * const apiCall = callApi(\"/api/data\", {\n\t * dedupeKey: (context) => {\n\t * const authHeader = context.request.headers.get(\"Authorization\");\n\t * return `${context.options.fullURL}-${authHeader}`;\n\t * }\n\t * });\n\t *\n\t * // User-specific deduplication\n\t * const userSpecificCall = callApi(\"/api/dashboard\", {\n\t * dedupeKey: (context) => {\n\t * const userId = context.options.fullURL.match(/user\\/(\\d+)/)?.[1];\n\t * return `dashboard-${userId}`;\n\t * }\n\t * });\n\t *\n\t * // Ignore certain query parameters\n\t * const searchCall = callApi(\"/api/search?q=test&timestamp=123456\", {\n\t * dedupeKey: (context) => {\n\t * const url = new URL(context.options.fullURL);\n\t * url.searchParams.delete(\"timestamp\"); // Remove volatile param\n\t * return `search:${url.toString()}`;\n\t * }\n\t * });\n\t * ```\n\t *\n\t * @default Auto-generated from request details\n\t */\n\tdedupeKey?: string | ((context: RequestContext) => string | undefined);\n\n\t/**\n\t * Strategy for handling duplicate requests. Can be a static string or callback function.\n\t *\n\t * **Available Strategies:**\n\t * - `\"cancel\"`: Cancel previous request when new one starts (good for search)\n\t * - `\"defer\"`: Share response between duplicate requests (good for config loading)\n\t * - `\"none\"`: No deduplication, all requests execute independently\n\t *\n\t * @example\n\t * ```ts\n\t * // Static strategies\n\t * const searchClient = createFetchClient({\n\t * dedupeStrategy: \"cancel\" // Cancel previous searches\n\t * });\n\t *\n\t * const configClient = createFetchClient({\n\t * dedupeStrategy: \"defer\" // Share config across components\n\t * });\n\t *\n\t * // Dynamic strategy based on request\n\t * const smartClient = createFetchClient({\n\t * dedupeStrategy: (context) => {\n\t * return context.options.method === \"GET\" ? \"defer\" : \"cancel\";\n\t * }\n\t * });\n\t *\n\t * // Search-as-you-type with cancel strategy\n\t * const handleSearch = async (query: string) => {\n\t * try {\n\t * const { data } = await callApi(\"/api/search\", {\n\t * method: \"POST\",\n\t * body: { query },\n\t * dedupeStrategy: \"cancel\",\n\t * dedupeKey: \"search\" // Cancel previous searches, only latest one goes through\n\t * });\n\t *\n\t * updateSearchResults(data);\n\t * } catch (error) {\n\t * if (error.name === \"AbortError\") {\n\t * // Previous search cancelled - (expected behavior)\n\t * return;\n\t * }\n\t * console.error(\"Search failed:\", error);\n\t * }\n\t * };\n\t *\n\t * ```\n\t *\n\t * @default \"cancel\"\n\t */\n\tdedupeStrategy?: DedupeStrategyUnion | ((context: RequestContext) => DedupeStrategyUnion);\n};\n","import type { RequestContext } from \"./hooks\";\nimport type { CallApiContext } from \"./types/common\";\nimport type { DefaultCallApiContext } from \"./types/default-types\";\nimport type { Awaitable, UnmaskType } from \"./types/type-helpers\";\n\nexport type FetchImpl = UnmaskType<\n\t(input: string | Request | URL, init?: RequestInit) => Awaitable<Response>\n>;\n\nexport type FetchMiddlewareContext<TCallApiContext extends CallApiContext> =\n\tRequestContext<TCallApiContext> & {\n\t\tfetchImpl: FetchImpl;\n\t};\n\nexport interface Middlewares<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> {\n\t/**\n\t * Wraps the fetch implementation to intercept requests at the network layer.\n\t *\n\t * Takes a context object containing the current fetch function and returns a new fetch function.\n\t * Use it to cache responses, add logging, handle offline mode, or short-circuit requests etc.\n\t * Multiple middleware compose in order: plugins → base config → per-request.\n\t *\n\t * Unlike `customFetchImpl`, middleware can call through to the original fetch.\n\t *\n\t * @example\n\t * ```ts\n\t * // Cache responses\n\t * const cache = new Map();\n\t *\n\t * fetchMiddleware: (ctx) => async (input, init) => {\n\t * const key = input.toString();\n\t *\n\t * const cachedResponse = cache.get(key);\n\t *\n\t * if (cachedResponse) {\n\t *\t return cachedResponse.clone();\n\t * }\n\t *\n\t * const response = await ctx.fetchImpl(input, init);\n\t * cache.set(key, response.clone());\n\t *\n\t * return response;\n\t * }\n\t *\n\t * // Handle offline\n\t * fetchMiddleware: (ctx) => async (...parameters) => {\n\t * if (!navigator.onLine) {\n\t * return new Response('{\"error\": \"offline\"}', { status: 503 });\n\t * }\n\t *\n\t * return ctx.fetchImpl(...parameters);\n\t * }\n\t * ```\n\t */\n\tfetchMiddleware?: (context: FetchMiddlewareContext<TCallApiContext>) => FetchImpl;\n}\n\ntype MiddlewareRegistries = Required<{\n\t[Key in keyof Middlewares]: Set<Middlewares[Key]>;\n}>;\n\nexport const getMiddlewareRegistriesAndKeys = () => {\n\tconst middlewareRegistries: MiddlewareRegistries = {\n\t\tfetchMiddleware: new Set(),\n\t};\n\n\tconst middlewareRegistryKeys = Object.keys(middlewareRegistries) as Array<keyof Middlewares>;\n\n\treturn { middlewareRegistries, middlewareRegistryKeys };\n};\n\nexport const composeMiddlewaresFromArray = (\n\tmiddlewareArray: Array<Middlewares[keyof Middlewares] | undefined>\n) => {\n\tlet composedMiddleware: Middlewares[keyof Middlewares];\n\n\tfor (const currentMiddleware of middlewareArray) {\n\t\tif (!currentMiddleware) continue;\n\n\t\tconst previousMiddleware = composedMiddleware;\n\n\t\tif (!previousMiddleware) {\n\t\t\tcomposedMiddleware = currentMiddleware;\n\t\t\tcontinue;\n\t\t}\n\n\t\tcomposedMiddleware = (context) => {\n\t\t\tconst prevFetchImpl = previousMiddleware(context);\n\t\t\tconst fetchImpl = currentMiddleware({ ...context, fetchImpl: prevFetchImpl });\n\n\t\t\treturn fetchImpl;\n\t\t};\n\t}\n\n\treturn composedMiddleware;\n};\n","import { extraOptionDefaults } from \"./constants/defaults\";\nimport {\n\tcomposeHooksFromArray,\n\tgetHookRegistriesAndKeys,\n\ttype Hooks,\n\ttype HooksOrHooksArray,\n\ttype RequestContext,\n} from \"./hooks\";\nimport {\n\tcomposeMiddlewaresFromArray,\n\tgetMiddlewareRegistriesAndKeys,\n\ttype Middlewares,\n} from \"./middlewares\";\nimport type { CallApiContext, CallApiRequestOptions, OverrideCallApiContext } from \"./types/common\";\nimport type { DefaultCallApiContext, DefaultDataType } from \"./types/default-types\";\nimport type { AnyFunction, Awaitable, UnionToIntersection } from \"./types/type-helpers\";\nimport type { InitURLOrURLObject } from \"./url\";\nimport { isArray, isFunction, isString } from \"./utils/guards\";\nimport {\n\tgetCurrentRouteSchemaKeyAndMainInitURL,\n\ttype BaseCallApiSchemaAndConfig,\n\ttype InferSchemaOutput,\n} from \"./validation\";\n\nexport type PluginSetupContext<TCallApiContext extends CallApiContext = DefaultCallApiContext> =\n\tRequestContext<TCallApiContext> & ReturnType<typeof getCurrentRouteSchemaKeyAndMainInitURL>;\n\nexport type PluginInitResult<TCallApiContext extends CallApiContext = DefaultCallApiContext> = Partial<\n\tOmit<PluginSetupContext<TCallApiContext>, \"initURL\" | \"request\"> & {\n\t\tinitURL: InitURLOrURLObject;\n\t\trequest: CallApiRequestOptions;\n\t}\n>;\n\ntype GetDefaultDataTypeForPlugins<TData> = DefaultDataType extends TData ? never : TData;\n\nexport type PluginHooks<TCallApiContext extends CallApiContext = DefaultCallApiContext> =\n\tHooksOrHooksArray<\n\t\tOverrideCallApiContext<\n\t\t\tTCallApiContext,\n\t\t\t{\n\t\t\t\tData: GetDefaultDataTypeForPlugins<TCallApiContext[\"Data\"]>;\n\t\t\t\tErrorData: GetDefaultDataTypeForPlugins<TCallApiContext[\"ErrorData\"]>;\n\t\t\t}\n\t\t>\n\t>;\n\nexport type PluginMiddlewares<TCallApiContext extends CallApiContext = DefaultCallApiContext> =\n\tMiddlewares<\n\t\tOverrideCallApiContext<\n\t\t\tTCallApiContext,\n\t\t\t{\n\t\t\t\tData: GetDefaultDataTypeForPlugins<TCallApiContext[\"Data\"]>;\n\t\t\t\tErrorData: GetDefaultDataTypeForPlugins<TCallApiContext[\"ErrorData\"]>;\n\t\t\t}\n\t\t>\n\t>;\n\nexport interface CallApiPlugin<TCallApiContext extends CallApiContext = DefaultCallApiContext> {\n\t/**\n\t * Defines additional options that can be passed to callApi\n\t */\n\tdefineExtraOptions?: () => TCallApiContext[\"InferredExtraOptions\"];\n\n\t/**\n\t * A description for the plugin\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Hooks for the plugin\n\t */\n\thooks?:\n\t\t| PluginHooks<TCallApiContext>\n\t\t| ((\n\t\t\t\tcontext: PluginSetupContext<TCallApiContext>\n\t\t ) => Awaitable<PluginHooks<TCallApiContext>> | Awaitable<void>);\n\n\t/**\n\t * A unique id for the plugin\n\t */\n\tid: string;\n\n\t/**\n\t * Middlewares that for the plugin\n\t */\n\tmiddlewares?:\n\t\t| PluginMiddlewares<TCallApiContext>\n\t\t| ((\n\t\t\t\tcontext: PluginSetupContext<TCallApiContext>\n\t\t ) => Awaitable<PluginMiddlewares<TCallApiContext>> | Awaitable<void>);\n\n\t/**\n\t * A name for the plugin\n\t */\n\tname: string;\n\n\t/**\n\t * Base schema for the client.\n\t */\n\tschema?: BaseCallApiSchemaAndConfig;\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\tsetup?: (\n\t\tcontext: PluginSetupContext<TCallApiContext>\n\t) => Awaitable<PluginInitResult<TCallApiContext>> | Awaitable<void>;\n\n\t/**\n\t * A version for the plugin\n\t */\n\tversion?: string;\n}\n\nexport type InferPluginExtraOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<\n\tTPluginArray extends Array<infer TPlugin> ?\n\t\tTPlugin extends CallApiPlugin ?\n\t\t\tTPlugin[\"defineExtraOptions\"] extends AnyFunction<infer TResult> ?\n\t\t\t\tInferSchemaOutput<TResult, TResult>\n\t\t\t:\tnever\n\t\t:\tnever\n\t:\tnever\n>;\n\nexport const getResolvedPlugins = (context: Pick<RequestContext, \"baseConfig\" | \"options\">) => {\n\tconst { baseConfig, options } = context;\n\n\tconst resolvedPlugins =\n\t\tisFunction(options.plugins) ?\n\t\t\toptions.plugins({ basePlugins: baseConfig.plugins ?? [] })\n\t\t:\t(options.plugins ?? []);\n\n\treturn resolvedPlugins;\n};\n\nexport const initializePlugins = async (setupContext: PluginSetupContext) => {\n\tconst { baseConfig, config, currentRouteSchemaKey, mainInitURL, options, request } = setupContext;\n\n\tconst {\n\t\taddMainHooks,\n\t\taddMainMiddlewares,\n\t\taddPluginHooks,\n\t\taddPluginMiddlewares,\n\t\tgetResolvedHooks,\n\t\tgetResolvedMiddlewares,\n\t} = setupHooksAndMiddlewares({ baseConfig, config, options });\n\n\tlet resolvedCurrentRouteSchemaKey = currentRouteSchemaKey;\n\tlet resolvedInitURL = mainInitURL;\n\tconst resolvedOptions = options;\n\tconst resolvedRequest = request;\n\n\tconst executePluginSetupFn = async (pluginSetup: CallApiPlugin[\"setup\"]) => {\n\t\tif (!pluginSetup) return;\n\n\t\tconst initResult = await pluginSetup(setupContext);\n\n\t\tif (!initResult) return;\n\n\t\tconst urlString = initResult.initURL?.toString();\n\n\t\tif (isString(urlString)) {\n\t\t\tconst newURLResult = getCurrentRouteSchemaKeyAndMainInitURL({\n\t\t\t\tbaseExtraOptions: baseConfig,\n\t\t\t\textraOptions: config,\n\t\t\t\tinitURL: urlString,\n\t\t\t});\n\n\t\t\tresolvedCurrentRouteSchemaKey = newURLResult.currentRouteSchemaKey;\n\t\t\tresolvedInitURL = newURLResult.mainInitURL;\n\t\t}\n\n\t\tif (initResult.request) {\n\t\t\tObject.assign(resolvedRequest, initResult.request, initResult.request.extraFetchOptions);\n\t\t}\n\n\t\tif (initResult.options) {\n\t\t\tObject.assign(resolvedOptions, initResult.options);\n\t\t}\n\t};\n\n\tconst resolvedPlugins = getResolvedPlugins({ baseConfig, options });\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\tconst [, pluginHooks, pluginMiddlewares] = await Promise.all([\n\t\t\texecutePluginSetupFn(plugin.setup),\n\t\t\tisFunction(plugin.hooks) ? plugin.hooks(setupContext) : plugin.hooks,\n\t\t\tisFunction(plugin.middlewares) ? plugin.middlewares(setupContext) : plugin.middlewares,\n\t\t]);\n\n\t\tpluginHooks && addPluginHooks(pluginHooks);\n\t\tpluginMiddlewares && addPluginMiddlewares(pluginMiddlewares);\n\t}\n\n\taddMainHooks();\n\n\taddMainMiddlewares();\n\n\tconst resolvedHooks = getResolvedHooks();\n\n\tconst resolvedMiddlewares = getResolvedMiddlewares();\n\n\treturn {\n\t\tresolvedCurrentRouteSchemaKey,\n\t\tresolvedHooks,\n\t\tresolvedInitURL,\n\t\tresolvedMiddlewares,\n\t\tresolvedOptions,\n\t\tresolvedRequest,\n\t};\n};\n\nconst setupHooksAndMiddlewares = (\n\tcontext: Pick<PluginSetupContext, \"baseConfig\" | \"config\" | \"options\">\n) => {\n\tconst { baseConfig, config, options } = context;\n\n\tconst { hookRegistries, hookRegistryKeys } = getHookRegistriesAndKeys();\n\n\tconst { middlewareRegistries, middlewareRegistryKeys } = getMiddlewareRegistriesAndKeys();\n\n\tconst addMainHooks = () => {\n\t\tfor (const hookName of hookRegistryKeys) {\n\t\t\tconst overriddenHook = options[hookName];\n\t\t\tconst baseHook = baseConfig[hookName];\n\t\t\tconst instanceHook = config[hookName];\n\n\t\t\tconst shouldMergeBaseAndInstanceHooks = isArray(baseHook) && instanceHook;\n\n\t\t\tconst mainHook =\n\t\t\t\tshouldMergeBaseAndInstanceHooks ? [baseHook, instanceHook].flat() : overriddenHook;\n\n\t\t\tmainHook && hookRegistries[hookName].add(mainHook as never);\n\t\t}\n\t};\n\n\tconst addPluginHooks = (pluginHooks: PluginHooks) => {\n\t\tfor (const hookName of hookRegistryKeys) {\n\t\t\tconst pluginHook = pluginHooks[hookName];\n\n\t\t\tpluginHook && hookRegistries[hookName].add(pluginHook as never);\n\t\t}\n\t};\n\n\tconst addMainMiddlewares = () => {\n\t\tfor (const middlewareName of middlewareRegistryKeys) {\n\t\t\tconst baseMiddleware = baseConfig[middlewareName];\n\t\t\tconst instanceMiddleware = config[middlewareName];\n\n\t\t\tbaseMiddleware && middlewareRegistries[middlewareName].add(baseMiddleware);\n\n\t\t\tinstanceMiddleware && middlewareRegistries[middlewareName].add(instanceMiddleware);\n\t\t}\n\t};\n\n\tconst addPluginMiddlewares = (pluginMiddlewares: PluginMiddlewares) => {\n\t\tfor (const middlewareName of middlewareRegistryKeys) {\n\t\t\tconst pluginMiddleware = pluginMiddlewares[middlewareName];\n\n\t\t\tif (!pluginMiddleware) continue;\n\n\t\t\tmiddlewareRegistries[middlewareName].add(pluginMiddleware);\n\t\t}\n\t};\n\n\tconst getResolvedHooks = () => {\n\t\tconst resolvedHooks: Hooks = {};\n\n\t\tfor (const [hookName, hookRegistry] of Object.entries(hookRegistries)) {\n\t\t\tif (hookRegistry.size === 0) continue;\n\n\t\t\t// == Flatten the hook registry to remove any nested arrays, incase an array of hooks is passed to any of the hooks\n\t\t\tconst flattenedHookArray = [...hookRegistry].flat();\n\n\t\t\tif (flattenedHookArray.length === 0) continue;\n\n\t\t\tconst hooksExecutionMode = options.hooksExecutionMode ?? extraOptionDefaults.hooksExecutionMode;\n\n\t\t\tconst composedHook = composeHooksFromArray(flattenedHookArray, hooksExecutionMode);\n\n\t\t\tresolvedHooks[hookName as keyof Hooks] = composedHook;\n\t\t}\n\n\t\treturn resolvedHooks;\n\t};\n\n\tconst getResolvedMiddlewares = () => {\n\t\tconst resolvedMiddlewares: Middlewares = {};\n\n\t\tfor (const [middlewareName, middlewareRegistry] of Object.entries(middlewareRegistries)) {\n\t\t\tif (middlewareRegistry.size === 0) continue;\n\n\t\t\tconst middlewareArray = [...middlewareRegistry];\n\n\t\t\tif (middlewareArray.length === 0) continue;\n\n\t\t\tconst composedMiddleware = composeMiddlewaresFromArray(middlewareArray);\n\n\t\t\tresolvedMiddlewares[middlewareName as keyof Middlewares] = composedMiddleware;\n\t\t}\n\n\t\treturn resolvedMiddlewares;\n\t};\n\n\treturn {\n\t\taddMainHooks,\n\t\taddMainMiddlewares,\n\t\taddPluginHooks,\n\t\taddPluginMiddlewares,\n\t\tgetResolvedHooks,\n\t\tgetResolvedMiddlewares,\n\t};\n};\n","import { extraOptionDefaults } from \"./constants/defaults\";\nimport type { CallApiImpl } from \"./retry\";\nimport type { CallApiConfig, CallApiExtraOptions, CallApiResultLoose } from \"./types/common\";\nimport type { InitURLOrURLObject } from \"./url\";\n\nexport interface RefetchOptions {\n\t/**\n\t * Tracks the number of times refetch has been called\n\t * @internal\n\t * @deprecated **NOTE**: This property is used internally to track refetch calls. Please abstain from modifying it.\n\t */\n\treadonly [\"~refetchCount\"]?: number;\n\n\t/**\n\t * Maximum number of times refetch can be called from error hooks.\n\t *\n\t * Prevents infinite loops when refetch is called repeatedly in error hooks.\n\t * When the limit is reached, refetch will throw an error instead of retrying.\n\t *\n\t * @default 1\n\t *\n\t * @example\n\t * ```ts\n\t * // Allow up to 5 refetch attempts\n\t * refetchAttempts: 5\n\t *\n\t * // Disable refetch limit\n\t * refetchAttempts: Infinity\n\t *\n\t * // Strict limit of 1 refetch\n\t * refetchAttempts: 1\n\t * ```\n\t */\n\trefetchAttempts?: number;\n}\n\nexport type RefetchFn = (\n\toverrides?: Pick<RefetchOptions, \"refetchAttempts\">\n) => Promise<CallApiResultLoose<unknown, unknown> | null>;\n\nexport const createRefetchManager = <TCallApi extends CallApiImpl>(ctx: {\n\tcallApi: TCallApi;\n\tcallApiArgs: { config: CallApiConfig; initURL: InitURLOrURLObject };\n\toptions: CallApiExtraOptions;\n}) => {\n\tconst { callApi, callApiArgs, options } = ctx;\n\n\t// eslint-disable-next-line ts-eslint/no-deprecated -- Allowed for internal use\n\tconst currentRefetchCount = options[\"~refetchCount\"] ?? 1;\n\n\tconst refetch: RefetchFn = async (refetchOptionOverrides) => {\n\t\tconst maxRefetchAttempts =\n\t\t\trefetchOptionOverrides?.refetchAttempts\n\t\t\t?? options.refetchAttempts\n\t\t\t?? extraOptionDefaults.refetchAttempts;\n\n\t\tconst shouldRefetch = currentRefetchCount <= maxRefetchAttempts;\n\n\t\tif (!shouldRefetch) {\n\t\t\tconst message = `Maximum refetch attempts (${maxRefetchAttempts}) exceeded. This prevents infinite loops. Increase 'maxRefetchAttempts' if needed.`;\n\n\t\t\tconsole.error(message);\n\n\t\t\treturn null;\n\t\t}\n\n\t\tconst updatedConfig = {\n\t\t\t...callApiArgs.config,\n\t\t\t...refetchOptionOverrides,\n\t\t\t\"~refetchCount\": currentRefetchCount + 1,\n\t\t} satisfies CallApiConfig;\n\n\t\treturn callApi(callApiArgs.initURL as never, updatedConfig);\n\t};\n\n\treturn {\n\t\trefetch,\n\t};\n};\n","import { extraOptionDefaults } from \"./constants/defaults\";\nimport {\n\texecuteHooksInCatchBlock,\n\ttype ErrorContext,\n\ttype ExecuteHookInfo,\n\ttype RetryContext,\n} from \"./hooks\";\nimport type { CallApiResultErrorVariant } from \"./result\";\nimport type { CallApiConfig, CallApiResultLoose } from \"./types/common\";\nimport type { MethodUnion } from \"./types/conditional-types\";\nimport { defineEnum, type AnyNumber, type Awaitable, type UnmaskType } from \"./types/type-helpers\";\nimport type { InitURLOrURLObject } from \"./url\";\nimport { waitFor } from \"./utils/common\";\nimport { isBoolean, isFunction, isString } from \"./utils/guards\";\n\n// eslint-disable-next-line ts-eslint/no-unused-vars -- Ignore\nconst defaultRetryStatusCodesLookup = () =>\n\tdefineEnum({\n\t\t408: \"Request Timeout\",\n\t\t409: \"Conflict\",\n\t\t425: \"Too Early\",\n\t\t429: \"Too Many Requests\",\n\t\t500: \"Internal Server Error\",\n\t\t502: \"Bad Gateway\",\n\t\t503: \"Service Unavailable\",\n\t\t504: \"Gateway Timeout\",\n\t});\n\ntype RetryStatusCodes = UnmaskType<AnyNumber | keyof ReturnType<typeof defaultRetryStatusCodesLookup>>;\n\ntype RetryCondition<TErrorData> = (context: ErrorContext<{ ErrorData: TErrorData }>) => Awaitable<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 * @internal\n\t * @deprecated **NOTE**: This property is used internally to track retries. Please abstain from modifying it.\n\t */\n\treadonly [\"~retryAttemptCount\"]?: 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 | ((currentAttemptCount: number) => 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?: MethodUnion[];\n\n\t/**\n\t * HTTP status codes that trigger a retry\n\t */\n\tretryStatusCodes?: RetryStatusCodes[];\n\n\t/**\n\t * Strategy to use when retrying\n\t * @default \"linear\"\n\t */\n\tretryStrategy?: \"exponential\" | \"linear\";\n}\n\nconst getLinearDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? extraOptionDefaults.retryDelay;\n\n\tconst resolveRetryDelay = isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay;\n\n\treturn resolveRetryDelay;\n};\n\nconst getExponentialDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? extraOptionDefaults.retryDelay;\n\n\tconst resolvedRetryDelay = isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay;\n\n\tconst maxDelay = options.retryMaxDelay ?? extraOptionDefaults.retryMaxDelay;\n\n\tconst exponentialDelay = resolvedRetryDelay * 2 ** currentAttemptCount;\n\n\treturn Math.min(exponentialDelay, maxDelay);\n};\n\nexport type CallApiImpl = (\n\tinitURL: never,\n\tinit?: CallApiConfig\n) => Promise<CallApiResultLoose<unknown, unknown>>;\n\nexport const createRetryManager = <TCallApi extends CallApiImpl>(ctx: {\n\tcallApi: TCallApi;\n\tcallApiArgs: { config: CallApiConfig; initURL: InitURLOrURLObject };\n\terror: unknown;\n\terrorContext: ErrorContext;\n\terrorResult: CallApiResultErrorVariant<unknown> | null;\n\thookInfo: ExecuteHookInfo;\n}) => {\n\tconst { callApi, callApiArgs, error, errorContext, errorResult, hookInfo } = ctx;\n\n\tconst { options, request } = errorContext;\n\n\t// eslint-disable-next-line ts-eslint/no-deprecated -- Allowed for internal use\n\tconst currentAttemptCount = options[\"~retryAttemptCount\"] ?? 1;\n\n\tconst retryStrategy = options.retryStrategy ?? extraOptionDefaults.retryStrategy;\n\n\tconst getDelay = () => {\n\t\tswitch (retryStrategy) {\n\t\t\tcase \"exponential\": {\n\t\t\t\treturn getExponentialDelay(currentAttemptCount, options);\n\t\t\t}\n\t\t\tcase \"linear\": {\n\t\t\t\treturn getLinearDelay(currentAttemptCount, options);\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(`Invalid retry strategy: ${String(retryStrategy)}`);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst shouldAttemptRetry = async () => {\n\t\tif (isBoolean(request.signal) && request.signal.aborted) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst retryCondition = options.retryCondition ?? extraOptionDefaults.retryCondition;\n\n\t\tconst maxRetryAttempts = options.retryAttempts ?? extraOptionDefaults.retryAttempts;\n\n\t\tconst customRetryCondition = await retryCondition(errorContext);\n\n\t\tconst baseShouldRetry = currentAttemptCount <= maxRetryAttempts && customRetryCondition;\n\n\t\tif (!baseShouldRetry) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst retryMethods = new Set(options.retryMethods ?? extraOptionDefaults.retryMethods);\n\n\t\tconst includesMethod =\n\t\t\tisString(request.method) && retryMethods.size > 0 ? retryMethods.has(request.method) : true;\n\n\t\tconst retryStatusCodes = new Set(options.retryStatusCodes ?? extraOptionDefaults.retryStatusCodes);\n\n\t\tconst includesStatusCodes =\n\t\t\terrorContext.response != null && retryStatusCodes.size > 0 ?\n\t\t\t\tretryStatusCodes.has(errorContext.response.status)\n\t\t\t:\ttrue;\n\n\t\tconst shouldRetry = includesMethod && includesStatusCodes;\n\n\t\treturn shouldRetry;\n\t};\n\n\tconst handleRetry = async () => {\n\t\tconst retryContext = {\n\t\t\t...errorContext,\n\t\t\tretryAttemptCount: currentAttemptCount,\n\t\t} satisfies RetryContext<{ ErrorData: unknown }>;\n\n\t\tconst hookError = await executeHooksInCatchBlock([options.onRetry?.(retryContext)], hookInfo);\n\n\t\tif (hookError) {\n\t\t\treturn hookError;\n\t\t}\n\n\t\tawait waitFor(getDelay());\n\n\t\tconst updatedConfig = {\n\t\t\t...callApiArgs.config,\n\t\t\t\"~retryAttemptCount\": currentAttemptCount + 1,\n\t\t} satisfies CallApiConfig;\n\n\t\treturn callApi(callApiArgs.initURL as never, updatedConfig);\n\t};\n\n\tconst handleRetryOrGetErrorResult = async () => {\n\t\tconst shouldRetry = await shouldAttemptRetry();\n\n\t\tif (shouldRetry) {\n\t\t\treturn handleRetry() as never;\n\t\t}\n\n\t\tif (hookInfo.shouldThrowOnError) {\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn errorResult;\n\t};\n\n\treturn {\n\t\thandleRetryOrGetErrorResult,\n\t};\n};\n","import { createDedupeStrategy, type GlobalRequestInfoCache, type RequestInfoCache } from \"./dedupe\";\nimport {\n\texecuteHooks,\n\texecuteHooksInCatchBlock,\n\ttype CallApiExtraOptionsForHooks,\n\ttype CallApiRequestOptionsForHooks,\n\ttype ErrorContext,\n\ttype ExecuteHookInfo,\n\ttype RequestContext,\n\ttype ResponseContext,\n\ttype SuccessContext,\n\ttype ValidationErrorContext,\n} from \"./hooks\";\nimport { initializePlugins, type CallApiPlugin } from \"./plugins\";\nimport { createRefetchManager } from \"./refetch\";\nimport {\n\tgetCustomizedErrorResult,\n\tresolveErrorResult,\n\tresolveResponseData,\n\tresolveSuccessResult,\n\ttype ErrorInfo,\n\ttype GetResponseType,\n\ttype ResponseTypeType,\n\ttype ResultModeType,\n} from \"./result\";\nimport { createRetryManager } from \"./retry\";\nimport type {\n\tBaseCallApiConfig,\n\tCallApiConfig,\n\tCallApiContext,\n\tCallApiExtraOptions,\n\tCallApiRequestOptions,\n\tCallApiResult,\n\tGetBaseSchemaConfig,\n\tGetBaseSchemaRoutes,\n} from \"./types/common\";\nimport type {\n\tGetCurrentRouteSchema,\n\tGetCurrentRouteSchemaKey,\n\tInferInitURL,\n\tThrowOnErrorBoolean,\n} from \"./types/conditional-types\";\nimport type {\n\tDefaultCallApiContext,\n\tDefaultPluginArray,\n\tDefaultThrowOnError,\n} from \"./types/default-types\";\nimport type { AnyFunction } from \"./types/type-helpers\";\nimport { getFullAndNormalizedURL } from \"./url\";\nimport {\n\tcreateCombinedSignal,\n\tcreateTimeoutSignal,\n\tgetBody,\n\tgetFetchImpl,\n\tgetHeaders,\n\tgetMethod,\n\tgetResolvedHeaders,\n\tsplitBaseConfig,\n\tsplitConfig,\n} from \"./utils/common\";\nimport { HTTPError } from \"./utils/external/error\";\nimport { isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/external/guards\";\nimport { isFunction } from \"./utils/guards\";\nimport {\n\tgetCurrentRouteSchemaKeyAndMainInitURL,\n\thandleConfigValidation,\n\thandleSchemaValidation,\n\ttype BaseCallApiSchemaAndConfig,\n\ttype BaseCallApiSchemaRoutes,\n\ttype CallApiSchema,\n\ttype CallApiSchemaConfig,\n\ttype InferSchemaOutput,\n} from \"./validation\";\n\nconst $GlobalRequestInfoCache: GlobalRequestInfoCache = new Map();\n\nexport const createFetchClientWithContext = <\n\tTOuterCallApiContext extends CallApiContext = DefaultCallApiContext,\n>() => {\n\tconst createFetchClient = <\n\t\tTBaseCallApiContext extends CallApiContext = TOuterCallApiContext,\n\t\tTBaseData = TBaseCallApiContext[\"Data\"],\n\t\tTBaseErrorData = TBaseCallApiContext[\"ErrorData\"],\n\t\tTBaseResultMode extends ResultModeType = TBaseCallApiContext[\"ResultMode\"] extends ResultModeType ?\n\t\t\tTBaseCallApiContext[\"ResultMode\"]\n\t\t:\tDefaultCallApiContext[\"ResultMode\"],\n\t\tTBaseThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError,\n\t\tTBaseResponseType extends ResponseTypeType = ResponseTypeType,\n\t\tconst TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig,\n\t\tconst TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\t\tTComputedBaseSchemaConfig extends CallApiSchemaConfig = GetBaseSchemaConfig<TBaseSchemaAndConfig>,\n\t\tTComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes =\n\t\t\tGetBaseSchemaRoutes<TBaseSchemaAndConfig>,\n\t>(\n\t\tinitBaseConfig: BaseCallApiConfig<\n\t\t\tTBaseCallApiContext,\n\t\t\tTBaseData,\n\t\t\tTBaseErrorData,\n\t\t\tTBaseResultMode,\n\t\t\tTBaseThrowOnError,\n\t\t\tTBaseResponseType,\n\t\t\tTBaseSchemaAndConfig,\n\t\t\tTBasePluginArray\n\t\t> = {} as never\n\t) => {\n\t\tconst $LocalRequestInfoCache: RequestInfoCache = new Map();\n\n\t\tconst callApi = async <\n\t\t\tTData = TBaseData,\n\t\t\tTErrorData = TBaseErrorData,\n\t\t\tTResultMode extends ResultModeType = TBaseResultMode,\n\t\t\tTCallApiContext extends CallApiContext = TBaseCallApiContext,\n\t\t\tTThrowOnError extends ThrowOnErrorBoolean = TBaseThrowOnError,\n\t\t\tTResponseType extends ResponseTypeType = TBaseResponseType,\n\t\t\tconst TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig,\n\t\t\tTInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<\n\t\t\t\tTComputedBaseSchemaRoutes,\n\t\t\t\tTSchemaConfig\n\t\t\t>,\n\t\t\tTCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> =\n\t\t\t\tGetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>,\n\t\t\tconst TSchema extends CallApiSchema = GetCurrentRouteSchema<\n\t\t\t\tTComputedBaseSchemaRoutes,\n\t\t\t\tTCurrentRouteSchemaKey\n\t\t\t>,\n\t\t\tconst TPluginArray extends CallApiPlugin[] = TBasePluginArray,\n\t\t\tTComputedData = InferSchemaOutput<TSchema[\"data\"], GetResponseType<TData, TResponseType>>,\n\t\t\tTComputedErrorData = InferSchemaOutput<\n\t\t\t\tTSchema[\"errorData\"],\n\t\t\t\tGetResponseType<TErrorData, TResponseType>\n\t\t\t>,\n\t\t\tTComputedResult = CallApiResult<TComputedData, TComputedErrorData, TResultMode, TThrowOnError>,\n\t\t>(\n\t\t\tinitURL: TInitURL,\n\t\t\tinitConfig: CallApiConfig<\n\t\t\t\tTCallApiContext,\n\t\t\t\tTComputedData,\n\t\t\t\tTComputedErrorData,\n\t\t\t\tTResultMode,\n\t\t\t\tTThrowOnError,\n\t\t\t\tTResponseType,\n\t\t\t\tTComputedBaseSchemaRoutes,\n\t\t\t\tTSchema,\n\t\t\t\tTComputedBaseSchemaConfig,\n\t\t\t\tTSchemaConfig,\n\t\t\t\tTInitURL,\n\t\t\t\tTCurrentRouteSchemaKey,\n\t\t\t\tTBasePluginArray,\n\t\t\t\tTPluginArray\n\t\t\t> = {} as never\n\t\t): Promise<TComputedResult> => {\n\t\t\tconst [fetchOptions, extraOptions] = splitConfig(initConfig);\n\n\t\t\tconst resolvedBaseConfig =\n\t\t\t\tisFunction(initBaseConfig) ?\n\t\t\t\t\tinitBaseConfig({\n\t\t\t\t\t\tinitURL: initURL.toString(),\n\t\t\t\t\t\toptions: extraOptions,\n\t\t\t\t\t\trequest: fetchOptions,\n\t\t\t\t\t})\n\t\t\t\t:\tinitBaseConfig;\n\n\t\t\tconst baseConfig = resolvedBaseConfig as Exclude<BaseCallApiConfig, AnyFunction>;\n\t\t\tconst config = initConfig as CallApiConfig;\n\n\t\t\tconst [baseFetchOptions, baseExtraOptions] = splitBaseConfig(baseConfig);\n\n\t\t\tconst shouldSkipAutoMergeForOptions =\n\t\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"options\";\n\n\t\t\tconst shouldSkipAutoMergeForRequest =\n\t\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"request\";\n\n\t\t\t// == Merged Extra Options\n\t\t\tconst mergedExtraOptions = {\n\t\t\t\t...baseExtraOptions,\n\t\t\t\t...(!shouldSkipAutoMergeForOptions && extraOptions),\n\t\t\t};\n\n\t\t\t// == Merged Request Options\n\t\t\tconst mergedRequestOptions = {\n\t\t\t\t...baseFetchOptions,\n\t\t\t\t...baseFetchOptions.extraFetchOptions,\n\t\t\t\t...(!shouldSkipAutoMergeForRequest && fetchOptions),\n\t\t\t\t...(!shouldSkipAutoMergeForRequest && fetchOptions.extraFetchOptions),\n\t\t\t} satisfies CallApiRequestOptions;\n\n\t\t\tconst initURLResult = getCurrentRouteSchemaKeyAndMainInitURL({\n\t\t\t\tbaseExtraOptions: baseConfig,\n\t\t\t\textraOptions: config,\n\t\t\t\tinitURL: initURL.toString(),\n\t\t\t});\n\n\t\t\tconst {\n\t\t\t\tresolvedCurrentRouteSchemaKey,\n\t\t\t\tresolvedHooks,\n\t\t\t\tresolvedInitURL,\n\t\t\t\tresolvedMiddlewares,\n\t\t\t\tresolvedOptions,\n\t\t\t\tresolvedRequest,\n\t\t\t} = await initializePlugins({\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\t...initURLResult,\n\t\t\t\toptions: mergedExtraOptions as CallApiExtraOptionsForHooks,\n\t\t\t\trequest: {\n\t\t\t\t\t...mergedRequestOptions,\n\t\t\t\t\theaders: getResolvedHeaders({ baseHeaders: baseConfig.headers, headers: config.headers }),\n\t\t\t\t\tmethod: getMethod({ initURL: initURLResult.initURL, method: mergedRequestOptions.method }),\n\t\t\t\t} as CallApiRequestOptionsForHooks,\n\t\t\t});\n\n\t\t\tconst { fullURL, normalizedInitURL } = getFullAndNormalizedURL({\n\t\t\t\tbaseURL: resolvedOptions.baseURL,\n\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\tparams: resolvedOptions.params,\n\t\t\t\tquery: resolvedOptions.query,\n\t\t\t});\n\n\t\t\tconst initOptions = {\n\t\t\t\t...resolvedOptions,\n\t\t\t\t...resolvedHooks,\n\t\t\t\t...resolvedMiddlewares,\n\t\t\t\tfullURL,\n\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\tinitURLNormalized: normalizedInitURL,\n\t\t\t} satisfies CallApiExtraOptions;\n\n\t\t\tconst { refetch } = createRefetchManager({\n\t\t\t\tcallApi,\n\t\t\t\tcallApiArgs: { config, initURL },\n\t\t\t\toptions: initOptions,\n\t\t\t});\n\n\t\t\tconst options = {\n\t\t\t\t...initOptions,\n\t\t\t\trefetch,\n\t\t\t} satisfies CallApiExtraOptionsForHooks;\n\n\t\t\tconst newFetchController = new AbortController();\n\n\t\t\tconst timeoutSignal = createTimeoutSignal(options.timeout);\n\n\t\t\tconst combinedSignal = createCombinedSignal(\n\t\t\t\ttimeoutSignal,\n\t\t\t\tresolvedRequest.signal,\n\t\t\t\tnewFetchController.signal\n\t\t\t);\n\n\t\t\tconst request = {\n\t\t\t\t...resolvedRequest,\n\t\t\t\tsignal: combinedSignal,\n\t\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\t\tconst {\n\t\t\t\tgetAbortErrorMessage,\n\t\t\t\thandleRequestCancelStrategy,\n\t\t\t\thandleRequestDeferStrategy,\n\t\t\t\tremoveDedupeKeyFromCache,\n\t\t\t\tresolvedDedupeStrategy,\n\t\t\t} = await createDedupeStrategy({\n\t\t\t\t$GlobalRequestInfoCache,\n\t\t\t\t$LocalRequestInfoCache,\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tnewFetchController,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\thandleRequestCancelStrategy();\n\n\t\t\t\tawait executeHooks(options.onRequest?.({ baseConfig, config, options, request }));\n\n\t\t\t\tconst {\n\t\t\t\t\textraOptionsValidationResult,\n\t\t\t\t\trequestOptionsValidationResult,\n\t\t\t\t\tresolvedSchema,\n\t\t\t\t\tresolvedSchemaConfig,\n\t\t\t\t} = await handleConfigValidation({\n\t\t\t\t\tbaseExtraOptions,\n\t\t\t\t\tcurrentRouteSchemaKey: resolvedCurrentRouteSchemaKey,\n\t\t\t\t\textraOptions,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t});\n\n\t\t\t\t// == Apply Schema Output for Extra Options\n\n\t\t\t\tObject.assign(options, extraOptionsValidationResult);\n\n\t\t\t\tconst modifiedRequestOptionsValidationResult = {\n\t\t\t\t\tbody: getBody({\n\t\t\t\t\t\tbody: requestOptionsValidationResult.body,\n\t\t\t\t\t\tbodySerializer: options.bodySerializer,\n\t\t\t\t\t\tresolvedHeaders: requestOptionsValidationResult.headers,\n\t\t\t\t\t}),\n\t\t\t\t\theaders: await getHeaders({\n\t\t\t\t\t\tauth: options.auth,\n\t\t\t\t\t\tbody: requestOptionsValidationResult.body,\n\t\t\t\t\t\tresolvedHeaders: requestOptionsValidationResult.headers,\n\t\t\t\t\t}),\n\t\t\t\t\tmethod: getMethod({\n\t\t\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\t\t\tmethod: requestOptionsValidationResult.method,\n\t\t\t\t\t}),\n\t\t\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\t\t\t// == Apply Schema Output for Request Options\n\t\t\t\tObject.assign(request, modifiedRequestOptionsValidationResult);\n\n\t\t\t\tconst readyRequestContext = {\n\t\t\t\t\tbaseConfig,\n\t\t\t\t\tconfig,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t} satisfies RequestContext;\n\n\t\t\t\tawait executeHooks(options.onRequestReady?.(readyRequestContext));\n\n\t\t\t\tconst fetchApi = getFetchImpl({\n\t\t\t\t\tcustomFetchImpl: options.customFetchImpl,\n\t\t\t\t\tfetchMiddleware: options.fetchMiddleware,\n\t\t\t\t\trequestContext: readyRequestContext,\n\t\t\t\t});\n\n\t\t\t\tconst response = await handleRequestDeferStrategy({ fetchApi, options, request });\n\n\t\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\t\tconst shouldCloneResponse = Boolean(\n\t\t\t\t\tresolvedDedupeStrategy === \"defer\" || options.cloneResponse\n\t\t\t\t);\n\n\t\t\t\tconst responseData = await resolveResponseData({\n\t\t\t\t\tresponse: shouldCloneResponse ? response.clone() : response,\n\t\t\t\t\tresponseParser: options.responseParser,\n\t\t\t\t\tresponseType: options.responseType,\n\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t});\n\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tconst validErrorData = await handleSchemaValidation(resolvedSchema, \"errorData\", {\n\t\t\t\t\t\tinputValue: responseData,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t\t\t});\n\n\t\t\t\t\t// == Push all error handling responsibilities to the catch block if not retrying\n\t\t\t\t\tthrow new HTTPError(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdefaultHTTPErrorMessage: options.defaultHTTPErrorMessage,\n\t\t\t\t\t\t\terrorData: validErrorData,\n\t\t\t\t\t\t\tresponse,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ cause: validErrorData }\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst validSuccessData = await handleSchemaValidation(resolvedSchema, \"data\", {\n\t\t\t\t\tinputValue: responseData,\n\t\t\t\t\tresponse,\n\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t\t});\n\n\t\t\t\tconst successContext = {\n\t\t\t\t\tbaseConfig,\n\t\t\t\t\tconfig,\n\t\t\t\t\tdata: validSuccessData,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t\tresponse,\n\t\t\t\t} satisfies SuccessContext;\n\n\t\t\t\tawait executeHooks(\n\t\t\t\t\toptions.onSuccess?.(successContext),\n\t\t\t\t\toptions.onResponse?.({ ...successContext, error: null })\n\t\t\t\t);\n\n\t\t\t\tconst successResult = resolveSuccessResult(successContext.data, {\n\t\t\t\t\tresponse: successContext.response,\n\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t});\n\n\t\t\t\treturn successResult as never;\n\n\t\t\t\t// == Exhaustive Error handling\n\t\t\t} catch (error) {\n\t\t\t\tconst errorInfo = {\n\t\t\t\t\tcloneResponse: options.cloneResponse,\n\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t} satisfies ErrorInfo;\n\n\t\t\t\tconst { errorDetails, errorResult } = resolveErrorResult(error, errorInfo);\n\n\t\t\t\tconst errorContext = {\n\t\t\t\t\tbaseConfig,\n\t\t\t\t\tconfig,\n\t\t\t\t\terror: errorDetails.error as never,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t\tresponse: errorDetails.response as never,\n\t\t\t\t} satisfies ErrorContext;\n\n\t\t\t\tconst shouldThrowOnError = Boolean(\n\t\t\t\t\tisFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError\n\t\t\t\t);\n\n\t\t\t\tconst hookInfo = {\n\t\t\t\t\terrorInfo,\n\t\t\t\t\tshouldThrowOnError,\n\t\t\t\t} satisfies ExecuteHookInfo;\n\n\t\t\t\tconst { handleRetryOrGetErrorResult } = createRetryManager({\n\t\t\t\t\tcallApi,\n\t\t\t\t\tcallApiArgs: { config, initURL },\n\t\t\t\t\terror,\n\t\t\t\t\terrorContext,\n\t\t\t\t\terrorResult,\n\t\t\t\t\thookInfo,\n\t\t\t\t});\n\n\t\t\t\tconst responseContext: ResponseContext | null =\n\t\t\t\t\t(errorContext.response as Response | null) ? { ...errorContext, data: null } : null;\n\n\t\t\t\tif (isValidationErrorInstance(error)) {\n\t\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\tresponseContext && options.onResponse?.(responseContext),\n\t\t\t\t\t\t\toptions.onValidationError?.(errorContext as ValidationErrorContext),\n\t\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t\t],\n\t\t\t\t\t\thookInfo\n\t\t\t\t\t);\n\n\t\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t\t}\n\n\t\t\t\tif (isHTTPErrorInstance<TErrorData>(error)) {\n\t\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\tresponseContext && options.onResponse?.(responseContext),\n\t\t\t\t\t\t\toptions.onResponseError?.(errorContext),\n\t\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t\t],\n\t\t\t\t\t\thookInfo\n\t\t\t\t\t);\n\n\t\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t\t}\n\n\t\t\t\tlet message = (error as Error | undefined)?.message;\n\n\t\t\t\tif (error instanceof DOMException && error.name === \"AbortError\") {\n\t\t\t\t\tmessage = getAbortErrorMessage();\n\n\t\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t\t}\n\n\t\t\t\tif (error instanceof DOMException && error.name === \"TimeoutError\") {\n\t\t\t\t\tmessage = `Request timed out after ${options.timeout}ms`;\n\n\t\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t\t}\n\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[\n\t\t\t\t\t\tresponseContext && options.onResponse?.(responseContext),\n\t\t\t\t\t\toptions.onRequestError?.(errorContext),\n\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError\n\t\t\t\t\t?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message })) as never;\n\n\t\t\t\t// == Removing the now unneeded AbortController from store\n\t\t\t} finally {\n\t\t\t\tremoveDedupeKeyFromCache();\n\t\t\t}\n\t\t};\n\n\t\treturn callApi;\n\t};\n\n\treturn createFetchClient;\n};\n\nexport const createFetchClient = createFetchClientWithContext();\n\nexport const callApi = createFetchClient();\n"],"mappings":";;AAoBA,MAAa,mBAA0B,UAAoB,oBAA2C;CACrG,mBAAmB,SAAS,aAAa;CACzC,YAAY,SAAS,MAAM;CAC3B,gBAAgB,SAAS,UAAU;CACnC,MAAM,YAA4B;AAEjC,SAAO,eADM,MAAM,SAAS,MAAM,CACP;;CAE5B,cAAc,SAAS;CACvB,YAAY,SAAS,MAAM;CAC3B;AAuBD,MAAM,YAAY,IAAI,IAAI;CAAC;CAAa;CAAmB;CAAqB;CAAmB,CAAC;AACpG,MAAM,aAAa;AAEnB,MAAM,sBAAsB,aAA4E;CACvG,MAAM,kBAAkB,SAAS,QAAQ,IAAI,eAAe;AAE5D,KAAI,CAAC,gBACJ,QAAO,oBAAoB;CAG5B,MAAM,cAAc,gBAAgB,MAAM,IAAI,CAAC,MAAM;AAErD,KAAI,WAAW,KAAK,YAAY,CAC/B,QAAO;AAGR,KAAI,UAAU,IAAI,YAAY,IAAI,YAAY,WAAW,QAAQ,CAChE,QAAO;AAGR,QAAO;;AAGR,MAAa,sBAAsB,OAAO,YAKpC;CACL,MAAM,EAAE,UAAU,gBAAgB,cAAc,eAAe;AAG/D,KAAI,eAAe,WAClB,QAAO;CAGR,MAAM,iBAAiB,kBAAkB,oBAAoB;CAC7D,MAAM,uBAAuB,gBAAgB,mBAAmB,SAAS;CAEzE,MAAM,uBAAuB,gBAAgB,UAAU,eAAe;AAEtE,KAAI,CAAC,OAAO,OAAO,sBAAsB,qBAAqB,CAC7D,OAAM,IAAI,MAAM,0BAA0B,uBAAuB;AAGlE,QAAO,qBAAqB,uBAAuB;;AAkHpD,MAAM,oBAAoB,YAAqD;A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,SAAS,gBAAgB;AACnE,eAAU,2BAA2B,QAAQ,QAAQ;AAErD,MAAC,sBAAsB,QAAQ,MAAM,GAAG,MAAM,KAAK,IAAI,QAAQ;;AAYhE,WATkB,MAAM,yBACvB;KACC,mBAAmB,QAAQ,aAAa,gBAAgB;KACxD,QAAQ,iBAAiB,aAAa;KACtC,QAAQ,UAAU,aAAa;KAC/B,EACD,SACA,IAGG,yBAAyB,MAAM,6BAA6B,EAAE,EAAE,SAAS,CAAC;aAGrE;AACT,8BAA0B;;;AAI5B,SAAO;;AAGR,QAAO;;AAGR,MAAa,oBAAoB,8BAA8B;AAE/D,MAAa,UAAU,mBAAmB"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/result.ts","../src/hooks.ts","../src/stream.ts","../src/dedupe.ts","../src/middlewares.ts","../src/plugins.ts","../src/refetch.ts","../src/retry.ts","../src/createFetchClient.ts"],"sourcesContent":["import { extraOptionDefaults } from \"./constants/defaults\";\nimport type { CallApiExtraOptions } from \"./types/common\";\nimport type { ThrowOnErrorBoolean } from \"./types/conditional-types\";\nimport type { DefaultDataType, DefaultThrowOnError } from \"./types/default-types\";\nimport type {\n\tAnyString,\n\tAwaitable,\n\tDistributiveOmit,\n\tNoInferUnMasked,\n\tPrettify,\n\tUnmaskType,\n} from \"./types/type-helpers\";\nimport { omitKeys } from \"./utils/common\";\nimport type { HTTPError, ValidationError } from \"./utils/external/error\";\nimport { isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/external/guards\";\n\nexport type ResponseType = \"blob\" | \"json\" | \"text\";\n\nexport type ResponseParser<TData> = (text: string) => Awaitable<TData>;\n\nexport const getResponseType = <TData>(response: Response, responseParser: ResponseParser<TData>) => ({\n\tarrayBuffer: () => response.arrayBuffer(),\n\tblob: () => response.blob(),\n\tformData: () => response.formData(),\n\tjson: async (): Promise<TData> => {\n\t\tconst text = await response.text();\n\t\treturn responseParser(text);\n\t},\n\tstream: () => response.body,\n\ttext: () => response.text(),\n});\n\ntype InitResponseTypeMap<TData = unknown> = ReturnType<typeof getResponseType<TData>>;\n\ntype ResponseTypeUnion = keyof InitResponseTypeMap;\n\ntype ResponseTypePlaceholder = null;\n\nexport type ResponseTypeType = ResponseTypePlaceholder | ResponseTypeUnion;\n\nexport type ResponseTypeMap<TData> = {\n\t[Key in keyof InitResponseTypeMap<TData>]: Awaited<ReturnType<InitResponseTypeMap<TData>[Key]>>;\n};\n\nexport type GetResponseType<\n\tTData,\n\tTResponseType extends ResponseTypeType,\n\tTComputedResponseTypeMap extends ResponseTypeMap<TData> = ResponseTypeMap<TData>,\n> =\n\tnull extends TResponseType ? TComputedResponseTypeMap[\"json\"]\n\t: TResponseType extends NonNullable<ResponseTypeType> ? TComputedResponseTypeMap[TResponseType]\n\t: never;\n\nconst textTypes = new Set([\"image/svg\", \"application/xml\", \"application/xhtml\", \"application/html\"]);\nconst JSON_REGEX = /^application\\/(?:[\\w!#$%&*.^`~-]*\\+)?json(;.+)?$/i;\n\nconst detectResponseType = (response: Response): Extract<ResponseTypeType, \"blob\" | \"json\" | \"text\"> => {\n\tconst initContentType = response.headers.get(\"content-type\");\n\n\tif (!initContentType) {\n\t\treturn extraOptionDefaults.responseType;\n\t}\n\n\tconst contentType = initContentType.split(\";\")[0] ?? \"\";\n\n\tif (JSON_REGEX.test(contentType)) {\n\t\treturn \"json\";\n\t}\n\n\tif (textTypes.has(contentType) || contentType.startsWith(\"text/\")) {\n\t\treturn \"text\";\n\t}\n\n\treturn \"blob\";\n};\n\nexport const resolveResponseData = async (options: {\n\tresponse: Response;\n\tresponseParser: CallApiExtraOptions[\"responseParser\"];\n\tresponseType: CallApiExtraOptions[\"responseType\"];\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n}) => {\n\tconst { response, responseParser, responseType, resultMode } = options;\n\n\t// == If the result mode is set to `fetchApi`, then don't try to resolve the responseData and just return null\n\tif (resultMode === \"fetchApi\") {\n\t\treturn null;\n\t}\n\n\tconst selectedParser = responseParser ?? extraOptionDefaults.responseParser;\n\tconst selectedResponseType = responseType ?? detectResponseType(response);\n\n\tconst RESPONSE_TYPE_LOOKUP = getResponseType(response, selectedParser);\n\n\tif (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, selectedResponseType)) {\n\t\tthrow new Error(`Invalid response type: ${selectedResponseType}`);\n\t}\n\n\treturn RESPONSE_TYPE_LOOKUP[selectedResponseType]();\n};\n\nexport type CallApiResultSuccessVariant<TData> = {\n\tdata: NoInferUnMasked<TData>;\n\terror: null;\n\tresponse: Response;\n};\nexport type PossibleJavaScriptError = UnmaskType<{\n\terrorData: false;\n\tmessage: string;\n\tname: \"AbortError\" | \"Error\" | \"SyntaxError\" | \"TimeoutError\" | \"TypeError\" | AnyString;\n\toriginalError: DOMException | Error | SyntaxError | TypeError;\n}>;\n\nexport type PossibleHTTPError<TErrorData> = UnmaskType<{\n\terrorData: NoInferUnMasked<TErrorData>;\n\tmessage: string;\n\tname: \"HTTPError\";\n\toriginalError: HTTPError;\n}>;\n\nexport type PossibleValidationError = UnmaskType<{\n\terrorData: ValidationError[\"errorData\"];\n\tissueCause: ValidationError[\"issueCause\"];\n\tmessage: string;\n\tname: \"ValidationError\";\n\toriginalError: ValidationError;\n}>;\n\nexport type CallApiResultErrorVariant<TErrorData> =\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleHTTPError<TErrorData>;\n\t\t\tresponse: Response;\n\t }\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleJavaScriptError;\n\t\t\tresponse: Response | null;\n\t }\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleValidationError;\n\t\t\tresponse: Response | null;\n\t };\n\nexport type CallApiResultSuccessOrErrorVariant<TData, TError> =\n\t| CallApiResultErrorVariant<TError>\n\t| CallApiResultSuccessVariant<TData>;\n\ntype GetCallApiResult<\n\tTThrowOnError extends ThrowOnErrorBoolean,\n\tTResultWithException extends CallApiResultSuccessVariant<unknown>,\n\tTResultWithoutException extends CallApiResultSuccessOrErrorVariant<unknown, unknown>,\n> = TThrowOnError extends true ? TResultWithException : TResultWithoutException;\n\nexport type ResultModeMap<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError,\n\tTComputedResult extends GetCallApiResult<\n\t\tTThrowOnError,\n\t\tCallApiResultSuccessVariant<TData>,\n\t\tCallApiResultSuccessOrErrorVariant<TData, TErrorData>\n\t> = GetCallApiResult<\n\t\tTThrowOnError,\n\t\tCallApiResultSuccessVariant<TData>,\n\t\tCallApiResultSuccessOrErrorVariant<TData, TErrorData>\n\t>,\n> = UnmaskType<{\n\tall: TComputedResult;\n\tfetchApi: TComputedResult[\"response\"];\n\tonlyData: TComputedResult[\"data\"];\n\tonlyResponse: TComputedResult[\"response\"];\n\twithoutResponse: Prettify<DistributiveOmit<TComputedResult, \"response\">>;\n}>;\n\ntype ResultModePlaceholder = null;\n\ntype ResultModeUnion = keyof ResultModeMap;\n\n// FIXME - Revisit this idea later. Take inspirations from how zod does it with pick({}) and omit({d})\n// type ResultModeObject = { data?: boolean; error?: boolean; response?: boolean };\n\nexport type ResultModeType = ResultModePlaceholder | ResultModeUnion;\n\nexport type InferCallApiResult<\n\tTData,\n\tTErrorData,\n\tTResultMode extends ResultModeType,\n\tTThrowOnError extends ThrowOnErrorBoolean,\n\tTComputedResultModeMapWithException extends ResultModeMap<TData, TErrorData, true> = ResultModeMap<\n\t\tTData,\n\t\tTErrorData,\n\t\ttrue\n\t>,\n\tTComputedResultModeMapWithoutException extends ResultModeMap<TData, TErrorData, TThrowOnError> =\n\t\tResultModeMap<TData, TErrorData, TThrowOnError>,\n> =\n\tTErrorData extends false ? TComputedResultModeMapWithException[\"onlyData\"]\n\t: TErrorData extends false | undefined ? TComputedResultModeMapWithException[\"onlyData\"]\n\t: ResultModePlaceholder extends TResultMode ? TComputedResultModeMapWithoutException[\"all\"]\n\t: TResultMode extends ResultModeUnion ? TComputedResultModeMapWithoutException[TResultMode]\n\t: never;\n\ntype SuccessInfo = Pick<CallApiExtraOptions, \"resultMode\"> & {\n\tresponse: Response;\n};\n\ntype LazyResultModeMap = {\n\t[key in keyof ResultModeMap]: () => ResultModeMap[key];\n};\n\nconst getResultModeMap = (details: ResultModeMap[\"all\"]): LazyResultModeMap => {\n\treturn {\n\t\tall: () => details,\n\t\tfetchApi: () => details.response,\n\t\tonlyData: () => details.data,\n\t\tonlyResponse: () => details.response,\n\t\twithoutResponse: () => omitKeys(details, [\"response\"]),\n\t};\n};\n\ntype SuccessResult = CallApiResultSuccessVariant<unknown> | null;\n\n// The return statement is casted due to a design limitation in ts.\n// LINK - See https://www.zhenghao.io/posts/type-functions for more info\nexport const resolveSuccessResult = (data: unknown, info: SuccessInfo): SuccessResult => {\n\tconst { response, resultMode } = info;\n\n\tconst details = {\n\t\tdata,\n\t\terror: null,\n\t\tresponse,\n\t} satisfies CallApiResultSuccessVariant<unknown>;\n\n\tconst resultModeMap = getResultModeMap(details);\n\n\tconst successResult = resultModeMap[resultMode ?? \"all\"]();\n\n\treturn successResult as SuccessResult;\n};\n\nexport type ErrorInfo = Omit<SuccessInfo, \"response\">\n\t& Pick<CallApiExtraOptions, \"cloneResponse\"> & {\n\t\tmessage?: string;\n\t};\n\nexport type ErrorResult = {\n\terrorDetails: CallApiResultErrorVariant<unknown>;\n\terrorResult: CallApiResultErrorVariant<unknown> | null;\n};\n\nexport const resolveErrorResult = (error: unknown, info: ErrorInfo): ErrorResult => {\n\tconst { cloneResponse, message: customErrorMessage, resultMode } = info;\n\n\tlet errorDetails = {\n\t\tdata: null,\n\t\terror: {\n\t\t\terrorData: false,\n\t\t\tmessage: customErrorMessage ?? (error as Error).message,\n\t\t\tname: (error as Error).name,\n\t\t\toriginalError: error as Error,\n\t\t},\n\t\tresponse: null,\n\t} satisfies CallApiResultErrorVariant<unknown> as CallApiResultErrorVariant<unknown>;\n\n\tif (isValidationErrorInstance(error)) {\n\t\tconst { errorData, message, response } = error;\n\n\t\terrorDetails = {\n\t\t\tdata: null,\n\t\t\terror: {\n\t\t\t\terrorData,\n\t\t\t\tissueCause: error.issueCause,\n\t\t\t\tmessage,\n\t\t\t\tname: \"ValidationError\",\n\t\t\t\toriginalError: error,\n\t\t\t},\n\t\t\tresponse,\n\t\t};\n\t}\n\n\tif (isHTTPErrorInstance<never>(error)) {\n\t\tconst { errorData, message, name, response } = error;\n\n\t\terrorDetails = {\n\t\t\tdata: null,\n\t\t\terror: { errorData, message, name, originalError: error },\n\t\t\tresponse: cloneResponse ? response.clone() : response,\n\t\t};\n\t}\n\n\tconst resultModeMap = getResultModeMap(errorDetails);\n\n\tconst errorResult = resultModeMap[resultMode ?? \"all\"]() as never;\n\n\treturn { errorDetails, errorResult };\n};\n\nexport const getCustomizedErrorResult = (\n\terrorResult: ErrorResult[\"errorResult\"],\n\tcustomErrorInfo: { message: string | undefined }\n): ErrorResult[\"errorResult\"] => {\n\tif (!errorResult) {\n\t\treturn null;\n\t}\n\n\tconst { message = errorResult.error.message } = customErrorInfo;\n\n\treturn {\n\t\t...errorResult,\n\t\terror: {\n\t\t\t...errorResult.error,\n\t\t\tmessage,\n\t\t} satisfies NonNullable<ErrorResult[\"errorResult\"]>[\"error\"] as never,\n\t};\n};\n","import type { RefetchFnOption } from \"./refetch\";\nimport {\n\tresolveErrorResult,\n\ttype CallApiResultErrorVariant,\n\ttype CallApiResultSuccessVariant,\n\ttype ErrorInfo,\n\ttype PossibleHTTPError,\n\ttype PossibleJavaScriptError,\n\ttype PossibleValidationError,\n} from \"./result\";\nimport type { StreamProgressEvent } from \"./stream\";\nimport type {\n\tBaseCallApiConfig,\n\tCallApiConfig,\n\tCallApiContext,\n\tCallApiExtraOptions,\n\tCallApiRequestOptions,\n} from \"./types/common\";\nimport type { DefaultCallApiContext } from \"./types/default-types\";\nimport type {\n\tAnyFunction,\n\tAwaitable,\n\tCommonRequestHeaders,\n\tDistributiveOmit,\n\tPrettify,\n} from \"./types/type-helpers\";\n\nexport type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, \"headers\"> & {\n\theaders: Partial<Record<\"Authorization\" | \"Content-Type\" | CommonRequestHeaders, string>>;\n};\n\nexport type CallApiExtraOptionsForHooks<TCallApiContext extends CallApiContext = DefaultCallApiContext> =\n\tHooks & Omit<CallApiExtraOptions<TCallApiContext>, keyof Hooks> & RefetchFnOption;\n\nexport interface Hooks<TCallApiContext extends CallApiContext = DefaultCallApiContext> {\n\t/**\n\t * Hook called when any error occurs within the request/response lifecycle.\n\t *\n\t * This is a unified error handler that catches both request errors (network failures,\n\t * timeouts, etc.) and response errors (HTTP error status codes). It's essentially\n\t * a combination of `onRequestError` and `onResponseError` hooks.\n\t *\n\t * @param context - Error context containing error details, request info, and response (if available)\n\t * @returns Promise or void - Hook can be async or sync\n\t */\n\tonError?: (context: ErrorContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called before the HTTP request is sent and before any internal processing of the request object begins.\n\t *\n\t * This is the ideal place to modify request headers, add authentication,\n\t * implement request logging, or perform any setup before the network call.\n\t *\n\t * @param context - Request context with mutable request object and configuration\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonRequest?: (context: RequestContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when an error occurs during the fetch request itself.\n\t *\n\t * This handles network-level errors like connection failures, timeouts,\n\t * DNS resolution errors, or other issues that prevent getting an HTTP response.\n\t * Note that HTTP error status codes (4xx, 5xx) are handled by `onResponseError`.\n\t *\n\t * @param context - Request error context with error details and null response\n\t * @returns Promise or void - Hook can be async or sync\n\t */\n\tonRequestError?: (context: RequestErrorContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called just before the HTTP request is sent and after the request has been processed.\n\t *\n\t * @param context - Request context with mutable request object and configuration\n\t */\n\tonRequestReady?: (context: RequestContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called during upload stream progress tracking.\n\t *\n\t * This hook is triggered when uploading data (like file uploads) and provides\n\t * progress information about the upload. Useful for implementing progress bars\n\t * or upload status indicators.\n\t *\n\t * @param context - Request stream context with progress event and request instance\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonRequestStream?: (context: RequestStreamContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when any HTTP response is received from the API.\n\t *\n\t * This hook is triggered for both successful (2xx) and error (4xx, 5xx) responses.\n\t * It's useful for response logging, metrics collection, or any processing that\n\t * should happen regardless of response status.\n\t *\n\t * @param context - Response context with either success data or error information\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonResponse?: (context: ResponseContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when an HTTP error response (4xx, 5xx) is received from the API.\n\t *\n\t * This handles server-side errors where an HTTP response was successfully received\n\t * but indicates an error condition. Different from `onRequestError` which handles\n\t * network-level failures.\n\t *\n\t * @param context - Response error context with HTTP error details and response\n\t * @returns Promise or void - Hook can be async or sync\n\t */\n\tonResponseError?: (context: ResponseErrorContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called during download stream progress tracking.\n\t *\n\t * This hook is triggered when downloading data (like file downloads) and provides\n\t * progress information about the download. Useful for implementing progress bars\n\t * or download status indicators.\n\t *\n\t * @param context - Response stream context with progress event and response\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonResponseStream?: (context: ResponseStreamContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when a request is being retried.\n\t *\n\t * This hook is triggered before each retry attempt, providing information about\n\t * the previous failure and the current retry attempt number. Useful for implementing\n\t * custom retry logic, exponential backoff, or retry logging.\n\t *\n\t * @param context - Retry context with error details and retry attempt count\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonRetry?: (context: RetryContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when a successful response (2xx status) is received from the API.\n\t *\n\t * This hook is triggered only for successful responses and provides access to\n\t * the parsed response data. Ideal for success logging, caching, or post-processing\n\t * of successful API responses.\n\t *\n\t * @param context - Success context with parsed response data and response object\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonSuccess?: (context: SuccessContext<TCallApiContext>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called when a validation error occurs.\n\t *\n\t * This hook is triggered when request or response data fails validation against\n\t * a defined schema. It provides access to the validation error details and can\n\t * be used for custom error handling, logging, or fallback behavior.\n\t *\n\t * @param context - Validation error context with error details and response (if available)\n\t * @returns Promise or void - Hook can be async or sync\n\t *\n\t */\n\tonValidationError?: (context: ValidationErrorContext<TCallApiContext>) => Awaitable<unknown>;\n}\n\nexport type HooksOrHooksArray<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> = {\n\t[Key in keyof Hooks<TCallApiContext>]:\n\t\t| Hooks<TCallApiContext>[Key]\n\t\t// eslint-disable-next-line perfectionist/sort-union-types -- I need arrays to be last\n\t\t| Array<Hooks<TCallApiContext>[Key]>;\n};\n\nexport interface HookConfigOptions {\n\t/**\n\t * Controls the execution mode of all composed hooks (main + plugin hooks).\n\t *\n\t * - **\"parallel\"**: All hooks execute simultaneously via Promise.all() for better performance\n\t * - **\"sequential\"**: All hooks execute one by one in registration order via await in a loop\n\t *\n\t * This affects how ALL hooks execute together, regardless of their source (main or plugin).\n\t *\n\t * @default \"parallel\"\n\t */\n\thooksExecutionMode?: \"parallel\" | \"sequential\";\n}\n\nexport type RequestContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = {\n\t/**\n\t * Base configuration object passed to createFetchClient.\n\t *\n\t * Contains the foundational configuration that applies to all requests\n\t * made by this client instance, such as baseURL, default headers, and\n\t * global options.\n\t */\n\tbaseConfig: Exclude<BaseCallApiConfig, AnyFunction>;\n\n\t/**\n\t * Instance-specific configuration object passed to the callApi instance.\n\t *\n\t * Contains configuration specific to this particular API call, which\n\t * can override or extend the base configuration.\n\t */\n\tconfig: CallApiConfig;\n\n\t/**\n\t * Merged options combining base config, instance config, and default options.\n\t *\n\t * This is the final resolved configuration that will be used for the request,\n\t * with proper precedence applied (instance > base > defaults).\n\t */\n\toptions: CallApiExtraOptionsForHooks<TCallApiContext>;\n\n\t/**\n\t * Merged request object ready to be sent.\n\t *\n\t * Contains the final request configuration including URL, method, headers,\n\t * body, and other fetch options. This object can be modified in onRequest\n\t * hooks to customize the outgoing request.\n\t */\n\trequest: CallApiRequestOptionsForHooks;\n};\n\nexport type SuccessContext<\n\tTCallApiContext extends Pick<CallApiContext, \"Data\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = DistributiveOmit<CallApiResultSuccessVariant<TCallApiContext[\"Data\"]>, \"error\">\n\t& RequestContext<TCallApiContext>;\n\nexport type ResponseContext<\n\tTCallApiContext extends Pick<CallApiContext, \"Data\" | \"ErrorData\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = RequestContext<TCallApiContext>\n\t& (\n\t\t| Prettify<CallApiResultSuccessVariant<TCallApiContext[\"Data\"]>>\n\t\t| Prettify<\n\t\t\t\tExtract<\n\t\t\t\t\tCallApiResultErrorVariant<TCallApiContext[\"ErrorData\"]>,\n\t\t\t\t\t{ error: PossibleHTTPError<TCallApiContext[\"ErrorData\"]> }\n\t\t\t\t>\n\t\t >\n\t);\n\nexport type RequestStreamContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = RequestContext<TCallApiContext> & {\n\tevent: StreamProgressEvent;\n\trequestInstance: Request;\n};\n\nexport type ResponseStreamContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = RequestContext<TCallApiContext> & {\n\tevent: StreamProgressEvent;\n\tresponse: Response;\n};\n\nexport type ErrorContext<\n\tTCallApiContext extends Pick<CallApiContext, \"ErrorData\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = DistributiveOmit<CallApiResultErrorVariant<TCallApiContext[\"ErrorData\"]>, \"data\">\n\t& RequestContext<TCallApiContext>;\n\nexport type ValidationErrorContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = Extract<ErrorContext<TCallApiContext>, { error: PossibleValidationError }>\n\t& RequestContext<TCallApiContext>;\n\nexport type RequestErrorContext<\n\tTCallApiContext extends Pick<CallApiContext, \"InferredExtraOptions\" | \"Meta\"> = DefaultCallApiContext,\n> = Extract<ErrorContext<TCallApiContext>, { error: PossibleJavaScriptError }>\n\t& RequestContext<TCallApiContext>;\n\nexport type ResponseErrorContext<\n\tTCallApiContext extends Pick<CallApiContext, \"ErrorData\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = Extract<ErrorContext<TCallApiContext>, { error: PossibleHTTPError<TCallApiContext[\"ErrorData\"]> }>\n\t& RequestContext<TCallApiContext>;\n\nexport type RetryContext<\n\tTCallApiContext extends Pick<CallApiContext, \"ErrorData\" | \"InferredExtraOptions\" | \"Meta\"> =\n\t\tDefaultCallApiContext,\n> = ErrorContext<TCallApiContext> & {\n\tretryAttemptCount: number;\n};\n\ntype HookRegistries = Required<{\n\t[Key in keyof Hooks]: Set<Hooks[Key]>;\n}>;\n\nexport const getHookRegistriesAndKeys = () => {\n\tconst hookRegistries: HookRegistries = {\n\t\tonError: new Set(),\n\t\tonRequest: new Set(),\n\t\tonRequestError: new Set(),\n\t\tonRequestReady: new Set(),\n\t\tonRequestStream: new Set(),\n\t\tonResponse: new Set(),\n\t\tonResponseError: new Set(),\n\t\tonResponseStream: new Set(),\n\t\tonRetry: new Set(),\n\t\tonSuccess: new Set(),\n\t\tonValidationError: new Set(),\n\t};\n\n\tconst hookRegistryKeys = Object.keys(hookRegistries) as Array<keyof Hooks>;\n\n\treturn { hookRegistries, hookRegistryKeys };\n};\n\nexport const composeHooksFromArray = (\n\thooksArray: Array<Hooks[keyof Hooks] | undefined>,\n\thooksExecutionMode: NonNullable<CallApiExtraOptionsForHooks[\"hooksExecutionMode\"]>\n) => {\n\tconst composedHook = async (ctx: unknown) => {\n\t\tswitch (hooksExecutionMode) {\n\t\t\tcase \"parallel\": {\n\t\t\t\tawait Promise.all(hooksArray.map((hook) => hook?.(ctx as never)));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"sequential\": {\n\t\t\t\tfor (const hook of hooksArray) {\n\t\t\t\t\t// eslint-disable-next-line no-await-in-loop -- This is necessary in this case\n\t\t\t\t\tawait hook?.(ctx as never);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\thooksExecutionMode satisfies never;\n\t\t\t}\n\t\t}\n\t};\n\n\treturn composedHook;\n};\n\nexport const executeHooks = async (...hookResultsOrPromise: Array<Awaitable<unknown>>) => {\n\tawait Promise.all(hookResultsOrPromise);\n};\n\nexport type ExecuteHookInfo = {\n\terrorInfo: ErrorInfo;\n\tshouldThrowOnError: boolean | undefined;\n};\n\nexport const executeHooksInCatchBlock = async (\n\thookResultsOrPromise: Array<Awaitable<unknown>>,\n\thookInfo: ExecuteHookInfo\n) => {\n\tconst { errorInfo, shouldThrowOnError } = hookInfo;\n\n\ttry {\n\t\tawait Promise.all(hookResultsOrPromise);\n\n\t\treturn null;\n\t} catch (hookError) {\n\t\tif (shouldThrowOnError) {\n\t\t\tthrow hookError;\n\t\t}\n\n\t\tconst { errorResult } = resolveErrorResult(hookError, errorInfo);\n\n\t\treturn errorResult;\n\t}\n};\n","import {\n\texecuteHooks,\n\ttype RequestContext,\n\ttype RequestStreamContext,\n\ttype ResponseStreamContext,\n} from \"./hooks\";\nimport { isReadableStream } from \"./utils/guards\";\n\nexport type StreamProgressEvent = {\n\t/**\n\t * Current chunk of data being streamed\n\t */\n\tchunk: Uint8Array;\n\t/**\n\t * Progress in percentage\n\t */\n\tprogress: number;\n\t/**\n\t * Total size of data in bytes\n\t */\n\ttotalBytes: number;\n\t/**\n\t * Amount of data transferred so far\n\t */\n\ttransferredBytes: number;\n};\n\nconst createProgressEvent = (options: {\n\tchunk: Uint8Array;\n\ttotalBytes: number;\n\ttransferredBytes: number;\n}): StreamProgressEvent => {\n\tconst { chunk, totalBytes, transferredBytes } = options;\n\n\treturn {\n\t\tchunk,\n\t\tprogress: Math.round((transferredBytes / totalBytes) * 100) || 0,\n\t\ttotalBytes,\n\t\ttransferredBytes,\n\t};\n};\n\nconst calculateTotalBytesFromBody = async (\n\trequestBody: Request[\"body\"] | null,\n\texistingTotalBytes: number\n) => {\n\tlet totalBytes = existingTotalBytes;\n\n\tif (!requestBody) {\n\t\treturn totalBytes;\n\t}\n\n\tfor await (const chunk of requestBody) {\n\t\ttotalBytes += chunk.byteLength;\n\t}\n\n\treturn totalBytes;\n};\n\ntype ToStreamableRequestContext = RequestContext;\n\nexport const toStreamableRequest = async (\n\tcontext: ToStreamableRequestContext\n): Promise<Request | RequestInit> => {\n\tconst { baseConfig, config, options, request } = context;\n\n\tif (!options.onRequestStream || !isReadableStream(request.body)) {\n\t\treturn request as RequestInit;\n\t}\n\n\tconst requestInstance = new Request(\n\t\toptions.fullURL as NonNullable<typeof options.fullURL>,\n\t\t{ ...request, duplex: \"half\" } as RequestInit\n\t);\n\n\tconst contentLength = requestInstance.headers.get(\"content-length\");\n\n\tlet totalBytes = Number(contentLength ?? 0);\n\n\t// == If no content length is present, we read the total bytes from the body\n\tif (!contentLength && options.forcefullyCalculateRequestStreamSize) {\n\t\ttotalBytes = await calculateTotalBytesFromBody(requestInstance.clone().body, totalBytes);\n\t}\n\n\tlet transferredBytes = 0;\n\n\tconst stream = new ReadableStream({\n\t\tstart: async (controller) => {\n\t\t\tconst body = requestInstance.body;\n\n\t\t\tif (!body) return;\n\n\t\t\tconst requestStreamContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tevent: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\trequestInstance,\n\t\t\t} satisfies RequestStreamContext;\n\n\t\t\tawait executeHooks(options.onRequestStream?.(requestStreamContext));\n\n\t\t\tfor await (const chunk of body) {\n\t\t\t\ttransferredBytes += chunk.byteLength;\n\n\t\t\t\ttotalBytes = Math.max(totalBytes, transferredBytes);\n\n\t\t\t\tawait executeHooks(\n\t\t\t\t\toptions.onRequestStream?.({\n\t\t\t\t\t\t...requestStreamContext,\n\t\t\t\t\t\tevent: createProgressEvent({ chunk, totalBytes, transferredBytes }),\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t}\n\n\t\t\tcontroller.close();\n\t\t},\n\t});\n\n\treturn new Request(requestInstance, { body: stream, duplex: \"half\" } as RequestInit);\n};\n\ntype StreamableResponseContext = RequestContext & { response: Response };\n\nexport const toStreamableResponse = (context: StreamableResponseContext): Response => {\n\tconst { baseConfig, config, options, request, response } = context;\n\n\tif (!options.onResponseStream || !response.body) {\n\t\treturn response;\n\t}\n\n\tconst contentLength = response.headers.get(\"content-length\");\n\n\tlet totalBytes = Number(contentLength ?? 0);\n\n\tlet transferredBytes = 0;\n\n\tconst stream = new ReadableStream({\n\t\tstart: async (controller) => {\n\t\t\tconst body = response.body;\n\n\t\t\tif (!body) return;\n\n\t\t\tconst responseStreamContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tevent: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse,\n\t\t\t} satisfies ResponseStreamContext;\n\n\t\t\tawait executeHooks(options.onResponseStream?.(responseStreamContext));\n\n\t\t\tfor await (const chunk of body) {\n\t\t\t\ttransferredBytes += chunk.byteLength;\n\n\t\t\t\ttotalBytes = Math.max(totalBytes, transferredBytes);\n\n\t\t\t\tawait executeHooks(\n\t\t\t\t\toptions.onResponseStream?.({\n\t\t\t\t\t\t...responseStreamContext,\n\t\t\t\t\t\tevent: createProgressEvent({ chunk, totalBytes, transferredBytes }),\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t}\n\n\t\t\tcontroller.close();\n\t\t},\n\t});\n\n\treturn new Response(stream, response);\n};\n","import { extraOptionDefaults } from \"./constants/defaults\";\nimport type { RequestContext } from \"./hooks\";\nimport { toStreamableRequest, toStreamableResponse } from \"./stream\";\nimport type { AnyString, Awaitable, UnmaskType } from \"./types/type-helpers\";\nimport { waitFor } from \"./utils/common\";\nimport { isFunction } from \"./utils/guards\";\n\ntype RequestInfo = {\n\tcontroller: AbortController;\n\tresponsePromise: Awaitable<Response>;\n};\n\n/**\n * Cache that stores active request information for deduplication within a specific scope.\n *\n * Maps deduplication keys to their corresponding request information, including the abort controller\n * and response promise. A `null` key represents requests that don't participate in deduplication.\n *\n * **Internal Usage:**\n * This type is primarily used internally by the deduplication system. You typically won't need to\n * interact with it directly unless you're building custom deduplication logic or debugging.\n *\n * @example\n * ```ts\n * // This is handled internally, but conceptually:\n * const cache: RequestInfoCache = new Map([\n * [\"user-123\", { controller: abortController, responsePromise: fetchPromise }],\n * [\"config\", { controller: abortController2, responsePromise: fetchPromise2 }],\n * ]);\n * ```\n */\nexport type RequestInfoCache = Map<string | null, RequestInfo>;\n\n/**\n * Global cache that manages multiple request info caches, organized by scope keys.\n *\n * This enables the global deduplication feature by maintaining separate cache namespaces\n * for different scope keys. Each scope key gets its own `RequestInfoCache` instance.\n *\n * **Cache Lifecycle:**\n * - Caches are created on-demand when first accessed\n * - Automatic cleanup occurs when no references remain\n * - Each scope key maintains independent deduplication state\n *\n * **Memory Considerations:**\n * - Each scope key creates a separate cache instance\n * - Consider the number of different scope keys in your application\n * - Caches are cleaned up automatically when clients are garbage collected\n *\n * @example\n * ```ts\n * // This is managed internally, but conceptually:\n * const globalCache: GlobalRequestInfoCache = new Map([\n * [\"user-service\", new Map([...])], // Cache for user service requests\n * [\"analytics\", new Map([...])], // Cache for analytics requests\n * [\"default\", new Map([...])] // Default cache scope\n * ]);\n * ```\n */\nexport type GlobalRequestInfoCache = Map<DedupeOptions[\"dedupeCacheScopeKey\"], RequestInfoCache>;\n\ntype DedupeContext = RequestContext & {\n\t$GlobalRequestInfoCache: GlobalRequestInfoCache;\n\t$LocalRequestInfoCache: RequestInfoCache;\n\tnewFetchController: AbortController;\n};\n\nexport const createDedupeStrategy = async (context: DedupeContext) => {\n\tconst {\n\t\t$GlobalRequestInfoCache,\n\t\t$LocalRequestInfoCache,\n\t\tbaseConfig,\n\t\tconfig,\n\t\tnewFetchController,\n\t\toptions: globalOptions,\n\t} = context;\n\n\tconst dedupeStrategy = globalOptions.dedupeStrategy ?? extraOptionDefaults.dedupeStrategy;\n\n\tconst resolvedDedupeStrategy = isFunction(dedupeStrategy) ? dedupeStrategy(context) : dedupeStrategy;\n\n\tconst getDedupeKey = () => {\n\t\tconst shouldHaveDedupeKey =\n\t\t\tresolvedDedupeStrategy === \"cancel\" || resolvedDedupeStrategy === \"defer\";\n\n\t\tif (!shouldHaveDedupeKey) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst dedupeKey = globalOptions.dedupeKey ?? extraOptionDefaults.dedupeKey;\n\n\t\tconst resolvedDedupeKey = isFunction(dedupeKey) ? dedupeKey(context) : dedupeKey;\n\n\t\treturn resolvedDedupeKey;\n\t};\n\n\tconst getDedupeCacheScopeKey = () => {\n\t\tconst dedupeCacheScopeKey =\n\t\t\tglobalOptions.dedupeCacheScopeKey ?? extraOptionDefaults.dedupeCacheScopeKey;\n\n\t\tconst resolvedDedupeCacheScopeKey =\n\t\t\tisFunction(dedupeCacheScopeKey) ? dedupeCacheScopeKey(context) : dedupeCacheScopeKey;\n\n\t\treturn resolvedDedupeCacheScopeKey;\n\t};\n\n\tconst dedupeKey = getDedupeKey();\n\n\tconst getRequestInfoCache = () => {\n\t\tif (!dedupeKey) return;\n\n\t\tconst dedupeCacheScope = globalOptions.dedupeCacheScope ?? extraOptionDefaults.dedupeCacheScope;\n\n\t\tconst dedupeCacheScopeKey = getDedupeCacheScopeKey();\n\n\t\tconst $RequestInfoCache =\n\t\t\tdedupeCacheScope === \"global\" ?\n\t\t\t\t($GlobalRequestInfoCache.get(dedupeCacheScopeKey)\n\t\t\t\t?? $GlobalRequestInfoCache.set(dedupeCacheScopeKey, new Map()).get(dedupeCacheScopeKey))\n\t\t\t:\t$LocalRequestInfoCache;\n\n\t\treturn {\n\t\t\tdelete: () => $RequestInfoCache?.delete(dedupeKey),\n\t\t\tget: () => $RequestInfoCache?.get(dedupeKey),\n\t\t\tset: (value: RequestInfo) => $RequestInfoCache?.set(dedupeKey, value),\n\t\t};\n\t};\n\n\tconst $RequestInfoCache = getRequestInfoCache();\n\n\t/**\n\t * Force sequential execution of parallel requests to enable proper cache-based deduplication.\n\t *\n\t * Problem: When Promise.all([callApi(url), callApi(url)]) executes, both requests\n\t * start synchronously and reach this point before either can populate the cache.\n\t *\n\t * Why `await Promise.resolve()` fails:\n\t * - All microtasks in a batch resolve together at the next microtask checkpoint\n\t * - Both requests resume execution simultaneously after the await\n\t * - Both check `prevRequestInfo` at the same time → both see empty cache\n\t * - Both proceed to populate cache → deduplication fails\n\t *\n\t * Why `wait new Promise(()=> setTimeout(resolve, number))` works:\n\t * - Each setTimeout creates a separate task in the task queue\n\t * - Tasks execute sequentially, not simultaneously\n\t * - Request 1's task runs first: checks cache (empty) → continues → populates cache\n\t * - Request 2's task runs after: checks cache (populated) → uses cached promise\n\t * - Deduplication succeeds\n\t *\n\t * IMPORTANT: The delay must be non-zero. setTimeout(fn, 0) fails because JavaScript engines\n\t * may optimize zero-delay timers by batching them together, causing all requests to resume\n\t * simultaneously (same problem as microtasks). Any non-zero value (even 0.0000000001) forces\n\t * proper sequential task queue scheduling, ensuring each request gets its own task slot.\n\t */\n\tif (dedupeKey !== null) {\n\t\tawait waitFor(0.01);\n\t}\n\n\tconst prevRequestInfo = $RequestInfoCache?.get();\n\n\tconst getAbortErrorMessage = () => {\n\t\tif (globalOptions.dedupeKey) {\n\t\t\treturn `Duplicate request detected - Aborted previous request with key '${dedupeKey}'`;\n\t\t}\n\n\t\treturn `Duplicate request detected - Aborted previous request to '${globalOptions.fullURL}'`;\n\t};\n\n\tconst handleRequestCancelStrategy = () => {\n\t\tconst shouldCancelRequest = prevRequestInfo && resolvedDedupeStrategy === \"cancel\";\n\n\t\tif (!shouldCancelRequest) return;\n\n\t\tconst message = getAbortErrorMessage();\n\n\t\tconst reason = new DOMException(message, \"AbortError\");\n\n\t\tprevRequestInfo.controller.abort(reason);\n\t};\n\n\tconst handleRequestDeferStrategy = async (deferContext: {\n\t\tfetchApi: NonNullable<DedupeContext[\"options\"][\"customFetchImpl\"]>;\n\t\toptions: DedupeContext[\"options\"];\n\t\trequest: DedupeContext[\"request\"];\n\t}) => {\n\t\t// == Local options and request are needed so that transformations are applied can be applied to both from call site\n\t\tconst { fetchApi, options: localOptions, request: localRequest } = deferContext;\n\n\t\tconst shouldUsePromiseFromCache = prevRequestInfo && resolvedDedupeStrategy === \"defer\";\n\n\t\tconst streamableContext = {\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\toptions: localOptions,\n\t\t\trequest: localRequest,\n\t\t} satisfies RequestContext;\n\n\t\tconst streamableRequest = await toStreamableRequest(streamableContext);\n\n\t\tconst responsePromise =\n\t\t\tshouldUsePromiseFromCache ?\n\t\t\t\tprevRequestInfo.responsePromise\n\t\t\t:\tfetchApi(localOptions.fullURL as NonNullable<typeof localOptions.fullURL>, streamableRequest);\n\n\t\t$RequestInfoCache?.set({ controller: newFetchController, responsePromise });\n\n\t\treturn toStreamableResponse({ ...streamableContext, response: await responsePromise });\n\t};\n\n\tconst removeDedupeKeyFromCache = () => {\n\t\t$RequestInfoCache?.delete();\n\t};\n\n\treturn {\n\t\tgetAbortErrorMessage,\n\t\thandleRequestCancelStrategy,\n\t\thandleRequestDeferStrategy,\n\t\tremoveDedupeKeyFromCache,\n\t\tresolvedDedupeStrategy,\n\t};\n};\n\ntype DedupeStrategyUnion = UnmaskType<\"cancel\" | \"defer\" | \"none\">;\n\nexport type DedupeOptions = {\n\t/**\n\t * Controls the scope of request deduplication caching.\n\t *\n\t * - `\"global\"`: Shares deduplication cache across all `createFetchClient` instances with the same `dedupeCacheScopeKey`.\n\t * Useful for applications with multiple API clients that should share deduplication state.\n\t * - `\"local\"`: Limits deduplication to requests within the same `createFetchClient` instance.\n\t * Provides better isolation and is recommended for most use cases.\n\t *\n\t *\n\t * **Real-world Scenarios:**\n\t * - Use `\"global\"` when you have multiple API clients (user service, auth service, etc.) that might make overlapping requests\n\t * - Use `\"local\"` (default) for single-purpose clients or when you want strict isolation between different parts of your app\n\t *\n\t * @example\n\t * ```ts\n\t * // Local scope - each client has its own deduplication cache\n\t * const userClient = createFetchClient({ baseURL: \"/api/users\" });\n\t * const postClient = createFetchClient({ baseURL: \"/api/posts\" });\n\t * // These clients won't share deduplication state\n\t *\n\t * // Global scope - share cache across related clients\n\t * const userClient = createFetchClient({\n\t * baseURL: \"/api/users\",\n\t * dedupeCacheScope: \"global\",\n\t * });\n\t * const postClient = createFetchClient({\n\t * baseURL: \"/api/posts\",\n\t * dedupeCacheScope: \"global\",\n\t * });\n\t * // These clients will share deduplication state\n\t * ```\n\t *\n\t * @default \"local\"\n\t */\n\tdedupeCacheScope?: \"global\" | \"local\";\n\n\t/**\n\t * Unique namespace for the global deduplication cache when using `dedupeCacheScope: \"global\"`.\n\t *\n\t * This creates logical groupings of deduplication caches. All instances with the same key\n\t * will share the same cache namespace, allowing fine-grained control over which clients\n\t * share deduplication state.\n\t *\n\t * **Best Practices:**\n\t * - Use descriptive names that reflect the logical grouping (e.g., \"user-service\", \"analytics-api\")\n\t * - Keep scope keys consistent across related API clients\n\t * - Consider using different scope keys for different environments (dev, staging, prod)\n\t * - Avoid overly broad scope keys that might cause unintended cache sharing\n\t *\n\t * **Cache Management:**\n\t * - Each scope key maintains its own independent cache\n\t * - Caches are automatically cleaned up when no references remain\n\t * - Consider the memory implications of multiple global scopes\n\t *\n\t * @example\n\t * ```ts\n\t * // Group related API clients together\n\t * const userClient = createFetchClient({\n\t * baseURL: \"/api/users\",\n\t * dedupeCacheScope: \"global\",\n\t * dedupeCacheScopeKey: \"user-service\"\n\t * });\n\t * const profileClient = createFetchClient({\n\t * baseURL: \"/api/profiles\",\n\t * dedupeCacheScope: \"global\",\n\t * dedupeCacheScopeKey: \"user-service\" // Same scope - will share cache\n\t * });\n\t *\n\t * // Separate analytics client with its own cache\n\t * const analyticsClient = createFetchClient({\n\t * baseURL: \"/api/analytics\",\n\t * dedupeCacheScope: \"global\",\n\t * dedupeCacheScopeKey: \"analytics-service\" // Different scope\n\t * });\n\t *\n\t * // Environment-specific scoping\n\t * const apiClient = createFetchClient({\n\t * dedupeCacheScope: \"global\",\n\t * dedupeCacheScopeKey: `api-${process.env.NODE_ENV}` // \"api-development\", \"api-production\", etc.\n\t * });\n\t * ```\n\t *\n\t * @default \"default\"\n\t */\n\tdedupeCacheScopeKey?: \"default\" | AnyString | ((context: RequestContext) => string | undefined);\n\n\t/**\n\t * Custom key generator for request deduplication.\n\t *\n\t * Override the default key generation strategy to control exactly which requests\n\t * are considered duplicates. The default key combines URL, method, body, and\n\t * relevant headers (excluding volatile ones like 'Date', 'Authorization', etc.).\n\t *\n\t * **Default Key Generation:**\n\t * The auto-generated key includes:\n\t * - Full request URL (including query parameters)\n\t * - HTTP method (GET, POST, etc.)\n\t * - Request body (for POST/PUT/PATCH requests)\n\t * - Stable headers (excludes Date, Authorization, User-Agent, etc.)\n\t *\n\t * **Custom Key Best Practices:**\n\t * - Include only the parts of the request that should affect deduplication\n\t * - Avoid including volatile data (timestamps, random IDs, etc.)\n\t * - Consider performance - simpler keys are faster to compute and compare\n\t * - Ensure keys are deterministic for the same logical request\n\t * - Use consistent key formats across your application\n\t *\n\t * **Performance Considerations:**\n\t * - Function-based keys are computed on every request - keep them lightweight\n\t * - String keys are fastest but least flexible\n\t * - Consider caching expensive key computations if needed\n\t *\n\t * @example\n\t * ```ts\n\t * import { callApi } from \"@zayne-labs/callapi\";\n\t *\n\t * // Simple static key - useful for singleton requests\n\t * const config = callApi(\"/api/config\", {\n\t * dedupeKey: \"app-config\",\n\t * dedupeStrategy: \"defer\" // Share the same config across all requests\n\t * });\n\t *\n\t * // URL and method only - ignore headers and body\n\t * const userData = callApi(\"/api/user/123\", {\n\t * dedupeKey: (context) => `${context.options.method}:${context.options.fullURL}`\n\t * });\n\t *\n\t * // Include specific headers in deduplication\n\t * const apiCall = callApi(\"/api/data\", {\n\t * dedupeKey: (context) => {\n\t * const authHeader = context.request.headers.get(\"Authorization\");\n\t * return `${context.options.fullURL}-${authHeader}`;\n\t * }\n\t * });\n\t *\n\t * // User-specific deduplication\n\t * const userSpecificCall = callApi(\"/api/dashboard\", {\n\t * dedupeKey: (context) => {\n\t * const userId = context.options.fullURL.match(/user\\/(\\d+)/)?.[1];\n\t * return `dashboard-${userId}`;\n\t * }\n\t * });\n\t *\n\t * // Ignore certain query parameters\n\t * const searchCall = callApi(\"/api/search?q=test&timestamp=123456\", {\n\t * dedupeKey: (context) => {\n\t * const url = new URL(context.options.fullURL);\n\t * url.searchParams.delete(\"timestamp\"); // Remove volatile param\n\t * return `search:${url.toString()}`;\n\t * }\n\t * });\n\t * ```\n\t *\n\t * @default Auto-generated from request details\n\t */\n\tdedupeKey?: string | ((context: RequestContext) => string | undefined);\n\n\t/**\n\t * Strategy for handling duplicate requests. Can be a static string or callback function.\n\t *\n\t * **Available Strategies:**\n\t * - `\"cancel\"`: Cancel previous request when new one starts (good for search)\n\t * - `\"defer\"`: Share response between duplicate requests (good for config loading)\n\t * - `\"none\"`: No deduplication, all requests execute independently\n\t *\n\t * @example\n\t * ```ts\n\t * // Static strategies\n\t * const searchClient = createFetchClient({\n\t * dedupeStrategy: \"cancel\" // Cancel previous searches\n\t * });\n\t *\n\t * const configClient = createFetchClient({\n\t * dedupeStrategy: \"defer\" // Share config across components\n\t * });\n\t *\n\t * // Dynamic strategy based on request\n\t * const smartClient = createFetchClient({\n\t * dedupeStrategy: (context) => {\n\t * return context.options.method === \"GET\" ? \"defer\" : \"cancel\";\n\t * }\n\t * });\n\t *\n\t * // Search-as-you-type with cancel strategy\n\t * const handleSearch = async (query: string) => {\n\t * try {\n\t * const { data } = await callApi(\"/api/search\", {\n\t * method: \"POST\",\n\t * body: { query },\n\t * dedupeStrategy: \"cancel\",\n\t * dedupeKey: \"search\" // Cancel previous searches, only latest one goes through\n\t * });\n\t *\n\t * updateSearchResults(data);\n\t * } catch (error) {\n\t * if (error.name === \"AbortError\") {\n\t * // Previous search cancelled - (expected behavior)\n\t * return;\n\t * }\n\t * console.error(\"Search failed:\", error);\n\t * }\n\t * };\n\t *\n\t * ```\n\t *\n\t * @default \"cancel\"\n\t */\n\tdedupeStrategy?: DedupeStrategyUnion | ((context: RequestContext) => DedupeStrategyUnion);\n};\n","import type { RequestContext } from \"./hooks\";\nimport type { CallApiContext } from \"./types/common\";\nimport type { DefaultCallApiContext } from \"./types/default-types\";\nimport type { Awaitable, UnmaskType } from \"./types/type-helpers\";\n\nexport type FetchImpl = UnmaskType<\n\t(input: string | Request | URL, init?: RequestInit) => Awaitable<Response>\n>;\n\nexport type FetchMiddlewareContext<TCallApiContext extends CallApiContext> =\n\tRequestContext<TCallApiContext> & {\n\t\tfetchImpl: FetchImpl;\n\t};\n\nexport interface Middlewares<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> {\n\t/**\n\t * Wraps the fetch implementation to intercept requests at the network layer.\n\t *\n\t * Takes a context object containing the current fetch function and returns a new fetch function.\n\t * Use it to cache responses, add logging, handle offline mode, or short-circuit requests etc.\n\t * Multiple middleware compose in order: plugins → base config → per-request.\n\t *\n\t * Unlike `customFetchImpl`, middleware can call through to the original fetch.\n\t *\n\t * @example\n\t * ```ts\n\t * // Cache responses\n\t * const cache = new Map();\n\t *\n\t * fetchMiddleware: (ctx) => async (input, init) => {\n\t * const key = input.toString();\n\t *\n\t * const cachedResponse = cache.get(key);\n\t *\n\t * if (cachedResponse) {\n\t *\t return cachedResponse.clone();\n\t * }\n\t *\n\t * const response = await ctx.fetchImpl(input, init);\n\t * cache.set(key, response.clone());\n\t *\n\t * return response;\n\t * }\n\t *\n\t * // Handle offline\n\t * fetchMiddleware: (ctx) => async (...parameters) => {\n\t * if (!navigator.onLine) {\n\t * return new Response('{\"error\": \"offline\"}', { status: 503 });\n\t * }\n\t *\n\t * return ctx.fetchImpl(...parameters);\n\t * }\n\t * ```\n\t */\n\tfetchMiddleware?: (context: FetchMiddlewareContext<TCallApiContext>) => FetchImpl;\n}\n\ntype MiddlewareRegistries = Required<{\n\t[Key in keyof Middlewares]: Set<Middlewares[Key]>;\n}>;\n\nexport const getMiddlewareRegistriesAndKeys = () => {\n\tconst middlewareRegistries: MiddlewareRegistries = {\n\t\tfetchMiddleware: new Set(),\n\t};\n\n\tconst middlewareRegistryKeys = Object.keys(middlewareRegistries) as Array<keyof Middlewares>;\n\n\treturn { middlewareRegistries, middlewareRegistryKeys };\n};\n\nexport const composeMiddlewaresFromArray = (\n\tmiddlewareArray: Array<Middlewares[keyof Middlewares] | undefined>\n) => {\n\tlet composedMiddleware: Middlewares[keyof Middlewares];\n\n\tfor (const currentMiddleware of middlewareArray) {\n\t\tif (!currentMiddleware) continue;\n\n\t\tconst previousMiddleware = composedMiddleware;\n\n\t\tif (!previousMiddleware) {\n\t\t\tcomposedMiddleware = currentMiddleware;\n\t\t\tcontinue;\n\t\t}\n\n\t\tcomposedMiddleware = (context) => {\n\t\t\tconst prevFetchImpl = previousMiddleware(context);\n\t\t\tconst fetchImpl = currentMiddleware({ ...context, fetchImpl: prevFetchImpl });\n\n\t\t\treturn fetchImpl;\n\t\t};\n\t}\n\n\treturn composedMiddleware;\n};\n","import { extraOptionDefaults } from \"./constants/defaults\";\nimport {\n\tcomposeHooksFromArray,\n\tgetHookRegistriesAndKeys,\n\ttype Hooks,\n\ttype HooksOrHooksArray,\n\ttype RequestContext,\n} from \"./hooks\";\nimport {\n\tcomposeMiddlewaresFromArray,\n\tgetMiddlewareRegistriesAndKeys,\n\ttype Middlewares,\n} from \"./middlewares\";\nimport type { CallApiContext, CallApiRequestOptions, OverrideCallApiContext } from \"./types/common\";\nimport type { DefaultCallApiContext, DefaultDataType } from \"./types/default-types\";\nimport type { AnyFunction, Awaitable, UnionToIntersection } from \"./types/type-helpers\";\nimport type { InitURLOrURLObject } from \"./url\";\nimport { isArray, isFunction, isString } from \"./utils/guards\";\nimport {\n\tgetCurrentRouteSchemaKeyAndMainInitURL,\n\ttype BaseCallApiSchemaAndConfig,\n\ttype InferSchemaOutput,\n} from \"./validation\";\n\nexport type PluginSetupContext<TCallApiContext extends CallApiContext = DefaultCallApiContext> =\n\tRequestContext<TCallApiContext> & ReturnType<typeof getCurrentRouteSchemaKeyAndMainInitURL>;\n\nexport type PluginInitResult<TCallApiContext extends CallApiContext = DefaultCallApiContext> = Partial<\n\tOmit<PluginSetupContext<TCallApiContext>, \"initURL\" | \"request\"> & {\n\t\tinitURL: InitURLOrURLObject;\n\t\trequest: CallApiRequestOptions;\n\t}\n>;\n\ntype GetDefaultDataTypeForPlugins<TData> = DefaultDataType extends TData ? never : TData;\n\nexport type PluginHooks<TCallApiContext extends CallApiContext = DefaultCallApiContext> =\n\tHooksOrHooksArray<\n\t\tOverrideCallApiContext<\n\t\t\tTCallApiContext,\n\t\t\t{\n\t\t\t\tData: GetDefaultDataTypeForPlugins<TCallApiContext[\"Data\"]>;\n\t\t\t\tErrorData: GetDefaultDataTypeForPlugins<TCallApiContext[\"ErrorData\"]>;\n\t\t\t}\n\t\t>\n\t>;\n\nexport type PluginMiddlewares<TCallApiContext extends CallApiContext = DefaultCallApiContext> =\n\tMiddlewares<\n\t\tOverrideCallApiContext<\n\t\t\tTCallApiContext,\n\t\t\t{\n\t\t\t\tData: GetDefaultDataTypeForPlugins<TCallApiContext[\"Data\"]>;\n\t\t\t\tErrorData: GetDefaultDataTypeForPlugins<TCallApiContext[\"ErrorData\"]>;\n\t\t\t}\n\t\t>\n\t>;\n\nexport interface CallApiPlugin<TCallApiContext extends CallApiContext = DefaultCallApiContext> {\n\t/**\n\t * Defines additional options that can be passed to callApi\n\t */\n\tdefineExtraOptions?: () => TCallApiContext[\"InferredExtraOptions\"];\n\n\t/**\n\t * A description for the plugin\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Hooks for the plugin\n\t */\n\thooks?:\n\t\t| PluginHooks<TCallApiContext>\n\t\t| ((\n\t\t\t\tcontext: PluginSetupContext<TCallApiContext>\n\t\t ) => Awaitable<PluginHooks<TCallApiContext>> | Awaitable<void>);\n\n\t/**\n\t * A unique id for the plugin\n\t */\n\tid: string;\n\n\t/**\n\t * Middlewares that for the plugin\n\t */\n\tmiddlewares?:\n\t\t| PluginMiddlewares<TCallApiContext>\n\t\t| ((\n\t\t\t\tcontext: PluginSetupContext<TCallApiContext>\n\t\t ) => Awaitable<PluginMiddlewares<TCallApiContext>> | Awaitable<void>);\n\n\t/**\n\t * A name for the plugin\n\t */\n\tname: string;\n\n\t/**\n\t * Base schema for the client.\n\t */\n\tschema?: BaseCallApiSchemaAndConfig;\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\tsetup?: (\n\t\tcontext: PluginSetupContext<TCallApiContext>\n\t) => Awaitable<PluginInitResult<TCallApiContext>> | Awaitable<void>;\n\n\t/**\n\t * A version for the plugin\n\t */\n\tversion?: string;\n}\n\nexport type InferPluginExtraOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<\n\tTPluginArray extends Array<infer TPlugin> ?\n\t\tTPlugin extends CallApiPlugin ?\n\t\t\tTPlugin[\"defineExtraOptions\"] extends AnyFunction<infer TResult> ?\n\t\t\t\tInferSchemaOutput<TResult, TResult>\n\t\t\t:\tnever\n\t\t:\tnever\n\t:\tnever\n>;\n\nexport const getResolvedPlugins = (context: Pick<RequestContext, \"baseConfig\" | \"options\">) => {\n\tconst { baseConfig, options } = context;\n\n\tconst resolvedPlugins =\n\t\tisFunction(options.plugins) ?\n\t\t\toptions.plugins({ basePlugins: baseConfig.plugins ?? [] })\n\t\t:\t(options.plugins ?? []);\n\n\treturn resolvedPlugins;\n};\n\nexport const initializePlugins = async (setupContext: PluginSetupContext) => {\n\tconst { baseConfig, config, currentRouteSchemaKey, mainInitURL, options, request } = setupContext;\n\n\tconst {\n\t\taddMainHooks,\n\t\taddMainMiddlewares,\n\t\taddPluginHooks,\n\t\taddPluginMiddlewares,\n\t\tgetResolvedHooks,\n\t\tgetResolvedMiddlewares,\n\t} = setupHooksAndMiddlewares({ baseConfig, config, options });\n\n\tlet resolvedCurrentRouteSchemaKey = currentRouteSchemaKey;\n\tlet resolvedInitURL = mainInitURL;\n\tconst resolvedOptions = options;\n\tconst resolvedRequest = request;\n\n\tconst executePluginSetupFn = async (pluginSetup: CallApiPlugin[\"setup\"]) => {\n\t\tif (!pluginSetup) return;\n\n\t\tconst initResult = await pluginSetup(setupContext);\n\n\t\tif (!initResult) return;\n\n\t\tconst urlString = initResult.initURL?.toString();\n\n\t\tif (isString(urlString)) {\n\t\t\tconst newURLResult = getCurrentRouteSchemaKeyAndMainInitURL({\n\t\t\t\tbaseExtraOptions: baseConfig,\n\t\t\t\textraOptions: config,\n\t\t\t\tinitURL: urlString,\n\t\t\t});\n\n\t\t\tresolvedCurrentRouteSchemaKey = newURLResult.currentRouteSchemaKey;\n\t\t\tresolvedInitURL = newURLResult.mainInitURL;\n\t\t}\n\n\t\tif (initResult.request) {\n\t\t\tObject.assign(resolvedRequest, initResult.request, initResult.request.extraFetchOptions);\n\t\t}\n\n\t\tif (initResult.options) {\n\t\t\tObject.assign(resolvedOptions, initResult.options);\n\t\t}\n\t};\n\n\tconst resolvedPlugins = getResolvedPlugins({ baseConfig, options });\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\tconst [, pluginHooks, pluginMiddlewares] = await Promise.all([\n\t\t\texecutePluginSetupFn(plugin.setup),\n\t\t\tisFunction(plugin.hooks) ? plugin.hooks(setupContext) : plugin.hooks,\n\t\t\tisFunction(plugin.middlewares) ? plugin.middlewares(setupContext) : plugin.middlewares,\n\t\t]);\n\n\t\tpluginHooks && addPluginHooks(pluginHooks);\n\t\tpluginMiddlewares && addPluginMiddlewares(pluginMiddlewares);\n\t}\n\n\taddMainHooks();\n\n\taddMainMiddlewares();\n\n\tconst resolvedHooks = getResolvedHooks();\n\n\tconst resolvedMiddlewares = getResolvedMiddlewares();\n\n\treturn {\n\t\tresolvedCurrentRouteSchemaKey,\n\t\tresolvedHooks,\n\t\tresolvedInitURL,\n\t\tresolvedMiddlewares,\n\t\tresolvedOptions,\n\t\tresolvedRequest,\n\t};\n};\n\nconst setupHooksAndMiddlewares = (\n\tcontext: Pick<PluginSetupContext, \"baseConfig\" | \"config\" | \"options\">\n) => {\n\tconst { baseConfig, config, options } = context;\n\n\tconst { hookRegistries, hookRegistryKeys } = getHookRegistriesAndKeys();\n\n\tconst { middlewareRegistries, middlewareRegistryKeys } = getMiddlewareRegistriesAndKeys();\n\n\tconst addMainHooks = () => {\n\t\tfor (const hookName of hookRegistryKeys) {\n\t\t\tconst overriddenHook = options[hookName];\n\t\t\tconst baseHook = baseConfig[hookName];\n\t\t\tconst instanceHook = config[hookName];\n\n\t\t\tconst shouldMergeBaseAndInstanceHooks = isArray(baseHook) && instanceHook;\n\n\t\t\tconst mainHook =\n\t\t\t\tshouldMergeBaseAndInstanceHooks ? [baseHook, instanceHook].flat() : overriddenHook;\n\n\t\t\tmainHook && hookRegistries[hookName].add(mainHook as never);\n\t\t}\n\t};\n\n\tconst addPluginHooks = (pluginHooks: PluginHooks) => {\n\t\tfor (const hookName of hookRegistryKeys) {\n\t\t\tconst pluginHook = pluginHooks[hookName];\n\n\t\t\tpluginHook && hookRegistries[hookName].add(pluginHook as never);\n\t\t}\n\t};\n\n\tconst addMainMiddlewares = () => {\n\t\tfor (const middlewareName of middlewareRegistryKeys) {\n\t\t\tconst baseMiddleware = baseConfig[middlewareName];\n\t\t\tconst instanceMiddleware = config[middlewareName];\n\n\t\t\tbaseMiddleware && middlewareRegistries[middlewareName].add(baseMiddleware);\n\n\t\t\tinstanceMiddleware && middlewareRegistries[middlewareName].add(instanceMiddleware);\n\t\t}\n\t};\n\n\tconst addPluginMiddlewares = (pluginMiddlewares: PluginMiddlewares) => {\n\t\tfor (const middlewareName of middlewareRegistryKeys) {\n\t\t\tconst pluginMiddleware = pluginMiddlewares[middlewareName];\n\n\t\t\tif (!pluginMiddleware) continue;\n\n\t\t\tmiddlewareRegistries[middlewareName].add(pluginMiddleware);\n\t\t}\n\t};\n\n\tconst getResolvedHooks = () => {\n\t\tconst resolvedHooks: Hooks = {};\n\n\t\tfor (const [hookName, hookRegistry] of Object.entries(hookRegistries)) {\n\t\t\tif (hookRegistry.size === 0) continue;\n\n\t\t\t// == Flatten the hook registry to remove any nested arrays, incase an array of hooks is passed to any of the hooks\n\t\t\tconst flattenedHookArray = [...hookRegistry].flat();\n\n\t\t\tif (flattenedHookArray.length === 0) continue;\n\n\t\t\tconst hooksExecutionMode = options.hooksExecutionMode ?? extraOptionDefaults.hooksExecutionMode;\n\n\t\t\tconst composedHook = composeHooksFromArray(flattenedHookArray, hooksExecutionMode);\n\n\t\t\tresolvedHooks[hookName as keyof Hooks] = composedHook;\n\t\t}\n\n\t\treturn resolvedHooks;\n\t};\n\n\tconst getResolvedMiddlewares = () => {\n\t\tconst resolvedMiddlewares: Middlewares = {};\n\n\t\tfor (const [middlewareName, middlewareRegistry] of Object.entries(middlewareRegistries)) {\n\t\t\tif (middlewareRegistry.size === 0) continue;\n\n\t\t\tconst middlewareArray = [...middlewareRegistry];\n\n\t\t\tif (middlewareArray.length === 0) continue;\n\n\t\t\tconst composedMiddleware = composeMiddlewaresFromArray(middlewareArray);\n\n\t\t\tresolvedMiddlewares[middlewareName as keyof Middlewares] = composedMiddleware;\n\t\t}\n\n\t\treturn resolvedMiddlewares;\n\t};\n\n\treturn {\n\t\taddMainHooks,\n\t\taddMainMiddlewares,\n\t\taddPluginHooks,\n\t\taddPluginMiddlewares,\n\t\tgetResolvedHooks,\n\t\tgetResolvedMiddlewares,\n\t};\n};\n","import { extraOptionDefaults } from \"./constants/defaults\";\nimport type { CallApiImpl } from \"./retry\";\nimport type { CallApiConfig, CallApiExtraOptions, CallApiResultLoose } from \"./types/common\";\nimport type { InitURLOrURLObject } from \"./url\";\n\nexport interface RefetchOptions {\n\t/**\n\t * Tracks the number of times refetch has been called\n\t * @internal\n\t * @deprecated **NOTE**: This property is used internally to track refetch calls. Please abstain from modifying it.\n\t */\n\treadonly [\"~refetchCount\"]?: number;\n\n\t/**\n\t * Maximum number of times refetch can be called from error hooks.\n\t *\n\t * Prevents infinite loops when refetch is called repeatedly in error hooks.\n\t * When the limit is reached, refetch will throw an error instead of retrying.\n\t *\n\t * @default 1\n\t *\n\t * @example\n\t * ```ts\n\t * // Allow up to 5 refetch attempts\n\t * refetchAttempts: 5\n\t *\n\t * // Disable refetch limit\n\t * refetchAttempts: Infinity\n\t *\n\t * // Strict limit of 1 refetch\n\t * refetchAttempts: 1\n\t * ```\n\t */\n\trefetchAttempts?: number;\n}\n\nexport type RefetchFn = (\n\toverrides?: Pick<RefetchOptions, \"refetchAttempts\">\n) => Promise<CallApiResultLoose<unknown, unknown> | null>;\n\nexport interface RefetchFnOption {\n\trefetch: RefetchFn;\n}\n\nexport const createRefetchManager = <TCallApi extends CallApiImpl>(ctx: {\n\tcallApi: TCallApi;\n\tcallApiArgs: { config: CallApiConfig; initURL: InitURLOrURLObject };\n\toptions: CallApiExtraOptions;\n}): RefetchFnOption => {\n\tconst { callApi, callApiArgs, options } = ctx;\n\n\t// eslint-disable-next-line ts-eslint/no-deprecated -- Allowed for internal use\n\tconst currentRefetchCount = options[\"~refetchCount\"] ?? 1;\n\n\tconst refetch: RefetchFnOption[\"refetch\"] = async (refetchOptionOverrides) => {\n\t\tconst maxRefetchAttempts =\n\t\t\trefetchOptionOverrides?.refetchAttempts\n\t\t\t?? options.refetchAttempts\n\t\t\t?? extraOptionDefaults.refetchAttempts;\n\n\t\tconst shouldRefetch = currentRefetchCount <= maxRefetchAttempts;\n\n\t\tif (!shouldRefetch) {\n\t\t\tconst message = `Maximum refetch attempts (${maxRefetchAttempts}) exceeded. This prevents infinite loops. Increase 'maxRefetchAttempts' if needed.`;\n\n\t\t\tconsole.error(message);\n\n\t\t\treturn null;\n\t\t}\n\n\t\tconst updatedConfig = {\n\t\t\t...callApiArgs.config,\n\t\t\t...refetchOptionOverrides,\n\t\t\t\"~refetchCount\": currentRefetchCount + 1,\n\t\t} satisfies CallApiConfig;\n\n\t\treturn callApi(callApiArgs.initURL as never, updatedConfig);\n\t};\n\n\treturn {\n\t\trefetch,\n\t};\n};\n","import { extraOptionDefaults } from \"./constants/defaults\";\nimport {\n\texecuteHooksInCatchBlock,\n\ttype ErrorContext,\n\ttype ExecuteHookInfo,\n\ttype RetryContext,\n} from \"./hooks\";\nimport type { CallApiResultErrorVariant } from \"./result\";\nimport type { CallApiConfig, CallApiResultLoose } from \"./types/common\";\nimport type { MethodUnion } from \"./types/conditional-types\";\nimport { defineEnum, type AnyNumber, type Awaitable, type UnmaskType } from \"./types/type-helpers\";\nimport type { InitURLOrURLObject } from \"./url\";\nimport { waitFor } from \"./utils/common\";\nimport { isBoolean, isFunction, isString } from \"./utils/guards\";\n\n// eslint-disable-next-line ts-eslint/no-unused-vars -- Ignore\nconst defaultRetryStatusCodesLookup = () =>\n\tdefineEnum({\n\t\t408: \"Request Timeout\",\n\t\t409: \"Conflict\",\n\t\t425: \"Too Early\",\n\t\t429: \"Too Many Requests\",\n\t\t500: \"Internal Server Error\",\n\t\t502: \"Bad Gateway\",\n\t\t503: \"Service Unavailable\",\n\t\t504: \"Gateway Timeout\",\n\t});\n\ntype RetryStatusCodes = UnmaskType<AnyNumber | keyof ReturnType<typeof defaultRetryStatusCodesLookup>>;\n\ntype RetryCondition<TErrorData> = (context: ErrorContext<{ ErrorData: TErrorData }>) => Awaitable<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 * @internal\n\t * @deprecated **NOTE**: This property is used internally to track retries. Please abstain from modifying it.\n\t */\n\treadonly [\"~retryAttemptCount\"]?: 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 | ((currentAttemptCount: number) => 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?: MethodUnion[];\n\n\t/**\n\t * HTTP status codes that trigger a retry\n\t */\n\tretryStatusCodes?: RetryStatusCodes[];\n\n\t/**\n\t * Strategy to use when retrying\n\t * @default \"linear\"\n\t */\n\tretryStrategy?: \"exponential\" | \"linear\";\n}\n\nconst getLinearDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? extraOptionDefaults.retryDelay;\n\n\tconst resolveRetryDelay = isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay;\n\n\treturn resolveRetryDelay;\n};\n\nconst getExponentialDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? extraOptionDefaults.retryDelay;\n\n\tconst resolvedRetryDelay = isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay;\n\n\tconst maxDelay = options.retryMaxDelay ?? extraOptionDefaults.retryMaxDelay;\n\n\tconst exponentialDelay = resolvedRetryDelay * 2 ** currentAttemptCount;\n\n\treturn Math.min(exponentialDelay, maxDelay);\n};\n\nexport type CallApiImpl = (\n\tinitURL: never,\n\tinit?: CallApiConfig\n) => Promise<CallApiResultLoose<unknown, unknown>>;\n\nexport const createRetryManager = <TCallApi extends CallApiImpl>(ctx: {\n\tcallApi: TCallApi;\n\tcallApiArgs: { config: CallApiConfig; initURL: InitURLOrURLObject };\n\terror: unknown;\n\terrorContext: ErrorContext;\n\terrorResult: CallApiResultErrorVariant<unknown> | null;\n\thookInfo: ExecuteHookInfo;\n}) => {\n\tconst { callApi, callApiArgs, error, errorContext, errorResult, hookInfo } = ctx;\n\n\tconst { options, request } = errorContext;\n\n\t// eslint-disable-next-line ts-eslint/no-deprecated -- Allowed for internal use\n\tconst currentAttemptCount = options[\"~retryAttemptCount\"] ?? 1;\n\n\tconst retryStrategy = options.retryStrategy ?? extraOptionDefaults.retryStrategy;\n\n\tconst getDelay = () => {\n\t\tswitch (retryStrategy) {\n\t\t\tcase \"exponential\": {\n\t\t\t\treturn getExponentialDelay(currentAttemptCount, options);\n\t\t\t}\n\t\t\tcase \"linear\": {\n\t\t\t\treturn getLinearDelay(currentAttemptCount, options);\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(`Invalid retry strategy: ${String(retryStrategy)}`);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst shouldAttemptRetry = async () => {\n\t\tif (isBoolean(request.signal) && request.signal.aborted) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst retryCondition = options.retryCondition ?? extraOptionDefaults.retryCondition;\n\n\t\tconst maxRetryAttempts = options.retryAttempts ?? extraOptionDefaults.retryAttempts;\n\n\t\tconst customRetryCondition = await retryCondition(errorContext);\n\n\t\tconst baseShouldRetry = currentAttemptCount <= maxRetryAttempts && customRetryCondition;\n\n\t\tif (!baseShouldRetry) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst retryMethods = new Set(options.retryMethods ?? extraOptionDefaults.retryMethods);\n\n\t\tconst includesMethod =\n\t\t\tisString(request.method) && retryMethods.size > 0 ? retryMethods.has(request.method) : true;\n\n\t\tconst retryStatusCodes = new Set(options.retryStatusCodes ?? extraOptionDefaults.retryStatusCodes);\n\n\t\tconst includesStatusCodes =\n\t\t\terrorContext.response != null && retryStatusCodes.size > 0 ?\n\t\t\t\tretryStatusCodes.has(errorContext.response.status)\n\t\t\t:\ttrue;\n\n\t\tconst shouldRetry = includesMethod && includesStatusCodes;\n\n\t\treturn shouldRetry;\n\t};\n\n\tconst handleRetry = async () => {\n\t\tconst retryContext = {\n\t\t\t...errorContext,\n\t\t\tretryAttemptCount: currentAttemptCount,\n\t\t} satisfies RetryContext<{ ErrorData: unknown }>;\n\n\t\tconst hookError = await executeHooksInCatchBlock([options.onRetry?.(retryContext)], hookInfo);\n\n\t\tif (hookError) {\n\t\t\treturn hookError;\n\t\t}\n\n\t\tawait waitFor(getDelay());\n\n\t\tconst updatedConfig = {\n\t\t\t...callApiArgs.config,\n\t\t\t\"~retryAttemptCount\": currentAttemptCount + 1,\n\t\t} satisfies CallApiConfig;\n\n\t\treturn callApi(callApiArgs.initURL as never, updatedConfig);\n\t};\n\n\tconst handleRetryOrGetErrorResult = async () => {\n\t\tconst shouldRetry = await shouldAttemptRetry();\n\n\t\tif (shouldRetry) {\n\t\t\treturn handleRetry() as never;\n\t\t}\n\n\t\tif (hookInfo.shouldThrowOnError) {\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn errorResult;\n\t};\n\n\treturn {\n\t\thandleRetryOrGetErrorResult,\n\t};\n};\n","import { createDedupeStrategy, type GlobalRequestInfoCache, type RequestInfoCache } from \"./dedupe\";\nimport {\n\texecuteHooks,\n\texecuteHooksInCatchBlock,\n\ttype CallApiExtraOptionsForHooks,\n\ttype CallApiRequestOptionsForHooks,\n\ttype ErrorContext,\n\ttype ExecuteHookInfo,\n\ttype RequestContext,\n\ttype ResponseContext,\n\ttype SuccessContext,\n\ttype ValidationErrorContext,\n} from \"./hooks\";\nimport { initializePlugins, type CallApiPlugin } from \"./plugins\";\nimport { createRefetchManager } from \"./refetch\";\nimport {\n\tgetCustomizedErrorResult,\n\tresolveErrorResult,\n\tresolveResponseData,\n\tresolveSuccessResult,\n\ttype ErrorInfo,\n\ttype GetResponseType,\n\ttype ResponseTypeType,\n\ttype ResultModeType,\n} from \"./result\";\nimport { createRetryManager } from \"./retry\";\nimport type {\n\tBaseCallApiConfig,\n\tBaseCallApiExtraOptions,\n\tCallApiConfig,\n\tCallApiContext,\n\tCallApiExtraOptions,\n\tCallApiRequestOptions,\n\tCallApiResult,\n\tGetBaseSchemaConfig,\n\tGetBaseSchemaRoutes,\n} from \"./types/common\";\nimport type {\n\tGetCurrentRouteSchema,\n\tGetCurrentRouteSchemaKey,\n\tInferInitURL,\n\tThrowOnErrorBoolean,\n} from \"./types/conditional-types\";\nimport type {\n\tDefaultCallApiContext,\n\tDefaultPluginArray,\n\tDefaultThrowOnError,\n} from \"./types/default-types\";\nimport type { AnyFunction } from \"./types/type-helpers\";\nimport { getFullAndNormalizedURL } from \"./url\";\nimport {\n\tcreateCombinedSignal,\n\tcreateTimeoutSignal,\n\tgetBody,\n\tgetFetchImpl,\n\tgetHeaders,\n\tgetMethod,\n\tgetResolvedHeaders,\n\tsplitConfig,\n} from \"./utils/common\";\nimport { HTTPError } from \"./utils/external/error\";\nimport { isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/external/guards\";\nimport { isFunction } from \"./utils/guards\";\nimport {\n\tgetCurrentRouteSchemaKeyAndMainInitURL,\n\thandleConfigValidation,\n\thandleSchemaValidation,\n\ttype BaseCallApiSchemaAndConfig,\n\ttype BaseCallApiSchemaRoutes,\n\ttype CallApiSchema,\n\ttype CallApiSchemaConfig,\n\ttype InferSchemaOutput,\n} from \"./validation\";\n\nconst getTimeoutSignal =\n\t\"timeout\" in AbortSignal ? createTimeoutSignal\n\t\t// eslint-disable-next-line unicorn/prefer-top-level-await -- Ignore\n\t: import(\"./utils/polyfills/timeoutSignal\").then((module) => module.createTimeoutSignal);\n\nconst getCombinedSignal =\n\t\"any\" in AbortSignal ? createCombinedSignal\n\t\t// eslint-disable-next-line unicorn/prefer-top-level-await -- Ignore\n\t: import(\"./utils/polyfills/combinedSignal\").then((module) => module.createCombinedSignal);\n\nconst $GlobalRequestInfoCache: GlobalRequestInfoCache = new Map();\n\nexport const createFetchClientWithContext = <\n\tTOuterCallApiContext extends CallApiContext = DefaultCallApiContext,\n>() => {\n\tconst createFetchClient = <\n\t\tTBaseCallApiContext extends CallApiContext = TOuterCallApiContext,\n\t\tTBaseData = TBaseCallApiContext[\"Data\"],\n\t\tTBaseErrorData = TBaseCallApiContext[\"ErrorData\"],\n\t\tTBaseResultMode extends ResultModeType = TBaseCallApiContext[\"ResultMode\"] extends ResultModeType ?\n\t\t\tTBaseCallApiContext[\"ResultMode\"]\n\t\t:\tDefaultCallApiContext[\"ResultMode\"],\n\t\tTBaseThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError,\n\t\tTBaseResponseType extends ResponseTypeType = ResponseTypeType,\n\t\tconst TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig,\n\t\tconst TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\t\tTComputedBaseSchemaConfig extends CallApiSchemaConfig = GetBaseSchemaConfig<TBaseSchemaAndConfig>,\n\t\tTComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes =\n\t\t\tGetBaseSchemaRoutes<TBaseSchemaAndConfig>,\n\t>(\n\t\tinitBaseConfig: BaseCallApiConfig<\n\t\t\tTBaseCallApiContext,\n\t\t\tTBaseData,\n\t\t\tTBaseErrorData,\n\t\t\tTBaseResultMode,\n\t\t\tTBaseThrowOnError,\n\t\t\tTBaseResponseType,\n\t\t\tTBaseSchemaAndConfig,\n\t\t\tTBasePluginArray\n\t\t> = {} as never\n\t) => {\n\t\tconst $LocalRequestInfoCache: RequestInfoCache = new Map();\n\n\t\tconst callApi = async <\n\t\t\tTData = TBaseData,\n\t\t\tTErrorData = TBaseErrorData,\n\t\t\tTResultMode extends ResultModeType = TBaseResultMode,\n\t\t\tTCallApiContext extends CallApiContext = TBaseCallApiContext,\n\t\t\tTThrowOnError extends ThrowOnErrorBoolean = TBaseThrowOnError,\n\t\t\tTResponseType extends ResponseTypeType = TBaseResponseType,\n\t\t\tconst TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig,\n\t\t\tTInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<\n\t\t\t\tTComputedBaseSchemaRoutes,\n\t\t\t\tTSchemaConfig\n\t\t\t>,\n\t\t\tTCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> =\n\t\t\t\tGetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>,\n\t\t\tconst TSchema extends CallApiSchema = GetCurrentRouteSchema<\n\t\t\t\tTComputedBaseSchemaRoutes,\n\t\t\t\tTCurrentRouteSchemaKey\n\t\t\t>,\n\t\t\tconst TPluginArray extends CallApiPlugin[] = TBasePluginArray,\n\t\t\tTComputedData = InferSchemaOutput<TSchema[\"data\"], GetResponseType<TData, TResponseType>>,\n\t\t\tTComputedErrorData = InferSchemaOutput<\n\t\t\t\tTSchema[\"errorData\"],\n\t\t\t\tGetResponseType<TErrorData, TResponseType>\n\t\t\t>,\n\t\t\tTComputedResult = CallApiResult<TComputedData, TComputedErrorData, TResultMode, TThrowOnError>,\n\t\t>(\n\t\t\tinitURL: TInitURL,\n\t\t\tinitConfig: CallApiConfig<\n\t\t\t\tTCallApiContext,\n\t\t\t\tTComputedData,\n\t\t\t\tTComputedErrorData,\n\t\t\t\tTResultMode,\n\t\t\t\tTThrowOnError,\n\t\t\t\tTResponseType,\n\t\t\t\tTComputedBaseSchemaRoutes,\n\t\t\t\tTSchema,\n\t\t\t\tTComputedBaseSchemaConfig,\n\t\t\t\tTSchemaConfig,\n\t\t\t\tTInitURL,\n\t\t\t\tTCurrentRouteSchemaKey,\n\t\t\t\tTBasePluginArray,\n\t\t\t\tTPluginArray\n\t\t\t> = {} as never\n\t\t): Promise<TComputedResult> => {\n\t\t\tconst [fetchOptions, extraOptions] = splitConfig<CallApiExtraOptions>(initConfig);\n\n\t\t\tconst resolvedBaseConfig =\n\t\t\t\tisFunction(initBaseConfig) ?\n\t\t\t\t\tinitBaseConfig({\n\t\t\t\t\t\tinitURL: initURL.toString(),\n\t\t\t\t\t\toptions: extraOptions,\n\t\t\t\t\t\trequest: fetchOptions,\n\t\t\t\t\t})\n\t\t\t\t:\tinitBaseConfig;\n\n\t\t\tconst baseConfig = resolvedBaseConfig as Exclude<BaseCallApiConfig, AnyFunction>;\n\t\t\tconst config = initConfig as CallApiConfig;\n\n\t\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-type-arguments -- False Positive\n\t\t\tconst [baseFetchOptions, baseExtraOptions] = splitConfig<BaseCallApiExtraOptions>(baseConfig);\n\n\t\t\tconst shouldSkipAutoMergeForOptions =\n\t\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"options\";\n\n\t\t\tconst shouldSkipAutoMergeForRequest =\n\t\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"request\";\n\n\t\t\t// == Merged Extra Options\n\t\t\tconst mergedExtraOptions = {\n\t\t\t\t...baseExtraOptions,\n\t\t\t\t...(!shouldSkipAutoMergeForOptions && extraOptions),\n\t\t\t};\n\n\t\t\t// == Merged Request Options\n\t\t\tconst mergedRequestOptions = {\n\t\t\t\t...baseFetchOptions,\n\t\t\t\t...baseFetchOptions.extraFetchOptions,\n\t\t\t\t...(!shouldSkipAutoMergeForRequest && fetchOptions),\n\t\t\t\t...(!shouldSkipAutoMergeForRequest && fetchOptions.extraFetchOptions),\n\t\t\t} satisfies CallApiRequestOptions;\n\n\t\t\tconst initURLResult = getCurrentRouteSchemaKeyAndMainInitURL({\n\t\t\t\tbaseExtraOptions: baseConfig,\n\t\t\t\textraOptions: config,\n\t\t\t\tinitURL: initURL.toString(),\n\t\t\t});\n\n\t\t\tconst {\n\t\t\t\tresolvedCurrentRouteSchemaKey,\n\t\t\t\tresolvedHooks,\n\t\t\t\tresolvedInitURL,\n\t\t\t\tresolvedMiddlewares,\n\t\t\t\tresolvedOptions,\n\t\t\t\tresolvedRequest,\n\t\t\t} = await initializePlugins({\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\t...initURLResult,\n\t\t\t\toptions: mergedExtraOptions as CallApiExtraOptionsForHooks,\n\t\t\t\trequest: {\n\t\t\t\t\t...mergedRequestOptions,\n\t\t\t\t\theaders: getResolvedHeaders({ baseHeaders: baseConfig.headers, headers: config.headers }),\n\t\t\t\t\tmethod: getMethod({ initURL: initURLResult.initURL, method: mergedRequestOptions.method }),\n\t\t\t\t} as CallApiRequestOptionsForHooks,\n\t\t\t});\n\n\t\t\tconst { fullURL, normalizedInitURL } = getFullAndNormalizedURL({\n\t\t\t\tbaseURL: resolvedOptions.baseURL,\n\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\tparams: resolvedOptions.params,\n\t\t\t\tquery: resolvedOptions.query,\n\t\t\t});\n\n\t\t\tconst options = {\n\t\t\t\t...resolvedOptions,\n\t\t\t\t...resolvedHooks,\n\t\t\t\t...resolvedMiddlewares,\n\t\t\t\tfullURL,\n\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\tinitURLNormalized: normalizedInitURL,\n\t\t\t} satisfies CallApiExtraOptions;\n\n\t\t\tconst refetchFnResult = createRefetchManager({\n\t\t\t\tcallApi,\n\t\t\t\tcallApiArgs: { config, initURL },\n\t\t\t\toptions,\n\t\t\t});\n\n\t\t\tObject.assign(options, refetchFnResult);\n\n\t\t\tconst newFetchController = new AbortController();\n\n\t\t\tconst timeoutSignal = (await getTimeoutSignal)(options.timeout);\n\n\t\t\tconst combinedSignal = (await getCombinedSignal)(\n\t\t\t\ttimeoutSignal,\n\t\t\t\tresolvedRequest.signal,\n\t\t\t\tnewFetchController.signal\n\t\t\t);\n\n\t\t\tconst request = {\n\t\t\t\t...resolvedRequest,\n\t\t\t\tsignal: combinedSignal,\n\t\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\t\tconst {\n\t\t\t\tgetAbortErrorMessage,\n\t\t\t\thandleRequestCancelStrategy,\n\t\t\t\thandleRequestDeferStrategy,\n\t\t\t\tremoveDedupeKeyFromCache,\n\t\t\t\tresolvedDedupeStrategy,\n\t\t\t} = await createDedupeStrategy({\n\t\t\t\t$GlobalRequestInfoCache,\n\t\t\t\t$LocalRequestInfoCache,\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tnewFetchController,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\thandleRequestCancelStrategy();\n\n\t\t\t\tawait executeHooks(options.onRequest?.({ baseConfig, config, options, request }));\n\n\t\t\t\tconst {\n\t\t\t\t\textraOptionsValidationResult,\n\t\t\t\t\trequestOptionsValidationResult,\n\t\t\t\t\tresolvedSchema,\n\t\t\t\t\tresolvedSchemaConfig,\n\t\t\t\t} = await handleConfigValidation({\n\t\t\t\t\tbaseExtraOptions,\n\t\t\t\t\tcurrentRouteSchemaKey: resolvedCurrentRouteSchemaKey,\n\t\t\t\t\textraOptions,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t});\n\n\t\t\t\t// == Apply Schema Output for Extra Options\n\n\t\t\t\tObject.assign(options, extraOptionsValidationResult);\n\n\t\t\t\tconst modifiedRequestOptionsValidationResult = {\n\t\t\t\t\tbody: getBody({\n\t\t\t\t\t\tbody: requestOptionsValidationResult.body,\n\t\t\t\t\t\tbodySerializer: options.bodySerializer,\n\t\t\t\t\t\tresolvedHeaders: requestOptionsValidationResult.headers,\n\t\t\t\t\t}),\n\t\t\t\t\theaders: await getHeaders({\n\t\t\t\t\t\tauth: options.auth,\n\t\t\t\t\t\tbody: requestOptionsValidationResult.body,\n\t\t\t\t\t\tresolvedHeaders: requestOptionsValidationResult.headers,\n\t\t\t\t\t}),\n\t\t\t\t\tmethod: getMethod({\n\t\t\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\t\t\tmethod: requestOptionsValidationResult.method,\n\t\t\t\t\t}),\n\t\t\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\t\t\t// == Apply Schema Output for Request Options\n\t\t\t\tObject.assign(request, modifiedRequestOptionsValidationResult);\n\n\t\t\t\tconst readyRequestContext = {\n\t\t\t\t\tbaseConfig,\n\t\t\t\t\tconfig,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t} satisfies RequestContext;\n\n\t\t\t\tawait executeHooks(options.onRequestReady?.(readyRequestContext));\n\n\t\t\t\tconst fetchApi = getFetchImpl({\n\t\t\t\t\tcustomFetchImpl: options.customFetchImpl,\n\t\t\t\t\tfetchMiddleware: options.fetchMiddleware,\n\t\t\t\t\trequestContext: readyRequestContext,\n\t\t\t\t});\n\n\t\t\t\tconst response = await handleRequestDeferStrategy({ fetchApi, options, request });\n\n\t\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\t\tconst shouldCloneResponse = Boolean(\n\t\t\t\t\tresolvedDedupeStrategy === \"defer\" || options.cloneResponse\n\t\t\t\t);\n\n\t\t\t\tconst responseData = await resolveResponseData({\n\t\t\t\t\tresponse: shouldCloneResponse ? response.clone() : response,\n\t\t\t\t\tresponseParser: options.responseParser,\n\t\t\t\t\tresponseType: options.responseType,\n\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t});\n\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tconst validErrorData = await handleSchemaValidation(resolvedSchema, \"errorData\", {\n\t\t\t\t\t\tinputValue: responseData,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t\t\t});\n\n\t\t\t\t\t// == Push all error handling responsibilities to the catch block if not retrying\n\t\t\t\t\tthrow new HTTPError(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdefaultHTTPErrorMessage: options.defaultHTTPErrorMessage,\n\t\t\t\t\t\t\terrorData: validErrorData,\n\t\t\t\t\t\t\tresponse,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ cause: validErrorData }\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst validSuccessData = await handleSchemaValidation(resolvedSchema, \"data\", {\n\t\t\t\t\tinputValue: responseData,\n\t\t\t\t\tresponse,\n\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t\t});\n\n\t\t\t\tconst successContext = {\n\t\t\t\t\tbaseConfig,\n\t\t\t\t\tconfig,\n\t\t\t\t\tdata: validSuccessData,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t\tresponse,\n\t\t\t\t} satisfies SuccessContext;\n\n\t\t\t\tawait executeHooks(\n\t\t\t\t\toptions.onSuccess?.(successContext),\n\t\t\t\t\toptions.onResponse?.({ ...successContext, error: null })\n\t\t\t\t);\n\n\t\t\t\tconst successResult = resolveSuccessResult(successContext.data, {\n\t\t\t\t\tresponse: successContext.response,\n\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t});\n\n\t\t\t\treturn successResult as never;\n\n\t\t\t\t// == Exhaustive Error handling\n\t\t\t} catch (error) {\n\t\t\t\tconst errorInfo = {\n\t\t\t\t\tcloneResponse: options.cloneResponse,\n\t\t\t\t\tresultMode: options.resultMode,\n\t\t\t\t} satisfies ErrorInfo;\n\n\t\t\t\tconst { errorDetails, errorResult } = resolveErrorResult(error, errorInfo);\n\n\t\t\t\tconst errorContext = {\n\t\t\t\t\tbaseConfig,\n\t\t\t\t\tconfig,\n\t\t\t\t\terror: errorDetails.error as never,\n\t\t\t\t\toptions,\n\t\t\t\t\trequest,\n\t\t\t\t\tresponse: errorDetails.response as never,\n\t\t\t\t} satisfies ErrorContext;\n\n\t\t\t\tconst shouldThrowOnError = Boolean(\n\t\t\t\t\tisFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError\n\t\t\t\t);\n\n\t\t\t\tconst hookInfo = {\n\t\t\t\t\terrorInfo,\n\t\t\t\t\tshouldThrowOnError,\n\t\t\t\t} satisfies ExecuteHookInfo;\n\n\t\t\t\tconst { handleRetryOrGetErrorResult } = createRetryManager({\n\t\t\t\t\tcallApi,\n\t\t\t\t\tcallApiArgs: { config, initURL },\n\t\t\t\t\terror,\n\t\t\t\t\terrorContext,\n\t\t\t\t\terrorResult,\n\t\t\t\t\thookInfo,\n\t\t\t\t});\n\n\t\t\t\tconst responseContext: ResponseContext | null =\n\t\t\t\t\t(errorContext.response as Response | null) ? { ...errorContext, data: null } : null;\n\n\t\t\t\tif (isValidationErrorInstance(error)) {\n\t\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\tresponseContext && options.onResponse?.(responseContext),\n\t\t\t\t\t\t\toptions.onValidationError?.(errorContext as ValidationErrorContext),\n\t\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t\t],\n\t\t\t\t\t\thookInfo\n\t\t\t\t\t);\n\n\t\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t\t}\n\n\t\t\t\tif (isHTTPErrorInstance<TErrorData>(error)) {\n\t\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\tresponseContext && options.onResponse?.(responseContext),\n\t\t\t\t\t\t\toptions.onResponseError?.(errorContext),\n\t\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t\t],\n\t\t\t\t\t\thookInfo\n\t\t\t\t\t);\n\n\t\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t\t}\n\n\t\t\t\tlet message = (error as Error | undefined)?.message;\n\n\t\t\t\tif (error instanceof DOMException && error.name === \"AbortError\") {\n\t\t\t\t\tmessage = getAbortErrorMessage();\n\n\t\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t\t}\n\n\t\t\t\tif (error instanceof DOMException && error.name === \"TimeoutError\") {\n\t\t\t\t\tmessage = `Request timed out after ${options.timeout}ms`;\n\n\t\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t\t}\n\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[\n\t\t\t\t\t\tresponseContext && options.onResponse?.(responseContext),\n\t\t\t\t\t\toptions.onRequestError?.(errorContext),\n\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError\n\t\t\t\t\t?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message })) as never;\n\n\t\t\t\t// == Removing the now unneeded AbortController from store\n\t\t\t} finally {\n\t\t\t\tremoveDedupeKeyFromCache();\n\t\t\t}\n\t\t};\n\n\t\treturn callApi;\n\t};\n\n\treturn createFetchClient;\n};\n\nexport const createFetchClient = createFetchClientWithContext();\n\nexport const callApi = createFetchClient();\n"],"mappings":";;AAoBA,MAAa,mBAA0B,UAAoB,oBAA2C;CACrG,mBAAmB,SAAS,aAAa;CACzC,YAAY,SAAS,MAAM;CAC3B,gBAAgB,SAAS,UAAU;CACnC,MAAM,YAA4B;AAEjC,SAAO,eADM,MAAM,SAAS,MAAM,CACP;;CAE5B,cAAc,SAAS;CACvB,YAAY,SAAS,MAAM;CAC3B;AAuBD,MAAM,YAAY,IAAI,IAAI;CAAC;CAAa;CAAmB;CAAqB;CAAmB,CAAC;AACpG,MAAM,aAAa;AAEnB,MAAM,sBAAsB,aAA4E;CACvG,MAAM,kBAAkB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,13 @@
1
+ //#region src/utils/polyfills/timeoutSignal.ts
2
+ const createTimeoutSignal = (ms) => {
3
+ if (ms == null) return;
4
+ const controller = new AbortController();
5
+ const reason = new DOMException("Request timed out", "TimeoutError");
6
+ const timeout = setTimeout(() => controller.abort(reason), ms);
7
+ controller.signal.addEventListener("abort", () => clearTimeout(timeout));
8
+ return controller.signal;
9
+ };
10
+ //#endregion
11
+ export { createTimeoutSignal };
12
+
13
+ //# sourceMappingURL=timeoutSignal-B9V7QESI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeoutSignal-B9V7QESI.js","names":[],"sources":["../src/utils/polyfills/timeoutSignal.ts"],"sourcesContent":["export const createTimeoutSignal = (ms: number | undefined) => {\n\tif (ms == null) return;\n\n\tconst controller = new AbortController();\n\n\tconst reason = new DOMException(\"Request timed out\", \"TimeoutError\");\n\n\tconst timeout = setTimeout(() => controller.abort(reason), ms);\n\n\tcontroller.signal.addEventListener(\"abort\", () => clearTimeout(timeout));\n\n\treturn controller.signal;\n};\n"],"mappings":";AAAA,MAAa,uBAAuB,OAA2B;AAC9D,KAAI,MAAM,KAAM;CAEhB,MAAM,aAAa,IAAI,iBAAiB;CAExC,MAAM,SAAS,IAAI,aAAa,qBAAqB,eAAe;CAEpE,MAAM,UAAU,iBAAiB,WAAW,MAAM,OAAO,EAAE,GAAG;AAE9D,YAAW,OAAO,iBAAiB,eAAe,aAAa,QAAQ,CAAC;AAExE,QAAO,WAAW"}
@@ -1,4 +1,4 @@
1
- import { Et as Writeable, F as HTTPError, I as ValidationError, T as CallApiRequestOptions, Tt as Satisfies, _t as InferSchemaOutput, c as CallApiResultErrorVariant, dt as BaseCallApiSchemaRoutes, h as PossibleValidationError, ht as CallApiSchemaType, i as CallApiPlugin, m as PossibleJavaScriptError, mt as CallApiSchemaConfig, p as PossibleHTTPError, pt as CallApiSchema, x as CallApiConfig, xt as AnyFunction, y as BaseCallApiConfig } from "../../default-types-CLNJkstU.js";
1
+ import { Et as Writeable, F as HTTPError, I as ValidationError, T as CallApiRequestOptions, Tt as Satisfies, _t as InferSchemaOutput, c as CallApiResultErrorVariant, dt as BaseCallApiSchemaRoutes, h as PossibleValidationError, ht as CallApiSchemaType, i as CallApiPlugin, m as PossibleJavaScriptError, mt as CallApiSchemaConfig, p as PossibleHTTPError, pt as CallApiSchema, x as CallApiConfig, xt as AnyFunction, y as BaseCallApiConfig } from "../../default-types-JDMZem2Z.js";
2
2
 
3
3
  //#region src/utils/external/body.d.ts
4
4
  type BodyType = NonNullable<CallApiRequestOptions["body"]>;
@@ -1,2 +1,2 @@
1
- import { C as definePlugin, D as toFormData, E as defineSchemaRoutes, F as ValidationError, O as toQueryString, P as HTTPError, S as defineMainSchema, T as defineSchemaConfig, _ as isJavascriptError, b as defineBaseConfig, g as isHTTPErrorInstance, h as isHTTPError, k as toSearchParams, m as objectifyHeaders, v as isValidationError, w as defineSchema, x as defineInstanceConfig, y as isValidationErrorInstance } from "../../defaults-DsWxUrb7.js";
1
+ import { C as defineSchema, D as toQueryString, E as toFormData, N as HTTPError, O as toSearchParams, P as ValidationError, S as definePlugin, T as defineSchemaRoutes, _ as isValidationError, b as defineInstanceConfig, g as isJavascriptError, h as isHTTPErrorInstance, m as isHTTPError, p as objectifyHeaders, v as isValidationErrorInstance, w as defineSchemaConfig, x as defineMainSchema, y as defineBaseConfig } from "../../defaults-S9x_Ra9q.js";
2
2
  export { HTTPError, ValidationError, defineBaseConfig, defineInstanceConfig, defineMainSchema, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes, isHTTPError, isHTTPErrorInstance, isJavascriptError, isValidationError, isValidationErrorInstance, objectifyHeaders, toFormData, toQueryString, toSearchParams };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/callapi",
3
3
  "type": "module",
4
- "version": "1.12.2",
4
+ "version": "1.12.3",
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",
@@ -40,9 +40,9 @@
40
40
  "@size-limit/esbuild-why": "12.0.1",
41
41
  "@size-limit/preset-small-lib": "12.0.1",
42
42
  "@total-typescript/ts-reset": "0.6.1",
43
- "@vitest/browser": "4.1.2",
44
- "@vitest/browser-playwright": "4.1.2",
45
- "@vitest/coverage-v8": "4.1.2",
43
+ "@vitest/browser": "4.1.3",
44
+ "@vitest/browser-playwright": "4.1.3",
45
+ "@vitest/coverage-v8": "4.1.3",
46
46
  "@zayne-labs/prettier-config": "^0.12.10",
47
47
  "@zayne-labs/tsconfig": "0.12.10",
48
48
  "concurrently": "^9.2.1",
@@ -63,7 +63,7 @@
63
63
  "size-limit": [
64
64
  {
65
65
  "path": "./src/index.ts",
66
- "limit": "6.8 kb"
66
+ "limit": "7 kb"
67
67
  },
68
68
  {
69
69
  "path": "./src/utils/external/index.ts",