-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rebuild dist with latest changes
- Loading branch information
Showing
6 changed files
with
11 additions
and
11 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
var R=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=(a,e,t,s)=>{for(var n=s>1?void 0:s?m(e,t):e,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(s?o(e,t,n):o(n))||n);return s&&n&&R(e,t,n),n};import{applyMagic as b}from"js-magic";import h from"axios";import{applyMagic as q}from"js-magic";var f=class{constructor(e,t){this.logger=e,this.httpRequestErrorService=t}process(e){this.logger&&this.logger.warn&&this.logger.warn("API ERROR",e);let t=e;typeof e=="string"&&(t=new Error(e)),this.httpRequestErrorService&&(typeof this.httpRequestErrorService.process<"u"?this.httpRequestErrorService.process(t):typeof this.httpRequestErrorService=="function"&&this.httpRequestErrorService(t))}};var c=class{constructor({baseURL:e="",timeout:t=null,cancellable:s=!1,strategy:n=null,flattenResponse:r=null,defaultResponse:o={},logger:i=null,onError:l=null,...u}){this.timeout=3e4;this.cancellable=!1;this.strategy="silent";this.flattenResponse=!0;this.defaultResponse=null;this.timeout=t!==null?t:this.timeout,this.strategy=n!==null?n:this.strategy,this.cancellable=s||this.cancellable,this.flattenResponse=r!==null?r:this.flattenResponse,this.defaultResponse=o,this.logger=i||global.console||window.console||null,this.httpRequestErrorService=l,this.requestsQueue=new Map,this.requestInstance=h.create({...u,baseURL:e,timeout:this.timeout})}getInstance(){return this.requestInstance}interceptRequest(e){this.getInstance().interceptors.request.use(e)}__get(e){return e in this?this[e]:this.prepareRequest.bind(this,e)}prepareRequest(e,t,s=null,n=null){return this.handleRequest({type:e,url:t,data:s,config:n})}buildRequestConfig(e,t,s,n){let r=e.toLowerCase();return{...n,url:t,method:r,[r==="get"||r==="head"?"params":"data"]:s||{}}}processRequestError(e,t){if(h.isCancel(e))return;t.onError&&typeof t.onError=="function"&&t.onError(e),new f(this.logger,this.httpRequestErrorService).process(e)}async outputErrorResponse(e,t){let s=t.cancelToken&&h.isCancel(e),n=t.strategy||this.strategy;return s&&!t.rejectCancelled?this.defaultResponse:n==="silent"?(await new Promise(()=>null),this.defaultResponse):n==="reject"||n==="throwError"?Promise.reject(e):this.defaultResponse}isRequestCancelled(e,t){return t.cancelToken&&h.isCancel(e)}addCancellationToken(e,t,s){if(!this.cancellable&&!s.cancellable)return{};if(typeof s.cancellable<"u"&&!s.cancellable)return{};let n=`${e}-${t}`,r=this.requestsQueue.get(n);r&&r.cancel();let o=h.CancelToken.source();this.requestsQueue.set(n,o);let i=this.requestsQueue.get(n)||{};return i.token?{cancelToken:i.token}:{}}async handleRequest({type:e,url:t,data:s=null,config:n=null}){let r=null,o=n||{},i=this.buildRequestConfig(e,t,s,o);i={...this.addCancellationToken(e,t,i),...i};try{r=await this.requestInstance.request(i)}catch(l){return this.processRequestError(l,i),this.outputErrorResponse(l,i)}return this.processResponseData(r)}processResponseData(e){return e.data?this.flattenResponse?typeof e.data=="object"&&typeof e.data.data<"u"&&Object.keys(e.data).length===1?e.data.data:e.data:e:this.defaultResponse}};c=g([q],c);var d=class{constructor({apiUrl:e,apiEndpoints:t,timeout:s=null,cancellable:n=!1,strategy:r=null,flattenResponse:o=null,defaultResponse:i={},logger:l=null,onError:u=null,...p}){this.apiUrl="";this.apiUrl=e,this.apiEndpoints=t,this.logger=l,this.httpRequestHandler=new c({...p,baseURL:this.apiUrl,timeout:s,cancellable:n,strategy:r,flattenResponse:o,defaultResponse:i,logger:l,onError:u})}getInstance(){return this.httpRequestHandler.getInstance()}__get(e){return e in this?this[e]:this.apiEndpoints[e]?this.handleRequest.bind(this,e):this.handleNonImplemented.bind(this,e)}async handleRequest(...e){let t=e[0],s=this.apiEndpoints[t],n=e[1]||{},r=e[2]||{},o=e[3]||{},i=s.url.replace(/:[a-z]+/gi,p=>r[p.substring(1)]?r[p.substring(1)]:p),l=null,u={...s};return delete u.url,delete u.method,l=await this.httpRequestHandler[(s.method||"get").toLowerCase()](i,n,{...o,...u}),l}handleNonImplemented(e){return this.logger&&this.logger.log&&this.logger.log(`${e} endpoint not implemented.`),Promise.resolve(null)}};d=g([b],d);var A=a=>new d(a);export{d as ApiHandler,f as HttpRequestErrorHandler,c as HttpRequestHandler,A as createApiFetcher}; | ||
var R=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var h=(u,e,t,r)=>{for(var n=r>1?void 0:r?b(e,t):e,s=u.length-1,o;s>=0;s--)(o=u[s])&&(n=(r?o(e,t,n):o(n))||n);return r&&n&&R(e,t,n),n};import{applyMagic as q}from"js-magic";import f from"axios";import{applyMagic as m}from"js-magic";var g=class{constructor(e,t){this.logger=e,this.httpRequestErrorService=t}process(e){this.logger&&this.logger.warn&&this.logger.warn("API ERROR",e);let t=e;typeof e=="string"&&(t=new Error(e)),this.httpRequestErrorService&&(typeof this.httpRequestErrorService.process<"u"?this.httpRequestErrorService.process(t):typeof this.httpRequestErrorService=="function"&&this.httpRequestErrorService(t))}};var c=class{constructor({baseURL:e="",timeout:t=null,cancellable:r=!1,strategy:n=null,flattenResponse:s=null,defaultResponse:o={},logger:i=null,onError:l=null,...a}){this.timeout=3e4;this.cancellable=!1;this.strategy="reject";this.flattenResponse=!0;this.defaultResponse=null;this.timeout=t!==null?t:this.timeout,this.strategy=n!==null?n:this.strategy,this.cancellable=r||this.cancellable,this.flattenResponse=s!==null?s:this.flattenResponse,this.defaultResponse=o,this.logger=i||global.console||window.console||null,this.httpRequestErrorService=l,this.requestsQueue=new Map,this.requestInstance=f.create({...a,baseURL:e,timeout:this.timeout})}getInstance(){return this.requestInstance}interceptRequest(e){this.getInstance().interceptors.request.use(e)}__get(e){return e in this?this[e]:this.prepareRequest.bind(this,e)}prepareRequest(e,t,r=null,n=null){return this.handleRequest({type:e,url:t,data:r,config:n})}buildRequestConfig(e,t,r,n){let s=e.toLowerCase();return{...n,url:t,method:s,[s==="get"||s==="head"?"params":"data"]:r||{}}}processRequestError(e,t){if(this.isRequestCancelled(e,t))return;t.onError&&typeof t.onError=="function"&&t.onError(e),new g(this.logger,this.httpRequestErrorService).process(e)}async outputErrorResponse(e,t){let r=this.isRequestCancelled(e,t),n=t.strategy||this.strategy;return r&&!t.rejectCancelled?this.defaultResponse:n==="silent"?(await new Promise(()=>null),this.defaultResponse):n==="reject"||n==="throwError"?Promise.reject(e):this.defaultResponse}isRequestCancelled(e,t){return f.isCancel(e)}addCancellationToken(e){if(!this.cancellable&&!e.cancellable)return{};if(typeof e.cancellable<"u"&&!e.cancellable)return{};if(typeof AbortController>"u")return console.error("AbortController is unavailable in your ENV."),{};let{method:t,baseURL:r,url:n,params:s,data:o}=e,i=JSON.stringify([t,r,n,s,o]).substring(0,55**5),l=this.requestsQueue.get(i);l&&l.abort();let a=new AbortController;return this.requestsQueue.set(i,a),{signal:a.signal}}async handleRequest({type:e,url:t,data:r=null,config:n=null}){let s=null,o=n||{},i=this.buildRequestConfig(e,t,r,o);i={...this.addCancellationToken(i),...i};try{s=await this.requestInstance.request(i)}catch(l){return this.processRequestError(l,i),this.outputErrorResponse(l,i)}return this.processResponseData(s)}processResponseData(e){return e.data?this.flattenResponse?typeof e.data=="object"&&typeof e.data.data<"u"&&Object.keys(e.data).length===1?e.data.data:e.data:e:this.defaultResponse}};c=h([m],c);var d=class{constructor({apiUrl:e,endpoints:t,timeout:r=null,cancellable:n=!1,strategy:s=null,flattenResponse:o=null,defaultResponse:i={},logger:l=null,onError:a=null,...p}){this.apiUrl="";this.apiUrl=e,this.endpoints=t,this.logger=l,this.httpRequestHandler=new c({...p,baseURL:this.apiUrl,timeout:r,cancellable:n,strategy:s,flattenResponse:o,defaultResponse:i,logger:l,onError:a})}getInstance(){return this.httpRequestHandler.getInstance()}__get(e){return e in this?this[e]:this.endpoints[e]?this.handleRequest.bind(this,e):this.handleNonImplemented.bind(this,e)}async handleRequest(...e){let t=e[0],r=this.endpoints[t],n=e[1]||{},s=e[2]||{},o=e[3]||{},i=r.url.replace(/:[a-z]+/gi,p=>s[p.substring(1)]?s[p.substring(1)]:p),l=null,a={...r};return delete a.url,delete a.method,l=await this.httpRequestHandler[(r.method||"get").toLowerCase()](i,n,{...o,...a}),l}handleNonImplemented(e){return this.logger&&this.logger.log&&this.logger.log(`${e} endpoint not implemented.`),Promise.resolve(null)}};d=h([q],d);var k=u=>new d(u);export{d as ApiHandler,g as HttpRequestErrorHandler,c as HttpRequestHandler,k as createApiFetcher}; | ||
//# sourceMappingURL=index.mjs.map |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.