@zayne-labs/callapi 1.11.23 → 1.11.25

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
@@ -26,7 +26,7 @@
26
26
 
27
27
  ---
28
28
 
29
- ## Why?
29
+ ## Why CallApi?
30
30
 
31
31
  Fetch is too basic for real apps. You end up writing the same boilerplate: error handling, retries, deduplication, response parsing etc. CallApi handles all of that and practically more.
32
32
 
@@ -40,20 +40,26 @@ const { data, error } = await callApi("/api/users");
40
40
 
41
41
  ## Features
42
42
 
43
- **Request Deduplication** - User spam-clicks a button? Handled. No race conditions.
43
+ ### Request Deduplication
44
+
45
+ User spam-clicks a button? Handled. No race conditions.
44
46
 
45
47
  ```js
46
48
  const req1 = callApi("/api/user");
47
49
  const req2 = callApi("/api/user"); // Cancels req1 (can be configured to share it's response instead)
48
50
  ```
49
51
 
50
- **Smart Response Parsing** - Looks at Content-Type, does the right thing.
52
+ ### Smart Response Parsing
53
+
54
+ Looks at Content-Type and parses accordingly.
51
55
 
52
56
  ```js
53
57
  const { data } = await callApi("/api/data"); // JSON? Parsed.
54
58
  ```
55
59
 
56
- **Error Handling** - Structured errors, making proper error handling trivial.
60
+ ### Error Handling
61
+
62
+ Structured errors make robust error handling trivial.
57
63
 
58
64
  ```js
59
65
  const { data, error } = await callApi("/api/users");
@@ -64,7 +70,9 @@ if (error) {
64
70
  }
65
71
  ```
66
72
 
67
- **Retries** - Exponential backoff, custom conditions etc.
73
+ ### Retries
74
+
75
+ Supports exponential backoff and custom retry conditions.
68
76
 
69
77
  ```js
70
78
  await callApi("/api/data", {
@@ -74,9 +82,11 @@ await callApi("/api/data", {
74
82
  });
75
83
  ```
76
84
 
77
- **Schema Validation** - TypeScript types + runtime validation.
85
+ ### Schema Validation
78
86
 
79
- ```js
87
+ TypeScript-first types with runtime validation.
88
+
89
+ ```ts
80
90
  import { z } from "zod";
81
91
  import { createFetchClient } from "@zayne-labs/callapi";
82
92
  import { defineSchema } from "@zayne-labs/callapi/utils";
@@ -98,7 +108,9 @@ const user = await callMainApi("/users/:id", {
98
108
  });
99
109
  ```
100
110
 
101
- **Hooks** - Hook in callApi's lifecycle at any point.
111
+ ### Hooks
112
+
113
+ Hook into CallApi's lifecycle at any point.
102
114
 
103
115
  ```js
104
116
  const api = createFetchClient({
@@ -114,7 +126,9 @@ const api = createFetchClient({
114
126
  });
115
127
  ```
116
128
 
117
- **Plugins** - Extend with setup, hooks, and middleware.
129
+ ### Plugins
130
+
131
+ Extend functionality with setup, hooks, and middleware.
118
132
 
119
133
  ```js
120
134
  const metricsPlugin = definePlugin({
@@ -153,7 +167,9 @@ const api = createFetchClient({
153
167
  });
154
168
  ```
155
169
 
156
- **URL Helpers** - Dynamic params, query strings, method prefixes.
170
+ ### URL Helpers
171
+
172
+ Dynamic params, query strings, and method prefixes.
157
173
 
158
174
  ```js
159
175
  await callApi("/users/:id", { params: { id: 123 } });
@@ -161,7 +177,9 @@ await callApi("/search", { query: { q: "test" } });
161
177
  await callApi("@delete/users/123");
162
178
  ```
163
179
 
164
- **See the [full documentation](https://zayne-labs-callapi.netlify.app/docs) for all features.**
180
+ And so many more
181
+
182
+ See the [full documentation](https://zayne-labs-callapi.netlify.app/docs) for the full list of features.
165
183
 
166
184
  ## Installation
167
185
 
@@ -1 +1 @@
1
- {"version":3,"file":"defaults-C6WKIXsf.js","names":[],"sources":["../src/types/type-helpers.ts","../src/constants/defaults.ts"],"sourcesContent":["// == These two types allows for adding arbitrary literal types, while still provided autocomplete for defaults.\n\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 Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };\n\ntype 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[] | readonly unknown[];\n\nexport type Writeable<TObject, TLevel extends WriteableLevel = \"shallow\"> =\n\tTObject extends ArrayOrObject ?\n\t\t{\n\t\t\t-readonly [Key in keyof TObject]: TLevel extends \"deep\" ?\n\t\t\t\tNonNullable<TObject[Key]> extends ArrayOrObject ?\n\t\t\t\t\tWriteable<TObject[Key], \"deep\">\n\t\t\t\t:\tTObject[Key]\n\t\t\t:\tTObject[Key];\n\t\t}\n\t:\tTObject;\n\nexport const defineEnum = <const TValue extends object>(value: TValue) =>\n\tObject.freeze(value) as Readonly<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 RemovePrefix<TPrefix extends \"dedupe\" | \"retry\", TKey extends string> =\n\tTKey extends `${TPrefix}${infer TRest}` ? Uncapitalize<TRest> : TKey;\n\nexport type Awaitable<TValue> = Promise<TValue> | TValue;\n\n// export type MatchExactObjectType<TActualObject extends TExpectedObject, TExpectedObject> = {\n// \t[Key in keyof TActualObject]: Key extends keyof TExpectedObject ? TActualObject[Key] : never;\n// };\n\n// export type MatchExactObjectType<TActualObject extends TExpectedObject, TExpectedObject> = {\n// \t[Key in keyof TActualObject]: Key extends keyof TExpectedObject ?\n// \t\tTActualObject[Key]\n// \t:\tnever;\n// };\nexport type Satisfies<TActualObject extends TExpectedObject, TExpectedObject> = {\n\t[Key in keyof TActualObject & keyof TExpectedObject]: TActualObject[Key];\n};\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 = Object.freeze(\n\tdefineEnum({\n\t\t// Common defaults\n\t\tbodySerializer: JSON.stringify,\n\t\tdefaultHTTPErrorMessage: \"Request failed unexpectedly\",\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 = defineEnum({\n\tmethod: \"GET\",\n} satisfies CallApiConfig);\n"],"mappings":";AAoCA,MAAa,cAA2C,UACvD,OAAO,OAAO,MAAM;;;;AClCrB,MAAa,sBAAsB,OAAO,OACzC,WAAW;CAEV,gBAAgB,KAAK;CACrB,yBAAyB;CAIzB,kBAAkB;CAClB,qBAAqB;CACrB,gBAAgB;CAIhB,oBAAoB;CAGpB,gBAAgB,KAAK;CACrB,cAAc;CACd,YAAY;CAGZ,eAAe;CACf,sBAAsB;CACtB,YAAY;CACZ,eAAe;CACf,cAAc,CAAC,OAAO,OAAO;CAC7B,kBAAkB,EAAE;CACpB,eAAe;CACf,CAA+B,CAChC;AAED,MAAa,wBAAwB,WAAW,EAC/C,QAAQ,OACR,CAAyB"}
1
+ {"version":3,"file":"defaults-C6WKIXsf.js","names":[],"sources":["../src/types/type-helpers.ts","../src/constants/defaults.ts"],"sourcesContent":["// == These two types allows for adding arbitrary literal types, while still provided autocomplete for defaults.\n\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 Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };\n\ntype 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[] | readonly unknown[];\n\nexport type Writeable<TObject, TLevel extends WriteableLevel = \"shallow\"> =\n\tTObject extends ArrayOrObject ?\n\t\t{\n\t\t\t-readonly [Key in keyof TObject]: TLevel extends \"deep\" ?\n\t\t\t\tNonNullable<TObject[Key]> extends ArrayOrObject ?\n\t\t\t\t\tWriteable<TObject[Key], \"deep\">\n\t\t\t\t:\tTObject[Key]\n\t\t\t:\tTObject[Key];\n\t\t}\n\t:\tTObject;\n\nexport const defineEnum = <const TValue extends object>(value: TValue) =>\n\tObject.freeze(value) as Readonly<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 RemovePrefix<TPrefix extends \"dedupe\" | \"retry\", TKey extends string> =\n\tTKey extends `${TPrefix}${infer TRest}` ? Uncapitalize<TRest> : TKey;\n\nexport type Awaitable<TValue> = Promise<TValue> | TValue;\n\n// export type MatchExactObjectType<TActualObject extends TExpectedObject, TExpectedObject> = {\n// \t[Key in keyof TActualObject]: Key extends keyof TExpectedObject ? TActualObject[Key] : never;\n// };\n\nexport type Satisfies<TActualObject extends TExpectedObject, TExpectedObject> = {\n\t[Key in keyof TActualObject]: Key extends keyof TExpectedObject ? TActualObject[Key] : never;\n};\n// export type Satisfies<TActualObject extends TExpectedObject, TExpectedObject> = {\n// \t[Key in keyof TActualObject & keyof TExpectedObject]: TActualObject[Key];\n// };\n\nexport type DistributiveOmit<TObject, TKeysToOmit extends keyof TObject> =\n\tTObject extends unknown ? Omit<TObject, TKeysToOmit> : never;\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 = Object.freeze(\n\tdefineEnum({\n\t\t// Common defaults\n\t\tbodySerializer: JSON.stringify,\n\t\tdefaultHTTPErrorMessage: \"Request failed unexpectedly\",\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 = defineEnum({\n\tmethod: \"GET\",\n} satisfies CallApiConfig);\n"],"mappings":";AAoCA,MAAa,cAA2C,UACvD,OAAO,OAAO,MAAM;;;;AClCrB,MAAa,sBAAsB,OAAO,OACzC,WAAW;CAEV,gBAAgB,KAAK;CACrB,yBAAyB;CAIzB,kBAAkB;CAClB,qBAAqB;CACrB,gBAAgB;CAIhB,oBAAoB;CAGpB,gBAAgB,KAAK;CACrB,cAAc;CACd,YAAY;CAGZ,eAAe;CACf,sBAAsB;CACtB,YAAY;CACZ,eAAe;CACf,cAAc,CAAC,OAAO,OAAO;CAC7B,kBAAkB,EAAE;CACpB,eAAe;CACf,CAA+B,CAChC;AAED,MAAa,wBAAwB,WAAW,EAC/C,QAAQ,OACR,CAAyB"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  import "./validation-Dq--Q5zC.js";
2
- import { $ as CallApiResultSuccessVariantWithoutResponse, A as RequestContext, C as ThrowOnErrorUnion, Ct as DefaultPluginArray, D as Hooks, Dt as AnyString, E as ErrorContext, F as SuccessContext, J as PluginHooks, M as ResponseContext, N as ResponseErrorContext, O as HooksOrHooksArray, P as ResponseStreamContext, Q as CallApiResultSuccessVariant, S as Register, St as DefaultDataType, T as DedupeOptions, X as PluginSetupContext, Y as PluginHooksWithMoreOptions, Z as CallApiResultErrorVariant, _ as ApplyURLBasedConfig, _t as CallApiSchemaConfig, a as CallApiExtraOptionsForHooks, at as PossibleJavaScriptOrValidationError, b as InferInitURL, bt as InferSchemaResult, c as CallApiRequestOptionsForHooks, ct as ResponseTypeType, d as GetBaseSchemaConfig, et as CallApiSuccessOrErrorVariant, f as GetBaseSchemaRoutes, g as ApplyStrictConfig, gt as CallApiSchema, h as InstanceContext, ht as BaseSchemaRouteKeyPrefixes, i as CallApiExtraOptions, it as PossibleJavaScriptError, j as RequestStreamContext, k as PluginExtraOptions, l as CallApiResult, lt as ResultModeMap, m as InferExtendSchemaContext, mt as BaseCallApiSchemaRoutes, n as BaseCallApiExtraOptions, nt as GetResponseType, o as CallApiParameters, ot as PossibleValidationError, p as InferExtendSchemaConfigContext, pt as BaseCallApiSchemaAndConfig, q as CallApiPlugin, r as CallApiConfig, rt as PossibleHTTPError, s as CallApiRequestOptions, st as ResponseTypeMap, t as BaseCallApiConfig, tt as GetCallApiResult, u as CallApiResultLoose, ut as ResultModeType, v as GetCurrentRouteSchema, vt as InferSchemaInput, w as RetryOptions, wt as DefaultThrowOnError, x as InferParamsFromRoute, xt as URLOptions, y as GetCurrentRouteSchemaKey, yt as InferSchemaOutput } from "./common-BKNanXjv.js";
2
+ import { A as InferInitURL, B as RequestContext, C as InferExtendSchemaConfigContext, Ct as DefaultPluginArray, D as ApplyURLBasedConfig, Dt as Writeable, E as ApplyStrictConfig, Et as AnyString, F as DedupeOptions, G as SuccessContext, H as ResponseContext, I as ErrorContext, L as Hooks, M as Register, N as ThrowOnErrorUnion, O as GetCurrentRouteSchema, P as RetryOptions, R as HooksOrHooksArray, S as GetBaseSchemaRoutes, T as InstanceContext, U as ResponseErrorContext, V as RequestStreamContext, W as ResponseStreamContext, _ as CallApiRequestOptions, _t as ResponseTypeMap, a as CallApiSchemaConfig, at as PluginHooksWithMoreOptions, b as CallApiResultLoose, bt as ResultModeType, c as InferSchemaResult, ct as CallApiResultErrorVariant, d as BlankCallApiEnv, dt as GetCallApiResult, f as CallApiConfig, ft as GetResponseType, g as CallApiParameters, gt as PossibleValidationError, h as CallApiExtraOptionsForHooks, ht as PossibleJavaScriptOrValidationError, i as CallApiSchema, it as PluginHooks, j as InferParamsFromRoute, k as GetCurrentRouteSchemaKey, l as BaseCallApiConfig, lt as CallApiResultSuccessVariant, m as CallApiExtraOptions, mt as PossibleJavaScriptError, n as BaseCallApiSchemaRoutes, o as InferSchemaInput, ot as PluginSetupContext, p as CallApiEnv, pt as PossibleHTTPError, r as BaseSchemaRouteKeyPrefixes, rt as CallApiPlugin, s as InferSchemaOutput, st as URLOptions, t as BaseCallApiSchemaAndConfig, u as BaseCallApiExtraOptions, ut as CallApiSuccessOrErrorVariant, v as CallApiRequestOptionsForHooks, vt as ResponseTypeType, w as InferExtendSchemaContext, x as GetBaseSchemaConfig, y as CallApiResult, yt as ResultModeMap, z as PluginExtraOptions } from "./validation-BXtphXvQ.js";
3
3
 
4
4
  //#region src/createFetchClient.d.ts
5
5
 
6
- declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = GetBaseSchemaConfig<TBaseSchemaAndConfig>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = GetBaseSchemaRoutes<TBaseSchemaAndConfig>>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeType = TBaseResultMode, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeType = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedResult = CallApiResult<InferSchemaOutput<TSchema["data"], TData>, InferSchemaOutput<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaOutput<TSchema["data"], GetResponseType<TData, TResponseType>>, InferSchemaOutput<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => Promise<TComputedResult>;
7
- declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = boolean, TResponseType extends ResponseTypeType = ResponseTypeType, const TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<{
6
+ declare const createFetchClientWithEnv: <TOuterCallApiEnv extends CallApiEnv = BlankCallApiEnv>() => <TBaseData = unknown, TBaseErrorData = unknown, TBaseResultMode extends ResultModeType = ResultModeType, TBaseCallApiEnv extends CallApiEnv = TOuterCallApiEnv, TBaseThrowOnError extends ThrowOnErrorUnion = boolean, TBaseResponseType extends ResponseTypeType = ResponseTypeType, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = GetBaseSchemaConfig<TBaseSchemaAndConfig>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = GetBaseSchemaRoutes<TBaseSchemaAndConfig>>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseCallApiEnv, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeType = TBaseResultMode, TCallApiEnv extends CallApiEnv = TBaseCallApiEnv, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeType = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedResult = CallApiResult<InferSchemaOutput<TSchema["data"], TData>, InferSchemaOutput<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaOutput<TSchema["data"], GetResponseType<TData, TResponseType>>, InferSchemaOutput<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TResultMode, TCallApiEnv, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => Promise<TComputedResult>;
7
+ declare const createFetchClient: <TBaseData = unknown, TBaseErrorData = unknown, TBaseResultMode extends ResultModeType = ResultModeType, TBaseCallApiEnv extends CallApiEnv = BlankCallApiEnv, TBaseThrowOnError extends ThrowOnErrorUnion = boolean, TBaseResponseType extends ResponseTypeType = ResponseTypeType, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = Writeable<NonNullable<TBaseSchemaAndConfig["config"]>, "deep">, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = Writeable<TBaseSchemaAndConfig["routes"], "deep">>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseCallApiEnv, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeType = TBaseResultMode, TCallApiEnv extends CallApiEnv = TBaseCallApiEnv, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeType = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey, TComputedBaseSchemaRoutes["@default"], TComputedBaseSchemaRoutes[TCurrentRouteSchemaKey], NonNullable<Omit<TComputedBaseSchemaRoutes["@default"], keyof TComputedBaseSchemaRoutes[TCurrentRouteSchemaKey]> & TComputedBaseSchemaRoutes[TCurrentRouteSchemaKey]>>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedResult = GetCallApiResult<InferSchemaResult<TSchema["data"], TData, "infer-output">, InferSchemaResult<TSchema["errorData"], TErrorData, "infer-output">, TResultMode, TThrowOnError, TResponseType, {
8
+ all: CallApiResultSuccessVariant<GetResponseType<InferSchemaResult<TSchema["data"], TData, "infer-output">, TResponseType, ResponseTypeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">>>>;
9
+ onlyData: NoInfer<GetResponseType<InferSchemaResult<TSchema["data"], TData, "infer-output">, TResponseType, ResponseTypeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">>>>;
10
+ onlyResponse: Response;
11
+ withoutResponse: Omit<CallApiResultSuccessVariant<GetResponseType<InferSchemaResult<TSchema["data"], TData, "infer-output">, TResponseType, ResponseTypeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">>>>, "response">;
12
+ }, ResultModeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">, InferSchemaResult<TSchema["errorData"], TErrorData, "infer-output">, TResponseType, TThrowOnError>>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>, "infer-output">, InferSchemaResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>, "infer-output">, TResultMode, TCallApiEnv, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => Promise<TComputedResult>;
13
+ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeType = ResultModeType, TCallApiEnv extends CallApiEnv = BlankCallApiEnv, TThrowOnError extends ThrowOnErrorUnion = boolean, TResponseType extends ResponseTypeType = ResponseTypeType, const TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<{
8
14
  [x: AnyString]: CallApiSchema | undefined;
9
15
  "@default"?: CallApiSchema | undefined;
10
16
  "@delete/"?: CallApiSchema | undefined;
@@ -40,8 +46,8 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
40
46
  all: CallApiResultSuccessVariant<GetResponseType<InferSchemaResult<TSchema["data"], TData, "infer-output">, TResponseType, ResponseTypeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">>>>;
41
47
  onlyData: NoInfer<GetResponseType<InferSchemaResult<TSchema["data"], TData, "infer-output">, TResponseType, ResponseTypeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">>>>;
42
48
  onlyResponse: Response;
43
- withoutResponse: CallApiResultSuccessVariantWithoutResponse<GetResponseType<InferSchemaResult<TSchema["data"], TData, "infer-output">, TResponseType, ResponseTypeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">>>>;
44
- }, ResultModeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">, InferSchemaResult<TSchema["errorData"], TErrorData, "infer-output">, TResponseType, TThrowOnError>>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>, "infer-output">, InferSchemaResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>, "infer-output">, TResultMode, TThrowOnError, TResponseType, {
49
+ withoutResponse: Omit<CallApiResultSuccessVariant<GetResponseType<InferSchemaResult<TSchema["data"], TData, "infer-output">, TResponseType, ResponseTypeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">>>>, "response">;
50
+ }, ResultModeMap<InferSchemaResult<TSchema["data"], TData, "infer-output">, InferSchemaResult<TSchema["errorData"], TErrorData, "infer-output">, TResponseType, TThrowOnError>>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>, "infer-output">, InferSchemaResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>, "infer-output">, TResultMode, TCallApiEnv, TThrowOnError, TResponseType, {
45
51
  [x: AnyString]: CallApiSchema | undefined;
46
52
  "@default"?: CallApiSchema | undefined;
47
53
  "@delete/"?: CallApiSchema | undefined;
@@ -51,5 +57,5 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
51
57
  "@put/"?: CallApiSchema | undefined;
52
58
  }, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray>) => Promise<TComputedResult>;
53
59
  //#endregion
54
- export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type BaseSchemaRouteKeyPrefixes, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResultLoose as CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type CallApiSuccessOrErrorVariant, type DedupeOptions, type ErrorContext, type Hooks, type HooksOrHooksArray, type InferExtendSchemaConfigContext, type InferExtendSchemaContext, type InferParamsFromRoute, type InferSchemaInput, type InferSchemaOutput, type InstanceContext, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type PluginSetupContext, type PossibleHTTPError, type PossibleJavaScriptError, type PossibleJavaScriptOrValidationError, type PossibleValidationError, type Register, type RequestContext, type RequestStreamContext, type ResponseContext, type ResponseErrorContext, type ResponseStreamContext, type ResponseTypeType, type ResultModeType, type RetryOptions, type SuccessContext, type URLOptions, callApi, createFetchClient };
60
+ export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type BaseSchemaRouteKeyPrefixes, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResultLoose as CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type CallApiSuccessOrErrorVariant, type DedupeOptions, type ErrorContext, type Hooks, type HooksOrHooksArray, type InferExtendSchemaConfigContext, type InferExtendSchemaContext, type InferParamsFromRoute, type InferSchemaInput, type InferSchemaOutput, type InstanceContext, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type PluginSetupContext, type PossibleHTTPError, type PossibleJavaScriptError, type PossibleJavaScriptOrValidationError, type PossibleValidationError, type Register, type RequestContext, type RequestStreamContext, type ResponseContext, type ResponseErrorContext, type ResponseStreamContext, type ResponseTypeType, type ResultModeType, type RetryOptions, type SuccessContext, type URLOptions, callApi, createFetchClient, createFetchClientWithEnv };
55
61
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -977,213 +977,217 @@ const createRetryManager = (ctx) => {
977
977
  //#endregion
978
978
  //#region src/createFetchClient.ts
979
979
  const $GlobalRequestInfoCache = /* @__PURE__ */ new Map();
980
- const createFetchClient = (initBaseConfig = {}) => {
981
- const $LocalRequestInfoCache = /* @__PURE__ */ new Map();
982
- const callApi$1 = async (initURL, initConfig = {}) => {
983
- const [fetchOptions, extraOptions] = splitConfig(initConfig);
984
- const baseConfig = isFunction(initBaseConfig) ? initBaseConfig({
985
- initURL: initURL.toString(),
986
- options: extraOptions,
987
- request: fetchOptions
988
- }) : initBaseConfig;
989
- const config = initConfig;
990
- const [baseFetchOptions, baseExtraOptions] = splitBaseConfig(baseConfig);
991
- const shouldSkipAutoMergeForOptions = baseExtraOptions.skipAutoMergeFor === "all" || baseExtraOptions.skipAutoMergeFor === "options";
992
- const shouldSkipAutoMergeForRequest = baseExtraOptions.skipAutoMergeFor === "all" || baseExtraOptions.skipAutoMergeFor === "request";
993
- const mergedExtraOptions = {
994
- ...baseExtraOptions,
995
- ...!shouldSkipAutoMergeForOptions && extraOptions
996
- };
997
- const mergedRequestOptions = {
998
- headers: {},
999
- ...baseFetchOptions,
1000
- ...!shouldSkipAutoMergeForRequest && fetchOptions
1001
- };
1002
- const { resolvedCurrentRouteSchemaKey, resolvedHooks, resolvedInitURL, resolvedMiddlewares, resolvedOptions, resolvedRequestOptions } = await initializePlugins({
1003
- baseConfig,
1004
- config,
1005
- initURL: initURL.toString(),
1006
- options: mergedExtraOptions,
1007
- request: mergedRequestOptions
1008
- });
1009
- const { fullURL, normalizedInitURL } = getFullAndNormalizedURL({
1010
- baseURL: resolvedOptions.baseURL,
1011
- initURL: resolvedInitURL,
1012
- params: resolvedOptions.params,
1013
- query: resolvedOptions.query
1014
- });
1015
- const options = {
1016
- ...resolvedOptions,
1017
- ...resolvedHooks,
1018
- ...resolvedMiddlewares,
1019
- fullURL,
1020
- initURL: resolvedInitURL,
1021
- initURLNormalized: normalizedInitURL
1022
- };
1023
- const newFetchController = new AbortController();
1024
- const combinedSignal = createCombinedSignal(createTimeoutSignal(options.timeout), resolvedRequestOptions.signal, newFetchController.signal);
1025
- const initMethod = getMethod({
1026
- initURL: resolvedInitURL,
1027
- method: resolvedRequestOptions.method
1028
- });
1029
- const request = {
1030
- ...resolvedRequestOptions,
1031
- method: initMethod,
1032
- signal: combinedSignal
1033
- };
1034
- const { getAbortErrorMessage, handleRequestCancelStrategy, handleRequestDeferStrategy, removeDedupeKeyFromCache, resolvedDedupeStrategy } = await createDedupeStrategy({
1035
- $GlobalRequestInfoCache,
1036
- $LocalRequestInfoCache,
1037
- baseConfig,
1038
- config,
1039
- newFetchController,
1040
- options,
1041
- request
1042
- });
1043
- try {
1044
- await handleRequestCancelStrategy();
1045
- await executeHooks(options.onRequest?.({
980
+ const createFetchClientWithEnv = () => {
981
+ const createFetchClient$1 = (initBaseConfig = {}) => {
982
+ const $LocalRequestInfoCache = /* @__PURE__ */ new Map();
983
+ const callApi$1 = async (initURL, initConfig = {}) => {
984
+ const [fetchOptions, extraOptions] = splitConfig(initConfig);
985
+ const baseConfig = isFunction(initBaseConfig) ? initBaseConfig({
986
+ initURL: initURL.toString(),
987
+ options: extraOptions,
988
+ request: fetchOptions
989
+ }) : initBaseConfig;
990
+ const config = initConfig;
991
+ const [baseFetchOptions, baseExtraOptions] = splitBaseConfig(baseConfig);
992
+ const shouldSkipAutoMergeForOptions = baseExtraOptions.skipAutoMergeFor === "all" || baseExtraOptions.skipAutoMergeFor === "options";
993
+ const shouldSkipAutoMergeForRequest = baseExtraOptions.skipAutoMergeFor === "all" || baseExtraOptions.skipAutoMergeFor === "request";
994
+ const mergedExtraOptions = {
995
+ ...baseExtraOptions,
996
+ ...!shouldSkipAutoMergeForOptions && extraOptions
997
+ };
998
+ const mergedRequestOptions = {
999
+ headers: {},
1000
+ ...baseFetchOptions,
1001
+ ...!shouldSkipAutoMergeForRequest && fetchOptions
1002
+ };
1003
+ const { resolvedCurrentRouteSchemaKey, resolvedHooks, resolvedInitURL, resolvedMiddlewares, resolvedOptions, resolvedRequestOptions } = await initializePlugins({
1046
1004
  baseConfig,
1047
1005
  config,
1048
- options,
1049
- request
1050
- }));
1051
- const { extraOptionsValidationResult, requestOptionsValidationResult, resolvedSchema, resolvedSchemaConfig, shouldApplySchemaOutput } = await handleConfigValidation({
1052
- baseExtraOptions,
1053
- currentRouteSchemaKey: resolvedCurrentRouteSchemaKey,
1054
- extraOptions,
1055
- options,
1056
- requestOptions: request
1006
+ initURL: initURL.toString(),
1007
+ options: mergedExtraOptions,
1008
+ request: mergedRequestOptions
1057
1009
  });
1058
- if (shouldApplySchemaOutput) Object.assign(options, extraOptionsValidationResult);
1059
- const validMethod = getMethod({
1010
+ const { fullURL, normalizedInitURL } = getFullAndNormalizedURL({
1011
+ baseURL: resolvedOptions.baseURL,
1060
1012
  initURL: resolvedInitURL,
1061
- method: shouldApplySchemaOutput ? requestOptionsValidationResult?.method : request.method
1013
+ params: resolvedOptions.params,
1014
+ query: resolvedOptions.query
1062
1015
  });
1063
- const validBody = getBody({
1064
- body: shouldApplySchemaOutput ? requestOptionsValidationResult?.body : request.body,
1065
- bodySerializer: options.bodySerializer
1066
- });
1067
- const resolvedHeaders = isFunction(fetchOptions.headers) ? fetchOptions.headers({ baseHeaders: baseFetchOptions.headers ?? {} }) : fetchOptions.headers ?? baseFetchOptions.headers;
1068
- const validHeaders = await getHeaders({
1069
- auth: options.auth,
1070
- body: validBody,
1071
- headers: shouldApplySchemaOutput ? requestOptionsValidationResult?.headers : resolvedHeaders
1072
- });
1073
- Object.assign(request, {
1074
- ...validBody && { body: validBody },
1075
- ...validHeaders && { headers: validHeaders },
1076
- ...validMethod && { method: validMethod }
1016
+ const options = {
1017
+ ...resolvedOptions,
1018
+ ...resolvedHooks,
1019
+ ...resolvedMiddlewares,
1020
+ fullURL,
1021
+ initURL: resolvedInitURL,
1022
+ initURLNormalized: normalizedInitURL
1023
+ };
1024
+ const newFetchController = new AbortController();
1025
+ const combinedSignal = createCombinedSignal(createTimeoutSignal(options.timeout), resolvedRequestOptions.signal, newFetchController.signal);
1026
+ const initMethod = getMethod({
1027
+ initURL: resolvedInitURL,
1028
+ method: resolvedRequestOptions.method
1077
1029
  });
1078
- const readyRequestContext = {
1030
+ const request = {
1031
+ ...resolvedRequestOptions,
1032
+ method: initMethod,
1033
+ signal: combinedSignal
1034
+ };
1035
+ const { getAbortErrorMessage, handleRequestCancelStrategy, handleRequestDeferStrategy, removeDedupeKeyFromCache, resolvedDedupeStrategy } = await createDedupeStrategy({
1036
+ $GlobalRequestInfoCache,
1037
+ $LocalRequestInfoCache,
1079
1038
  baseConfig,
1080
1039
  config,
1081
- options,
1082
- request
1083
- };
1084
- await executeHooks(options.onRequestReady?.(readyRequestContext));
1085
- const response = await handleRequestDeferStrategy({
1086
- fetchApi: getFetchImpl({
1087
- customFetchImpl: options.customFetchImpl,
1088
- fetchMiddleware: options.fetchMiddleware,
1089
- requestContext: readyRequestContext
1090
- }),
1040
+ newFetchController,
1091
1041
  options,
1092
1042
  request
1093
1043
  });
1094
- const shouldCloneResponse = resolvedDedupeStrategy === "defer" || options.cloneResponse;
1095
- if (!response.ok) {
1096
- const validErrorData = await handleSchemaValidation(resolvedSchema, "errorData", {
1097
- inputValue: await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser),
1098
- response,
1099
- schemaConfig: resolvedSchemaConfig
1044
+ try {
1045
+ await handleRequestCancelStrategy();
1046
+ await executeHooks(options.onRequest?.({
1047
+ baseConfig,
1048
+ config,
1049
+ options,
1050
+ request
1051
+ }));
1052
+ const { extraOptionsValidationResult, requestOptionsValidationResult, resolvedSchema, resolvedSchemaConfig, shouldApplySchemaOutput } = await handleConfigValidation({
1053
+ baseExtraOptions,
1054
+ currentRouteSchemaKey: resolvedCurrentRouteSchemaKey,
1055
+ extraOptions,
1056
+ options,
1057
+ requestOptions: request
1058
+ });
1059
+ if (shouldApplySchemaOutput) Object.assign(options, extraOptionsValidationResult);
1060
+ const validMethod = getMethod({
1061
+ initURL: resolvedInitURL,
1062
+ method: shouldApplySchemaOutput ? requestOptionsValidationResult?.method : request.method
1063
+ });
1064
+ const validBody = getBody({
1065
+ body: shouldApplySchemaOutput ? requestOptionsValidationResult?.body : request.body,
1066
+ bodySerializer: options.bodySerializer
1067
+ });
1068
+ const resolvedHeaders = isFunction(fetchOptions.headers) ? fetchOptions.headers({ baseHeaders: baseFetchOptions.headers ?? {} }) : fetchOptions.headers ?? baseFetchOptions.headers;
1069
+ const validHeaders = await getHeaders({
1070
+ auth: options.auth,
1071
+ body: validBody,
1072
+ headers: shouldApplySchemaOutput ? requestOptionsValidationResult?.headers : resolvedHeaders
1073
+ });
1074
+ Object.assign(request, {
1075
+ ...validBody && { body: validBody },
1076
+ ...validHeaders && { headers: validHeaders },
1077
+ ...validMethod && { method: validMethod }
1100
1078
  });
1101
- throw new HTTPError({
1102
- defaultHTTPErrorMessage: options.defaultHTTPErrorMessage,
1103
- errorData: validErrorData,
1079
+ const readyRequestContext = {
1080
+ baseConfig,
1081
+ config,
1082
+ options,
1083
+ request
1084
+ };
1085
+ await executeHooks(options.onRequestReady?.(readyRequestContext));
1086
+ const response = await handleRequestDeferStrategy({
1087
+ fetchApi: getFetchImpl({
1088
+ customFetchImpl: options.customFetchImpl,
1089
+ fetchMiddleware: options.fetchMiddleware,
1090
+ requestContext: readyRequestContext
1091
+ }),
1092
+ options,
1093
+ request
1094
+ });
1095
+ const shouldCloneResponse = resolvedDedupeStrategy === "defer" || options.cloneResponse;
1096
+ if (!response.ok) {
1097
+ const validErrorData = await handleSchemaValidation(resolvedSchema, "errorData", {
1098
+ inputValue: await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser),
1099
+ response,
1100
+ schemaConfig: resolvedSchemaConfig
1101
+ });
1102
+ throw new HTTPError({
1103
+ defaultHTTPErrorMessage: options.defaultHTTPErrorMessage,
1104
+ errorData: validErrorData,
1105
+ response
1106
+ }, { cause: validErrorData });
1107
+ }
1108
+ const successContext = {
1109
+ baseConfig,
1110
+ config,
1111
+ data: await handleSchemaValidation(resolvedSchema, "data", {
1112
+ inputValue: await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser),
1113
+ response,
1114
+ schemaConfig: resolvedSchemaConfig
1115
+ }),
1116
+ options,
1117
+ request,
1104
1118
  response
1105
- }, { cause: validErrorData });
1106
- }
1107
- const successContext = {
1108
- baseConfig,
1109
- config,
1110
- data: await handleSchemaValidation(resolvedSchema, "data", {
1111
- inputValue: await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser),
1112
- response,
1113
- schemaConfig: resolvedSchemaConfig
1114
- }),
1115
- options,
1116
- request,
1117
- response
1118
- };
1119
- await executeHooks(options.onSuccess?.(successContext), options.onResponse?.({
1120
- ...successContext,
1121
- error: null
1122
- }));
1123
- return resolveSuccessResult(successContext.data, {
1124
- response: successContext.response,
1125
- resultMode: options.resultMode
1126
- });
1127
- } catch (error) {
1128
- const errorInfo = {
1129
- cloneResponse: options.cloneResponse,
1130
- resultMode: options.resultMode
1131
- };
1132
- const { errorDetails, errorResult } = resolveErrorResult(error, errorInfo);
1133
- const errorContext = {
1134
- baseConfig,
1135
- config,
1136
- error: errorDetails.error,
1137
- options,
1138
- request,
1139
- response: errorDetails.response
1140
- };
1141
- const shouldThrowOnError = Boolean(isFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError);
1142
- const hookInfo = {
1143
- errorInfo,
1144
- shouldThrowOnError
1145
- };
1146
- const { handleRetry, shouldAttemptRetry } = createRetryManager(errorContext);
1147
- const handleRetryOrGetErrorResult = async () => {
1148
- if (await shouldAttemptRetry()) return handleRetry({
1149
- callApi: callApi$1,
1150
- callApiArgs: {
1151
- config,
1152
- initURL
1153
- },
1154
- errorContext,
1155
- hookInfo
1119
+ };
1120
+ await executeHooks(options.onSuccess?.(successContext), options.onResponse?.({
1121
+ ...successContext,
1122
+ error: null
1123
+ }));
1124
+ return resolveSuccessResult(successContext.data, {
1125
+ response: successContext.response,
1126
+ resultMode: options.resultMode
1156
1127
  });
1157
- if (shouldThrowOnError) throw error;
1158
- return errorResult;
1159
- };
1160
- if (isValidationErrorInstance(error)) return await executeHooksInCatchBlock([options.onValidationError?.(errorContext), options.onError?.(errorContext)], hookInfo) ?? await handleRetryOrGetErrorResult();
1161
- if (isHTTPErrorInstance(error)) return await executeHooksInCatchBlock([
1162
- options.onResponseError?.(errorContext),
1163
- options.onError?.(errorContext),
1164
- options.onResponse?.({
1165
- ...errorContext,
1166
- data: null
1167
- })
1168
- ], hookInfo) ?? await handleRetryOrGetErrorResult();
1169
- let message = error?.message;
1170
- if (error instanceof DOMException && error.name === "AbortError") {
1171
- message = getAbortErrorMessage();
1172
- !shouldThrowOnError && console.error(`${error.name}:`, message);
1128
+ } catch (error) {
1129
+ const errorInfo = {
1130
+ cloneResponse: options.cloneResponse,
1131
+ resultMode: options.resultMode
1132
+ };
1133
+ const { errorDetails, errorResult } = resolveErrorResult(error, errorInfo);
1134
+ const errorContext = {
1135
+ baseConfig,
1136
+ config,
1137
+ error: errorDetails.error,
1138
+ options,
1139
+ request,
1140
+ response: errorDetails.response
1141
+ };
1142
+ const shouldThrowOnError = Boolean(isFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError);
1143
+ const hookInfo = {
1144
+ errorInfo,
1145
+ shouldThrowOnError
1146
+ };
1147
+ const { handleRetry, shouldAttemptRetry } = createRetryManager(errorContext);
1148
+ const handleRetryOrGetErrorResult = async () => {
1149
+ if (await shouldAttemptRetry()) return handleRetry({
1150
+ callApi: callApi$1,
1151
+ callApiArgs: {
1152
+ config,
1153
+ initURL
1154
+ },
1155
+ errorContext,
1156
+ hookInfo
1157
+ });
1158
+ if (shouldThrowOnError) throw error;
1159
+ return errorResult;
1160
+ };
1161
+ if (isValidationErrorInstance(error)) return await executeHooksInCatchBlock([options.onValidationError?.(errorContext), options.onError?.(errorContext)], hookInfo) ?? await handleRetryOrGetErrorResult();
1162
+ if (isHTTPErrorInstance(error)) return await executeHooksInCatchBlock([
1163
+ options.onResponseError?.(errorContext),
1164
+ options.onError?.(errorContext),
1165
+ options.onResponse?.({
1166
+ ...errorContext,
1167
+ data: null
1168
+ })
1169
+ ], hookInfo) ?? await handleRetryOrGetErrorResult();
1170
+ let message = error?.message;
1171
+ if (error instanceof DOMException && error.name === "AbortError") {
1172
+ message = getAbortErrorMessage();
1173
+ !shouldThrowOnError && console.error(`${error.name}:`, message);
1174
+ }
1175
+ if (error instanceof DOMException && error.name === "TimeoutError") {
1176
+ message = `Request timed out after ${options.timeout}ms`;
1177
+ !shouldThrowOnError && console.error(`${error.name}:`, message);
1178
+ }
1179
+ return await executeHooksInCatchBlock([options.onRequestError?.(errorContext), options.onError?.(errorContext)], hookInfo) ?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message });
1180
+ } finally {
1181
+ removeDedupeKeyFromCache();
1173
1182
  }
1174
- if (error instanceof DOMException && error.name === "TimeoutError") {
1175
- message = `Request timed out after ${options.timeout}ms`;
1176
- !shouldThrowOnError && console.error(`${error.name}:`, message);
1177
- }
1178
- return await executeHooksInCatchBlock([options.onRequestError?.(errorContext), options.onError?.(errorContext)], hookInfo) ?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message });
1179
- } finally {
1180
- removeDedupeKeyFromCache();
1181
- }
1183
+ };
1184
+ return callApi$1;
1182
1185
  };
1183
- return callApi$1;
1186
+ return createFetchClient$1;
1184
1187
  };
1188
+ const createFetchClient = createFetchClientWithEnv();
1185
1189
  const callApi = createFetchClient();
1186
1190
 
1187
1191
  //#endregion
1188
- export { callApi, createFetchClient };
1192
+ export { callApi, createFetchClient, createFetchClientWithEnv };
1189
1193
  //# sourceMappingURL=index.js.map