@hyper-fetch/core 4.0.0 → 4.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/dist/browser/index.cjs.js +1 -1
- package/dist/browser/index.cjs.js.map +3 -3
- package/dist/browser/index.esm.js +1 -1
- package/dist/browser/index.esm.js.map +3 -3
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +3 -3
- package/package.json +1 -1
- package/src/adapter/adapter.browser.ts +2 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Dt=Object.defineProperty,Qt=Object.defineProperties;var Lt=Object.getOwnPropertyDescriptors;var ge=Object.getOwnPropertySymbols;var Je=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable;var Ne=(s,e,t)=>e in s?Dt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,$=(s,e)=>{for(var t in e||(e={}))Je.call(e,t)&&Ne(s,t,e[t]);if(ge)for(var t of ge(e))et.call(e,t)&&Ne(s,t,e[t]);return s},W=(s,e)=>Qt(s,Lt(e));var tt=(s,e)=>{var t={};for(var r in s)Je.call(s,r)&&e.indexOf(r)<0&&(t[r]=s[r]);if(s!=null&&ge)for(var r of ge(s))e.indexOf(r)<0&&et.call(s,r)&&(t[r]=s[r]);return t};var l=(s,e,t)=>new Promise((r,n)=>{var o=i=>{try{d(t.next(i))}catch(u){n(u)}},a=i=>{try{d(t.throw(i))}catch(u){n(u)}},d=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,a);d((t=t.apply(s,e)).next())});var rt=class{constructor(e){this.config=e;this.getEffectKey=()=>this.config.effectKey;this.onTrigger=e=>{var t,r;(r=(t=this.config).onTrigger)==null||r.call(t,e)};this.onStart=e=>{var t,r;(r=(t=this.config).onStart)==null||r.call(t,e)};this.onSuccess=(e,t)=>{var r,n;(n=(r=this.config).onSuccess)==null||n.call(r,e,t)};this.onError=(e,t)=>{var r,n;(n=(r=this.config).onError)==null||n.call(r,e,t)};this.onFinished=(e,t)=>{var r,n;(n=(r=this.config).onFinished)==null||n.call(r,e,t)}}};var je=(u=>(u[u.second=1e3]="second",u[u.minute=6e4]="minute",u[u.hour=36e5]="hour",u[u.day=864e5]="day",u[u.week=6048e5]="week",u[u.month30=2592e6]="month30",u[u.month31=26784e5]="month31",u[u.year=31536e6]="year",u[u.yearLeap=316224e5]="yearLeap",u))(je||{});var ye=1e3*5;var st=(s,e)=>l(void 0,null,function*(){let{makeRequest:t,fullUrl:r,config:n,headers:o,onError:a,onResponseEnd:d,onTimeoutError:i,onRequestEnd:u,createAbortListener:x,onResponseProgress:h,onRequestProgress:A,onResponseStart:c,onBeforeRequest:b,onRequestStart:y,onSuccess:f}=yield he(s,e,0,{headers:{}}),{method:D="GET"}=s;return t(T=>{let R=new XMLHttpRequest;R.timeout=ye;let Q=()=>R.abort();Object.entries(n).forEach(([g,E])=>{R[g]=E}),R.open(D,r,!0),Object.entries(o).forEach(([g,E])=>R.setRequestHeader(g,E));let K=x(0,U,Q,T);R.upload.onprogress=A,R.onloadstart=()=>{u(),c()},R.onprogress=h,R.onloadend=()=>{d(),K()},R.ontimeout=()=>i(0,U,T),R.onreadystatechange=g=>{let E=g,v=4;if(E.target&&E.target.readyState===v){let{status:P}=E.target,w=String(P).startsWith("2")||String(P).startsWith("3"),L=nt(R.getAllResponseHeaders());if(w){let q=ie(E.target.response);f(q,P,{headers:L},T)}else{let q=fe(E.target.response);a(q,P,{headers:L},T)}}},b(),y(),R.send()})});import St from"http";import Gt from"stream";import Vt from"https";var me=s=>`${s}_${Date.now().toString(36)}_${Math.random().toString(36).substring(2)}`;var J=class{constructor(e,t,r){this.client=e;this.requestOptions=t;this.requestJSON=r;this.setHeaders=e=>this.clone({headers:e});this.setAuth=e=>this.clone({auth:e});this.setParams=e=>this.clone({params:e});this.setData=e=>this.clone({data:e});this.setQueryParams=e=>this.clone({queryParams:e});this.setOptions=e=>this.clone({options:e});this.setCancelable=e=>this.clone({cancelable:e});this.setRetry=e=>this.clone({retry:e});this.setRetryTime=e=>this.clone({retryTime:e});this.setGarbageCollection=e=>this.clone({garbageCollection:e});this.setCache=e=>this.clone({cache:e});this.setCacheTime=e=>this.clone({cacheTime:e});this.setQueued=e=>this.clone({queued:e});this.setAbortKey=e=>(this.updatedAbortKey=!0,this.clone({abortKey:e}));this.setCacheKey=e=>(this.updatedCacheKey=!0,this.clone({cacheKey:e}));this.setQueueKey=e=>(this.updatedQueueKey=!0,this.clone({queueKey:e}));this.setEffectKey=e=>(this.updatedEffectKey=!0,this.clone({effectKey:e}));this.setDeduplicate=e=>this.clone({deduplicate:e});this.setDeduplicateTime=e=>this.clone({deduplicateTime:e});this.setUsed=e=>this.clone({used:e});this.setOffline=e=>this.clone({offline:e});this.setMock=e=>{let t=function*(n){if(Array.isArray(e)){let o=0;for(;;)yield n[o],o=e.length===o+1?0:o+1}else for(;;)yield e};return this.mockData=e,this.mock=t(e),this};this.removeMock=()=>(this.mockData=null,this.mock=null,this);this.setDataMapper=e=>{let t=this.clone(void 0);return t.dataMapper=e,t};this.setRequestMapper=e=>{let t=this.clone(void 0);return t.requestMapper=e,t};this.setResponseMapper=e=>{let t=this.clone();return t.responseMapper=e,t};this.paramsMapper=(e,t)=>{let r=this.requestOptions.endpoint;return e&&Object.entries(e).forEach(([n,o])=>{r=r.replace(new RegExp(`:${n}`,"g"),String(o))}),t&&(r+=this.client.stringifyQueryParams(t)),r};this.abort=()=>{let{requestManager:e}=this.client;return e.abortByKey(this.abortKey),this.clone()};this.exec=e=>l(this,null,function*(){let{adapter:t,requestManager:r}=this.client,n=this.clone(e),o=me(this.queueKey);r.addAbortController(this.abortKey,o);let a=yield t(n,o);return r.removeAbortController(this.abortKey,o),n.responseMapper?n.responseMapper(a):a});this.send=e=>l(this,null,function*(){let o=e||{},{dispatcherType:t}=o,r=tt(o,["dispatcherType"]),n=this.clone(r);return ot(n,e)});var E,v,P,w,L,q,_,G,S,k,B,V,X,Y,Z,j,te,re,z,se,ne,le,oe,ae,Oe,p,m,C,I;let{endpoint:n,headers:o,auth:a=!0,method:d=e.defaultMethod,options:i,cancelable:u=!1,retry:x=0,retryTime:h=500,garbageCollection:A=6e4*5,cache:c=!0,cacheTime:b=6e4*5,queued:y=!1,offline:f=!0,abortKey:D,cacheKey:T,queueKey:R,effectKey:Q,deduplicate:K=!1,deduplicateTime:g=10}=$($({},(v=(E=this.client).requestDefaultOptions)==null?void 0:v.call(E,t)),t);this.endpoint=(P=r==null?void 0:r.endpoint)!=null?P:n,this.headers=(w=r==null?void 0:r.headers)!=null?w:o,this.auth=(L=r==null?void 0:r.auth)!=null?L:a,this.method=d,this.params=r==null?void 0:r.params,this.data=r==null?void 0:r.data,this.queryParams=r==null?void 0:r.queryParams,this.options=(q=r==null?void 0:r.options)!=null?q:i,this.cancelable=(_=r==null?void 0:r.cancelable)!=null?_:u,this.retry=(G=r==null?void 0:r.retry)!=null?G:x,this.retryTime=(S=r==null?void 0:r.retryTime)!=null?S:h,this.garbageCollection=(k=r==null?void 0:r.garbageCollection)!=null?k:A,this.cache=(B=r==null?void 0:r.cache)!=null?B:c,this.cacheTime=(V=r==null?void 0:r.cacheTime)!=null?V:b,this.queued=(X=r==null?void 0:r.queued)!=null?X:y,this.offline=(Y=r==null?void 0:r.offline)!=null?Y:f,this.abortKey=(j=(Z=r==null?void 0:r.abortKey)!=null?Z:D)!=null?j:this.client.abortKeyMapper(this),this.cacheKey=(re=(te=r==null?void 0:r.cacheKey)!=null?te:T)!=null?re:this.client.cacheKeyMapper(this),this.queueKey=(se=(z=r==null?void 0:r.queueKey)!=null?z:R)!=null?se:this.client.queueKeyMapper(this),this.effectKey=(le=(ne=r==null?void 0:r.effectKey)!=null?ne:Q)!=null?le:this.client.effectKeyMapper(this),this.used=(oe=r==null?void 0:r.used)!=null?oe:!1,this.deduplicate=(ae=r==null?void 0:r.deduplicate)!=null?ae:K,this.deduplicateTime=(Oe=r==null?void 0:r.deduplicateTime)!=null?Oe:g,this.updatedAbortKey=(p=r==null?void 0:r.updatedAbortKey)!=null?p:!1,this.updatedCacheKey=(m=r==null?void 0:r.updatedCacheKey)!=null?m:!1,this.updatedQueueKey=(C=r==null?void 0:r.updatedQueueKey)!=null?C:!1,this.updatedEffectKey=(I=r==null?void 0:r.updatedEffectKey)!=null?I:!1}toJSON(){return{requestOptions:this.requestOptions,endpoint:this.endpoint,headers:this.headers,auth:this.auth,method:this.method,params:this.params,data:this.data,queryParams:this.queryParams,options:this.options,cancelable:this.cancelable,retry:this.retry,retryTime:this.retryTime,garbageCollection:this.garbageCollection,cache:this.cache,cacheTime:this.cacheTime,queued:this.queued,offline:this.offline,abortKey:this.abortKey,cacheKey:this.cacheKey,queueKey:this.queueKey,effectKey:this.effectKey,used:this.used,disableResponseInterceptors:this.requestOptions.disableResponseInterceptors,disableRequestInterceptors:this.requestOptions.disableRequestInterceptors,updatedAbortKey:this.updatedAbortKey,updatedCacheKey:this.updatedCacheKey,updatedQueueKey:this.updatedQueueKey,updatedEffectKey:this.updatedEffectKey,deduplicate:this.deduplicate,deduplicateTime:this.deduplicateTime}}clone(e){let t=this.toJSON(),r=W($($({},t),e),{abortKey:this.updatedAbortKey?(e==null?void 0:e.abortKey)||this.abortKey:void 0,cacheKey:this.updatedCacheKey?(e==null?void 0:e.cacheKey)||this.cacheKey:void 0,queueKey:this.updatedQueueKey?(e==null?void 0:e.queueKey)||this.queueKey:void 0,endpoint:this.paramsMapper((e==null?void 0:e.params)||this.params,(e==null?void 0:e.queryParams)||this.queryParams),queryParams:(e==null?void 0:e.queryParams)||this.queryParams,data:(e==null?void 0:e.data)||this.data}),n=new J(this.client,this.requestOptions,r);return n.dataMapper=this.dataMapper,n.responseMapper=this.responseMapper,n.requestMapper=this.requestMapper,n.mockData=this.mockData,n.mock=this.mock,n}};var Re=(o=>(o.get="GET",o.post="POST",o.put="PUT",o.patch="PATCH",o.delete="DELETE",o))(Re||{});var We=(n=>(n.oneByOne="one-by-one",n.allAtOnce="all-at-once",n.previousCanceled="previous-canceled",n.deduplicated="deduplicated",n))(We||{});var at=s=>({setDrained:(e,t)=>{s.emit(Te(e),t)},setQueueStatus:(e,t)=>{s.emit(Ee(e),t)},setQueueChanged:(e,t)=>{s.emit(xe(e),t)},onDrained:(e,t)=>(s.on(Te(e),t),()=>s.removeListener(Te(e),t)),onQueueStatus:(e,t)=>(s.on(Ee(e),t),()=>s.removeListener(Ee(e),t)),onQueueChange:(e,t)=>(s.on(xe(e),t),()=>s.removeListener(xe(e),t))});import kt from"events";var N=class{constructor(e,t){this.client=e;this.options=t;this.emitter=new kt;this.events=at(this.emitter);this.storage=new Map;this.requestCount=new Map;this.runningRequests=new Map;this.start=e=>{let t=this.getQueue(e);t.stopped=!1,this.setQueue(e,t),this.flushQueue(e),this.events.setQueueStatus(e,t)};this.pause=e=>{let t=this.getQueue(e);t.stopped=!0,this.setQueue(e,t),this.events.setQueueStatus(e,t)};this.stop=e=>{let t=this.getQueue(e);t.stopped=!0,this.setQueue(e,t),this.cancelRunningRequests(e),this.events.setQueueStatus(e,t)};this.getQueuesKeys=()=>Array.from(this.storage.keys());this.getQueue=e=>{let t={requests:[],stopped:!1};return this.storage.get(e)||t};this.getRequest=(e,t)=>{let r={requests:[],stopped:!1};return(this.storage.get(e)||r).requests.find(o=>o.requestId===t)};this.getIsActiveQueue=e=>{let t=this.getQueue(e),r=t.requests.some(o=>!o.stopped),n=!t.stopped;return r&&n};this.addQueueElement=(e,t)=>{let r=this.getQueue(e);r.requests.push(t),this.setQueue(e,r)};this.setQueue=(e,t)=>{var r,n;return this.storage.set(e,t),(n=(r=this.options)==null?void 0:r.onUpdateStorage)==null||n.call(r,e,t),this.events.setQueueChanged(e,t),t};this.clearQueue=e=>{var n,o;let t=this.getQueue(e),r={requests:[],stopped:t.stopped};return this.storage.set(e,r),(o=(n=this.options)==null?void 0:n.onDeleteFromStorage)==null||o.call(n,e,r),this.events.setQueueChanged(e,r),r};this.flushQueue=e=>l(this,null,function*(){let t=this.getQueue(e),r=this.getRunningRequests(e),n=t.requests.find(x=>!x.stopped),o=t&&t.stopped,a=!this.client.appManager.isOnline,d=!(n!=null&&n.request.queued),i=!r.length,u=!n;o||a||u?this.logger.debug("Skipping queue trigger",{isStopped:o,isOffline:a,isEmpty:u}):d?t.requests.forEach(x=>{this.hasRunningRequest(e,x.requestId)||this.performRequest(x)}):i&&(yield this.performRequest(n),this.flushQueue(e))});this.flush=()=>l(this,null,function*(){let e=this.getQueuesKeys();for(let t of e)this.getQueue(t)&&this.flushQueue(t)});this.clear=()=>{var t,r;this.getQueuesKeys().forEach(n=>this.cancelRunningRequests(n)),this.runningRequests.clear(),this.storage.clear(),(r=(t=this.options)==null?void 0:t.onClearStorage)==null||r.call(t,this)};this.startRequest=(e,t)=>{let r=this.getQueue(e),n=r.requests.find(o=>o.requestId===t);n&&(n.stopped=!1,this.setQueue(e,r),this.flushQueue(e),this.events.setQueueStatus(e,r))};this.stopRequest=(e,t)=>{let r=this.getQueue(e),n=r.requests.find(o=>o.requestId===t);n&&(n.stopped=!0,this.setQueue(e,r),this.cancelRunningRequest(e,t),this.events.setQueueStatus(e,r))};this.getAllRunningRequest=()=>Array.from(this.runningRequests.values()).flat();this.getRunningRequests=e=>this.runningRequests.get(e)||[];this.getRunningRequest=(e,t)=>this.getRunningRequests(e).find(n=>n.requestId===t);this.addRunningRequest=(e,t,r)=>{let n=this.getRunningRequests(e);n.push({requestId:t,request:r}),this.runningRequests.set(e,n)};this.hasRunningRequests=e=>!!this.getRunningRequests(e).length;this.hasRunningRequest=(e,t)=>!!this.getRunningRequests(e).find(n=>n.requestId===t);this.cancelRunningRequests=e=>{var t;(t=this.runningRequests.get(e))==null||t.forEach(r=>{this.client.requestManager.abortByRequestId(r.request.abortKey,r.requestId)}),this.deleteRunningRequests(e)};this.cancelRunningRequest=(e,t)=>{let r=this.getRunningRequests(e).filter(n=>n.requestId===t?(this.client.requestManager.abortByRequestId(n.request.abortKey,n.requestId),!1):!0);this.runningRequests.set(e,r)};this.deleteRunningRequests=e=>{this.runningRequests.set(e,[])};this.deleteRunningRequest=(e,t)=>{let r=this.getRunningRequests(e);this.runningRequests.set(e,r.filter(n=>n.requestId!==t))};this.getQueueRequestCount=e=>this.requestCount.get(e)||0;this.incrementQueueRequestCount=e=>{let t=this.requestCount.get(e)||0;this.requestCount.set(e,t+1)};this.createStorageElement=e=>({requestId:me(e.queueKey),timestamp:+new Date,request:e,retries:0,stopped:!1});this.add=e=>{let{queueKey:t}=e,r=this.createStorageElement(e),{requestId:n}=r,o=this.getQueue(t),[a]=o.requests.slice(-1),d=it(e,a);switch(this.logger.debug("Adding request to queue",{requestType:d,request:e,requestId:n}),d){case"one-by-one":return this.addQueueElement(t,r),this.flushQueue(t),n;case"previous-canceled":return this.cancelRunningRequests(t),this.clearQueue(t),this.addQueueElement(t,r),this.flushQueue(t),n;case"deduplicated":return o.requests[0].requestId;default:return this.addQueueElement(t,r),this.flushQueue(t),n}};this.delete=(e,t,r)=>{var a,d;this.logger.debug("Deleting request",{queueKey:e,requestId:t,abortKey:r});let n=this.getQueue(e),o=n.requests.find(i=>i.requestId===t);if(!!o)return n.requests=n.requests.filter(i=>i.requestId!==t),this.storage.set(e,n),this.hasRunningRequest(e,t)&&(this.deleteRunningRequest(e,t),this.client.requestManager.abortByRequestId(r,t)),(d=(a=this.options)==null?void 0:a.onDeleteFromStorage)==null||d.call(a,e,n),this.events.setQueueChanged(e,n),this.client.requestManager.events.emitRemove(e,t,{requestId:t,request:o.request}),n.requests.length||this.events.setDrained(e,n),n};this.performRequest=e=>l(this,null,function*(){var E;let{request:t,requestId:r}=e;this.logger.info("Performing request",{request:t,requestId:r});let{retry:n,retryTime:o,queueKey:a,cacheKey:d,abortKey:i,offline:u}=t,{adapter:x,requestManager:h,cache:A,appManager:c}=this.client,b=be(e.retries,n),y=!c.isOnline&&u,f=this.hasRunningRequest(a,r),D=e.stopped;if(y||f||D)return this.logger.warning("Unable to perform request",{isOffline:y,isAlreadyRunning:f,isStopped:D});this.addRunningRequest(a,r,t),h.events.emitLoading(a,r,{queueKey:a,requestId:r,loading:!0,isRetry:!!e.retries,isOffline:y}),this.incrementQueueRequestCount(a),h.addAbortController(i,r);let T=yield x(t,r);h.removeAbortController(i,r);let R=!c.isOnline,Q=O("abort").message===((E=T.error)==null?void 0:E.message),K=!this.hasRunningRequest(a,r)||Q;this.deleteRunningRequest(a,r);let g={isCanceled:K,isOffline:R,retries:e.retries,timestamp:+new Date};if(h.events.emitLoading(a,r,{queueKey:a,requestId:r,loading:!1,isRetry:!!e.retries,isOffline:y}),h.events.emitResponse(d,r,T,g),A.set(t,$($({},T),g)),this.logger.info("Request finished",{requestId:r,request:t,response:T,requestDetails:g}),K){let v=this.getQueue(a),P=v.requests.find(w=>w.requestId===r);return!v.stopped&&!(P!=null&&P.stopped)?(this.logger.debug("Request paused",{response:T,requestDetails:g,request:t}),this.delete(a,r,i)):this.logger.debug("Request canceled",{response:T,requestDetails:g,request:t})}if(!T.success&&R)return u?this.logger.debug("Awaiting for network restoration",{response:T,requestDetails:g,request:t}):(this.logger.warning("Removing non-offline request",{response:T,requestDetails:g,request:t}),this.delete(a,r,i));if(T.success)return this.delete(a,r,i),this.logger.debug("Successful response, removing request from queue.",{response:T,requestDetails:g,request:t});!T.success&&b?(this.logger.debug("Waiting for retry",{response:T,requestDetails:g,request:t}),setTimeout(()=>{this.logger.warning("Error response, performing retry"),this.performRequest(W($({},e),{retries:e.retries+1}))},o||0)):(this.logger.error("All retries have been used. Removing request from queue."),this.delete(a,r,i))});var r,n,o;this.logger=e.loggerManager.init("Dispatcher"),(r=this.options)!=null&&r.storage&&(this.storage=this.options.storage),this.client.appManager.events.onOnline(()=>{this.flush()}),(o=(n=this.options)==null?void 0:n.onInitialization)==null||o.call(n,this)}};var Te=s=>`${s}-drained-event`,Ee=s=>`${s}-status-event`,xe=s=>`${s}-change-event`,Wr=(s,e,t)=>t?t-s<=e:!1,be=(s,e)=>!!(e&&s<e),it=(s,e)=>{let{queued:t,cancelable:r,deduplicate:n}=s,o=e?+new Date-e.timestamp<=s.deduplicateTime:!1;return t?"one-by-one":r?"previous-canceled":o&&n?"deduplicated":"all-at-once"};var pt=s=>{try{if(typeof s=="string")return s;if(s==null)return"";let e=JSON.stringify(s);if(typeof e!="string")throw new Error;return e}catch(e){return""}},$t=({loaded:s,total:e})=>!s||!e?0:Number((s*100/e).toFixed(0)),Ft=(s,e,{total:t,loaded:r})=>{let n=+e-+s||1,o=r/n,a=Math.max(t,r),d=a-r,i=o?d/o:null;return{timeLeft:a===r?0:i,sizeLeft:d}},Xe=(s,e,t)=>{let{total:r,loaded:n}=t;if(Number.isNaN(r)||Number.isNaN(n))return{progress:0,timeLeft:0,sizeLeft:0,total:0,loaded:0,startTimestamp:+s};let{timeLeft:o,sizeLeft:a}=Ft(s,e,t);return{progress:$t(t),timeLeft:o,sizeLeft:a,total:r,loaded:n,startTimestamp:+s}},Ae=s=>`${s.method}_${s.requestOptions.endpoint}_${s.cancelable}`,ut=(s,e)=>{let t=pt(s.method),r=e?s.requestOptions.endpoint:pt(s.endpoint);return`${t}_${r}`},_t=(s,e="auto")=>{let{fetchDispatcher:t,submitDispatcher:r}=s.client,n=s.method==="GET",o=e==="auto"&&n||e==="fetch";return[o?t:r,o]},ot=(s,e)=>{let{requestManager:t}=s.client,[r]=_t(s,e==null?void 0:e.dispatcherType);return new Promise(n=>{var b;let o=!1,a=r.add(s);(b=e==null?void 0:e.onSettle)==null||b.call(e,a,s);let d=t.events.onRequestStartById(a,(...y)=>{var f;return(f=e==null?void 0:e.onRequestStart)==null?void 0:f.call(e,...y)}),i=t.events.onResponseStartById(a,(...y)=>{var f;return(f=e==null?void 0:e.onResponseStart)==null?void 0:f.call(e,...y)}),u=t.events.onUploadProgressById(a,(...y)=>{var f;return(f=e==null?void 0:e.onUploadProgress)==null?void 0:f.call(e,...y)}),x=t.events.onDownloadProgressById(a,(...y)=>{var f;return(f=e==null?void 0:e.onDownloadProgress)==null?void 0:f.call(e,...y)}),h=t.events.onResponseById(a,(y,f)=>{var K;o=!0;let D=(K=s.responseMapper)==null?void 0:K.call(s,y),T=s.offline&&f.isOffline,R=be(f.retries,s.retry),Q=(g,E)=>{var v;!g&&T||!g&&R||((v=e==null?void 0:e.onResponse)==null||v.call(e,E,f),n(E),c())};if(D instanceof Promise)l(void 0,null,function*(){let g=yield D,{success:E}=g;Q(E,g)});else{let g=D||y,{success:E}=g;Q(E,g)}}),A=t.events.onRemoveById(a,(...y)=>{var f;o||((f=e==null?void 0:e.onRemove)==null||f.call(e,...y),n({data:null,status:null,success:null,error:O("deleted"),extra:s.client.defaultExtra}),c())});function c(){d(),i(),u(),x(),h(),A()}})};var ct=(A,c)=>l(void 0,[A,c],function*(s,{onError:e,onResponseEnd:t,onTimeoutError:r,onRequestEnd:n,createAbortListener:o,onResponseProgress:a,onRequestProgress:d,onResponseStart:i,onBeforeRequest:u,onRequestStart:x,onSuccess:h}){var D,T;let b=((D=s.requestOptions.options)==null?void 0:D.timeout)||((T=s.options)==null?void 0:T.timeout),y=s.mock.next(),f=y.value instanceof Function?yield y.value(s):y.value;return new Promise(R=>{let{data:Q,config:K={},extra:g}=f,{status:E=200,success:v=!0,responseDelay:P=5,requestSentDuration:w=0,responseReceivedDuration:L=0}=K,q=()=>b&&w+L>b?[Math.floor(b/2)-1,Math.floor(b/2)-1]:[w,L],[_,G]=q();o(0,{},()=>{},R),u(),x();let S=(B,V)=>new Promise(X=>{let Y=+new Date;setInterval(()=>{let Z=+new Date,j=Math.min(B,Z-Y);j>=B&&X(!0),V({total:B,loaded:j})},20)}),k=()=>l(void 0,null,function*(){yield S(_,d),n(),i(),yield S(G,a),v?h(Q,E,g||{},R):e(Q,E,g||{},R)});b&&P>b?setTimeout(()=>r(0,g||{},R),b+1):setTimeout(k,P),t()})});var he=(s,e,t,r)=>l(void 0,null,function*(){let{url:n,requestManager:o,loggerManager:a,headerMapper:d,payloadMapper:i}=s.client,u=a.init("Adapter"),x=null,h=null,A=null,c=s,b=1,y=1,f=0,D=0;u.debug("Starting request middleware callbacks");try{c=yield c.client.__modifyRequest(s),c.auth&&(c=yield c.client.__modifyAuth(s)),c.requestMapper&&(c=yield c.requestMapper(c,e))}catch(p){x=p}let{client:T,abortKey:R,queueKey:Q,endpoint:K,data:g}=c,E=n+K,v=T.effects.filter(p=>c.effectKey===p.getEffectKey()),P=d(c),w=g;try{w=i(g),c.dataMapper&&(w=yield c.dataMapper(g))}catch(p){x=p}let L=$({},c.options),q=()=>h,_=()=>A,G=(p,m)=>{if(!m)return p;let C=Number(m.total||0),I=Number(m.loaded||0);return Math.max(C,I,p)},S=(p,m,C)=>{let I=Xe(new Date(p),new Date(m),C);f!==100&&(f=I.total,o.events.emitUploadProgress(Q,e,I,{requestId:e,request:c}))},k=(p,m,C)=>{let I=Xe(new Date(p),new Date(m),C);D!==100&&(D=I.total,o.events.emitDownloadProgress(Q,e,I,{requestId:e,request:c}))},B=()=>{v.forEach(p=>p.onTrigger(c))},V=p=>{v.forEach(C=>C.onStart(c)),p!=null&&p.total&&(b=G(b,p));let m={total:b,loaded:(p==null?void 0:p.loaded)||0};return h=+new Date,S(h,h,m),o.events.emitRequestStart(Q,e,{requestId:e,request:c}),h},X=p=>{h||(h=+new Date),b=G(b,p);let m=+new Date;return S(h,m,{total:b,loaded:p.loaded||0}),m},Y=()=>{h||(h=+new Date);let p=+new Date;return S(h,p,{total:b,loaded:b}),p},Z=p=>{A=+new Date,y=G(y,p);let m={total:y,loaded:(p==null?void 0:p.loaded)||0};return k(A,A,m),o.events.emitResponseStart(Q,e,{requestId:e,request:c}),A},j=p=>{A||(A=+new Date);let m=+new Date;return y=G(y,p),k(A,m,{total:p.total||y,loaded:p.loaded||0}),m},te=()=>{A||(A=+new Date);let p=+new Date;return k(A,p,{total:y,loaded:y}),p},re=(p,m,C,I)=>l(void 0,null,function*(){let M={data:p,error:null,success:!0,status:m,extra:C};return M=yield c.client.__modifyResponse(M,c),M=yield c.client.__modifySuccessResponse(M,c),v.forEach(H=>H.onSuccess(M,c)),v.forEach(H=>H.onFinished(M,c)),I(M),M}),z=(p,m,C,I)=>l(void 0,null,function*(){let M={data:null,status:m,error:p,success:!1,extra:C};return M=yield c.client.__modifyResponse(M,c),M=yield c.client.__modifyErrorResponse(M,c),v.forEach(H=>H.onError(M,c)),v.forEach(H=>H.onFinished(M,c)),I(M),M}),se=(p,m,C)=>{let I=O("abort");return z(I,p,m,C)},ne=(p,m,C)=>{let I=O("timeout");return z(I,p,m,C)},le=(p,m,C)=>{let I=O();return z(I,p,m,C)},oe=()=>o.getAbortController(R,e),ae=(p,m,C,I)=>{let M=oe();if(!M)throw new Error("Controller is not found");let H=()=>{se(p,m,I),C(),o.events.emitAbort(R,e,c)};return M.signal.aborted&&H(),M.signal.addEventListener("abort",H),()=>M.signal.removeEventListener("abort",H)};return{fullUrl:E,data:g,headers:P,payload:w,config:L,getAbortController:oe,getRequestStartTimestamp:q,getResponseStartTimestamp:_,createAbortListener:ae,onBeforeRequest:B,onRequestStart:V,onRequestProgress:X,onRequestEnd:Y,onResponseStart:Z,onResponseProgress:j,onResponseEnd:te,onSuccess:re,onAbortError:se,onTimeoutError:ne,onUnexpectedError:le,onError:z,makeRequest:p=>x?z(x,t,r,()=>null):s.mock?ct(c,{onError:z,onResponseEnd:te,onTimeoutError:ne,onRequestEnd:Y,createAbortListener:ae,onResponseProgress:j,onRequestProgress:X,onResponseStart:Z,onBeforeRequest:B,onRequestStart:V,onSuccess:re}):new Promise(p)}});var O=s=>s==="timeout"?new Error("Request timeout"):s==="abort"?new Error("Request cancelled"):new Error("Unexpected error"),nt=s=>{let e=s.trim().split(/[\r\n]+/),t={};return e.forEach(r=>{let n=r.split(": "),o=n.shift(),a=n.join(": ");t[o]=a}),t},ie=s=>{try{return JSON.parse(s)}catch(e){return s}},fe=s=>s?ie(s):O(),dt=s=>s.length,lt=s=>s;var gt=(s,e)=>l(void 0,null,function*(){let{makeRequest:t,fullUrl:r,config:n,headers:o,payload:a,onError:d,onResponseEnd:i,onTimeoutError:u,onRequestEnd:x,createAbortListener:h,onResponseProgress:A,onRequestProgress:c,onResponseStart:b,onBeforeRequest:y,onRequestStart:f,onSuccess:D}=yield he(s,e,0,U),{method:T="GET",client:R}=s,Q=R.url.includes("https://")?Vt:St,K={path:r,method:T,headers:o,timeout:ye};Object.entries(n).forEach(([w,L])=>{K[w]=L});let g=()=>null;y();let E=a?Number(dt(a)):0,v=0,P=yield lt(a);return t(w=>{let L=Q.request(K,q=>{q.setEncoding("utf8"),g=h(0,U,q.destroy,w);let _="",G=Number(q.headers["content-length"]),S=0;q.on("data",k=>{_||b(),S+=k.length,_+=k,A({total:G,loaded:S})}),q.on("end",()=>{let{statusCode:k}=q;if(String(k).startsWith("2")||String(k).startsWith("3")){let V=ie(_);D(V,k,{headers:q.headers},w)}else{let V=fe(_);d(V,k,{headers:q.headers},w)}g(),i()})});L.on("timeout",()=>u(0,U,w)),L.on("error",q=>d(q,0,U,w)),P?Gt.Readable.from(P,{objectMode:!1}).on("data",_=>{v||f(),v+=_.length,c({total:E,loaded:v})}).on("end",()=>{x()}).pipe(L):L.end()})});var yt=(s,e)=>l(void 0,null,function*(){return typeof XMLHttpRequest!="undefined"?st(s,e):gt(s,e)});import Bt from"events";var pe=class{constructor(e,t){this.client=e;this.options=t;this.emitter=new Bt;this.garbageCollectors=new Map;this.set=(e,t)=>{var x,h,A;this.logger.debug("Processing cache response",{request:e,response:t});let{cacheKey:r,cache:n,cacheTime:o,garbageCollection:a}=e,d=this.storage.get(r),i=ht(d,t),u=W($({},i),{cacheTime:o,clearKey:this.clearKey,garbageCollection:a});if(this.events.emitCacheData(r,u),this.logger.debug("Emitting cache response",{request:e,data:i}),!n)return this.logger.debug("Prevented saving response to cache",{request:e,data:i});t.success&&(this.logger.debug("Saving response to cache storage",{request:e,data:i}),this.storage.set(r,u),(x=this.lazyStorage)==null||x.set(r,u),(A=(h=this.options)==null?void 0:h.onChange)==null||A.call(h,r,u),this.scheduleGarbageCollector(r))};this.get=e=>(this.getLazyResource(e),this.storage.get(e));this.keys=()=>{let e=this.storage.keys();return Array.from(e)};this.delete=e=>{var t,r,n;this.logger.debug("Deleting cache element",{cacheKey:e}),this.storage.delete(e),(r=(t=this.options)==null?void 0:t.onDelete)==null||r.call(t,e),(n=this.lazyStorage)==null||n.delete(e)};this.revalidate=e=>l(this,null,function*(){this.logger.debug("Revalidating cache element",{cacheKey:e});let t=yield this.getLazyKeys();if(typeof e=="string")this.events.emitRevalidation(e),this.delete(e);else for(let r of t)e.test(r)&&(this.events.emitRevalidation(r),this.delete(r))});this.getLazyResource=e=>l(this,null,function*(){var a;let t=yield(a=this.lazyStorage)==null?void 0:a.get(e),r=this.storage.get(e);if(this.lazyStorage&&t){let d=+new Date,i=r?r.timestamp<t.timestamp:!0,u=t.cacheTime<=d-t.timestamp,x=t.clearKey===this.clearKey;if(x||this.lazyStorage.delete(e),i&&!u&&x)return this.storage.set(e,t),this.events.emitCacheData(e,t),t}let o=(r==null?void 0:r.clearKey)===this.clearKey;return r&&!o&&this.delete(e),r});this.getLazyKeys=()=>l(this,null,function*(){var n;let e=yield(n=this.lazyStorage)==null?void 0:n.keys(),t=Array.from(e||[]),r=Array.from(this.storage.keys());return[...new Set([...t,...r])]});this.scheduleGarbageCollector=e=>l(this,null,function*(){let t=yield this.getLazyResource(e);if(clearTimeout(this.garbageCollectors.get(e)),t){let r=t.garbageCollection+t.timestamp-+new Date;t.garbageCollection!==null&&JSON.stringify(t.garbageCollection)==="null"?this.logger.info("Cache value is Infinite",{cacheKey:e}):r>=0?this.garbageCollectors.set(e,setTimeout(()=>{this.client.appManager.isOnline&&(this.logger.info("Garbage collecting cache element",{cacheKey:e}),this.delete(e))},r)):this.client.appManager.isOnline&&(this.logger.info("Garbage collecting cache element",{cacheKey:e}),this.delete(e))}});this.clear=()=>l(this,null,function*(){this.storage.clear()});var r,n,o,a,d;this.storage=((r=this.options)==null?void 0:r.storage)||new Map,this.events=ft(this.emitter),(o=(n=this.options)==null?void 0:n.onInitialization)==null||o.call(n,this),this.clearKey=((a=this.options)==null?void 0:a.clearKey)||"",this.lazyStorage=(d=this.options)==null?void 0:d.lazyStorage,this.logger=this.client.loggerManager.init("Cache"),this.getLazyKeys().then(i=>{i.forEach(this.scheduleGarbageCollector)}),this.client.appManager.events.onOnline(()=>{this.getLazyKeys().then(i=>{i.forEach(this.scheduleGarbageCollector)})})}};var ht=(s,e)=>{let{data:t,success:r}=e,n=!r&&s?s.data:null,o=t||n;return W($({},e),{data:o})},ve=s=>`${s}_revalidate`,qe=s=>`${s}_cache`,un=s=>`${s}_cache_by_id`;var ft=s=>({emitCacheData:(e,t)=>{s.emit(qe(e),t)},emitRevalidation:e=>{s.emit(ve(e))},onData:(e,t)=>(s.on(qe(e),t),()=>s.removeListener(qe(e),t)),onRevalidate:(e,t)=>(s.on(ve(e),t),()=>s.removeListener(ve(e),t))});import Ut from"events";var ue=class{constructor(e){this.options=e;this.emitter=new Ut;this.events=mt(this.emitter);this.setInitialFocus=e=>l(this,null,function*(){typeof e=="function"?(this.isFocused=!1,this.isFocused=yield e()):this.isFocused=e});this.setInitialOnline=e=>l(this,null,function*(){typeof e=="function"?(this.isOnline=!1,this.isOnline=yield e()):this.isOnline=e});this.setFocused=e=>{this.isFocused=e,e?this.events.emitFocus():this.events.emitBlur()};this.setOnline=e=>{this.isOnline=e,e?this.events.emitOnline():this.events.emitOffline()};let{focusEvent:t=ee.focusEvent,onlineEvent:r=ee.onlineEvent,initiallyFocused:n=ee.initiallyFocused,initiallyOnline:o=ee.initiallyOnline}=this.options||ee;this.setInitialFocus(n),this.setInitialOnline(o),t(this.setFocused),r(this.setOnline),this.isBrowser=Ye()}};var ce=()=>{try{return Boolean(window&&window.addEventListener)}catch(s){return!1}},Ye=()=>{try{return Boolean(ce()&&window.document&&window.document.addEventListener)}catch(s){return!1}},de=(s,e,t)=>{ce()&&window.addEventListener(s,e,t)},Rt=(s,e,t)=>{Ye()&&window.document.addEventListener(s,e,t)};var mt=s=>({emitFocus:()=>{s.emit("focus")},emitBlur:()=>{s.emit("blur")},emitOnline:()=>{s.emit("online")},emitOffline:()=>{s.emit("offline")},onFocus:e=>(s.on("focus",e),()=>s.removeListener("focus",e)),onBlur:e=>(s.on("blur",e),()=>s.removeListener("blur",e)),onOnline:e=>(s.on("online",e),()=>s.removeListener("online",e)),onOffline:e=>(s.on("offline",e),()=>s.removeListener("offline",e))});var Tt=(n=>(n.focus="focus",n.blur="blur",n.online="online",n.offline="offline",n))(Tt||{}),ee={initiallyFocused:!0,initiallyOnline:!0,focusEvent:s=>{Rt("visibilitychange",()=>s(!0)),de("focus",()=>s(!0)),de("blur",()=>s(!1))},onlineEvent:s=>{de("online",()=>s(!0)),de("offline",()=>s(!1))}};import zt from"events";var Ce=class{constructor(){this.emitter=new zt;this.events=Et(this.emitter);this.abortControllers=new Map;this.addAbortController=(e,t)=>{let r=this.abortControllers.get(e);if(!r){let o=new Map;r=o,this.abortControllers.set(e,o)}let n=r.get(t);(!n||n.signal.aborted)&&r.set(t,new AbortController)};this.getAbortController=(e,t)=>{var r;return(r=this.abortControllers.get(e))==null?void 0:r.get(t)};this.removeAbortController=(e,t)=>{var r;(r=this.abortControllers.get(e))==null||r.delete(t)};this.useAbortController=(e,t)=>{var n;let r=(n=this.abortControllers.get(e))==null?void 0:n.get(t);r==null||r.abort()};this.abortByKey=e=>{let t=this.abortControllers.get(e);t&&Array.from(t.entries()).forEach(([n])=>{this.useAbortController(e,n)})};this.abortByRequestId=(e,t)=>{this.useAbortController(e,t)};this.abortAll=()=>{Array.from(this.abortControllers.entries()).forEach(([t,r])=>{Array.from(r.entries()).forEach(([o])=>{this.useAbortController(t,o)})})}}};var Ie=s=>`${s}-loading-event`,Me=s=>`${s}-loading-event-by-id`,we=s=>`${s}-remove-event`,Pe=s=>`${s}-remove-event-by-id`,De=s=>`${s}-request-abort`,Qe=s=>`${s}-request-abort-by-id`,Le=s=>`${s}-response`,Ke=s=>`${s}-response-by-id`,ke=s=>`${s}-request-start`,$e=s=>`${s}-request-start-by-id`,Fe=s=>`${s}-response-start`,_e=s=>`${s}-response-start-by-id`,Se=s=>`${s}-request-progress`,Ge=s=>`${s}-request-progress-by-id`,Ve=s=>`${s}-response-progress`,He=s=>`${s}-response-progress-by-id`;var Et=s=>({emitLoading:(e,t,r)=>{s.emit(Me(t),r),s.emit(Ie(e),r)},emitRequestStart:(e,t,r)=>{s.emit($e(t),r),s.emit(ke(e),r)},emitResponseStart:(e,t,r)=>{s.emit(_e(t),r),s.emit(Fe(e),r)},emitUploadProgress:(e,t,r,n)=>{s.emit(Ge(t),r,n),s.emit(Se(e),r,n)},emitDownloadProgress:(e,t,r,n)=>{s.emit(He(t),r,n),s.emit(Ve(e),r,n)},emitResponse:(e,t,r,n)=>{s.emit(Ke(t),r,n),s.emit(Le(e),r,n)},emitAbort:(e,t,r)=>{s.emit(Qe(t),r),s.emit(De(e),r)},emitRemove:(e,t,r)=>{s.emit(we(e),r),s.emit(Pe(t),r)},onLoading:(e,t)=>(s.on(Ie(e),t),()=>s.removeListener(Ie(e),t)),onLoadingById:(e,t)=>(s.on(Me(e),t),()=>s.removeListener(Me(e),t)),onRequestStart:(e,t)=>(s.on(ke(e),t),()=>s.removeListener(ke(e),t)),onRequestStartById:(e,t)=>(s.on($e(e),t),()=>s.removeListener($e(e),t)),onResponseStart:(e,t)=>(s.on(Fe(e),t),()=>s.removeListener(Fe(e),t)),onResponseStartById:(e,t)=>(s.on(_e(e),t),()=>s.removeListener(_e(e),t)),onUploadProgress:(e,t)=>(s.on(Se(e),t),()=>s.removeListener(Se(e),t)),onUploadProgressById:(e,t)=>(s.on(Ge(e),t),()=>s.removeListener(Ge(e),t)),onDownloadProgress:(e,t)=>(s.on(Ve(e),t),()=>s.removeListener(Ve(e),t)),onDownloadProgressById:(e,t)=>(s.on(He(e),t),()=>s.removeListener(He(e),t)),onResponse:(e,t)=>(s.on(Le(e),t),()=>s.removeListener(Le(e),t)),onResponseById:(e,t)=>(s.on(Ke(e),t),()=>s.removeListener(Ke(e),t)),onAbort:(e,t)=>(s.on(De(e),t),()=>s.removeListener(De(e),t)),onAbortById:(e,t)=>(s.on(Qe(e),t),()=>s.removeListener(Qe(e),t)),onRemove:(e,t)=>(s.on(we(e),t),()=>s.removeListener(we(e),t)),onRemoveById:(e,t)=>(s.on(Pe(e),t),()=>s.removeListener(Pe(e),t))});import Ot from"events";var Be=class{constructor(e,t){this.client=e;this.options=t;this.emitter=new Ot;this.setSeverity=e=>{this.severity=e};this.init=e=>({error:(t,...r)=>{this.logger({level:"error",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})},warning:(t,...r)=>{this.logger({level:"warning",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})},info:(t,...r)=>{this.logger({level:"info",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})},debug:(t,...r)=>{this.logger({level:"debug",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})}});var r,n;this.logger=((r=this.options)==null?void 0:r.logger)||xt,this.severity=((n=this.options)==null?void 0:n.severity)||2}};var jt=()=>{let s=new Date;return`${s.toLocaleTimeString()}(:${s.getMilliseconds()})`},xt=s=>{var e;if(s.enabled&&s.severity>=vt[s.level]){let t=bt[s.level],r=At[s.level],n=`%c[${s.module}]:[${jt()}]:`,o=`${r}${n} ${s.message}`;(e=s.extra)!=null&&e.length?(console.groupCollapsed(o,t),s.extra.forEach(a=>{console.log(a)}),console.groupEnd()):console.log(o,t)}};var Ue="background:rgba(0,0,0,0.2);padding:2px 5px;border-radius:5px;font-weight:bold;",bt={error:`${Ue}color:#db2525`,warning:`${Ue}color:#e1941e`,info:`${Ue}color:#1e74e1`,debug:`${Ue}color:#adadad`},At={error:"\u{1F6A8}",warning:"\u{1F6A7}",info:"\u2139\uFE0F",debug:"\u{1F6E9}\uFE0F"},vt={error:0,warning:1,info:2,debug:3};var Wt=s=>{try{return JSON.stringify(s)}catch(e){return""}},Ze=(s,e)=>l(void 0,null,function*(){let t=e;if(!e.requestOptions.disableRequestInterceptors){for(let r of s)if(t=yield r(e),!t)throw new Error("Request modifier must return request")}return t}),ze=(s,e,t)=>l(void 0,null,function*(){let r=e;if(!t.requestOptions.disableResponseInterceptors){for(let n of s)if(r=yield n(e,t),!r)throw new Error("Response modifier must return data")}return r}),qt=s=>{let e=ce()&&s.data instanceof FormData,t={};return e||(t["Content-Type"]="application/json"),Object.assign(t,s.headers),t},Ct=s=>ce()&&s instanceof FormData?s:Wt(s),It=s=>e=>{let{skipNull:t,skipEmptyString:r}=s;return!(r&&e===void 0||r&&e===""||t&&e===null)},F=(s,{encode:e,strict:t})=>e&&t?encodeURIComponent(s).replace(/[!'()*]/g,r=>`%${r.charCodeAt(0).toString(16).toUpperCase()}`):e?encodeURIComponent(s):s,Xt=(s,e,t)=>{let r=!It(t)(e);if(!s||r)return"";let n=()=>{var o,a;return e instanceof Date?((o=t.dateParser)==null?void 0:o.call(t,e))||e.toISOString():typeof e=="object"&&!Array.isArray(e)?((a=t.objectParser)==null?void 0:a.call(t,e))||JSON.stringify(e):String(e)};return`${F(s,t)}=${F(n(),t)}`},Yt=(s,e,t)=>{let{arrayFormat:r,arraySeparator:n}=t;return e.filter(It(t)).reduce((o,a,d)=>{switch(r){case"index":{let i=`${F(s,t)}[${F(String(d),t)}]=`;o.push(`${i}${F(String(a),t)}`);break}case"bracket":{let i=`${F(s,t)}[]=`;o.push(`${i}${F(String(a),t)}`);break}case"comma":{let i=!o.length&&`${F(s,t)}=`||"";return[[...o,`${i}${F(String(a),t)}`].join(",")]}case"separator":{let i=!o.length&&`${F(s,t)}=`||"";return[[...o,`${i}${F(String(a),t)}`].join(n||"|")]}case"bracket-separator":{let i=!o.length&&`${F(s,t)}[]=`||"";return[[...o,`${i}${F(String(a),t)}`].join(n||"|")]}default:{let i=`${F(s,t)}=`;o.push(`${i}${F(String(a),t)}`)}}return o},[]).join("&")},Mt=(s,e=wt)=>{if(!s||!Object.keys(s).length)return"";if(typeof s=="string")return s[0]==="?"?s:`?${s}`;let t=Object.entries(s).map(([r,n])=>Array.isArray(n)?Yt(r,n,e):Xt(r,n,e)).filter(Boolean).join("&");return t?`?${t}`:""};var Pt=class{constructor(e){this.options=e;this.__onErrorCallbacks=[];this.__onSuccessCallbacks=[];this.__onResponseCallbacks=[];this.__onAuthCallbacks=[];this.__onRequestCallbacks=[];this.requestManager=new Ce;this.loggerManager=new Be(this);this.defaultMethod="GET";this.defaultExtra=U;this.effects=[];this.abortKeyMapper=Ae;this.cacheKeyMapper=ut;this.queueKeyMapper=Ae;this.effectKeyMapper=Ae;this.stringifyQueryParams=e=>Mt(e,this.queryParamsConfig);this.headerMapper=qt;this.payloadMapper=Ct;this.logger=this.loggerManager.init("Client");this.setRequestDefaultOptions=e=>(this.requestDefaultOptions=e,this);this.setAdapterDefaultOptions=e=>(this.adapterDefaultOptions=e,this);this.setDebug=e=>(this.debug=e,this);this.setLoggerSeverity=e=>(this.loggerManager.setSeverity(e),this);this.setLogger=e=>(this.loggerManager=e(this),this);this.setQueryParamsConfig=e=>(this.queryParamsConfig=e,this);this.setStringifyQueryParams=e=>(this.stringifyQueryParams=e,this);this.setHeaderMapper=e=>(this.headerMapper=e,this);this.setPayloadMapper=e=>(this.payloadMapper=e,this);this.setAdapter=e=>(this.adapter=e(this),this);this.setDefaultMethod=e=>(this.defaultMethod=e,this);this.setDefaultExtra=e=>(this.defaultExtra=e,this);this.onAuth=e=>(this.__onAuthCallbacks.push(e),this);this.onError=e=>(this.__onErrorCallbacks.push(e),this);this.onSuccess=e=>(this.__onSuccessCallbacks.push(e),this);this.onRequest=e=>(this.__onRequestCallbacks.push(e),this);this.onResponse=e=>(this.__onResponseCallbacks.push(e),this);this.addEffect=e=>(this.effects=this.effects.concat(e),this);this.removeEffect=e=>{let t=typeof e=="string"?e:e.getEffectKey();return this.effects=this.effects.filter(r=>r.getEffectKey()!==t),this};this.setAbortKeyMapper=e=>{this.abortKeyMapper=e};this.setCacheKeyMapper=e=>{this.cacheKeyMapper=e};this.setQueueKeyMapper=e=>{this.queueKeyMapper=e};this.setEffectKeyMapper=e=>{this.effectKeyMapper=e};this.__modifyAuth=e=>l(this,null,function*(){return Ze(this.__onAuthCallbacks,e)});this.__modifyRequest=e=>l(this,null,function*(){return Ze(this.__onRequestCallbacks,e)});this.__modifyErrorResponse=(e,t)=>l(this,null,function*(){return ze(this.__onErrorCallbacks,e,t)});this.__modifySuccessResponse=(e,t)=>l(this,null,function*(){return ze(this.__onSuccessCallbacks,e,t)});this.__modifyResponse=(e,t)=>l(this,null,function*(){return ze(this.__onResponseCallbacks,e,t)});this.clear=()=>{let{appManager:e,cache:t,fetchDispatcher:r,submitDispatcher:n}=this.options;this.requestManager.abortControllers.clear(),this.fetchDispatcher.clear(),this.submitDispatcher.clear(),this.cache.clear(),this.requestManager.emitter.removeAllListeners(),this.fetchDispatcher.emitter.removeAllListeners(),this.submitDispatcher.emitter.removeAllListeners(),this.cache.emitter.removeAllListeners(),this.appManager=(e==null?void 0:e(this))||new ue,this.cache=(t==null?void 0:t(this))||new pe(this),this.fetchDispatcher=(r==null?void 0:r(this))||new N(this),this.submitDispatcher=(n==null?void 0:n(this))||new N(this)};this.createRequest=()=>e=>new J(this,e);let{url:t,adapter:r,appManager:n,cache:o,fetchDispatcher:a,submitDispatcher:d}=this.options;this.url=t,this.adapter=r||yt,this.appManager=(n==null?void 0:n(this))||new ue,this.cache=(o==null?void 0:o(this))||new pe(this),this.fetchDispatcher=(a==null?void 0:a(this))||new N(this),this.submitDispatcher=(d==null?void 0:d(this))||new N(this)}};var wt={strict:!0,encode:!0,arrayFormat:"bracket",arraySeparator:"",sort:!1,skipNull:!0,skipEmptyString:!0},U={headers:{}};export{Tt as AppEvents,ue as AppManager,pe as Cache,Pt as Client,je as DateInterval,N as Dispatcher,We as DispatcherRequestType,Re as HttpMethodsEnum,Be as LoggerManager,J as Request,rt as RequestEffect,Ce as RequestManager,yt as adapter,ee as appManagerInitialOptions,be as canRetryRequest,ye as defaultTimeout,Qe as getAbortByIdEventKey,De as getAbortEventKey,he as getAdapterBindings,qt as getAdapterHeaders,Ct as getAdapterPayload,mt as getAppManagerEvents,ht as getCacheData,ft as getCacheEvents,un as getCacheIdKey,qe as getCacheKey,xe as getDispatcherChangeEventKey,Te as getDispatcherDrainedEventKey,at as getDispatcherEvents,Ee as getDispatcherStatusEventKey,Ve as getDownloadProgressEventKey,He as getDownloadProgressIdEventKey,O as getErrorMessage,Wr as getIsEqualTimestamp,Ie as getLoadingEventKey,Me as getLoadingIdEventKey,Xe as getProgressData,$t as getProgressValue,we as getRemoveEventKey,Pe as getRemoveIdEventKey,_t as getRequestDispatcher,Ft as getRequestEta,ut as getRequestKey,Et as getRequestManagerEvents,ke as getRequestStartEventKey,$e as getRequestStartIdEventKey,it as getRequestType,Le as getResponseEventKey,nt as getResponseHeaders,Ke as getResponseIdEventKey,Fe as getResponseStartEventKey,_e as getResponseStartIdEventKey,ve as getRevalidateEventKey,Ae as getSimpleKey,lt as getStreamPayload,jt as getTime,me as getUniqueRequestId,Se as getUploadProgressEventKey,Ge as getUploadProgressIdEventKey,dt as getUploadSize,Ye as hasDocument,ce as hasWindow,Ze as interceptRequest,ze as interceptResponse,xt as logger,At as loggerIconLevels,bt as loggerStyles,ct as mocker,Rt as onDocumentEvent,de as onWindowEvent,fe as parseErrorResponse,ie as parseResponse,ot as sendRequest,vt as severity,wt as stringifyDefaultOptions,pt as stringifyKey,Mt as stringifyQueryParams,Wt as stringifyValue,U as xhrExtra};
|
|
1
|
+
var Dt=Object.defineProperty,Qt=Object.defineProperties;var Lt=Object.getOwnPropertyDescriptors;var ge=Object.getOwnPropertySymbols;var Je=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable;var Ne=(s,e,t)=>e in s?Dt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,F=(s,e)=>{for(var t in e||(e={}))Je.call(e,t)&&Ne(s,t,e[t]);if(ge)for(var t of ge(e))et.call(e,t)&&Ne(s,t,e[t]);return s},W=(s,e)=>Qt(s,Lt(e));var tt=(s,e)=>{var t={};for(var r in s)Je.call(s,r)&&e.indexOf(r)<0&&(t[r]=s[r]);if(s!=null&&ge)for(var r of ge(s))e.indexOf(r)<0&&et.call(s,r)&&(t[r]=s[r]);return t};var l=(s,e,t)=>new Promise((r,n)=>{var o=i=>{try{d(t.next(i))}catch(u){n(u)}},a=i=>{try{d(t.throw(i))}catch(u){n(u)}},d=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,a);d((t=t.apply(s,e)).next())});var rt=class{constructor(e){this.config=e;this.getEffectKey=()=>this.config.effectKey;this.onTrigger=e=>{var t,r;(r=(t=this.config).onTrigger)==null||r.call(t,e)};this.onStart=e=>{var t,r;(r=(t=this.config).onStart)==null||r.call(t,e)};this.onSuccess=(e,t)=>{var r,n;(n=(r=this.config).onSuccess)==null||n.call(r,e,t)};this.onError=(e,t)=>{var r,n;(n=(r=this.config).onError)==null||n.call(r,e,t)};this.onFinished=(e,t)=>{var r,n;(n=(r=this.config).onFinished)==null||n.call(r,e,t)}}};var je=(u=>(u[u.second=1e3]="second",u[u.minute=6e4]="minute",u[u.hour=36e5]="hour",u[u.day=864e5]="day",u[u.week=6048e5]="week",u[u.month30=2592e6]="month30",u[u.month31=26784e5]="month31",u[u.year=31536e6]="year",u[u.yearLeap=316224e5]="yearLeap",u))(je||{});var ye=1e3*5;var st=(s,e)=>l(void 0,null,function*(){let{makeRequest:t,fullUrl:r,config:n,payload:o,headers:a,onError:d,onResponseEnd:i,onTimeoutError:u,onRequestEnd:E,createAbortListener:h,onResponseProgress:v,onRequestProgress:c,onResponseStart:x,onBeforeRequest:g,onRequestStart:f,onSuccess:D}=yield he(s,e,0,{headers:{}}),{method:b="GET"}=s;return t(w=>{let T=new XMLHttpRequest;T.timeout=ye;let L=()=>T.abort();Object.entries(n).forEach(([A,R])=>{T[A]=R}),T.open(b,r,!0),Object.entries(a).forEach(([A,R])=>T.setRequestHeader(A,R));let y=h(0,U,L,w);T.upload.onprogress=c,T.onloadstart=()=>{E(),x()},T.onprogress=v,T.onloadend=()=>{i(),y()},T.ontimeout=()=>u(0,U,w),T.onreadystatechange=A=>{let R=A,K=4;if(R.target&&R.target.readyState===K){let{status:q}=R.target,k=String(q).startsWith("2")||String(q).startsWith("3"),P=nt(T.getAllResponseHeaders());if(k){let Q=ie(R.target.response);D(Q,q,{headers:P},w)}else{let Q=fe(R.target.response);d(Q,q,{headers:P},w)}}},g(),f(),T.send(o)})});import St from"http";import Gt from"stream";import Vt from"https";var me=s=>`${s}_${Date.now().toString(36)}_${Math.random().toString(36).substring(2)}`;var J=class{constructor(e,t,r){this.client=e;this.requestOptions=t;this.requestJSON=r;this.setHeaders=e=>this.clone({headers:e});this.setAuth=e=>this.clone({auth:e});this.setParams=e=>this.clone({params:e});this.setData=e=>this.clone({data:e});this.setQueryParams=e=>this.clone({queryParams:e});this.setOptions=e=>this.clone({options:e});this.setCancelable=e=>this.clone({cancelable:e});this.setRetry=e=>this.clone({retry:e});this.setRetryTime=e=>this.clone({retryTime:e});this.setGarbageCollection=e=>this.clone({garbageCollection:e});this.setCache=e=>this.clone({cache:e});this.setCacheTime=e=>this.clone({cacheTime:e});this.setQueued=e=>this.clone({queued:e});this.setAbortKey=e=>(this.updatedAbortKey=!0,this.clone({abortKey:e}));this.setCacheKey=e=>(this.updatedCacheKey=!0,this.clone({cacheKey:e}));this.setQueueKey=e=>(this.updatedQueueKey=!0,this.clone({queueKey:e}));this.setEffectKey=e=>(this.updatedEffectKey=!0,this.clone({effectKey:e}));this.setDeduplicate=e=>this.clone({deduplicate:e});this.setDeduplicateTime=e=>this.clone({deduplicateTime:e});this.setUsed=e=>this.clone({used:e});this.setOffline=e=>this.clone({offline:e});this.setMock=e=>{let t=function*(n){if(Array.isArray(e)){let o=0;for(;;)yield n[o],o=e.length===o+1?0:o+1}else for(;;)yield e};return this.mockData=e,this.mock=t(e),this};this.removeMock=()=>(this.mockData=null,this.mock=null,this);this.setDataMapper=e=>{let t=this.clone(void 0);return t.dataMapper=e,t};this.setRequestMapper=e=>{let t=this.clone(void 0);return t.requestMapper=e,t};this.setResponseMapper=e=>{let t=this.clone();return t.responseMapper=e,t};this.paramsMapper=(e,t)=>{let r=this.requestOptions.endpoint;return e&&Object.entries(e).forEach(([n,o])=>{r=r.replace(new RegExp(`:${n}`,"g"),String(o))}),t&&(r+=this.client.stringifyQueryParams(t)),r};this.abort=()=>{let{requestManager:e}=this.client;return e.abortByKey(this.abortKey),this.clone()};this.exec=e=>l(this,null,function*(){let{adapter:t,requestManager:r}=this.client,n=this.clone(e),o=me(this.queueKey);r.addAbortController(this.abortKey,o);let a=yield t(n,o);return r.removeAbortController(this.abortKey,o),n.responseMapper?n.responseMapper(a):a});this.send=e=>l(this,null,function*(){let o=e||{},{dispatcherType:t}=o,r=tt(o,["dispatcherType"]),n=this.clone(r);return ot(n,e)});var A,R,K,q,k,P,Q,G,S,$,B,V,X,Y,Z,j,te,re,z,se,ne,le,oe,ae,Oe,p,m,C,I;let{endpoint:n,headers:o,auth:a=!0,method:d=e.defaultMethod,options:i,cancelable:u=!1,retry:E=0,retryTime:h=500,garbageCollection:v=6e4*5,cache:c=!0,cacheTime:x=6e4*5,queued:g=!1,offline:f=!0,abortKey:D,cacheKey:b,queueKey:w,effectKey:T,deduplicate:L=!1,deduplicateTime:y=10}=F(F({},(R=(A=this.client).requestDefaultOptions)==null?void 0:R.call(A,t)),t);this.endpoint=(K=r==null?void 0:r.endpoint)!=null?K:n,this.headers=(q=r==null?void 0:r.headers)!=null?q:o,this.auth=(k=r==null?void 0:r.auth)!=null?k:a,this.method=d,this.params=r==null?void 0:r.params,this.data=r==null?void 0:r.data,this.queryParams=r==null?void 0:r.queryParams,this.options=(P=r==null?void 0:r.options)!=null?P:i,this.cancelable=(Q=r==null?void 0:r.cancelable)!=null?Q:u,this.retry=(G=r==null?void 0:r.retry)!=null?G:E,this.retryTime=(S=r==null?void 0:r.retryTime)!=null?S:h,this.garbageCollection=($=r==null?void 0:r.garbageCollection)!=null?$:v,this.cache=(B=r==null?void 0:r.cache)!=null?B:c,this.cacheTime=(V=r==null?void 0:r.cacheTime)!=null?V:x,this.queued=(X=r==null?void 0:r.queued)!=null?X:g,this.offline=(Y=r==null?void 0:r.offline)!=null?Y:f,this.abortKey=(j=(Z=r==null?void 0:r.abortKey)!=null?Z:D)!=null?j:this.client.abortKeyMapper(this),this.cacheKey=(re=(te=r==null?void 0:r.cacheKey)!=null?te:b)!=null?re:this.client.cacheKeyMapper(this),this.queueKey=(se=(z=r==null?void 0:r.queueKey)!=null?z:w)!=null?se:this.client.queueKeyMapper(this),this.effectKey=(le=(ne=r==null?void 0:r.effectKey)!=null?ne:T)!=null?le:this.client.effectKeyMapper(this),this.used=(oe=r==null?void 0:r.used)!=null?oe:!1,this.deduplicate=(ae=r==null?void 0:r.deduplicate)!=null?ae:L,this.deduplicateTime=(Oe=r==null?void 0:r.deduplicateTime)!=null?Oe:y,this.updatedAbortKey=(p=r==null?void 0:r.updatedAbortKey)!=null?p:!1,this.updatedCacheKey=(m=r==null?void 0:r.updatedCacheKey)!=null?m:!1,this.updatedQueueKey=(C=r==null?void 0:r.updatedQueueKey)!=null?C:!1,this.updatedEffectKey=(I=r==null?void 0:r.updatedEffectKey)!=null?I:!1}toJSON(){return{requestOptions:this.requestOptions,endpoint:this.endpoint,headers:this.headers,auth:this.auth,method:this.method,params:this.params,data:this.data,queryParams:this.queryParams,options:this.options,cancelable:this.cancelable,retry:this.retry,retryTime:this.retryTime,garbageCollection:this.garbageCollection,cache:this.cache,cacheTime:this.cacheTime,queued:this.queued,offline:this.offline,abortKey:this.abortKey,cacheKey:this.cacheKey,queueKey:this.queueKey,effectKey:this.effectKey,used:this.used,disableResponseInterceptors:this.requestOptions.disableResponseInterceptors,disableRequestInterceptors:this.requestOptions.disableRequestInterceptors,updatedAbortKey:this.updatedAbortKey,updatedCacheKey:this.updatedCacheKey,updatedQueueKey:this.updatedQueueKey,updatedEffectKey:this.updatedEffectKey,deduplicate:this.deduplicate,deduplicateTime:this.deduplicateTime}}clone(e){let t=this.toJSON(),r=W(F(F({},t),e),{abortKey:this.updatedAbortKey?(e==null?void 0:e.abortKey)||this.abortKey:void 0,cacheKey:this.updatedCacheKey?(e==null?void 0:e.cacheKey)||this.cacheKey:void 0,queueKey:this.updatedQueueKey?(e==null?void 0:e.queueKey)||this.queueKey:void 0,endpoint:this.paramsMapper((e==null?void 0:e.params)||this.params,(e==null?void 0:e.queryParams)||this.queryParams),queryParams:(e==null?void 0:e.queryParams)||this.queryParams,data:(e==null?void 0:e.data)||this.data}),n=new J(this.client,this.requestOptions,r);return n.dataMapper=this.dataMapper,n.responseMapper=this.responseMapper,n.requestMapper=this.requestMapper,n.mockData=this.mockData,n.mock=this.mock,n}};var Re=(o=>(o.get="GET",o.post="POST",o.put="PUT",o.patch="PATCH",o.delete="DELETE",o))(Re||{});var We=(n=>(n.oneByOne="one-by-one",n.allAtOnce="all-at-once",n.previousCanceled="previous-canceled",n.deduplicated="deduplicated",n))(We||{});var at=s=>({setDrained:(e,t)=>{s.emit(Te(e),t)},setQueueStatus:(e,t)=>{s.emit(Ee(e),t)},setQueueChanged:(e,t)=>{s.emit(xe(e),t)},onDrained:(e,t)=>(s.on(Te(e),t),()=>s.removeListener(Te(e),t)),onQueueStatus:(e,t)=>(s.on(Ee(e),t),()=>s.removeListener(Ee(e),t)),onQueueChange:(e,t)=>(s.on(xe(e),t),()=>s.removeListener(xe(e),t))});import kt from"events";var N=class{constructor(e,t){this.client=e;this.options=t;this.emitter=new kt;this.events=at(this.emitter);this.storage=new Map;this.requestCount=new Map;this.runningRequests=new Map;this.start=e=>{let t=this.getQueue(e);t.stopped=!1,this.setQueue(e,t),this.flushQueue(e),this.events.setQueueStatus(e,t)};this.pause=e=>{let t=this.getQueue(e);t.stopped=!0,this.setQueue(e,t),this.events.setQueueStatus(e,t)};this.stop=e=>{let t=this.getQueue(e);t.stopped=!0,this.setQueue(e,t),this.cancelRunningRequests(e),this.events.setQueueStatus(e,t)};this.getQueuesKeys=()=>Array.from(this.storage.keys());this.getQueue=e=>{let t={requests:[],stopped:!1};return this.storage.get(e)||t};this.getRequest=(e,t)=>{let r={requests:[],stopped:!1};return(this.storage.get(e)||r).requests.find(o=>o.requestId===t)};this.getIsActiveQueue=e=>{let t=this.getQueue(e),r=t.requests.some(o=>!o.stopped),n=!t.stopped;return r&&n};this.addQueueElement=(e,t)=>{let r=this.getQueue(e);r.requests.push(t),this.setQueue(e,r)};this.setQueue=(e,t)=>{var r,n;return this.storage.set(e,t),(n=(r=this.options)==null?void 0:r.onUpdateStorage)==null||n.call(r,e,t),this.events.setQueueChanged(e,t),t};this.clearQueue=e=>{var n,o;let t=this.getQueue(e),r={requests:[],stopped:t.stopped};return this.storage.set(e,r),(o=(n=this.options)==null?void 0:n.onDeleteFromStorage)==null||o.call(n,e,r),this.events.setQueueChanged(e,r),r};this.flushQueue=e=>l(this,null,function*(){let t=this.getQueue(e),r=this.getRunningRequests(e),n=t.requests.find(E=>!E.stopped),o=t&&t.stopped,a=!this.client.appManager.isOnline,d=!(n!=null&&n.request.queued),i=!r.length,u=!n;o||a||u?this.logger.debug("Skipping queue trigger",{isStopped:o,isOffline:a,isEmpty:u}):d?t.requests.forEach(E=>{this.hasRunningRequest(e,E.requestId)||this.performRequest(E)}):i&&(yield this.performRequest(n),this.flushQueue(e))});this.flush=()=>l(this,null,function*(){let e=this.getQueuesKeys();for(let t of e)this.getQueue(t)&&this.flushQueue(t)});this.clear=()=>{var t,r;this.getQueuesKeys().forEach(n=>this.cancelRunningRequests(n)),this.runningRequests.clear(),this.storage.clear(),(r=(t=this.options)==null?void 0:t.onClearStorage)==null||r.call(t,this)};this.startRequest=(e,t)=>{let r=this.getQueue(e),n=r.requests.find(o=>o.requestId===t);n&&(n.stopped=!1,this.setQueue(e,r),this.flushQueue(e),this.events.setQueueStatus(e,r))};this.stopRequest=(e,t)=>{let r=this.getQueue(e),n=r.requests.find(o=>o.requestId===t);n&&(n.stopped=!0,this.setQueue(e,r),this.cancelRunningRequest(e,t),this.events.setQueueStatus(e,r))};this.getAllRunningRequest=()=>Array.from(this.runningRequests.values()).flat();this.getRunningRequests=e=>this.runningRequests.get(e)||[];this.getRunningRequest=(e,t)=>this.getRunningRequests(e).find(n=>n.requestId===t);this.addRunningRequest=(e,t,r)=>{let n=this.getRunningRequests(e);n.push({requestId:t,request:r}),this.runningRequests.set(e,n)};this.hasRunningRequests=e=>!!this.getRunningRequests(e).length;this.hasRunningRequest=(e,t)=>!!this.getRunningRequests(e).find(n=>n.requestId===t);this.cancelRunningRequests=e=>{var t;(t=this.runningRequests.get(e))==null||t.forEach(r=>{this.client.requestManager.abortByRequestId(r.request.abortKey,r.requestId)}),this.deleteRunningRequests(e)};this.cancelRunningRequest=(e,t)=>{let r=this.getRunningRequests(e).filter(n=>n.requestId===t?(this.client.requestManager.abortByRequestId(n.request.abortKey,n.requestId),!1):!0);this.runningRequests.set(e,r)};this.deleteRunningRequests=e=>{this.runningRequests.set(e,[])};this.deleteRunningRequest=(e,t)=>{let r=this.getRunningRequests(e);this.runningRequests.set(e,r.filter(n=>n.requestId!==t))};this.getQueueRequestCount=e=>this.requestCount.get(e)||0;this.incrementQueueRequestCount=e=>{let t=this.requestCount.get(e)||0;this.requestCount.set(e,t+1)};this.createStorageElement=e=>({requestId:me(e.queueKey),timestamp:+new Date,request:e,retries:0,stopped:!1});this.add=e=>{let{queueKey:t}=e,r=this.createStorageElement(e),{requestId:n}=r,o=this.getQueue(t),[a]=o.requests.slice(-1),d=it(e,a);switch(this.logger.debug("Adding request to queue",{requestType:d,request:e,requestId:n}),d){case"one-by-one":return this.addQueueElement(t,r),this.flushQueue(t),n;case"previous-canceled":return this.cancelRunningRequests(t),this.clearQueue(t),this.addQueueElement(t,r),this.flushQueue(t),n;case"deduplicated":return o.requests[0].requestId;default:return this.addQueueElement(t,r),this.flushQueue(t),n}};this.delete=(e,t,r)=>{var a,d;this.logger.debug("Deleting request",{queueKey:e,requestId:t,abortKey:r});let n=this.getQueue(e),o=n.requests.find(i=>i.requestId===t);if(!!o)return n.requests=n.requests.filter(i=>i.requestId!==t),this.storage.set(e,n),this.hasRunningRequest(e,t)&&(this.deleteRunningRequest(e,t),this.client.requestManager.abortByRequestId(r,t)),(d=(a=this.options)==null?void 0:a.onDeleteFromStorage)==null||d.call(a,e,n),this.events.setQueueChanged(e,n),this.client.requestManager.events.emitRemove(e,t,{requestId:t,request:o.request}),n.requests.length||this.events.setDrained(e,n),n};this.performRequest=e=>l(this,null,function*(){var A;let{request:t,requestId:r}=e;this.logger.info("Performing request",{request:t,requestId:r});let{retry:n,retryTime:o,queueKey:a,cacheKey:d,abortKey:i,offline:u}=t,{adapter:E,requestManager:h,cache:v,appManager:c}=this.client,x=be(e.retries,n),g=!c.isOnline&&u,f=this.hasRunningRequest(a,r),D=e.stopped;if(g||f||D)return this.logger.warning("Unable to perform request",{isOffline:g,isAlreadyRunning:f,isStopped:D});this.addRunningRequest(a,r,t),h.events.emitLoading(a,r,{queueKey:a,requestId:r,loading:!0,isRetry:!!e.retries,isOffline:g}),this.incrementQueueRequestCount(a),h.addAbortController(i,r);let b=yield E(t,r);h.removeAbortController(i,r);let w=!c.isOnline,T=O("abort").message===((A=b.error)==null?void 0:A.message),L=!this.hasRunningRequest(a,r)||T;this.deleteRunningRequest(a,r);let y={isCanceled:L,isOffline:w,retries:e.retries,timestamp:+new Date};if(h.events.emitLoading(a,r,{queueKey:a,requestId:r,loading:!1,isRetry:!!e.retries,isOffline:g}),h.events.emitResponse(d,r,b,y),v.set(t,F(F({},b),y)),this.logger.info("Request finished",{requestId:r,request:t,response:b,requestDetails:y}),L){let R=this.getQueue(a),K=R.requests.find(q=>q.requestId===r);return!R.stopped&&!(K!=null&&K.stopped)?(this.logger.debug("Request paused",{response:b,requestDetails:y,request:t}),this.delete(a,r,i)):this.logger.debug("Request canceled",{response:b,requestDetails:y,request:t})}if(!b.success&&w)return u?this.logger.debug("Awaiting for network restoration",{response:b,requestDetails:y,request:t}):(this.logger.warning("Removing non-offline request",{response:b,requestDetails:y,request:t}),this.delete(a,r,i));if(b.success)return this.delete(a,r,i),this.logger.debug("Successful response, removing request from queue.",{response:b,requestDetails:y,request:t});!b.success&&x?(this.logger.debug("Waiting for retry",{response:b,requestDetails:y,request:t}),setTimeout(()=>{this.logger.warning("Error response, performing retry"),this.performRequest(W(F({},e),{retries:e.retries+1}))},o||0)):(this.logger.error("All retries have been used. Removing request from queue."),this.delete(a,r,i))});var r,n,o;this.logger=e.loggerManager.init("Dispatcher"),(r=this.options)!=null&&r.storage&&(this.storage=this.options.storage),this.client.appManager.events.onOnline(()=>{this.flush()}),(o=(n=this.options)==null?void 0:n.onInitialization)==null||o.call(n,this)}};var Te=s=>`${s}-drained-event`,Ee=s=>`${s}-status-event`,xe=s=>`${s}-change-event`,Wr=(s,e,t)=>t?t-s<=e:!1,be=(s,e)=>!!(e&&s<e),it=(s,e)=>{let{queued:t,cancelable:r,deduplicate:n}=s,o=e?+new Date-e.timestamp<=s.deduplicateTime:!1;return t?"one-by-one":r?"previous-canceled":o&&n?"deduplicated":"all-at-once"};var pt=s=>{try{if(typeof s=="string")return s;if(s==null)return"";let e=JSON.stringify(s);if(typeof e!="string")throw new Error;return e}catch(e){return""}},$t=({loaded:s,total:e})=>!s||!e?0:Number((s*100/e).toFixed(0)),Ft=(s,e,{total:t,loaded:r})=>{let n=+e-+s||1,o=r/n,a=Math.max(t,r),d=a-r,i=o?d/o:null;return{timeLeft:a===r?0:i,sizeLeft:d}},Xe=(s,e,t)=>{let{total:r,loaded:n}=t;if(Number.isNaN(r)||Number.isNaN(n))return{progress:0,timeLeft:0,sizeLeft:0,total:0,loaded:0,startTimestamp:+s};let{timeLeft:o,sizeLeft:a}=Ft(s,e,t);return{progress:$t(t),timeLeft:o,sizeLeft:a,total:r,loaded:n,startTimestamp:+s}},Ae=s=>`${s.method}_${s.requestOptions.endpoint}_${s.cancelable}`,ut=(s,e)=>{let t=pt(s.method),r=e?s.requestOptions.endpoint:pt(s.endpoint);return`${t}_${r}`},_t=(s,e="auto")=>{let{fetchDispatcher:t,submitDispatcher:r}=s.client,n=s.method==="GET",o=e==="auto"&&n||e==="fetch";return[o?t:r,o]},ot=(s,e)=>{let{requestManager:t}=s.client,[r]=_t(s,e==null?void 0:e.dispatcherType);return new Promise(n=>{var x;let o=!1,a=r.add(s);(x=e==null?void 0:e.onSettle)==null||x.call(e,a,s);let d=t.events.onRequestStartById(a,(...g)=>{var f;return(f=e==null?void 0:e.onRequestStart)==null?void 0:f.call(e,...g)}),i=t.events.onResponseStartById(a,(...g)=>{var f;return(f=e==null?void 0:e.onResponseStart)==null?void 0:f.call(e,...g)}),u=t.events.onUploadProgressById(a,(...g)=>{var f;return(f=e==null?void 0:e.onUploadProgress)==null?void 0:f.call(e,...g)}),E=t.events.onDownloadProgressById(a,(...g)=>{var f;return(f=e==null?void 0:e.onDownloadProgress)==null?void 0:f.call(e,...g)}),h=t.events.onResponseById(a,(g,f)=>{var L;o=!0;let D=(L=s.responseMapper)==null?void 0:L.call(s,g),b=s.offline&&f.isOffline,w=be(f.retries,s.retry),T=(y,A)=>{var R;!y&&b||!y&&w||((R=e==null?void 0:e.onResponse)==null||R.call(e,A,f),n(A),c())};if(D instanceof Promise)l(void 0,null,function*(){let y=yield D,{success:A}=y;T(A,y)});else{let y=D||g,{success:A}=y;T(A,y)}}),v=t.events.onRemoveById(a,(...g)=>{var f;o||((f=e==null?void 0:e.onRemove)==null||f.call(e,...g),n({data:null,status:null,success:null,error:O("deleted"),extra:s.client.defaultExtra}),c())});function c(){d(),i(),u(),E(),h(),v()}})};var ct=(v,c)=>l(void 0,[v,c],function*(s,{onError:e,onResponseEnd:t,onTimeoutError:r,onRequestEnd:n,createAbortListener:o,onResponseProgress:a,onRequestProgress:d,onResponseStart:i,onBeforeRequest:u,onRequestStart:E,onSuccess:h}){var D,b;let x=((D=s.requestOptions.options)==null?void 0:D.timeout)||((b=s.options)==null?void 0:b.timeout),g=s.mock.next(),f=g.value instanceof Function?yield g.value(s):g.value;return new Promise(w=>{let{data:T,config:L={},extra:y}=f,{status:A=200,success:R=!0,responseDelay:K=5,requestSentDuration:q=0,responseReceivedDuration:k=0}=L,P=()=>x&&q+k>x?[Math.floor(x/2)-1,Math.floor(x/2)-1]:[q,k],[Q,G]=P();o(0,{},()=>{},w),u(),E();let S=(B,V)=>new Promise(X=>{let Y=+new Date;setInterval(()=>{let Z=+new Date,j=Math.min(B,Z-Y);j>=B&&X(!0),V({total:B,loaded:j})},20)}),$=()=>l(void 0,null,function*(){yield S(Q,d),n(),i(),yield S(G,a),R?h(T,A,y||{},w):e(T,A,y||{},w)});x&&K>x?setTimeout(()=>r(0,y||{},w),x+1):setTimeout($,K),t()})});var he=(s,e,t,r)=>l(void 0,null,function*(){let{url:n,requestManager:o,loggerManager:a,headerMapper:d,payloadMapper:i}=s.client,u=a.init("Adapter"),E=null,h=null,v=null,c=s,x=1,g=1,f=0,D=0;u.debug("Starting request middleware callbacks");try{c=yield c.client.__modifyRequest(s),c.auth&&(c=yield c.client.__modifyAuth(s)),c.requestMapper&&(c=yield c.requestMapper(c,e))}catch(p){E=p}let{client:b,abortKey:w,queueKey:T,endpoint:L,data:y}=c,A=n+L,R=b.effects.filter(p=>c.effectKey===p.getEffectKey()),K=d(c),q=y;try{q=i(y),c.dataMapper&&(q=yield c.dataMapper(y))}catch(p){E=p}let k=F({},c.options),P=()=>h,Q=()=>v,G=(p,m)=>{if(!m)return p;let C=Number(m.total||0),I=Number(m.loaded||0);return Math.max(C,I,p)},S=(p,m,C)=>{let I=Xe(new Date(p),new Date(m),C);f!==100&&(f=I.total,o.events.emitUploadProgress(T,e,I,{requestId:e,request:c}))},$=(p,m,C)=>{let I=Xe(new Date(p),new Date(m),C);D!==100&&(D=I.total,o.events.emitDownloadProgress(T,e,I,{requestId:e,request:c}))},B=()=>{R.forEach(p=>p.onTrigger(c))},V=p=>{R.forEach(C=>C.onStart(c)),p!=null&&p.total&&(x=G(x,p));let m={total:x,loaded:(p==null?void 0:p.loaded)||0};return h=+new Date,S(h,h,m),o.events.emitRequestStart(T,e,{requestId:e,request:c}),h},X=p=>{h||(h=+new Date),x=G(x,p);let m=+new Date;return S(h,m,{total:x,loaded:p.loaded||0}),m},Y=()=>{h||(h=+new Date);let p=+new Date;return S(h,p,{total:x,loaded:x}),p},Z=p=>{v=+new Date,g=G(g,p);let m={total:g,loaded:(p==null?void 0:p.loaded)||0};return $(v,v,m),o.events.emitResponseStart(T,e,{requestId:e,request:c}),v},j=p=>{v||(v=+new Date);let m=+new Date;return g=G(g,p),$(v,m,{total:p.total||g,loaded:p.loaded||0}),m},te=()=>{v||(v=+new Date);let p=+new Date;return $(v,p,{total:g,loaded:g}),p},re=(p,m,C,I)=>l(void 0,null,function*(){let M={data:p,error:null,success:!0,status:m,extra:C};return M=yield c.client.__modifyResponse(M,c),M=yield c.client.__modifySuccessResponse(M,c),R.forEach(H=>H.onSuccess(M,c)),R.forEach(H=>H.onFinished(M,c)),I(M),M}),z=(p,m,C,I)=>l(void 0,null,function*(){let M={data:null,status:m,error:p,success:!1,extra:C};return M=yield c.client.__modifyResponse(M,c),M=yield c.client.__modifyErrorResponse(M,c),R.forEach(H=>H.onError(M,c)),R.forEach(H=>H.onFinished(M,c)),I(M),M}),se=(p,m,C)=>{let I=O("abort");return z(I,p,m,C)},ne=(p,m,C)=>{let I=O("timeout");return z(I,p,m,C)},le=(p,m,C)=>{let I=O();return z(I,p,m,C)},oe=()=>o.getAbortController(w,e),ae=(p,m,C,I)=>{let M=oe();if(!M)throw new Error("Controller is not found");let H=()=>{se(p,m,I),C(),o.events.emitAbort(w,e,c)};return M.signal.aborted&&H(),M.signal.addEventListener("abort",H),()=>M.signal.removeEventListener("abort",H)};return{fullUrl:A,data:y,headers:K,payload:q,config:k,getAbortController:oe,getRequestStartTimestamp:P,getResponseStartTimestamp:Q,createAbortListener:ae,onBeforeRequest:B,onRequestStart:V,onRequestProgress:X,onRequestEnd:Y,onResponseStart:Z,onResponseProgress:j,onResponseEnd:te,onSuccess:re,onAbortError:se,onTimeoutError:ne,onUnexpectedError:le,onError:z,makeRequest:p=>E?z(E,t,r,()=>null):s.mock?ct(c,{onError:z,onResponseEnd:te,onTimeoutError:ne,onRequestEnd:Y,createAbortListener:ae,onResponseProgress:j,onRequestProgress:X,onResponseStart:Z,onBeforeRequest:B,onRequestStart:V,onSuccess:re}):new Promise(p)}});var O=s=>s==="timeout"?new Error("Request timeout"):s==="abort"?new Error("Request cancelled"):new Error("Unexpected error"),nt=s=>{let e=s.trim().split(/[\r\n]+/),t={};return e.forEach(r=>{let n=r.split(": "),o=n.shift(),a=n.join(": ");t[o]=a}),t},ie=s=>{try{return JSON.parse(s)}catch(e){return s}},fe=s=>s?ie(s):O(),dt=s=>s.length,lt=s=>s;var gt=(s,e)=>l(void 0,null,function*(){let{makeRequest:t,fullUrl:r,config:n,headers:o,payload:a,onError:d,onResponseEnd:i,onTimeoutError:u,onRequestEnd:E,createAbortListener:h,onResponseProgress:v,onRequestProgress:c,onResponseStart:x,onBeforeRequest:g,onRequestStart:f,onSuccess:D}=yield he(s,e,0,U),{method:b="GET",client:w}=s,T=w.url.includes("https://")?Vt:St,L={path:r,method:b,headers:o,timeout:ye};Object.entries(n).forEach(([q,k])=>{L[q]=k});let y=()=>null;g();let A=a?Number(dt(a)):0,R=0,K=yield lt(a);return t(q=>{let k=T.request(L,P=>{P.setEncoding("utf8"),y=h(0,U,P.destroy,q);let Q="",G=Number(P.headers["content-length"]),S=0;P.on("data",$=>{Q||x(),S+=$.length,Q+=$,v({total:G,loaded:S})}),P.on("end",()=>{let{statusCode:$}=P;if(String($).startsWith("2")||String($).startsWith("3")){let V=ie(Q);D(V,$,{headers:P.headers},q)}else{let V=fe(Q);d(V,$,{headers:P.headers},q)}y(),i()})});k.on("timeout",()=>u(0,U,q)),k.on("error",P=>d(P,0,U,q)),K?Gt.Readable.from(K,{objectMode:!1}).on("data",Q=>{R||f(),R+=Q.length,c({total:A,loaded:R})}).on("end",()=>{E()}).pipe(k):k.end()})});var yt=(s,e)=>l(void 0,null,function*(){return typeof XMLHttpRequest!="undefined"?st(s,e):gt(s,e)});import Bt from"events";var pe=class{constructor(e,t){this.client=e;this.options=t;this.emitter=new Bt;this.garbageCollectors=new Map;this.set=(e,t)=>{var E,h,v;this.logger.debug("Processing cache response",{request:e,response:t});let{cacheKey:r,cache:n,cacheTime:o,garbageCollection:a}=e,d=this.storage.get(r),i=ht(d,t),u=W(F({},i),{cacheTime:o,clearKey:this.clearKey,garbageCollection:a});if(this.events.emitCacheData(r,u),this.logger.debug("Emitting cache response",{request:e,data:i}),!n)return this.logger.debug("Prevented saving response to cache",{request:e,data:i});t.success&&(this.logger.debug("Saving response to cache storage",{request:e,data:i}),this.storage.set(r,u),(E=this.lazyStorage)==null||E.set(r,u),(v=(h=this.options)==null?void 0:h.onChange)==null||v.call(h,r,u),this.scheduleGarbageCollector(r))};this.get=e=>(this.getLazyResource(e),this.storage.get(e));this.keys=()=>{let e=this.storage.keys();return Array.from(e)};this.delete=e=>{var t,r,n;this.logger.debug("Deleting cache element",{cacheKey:e}),this.storage.delete(e),(r=(t=this.options)==null?void 0:t.onDelete)==null||r.call(t,e),(n=this.lazyStorage)==null||n.delete(e)};this.revalidate=e=>l(this,null,function*(){this.logger.debug("Revalidating cache element",{cacheKey:e});let t=yield this.getLazyKeys();if(typeof e=="string")this.events.emitRevalidation(e),this.delete(e);else for(let r of t)e.test(r)&&(this.events.emitRevalidation(r),this.delete(r))});this.getLazyResource=e=>l(this,null,function*(){var a;let t=yield(a=this.lazyStorage)==null?void 0:a.get(e),r=this.storage.get(e);if(this.lazyStorage&&t){let d=+new Date,i=r?r.timestamp<t.timestamp:!0,u=t.cacheTime<=d-t.timestamp,E=t.clearKey===this.clearKey;if(E||this.lazyStorage.delete(e),i&&!u&&E)return this.storage.set(e,t),this.events.emitCacheData(e,t),t}let o=(r==null?void 0:r.clearKey)===this.clearKey;return r&&!o&&this.delete(e),r});this.getLazyKeys=()=>l(this,null,function*(){var n;let e=yield(n=this.lazyStorage)==null?void 0:n.keys(),t=Array.from(e||[]),r=Array.from(this.storage.keys());return[...new Set([...t,...r])]});this.scheduleGarbageCollector=e=>l(this,null,function*(){let t=yield this.getLazyResource(e);if(clearTimeout(this.garbageCollectors.get(e)),t){let r=t.garbageCollection+t.timestamp-+new Date;t.garbageCollection!==null&&JSON.stringify(t.garbageCollection)==="null"?this.logger.info("Cache value is Infinite",{cacheKey:e}):r>=0?this.garbageCollectors.set(e,setTimeout(()=>{this.client.appManager.isOnline&&(this.logger.info("Garbage collecting cache element",{cacheKey:e}),this.delete(e))},r)):this.client.appManager.isOnline&&(this.logger.info("Garbage collecting cache element",{cacheKey:e}),this.delete(e))}});this.clear=()=>l(this,null,function*(){this.storage.clear()});var r,n,o,a,d;this.storage=((r=this.options)==null?void 0:r.storage)||new Map,this.events=ft(this.emitter),(o=(n=this.options)==null?void 0:n.onInitialization)==null||o.call(n,this),this.clearKey=((a=this.options)==null?void 0:a.clearKey)||"",this.lazyStorage=(d=this.options)==null?void 0:d.lazyStorage,this.logger=this.client.loggerManager.init("Cache"),this.getLazyKeys().then(i=>{i.forEach(this.scheduleGarbageCollector)}),this.client.appManager.events.onOnline(()=>{this.getLazyKeys().then(i=>{i.forEach(this.scheduleGarbageCollector)})})}};var ht=(s,e)=>{let{data:t,success:r}=e,n=!r&&s?s.data:null,o=t||n;return W(F({},e),{data:o})},ve=s=>`${s}_revalidate`,qe=s=>`${s}_cache`,un=s=>`${s}_cache_by_id`;var ft=s=>({emitCacheData:(e,t)=>{s.emit(qe(e),t)},emitRevalidation:e=>{s.emit(ve(e))},onData:(e,t)=>(s.on(qe(e),t),()=>s.removeListener(qe(e),t)),onRevalidate:(e,t)=>(s.on(ve(e),t),()=>s.removeListener(ve(e),t))});import Ut from"events";var ue=class{constructor(e){this.options=e;this.emitter=new Ut;this.events=mt(this.emitter);this.setInitialFocus=e=>l(this,null,function*(){typeof e=="function"?(this.isFocused=!1,this.isFocused=yield e()):this.isFocused=e});this.setInitialOnline=e=>l(this,null,function*(){typeof e=="function"?(this.isOnline=!1,this.isOnline=yield e()):this.isOnline=e});this.setFocused=e=>{this.isFocused=e,e?this.events.emitFocus():this.events.emitBlur()};this.setOnline=e=>{this.isOnline=e,e?this.events.emitOnline():this.events.emitOffline()};let{focusEvent:t=ee.focusEvent,onlineEvent:r=ee.onlineEvent,initiallyFocused:n=ee.initiallyFocused,initiallyOnline:o=ee.initiallyOnline}=this.options||ee;this.setInitialFocus(n),this.setInitialOnline(o),t(this.setFocused),r(this.setOnline),this.isBrowser=Ye()}};var ce=()=>{try{return Boolean(window&&window.addEventListener)}catch(s){return!1}},Ye=()=>{try{return Boolean(ce()&&window.document&&window.document.addEventListener)}catch(s){return!1}},de=(s,e,t)=>{ce()&&window.addEventListener(s,e,t)},Rt=(s,e,t)=>{Ye()&&window.document.addEventListener(s,e,t)};var mt=s=>({emitFocus:()=>{s.emit("focus")},emitBlur:()=>{s.emit("blur")},emitOnline:()=>{s.emit("online")},emitOffline:()=>{s.emit("offline")},onFocus:e=>(s.on("focus",e),()=>s.removeListener("focus",e)),onBlur:e=>(s.on("blur",e),()=>s.removeListener("blur",e)),onOnline:e=>(s.on("online",e),()=>s.removeListener("online",e)),onOffline:e=>(s.on("offline",e),()=>s.removeListener("offline",e))});var Tt=(n=>(n.focus="focus",n.blur="blur",n.online="online",n.offline="offline",n))(Tt||{}),ee={initiallyFocused:!0,initiallyOnline:!0,focusEvent:s=>{Rt("visibilitychange",()=>s(!0)),de("focus",()=>s(!0)),de("blur",()=>s(!1))},onlineEvent:s=>{de("online",()=>s(!0)),de("offline",()=>s(!1))}};import zt from"events";var Ce=class{constructor(){this.emitter=new zt;this.events=Et(this.emitter);this.abortControllers=new Map;this.addAbortController=(e,t)=>{let r=this.abortControllers.get(e);if(!r){let o=new Map;r=o,this.abortControllers.set(e,o)}let n=r.get(t);(!n||n.signal.aborted)&&r.set(t,new AbortController)};this.getAbortController=(e,t)=>{var r;return(r=this.abortControllers.get(e))==null?void 0:r.get(t)};this.removeAbortController=(e,t)=>{var r;(r=this.abortControllers.get(e))==null||r.delete(t)};this.useAbortController=(e,t)=>{var n;let r=(n=this.abortControllers.get(e))==null?void 0:n.get(t);r==null||r.abort()};this.abortByKey=e=>{let t=this.abortControllers.get(e);t&&Array.from(t.entries()).forEach(([n])=>{this.useAbortController(e,n)})};this.abortByRequestId=(e,t)=>{this.useAbortController(e,t)};this.abortAll=()=>{Array.from(this.abortControllers.entries()).forEach(([t,r])=>{Array.from(r.entries()).forEach(([o])=>{this.useAbortController(t,o)})})}}};var Ie=s=>`${s}-loading-event`,Me=s=>`${s}-loading-event-by-id`,we=s=>`${s}-remove-event`,Pe=s=>`${s}-remove-event-by-id`,De=s=>`${s}-request-abort`,Qe=s=>`${s}-request-abort-by-id`,Le=s=>`${s}-response`,Ke=s=>`${s}-response-by-id`,ke=s=>`${s}-request-start`,$e=s=>`${s}-request-start-by-id`,Fe=s=>`${s}-response-start`,_e=s=>`${s}-response-start-by-id`,Se=s=>`${s}-request-progress`,Ge=s=>`${s}-request-progress-by-id`,Ve=s=>`${s}-response-progress`,He=s=>`${s}-response-progress-by-id`;var Et=s=>({emitLoading:(e,t,r)=>{s.emit(Me(t),r),s.emit(Ie(e),r)},emitRequestStart:(e,t,r)=>{s.emit($e(t),r),s.emit(ke(e),r)},emitResponseStart:(e,t,r)=>{s.emit(_e(t),r),s.emit(Fe(e),r)},emitUploadProgress:(e,t,r,n)=>{s.emit(Ge(t),r,n),s.emit(Se(e),r,n)},emitDownloadProgress:(e,t,r,n)=>{s.emit(He(t),r,n),s.emit(Ve(e),r,n)},emitResponse:(e,t,r,n)=>{s.emit(Ke(t),r,n),s.emit(Le(e),r,n)},emitAbort:(e,t,r)=>{s.emit(Qe(t),r),s.emit(De(e),r)},emitRemove:(e,t,r)=>{s.emit(we(e),r),s.emit(Pe(t),r)},onLoading:(e,t)=>(s.on(Ie(e),t),()=>s.removeListener(Ie(e),t)),onLoadingById:(e,t)=>(s.on(Me(e),t),()=>s.removeListener(Me(e),t)),onRequestStart:(e,t)=>(s.on(ke(e),t),()=>s.removeListener(ke(e),t)),onRequestStartById:(e,t)=>(s.on($e(e),t),()=>s.removeListener($e(e),t)),onResponseStart:(e,t)=>(s.on(Fe(e),t),()=>s.removeListener(Fe(e),t)),onResponseStartById:(e,t)=>(s.on(_e(e),t),()=>s.removeListener(_e(e),t)),onUploadProgress:(e,t)=>(s.on(Se(e),t),()=>s.removeListener(Se(e),t)),onUploadProgressById:(e,t)=>(s.on(Ge(e),t),()=>s.removeListener(Ge(e),t)),onDownloadProgress:(e,t)=>(s.on(Ve(e),t),()=>s.removeListener(Ve(e),t)),onDownloadProgressById:(e,t)=>(s.on(He(e),t),()=>s.removeListener(He(e),t)),onResponse:(e,t)=>(s.on(Le(e),t),()=>s.removeListener(Le(e),t)),onResponseById:(e,t)=>(s.on(Ke(e),t),()=>s.removeListener(Ke(e),t)),onAbort:(e,t)=>(s.on(De(e),t),()=>s.removeListener(De(e),t)),onAbortById:(e,t)=>(s.on(Qe(e),t),()=>s.removeListener(Qe(e),t)),onRemove:(e,t)=>(s.on(we(e),t),()=>s.removeListener(we(e),t)),onRemoveById:(e,t)=>(s.on(Pe(e),t),()=>s.removeListener(Pe(e),t))});import Ot from"events";var Be=class{constructor(e,t){this.client=e;this.options=t;this.emitter=new Ot;this.setSeverity=e=>{this.severity=e};this.init=e=>({error:(t,...r)=>{this.logger({level:"error",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})},warning:(t,...r)=>{this.logger({level:"warning",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})},info:(t,...r)=>{this.logger({level:"info",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})},debug:(t,...r)=>{this.logger({level:"debug",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})}});var r,n;this.logger=((r=this.options)==null?void 0:r.logger)||xt,this.severity=((n=this.options)==null?void 0:n.severity)||2}};var jt=()=>{let s=new Date;return`${s.toLocaleTimeString()}(:${s.getMilliseconds()})`},xt=s=>{var e;if(s.enabled&&s.severity>=vt[s.level]){let t=bt[s.level],r=At[s.level],n=`%c[${s.module}]:[${jt()}]:`,o=`${r}${n} ${s.message}`;(e=s.extra)!=null&&e.length?(console.groupCollapsed(o,t),s.extra.forEach(a=>{console.log(a)}),console.groupEnd()):console.log(o,t)}};var Ue="background:rgba(0,0,0,0.2);padding:2px 5px;border-radius:5px;font-weight:bold;",bt={error:`${Ue}color:#db2525`,warning:`${Ue}color:#e1941e`,info:`${Ue}color:#1e74e1`,debug:`${Ue}color:#adadad`},At={error:"\u{1F6A8}",warning:"\u{1F6A7}",info:"\u2139\uFE0F",debug:"\u{1F6E9}\uFE0F"},vt={error:0,warning:1,info:2,debug:3};var Wt=s=>{try{return JSON.stringify(s)}catch(e){return""}},Ze=(s,e)=>l(void 0,null,function*(){let t=e;if(!e.requestOptions.disableRequestInterceptors){for(let r of s)if(t=yield r(e),!t)throw new Error("Request modifier must return request")}return t}),ze=(s,e,t)=>l(void 0,null,function*(){let r=e;if(!t.requestOptions.disableResponseInterceptors){for(let n of s)if(r=yield n(e,t),!r)throw new Error("Response modifier must return data")}return r}),qt=s=>{let e=ce()&&s.data instanceof FormData,t={};return e||(t["Content-Type"]="application/json"),Object.assign(t,s.headers),t},Ct=s=>ce()&&s instanceof FormData?s:Wt(s),It=s=>e=>{let{skipNull:t,skipEmptyString:r}=s;return!(r&&e===void 0||r&&e===""||t&&e===null)},_=(s,{encode:e,strict:t})=>e&&t?encodeURIComponent(s).replace(/[!'()*]/g,r=>`%${r.charCodeAt(0).toString(16).toUpperCase()}`):e?encodeURIComponent(s):s,Xt=(s,e,t)=>{let r=!It(t)(e);if(!s||r)return"";let n=()=>{var o,a;return e instanceof Date?((o=t.dateParser)==null?void 0:o.call(t,e))||e.toISOString():typeof e=="object"&&!Array.isArray(e)?((a=t.objectParser)==null?void 0:a.call(t,e))||JSON.stringify(e):String(e)};return`${_(s,t)}=${_(n(),t)}`},Yt=(s,e,t)=>{let{arrayFormat:r,arraySeparator:n}=t;return e.filter(It(t)).reduce((o,a,d)=>{switch(r){case"index":{let i=`${_(s,t)}[${_(String(d),t)}]=`;o.push(`${i}${_(String(a),t)}`);break}case"bracket":{let i=`${_(s,t)}[]=`;o.push(`${i}${_(String(a),t)}`);break}case"comma":{let i=!o.length&&`${_(s,t)}=`||"";return[[...o,`${i}${_(String(a),t)}`].join(",")]}case"separator":{let i=!o.length&&`${_(s,t)}=`||"";return[[...o,`${i}${_(String(a),t)}`].join(n||"|")]}case"bracket-separator":{let i=!o.length&&`${_(s,t)}[]=`||"";return[[...o,`${i}${_(String(a),t)}`].join(n||"|")]}default:{let i=`${_(s,t)}=`;o.push(`${i}${_(String(a),t)}`)}}return o},[]).join("&")},Mt=(s,e=wt)=>{if(!s||!Object.keys(s).length)return"";if(typeof s=="string")return s[0]==="?"?s:`?${s}`;let t=Object.entries(s).map(([r,n])=>Array.isArray(n)?Yt(r,n,e):Xt(r,n,e)).filter(Boolean).join("&");return t?`?${t}`:""};var Pt=class{constructor(e){this.options=e;this.__onErrorCallbacks=[];this.__onSuccessCallbacks=[];this.__onResponseCallbacks=[];this.__onAuthCallbacks=[];this.__onRequestCallbacks=[];this.requestManager=new Ce;this.loggerManager=new Be(this);this.defaultMethod="GET";this.defaultExtra=U;this.effects=[];this.abortKeyMapper=Ae;this.cacheKeyMapper=ut;this.queueKeyMapper=Ae;this.effectKeyMapper=Ae;this.stringifyQueryParams=e=>Mt(e,this.queryParamsConfig);this.headerMapper=qt;this.payloadMapper=Ct;this.logger=this.loggerManager.init("Client");this.setRequestDefaultOptions=e=>(this.requestDefaultOptions=e,this);this.setAdapterDefaultOptions=e=>(this.adapterDefaultOptions=e,this);this.setDebug=e=>(this.debug=e,this);this.setLoggerSeverity=e=>(this.loggerManager.setSeverity(e),this);this.setLogger=e=>(this.loggerManager=e(this),this);this.setQueryParamsConfig=e=>(this.queryParamsConfig=e,this);this.setStringifyQueryParams=e=>(this.stringifyQueryParams=e,this);this.setHeaderMapper=e=>(this.headerMapper=e,this);this.setPayloadMapper=e=>(this.payloadMapper=e,this);this.setAdapter=e=>(this.adapter=e(this),this);this.setDefaultMethod=e=>(this.defaultMethod=e,this);this.setDefaultExtra=e=>(this.defaultExtra=e,this);this.onAuth=e=>(this.__onAuthCallbacks.push(e),this);this.onError=e=>(this.__onErrorCallbacks.push(e),this);this.onSuccess=e=>(this.__onSuccessCallbacks.push(e),this);this.onRequest=e=>(this.__onRequestCallbacks.push(e),this);this.onResponse=e=>(this.__onResponseCallbacks.push(e),this);this.addEffect=e=>(this.effects=this.effects.concat(e),this);this.removeEffect=e=>{let t=typeof e=="string"?e:e.getEffectKey();return this.effects=this.effects.filter(r=>r.getEffectKey()!==t),this};this.setAbortKeyMapper=e=>{this.abortKeyMapper=e};this.setCacheKeyMapper=e=>{this.cacheKeyMapper=e};this.setQueueKeyMapper=e=>{this.queueKeyMapper=e};this.setEffectKeyMapper=e=>{this.effectKeyMapper=e};this.__modifyAuth=e=>l(this,null,function*(){return Ze(this.__onAuthCallbacks,e)});this.__modifyRequest=e=>l(this,null,function*(){return Ze(this.__onRequestCallbacks,e)});this.__modifyErrorResponse=(e,t)=>l(this,null,function*(){return ze(this.__onErrorCallbacks,e,t)});this.__modifySuccessResponse=(e,t)=>l(this,null,function*(){return ze(this.__onSuccessCallbacks,e,t)});this.__modifyResponse=(e,t)=>l(this,null,function*(){return ze(this.__onResponseCallbacks,e,t)});this.clear=()=>{let{appManager:e,cache:t,fetchDispatcher:r,submitDispatcher:n}=this.options;this.requestManager.abortControllers.clear(),this.fetchDispatcher.clear(),this.submitDispatcher.clear(),this.cache.clear(),this.requestManager.emitter.removeAllListeners(),this.fetchDispatcher.emitter.removeAllListeners(),this.submitDispatcher.emitter.removeAllListeners(),this.cache.emitter.removeAllListeners(),this.appManager=(e==null?void 0:e(this))||new ue,this.cache=(t==null?void 0:t(this))||new pe(this),this.fetchDispatcher=(r==null?void 0:r(this))||new N(this),this.submitDispatcher=(n==null?void 0:n(this))||new N(this)};this.createRequest=()=>e=>new J(this,e);let{url:t,adapter:r,appManager:n,cache:o,fetchDispatcher:a,submitDispatcher:d}=this.options;this.url=t,this.adapter=r||yt,this.appManager=(n==null?void 0:n(this))||new ue,this.cache=(o==null?void 0:o(this))||new pe(this),this.fetchDispatcher=(a==null?void 0:a(this))||new N(this),this.submitDispatcher=(d==null?void 0:d(this))||new N(this)}};var wt={strict:!0,encode:!0,arrayFormat:"bracket",arraySeparator:"",sort:!1,skipNull:!0,skipEmptyString:!0},U={headers:{}};export{Tt as AppEvents,ue as AppManager,pe as Cache,Pt as Client,je as DateInterval,N as Dispatcher,We as DispatcherRequestType,Re as HttpMethodsEnum,Be as LoggerManager,J as Request,rt as RequestEffect,Ce as RequestManager,yt as adapter,ee as appManagerInitialOptions,be as canRetryRequest,ye as defaultTimeout,Qe as getAbortByIdEventKey,De as getAbortEventKey,he as getAdapterBindings,qt as getAdapterHeaders,Ct as getAdapterPayload,mt as getAppManagerEvents,ht as getCacheData,ft as getCacheEvents,un as getCacheIdKey,qe as getCacheKey,xe as getDispatcherChangeEventKey,Te as getDispatcherDrainedEventKey,at as getDispatcherEvents,Ee as getDispatcherStatusEventKey,Ve as getDownloadProgressEventKey,He as getDownloadProgressIdEventKey,O as getErrorMessage,Wr as getIsEqualTimestamp,Ie as getLoadingEventKey,Me as getLoadingIdEventKey,Xe as getProgressData,$t as getProgressValue,we as getRemoveEventKey,Pe as getRemoveIdEventKey,_t as getRequestDispatcher,Ft as getRequestEta,ut as getRequestKey,Et as getRequestManagerEvents,ke as getRequestStartEventKey,$e as getRequestStartIdEventKey,it as getRequestType,Le as getResponseEventKey,nt as getResponseHeaders,Ke as getResponseIdEventKey,Fe as getResponseStartEventKey,_e as getResponseStartIdEventKey,ve as getRevalidateEventKey,Ae as getSimpleKey,lt as getStreamPayload,jt as getTime,me as getUniqueRequestId,Se as getUploadProgressEventKey,Ge as getUploadProgressIdEventKey,dt as getUploadSize,Ye as hasDocument,ce as hasWindow,Ze as interceptRequest,ze as interceptResponse,xt as logger,At as loggerIconLevels,bt as loggerStyles,ct as mocker,Rt as onDocumentEvent,de as onWindowEvent,fe as parseErrorResponse,ie as parseResponse,ot as sendRequest,vt as severity,wt as stringifyDefaultOptions,pt as stringifyKey,Mt as stringifyQueryParams,Wt as stringifyValue,U as xhrExtra};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|