@oxog/requestkit 1.0.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 ADDED
@@ -0,0 +1,65 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ Nothing yet.
11
+
12
+ ## [1.0.0] - 2025-12-29
13
+
14
+ ### Added
15
+
16
+ - Initial release of RequestKit
17
+ - **Core HTTP Client**
18
+ - All standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS)
19
+ - Factory pattern with `createClient()`
20
+ - Configurable base URL, headers, and defaults
21
+ - Request and response interceptors
22
+ - Custom status validation
23
+ - **Retry Logic**
24
+ - Automatic retry with configurable limits
25
+ - Linear and exponential backoff strategies
26
+ - Configurable retry conditions and status codes
27
+ - `onRetry` callback for monitoring
28
+ - **Request Cancellation**
29
+ - CancelToken pattern (Axios-compatible)
30
+ - Native AbortController support
31
+ - `cancelable` option for automatic abort controller
32
+ - **Progress Tracking**
33
+ - Upload progress via `onUploadProgress`
34
+ - Download progress via `onDownloadProgress`
35
+ - **TypeScript Support**
36
+ - Full type definitions
37
+ - Strict mode compatible
38
+ - Generic response types
39
+ - **React Adapter** (`@oxog/requestkit/react`)
40
+ - `RequestProvider` - Context provider
41
+ - `useClient` - Access client instance
42
+ - `useRequest` - Manual request execution
43
+ - `useQuery` - Auto-fetching with caching
44
+ - `useMutation` - Mutation handling
45
+ - `useInfiniteQuery` - Paginated/infinite scroll
46
+ - **Serializers**
47
+ - Query parameter serialization (brackets, repeat, comma formats)
48
+ - Automatic JSON body serialization
49
+ - FormData and URLSearchParams support
50
+ - **Utilities**
51
+ - URL utilities (combineURLs, parseURL, isAbsoluteURL)
52
+ - Deep merge and clone helpers
53
+ - Type guards for common types
54
+ - **Documentation**
55
+ - Comprehensive README
56
+ - Documentation website with interactive playground
57
+
58
+ ### Technical Details
59
+
60
+ - Zero runtime dependencies
61
+ - Built on native Fetch API
62
+ - ESM and CommonJS dual package
63
+ - Tree-shakeable exports
64
+ - Bundle size: ~20KB core, ~6.5KB React adapter (uncompressed)
65
+ - 355 tests with full coverage
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ersin KOÇ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,253 @@
1
+ # RequestKit
2
+
3
+ <div align="center">
4
+
5
+ ![RequestKit Logo](website/public/logo.svg)
6
+
7
+ **Zero-dependency HTTP client built on native fetch**
8
+
9
+ [![npm version](https://img.shields.io/npm/v/@oxog/requestkit.svg)](https://www.npmjs.com/package/@oxog/requestkit)
10
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@oxog/requestkit)](https://bundlephobia.com/package/@oxog/requestkit)
11
+ [![license](https://img.shields.io/npm/l/@oxog/requestkit.svg)](LICENSE)
12
+
13
+ [Documentation](https://oxog.github.io/requestkit) | [Examples](https://oxog.github.io/requestkit/examples) | [Playground](https://oxog.github.io/requestkit/playground)
14
+
15
+ </div>
16
+
17
+ ## Features
18
+
19
+ - **Zero Dependencies** - Built entirely on native fetch API
20
+ - **TypeScript First** - Full type safety with excellent DX
21
+ - **Interceptors** - Request/response interceptors like axios
22
+ - **Automatic Retry** - Configurable retry with exponential backoff
23
+ - **Request Cancellation** - Cancel tokens and AbortController support
24
+ - **Progress Tracking** - Upload and download progress callbacks
25
+ - **React Hooks** - Built-in useQuery, useMutation, useInfiniteQuery
26
+ - **Tiny Bundle** - < 4KB core, < 6KB with React adapter (gzipped)
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install @oxog/requestkit
32
+
33
+ # or with yarn
34
+ yarn add @oxog/requestkit
35
+
36
+ # or with pnpm
37
+ pnpm add @oxog/requestkit
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ```typescript
43
+ import { createClient } from '@oxog/requestkit'
44
+
45
+ // Create a client instance
46
+ const api = createClient({
47
+ baseURL: 'https://api.example.com',
48
+ })
49
+
50
+ // Make requests
51
+ const users = await api.get<User[]>('/users')
52
+ const user = await api.post<User>('/users', { name: 'John' })
53
+ ```
54
+
55
+ ## Configuration
56
+
57
+ ```typescript
58
+ const api = createClient({
59
+ baseURL: 'https://api.example.com/v1',
60
+ headers: {
61
+ 'Authorization': 'Bearer token',
62
+ },
63
+ timeout: 10000,
64
+ retry: {
65
+ limit: 3,
66
+ delay: 1000,
67
+ backoff: 'exponential',
68
+ },
69
+ })
70
+ ```
71
+
72
+ ## Interceptors
73
+
74
+ ```typescript
75
+ // Request interceptor
76
+ api.interceptors.request.use((config) => {
77
+ config.headers = {
78
+ ...config.headers,
79
+ 'X-Request-Id': crypto.randomUUID(),
80
+ }
81
+ return config
82
+ })
83
+
84
+ // Response interceptor
85
+ api.interceptors.response.use(
86
+ (response) => response,
87
+ (error) => {
88
+ if (error.status === 401) {
89
+ window.location.href = '/login'
90
+ }
91
+ return Promise.reject(error)
92
+ }
93
+ )
94
+ ```
95
+
96
+ ## React Integration
97
+
98
+ ```tsx
99
+ import { createClient } from '@oxog/requestkit'
100
+ import { RequestProvider, useQuery } from '@oxog/requestkit/react'
101
+
102
+ const client = createClient({
103
+ baseURL: 'https://api.example.com',
104
+ })
105
+
106
+ function App() {
107
+ return (
108
+ <RequestProvider client={client}>
109
+ <UserList />
110
+ </RequestProvider>
111
+ )
112
+ }
113
+
114
+ function UserList() {
115
+ const { data, loading, error } = useQuery<User[]>('/users')
116
+
117
+ if (loading) return <div>Loading...</div>
118
+ if (error) return <div>Error: {error.message}</div>
119
+
120
+ return (
121
+ <ul>
122
+ {data?.map(user => (
123
+ <li key={user.id}>{user.name}</li>
124
+ ))}
125
+ </ul>
126
+ )
127
+ }
128
+ ```
129
+
130
+ ## Available Hooks
131
+
132
+ ### useQuery
133
+
134
+ Fetch data on component mount with automatic refetching.
135
+
136
+ ```tsx
137
+ const { data, loading, error, refetch } = useQuery<User[]>('/users', {
138
+ enabled: true,
139
+ onSuccess: (data) => console.log('Fetched:', data),
140
+ })
141
+ ```
142
+
143
+ ### useMutation
144
+
145
+ Execute mutations with loading states.
146
+
147
+ ```tsx
148
+ const { mutate, mutateAsync, loading } = useMutation<User, CreateUserInput>(
149
+ (input) => client.post('/users', input),
150
+ { onSuccess: (user) => console.log('Created:', user) }
151
+ )
152
+ ```
153
+
154
+ ### useInfiniteQuery
155
+
156
+ Fetch paginated data with infinite scroll.
157
+
158
+ ```tsx
159
+ const { data, hasNextPage, fetchNextPage } = useInfiniteQuery<Page>(
160
+ (cursor) => `/items?cursor=${cursor}`,
161
+ { getNextPageParam: (page) => page.nextCursor }
162
+ )
163
+ ```
164
+
165
+ ## Error Handling
166
+
167
+ ```typescript
168
+ import { isRequestError } from '@oxog/requestkit'
169
+
170
+ try {
171
+ await api.get('/users/999')
172
+ } catch (error) {
173
+ if (isRequestError(error)) {
174
+ console.log('Status:', error.status)
175
+ console.log('Data:', error.data)
176
+ }
177
+ }
178
+ ```
179
+
180
+ ## Request Cancellation
181
+
182
+ ```typescript
183
+ import { CancelToken } from '@oxog/requestkit'
184
+
185
+ const source = CancelToken.source()
186
+
187
+ api.get('/data', { cancelToken: source.token })
188
+
189
+ // Cancel the request
190
+ source.cancel('Operation canceled')
191
+ ```
192
+
193
+ ## Progress Tracking
194
+
195
+ ```typescript
196
+ await api.post('/upload', formData, {
197
+ onUploadProgress: (progress) => {
198
+ console.log(`${progress.percent}% uploaded`)
199
+ },
200
+ })
201
+ ```
202
+
203
+ ## API Reference
204
+
205
+ ### createClient(config)
206
+
207
+ Creates a new HTTP client instance.
208
+
209
+ | Option | Type | Description |
210
+ |--------|------|-------------|
211
+ | `baseURL` | `string` | Base URL for all requests |
212
+ | `headers` | `Record<string, string>` | Default headers |
213
+ | `timeout` | `number` | Request timeout in ms |
214
+ | `retry` | `RetryConfig` | Retry configuration |
215
+ | `validateStatus` | `(status: number) => boolean` | Custom status validation |
216
+ | `responseType` | `'json' \| 'text' \| 'blob' \| 'arraybuffer'` | Response type |
217
+
218
+ ### HTTP Methods
219
+
220
+ ```typescript
221
+ api.get<T>(url, options?)
222
+ api.post<T>(url, data?, options?)
223
+ api.put<T>(url, data?, options?)
224
+ api.patch<T>(url, data?, options?)
225
+ api.delete<T>(url, options?)
226
+ api.head<T>(url, options?)
227
+ api.options<T>(url, options?)
228
+ ```
229
+
230
+ ### RetryConfig
231
+
232
+ | Option | Type | Default | Description |
233
+ |--------|------|---------|-------------|
234
+ | `limit` | `number` | - | Max retry attempts |
235
+ | `delay` | `number` | - | Initial delay in ms |
236
+ | `backoff` | `'linear' \| 'exponential'` | `'exponential'` | Backoff strategy |
237
+ | `retryOn` | `number[]` | `[408, 429, 500, 502, 503, 504]` | Status codes to retry |
238
+ | `maxDelay` | `number` | - | Maximum delay cap |
239
+
240
+ ## Browser Support
241
+
242
+ RequestKit works in all modern browsers that support the fetch API:
243
+
244
+ - Chrome 42+
245
+ - Firefox 39+
246
+ - Safari 10.1+
247
+ - Edge 14+
248
+
249
+ For older browsers, you may need a fetch polyfill.
250
+
251
+ ## License
252
+
253
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +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=jt;exports.ContentTypes=pt;exports.abortableDelay=qt;exports.buildURL=se;exports.combineURLs=oe;exports.createClient=me;exports.createError=q;exports.createParamsSerializer=yt;exports.deepClone=E;exports.deepMerge=C;exports.delay=de;exports.getContentType=ae;exports.getHeader=ke;exports.getOrigin=ct;exports.hasHeader=dt;exports.isAbortSignal=et;exports.isAbsoluteURL=J;exports.isArray=y;exports.isArrayBuffer=M;exports.isArrayBufferView=v;exports.isBlob=F;exports.isBoolean=We;exports.isCancel=Ut;exports.isCancelError=te;exports.isClientError=it;exports.isDate=Y;exports.isFile=Ve;exports.isFormData=P;exports.isFunction=A;exports.isHeaders=z;exports.isJSONContentType=Q;exports.isNetworkError=ot;exports.isNullOrUndefined=x;exports.isNumber=Qe;exports.isObject=Xe;exports.isPlainObject=l;exports.isRequest=Ye;exports.isRequestError=m;exports.isResponse=Ze;exports.isSameOrigin=ft;exports.isServerError=at;exports.isStream=N;exports.isString=$;exports.isTextContentType=mt;exports.isTimeoutError=st;exports.isURLSearchParams=D;exports.isUndefined=Ge;exports.mergeHeaders=fe;exports.normalizeHeaders=Ce;exports.objectToFormData=O;exports.objectToURLSearchParams=ie;exports.omit=rt;exports.parseHeaders=lt;exports.parseParams=gt;exports.parseURL=ut;exports.pick=nt;exports.serializeParams=le;exports.shallowMerge=tt;//# sourceMappingURL=index.cjs.map
3
+ //# sourceMappingURL=index.cjs.map