@oxog/requestkit 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +63 -19
- package/dist/chunk-SEYWPFTU.cjs +2 -0
- package/dist/chunk-SEYWPFTU.cjs.map +1 -0
- package/dist/chunk-WLUDQEUI.js +2 -0
- package/dist/chunk-WLUDQEUI.js.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -262
- package/dist/index.d.ts +4 -262
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +2 -233
- package/dist/react/index.d.ts +2 -233
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/types-BjdiOCBe.d.cts +283 -0
- package/dist/types-BjdiOCBe.d.ts +283 -0
- package/package.json +14 -11
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,59 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
Nothing yet.
|
|
11
11
|
|
|
12
|
+
## [1.2.0] - 2026-11-30
|
|
13
|
+
|
|
14
|
+
This release also contains the changes listed under 1.1.0, which was never published to npm (the previous npm release is 1.0.0).
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- `retry.limit` now means the number of retries, as documented: `retry: 3` makes up to 4 attempts. Before, a request ran at most `limit` times, so `retry: 1` never retried.
|
|
19
|
+
- The documented `retry.retryOn` option was ignored; it now works as an alias of `statusCodes`.
|
|
20
|
+
- `Retry-After` response headers (seconds or HTTP date) are honored, capped by `maxDelay`. Malformed values such as `12abc` are ignored instead of being read as 12 seconds.
|
|
21
|
+
- The README `CancelToken` example did nothing: `cancelToken` was not a request option. Cancel tokens now abort the request (also when already canceled) and reject with `ERR_CANCELED`.
|
|
22
|
+
- Cancelling through `cancelable: true` (`cancel()`) or `AbortController.abort(reason)` with a custom reason was reported as `ERR_NETWORK` (and could be retried); it is now `ERR_CANCELED` with the reason's message.
|
|
23
|
+
- Aborting while a retry is waiting for its backoff delay rejected only after the full delay; it now rejects immediately with `ERR_CANCELED`.
|
|
24
|
+
- The timeout timer was never cleared, so a successful request with `timeout: 30000` kept a Node.js process alive for 30 seconds. Timers are now cleared as soon as each attempt settles.
|
|
25
|
+
- Listeners added to a caller's `AbortSignal` were never removed, so a long-lived signal reused across requests accumulated one listener per request.
|
|
26
|
+
- A request whose body is a `ReadableStream` is no longer retried (the stream was already consumed, so the retry failed with a misleading error).
|
|
27
|
+
- Configuration and interceptor errors without a response (for example `ERR_BAD_REQUEST`) are no longer retried; only network errors, timeouts and the configured status codes are.
|
|
28
|
+
- An error thrown by a response error interceptor was discarded and the original error rethrown. The new error now reaches the caller (as a `RequestError` with the thrown value as `cause` and the original `status`/`response`).
|
|
29
|
+
- An error thrown by a request interceptor rejected with a plain object instead of an `Error`; it is now a `RequestError` with `cause`.
|
|
30
|
+
- The README interceptor example (`config.headers = { ...config.headers, ... }`) silently dropped all default headers such as `Authorization` and crashed POST requests (`e.has is not a function`). Plain-object headers assigned by interceptors are now accepted, and the README shows `config.headers.set(...)`.
|
|
31
|
+
- `client.extend()` dropped the parent's headers when they were given as a `Headers` instance.
|
|
32
|
+
- An empty response body with a JSON content type resolved to `''`; it now resolves to `undefined`, like other empty bodies.
|
|
33
|
+
- `deepMerge`/`deepClone` (used for every client and request config) let a `__proto__` key replace the prototype of the merged object; `__proto__`, `constructor` and `prototype` keys are now ignored.
|
|
34
|
+
- `createParamsSerializer()` reported `arrayFormat: 'brackets'` while encoding arrays as `repeat`; it now reports `'repeat'`.
|
|
35
|
+
- `useQuery` kept a scheduled retry timer after unmount and sent the request anyway.
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
|
|
39
|
+
- `allowAbsoluteUrls: false` client/request option: absolute and protocol-relative URLs are rejected instead of bypassing `baseURL` with the default headers.
|
|
40
|
+
- `retry.jitter` option (full jitter, off by default).
|
|
41
|
+
- README sections on retry behavior and security (absolute URLs, redirects, error logging).
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- `timeout` now applies to each attempt and also covers reading the response body (except for `responseType: 'stream'` and `'raw'`). A timed-out idempotent request is retried when retries are enabled; previously one timer covered all attempts and a timeout ended the request.
|
|
46
|
+
- `error.config`, `error.request` and `error.response` are non-enumerable, so `console.log(error)` no longer prints request headers such as `Authorization`. They are still readable as properties.
|
|
47
|
+
- `getRetryAfterDelay()` returns `0` for a date in the past (retry now) instead of `undefined`.
|
|
48
|
+
- The React entry now shares code with the main entry through a common chunk instead of bundling its own copy.
|
|
49
|
+
- The README bundle-size claim is corrected (about 6 KB core, 7 KB with the React adapter, min+gzip).
|
|
50
|
+
- `cacheTime` (`useQuery`) and `staleTime` (`useInfiniteQuery`) are marked deprecated: they were never implemented.
|
|
51
|
+
- `package.json` exports `./package.json`; repository URLs use the GitHub repository's casing.
|
|
52
|
+
|
|
53
|
+
## [1.1.0] - 2026-11-30 (not published)
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
|
|
57
|
+
- Client and request options for a Fetch-compatible transport and redirect mode.
|
|
58
|
+
- Installed-package tests for the ESM and CommonJS entry points, React adapter and real HTTP response handling.
|
|
59
|
+
|
|
60
|
+
### Fixed
|
|
61
|
+
|
|
62
|
+
- Preserve caller cancellation when a request also exposes its own cancel handle.
|
|
63
|
+
- Track upload progress on the prepared request body so request transformations and redirect settings are preserved.
|
|
64
|
+
|
|
12
65
|
## [1.0.0] - 2025-12-29
|
|
13
66
|
|
|
14
67
|
### Added
|
package/README.md
CHANGED
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
- **Zero Dependencies** - Built entirely on native fetch API
|
|
20
20
|
- **TypeScript First** - Full type safety with excellent DX
|
|
21
21
|
- **Interceptors** - Request/response interceptors like axios
|
|
22
|
-
- **Automatic Retry** -
|
|
22
|
+
- **Automatic Retry** - Idempotent methods only by default, exponential backoff, optional jitter, `Retry-After` support
|
|
23
23
|
- **Request Cancellation** - Cancel tokens and AbortController support
|
|
24
24
|
- **Progress Tracking** - Upload and download progress callbacks
|
|
25
25
|
- **React Hooks** - Built-in useQuery, useMutation, useInfiniteQuery
|
|
26
|
-
- **
|
|
26
|
+
- **Small Bundle** - about 6 KB core, about 7 KB with the React adapter (minified + gzipped)
|
|
27
27
|
|
|
28
28
|
## Installation
|
|
29
29
|
|
|
@@ -60,9 +60,9 @@ const api = createClient({
|
|
|
60
60
|
headers: {
|
|
61
61
|
'Authorization': 'Bearer token',
|
|
62
62
|
},
|
|
63
|
-
timeout: 10000,
|
|
63
|
+
timeout: 10000, // per attempt
|
|
64
64
|
retry: {
|
|
65
|
-
limit: 3,
|
|
65
|
+
limit: 3, // up to 3 retries (4 attempts in total)
|
|
66
66
|
delay: 1000,
|
|
67
67
|
backoff: 'exponential',
|
|
68
68
|
},
|
|
@@ -72,12 +72,9 @@ const api = createClient({
|
|
|
72
72
|
## Interceptors
|
|
73
73
|
|
|
74
74
|
```typescript
|
|
75
|
-
// Request interceptor
|
|
75
|
+
// Request interceptor (config.headers is a Headers instance)
|
|
76
76
|
api.interceptors.request.use((config) => {
|
|
77
|
-
config.headers
|
|
78
|
-
...config.headers,
|
|
79
|
-
'X-Request-Id': crypto.randomUUID(),
|
|
80
|
-
}
|
|
77
|
+
config.headers.set('X-Request-Id', crypto.randomUUID())
|
|
81
78
|
return config
|
|
82
79
|
})
|
|
83
80
|
|
|
@@ -93,6 +90,8 @@ api.interceptors.response.use(
|
|
|
93
90
|
)
|
|
94
91
|
```
|
|
95
92
|
|
|
93
|
+
Request interceptors run in the order they were added; response interceptors run in reverse order. An error interceptor can recover by returning a `Response`, or replace the error by throwing: the caller receives the new error (as a `RequestError` whose `cause` is what you threw, with the original `status` and `response`).
|
|
94
|
+
|
|
96
95
|
## React Integration
|
|
97
96
|
|
|
98
97
|
```tsx
|
|
@@ -157,7 +156,8 @@ Fetch paginated data with infinite scroll.
|
|
|
157
156
|
|
|
158
157
|
```tsx
|
|
159
158
|
const { data, hasNextPage, fetchNextPage } = useInfiniteQuery<Page>(
|
|
160
|
-
|
|
159
|
+
// The first page is requested with an undefined cursor
|
|
160
|
+
(cursor) => (cursor === undefined ? '/items' : `/items?cursor=${cursor}`),
|
|
161
161
|
{ getNextPageParam: (page) => page.nextCursor }
|
|
162
162
|
)
|
|
163
163
|
```
|
|
@@ -180,26 +180,37 @@ try {
|
|
|
180
180
|
## Request Cancellation
|
|
181
181
|
|
|
182
182
|
```typescript
|
|
183
|
-
import { CancelToken } from '@oxog/requestkit'
|
|
183
|
+
import { CancelToken, isCancelError } from '@oxog/requestkit'
|
|
184
184
|
|
|
185
185
|
const source = CancelToken.source()
|
|
186
186
|
|
|
187
|
-
api.get('/data', { cancelToken: source.token })
|
|
187
|
+
api.get('/data', { cancelToken: source.token }).catch((error) => {
|
|
188
|
+
if (isCancelError(error)) console.log(error.message) // 'Operation canceled'
|
|
189
|
+
})
|
|
188
190
|
|
|
189
191
|
// Cancel the request
|
|
190
192
|
source.cancel('Operation canceled')
|
|
193
|
+
|
|
194
|
+
// A native AbortSignal works too, together with `timeout`
|
|
195
|
+
const controller = new AbortController()
|
|
196
|
+
api.get('/data', { signal: controller.signal, timeout: 5000 }).catch(console.error)
|
|
197
|
+
controller.abort()
|
|
191
198
|
```
|
|
192
199
|
|
|
200
|
+
Caller cancellation rejects with `code: 'ERR_CANCELED'` (also while waiting between retries); a timeout rejects with `code: 'ERR_TIMEOUT'`. The timeout applies to each attempt, covers reading the response body (except for `responseType: 'stream'` and `'raw'`), and its timer is cleared as soon as the attempt settles.
|
|
201
|
+
|
|
193
202
|
## Progress Tracking
|
|
194
203
|
|
|
195
204
|
```typescript
|
|
196
|
-
await api.post('/upload',
|
|
205
|
+
await api.post('/upload', 'large text body', {
|
|
197
206
|
onUploadProgress: (progress) => {
|
|
198
207
|
console.log(`${progress.percent}% uploaded`)
|
|
199
208
|
},
|
|
200
209
|
})
|
|
201
210
|
```
|
|
202
211
|
|
|
212
|
+
Upload progress streams string, `Blob`, `ArrayBuffer` and typed-array bodies, which requires a runtime that supports streaming request bodies (Node.js 18+, Chromium-based browsers over HTTP/2; Firefox and Safari do not support them). `FormData` and `URLSearchParams` bodies are sent as-is and report a single 100% event.
|
|
213
|
+
|
|
203
214
|
## API Reference
|
|
204
215
|
|
|
205
216
|
### createClient(config)
|
|
@@ -209,12 +220,33 @@ Creates a new HTTP client instance.
|
|
|
209
220
|
| Option | Type | Description |
|
|
210
221
|
|--------|------|-------------|
|
|
211
222
|
| `baseURL` | `string` | Base URL for all requests |
|
|
223
|
+
| `allowAbsoluteUrls` | `boolean` | Allow absolute/protocol-relative request URLs to bypass `baseURL` (default `true`) |
|
|
212
224
|
| `headers` | `Record<string, string>` | Default headers |
|
|
213
|
-
| `timeout` | `number` |
|
|
225
|
+
| `timeout` | `number` | Timeout per attempt in ms (`0` = none) |
|
|
214
226
|
| `retry` | `RetryConfig` | Retry configuration |
|
|
227
|
+
| `transport` | `RequestTransport` | Execute the prepared request with a custom transport |
|
|
228
|
+
| `redirect` | `RequestRedirect` | Redirect mode |
|
|
215
229
|
| `validateStatus` | `(status: number) => boolean` | Custom status validation |
|
|
216
230
|
| `responseType` | `'json' \| 'text' \| 'blob' \| 'arraybuffer'` | Response type |
|
|
217
231
|
|
|
232
|
+
### Custom transports and redirects
|
|
233
|
+
|
|
234
|
+
Set `transport` on `createClient` or override it in a single request. The transport receives a fully prepared `Request` and returns a `Promise<Response>`. It should respect the request URL, abort signal, and redirect mode.
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
const client = createClient({
|
|
238
|
+
transport: request => fetch(request),
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
const response = await client.get<Response>('https://api.example.com/report', {
|
|
242
|
+
redirect: 'manual',
|
|
243
|
+
responseType: 'raw',
|
|
244
|
+
validateStatus: () => true,
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
When the selected transport exposes an intermediate response, `responseType: 'raw'` and a status validator that accepts the response let the caller inspect it before reading the body. The default transport uses native fetch and its default redirect behavior.
|
|
249
|
+
|
|
218
250
|
### HTTP Methods
|
|
219
251
|
|
|
220
252
|
```typescript
|
|
@@ -231,11 +263,23 @@ api.options<T>(url, options?)
|
|
|
231
263
|
|
|
232
264
|
| Option | Type | Default | Description |
|
|
233
265
|
|--------|------|---------|-------------|
|
|
234
|
-
| `limit` | `number` |
|
|
235
|
-
| `delay` | `number` |
|
|
236
|
-
| `backoff` | `'linear' \| 'exponential'` | `'exponential'` |
|
|
237
|
-
| `
|
|
238
|
-
| `maxDelay` | `number` |
|
|
266
|
+
| `limit` | `number` | `0` | Number of retries after the first attempt (`retry: 3` is shorthand for `{ limit: 3 }`) |
|
|
267
|
+
| `delay` | `number` | `1000` | Initial delay in ms |
|
|
268
|
+
| `backoff` | `'linear' \| 'exponential'` | `'exponential'` | `linear`: delay × n, `exponential`: delay × 2^(n-1) |
|
|
269
|
+
| `jitter` | `boolean` | `false` | Randomize each delay between 0 and the computed value |
|
|
270
|
+
| `maxDelay` | `number` | `30000` | Maximum delay, also caps a server's `Retry-After` |
|
|
271
|
+
| `methods` | `HttpMethod[]` | `['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE']` | Methods that may be retried (POST and PATCH are not, by default) |
|
|
272
|
+
| `statusCodes` / `retryOn` | `number[]` | `[408, 429, 500, 502, 503, 504]` | Status codes to retry |
|
|
273
|
+
| `retryCondition` | `(error) => boolean` | - | Extra check before each retry |
|
|
274
|
+
| `onRetry` | `(attempt, error, config) => void` | - | Called before each retry |
|
|
275
|
+
|
|
276
|
+
Network errors and timeouts are retried for the allowed methods; other 4xx responses, cancellations and interceptor errors are not. A `Retry-After` header (seconds or HTTP date) replaces the computed delay. A request whose body is a `ReadableStream` is never retried, because the stream cannot be sent twice.
|
|
277
|
+
|
|
278
|
+
## Security notes
|
|
279
|
+
|
|
280
|
+
- **Absolute URLs**: a request URL such as `https://other.example/x` or `//other.example/x` bypasses `baseURL` and still carries the client's default headers (for example `Authorization`). If paths can come from user input, create the client with `allowAbsoluteUrls: false`; such requests then reject with `ERR_BAD_REQUEST` before anything is sent.
|
|
281
|
+
- **Redirects** are followed by the runtime's `fetch`. Per the Fetch standard, Node.js 18+ (undici) drops `Authorization` and `Cookie` when a redirect leaves the original origin; use `redirect: 'manual'` to handle redirects yourself.
|
|
282
|
+
- **Errors**: `error.config`, `error.request` and `error.response` stay available but are non-enumerable, so logging (`console.log(error)`) or `JSON.stringify(error)` does not print request headers.
|
|
239
283
|
|
|
240
284
|
## Browser Support
|
|
241
285
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var E=class e extends Error{name="RequestError";status;statusText;data;code;constructor(n,t,s,o,r,u,c){super(n),this.code=s,this.data=u,R(this,"config",t),R(this,"request",o),R(this,"response",r),c!==void 0&&R(this,"cause",c),r&&(this.status=r.status,this.statusText=r.statusText),Error.captureStackTrace&&Error.captureStackTrace(this,e),Object.setPrototypeOf(this,e.prototype);}toJSON(){return {name:this.name,message:this.message,status:this.status,statusText:this.statusText,code:this.code,data:this.data,config:{url:this.config.url,method:this.config.method,baseURL:this.config.baseURL}}}};function R(e,n,t){Object.defineProperty(e,n,{value:t,writable:true,configurable:true,enumerable:false});}function i(e,n,t,s,o,r,u){return new E(e,n,t,s,o,r,u)}function d(e,n="Request canceled"){if(typeof e=="string"&&e)return e;if(e&&typeof e=="object"&&"message"in e){let t=e.message;if(typeof t=="string"&&t&&t!=="This operation was aborted")return t}return n}function g(e,n,t){return i(d(e),n,"ERR_CANCELED",t,void 0,void 0,e)}function m(e,n,t){return e.name==="AbortError"?i(e.message||"Request aborted",n,"ERR_CANCELED",t):e.name==="TimeoutError"||e.message?.includes("timeout")?i(e.message||"Request timeout",n,"ERR_TIMEOUT",t):i(e.message||"Network error",n,"ERR_NETWORK",t)}async function l(e,n,t){let s=e.status,o=e.statusText,r;try{let f=await e.text();try{r=JSON.parse(f);}catch{r=f;}}catch{r=void 0;}let u=s>=500?"ERR_BAD_RESPONSE":"ERR_BAD_REQUEST",c=`Request failed with status ${s}${o?`: ${o}`:""}`;return i(c,n,u,t,e,r)}function a(e){return e instanceof E||e instanceof Error&&e.name==="RequestError"&&"config"in e}function p(e){return a(e)&&e.code==="ERR_NETWORK"}function h(e){return a(e)&&e.code==="ERR_TIMEOUT"}function q(e){return a(e)?e.code==="ERR_CANCELED":e instanceof Error&&e.name==="AbortError"}function w(e){return a(e)&&e.code==="ERR_BAD_REQUEST"}function k(e){return a(e)&&e.code==="ERR_BAD_RESPONSE"}exports.a=i;exports.b=g;exports.c=m;exports.d=l;exports.e=a;exports.f=p;exports.g=h;exports.h=q;exports.i=w;exports.j=k;//# sourceMappingURL=chunk-SEYWPFTU.cjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-SEYWPFTU.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/error.ts"],"names":["RequestErrorImpl","_RequestErrorImpl","message","config","code","request","response","data","cause","hide","target","key","value","createError","abortReasonMessage","reason","fallback","createCancelError","createNetworkError","error","createResponseError","status","statusText","text","isRequestError","isNetworkError","isTimeoutError","isCancelError","isClientError","isServerError"],"mappings":"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","file":"chunk-SEYWPFTU.cjs","sourcesContent":["/**\n * Error handling utilities\n */\n\nimport type { RequestError, ErrorCode, InternalRequestConfig } from '../types.js'\n\n/**\n * RequestError class for HTTP errors\n */\nexport class RequestErrorImpl extends Error implements RequestError {\n override readonly name = 'RequestError' as const\n status?: number\n statusText?: string\n data?: unknown\n declare config: InternalRequestConfig\n declare request?: Request\n declare response?: Response\n code?: ErrorCode\n\n constructor(\n message: string,\n config: InternalRequestConfig,\n code?: ErrorCode,\n request?: Request,\n response?: Response,\n data?: unknown,\n cause?: unknown\n ) {\n super(message)\n this.code = code\n this.data = data\n\n // config, request and response carry the request headers (Authorization,\n // Cookie, ...). Keep them accessible but non-enumerable so that logging or\n // serializing an error does not print credentials.\n hide(this, 'config', config)\n hide(this, 'request', request)\n hide(this, 'response', response)\n if (cause !== undefined) {\n hide(this, 'cause', cause)\n }\n\n if (response) {\n this.status = response.status\n this.statusText = response.statusText\n }\n\n // Maintain proper stack trace in V8 engines\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, RequestErrorImpl)\n }\n\n // Set prototype explicitly for proper instanceof checks\n Object.setPrototypeOf(this, RequestErrorImpl.prototype)\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n status: this.status,\n statusText: this.statusText,\n code: this.code,\n data: this.data,\n config: {\n url: this.config.url,\n method: this.config.method,\n baseURL: this.config.baseURL,\n },\n }\n }\n}\n\nfunction hide(target: object, key: string, value: unknown): void {\n Object.defineProperty(target, key, { value, writable: true, configurable: true, enumerable: false })\n}\n\n/**\n * Create a RequestError from various inputs\n */\nexport function createError(\n message: string,\n config: InternalRequestConfig,\n code?: ErrorCode,\n request?: Request,\n response?: Response,\n data?: unknown,\n cause?: unknown\n): RequestError {\n return new RequestErrorImpl(message, config, code, request, response, data, cause)\n}\n\n/**\n * Human-readable text for an abort reason (Error, Cancel, string, ...).\n */\nexport function abortReasonMessage(reason: unknown, fallback = 'Request canceled'): string {\n if (typeof reason === 'string' && reason) {\n return reason\n }\n if (reason && typeof reason === 'object' && 'message' in reason) {\n const message = (reason as { message?: unknown }).message\n if (typeof message === 'string' && message && message !== 'This operation was aborted') {\n return message\n }\n }\n return fallback\n}\n\n/**\n * Create an ERR_CANCELED error for a caller-initiated abort.\n */\nexport function createCancelError(\n reason: unknown,\n config: InternalRequestConfig,\n request?: Request\n): RequestError {\n return createError(abortReasonMessage(reason), config, 'ERR_CANCELED', request, undefined, undefined, reason)\n}\n\n/**\n * Create error from a failed fetch\n */\nexport function createNetworkError(\n error: Error,\n config: InternalRequestConfig,\n request?: Request\n): RequestError {\n // Check if it's an abort error\n if (error.name === 'AbortError') {\n return createError(\n error.message || 'Request aborted',\n config,\n 'ERR_CANCELED',\n request\n )\n }\n\n // Check if it's a timeout error (custom timeout implementation)\n if (error.name === 'TimeoutError' || error.message?.includes('timeout')) {\n return createError(\n error.message || 'Request timeout',\n config,\n 'ERR_TIMEOUT',\n request\n )\n }\n\n // Generic network error\n return createError(\n error.message || 'Network error',\n config,\n 'ERR_NETWORK',\n request\n )\n}\n\n/**\n * Create error from HTTP response\n */\nexport async function createResponseError(\n response: Response,\n config: InternalRequestConfig,\n request?: Request\n): Promise<RequestError> {\n const status = response.status\n const statusText = response.statusText\n\n // Try to parse response body\n let data: unknown\n try {\n const text = await response.text()\n try {\n data = JSON.parse(text)\n } catch {\n data = text\n }\n } catch {\n data = undefined\n }\n\n // Determine error code based on status\n const code: ErrorCode = status >= 500 ? 'ERR_BAD_RESPONSE' : 'ERR_BAD_REQUEST'\n\n // Create descriptive message\n const message = `Request failed with status ${status}${statusText ? `: ${statusText}` : ''}`\n\n return createError(message, config, code, request, response, data)\n}\n\n/**\n * Type guard to check if error is a RequestError\n */\nexport function isRequestError(error: unknown): error is RequestError {\n return (\n error instanceof RequestErrorImpl ||\n (error instanceof Error &&\n error.name === 'RequestError' &&\n 'config' in error)\n )\n}\n\n/**\n * Check if error is a network error\n */\nexport function isNetworkError(error: unknown): boolean {\n return isRequestError(error) && error.code === 'ERR_NETWORK'\n}\n\n/**\n * Check if error is a timeout error\n */\nexport function isTimeoutError(error: unknown): boolean {\n return isRequestError(error) && error.code === 'ERR_TIMEOUT'\n}\n\n/**\n * Check if error is a cancel/abort error\n */\nexport function isCancelError(error: unknown): boolean {\n if (isRequestError(error)) {\n return error.code === 'ERR_CANCELED'\n }\n return error instanceof Error && error.name === 'AbortError'\n}\n\n/**\n * Check if error is a client error (4xx)\n */\nexport function isClientError(error: unknown): boolean {\n return isRequestError(error) && error.code === 'ERR_BAD_REQUEST'\n}\n\n/**\n * Check if error is a server error (5xx)\n */\nexport function isServerError(error: unknown): boolean {\n return isRequestError(error) && error.code === 'ERR_BAD_RESPONSE'\n}\n\n/**\n * Get status code from error\n */\nexport function getErrorStatus(error: unknown): number | undefined {\n if (isRequestError(error)) {\n return error.status\n }\n return undefined\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var E=class e extends Error{name="RequestError";status;statusText;data;code;constructor(n,t,s,o,r,u,c){super(n),this.code=s,this.data=u,R(this,"config",t),R(this,"request",o),R(this,"response",r),c!==void 0&&R(this,"cause",c),r&&(this.status=r.status,this.statusText=r.statusText),Error.captureStackTrace&&Error.captureStackTrace(this,e),Object.setPrototypeOf(this,e.prototype);}toJSON(){return {name:this.name,message:this.message,status:this.status,statusText:this.statusText,code:this.code,data:this.data,config:{url:this.config.url,method:this.config.method,baseURL:this.config.baseURL}}}};function R(e,n,t){Object.defineProperty(e,n,{value:t,writable:true,configurable:true,enumerable:false});}function i(e,n,t,s,o,r,u){return new E(e,n,t,s,o,r,u)}function d(e,n="Request canceled"){if(typeof e=="string"&&e)return e;if(e&&typeof e=="object"&&"message"in e){let t=e.message;if(typeof t=="string"&&t&&t!=="This operation was aborted")return t}return n}function g(e,n,t){return i(d(e),n,"ERR_CANCELED",t,void 0,void 0,e)}function m(e,n,t){return e.name==="AbortError"?i(e.message||"Request aborted",n,"ERR_CANCELED",t):e.name==="TimeoutError"||e.message?.includes("timeout")?i(e.message||"Request timeout",n,"ERR_TIMEOUT",t):i(e.message||"Network error",n,"ERR_NETWORK",t)}async function l(e,n,t){let s=e.status,o=e.statusText,r;try{let f=await e.text();try{r=JSON.parse(f);}catch{r=f;}}catch{r=void 0;}let u=s>=500?"ERR_BAD_RESPONSE":"ERR_BAD_REQUEST",c=`Request failed with status ${s}${o?`: ${o}`:""}`;return i(c,n,u,t,e,r)}function a(e){return e instanceof E||e instanceof Error&&e.name==="RequestError"&&"config"in e}function p(e){return a(e)&&e.code==="ERR_NETWORK"}function h(e){return a(e)&&e.code==="ERR_TIMEOUT"}function q(e){return a(e)?e.code==="ERR_CANCELED":e instanceof Error&&e.name==="AbortError"}function w(e){return a(e)&&e.code==="ERR_BAD_REQUEST"}function k(e){return a(e)&&e.code==="ERR_BAD_RESPONSE"}export{i as a,g as b,m as c,l as d,a as e,p as f,h as g,q as h,w as i,k as j};//# sourceMappingURL=chunk-WLUDQEUI.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-WLUDQEUI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/error.ts"],"names":["RequestErrorImpl","_RequestErrorImpl","message","config","code","request","response","data","cause","hide","target","key","value","createError","abortReasonMessage","reason","fallback","createCancelError","createNetworkError","error","createResponseError","status","statusText","text","isRequestError","isNetworkError","isTimeoutError","isCancelError","isClientError","isServerError"],"mappings":"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","file":"chunk-WLUDQEUI.js","sourcesContent":["/**\n * Error handling utilities\n */\n\nimport type { RequestError, ErrorCode, InternalRequestConfig } from '../types.js'\n\n/**\n * RequestError class for HTTP errors\n */\nexport class RequestErrorImpl extends Error implements RequestError {\n override readonly name = 'RequestError' as const\n status?: number\n statusText?: string\n data?: unknown\n declare config: InternalRequestConfig\n declare request?: Request\n declare response?: Response\n code?: ErrorCode\n\n constructor(\n message: string,\n config: InternalRequestConfig,\n code?: ErrorCode,\n request?: Request,\n response?: Response,\n data?: unknown,\n cause?: unknown\n ) {\n super(message)\n this.code = code\n this.data = data\n\n // config, request and response carry the request headers (Authorization,\n // Cookie, ...). Keep them accessible but non-enumerable so that logging or\n // serializing an error does not print credentials.\n hide(this, 'config', config)\n hide(this, 'request', request)\n hide(this, 'response', response)\n if (cause !== undefined) {\n hide(this, 'cause', cause)\n }\n\n if (response) {\n this.status = response.status\n this.statusText = response.statusText\n }\n\n // Maintain proper stack trace in V8 engines\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, RequestErrorImpl)\n }\n\n // Set prototype explicitly for proper instanceof checks\n Object.setPrototypeOf(this, RequestErrorImpl.prototype)\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n status: this.status,\n statusText: this.statusText,\n code: this.code,\n data: this.data,\n config: {\n url: this.config.url,\n method: this.config.method,\n baseURL: this.config.baseURL,\n },\n }\n }\n}\n\nfunction hide(target: object, key: string, value: unknown): void {\n Object.defineProperty(target, key, { value, writable: true, configurable: true, enumerable: false })\n}\n\n/**\n * Create a RequestError from various inputs\n */\nexport function createError(\n message: string,\n config: InternalRequestConfig,\n code?: ErrorCode,\n request?: Request,\n response?: Response,\n data?: unknown,\n cause?: unknown\n): RequestError {\n return new RequestErrorImpl(message, config, code, request, response, data, cause)\n}\n\n/**\n * Human-readable text for an abort reason (Error, Cancel, string, ...).\n */\nexport function abortReasonMessage(reason: unknown, fallback = 'Request canceled'): string {\n if (typeof reason === 'string' && reason) {\n return reason\n }\n if (reason && typeof reason === 'object' && 'message' in reason) {\n const message = (reason as { message?: unknown }).message\n if (typeof message === 'string' && message && message !== 'This operation was aborted') {\n return message\n }\n }\n return fallback\n}\n\n/**\n * Create an ERR_CANCELED error for a caller-initiated abort.\n */\nexport function createCancelError(\n reason: unknown,\n config: InternalRequestConfig,\n request?: Request\n): RequestError {\n return createError(abortReasonMessage(reason), config, 'ERR_CANCELED', request, undefined, undefined, reason)\n}\n\n/**\n * Create error from a failed fetch\n */\nexport function createNetworkError(\n error: Error,\n config: InternalRequestConfig,\n request?: Request\n): RequestError {\n // Check if it's an abort error\n if (error.name === 'AbortError') {\n return createError(\n error.message || 'Request aborted',\n config,\n 'ERR_CANCELED',\n request\n )\n }\n\n // Check if it's a timeout error (custom timeout implementation)\n if (error.name === 'TimeoutError' || error.message?.includes('timeout')) {\n return createError(\n error.message || 'Request timeout',\n config,\n 'ERR_TIMEOUT',\n request\n )\n }\n\n // Generic network error\n return createError(\n error.message || 'Network error',\n config,\n 'ERR_NETWORK',\n request\n )\n}\n\n/**\n * Create error from HTTP response\n */\nexport async function createResponseError(\n response: Response,\n config: InternalRequestConfig,\n request?: Request\n): Promise<RequestError> {\n const status = response.status\n const statusText = response.statusText\n\n // Try to parse response body\n let data: unknown\n try {\n const text = await response.text()\n try {\n data = JSON.parse(text)\n } catch {\n data = text\n }\n } catch {\n data = undefined\n }\n\n // Determine error code based on status\n const code: ErrorCode = status >= 500 ? 'ERR_BAD_RESPONSE' : 'ERR_BAD_REQUEST'\n\n // Create descriptive message\n const message = `Request failed with status ${status}${statusText ? `: ${statusText}` : ''}`\n\n return createError(message, config, code, request, response, data)\n}\n\n/**\n * Type guard to check if error is a RequestError\n */\nexport function isRequestError(error: unknown): error is RequestError {\n return (\n error instanceof RequestErrorImpl ||\n (error instanceof Error &&\n error.name === 'RequestError' &&\n 'config' in error)\n )\n}\n\n/**\n * Check if error is a network error\n */\nexport function isNetworkError(error: unknown): boolean {\n return isRequestError(error) && error.code === 'ERR_NETWORK'\n}\n\n/**\n * Check if error is a timeout error\n */\nexport function isTimeoutError(error: unknown): boolean {\n return isRequestError(error) && error.code === 'ERR_TIMEOUT'\n}\n\n/**\n * Check if error is a cancel/abort error\n */\nexport function isCancelError(error: unknown): boolean {\n if (isRequestError(error)) {\n return error.code === 'ERR_CANCELED'\n }\n return error instanceof Error && error.name === 'AbortError'\n}\n\n/**\n * Check if error is a client error (4xx)\n */\nexport function isClientError(error: unknown): boolean {\n return isRequestError(error) && error.code === 'ERR_BAD_REQUEST'\n}\n\n/**\n * Check if error is a server error (5xx)\n */\nexport function isServerError(error: unknown): boolean {\n return isRequestError(error) && error.code === 'ERR_BAD_RESPONSE'\n}\n\n/**\n * Get status code from error\n */\nexport function getErrorStatus(error: unknown): number | undefined {\n if (isRequestError(error)) {\n return error.status\n }\n return undefined\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var Ke=Object.defineProperty;var he=(e,t)=>()=>(e&&(t=e(e=0)),t);var Je=(e,t)=>{for(var n in t)Ke(e,n,{get:t[n],enumerable:true});};function P(e){return typeof FormData<"u"&&e instanceof FormData}function F(e){return typeof Blob<"u"&&e instanceof Blob}function Ve(e){return typeof File<"u"&&e instanceof File}function M(e){return typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer}function v(e){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView(e)}function D(e){return typeof URLSearchParams<"u"&&e instanceof URLSearchParams}function N(e){return typeof ReadableStream<"u"&&e instanceof ReadableStream}function l(e){if(e===null||typeof e!="object")return false;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function A(e){return typeof e=="function"}function $(e){return typeof e=="string"}function Qe(e){return typeof e=="number"&&!Number.isNaN(e)}function Ge(e){return typeof e>"u"}function x(e){return e==null}function Y(e){return e instanceof Date&&!Number.isNaN(e.getTime())}function We(e){return typeof e=="boolean"}function y(e){return Array.isArray(e)}function Xe(e){return e!==null&&typeof e=="object"}function z(e){return typeof Headers<"u"&&e instanceof Headers}function Ye(e){return typeof Request<"u"&&e instanceof Request}function Ze(e){return typeof Response<"u"&&e instanceof Response}function et(e){return typeof AbortSignal<"u"&&e instanceof AbortSignal}var b=he(()=>{});var xe={};Je(xe,{getContentType:()=>ae,objectToFormData:()=>O,objectToURLSearchParams:()=>ie,serializeBody:()=>ue,shouldHaveBody:()=>ce});function O(e,t=new FormData,n=""){for(let[r,o]of Object.entries(e)){let s=n?`${n}[${r}]`:r;if(o!=null)if(o instanceof File)t.append(s,o,o.name);else if(o instanceof Blob)t.append(s,o);else if(Array.isArray(o))for(let i=0;i<o.length;i++){let a=o[i];a instanceof File?t.append(`${s}[${i}]`,a,a.name):a instanceof Blob?t.append(`${s}[${i}]`,a):typeof a=="object"&&a!==null?O({[i]:a},t,s):t.append(`${s}[]`,String(a));}else l(o)?O(o,t,s):t.append(s,String(o));}return t}function ie(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!=null)if(Array.isArray(r))for(let o of r)o!=null&&t.append(n,String(o));else t.append(n,String(r));return t}function ae(e){if(!P(e)){if(F(e))return e.type||"application/octet-stream";if(D(e))return "application/x-www-form-urlencoded;charset=UTF-8";if(M(e)||v(e)||N(e))return "application/octet-stream";if($(e))return "text/plain;charset=UTF-8";if(l(e)||Array.isArray(e))return "application/json;charset=UTF-8"}}function ue(e){if(e.json!==void 0)return {body:JSON.stringify(e.json),contentType:"application/json;charset=UTF-8"};if(e.form!==void 0){if(P(e.form))return {body:e.form,contentType:void 0};let t=e.headers,n;if(t){if(t instanceof Headers)n=t.get("content-type")??void 0;else if(Array.isArray(t))n=t.find(([o])=>o.toLowerCase()==="content-type")?.[1];else for(let[r,o]of Object.entries(t))if(r.toLowerCase()==="content-type"){n=o;break}}return n?.includes("application/x-www-form-urlencoded")?{body:ie(e.form),contentType:"application/x-www-form-urlencoded;charset=UTF-8"}:{body:O(e.form),contentType:void 0}}if(e.body!==void 0){let t=e.body;return P(t)||F(t)||M(t)||v(t)||D(t)||N(t)||$(t)?{body:t,contentType:ae(t)}:l(t)||Array.isArray(t)?{body:JSON.stringify(t),contentType:"application/json;charset=UTF-8"}:{body:String(t),contentType:"text/plain;charset=UTF-8"}}return {body:void 0,contentType:void 0}}function ce(e){let t=e.toUpperCase();return t!=="GET"&&t!=="HEAD"}var V=he(()=>{b();});b();function C(...e){let t={};for(let n of e)if(n)for(let r of Object.keys(n)){let o=n[r],s=t[r];l(o)&&l(s)?t[r]=C(s,o):o!==void 0&&(t[r]=y(o)?[...o]:o);}return t}function tt(...e){let t={};for(let n of e)if(n)for(let r of Object.keys(n)){let o=n[r];o!==void 0&&(t[r]=o);}return t}function E(e){if(e===null||typeof e!="object")return e;if(y(e))return e.map(t=>E(t));if(e instanceof Date)return new Date(e.getTime());if(e instanceof Map){let t=new Map;return e.forEach((n,r)=>t.set(E(r),E(n))),t}if(e instanceof Set){let t=new Set;return e.forEach(n=>t.add(E(n))),t}if(typeof Headers<"u"&&e instanceof Headers){let t=new Headers;return e.forEach((n,r)=>t.set(r,n)),t}if(l(e)){let t={};for(let n of Object.keys(e))t[n]=E(e[n]);return t}return e}function nt(e,t){let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}function rt(e,t){let n={...e};for(let r of t)delete n[r];return n}var Z=class{handlers=new Map;nextId=0;use(t,n){let r=this.nextId++;return this.handlers.set(r,{fulfilled:t,rejected:n}),r}eject(t){this.handlers.delete(t);}clear(){this.handlers.clear();}forEach(t){this.handlers.forEach(t);}getHandlers(){return Array.from(this.handlers.values())}get size(){return this.handlers.size}};function ee(){return new Z}var _=class e extends Error{name="RequestError";status;statusText;data;config;request;response;code;constructor(t,n,r,o,s,i){super(t),this.config=n,this.code=r,this.request=o,this.response=s,this.data=i,s&&(this.status=s.status,this.statusText=s.statusText),Error.captureStackTrace&&Error.captureStackTrace(this,e),Object.setPrototypeOf(this,e.prototype);}toJSON(){return {name:this.name,message:this.message,status:this.status,statusText:this.statusText,code:this.code,data:this.data,config:{url:this.config.url,method:this.config.method,baseURL:this.config.baseURL}}}};function q(e,t,n,r,o,s){return new _(e,t,n,r,o,s)}function Te(e,t,n){return e.name==="AbortError"?q(e.message||"Request aborted",t,"ERR_CANCELED",n):e.name==="TimeoutError"||e.message?.includes("timeout")?q(e.message||"Request timeout",t,"ERR_TIMEOUT",n):q(e.message||"Network error",t,"ERR_NETWORK",n)}async function we(e,t,n){let r=e.status,o=e.statusText,s;try{let c=await e.text();try{s=JSON.parse(c);}catch{s=c;}}catch{s=void 0;}let i=r>=500?"ERR_BAD_RESPONSE":"ERR_BAD_REQUEST",a=`Request failed with status ${r}${o?`: ${o}`:""}`;return q(a,t,i,n,e,s)}function m(e){return e instanceof _||e instanceof Error&&e.name==="RequestError"&&"config"in e}function ot(e){return m(e)&&e.code==="ERR_NETWORK"}function st(e){return m(e)&&e.code==="ERR_TIMEOUT"}function te(e){return m(e)?e.code==="ERR_CANCELED":e instanceof Error&&e.name==="AbortError"}function it(e){return m(e)&&e.code==="ERR_BAD_REQUEST"}function at(e){return m(e)&&e.code==="ERR_BAD_RESPONSE"}async function be(e,t){let n=e,r=t.getHandlers();for(let o of r)try{if(o.fulfilled){let s=o.fulfilled(n);n=s instanceof Promise?await s:s;}}catch(s){if(o.rejected)try{let i=o.rejected(m(s)?s:ne(s,n));if(i&&typeof i=="object"&&"url"in i){n=i;continue}if(i instanceof Promise){let a=await i;if(a&&typeof a=="object"&&"url"in a){n=a;continue}}}catch(i){throw m(i)?i:ne(i,n)}throw m(s)?s:ne(s,n)}return n}function ne(e,t){return {name:"RequestError",message:e instanceof Error?e.message:"Request interceptor error",config:t,code:"ERR_BAD_REQUEST"}}async function Ee(e,t,n){let r=e,o=t.getHandlers().slice().reverse();for(let s of o)try{if(s.fulfilled){let i=s.fulfilled(r);r=i instanceof Promise?await i:i;}}catch(i){if(s.rejected)try{let a=s.rejected(m(i)?i:K(i,n,r));if(a instanceof Response){r=a;continue}if(a instanceof Promise){let c=await a;if(c instanceof Response){r=c;continue}}}catch(a){throw m(a)?a:K(a,n,r)}throw m(i)?i:K(i,n,r)}return r}async function re(e,t,n){let r=t.getHandlers().slice().reverse();for(let o of r)if(o.rejected)try{let s=o.rejected(e);if(s instanceof Response)return s;if(s instanceof Promise){let i=await s;if(i instanceof Response)return i}}catch(s){e=m(s)?s:K(s,n);}throw e}function K(e,t,n){let r=e instanceof Error?e.message:"Response interceptor error";return q(r,t,n&&n.status>=500?"ERR_BAD_RESPONSE":"ERR_BAD_REQUEST",void 0,n)}function J(e){return /^(?:[a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function oe(e,t){if(!e)return t;if(!t)return e;if(J(t))return t;let n=e.replace(/\/+$/,""),r=t.replace(/^\/+/,"");return `${n}/${r}`}function se(e,t){if(!t)return e;let n;if(typeof t=="string")n=t;else if(t instanceof URLSearchParams)n=t.toString();else {let a=[];for(let[c,h]of Object.entries(t))if(h!=null)if(Array.isArray(h))for(let I of h)I!=null&&a.push(`${encodeURIComponent(c)}=${encodeURIComponent(String(I))}`);else h instanceof Date?a.push(`${encodeURIComponent(c)}=${encodeURIComponent(h.toISOString())}`):typeof h=="object"?a.push(`${encodeURIComponent(c)}=${encodeURIComponent(JSON.stringify(h))}`):a.push(`${encodeURIComponent(c)}=${encodeURIComponent(String(h))}`);n=a.join("&");}if(!n)return e;let r=e.indexOf("#"),o=e,s="";r!==-1&&(s=e.slice(r),o=e.slice(0,r));let i=o.includes("?")?"&":"?";return `${o}${i}${n}${s}`}function ut(e){try{let t=new URL(e,"http://localhost");return {protocol:t.protocol,host:t.host,pathname:t.pathname,search:t.search,hash:t.hash}}catch{return {protocol:"",host:"",pathname:e,search:"",hash:""}}}function ct(e){try{return new URL(e).origin}catch{return ""}}function ft(e,t){try{let n=new URL(e).origin,r=new URL(t).origin;return n===r}catch{return false}}b();V();b();function Ce(e){if(!e)return new Headers;if(z(e)){let t=new Headers;return e.forEach((n,r)=>{t.set(r,n);}),t}if(y(e))return new Headers(e);if(l(e)){let t=new Headers;for(let[n,r]of Object.entries(e))r!=null&&t.set(n,String(r));return t}return new Headers(e)}function fe(...e){let t=new Headers;for(let n of e){if(!n)continue;Ce(n).forEach((o,s)=>{o===""?t.delete(s):t.set(s,o);});}return t}function lt(e){let t={};return e.forEach((n,r)=>{t[r]=n;}),t}function qe(e,t,n){e.has(t)||e.set(t,n);}function ke(e,t){if(!e)return;if(z(e))return e.get(t)??void 0;let n=t.toLowerCase();if(y(e))return e.find(([o])=>o.toLowerCase()===n)?.[1];if(l(e)){for(let[r,o]of Object.entries(e))if(r.toLowerCase()===n)return o}}function dt(e,t){return ke(e,t)!==void 0}var pt={JSON:"application/json",FORM:"application/x-www-form-urlencoded",MULTIPART:"multipart/form-data",TEXT:"text/plain",HTML:"text/html",XML:"application/xml",OCTET_STREAM:"application/octet-stream"};function Q(e){return e?e.includes("application/json")||e.includes("+json"):false}function mt(e){return e?e.startsWith("text/")||Q(e)||e.includes("application/xml")||e.includes("+xml"):false}b();function k(e,t=true){return t?encodeURIComponent(e):e}function j(e){return Y(e)?e.toISOString():l(e)||y(e)?JSON.stringify(e):String(e)}function Rt(e,t,n,r){let o=k(e,r),s=[];switch(n){case "indices":for(let i=0;i<t.length;i++){let a=t[i];x(a)||s.push(`${o}[${i}]=${k(j(a),r)}`);}break;case "brackets":for(let i of t)x(i)||s.push(`${o}[]=${k(j(i),r)}`);break;case "comma":{let i=t.filter(a=>!x(a));if(i.length>0){let a=i.map(c=>j(c)).join(",");s.push(`${o}=${k(a,r)}`);}break}default:for(let i of t)x(i)||s.push(`${o}=${k(j(i),r)}`);break}return s}function le(e,t={}){let{arrayFormat:n="repeat",encode:r=true}=t,o=[];for(let[s,i]of Object.entries(e))if(!x(i))if(y(i))o.push(...Rt(s,i,n,r));else {let a=k(s,r),c=k(j(i),r);o.push(`${a}=${c}`);}return o.join("&")}function gt(e){let t={};if(!e)return t;let n=e.startsWith("?")?e.slice(1):e,r=new URLSearchParams(n);for(let[o,s]of r.entries()){let i=o.match(/^(.+)\[\d*\]$/),a=i?i[1]:o;if(i||r.getAll(o).length>1){if(a){let c=t[a];y(c)?c.push(s):c!==void 0?t[a]=[c,s]:t[a]=[s];}}else {let c=t[o];c!==void 0?y(c)?c.push(s):t[o]=[c,s]:t[o]=s;}}return t}function yt(e={}){return {arrayFormat:e.arrayFormat??"brackets",encode:t=>le(t,e)}}function Se(e,t){return e instanceof URLSearchParams?e.toString():t?.encode?t.encode(e):le(e,{arrayFormat:t?.arrayFormat??"repeat"})}var G={timeout:0,responseType:"json",validateStatus:e=>e>=200&&e<300};function ht(e){let t=e.url;if(e.baseURL&&!J(t)&&(t=oe(e.baseURL,t)),e.params){let n=Se(e.params,e.paramsSerializer);t=se(t,n);}return t}function Tt(e,t,n){if(!t)return e;let r=y(t)?t:[t],o=e;for(let s of r)A(s)&&(o=s(o,n));return o}function Ie(e,t={}){let n=C(G,e,t),r=fe(e.headers,t.headers);return {...n,url:t.url??"",method:(t.method??"GET").toUpperCase(),headers:r,baseURL:e.baseURL}}function Pe(e){let t=ht(e),n,r;if(ce(e.method)){let s=ue(e);if(n=s.body,n&&e.transformRequest){let i=Tt(l(e.body)||l(e.json)?e.json??e.body:n,e.transformRequest,e.headers);i!==n&&l(i)&&(n=JSON.stringify(i),r="application/json;charset=UTF-8");}r=r??s.contentType;}r&&qe(e.headers,"Content-Type",r);let o={method:e.method,headers:e.headers,body:n,signal:e.signal,credentials:e.credentials,cache:e.cache,mode:e.mode};return new Request(t,o)}async function Ae(e){return fetch(e)}b();async function wt(e,t="json"){switch(t){case "text":return await e.text();case "blob":return await e.blob();case "arrayBuffer":return await e.arrayBuffer();case "stream":return e.body;case "raw":return e;default:{let n=e.headers.get("content-type");if(e.headers.get("content-length")==="0"||e.status===204||e.status===205)return;if(Q(n)){let s=e.clone();try{return await e.json()}catch{return await s.text()}}let o=await e.text();if(!o)return;try{return JSON.parse(o)}catch{return o}}}}function bt(e,t,n){if(!t)return e;let r=y(t)?t:[t],o=e;for(let s of r)A(s)&&(o=s(o,n));return o}function Et(e,t,n,r){return {data:e,status:t.status,statusText:t.statusText,headers:t.headers,config:n,request:r,ok:t.ok}}async function W(e,t,n){let r=t.responseType??"json",o=await wt(e,r);return o=bt(o,t.transformResponse,e.headers),t.raw?Et(o,e,t,n):o}function Oe(e,t){return t?t(e):e>=200&&e<300}function xt(e){let t=new AbortController;return setTimeout(()=>{t.abort(new DOMException("Request timeout","TimeoutError"));},e),t.signal}function Ct(...e){let t=new AbortController;for(let n of e)if(n){if(n.aborted)return t.abort(n.reason),t.signal;n.addEventListener("abort",()=>t.abort(n.reason),{once:true});}return t.signal}function je(e,t){if(!e||e<=0)return t;let n=xt(e);return t?Ct(n,t):n}function Ue(e){return e instanceof DOMException&&e.name==="TimeoutError"?true:e instanceof Error&&e.name==="AbortError"?e.message.toLowerCase().includes("timeout"):false}function de(e){return new Promise(t=>setTimeout(t,e))}function qt(e,t){return new Promise((n,r)=>{if(t?.aborted){r(t.reason??new DOMException("Aborted","AbortError"));return}let o=setTimeout(()=>{t?.removeEventListener("abort",s),n();},e),s=()=>{clearTimeout(o),r(t?.reason??new DOMException("Aborted","AbortError"));};t?.addEventListener("abort",s,{once:true});})}var U={limit:0,methods:["GET","HEAD","OPTIONS","PUT","DELETE"],statusCodes:[408,429,500,502,503,504],delay:1e3,backoff:"exponential",maxDelay:3e4,retryCondition:()=>true,onRetry:()=>{}};function kt(e){return e===void 0||e===0?{...U,limit:0}:typeof e=="number"?{...U,limit:e}:{...U,...e,methods:e.methods??U.methods,statusCodes:e.statusCodes??U.statusCodes}}function St(e,t){let{delay:n,backoff:r,maxDelay:o}=t,s;return r==="linear"?s=n*e:s=n*Math.pow(2,e-1),Math.min(s,o)}function It(e,t,n,r){return !(t>=n.limit||te(e)||!n.methods.includes(r)||e.status!==void 0&&!n.statusCodes.includes(e.status)||!n.retryCondition(e))}async function He(e,t,n){let r=kt(t);if(r.limit===0)return e();let o,s=0;for(;s<=r.limit;)try{return await e()}catch(i){let a=i;if(o=a,s++,!It(a,s,r,n.method))throw a;let c=St(s,r);if(r.onRetry(s,a,n),await de(c),n.signal?.aborted)throw a}throw o??new Error("Retry failed")}function S(e,t){let n=t>0?Math.round(e/t*100):0;return {loaded:e,total:t,percent:n}}function Be(e,t){let n=e.headers.get("content-length"),r=n?parseInt(n,10):0;if(!e.body)return t(S(0,0)),e;let o=0,s=e.body.getReader(),i=new ReadableStream({async start(a){try{for(;;){let{done:c,value:h}=await s.read();if(c){t(S(o,r||o)),a.close();break}o+=h.byteLength,t(S(o,r)),a.enqueue(h);}}catch(c){a.error(c);}},cancel(a){s.cancel(a);}});return new Response(i,{status:e.status,statusText:e.statusText,headers:e.headers})}function Pt(e,t,n){let r=0,o=e.getReader();return new ReadableStream({async start(){n(S(0,t));},async pull(s){try{let{done:i,value:a}=await o.read();if(i){n(S(r,t||r)),s.close();return}r+=a.byteLength,n(S(r,t)),s.enqueue(a);}catch(i){s.error(i);}},cancel(s){o.cancel(s);}})}function At(e){if(!e)return 0;if(typeof e=="string")return new TextEncoder().encode(e).length;if(e instanceof Blob)return e.size;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return e.byteLength;if(e instanceof FormData){let t=0;return e.forEach(n=>{typeof n=="string"?t+=new TextEncoder().encode(n).length:n instanceof Blob&&(t+=n.size);}),t}return e instanceof URLSearchParams?new TextEncoder().encode(e.toString()).length:0}function Ot(e){if(e instanceof ReadableStream)return e;if(typeof e=="string"){let n=new TextEncoder().encode(e);return new ReadableStream({start(r){r.enqueue(n),r.close();}})}if(e instanceof Blob)return typeof e.stream=="function"?e.stream():null;if(e instanceof ArrayBuffer){let t=new Uint8Array(e);return new ReadableStream({start(n){n.enqueue(t),n.close();}})}return ArrayBuffer.isView(e)?new ReadableStream({start(t){t.enqueue(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),t.close();}}):null}function Le(e,t){let n=At(e),r=Ot(e);return r?Pt(r,n,t):(t(S(n,n)),e)}var H=class{message;constructor(t){this.message=t;}toString(){return this.message??"Request canceled"}},pe=class{promise;reason;resolvePromise;constructor(){this.promise=new Promise(t=>{this.resolvePromise=t;});}throwIfRequested(){if(this.reason)throw this.reason}_cancel(t){this.reason||(this.reason=new H(t),this.resolvePromise(this.reason));}},jt={source(){let e=new pe;return {token:e,cancel:t=>{e._cancel(t);}}}};function Ut(e){return e instanceof H}function Fe(e,t){return {data:e,cancel:()=>t.abort(new H("Canceled"))}}b();function me(e={}){let t=C(G,e),n=ee(),r=ee(),o={request:n,response:r};async function s(d,f){let p;typeof d=="string"?p={...f,url:d}:p=d;let u=Ie(t,p);if(t.onRequest){let g=t.onRequest(u);u=g instanceof Promise?await g:g;}u=await be(u,n);let Re=p.cancelable,B;Re&&(B=new AbortController,u.signal=B.signal);let $e=u.signal,L=u.timeout;L&&L>0&&(u.signal=je(L,$e));let ze=async()=>{let g;try{if(g=Pe(u),u.onUploadProgress&&g.body&&(u.body??u.json??u.form)){let{body:ye}=await Promise.resolve().then(()=>(V(),xe)).then(X=>X.serializeBody(u));if(ye){let X=Le(ye,u.onUploadProgress);g=new Request(g.url,{method:g.method,headers:g.headers,body:X,signal:u.signal,credentials:u.credentials,cache:u.cache,mode:u.mode});}}let R=await Ae(g);if(u.onDownloadProgress&&(R=Be(R,u.onDownloadProgress)),t.onResponse){let w=t.onResponse(R);R=w instanceof Promise?await w:w;}R=await Ee(R,r,u);let T=u.validateStatus??G.validateStatus;if(!Oe(R.status,T)){let w=await we(R,u,g);throw t.onError&&t.onError(w),w}return W(R,u,g)}catch(R){if(!m(R)){let T=Te(R,u,g);t.onError&&t.onError(T),Ue(R)&&(T.code="ERR_TIMEOUT",T.message=`Request timeout after ${L}ms`);try{let w=await re(T,r,u);return W(w,u,g)}catch{throw T}}t.onError&&!m(R)&&t.onError(R);try{let T=await re(R,r,u);return W(T,u,g)}catch{throw R}}},_e=u.retry,ge=He(ze,_e,u);return Re&&B?Fe(ge,B):ge}function i(d,f){return s(d,{...f,method:"GET"})}function a(d,f,p){let u={...p,method:"POST"};return f!==void 0&&(l(f)?u.json=f:u.body=f),s(d,u)}function c(d,f,p){let u={...p,method:"PUT"};return f!==void 0&&(l(f)?u.json=f:u.body=f),s(d,u)}function h(d,f,p){let u={...p,method:"PATCH"};return f!==void 0&&(l(f)?u.json=f:u.body=f),s(d,u)}function I(d,f){return s(d,{...f,method:"DELETE"})}function Me(d,f){return s(d,{...f,method:"HEAD"})}function ve(d,f){return s(d,{...f,method:"OPTIONS"})}function De(d){let f=C(t,d),p=me(f);return n.forEach(u=>{p.interceptors.request.use(u.fulfilled,u.rejected);}),r.forEach(u=>{p.interceptors.response.use(u.fulfilled,u.rejected);}),p}function Ne(){let d=E(t),f=me(d);return n.forEach(p=>{f.interceptors.request.use(p.fulfilled,p.rejected);}),r.forEach(p=>{f.interceptors.response.use(p.fulfilled,p.rejected);}),f}return {request:s,get:i,post:a,put:c,patch:h,delete:I,head:Me,options:ve,interceptors:o,defaults:t,extend:De,clone:Ne}}V();b();
|
|
2
|
-
exports.CancelToken=
|
|
1
|
+
'use strict';var chunkSEYWPFTU_cjs=require('./chunk-SEYWPFTU.cjs');function H(e){return typeof FormData<"u"&&e instanceof FormData}function N(e){return typeof Blob<"u"&&e instanceof Blob}function Ze(e){return typeof File<"u"&&e instanceof File}function $(e){return typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer}function _(e){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView(e)}function K(e){return typeof URLSearchParams<"u"&&e instanceof URLSearchParams}function k(e){return typeof ReadableStream<"u"&&e instanceof ReadableStream}function d(e){if(e===null||typeof e!="object")return false;let n=Object.getPrototypeOf(e);return n===null||n===Object.prototype}function L(e){return typeof e=="function"}function V(e){return typeof e=="string"}function en(e){return typeof e=="number"&&!Number.isNaN(e)}function nn(e){return typeof e>"u"}function A(e){return e==null}function te(e){return e instanceof Date&&!Number.isNaN(e.getTime())}function tn(e){return typeof e=="boolean"}function g(e){return Array.isArray(e)}function rn(e){return e!==null&&typeof e=="object"}function E(e){return typeof Headers<"u"&&e instanceof Headers}function on(e){return typeof Request<"u"&&e instanceof Request}function sn(e){return typeof Response<"u"&&e instanceof Response}function an(e){return typeof AbortSignal<"u"&&e instanceof AbortSignal}var un=new Set(["__proto__","constructor","prototype"]);function re(e){return !un.has(e)}function I(...e){let n={};for(let t of e)if(t)for(let r of Object.keys(t).filter(re)){let o=t[r],s=n[r];d(o)&&d(s)?n[r]=I(s,o):o!==void 0&&(n[r]=g(o)?[...o]:o);}return n}function cn(...e){let n={};for(let t of e)if(t)for(let r of Object.keys(t).filter(re)){let o=t[r];o!==void 0&&(n[r]=o);}return n}function S(e){if(e===null||typeof e!="object")return e;if(g(e))return e.map(n=>S(n));if(e instanceof Date)return new Date(e.getTime());if(e instanceof Map){let n=new Map;return e.forEach((t,r)=>n.set(S(r),S(t))),n}if(e instanceof Set){let n=new Set;return e.forEach(t=>n.add(S(t))),n}if(typeof Headers<"u"&&e instanceof Headers){let n=new Headers;return e.forEach((t,r)=>n.set(r,t)),n}if(d(e)){let n={};for(let t of Object.keys(e).filter(re))n[t]=S(e[t]);return n}return e}function fn(e,n){let t={};for(let r of n)r in e&&(t[r]=e[r]);return t}function ln(e,n){let t={...e};for(let r of n)delete t[r];return t}var oe=class{handlers=new Map;nextId=0;use(n,t){let r=this.nextId++;return this.handlers.set(r,{fulfilled:n,rejected:t}),r}eject(n){this.handlers.delete(n);}clear(){this.handlers.clear();}forEach(n){this.handlers.forEach(n);}getHandlers(){return Array.from(this.handlers.values())}get size(){return this.handlers.size}};function se(){return new oe}async function Ce(e,n){let t=e,r=n.getHandlers();for(let o of r)try{if(o.fulfilled){let s=o.fulfilled(t);t=s instanceof Promise?await s:s;}}catch(s){if(o.rejected)try{let i=o.rejected(chunkSEYWPFTU_cjs.e(s)?s:ie(s,t));if(i&&typeof i=="object"&&"url"in i){t=i;continue}if(i instanceof Promise){let a=await i;if(a&&typeof a=="object"&&"url"in a){t=a;continue}}}catch(i){throw chunkSEYWPFTU_cjs.e(i)?i:ie(i,t)}throw chunkSEYWPFTU_cjs.e(s)?s:ie(s,t)}return t}function ie(e,n){let t=e instanceof Error?e.message:"Request interceptor error";return chunkSEYWPFTU_cjs.a(t,n,"ERR_BAD_REQUEST",void 0,void 0,void 0,e)}async function xe(e,n,t){let r=e,o=n.getHandlers().slice().reverse();for(let s of o)try{if(s.fulfilled){let i=s.fulfilled(r);r=i instanceof Promise?await i:i;}}catch(i){if(s.rejected)try{let a=s.rejected(chunkSEYWPFTU_cjs.e(i)?i:J(i,t,r));if(a instanceof Response){r=a;continue}if(a instanceof Promise){let c=await a;if(c instanceof Response){r=c;continue}}}catch(a){throw chunkSEYWPFTU_cjs.e(a)?a:J(a,t,r)}throw chunkSEYWPFTU_cjs.e(i)?i:J(i,t,r)}return r}async function ke(e,n,t){let r=n.getHandlers().slice().reverse();for(let o of r)if(o.rejected)try{let s=o.rejected(e);if(s instanceof Response)return s;if(s instanceof Promise){let i=await s;if(i instanceof Response)return i}}catch(s){e=chunkSEYWPFTU_cjs.e(s)?s:J(s,t,e.response);}throw e}function J(e,n,t){let r=e instanceof Error?e.message:"Response interceptor error";return chunkSEYWPFTU_cjs.a(r,n,t&&t.status>=500?"ERR_BAD_RESPONSE":"ERR_BAD_REQUEST",void 0,t,void 0,e)}function F(e){return /^(?:[a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function ae(e,n){if(!e)return n;if(!n)return e;if(F(n))return n;let t=e.replace(/\/+$/,""),r=n.replace(/^\/+/,"");return `${t}/${r}`}function ue(e,n){if(!n)return e;let t;if(typeof n=="string")t=n;else if(n instanceof URLSearchParams)t=n.toString();else {let a=[];for(let[c,R]of Object.entries(n))if(R!=null)if(Array.isArray(R))for(let q of R)q!=null&&a.push(`${encodeURIComponent(c)}=${encodeURIComponent(String(q))}`);else R instanceof Date?a.push(`${encodeURIComponent(c)}=${encodeURIComponent(R.toISOString())}`):typeof R=="object"?a.push(`${encodeURIComponent(c)}=${encodeURIComponent(JSON.stringify(R))}`):a.push(`${encodeURIComponent(c)}=${encodeURIComponent(String(R))}`);t=a.join("&");}if(!t)return e;let r=e.indexOf("#"),o=e,s="";r!==-1&&(s=e.slice(r),o=e.slice(0,r));let i=o.includes("?")?"&":"?";return `${o}${i}${t}${s}`}function dn(e){try{let n=new URL(e,"http://localhost");return {protocol:n.protocol,host:n.host,pathname:n.pathname,search:n.search,hash:n.hash}}catch{return {protocol:"",host:"",pathname:e,search:"",hash:""}}}function pn(e){try{return new URL(e).origin}catch{return ""}}function mn(e,n){try{let t=new URL(e).origin,r=new URL(n).origin;return t===r}catch{return false}}function Q(e,n=new FormData,t=""){for(let[r,o]of Object.entries(e)){let s=t?`${t}[${r}]`:r;if(o!=null)if(o instanceof File)n.append(s,o,o.name);else if(o instanceof Blob)n.append(s,o);else if(Array.isArray(o))for(let i=0;i<o.length;i++){let a=o[i];a instanceof File?n.append(`${s}[${i}]`,a,a.name):a instanceof Blob?n.append(`${s}[${i}]`,a):typeof a=="object"&&a!==null?Q({[i]:a},n,s):n.append(`${s}[]`,String(a));}else d(o)?Q(o,n,s):n.append(s,String(o));}return n}function Ee(e){let n=new URLSearchParams;for(let[t,r]of Object.entries(e))if(r!=null)if(Array.isArray(r))for(let o of r)o!=null&&n.append(t,String(o));else n.append(t,String(r));return n}function Se(e){if(!H(e)){if(N(e))return e.type||"application/octet-stream";if(K(e))return "application/x-www-form-urlencoded;charset=UTF-8";if($(e)||_(e)||k(e))return "application/octet-stream";if(V(e))return "text/plain;charset=UTF-8";if(d(e)||Array.isArray(e))return "application/json;charset=UTF-8"}}function qe(e){if(e.json!==void 0)return {body:JSON.stringify(e.json),contentType:"application/json;charset=UTF-8"};if(e.form!==void 0){if(H(e.form))return {body:e.form,contentType:void 0};let n=e.headers,t;if(n){if(n instanceof Headers)t=n.get("content-type")??void 0;else if(Array.isArray(n))t=n.find(([o])=>o.toLowerCase()==="content-type")?.[1];else for(let[r,o]of Object.entries(n))if(r.toLowerCase()==="content-type"){t=o;break}}return t?.includes("application/x-www-form-urlencoded")?{body:Ee(e.form),contentType:"application/x-www-form-urlencoded;charset=UTF-8"}:{body:Q(e.form),contentType:void 0}}if(e.body!==void 0){let n=e.body;return H(n)||N(n)||$(n)||_(n)||K(n)||k(n)||V(n)?{body:n,contentType:Se(n)}:d(n)||Array.isArray(n)?{body:JSON.stringify(n),contentType:"application/json;charset=UTF-8"}:{body:String(n),contentType:"text/plain;charset=UTF-8"}}return {body:void 0,contentType:void 0}}function Ae(e){let n=e.toUpperCase();return n!=="GET"&&n!=="HEAD"}function U(e){if(!e)return new Headers;if(E(e)){let n=new Headers;return e.forEach((t,r)=>{n.set(r,t);}),n}if(g(e))return new Headers(e);if(d(e)){let n=new Headers;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,String(r));return n}return new Headers(e)}function M(...e){let n=new Headers;for(let t of e){if(!t)continue;U(t).forEach((o,s)=>{o===""?n.delete(s):n.set(s,o);});}return n}function Rn(e){let n={};return e.forEach((t,r)=>{n[r]=t;}),n}function Ie(e,n,t){e.has(n)||e.set(n,t);}function Pe(e,n){if(!e)return;if(E(e))return e.get(n)??void 0;let t=n.toLowerCase();if(g(e))return e.find(([o])=>o.toLowerCase()===t)?.[1];if(d(e)){for(let[r,o]of Object.entries(e))if(r.toLowerCase()===t)return o}}function gn(e,n){return Pe(e,n)!==void 0}var yn={JSON:"application/json",FORM:"application/x-www-form-urlencoded",MULTIPART:"multipart/form-data",TEXT:"text/plain",HTML:"text/html",XML:"application/xml",OCTET_STREAM:"application/octet-stream"};function Oe(e){return e?e.includes("application/json")||e.includes("+json"):false}function hn(e){return e?e.startsWith("text/")||Oe(e)||e.includes("application/xml")||e.includes("+xml"):false}function P(e,n=true){return n?encodeURIComponent(e):e}function v(e){return te(e)?e.toISOString():d(e)||g(e)?JSON.stringify(e):String(e)}function Tn(e,n,t,r){let o=P(e,r),s=[];switch(t){case "indices":for(let i=0;i<n.length;i++){let a=n[i];A(a)||s.push(`${o}[${i}]=${P(v(a),r)}`);}break;case "brackets":for(let i of n)A(i)||s.push(`${o}[]=${P(v(i),r)}`);break;case "comma":{let i=n.filter(a=>!A(a));if(i.length>0){let a=i.map(c=>v(c)).join(",");s.push(`${o}=${P(a,r)}`);}break}default:for(let i of n)A(i)||s.push(`${o}=${P(v(i),r)}`);break}return s}function ce(e,n={}){let{arrayFormat:t="repeat",encode:r=true}=n,o=[];for(let[s,i]of Object.entries(e))if(!A(i))if(g(i))o.push(...Tn(s,i,t,r));else {let a=P(s,r),c=P(v(i),r);o.push(`${a}=${c}`);}return o.join("&")}function wn(e){let n={};if(!e)return n;let t=e.startsWith("?")?e.slice(1):e,r=new URLSearchParams(t);for(let[o,s]of r.entries()){let i=o.match(/^(.+)\[\d*\]$/),a=i?i[1]:o;if(i||r.getAll(o).length>1){if(a){let c=n[a];g(c)?c.push(s):c!==void 0?n[a]=[c,s]:n[a]=[s];}}else {let c=n[o];c!==void 0?g(c)?c.push(s):n[o]=[c,s]:n[o]=s;}}return n}function bn(e={}){return {arrayFormat:e.arrayFormat??"repeat",encode:n=>ce(n,e)}}function Ue(e,n){return e instanceof URLSearchParams?e.toString():n?.encode?n.encode(e):ce(e,{arrayFormat:n?.arrayFormat??"repeat"})}function O(e,n){let t=n>0?Math.round(e/n*100):0;return {loaded:e,total:n,percent:t}}function je(e,n){let t=e.headers.get("content-length"),r=t?parseInt(t,10):0;if(!e.body)return n(O(0,0)),e;let o=0,s=e.body.getReader(),i=new ReadableStream({async start(a){try{for(;;){let{done:c,value:R}=await s.read();if(c){n(O(o,r||o)),a.close();break}o+=R.byteLength,n(O(o,r)),a.enqueue(R);}}catch(c){a.error(c);}},cancel(a){s.cancel(a);}});return new Response(i,{status:e.status,statusText:e.statusText,headers:e.headers})}function Cn(e,n,t){let r=0,o=e.getReader();return new ReadableStream({async start(){t(O(0,n));},async pull(s){try{let{done:i,value:a}=await o.read();if(i){t(O(r,n||r)),s.close();return}r+=a.byteLength,t(O(r,n)),s.enqueue(a);}catch(i){s.error(i);}},cancel(s){o.cancel(s);}})}function xn(e){if(!e)return 0;if(typeof e=="string")return new TextEncoder().encode(e).length;if(e instanceof Blob)return e.size;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return e.byteLength;if(e instanceof FormData){let n=0;return e.forEach(t=>{typeof t=="string"?n+=new TextEncoder().encode(t).length:t instanceof Blob&&(n+=t.size);}),n}return e instanceof URLSearchParams?new TextEncoder().encode(e.toString()).length:0}function kn(e){if(e instanceof ReadableStream)return e;if(typeof e=="string"){let t=new TextEncoder().encode(e);return new ReadableStream({start(r){r.enqueue(t),r.close();}})}if(e instanceof Blob)return typeof e.stream=="function"?e.stream():null;if(e instanceof ArrayBuffer){let n=new Uint8Array(e);return new ReadableStream({start(t){t.enqueue(n),t.close();}})}return ArrayBuffer.isView(e)?new ReadableStream({start(n){n.enqueue(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),n.close();}}):null}function He(e,n){let t=xn(e),r=kn(e);return r?Cn(r,t,n):(n(O(t,t)),e)}var G={timeout:0,responseType:"json",validateStatus:e=>e>=200&&e<300};function En(e){let n=e.url;if(e.allowAbsoluteUrls===false&&F(n))throw chunkSEYWPFTU_cjs.a(`Absolute URL "${n}" is not allowed (allowAbsoluteUrls: false)`,e,"ERR_BAD_REQUEST");if(e.baseURL&&!F(n)&&(n=ae(e.baseURL,n)),e.params){let t=Ue(e.params,e.paramsSerializer);n=ue(n,t);}return n}function Sn(e,n,t){if(!n)return e;let r=g(n)?n:[n],o=e;for(let s of r)L(s)&&(o=s(o,t));return o}function Le(e,n={}){let t=I(G,e,n),r=M(e.headers,n.headers);return {...t,url:n.url??"",method:(n.method??"GET").toUpperCase(),headers:r,baseURL:e.baseURL}}function Fe(e){E(e.headers)||(e.headers=U(e.headers));let n=En(e),t,r;if(Ae(e.method)){let s=qe(e);if(t=s.body,t&&e.transformRequest){let i=Sn(d(e.body)||d(e.json)?e.json??e.body:t,e.transformRequest,e.headers);i!==t&&d(i)&&(t=JSON.stringify(i),r="application/json;charset=UTF-8");}r=r??s.contentType;}r&&Ie(e.headers,"Content-Type",r),t!==void 0&&e.onUploadProgress&&(t=He(t,e.onUploadProgress));let o={method:e.method,headers:e.headers,body:t,signal:e.signal,credentials:e.credentials,cache:e.cache,mode:e.mode,redirect:e.redirect};return k(t)&&(o.duplex="half"),new Request(n,o)}async function Me(e,n){return n?n(e):fetch(e)}async function qn(e,n="json"){switch(n){case "text":return await e.text();case "blob":return await e.blob();case "arrayBuffer":return await e.arrayBuffer();case "stream":return e.body;case "raw":return e;default:{if(e.headers.get("content-length")==="0"||e.status===204||e.status===205)return;let r=await e.text();if(!r)return;try{return JSON.parse(r)}catch{return r}}}}function An(e,n,t){if(!n)return e;let r=g(n)?n:[n],o=e;for(let s of r)L(s)&&(o=s(o,t));return o}function In(e,n,t,r){return {data:e,status:n.status,statusText:n.statusText,headers:n.headers,config:t,request:r,ok:n.ok}}async function fe(e,n,t){let r=n.responseType??"json",o=await qn(e,r);return o=An(o,n.transformResponse,e.headers),n.raw?In(o,e,n,t):o}function ve(e,n){return n?n(e):e>=200&&e<300}function le(...e){let n=e.filter(s=>s!==void 0);if(n.length===0)return {signal:void 0,cleanup:()=>{}};if(n.length===1)return {signal:n[0],cleanup:()=>{}};let t=new AbortController,r=[],o=()=>{for(let[s,i]of r)s.removeEventListener("abort",i);r.length=0;};for(let s of n){if(s.aborted)return o(),t.abort(s.reason),{signal:t.signal,cleanup:o};let i=()=>{o(),t.abort(s.reason);};s.addEventListener("abort",i,{once:true}),r.push([s,i]);}return {signal:t.signal,cleanup:o}}function Be(e){return e instanceof DOMException&&e.name==="TimeoutError"?true:e instanceof Error&&e.name==="AbortError"?e.message.toLowerCase().includes("timeout"):false}function Pn(e){return new Promise(n=>setTimeout(n,e))}function de(e,n){return new Promise((t,r)=>{if(n?.aborted){r(n.reason??new DOMException("Aborted","AbortError"));return}let o=setTimeout(()=>{n?.removeEventListener("abort",s),t();},e),s=()=>{clearTimeout(o),r(n?.reason??new DOMException("Aborted","AbortError"));};n?.addEventListener("abort",s,{once:true});})}var B={limit:0,methods:["GET","HEAD","OPTIONS","PUT","DELETE"],statusCodes:[408,429,500,502,503,504],delay:1e3,backoff:"exponential",maxDelay:3e4,jitter:false,retryCondition:()=>true,onRetry:()=>{}};function On(e){if(e===void 0||e===0)return {...B,limit:0};if(typeof e=="number")return {...B,limit:e};let{retryOn:n,...t}=e,r={...B};for(let[o,s]of Object.entries(t))s!==void 0&&(r[o]=s);return r.methods=(e.methods??B.methods).map(o=>o.toUpperCase()),r.statusCodes=e.statusCodes??n??B.statusCodes,r}function Un(e,n){let{delay:t,backoff:r,maxDelay:o}=n,s;r==="linear"?s=t*e:s=t*Math.pow(2,e-1);let i=Math.min(s,o);return n.jitter?Math.round(Math.random()*i):i}function jn(e,n,t,r){if(n>t.limit||chunkSEYWPFTU_cjs.h(e)||!t.methods.includes(r.toUpperCase()))return false;if(e.status!==void 0){if(!t.statusCodes.includes(e.status))return false}else if(e.code!==void 0&&e.code!=="ERR_NETWORK"&&e.code!=="ERR_TIMEOUT")return false;return !!t.retryCondition(e)}async function De(e,n,t,r={}){let o=On(n);if(o.limit===0)return e();let s=r.signal??t.signal,i=0;for(;;)try{return await e()}catch(a){let c=a;if(i++,s?.aborted||!jn(c,i,o,t.method)||r.canRetry&&!r.canRetry())throw c;let R=c.response?Hn(c.response):void 0,q=R!==void 0?Math.min(R,o.maxDelay):Un(i,o);o.onRetry(i,c,t);try{await de(q,s);}catch(W){throw chunkSEYWPFTU_cjs.b(W,t)}}}function Hn(e){let n=e.headers.get("Retry-After");if(!n)return;let t=n.trim();if(/^\d+$/.test(t))return Number(t)*1e3;let r=Date.parse(t);if(!isNaN(r)){let o=r-Date.now();return o>0?o:0}}var D=class{message;constructor(n){this.message=n;}toString(){return this.message??"Request canceled"}},pe=class{promise;reason;resolvePromise;constructor(){this.promise=new Promise(n=>{this.resolvePromise=n;});}throwIfRequested(){if(this.reason)throw this.reason}_cancel(n){this.reason||(this.reason=new D(n),this.resolvePromise(this.reason));}},Ln={source(){let e=new pe;return {token:e,cancel:n=>{e._cancel(n);}}}};function Fn(e){return e instanceof D}function ze(e){let n=new AbortController;return e.reason?n.abort(e.reason):e.promise.then(t=>{n.abort(t);}),n}function Ne(e,n){return {data:e,cancel:()=>n.abort(new D("Canceled"))}}function me(e={}){let n=I(G,e),t=se(),r=se(),o={request:t,response:r};async function s(l,f){let p;typeof l=="string"?p={...f,url:l}:p=l;let u=Le(n,p);if(n.onRequest){let y=n.onRequest(u);u=y instanceof Promise?await y:y;}try{u=await Ce(u,t);}catch(y){throw n.onError?.(y),y}E(u.headers)||(u.headers=U(u.headers));let Re=p.cancelable,X=Re?new AbortController:void 0,Ve=u.cancelToken?ze(u.cancelToken):void 0,Y=le(u.signal,X?.signal,Ve?.signal),C=Y.signal;u.signal=C;let x=u.timeout,ge=u.responseType,ye=ge==="stream"||ge==="raw",Je=async()=>{let y,he,ee;if(x&&x>0){let m=new AbortController;ee=m,he=setTimeout(()=>{m.abort(new DOMException(`Request timeout after ${x}ms`,"TimeoutError"));},x);}let Te=le(C,ee?.signal),h={...u,signal:Te.signal};try{try{if(C?.aborted)throw C.reason;y=Fe(h);let m=await Me(y,h.transport);if(h.onDownloadProgress&&(m=je(m,h.onDownloadProgress)),n.onResponse){let j=n.onResponse(m);m=j instanceof Promise?await j:j;}m=await xe(m,r,h);let w=h.validateStatus??G.validateStatus;if(!ve(m.status,w))throw await chunkSEYWPFTU_cjs.d(m,h,y);return await fe(m,h,y)}catch(m){let w;chunkSEYWPFTU_cjs.e(m)?w=m:ee?.signal.aborted&&!C?.aborted?w=chunkSEYWPFTU_cjs.a(`Request timeout after ${x}ms`,h,"ERR_TIMEOUT",y,void 0,void 0,m):C?.aborted?w=chunkSEYWPFTU_cjs.b(C.reason,h,y):(w=chunkSEYWPFTU_cjs.c(m,h,y),Be(m)&&(w.code="ERR_TIMEOUT",x&&x>0&&(w.message=`Request timeout after ${x}ms`))),n.onError?.(w);let j=await ke(w,r,h);return await fe(j,h,y)}}finally{clearTimeout(he),ye||Te.cleanup();}},Qe=u.retry,Z=De(Je,Qe,u,{signal:C,canRetry:()=>!k(u.body)});return ye||Z.then(Y.cleanup,Y.cleanup),Re&&X?Ne(Z,X):Z}function i(l,f){return s(l,{...f,method:"GET"})}function a(l,f,p){let u={...p,method:"POST"};return f!==void 0&&(d(f)?u.json=f:u.body=f),s(l,u)}function c(l,f,p){let u={...p,method:"PUT"};return f!==void 0&&(d(f)?u.json=f:u.body=f),s(l,u)}function R(l,f,p){let u={...p,method:"PATCH"};return f!==void 0&&(d(f)?u.json=f:u.body=f),s(l,u)}function q(l,f){return s(l,{...f,method:"DELETE"})}function W(l,f){return s(l,{...f,method:"HEAD"})}function $e(l,f){return s(l,{...f,method:"OPTIONS"})}function _e(l){let f=I(n,l);(n.headers||l.headers)&&(f.headers=M(n.headers,l.headers));let p=me(f);return t.forEach(u=>{p.interceptors.request.use(u.fulfilled,u.rejected);}),r.forEach(u=>{p.interceptors.response.use(u.fulfilled,u.rejected);}),p}function Ke(){let l=S(n),f=me(l);return t.forEach(p=>{f.interceptors.request.use(p.fulfilled,p.rejected);}),r.forEach(p=>{f.interceptors.response.use(p.fulfilled,p.rejected);}),f}return {request:s,get:i,post:a,put:c,patch:R,delete:q,head:W,options:$e,interceptors:o,defaults:n,extend:_e,clone:Ke}}
|
|
2
|
+
Object.defineProperty(exports,"createError",{enumerable:true,get:function(){return chunkSEYWPFTU_cjs.a}});Object.defineProperty(exports,"isCancelError",{enumerable:true,get:function(){return chunkSEYWPFTU_cjs.h}});Object.defineProperty(exports,"isClientError",{enumerable:true,get:function(){return chunkSEYWPFTU_cjs.i}});Object.defineProperty(exports,"isNetworkError",{enumerable:true,get:function(){return chunkSEYWPFTU_cjs.f}});Object.defineProperty(exports,"isRequestError",{enumerable:true,get:function(){return chunkSEYWPFTU_cjs.e}});Object.defineProperty(exports,"isServerError",{enumerable:true,get:function(){return chunkSEYWPFTU_cjs.j}});Object.defineProperty(exports,"isTimeoutError",{enumerable:true,get:function(){return chunkSEYWPFTU_cjs.g}});exports.CancelToken=Ln;exports.ContentTypes=yn;exports.abortableDelay=de;exports.buildURL=ue;exports.combineURLs=ae;exports.createClient=me;exports.createParamsSerializer=bn;exports.deepClone=S;exports.deepMerge=I;exports.delay=Pn;exports.getContentType=Se;exports.getHeader=Pe;exports.getOrigin=pn;exports.hasHeader=gn;exports.isAbortSignal=an;exports.isAbsoluteURL=F;exports.isArray=g;exports.isArrayBuffer=$;exports.isArrayBufferView=_;exports.isBlob=N;exports.isBoolean=tn;exports.isCancel=Fn;exports.isDate=te;exports.isFile=Ze;exports.isFormData=H;exports.isFunction=L;exports.isHeaders=E;exports.isJSONContentType=Oe;exports.isNullOrUndefined=A;exports.isNumber=en;exports.isObject=rn;exports.isPlainObject=d;exports.isRequest=on;exports.isResponse=sn;exports.isSameOrigin=mn;exports.isStream=k;exports.isString=V;exports.isTextContentType=hn;exports.isURLSearchParams=K;exports.isUndefined=nn;exports.mergeHeaders=M;exports.normalizeHeaders=U;exports.objectToFormData=Q;exports.objectToURLSearchParams=Ee;exports.omit=ln;exports.parseHeaders=Rn;exports.parseParams=wn;exports.parseURL=dn;exports.pick=fn;exports.serializeParams=ce;exports.shallowMerge=cn;//# sourceMappingURL=index.cjs.map
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|