httix-http 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <img src="https://img.shields.io/badge/coverage-100%25-success?style=flat-square" alt="100% Coverage" />
8
8
  </p>
9
9
 
10
- <h1 align="center">httix</h1>
10
+ <h1 align="center">httix-http</h1>
11
11
 
12
12
  <p align="center">
13
13
  <strong>Ultra-lightweight, type-safe, zero-dependency HTTP client built on native Fetch.</strong><br/>
@@ -16,9 +16,9 @@
16
16
 
17
17
  ---
18
18
 
19
- ## Why httix?
19
+ ## Why httix-http?
20
20
 
21
- | Feature | **httix** | axios | got | ky | ofetch |
21
+ | Feature | **httix-http** | axios | got | ky | ofetch |
22
22
  |---|---|---|---|---|---|
23
23
  | Dependencies | **0** | 2 | 11 | 2 | 5 |
24
24
  | Size (min+gzip) | **~5 kB** | ~28 kB | ~67 kB | ~9 kB | ~12 kB |
@@ -84,7 +84,7 @@ console.log(data.id); // created user id
84
84
  ### 3. Create a configured client
85
85
 
86
86
  ```ts
87
- import { createHttix } from 'httix';
87
+ import { createHttix } from 'httix-http';
88
88
 
89
89
  const api = createHttix({
90
90
  baseURL: 'https://api.example.com',
@@ -98,7 +98,7 @@ const { data } = await api.get('/users/me');
98
98
  ### 4. Error handling
99
99
 
100
100
  ```ts
101
- import httix, { HttixResponseError, HttixTimeoutError, HttixAbortError } from 'httix';
101
+ import httix, { HttixResponseError, HttixTimeoutError, HttixAbortError } from 'httix-http';
102
102
 
103
103
  try {
104
104
  const { data } = await httix.get('/users/999');
@@ -117,7 +117,7 @@ try {
117
117
  ### 5. Streaming SSE events
118
118
 
119
119
  ```ts
120
- import httix from 'httix';
120
+ import httix from 'httix-http';
121
121
 
122
122
  for await (const event of httix.stream.sse('/events')) {
123
123
  console.log(`[${event.type}] ${event.data}`);
@@ -136,7 +136,7 @@ for await (const event of httix.stream.sse('/events')) {
136
136
  Create a new client instance with the given configuration. This is the recommended entry-point for creating dedicated API clients.
137
137
 
138
138
  ```ts
139
- import { createHttix } from 'httix';
139
+ import { createHttix } from 'httix-http';
140
140
 
141
141
  const api = createHttix({
142
142
  baseURL: 'https://api.example.com/v2',
@@ -157,7 +157,7 @@ const { data } = await api.get('/users');
157
157
  Create a derived client from the default instance, merging new configuration with the defaults:
158
158
 
159
159
  ```ts
160
- import httix from 'httix';
160
+ import httix from 'httix-http';
161
161
 
162
162
  const adminApi = httix.create({
163
163
  baseURL: 'https://admin.api.example.com',
@@ -170,7 +170,7 @@ const adminApi = httix.create({
170
170
  A pre-configured default instance is exported for convenience:
171
171
 
172
172
  ```ts
173
- import httix from 'httix';
173
+ import httix from 'httix-http';
174
174
 
175
175
  // Use directly
176
176
  await httix.get('/users');
@@ -361,7 +361,7 @@ httix.interceptors.request.clear();
361
361
  Automatic retry with configurable backoff strategies is built-in and enabled by default.
362
362
 
363
363
  ```ts
364
- import { createHttix } from 'httix';
364
+ import { createHttix } from 'httix-http';
365
365
 
366
366
  const client = createHttix({
367
367
  baseURL: 'https://api.example.com',
@@ -452,7 +452,7 @@ try {
452
452
  Stream SSE events as an async iterable:
453
453
 
454
454
  ```ts
455
- import httix from 'httix';
455
+ import httix from 'httix-http';
456
456
 
457
457
  for await (const event of httix.stream.sse('https://api.example.com/events', {
458
458
  headers: { 'Accept': 'text/event-stream' },
@@ -472,7 +472,7 @@ for await (const event of httix.stream.sse('https://api.example.com/events', {
472
472
  Stream newline-delimited JSON objects:
473
473
 
474
474
  ```ts
475
- import httix from 'httix';
475
+ import httix from 'httix-http';
476
476
 
477
477
  interface LogEntry {
478
478
  timestamp: string;
@@ -490,7 +490,7 @@ for await (const entry of httix.stream.ndjson<LogEntry>('/logs/stream')) {
490
490
  Automatically deduplicate identical in-flight requests. When enabled, if multiple calls are made with the same config before the first resolves, they share the same promise.
491
491
 
492
492
  ```ts
493
- import { createHttix } from 'httix';
493
+ import { createHttix } from 'httix-http';
494
494
 
495
495
  const client = createHttix({
496
496
  baseURL: 'https://api.example.com',
@@ -518,7 +518,7 @@ const client2 = createHttix({
518
518
  Client-side rate limiting to avoid overwhelming APIs:
519
519
 
520
520
  ```ts
521
- import { createHttix } from 'httix';
521
+ import { createHttix } from 'httix-http';
522
522
 
523
523
  const client = createHttix({
524
524
  baseURL: 'https://rate-limited-api.example.com',
@@ -542,7 +542,7 @@ const results = await Promise.all([
542
542
  Middleware functions have access to both the request and response, and can modify either:
543
543
 
544
544
  ```ts
545
- import httix, { type MiddlewareFn, type MiddlewareContext } from 'httix';
545
+ import httix, { type MiddlewareFn, type MiddlewareContext } from 'httix-http';
546
546
 
547
547
  // Timing middleware
548
548
  const timingMiddleware: MiddlewareFn = async (ctx, next) => {
@@ -576,7 +576,7 @@ const client = httix.create({
576
576
  #### Bearer Auth
577
577
 
578
578
  ```ts
579
- import { createHttix } from 'httix';
579
+ import { createHttix } from 'httix-http';
580
580
 
581
581
  // Static token
582
582
  const client = createHttix({
@@ -647,7 +647,7 @@ const client2 = createHttix({
647
647
  Automatically fetch all pages of a paginated resource:
648
648
 
649
649
  ```ts
650
- import { createHttix } from 'httix';
650
+ import { createHttix } from 'httix-http';
651
651
 
652
652
  const client = createHttix({ baseURL: 'https://api.example.com' });
653
653
  ```
@@ -761,8 +761,8 @@ const { data: repo } = await httix.get('/repos/:owner/:repo', {
761
761
  Plugins extend httix by registering interceptors and lifecycle hooks. Import them from `httix/plugins`.
762
762
 
763
763
  ```ts
764
- import { loggerPlugin, cachePlugin, mockPlugin } from 'httix/plugins';
765
- import { createHttix } from 'httix';
764
+ import { loggerPlugin, cachePlugin, mockPlugin } from 'httix-http/plugins';
765
+ import { createHttix } from 'httix-http';
766
766
 
767
767
  const client = createHttix({ baseURL: 'https://api.example.com' });
768
768
 
@@ -776,8 +776,8 @@ const logger = loggerPlugin({ level: 'debug' });
776
776
  LRU response cache with configurable TTL, stale-while-revalidate, and size limits:
777
777
 
778
778
  ```ts
779
- import { cachePlugin } from 'httix/plugins';
780
- import { createHttix } from 'httix';
779
+ import { cachePlugin } from 'httix-http/plugins';
780
+ import { createHttix } from 'httix-http';
781
781
 
782
782
  const client = createHttix({ baseURL: 'https://api.example.com' });
783
783
 
@@ -802,8 +802,8 @@ console.log(cache.getStats()); // { size: 12, maxSize: 200, ttl: 300000
802
802
  Structured logging of request/response lifecycle events:
803
803
 
804
804
  ```ts
805
- import { loggerPlugin } from 'httix/plugins';
806
- import { createHttix } from 'httix';
805
+ import { loggerPlugin } from 'httix-http/plugins';
806
+ import { createHttix } from 'httix-http';
807
807
 
808
808
  const client = createHttix({ baseURL: 'https://api.example.com' });
809
809
 
@@ -827,8 +827,8 @@ loggerPlugin({
827
827
  Replace `fetch` with an in-memory mock adapter — perfect for unit tests:
828
828
 
829
829
  ```ts
830
- import { mockPlugin } from 'httix/plugins';
831
- import { createHttix } from 'httix';
830
+ import { mockPlugin } from 'httix-http/plugins';
831
+ import { createHttix } from 'httix-http';
832
832
 
833
833
  const mock = mockPlugin();
834
834
  const client = createHttix({ baseURL: 'https://api.example.com' });
@@ -868,8 +868,8 @@ mock.restore();
868
868
 
869
869
  ```ts
870
870
  import { describe, it, expect, afterEach } from 'vitest';
871
- import { mockPlugin } from 'httix/plugins';
872
- import { createHttix } from 'httix';
871
+ import { mockPlugin } from 'httix-http/plugins';
872
+ import { createHttix } from 'httix-http';
873
873
 
874
874
  describe('Users API', () => {
875
875
  const mock = mockPlugin();
@@ -924,7 +924,7 @@ import {
924
924
  HttixTimeoutError,
925
925
  HttixAbortError,
926
926
  HttixRetryError,
927
- } from 'httix';
927
+ } from 'httix-http';
928
928
 
929
929
  try {
930
930
  await httix.get('/unstable-endpoint');
@@ -999,7 +999,7 @@ const { data: user } = await httix.post<User>('/users', { name: 'Jane' });
999
999
  #### Typing request config
1000
1000
 
1001
1001
  ```ts
1002
- import type { HttixRequestConfig, HttixResponse, RetryConfig } from 'httix';
1002
+ import type { HttixRequestConfig, HttixResponse, RetryConfig } from 'httix-http';
1003
1003
 
1004
1004
  const config: HttixRequestConfig = {
1005
1005
  url: '/users',
@@ -1016,7 +1016,7 @@ const config: HttixRequestConfig = {
1016
1016
  #### Typing middleware
1017
1017
 
1018
1018
  ```ts
1019
- import type { MiddlewareFn, MiddlewareContext, HttixResponse } from 'httix';
1019
+ import type { MiddlewareFn, MiddlewareContext, HttixResponse } from 'httix-http';
1020
1020
 
1021
1021
  const myMiddleware: MiddlewareFn<User, HttixRequestConfig, HttixResponse<User>> = async (
1022
1022
  ctx: MiddlewareContext<HttixRequestConfig, HttixResponse<User>>,
@@ -1034,7 +1034,7 @@ const myMiddleware: MiddlewareFn<User, HttixRequestConfig, HttixResponse<User>>
1034
1034
  #### Typing plugins
1035
1035
 
1036
1036
  ```ts
1037
- import type { HttixPlugin } from 'httix';
1037
+ import type { HttixPlugin } from 'httix-http';
1038
1038
 
1039
1039
  const myPlugin: HttixPlugin = {
1040
1040
  name: 'my-plugin',
@@ -1061,7 +1061,7 @@ import axios from 'axios';
1061
1061
  const { data } = await axios.get('/users');
1062
1062
 
1063
1063
  // httix
1064
- import httix from 'httix';
1064
+ import httix from 'httix-http';
1065
1065
  const { data } = await httix.get('/users');
1066
1066
  ```
1067
1067
 
@@ -1,4 +1,4 @@
1
- "use strict";var V=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var Oe=(r,e)=>{for(var t in e)V(r,t,{get:e[t],enumerable:!0})},Me=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Se(e))!ve.call(r,o)&&o!==t&&V(r,o,{get:()=>e[o],enumerable:!(n=Ae(e,o))||n.enumerable});return r};var De=r=>Me(V({},"__esModule",{value:!0}),r);var Ke={};Oe(Ke,{DEFAULT_CONFIG:()=>M,DEFAULT_HEADERS:()=>S,DEFAULT_REQUEST_CONFIG:()=>ne,DEFAULT_RETRY:()=>d,DEFAULT_TIMEOUT:()=>O,HttixAbortError:()=>p,HttixClientImpl:()=>g,HttixError:()=>x,HttixRequestError:()=>m,HttixResponseError:()=>f,HttixRetryError:()=>D,HttixTimeoutError:()=>C,InterceptorManager:()=>b,RateLimiter:()=>k,RequestDeduplicator:()=>I,applyAuth:()=>w,clearTimeoutController:()=>Ce,composeMiddleware:()=>$,createAuthInterceptor:()=>B,createAuthRefreshHandler:()=>F,createCancelError:()=>Re,createCancelToken:()=>ye,createDeleteMethod:()=>Ee,createGetMethod:()=>Te,createHeadMethod:()=>Pe,createHttix:()=>ge,createOptionsMethod:()=>Ie,createPaginator:()=>Q,createPatchMethod:()=>we,createPostMethod:()=>qe,createProgressReader:()=>pe,createPutMethod:()=>be,createRequestMethod:()=>ke,createTimeoutController:()=>He,default:()=>Ve,isCancel:()=>z,parseLinkHeader:()=>Y,parseNDJSON:()=>G,parseRetryAfter:()=>N,parseSSE:()=>_,retryRequest:()=>L});module.exports=De(Ke);var d={attempts:3,backoff:"exponential",baseDelay:1e3,maxDelay:3e4,jitter:!0,retryOn:[408,429,500,502,503,504],retryOnNetworkError:!0,retryOnSafeMethodsOnly:!1,retryCondition:()=>!0,onRetry:()=>{}},O=3e4,S={Accept:"application/json, text/plain, */*","Accept-Encoding":"gzip, deflate, br","Accept-Language":"*"},ne={method:"GET",timeout:O,throwOnError:!0,credentials:"same-origin",mode:"cors",redirect:"follow",cache:"default"},M={url:"",baseURL:"",headers:S,timeout:O,throwOnError:!0,credentials:"same-origin",mode:"cors",redirect:"follow",cache:"default",retry:d,dedup:!1};var x=class extends Error{name="HttixError";config;cause;constructor(e,t){super(e),this.name="HttixError",this.config=t?.config,this.cause=t?.cause,Object.setPrototypeOf(this,new.target.prototype);let n=Error;n.captureStackTrace&&n.captureStackTrace(this,this.constructor)}},m=class extends x{name="HttixRequestError";constructor(e,t){super(e,t),this.name="HttixRequestError"}},f=class extends x{name="HttixResponseError";status;statusText;data;headers;config;constructor(e,t,n,o,s){let i=`Request failed with status ${e}: ${t}`;super(i,{message:i,config:s}),this.name="HttixResponseError",this.status=e,this.statusText=t,this.data=n,this.headers=o,this.config=s}},C=class extends x{name="HttixTimeoutError";timeout;constructor(e,t){let n=`Request timed out after ${e}ms`;super(n,{message:n,config:t}),this.name="HttixTimeoutError",this.timeout=e}},p=class extends x{name="HttixAbortError";reason;constructor(e,t){let n=e??"Request was aborted";super(n,{message:n,config:t}),this.name="HttixAbortError",this.reason=n}},D=class extends x{name="HttixRetryError";attempts;lastError;constructor(e,t,n){let o=`Request failed after ${e} attempt${e===1?"":"s"}`;super(o,{message:o,config:n,cause:t}),this.name="HttixRetryError",this.attempts=e,this.lastError=t}};function j(r){let e=Ue(r.baseURL,r.url,r.params,r.query),t=Le(S,r.headers),n=$e(r.body,t),s={method:r.method??"GET",headers:t,body:n,credentials:r.credentials,mode:r.mode,cache:r.cache,redirect:r.redirect,referrerPolicy:r.referrerPolicy},i=r.timeout??0,a,u;return i>0?(a=new AbortController,u=setTimeout(()=>{a.abort(new DOMException(`Request timed out after ${i}ms`,"TimeoutError"))},i),r.signal?s.signal=je(r.signal,a.signal):s.signal=a.signal):r.signal&&(s.signal=r.signal),{request:new globalThis.Request(e,s),timeoutController:a,timeoutId:u}}function q(r,e){e!==void 0&&clearTimeout(e),r&&r.abort()}function je(...r){let e=new AbortController;for(let t of r){if(t.aborted){e.abort(t.reason);break}t.addEventListener("abort",()=>e.abort(t.reason),{once:!0})}return e.signal}function Ue(r,e,t,n){let o=e;if(r){let s=r.endsWith("/")?r.slice(0,-1):r,i=o.startsWith("/")?o:`/${o}`;o=`${s}${i}`}if(t)for(let[s,i]of Object.entries(t))o=o.replace(`:${s}`,encodeURIComponent(String(i)));if(n&&Object.keys(n).length>0){let s=o.includes("?")?"&":"?";o+=`${s}${Ne(n)}`}return o}function Ne(r){let e=[];for(let[t,n]of Object.entries(r))if(n!=null)if(Array.isArray(n))for(let o of n)o!=null&&e.push(`${encodeURIComponent(t)}=${encodeURIComponent(String(o))}`);else e.push(`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`);return e.join("&")}function Le(r,e){let t=new Headers;return oe(t,r),e&&oe(t,e),t}function oe(r,e){if(e instanceof Headers)e.forEach((t,n)=>{r.set(n,t)});else for(let[t,n]of Object.entries(e))n!==void 0&&r.set(t,n)}function $e(r,e){if(r!=null){if(typeof r=="string"||r instanceof FormData||r instanceof URLSearchParams||r instanceof Blob||r instanceof ArrayBuffer||r instanceof ReadableStream)return r;if(typeof r=="object"||typeof r=="number"||typeof r=="boolean")return e.has("Content-Type")||e.set("Content-Type","application/json"),JSON.stringify(r)}}function se(r,e,t,n){return{data:t,status:r.status,statusText:r.statusText,headers:r.headers,ok:r.ok,raw:r,timing:n,config:e}}async function ie(r,e){if(typeof e.parseResponse=="function")return await e.parseResponse(r);if(r.status===204)return;let t=r.headers.get("Content-Type")??"";return e.responseType?Be(r,e.responseType):Fe(r,t)}async function Be(r,e){switch(e){case"json":try{return await r.json()}catch{return}case"text":try{return await r.text()}catch{return}case"blob":try{return await r.blob()}catch{return}case"arrayBuffer":try{return await r.arrayBuffer()}catch{return}}}async function Fe(r,e){let t=e.toLowerCase();if(t.includes("application/json"))try{return await r.json()}catch{return}if(t.includes("text/"))try{return await r.text()}catch{return}if(r.body)try{let n=await r.text();if(!n)return;try{return JSON.parse(n)}catch{return n}}catch{return}}var b=class{handlers=[];use(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1}eject(e){e>=0&&e<this.handlers.length&&(this.handlers[e]=null)}clear(){this.handlers=[]}};async function U(r,e){let t=r;for(let n of e.handlers)if(n!==null)try{t=await n.fulfilled(t)}catch(o){if(n.rejected)try{let s=await n.rejected(o);s!==void 0&&(t=s)}catch{throw o}else throw o}return t}async function ae(r,e){let t=r;for(let n of e.handlers)if(n!==null)try{t=await n.fulfilled(t)}catch(o){if(n.rejected)try{let s=await n.rejected(o);s!==void 0&&(t=s)}catch{throw o}else throw o}return t}async function ue(r,e){for(let t of e.handlers)if(t!==null&&t.rejected)try{let n=await t.rejected(r);if(n!=null)return n}catch{continue}throw r}function K(r){return new Promise(e=>setTimeout(e,r))}function ce(){return`req_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function W(r,e,t,n,o){let s;switch(e){case"fixed":s=t;break;case"linear":s=t*r;break;case"exponential":s=t*Math.pow(2,r-1);break;default:s=t;break}return s=Math.min(s,n),o&&(s=s*(.5+Math.random()*.5)),Math.max(0,s)}var Qe=new Set(["GET","HEAD","OPTIONS"]);function N(r){if(r===null)return null;let e=Number(r);if(!Number.isNaN(e)&&e>0&&String(e)===r.trim())return e*1e3;let t=Date.parse(r);if(!Number.isNaN(t)){let n=t-Date.now();return n>0?n:0}return null}async function L(r,e,t){if(e===!1||e===void 0)return r();let n={attempts:e.attempts??d.attempts,backoff:e.backoff??d.backoff,baseDelay:e.baseDelay??d.baseDelay,maxDelay:e.maxDelay??d.maxDelay,jitter:e.jitter??d.jitter,retryOn:e.retryOn??d.retryOn,retryOnNetworkError:e.retryOnNetworkError??d.retryOnNetworkError,retryOnSafeMethodsOnly:e.retryOnSafeMethodsOnly??d.retryOnSafeMethodsOnly,retryCondition:e.retryCondition??d.retryCondition,onRetry:e.onRetry??d.onRetry},o=n.attempts,s=(t.method??"GET").toUpperCase(),i;for(let a=0;a<o;a++)try{let u=await r();if(u.status>=200&&u.status<300||!n.retryOn.includes(u.status))return u;let c=new f(u.status,u.statusText,u.data,u.headers,t);if(i=c,!le(c,a,o,n,s))throw c;let h=N(u.headers.get("retry-after")),y=W(a+1,n.backoff,n.baseDelay,n.maxDelay,n.jitter),R=h!==null?h:y;n.onRetry(a+1,c,R),await K(R)}catch(u){if(i=u,!le(u,a,o,n,s))throw u;let c=u,h=c instanceof f?N(c.headers?.get("retry-after")??null):null,y=W(a+1,n.backoff,n.baseDelay,n.maxDelay,n.jitter),R=h!==null?h:y;n.onRetry(a+1,c,R),await K(R)}throw i||new Error("All retry attempts exhausted")}function le(r,e,t,n,o){return e+1>=t||n.retryOnSafeMethodsOnly&&!Qe.has(o)||!n.retryCondition(r)?!1:r instanceof m?n.retryOnNetworkError:r instanceof f?n.retryOn.includes(r.status):!1}var I=class{inflight=new Map;cache=new Map;ttl;constructor(e=0){this.ttl=e}async dedup(e,t){if(this.ttl>0){let s=this.cache.get(e);if(s&&Date.now()-s.timestamp<this.ttl)return s.data}let n=this.inflight.get(e);if(n)return n;let o=t().then(s=>(this.ttl>0&&this.cache.set(e,{data:s,timestamp:Date.now()}),this.inflight.delete(e),s)).catch(s=>{throw this.inflight.delete(e),s});return this.inflight.set(e,o),o}generateKey(e){let t=new URL(e.url,e.baseURL),n=e.query?Object.keys(e.query).sort().map(o=>`${o}=${String(e.query[o])}`).join("&"):"";return`${e.method||"GET"}:${t.origin}${t.pathname}${n?"?"+n:""}`}clear(){this.inflight.clear(),this.cache.clear()}};var k=class{constructor(e,t){this.maxRequests=e;this.interval=t}maxRequests;interval;queues=new Map;activeCounts=new Map;timers=new Map;async throttle(e,t){this.timers.has(e)||this.activeCounts.set(e,0);let n=this.activeCounts.get(e)||0;return n<this.maxRequests?(this.activeCounts.set(e,n+1),n===0&&this.timers.set(e,setTimeout(()=>{this.activeCounts.set(e,0),this.timers.delete(e),this.drainQueue(e)},this.interval)),t()):new Promise(o=>{this.queues.has(e)||this.queues.set(e,[]),this.queues.get(e).push({execute:async()=>{let s=await t();o(s)},resolve:()=>{}})})}drainQueue(e){let t=this.queues.get(e);if(!t||t.length===0)return;let n=t.splice(0,this.maxRequests);this.activeCounts.set(e,n.length),this.timers.set(e,setTimeout(()=>{this.activeCounts.set(e,0),this.timers.delete(e),this.drainQueue(e)},this.interval));for(let o of n)o.execute()}clear(){for(let e of this.timers.values())clearTimeout(e);this.queues.clear(),this.activeCounts.clear(),this.timers.clear()}getQueueSize(e){return this.queues.get(e)?.length||0}};function $(r){return function(t,n){let o=-1;async function s(i){if(i<=o)throw new Error("next() called multiple times");o=i;let a=r[i];if(!a)return n();await a(t,()=>s(i+1))}return s(0)}}async function fe(r){return typeof r=="function"?r():r}function _e(r){return{...r}}async function w(r,e){let t=_e(r),n={};t.headers&&(t.headers instanceof Headers?t.headers.forEach((s,i)=>{n[i]=s}):Object.assign(n,t.headers)),t.headers=n;let o={...t.query};switch(e.type){case"bearer":{let s=await fe(e.token);n.Authorization=`Bearer ${s}`;break}case"basic":{let s=`${e.username}:${e.password}`,i=btoa(s);n.Authorization=`Basic ${i}`;break}case"apiKey":{let s=await fe(e.value);e.in==="header"?n[e.key]=s:o[e.key]=s;break}}return(Object.keys(o).length>Object.keys(t.query??{}).length||e.type==="apiKey"&&e.in==="query")&&(t.query=o),t}function B(r){return async e=>w(e,r)}function F(r){if(!r.refreshToken)return t=>{};let e=null;return(async t=>{if(!(t instanceof f)||t.status!==401)return;let n=t.config;if(!n)return;e||(e=r.refreshToken().then(a=>(r.onTokenRefresh&&r.onTokenRefresh(a),typeof r.token=="string"&&(r.token=a),e=null,a)).catch(a=>{throw e=null,a}));let o;try{o=await e}catch{throw t}let s=await w(n,r),i={};s.headers&&Object.assign(i,s.headers),i.Authorization=`Bearer ${o}`,s.headers=i})}function Y(r){let e={};if(!r)return e;let t=r.split(",");for(let n of t){let o=n.trim(),s=o.match(/<([^>]+)>/);if(!s)continue;let i=s[1];if(i===void 0)continue;let a=o.match(/rel\s*=\s*"([^"]+)"/);if(!a)continue;let u=a[1];e[u]=i}return e}function Q(r){return async function*(t,n){let o=n?.pagination;if(!o)return;let{style:s,pageSize:i=20,maxPages:a=1/0,offsetParam:u="offset",limitParam:c="limit",cursorParam:h="cursor",cursorExtractor:y,linkExtractor:R,dataExtractor:Z,stopCondition:ee}=o,E=t,te=0,v,J=0;for(;E&&J<a;){let P={...n};s==="offset"?P.query={...P.query,[u]:te,[c]:i}:s==="cursor"&&(P.query={...P.query,[h]:v});let H;s==="link"&&J>0?H=await r.request({url:E,...P}):H=await r.request({url:E,...P}),J++;let T;if(Z?T=Z(H.data):T=H.data??[],ee&&ee(H.data)){T.length>0&&(yield T);return}if(T.length===0)return;switch(yield T,s){case"offset":{if(T.length<i)return;te+=i;break}case"cursor":{if(y?v=y(H.data):v=null,!v)return;break}case"link":{if(R)E=R(H.headers)??null;else{let re=H.headers.get("link");re?E=Y(re).next??null:E=null}break}}}}}async function*_(r){let e=r.getReader(),t=new TextDecoder,n="";try{for(;;){let{done:o,value:s}=await e.read();if(o)break;n+=t.decode(s,{stream:!0});let i=n.split(`
1
+ "use strict";var V=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var Oe=(r,e)=>{for(var t in e)V(r,t,{get:e[t],enumerable:!0})},Me=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Se(e))!ve.call(r,o)&&o!==t&&V(r,o,{get:()=>e[o],enumerable:!(n=Ae(e,o))||n.enumerable});return r};var De=r=>Me(V({},"__esModule",{value:!0}),r);var Ke={};Oe(Ke,{DEFAULT_CONFIG:()=>M,DEFAULT_HEADERS:()=>S,DEFAULT_REQUEST_CONFIG:()=>ne,DEFAULT_RETRY:()=>d,DEFAULT_TIMEOUT:()=>O,HttixAbortError:()=>p,HttixClientImpl:()=>g,HttixError:()=>x,HttixRequestError:()=>m,HttixResponseError:()=>f,HttixRetryError:()=>D,HttixTimeoutError:()=>C,InterceptorManager:()=>b,RateLimiter:()=>k,RequestDeduplicator:()=>I,applyAuth:()=>w,clearTimeoutController:()=>Ce,composeMiddleware:()=>$,createAuthInterceptor:()=>B,createAuthRefreshHandler:()=>F,createCancelError:()=>Re,createCancelToken:()=>ye,createDeleteMethod:()=>Ee,createGetMethod:()=>Te,createHeadMethod:()=>Pe,createHttix:()=>ge,createOptionsMethod:()=>Ie,createPaginator:()=>Q,createPatchMethod:()=>we,createPostMethod:()=>qe,createProgressReader:()=>pe,createPutMethod:()=>be,createRequestMethod:()=>ke,createTimeoutController:()=>He,default:()=>Ve,isCancel:()=>z,parseLinkHeader:()=>Y,parseNDJSON:()=>G,parseRetryAfter:()=>N,parseSSE:()=>_,retryRequest:()=>L});module.exports=De(Ke);var d={attempts:3,backoff:"exponential",baseDelay:1e3,maxDelay:3e4,jitter:!0,retryOn:[408,429,500,502,503,504],retryOnNetworkError:!0,retryOnSafeMethodsOnly:!1,retryCondition:()=>!0,onRetry:()=>{}},O=3e4,S={Accept:"application/json, text/plain, */*","Accept-Encoding":"gzip, deflate, br","Accept-Language":"*"},ne={method:"GET",timeout:O,throwOnError:!0,credentials:"same-origin",mode:"cors",redirect:"follow",cache:"default"},M={url:"",baseURL:"",headers:S,timeout:O,throwOnError:!0,credentials:"same-origin",mode:"cors",redirect:"follow",cache:"default",retry:d,dedup:!1};var x=class extends Error{name="HttixError";config;cause;constructor(e,t){super(e),this.name="HttixError",this.config=t?.config,this.cause=t?.cause,Object.setPrototypeOf(this,new.target.prototype);let n=Error;n.captureStackTrace&&n.captureStackTrace(this,this.constructor)}},m=class extends x{name="HttixRequestError";constructor(e,t){super(e,t),this.name="HttixRequestError"}},f=class extends x{name="HttixResponseError";status;statusText;data;headers;config;constructor(e,t,n,o,s){let i=`Request failed with status ${e}: ${t}`;super(i,{message:i,config:s}),this.name="HttixResponseError",this.status=e,this.statusText=t,this.data=n,this.headers=o,this.config=s}},C=class extends x{name="HttixTimeoutError";timeout;constructor(e,t){let n=`Request timed out after ${e}ms`;super(n,{message:n,config:t}),this.name="HttixTimeoutError",this.timeout=e}},p=class extends x{name="HttixAbortError";reason;constructor(e,t){let n=e??"Request was aborted";super(n,{message:n,config:t}),this.name="HttixAbortError",this.reason=n}},D=class extends x{name="HttixRetryError";attempts;lastError;constructor(e,t,n){let o=`Request failed after ${e} attempt${e===1?"":"s"}`;super(o,{message:o,config:n,cause:t}),this.name="HttixRetryError",this.attempts=e,this.lastError=t}};function j(r){let e=Ue(r.baseURL,r.url,r.params,r.query),t=Le(S,r.headers),n=$e(r.body,t),s={method:r.method??"GET",headers:t,body:n,credentials:r.credentials,mode:r.mode,cache:r.cache,redirect:r.redirect,referrerPolicy:r.referrerPolicy},i=r.timeout??0,a,u;return i>0?(a=new AbortController,u=setTimeout(()=>{a.abort(new DOMException(`Request timed out after ${i}ms`,"TimeoutError"))},i),r.signal?s.signal=je(r.signal,a.signal):s.signal=a.signal):r.signal&&(s.signal=r.signal),{request:new globalThis.Request(e,s),timeoutController:a,timeoutId:u}}function q(r,e){e!==void 0&&clearTimeout(e)}function je(...r){let e=new AbortController;for(let t of r){if(t.aborted){e.abort(t.reason);break}t.addEventListener("abort",()=>e.abort(t.reason),{once:!0})}return e.signal}function Ue(r,e,t,n){let o=e;if(r){let s=r.endsWith("/")?r.slice(0,-1):r,i=o.startsWith("/")?o:`/${o}`;o=`${s}${i}`}if(t)for(let[s,i]of Object.entries(t))o=o.replace(`:${s}`,encodeURIComponent(String(i)));if(n&&Object.keys(n).length>0){let s=o.includes("?")?"&":"?";o+=`${s}${Ne(n)}`}return o}function Ne(r){let e=[];for(let[t,n]of Object.entries(r))if(n!=null)if(Array.isArray(n))for(let o of n)o!=null&&e.push(`${encodeURIComponent(t)}=${encodeURIComponent(String(o))}`);else e.push(`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`);return e.join("&")}function Le(r,e){let t=new Headers;return oe(t,r),e&&oe(t,e),t}function oe(r,e){if(e instanceof Headers)e.forEach((t,n)=>{r.set(n,t)});else for(let[t,n]of Object.entries(e))n!==void 0&&r.set(t,n)}function $e(r,e){if(r!=null){if(typeof r=="string"||r instanceof FormData||r instanceof URLSearchParams||r instanceof Blob||r instanceof ArrayBuffer||r instanceof ReadableStream)return r;if(typeof r=="object"||typeof r=="number"||typeof r=="boolean")return e.has("Content-Type")||e.set("Content-Type","application/json"),JSON.stringify(r)}}function se(r,e,t,n){return{data:t,status:r.status,statusText:r.statusText,headers:r.headers,ok:r.ok,raw:r,timing:n,config:e}}async function ie(r,e){if(typeof e.parseResponse=="function")return await e.parseResponse(r);if(r.status===204)return;let t=r.headers.get("Content-Type")??"";return e.responseType?Be(r,e.responseType):Fe(r,t)}async function Be(r,e){switch(e){case"json":try{return await r.json()}catch{return}case"text":try{return await r.text()}catch{return}case"blob":try{return await r.blob()}catch{return}case"arrayBuffer":try{return await r.arrayBuffer()}catch{return}}}async function Fe(r,e){let t=e.toLowerCase();if(t.includes("application/json"))try{return await r.json()}catch{return}if(t.includes("text/"))try{return await r.text()}catch{return}if(r.body)try{let n=await r.text();if(!n)return;try{return JSON.parse(n)}catch{return n}}catch{return}}var b=class{handlers=[];use(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1}eject(e){e>=0&&e<this.handlers.length&&(this.handlers[e]=null)}clear(){this.handlers=[]}};async function U(r,e){let t=r;for(let n of e.handlers)if(n!==null)try{t=await n.fulfilled(t)}catch(o){if(n.rejected)try{let s=await n.rejected(o);s!==void 0&&(t=s)}catch{throw o}else throw o}return t}async function ae(r,e){let t=r;for(let n of e.handlers)if(n!==null)try{t=await n.fulfilled(t)}catch(o){if(n.rejected)try{let s=await n.rejected(o);s!==void 0&&(t=s)}catch{throw o}else throw o}return t}async function ue(r,e){for(let t of e.handlers)if(t!==null&&t.rejected)try{let n=await t.rejected(r);if(n!=null)return n}catch{continue}throw r}function K(r){return new Promise(e=>setTimeout(e,r))}function ce(){return`req_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function W(r,e,t,n,o){let s;switch(e){case"fixed":s=t;break;case"linear":s=t*r;break;case"exponential":s=t*Math.pow(2,r-1);break;default:s=t;break}return s=Math.min(s,n),o&&(s=s*(.5+Math.random()*.5)),Math.max(0,s)}var Qe=new Set(["GET","HEAD","OPTIONS"]);function N(r){if(r===null)return null;let e=Number(r);if(!Number.isNaN(e)&&e>0&&String(e)===r.trim())return e*1e3;let t=Date.parse(r);if(!Number.isNaN(t)){let n=t-Date.now();return n>0?n:0}return null}async function L(r,e,t){if(e===!1||e===void 0)return r();let n={attempts:e.attempts??d.attempts,backoff:e.backoff??d.backoff,baseDelay:e.baseDelay??d.baseDelay,maxDelay:e.maxDelay??d.maxDelay,jitter:e.jitter??d.jitter,retryOn:e.retryOn??d.retryOn,retryOnNetworkError:e.retryOnNetworkError??d.retryOnNetworkError,retryOnSafeMethodsOnly:e.retryOnSafeMethodsOnly??d.retryOnSafeMethodsOnly,retryCondition:e.retryCondition??d.retryCondition,onRetry:e.onRetry??d.onRetry},o=n.attempts,s=(t.method??"GET").toUpperCase(),i;for(let a=0;a<o;a++)try{let u=await r();if(u.status>=200&&u.status<300||!n.retryOn.includes(u.status))return u;let c=new f(u.status,u.statusText,u.data,u.headers,t);if(i=c,!le(c,a,o,n,s))throw c;let h=N(u.headers.get("retry-after")),y=W(a+1,n.backoff,n.baseDelay,n.maxDelay,n.jitter),R=h!==null?h:y;n.onRetry(a+1,c,R),await K(R)}catch(u){if(i=u,!le(u,a,o,n,s))throw u;let c=u,h=c instanceof f?N(c.headers?.get("retry-after")??null):null,y=W(a+1,n.backoff,n.baseDelay,n.maxDelay,n.jitter),R=h!==null?h:y;n.onRetry(a+1,c,R),await K(R)}throw i||new Error("All retry attempts exhausted")}function le(r,e,t,n,o){return e+1>=t||n.retryOnSafeMethodsOnly&&!Qe.has(o)||!n.retryCondition(r)?!1:r instanceof m?n.retryOnNetworkError:r instanceof f?n.retryOn.includes(r.status):!1}var I=class{inflight=new Map;cache=new Map;ttl;constructor(e=0){this.ttl=e}async dedup(e,t){if(this.ttl>0){let s=this.cache.get(e);if(s&&Date.now()-s.timestamp<this.ttl)return s.data}let n=this.inflight.get(e);if(n)return n;let o=t().then(s=>(this.ttl>0&&this.cache.set(e,{data:s,timestamp:Date.now()}),this.inflight.delete(e),s)).catch(s=>{throw this.inflight.delete(e),s});return this.inflight.set(e,o),o}generateKey(e){let t=new URL(e.url,e.baseURL),n=e.query?Object.keys(e.query).sort().map(o=>`${o}=${String(e.query[o])}`).join("&"):"";return`${e.method||"GET"}:${t.origin}${t.pathname}${n?"?"+n:""}`}clear(){this.inflight.clear(),this.cache.clear()}};var k=class{constructor(e,t){this.maxRequests=e;this.interval=t}maxRequests;interval;queues=new Map;activeCounts=new Map;timers=new Map;async throttle(e,t){this.timers.has(e)||this.activeCounts.set(e,0);let n=this.activeCounts.get(e)||0;return n<this.maxRequests?(this.activeCounts.set(e,n+1),n===0&&this.timers.set(e,setTimeout(()=>{this.activeCounts.set(e,0),this.timers.delete(e),this.drainQueue(e)},this.interval)),t()):new Promise(o=>{this.queues.has(e)||this.queues.set(e,[]),this.queues.get(e).push({execute:async()=>{let s=await t();o(s)},resolve:()=>{}})})}drainQueue(e){let t=this.queues.get(e);if(!t||t.length===0)return;let n=t.splice(0,this.maxRequests);this.activeCounts.set(e,n.length),this.timers.set(e,setTimeout(()=>{this.activeCounts.set(e,0),this.timers.delete(e),this.drainQueue(e)},this.interval));for(let o of n)o.execute()}clear(){for(let e of this.timers.values())clearTimeout(e);this.queues.clear(),this.activeCounts.clear(),this.timers.clear()}getQueueSize(e){return this.queues.get(e)?.length||0}};function $(r){return function(t,n){let o=-1;async function s(i){if(i<=o)throw new Error("next() called multiple times");o=i;let a=r[i];if(!a)return n();await a(t,()=>s(i+1))}return s(0)}}async function fe(r){return typeof r=="function"?r():r}function _e(r){return{...r}}async function w(r,e){let t=_e(r),n={};t.headers&&(t.headers instanceof Headers?t.headers.forEach((s,i)=>{n[i]=s}):Object.assign(n,t.headers)),t.headers=n;let o={...t.query};switch(e.type){case"bearer":{let s=await fe(e.token);n.Authorization=`Bearer ${s}`;break}case"basic":{let s=`${e.username}:${e.password}`,i=btoa(s);n.Authorization=`Basic ${i}`;break}case"apiKey":{let s=await fe(e.value);e.in==="header"?n[e.key]=s:o[e.key]=s;break}}return(Object.keys(o).length>Object.keys(t.query??{}).length||e.type==="apiKey"&&e.in==="query")&&(t.query=o),t}function B(r){return async e=>w(e,r)}function F(r){if(!r.refreshToken)return t=>{};let e=null;return(async t=>{if(!(t instanceof f)||t.status!==401)return;let n=t.config;if(!n)return;e||(e=r.refreshToken().then(a=>(r.onTokenRefresh&&r.onTokenRefresh(a),typeof r.token=="string"&&(r.token=a),e=null,a)).catch(a=>{throw e=null,a}));let o;try{o=await e}catch{throw t}let s=await w(n,r),i={};s.headers&&Object.assign(i,s.headers),i.Authorization=`Bearer ${o}`,s.headers=i})}function Y(r){let e={};if(!r)return e;let t=r.split(",");for(let n of t){let o=n.trim(),s=o.match(/<([^>]+)>/);if(!s)continue;let i=s[1];if(i===void 0)continue;let a=o.match(/rel\s*=\s*"([^"]+)"/);if(!a)continue;let u=a[1];e[u]=i}return e}function Q(r){return async function*(t,n){let o=n?.pagination;if(!o)return;let{style:s,pageSize:i=20,maxPages:a=1/0,offsetParam:u="offset",limitParam:c="limit",cursorParam:h="cursor",cursorExtractor:y,linkExtractor:R,dataExtractor:Z,stopCondition:ee}=o,E=t,te=0,v,J=0;for(;E&&J<a;){let P={...n};s==="offset"?P.query={...P.query,[u]:te,[c]:i}:s==="cursor"&&(P.query={...P.query,[h]:v});let H;s==="link"&&J>0?H=await r.request({url:E,...P}):H=await r.request({url:E,...P}),J++;let T;if(Z?T=Z(H.data):T=H.data??[],ee&&ee(H.data)){T.length>0&&(yield T);return}if(T.length===0)return;switch(yield T,s){case"offset":{if(T.length<i)return;te+=i;break}case"cursor":{if(y?v=y(H.data):v=null,!v)return;break}case"link":{if(R)E=R(H.headers)??null;else{let re=H.headers.get("link");re?E=Y(re).next??null:E=null}break}}}}}async function*_(r){let e=r.getReader(),t=new TextDecoder,n="";try{for(;;){let{done:o,value:s}=await e.read();if(o)break;n+=t.decode(s,{stream:!0});let i=n.split(`
2
2
 
3
3
  `);n=i.pop();for(let a of i){let u=de(a);u!==null&&(yield u)}}if(n.trim().length>0){let o=de(n);o!==null&&(yield o)}}finally{e.releaseLock()}}function de(r){let e=r.split(`
4
4
  `),t={},n=[];for(let o of e){if(o===""||o.startsWith(":"))continue;let s=o.indexOf(":");if(s===-1){o.trim()==="data"&&n.push("");continue}let i=o.slice(0,s).trim(),a=o.slice(s+1);switch(a.startsWith(" ")&&(a=a.slice(1)),i){case"event":t.type=a;break;case"data":n.push(a);break;case"id":t.id=a;break;case"retry":t.retry=parseInt(a,10);break}}return n.length===0?null:{type:t.type??"message",data:n.join(`