@zayne-labs/callapi 1.7.8 → 1.7.10

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.
@@ -31,10 +31,61 @@ var requestOptionDefaults = defineEnum({
31
31
  method: "GET"
32
32
  });
33
33
 
34
- // src/error.ts
35
- var resolveErrorResult = (info) => {
36
- const { cloneResponse, defaultErrorMessage, error, message: customErrorMessage, resultMode } = info;
37
- let apiDetails = {
34
+ // src/result.ts
35
+ var getResponseType = (response, parser) => ({
36
+ arrayBuffer: () => response.arrayBuffer(),
37
+ blob: () => response.blob(),
38
+ formData: () => response.formData(),
39
+ json: async () => {
40
+ const text = await response.text();
41
+ return parser(text);
42
+ },
43
+ stream: () => response.body,
44
+ text: () => response.text()
45
+ });
46
+ var resolveResponseData = (response, responseType, parser) => {
47
+ const selectedParser = parser ?? responseDefaults.responseParser;
48
+ const selectedResponseType = responseType ?? responseDefaults.responseType;
49
+ const RESPONSE_TYPE_LOOKUP = getResponseType(response, selectedParser);
50
+ if (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, selectedResponseType)) {
51
+ throw new Error(`Invalid response type: ${responseType}`);
52
+ }
53
+ return RESPONSE_TYPE_LOOKUP[selectedResponseType]();
54
+ };
55
+ var resolveSuccessResult = (data, info) => {
56
+ const { response, resultMode } = info;
57
+ const details = {
58
+ data,
59
+ error: null,
60
+ response
61
+ };
62
+ const resultModeMap = {
63
+ all: details,
64
+ allWithException: details,
65
+ onlySuccess: details.data,
66
+ onlySuccessWithException: details.data
67
+ };
68
+ const successResult = resultModeMap[resultMode ?? "all"];
69
+ return successResult;
70
+ };
71
+ var HTTPError = class extends Error {
72
+ errorData;
73
+ isHTTPError = true;
74
+ name = "HTTPError";
75
+ response;
76
+ constructor(errorDetails, errorOptions) {
77
+ const { defaultErrorMessage, errorData, response } = errorDetails;
78
+ const selectedDefaultErrorMessage = defaultErrorMessage ?? commonDefaults.defaultErrorMessage;
79
+ const message = errorData?.message ?? selectedDefaultErrorMessage;
80
+ super(message, errorOptions);
81
+ this.errorData = errorData;
82
+ this.response = response;
83
+ Error.captureStackTrace(this, this.constructor);
84
+ }
85
+ };
86
+ var resolveErrorResult = (error, info) => {
87
+ const { cloneResponse, defaultErrorMessage, message: customErrorMessage, resultMode } = info;
88
+ let details = {
38
89
  data: null,
39
90
  error: {
40
91
  errorData: error,
@@ -46,7 +97,7 @@ var resolveErrorResult = (info) => {
46
97
  if (isHTTPErrorInstance(error)) {
47
98
  const selectedDefaultErrorMessage = defaultErrorMessage ?? commonDefaults.defaultErrorMessage;
48
99
  const { errorData, message = selectedDefaultErrorMessage, name, response } = error;
49
- apiDetails = {
100
+ details = {
50
101
  data: null,
51
102
  error: {
52
103
  errorData,
@@ -57,41 +108,26 @@ var resolveErrorResult = (info) => {
57
108
  };
58
109
  }
59
110
  const resultModeMap = {
60
- all: apiDetails,
61
- allWithException: apiDetails,
62
- allWithoutResponse: omitKeys(apiDetails, ["response"]),
63
- onlyError: apiDetails.error,
64
- onlyResponse: apiDetails.response,
65
- onlyResponseWithException: apiDetails.response,
66
- onlySuccess: apiDetails.data,
67
- onlySuccessWithException: apiDetails.data
111
+ all: details,
112
+ allWithException: details,
113
+ onlySuccess: details.data,
114
+ onlySuccessWithException: details.data
68
115
  };
69
- const getErrorResult = (customErrorInfo) => {
70
- const errorVariantResult = resultModeMap[resultMode ?? "all"];
71
- return customErrorInfo ? {
72
- ...errorVariantResult,
73
- error: {
74
- ...errorVariantResult.error,
75
- ...customErrorInfo
76
- }
77
- } : errorVariantResult;
78
- };
79
- return { apiDetails, getErrorResult };
116
+ const errorResult = resultModeMap[resultMode ?? "all"];
117
+ return errorResult;
80
118
  };
81
- var HTTPError = class extends Error {
82
- errorData;
83
- isHTTPError = true;
84
- name = "HTTPError";
85
- response;
86
- constructor(errorDetails, errorOptions) {
87
- const { defaultErrorMessage, errorData, response } = errorDetails;
88
- const selectedDefaultErrorMessage = defaultErrorMessage ?? commonDefaults.defaultErrorMessage;
89
- const message = errorData?.message ?? selectedDefaultErrorMessage;
90
- super(message, errorOptions);
91
- this.errorData = errorData;
92
- this.response = response;
93
- Error.captureStackTrace(this, this.constructor);
119
+ var getCustomizedErrorResult = (errorResult, customErrorInfo) => {
120
+ if (!errorResult) {
121
+ return null;
94
122
  }
123
+ const { message = errorResult.error.message } = customErrorInfo;
124
+ return {
125
+ ...errorResult,
126
+ error: {
127
+ ...errorResult.error,
128
+ message
129
+ }
130
+ };
95
131
  };
96
132
 
97
133
  // src/utils/guards.ts
@@ -99,10 +135,10 @@ var isHTTPError = (error) => {
99
135
  return isPlainObject(error) && error.name === "HTTPError";
100
136
  };
101
137
  var isHTTPErrorInstance = (error) => {
102
- return (
103
- // prettier-ignore
104
- error instanceof HTTPError || isPlainObject(error) && error.name === "HTTPError" && error.isHTTPError === true
105
- );
138
+ if (error instanceof HTTPError) {
139
+ return true;
140
+ }
141
+ return isPlainObject(error) && error.name === "HTTPError" && error.isHTTPError === true;
106
142
  };
107
143
  var isArray = (value) => Array.isArray(value);
108
144
  var isObject = (value) => typeof value === "object" && value !== null;
@@ -154,31 +190,31 @@ var isReadableStream = (value) => {
154
190
  var getValue = (value) => {
155
191
  return isFunction(value) ? value() : value;
156
192
  };
157
- var getAuthHeader = (auth) => {
193
+ var getAuthHeader = async (auth) => {
158
194
  if (auth === void 0) return;
159
195
  if (isString(auth) || auth === null) {
160
196
  return { Authorization: `Bearer ${auth}` };
161
197
  }
162
198
  switch (auth.type) {
163
199
  case "Basic": {
164
- const username = getValue(auth.username);
165
- const password = getValue(auth.password);
200
+ const username = await getValue(auth.username);
201
+ const password = await getValue(auth.password);
166
202
  if (username === void 0 || password === void 0) return;
167
203
  return {
168
204
  Authorization: `Basic ${globalThis.btoa(`${username}:${password}`)}`
169
205
  };
170
206
  }
171
207
  case "Custom": {
172
- const value = getValue(auth.value);
208
+ const value = await getValue(auth.value);
173
209
  if (value === void 0) return;
174
- const prefix = getValue(auth.prefix);
210
+ const prefix = await getValue(auth.prefix);
175
211
  return {
176
212
  Authorization: `${prefix} ${value}`
177
213
  };
178
214
  }
179
215
  default: {
180
- const bearer = getValue(auth.bearer);
181
- const token = getValue(auth.token);
216
+ const bearer = await getValue(auth.bearer);
217
+ const token = await getValue(auth.token);
182
218
  if ("token" in auth && token !== void 0) {
183
219
  return { Authorization: `Token ${token}` };
184
220
  }
@@ -254,12 +290,12 @@ var objectifyHeaders = (headers) => {
254
290
  }
255
291
  return Object.fromEntries(headers);
256
292
  };
257
- var mergeAndResolveHeaders = (options) => {
293
+ var getHeaders = async (options) => {
258
294
  const { auth, baseHeaders, body, headers } = options;
259
295
  const shouldResolveHeaders = Boolean(baseHeaders || headers || body || auth);
260
296
  if (!shouldResolveHeaders) return;
261
297
  const headersObject = {
262
- ...getAuthHeader(auth),
298
+ ...await getAuthHeader(auth),
263
299
  ...objectifyHeaders(baseHeaders),
264
300
  ...objectifyHeaders(headers)
265
301
  };
@@ -304,6 +340,6 @@ var createCombinedSignal = (...signals) => {
304
340
  };
305
341
  var createTimeoutSignal = (milliseconds) => AbortSignal.timeout(milliseconds);
306
342
 
307
- export { HTTPError, commonDefaults, createCombinedSignal, createTimeoutSignal, dedupeDefaults, getFetchImpl, hookDefaults, isArray, isFunction, isHTTPError, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isSerializable, isString, mergeAndResolveHeaders, omitKeys, requestOptionDefaults, resolveErrorResult, responseDefaults, retryDefaults, splitBaseConfig, splitConfig, toQueryString, waitUntil };
308
- //# sourceMappingURL=chunk-DLKKYMSL.js.map
309
- //# sourceMappingURL=chunk-DLKKYMSL.js.map
343
+ export { HTTPError, commonDefaults, createCombinedSignal, createTimeoutSignal, dedupeDefaults, getCustomizedErrorResult, getFetchImpl, getHeaders, hookDefaults, isArray, isFunction, isHTTPError, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isSerializable, isString, requestOptionDefaults, resolveErrorResult, resolveResponseData, resolveSuccessResult, retryDefaults, splitBaseConfig, splitConfig, toQueryString, waitUntil };
344
+ //# sourceMappingURL=chunk-SJZKYDA4.js.map
345
+ //# sourceMappingURL=chunk-SJZKYDA4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/type-helpers.ts","../../src/constants/default-options.ts","../../src/result.ts","../../src/utils/guards.ts","../../src/auth.ts","../../src/constants/common.ts","../../src/types/common.ts","../../src/utils/common.ts"],"names":[],"mappings":";AAuDO,IAAM,UAAA,GAAa,CAAe,KAAkB,KAAA,KAAA;;;ACpDpD,IAAM,gBAAgB,UAAW,CAAA;AAAA,EACvC,QAAU,EAAA,CAAA;AAAA,EACV,WAAW,MAAM,IAAA;AAAA,EACjB,KAAO,EAAA,GAAA;AAAA,EACP,QAAU,EAAA,GAAA;AAAA,EACV,OAAA,EAAS,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,EACvB,aAAa,EAAC;AAAA,EACd,QAAU,EAAA;AACX,CAAC;AAaM,IAAM,iBAAiB,UAAW,CAAA;AAAA,EACxC,gBAAgB,IAAK,CAAA,SAAA;AAAA,EACrB,mBAAqB,EAAA;AACtB,CAAC;AAEM,IAAM,mBAAmB,UAAW,CAAA;AAAA,EAC1C,gBAAgB,IAAK,CAAA,KAAA;AAAA,EACrB,YAAc,EAAA,MAAA;AAAA,EACd,UAAY,EAAA;AACb,CAAC,CAAA;AAEM,IAAM,eAAe,UAAW,CAAA;AAAA,EACtC,wBAA0B,EAAA,UAAA;AAAA,EAC1B,yBAA2B,EAAA;AAC5B,CAAC;AAEM,IAAM,iBAAiB,UAAW,CAAA;AAAA,EACxC,cAAgB,EAAA;AACjB,CAAC;AAEM,IAAM,wBAAwB,UAAW,CAAA;AAAA,EAC/C,MAAQ,EAAA;AACT,CAAC;;;ACtCM,IAAM,eAAA,GAAkB,CAAY,QAAA,EAAoB,MAAoB,MAAA;AAAA,EAClF,WAAA,EAAa,MAAM,QAAA,CAAS,WAAY,EAAA;AAAA,EACxC,IAAA,EAAM,MAAM,QAAA,CAAS,IAAK,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BAA+B,CAAA;AAChD;AAEA,IAAM,uBAAuB,MAAM;AAClC,EAAI,IAAA,MAAA;AACJ,EAAI,IAAA,OAAA;AAEJ,EAAA,MAAM,OAAU,GAAA,IAAI,OAAQ,CAAA,CAAC,KAAK,GAAQ,KAAA;AACzC,IAAU,OAAA,GAAA,GAAA;AACV,IAAS,MAAA,GAAA,GAAA;AAAA,GACT,CAAA;AAED,EAAO,OAAA,EAAE,OAAS,EAAA,MAAA,EAAQ,OAAQ,EAAA;AACnC,CAAA;AAEa,IAAA,SAAA,GAAY,CAAC,KAAkB,KAAA;AAC3C,EAAA,IAAI,UAAU,CAAG,EAAA;AAEjB,EAAA,MAAM,EAAE,OAAA,EAAS,OAAQ,EAAA,GAAI,oBAAqB,EAAA;AAElD,EAAA,UAAA,CAAW,SAAS,KAAK,CAAA;AAEzB,EAAO,OAAA,OAAA;AACR;AAEa,IAAA,oBAAA,GAAuB,IAAI,OAAmD,KAAA;AAC1F,EAAM,MAAA,cAAA,GAAiB,OAAQ,CAAA,MAAA,CAAO,OAAO,CAAA;AAE7C,EAAM,MAAA,cAAA,GAAiB,WAAY,CAAA,GAAA,CAAI,cAAc,CAAA;AAErD,EAAO,OAAA,cAAA;AACR;AAEO,IAAM,mBAAsB,GAAA,CAAC,YAAyB,KAAA,WAAA,CAAY,QAAQ,YAAY","file":"chunk-SJZKYDA4.js","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 & { z_placeholder?: never };\nexport type AnyNumber = number & { z_placeholder?: never };\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 WriteableVariantUnion = \"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<\n\tTObject,\n\tTVariant extends WriteableVariantUnion = \"shallow\",\n> = TObject extends readonly [...infer TTupleItems]\n\t? TVariant extends \"deep\"\n\t\t? [\n\t\t\t\t...{\n\t\t\t\t\t[Key in keyof TTupleItems]: TTupleItems[Key] extends ArrayOrObject\n\t\t\t\t\t\t? Writeable<TTupleItems[Key], TVariant>\n\t\t\t\t\t\t: TTupleItems[Key];\n\t\t\t\t},\n\t\t\t]\n\t\t: [...TTupleItems]\n\t: TObject extends ReadonlyArray<infer TArrayItem>\n\t\t? TVariant extends \"deep\"\n\t\t\t? Array<TArrayItem extends ArrayOrObject ? Writeable<TArrayItem, TVariant> : TArrayItem>\n\t\t\t: TArrayItem[]\n\t\t: TObject extends ArrayOrObject\n\t\t\t? {\n\t\t\t\t\t-readonly [Key in keyof TObject]: TVariant extends \"shallow\"\n\t\t\t\t\t\t? TObject[Key]\n\t\t\t\t\t\t: TVariant extends \"deep\"\n\t\t\t\t\t\t\t? TObject[Key] extends ArrayOrObject\n\t\t\t\t\t\t\t\t? Writeable<TObject[Key], TVariant>\n\t\t\t\t\t\t\t\t: TObject[Key]\n\t\t\t\t\t\t\t: never;\n\t\t\t\t}\n\t\t\t: TObject;\n\nexport const defineEnum = <const TValue>(value: TValue) => value as Prettify<Writeable<TValue, \"deep\">>;\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 { BaseCallApiExtraOptions } from \"../types\";\nimport { defineEnum } from \"../utils/type-helpers\";\n\nexport const retryDefaults = defineEnum({\n\tattempts: 0,\n\tcondition: () => true,\n\tdelay: 1000,\n\tmaxDelay: 10000,\n\tmethods: [\"GET\", \"POST\"] satisfies BaseCallApiExtraOptions[\"retryMethods\"],\n\tstatusCodes: [] satisfies BaseCallApiExtraOptions[\"retryStatusCodes\"],\n\tstrategy: \"linear\",\n});\n\nexport const defaultRetryStatusCodesLookup = defineEnum({\n\t408: \"Request Timeout\",\n\t409: \"Conflict\",\n\t425: \"Too Early\",\n\t429: \"Too Many Requests\",\n\t500: \"Internal Server Error\",\n\t502: \"Bad Gateway\",\n\t503: \"Service Unavailable\",\n\t504: \"Gateway Timeout\",\n});\n\nexport const commonDefaults = defineEnum({\n\tbodySerializer: JSON.stringify,\n\tdefaultErrorMessage: \"Failed to fetch data from server!\",\n});\n\nexport const responseDefaults = defineEnum({\n\tresponseParser: JSON.parse,\n\tresponseType: \"json\",\n\tresultMode: \"all\",\n});\n\nexport const hookDefaults = defineEnum({\n\tmergedHooksExecutionMode: \"parallel\",\n\tmergedHooksExecutionOrder: \"mainHooksAfterPlugins\",\n});\n\nexport const dedupeDefaults = defineEnum({\n\tdedupeStrategy: \"cancel\",\n});\n\nexport const requestOptionDefaults = defineEnum({\n\tmethod: \"GET\",\n});\n","import { commonDefaults, responseDefaults } from \"./constants/default-options\";\nimport type { CallApiExtraOptions } from \"./types\";\nimport type { DefaultDataType } from \"./types/default-types\";\nimport { isHTTPErrorInstance } from \"./utils/guards\";\nimport type { Awaitable, Prettify, UnmaskType } from \"./utils/type-helpers\";\n\ntype Parser = (responseString: string) => Awaitable<Record<string, unknown>>;\n\nexport const getResponseType = <TResponse>(response: Response, parser: Parser) => ({\n\tarrayBuffer: () => response.arrayBuffer(),\n\tblob: () => response.blob(),\n\tformData: () => response.formData(),\n\tjson: async () => {\n\t\tconst text = await response.text();\n\t\treturn parser(text) as TResponse;\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> = null extends TResponseType\n\t? TComputedResponseTypeMap[\"json\"]\n\t: TResponseType extends NonNullable<ResponseTypeUnion>\n\t\t? TComputedResponseTypeMap[TResponseType]\n\t\t: never;\n\nexport const resolveResponseData = <TResponse>(\n\tresponse: Response,\n\tresponseType?: ResponseTypeUnion,\n\tparser?: Parser\n) => {\n\tconst selectedParser = parser ?? responseDefaults.responseParser;\n\tconst selectedResponseType = responseType ?? responseDefaults.responseType;\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: TData;\n\terror: null;\n\tresponse: Response;\n};\n\nexport type CallApiResultErrorVariant<TErrorData> =\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleHTTPError<TErrorData>;\n\t\t\tresponse: Response;\n\t }\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleJavaScriptError;\n\t\t\tresponse: null;\n\t };\n\nexport type ResultModeMap<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTComputedData = GetResponseType<TData, TResponseType>,\n\tTComputedErrorData = GetResponseType<TErrorData, TResponseType>,\n> = UnmaskType<{\n\t/* eslint-disable perfectionist/sort-union-types -- I need the first one to be first */\n\tall: CallApiResultSuccessVariant<TComputedData> | CallApiResultErrorVariant<TComputedErrorData>;\n\n\tallWithException: CallApiResultSuccessVariant<TComputedData>;\n\n\tonlySuccess:\n\t\t| CallApiResultErrorVariant<TComputedErrorData>[\"data\"]\n\t\t| CallApiResultSuccessVariant<TComputedData>[\"data\"];\n\n\tonlySuccessWithException: CallApiResultSuccessVariant<TComputedData>[\"data\"];\n\t/* eslint-enable perfectionist/sort-union-types -- I need the first one to be first */\n}>;\n\nexport type ResultModeUnion = keyof ResultModeMap | null;\n\nexport type GetCallApiResult<\n\tTData,\n\tTErrorData,\n\tTResultMode extends ResultModeUnion,\n\tTThrowOnError extends boolean,\n\tTResponseType extends ResponseTypeUnion,\n> = TErrorData extends false | undefined\n\t? ResultModeMap<TData, TErrorData, TResponseType>[\"onlySuccessWithException\"]\n\t: null extends TResultMode\n\t\t? TThrowOnError extends true\n\t\t\t? ResultModeMap<TData, TErrorData, TResponseType>[\"allWithException\"]\n\t\t\t: ResultModeMap<TData, TErrorData, TResponseType>[\"all\"]\n\t\t: TResultMode extends NonNullable<ResultModeUnion>\n\t\t\t? ResultModeMap<TData, TErrorData, TResponseType>[TResultMode]\n\t\t\t: never;\n\ntype SuccessInfo = {\n\tresponse: Response;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n};\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) => {\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 = {\n\t\tall: details,\n\t\tallWithException: details,\n\t\tonlySuccess: details.data,\n\t\tonlySuccessWithException: details.data,\n\t} satisfies ResultModeMap;\n\n\tconst successResult = resultModeMap[resultMode ?? \"all\"];\n\n\treturn successResult;\n};\n\n// export const resolveErrorResultAndContextForHooks = (info: ErrorInfo) => {\n// \tconst { baseConfig, config, error, message: customErrorMessage, options, request } = info;\n\n// \tconst errorContext = {\n// \t\tbaseConfig,\n// \t\tconfig,\n// \t\terror: errorResult?.error as never,\n// \t\toptions,\n// \t\trequest,\n// \t\tresponse: errorResult?.response as never,\n// \t} satisfies ErrorContext<unknown>;\n\n// \tconst shouldThrowOnError = isFunction(options.throwOnError)\n// \t\t? options.throwOnError(errorContext)\n// \t\t: options.throwOnError;\n\n// \tconst executeHooksInCatchBlock = async (...hookResults: Array<Awaitable<unknown>>) => {\n// \t\ttry {\n// \t\t\tawait Promise.all(hookResults);\n\n// \t\t\treturn null;\n// \t\t} catch (hookError) {\n// \t\t\tif (shouldThrowOnError) {\n// \t\t\t\tthrow hookError;\n// \t\t\t}\n\n// \t\t\tconst { errorResult: hookErrorResult } = resolveErrorResult({ ...info, error: hookError });\n\n// \t\t\treturn hookErrorResult;\n// \t\t}\n// \t};\n\n// \treturn { errorContext, errorResult, executeHooksInCatchBlock, shouldThrowOnError };\n// };\n\ntype ErrorDetails<TErrorResponse> = {\n\tdefaultErrorMessage: CallApiExtraOptions[\"defaultErrorMessage\"];\n\terrorData: TErrorResponse;\n\tresponse: Response;\n};\n\n// export const httpErrorSymbol = Symbol(\"HTTPError\");\n\nexport class HTTPError<TErrorResponse = Record<string, unknown>> extends Error {\n\terrorData: ErrorDetails<TErrorResponse>[\"errorData\"];\n\n\tisHTTPError = true;\n\n\toverride name = \"HTTPError\" as const;\n\n\tresponse: ErrorDetails<TErrorResponse>[\"response\"];\n\n\tconstructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions) {\n\t\tconst { defaultErrorMessage, errorData, response } = errorDetails;\n\n\t\tconst selectedDefaultErrorMessage = defaultErrorMessage ?? commonDefaults.defaultErrorMessage;\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\tError.captureStackTrace(this, this.constructor);\n\t}\n}\n\nexport type PossibleJavaScriptError = UnmaskType<{\n\terrorData: DOMException | Error | SyntaxError | TypeError;\n\tmessage: string;\n\tname: \"AbortError\" | \"Error\" | \"SyntaxError\" | \"TimeoutError\" | \"TypeError\" | (`${string}Error` & {});\n}>;\n\nexport type PossibleHTTPError<TErrorData> = Prettify<\n\tUnmaskType<{\n\t\terrorData: TErrorData;\n\t\tmessage: string;\n\t\tname: \"HTTPError\";\n\t}>\n>;\n\nexport type ErrorInfo = {\n\tcloneResponse: CallApiExtraOptions[\"cloneResponse\"];\n\tdefaultErrorMessage: CallApiExtraOptions[\"defaultErrorMessage\"];\n\tmessage?: string;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n};\n\ntype ErrorResult = CallApiResultErrorVariant<unknown> | null;\n\nexport const resolveErrorResult = (error: unknown, info: ErrorInfo): ErrorResult => {\n\tconst { cloneResponse, defaultErrorMessage, message: customErrorMessage, resultMode } = info;\n\n\tlet details = {\n\t\tdata: null,\n\t\terror: {\n\t\t\terrorData: error as Error,\n\t\t\tmessage: customErrorMessage ?? (error as Error).message,\n\t\t\tname: (error as Error).name as PossibleJavaScriptError[\"name\"],\n\t\t},\n\t\tresponse: null,\n\t} satisfies CallApiResultErrorVariant<unknown> as CallApiResultErrorVariant<unknown>;\n\n\tif (isHTTPErrorInstance<never>(error)) {\n\t\tconst selectedDefaultErrorMessage = defaultErrorMessage ?? commonDefaults.defaultErrorMessage;\n\n\t\tconst { errorData, message = selectedDefaultErrorMessage, name, response } = error;\n\n\t\tdetails = {\n\t\t\tdata: null,\n\t\t\terror: {\n\t\t\t\terrorData,\n\t\t\t\tmessage,\n\t\t\t\tname,\n\t\t\t},\n\t\t\tresponse: cloneResponse ? response.clone() : response,\n\t\t};\n\t}\n\n\tconst resultModeMap = {\n\t\tall: details,\n\t\tallWithException: details as never,\n\t\tonlySuccess: details.data,\n\t\tonlySuccessWithException: details.data,\n\t} satisfies ResultModeMap;\n\n\tconst errorResult = resultModeMap[resultMode ?? \"all\"];\n\n\treturn errorResult;\n};\n\nexport const getCustomizedErrorResult = (\n\terrorResult: ErrorResult,\n\tcustomErrorInfo: { message: string }\n): ErrorResult => {\n\tif (!errorResult) {\n\t\treturn null;\n\t}\n\n\tconst { message = errorResult.error.message } = customErrorInfo;\n\n\treturn {\n\t\t...errorResult,\n\t\terror: {\n\t\t\t...errorResult.error,\n\t\t\tmessage,\n\t\t} satisfies NonNullable<ErrorResult>[\"error\"] as never,\n\t};\n};\n","import { type CallApiResultErrorVariant, HTTPError, type PossibleHTTPError } from \"../result\";\nimport type { AnyFunction } from \"./type-helpers\";\n\nexport const isHTTPError = <TErrorData>(\n\terror: CallApiResultErrorVariant<TErrorData>[\"error\"] | null\n): error is PossibleHTTPError<TErrorData> => {\n\treturn isPlainObject(error) && error.name === \"HTTPError\";\n};\n\nexport const isHTTPErrorInstance = <TErrorResponse>(\n\terror: unknown\n): error is HTTPError<TErrorResponse> => {\n\tif (error instanceof HTTPError) {\n\t\treturn true;\n\t}\n\n\treturn isPlainObject(error) && error.name === \"HTTPError\" && error.isHTTPError === true;\n};\n\n// FIXME: Outsource to type-helpers later as a peer dependency\n\nexport const isArray = <TArrayItem>(value: unknown): value is TArrayItem[] => Array.isArray(value);\n\nexport const isObject = (value: unknown) => typeof value === \"object\" && value !== null;\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 isJsonString = (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\n// https://github.com/unjs/ofetch/blob/main/src/utils.ts\n// TODO Find a way to incorporate this function in checking when to apply the bodySerializer on the body and also whether to add the content type application/json\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\nexport const isReadableStream = (value: unknown): value is ReadableStream<unknown> => {\n\treturn value instanceof ReadableStream;\n};\n","/* eslint-disable perfectionist/sort-object-types -- Avoid Sorting for now */\n\nimport type { ExtraOptions } from \"./types/common\";\nimport { isFunction, isString } from \"./utils/guards\";\nimport type { Awaitable } from \"./utils/type-helpers\";\n\ntype ValueOrFunctionResult<TValue> = TValue | (() => TValue);\n\ntype ValidAuthValue = ValueOrFunctionResult<Awaitable<string | null | undefined>>;\n\n/**\n * Bearer Or Token authentication\n *\n * The value of `bearer` will be added to a header as\n * `auth: Bearer some-auth-token`,\n *\n * The value of `token` will be added to a header as\n * `auth: Token some-auth-token`,\n */\nexport type BearerOrTokenAuth =\n\t| {\n\t\t\ttype?: \"Bearer\";\n\t\t\tbearer?: ValidAuthValue;\n\t\t\ttoken?: never;\n\t }\n\t| {\n\t\t\ttype?: \"Token\";\n\t\t\tbearer?: never;\n\t\t\ttoken?: ValidAuthValue;\n\t };\n\n/**\n * Basic auth\n */\nexport type BasicAuth = {\n\ttype: \"Basic\";\n\tusername: ValidAuthValue;\n\tpassword: ValidAuthValue;\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: ValidAuthValue;\n\tvalue: ValidAuthValue;\n};\n\n// eslint-disable-next-line perfectionist/sort-union-types -- Let the first one be first\nexport type Auth = BearerOrTokenAuth | BasicAuth | CustomAuth;\n\nconst getValue = (value: ValidAuthValue) => {\n\treturn isFunction(value) ? value() : value;\n};\n\ntype AuthorizationHeader = {\n\tAuthorization: string;\n};\n\nexport const getAuthHeader = async (\n\tauth: ExtraOptions[\"auth\"]\n): Promise<false | AuthorizationHeader | undefined> => {\n\tif (auth === undefined) return;\n\n\tif (isString(auth) || auth === null) {\n\t\treturn { Authorization: `Bearer ${auth}` };\n\t}\n\n\tswitch (auth.type) {\n\t\tcase \"Basic\": {\n\t\t\tconst username = await getValue(auth.username);\n\t\t\tconst password = await getValue(auth.password);\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 value = await getValue(auth.value);\n\n\t\t\tif (value === undefined) return;\n\n\t\t\tconst prefix = await getValue(auth.prefix);\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 = await getValue(auth.bearer);\n\t\t\tconst token = await getValue(auth.token);\n\n\t\t\tif (\"token\" in auth && token !== undefined) {\n\t\t\t\treturn { Authorization: `Token ${token}` };\n\t\t\t}\n\n\t\t\treturn bearer !== undefined && { Authorization: `Bearer ${bearer}` };\n\t\t}\n\t}\n};\n","import type { ModifiedRequestInit } from \"../types\";\nimport { defineEnum } from \"../utils/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 type { Auth } from \"../auth\";\nimport type { fetchSpecificKeys } from \"../constants/common\";\nimport type { ErrorContext, Hooks, HooksOrHooksArray } from \"../hooks\";\nimport type { CallApiPlugin, InferPluginOptions, Plugins } from \"../plugins\";\nimport type { GetCallApiResult, ResponseTypeUnion, ResultModeUnion } from \"../result\";\nimport type { RetryOptions } from \"../retry\";\nimport type { InitURL, UrlOptions } from \"../url\";\nimport { type Awaitable, type Prettify, type UnmaskType, defineEnum } from \"../utils/type-helpers\";\nimport type { CallApiSchemas, CallApiValidators, InferSchemaResult } from \"../validation\";\nimport type {\n\tBodyOption,\n\tHeadersOption,\n\tMetaOption,\n\tMethodOption,\n\tResultModeOption,\n} from \"./conditional-types\";\nimport type {\n\tDefaultDataType,\n\tDefaultMoreOptions,\n\tDefaultPluginArray,\n\tDefaultThrowOnError,\n} from \"./default-types\";\n\ntype FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], \"body\" | \"headers\" | \"method\">;\n\nexport type ModifiedRequestInit = RequestInit & { duplex?: \"half\" };\n\nexport type CallApiRequestOptions<TSchemas extends CallApiSchemas = DefaultMoreOptions> = Prettify<\n\tBodyOption<TSchemas>\n\t\t& HeadersOption<TSchemas>\n\t\t& MethodOption<TSchemas>\n\t\t& Pick<ModifiedRequestInit, FetchSpecificKeysUnion>\n>;\n\nexport type CallApiRequestOptionsForHooks<TSchemas extends CallApiSchemas = DefaultMoreOptions> = Omit<\n\tCallApiRequestOptions<TSchemas>,\n\t\"headers\"\n> & {\n\theaders?: Record<string, string | undefined>;\n};\n\ntype FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;\n\nexport type ExtraOptions<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResultMode extends ResultModeUnion = ResultModeUnion,\n\tTThrowOnError extends boolean = DefaultThrowOnError,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTPluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTSchemas extends CallApiSchemas = DefaultMoreOptions,\n> = {\n\t/**\n\t * Authorization header value.\n\t */\n\tauth?: string | Auth | null;\n\t/**\n\t * Base URL to be prepended to all request URLs\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * Custom function to serialize the body object into a string.\n\t */\n\tbodySerializer?: (bodyData: Record<string, unknown>) => string;\n\n\t/**\n\t * Whether or not to clone the response, so response.json() and the like, can be read again else where.\n\t * @see https://developer.mozilla.org/en-US/docs/Web/API/Response/clone\n\t * @default false\n\t */\n\tcloneResponse?: boolean;\n\n\t/**\n\t * Custom fetch implementation\n\t */\n\tcustomFetchImpl?: FetchImpl;\n\n\t/**\n\t * Custom request key to be used to identify a request in the fetch deduplication strategy.\n\t * @default the full request url + string formed from the request options\n\t */\n\tdedupeKey?: string;\n\n\t/**\n\t * Defines the deduplication strategy for the request, can be set to \"none\" | \"defer\" | \"cancel\".\n\t * - If set to \"cancel\", the previous pending request with the same request key will be cancelled and lets the new request through.\n\t * - If set to \"defer\", all new request with the same request key will be share the same response, until the previous one is completed.\n\t * - If set to \"none\", deduplication is disabled.\n\t * @default \"cancel\"\n\t */\n\tdedupeStrategy?: \"cancel\" | \"defer\" | \"none\";\n\n\t/**\n\t * Default error message to use if none is provided from a response.\n\t * @default \"Failed to fetch data from server!\"\n\t */\n\tdefaultErrorMessage?: string;\n\n\t/**\n\t * If true, forces the calculation of the total byte size from the request or response body, in case the content-length header is not present or is incorrect.\n\t * @default false\n\t */\n\tforceCalculateStreamSize?: boolean | { request?: boolean; response?: boolean };\n\n\t/**\n\t * Resolved request URL\n\t */\n\treadonly fullURL?: string;\n\n\t/**\n\t * Defines the mode in which the composed hooks are executed\".\n\t * - If set to \"parallel\", main and plugin hooks will be executed in parallel.\n\t * - If set to \"sequential\", the plugin hooks will be executed first, followed by the main hook.\n\t * @default \"parallel\"\n\t */\n\tmergedHooksExecutionMode?: \"parallel\" | \"sequential\";\n\n\t/**\n\t * - Controls what order in which the composed hooks execute\n\t * @default \"mainHooksAfterPlugins\"\n\t */\n\tmergedHooksExecutionOrder?: \"mainHooksAfterPlugins\" | \"mainHooksBeforePlugins\";\n\n\t/**\n\t * An array of CallApi plugins. It allows you to extend the behavior of the library.\n\t */\n\tplugins?: Plugins<TPluginArray>;\n\n\t/**\n\t * Custom function to parse the response string\n\t */\n\tresponseParser?: (responseString: string) => Awaitable<Record<string, unknown>>;\n\n\t/**\n\t * Expected response type, affects how response is parsed\n\t * @default \"json\"\n\t */\n\tresponseType?: TResponseType;\n\n\t/**\n\t * Mode of the result, can influence how results are handled or returned.\n\t * Can be set to \"all\" | \"onlySuccess\" | \"onlyError\" | \"onlyResponse\".\n\t * @default \"all\"\n\t */\n\tresultMode?: TResultMode;\n\n\t/**\n\t * Type-safe schemas for the response validation.\n\t */\n\tschemas?: TSchemas;\n\n\t/**\n\t * If true or the function returns true, throws errors instead of returning them\n\t * The function is passed the error object and can be used to conditionally throw the error\n\t * @default false\n\t */\n\tthrowOnError?: TThrowOnError | ((context: ErrorContext<TErrorData>) => TThrowOnError);\n\n\t/**\n\t * Request timeout in milliseconds\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Custom validation functions for response validation\n\t */\n\tvalidators?: CallApiValidators<TData, TErrorData>;\n\t/* eslint-disable perfectionist/sort-intersection-types -- Allow these to be last for the sake of docs */\n} & HooksOrHooksArray<TData, TErrorData, Partial<InferPluginOptions<TPluginArray>>>\n\t& Partial<InferPluginOptions<TPluginArray>>\n\t& MetaOption<TSchemas>\n\t& RetryOptions<TErrorData>\n\t& ResultModeOption<TErrorData, TResultMode>\n\t& UrlOptions<TSchemas>;\n/* eslint-enable perfectionist/sort-intersection-types -- Allow these to be last for the sake of docs */\n\nexport type CallApiExtraOptions<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResultMode extends ResultModeUnion = ResultModeUnion,\n\tTThrowOnError extends boolean = DefaultThrowOnError,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTPluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTSchemas extends CallApiSchemas = DefaultMoreOptions,\n> = ExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> & {\n\tplugins?:\n\t\t| Plugins<TPluginArray>\n\t\t| ((context: { basePlugins: Plugins<TPluginArray> }) => Plugins<TPluginArray>);\n\n\tschemas?: TSchemas | ((context: { baseSchemas: TSchemas | undefined }) => TSchemas);\n\n\tvalidators?:\n\t\t| CallApiValidators<TData, TErrorData>\n\t\t| ((context: {\n\t\t\t\tbaseValidators: CallApiValidators<TData, TErrorData> | undefined;\n\t\t }) => CallApiValidators<TData, TErrorData>);\n};\n\nexport const optionsEnumToOmitFromBase = defineEnum([\"dedupeKey\"] satisfies Array<\n\tkeyof CallApiExtraOptions\n>);\n\nexport type BaseCallApiExtraOptions<\n\tTBaseData = DefaultDataType,\n\tTBaseErrorData = DefaultDataType,\n\tTBaseResultMode extends ResultModeUnion = ResultModeUnion,\n\tTBaseThrowOnError extends boolean = DefaultThrowOnError,\n\tTBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTBaseSchemas extends CallApiSchemas = DefaultMoreOptions,\n> = Omit<\n\tPartial<\n\t\tCallApiExtraOptions<\n\t\t\tTBaseData,\n\t\t\tTBaseErrorData,\n\t\t\tTBaseResultMode,\n\t\t\tTBaseThrowOnError,\n\t\t\tTBaseResponseType,\n\t\t\tTBasePluginArray,\n\t\t\tTBaseSchemas\n\t\t>\n\t>,\n\t(typeof optionsEnumToOmitFromBase)[number]\n> & {\n\t/**\n\t * Specifies which configuration parts should skip automatic merging between base and main configs.\n\t * Use this when you need manual control over how configs are combined.\n\t *\n\t * @values\n\t * - \"all\" - Disables automatic merging for both request and options\n\t * - \"options\" - Disables automatic merging of options only\n\t * - \"request\" - Disables automatic merging of request only\n\t *\n\t * @example\n\t * ```ts\n\t * const client = createFetchClient((ctx) => ({\n\t * skipAutoMergeFor: \"options\",\n\t *\n\t * // Now you can manually merge options in your config function\n\t * ...ctx.options,\n\t * }));\n\t * ```\n\t */\n\tskipAutoMergeFor?: \"all\" | \"options\" | \"request\";\n};\n\ntype CombinedExtraOptionsWithoutHooks = Omit<BaseCallApiExtraOptions & CallApiExtraOptions, keyof Hooks>;\n\n// eslint-disable-next-line ts-eslint/consistent-type-definitions -- Allow this to be an interface\nexport interface CombinedCallApiExtraOptions extends CombinedExtraOptionsWithoutHooks, Hooks {}\n\nexport type BaseCallApiConfig<\n\tTBaseData = DefaultDataType,\n\tTBaseErrorData = DefaultDataType,\n\tTBaseResultMode extends ResultModeUnion = ResultModeUnion,\n\tTBaseThrowOnError extends boolean = DefaultThrowOnError,\n\tTBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTBaseSchemas extends CallApiSchemas = DefaultMoreOptions,\n> =\n\t| (CallApiRequestOptions<TBaseSchemas> // eslint-disable-next-line perfectionist/sort-intersection-types -- Allow\n\t\t\t& BaseCallApiExtraOptions<\n\t\t\t\tTBaseData,\n\t\t\t\tTBaseErrorData,\n\t\t\t\tTBaseResultMode,\n\t\t\t\tTBaseThrowOnError,\n\t\t\t\tTBaseResponseType,\n\t\t\t\tTBasePluginArray,\n\t\t\t\tTBaseSchemas\n\t\t\t>)\n\t| ((context: {\n\t\t\tinitURL: string;\n\t\t\toptions: CallApiExtraOptions;\n\t\t\trequest: CallApiRequestOptions;\n\t }) => CallApiRequestOptions<TBaseSchemas> // eslint-disable-next-line perfectionist/sort-intersection-types -- Allow\n\t\t\t& BaseCallApiExtraOptions<\n\t\t\t\tTBaseData,\n\t\t\t\tTBaseErrorData,\n\t\t\t\tTBaseResultMode,\n\t\t\t\tTBaseThrowOnError,\n\t\t\t\tTBaseResponseType,\n\t\t\t\tTBasePluginArray,\n\t\t\t\tTBaseSchemas\n\t\t\t>);\n\nexport type CallApiConfig<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResultMode extends ResultModeUnion = ResultModeUnion,\n\tTThrowOnError extends boolean = DefaultThrowOnError,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTPluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTSchemas extends CallApiSchemas = DefaultMoreOptions,\n> = CallApiRequestOptions<TSchemas> // eslint-disable-next-line perfectionist/sort-intersection-types -- Allow these to be last for the sake of docs\n\t& CallApiExtraOptions<\n\t\tTData,\n\t\tTErrorData,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType,\n\t\tTPluginArray,\n\t\tTSchemas\n\t>;\n\nexport type CallApiParameters<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResultMode extends ResultModeUnion = ResultModeUnion,\n\tTThrowOnError extends boolean = DefaultThrowOnError,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTPluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTSchemas extends CallApiSchemas = DefaultMoreOptions,\n> = [\n\tinitURL: InferSchemaResult<TSchemas[\"initURL\"], InitURL>,\n\tconfig?: CallApiConfig<\n\t\tTData,\n\t\tTErrorData,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType,\n\t\tTPluginArray,\n\t\tTSchemas\n\t>,\n];\n\nexport type CallApiResult<\n\tTData,\n\tTErrorData,\n\tTResultMode extends ResultModeUnion,\n\tTThrowOnError extends boolean,\n\tTResponseType extends ResponseTypeUnion,\n> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;\n","import { getAuthHeader } from \"../auth\";\nimport { fetchSpecificKeys } from \"../constants/common\";\nimport {\n\ttype BaseCallApiExtraOptions,\n\ttype CallApiExtraOptions,\n\ttype CallApiRequestOptions,\n\toptionsEnumToOmitFromBase,\n} from \"../types/common\";\nimport { isFunction, isJsonString, isPlainObject, isQueryString, isSerializable } from \"./guards\";\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, [\n\t\t\t...fetchSpecificKeys,\n\t\t\t...optionsEnumToOmitFromBase,\n\t\t]) 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\ntype MergeAndResolveHeadersOptions = {\n\tauth: CallApiExtraOptions[\"auth\"];\n\tbaseHeaders?: CallApiRequestOptions[\"headers\"];\n\tbody: CallApiRequestOptions[\"body\"];\n\theaders: CallApiRequestOptions[\"headers\"];\n};\n\nexport const getHeaders = async (options: MergeAndResolveHeadersOptions) => {\n\tconst { auth, baseHeaders, body, headers } = options;\n\n\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- Nullish coalescing makes no sense in this boolean context\n\tconst shouldResolveHeaders = Boolean(baseHeaders || headers || body || auth);\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\t// == - headers are provided\n\t// == - The body is an object\n\t// == - The auth option is provided\n\tif (!shouldResolveHeaders) return;\n\n\tconst headersObject: Record<string, string | undefined> = {\n\t\t...(await getAuthHeader(auth)),\n\t\t...objectifyHeaders(baseHeaders),\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) || isJsonString(body)) {\n\t\theadersObject[\"Content-Type\"] = \"application/json\";\n\t\theadersObject.Accept = \"application/json\";\n\t}\n\n\treturn headersObject;\n};\n\nexport const getFetchImpl = (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\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 waitUntil = (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(Boolean);\n\n\tconst combinedSignal = AbortSignal.any(cleanedSignals);\n\n\treturn combinedSignal;\n};\n\nexport const createTimeoutSignal = (milliseconds: number) => AbortSignal.timeout(milliseconds);\n"]}