js-fetch-api
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -19,5 +19,6 @@ /// <reference types="react" /> | ||
expectedPayload?: any | ||
expectedFailure?: boolean | ||
expectedFailureRate ?: number | ||
expectedServerErrorRate?: number | ||
expectedFailureRate?: number | ||
headers?: any | ||
maxDelayTime?: number | ||
method?: string | ||
@@ -24,0 +25,0 @@ payload?: any |
@@ -1,2 +0,2 @@ | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var o in r)("object"==typeof exports?exports:t)[o]=r[o]}}(window,(function(){return function(t){var e={};function r(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,o){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(o,n,function(e){return t[e]}.bind(null,n));return o},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="/lib/",r(r.s=3)}([function(t,e){e.defaults={},e.set=function(t,r,o){var n=o||{},i=e.defaults,s=n.expires||i.expires,a=n.domain||i.domain,u=void 0!==n.path?n.path:void 0!==i.path?i.path:"/",c=void 0!==n.secure?n.secure:i.secure,d=void 0!==n.httponly?n.httponly:i.httponly,h=void 0!==n.samesite?n.samesite:i.samesite,f=s?new Date("number"==typeof s?(new Date).getTime()+864e5*s:s):0;document.cookie=t.replace(/[^+#$&^`|]/g,encodeURIComponent).replace("(","%28").replace(")","%29")+"="+r.replace(/[^+#$&/:<-\[\]-}]/g,encodeURIComponent)+(f&&f.getTime()>=0?";expires="+f.toUTCString():"")+(a?";domain="+a:"")+(u?";path="+u:"")+(c?";secure":"")+(d?";httponly":"")+(h?";samesite="+h:"")},e.get=function(t){for(var e=document.cookie.split(";");e.length;){var r=e.pop(),o=r.indexOf("=");if(o=o<0?r.length:o,decodeURIComponent(r.slice(0,o).replace(/^\s+/,""))===t)return decodeURIComponent(r.slice(o+1))}return null},e.erase=function(t,r){e.set(t,"",{expires:-1,domain:r&&r.domain,path:r&&r.path,secure:0,httponly:0})},e.all=function(){for(var t={},e=document.cookie.split(";");e.length;){var r=e.pop(),o=r.indexOf("=");o=o<0?r.length:o,t[decodeURIComponent(r.slice(0,o).replace(/^\s+/,""))]=decodeURIComponent(r.slice(o+1))}return t}},function(t,e){var r="undefined"!=typeof self?self:this,o=function(){function t(){this.fetch=!1,this.DOMException=r.DOMException}return t.prototype=r,new t}();!function(t){!function(e){var r="URLSearchParams"in t,o="Symbol"in t&&"iterator"in Symbol,n="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function d(t){return"string"!=typeof t&&(t=String(t)),t}function h(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return o&&(e[Symbol.iterator]=function(){return e}),e}function f(t){this.map={},t instanceof f?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=l(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:n&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&n&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},n&&(this.blob=function(){var t=p(this);if(t)return t;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)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,o=p(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=l(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),o=0;o<e.length;o++)r[o]=String.fromCharCode(e[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(t,e){t=c(t),e=d(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},f.prototype.delete=function(t){delete this.map[c(t)]},f.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},f.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},f.prototype.set=function(t,e){this.map[c(t)]=d(e)},f.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},f.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),h(t)},f.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),h(t)},f.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),h(t)},o&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var r,o,n=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new f(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new f(e.headers)),this.method=(r=e.method||this.method||"GET",o=r.toUpperCase(),w.indexOf(o)>-1?o:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function g(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(n))}})),e}function E(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new f(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},m.call(v.prototype),m.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var x=[301,302,303,307,308];E.redirect=function(t,e){if(-1===x.indexOf(e))throw new RangeError("Invalid status code");return new E(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function O(t,r){return new Promise((function(o,i){var s=new v(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new f,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();e.append(o,n)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var n="response"in a?a.response:a.responseText;o(new E(n,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&n&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}O.polyfill=!0,t.fetch||(t.fetch=O,t.Headers=f,t.Request=v,t.Response=E),e.Headers=f,e.Request=v,e.Response=E,e.fetch=O,Object.defineProperty(e,"__esModule",{value:!0})}({})}(o),o.fetch.ponyfill=!0,delete o.fetch.polyfill;var n=o;(e=n.fetch).default=n.fetch,e.fetch=n.fetch,e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response,t.exports=e},function(t,e){!function(t){!function(e){var r="URLSearchParams"in t,o="Symbol"in t&&"iterator"in Symbol,n="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function d(t){return"string"!=typeof t&&(t=String(t)),t}function h(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return o&&(e[Symbol.iterator]=function(){return e}),e}function f(t){this.map={},t instanceof f?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=l(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:n&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&n&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},n&&(this.blob=function(){var t=p(this);if(t)return t;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)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,o=p(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=l(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),o=0;o<e.length;o++)r[o]=String.fromCharCode(e[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(t,e){t=c(t),e=d(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},f.prototype.delete=function(t){delete this.map[c(t)]},f.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},f.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},f.prototype.set=function(t,e){this.map[c(t)]=d(e)},f.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},f.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),h(t)},f.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),h(t)},f.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),h(t)},o&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var r,o,n=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new f(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new f(e.headers)),this.method=(r=e.method||this.method||"GET",o=r.toUpperCase(),w.indexOf(o)>-1?o:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function g(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(n))}})),e}function E(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new f(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},m.call(v.prototype),m.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var x=[301,302,303,307,308];E.redirect=function(t,e){if(-1===x.indexOf(e))throw new RangeError("Invalid status code");return new E(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function O(t,r){return new Promise((function(o,i){var s=new v(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new f,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();e.append(o,n)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var n="response"in a?a.response:a.responseText;o(new E(n,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&n&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}O.polyfill=!0,t.fetch||(t.fetch=O,t.Headers=f,t.Request=v,t.Response=E),e.Headers=f,e.Request=v,e.Response=E,e.fetch=O,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:this)},function(t,e,r){"use strict";r.r(e),r.d(e,"fakeCall",(function(){return w})),r.d(e,"realCall",(function(){return v})),r.d(e,"call",(function(){return g}));var o=r(0);const n=!navigator.userAgent.includes("jsdom"),i=window.location.hostname;var s,a=r(1),u=r.n(a),c=(r(2),new Uint8Array(16));function d(){if(!s&&!(s="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return s(c)}var h=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var f=function(t){return"string"==typeof t&&h.test(t)},p=[],l=0;l<256;++l)p.push((l+256).toString(16).substr(1));var y=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(p[t[e+0]]+p[t[e+1]]+p[t[e+2]]+p[t[e+3]]+"-"+p[t[e+4]]+p[t[e+5]]+"-"+p[t[e+6]]+p[t[e+7]]+"-"+p[t[e+8]]+p[t[e+9]]+"-"+p[t[e+10]]+p[t[e+11]]+p[t[e+12]]+p[t[e+13]]+p[t[e+14]]+p[t[e+15]]).toLowerCase();if(!f(r))throw TypeError("Stringified UUID is invalid");return r};var b=function(t,e,r){var o=(t=t||{}).random||(t.rng||d)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,e){r=r||0;for(var n=0;n<16;++n)e[r+n]=o[n];return e}return y(o)};class m extends Error{constructor(t){super(t);const e=new.target.prototype;Object.setPrototypeOf(this,e)}}const w=({context:t,expectedPayload:e,expectedFailureRate:r=0,method:o,type:s,url:a})=>u=>{const c=!n&&"localhost"===i;c||console.log("FAKE API REQUEST FOR "+(o||"GET")+" "+a),u({type:s.request});const d=new Promise(t=>{setTimeout(()=>{const r="function"==typeof e?e():e;t(r)},c?1:Math.floor(2e3*Math.random()))}).then(e=>{c||(console.log("FAKE API SUCCESS FOR "+(o||"GET")+" "+a),console.log("Payload",e));let n=!1;return void 0!==r&&(n=Math.random()<=r),u({type:n?s.failure:s.success,payload:e,context:t})});return d.catch(t=>{console.error(JSON.stringify(t))}),d},v=({body:t,context:e,cascadeFailureError:r,headers:n,method:i,redirect:s,payload:a,type:c,url:d})=>h=>{h({type:c.request});let f=t||a;f=f?JSON.stringify(f):void 0;const p=Object(o.get)("NAV_CSRF_PROTECTION")?{NAV_CSRF_PROTECTION:Object(o.get)("NAV_CSRF_PROTECTION")}:{},l=(new Date).getTime(),y=d.match(/\?./)?d+"&ts="+l:d+"?ts="+l;return u()(y,{method:i||"GET",redirect:s||"follow",headers:Object.assign(Object.assign({"Content-Type":"application/json; charset=utf-8","X-Request-ID":b()},p),n),body:f}).catch(t=>(console.error(JSON.stringify(t)),Promise.reject(t))).then(t=>{if(t){if(t.status>=400){const e=new m(t.statusText);return e.response=t,e.status=t.status,t.json().then(t=>{throw e.message=t.message||t.error,e.stackTrace=t.stackTrace,e}).catch(t=>(console.error(JSON.stringify(t)),Promise.reject(e)))}return t.status>=300?Promise.resolve({status:t.status,headers:t.headers}):t.json().then(e=>Promise.resolve({status:t.status,headers:t.headers,json:e}))}}).then(r=>{const o=Object.fromEntries(r.headers.entries());return(null==r?void 0:r.status)<300?h({type:c.success,headers:o,payload:null==r?void 0:r.json,originalPayload:t,context:e}):h({type:c.redirect,headers:o,originalPayload:t,context:e})}).catch(o=>{const n=t||a;let i=!1;o.status>=400&&h({type:"API/CALL/REJECTED",error:o,originalPayload:n,context:e}),401===o.status&&(h({type:"SERVER/UNAUTHORIZED/ERROR",payload:{error:o},originalPayload:n,context:e}),i=!0),403===o.status&&(h({type:c.forbidden||c.failure,payload:{error:o},originalPayload:n,context:e}),i=!0),o.status>=500&&(h({type:"SERVER/INTERNAL/ERROR",payload:{error:o},originalPayload:n,context:e}),i=!0),(!i||i&&r)&&h({type:c.failure,payload:{error:o},originalPayload:n,context:e})})},g="localhost"===i?w:v}])})); | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var o in r)("object"==typeof exports?exports:t)[o]=r[o]}}(window,(function(){return function(t){var e={};function r(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,o){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(o,n,function(e){return t[e]}.bind(null,n));return o},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="/lib/",r(r.s=3)}([function(t,e){e.defaults={},e.set=function(t,r,o){var n=o||{},i=e.defaults,s=n.expires||i.expires,a=n.domain||i.domain,u=void 0!==n.path?n.path:void 0!==i.path?i.path:"/",c=void 0!==n.secure?n.secure:i.secure,d=void 0!==n.httponly?n.httponly:i.httponly,h=void 0!==n.samesite?n.samesite:i.samesite,f=s?new Date("number"==typeof s?(new Date).getTime()+864e5*s:s):0;document.cookie=t.replace(/[^+#$&^`|]/g,encodeURIComponent).replace("(","%28").replace(")","%29")+"="+r.replace(/[^+#$&/:<-\[\]-}]/g,encodeURIComponent)+(f&&f.getTime()>=0?";expires="+f.toUTCString():"")+(a?";domain="+a:"")+(u?";path="+u:"")+(c?";secure":"")+(d?";httponly":"")+(h?";samesite="+h:"")},e.get=function(t){for(var e=document.cookie.split(";");e.length;){var r=e.pop(),o=r.indexOf("=");if(o=o<0?r.length:o,decodeURIComponent(r.slice(0,o).replace(/^\s+/,""))===t)return decodeURIComponent(r.slice(o+1))}return null},e.erase=function(t,r){e.set(t,"",{expires:-1,domain:r&&r.domain,path:r&&r.path,secure:0,httponly:0})},e.all=function(){for(var t={},e=document.cookie.split(";");e.length;){var r=e.pop(),o=r.indexOf("=");o=o<0?r.length:o,t[decodeURIComponent(r.slice(0,o).replace(/^\s+/,""))]=decodeURIComponent(r.slice(o+1))}return t}},function(t,e){var r="undefined"!=typeof self?self:this,o=function(){function t(){this.fetch=!1,this.DOMException=r.DOMException}return t.prototype=r,new t}();!function(t){!function(e){var r="URLSearchParams"in t,o="Symbol"in t&&"iterator"in Symbol,n="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function d(t){return"string"!=typeof t&&(t=String(t)),t}function h(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return o&&(e[Symbol.iterator]=function(){return e}),e}function f(t){this.map={},t instanceof f?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=l(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:n&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&n&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},n&&(this.blob=function(){var t=p(this);if(t)return t;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)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,o=p(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=l(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),o=0;o<e.length;o++)r[o]=String.fromCharCode(e[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(t,e){t=c(t),e=d(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},f.prototype.delete=function(t){delete this.map[c(t)]},f.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},f.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},f.prototype.set=function(t,e){this.map[c(t)]=d(e)},f.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},f.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),h(t)},f.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),h(t)},f.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),h(t)},o&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var r,o,n=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new f(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new f(e.headers)),this.method=(r=e.method||this.method||"GET",o=r.toUpperCase(),w.indexOf(o)>-1?o:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function g(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(n))}})),e}function E(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new f(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},m.call(v.prototype),m.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var x=[301,302,303,307,308];E.redirect=function(t,e){if(-1===x.indexOf(e))throw new RangeError("Invalid status code");return new E(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function A(t,r){return new Promise((function(o,i){var s=new v(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new f,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();e.append(o,n)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var n="response"in a?a.response:a.responseText;o(new E(n,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&n&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}A.polyfill=!0,t.fetch||(t.fetch=A,t.Headers=f,t.Request=v,t.Response=E),e.Headers=f,e.Request=v,e.Response=E,e.fetch=A,Object.defineProperty(e,"__esModule",{value:!0})}({})}(o),o.fetch.ponyfill=!0,delete o.fetch.polyfill;var n=o;(e=n.fetch).default=n.fetch,e.fetch=n.fetch,e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response,t.exports=e},function(t,e){!function(t){!function(e){var r="URLSearchParams"in t,o="Symbol"in t&&"iterator"in Symbol,n="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function d(t){return"string"!=typeof t&&(t=String(t)),t}function h(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return o&&(e[Symbol.iterator]=function(){return e}),e}function f(t){this.map={},t instanceof f?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=l(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:n&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&n&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},n&&(this.blob=function(){var t=p(this);if(t)return t;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)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,o=p(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=l(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),o=0;o<e.length;o++)r[o]=String.fromCharCode(e[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(t,e){t=c(t),e=d(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},f.prototype.delete=function(t){delete this.map[c(t)]},f.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},f.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},f.prototype.set=function(t,e){this.map[c(t)]=d(e)},f.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},f.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),h(t)},f.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),h(t)},f.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),h(t)},o&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var r,o,n=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new f(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new f(e.headers)),this.method=(r=e.method||this.method||"GET",o=r.toUpperCase(),w.indexOf(o)>-1?o:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function g(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(n))}})),e}function E(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new f(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},m.call(v.prototype),m.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var x=[301,302,303,307,308];E.redirect=function(t,e){if(-1===x.indexOf(e))throw new RangeError("Invalid status code");return new E(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function A(t,r){return new Promise((function(o,i){var s=new v(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new f,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();e.append(o,n)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var n="response"in a?a.response:a.responseText;o(new E(n,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&n&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}A.polyfill=!0,t.fetch||(t.fetch=A,t.Headers=f,t.Request=v,t.Response=E),e.Headers=f,e.Request=v,e.Response=E,e.fetch=A,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:this)},function(t,e,r){"use strict";r.r(e),r.d(e,"fakeCall",(function(){return E})),r.d(e,"realCall",(function(){return x})),r.d(e,"call",(function(){return A}));var o=r(0);const n=!navigator.userAgent.includes("jsdom"),i=window.location.hostname;var s,a=r(1),u=r.n(a),c=(r(2),new Uint8Array(16));function d(){if(!s&&!(s="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return s(c)}var h=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var f=function(t){return"string"==typeof t&&h.test(t)},p=[],l=0;l<256;++l)p.push((l+256).toString(16).substr(1));var y=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(p[t[e+0]]+p[t[e+1]]+p[t[e+2]]+p[t[e+3]]+"-"+p[t[e+4]]+p[t[e+5]]+"-"+p[t[e+6]]+p[t[e+7]]+"-"+p[t[e+8]]+p[t[e+9]]+"-"+p[t[e+10]]+p[t[e+11]]+p[t[e+12]]+p[t[e+13]]+p[t[e+14]]+p[t[e+15]]).toLowerCase();if(!f(r))throw TypeError("Stringified UUID is invalid");return r};var b=function(t,e,r){var o=(t=t||{}).random||(t.rng||d)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,e){r=r||0;for(var n=0;n<16;++n)e[r+n]=o[n];return e}return y(o)};class m extends Error{constructor(t){super(t);const e=new.target.prototype;Object.setPrototypeOf(this,e)}}const w=t=>{if(t){if(t.status>=400){const e=new m(t.statusText);return e.response=t,e.status=t.status,t.json().then(t=>{throw e.message=t.message||t.error,e.stackTrace=t.stackTrace,e}).catch(t=>(console.error(JSON.stringify(t)),Promise.reject(e)))}return t.status>=300?Promise.resolve({status:t.status,headers:t.headers}):t.json().then(e=>Promise.resolve({status:t.status,headers:t.headers,json:e}))}},v=(t,e,r,o)=>n=>{const i=Object.fromEntries(n.headers.entries());return(null==n?void 0:n.status)<300?t({type:e.success,headers:i,payload:null==n?void 0:n.json,originalPayload:r,context:o}):t({type:e.redirect,headers:i,originalPayload:r,context:o})},g=(t,e,r,o,n)=>i=>{let s=!1;i.status>=400&&t({type:"API/CALL/REJECTED",error:i,originalPayload:r,context:o}),401===i.status&&(t({type:"SERVER/UNAUTHORIZED/ERROR",payload:{error:i},originalPayload:r,context:o}),s=!0),403===i.status&&(t({type:e.forbidden||e.failure,payload:{error:i},originalPayload:r,context:o}),s=!0),i.status>=500&&(t({type:"SERVER/INTERNAL/ERROR",payload:{error:i},originalPayload:r,context:o}),s=!0),(!s||s&&n)&&t({type:e.failure,payload:{error:i},originalPayload:r,context:o})},E=({body:t,context:e,cascadeFailureError:r=!1,expectedPayload:o,expectedServerErrorRate:s=0,expectedFailureRate:a=0,maxDelayTime:u=2e3,method:c,payload:d,type:h,url:f})=>p=>{const l=!n&&"localhost"===i;return l||console.log("FAKE API REQUEST FOR "+(c||"GET")+" "+f),p({type:h.request}),new Promise((t,e)=>{setTimeout(()=>{a>0&&Math.random()<=a&&(l||console.log("FAKE API FAILURE 404 FOR "+(c||"GET")+" "+f),e({status:404})),s>0&&Math.random()<=s&&(l||console.log("FAKE API FAILURE 500 FOR "+(c||"GET")+" "+f),e({status:500})),l||(console.log("FAKE API SUCCESS 200 FOR "+(c||"GET")+" "+f),console.log("Payload",d)),t({headers:{entries:()=>[]},status:200,json:"function"==typeof o?o():o})},l?1:Math.floor(Math.random()*u))}).then(v(p,h,t,e)).catch(g(p,h,t||d,e,r))},x=({body:t,context:e,cascadeFailureError:r=!1,headers:n,method:i,redirect:s,payload:a,type:c,url:d})=>h=>{h({type:c.request});let f=t||a;f=f?JSON.stringify(f):void 0;const p=Object(o.get)("NAV_CSRF_PROTECTION")?{NAV_CSRF_PROTECTION:Object(o.get)("NAV_CSRF_PROTECTION")}:{},l=(new Date).getTime(),y=d.match(/\?./)?d+"&ts="+l:d+"?ts="+l;return u()(y,{method:i||"GET",redirect:s||"follow",headers:Object.assign(Object.assign({"Content-Type":"application/json; charset=utf-8","X-Request-ID":b()},p),n),body:f}).catch(t=>(console.error(JSON.stringify(t)),Promise.reject(t))).then(w).then(v(h,c,t,e)).catch(g(h,c,t||a,e,r))},A="localhost"===i?E:x}])})); | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ { | ||
"main": "lib/index.js", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "scripts": { |
@@ -19,5 +19,6 @@ /// <reference types="react" /> | ||
expectedPayload?: any | ||
expectedFailure?: boolean | ||
expectedFailureRate ?: number | ||
expectedServerErrorRate?: number | ||
expectedFailureRate?: number | ||
headers?: any | ||
maxDelayTime?: number | ||
method?: string | ||
@@ -24,0 +25,0 @@ payload?: any |
303
src/index.ts
@@ -23,7 +23,131 @@ import { get as cookieGet } from 'browser-cookies' | ||
const handleResponse = (response: any) => { | ||
if (response) { | ||
if (response.status >= 400) { | ||
const apiError: ApiError = new ApiError(response.statusText) | ||
apiError.response = response | ||
apiError.status = response.status | ||
// 404s may have body | ||
return response.json().then((json: any) => { | ||
apiError.message = json.message || json.error | ||
apiError.stackTrace = json.stackTrace | ||
throw apiError | ||
}) | ||
.catch((error: any) => { | ||
if (!IS_TEST) { | ||
/* istanbul ignore next */ | ||
console.error(JSON.stringify(error)) | ||
} | ||
return Promise.reject(apiError) | ||
}) | ||
} else { | ||
if (response.status >= 300) { | ||
return Promise.resolve({ | ||
status: response.status, | ||
headers: response.headers | ||
}) | ||
} else { | ||
return response.json().then((json: any) => { | ||
return Promise.resolve({ | ||
status: response.status, | ||
headers: response.headers, | ||
json: json | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
const handleSuccessResponse = (dispatch: any, type: any, body: any, context: any) => { | ||
return (payload: any) => { | ||
const headers = Object.fromEntries(payload.headers.entries()) | ||
if (payload?.status < 300) { | ||
return dispatch({ | ||
type: type.success, | ||
headers: headers, | ||
payload: payload?.json, | ||
originalPayload: body, | ||
context: context | ||
}) | ||
} else { | ||
return dispatch({ | ||
type: type.redirect, | ||
headers: headers, | ||
originalPayload: body, | ||
context: context | ||
}) | ||
} | ||
} | ||
} | ||
const handleFailureResponse = (dispatch: any, type: any, body: any, context: any, cascadeFailureError: boolean) => { | ||
return (error: any) => { | ||
let failureHandled: boolean = false | ||
if (error.status >= 400) { | ||
dispatch({ | ||
type: types.API_CALL_REJECTED, | ||
error: error, | ||
originalPayload: body, | ||
context: context | ||
}) | ||
} | ||
if (error.status === 401) { | ||
dispatch({ | ||
type: types.SERVER_UNAUTHORIZED_ERROR, | ||
payload: { | ||
error: error | ||
}, | ||
originalPayload: body, | ||
context: context | ||
}) | ||
failureHandled = true | ||
} | ||
if (error.status === 403) { | ||
dispatch({ | ||
type: type.forbidden || type.failure, | ||
payload: { | ||
error: error | ||
}, | ||
originalPayload: body, | ||
context: context | ||
}) | ||
failureHandled = true | ||
} | ||
if (error.status >= 500) { | ||
dispatch({ | ||
type: types.SERVER_INTERNAL_ERROR, | ||
payload: { | ||
error: error | ||
}, | ||
originalPayload: body, | ||
context: context | ||
}) | ||
failureHandled = true | ||
} | ||
if (!failureHandled || (failureHandled && cascadeFailureError)) { | ||
dispatch({ | ||
type: type.failure, | ||
payload: { | ||
error: error | ||
}, | ||
originalPayload: body, | ||
context: context | ||
}) | ||
} | ||
} | ||
} | ||
export const fakeCall: ActionCreator<ThunkResult<ActionWithPayload>> = ({ | ||
body, | ||
context, | ||
cascadeFailureError = false, | ||
expectedPayload, | ||
expectedServerErrorRate = 0, | ||
expectedFailureRate = 0, | ||
maxDelayTime = 2000, | ||
method, | ||
payload, | ||
type, | ||
@@ -41,32 +165,40 @@ url | ||
}) | ||
const promise: Promise<ActionWithPayload> = new Promise((resolve) => { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(/* istanbul ignore next */ () => { | ||
const _payload = typeof expectedPayload === 'function' ? expectedPayload() : expectedPayload | ||
resolve(_payload) | ||
}, inTest ? 1 : /* istanbul ignore next */ Math.floor(Math.random() * 2000)) | ||
}).then(payload => { | ||
/* istanbul ignore next */ | ||
if (!inTest) { | ||
console.log('FAKE API SUCCESS FOR ' + (method || 'GET') + ' ' + url) | ||
/* istanbul ignore next */ | ||
console.log('Payload', payload) | ||
} | ||
let willFail: boolean = false | ||
if (expectedFailureRate !== undefined) { | ||
willFail = Math.random() <= expectedFailureRate | ||
} | ||
return dispatch({ | ||
type: willFail ? type.failure : type.success, | ||
payload: payload, | ||
context: context | ||
}) | ||
}) | ||
promise.catch((error) => { | ||
/* istanbul ignore next */ | ||
if (!IS_TEST) { | ||
console.error(JSON.stringify(error)) | ||
} | ||
}) | ||
return promise | ||
if (expectedFailureRate > 0) { | ||
if (Math.random() <= expectedFailureRate) { | ||
if (!inTest) { | ||
console.log('FAKE API FAILURE 404 FOR ' + (method || 'GET') + ' ' + url) | ||
} | ||
reject({ | ||
status: 404, | ||
}) | ||
} | ||
} | ||
if (expectedServerErrorRate > 0) { | ||
if (Math.random() <= expectedServerErrorRate) { | ||
if (!inTest) { | ||
console.log('FAKE API FAILURE 500 FOR ' + (method || 'GET') + ' ' + url) | ||
} | ||
reject({ | ||
status: 500 | ||
}) | ||
} | ||
} | ||
if (!inTest) { | ||
console.log('FAKE API SUCCESS 200 FOR ' + (method || 'GET') + ' ' + url) | ||
/* istanbul ignore next */ | ||
console.log('Payload', payload) | ||
} | ||
resolve({ | ||
headers: {entries: () => []}, | ||
status: 200, | ||
json: typeof expectedPayload === 'function' ? expectedPayload() : expectedPayload | ||
}) | ||
}, inTest ? 1 : /* istanbul ignore next */ Math.floor(Math.random() * maxDelayTime)) | ||
}).then(handleSuccessResponse(dispatch, type, body, context)) | ||
.catch(handleFailureResponse(dispatch, type, body || payload, context, cascadeFailureError)) | ||
} | ||
@@ -76,3 +208,3 @@ } | ||
export const realCall: ActionCreator<ThunkResult<Action | void>> = ({ | ||
body, context, cascadeFailureError, headers, method, redirect, payload, type, url | ||
body, context, cascadeFailureError = false, headers, method, redirect, payload, type, url | ||
}: ApiCallProps): (dispatch: MyThunkDispatch) => Promise<Action | void> => { | ||
@@ -105,112 +237,7 @@ return (dispatch: MyThunkDispatch): Promise<Action | void> => { | ||
return Promise.reject(error) | ||
}).then(response => { | ||
if (response) { | ||
if (response.status >= 400) { | ||
const apiError: ApiError = new ApiError(response.statusText) | ||
apiError.response = response | ||
apiError.status = response.status | ||
// 404s may have body | ||
return response.json().then((json) => { | ||
apiError.message = json.message || json.error | ||
apiError.stackTrace = json.stackTrace | ||
throw apiError | ||
}) | ||
.catch((error) => { | ||
if (!IS_TEST) { | ||
/* istanbul ignore next */ | ||
console.error(JSON.stringify(error)) | ||
} | ||
return Promise.reject(apiError) | ||
}) | ||
} else { | ||
if (response.status >= 300) { | ||
return Promise.resolve({ | ||
status: response.status, | ||
headers: response.headers | ||
}) | ||
} else { | ||
return response.json().then((json) => { | ||
return Promise.resolve({ | ||
status: response.status, | ||
headers: response.headers, | ||
json: json | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
}).then((payload: any) => { | ||
const headers = Object.fromEntries(payload.headers.entries()) | ||
if (payload?.status < 300) { | ||
return dispatch({ | ||
type: type.success, | ||
headers: headers, | ||
payload: payload?.json, | ||
originalPayload: body, | ||
context: context | ||
}) | ||
} else { | ||
return dispatch({ | ||
type: type.redirect, | ||
headers: headers, | ||
originalPayload: body, | ||
context: context | ||
}) | ||
} | ||
}).catch(error => { | ||
const _body: any = body || payload | ||
let failureHandled: boolean = false | ||
}) | ||
.then(handleResponse) | ||
.then(handleSuccessResponse(dispatch, type, body, context)) | ||
.catch(handleFailureResponse(dispatch, type, body || payload, context, cascadeFailureError)) | ||
if (error.status >= 400) { | ||
dispatch({ | ||
type: types.API_CALL_REJECTED, | ||
error: error, | ||
originalPayload: _body, | ||
context: context | ||
}) | ||
} | ||
if (error.status === 401) { | ||
dispatch({ | ||
type: types.SERVER_UNAUTHORIZED_ERROR, | ||
payload: { | ||
error: error | ||
}, | ||
originalPayload: _body, | ||
context: context | ||
}) | ||
failureHandled = true | ||
} | ||
if (error.status === 403) { | ||
dispatch({ | ||
type: type.forbidden || type.failure, | ||
payload: { | ||
error: error | ||
}, | ||
originalPayload: _body, | ||
context: context | ||
}) | ||
failureHandled = true | ||
} | ||
if (error.status >= 500) { | ||
dispatch({ | ||
type: types.SERVER_INTERNAL_ERROR, | ||
payload: { | ||
error: error | ||
}, | ||
originalPayload: _body, | ||
context: context | ||
}) | ||
failureHandled = true | ||
} | ||
if (!failureHandled || (failureHandled && cascadeFailureError)) { | ||
dispatch({ | ||
type: type.failure, | ||
payload: { | ||
error: error | ||
}, | ||
originalPayload: _body, | ||
context: context | ||
}) | ||
} | ||
}) | ||
} | ||
@@ -217,0 +244,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124263
691