var e=class{statusCode;reason;headers;body;constructor(e){this.statusCode=e.statusCode,this.reason=e.reason,this.headers=e.headers||{},this.body=e.body}static isInstance(e){if(!e)return!1;let t=e;return typeof t.statusCode==`number`&&typeof t.headers==`object`}},t=e=>encodeURIComponent(e).replace(/[!'()*]/g,n),n=e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`;function r(e){let n=[];for(let r of Object.keys(e).sort()){let i=e[r];if(r=t(r),Array.isArray(i))for(let e=0,a=i.length;e<a;e++)n.push(`${r}=${t(i[e])}`);else{let e=r;(i||typeof i==`string`)&&(e+=`=${t(i)}`),n.push(e)}}return n.join(`&`)}function i(e,t){return new Request(e,t)}function a(e=0){return new Promise((t,n)=>{e&&setTimeout(()=>{let t=Error(`Request did not complete within ${e} ms`);t.name=`TimeoutError`,n(t)},e)})}var o={supported:void 0},s=class t{config;configProvider;static create(e){return typeof e?.handle==`function`?e:new t(e)}constructor(e){typeof e==`function`?this.configProvider=e().then(e=>e||{}):(this.config=e??{},this.configProvider=Promise.resolve(this.config)),o.supported===void 0&&(o.supported=typeof Request<`u`&&`keepalive`in i(`https://[::1]`))}destroy(){}async handle(t,{abortSignal:n,requestTimeout:s}={}){this.config||=await this.configProvider;let l=s??this.config.requestTimeout,u=this.config.keepAlive===!0,d=this.config.credentials;if(n?.aborted){let e=c(n);return Promise.reject(e)}let f=t.path,p=r(t.query||{});p&&(f+=`?${p}`),t.fragment&&(f+=`#${t.fragment}`);let m=``;(t.username!=null||t.password!=null)&&(m=`${t.username??``}:${t.password??``}@`);let{port:h,method:g}=t,_=`${t.protocol}//${m}${t.hostname}${h?`:${h}`:``}${f}`,v=g===`GET`||g===`HEAD`?void 0:t.body,y={body:v,headers:new Headers(t.headers),method:g,credentials:d};this.config?.cache&&(y.cache=this.config.cache),v&&(y.duplex=`half`),typeof AbortController<`u`&&(y.signal=n),o.supported&&(y.keepalive=u),typeof this.config.requestInit==`function`&&Object.assign(y,this.config.requestInit(t));let b=()=>{},x=i(_,y),S=[fetch(x).then(t=>{let n=t.headers,r={};for(let e of n.entries())r[e[0]]=e[1];return t.body==null?t.blob().then(n=>({response:new e({headers:r,reason:t.statusText,statusCode:t.status,body:n})})):{response:new e({headers:r,reason:t.statusText,statusCode:t.status,body:t.body})}}),a(l)];return n&&S.push(new Promise((e,t)=>{let r=()=>{t(c(n))};if(typeof n.addEventListener==`function`){let e=n;e.addEventListener(`abort`,r,{once:!0}),b=()=>e.removeEventListener(`abort`,r)}else n.onabort=r})),Promise.race(S).finally(b)}updateHttpClientConfig(e,t){this.config=void 0,this.configProvider=this.configProvider.then(n=>(n[e]=t,n))}httpHandlerConfigs(){return this.config??{}}};function c(e){let t=e&&typeof e==`object`&&`reason`in e?e.reason:void 0;if(t){if(t instanceof Error){let e=Error(`Request aborted`);return e.name=`AbortError`,e.cause=t,e}let e=Error(String(t));return e.name=`AbortError`,e}let n=Error(`Request aborted`);return n.name=`AbortError`,n}export{t as n,e as r,s as t};