@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 2.29 kB
JavaScript
import{FALLBACK_CONTEXT as e,DEFAULT_HTTP_TIMEOUT as r}from"../config.js";import t from"../Errors/AdyenCheckoutError.js";function o(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function n(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(r){o(e,r,t[r])})}return e}function c(e,r){return r=null!=r?r:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r.push.apply(r,t)}return r}(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}),e}function a(o,c){var a,s;const{headers:l=[],errorLevel:u="warn",errorCode:f,loadingContext:d=e,method:p="GET",path:b,timeout:O=r}=o,g=n({method:p,mode:"cors",cache:"default",credentials:"same-origin",headers:n({Accept:"application/json, text/plain, */*","Content-Type":"POST"===p?"application/json":"text/plain"},l),redirect:"follow",referrerPolicy:"no-referrer-when-downgrade"},(null===(a=AbortSignal)||void 0===a?void 0:a.timeout)&&{signal:null===(s=AbortSignal)||void 0===s?void 0:s.timeout(O)},c&&{body:JSON.stringify(c)}),m=`${d}${b}`;return fetch(m,g).then(async e=>{if(204===e.status)return;const r=await e.json();if(e.ok)return r;if(function(e){return e&&e.errorCode&&e.errorType&&e.message&&e.status}(r))return void i({message:r.message,level:u,cause:r,code:f});i({message:o.errorMessage||`Service at ${m} is not available`,level:u,cause:r,code:f})}).catch(e=>{if(e instanceof t)throw e;i({message:o.errorMessage||`Call to ${m} failed. Error= ${e}`,level:u,cause:e,code:f})})}function i({message:e,level:r,cause:o,code:n}){switch(r){case"silent":break;case"info":case"warn":case"error":console[r](e);break;default:throw new t("NETWORK_ERROR",e,{cause:o,code:n})}}function s(e,r){return a(c(n({},e),{method:"GET"}),r)}function l(e,r){return a(c(n({},e),{method:"POST"}),r)}export{a as http,s as httpGet,l as httpPost};
//# sourceMappingURL=http.js.map