chaos-engineering-frontend
Version:
Chaos Engineering Frontend
2 lines • 2.44 kB
JavaScript
var ChaosEngineeringFrontend;!function(){"use strict";let n=(n,e)=>{var t,o,a,i;return t=void 0,o=void 0,a=void 0,i=function*(){if(!(null==e?void 0:e.enabled))return n;let t=Math.random()*(e.max-e.min)+e.min;return yield new Promise(n=>setTimeout(n,t)),n},new(a||(a=Promise))(function(n,e){function r(n){try{c(i.next(n))}catch(n){e(n)}}function u(n){try{c(i.throw(n))}catch(n){e(n)}}function c(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(n){n(t)})).then(r,u)}c((i=i.apply(t,o||[])).next())})},e=(n,e,t)=>{var o,a,i,r;return o=void 0,a=void 0,i=void 0,r=function*(){if(!(null==t?void 0:t.enabled)||Math.random()>t.rate)return n;let e=t.statusCodes[Math.floor(Math.random()*t.statusCodes.length)];return"pattern"===t.strategy&&t.pattern&&!(Date.now()%t.pattern.interval<t.pattern.duration)?n:new Response(`Simulated Error ${e}`,{status:e})},new(i||(i=Promise))(function(n,e){function t(n){try{c(r.next(n))}catch(n){e(n)}}function u(n){try{c(r.throw(n))}catch(n){e(n)}}function c(e){var o;e.done?n(e.value):((o=e.value)instanceof i?o:new i(function(n){n(o)})).then(t,u)}c((r=r.apply(o,a||[])).next())})},t=(n,e)=>(null==e?void 0:e.enabled)&&e.modifyResponse?e.modifyResponse(n):n,o=n=>{var e,t,o,a;return e=void 0,t=void 0,o=void 0,a=function*(){if(!(!(null==n?void 0:n.enabled)||Math.random()>n.rate))return new Response("Offline mode simulated",{status:503})},new(o||(o=Promise))(function(n,i){function r(n){try{c(a.next(n))}catch(n){i(n)}}function u(n){try{c(a.throw(n))}catch(n){i(n)}}function c(e){var t;e.done?n(e.value):((t=e.value)instanceof o?t:new o(function(n){n(t)})).then(r,u)}c((a=a.apply(e,t||[])).next())})},a={enabled:!1};self.addEventListener("message",n=>{let e=n.data;switch(e.type){case"CONFIGURE":a=e.payload;break;case"UPDATE_CONFIG":a=Object.assign(Object.assign({},a),e.payload);break;default:console.warn("Unknown message type")}}),self.addEventListener("fetch",i=>{var r,u,c,s;i.respondWith((r=void 0,u=void 0,c=void 0,s=function*(){let r=yield fetch(i.request),u=yield o(a.offline);return u?u:(r=yield n(r,a.latency),r=t(r=yield e(r,i.request,a.errors),a.tamper))},new(c||(c=Promise))(function(n,e){function t(n){try{a(s.next(n))}catch(n){e(n)}}function o(n){try{a(s.throw(n))}catch(n){e(n)}}function a(e){var a;e.done?n(e.value):((a=e.value)instanceof c?a:new c(function(n){n(a)})).then(t,o)}a((s=s.apply(r,u||[])).next())})))}),ChaosEngineeringFrontend={}}();
//# sourceMappingURL=sw.js.map