@zayne-labs/callapi 1.10.5 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,13 +18,140 @@
18
18
  </p>
19
19
 
20
20
  <p align="center">
21
- CallApi Fetch is an extra-lightweight wrapper over fetch that provides quality of life improvements beyond the bare fetch api, while keeping the API familiar.</p>
21
+ A modern fetch wrapper that actually makes HTTP requests enjoyable to work with.</p>
22
22
 
23
- It takes in a url and a request options object, just like fetch, but with some additional options to make your life easier. Check out the [API Reference](https://zayne-labs-callapi.netlify.app/docs/extra-options) for a quick look at the additional options.
23
+ CallApi keeps the familiar fetch API you know, but adds the features you've always wanted: automatic retries, request deduplication, smart response parsing, and proper error handling. No more writing the same boilerplate over and over.
24
24
 
25
- # Docs
25
+ ## Why CallApi?
26
26
 
27
- [View Documentation website](https://zayne-labs-callapi.netlify.app)
27
+ - **Drop-in replacement** - Same API as fetch, just better
28
+ - **Smart retries** - Exponential backoff, custom conditions
29
+ - **Request deduplication** - No more duplicate API calls
30
+ - **Auto response parsing** - JSON, text, or binary - it just works
31
+ - **Better error handling** - Structured errors you can actually use
32
+ - **Extensible** - Hooks and plugins for custom behavior
33
+ - **Tiny** - Under 6KB, zero dependencies
34
+
35
+ ## Quick Example
36
+
37
+ ```js
38
+ import { callApi } from "@zayne-labs/callapi";
39
+
40
+ // Simple request - response type detected automatically
41
+ const { data, error } = await callApi("/api/users");
42
+
43
+ // Create a configured client
44
+ import { createFetchClient } from "@zayne-labs/callapi";
45
+
46
+ const callBackendApi = createFetchClient({
47
+ baseURL: "https://api.example.com",
48
+ retryAttempts: 2,
49
+ timeout: 10000,
50
+ });
51
+
52
+ const user = await callBackendApi("/users/123");
53
+ ```
54
+
55
+ ## Key Features
56
+
57
+ ### Request Deduplication
58
+
59
+ Prevent duplicate requests automatically:
60
+
61
+ ```js
62
+ // These will share the same request
63
+ const req1 = callApi("/api/user");
64
+ const req2 = callApi("/api/user"); // Uses result from req1
65
+ ```
66
+
67
+ ### Smart Response Parsing
68
+
69
+ No more `response.json()` everywhere:
70
+
71
+ ```js
72
+ // Automatically parsed based on Content-Type
73
+ const { data } = await callApi("/api/data"); // JSON
74
+ const { data } = await callApi("/api/page"); // HTML text
75
+ const { data } = await callApi("/api/image.png"); // Blob
76
+ ```
77
+
78
+ ### Proper Error Handling
79
+
80
+ ```js
81
+ const { data, error } = await callApi("/api/users");
82
+
83
+ if (error) {
84
+ console.log(error.name); // "HTTPError", "ValidationError", etc.
85
+ console.log(error.message); // Human readable message
86
+ console.log(error.errorData); // Server response data
87
+ }
88
+ ```
89
+
90
+ ### URL Parameters & Query Strings
91
+
92
+ ```js
93
+ // Dynamic parameters
94
+ await callApi("/users/:id/posts/:postId", {
95
+ params: { id: 123, postId: 456 },
96
+ }); // → /users/123/posts/456
97
+
98
+ // Query parameters
99
+ await callApi("/search", {
100
+ query: { q: "javascript", limit: 10 },
101
+ }); // → /search?q=javascript&limit=10
102
+ ```
103
+
104
+ ### Schema Validation
105
+
106
+ Runtime validation with your favorite library:
107
+
108
+ ```js
109
+ import { z } from "zod";
110
+ import { defineSchema, createFetchClient } from "@zayne-labs/callapi";
111
+
112
+ // Client-level validation with route schemas
113
+ const callBackendApi = createFetchClient({
114
+ baseURL: "https://api.example.com",
115
+ schema: defineSchema({
116
+ "/users/:id": {
117
+ data: z.object({
118
+ id: z.number(),
119
+ name: z.string(),
120
+ email: z.string(),
121
+ }),
122
+ },
123
+ "/posts": {
124
+ data: z.array(
125
+ z.object({
126
+ id: z.number(),
127
+ title: z.string(),
128
+ })
129
+ ),
130
+ },
131
+ }),
132
+ });
133
+
134
+ // Automatically validated based on route (both at runtime and at the type level)
135
+ const user = await callBackendApi("/users/123"); // Typed as { id: number, name: string, email: string }
136
+ const posts = await callBackendApi("/posts"); // Typed as Array<{ id: number, title: string }>
137
+
138
+ // Per-request validation
139
+ import { callApi } from "@zayne-labs/callapi";
140
+
141
+ const userSchema = z.object({
142
+ id: z.number(),
143
+ name: z.string(),
144
+ });
145
+
146
+ const { data } = await callApi("/api/user", {
147
+ schema: { data: userSchema }, // Validates response
148
+ });
149
+ // data is now typed as { id: number, name: string }
150
+ ```
151
+
152
+ # Documentation
153
+
154
+ [Full documentation and examples →](https://zayne-labs-callapi.netlify.app)
28
155
 
29
156
  ## Installing `CallApi`
30
157
 
@@ -11,7 +11,6 @@ const extraOptionDefaults = () => {
11
11
  dedupeCacheScopeKey: "default",
12
12
  dedupeStrategy: "cancel",
13
13
  hooksExecutionMode: "parallel",
14
- hooksRegistrationOrder: "pluginsFirst",
15
14
  responseParser: JSON.parse,
16
15
  responseType: "json",
17
16
  resultMode: "all",
@@ -311,13 +310,12 @@ const handleConfigValidation = async (validationOptions) => {
311
310
  schema: resolvedSchema,
312
311
  schemaConfig: resolvedSchemaConfig
313
312
  })]);
314
- const shouldApplySchemaOutput = (Boolean(extraOptionsValidationResult) || Boolean(requestOptionsValidationResult)) && !resolvedSchemaConfig?.disableValidationOutputApplication;
315
313
  return {
316
314
  extraOptionsValidationResult,
317
315
  requestOptionsValidationResult,
318
316
  resolvedSchema,
319
317
  resolvedSchemaConfig,
320
- shouldApplySchemaOutput
318
+ shouldApplySchemaOutput: (Boolean(extraOptionsValidationResult) || Boolean(requestOptionsValidationResult)) && !resolvedSchemaConfig?.disableValidationOutputApplication
321
319
  };
322
320
  };
323
321
  const fallBackRouteSchemaKey = ".";
@@ -329,13 +327,12 @@ const getResolvedSchema = (context) => {
329
327
  ...fallbackRouteSchema,
330
328
  ...currentRouteSchema
331
329
  };
332
- const resolvedSchema = isFunction(extraOptions.schema) ? extraOptions.schema({
333
- baseSchemaRoutes: baseExtraOptions.schema?.routes ?? {},
334
- currentRouteSchema: resolvedRouteSchema ?? {}
335
- }) : extraOptions.schema ?? resolvedRouteSchema;
336
330
  return {
337
331
  currentRouteSchema,
338
- resolvedSchema
332
+ resolvedSchema: isFunction(extraOptions.schema) ? extraOptions.schema({
333
+ baseSchemaRoutes: baseExtraOptions.schema?.routes ?? {},
334
+ currentRouteSchema: resolvedRouteSchema ?? {}
335
+ }) : extraOptions.schema ?? resolvedRouteSchema
339
336
  };
340
337
  };
341
338
  const getResolvedSchemaConfig = (context) => {
@@ -443,8 +440,7 @@ const normalizeURL = (initURL) => {
443
440
  const getFullAndNormalizedURL = (options) => {
444
441
  const { baseURL, initURL, params, query } = options;
445
442
  const normalizedInitURL = normalizeURL(initURL);
446
- const urlWithMergedParams = mergeUrlWithParams(normalizedInitURL, params);
447
- const urlWithMergedQueryAndParams = mergeUrlWithQuery(urlWithMergedParams, query);
443
+ const urlWithMergedQueryAndParams = mergeUrlWithQuery(mergeUrlWithParams(normalizedInitURL, params), query);
448
444
  return {
449
445
  fullURL: !urlWithMergedQueryAndParams.startsWith("http") && baseURL ? `${baseURL}${urlWithMergedQueryAndParams}` : urlWithMergedQueryAndParams,
450
446
  normalizedInitURL
@@ -529,11 +525,15 @@ const getBody = (options) => {
529
525
  if (isSerializable(body)) return (bodySerializer ?? extraOptionDefaults().bodySerializer)(body);
530
526
  return body;
531
527
  };
532
- const getFetchImpl = (customFetchImpl) => {
528
+ const getInitFetchImpl = (customFetchImpl) => {
533
529
  if (customFetchImpl) return customFetchImpl;
534
530
  if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) return globalThis.fetch;
535
531
  throw new Error("No fetch implementation found");
536
532
  };
533
+ const getFetchImpl = (customFetchImpl, fetchMiddleware) => {
534
+ const initFetchApi = getInitFetchImpl(customFetchImpl);
535
+ return fetchMiddleware ? fetchMiddleware(initFetchApi) : initFetchApi;
536
+ };
537
537
  const PromiseWithResolvers = () => {
538
538
  let reject;
539
539
  let resolve;
@@ -574,4 +574,4 @@ const toArray = (value) => isArray(value) ? value : [value];
574
574
 
575
575
  //#endregion
576
576
  export { HTTPError, ValidationError, createCombinedSignal, createTimeoutSignal, deterministicHashFn, extraOptionDefaults, fallBackRouteSchemaKey, getBody, getCurrentRouteSchemaKeyAndMainInitURL, getFetchImpl, getFullAndNormalizedURL, getHeaders, getMethod, handleConfigValidation, handleSchemaValidation, isArray, isBoolean, isFunction, isHTTPError, isHTTPErrorInstance, isJavascriptError, isObject, isPlainObject, isReadableStream, isString, isValidationError, isValidationErrorInstance, splitBaseConfig, splitConfig, toQueryString, waitFor };
577
- //# sourceMappingURL=common-BFea9qeg.js.map
577
+ //# sourceMappingURL=common-CEcqiR7c.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-CEcqiR7c.js","names":["validatedResultObject: Prettify<\n\t\tPick<CallApiExtraOptions, (typeof extraOptionsToBeValidated)[number]>\n\t>","validatedResultObject: Prettify<\n\t\tPick<CallApiRequestOptions, (typeof requestOptionsToBeValidated)[number]>\n\t>","toQueryString: ToQueryStringFn","headersObject: Record<string, string | undefined>","reject!: (reason?: unknown) => void","resolve!: (value: unknown) => void","result: Record<string, unknown>"],"sources":["../../src/types/type-helpers.ts","../../src/constants/default-options.ts","../../src/error.ts","../../src/utils/guards.ts","../../src/auth.ts","../../src/constants/common.ts","../../src/validation.ts","../../src/url.ts","../../src/utils/polyfills.ts","../../src/utils/common.ts"],"sourcesContent":["// == These two types allows for adding arbitrary literal types, while still provided autocomplete for defaults.\n// == Usually intersection with \"{}\" or \"NonNullable<unknown>\" would make it work fine, but the placeholder with never type is added to make the AnyWhatever type appear last in a given union.\nexport type AnyString = string & NonNullable<unknown>;\nexport type AnyNumber = number & NonNullable<unknown>;\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is fine here\nexport type AnyObject = Record<keyof any, any>;\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is required here so that one can pass custom function type without type errors\nexport type AnyFunction<TResult = unknown> = (...args: any[]) => TResult;\n\nexport type CallbackFn<in TParams, out TResult = void> = (...params: TParams[]) => TResult;\n\nexport type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };\n\nexport type WriteableLevel = \"deep\" | \"shallow\";\n\n/**\n * Makes all properties in an object type writeable (removes readonly modifiers).\n * Supports both shallow and deep modes, and handles special cases like arrays, tuples, and unions.\n * @template TObject - The object type to make writeable\n * @template TVariant - The level of writeable transformation (\"shallow\" | \"deep\")\n */\n\ntype ArrayOrObject = Record<number | string | symbol, unknown> | unknown[];\n\nexport type Writeable<TObject, TLevel extends WriteableLevel = \"shallow\"> =\n\tTObject extends readonly [...infer TTupleItems] ?\n\t\t[\n\t\t\t...{\n\t\t\t\t[Index in keyof TTupleItems]: TLevel extends \"deep\" ? Writeable<TTupleItems[Index], \"deep\">\n\t\t\t\t:\tTTupleItems[Index];\n\t\t\t},\n\t\t]\n\t: TObject extends ArrayOrObject ?\n\t\t{\n\t\t\t-readonly [Key in keyof TObject]: TLevel extends \"deep\" ? Writeable<TObject[Key], \"deep\">\n\t\t\t:\tTObject[Key];\n\t\t}\n\t:\tTObject;\n\nexport const defineEnum = <const TValue extends object>(value: TValue) => value as Writeable<TValue>;\n\nexport type UnionToIntersection<TUnion> =\n\t(TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ?\n\t\tTParam\n\t:\tnever;\n\n// == Using this Immediately Indexed Mapped type helper to help show computed type of anything passed to it instead of just the type name\nexport type UnmaskType<TValue> = { _: TValue }[\"_\"];\n\nexport type Awaitable<TValue> = Promise<TValue> | TValue;\n\nexport type CommonRequestHeaders =\n\t| \"Access-Control-Allow-Credentials\"\n\t| \"Access-Control-Allow-Headers\"\n\t| \"Access-Control-Allow-Methods\"\n\t| \"Access-Control-Allow-Origin\"\n\t| \"Access-Control-Expose-Headers\"\n\t| \"Access-Control-Max-Age\"\n\t| \"Age\"\n\t| \"Allow\"\n\t| \"Cache-Control\"\n\t| \"Clear-Site-Data\"\n\t| \"Content-Disposition\"\n\t| \"Content-Encoding\"\n\t| \"Content-Language\"\n\t| \"Content-Length\"\n\t| \"Content-Location\"\n\t| \"Content-Range\"\n\t| \"Content-Security-Policy-Report-Only\"\n\t| \"Content-Security-Policy\"\n\t| \"Cookie\"\n\t| \"Cross-Origin-Embedder-Policy\"\n\t| \"Cross-Origin-Opener-Policy\"\n\t| \"Cross-Origin-Resource-Policy\"\n\t| \"Date\"\n\t| \"ETag\"\n\t| \"Expires\"\n\t| \"Last-Modified\"\n\t| \"Location\"\n\t| \"Permissions-Policy\"\n\t| \"Pragma\"\n\t| \"Retry-After\"\n\t| \"Save-Data\"\n\t| \"Sec-CH-Prefers-Color-Scheme\"\n\t| \"Sec-CH-Prefers-Reduced-Motion\"\n\t| \"Sec-CH-UA-Arch\"\n\t| \"Sec-CH-UA-Bitness\"\n\t| \"Sec-CH-UA-Form-Factor\"\n\t| \"Sec-CH-UA-Full-Version-List\"\n\t| \"Sec-CH-UA-Full-Version\"\n\t| \"Sec-CH-UA-Mobile\"\n\t| \"Sec-CH-UA-Model\"\n\t| \"Sec-CH-UA-Platform-Version\"\n\t| \"Sec-CH-UA-Platform\"\n\t| \"Sec-CH-UA-WoW64\"\n\t| \"Sec-CH-UA\"\n\t| \"Sec-Fetch-Dest\"\n\t| \"Sec-Fetch-Mode\"\n\t| \"Sec-Fetch-Site\"\n\t| \"Sec-Fetch-User\"\n\t| \"Sec-GPC\"\n\t| \"Server-Timing\"\n\t| \"Server\"\n\t| \"Service-Worker-Navigation-Preload\"\n\t| \"Set-Cookie\"\n\t| \"Strict-Transport-Security\"\n\t| \"Timing-Allow-Origin\"\n\t| \"Trailer\"\n\t| \"Transfer-Encoding\"\n\t| \"Upgrade\"\n\t| \"Vary\"\n\t| \"Warning\"\n\t| \"WWW-Authenticate\"\n\t| \"X-Content-Type-Options\"\n\t| \"X-DNS-Prefetch-Control\"\n\t| \"X-Frame-Options\"\n\t| \"X-Permitted-Cross-Domain-Policies\"\n\t| \"X-Powered-By\"\n\t| \"X-Robots-Tag\"\n\t| \"X-XSS-Protection\"\n\t| AnyString;\n\nexport type CommonAuthorizationHeaders = `${\"Basic\" | \"Bearer\" | \"Token\"} ${string}`;\n\nexport type CommonContentTypes =\n\t| \"application/epub+zip\"\n\t| \"application/gzip\"\n\t| \"application/json\"\n\t| \"application/ld+json\"\n\t| \"application/octet-stream\"\n\t| \"application/ogg\"\n\t| \"application/pdf\"\n\t| \"application/rtf\"\n\t| \"application/vnd.ms-fontobject\"\n\t| \"application/wasm\"\n\t| \"application/xhtml+xml\"\n\t| \"application/xml\"\n\t| \"application/zip\"\n\t| \"audio/aac\"\n\t| \"audio/mpeg\"\n\t| \"audio/ogg\"\n\t| \"audio/opus\"\n\t| \"audio/webm\"\n\t| \"audio/x-midi\"\n\t| \"font/otf\"\n\t| \"font/ttf\"\n\t| \"font/woff\"\n\t| \"font/woff2\"\n\t| \"image/avif\"\n\t| \"image/bmp\"\n\t| \"image/gif\"\n\t| \"image/jpeg\"\n\t| \"image/png\"\n\t| \"image/svg+xml\"\n\t| \"image/tiff\"\n\t| \"image/webp\"\n\t| \"image/x-icon\"\n\t| \"model/gltf-binary\"\n\t| \"model/gltf+json\"\n\t| \"text/calendar\"\n\t| \"text/css\"\n\t| \"text/csv\"\n\t| \"text/html\"\n\t| \"text/javascript\"\n\t| \"text/plain\"\n\t| \"video/3gpp\"\n\t| \"video/3gpp2\"\n\t| \"video/av1\"\n\t| \"video/mp2t\"\n\t| \"video/mp4\"\n\t| \"video/mpeg\"\n\t| \"video/ogg\"\n\t| \"video/webm\"\n\t| \"video/x-msvideo\"\n\t| AnyString;\n","import type { CallApiConfig, CallApiExtraOptions } from \"../types/common\";\nimport { defineEnum } from \"../types/type-helpers\";\n\nexport const extraOptionDefaults = () => {\n\treturn defineEnum({\n\t\t// Common defaults\n\t\tbodySerializer: JSON.stringify,\n\t\tdefaultHTTPErrorMessage: \"An unexpected error occurred during the HTTP request.\",\n\n\t\t// Dedupe defaults\n\t\t/* eslint-disable perfectionist/sort-objects -- Allow */\n\t\tdedupeCacheScope: \"local\",\n\t\tdedupeCacheScopeKey: \"default\",\n\t\tdedupeStrategy: \"cancel\",\n\t\t/* eslint-enable perfectionist/sort-objects -- Allow */\n\n\t\t// Hook defaults\n\t\thooksExecutionMode: \"parallel\",\n\n\t\t// Response defaults\n\t\tresponseParser: JSON.parse,\n\t\tresponseType: \"json\",\n\t\tresultMode: \"all\",\n\n\t\t// Retry Defaults\n\t\tretryAttempts: 0,\n\t\tretryCondition: () => true,\n\t\tretryDelay: 1000,\n\t\tretryMaxDelay: 10000,\n\t\tretryMethods: [\"GET\", \"POST\"],\n\t\tretryStatusCodes: [],\n\t\tretryStrategy: \"linear\",\n\t} satisfies CallApiExtraOptions);\n};\n\nexport const requestOptionDefaults = () => {\n\treturn defineEnum({\n\t\tmethod: \"GET\",\n\t} satisfies CallApiConfig);\n};\n","import { extraOptionDefaults } from \"./constants/default-options\";\nimport type { CallApiExtraOptions } from \"./types\";\nimport type { StandardSchemaV1 } from \"./types/standard-schema\";\nimport { isObject, isString } from \"./utils/guards\";\nimport type { CallApiSchema, CallApiSchemaConfig } from \"./validation\";\n\ntype HTTPErrorDetails<TErrorData> = Pick<CallApiExtraOptions, \"defaultHTTPErrorMessage\"> & {\n\terrorData: TErrorData;\n\tresponse: Response;\n};\n\nconst httpErrorSymbol = Symbol(\"HTTPError\");\n\nexport class HTTPError<TErrorData = Record<string, unknown>> extends Error {\n\terrorData: HTTPErrorDetails<TErrorData>[\"errorData\"];\n\n\treadonly httpErrorSymbol = httpErrorSymbol;\n\n\toverride name = \"HTTPError\" as const;\n\n\tresponse: HTTPErrorDetails<TErrorData>[\"response\"];\n\n\tconstructor(errorDetails: HTTPErrorDetails<TErrorData>, errorOptions?: ErrorOptions) {\n\t\tconst { defaultHTTPErrorMessage, errorData, response } = errorDetails;\n\n\t\tconst resolvedDefaultHTTPErrorMessage =\n\t\t\tisString(defaultHTTPErrorMessage) ? defaultHTTPErrorMessage : (\n\t\t\t\tdefaultHTTPErrorMessage?.({ errorData, response })\n\t\t\t);\n\n\t\tconst selectedDefaultErrorMessage =\n\t\t\tresolvedDefaultHTTPErrorMessage\n\t\t\t?? (response.statusText || extraOptionDefaults().defaultHTTPErrorMessage);\n\n\t\tconst message =\n\t\t\t(errorData as { message?: string } | undefined)?.message ?? selectedDefaultErrorMessage;\n\n\t\tsuper(message, errorOptions);\n\n\t\tthis.errorData = errorData;\n\t\tthis.response = response;\n\t}\n\n\t/**\n\t * @description Checks if the given error is an instance of HTTPError\n\t * @param error - The error to check\n\t * @returns true if the error is an instance of HTTPError, false otherwise\n\t */\n\tstatic override isError<TErrorData>(error: unknown): error is HTTPError<TErrorData> {\n\t\tif (!isObject<HTTPError>(error)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (error instanceof HTTPError) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst actualError = error as HTTPError;\n\n\t\treturn (\n\t\t\tactualError.httpErrorSymbol === httpErrorSymbol\n\t\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Allow\n\t\t\t&& actualError.name === \"HTTPError\"\n\t\t);\n\t}\n}\n\nconst prettifyPath = (path: ValidationError[\"errorData\"][number][\"path\"]) => {\n\tif (!path || path.length === 0) {\n\t\treturn \"\";\n\t}\n\n\tconst pathString = path.map((segment) => (isObject(segment) ? segment.key : segment)).join(\".\");\n\n\treturn ` → at ${pathString}`;\n};\n\nconst prettifyValidationIssues = (issues: ValidationError[\"errorData\"]) => {\n\tconst issuesString = issues\n\t\t.map((issue) => `✖ ${issue.message}${prettifyPath(issue.path)}`)\n\t\t.join(\" | \");\n\n\treturn issuesString;\n};\n\ntype LockedExtract<TUnion, TKey extends TUnion> = Extract<TUnion, TKey>;\n\ntype ValidationErrorDetails = {\n\t/**\n\t * The cause of the validation error.\n\t *\n\t * It's either the name the schema for which validation failed, or the name of the schema config option that led to the validation error.\n\t */\n\tissueCause:\n\t\t| \"unknown\"\n\t\t| `schemaConfig-(${LockedExtract<keyof CallApiSchemaConfig, \"strict\">})`\n\t\t| keyof CallApiSchema;\n\n\t/**\n\t * The issues that caused the validation error.\n\t */\n\tissues: readonly StandardSchemaV1.Issue[];\n\n\t/**\n\t * The response from server, if any.\n\t */\n\tresponse: Response | null;\n};\n\nconst validationErrorSymbol = Symbol(\"ValidationErrorSymbol\");\n\nexport class ValidationError extends Error {\n\terrorData: ValidationErrorDetails[\"issues\"];\n\n\tissueCause: ValidationErrorDetails[\"issueCause\"];\n\n\toverride name = \"ValidationError\" as const;\n\n\tresponse: ValidationErrorDetails[\"response\"];\n\n\treadonly validationErrorSymbol = validationErrorSymbol;\n\n\tconstructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions) {\n\t\tconst { issueCause, issues, response } = details;\n\n\t\tconst message = prettifyValidationIssues(issues);\n\n\t\tsuper(message, errorOptions);\n\n\t\tthis.errorData = issues;\n\t\tthis.response = response;\n\t\tthis.issueCause = issueCause;\n\t}\n\n\t/**\n\t * @description Checks if the given error is an instance of ValidationError\n\t * @param error - The error to check\n\t * @returns true if the error is an instance of ValidationError, false otherwise\n\t */\n\tstatic override isError(error: unknown): error is ValidationError {\n\t\tif (!isObject<ValidationError>(error)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (error instanceof ValidationError) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst actualError = error as ValidationError;\n\n\t\treturn (\n\t\t\tactualError.validationErrorSymbol === validationErrorSymbol\n\t\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Allow\n\t\t\t&& actualError.name === \"ValidationError\"\n\t\t);\n\t}\n}\n","import { HTTPError, ValidationError } from \"../error\";\nimport type {\n\tCallApiResultErrorVariant,\n\tPossibleHTTPError,\n\tPossibleJavaScriptError,\n\tPossibleValidationError,\n} from \"../result\";\nimport type { AnyFunction } from \"../types/type-helpers\";\n\nexport const isHTTPError = <TErrorData>(\n\terror: CallApiResultErrorVariant<TErrorData>[\"error\"] | null\n): error is PossibleHTTPError<TErrorData> => {\n\treturn isObject(error) && error.name === \"HTTPError\";\n};\n\nexport const isHTTPErrorInstance = <TErrorData>(error: unknown) => {\n\treturn HTTPError.isError<TErrorData>(error);\n};\n\nexport const isValidationError = (\n\terror: CallApiResultErrorVariant<unknown>[\"error\"] | null\n): error is PossibleValidationError => {\n\treturn isObject(error) && error.name === \"ValidationError\";\n};\n\nexport const isValidationErrorInstance = (error: unknown): error is ValidationError => {\n\treturn ValidationError.isError(error);\n};\n\nexport const isJavascriptError = (\n\terror: CallApiResultErrorVariant<unknown>[\"error\"] | null\n): error is PossibleJavaScriptError => {\n\treturn isObject(error) && !isHTTPError(error) && !isValidationError(error);\n};\n\nexport const isArray = <TArrayItem>(value: unknown): value is TArrayItem[] => Array.isArray(value);\n\nexport const isBoolean = (value: unknown): value is boolean => typeof value === \"boolean\";\n\nexport const isObject = <TObject extends object>(value: unknown): value is TObject => {\n\treturn typeof value === \"object\" && value !== null;\n};\n\nconst hasObjectPrototype = (value: unknown) => {\n\treturn Object.prototype.toString.call(value) === \"[object Object]\";\n};\n\n/**\n * @description Copied from TanStack Query's isPlainObject\n * @see https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L321\n */\nexport const isPlainObject = <TPlainObject extends Record<string, unknown>>(\n\tvalue: unknown\n): value is TPlainObject => {\n\tif (!hasObjectPrototype(value)) {\n\t\treturn false;\n\t}\n\n\t// If has no constructor\n\tconst constructor = (value as object | undefined)?.constructor;\n\tif (constructor === undefined) {\n\t\treturn true;\n\t}\n\n\t// If has modified prototype\n\tconst prototype = constructor.prototype as object;\n\tif (!hasObjectPrototype(prototype)) {\n\t\treturn false;\n\t}\n\n\t// If constructor does not have an Object-specific method\n\tif (!Object.hasOwn(prototype, \"isPrototypeOf\")) {\n\t\treturn false;\n\t}\n\n\t// Handles Objects created by Object.create(<arbitrary prototype>)\n\tif (Object.getPrototypeOf(value) !== Object.prototype) {\n\t\treturn false;\n\t}\n\n\t// It's probably a plain object at this point\n\treturn true;\n};\n\nexport const isValidJsonString = (value: unknown): value is string => {\n\tif (!isString(value)) {\n\t\treturn false;\n\t}\n\n\ttry {\n\t\tJSON.parse(value);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\nexport const isSerializable = (value: unknown) => {\n\treturn (\n\t\tisPlainObject(value)\n\t\t|| isArray(value)\n\t\t|| typeof (value as { toJSON: unknown } | undefined)?.toJSON === \"function\"\n\t);\n};\n\nexport const isFunction = <TFunction extends AnyFunction>(value: unknown): value is TFunction =>\n\ttypeof value === \"function\";\n\nexport const isQueryString = (value: unknown): value is string => isString(value) && value.includes(\"=\");\n\nexport const isString = (value: unknown) => typeof value === \"string\";\n\nexport const isPromise = (value: unknown) => value instanceof Promise;\n\nexport const isReadableStream = (value: unknown): value is ReadableStream<unknown> => {\n\treturn value instanceof ReadableStream;\n};\n\n// https://github.com/unjs/ofetch/blob/main/src/utils.ts\nexport const isJSONSerializable = (value: unknown) => {\n\tif (value === undefined) {\n\t\treturn false;\n\t}\n\tconst t = typeof value;\n\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- No time to make this more type-safe\n\tif (t === \"string\" || t === \"number\" || t === \"boolean\" || t === null) {\n\t\treturn true;\n\t}\n\tif (t !== \"object\") {\n\t\treturn false;\n\t}\n\tif (isArray(value)) {\n\t\treturn true;\n\t}\n\tif ((value as Buffer | null)?.buffer) {\n\t\treturn false;\n\t}\n\n\treturn (\n\t\t(value?.constructor && value.constructor.name === \"Object\")\n\t\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- Nullish coalescing makes no sense in this boolean context\n\t\t|| typeof (value as { toJSON: () => unknown } | null)?.toJSON === \"function\"\n\t);\n};\n","/* eslint-disable perfectionist/sort-object-types -- Avoid Sorting for now */\n\nimport type { CallApiExtraOptions } from \"./types/common\";\nimport type { Awaitable } from \"./types/type-helpers\";\nimport { isFunction, isObject, isPromise } from \"./utils/guards\";\n\ntype PossibleAuthValue = Awaitable<string | null | undefined>;\n\ntype PossibleAuthValueOrGetter = PossibleAuthValue | (() => PossibleAuthValue);\n\nexport type BearerOrTokenAuth =\n\t| {\n\t\t\ttype?: \"Bearer\";\n\t\t\tbearer?: PossibleAuthValueOrGetter;\n\t\t\ttoken?: never;\n\t }\n\t| {\n\t\t\ttype?: \"Token\";\n\t\t\tbearer?: never;\n\t\t\ttoken?: PossibleAuthValueOrGetter;\n\t };\n\nexport type BasicAuth = {\n\ttype: \"Basic\";\n\tusername: PossibleAuthValueOrGetter;\n\tpassword: PossibleAuthValueOrGetter;\n};\n\n/**\n * Custom auth\n *\n * @param prefix - prefix of the header\n * @param authValue - value of the header\n *\n * @example\n * ```ts\n * {\n * type: \"Custom\",\n * prefix: \"Token\",\n * authValue: \"token\"\n * }\n * ```\n */\nexport type CustomAuth = {\n\ttype: \"Custom\";\n\tprefix: PossibleAuthValueOrGetter;\n\tvalue: PossibleAuthValueOrGetter;\n};\n\n// eslint-disable-next-line perfectionist/sort-union-types -- Let the first one be first\nexport type Auth = PossibleAuthValueOrGetter | BearerOrTokenAuth | BasicAuth | CustomAuth;\n\nconst resolveAuthValue = (value: PossibleAuthValueOrGetter) => (isFunction(value) ? value() : value);\n\ntype AuthHeaderObject = { Authorization: string };\n\nexport const getAuthHeader = async (\n\tauth: CallApiExtraOptions[\"auth\"]\n): Promise<AuthHeaderObject | undefined> => {\n\tif (auth === undefined) return;\n\n\tif (isPromise(auth) || isFunction(auth) || !isObject(auth)) {\n\t\tconst authValue = await resolveAuthValue(auth);\n\n\t\tif (authValue === undefined) return;\n\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${authValue}`,\n\t\t};\n\t}\n\n\tswitch (auth.type) {\n\t\tcase \"Basic\": {\n\t\t\tconst [username, password] = await Promise.all([\n\t\t\t\tresolveAuthValue(auth.username),\n\t\t\t\tresolveAuthValue(auth.password),\n\t\t\t]);\n\n\t\t\tif (username === undefined || password === undefined) return;\n\n\t\t\treturn {\n\t\t\t\tAuthorization: `Basic ${globalThis.btoa(`${username}:${password}`)}`,\n\t\t\t};\n\t\t}\n\n\t\tcase \"Custom\": {\n\t\t\tconst [prefix, value] = await Promise.all([\n\t\t\t\tresolveAuthValue(auth.prefix),\n\t\t\t\tresolveAuthValue(auth.value),\n\t\t\t]);\n\n\t\t\tif (value === undefined) return;\n\n\t\t\treturn {\n\t\t\t\tAuthorization: `${prefix} ${value}`,\n\t\t\t};\n\t\t}\n\n\t\tdefault: {\n\t\t\tconst [bearer, token] = await Promise.all([\n\t\t\t\tresolveAuthValue(auth.bearer),\n\t\t\t\tresolveAuthValue(auth.token),\n\t\t\t]);\n\n\t\t\tif (bearer !== undefined) {\n\t\t\t\treturn { Authorization: `Bearer ${bearer}` };\n\t\t\t}\n\n\t\t\tif (token === undefined) return;\n\n\t\t\treturn { Authorization: `Token ${token}` };\n\t\t}\n\t}\n};\n","import type { ModifiedRequestInit } from \"../types\";\nimport { defineEnum } from \"../types/type-helpers\";\n\nexport const fetchSpecificKeys = defineEnum([\n\t\"body\",\n\t\"integrity\",\n\t\"duplex\",\n\t\"method\",\n\t\"headers\",\n\t\"signal\",\n\t\"cache\",\n\t\"redirect\",\n\t\"window\",\n\t\"credentials\",\n\t\"keepalive\",\n\t\"referrer\",\n\t\"priority\",\n\t\"mode\",\n\t\"referrerPolicy\",\n] satisfies Array<keyof ModifiedRequestInit> as Array<keyof ModifiedRequestInit>);\n","import { ValidationError } from \"./error\";\nimport type {\n\tBaseCallApiExtraOptions,\n\tBody,\n\tCallApiExtraOptions,\n\tCallApiRequestOptions,\n\tGlobalMeta,\n\tHeadersOption,\n\tMethodUnion,\n} from \"./types\";\nimport type { StandardSchemaV1 } from \"./types/standard-schema\";\nimport {\n\ttype AnyFunction,\n\ttype AnyString,\n\ttype Awaitable,\n\tdefineEnum,\n\ttype Prettify,\n\ttype UnionToIntersection,\n} from \"./types/type-helpers\";\nimport type { Params, Query } from \"./url\";\nimport { toArray } from \"./utils/common\";\nimport { isFunction } from \"./utils/guards\";\n\ntype InferSchemaInput<TSchema extends CallApiSchema[keyof CallApiSchema]> =\n\tTSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : never;\n\nexport type InferSchemaOutputResult<TSchema, TFallbackResult = unknown> =\n\t// == Checking for undefined first and returning fallback to avoid type errors when passing the config around (weird tbh)\n\tundefined extends TSchema ? TFallbackResult\n\t: TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema>\n\t: TSchema extends AnyFunction<infer TResult> ? Awaited<TResult>\n\t: TFallbackResult;\n\nexport type InferSchemaInputResult<TSchema, TFallbackResult = unknown> =\n\t// == Checking for undefined first and returning fallback to avoid type errors when passing the config around (weird tbh)\n\tundefined extends TSchema ? TFallbackResult\n\t: TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema>\n\t: TSchema extends AnyFunction<infer TResult> ? Awaited<TResult>\n\t: TFallbackResult;\n\nconst handleValidatorFunction = async <TInput>(\n\tvalidator: Extract<CallApiSchema[keyof CallApiSchema], AnyFunction>,\n\tinputData: TInput\n): Promise<StandardSchemaV1.Result<TInput>> => {\n\ttry {\n\t\tconst result = await validator(inputData as never);\n\n\t\treturn { issues: undefined, value: result as never };\n\t} catch (error) {\n\t\treturn { issues: toArray(error) as never, value: undefined };\n\t}\n};\n\nexport const standardSchemaParser = async <\n\tTFullSchema extends CallApiSchema,\n\tTSchemaName extends keyof CallApiSchema,\n\tTSchema extends NonNullable<TFullSchema[TSchemaName]>,\n>(\n\tfullSchema: TFullSchema | undefined,\n\tschemaName: TSchemaName,\n\tinputData: InferSchemaInput<TSchema>,\n\tresponse?: Response | null\n): Promise<InferSchemaOutputResult<TSchema>> => {\n\tconst schema = fullSchema?.[schemaName];\n\n\tif (!schema) {\n\t\treturn inputData as never;\n\t}\n\n\tconst result =\n\t\tisFunction(schema) ?\n\t\t\tawait handleValidatorFunction(schema, inputData)\n\t\t:\tawait schema[\"~standard\"].validate(inputData);\n\n\t// == If the `issues` field exists, it means the validation failed\n\n\tif (result.issues) {\n\t\tthrow new ValidationError({\n\t\t\tissueCause: schemaName,\n\t\t\tissues: result.issues,\n\t\t\tresponse: response ?? null,\n\t\t});\n\t}\n\n\treturn result.value as never;\n};\n\nexport interface CallApiSchemaConfig {\n\t/**\n\t * The base url of the schema. By default it's the baseURL of the callApi instance.\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * Disables runtime validation for the schema.\n\t */\n\tdisableRuntimeValidation?: boolean;\n\n\t/**\n\t * If `true`, the original input value will be used instead of the transformed/validated output.\n\t *\n\t * This is useful when you want to validate the input but don't want any transformations\n\t * applied by the validation schema (e.g., type coercion, default values, etc).\n\t */\n\tdisableValidationOutputApplication?: boolean;\n\n\t/**\n\t * Optional url prefix that will be substituted for the `baseURL` of the schemaConfig at runtime.\n\t *\n\t * This allows you to reuse the same schema against different base URLs (for example,\n\t * swapping between `/api/v1` and `/api/v2`) without redefining the entire schema.\n\t */\n\tprefix?: string;\n\n\t/**\n\t * Controls the strictness of API route validation.\n\t *\n\t * When true:\n\t * - Only routes explicitly defined in the schema will be considered valid to typescript and the runtime.\n\t * - Attempting to call routes not defined in the schema will result in both type errors and runtime validation errors.\n\t * - Useful for ensuring API calls conform exactly to your schema definition\n\t *\n\t * When false or undefined (default):\n\t * - All routes will be allowed, whether they are defined in the schema or not\n\t */\n\tstrict?: boolean;\n}\n\nexport interface CallApiSchema {\n\t/**\n\t * The schema to use for validating the request body.\n\t */\n\tbody?: StandardSchemaV1<Body> | ((body: Body) => Awaitable<Body>);\n\n\t/**\n\t * The schema to use for validating the response data.\n\t */\n\tdata?: StandardSchemaV1 | ((data: unknown) => unknown);\n\n\t/**\n\t * The schema to use for validating the response error data.\n\t */\n\terrorData?: StandardSchemaV1 | ((errorData: unknown) => unknown);\n\n\t/**\n\t * The schema to use for validating the request headers.\n\t */\n\theaders?:\n\t\t| StandardSchemaV1<HeadersOption | undefined>\n\t\t| ((headers: HeadersOption) => Awaitable<HeadersOption | undefined>);\n\n\t/**\n\t * The schema to use for validating the meta option.\n\t */\n\tmeta?:\n\t\t| StandardSchemaV1<GlobalMeta | undefined>\n\t\t| ((meta: GlobalMeta) => Awaitable<GlobalMeta | undefined>);\n\n\t/**\n\t * The schema to use for validating the request method.\n\t */\n\tmethod?:\n\t\t| StandardSchemaV1<MethodUnion | undefined>\n\t\t| ((method: MethodUnion) => Awaitable<MethodUnion | undefined>);\n\n\t/**\n\t * The schema to use for validating the request url parameters.\n\t */\n\tparams?: StandardSchemaV1<Params | undefined> | ((params: Params) => Awaitable<Params | undefined>);\n\n\t/**\n\t * The schema to use for validating the request url queries.\n\t */\n\tquery?: StandardSchemaV1<Query | undefined> | ((query: Query) => Awaitable<Query | undefined>);\n}\n\nexport const routeKeyMethods = defineEnum([\"delete\", \"get\", \"patch\", \"post\", \"put\"]);\n\nexport type RouteKeyMethods = (typeof routeKeyMethods)[number];\n\nexport type RouteKeyMethodsURLUnion = `@${RouteKeyMethods}/`;\n\nexport type BaseCallApiSchemaRoutes = Partial<Record<AnyString | RouteKeyMethodsURLUnion, CallApiSchema>>;\n\nexport type BaseCallApiSchemaAndConfig = {\n\tconfig?: CallApiSchemaConfig;\n\troutes: BaseCallApiSchemaRoutes;\n};\n\ntype ValidationOptions<\n\tTSchema extends CallApiSchema[keyof CallApiSchema] = CallApiSchema[keyof CallApiSchema],\n> = {\n\tinputValue: InferSchemaInput<TSchema>;\n\tresponse?: Response | null;\n\tschemaConfig: CallApiSchemaConfig | undefined;\n};\n\nexport const handleSchemaValidation = async <\n\tTFullSchema extends CallApiSchema,\n\tTSchemaName extends keyof CallApiSchema,\n\tTSchema extends NonNullable<TFullSchema[TSchemaName]>,\n>(\n\tfullSchema: TFullSchema | undefined,\n\tschemaName: TSchemaName,\n\tvalidationOptions: ValidationOptions<TSchema>\n): Promise<InferSchemaOutputResult<TSchema>> => {\n\tconst { inputValue, response, schemaConfig } = validationOptions;\n\n\tif (schemaConfig?.disableRuntimeValidation) {\n\t\treturn inputValue as never;\n\t}\n\n\tconst validResult = await standardSchemaParser(fullSchema, schemaName, inputValue, response);\n\n\treturn validResult as never;\n};\n\ntype LastOf<TValue> =\n\tUnionToIntersection<TValue extends unknown ? () => TValue : never> extends () => infer R ? R : never;\n\ntype Push<TArray extends unknown[], TArrayItem> = [...TArray, TArrayItem];\n\ntype UnionToTuple<\n\tTUnion,\n\tTComputedLastUnion = LastOf<TUnion>,\n\tTComputedIsUnionEqualToNever = [TUnion] extends [never] ? true : false,\n> =\n\ttrue extends TComputedIsUnionEqualToNever ? []\n\t:\tPush<UnionToTuple<Exclude<TUnion, TComputedLastUnion>>, TComputedLastUnion>;\n\nexport type Tuple<TTuple, TArray extends TTuple[] = []> =\n\tUnionToTuple<TTuple>[\"length\"] extends TArray[\"length\"] ? [...TArray]\n\t:\tTuple<TTuple, [TTuple, ...TArray]>;\n\nconst extraOptionsToBeValidated = [\"meta\", \"params\", \"query\"] satisfies Tuple<\n\tExtract<keyof CallApiSchema, keyof CallApiExtraOptions>\n>;\n\ntype ExtraOptionsValidationOptions = {\n\toptions: CallApiExtraOptions;\n\tschema: CallApiSchema | undefined;\n\tschemaConfig: CallApiSchemaConfig | undefined;\n};\n\nconst handleExtraOptionsValidation = async (validationOptions: ExtraOptionsValidationOptions) => {\n\tconst { options, schema, schemaConfig } = validationOptions;\n\n\tconst validationResultArray = await Promise.all(\n\t\textraOptionsToBeValidated.map((schemaName) =>\n\t\t\thandleSchemaValidation(schema, schemaName, {\n\t\t\t\tinputValue: options[schemaName],\n\t\t\t\tschemaConfig,\n\t\t\t})\n\t\t)\n\t);\n\n\tconst validatedResultObject: Prettify<\n\t\tPick<CallApiExtraOptions, (typeof extraOptionsToBeValidated)[number]>\n\t> = {};\n\n\tfor (const [index, schemaName] of extraOptionsToBeValidated.entries()) {\n\t\tconst validationResult = validationResultArray[index];\n\n\t\tif (validationResult === undefined) continue;\n\n\t\tvalidatedResultObject[schemaName] = validationResult as never;\n\t}\n\n\treturn validatedResultObject;\n};\n\nconst requestOptionsToBeValidated = [\"body\", \"headers\", \"method\"] satisfies Tuple<\n\tExtract<keyof CallApiSchema, keyof CallApiRequestOptions>\n>;\n\ntype RequestOptionsValidationOptions = {\n\trequestOptions: CallApiRequestOptions;\n\tschema: CallApiSchema | undefined;\n\tschemaConfig: CallApiSchemaConfig | undefined;\n};\n\nconst handleRequestOptionsValidation = async (validationOptions: RequestOptionsValidationOptions) => {\n\tconst { requestOptions, schema, schemaConfig } = validationOptions;\n\n\tconst validationResultArray = await Promise.all(\n\t\trequestOptionsToBeValidated.map((schemaName) =>\n\t\t\thandleSchemaValidation(schema, schemaName, {\n\t\t\t\tinputValue: requestOptions[schemaName],\n\t\t\t\tschemaConfig,\n\t\t\t})\n\t\t)\n\t);\n\n\tconst validatedResultObject: Prettify<\n\t\tPick<CallApiRequestOptions, (typeof requestOptionsToBeValidated)[number]>\n\t> = {};\n\n\tfor (const [index, propertyKey] of requestOptionsToBeValidated.entries()) {\n\t\tconst validationResult = validationResultArray[index];\n\n\t\tif (validationResult === undefined) continue;\n\n\t\tvalidatedResultObject[propertyKey] = validationResult as never;\n\t}\n\n\treturn validatedResultObject;\n};\n\nexport const handleConfigValidation = async (\n\tvalidationOptions: GetResolvedSchemaContext\n\t\t& Omit<ExtraOptionsValidationOptions & RequestOptionsValidationOptions, \"schema\" | \"schemaConfig\">\n) => {\n\tconst { baseExtraOptions, currentRouteSchemaKey, extraOptions, options, requestOptions } =\n\t\tvalidationOptions;\n\n\tconst { currentRouteSchema, resolvedSchema } = getResolvedSchema({\n\t\tbaseExtraOptions,\n\t\tcurrentRouteSchemaKey,\n\t\textraOptions,\n\t});\n\n\tconst resolvedSchemaConfig = getResolvedSchemaConfig({ baseExtraOptions, extraOptions });\n\n\tif (resolvedSchemaConfig?.strict === true && !currentRouteSchema) {\n\t\tthrow new ValidationError({\n\t\t\tissueCause: \"schemaConfig-(strict)\",\n\t\t\tissues: [{ message: `Strict Mode - No schema found for route '${currentRouteSchemaKey}' ` }],\n\t\t\tresponse: null,\n\t\t});\n\t}\n\n\tif (resolvedSchemaConfig?.disableRuntimeValidation) {\n\t\treturn {\n\t\t\textraOptionsValidationResult: null,\n\t\t\trequestOptionsValidationResult: null,\n\t\t\tresolvedSchema,\n\t\t\tresolvedSchemaConfig,\n\t\t\tshouldApplySchemaOutput: false,\n\t\t};\n\t}\n\n\tconst [extraOptionsValidationResult, requestOptionsValidationResult] = await Promise.all([\n\t\thandleExtraOptionsValidation({\n\t\t\toptions,\n\t\t\tschema: resolvedSchema,\n\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t}),\n\t\thandleRequestOptionsValidation({\n\t\t\trequestOptions,\n\t\t\tschema: resolvedSchema,\n\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t}),\n\t]);\n\n\tconst shouldApplySchemaOutput =\n\t\t(Boolean(extraOptionsValidationResult) || Boolean(requestOptionsValidationResult))\n\t\t&& !resolvedSchemaConfig?.disableValidationOutputApplication;\n\n\treturn {\n\t\textraOptionsValidationResult,\n\t\trequestOptionsValidationResult,\n\t\tresolvedSchema,\n\t\tresolvedSchemaConfig,\n\t\tshouldApplySchemaOutput,\n\t};\n};\n\ntype GetResolvedSchemaContext = {\n\tbaseExtraOptions: BaseCallApiExtraOptions;\n\tcurrentRouteSchemaKey: string;\n\textraOptions: CallApiExtraOptions;\n};\n\nexport const fallBackRouteSchemaKey = \".\";\n\nexport type FallBackRouteSchemaKey = typeof fallBackRouteSchemaKey;\n\nexport const getResolvedSchema = (context: GetResolvedSchemaContext) => {\n\tconst { baseExtraOptions, currentRouteSchemaKey, extraOptions } = context;\n\n\tconst fallbackRouteSchema = baseExtraOptions.schema?.routes[fallBackRouteSchemaKey];\n\tconst currentRouteSchema = baseExtraOptions.schema?.routes[currentRouteSchemaKey];\n\n\tconst resolvedRouteSchema = {\n\t\t...fallbackRouteSchema,\n\t\t// == Current route schema takes precedence over fallback route schema\n\t\t...currentRouteSchema,\n\t} satisfies CallApiSchema as CallApiSchema | undefined;\n\n\tconst resolvedSchema =\n\t\tisFunction(extraOptions.schema) ?\n\t\t\textraOptions.schema({\n\t\t\t\tbaseSchemaRoutes: baseExtraOptions.schema?.routes ?? {},\n\t\t\t\tcurrentRouteSchema: resolvedRouteSchema ?? {},\n\t\t\t})\n\t\t:\t(extraOptions.schema ?? resolvedRouteSchema);\n\n\treturn { currentRouteSchema, resolvedSchema };\n};\n\nexport const getResolvedSchemaConfig = (\n\tcontext: Omit<GetResolvedSchemaContext, \"currentRouteSchemaKey\">\n) => {\n\tconst { baseExtraOptions, extraOptions } = context;\n\n\tconst resolvedSchemaConfig =\n\t\tisFunction(extraOptions.schemaConfig) ?\n\t\t\textraOptions.schemaConfig({ baseSchemaConfig: baseExtraOptions.schema?.config ?? {} })\n\t\t:\t(extraOptions.schemaConfig ?? baseExtraOptions.schema?.config);\n\n\treturn resolvedSchemaConfig;\n};\n\nexport const getCurrentRouteSchemaKeyAndMainInitURL = (\n\tcontext: Pick<GetResolvedSchemaContext, \"baseExtraOptions\" | \"extraOptions\"> & { initURL: string }\n) => {\n\tconst { baseExtraOptions, extraOptions, initURL } = context;\n\n\tconst schemaConfig = getResolvedSchemaConfig({ baseExtraOptions, extraOptions });\n\n\tlet currentRouteSchemaKey = initURL;\n\tlet mainInitURL = initURL;\n\n\tif (schemaConfig?.prefix && currentRouteSchemaKey.startsWith(schemaConfig.prefix)) {\n\t\tcurrentRouteSchemaKey = currentRouteSchemaKey.replace(schemaConfig.prefix, \"\");\n\n\t\tmainInitURL = mainInitURL.replace(schemaConfig.prefix, schemaConfig.baseURL ?? \"\");\n\t}\n\n\tif (schemaConfig?.baseURL && currentRouteSchemaKey.startsWith(schemaConfig.baseURL)) {\n\t\tcurrentRouteSchemaKey = currentRouteSchemaKey.replace(schemaConfig.baseURL, \"\");\n\t}\n\n\treturn { currentRouteSchemaKey, mainInitURL };\n};\n","import type { CallApiExtraOptions } from \"./types/common\";\nimport type { AnyString, UnmaskType } from \"./types/type-helpers\";\nimport { toQueryString } from \"./utils\";\nimport { isArray } from \"./utils/guards\";\nimport { type RouteKeyMethodsURLUnion, routeKeyMethods } from \"./validation\";\n\nconst slash = \"/\";\nconst colon = \":\";\nconst openBrace = \"{\";\nconst closeBrace = \"}\";\n\nconst mergeUrlWithParams = (url: string, params: CallApiExtraOptions[\"params\"]) => {\n\tif (!params) {\n\t\treturn url;\n\t}\n\n\tlet newUrl = url;\n\n\tif (isArray(params)) {\n\t\tconst urlParts = newUrl.split(slash);\n\n\t\t// == Find all parameters in order (both :param and {param} patterns)\n\t\tconst matchedParamsArray = urlParts.filter(\n\t\t\t(part) => part.startsWith(colon) || (part.startsWith(openBrace) && part.endsWith(closeBrace))\n\t\t);\n\n\t\tfor (const [paramIndex, matchedParam] of matchedParamsArray.entries()) {\n\t\t\tconst stringParamValue = String(params[paramIndex]);\n\t\t\tnewUrl = newUrl.replace(matchedParam, stringParamValue);\n\t\t}\n\n\t\treturn newUrl;\n\t}\n\n\t// == Handle object params - replace both :param and {param} patterns\n\tfor (const [paramKey, paramValue] of Object.entries(params)) {\n\t\tconst colonPattern = `${colon}${paramKey}` as const;\n\t\tconst bracePattern = `${openBrace}${paramKey}${closeBrace}` as const;\n\t\tconst stringValue = String(paramValue);\n\n\t\tnewUrl = newUrl.replace(colonPattern, stringValue);\n\t\tnewUrl = newUrl.replace(bracePattern, stringValue);\n\t}\n\n\treturn newUrl;\n};\n\nconst questionMark = \"?\";\nconst ampersand = \"&\";\nconst mergeUrlWithQuery = (url: string, query: CallApiExtraOptions[\"query\"]): string => {\n\tif (!query) {\n\t\treturn url;\n\t}\n\n\tconst queryString = toQueryString(query);\n\n\tif (queryString?.length === 0) {\n\t\treturn url;\n\t}\n\n\tif (url.endsWith(questionMark)) {\n\t\treturn `${url}${queryString}`;\n\t}\n\n\tif (url.includes(questionMark)) {\n\t\treturn `${url}${ampersand}${queryString}`;\n\t}\n\n\treturn `${url}${questionMark}${queryString}`;\n};\n\n/**\n * @description Extracts the HTTP method from method-prefixed route patterns.\n *\n * Analyzes URLs that start with method modifiers (e.g., \"@get/\", \"@post/\") and extracts\n * the HTTP method for use in API requests. This enables method specification directly\n * in route definitions.\n *\n * @param initURL - The URL string to analyze for method modifiers\n * @returns The extracted HTTP method (lowercase) if found, otherwise undefined\n *\n * @example\n * ```typescript\n * // Method extraction from prefixed routes\n * extractMethodFromURL(\"@get/users\"); // Returns: \"get\"\n * extractMethodFromURL(\"@post/users\"); // Returns: \"post\"\n * extractMethodFromURL(\"@put/users/:id\"); // Returns: \"put\"\n * extractMethodFromURL(\"@delete/users/:id\"); // Returns: \"delete\"\n * extractMethodFromURL(\"@patch/users/:id\"); // Returns: \"patch\"\n *\n * // No method modifier\n * extractMethodFromURL(\"/users\"); // Returns: undefined\n * extractMethodFromURL(\"users\"); // Returns: undefined\n *\n * // Invalid or unsupported methods\n * extractMethodFromURL(\"@invalid/users\"); // Returns: undefined\n * extractMethodFromURL(\"@/users\"); // Returns: undefined\n *\n * // Edge cases\n * extractMethodFromURL(undefined); // Returns: undefined\n * extractMethodFromURL(\"\"); // Returns: undefined\n * ```\n */\nexport const extractMethodFromURL = (initURL: string | undefined) => {\n\tif (!initURL?.startsWith(\"@\")) return;\n\n\tconst method = initURL.split(\"@\")[1]?.split(\"/\")[0];\n\n\tif (!method || !routeKeyMethods.includes(method as (typeof routeKeyMethods)[number])) return;\n\n\treturn method;\n};\n\nconst normalizeURL = (initURL: string) => {\n\tconst methodFromURL = extractMethodFromURL(initURL);\n\n\tif (!methodFromURL) {\n\t\treturn initURL;\n\t}\n\n\tconst normalizedURL = initURL.replace(`@${methodFromURL}/`, \"/\");\n\n\treturn normalizedURL;\n};\n\ntype GetFullURLOptions = {\n\t/** Base URL to prepend to relative URLs */\n\tbaseURL: string | undefined;\n\t/** Initial URL pattern that may contain parameters and method modifiers */\n\tinitURL: string;\n\t/** Parameters to substitute into the URL path */\n\tparams: CallApiExtraOptions[\"params\"];\n\t/** Query parameters to append to the URL */\n\tquery: CallApiExtraOptions[\"query\"];\n};\n\nexport const getFullAndNormalizedURL = (options: GetFullURLOptions) => {\n\tconst { baseURL, initURL, params, query } = options;\n\n\tconst normalizedInitURL = normalizeURL(initURL);\n\n\tconst urlWithMergedParams = mergeUrlWithParams(normalizedInitURL, params);\n\n\tconst urlWithMergedQueryAndParams = mergeUrlWithQuery(urlWithMergedParams, query);\n\n\tconst shouldPrependBaseURL = !urlWithMergedQueryAndParams.startsWith(\"http\") && baseURL;\n\n\tconst fullURL =\n\t\tshouldPrependBaseURL ? `${baseURL}${urlWithMergedQueryAndParams}` : urlWithMergedQueryAndParams;\n\n\treturn {\n\t\tfullURL,\n\t\tnormalizedInitURL,\n\t};\n};\n\nexport type AllowedQueryParamValues = UnmaskType<boolean | number | string>;\n\nexport type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;\n\nexport type TupleStyleParams = UnmaskType<AllowedQueryParamValues[]>;\n\nexport type Params = UnmaskType<RecordStyleParams | TupleStyleParams>;\n\nexport type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;\n\nexport type InitURLOrURLObject = AnyString | RouteKeyMethodsURLUnion | URL;\n\nexport interface URLOptions {\n\t/**\n\t * Base URL for all API requests. Will only be prepended to relative URLs.\n\t *\n\t * Absolute URLs (starting with http/https) will not be prepended by the baseURL.\n\t *\n\t * @example\n\t * ```ts\n\t * // Set base URL for all requests\n\t * baseURL: \"https://api.example.com/v1\"\n\t *\n\t * // Then use relative URLs in requests\n\t * callApi(\"/users\") // → https://api.example.com/v1/users\n\t * callApi(\"/posts/123\") // → https://api.example.com/v1/posts/123\n\t *\n\t * // Environment-specific base URLs\n\t * baseURL: process.env.NODE_ENV === \"production\"\n\t * ? \"https://api.example.com\"\n\t * : \"http://localhost:3000/api\"\n\t * ```\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * Resolved request URL after processing baseURL, parameters, and query strings (readonly)\n\t *\n\t * This is the final URL that will be used for the HTTP request, computed from\n\t * baseURL, initURL, params, and query parameters.\n\t *\n\t */\n\treadonly fullURL?: string;\n\n\t/**\n\t * The original URL string passed to the callApi instance (readonly)\n\t *\n\t * This preserves the original URL as provided, including any method modifiers like \"@get/\" or \"@post/\".\n\t *\n\t */\n\treadonly initURL?: string;\n\n\t/**\n\t * The URL string after normalization, with method modifiers removed(readonly)\n\t *\n\t * Method modifiers like \"@get/\", \"@post/\" are stripped to create a clean URL\n\t * for parameter substitution and final URL construction.\n\t *\n\t */\n\treadonly initURLNormalized?: string;\n\n\t/**\n\t * Parameters to be substituted into URL path segments.\n\t *\n\t * Supports both object-style (named parameters) and array-style (positional parameters)\n\t * for flexible URL parameter substitution.\n\t *\n\t * @example\n\t * ```typescript\n\t * // Object-style parameters (recommended)\n\t * const namedParams: URLOptions = {\n\t * initURL: \"/users/:userId/posts/:postId\",\n\t * params: { userId: \"123\", postId: \"456\" }\n\t * };\n\t * // Results in: /users/123/posts/456\n\t *\n\t * // Array-style parameters (positional)\n\t * const positionalParams: URLOptions = {\n\t * initURL: \"/users/:userId/posts/:postId\",\n\t * params: [\"123\", \"456\"] // Maps in order: userId=123, postId=456\n\t * };\n\t * // Results in: /users/123/posts/456\n\t *\n\t * // Single parameter\n\t * const singleParam: URLOptions = {\n\t * initURL: \"/users/:id\",\n\t * params: { id: \"user-123\" }\n\t * };\n\t * // Results in: /users/user-123\n\t * ```\n\t */\n\tparams?: Params;\n\n\t/**\n\t * Query parameters to append to the URL as search parameters.\n\t *\n\t * These will be serialized into the URL query string using standard\n\t * URL encoding practices.\n\t *\n\t * @example\n\t * ```typescript\n\t * // Basic query parameters\n\t * const queryOptions: URLOptions = {\n\t * initURL: \"/users\",\n\t * query: {\n\t * page: 1,\n\t * limit: 10,\n\t * search: \"john doe\",\n\t * active: true\n\t * }\n\t * };\n\t * // Results in: /users?page=1&limit=10&search=john%20doe&active=true\n\t *\n\t * // Filtering and sorting\n\t * const filterOptions: URLOptions = {\n\t * initURL: \"/products\",\n\t * query: {\n\t * category: \"electronics\",\n\t * minPrice: 100,\n\t * maxPrice: 500,\n\t * sortBy: \"price\",\n\t * order: \"asc\"\n\t * }\n\t * };\n\t * // Results in: /products?category=electronics&minPrice=100&maxPrice=500&sortBy=price&order=asc\n\t * ```\n\t */\n\tquery?: Query;\n}\n","export const createCombinedSignalPolyfill = (signals: AbortSignal[]) => {\n\tconst controller = new AbortController();\n\n\tconst handleAbort = (actualSignal: AbortSignal) => {\n\t\tif (controller.signal.aborted) return;\n\n\t\tcontroller.abort(actualSignal.reason);\n\t};\n\n\tfor (const actualSignal of signals) {\n\t\tif (actualSignal.aborted) {\n\t\t\thandleAbort(actualSignal);\n\t\t\tbreak;\n\t\t}\n\n\t\tactualSignal.addEventListener(\"abort\", () => handleAbort(actualSignal), {\n\t\t\tsignal: controller.signal,\n\t\t});\n\t}\n\n\treturn controller.signal;\n};\n\nexport const createTimeoutSignalPolyfill = (milliseconds: number) => {\n\tconst controller = new AbortController();\n\n\tconst reason = new DOMException(\"Request timed out\", \"TimeoutError\");\n\n\tconst timeout = setTimeout(() => controller.abort(reason), milliseconds);\n\n\tcontroller.signal.addEventListener(\"abort\", () => clearTimeout(timeout));\n\n\treturn controller.signal;\n};\n","import { getAuthHeader } from \"../auth\";\nimport { fetchSpecificKeys } from \"../constants/common\";\nimport { extraOptionDefaults, requestOptionDefaults } from \"../constants/default-options\";\nimport type { Middlewares } from \"../middlewares\";\nimport type { BaseCallApiExtraOptions, CallApiExtraOptions, CallApiRequestOptions } from \"../types/common\";\nimport { extractMethodFromURL } from \"../url\";\nimport {\n\tisArray,\n\tisFunction,\n\tisPlainObject,\n\tisQueryString,\n\tisSerializable,\n\tisValidJsonString,\n} from \"./guards\";\nimport { createCombinedSignalPolyfill, createTimeoutSignalPolyfill } from \"./polyfills\";\n\nexport const omitKeys = <\n\tTObject extends Record<string, unknown>,\n\tconst TOmitArray extends Array<keyof TObject>,\n>(\n\tinitialObject: TObject,\n\tkeysToOmit: TOmitArray\n) => {\n\tconst updatedObject = {} as Record<string, unknown>;\n\n\tconst keysToOmitSet = new Set(keysToOmit);\n\n\tfor (const [key, value] of Object.entries(initialObject)) {\n\t\tif (!keysToOmitSet.has(key)) {\n\t\t\tupdatedObject[key] = value;\n\t\t}\n\t}\n\n\treturn updatedObject as Omit<TObject, TOmitArray[number]>;\n};\n\nexport const pickKeys = <\n\tTObject extends Record<string, unknown>,\n\tconst TPickArray extends Array<keyof TObject>,\n>(\n\tinitialObject: TObject,\n\tkeysToPick: TPickArray\n) => {\n\tconst updatedObject = {} as Record<string, unknown>;\n\n\tconst keysToPickSet = new Set(keysToPick);\n\n\tfor (const [key, value] of Object.entries(initialObject)) {\n\t\tif (keysToPickSet.has(key)) {\n\t\t\tupdatedObject[key] = value;\n\t\t}\n\t}\n\n\treturn updatedObject as Pick<TObject, TPickArray[number]>;\n};\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is required here so that one can pass custom function type without type errors\nexport const splitBaseConfig = (baseConfig: Record<string, any>) =>\n\t[\n\t\tpickKeys(baseConfig, fetchSpecificKeys) as CallApiRequestOptions,\n\t\tomitKeys(baseConfig, fetchSpecificKeys) as BaseCallApiExtraOptions,\n\t] as const;\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is required here so that one can pass custom function type without type errors\nexport const splitConfig = (config: Record<string, any>) =>\n\t[\n\t\tpickKeys(config, fetchSpecificKeys) as CallApiRequestOptions,\n\t\tomitKeys(config, fetchSpecificKeys) as CallApiExtraOptions,\n\t] as const;\n\ntype ToQueryStringFn = {\n\t(params: CallApiExtraOptions[\"query\"]): string | null;\n\t(params: Required<CallApiExtraOptions>[\"query\"]): string;\n};\n\nexport const toQueryString: ToQueryStringFn = (params) => {\n\tif (!params) {\n\t\tconsole.error(\"toQueryString:\", \"No query params provided!\");\n\n\t\treturn null as never;\n\t}\n\n\treturn new URLSearchParams(params as Record<string, string>).toString();\n};\n\nexport const objectifyHeaders = (headers: CallApiRequestOptions[\"headers\"]) => {\n\tif (!headers || isPlainObject(headers)) {\n\t\treturn headers;\n\t}\n\n\treturn Object.fromEntries(headers);\n};\n\nexport type GetHeadersOptions = {\n\tauth: CallApiExtraOptions[\"auth\"];\n\tbody: CallApiRequestOptions[\"body\"];\n\theaders: CallApiRequestOptions[\"headers\"];\n};\n\nexport const getHeaders = async (options: GetHeadersOptions) => {\n\tconst { auth, body, headers } = options;\n\n\t// == Return early if any of the following conditions are not met (so that native fetch would auto set the correct headers):\n\tconst shouldResolveHeaders = Boolean(headers) || Boolean(body) || Boolean(auth);\n\n\tif (!shouldResolveHeaders) return;\n\n\tconst headersObject: Record<string, string | undefined> = {\n\t\t...(await getAuthHeader(auth)),\n\t\t...objectifyHeaders(headers),\n\t};\n\n\tif (isQueryString(body)) {\n\t\theadersObject[\"Content-Type\"] = \"application/x-www-form-urlencoded\";\n\n\t\treturn headersObject;\n\t}\n\n\tif (isSerializable(body) || isValidJsonString(body)) {\n\t\theadersObject[\"Content-Type\"] = \"application/json\";\n\t\theadersObject.Accept = \"application/json\";\n\t}\n\n\treturn headersObject;\n};\n\nexport type GetMethodContext = {\n\t/** The URL string that may contain method modifiers like \"@get/\" or \"@post/\" */\n\tinitURL: string | undefined;\n\t/** Explicitly specified HTTP method */\n\tmethod: CallApiRequestOptions[\"method\"];\n};\n\nexport const getMethod = (ctx: GetMethodContext) => {\n\tconst { initURL, method } = ctx;\n\n\treturn (\n\t\tmethod?.toUpperCase()\n\t\t?? extractMethodFromURL(initURL)?.toUpperCase()\n\t\t?? requestOptionDefaults().method\n\t);\n};\n\nexport type GetBodyOptions = {\n\tbody: CallApiRequestOptions[\"body\"];\n\tbodySerializer: CallApiExtraOptions[\"bodySerializer\"];\n};\n\nexport const getBody = (options: GetBodyOptions) => {\n\tconst { body, bodySerializer } = options;\n\n\tif (isSerializable(body)) {\n\t\tconst selectedBodySerializer = bodySerializer ?? extraOptionDefaults().bodySerializer;\n\n\t\treturn selectedBodySerializer(body);\n\t}\n\n\treturn body;\n};\n\nexport const getInitFetchImpl = (customFetchImpl: CallApiExtraOptions[\"customFetchImpl\"]) => {\n\tif (customFetchImpl) {\n\t\treturn customFetchImpl;\n\t}\n\n\tif (typeof globalThis !== \"undefined\" && isFunction(globalThis.fetch)) {\n\t\treturn globalThis.fetch;\n\t}\n\n\tthrow new Error(\"No fetch implementation found\");\n};\n\nexport const getFetchImpl = (\n\tcustomFetchImpl: CallApiExtraOptions[\"customFetchImpl\"],\n\tfetchMiddleware: Middlewares[\"fetchMiddleware\"]\n) => {\n\tconst initFetchApi = getInitFetchImpl(customFetchImpl);\n\n\tconst fetchImpl = fetchMiddleware ? fetchMiddleware(initFetchApi) : initFetchApi;\n\n\treturn fetchImpl;\n};\n\nconst PromiseWithResolvers = () => {\n\tlet reject!: (reason?: unknown) => void;\n\tlet resolve!: (value: unknown) => void;\n\n\tconst promise = new Promise((res, rej) => {\n\t\tresolve = res;\n\t\treject = rej;\n\t});\n\n\treturn { promise, reject, resolve };\n};\n\nexport const waitFor = (delay: number) => {\n\tif (delay === 0) return;\n\n\tconst { promise, resolve } = PromiseWithResolvers();\n\n\tsetTimeout(resolve, delay);\n\n\treturn promise;\n};\n\nexport const createCombinedSignal = (...signals: Array<AbortSignal | null | undefined>) => {\n\tconst cleanedSignals = signals.filter((signal) => signal != null);\n\n\tif (!(\"any\" in AbortSignal)) {\n\t\treturn createCombinedSignalPolyfill(cleanedSignals);\n\t}\n\n\tconst combinedSignal = AbortSignal.any(cleanedSignals);\n\n\treturn combinedSignal;\n};\n\nexport const createTimeoutSignal = (milliseconds: number) => {\n\tif (!(\"timeout\" in AbortSignal)) {\n\t\treturn createTimeoutSignalPolyfill(milliseconds);\n\t}\n\n\treturn AbortSignal.timeout(milliseconds);\n};\n\nexport const deterministicHashFn = (value: unknown): string => {\n\treturn JSON.stringify(value, (_, val: unknown) => {\n\t\tif (!isPlainObject(val)) {\n\t\t\treturn val;\n\t\t}\n\n\t\tconst sortedKeys = Object.keys(val).toSorted();\n\n\t\tconst result: Record<string, unknown> = {};\n\n\t\tfor (const key of sortedKeys) {\n\t\t\tresult[key] = val[key];\n\t\t}\n\n\t\treturn result;\n\t});\n};\n\nexport const toArray = (value: unknown) => (isArray(value) ? value : [value]);\n"],"mappings":";AAyCA,MAAa,cAA2C,UAAkB;;;;ACtC1E,MAAa,4BAA4B;AACxC,QAAO,WAAW;EAEjB,gBAAgB,KAAK;EACrB,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aAAa;AAGjD,QAAO,YAAY,QAAQ,aAAa;;AAGzC,MAAa,uBAAuB,UAA2B;AAC9D,QAAO,KAAK,UAAU,QAAQ,GAAG,QAAiB;AACjD,MAAI,CAAC,cAAc,IAAI,CACtB,QAAO;EAGR,MAAM,aAAa,OAAO,KAAK,IAAI,CAAC,UAAU;EAE9C,MAAMC,SAAkC,EAAE;AAE1C,OAAK,MAAM,OAAO,WACjB,QAAO,OAAO,IAAI;AAGnB,SAAO;GACN;;AAGH,MAAa,WAAW,UAAoB,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM"}
@@ -417,6 +417,43 @@ declare class ValidationError extends Error {
417
417
  static isError(error: unknown): error is ValidationError;
418
418
  }
419
419
  //#endregion
420
+ //#region src/middlewares.d.ts
421
+ type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
422
+ interface Middlewares {
423
+ /**
424
+ * Wraps the fetch implementation to intercept requests at the network layer.
425
+ *
426
+ * Takes the current fetch function and returns a new one. Use it to cache responses,
427
+ * add logging, handle offline mode, or short-circuit requests etc. Multiple middleware
428
+ * compose in order: plugins → base config → per-request.
429
+ *
430
+ * Unlike `customFetchImpl`, middleware can call through to the original fetch.
431
+ *
432
+ * @example
433
+ * ```ts
434
+ * // Cache responses
435
+ * const cache = new Map();
436
+ * fetchMiddleware: (fetchImpl) => async (input, init) => {
437
+ * const key = input.toString();
438
+ * if (cache.has(key)) return cache.get(key).clone();
439
+ *
440
+ * const response = await fetchImpl(input, init);
441
+ * cache.set(key, response.clone());
442
+ * return response;
443
+ * }
444
+ *
445
+ * // Handle offline
446
+ * fetchMiddleware: (fetchImpl) => async (input, init) => {
447
+ * if (!navigator.onLine) {
448
+ * return new Response('{"error": "offline"}', { status: 503 });
449
+ * }
450
+ * return fetchImpl(input, init);
451
+ * }
452
+ * ```
453
+ */
454
+ fetchMiddleware?: (fetchImpl: FetchImpl) => FetchImpl;
455
+ }
456
+ //#endregion
420
457
  //#region src/plugins.d.ts
421
458
  type PluginSetupContext<TPluginExtraOptions = unknown> = RequestContext & PluginExtraOptions<TPluginExtraOptions> & {
422
459
  initURL: string;
@@ -437,13 +474,17 @@ interface CallApiPlugin {
437
474
  */
438
475
  description?: string;
439
476
  /**
440
- * Hooks / Interceptors for the plugin
477
+ * Hooks for the plugin
441
478
  */
442
- hooks?: PluginHooks;
479
+ hooks?: PluginHooks | ((context: PluginSetupContext) => Awaitable<PluginHooks>);
443
480
  /**
444
481
  * A unique id for the plugin
445
482
  */
446
483
  id: string;
484
+ /**
485
+ * Middlewares that for the plugin
486
+ */
487
+ middlewares?: Middlewares | ((context: PluginSetupContext) => Awaitable<Middlewares>);
447
488
  /**
448
489
  * A name for the plugin
449
490
  */
@@ -559,15 +600,6 @@ type PluginExtraOptions<TPluginOptions = unknown> = {
559
600
  options: Partial<TPluginOptions>;
560
601
  };
561
602
  interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOptions = unknown> {
562
- /**
563
- * First hook in the request lifecycle, executed before any internal processing begins.
564
- *
565
- * This is the earliest point to intercept requests - ideal for initial setup, logging,
566
- * or modifying the request before any other processing occurs.
567
- *
568
- * @param context - Request context with mutable request object and configuration
569
- */
570
- onBeforeRequest?: (context: RequestContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
571
603
  /**
572
604
  * Hook called when any error occurs within the request/response lifecycle.
573
605
  *
@@ -580,7 +612,7 @@ interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOp
580
612
  */
581
613
  onError?: (context: ErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
582
614
  /**
583
- * Hook called just before the HTTP request is sent.
615
+ * Hook called before the HTTP request is sent and before any internal processing of the request object begins.
584
616
  *
585
617
  * This is the ideal place to modify request headers, add authentication,
586
618
  * implement request logging, or perform any setup before the network call.
@@ -601,6 +633,12 @@ interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOp
601
633
  * @returns Promise or void - Hook can be async or sync
602
634
  */
603
635
  onRequestError?: (context: RequestErrorContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
636
+ /**
637
+ * Hook called just before the HTTP request is sent and after the request has been processed.
638
+ *
639
+ * @param context - Request context with mutable request object and configuration
640
+ */
641
+ onRequestReady?: (context: RequestContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
604
642
  /**
605
643
  * Hook called during upload stream progress tracking.
606
644
  *
@@ -695,8 +733,6 @@ interface HookConfigOptions {
695
733
  *
696
734
  * This affects how ALL hooks execute together, regardless of their source (main or plugin).
697
735
  *
698
- * Use `hookRegistrationOrder` to control the registration order of main vs plugin hooks.
699
- *
700
736
  * @default "parallel"
701
737
  *
702
738
  * @example
@@ -710,7 +746,6 @@ interface HookConfigOptions {
710
746
  * // Use case: Hooks have dependencies and must run in order
711
747
  * const client = callApi.create({
712
748
  * hooksExecutionMode: "sequential",
713
- * hookRegistrationOrder: "mainFirst",
714
749
  * plugins: [transformPlugin],
715
750
  * onRequest: (ctx) => {
716
751
  * // This runs first, then transform plugin runs
@@ -740,62 +775,6 @@ interface HookConfigOptions {
740
775
  * ```
741
776
  */
742
777
  hooksExecutionMode?: "parallel" | "sequential";
743
- /**
744
- * Controls the registration order of main hooks relative to plugin hooks.
745
- *
746
- * - **"pluginsFirst"**: Plugin hooks register first, then main hooks (default)
747
- * - **"mainFirst"**: Main hooks register first, then plugin hooks
748
- *
749
- * This determines the order hooks are added to the registry, which affects
750
- * their execution sequence when using sequential execution mode.
751
- *
752
- * @default "pluginsFirst"
753
- *
754
- * @example
755
- * ```ts
756
- * // Plugin hooks register first (default behavior)
757
- * hookRegistrationOrder: "pluginsFirst"
758
- *
759
- * // Main hooks register first
760
- * hookRegistrationOrder: "mainFirst"
761
- *
762
- * // Use case: Main validation before plugin processing
763
- * const client = callApi.create({
764
- * hookRegistrationOrder: "mainFirst",
765
- * hooksExecutionMode: "sequential",
766
- * plugins: [transformPlugin],
767
- * onRequest: (ctx) => {
768
- * // This main hook runs first in sequential mode
769
- * if (!ctx.request.headers.authorization) {
770
- * throw new Error("Authorization required");
771
- * }
772
- * }
773
- * });
774
- *
775
- * // Use case: Plugin setup before main logic (default)
776
- * const client = callApi.create({
777
- * hookRegistrationOrder: "pluginsFirst", // Default
778
- * hooksExecutionMode: "sequential",
779
- * plugins: [setupPlugin],
780
- * onRequest: (ctx) => {
781
- * // Plugin runs first, then this main hook
782
- * console.log("Request prepared:", ctx.request.url);
783
- * }
784
- * });
785
- *
786
- * // Use case: Parallel mode (registration order less important)
787
- * const client = callApi.create({
788
- * hookRegistrationOrder: "pluginsFirst",
789
- * hooksExecutionMode: "parallel", // All run simultaneously
790
- * plugins: [metricsPlugin, cachePlugin],
791
- * onRequest: (ctx) => {
792
- * // All hooks run in parallel regardless of registration order
793
- * addRequestId(ctx.request);
794
- * }
795
- * });
796
- * ```
797
- */
798
- hooksRegistrationOrder?: "mainFirst" | "pluginsFirst";
799
778
  }
800
779
  type RequestContext = {
801
780
  /**
@@ -1290,8 +1269,7 @@ type CallApiRequestOptions = Prettify<{
1290
1269
  type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
1291
1270
  headers: Record<string, string | undefined>;
1292
1271
  };
1293
- type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
1294
- type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<TData, TErrorData, Partial<InferPluginOptions<TPluginArray>>> & Partial<InferPluginOptions<TPluginArray>> & ResultModeOption<TErrorData, TResultMode> & RetryOptions<TErrorData> & ThrowOnErrorOption<TErrorData, TThrowOnError> & URLOptions & {
1272
+ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<TData, TErrorData, Partial<InferPluginOptions<TPluginArray>>> & Middlewares & Partial<InferPluginOptions<TPluginArray>> & ResultModeOption<TErrorData, TResultMode> & RetryOptions<TErrorData> & ThrowOnErrorOption<TErrorData, TThrowOnError> & URLOptions & {
1295
1273
  /**
1296
1274
  * Automatically add an Authorization header value.
1297
1275
  *
@@ -1811,4 +1789,4 @@ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TR
1811
1789
  type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
1812
1790
  //#endregion
1813
1791
  export { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey };
1814
- //# sourceMappingURL=common-BqnzZD5r.d.ts.map
1792
+ //# sourceMappingURL=common-CPTdKchS.d.ts.map
@@ -1,4 +1,4 @@
1
- import { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey } from "./common-BqnzZD5r.js";
1
+ import { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey } from "./common-CPTdKchS.js";
2
2
 
3
3
  //#region src/createFetchClient.d.ts
4
4