@trustpayments/http-client 2.0.642 → 2.0.643

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.
Files changed (2) hide show
  1. package/dist/index.cjs +1 -1
  2. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require(`rxjs`),t=require(`rxjs/operators`);var n=class{get$(n,r){return(0,e.from)(this.fetchRequest(n,{method:`GET`,...r})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,r)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}post$(n,r,i){return(0,e.from)(this.fetchRequest(n,{method:`POST`,body:r?JSON.stringify(r):void 0,headers:{"Content-Type":`application/json`,...i?.headers},...i})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,i)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}put$(n,r,i){return(0,e.from)(this.fetchRequest(n,{method:`PUT`,body:r?JSON.stringify(r):void 0,headers:{"Content-Type":`application/json`,...i?.headers},...i})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,i)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}patch$(n,r,i){return(0,e.from)(this.fetchRequest(n,{method:`PATCH`,body:r?JSON.stringify(r):void 0,headers:{"Content-Type":`application/json`,...i?.headers},...i})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,i)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}delete$(n,r){return(0,e.from)(this.fetchRequest(n,{method:`DELETE`,...r})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,r)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}async fetchRequest(e,t){let{timeout:n,...r}=t;if(n){let i=new AbortController,a=setTimeout(()=>i.abort(),n);r.signal=i.signal;try{let t=await fetch(e,r);return clearTimeout(a),t}catch(r){throw clearTimeout(a),r?.name===`AbortError`?this.createAxiosLikeError(Error(`timeout of ${n}ms exceeded`),e,t,`ECONNABORTED`):this.createAxiosLikeError(r,e,t)}}try{return await fetch(e,r)}catch(n){throw this.createAxiosLikeError(n,e,t)}}async mapFetchResponseToHttpClientResponse(e,t){let n={};e.headers.forEach((e,t)=>{n[t]=e});let r;try{let t=e.headers.get(`content-type`)||``;if(e.status===204||e.status===205)r=void 0;else if(t.includes(`application/json`)){let t=await e.text();r=t?JSON.parse(t):void 0}else if(t.includes(`text/`))r=await e.text();else{let t=await e.text();try{r=t?JSON.parse(t):void 0}catch{r=t}}}catch(n){if(e.ok)throw this.createAxiosLikeError(n,e.url,t,`ERR_BAD_RESPONSE`);r=void 0}if(!e.ok){let i=this.createAxiosLikeError(Error(`Request failed with status code ${e.status}`),e.url,t,`ERR_BAD_REQUEST`);throw i.response={data:r,status:e.status,statusText:e.statusText,headers:n},i}return{data:r,status:e.status,statusText:e.statusText,headers:n,config:t||{}}}createAxiosLikeError(e,t,n,r){let i=Error(e.message);return i.name=`AxiosError`,i.config=n,i.code=r,i.request={url:t},e.stack&&(i.stack=e.stack),i}};exports.HttpClient=n,exports.default=n;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("rxjs"),t=require("rxjs/operators");var n=class{get$(n,r){return(0,e.from)(this.fetchRequest(n,{method:`GET`,...r})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,r)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}post$(n,r,i){return(0,e.from)(this.fetchRequest(n,{method:`POST`,body:r?JSON.stringify(r):void 0,headers:{"Content-Type":`application/json`,...i?.headers},...i})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,i)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}put$(n,r,i){return(0,e.from)(this.fetchRequest(n,{method:`PUT`,body:r?JSON.stringify(r):void 0,headers:{"Content-Type":`application/json`,...i?.headers},...i})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,i)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}patch$(n,r,i){return(0,e.from)(this.fetchRequest(n,{method:`PATCH`,body:r?JSON.stringify(r):void 0,headers:{"Content-Type":`application/json`,...i?.headers},...i})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,i)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}delete$(n,r){return(0,e.from)(this.fetchRequest(n,{method:`DELETE`,...r})).pipe((0,t.first)(),(0,t.switchMap)(e=>this.mapFetchResponseToHttpClientResponse(e,r)),(0,t.catchError)(t=>(0,e.throwError)(()=>t)))}async fetchRequest(e,t){let{timeout:n,...r}=t;if(n){let i=new AbortController,a=setTimeout(()=>i.abort(),n);r.signal=i.signal;try{let t=await fetch(e,r);return clearTimeout(a),t}catch(r){throw clearTimeout(a),r?.name===`AbortError`?this.createAxiosLikeError(Error(`timeout of ${n}ms exceeded`),e,t,`ECONNABORTED`):this.createAxiosLikeError(r,e,t)}}try{return await fetch(e,r)}catch(n){throw this.createAxiosLikeError(n,e,t)}}async mapFetchResponseToHttpClientResponse(e,t){let n={};e.headers.forEach((e,t)=>{n[t]=e});let r;try{let t=e.headers.get(`content-type`)||``;if(e.status===204||e.status===205)r=void 0;else if(t.includes(`application/json`)){let t=await e.text();r=t?JSON.parse(t):void 0}else if(t.includes(`text/`))r=await e.text();else{let t=await e.text();try{r=t?JSON.parse(t):void 0}catch{r=t}}}catch(n){if(e.ok)throw this.createAxiosLikeError(n,e.url,t,`ERR_BAD_RESPONSE`);r=void 0}if(!e.ok){let i=this.createAxiosLikeError(Error(`Request failed with status code ${e.status}`),e.url,t,`ERR_BAD_REQUEST`);throw i.response={data:r,status:e.status,statusText:e.statusText,headers:n},i}return{data:r,status:e.status,statusText:e.statusText,headers:n,config:t||{}}}createAxiosLikeError(e,t,n,r){let i=Error(e.message);return i.name=`AxiosError`,i.config=n,i.code=r,i.request={url:t},e.stack&&(i.stack=e.stack),i}};exports.HttpClient=n,exports.default=n;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustpayments/http-client",
3
- "version": "2.0.642",
3
+ "version": "2.0.643",
4
4
  "description": "Generic http client",
5
5
  "author": "Trust Payments <support@trustpayments.com>",
6
6
  "homepage": "https://docs.trustpayments.com",
@@ -41,5 +41,5 @@
41
41
  "test": "vitest run",
42
42
  "type-check": "tsc --noEmit"
43
43
  },
44
- "gitHead": "2af64ce666da961ec6c057815f22e22f2d1e398e"
44
+ "gitHead": "4fbc175dde0f7c8593f0afbae535f0e7283c8cc6"
45
45
  }