@cegal/ds-utils
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -9,4 +9,13 @@ import 'cross-fetch/polyfill'; | ||
} | ||
export interface Env { | ||
environment?: string; | ||
IS_DEVELOPMENT: boolean; | ||
IS_PRODUCTION: boolean; | ||
IS_CHAOS: boolean; | ||
IS_TEST: boolean; | ||
RUNNING_IN_BROWSER: boolean; | ||
} | ||
export declare class Call { | ||
private headers; | ||
private env; | ||
private expectedResponses; | ||
@@ -13,0 +22,0 @@ constructor(options?: CallProps); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,(()=>(()=>{var e={423:function(){!function(e){!function(t){var r="undefined"!=typeof globalThis&&globalThis||void 0!==e&&e||void 0!==r&&r,o="URLSearchParams"in r,n="Symbol"in r&&"iterator"in Symbol,s="FileReader"in r&&"Blob"in r&&function(){try{return new Blob,!0}catch(e){return!1}}(),i="FormData"in r,a="ArrayBuffer"in r;if(a)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],h=ArrayBuffer.isView||function(e){return e&&u.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function d(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function f(e){this.map={},e instanceof f?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function y(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function b(e){var t=new FileReader,r=y(t);return t.readAsArrayBuffer(e),r}function m(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(e){var t;this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:o&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&s&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=m(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||h(e))?this._bodyArrayBuffer=m(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):o&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer)):this.blob().then(b)}),this.text=function(){var e,t,r,o=p(this);if(o)return o;if(this._bodyBlob)return e=this._bodyBlob,r=y(t=new FileReader),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),o=0;o<t.length;o++)r[o]=String.fromCharCode(t[o]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}f.prototype.append=function(e,t){e=c(e),t=d(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},f.prototype.delete=function(e){delete this.map[c(e)]},f.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},f.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},f.prototype.set=function(e,t){this.map[c(e)]=d(t)},f.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},f.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),l(e)},f.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},f.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),l(e)},n&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function E(e,t){if(!(this instanceof E))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,o,n=(t=t||{}).body;if(e instanceof E){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new f(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,n||null==e._bodyInit||(n=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new f(t.headers)),this.method=(o=(r=t.method||this.method||"GET").toUpperCase(),w.indexOf(o)>-1?o:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(n),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var s=/([?&])_=[^&]*/;s.test(this.url)?this.url=this.url.replace(s,"$1_="+(new Date).getTime()):this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}function g(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(o),decodeURIComponent(n))}})),t}function T(e,t){if(!(this instanceof T))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new f(t.headers),this.url=t.url||"",this._initBody(e)}E.prototype.clone=function(){return new E(this,{body:this._bodyInit})},v.call(E.prototype),v.call(T.prototype),T.prototype.clone=function(){return new T(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},T.error=function(){var e=new T(null,{status:0,statusText:""});return e.type="error",e};var O=[301,302,303,307,308];T.redirect=function(e,t){if(-1===O.indexOf(t))throw new RangeError("Invalid status code");return new T(null,{status:t,headers:{location:e}})},t.DOMException=r.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function A(e,o){return new Promise((function(n,i){var u=new E(e,o);if(u.signal&&u.signal.aborted)return i(new t.DOMException("Aborted","AbortError"));var h=new XMLHttpRequest;function c(){h.abort()}h.onload=function(){var e,t,r={status:h.status,statusText:h.statusText,headers:(e=h.getAllResponseHeaders()||"",t=new f,e.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e})).forEach((function(e){var r=e.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();t.append(o,n)}})),t)};r.url="responseURL"in h?h.responseURL:r.headers.get("X-Request-URL");var o="response"in h?h.response:h.responseText;setTimeout((function(){n(new T(o,r))}),0)},h.onerror=function(){setTimeout((function(){i(new TypeError("Network request failed"))}),0)},h.ontimeout=function(){setTimeout((function(){i(new TypeError("Network request failed"))}),0)},h.onabort=function(){setTimeout((function(){i(new t.DOMException("Aborted","AbortError"))}),0)},h.open(u.method,function(e){try{return""===e&&r.location.href?r.location.href:e}catch(t){return e}}(u.url),!0),"include"===u.credentials?h.withCredentials=!0:"omit"===u.credentials&&(h.withCredentials=!1),"responseType"in h&&(s?h.responseType="blob":a&&u.headers.get("Content-Type")&&-1!==u.headers.get("Content-Type").indexOf("application/octet-stream")&&(h.responseType="arraybuffer")),!o||"object"!=typeof o.headers||o.headers instanceof f?u.headers.forEach((function(e,t){h.setRequestHeader(t,e)})):Object.getOwnPropertyNames(o.headers).forEach((function(e){h.setRequestHeader(e,d(o.headers[e]))})),u.signal&&(u.signal.addEventListener("abort",c),h.onreadystatechange=function(){4===h.readyState&&u.signal.removeEventListener("abort",c)}),h.send(void 0===u._bodyInit?null:u._bodyInit)}))}A.polyfill=!0,r.fetch||(r.fetch=A,r.Headers=f,r.Request=E,r.Response=T),t.Headers=f,t.Request=E,t.Response=T,t.fetch=A}({})}("undefined"!=typeof self?self:this)},372:(e,t,r)=>{var o="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||void 0!==r.g&&r.g,n=function(){function e(){this.fetch=!1,this.DOMException=o.DOMException}return e.prototype=o,new e}();!function(e){!function(t){var r=void 0!==e&&e||"undefined"!=typeof self&&self||void 0!==r&&r,o="URLSearchParams"in r,n="Symbol"in r&&"iterator"in Symbol,s="FileReader"in r&&"Blob"in r&&function(){try{return new Blob,!0}catch(e){return!1}}(),i="FormData"in r,a="ArrayBuffer"in r;if(a)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],h=ArrayBuffer.isView||function(e){return e&&u.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function d(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function f(e){this.map={},e instanceof f?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function y(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function b(e){var t=new FileReader,r=y(t);return t.readAsArrayBuffer(e),r}function m(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(e){var t;this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:o&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&s&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=m(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||h(e))?this._bodyArrayBuffer=m(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):o&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer)):this.blob().then(b)}),this.text=function(){var e,t,r,o=p(this);if(o)return o;if(this._bodyBlob)return e=this._bodyBlob,r=y(t=new FileReader),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),o=0;o<t.length;o++)r[o]=String.fromCharCode(t[o]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}f.prototype.append=function(e,t){e=c(e),t=d(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},f.prototype.delete=function(e){delete this.map[c(e)]},f.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},f.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},f.prototype.set=function(e,t){this.map[c(e)]=d(t)},f.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},f.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),l(e)},f.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},f.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),l(e)},n&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function E(e,t){if(!(this instanceof E))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,o,n=(t=t||{}).body;if(e instanceof E){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new f(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,n||null==e._bodyInit||(n=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new f(t.headers)),this.method=(o=(r=t.method||this.method||"GET").toUpperCase(),w.indexOf(o)>-1?o:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(n),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var s=/([?&])_=[^&]*/;s.test(this.url)?this.url=this.url.replace(s,"$1_="+(new Date).getTime()):this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}function g(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(o),decodeURIComponent(n))}})),t}function T(e,t){if(!(this instanceof T))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new f(t.headers),this.url=t.url||"",this._initBody(e)}E.prototype.clone=function(){return new E(this,{body:this._bodyInit})},v.call(E.prototype),v.call(T.prototype),T.prototype.clone=function(){return new T(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},T.error=function(){var e=new T(null,{status:0,statusText:""});return e.type="error",e};var O=[301,302,303,307,308];T.redirect=function(e,t){if(-1===O.indexOf(t))throw new RangeError("Invalid status code");return new T(null,{status:t,headers:{location:e}})},t.DOMException=r.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function A(e,o){return new Promise((function(n,i){var u=new E(e,o);if(u.signal&&u.signal.aborted)return i(new t.DOMException("Aborted","AbortError"));var h=new XMLHttpRequest;function c(){h.abort()}h.onload=function(){var e,t,r={status:h.status,statusText:h.statusText,headers:(e=h.getAllResponseHeaders()||"",t=new f,e.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e})).forEach((function(e){var r=e.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();t.append(o,n)}})),t)};r.url="responseURL"in h?h.responseURL:r.headers.get("X-Request-URL");var o="response"in h?h.response:h.responseText;setTimeout((function(){n(new T(o,r))}),0)},h.onerror=function(){setTimeout((function(){i(new TypeError("Network request failed"))}),0)},h.ontimeout=function(){setTimeout((function(){i(new TypeError("Network request failed"))}),0)},h.onabort=function(){setTimeout((function(){i(new t.DOMException("Aborted","AbortError"))}),0)},h.open(u.method,function(e){try{return""===e&&r.location.href?r.location.href:e}catch(t){return e}}(u.url),!0),"include"===u.credentials?h.withCredentials=!0:"omit"===u.credentials&&(h.withCredentials=!1),"responseType"in h&&(s?h.responseType="blob":a&&u.headers.get("Content-Type")&&-1!==u.headers.get("Content-Type").indexOf("application/octet-stream")&&(h.responseType="arraybuffer")),!o||"object"!=typeof o.headers||o.headers instanceof f?u.headers.forEach((function(e,t){h.setRequestHeader(t,e)})):Object.getOwnPropertyNames(o.headers).forEach((function(e){h.setRequestHeader(e,d(o.headers[e]))})),u.signal&&(u.signal.addEventListener("abort",c),h.onreadystatechange=function(){4===h.readyState&&u.signal.removeEventListener("abort",c)}),h.send(void 0===u._bodyInit?null:u._bodyInit)}))}A.polyfill=!0,r.fetch||(r.fetch=A,r.Headers=f,r.Request=E,r.Response=T),t.Headers=f,t.Request=E,t.Response=T,t.fetch=A}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var s=o.fetch?o:n;(t=s.fetch).default=s.fetch,t.fetch=s.fetch,t.Headers=s.Headers,t.Request=s.Request,t.Response=s.Response,e.exports=t}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,r),s.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{"use strict";r.r(o),r.d(o,{fetch:()=>e});var e={};r.r(e),r.d(e,{Call:()=>f});var t=r(372),n=r.n(t);r(423);const s=process.env.REACT_APP_ENVIRONMENT,i="development"===process.env.REACT_APP_ENVIRONMENT,a="production"===process.env.REACT_APP_ENVIRONMENT,u="chaos"===process.env.REACT_APP_ENVIRONMENT,h="test"===process.env.REACT_APP_ENVIRONMENT,c=!navigator.userAgent.includes("jsdom"),d=window.location.hostname;class l extends Error{constructor(e,t){super(e),this.url=t;const r=new.target.prototype;Object.setPrototypeOf(this,r)}}class f{constructor(e={}){var t;this.headers={},this.expectedResponses={200:1},this.headers=null!==(t=e.headers)&&void 0!==t?t:{},u&&(this.expectedResponses={404:1,500:1})}setHeaders(e={}){this.headers=e}handleResponse(e,t){return r=>{if(r){if(r.status>=400){const e=new l(r.statusText,t);return e.response=r,r.json().then((t=>{throw e.payload=t,e})).catch((()=>Promise.reject(e)))}if(r.status>=300)return Promise.resolve({status:r.status,headers:null==r?void 0:r.headers});const o=(e={})=>Promise.resolve({status:null==r?void 0:r.status,headers:null==r?void 0:r.headers,payload:"SyntaxError"===Object.getPrototypeOf(e).name?{}:e});return"json"===e?r.json().then(o).catch(o):r.blob().then(o)}}}handleSuccessResponse(e,t,r,o){return n=>{var s,i,a;console.debug("handleSuccessResponse",n);const u=n&&n.headers&&n.headers.entries?Object.fromEntries(null===(i=null===(s=null==n?void 0:n.headers)||void 0===s?void 0:s.entries)||void 0===i?void 0:i.call(s)):{},h={context:o,headers:u,originalPayload:r,status:null==n?void 0:n.status};return(null==n?void 0:n.status)<300?e(Object.assign(Object.assign({},h),{type:t.success,payload:null==n?void 0:n.payload})):e(Object.assign(Object.assign({},h),{type:null!==(a=t.redirect)&&void 0!==a?a:"API/CALL/REDIRECT"}))}}handleFailureResponse(e,t,r,o,n){return s=>{var i,a,u,h;console.debug("handleFailureResponse",s);let c=!1;const d=Object.fromEntries(null!==(u=null===(a=null===(i=null==s?void 0:s.response)||void 0===i?void 0:i.headers)||void 0===a?void 0:a.entries())&&void 0!==u?u:[]),l={context:o,error:{url:null==s?void 0:s.url,message:null==s?void 0:s.message,stack:null==s?void 0:s.stack},headers:d,payload:s.payload,originalPayload:r,status:null===(h=null==s?void 0:s.response)||void 0===h?void 0:h.status};401===l.status&&(e(Object.assign(Object.assign({},l),{type:t.unauthorized||t.failure})),c=!0),403===l.status&&(e(Object.assign(Object.assign({},l),{type:t.forbidden||t.failure})),c=!0),l.status>=500&&(e(Object.assign(Object.assign({},l),{type:t.serverInternalError||"SERVER/INTERNAL/ERROR"})),c=!0),(!c||c&&l.status>=500&&n)&&e(Object.assign(Object.assign({},l),{type:t.failure}))}}pickOneHttpCode(e){const t=Object.keys(e).sort(((e,t)=>parseInt(t)-parseInt(e)));let r=0;const o={};t.forEach((t=>{const n=e[t];o[t]={low:r,high:r+n},r+=n}));const n=Math.random()*r;let s=0;return Object.keys(o).forEach((e=>{o[e].low<=n&&n<o[e].high&&(s=parseInt(e))})),s}fakeCall({body:e,context:t,cascadeFailureError:r=!1,expectedPayload:o,expectedResponses:n,maxDelayTime:s=2e3,method:i="GET",payload:a,type:u,url:h}){return c=>{console.debug("FAKE API REQUEST FOR "+i+" "+h),u.request&&c({type:u.request,context:t});const d=e||a;return new Promise(((e,t)=>{setTimeout((()=>{const r=this.pickOneHttpCode(null!=n?n:this.expectedResponses);if(r<400){const t=o instanceof Function?o():o;console.log("FAKE API SUCCESS "+r+" FOR "+i+" "+h),console.log("payload",t),e({status:r,payload:t,headers:{}})}else{console.log("FAKE API FAILURE "+r+" FOR "+i+" "+h);const e=new l("Generated "+r+" failure error in fetch-api for "+h);e.response={status:r},t(e)}}),Math.floor(Math.random()*s))})).then(this.handleSuccessResponse(c,u,d,t)).catch(this.handleFailureResponse(c,u,d,t,r))}}realCall({body:e,context:t,cascadeFailureError:r=!1,headers:o,method:s="GET",responseType:i="json",redirect:a="follow",payload:u,type:h,url:c,useTimestamp:d=!1}){return l=>{var f,p,y,b;const m={method:s,redirect:a,headers:Object.assign(Object.assign(Object.assign({},this.headers),o),{Accept:"pdf"===i?"application/pdf":"application/json; charset=utf-8"})},v=e||u,w=v?JSON.stringify(v):void 0;let E=c;if(d){const e=(new Date).getTime();E=c.match(/\?./)?c+"&ts="+e:c+"?ts="+e}return"GET"!==s&&"HEAD"!==s&&(m.headers["Content-Type"]="application/json; charset=utf-8",m.body=w),(null==h?void 0:h.request)&&l({type:h.request,context:t}),null===(b=null===(y=null===(p=null===(f=n()(E,m))||void 0===f?void 0:f.catch((e=>(console.error(e),Promise.reject(e)))))||void 0===p?void 0:p.then(this.handleResponse(i,E)))||void 0===y?void 0:y.then(this.handleSuccessResponse(l,h,v,t)))||void 0===b?void 0:b.catch(this.handleFailureResponse(l,h,v,t,r))}}call(e){var t;if((i||"localhost"===d&&c)&&!e.skipFake)return h||a||console.debug("using fakeCall, because ISDEVELOPMENT="+i+" HOST="+d+" RUNNING_IN_BROWSER="+c+" skipFake="+e.skipFake),this.fakeCall(e);if(u){const t=Math.floor(1e3*Math.random())%2==0;if(!t)return console.debug("using fakeCall, because ISCHAOS="+u+" useRealCall="+t),this.fakeCall(Object.assign({expectedResponses:this.expectedResponses},e))}return h||a||console.debug("using realCall in a "+(null!==(t=null==s?void 0:s.default)&&void 0!==t?t:"unknown")+" env"),this.realCall(e)}}})(),o})())); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,(()=>(()=>{var e={423:function(){!function(e){!function(t){var r="undefined"!=typeof globalThis&&globalThis||void 0!==e&&e||void 0!==r&&r,o="URLSearchParams"in r,n="Symbol"in r&&"iterator"in Symbol,s="FileReader"in r&&"Blob"in r&&function(){try{return new Blob,!0}catch(e){return!1}}(),i="FormData"in r,a="ArrayBuffer"in r;if(a)var h=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(e){return e&&h.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function d(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function f(e){this.map={},e instanceof f?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function y(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function b(e){var t=new FileReader,r=y(t);return t.readAsArrayBuffer(e),r}function m(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(e){var t;this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:o&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&s&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=m(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=m(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):o&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer)):this.blob().then(b)}),this.text=function(){var e,t,r,o=p(this);if(o)return o;if(this._bodyBlob)return e=this._bodyBlob,r=y(t=new FileReader),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),o=0;o<t.length;o++)r[o]=String.fromCharCode(t[o]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}f.prototype.append=function(e,t){e=c(e),t=d(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},f.prototype.delete=function(e){delete this.map[c(e)]},f.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},f.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},f.prototype.set=function(e,t){this.map[c(e)]=d(t)},f.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},f.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),l(e)},f.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},f.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),l(e)},n&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function E(e,t){if(!(this instanceof E))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,o,n=(t=t||{}).body;if(e instanceof E){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new f(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,n||null==e._bodyInit||(n=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new f(t.headers)),this.method=(o=(r=t.method||this.method||"GET").toUpperCase(),w.indexOf(o)>-1?o:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(n),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var s=/([?&])_=[^&]*/;s.test(this.url)?this.url=this.url.replace(s,"$1_="+(new Date).getTime()):this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}function g(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(o),decodeURIComponent(n))}})),t}function O(e,t){if(!(this instanceof O))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new f(t.headers),this.url=t.url||"",this._initBody(e)}E.prototype.clone=function(){return new E(this,{body:this._bodyInit})},v.call(E.prototype),v.call(O.prototype),O.prototype.clone=function(){return new O(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},O.error=function(){var e=new O(null,{status:0,statusText:""});return e.type="error",e};var T=[301,302,303,307,308];O.redirect=function(e,t){if(-1===T.indexOf(t))throw new RangeError("Invalid status code");return new O(null,{status:t,headers:{location:e}})},t.DOMException=r.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function _(e,o){return new Promise((function(n,i){var h=new E(e,o);if(h.signal&&h.signal.aborted)return i(new t.DOMException("Aborted","AbortError"));var u=new XMLHttpRequest;function c(){u.abort()}u.onload=function(){var e,t,r={status:u.status,statusText:u.statusText,headers:(e=u.getAllResponseHeaders()||"",t=new f,e.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e})).forEach((function(e){var r=e.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();t.append(o,n)}})),t)};r.url="responseURL"in u?u.responseURL:r.headers.get("X-Request-URL");var o="response"in u?u.response:u.responseText;setTimeout((function(){n(new O(o,r))}),0)},u.onerror=function(){setTimeout((function(){i(new TypeError("Network request failed"))}),0)},u.ontimeout=function(){setTimeout((function(){i(new TypeError("Network request failed"))}),0)},u.onabort=function(){setTimeout((function(){i(new t.DOMException("Aborted","AbortError"))}),0)},u.open(h.method,function(e){try{return""===e&&r.location.href?r.location.href:e}catch(t){return e}}(h.url),!0),"include"===h.credentials?u.withCredentials=!0:"omit"===h.credentials&&(u.withCredentials=!1),"responseType"in u&&(s?u.responseType="blob":a&&h.headers.get("Content-Type")&&-1!==h.headers.get("Content-Type").indexOf("application/octet-stream")&&(u.responseType="arraybuffer")),!o||"object"!=typeof o.headers||o.headers instanceof f?h.headers.forEach((function(e,t){u.setRequestHeader(t,e)})):Object.getOwnPropertyNames(o.headers).forEach((function(e){u.setRequestHeader(e,d(o.headers[e]))})),h.signal&&(h.signal.addEventListener("abort",c),u.onreadystatechange=function(){4===u.readyState&&h.signal.removeEventListener("abort",c)}),u.send(void 0===h._bodyInit?null:h._bodyInit)}))}_.polyfill=!0,r.fetch||(r.fetch=_,r.Headers=f,r.Request=E,r.Response=O),t.Headers=f,t.Request=E,t.Response=O,t.fetch=_}({})}("undefined"!=typeof self?self:this)},372:(e,t,r)=>{var o="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||void 0!==r.g&&r.g,n=function(){function e(){this.fetch=!1,this.DOMException=o.DOMException}return e.prototype=o,new e}();!function(e){!function(t){var r=void 0!==e&&e||"undefined"!=typeof self&&self||void 0!==r&&r,o="URLSearchParams"in r,n="Symbol"in r&&"iterator"in Symbol,s="FileReader"in r&&"Blob"in r&&function(){try{return new Blob,!0}catch(e){return!1}}(),i="FormData"in r,a="ArrayBuffer"in r;if(a)var h=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(e){return e&&h.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function d(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function f(e){this.map={},e instanceof f?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function y(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function b(e){var t=new FileReader,r=y(t);return t.readAsArrayBuffer(e),r}function m(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(e){var t;this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:o&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&s&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=m(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=m(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):o&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer)):this.blob().then(b)}),this.text=function(){var e,t,r,o=p(this);if(o)return o;if(this._bodyBlob)return e=this._bodyBlob,r=y(t=new FileReader),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),o=0;o<t.length;o++)r[o]=String.fromCharCode(t[o]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}f.prototype.append=function(e,t){e=c(e),t=d(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},f.prototype.delete=function(e){delete this.map[c(e)]},f.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},f.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},f.prototype.set=function(e,t){this.map[c(e)]=d(t)},f.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},f.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),l(e)},f.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},f.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),l(e)},n&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function E(e,t){if(!(this instanceof E))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,o,n=(t=t||{}).body;if(e instanceof E){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new f(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,n||null==e._bodyInit||(n=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new f(t.headers)),this.method=(o=(r=t.method||this.method||"GET").toUpperCase(),w.indexOf(o)>-1?o:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(n),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var s=/([?&])_=[^&]*/;s.test(this.url)?this.url=this.url.replace(s,"$1_="+(new Date).getTime()):this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}function g(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(o),decodeURIComponent(n))}})),t}function O(e,t){if(!(this instanceof O))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new f(t.headers),this.url=t.url||"",this._initBody(e)}E.prototype.clone=function(){return new E(this,{body:this._bodyInit})},v.call(E.prototype),v.call(O.prototype),O.prototype.clone=function(){return new O(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},O.error=function(){var e=new O(null,{status:0,statusText:""});return e.type="error",e};var T=[301,302,303,307,308];O.redirect=function(e,t){if(-1===T.indexOf(t))throw new RangeError("Invalid status code");return new O(null,{status:t,headers:{location:e}})},t.DOMException=r.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function _(e,o){return new Promise((function(n,i){var h=new E(e,o);if(h.signal&&h.signal.aborted)return i(new t.DOMException("Aborted","AbortError"));var u=new XMLHttpRequest;function c(){u.abort()}u.onload=function(){var e,t,r={status:u.status,statusText:u.statusText,headers:(e=u.getAllResponseHeaders()||"",t=new f,e.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e})).forEach((function(e){var r=e.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();t.append(o,n)}})),t)};r.url="responseURL"in u?u.responseURL:r.headers.get("X-Request-URL");var o="response"in u?u.response:u.responseText;setTimeout((function(){n(new O(o,r))}),0)},u.onerror=function(){setTimeout((function(){i(new TypeError("Network request failed"))}),0)},u.ontimeout=function(){setTimeout((function(){i(new TypeError("Network request failed"))}),0)},u.onabort=function(){setTimeout((function(){i(new t.DOMException("Aborted","AbortError"))}),0)},u.open(h.method,function(e){try{return""===e&&r.location.href?r.location.href:e}catch(t){return e}}(h.url),!0),"include"===h.credentials?u.withCredentials=!0:"omit"===h.credentials&&(u.withCredentials=!1),"responseType"in u&&(s?u.responseType="blob":a&&h.headers.get("Content-Type")&&-1!==h.headers.get("Content-Type").indexOf("application/octet-stream")&&(u.responseType="arraybuffer")),!o||"object"!=typeof o.headers||o.headers instanceof f?h.headers.forEach((function(e,t){u.setRequestHeader(t,e)})):Object.getOwnPropertyNames(o.headers).forEach((function(e){u.setRequestHeader(e,d(o.headers[e]))})),h.signal&&(h.signal.addEventListener("abort",c),u.onreadystatechange=function(){4===u.readyState&&h.signal.removeEventListener("abort",c)}),u.send(void 0===h._bodyInit?null:h._bodyInit)}))}_.polyfill=!0,r.fetch||(r.fetch=_,r.Headers=f,r.Request=E,r.Response=O),t.Headers=f,t.Request=E,t.Response=O,t.fetch=_}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var s=o.fetch?o:n;(t=s.fetch).default=s.fetch,t.fetch=s.fetch,t.Headers=s.Headers,t.Request=s.Request,t.Response=s.Response,e.exports=t}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,r),s.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{"use strict";r.r(o),r.d(o,{fetch:()=>e});var e={};r.r(e),r.d(e,{Call:()=>a});var t=r(372),n=r.n(t);r(423);const s=window.location.hostname;class i extends Error{constructor(e,t){super(e),this.url=t;const r=new.target.prototype;Object.setPrototypeOf(this,r)}}class a{constructor(e={}){var t,r;this.headers={},this.expectedResponses={200:1},this.headers=null!==(t=e.headers)&&void 0!==t?t:{},this.env={environment:r=null==e?void 0:e.environment,IS_DEVELOPMENT:"development"===r,IS_PRODUCTION:"production"===r,IS_CHAOS:"chaos"===r,IS_TEST:"test"===r,RUNNING_IN_BROWSER:!navigator.userAgent.includes("jsdom")},this.env.IS_CHAOS&&(this.expectedResponses={404:1,500:1})}setHeaders(e={}){this.headers=e}handleResponse(e,t){return r=>{if(r){if(r.status>=400){const e=new i(r.statusText,t);return e.response=r,r.json().then((t=>{throw e.payload=t,e})).catch((()=>Promise.reject(e)))}if(r.status>=300)return Promise.resolve({status:r.status,headers:null==r?void 0:r.headers});const o=(e={})=>Promise.resolve({status:null==r?void 0:r.status,headers:null==r?void 0:r.headers,payload:"SyntaxError"===Object.getPrototypeOf(e).name?{}:e});return"json"===e?r.json().then(o).catch(o):r.blob().then(o)}}}handleSuccessResponse(e,t,r,o){return n=>{var s,i,a;console.debug("handleSuccessResponse",n);const h=n&&n.headers&&n.headers.entries?Object.fromEntries(null===(i=null===(s=null==n?void 0:n.headers)||void 0===s?void 0:s.entries)||void 0===i?void 0:i.call(s)):{},u={context:o,headers:h,originalPayload:r,status:null==n?void 0:n.status};return(null==n?void 0:n.status)<300?e(Object.assign(Object.assign({},u),{type:t.success,payload:null==n?void 0:n.payload})):e(Object.assign(Object.assign({},u),{type:null!==(a=t.redirect)&&void 0!==a?a:"API/CALL/REDIRECT"}))}}handleFailureResponse(e,t,r,o,n){return s=>{var i,a,h,u;console.debug("handleFailureResponse",s);let c=!1;const d=Object.fromEntries(null!==(h=null===(a=null===(i=null==s?void 0:s.response)||void 0===i?void 0:i.headers)||void 0===a?void 0:a.entries())&&void 0!==h?h:[]),l={context:o,error:{url:null==s?void 0:s.url,message:null==s?void 0:s.message,stack:null==s?void 0:s.stack},headers:d,payload:s.payload,originalPayload:r,status:null===(u=null==s?void 0:s.response)||void 0===u?void 0:u.status};401===l.status&&(e(Object.assign(Object.assign({},l),{type:t.unauthorized||t.failure})),c=!0),403===l.status&&(e(Object.assign(Object.assign({},l),{type:t.forbidden||t.failure})),c=!0),l.status>=500&&(e(Object.assign(Object.assign({},l),{type:t.serverInternalError||"SERVER/INTERNAL/ERROR"})),c=!0),(!c||c&&l.status>=500&&n)&&e(Object.assign(Object.assign({},l),{type:t.failure}))}}pickOneHttpCode(e){const t=Object.keys(e).sort(((e,t)=>parseInt(t)-parseInt(e)));let r=0;const o={};t.forEach((t=>{const n=e[t];o[t]={low:r,high:r+n},r+=n}));const n=Math.random()*r;let s=0;return Object.keys(o).forEach((e=>{o[e].low<=n&&n<o[e].high&&(s=parseInt(e))})),s}fakeCall({body:e,context:t,cascadeFailureError:r=!1,expectedPayload:o,expectedResponses:n,maxDelayTime:s=2e3,method:a="GET",payload:h,type:u,url:c}){return d=>{console.debug("FAKE API REQUEST FOR "+a+" "+c),u.request&&d({type:u.request,context:t});const l=e||h;return new Promise(((e,t)=>{setTimeout((()=>{const r=this.pickOneHttpCode(null!=n?n:this.expectedResponses);if(r<400){const t=o instanceof Function?o():o;console.log("FAKE API SUCCESS "+r+" FOR "+a+" "+c),console.log("payload",t),e({status:r,payload:t,headers:{}})}else{console.log("FAKE API FAILURE "+r+" FOR "+a+" "+c);const e=new i("Generated "+r+" failure error in fetch-api for "+c);e.response={status:r},t(e)}}),Math.floor(Math.random()*s))})).then(this.handleSuccessResponse(d,u,l,t)).catch(this.handleFailureResponse(d,u,l,t,r))}}realCall({body:e,context:t,cascadeFailureError:r=!1,headers:o,method:s="GET",responseType:i="json",redirect:a="follow",payload:h,type:u,url:c,useTimestamp:d=!1}){return l=>{var f,p,y,b;const m={method:s,redirect:a,headers:Object.assign(Object.assign(Object.assign({},this.headers),o),{Accept:"pdf"===i?"application/pdf":"application/json; charset=utf-8"})},v=e||h,w=v?JSON.stringify(v):void 0;let E=c;if(d){const e=(new Date).getTime();E=c.match(/\?./)?c+"&ts="+e:c+"?ts="+e}return"GET"!==s&&"HEAD"!==s&&(m.headers["Content-Type"]="application/json; charset=utf-8",m.body=w),(null==u?void 0:u.request)&&l({type:u.request,context:t}),null===(b=null===(y=null===(p=null===(f=n()(E,m))||void 0===f?void 0:f.catch((e=>(console.error(e),Promise.reject(e)))))||void 0===p?void 0:p.then(this.handleResponse(i,E)))||void 0===y?void 0:y.then(this.handleSuccessResponse(l,u,v,t)))||void 0===b?void 0:b.catch(this.handleFailureResponse(l,u,v,t,r))}}call(e){var t;if((this.env.IS_DEVELOPMENT||"localhost"===s&&this.env.RUNNING_IN_BROWSER)&&!e.skipFake)return this.env.IS_TEST||this.env.IS_PRODUCTION||console.debug("using fakeCall, because ISDEVELOPMENT="+this.env.IS_DEVELOPMENT+" HOST="+s+" RUNNING_IN_BROWSER="+this.env.RUNNING_IN_BROWSER+" skipFake="+e.skipFake),this.fakeCall(e);if(this.env.IS_CHAOS){const t=Math.floor(1e3*Math.random())%2==0;if(!t)return console.debug("using fakeCall, because ISCHAOS="+this.env.IS_CHAOS+" useRealCall="+t),this.fakeCall(Object.assign({expectedResponses:this.expectedResponses},e))}return this.env.IS_TEST||this.env.IS_PRODUCTION||console.debug("using realCall in a "+(null!==(t=this.env.environment)&&void 0!==t?t:"unknown")+" env"),this.realCall(e)}}})(),o})())); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@cegal/ds-utils", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Cegal UI utilities", | ||
@@ -36,3 +36,3 @@ "repository": { | ||
"inspectpack": "^4.7.1", | ||
"nock": "^13.5.1", | ||
"nock": "^13.5.4", | ||
"peer-deps-externals-webpack-plugin": "^1.0.4", | ||
@@ -39,0 +39,0 @@ "redux-mock-store": "^1.5.4", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
116543
166
20
1