@zayne-labs/callapi 1.10.6 → 1.11.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["$GlobalRequestInfoCache","resolvedHooks: Hooks","$GlobalRequestInfoCache: GlobalRequestInfoCache","$LocalRequestInfoCache: RequestInfoCache","callApi"],"sources":["../../src/result.ts","../../src/hooks.ts","../../src/stream.ts","../../src/dedupe.ts","../../src/plugins.ts","../../src/retry.ts","../../src/createFetchClient.ts","../../src/defineHelpers.ts"],"sourcesContent":["import { extraOptionDefaults } from \"./constants/default-options\";\nimport type { HTTPError, ValidationError } from \"./error\";\nimport type { CallApiExtraOptions, ThrowOnErrorUnion } from \"./types\";\nimport type { DefaultDataType, DefaultThrowOnError } from \"./types/default-types\";\nimport type { AnyString, Awaitable, UnmaskType } from \"./types/type-helpers\";\nimport { isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/guards\";\n\nexport type ResponseType = \"blob\" | \"json\" | \"text\";\n\ntype Parser<TData> = (responseString: string) => Awaitable<TData>;\n\nexport const getResponseType = <TResponse>(response: Response, parser: Parser<TResponse>) => ({\n\tarrayBuffer: () => response.arrayBuffer(),\n\tblob: () => response.blob(),\n\tformData: () => response.formData(),\n\tjson: async (): Promise<TResponse> => {\n\t\tconst text = await response.text();\n\t\treturn parser(text);\n\t},\n\tstream: () => response.body,\n\ttext: () => response.text(),\n});\n\ntype InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;\n\nexport type ResponseTypeUnion = keyof InitResponseTypeMap | null;\n\nexport type ResponseTypeMap<TResponse> = {\n\t[Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>>;\n};\n\nexport type GetResponseType<\n\tTResponse,\n\tTResponseType extends ResponseTypeUnion,\n\tTComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>,\n> =\n\tnull extends TResponseType ? TComputedResponseTypeMap[\"json\"]\n\t: TResponseType extends NonNullable<ResponseTypeUnion> ? 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<ResponseTypeUnion, \"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 = <TResponse>(\n\tresponse: Response,\n\tresponseType: ResponseTypeUnion | undefined,\n\tparser: Parser<TResponse> | undefined\n) => {\n\tconst selectedParser = parser ?? extraOptionDefaults().responseParser;\n\tconst selectedResponseType = responseType ?? detectResponseType(response);\n\n\tconst RESPONSE_TYPE_LOOKUP = getResponseType<TResponse>(response, selectedParser);\n\n\tif (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, selectedResponseType)) {\n\t\tthrow new Error(`Invalid response type: ${responseType}`);\n\t}\n\n\treturn RESPONSE_TYPE_LOOKUP[selectedResponseType]();\n};\n\nexport type CallApiResultSuccessVariant<TData> = {\n\tdata: NoInfer<TData>;\n\terror: null;\n\tresponse: Response;\n};\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: NoInfer<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 PossibleJavaScriptOrValidationError = UnmaskType<\n\tPossibleJavaScriptError | PossibleValidationError\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: PossibleJavaScriptOrValidationError;\n\t\t\tresponse: Response | null;\n\t };\n\nexport type ResultModeMapWithoutException<\n\tTData,\n\tTErrorData,\n\tTResponseType extends ResponseTypeUnion,\n\tTComputedData = GetResponseType<TData, TResponseType>,\n\tTComputedErrorData = GetResponseType<TErrorData, TResponseType>,\n> = UnmaskType<{\n\tall: CallApiResultErrorVariant<TComputedErrorData> | CallApiResultSuccessVariant<TComputedData>;\n\n\tonlyData:\n\t\t| CallApiResultErrorVariant<TComputedErrorData>[\"data\"]\n\t\t| CallApiResultSuccessVariant<TComputedData>[\"data\"];\n}>;\n\ntype ResultModeMapWithException<\n\tTData,\n\tTResponseType extends ResponseTypeUnion,\n\tTComputedData = GetResponseType<TData, TResponseType>,\n> = {\n\tall: CallApiResultSuccessVariant<TComputedData>;\n\tonlyData: CallApiResultSuccessVariant<TComputedData>[\"data\"];\n};\n\nexport type ResultModeMap<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n> =\n\tTThrowOnError extends true ? ResultModeMapWithException<TData, TResponseType>\n\t:\tResultModeMapWithoutException<TData, TErrorData, TResponseType>;\n\ntype ResultModePlaceholder = null;\n\n// eslint-disable-next-line perfectionist/sort-union-types -- Allow\nexport type ResultModeUnion = keyof ResultModeMap | ResultModePlaceholder;\n\nexport type GetCallApiResult<\n\tTData,\n\tTErrorData,\n\tTResultMode extends ResultModeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion,\n\tTResponseType extends ResponseTypeUnion,\n> =\n\tTErrorData extends false ? ResultModeMapWithException<TData, TResponseType>[\"onlyData\"]\n\t: TErrorData extends false | undefined ? ResultModeMapWithException<TData, TResponseType>[\"onlyData\"]\n\t: ResultModePlaceholder extends TResultMode ?\n\t\tResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>[\"all\"]\n\t: TResultMode extends Exclude<ResultModeUnion, ResultModePlaceholder> ?\n\t\tResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>[TResultMode]\n\t:\tnever;\n\ntype SuccessInfo = {\n\tresponse: Response;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\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\tonlyData: () => details.data,\n\t};\n};\n\ntype SuccessResult = CallApiResultSuccessVariant<unknown> | null;\n\n// == The CallApiResult type is used to cast all return statements 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 = {\n\tcloneResponse: CallApiExtraOptions[\"cloneResponse\"];\n\tmessage?: string;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n};\n\ntype ErrorResult = {\n\terrorDetails: CallApiResultErrorVariant<unknown>;\n\tgeneralErrorResult: 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 generalErrorResult = resultModeMap[resultMode ?? \"all\"]() as never;\n\n\treturn {\n\t\terrorDetails,\n\t\tgeneralErrorResult,\n\t};\n};\n\nexport const getCustomizedErrorResult = (\n\terrorResult: ErrorResult[\"generalErrorResult\"],\n\tcustomErrorInfo: { message: string | undefined }\n): ErrorResult[\"generalErrorResult\"] => {\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[\"generalErrorResult\"]>[\"error\"] as never,\n\t};\n};\n","import {\n\ttype CallApiResultErrorVariant,\n\ttype CallApiResultSuccessVariant,\n\ttype ErrorInfo,\n\ttype PossibleHTTPError,\n\ttype PossibleJavaScriptError,\n\ttype PossibleJavaScriptOrValidationError,\n\ttype PossibleValidationError,\n\tresolveErrorResult,\n} from \"./result\";\nimport type { StreamProgressEvent } from \"./stream\";\nimport type {\n\tBaseCallApiExtraOptions,\n\tCallApiExtraOptions,\n\tCallApiExtraOptionsForHooks,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n} from \"./types/common\";\nimport type { DefaultDataType } from \"./types/default-types\";\nimport type { AnyFunction, Awaitable, Prettify, UnmaskType } from \"./types/type-helpers\";\n\nexport type PluginExtraOptions<TPluginOptions = unknown> = {\n\t/** Plugin-specific options passed to the plugin configuration */\n\toptions: Partial<TPluginOptions>;\n};\n\n/* eslint-disable perfectionist/sort-intersection-types -- Plugin options should come last */\nexport interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOptions = unknown> {\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?: (\n\t\tcontext: ErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook called before the HTTP request is sent and before any internal processing 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 & PluginExtraOptions<TPluginOptions>) => 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?: (\n\t\tcontext: RequestErrorContext & PluginExtraOptions<TPluginOptions>\n\t) => 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 & PluginExtraOptions<TPluginOptions>) => 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?: (\n\t\tcontext: RequestStreamContext & PluginExtraOptions<TPluginOptions>\n\t) => 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?: (\n\t\tcontext: ResponseContext<TData, TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => 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?: (\n\t\tcontext: ResponseErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => 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?: (\n\t\tcontext: ResponseStreamContext & PluginExtraOptions<TPluginOptions>\n\t) => 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?: (\n\t\tresponse: RetryContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => 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<TData> & PluginExtraOptions<TPluginOptions>) => 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?: (\n\t\tcontext: ValidationErrorContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n}\n/* eslint-enable perfectionist/sort-intersection-types -- Plugin options should come last */\n\nexport type HooksOrHooksArray<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTMoreOptions = unknown,\n> = {\n\t[Key in keyof Hooks<TData, TErrorData, TMoreOptions>]:\n\t\t| Hooks<TData, TErrorData, TMoreOptions>[Key]\n\t\t// eslint-disable-next-line perfectionist/sort-union-types -- I need arrays to be last\n\t\t| Array<Hooks<TData, TErrorData, TMoreOptions>[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 * Use `hookRegistrationOrder` to control the registration order of main vs plugin hooks.\n\t *\n\t * @default \"parallel\"\n\t *\n\t * @example\n\t * ```ts\n\t * // Parallel execution (default) - all hooks run simultaneously\n\t * hooksExecutionMode: \"parallel\"\n\t *\n\t * // Sequential execution - hooks run one after another\n\t * hooksExecutionMode: \"sequential\"\n\t *\n\t * // Use case: Hooks have dependencies and must run in order\n\t * const client = callApi.create({\n\t * hooksExecutionMode: \"sequential\",\n\t * hookRegistrationOrder: \"mainFirst\",\n\t * plugins: [transformPlugin],\n\t * onRequest: (ctx) => {\n\t * // This runs first, then transform plugin runs\n\t * ctx.request.headers[\"x-request-id\"] = generateId();\n\t * }\n\t * });\n\t *\n\t * // Use case: Independent operations can run in parallel for speed\n\t * const client = callApi.create({\n\t * hooksExecutionMode: \"parallel\", // Default\n\t * plugins: [metricsPlugin, cachePlugin, loggingPlugin],\n\t * onRequest: (ctx) => {\n\t * // All hooks (main + plugins) run simultaneously\n\t * addRequestTimestamp(ctx.request);\n\t * }\n\t * });\n\t *\n\t * // Use case: Error handling hooks that need sequential processing\n\t * const client = callApi.create({\n\t * hooksExecutionMode: \"sequential\",\n\t * onError: [\n\t * (ctx) => logError(ctx.error), // Log first\n\t * (ctx) => reportError(ctx.error), // Then report\n\t * (ctx) => cleanupResources(ctx) // Finally cleanup\n\t * ]\n\t * });\n\t * ```\n\t */\n\thooksExecutionMode?: \"parallel\" | \"sequential\";\n\n\t/**\n\t * Controls the registration order of main hooks relative to plugin hooks.\n\t *\n\t * - **\"pluginsFirst\"**: Plugin hooks register first, then main hooks (default)\n\t * - **\"mainFirst\"**: Main hooks register first, then plugin hooks\n\t *\n\t * This determines the order hooks are added to the registry, which affects\n\t * their execution sequence when using sequential execution mode.\n\t *\n\t * @default \"pluginsFirst\"\n\t *\n\t * @example\n\t * ```ts\n\t * // Plugin hooks register first (default behavior)\n\t * hookRegistrationOrder: \"pluginsFirst\"\n\t *\n\t * // Main hooks register first\n\t * hookRegistrationOrder: \"mainFirst\"\n\t *\n\t * // Use case: Main validation before plugin processing\n\t * const client = callApi.create({\n\t * hookRegistrationOrder: \"mainFirst\",\n\t * hooksExecutionMode: \"sequential\",\n\t * plugins: [transformPlugin],\n\t * onRequest: (ctx) => {\n\t * // This main hook runs first in sequential mode\n\t * if (!ctx.request.headers.authorization) {\n\t * throw new Error(\"Authorization required\");\n\t * }\n\t * }\n\t * });\n\t *\n\t * // Use case: Plugin setup before main logic (default)\n\t * const client = callApi.create({\n\t * hookRegistrationOrder: \"pluginsFirst\", // Default\n\t * hooksExecutionMode: \"sequential\",\n\t * plugins: [setupPlugin],\n\t * onRequest: (ctx) => {\n\t * // Plugin runs first, then this main hook\n\t * console.log(\"Request prepared:\", ctx.request.url);\n\t * }\n\t * });\n\t *\n\t * // Use case: Parallel mode (registration order less important)\n\t * const client = callApi.create({\n\t * hookRegistrationOrder: \"pluginsFirst\",\n\t * hooksExecutionMode: \"parallel\", // All run simultaneously\n\t * plugins: [metricsPlugin, cachePlugin],\n\t * onRequest: (ctx) => {\n\t * // All hooks run in parallel regardless of registration order\n\t * addRequestId(ctx.request);\n\t * }\n\t * });\n\t * ```\n\t */\n\thooksRegistrationOrder?: \"mainFirst\" | \"pluginsFirst\";\n}\n\nexport type RequestContext = {\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: BaseCallApiExtraOptions & CallApiRequestOptions;\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: CallApiExtraOptions & CallApiRequestOptions;\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;\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 ValidationErrorContext = UnmaskType<\n\tRequestContext & {\n\t\t/** Validation error containing details about what failed validation */\n\t\terror: PossibleValidationError;\n\t\t/** HTTP response object if validation failed on response, null if on request */\n\t\tresponse: Response | null;\n\t}\n>;\n\nexport type SuccessContext<TData> = UnmaskType<\n\tRequestContext & {\n\t\t/** Parsed response data with the expected success type */\n\t\tdata: TData;\n\t\t/** HTTP response object for the successful request */\n\t\tresponse: Response;\n\t}\n>;\n\nexport type ResponseContext<TData, TErrorData> = UnmaskType<\n\tRequestContext\n\t\t& (\n\t\t\t| Prettify<CallApiResultSuccessVariant<TData>>\n\t\t\t| Prettify<\n\t\t\t\t\tExtract<CallApiResultErrorVariant<TErrorData>, { error: PossibleHTTPError<TErrorData> }>\n\t\t\t >\n\t\t)\n>;\n\nexport type RequestErrorContext = RequestContext & {\n\t/** Error that occurred during the request (network, timeout, etc.) */\n\terror: PossibleJavaScriptError;\n\t/** Always null for request errors since no response was received */\n\tresponse: null;\n};\n\nexport type ErrorContext<TErrorData> = UnmaskType<\n\tRequestContext\n\t\t& (\n\t\t\t| {\n\t\t\t\t\t/** HTTP error with response data */\n\t\t\t\t\terror: PossibleHTTPError<TErrorData>;\n\t\t\t\t\t/** HTTP response object containing error status */\n\t\t\t\t\tresponse: Response;\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\t/** Request-level error (network, timeout, validation, etc.) */\n\t\t\t\t\terror: PossibleJavaScriptOrValidationError;\n\t\t\t\t\t/** Response object if available, null for request errors */\n\t\t\t\t\tresponse: Response | null;\n\t\t\t }\n\t\t)\n>;\n\nexport type ResponseErrorContext<TErrorData> = UnmaskType<\n\tExtract<ErrorContext<TErrorData>, { error: PossibleHTTPError<TErrorData> }> & RequestContext\n>;\n\nexport type RetryContext<TErrorData> = UnmaskType<\n\tErrorContext<TErrorData> & {\n\t\t/** Current retry attempt number (1-based, so 1 = first retry) */\n\t\tretryAttemptCount: number;\n\t}\n>;\n\nexport type RequestStreamContext = UnmaskType<\n\tRequestContext & {\n\t\t/** Progress event containing loaded/total bytes information */\n\t\tevent: StreamProgressEvent;\n\t\t/** The actual Request instance being uploaded */\n\t\trequestInstance: Request;\n\t}\n>;\n\nexport type ResponseStreamContext = UnmaskType<\n\tRequestContext & {\n\t\t/** Progress event containing loaded/total bytes information */\n\t\tevent: StreamProgressEvent;\n\t\t/** HTTP response object being downloaded */\n\t\tresponse: Response;\n\t}\n>;\n\ntype HookRegistries = Required<{\n\t[Key in keyof Hooks]: Set<Hooks[Key]>;\n}>;\n\nexport const getHookRegistries = (): HookRegistries => {\n\treturn {\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\nexport const composeAllHooks = (\n\thooksArray: Array<AnyFunction | undefined>,\n\thooksExecutionMode: CallApiExtraOptionsForHooks[\"hooksExecutionMode\"]\n) => {\n\tconst mergedHook = async (ctx: unknown) => {\n\t\tswitch (hooksExecutionMode) {\n\t\t\tcase \"parallel\": {\n\t\t\t\tawait Promise.all(hooksArray.map((uniqueHook) => uniqueHook?.(ctx)));\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);\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 undefined;\n\t\t\t}\n\t\t}\n\t};\n\n\treturn mergedHook;\n};\n\nexport const executeHooksInTryBlock = 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\tconst { generalErrorResult: hookErrorResult } = resolveErrorResult(hookError, errorInfo);\n\n\t\tif (shouldThrowOnError) {\n\t\t\tthrow hookError;\n\t\t}\n\n\t\treturn hookErrorResult;\n\t}\n};\n","import {\n\texecuteHooksInTryBlock,\n\ttype RequestContext,\n\ttype RequestStreamContext,\n\ttype ResponseStreamContext,\n} from \"./hooks\";\nimport { isObject, 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\ndeclare global {\n\tinterface ReadableStream<R> {\n\t\t[Symbol.asyncIterator]: () => AsyncIterableIterator<R>;\n\t}\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\tconst shouldForcefullyCalcStreamSize =\n\t\tisObject(options.forcefullyCalculateStreamSize) ?\n\t\t\toptions.forcefullyCalculateStreamSize.request\n\t\t:\toptions.forcefullyCalculateStreamSize;\n\n\t// == If no content length is present, we read the total bytes from the body\n\tif (!contentLength && shouldForcefullyCalcStreamSize) {\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 executeHooksInTryBlock(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 executeHooksInTryBlock(\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 = async (context: StreamableResponseContext): Promise<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\tconst shouldForceContentLengthCalc =\n\t\tisObject(options.forcefullyCalculateStreamSize) ?\n\t\t\toptions.forcefullyCalculateStreamSize.response\n\t\t:\toptions.forcefullyCalculateStreamSize;\n\n\t// == If no content length is present and `forceContentLengthCalculation` is enabled, we read the total bytes from the body\n\tif (!contentLength && shouldForceContentLengthCalc) {\n\t\ttotalBytes = await calculateTotalBytesFromBody(response.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 = 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 executeHooksInTryBlock(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 executeHooksInTryBlock(\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/default-options\";\nimport type { RequestContext } from \"./hooks\";\nimport { toStreamableRequest, toStreamableResponse } from \"./stream\";\nimport type { AnyString, UnmaskType } from \"./types/type-helpers\";\nimport { deterministicHashFn, getFetchImpl, waitFor } from \"./utils/common\";\nimport { isFunction } from \"./utils/guards\";\n\ntype RequestInfo = {\n\tcontroller: AbortController;\n\tresponsePromise: Promise<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\trequest: globalRequest,\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\tif (globalOptions.dedupeKey) {\n\t\t\tconst resolvedDedupeKey =\n\t\t\t\tisFunction(globalOptions.dedupeKey) ?\n\t\t\t\t\tglobalOptions.dedupeKey(context)\n\t\t\t\t:\tglobalOptions.dedupeKey;\n\n\t\t\treturn resolvedDedupeKey;\n\t\t}\n\n\t\treturn `${globalOptions.fullURL}-${deterministicHashFn({ options: globalOptions, request: globalRequest })}`;\n\t};\n\n\tconst dedupeKey = getDedupeKey();\n\n\tconst dedupeCacheScope = globalOptions.dedupeCacheScope ?? extraOptionDefaults().dedupeCacheScope;\n\n\tconst dedupeCacheScopeKey =\n\t\tglobalOptions.dedupeCacheScopeKey ?? extraOptionDefaults().dedupeCacheScopeKey;\n\n\tif (dedupeCacheScope === \"global\" && !$GlobalRequestInfoCache.has(dedupeCacheScopeKey)) {\n\t\t$GlobalRequestInfoCache.set(dedupeCacheScopeKey, new Map());\n\t}\n\n\tconst $RequestInfoCache =\n\t\tdedupeCacheScope === \"global\" ?\n\t\t\t$GlobalRequestInfoCache.get(dedupeCacheScopeKey)\n\t\t:\t$LocalRequestInfoCache;\n\n\t// == This is to ensure cache operations only occur when key is available\n\tconst $RequestInfoCacheOrNull = dedupeKey !== null ? $RequestInfoCache : null;\n\n\t/******\n\t * == Add a small delay to the execution to ensure proper request deduplication when multiple requests with the same key start simultaneously.\n\t * == This gives time for the cache to be updated with the previous request info before the next request checks it.\n\t ******/\n\tif (dedupeKey !== null) {\n\t\tawait waitFor(0.1);\n\t}\n\n\tconst prevRequestInfo = $RequestInfoCacheOrNull?.get(dedupeKey);\n\n\tconst getAbortErrorMessage = () => {\n\t\tif (globalOptions.dedupeKey) {\n\t\t\treturn `Duplicate request detected - Aborted previous request with key '${dedupeKey}' as a new request was initiated`;\n\t\t}\n\n\t\treturn `Duplicate request detected - Aborted previous request to '${globalOptions.fullURL}' as a new request with identical options was initiated`;\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\n\t\t// == Adding this just so that eslint forces me put await when calling the function (it looks better that way tbh)\n\t\treturn Promise.resolve();\n\t};\n\n\tconst handleRequestDeferStrategy = async (deferContext: {\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 { options: localOptions, request: localRequest } = deferContext;\n\n\t\tconst fetchApi = getFetchImpl(localOptions.customFetchImpl);\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$RequestInfoCacheOrNull?.set(dedupeKey, { controller: newFetchController, responsePromise });\n\n\t\tconst streamableResponse = toStreamableResponse({\n\t\t\t...streamableContext,\n\t\t\tresponse: await responsePromise,\n\t\t});\n\n\t\treturn streamableResponse;\n\t};\n\n\tconst removeDedupeKeyFromCache = () => {\n\t\t$RequestInfoCacheOrNull?.delete(dedupeKey);\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;\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);\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 { extraOptionDefaults } from \"./constants/default-options\";\nimport {\n\tcomposeAllHooks,\n\tgetHookRegistries,\n\ttype Hooks,\n\ttype HooksOrHooksArray,\n\ttype PluginExtraOptions,\n\ttype RequestContext,\n} from \"./hooks\";\nimport type { CallApiRequestOptions, CallApiRequestOptionsForHooks } from \"./types/common\";\nimport type { Awaitable } from \"./types/type-helpers\";\nimport type { InitURLOrURLObject } from \"./url\";\nimport { isArray, isFunction, isPlainObject, isString } from \"./utils/guards\";\nimport { type BaseCallApiSchemaAndConfig, getCurrentRouteSchemaKeyAndMainInitURL } from \"./validation\";\n\nexport type PluginSetupContext<TPluginExtraOptions = unknown> = RequestContext // eslint-disable-next-line perfectionist/sort-intersection-types -- Allow\n\t& PluginExtraOptions<TPluginExtraOptions> & { initURL: string };\n\nexport type PluginInitResult = Partial<\n\tOmit<PluginSetupContext, \"initURL\" | \"request\"> & {\n\t\tinitURL: InitURLOrURLObject;\n\t\trequest: CallApiRequestOptions;\n\t}\n>;\n\nexport type PluginHooksWithMoreOptions<TMoreOptions = unknown> = HooksOrHooksArray<\n\tnever,\n\tnever,\n\tTMoreOptions\n>;\n\nexport type PluginHooks<TData = never, TErrorData = never, TMoreOptions = unknown> = HooksOrHooksArray<\n\tTData,\n\tTErrorData,\n\tTMoreOptions\n>;\n\nexport interface CallApiPlugin {\n\t/**\n\t * Defines additional options that can be passed to callApi\n\t */\n\tdefineExtraOptions?: (...params: never[]) => unknown;\n\n\t/**\n\t * A description for the plugin\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Hooks / Interceptors for the plugin\n\t */\n\thooks?: PluginHooks;\n\n\t/**\n\t * A unique id for the plugin\n\t */\n\tid: string;\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?: (context: PluginSetupContext) => Awaitable<PluginInitResult> | Awaitable<void>;\n\n\t/**\n\t * A version for the plugin\n\t */\n\tversion?: string;\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 (context: PluginSetupContext) => {\n\tconst { baseConfig, config, initURL, options, request } = context;\n\n\tconst hookRegistries = getHookRegistries();\n\n\tconst hookRegistryKeyArray = Object.keys(hookRegistries) as Array<keyof Hooks>;\n\n\tconst addMainHooks = () => {\n\t\tfor (const key of hookRegistryKeyArray) {\n\t\t\tconst overriddenHook = options[key];\n\t\t\tconst baseHook = baseConfig[key];\n\t\t\tconst instanceHook = config[key];\n\n\t\t\t// == If the base hook is an array and instance hook is defined, we need to compose the base hook with the instance hook\n\t\t\tconst mainHook =\n\t\t\t\tisArray(baseHook) && Boolean(instanceHook) ? [baseHook, instanceHook].flat() : overriddenHook;\n\n\t\t\tif (!mainHook) continue;\n\n\t\t\thookRegistries[key].add(mainHook as never);\n\t\t}\n\t};\n\n\tconst addPluginHooks = (pluginHooks: Required<CallApiPlugin>[\"hooks\"]) => {\n\t\tfor (const key of hookRegistryKeyArray) {\n\t\t\tconst pluginHook = pluginHooks[key];\n\n\t\t\tif (!pluginHook) continue;\n\n\t\t\thookRegistries[key].add(pluginHook as never);\n\t\t}\n\t};\n\n\tconst hookRegistrationOrder =\n\t\toptions.hooksRegistrationOrder ?? extraOptionDefaults().hooksRegistrationOrder;\n\n\tif (hookRegistrationOrder === \"mainFirst\") {\n\t\taddMainHooks();\n\t}\n\n\tconst { currentRouteSchemaKey, mainInitURL } = getCurrentRouteSchemaKeyAndMainInitURL({\n\t\tbaseExtraOptions: baseConfig,\n\t\textraOptions: config,\n\t\tinitURL,\n\t});\n\n\tlet resolvedCurrentRouteSchemaKey = currentRouteSchemaKey;\n\tlet resolvedInitURL = mainInitURL;\n\tlet resolvedOptions = options;\n\tlet resolvedRequestOptions = request;\n\n\tconst executePluginSetupFn = async (pluginSetupFn: CallApiPlugin[\"setup\"]) => {\n\t\tif (!pluginSetupFn) return;\n\n\t\tconst initResult = await pluginSetupFn({\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tinitURL,\n\t\t\toptions,\n\t\t\trequest,\n\t\t});\n\n\t\tif (!isPlainObject(initResult)) return;\n\n\t\tconst urlString = initResult.initURL?.toString();\n\n\t\tif (isString(urlString)) {\n\t\t\tconst newResult = 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 = newResult.currentRouteSchemaKey;\n\t\t\tresolvedInitURL = newResult.mainInitURL;\n\t\t}\n\n\t\tif (isPlainObject(initResult.request)) {\n\t\t\tresolvedRequestOptions = initResult.request as CallApiRequestOptionsForHooks;\n\t\t}\n\n\t\tif (isPlainObject(initResult.options)) {\n\t\t\tresolvedOptions = 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\tawait executePluginSetupFn(plugin.setup);\n\n\t\tif (!plugin.hooks) continue;\n\n\t\taddPluginHooks(plugin.hooks);\n\t}\n\n\tif (hookRegistrationOrder === \"pluginsFirst\") {\n\t\taddMainHooks();\n\t}\n\n\tconst resolvedHooks: Hooks = {};\n\n\tfor (const [key, hookRegistry] of Object.entries(hookRegistries)) {\n\t\tif (hookRegistry.size === 0) continue;\n\n\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\tconst flattenedHookArray = [...hookRegistry].flat();\n\n\t\tif (flattenedHookArray.length === 0) continue;\n\n\t\tconst hooksExecutionMode = options.hooksExecutionMode ?? extraOptionDefaults().hooksExecutionMode;\n\n\t\tconst composedHook = composeAllHooks(flattenedHookArray, hooksExecutionMode);\n\n\t\tresolvedHooks[key as keyof Hooks] = composedHook;\n\t}\n\n\treturn {\n\t\tresolvedCurrentRouteSchemaKey,\n\t\tresolvedHooks,\n\t\tresolvedInitURL,\n\t\tresolvedOptions,\n\t\tresolvedRequestOptions,\n\t};\n};\n","import { extraOptionDefaults } from \"./constants/default-options\";\nimport type { ErrorContext, RequestContext } from \"./hooks\";\nimport type { MethodUnion } from \"./types\";\nimport { type AnyNumber, type Awaitable, defineEnum, type UnmaskType } from \"./types/type-helpers\";\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<TErrorData>) => Awaitable<boolean>;\n\ntype InnerRetryKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, \"~retryAttemptCount\" | \"retry\">;\n\ntype InnerRetryOptions<TErrorData> = {\n\t[Key in InnerRetryKeys<TErrorData> as Key extends `retry${infer TRest}` ?\n\t\tUncapitalize<TRest> extends \"attempts\" ?\n\t\t\tnever\n\t\t:\tUncapitalize<TRest>\n\t:\tKey]?: RetryOptions<TErrorData>[Key];\n} & {\n\tattempts: NonNullable<RetryOptions<TErrorData>[\"retryAttempts\"]>;\n};\n\nexport interface RetryOptions<TErrorData> {\n\t/**\n\t * Keeps track of the number of times the request has already been retried\n\t *\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 * All retry options in a single object instead of separate properties\n\t */\n\tretry?: InnerRetryOptions<TErrorData>;\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 ?? options.retry?.delay;\n\n\tconst resolveRetryDelay =\n\t\t(isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay)\n\t\t?? extraOptionDefaults().retryDelay;\n\n\treturn resolveRetryDelay;\n};\n\nconst getExponentialDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? options.retry?.delay ?? extraOptionDefaults().retryDelay;\n\n\tconst resolvedRetryDelay = isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay;\n\n\tconst maxDelay =\n\t\toptions.retryMaxDelay ?? options.retry?.maxDelay ?? extraOptionDefaults().retryMaxDelay;\n\n\tconst exponentialDelay = resolvedRetryDelay * 2 ** currentAttemptCount;\n\n\treturn Math.min(exponentialDelay, maxDelay);\n};\n\nexport const createRetryStrategy = (ctx: ErrorContext<unknown> & RequestContext) => {\n\tconst { options, request } = ctx;\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 =\n\t\toptions.retryStrategy ?? options.retry?.strategy ?? 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 =\n\t\t\toptions.retryCondition ?? options.retry?.condition ?? extraOptionDefaults().retryCondition;\n\n\t\tconst maximumRetryAttempts =\n\t\t\toptions.retryAttempts ?? options.retry?.attempts ?? extraOptionDefaults().retryAttempts;\n\n\t\tconst customRetryCondition = await retryCondition(ctx);\n\n\t\tconst baseShouldRetry = currentAttemptCount <= maximumRetryAttempts && customRetryCondition;\n\n\t\tif (!baseShouldRetry) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst retryMethods = new Set(\n\t\t\toptions.retryMethods ?? options.retry?.methods ?? extraOptionDefaults().retryMethods\n\t\t);\n\n\t\tconst includesMethod =\n\t\t\tisString(ctx.request.method) && retryMethods.size > 0 ?\n\t\t\t\tretryMethods.has(ctx.request.method)\n\t\t\t:\ttrue;\n\n\t\tconst retryStatusCodes = new Set(\n\t\t\toptions.retryStatusCodes ?? options.retry?.statusCodes ?? extraOptionDefaults().retryStatusCodes\n\t\t);\n\n\t\tconst includesStatusCodes =\n\t\t\tctx.response != null && retryStatusCodes.size > 0 ?\n\t\t\t\tretryStatusCodes.has(ctx.response.status)\n\t\t\t:\ttrue;\n\n\t\tconst shouldRetry = includesMethod && includesStatusCodes;\n\n\t\treturn shouldRetry;\n\t};\n\n\treturn {\n\t\tcurrentAttemptCount,\n\t\tgetDelay,\n\t\tshouldAttemptRetry,\n\t};\n};\n","import { createDedupeStrategy, type GlobalRequestInfoCache, type RequestInfoCache } from \"./dedupe\";\nimport { HTTPError } from \"./error\";\nimport {\n\ttype ErrorContext,\n\ttype ExecuteHookInfo,\n\texecuteHooksInCatchBlock,\n\texecuteHooksInTryBlock,\n\ttype RetryContext,\n\ttype SuccessContext,\n} from \"./hooks\";\nimport { type CallApiPlugin, initializePlugins } from \"./plugins\";\nimport {\n\ttype ErrorInfo,\n\ttype GetResponseType,\n\tgetCustomizedErrorResult,\n\ttype ResponseTypeUnion,\n\ttype ResultModeUnion,\n\tresolveErrorResult,\n\tresolveResponseData,\n\tresolveSuccessResult,\n} from \"./result\";\nimport { createRetryStrategy } from \"./retry\";\nimport type {\n\tGetCurrentRouteSchema,\n\tGetCurrentRouteSchemaKey,\n\tInferHeadersOption,\n\tInferInitURL,\n\tThrowOnErrorUnion,\n} from \"./types\";\nimport type {\n\tBaseCallApiConfig,\n\tBaseCallApiExtraOptions,\n\tCallApiExtraOptions,\n\tCallApiExtraOptionsForHooks,\n\tCallApiParameters,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n\tCallApiResult,\n} from \"./types/common\";\nimport type { DefaultDataType, DefaultPluginArray, DefaultThrowOnError } from \"./types/default-types\";\nimport type { AnyFunction, Writeable } from \"./types/type-helpers\";\nimport { getFullAndNormalizedURL } from \"./url\";\nimport {\n\tcreateCombinedSignal,\n\tcreateTimeoutSignal,\n\tgetBody,\n\tgetHeaders,\n\tgetMethod,\n\tsplitBaseConfig,\n\tsplitConfig,\n\twaitFor,\n} from \"./utils/common\";\nimport { isFunction, isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/guards\";\nimport {\n\ttype BaseCallApiSchemaAndConfig,\n\ttype BaseCallApiSchemaRoutes,\n\ttype CallApiSchema,\n\ttype CallApiSchemaConfig,\n\thandleConfigValidation,\n\thandleSchemaValidation,\n\ttype InferSchemaOutputResult,\n} from \"./validation\";\n\nconst $GlobalRequestInfoCache: GlobalRequestInfoCache = new Map();\n\nexport const createFetchClient = <\n\tTBaseData = DefaultDataType,\n\tTBaseErrorData = DefaultDataType,\n\tTBaseResultMode extends ResultModeUnion = ResultModeUnion,\n\tTBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n\tTBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tconst TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig,\n\tconst TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTComputedBaseSchemaConfig extends CallApiSchemaConfig = NonNullable<\n\t\tWriteable<TBaseSchemaAndConfig[\"config\"], \"deep\">\n\t>,\n\tTComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = Writeable<\n\t\tTBaseSchemaAndConfig[\"routes\"],\n\t\t\"deep\"\n\t>,\n>(\n\tinitBaseConfig: BaseCallApiConfig<\n\t\tTBaseData,\n\t\tTBaseErrorData,\n\t\tTBaseResultMode,\n\t\tTBaseThrowOnError,\n\t\tTBaseResponseType,\n\t\tTBaseSchemaAndConfig,\n\t\tTBasePluginArray\n\t> = {} as never\n) => {\n\tconst $LocalRequestInfoCache: RequestInfoCache = new Map();\n\n\tconst callApi = async <\n\t\tTData = TBaseData,\n\t\tTErrorData = TBaseErrorData,\n\t\tTResultMode extends ResultModeUnion = TBaseResultMode,\n\t\tTThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError,\n\t\tTResponseType extends ResponseTypeUnion = TBaseResponseType,\n\t\tconst TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig,\n\t\tTInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<\n\t\t\tTComputedBaseSchemaRoutes,\n\t\t\tTSchemaConfig\n\t\t>,\n\t\tTCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<\n\t\t\tTSchemaConfig,\n\t\t\tTInitURL\n\t\t> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>,\n\t\tconst TSchema extends CallApiSchema = GetCurrentRouteSchema<\n\t\t\tTComputedBaseSchemaRoutes,\n\t\t\tTCurrentRouteSchemaKey\n\t\t>,\n\t\tconst TPluginArray extends CallApiPlugin[] = TBasePluginArray,\n\t>(\n\t\t...parameters: CallApiParameters<\n\t\t\tInferSchemaOutputResult<TSchema[\"data\"], GetResponseType<TData, TResponseType>>,\n\t\t\tInferSchemaOutputResult<TSchema[\"errorData\"], GetResponseType<TErrorData, TResponseType>>,\n\t\t\tTResultMode,\n\t\t\tTThrowOnError,\n\t\t\tTResponseType,\n\t\t\tTComputedBaseSchemaRoutes,\n\t\t\tTSchema,\n\t\t\tTComputedBaseSchemaConfig,\n\t\t\tTSchemaConfig,\n\t\t\tTInitURL,\n\t\t\tTCurrentRouteSchemaKey,\n\t\t\tTBasePluginArray,\n\t\t\tTPluginArray\n\t\t>\n\t): CallApiResult<\n\t\tInferSchemaOutputResult<TSchema[\"data\"], TData>,\n\t\tInferSchemaOutputResult<TSchema[\"errorData\"], TErrorData>,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType\n\t> => {\n\t\tconst [initURLOrURLObject, initConfig = {}] = parameters;\n\n\t\tconst [fetchOptions, extraOptions] = splitConfig(initConfig);\n\n\t\tconst resolvedBaseConfig =\n\t\t\tisFunction(initBaseConfig) ?\n\t\t\t\tinitBaseConfig({\n\t\t\t\t\tinitURL: initURLOrURLObject.toString(),\n\t\t\t\t\toptions: extraOptions,\n\t\t\t\t\trequest: fetchOptions,\n\t\t\t\t})\n\t\t\t:\tinitBaseConfig;\n\n\t\tconst baseConfig = resolvedBaseConfig as BaseCallApiExtraOptions & CallApiRequestOptions;\n\t\tconst config = initConfig as CallApiExtraOptions & CallApiRequestOptions;\n\n\t\tconst [baseFetchOptions, baseExtraOptions] = splitBaseConfig(baseConfig);\n\n\t\tconst shouldSkipAutoMergeForOptions =\n\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"options\";\n\n\t\tconst shouldSkipAutoMergeForRequest =\n\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"request\";\n\n\t\t// == Merged Extra Options\n\t\tconst mergedExtraOptions = {\n\t\t\t...baseExtraOptions,\n\t\t\t...(!shouldSkipAutoMergeForOptions && extraOptions),\n\t\t};\n\n\t\t// == Merged Request Options\n\t\tconst mergedRequestOptions = {\n\t\t\theaders: {}, // == Making sure headers is always an object\n\n\t\t\t...baseFetchOptions,\n\t\t\t...(!shouldSkipAutoMergeForRequest && fetchOptions),\n\t\t} satisfies CallApiRequestOptions;\n\n\t\tconst {\n\t\t\tresolvedCurrentRouteSchemaKey,\n\t\t\tresolvedHooks,\n\t\t\tresolvedInitURL,\n\t\t\tresolvedOptions,\n\t\t\tresolvedRequestOptions,\n\t\t} = await initializePlugins({\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tinitURL: initURLOrURLObject.toString(),\n\t\t\toptions: mergedExtraOptions as CallApiExtraOptionsForHooks,\n\t\t\trequest: mergedRequestOptions as CallApiRequestOptionsForHooks,\n\t\t});\n\n\t\tconst { fullURL, normalizedInitURL } = getFullAndNormalizedURL({\n\t\t\tbaseURL: resolvedOptions.baseURL,\n\t\t\tinitURL: resolvedInitURL,\n\t\t\tparams: resolvedOptions.params,\n\t\t\tquery: resolvedOptions.query,\n\t\t});\n\n\t\tlet options = {\n\t\t\t...resolvedOptions,\n\t\t\t...resolvedHooks,\n\n\t\t\tfullURL,\n\t\t\tinitURL: resolvedInitURL,\n\t\t\tinitURLNormalized: normalizedInitURL,\n\t\t} satisfies CallApiExtraOptionsForHooks;\n\n\t\tconst newFetchController = new AbortController();\n\n\t\tconst timeoutSignal = options.timeout != null ? createTimeoutSignal(options.timeout) : null;\n\n\t\tconst combinedSignal = createCombinedSignal(\n\t\t\tresolvedRequestOptions.signal,\n\t\t\ttimeoutSignal,\n\t\t\tnewFetchController.signal\n\t\t);\n\n\t\tconst initMethod = getMethod({ initURL: resolvedInitURL, method: resolvedRequestOptions.method });\n\n\t\tlet request = {\n\t\t\t...resolvedRequestOptions,\n\n\t\t\tmethod: initMethod,\n\t\t\tsignal: combinedSignal,\n\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\tconst {\n\t\t\tgetAbortErrorMessage,\n\t\t\thandleRequestCancelStrategy,\n\t\t\thandleRequestDeferStrategy,\n\t\t\tremoveDedupeKeyFromCache,\n\t\t\tresolvedDedupeStrategy,\n\t\t} = await createDedupeStrategy({\n\t\t\t$GlobalRequestInfoCache,\n\t\t\t$LocalRequestInfoCache,\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tnewFetchController,\n\t\t\toptions,\n\t\t\trequest,\n\t\t});\n\n\t\ttry {\n\t\t\tawait handleRequestCancelStrategy();\n\n\t\t\tawait executeHooksInTryBlock(options.onRequest?.({ baseConfig, config, options, request }));\n\n\t\t\tconst {\n\t\t\t\textraOptionsValidationResult,\n\t\t\t\trequestOptionsValidationResult,\n\t\t\t\tresolvedSchema,\n\t\t\t\tresolvedSchemaConfig,\n\t\t\t\tshouldApplySchemaOutput,\n\t\t\t} = await handleConfigValidation({\n\t\t\t\tbaseExtraOptions,\n\t\t\t\tcurrentRouteSchemaKey: resolvedCurrentRouteSchemaKey,\n\t\t\t\textraOptions,\n\t\t\t\toptions,\n\t\t\t\trequestOptions: request,\n\t\t\t});\n\n\t\t\t// == Apply Schema Output for Extra Options\n\t\t\tif (shouldApplySchemaOutput) {\n\t\t\t\toptions = { ...options, ...extraOptionsValidationResult };\n\t\t\t}\n\n\t\t\t// == Apply Schema Output for Request Options\n\t\t\tconst validMethod = getMethod({\n\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\tmethod: shouldApplySchemaOutput ? requestOptionsValidationResult?.method : request.method,\n\t\t\t});\n\n\t\t\tconst validBody = getBody({\n\t\t\t\tbody: shouldApplySchemaOutput ? requestOptionsValidationResult?.body : request.body,\n\t\t\t\tbodySerializer: options.bodySerializer,\n\t\t\t});\n\n\t\t\ttype HeaderFn = Extract<InferHeadersOption<CallApiSchema>[\"headers\"], AnyFunction>;\n\n\t\t\tconst resolvedHeaders =\n\t\t\t\tisFunction<HeaderFn>(fetchOptions.headers) ?\n\t\t\t\t\tfetchOptions.headers({ baseHeaders: baseFetchOptions.headers ?? {} })\n\t\t\t\t:\t(fetchOptions.headers ?? baseFetchOptions.headers);\n\n\t\t\tconst validHeaders = await getHeaders({\n\t\t\t\tauth: options.auth,\n\t\t\t\tbody: validBody,\n\t\t\t\theaders: shouldApplySchemaOutput ? requestOptionsValidationResult?.headers : resolvedHeaders,\n\t\t\t});\n\n\t\t\trequest = {\n\t\t\t\t...request,\n\t\t\t\t...(Boolean(validBody) && { body: validBody }),\n\t\t\t\t...(Boolean(validHeaders) && { headers: validHeaders }),\n\t\t\t\t...(Boolean(validMethod) && { method: validMethod }),\n\t\t\t};\n\n\t\t\tawait executeHooksInTryBlock(options.onRequestReady?.({ baseConfig, config, options, request }));\n\n\t\t\tconst response = await handleRequestDeferStrategy({ options, request });\n\n\t\t\t// == Also clone response when dedupeStrategy is set to \"defer\" to avoid error thrown from reading response.(whatever) more than once\n\t\t\tconst shouldCloneResponse = resolvedDedupeStrategy === \"defer\" || options.cloneResponse;\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst errorData = await resolveResponseData(\n\t\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\t\toptions.responseType,\n\t\t\t\t\toptions.responseParser\n\t\t\t\t);\n\n\t\t\t\tconst validErrorData = await handleSchemaValidation(resolvedSchema, \"errorData\", {\n\t\t\t\t\tinputValue: errorData,\n\t\t\t\t\tresponse,\n\t\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t\t});\n\n\t\t\t\t// == Push all error handling responsibilities to the catch block if not retrying\n\t\t\t\tthrow new HTTPError(\n\t\t\t\t\t{\n\t\t\t\t\t\tdefaultHTTPErrorMessage: options.defaultHTTPErrorMessage,\n\t\t\t\t\t\terrorData: validErrorData,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t},\n\t\t\t\t\t{ cause: validErrorData }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst successData = await resolveResponseData(\n\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\toptions.responseType,\n\t\t\t\toptions.responseParser\n\t\t\t);\n\n\t\t\tconst validSuccessData = await handleSchemaValidation(resolvedSchema, \"data\", {\n\t\t\t\tinputValue: successData,\n\t\t\t\tresponse,\n\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t});\n\n\t\t\tconst successContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tdata: validSuccessData,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse,\n\t\t\t} satisfies SuccessContext<unknown>;\n\n\t\t\tawait executeHooksInTryBlock(\n\t\t\t\toptions.onSuccess?.(successContext),\n\n\t\t\t\toptions.onResponse?.({ ...successContext, error: null })\n\t\t\t);\n\n\t\t\tconst successResult = resolveSuccessResult(successContext.data, {\n\t\t\t\tresponse: successContext.response,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t});\n\n\t\t\treturn successResult as never;\n\n\t\t\t// == Exhaustive Error handling\n\t\t} catch (error) {\n\t\t\tconst errorInfo = {\n\t\t\t\tcloneResponse: options.cloneResponse,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t} satisfies ErrorInfo;\n\n\t\t\tconst { errorDetails, generalErrorResult } = resolveErrorResult(error, errorInfo);\n\n\t\t\tconst errorContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\terror: errorDetails.error as never,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse: errorDetails.response as never,\n\t\t\t} satisfies ErrorContext<unknown>;\n\n\t\t\tconst shouldThrowOnError = Boolean(\n\t\t\t\tisFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError\n\t\t\t);\n\n\t\t\tconst hookInfo = {\n\t\t\t\terrorInfo,\n\t\t\t\tshouldThrowOnError,\n\t\t\t} satisfies ExecuteHookInfo;\n\n\t\t\tconst handleRetryOrGetErrorResult = async () => {\n\t\t\t\tconst { currentAttemptCount, getDelay, shouldAttemptRetry } =\n\t\t\t\t\tcreateRetryStrategy(errorContext);\n\n\t\t\t\tconst shouldRetry = await shouldAttemptRetry();\n\n\t\t\t\tif (shouldRetry) {\n\t\t\t\t\tconst retryContext = {\n\t\t\t\t\t\t...errorContext,\n\t\t\t\t\t\tretryAttemptCount: currentAttemptCount,\n\t\t\t\t\t} satisfies RetryContext<unknown>;\n\n\t\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t\t[options.onRetry?.(retryContext)],\n\t\t\t\t\t\thookInfo\n\t\t\t\t\t);\n\n\t\t\t\t\tif (hookError) {\n\t\t\t\t\t\treturn hookError;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst delay = getDelay();\n\n\t\t\t\t\tawait waitFor(delay);\n\n\t\t\t\t\tconst updatedOptions = {\n\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\"~retryAttemptCount\": currentAttemptCount + 1,\n\t\t\t\t\t} satisfies typeof config;\n\n\t\t\t\t\treturn callApi(initURLOrURLObject as never, updatedOptions as never) as never;\n\t\t\t\t}\n\n\t\t\t\tif (shouldThrowOnError) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\n\t\t\t\treturn generalErrorResult;\n\t\t\t};\n\n\t\t\tif (isValidationErrorInstance(error)) {\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[options.onValidationError?.(errorContext), options.onError?.(errorContext)],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t}\n\n\t\t\tif (isHTTPErrorInstance<TErrorData>(error)) {\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[\n\t\t\t\t\t\toptions.onResponseError?.(errorContext),\n\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t\toptions.onResponse?.({ ...errorContext, data: null }),\n\t\t\t\t\t],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t}\n\n\t\t\tlet message = (error as Error | undefined)?.message;\n\n\t\t\tif (error instanceof DOMException && error.name === \"AbortError\") {\n\t\t\t\tmessage = getAbortErrorMessage();\n\n\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t}\n\n\t\t\tif (error instanceof DOMException && error.name === \"TimeoutError\") {\n\t\t\t\tmessage = `Request timed out after ${options.timeout}ms`;\n\n\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t}\n\n\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t[options.onRequestError?.(errorContext), options.onError?.(errorContext)],\n\t\t\t\thookInfo\n\t\t\t);\n\n\t\t\treturn (hookError\n\t\t\t\t?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message })) as never;\n\n\t\t\t// == Removing the now unneeded AbortController from store\n\t\t} finally {\n\t\t\tremoveDedupeKeyFromCache();\n\t\t}\n\t};\n\n\treturn callApi;\n};\n\nexport const callApi = createFetchClient();\n","import type { CallApiPlugin } from \"./plugins\";\nimport type { ResponseTypeUnion, ResultModeUnion } from \"./result\";\nimport type {\n\tBaseCallApiConfig,\n\tCallApiExtraOptions,\n\tCallApiParameters,\n\tInferInitURL,\n\tThrowOnErrorUnion,\n} from \"./types\";\nimport type { DefaultDataType, DefaultPluginArray, DefaultThrowOnError } from \"./types/default-types\";\nimport type { AnyFunction, Writeable } from \"./types/type-helpers\";\nimport type {\n\tBaseCallApiSchemaAndConfig,\n\tBaseCallApiSchemaRoutes,\n\tCallApiSchema,\n\tCallApiSchemaConfig,\n} from \"./validation\";\n\nexport const defineSchema = <\n\tconst TBaseSchemaRoutes extends BaseCallApiSchemaRoutes,\n\tconst TSchemaConfig extends CallApiSchemaConfig,\n>(\n\troutes: TBaseSchemaRoutes,\n\tconfig?: TSchemaConfig\n) => {\n\treturn {\n\t\tconfig: defineSchemaConfig(config),\n\t\troutes: defineSchemaRoutes(routes),\n\t} satisfies BaseCallApiSchemaAndConfig;\n};\n\nexport const defineSchemaConfig = <const TConfig extends CallApiExtraOptions[\"schemaConfig\"]>(\n\tconfig: TConfig\n) => {\n\treturn config as NonNullable<Writeable<typeof config, \"deep\">>;\n};\n\nexport const defineSchemaRoutes = <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes>(\n\troutes: TBaseSchemaRoutes\n) => {\n\treturn routes as Writeable<typeof routes, \"deep\">;\n};\n\nexport const definePlugin = <\n\t// eslint-disable-next-line perfectionist/sort-union-types -- Let the first one be first\n\tconst TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>,\n>(\n\tplugin: TPlugin\n) => {\n\treturn plugin as Writeable<TPlugin, \"deep\">;\n};\n\nexport const defineBaseConfig = <const TBaseConfig extends BaseCallApiConfig>(baseConfig: TBaseConfig) => {\n\treturn baseConfig as Writeable<typeof baseConfig, \"deep\">;\n};\n\nexport const defineParameters = <\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResultMode extends ResultModeUnion = ResultModeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes,\n\tTSchema extends CallApiSchema = CallApiSchema,\n\tTBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig,\n\tTSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig,\n\tTInitURL extends InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig> = InferInitURL<\n\t\tBaseCallApiSchemaRoutes,\n\t\tTSchemaConfig\n\t>,\n\tTCurrentRouteSchemaKey extends string = string,\n\tTBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTPluginArray extends CallApiPlugin[] = DefaultPluginArray,\n>(\n\t...parameters: CallApiParameters<\n\t\tTData,\n\t\tTErrorData,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType,\n\t\tTBaseSchemaRoutes,\n\t\tTSchema,\n\t\tTBaseSchemaConfig,\n\t\tTSchemaConfig,\n\t\tTInitURL,\n\t\tTCurrentRouteSchemaKey,\n\t\tTBasePluginArray,\n\t\tTPluginArray\n\t>\n) => {\n\treturn parameters;\n};\n"],"mappings":";;;AAWA,MAAa,mBAA8B,UAAoB,YAA+B;CAC7F,mBAAmB,SAAS,aAAa;CACzC,YAAY,SAAS,MAAM;CAC3B,gBAAgB,SAAS,UAAU;CACnC,MAAM,YAAgC;EACrC,MAAM,OA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M;KAAM,CAAC;IACrD,EACD,SACA,IAEqB,MAAM,6BAA6B;GAG1D,IAAI,UAAW,OAA6B;AAE5C,OAAI,iBAAiB,gBAAgB,MAAM,SAAS,cAAc;AACjE,cAAU,sBAAsB;AAEhC,KAAC,sBAAsB,QAAQ,MAAM,GAAG,MAAM,KAAK,IAAI,QAAQ;;AAGhE,OAAI,iBAAiB,gBAAgB,MAAM,SAAS,gBAAgB;AACnE,cAAU,2BAA2B,QAAQ,QAAQ;AAErD,KAAC,sBAAsB,QAAQ,MAAM,GAAG,MAAM,KAAK,IAAI,QAAQ;;AAQhE,UALkB,MAAM,yBACvB,CAAC,QAAQ,iBAAiB,aAAa,EAAE,QAAQ,UAAU,aAAa,CAAC,EACzE,SACA,IAGG,yBAAyB,MAAM,6BAA6B,EAAE,EAAE,SAAS,CAAC;YAGrE;AACT,6BAA0B;;;AAI5B,QAAOA;;AAGR,MAAa,UAAU,mBAAmB;;;;AC7c1C,MAAa,gBAIZ,QACA,WACI;AACJ,QAAO;EACN,QAAQ,mBAAmB,OAAO;EAClC,QAAQ,mBAAmB,OAAO;EAClC;;AAGF,MAAa,sBACZ,WACI;AACJ,QAAO;;AAGR,MAAa,sBACZ,WACI;AACJ,QAAO;;AAGR,MAAa,gBAIZ,WACI;AACJ,QAAO;;AAGR,MAAa,oBAAiE,eAA4B;AACzG,QAAO;;AAGR,MAAa,oBAkBZ,GAAG,eAeC;AACJ,QAAO"}
1
+ {"version":3,"file":"index.js","names":["hookRegistries: HookRegistries","dedupeKey","$GlobalRequestInfoCache","middlewareRegistries: MiddlewareRegistries","composedMiddleware: Middlewares[keyof Middlewares]","resolvedHooks: Hooks","resolvedMiddlewares: Middlewares","$GlobalRequestInfoCache: GlobalRequestInfoCache","$LocalRequestInfoCache: RequestInfoCache","callApi"],"sources":["../../src/result.ts","../../src/hooks.ts","../../src/stream.ts","../../src/dedupe.ts","../../src/middlewares.ts","../../src/plugins.ts","../../src/retry.ts","../../src/createFetchClient.ts","../../src/defineHelpers.ts"],"sourcesContent":["import { extraOptionDefaults } from \"./constants/default-options\";\nimport type { HTTPError, ValidationError } from \"./error\";\nimport type { CallApiExtraOptions, ThrowOnErrorUnion } from \"./types\";\nimport type { DefaultDataType, DefaultThrowOnError } from \"./types/default-types\";\nimport type { AnyString, Awaitable, UnmaskType } from \"./types/type-helpers\";\nimport { isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/guards\";\n\nexport type ResponseType = \"blob\" | \"json\" | \"text\";\n\ntype Parser<TData> = (responseString: string) => Awaitable<TData>;\n\nexport const getResponseType = <TResponse>(response: Response, parser: Parser<TResponse>) => ({\n\tarrayBuffer: () => response.arrayBuffer(),\n\tblob: () => response.blob(),\n\tformData: () => response.formData(),\n\tjson: async (): Promise<TResponse> => {\n\t\tconst text = await response.text();\n\t\treturn parser(text);\n\t},\n\tstream: () => response.body,\n\ttext: () => response.text(),\n});\n\ntype InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;\n\nexport type ResponseTypeUnion = keyof InitResponseTypeMap | null;\n\nexport type ResponseTypeMap<TResponse> = {\n\t[Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>>;\n};\n\nexport type GetResponseType<\n\tTResponse,\n\tTResponseType extends ResponseTypeUnion,\n\tTComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>,\n> =\n\tnull extends TResponseType ? TComputedResponseTypeMap[\"json\"]\n\t: TResponseType extends NonNullable<ResponseTypeUnion> ? 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<ResponseTypeUnion, \"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 = <TResponse>(\n\tresponse: Response,\n\tresponseType: ResponseTypeUnion | undefined,\n\tparser: Parser<TResponse> | undefined\n) => {\n\tconst selectedParser = parser ?? extraOptionDefaults.responseParser;\n\tconst selectedResponseType = responseType ?? detectResponseType(response);\n\n\tconst RESPONSE_TYPE_LOOKUP = getResponseType<TResponse>(response, selectedParser);\n\n\tif (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, selectedResponseType)) {\n\t\tthrow new Error(`Invalid response type: ${responseType}`);\n\t}\n\n\treturn RESPONSE_TYPE_LOOKUP[selectedResponseType]();\n};\n\nexport type CallApiResultSuccessVariant<TData> = {\n\tdata: NoInfer<TData>;\n\terror: null;\n\tresponse: Response;\n};\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: NoInfer<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 PossibleJavaScriptOrValidationError = UnmaskType<\n\tPossibleJavaScriptError | PossibleValidationError\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: PossibleJavaScriptOrValidationError;\n\t\t\tresponse: Response | null;\n\t };\n\nexport type ResultModeMapWithoutException<\n\tTData,\n\tTErrorData,\n\tTResponseType extends ResponseTypeUnion,\n\tTComputedData = GetResponseType<TData, TResponseType>,\n\tTComputedErrorData = GetResponseType<TErrorData, TResponseType>,\n> = UnmaskType<{\n\tall: CallApiResultErrorVariant<TComputedErrorData> | CallApiResultSuccessVariant<TComputedData>;\n\n\tonlyData:\n\t\t| CallApiResultErrorVariant<TComputedErrorData>[\"data\"]\n\t\t| CallApiResultSuccessVariant<TComputedData>[\"data\"];\n}>;\n\ntype ResultModeMapWithException<\n\tTData,\n\tTResponseType extends ResponseTypeUnion,\n\tTComputedData = GetResponseType<TData, TResponseType>,\n> = {\n\tall: CallApiResultSuccessVariant<TComputedData>;\n\tonlyData: CallApiResultSuccessVariant<TComputedData>[\"data\"];\n};\n\nexport type ResultModeMap<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n> =\n\tTThrowOnError extends true ? ResultModeMapWithException<TData, TResponseType>\n\t:\tResultModeMapWithoutException<TData, TErrorData, TResponseType>;\n\ntype ResultModePlaceholder = null;\n\n// eslint-disable-next-line perfectionist/sort-union-types -- Allow\nexport type ResultModeUnion = keyof ResultModeMap | ResultModePlaceholder;\n\nexport type GetCallApiResult<\n\tTData,\n\tTErrorData,\n\tTResultMode extends ResultModeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion,\n\tTResponseType extends ResponseTypeUnion,\n> =\n\tTErrorData extends false ? ResultModeMapWithException<TData, TResponseType>[\"onlyData\"]\n\t: TErrorData extends false | undefined ? ResultModeMapWithException<TData, TResponseType>[\"onlyData\"]\n\t: ResultModePlaceholder extends TResultMode ?\n\t\tResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>[\"all\"]\n\t: TResultMode extends Exclude<ResultModeUnion, ResultModePlaceholder> ?\n\t\tResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>[TResultMode]\n\t:\tnever;\n\ntype SuccessInfo = {\n\tresponse: Response;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\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\tonlyData: () => details.data,\n\t};\n};\n\ntype SuccessResult = CallApiResultSuccessVariant<unknown> | null;\n\n// == The CallApiResult type is used to cast all return statements 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 = {\n\tcloneResponse: CallApiExtraOptions[\"cloneResponse\"];\n\tmessage?: string;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n};\n\ntype ErrorResult = {\n\terrorDetails: CallApiResultErrorVariant<unknown>;\n\tgeneralErrorResult: 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 generalErrorResult = resultModeMap[resultMode ?? \"all\"]() as never;\n\n\treturn {\n\t\terrorDetails,\n\t\tgeneralErrorResult,\n\t};\n};\n\nexport const getCustomizedErrorResult = (\n\terrorResult: ErrorResult[\"generalErrorResult\"],\n\tcustomErrorInfo: { message: string | undefined }\n): ErrorResult[\"generalErrorResult\"] => {\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[\"generalErrorResult\"]>[\"error\"] as never,\n\t};\n};\n","import {\n\ttype CallApiResultErrorVariant,\n\ttype CallApiResultSuccessVariant,\n\ttype ErrorInfo,\n\ttype PossibleHTTPError,\n\ttype PossibleJavaScriptError,\n\ttype PossibleJavaScriptOrValidationError,\n\ttype PossibleValidationError,\n\tresolveErrorResult,\n} from \"./result\";\nimport type { StreamProgressEvent } from \"./stream\";\nimport type {\n\tBaseCallApiExtraOptions,\n\tCallApiExtraOptions,\n\tCallApiExtraOptionsForHooks,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n} from \"./types/common\";\nimport type { DefaultDataType } from \"./types/default-types\";\nimport type { Awaitable, Prettify, UnmaskType } from \"./types/type-helpers\";\n\nexport type PluginExtraOptions<TPluginOptions = unknown> = {\n\t/** Plugin-specific options passed to the plugin configuration */\n\toptions: Partial<TPluginOptions>;\n};\n\n/* eslint-disable perfectionist/sort-intersection-types -- Plugin options should come last */\nexport interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOptions = unknown> {\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?: (\n\t\tcontext: ErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => 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 & PluginExtraOptions<TPluginOptions>) => 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?: (\n\t\tcontext: RequestErrorContext & PluginExtraOptions<TPluginOptions>\n\t) => 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 & PluginExtraOptions<TPluginOptions>) => 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?: (\n\t\tcontext: RequestStreamContext & PluginExtraOptions<TPluginOptions>\n\t) => 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?: (\n\t\tcontext: ResponseContext<TData, TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => 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?: (\n\t\tcontext: ResponseErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => 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?: (\n\t\tcontext: ResponseStreamContext & PluginExtraOptions<TPluginOptions>\n\t) => 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?: (\n\t\tresponse: RetryContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => 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<TData> & PluginExtraOptions<TPluginOptions>) => 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?: (\n\t\tcontext: ValidationErrorContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n}\n/* eslint-enable perfectionist/sort-intersection-types -- Plugin options should come last */\n\nexport type HooksOrHooksArray<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTMoreOptions = unknown,\n> = {\n\t[Key in keyof Hooks<TData, TErrorData, TMoreOptions>]:\n\t\t| Hooks<TData, TErrorData, TMoreOptions>[Key]\n\t\t// eslint-disable-next-line perfectionist/sort-union-types -- I need arrays to be last\n\t\t| Array<Hooks<TData, TErrorData, TMoreOptions>[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\t * @example\n\t * ```ts\n\t * // Parallel execution (default) - all hooks run simultaneously\n\t * hooksExecutionMode: \"parallel\"\n\t *\n\t * // Sequential execution - hooks run one after another\n\t * hooksExecutionMode: \"sequential\"\n\t *\n\t * // Use case: Hooks have dependencies and must run in order\n\t * const client = callApi.create({\n\t * hooksExecutionMode: \"sequential\",\n\t * plugins: [transformPlugin],\n\t * onRequest: (ctx) => {\n\t * // This runs first, then transform plugin runs\n\t * ctx.request.headers[\"x-request-id\"] = generateId();\n\t * }\n\t * });\n\t *\n\t * // Use case: Independent operations can run in parallel for speed\n\t * const client = callApi.create({\n\t * hooksExecutionMode: \"parallel\", // Default\n\t * plugins: [metricsPlugin, cachePlugin, loggingPlugin],\n\t * onRequest: (ctx) => {\n\t * // All hooks (main + plugins) run simultaneously\n\t * addRequestTimestamp(ctx.request);\n\t * }\n\t * });\n\t *\n\t * // Use case: Error handling hooks that need sequential processing\n\t * const client = callApi.create({\n\t * hooksExecutionMode: \"sequential\",\n\t * onError: [\n\t * (ctx) => logError(ctx.error), // Log first\n\t * (ctx) => reportError(ctx.error), // Then report\n\t * (ctx) => cleanupResources(ctx) // Finally cleanup\n\t * ]\n\t * });\n\t * ```\n\t */\n\thooksExecutionMode?: \"parallel\" | \"sequential\";\n}\n\nexport type RequestContext = {\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: BaseCallApiExtraOptions & CallApiRequestOptions;\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: CallApiExtraOptions & CallApiRequestOptions;\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;\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 ValidationErrorContext = UnmaskType<\n\tRequestContext & {\n\t\t/** Validation error containing details about what failed validation */\n\t\terror: PossibleValidationError;\n\t\t/** HTTP response object if validation failed on response, null if on request */\n\t\tresponse: Response | null;\n\t}\n>;\n\nexport type SuccessContext<TData> = UnmaskType<\n\tRequestContext & {\n\t\t/** Parsed response data with the expected success type */\n\t\tdata: TData;\n\t\t/** HTTP response object for the successful request */\n\t\tresponse: Response;\n\t}\n>;\n\nexport type ResponseContext<TData, TErrorData> = UnmaskType<\n\tRequestContext\n\t\t& (\n\t\t\t| Prettify<CallApiResultSuccessVariant<TData>>\n\t\t\t| Prettify<\n\t\t\t\t\tExtract<CallApiResultErrorVariant<TErrorData>, { error: PossibleHTTPError<TErrorData> }>\n\t\t\t >\n\t\t)\n>;\n\nexport type RequestErrorContext = RequestContext & {\n\t/** Error that occurred during the request (network, timeout, etc.) */\n\terror: PossibleJavaScriptError;\n\t/** Always null for request errors since no response was received */\n\tresponse: null;\n};\n\nexport type ErrorContext<TErrorData> = UnmaskType<\n\tRequestContext\n\t\t& (\n\t\t\t| {\n\t\t\t\t\t/** HTTP error with response data */\n\t\t\t\t\terror: PossibleHTTPError<TErrorData>;\n\t\t\t\t\t/** HTTP response object containing error status */\n\t\t\t\t\tresponse: Response;\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\t/** Request-level error (network, timeout, validation, etc.) */\n\t\t\t\t\terror: PossibleJavaScriptOrValidationError;\n\t\t\t\t\t/** Response object if available, null for request errors */\n\t\t\t\t\tresponse: Response | null;\n\t\t\t }\n\t\t)\n>;\n\nexport type ResponseErrorContext<TErrorData> = UnmaskType<\n\tExtract<ErrorContext<TErrorData>, { error: PossibleHTTPError<TErrorData> }> & RequestContext\n>;\n\nexport type RetryContext<TErrorData> = UnmaskType<\n\tErrorContext<TErrorData> & {\n\t\t/** Current retry attempt number (1-based, so 1 = first retry) */\n\t\tretryAttemptCount: number;\n\t}\n>;\n\nexport type RequestStreamContext = UnmaskType<\n\tRequestContext & {\n\t\t/** Progress event containing loaded/total bytes information */\n\t\tevent: StreamProgressEvent;\n\t\t/** The actual Request instance being uploaded */\n\t\trequestInstance: Request;\n\t}\n>;\n\nexport type ResponseStreamContext = UnmaskType<\n\tRequestContext & {\n\t\t/** Progress event containing loaded/total bytes information */\n\t\tevent: StreamProgressEvent;\n\t\t/** HTTP response object being downloaded */\n\t\tresponse: Response;\n\t}\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 composeAllHooks = (\n\thooksArray: Array<Hooks[keyof Hooks] | undefined>,\n\thooksExecutionMode: 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((uniqueHook) => uniqueHook?.(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 undefined;\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\tconst { generalErrorResult: hookErrorResult } = resolveErrorResult(hookError, errorInfo);\n\n\t\tif (shouldThrowOnError) {\n\t\t\tthrow hookError;\n\t\t}\n\n\t\treturn hookErrorResult;\n\t}\n};\n","import {\n\texecuteHooks,\n\ttype RequestContext,\n\ttype RequestStreamContext,\n\ttype ResponseStreamContext,\n} from \"./hooks\";\nimport { isObject, 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\ndeclare global {\n\tinterface ReadableStream<R> {\n\t\t[Symbol.asyncIterator]: () => AsyncIterableIterator<R>;\n\t}\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\tconst shouldForcefullyCalcStreamSize =\n\t\tisObject(options.forcefullyCalculateStreamSize) ?\n\t\t\toptions.forcefullyCalculateStreamSize.request\n\t\t:\toptions.forcefullyCalculateStreamSize;\n\n\t// == If no content length is present, we read the total bytes from the body\n\tif (!contentLength && shouldForcefullyCalcStreamSize) {\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 = async (context: StreamableResponseContext): Promise<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\tconst shouldForceContentLengthCalc =\n\t\tisObject(options.forcefullyCalculateStreamSize) ?\n\t\t\toptions.forcefullyCalculateStreamSize.response\n\t\t:\toptions.forcefullyCalculateStreamSize;\n\n\t// == If no content length is present and `forceContentLengthCalculation` is enabled, we read the total bytes from the body\n\tif (!contentLength && shouldForceContentLengthCalc) {\n\t\ttotalBytes = await calculateTotalBytesFromBody(response.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 = 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/default-options\";\nimport type { RequestContext } from \"./hooks\";\nimport { toStreamableRequest, toStreamableResponse } from \"./stream\";\nimport type { AnyString, RemovePrefix, UnmaskType } from \"./types/type-helpers\";\nimport { deterministicHashFn, waitFor } from \"./utils/common\";\nimport { isFunction } from \"./utils/guards\";\n\ntype RequestInfo = {\n\tcontroller: AbortController;\n\tresponsePromise: Promise<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\trequest: globalRequest,\n\t} = context;\n\n\tconst dedupeStrategy =\n\t\tglobalOptions.dedupeStrategy ?? globalOptions.dedupe?.strategy ?? 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 ?? globalOptions.dedupe?.key;\n\n\t\tif (dedupeKey) {\n\t\t\tconst resolvedDedupeKey = isFunction(dedupeKey) ? dedupeKey(context) : dedupeKey;\n\n\t\t\treturn resolvedDedupeKey;\n\t\t}\n\n\t\treturn `${globalOptions.fullURL}-${deterministicHashFn({ options: globalOptions, request: globalRequest })}`;\n\t};\n\n\tconst dedupeKey = getDedupeKey();\n\n\tconst dedupeCacheScope =\n\t\tglobalOptions.dedupeCacheScope\n\t\t?? globalOptions.dedupe?.cacheScope\n\t\t?? extraOptionDefaults.dedupeCacheScope;\n\n\tconst dedupeCacheScopeKey =\n\t\tglobalOptions.dedupeCacheScopeKey\n\t\t?? globalOptions.dedupe?.cacheScopeKey\n\t\t?? extraOptionDefaults.dedupeCacheScopeKey;\n\n\tif (dedupeCacheScope === \"global\" && !$GlobalRequestInfoCache.has(dedupeCacheScopeKey)) {\n\t\t$GlobalRequestInfoCache.set(dedupeCacheScopeKey, new Map());\n\t}\n\n\tconst $RequestInfoCache =\n\t\tdedupeCacheScope === \"global\" ?\n\t\t\t$GlobalRequestInfoCache.get(dedupeCacheScopeKey)\n\t\t:\t$LocalRequestInfoCache;\n\n\t// == This is to ensure cache operations only occur when key is available\n\tconst $RequestInfoCacheOrNull = dedupeKey !== null ? $RequestInfoCache : null;\n\n\t/******\n\t * == Add a small delay to the execution to ensure proper request deduplication when multiple requests with the same key start simultaneously.\n\t * == This gives time for the cache to be updated with the previous request info before the next request checks it.\n\t ******/\n\tif (dedupeKey !== null) {\n\t\tawait waitFor(0.1);\n\t}\n\n\tconst prevRequestInfo = $RequestInfoCacheOrNull?.get(dedupeKey);\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 aborted - 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\n\t\t// == Adding this just so that eslint forces me put await when calling the function (it looks better that way tbh)\n\t\treturn Promise.resolve();\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$RequestInfoCacheOrNull?.set(dedupeKey, { controller: newFetchController, responsePromise });\n\n\t\treturn toStreamableResponse({\n\t\t\t...streamableContext,\n\t\t\tresponse: await responsePromise,\n\t\t});\n\t};\n\n\tconst removeDedupeKeyFromCache = () => {\n\t\t$RequestInfoCacheOrNull?.delete(dedupeKey);\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\ntype DedupeOptionKeys = Exclude<keyof DedupeOptions, \"dedupe\">;\n\ntype InnerDedupeOptions = {\n\t[Key in DedupeOptionKeys as RemovePrefix<\"dedupe\", Key>]?: DedupeOptions[Key];\n};\n\nexport type DedupeOptions = {\n\t/**\n\t * All dedupe options in a single object instead of separate properties\n\t */\n\tdedupe?: InnerDedupeOptions;\n\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;\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);\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 { UnmaskType } from \"./types/type-helpers\";\n\nexport type FetchImpl = UnmaskType<\n\t(input: string | Request | URL, init?: RequestInit) => Promise<Response>\n>;\n\nexport interface Middlewares {\n\t/**\n\t * Wraps the fetch implementation to intercept requests at the network layer.\n\t *\n\t * Takes the current fetch function and returns a new one. Use it to cache responses,\n\t * add logging, handle offline mode, or short-circuit requests etc. Multiple middleware\n\t * 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 * fetchMiddleware: (fetchImpl) => async (input, init) => {\n\t * const key = input.toString();\n\t * if (cache.has(key)) return cache.get(key).clone();\n\t *\n\t * const response = await fetchImpl(input, init);\n\t * cache.set(key, response.clone());\n\t * return response;\n\t * }\n\t *\n\t * // Handle offline\n\t * fetchMiddleware: (fetchImpl) => async (input, init) => {\n\t * if (!navigator.onLine) {\n\t * return new Response('{\"error\": \"offline\"}', { status: 503 });\n\t * }\n\t * return fetchImpl(input, init);\n\t * }\n\t * ```\n\t */\n\tfetchMiddleware?: (fetchImpl: FetchImpl) => 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 composeAllMiddlewares = (\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\tcomposedMiddleware =\n\t\t\tpreviousMiddleware ?\n\t\t\t\t(fetchImpl) => currentMiddleware(previousMiddleware(fetchImpl))\n\t\t\t:\tcurrentMiddleware;\n\t}\n\n\treturn composedMiddleware;\n};\n","import { extraOptionDefaults } from \"./constants/default-options\";\nimport {\n\tcomposeAllHooks,\n\tgetHookRegistriesAndKeys,\n\ttype Hooks,\n\ttype HooksOrHooksArray,\n\ttype PluginExtraOptions,\n\ttype RequestContext,\n} from \"./hooks\";\nimport { composeAllMiddlewares, getMiddlewareRegistriesAndKeys, type Middlewares } from \"./middlewares\";\nimport type { CallApiRequestOptions, CallApiRequestOptionsForHooks } from \"./types/common\";\nimport type { Awaitable } from \"./types/type-helpers\";\nimport type { InitURLOrURLObject } from \"./url\";\nimport { isArray, isFunction, isPlainObject, isString } from \"./utils/guards\";\nimport { type BaseCallApiSchemaAndConfig, getCurrentRouteSchemaKeyAndMainInitURL } from \"./validation\";\n\nexport type PluginSetupContext<TPluginExtraOptions = unknown> = RequestContext // eslint-disable-next-line perfectionist/sort-intersection-types -- Allow\n\t& PluginExtraOptions<TPluginExtraOptions> & { initURL: string };\n\nexport type PluginInitResult = Partial<\n\tOmit<PluginSetupContext, \"initURL\" | \"request\"> & {\n\t\tinitURL: InitURLOrURLObject;\n\t\trequest: CallApiRequestOptions;\n\t}\n>;\n\nexport type PluginHooksWithMoreOptions<TMoreOptions = unknown> = HooksOrHooksArray<\n\tnever,\n\tnever,\n\tTMoreOptions\n>;\n\nexport type PluginHooks<TData = never, TErrorData = never, TMoreOptions = unknown> = HooksOrHooksArray<\n\tTData,\n\tTErrorData,\n\tTMoreOptions\n>;\n\nexport type PluginMiddlewares = Middlewares;\n\nexport interface CallApiPlugin {\n\t/**\n\t * Defines additional options that can be passed to callApi\n\t */\n\tdefineExtraOptions?: (...params: never[]) => unknown;\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?: PluginHooks | ((context: PluginSetupContext) => Awaitable<PluginHooks>);\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?: Middlewares | ((context: PluginSetupContext) => Awaitable<Middlewares>);\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?: (context: PluginSetupContext) => Awaitable<PluginInitResult> | Awaitable<void>;\n\n\t/**\n\t * A version for the plugin\n\t */\n\tversion?: string;\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 (context: PluginSetupContext) => {\n\tconst { baseConfig, config, initURL, options, request } = context;\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\tconst { currentRouteSchemaKey, mainInitURL } = getCurrentRouteSchemaKeyAndMainInitURL({\n\t\tbaseExtraOptions: baseConfig,\n\t\textraOptions: config,\n\t\tinitURL,\n\t});\n\n\tlet resolvedCurrentRouteSchemaKey = currentRouteSchemaKey;\n\tlet resolvedInitURL = mainInitURL;\n\tlet resolvedOptions = options;\n\tlet resolvedRequestOptions = request;\n\n\tconst executePluginSetupFn = async (pluginSetup: CallApiPlugin[\"setup\"]) => {\n\t\tif (!pluginSetup) return;\n\n\t\tconst initResult = await pluginSetup(context);\n\n\t\tif (!isPlainObject(initResult)) return;\n\n\t\tconst urlString = initResult.initURL?.toString();\n\n\t\tif (isString(urlString)) {\n\t\t\tconst newResult = 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 = newResult.currentRouteSchemaKey;\n\t\t\tresolvedInitURL = newResult.mainInitURL;\n\t\t}\n\n\t\tif (isPlainObject(initResult.request)) {\n\t\t\tresolvedRequestOptions = {\n\t\t\t\t...resolvedRequestOptions,\n\t\t\t\t...(initResult.request as CallApiRequestOptionsForHooks),\n\t\t\t};\n\t\t}\n\n\t\tif (isPlainObject(initResult.options)) {\n\t\t\tresolvedOptions = { ...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(context) : plugin.hooks,\n\t\t\tisFunction(plugin.middlewares) ? plugin.middlewares(context) : 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\tresolvedRequestOptions,\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 = composeAllHooks(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 = composeAllMiddlewares(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/default-options\";\nimport type { ErrorContext, RequestContext } from \"./hooks\";\nimport type { MethodUnion } from \"./types\";\nimport {\n\ttype AnyNumber,\n\ttype Awaitable,\n\tdefineEnum,\n\ttype RemovePrefix,\n\ttype UnmaskType,\n} from \"./types/type-helpers\";\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<TErrorData>) => Awaitable<boolean>;\n\ntype RetryOptionKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, \"~retryAttemptCount\" | \"retry\">;\n\ntype InnerRetryOptions<TErrorData> = {\n\t[Key in RetryOptionKeys<TErrorData> as RemovePrefix<\"retry\", Key>]?: RetryOptions<TErrorData>[Key];\n};\n\nexport interface RetryOptions<TErrorData> {\n\t/**\n\t * Keeps track of the number of times the request has already been retried\n\t *\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 * All retry options in a single object instead of separate properties\n\t */\n\tretry?: InnerRetryOptions<TErrorData>;\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 ?? options.retry?.delay;\n\n\tconst resolveRetryDelay =\n\t\t(isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay)\n\t\t?? extraOptionDefaults.retryDelay;\n\n\treturn resolveRetryDelay;\n};\n\nconst getExponentialDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? options.retry?.delay ?? extraOptionDefaults.retryDelay;\n\n\tconst resolvedRetryDelay = isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay;\n\n\tconst maxDelay = options.retryMaxDelay ?? options.retry?.maxDelay ?? extraOptionDefaults.retryMaxDelay;\n\n\tconst exponentialDelay = resolvedRetryDelay * 2 ** currentAttemptCount;\n\n\treturn Math.min(exponentialDelay, maxDelay);\n};\n\nexport const createRetryStrategy = (ctx: ErrorContext<unknown> & RequestContext) => {\n\tconst { options, request } = ctx;\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 =\n\t\toptions.retryStrategy ?? options.retry?.strategy ?? 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 =\n\t\t\toptions.retryCondition ?? options.retry?.condition ?? extraOptionDefaults.retryCondition;\n\n\t\tconst maximumRetryAttempts =\n\t\t\toptions.retryAttempts ?? options.retry?.attempts ?? extraOptionDefaults.retryAttempts;\n\n\t\tconst customRetryCondition = await retryCondition(ctx);\n\n\t\tconst baseShouldRetry = currentAttemptCount <= maximumRetryAttempts && customRetryCondition;\n\n\t\tif (!baseShouldRetry) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst retryMethods = new Set(\n\t\t\toptions.retryMethods ?? options.retry?.methods ?? extraOptionDefaults.retryMethods\n\t\t);\n\n\t\tconst includesMethod =\n\t\t\tisString(ctx.request.method) && retryMethods.size > 0 ?\n\t\t\t\tretryMethods.has(ctx.request.method)\n\t\t\t:\ttrue;\n\n\t\tconst retryStatusCodes = new Set(\n\t\t\toptions.retryStatusCodes ?? options.retry?.statusCodes ?? extraOptionDefaults.retryStatusCodes\n\t\t);\n\n\t\tconst includesStatusCodes =\n\t\t\tctx.response != null && retryStatusCodes.size > 0 ?\n\t\t\t\tretryStatusCodes.has(ctx.response.status)\n\t\t\t:\ttrue;\n\n\t\tconst shouldRetry = includesMethod && includesStatusCodes;\n\n\t\treturn shouldRetry;\n\t};\n\n\treturn {\n\t\tcurrentAttemptCount,\n\t\tgetDelay,\n\t\tshouldAttemptRetry,\n\t};\n};\n","import { createDedupeStrategy, type GlobalRequestInfoCache, type RequestInfoCache } from \"./dedupe\";\nimport { HTTPError } from \"./error\";\nimport {\n\ttype ErrorContext,\n\ttype ExecuteHookInfo,\n\texecuteHooks,\n\texecuteHooksInCatchBlock,\n\ttype RetryContext,\n\ttype SuccessContext,\n} from \"./hooks\";\nimport { type CallApiPlugin, initializePlugins } from \"./plugins\";\nimport {\n\ttype ErrorInfo,\n\ttype GetResponseType,\n\tgetCustomizedErrorResult,\n\ttype ResponseTypeUnion,\n\ttype ResultModeUnion,\n\tresolveErrorResult,\n\tresolveResponseData,\n\tresolveSuccessResult,\n} from \"./result\";\nimport { createRetryStrategy } from \"./retry\";\nimport type {\n\tGetCurrentRouteSchema,\n\tGetCurrentRouteSchemaKey,\n\tInferHeadersOption,\n\tInferInitURL,\n\tThrowOnErrorUnion,\n} from \"./types\";\nimport type {\n\tBaseCallApiConfig,\n\tBaseCallApiExtraOptions,\n\tCallApiExtraOptions,\n\tCallApiExtraOptionsForHooks,\n\tCallApiParameters,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n\tCallApiResult,\n} from \"./types/common\";\nimport type { DefaultDataType, DefaultPluginArray, DefaultThrowOnError } from \"./types/default-types\";\nimport type { AnyFunction, Writeable } from \"./types/type-helpers\";\nimport { getFullAndNormalizedURL } from \"./url\";\nimport {\n\tcreateCombinedSignal,\n\tcreateTimeoutSignal,\n\tgetBody,\n\tgetFetchImpl,\n\tgetHeaders,\n\tgetMethod,\n\tsplitBaseConfig,\n\tsplitConfig,\n\twaitFor,\n} from \"./utils/common\";\nimport { isFunction, isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/guards\";\nimport {\n\ttype BaseCallApiSchemaAndConfig,\n\ttype BaseCallApiSchemaRoutes,\n\ttype CallApiSchema,\n\ttype CallApiSchemaConfig,\n\thandleConfigValidation,\n\thandleSchemaValidation,\n\ttype InferSchemaOutputResult,\n} from \"./validation\";\n\nconst $GlobalRequestInfoCache: GlobalRequestInfoCache = new Map();\n\nexport const createFetchClient = <\n\tTBaseData = DefaultDataType,\n\tTBaseErrorData = DefaultDataType,\n\tTBaseResultMode extends ResultModeUnion = ResultModeUnion,\n\tTBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n\tTBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tconst TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig,\n\tconst TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTComputedBaseSchemaConfig extends CallApiSchemaConfig = NonNullable<\n\t\tWriteable<TBaseSchemaAndConfig[\"config\"], \"deep\">\n\t>,\n\tTComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = Writeable<\n\t\tTBaseSchemaAndConfig[\"routes\"],\n\t\t\"deep\"\n\t>,\n>(\n\tinitBaseConfig: BaseCallApiConfig<\n\t\tTBaseData,\n\t\tTBaseErrorData,\n\t\tTBaseResultMode,\n\t\tTBaseThrowOnError,\n\t\tTBaseResponseType,\n\t\tTBaseSchemaAndConfig,\n\t\tTBasePluginArray\n\t> = {} as never\n) => {\n\tconst $LocalRequestInfoCache: RequestInfoCache = new Map();\n\n\tconst callApi = async <\n\t\tTData = TBaseData,\n\t\tTErrorData = TBaseErrorData,\n\t\tTResultMode extends ResultModeUnion = TBaseResultMode,\n\t\tTThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError,\n\t\tTResponseType extends ResponseTypeUnion = TBaseResponseType,\n\t\tconst TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig,\n\t\tTInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<\n\t\t\tTComputedBaseSchemaRoutes,\n\t\t\tTSchemaConfig\n\t\t>,\n\t\tTCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<\n\t\t\tTSchemaConfig,\n\t\t\tTInitURL\n\t\t> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>,\n\t\tconst TSchema extends CallApiSchema = GetCurrentRouteSchema<\n\t\t\tTComputedBaseSchemaRoutes,\n\t\t\tTCurrentRouteSchemaKey\n\t\t>,\n\t\tconst TPluginArray extends CallApiPlugin[] = TBasePluginArray,\n\t>(\n\t\t...parameters: CallApiParameters<\n\t\t\tInferSchemaOutputResult<TSchema[\"data\"], GetResponseType<TData, TResponseType>>,\n\t\t\tInferSchemaOutputResult<TSchema[\"errorData\"], GetResponseType<TErrorData, TResponseType>>,\n\t\t\tTResultMode,\n\t\t\tTThrowOnError,\n\t\t\tTResponseType,\n\t\t\tTComputedBaseSchemaRoutes,\n\t\t\tTSchema,\n\t\t\tTComputedBaseSchemaConfig,\n\t\t\tTSchemaConfig,\n\t\t\tTInitURL,\n\t\t\tTCurrentRouteSchemaKey,\n\t\t\tTBasePluginArray,\n\t\t\tTPluginArray\n\t\t>\n\t): CallApiResult<\n\t\tInferSchemaOutputResult<TSchema[\"data\"], TData>,\n\t\tInferSchemaOutputResult<TSchema[\"errorData\"], TErrorData>,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType\n\t> => {\n\t\tconst [initURLOrURLObject, initConfig = {}] = parameters;\n\n\t\tconst [fetchOptions, extraOptions] = splitConfig(initConfig);\n\n\t\tconst resolvedBaseConfig =\n\t\t\tisFunction(initBaseConfig) ?\n\t\t\t\tinitBaseConfig({\n\t\t\t\t\tinitURL: initURLOrURLObject.toString(),\n\t\t\t\t\toptions: extraOptions,\n\t\t\t\t\trequest: fetchOptions,\n\t\t\t\t})\n\t\t\t:\tinitBaseConfig;\n\n\t\tconst baseConfig = resolvedBaseConfig as BaseCallApiExtraOptions & CallApiRequestOptions;\n\t\tconst config = initConfig as CallApiExtraOptions & CallApiRequestOptions;\n\n\t\tconst [baseFetchOptions, baseExtraOptions] = splitBaseConfig(baseConfig);\n\n\t\tconst shouldSkipAutoMergeForOptions =\n\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"options\";\n\n\t\tconst shouldSkipAutoMergeForRequest =\n\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"request\";\n\n\t\t// == Merged Extra Options\n\t\tconst mergedExtraOptions = {\n\t\t\t...baseExtraOptions,\n\t\t\t...(!shouldSkipAutoMergeForOptions && extraOptions),\n\t\t};\n\n\t\t// == Merged Request Options\n\t\tconst mergedRequestOptions = {\n\t\t\theaders: {}, // == Making sure headers is always an object\n\n\t\t\t...baseFetchOptions,\n\t\t\t...(!shouldSkipAutoMergeForRequest && fetchOptions),\n\t\t} satisfies CallApiRequestOptions;\n\n\t\tconst {\n\t\t\tresolvedCurrentRouteSchemaKey,\n\t\t\tresolvedHooks,\n\t\t\tresolvedInitURL,\n\t\t\tresolvedMiddlewares,\n\t\t\tresolvedOptions,\n\t\t\tresolvedRequestOptions,\n\t\t} = await initializePlugins({\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tinitURL: initURLOrURLObject.toString(),\n\t\t\toptions: mergedExtraOptions as CallApiExtraOptionsForHooks,\n\t\t\trequest: mergedRequestOptions as CallApiRequestOptionsForHooks,\n\t\t});\n\n\t\tconst { fullURL, normalizedInitURL } = getFullAndNormalizedURL({\n\t\t\tbaseURL: resolvedOptions.baseURL,\n\t\t\tinitURL: resolvedInitURL,\n\t\t\tparams: resolvedOptions.params,\n\t\t\tquery: resolvedOptions.query,\n\t\t});\n\n\t\tconst options = {\n\t\t\t...resolvedOptions,\n\t\t\t...resolvedHooks,\n\t\t\t...resolvedMiddlewares,\n\n\t\t\tfullURL,\n\t\t\tinitURL: resolvedInitURL,\n\t\t\tinitURLNormalized: normalizedInitURL,\n\t\t} satisfies CallApiExtraOptionsForHooks;\n\n\t\tconst newFetchController = new AbortController();\n\n\t\tconst timeoutSignal = options.timeout != null ? createTimeoutSignal(options.timeout) : null;\n\n\t\tconst combinedSignal = createCombinedSignal(\n\t\t\tresolvedRequestOptions.signal,\n\t\t\ttimeoutSignal,\n\t\t\tnewFetchController.signal\n\t\t);\n\n\t\tconst initMethod = getMethod({ initURL: resolvedInitURL, method: resolvedRequestOptions.method });\n\n\t\tconst request = {\n\t\t\t...resolvedRequestOptions,\n\n\t\t\tmethod: initMethod,\n\t\t\tsignal: combinedSignal,\n\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\tconst {\n\t\t\tgetAbortErrorMessage,\n\t\t\thandleRequestCancelStrategy,\n\t\t\thandleRequestDeferStrategy,\n\t\t\tremoveDedupeKeyFromCache,\n\t\t\tresolvedDedupeStrategy,\n\t\t} = await createDedupeStrategy({\n\t\t\t$GlobalRequestInfoCache,\n\t\t\t$LocalRequestInfoCache,\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tnewFetchController,\n\t\t\toptions,\n\t\t\trequest,\n\t\t});\n\n\t\ttry {\n\t\t\tawait handleRequestCancelStrategy();\n\n\t\t\tawait executeHooks(options.onRequest?.({ baseConfig, config, options, request }));\n\n\t\t\tconst {\n\t\t\t\textraOptionsValidationResult,\n\t\t\t\trequestOptionsValidationResult,\n\t\t\t\tresolvedSchema,\n\t\t\t\tresolvedSchemaConfig,\n\t\t\t\tshouldApplySchemaOutput,\n\t\t\t} = await handleConfigValidation({\n\t\t\t\tbaseExtraOptions,\n\t\t\t\tcurrentRouteSchemaKey: resolvedCurrentRouteSchemaKey,\n\t\t\t\textraOptions,\n\t\t\t\toptions,\n\t\t\t\trequestOptions: request,\n\t\t\t});\n\n\t\t\t// == Apply Schema Output for Extra Options\n\t\t\tif (shouldApplySchemaOutput) {\n\t\t\t\tObject.assign(options, extraOptionsValidationResult);\n\t\t\t}\n\n\t\t\t// == Apply Schema Output for Request Options\n\t\t\tconst validMethod = getMethod({\n\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\tmethod: shouldApplySchemaOutput ? requestOptionsValidationResult?.method : request.method,\n\t\t\t});\n\n\t\t\tconst validBody = getBody({\n\t\t\t\tbody: shouldApplySchemaOutput ? requestOptionsValidationResult?.body : request.body,\n\t\t\t\tbodySerializer: options.bodySerializer,\n\t\t\t});\n\n\t\t\ttype HeaderFn = Extract<InferHeadersOption<CallApiSchema>[\"headers\"], AnyFunction>;\n\n\t\t\tconst resolvedHeaders =\n\t\t\t\tisFunction<HeaderFn>(fetchOptions.headers) ?\n\t\t\t\t\tfetchOptions.headers({ baseHeaders: baseFetchOptions.headers ?? {} })\n\t\t\t\t:\t(fetchOptions.headers ?? baseFetchOptions.headers);\n\n\t\t\tconst validHeaders = await getHeaders({\n\t\t\t\tauth: options.auth,\n\t\t\t\tbody: validBody,\n\t\t\t\theaders: shouldApplySchemaOutput ? requestOptionsValidationResult?.headers : resolvedHeaders,\n\t\t\t});\n\n\t\t\tObject.assign(request, {\n\t\t\t\t...(validBody && { body: validBody }),\n\t\t\t\t...(validHeaders && { headers: validHeaders }),\n\t\t\t\t...(validMethod && { method: validMethod }),\n\t\t\t});\n\n\t\t\tawait executeHooks(options.onRequestReady?.({ baseConfig, config, options, request }));\n\n\t\t\tconst fetchApi = getFetchImpl(options.customFetchImpl, options.fetchMiddleware);\n\n\t\t\tconst response = await handleRequestDeferStrategy({ fetchApi, options, request });\n\n\t\t\t// == Also clone response when dedupeStrategy is set to \"defer\" to avoid error thrown from reading response.(whatever) more than once\n\t\t\tconst shouldCloneResponse = resolvedDedupeStrategy === \"defer\" || options.cloneResponse;\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst errorData = await resolveResponseData(\n\t\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\t\toptions.responseType,\n\t\t\t\t\toptions.responseParser\n\t\t\t\t);\n\n\t\t\t\tconst validErrorData = await handleSchemaValidation(resolvedSchema, \"errorData\", {\n\t\t\t\t\tinputValue: errorData,\n\t\t\t\t\tresponse,\n\t\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t\t});\n\n\t\t\t\t// == Push all error handling responsibilities to the catch block if not retrying\n\t\t\t\tthrow new HTTPError(\n\t\t\t\t\t{\n\t\t\t\t\t\tdefaultHTTPErrorMessage: options.defaultHTTPErrorMessage,\n\t\t\t\t\t\terrorData: validErrorData,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t},\n\t\t\t\t\t{ cause: validErrorData }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst successData = await resolveResponseData(\n\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\toptions.responseType,\n\t\t\t\toptions.responseParser\n\t\t\t);\n\n\t\t\tconst validSuccessData = await handleSchemaValidation(resolvedSchema, \"data\", {\n\t\t\t\tinputValue: successData,\n\t\t\t\tresponse,\n\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t});\n\n\t\t\tconst successContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tdata: validSuccessData,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse,\n\t\t\t} satisfies SuccessContext<unknown>;\n\n\t\t\tawait executeHooks(\n\t\t\t\toptions.onSuccess?.(successContext),\n\n\t\t\t\toptions.onResponse?.({ ...successContext, error: null })\n\t\t\t);\n\n\t\t\tconst successResult = resolveSuccessResult(successContext.data, {\n\t\t\t\tresponse: successContext.response,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t});\n\n\t\t\treturn successResult as never;\n\n\t\t\t// == Exhaustive Error handling\n\t\t} catch (error) {\n\t\t\tconst errorInfo = {\n\t\t\t\tcloneResponse: options.cloneResponse,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t} satisfies ErrorInfo;\n\n\t\t\tconst { errorDetails, generalErrorResult } = resolveErrorResult(error, errorInfo);\n\n\t\t\tconst errorContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\terror: errorDetails.error as never,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse: errorDetails.response as never,\n\t\t\t} satisfies ErrorContext<unknown>;\n\n\t\t\tconst shouldThrowOnError = Boolean(\n\t\t\t\tisFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError\n\t\t\t);\n\n\t\t\tconst hookInfo = {\n\t\t\t\terrorInfo,\n\t\t\t\tshouldThrowOnError,\n\t\t\t} satisfies ExecuteHookInfo;\n\n\t\t\tconst handleRetryOrGetErrorResult = async () => {\n\t\t\t\tconst { currentAttemptCount, getDelay, shouldAttemptRetry } =\n\t\t\t\t\tcreateRetryStrategy(errorContext);\n\n\t\t\t\tconst shouldRetry = await shouldAttemptRetry();\n\n\t\t\t\tif (shouldRetry) {\n\t\t\t\t\tconst retryContext = {\n\t\t\t\t\t\t...errorContext,\n\t\t\t\t\t\tretryAttemptCount: currentAttemptCount,\n\t\t\t\t\t} satisfies RetryContext<unknown>;\n\n\t\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t\t[options.onRetry?.(retryContext)],\n\t\t\t\t\t\thookInfo\n\t\t\t\t\t);\n\n\t\t\t\t\tif (hookError) {\n\t\t\t\t\t\treturn hookError;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst delay = getDelay();\n\n\t\t\t\t\tawait waitFor(delay);\n\n\t\t\t\t\tconst updatedOptions = {\n\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\"~retryAttemptCount\": currentAttemptCount + 1,\n\t\t\t\t\t} satisfies typeof config;\n\n\t\t\t\t\treturn callApi(initURLOrURLObject as never, updatedOptions as never) as never;\n\t\t\t\t}\n\n\t\t\t\tif (shouldThrowOnError) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\n\t\t\t\treturn generalErrorResult;\n\t\t\t};\n\n\t\t\tif (isValidationErrorInstance(error)) {\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[options.onValidationError?.(errorContext), options.onError?.(errorContext)],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t}\n\n\t\t\tif (isHTTPErrorInstance<TErrorData>(error)) {\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[\n\t\t\t\t\t\toptions.onResponseError?.(errorContext),\n\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t\toptions.onResponse?.({ ...errorContext, data: null }),\n\t\t\t\t\t],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t}\n\n\t\t\tlet message = (error as Error | undefined)?.message;\n\n\t\t\tif (error instanceof DOMException && error.name === \"AbortError\") {\n\t\t\t\tmessage = getAbortErrorMessage();\n\n\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t}\n\n\t\t\tif (error instanceof DOMException && error.name === \"TimeoutError\") {\n\t\t\t\tmessage = `Request timed out after ${options.timeout}ms`;\n\n\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t}\n\n\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t[options.onRequestError?.(errorContext), options.onError?.(errorContext)],\n\t\t\t\thookInfo\n\t\t\t);\n\n\t\t\treturn (hookError\n\t\t\t\t?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message })) as never;\n\n\t\t\t// == Removing the now unneeded AbortController from store\n\t\t} finally {\n\t\t\tremoveDedupeKeyFromCache();\n\t\t}\n\t};\n\n\treturn callApi;\n};\n\nexport const callApi = createFetchClient();\n","import type { CallApiPlugin } from \"./plugins\";\nimport type { ResponseTypeUnion, ResultModeUnion } from \"./result\";\nimport type {\n\tBaseCallApiConfig,\n\tCallApiExtraOptions,\n\tCallApiParameters,\n\tInferInitURL,\n\tThrowOnErrorUnion,\n} from \"./types\";\nimport type { DefaultDataType, DefaultPluginArray, DefaultThrowOnError } from \"./types/default-types\";\nimport type { AnyFunction, Writeable } from \"./types/type-helpers\";\nimport type {\n\tBaseCallApiSchemaAndConfig,\n\tBaseCallApiSchemaRoutes,\n\tCallApiSchema,\n\tCallApiSchemaConfig,\n} from \"./validation\";\n\nexport const defineSchema = <\n\tconst TBaseSchemaRoutes extends BaseCallApiSchemaRoutes,\n\tconst TSchemaConfig extends CallApiSchemaConfig,\n>(\n\troutes: TBaseSchemaRoutes,\n\tconfig?: TSchemaConfig\n) => {\n\treturn {\n\t\tconfig: defineSchemaConfig(config),\n\t\troutes: defineSchemaRoutes(routes),\n\t} satisfies BaseCallApiSchemaAndConfig;\n};\n\nexport const defineSchemaConfig = <const TConfig extends CallApiExtraOptions[\"schemaConfig\"]>(\n\tconfig: TConfig\n) => {\n\treturn config as NonNullable<Writeable<typeof config, \"deep\">>;\n};\n\nexport const defineSchemaRoutes = <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes>(\n\troutes: TBaseSchemaRoutes\n) => {\n\treturn routes as Writeable<typeof routes, \"deep\">;\n};\n\nexport const definePlugin = <\n\t// eslint-disable-next-line perfectionist/sort-union-types -- Let the first one be first\n\tconst TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>,\n>(\n\tplugin: TPlugin\n) => {\n\treturn plugin as Writeable<TPlugin, \"deep\">;\n};\n\nexport const defineBaseConfig = <const TBaseConfig extends BaseCallApiConfig>(baseConfig: TBaseConfig) => {\n\treturn baseConfig as Writeable<typeof baseConfig, \"deep\">;\n};\n\nexport const defineParameters = <\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResultMode extends ResultModeUnion = ResultModeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes,\n\tTSchema extends CallApiSchema = CallApiSchema,\n\tTBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig,\n\tTSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig,\n\tTInitURL extends InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig> = InferInitURL<\n\t\tBaseCallApiSchemaRoutes,\n\t\tTSchemaConfig\n\t>,\n\tTCurrentRouteSchemaKey extends string = string,\n\tTBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTPluginArray extends CallApiPlugin[] = DefaultPluginArray,\n>(\n\t...parameters: CallApiParameters<\n\t\tTData,\n\t\tTErrorData,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType,\n\t\tTBaseSchemaRoutes,\n\t\tTSchema,\n\t\tTBaseSchemaConfig,\n\t\tTSchemaConfig,\n\t\tTInitURL,\n\t\tTCurrentRouteSchemaKey,\n\t\tTBasePluginArray,\n\t\tTPluginArray\n\t>\n) => {\n\treturn parameters;\n};\n"],"mappings":";;;AAWA,MAAa,mBAA8B,UAAoB,YAA+B;CAC7F,mBAAmB,SAAS,aAAa;CACzC,YAAY,SAAS,MAAM;CAC3B,gBAAgB,SAAS,UAAU;CACnC,MAAM,YAAgC;AAErC,SAAO,OADM,MAAM,SAAS,MAAM,CACf;;CAEpB,cAAc,SAAS;CACvB,YAAY,SAAS,MAAM;CAC3B;AAmBD,MAAM,YAAY,IAAI,IAAI;CAAC;CAAa;CAAmB;CAAqB;CAAmB,CAAC;AACpG,MAAM,aAAa;AAEnB,MAAM,sBAAsB,aAA6E;CACxG,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,uBACZ,UACA,cACA,WACI;CACJ,MAAM,iBAAiB,UAAU,oBAAoB;CACrD,MAAM,uBAAuB,gBAAgB,mBAAmB,SAAS;CAEzE,MAAM,uBAAuB,gBAA2B,UAAU,eAAe;AAEjF,KAAI,CAAC,OAAO,OAAO,sBAAsB,qBAAqB,CAC7D,OAAM,IAAI,MAAM,0BAA0B,eAAe;AAG1D,QAAO,qBAAqB,uBAAuB;;AA4GpD,MAAM,oBAAoB,YAAqD;AAC9E,QAAO;E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;;AAGR,MAAa,sBACZ,WACI;AACJ,QAAO;;AAGR,MAAa,gBAIZ,WACI;AACJ,QAAO;;AAGR,MAAa,oBAAiE,eAA4B;AACzG,QAAO;;AAGR,MAAa,oBAkBZ,GAAG,eAeC;AACJ,QAAO"}
@@ -1,4 +1,4 @@
1
- import { CallApiExtraOptions, CallApiResultErrorVariant, HTTPError, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, ValidationError } from "../common-0nTMuN7U.js";
1
+ import { CallApiExtraOptions, CallApiResultErrorVariant, HTTPError, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, ValidationError } from "../common-BMWVqV15.js";
2
2
 
3
3
  //#region src/utils/common.d.ts
4
4
 
@@ -1,3 +1,3 @@
1
- import { isHTTPError, isHTTPErrorInstance, isJavascriptError, isValidationError, isValidationErrorInstance, toQueryString } from "../common-BFea9qeg.js";
1
+ import { isHTTPError, isHTTPErrorInstance, isJavascriptError, isValidationError, isValidationErrorInstance, toQueryString } from "../common-B2rPuIEQ.js";
2
2
 
3
3
  export { isHTTPError, isHTTPErrorInstance, isJavascriptError, isValidationError, isValidationErrorInstance, toQueryString };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/callapi",
3
3
  "type": "module",
4
- "version": "1.10.6",
4
+ "version": "1.11.1",
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",
@@ -41,15 +41,15 @@
41
41
  "@total-typescript/ts-reset": "0.6.1",
42
42
  "@vitest/browser": "^3.2.4",
43
43
  "@vitest/coverage-v8": "3.2.4",
44
- "@zayne-labs/prettier-config": "^0.9.17",
45
- "@zayne-labs/tsconfig": "0.9.17",
44
+ "@zayne-labs/prettier-config": "^0.10.6",
45
+ "@zayne-labs/tsconfig": "0.10.6",
46
46
  "concurrently": "^9.2.1",
47
- "cross-env": "^10.0.0",
47
+ "cross-env": "^10.1.0",
48
48
  "playwright": "^1.55.1",
49
49
  "publint": "^0.3.13",
50
50
  "size-limit": "11.2.0",
51
- "tsdown": "^0.15.4",
52
- "typescript": "5.9.2",
51
+ "tsdown": "^0.15.6",
52
+ "typescript": "5.9.3",
53
53
  "vitest": "^3.2.4",
54
54
  "zod": "^4.1.11"
55
55
  },