axios-cache-interceptor
Version:
Cache interceptor for axios
7 lines • 21.4 kB
JavaScript
/*!
* Axios Cache Interceptor 1.7.0
* (c) 2021-present Arthur Fiorette & Contributors
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("cache-parser"),require("fast-defer"),require("object-code")):"function"==typeof define&&define.amd?define(["exports","cache-parser","fast-defer","object-code"],t):t((e||self).axiosCacheInterceptor={},e.cacheParser,e.fastDefer,e.objectCode)}(this,function(e,t,r,n){var a=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",Pragma:"pragma",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),o=function(e,r){if(!e)return"not enough headers";var n=e[a.CacheControl];if(n){var o=t.parse(String(n));if(o.noCache||o.noStore||"server"===r&&o.private)return"dont cache";if(o.immutable)return{cache:31536e6};if(void 0!==o.maxAge){var i=e[a.Age];return{cache:i?1e3*(o.maxAge-Number(i)):1e3*o.maxAge,stale:void 0!==o.maxStale?1e3*o.maxStale:void 0!==o.staleWhileRevalidate?1e3*o.staleWhileRevalidate:void 0}}}var c=e[a.Expires];if(c){var s=Date.parse(String(c))-Date.now();return s>=0?{cache:s}:"dont cache"}return"not enough headers"};function i(){return i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i.apply(this,arguments)}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function s(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(e){return e?function(t){return e(t)||304===t}:function(e){return e>=200&&e<300||304===e}}function d(e,t){return void 0===e&&(e="get"),void 0===t&&(t=[]),e=e.toLowerCase(),t.some(function(t){return t===e})}function f(e,t){t.headers||(t.headers={});var r=t.cache,n=r.etag,o=r.modifiedSince;if(n){var i,c=!0===n?null==(i=e.data)?void 0:i.headers[a.ETag]:n;c&&(t.headers[a.IfNoneMatch]=c)}o&&(t.headers[a.IfModifiedSince]=!0===o?e.data.headers[a.LastModified]||new Date(e.createdAt).toUTCString():o.toUTCString())}function h(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=i({},t.headers,e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function l(e){return{onFulfilled:function t(n){try{if(n.id=e.generateKey(n),!1===n.cache)return e.debug({id:n.id,msg:"Ignoring cache because config.cache === false",data:n}),Promise.resolve(n);if(n.cache=i({},e.defaults.cache,n.cache),"object"==typeof n.cache.cachePredicate&&n.cache.cachePredicate.ignoreUrls&&n.url)for(var o,c=s(n.cache.cachePredicate.ignoreUrls);!(o=c()).done;){var h=o.value;if(h instanceof RegExp?(h.lastIndex=0,h.test(n.url)):n.url.includes(h))return e.debug({id:n.id,msg:"Ignored because url ("+n.url+") matches ignoreUrls ("+n.cache.cachePredicate.ignoreUrls+")",data:{url:n.url,cachePredicate:n.cache.cachePredicate}}),Promise.resolve(n)}var l,v,g,m,p,b;return n.cache.cacheTakeover&&(null!=(l=n.headers)[v=a.CacheControl]||(l[v]="no-cache"),null!=(g=n.headers)[m=a.Pragma]||(g[m]="no-cache"),null!=(p=n.headers)[b=a.Expires]||(p[b]="0")),d(n.method,n.cache.methods)?Promise.resolve(e.storage.get(n.id,n)).then(function(a){var o;function i(r){var i,c;if(o)return r;function s(t){return i?t:(n.transformResponse=void 0,n.adapter=function(){return Promise.resolve({config:n,data:c.data,headers:c.headers,status:c.status,statusText:c.statusText,cached:!0,stale:"stale"===a.previous,id:n.id})},e.debug({id:n.id,msg:"Returning cached response"}),n)}var u=function(){if("loading"===a.state){var r=function(r){return i?r:(e.debug({id:n.id,msg:"Detected concurrent request, waiting for it to finish"}),function(r,a){try{var s=Promise.resolve(o).then(function(){return Promise.resolve(e.storage.get(n.id,n)).then(function(r){if(!r.data){e.debug({id:n.id,msg:"Deferred resolved, but no data was found, requesting again"});var a=t(n);return i=1,a}c=r.data})})}catch(e){return a(e)}return s&&s.then?s.then(void 0,a):s}(0,function(r){function o(){var e=t(n);return i=1,e}e.debug({id:n.id,msg:"Deferred rejected, requesting again",data:r});var c=function(){if(a.data)return Promise.resolve(null==n.cache.hydrate?void 0:n.cache.hydrate(a)).then(function(){})}();return c&&c.then?c.then(o):o()}))},o=e.waiting.get(n.id),s=function(){if(!o){var e=function(){return i=1,n},t=function(){if(a.data)return Promise.resolve(null==n.cache.hydrate?void 0:n.cache.hydrate(a)).then(function(){})}();return t&&t.then?t.then(e):e()}}();return s&&s.then?s.then(r):r(s)}c=a.data}();return u&&u.then?u.then(s):s(u)}var c=n.cache.override,s=function(){if("empty"===a.state||"stale"===a.state||"must-revalidate"===a.state||c){var t=function(){var t=r.deferred();return e.waiting.set(n.id,t),t.catch(function(){}),Promise.resolve(e.storage.set(n.id,{state:"loading",previous:c?a.data?"stale":"empty":a.state,data:a.data,createdAt:c&&!a.createdAt?Date.now():a.createdAt},n)).then(function(){function t(){return o=1,n}"stale"!==a.state&&"must-revalidate"!==a.state||(f(a,n),e.debug({id:n.id,msg:"Updated stale request"})),n.validateStatus=u(n.validateStatus),e.debug({id:n.id,msg:"Sending request, waiting for response",data:{overrideCache:c,state:a.state}});var r=function(){if("stale"===a.state||a.data&&"must-revalidate"!==a.state)return Promise.resolve(null==n.cache.hydrate?void 0:n.cache.hydrate(a)).then(function(){})}();return r&&r.then?r.then(t):t()})},i=function(){if(e.waiting.has(n.id)&&!c)return Promise.resolve(e.storage.get(n.id,n)).then(function(t){"empty"!==(a=t).state&&"must-revalidate"!==a.state&&e.debug({id:n.id,msg:"Waiting list had an deferred for this key, waiting for it to finish"})})}();return i&&i.then?i.then(t):t()}}();return s&&s.then?s.then(i):i(s)}):(e.debug({id:n.id,msg:"Ignored because method ("+n.method+") is not in cache.methods ("+n.cache.methods+")"}),Promise.resolve(n))}catch(e){return Promise.reject(e)}}}}const v="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function g(e,t,r){if(!e.s){if(r instanceof m){if(!r.s)return void(r.o=g.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(g.bind(null,e,t),g.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var m=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,a=this.s;if(a){var o=1&a?t:r;if(o){try{g(n,1,o(this.v))}catch(e){g(n,2,e)}return n}return this}return this.o=function(e){try{var a=e.v;1&e.s?g(n,1,t?t(a):a):r?g(n,1,r(a)):g(n,2,a)}catch(e){g(n,2,e)}},n},e}();function p(e){return e instanceof m&&1&e.s}var b=function(e,t){try{var r=function(t){function r(r){var i;if(n&&!t||a&&!r)return!1;var c=function(){if(o)return function(e,t,r){if("function"==typeof e[v]){var n,a,o,i=e[v]();if(function e(c){try{for(;!((n=i.next()).done||r&&r());)if((c=t(n.value))&&c.then){if(!p(c))return void c.then(e,o||(o=g.bind(null,a=new m,2)));c=c.v}a?g(a,1,c):a=c}catch(e){g(a||(a=new m),2,e)}}(),i.return){var c=function(e){try{n.done||i.return()}catch(e){}return e};if(a&&a.then)return a.then(c,function(e){throw c(e)});c()}return a}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],u=0;u<e.length;u++)s.push(e[u]);return function(e,t,r){var n,a,o=-1;return function i(c){try{for(;++o<e.length&&(!r||!r());)if((c=t(o))&&c.then){if(!p(c))return void c.then(i,a||(a=g.bind(null,n=new m,2)));c=c.v}n?g(n,1,c):n=c}catch(e){g(n||(n=new m),2,e)}}(),n}(s,function(e){return t(s[e])},r)}(Object.entries(o),function(t){var r,n=t[0];return Promise.resolve((0,t[1])(null!=(r=e.headers[n.toLowerCase()])?r:e.headers[n])).then(function(e){if(!e)return i=1,!1})},function(){return i})}();return c&&c.then?c.then(function(e){return!i||e}):!i||c}return n&&!t||!a?r(n&&!t||a&&a(e)):Promise.resolve(n&&!t||a&&a(e)).then(r)};if("function"==typeof t)return Promise.resolve(t(e));var n=t.statusCheck,a=t.responseMatch,o=t.containsHeaders;return Promise.resolve(n?Promise.resolve(n(e.status)).then(r):r(n))}catch(e){return Promise.reject(e)}};const y="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function P(e,t,r){if(!e.s){if(r instanceof w){if(!r.s)return void(r.o=P.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(P.bind(null,e,t),P.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var w=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,a=this.s;if(a){var o=1&a?t:r;if(o){try{P(n,1,o(this.v))}catch(e){P(n,2,e)}return n}return this}return this.o=function(e){try{var a=e.v;1&e.s?P(n,1,t?t(a):a):r?P(n,1,r(a)):P(n,2,a)}catch(e){P(n,2,e)}},n},e}();function S(e){return e instanceof w&&1&e.s}var I=function(e,t,r){try{if("function"==typeof r)return Promise.resolve(r(t));var n=function(e,t,r){if("function"==typeof e[y]){var n,a,o,i=e[y]();if(function e(r){try{for(;!(n=i.next()).done;)if((r=t(n.value))&&r.then){if(!S(r))return void r.then(e,o||(o=P.bind(null,a=new w,2)));r=r.v}a?P(a,1,r):a=r}catch(e){P(a||(a=new w),2,e)}}(),i.return){var c=function(e){try{n.done||i.return()}catch(e){}return e};if(a&&a.then)return a.then(c,function(e){throw c(e)});c()}return a}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],u=0;u<e.length;u++)s.push(e[u]);return function(e,t,r){var n,a,o=-1;return function r(i){try{for(;++o<e.length;)if((i=t(o))&&i.then){if(!S(i))return void i.then(r,a||(a=P.bind(null,n=new w,2)));i=i.v}n?P(n,1,i):n=i}catch(e){P(n||(n=new w),2,e)}}(),n}(s,function(e){return t(s[e])})}(Object.entries(r),function(r){var n=r[0],a=r[1];function o(){return Promise.resolve(e.get(n,t.config)).then(function(r){if("loading"!==r.state)return Promise.resolve(a(r,t)).then(function(r){function a(){var a=function(){if("ignore"!==r)return Promise.resolve(e.set(n,r,t.config)).then(function(){})}();if(a&&a.then)return a.then(function(){})}var o=function(){if("delete"===r)return Promise.resolve(e.remove(n,t.config)).then(function(){})}();return o&&o.then?o.then(a):a()})})}var i=function(){if("delete"===a)return Promise.resolve(e.remove(n,t.config)).then(function(){})}();return i&&i.then?i.then(o):o()});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}};function x(e){var r=function(t,r,n){try{var a=function(){var r=e.waiting.get(t);r&&(r.reject(),e.waiting.delete(t))},o=function(){if(n)return Promise.resolve(e.storage.remove(t,r)).then(function(){})}();return Promise.resolve(o&&o.then?o.then(a):a())}catch(e){return Promise.reject(e)}};return{onFulfilled:function(t){try{var n=function(){return d(o.method,i.methods)?Promise.resolve(e.storage.get(t.id,o)).then(function(n){function c(c){function u(c){var s;function u(r){if(s)return r;function c(){i.staleIfError&&(t.headers[a.XAxiosCacheStaleIfError]=String(g)),e.debug({id:t.id,msg:"Useful response configuration found",data:{cacheConfig:i,cacheResponse:u}});var r={state:"cached",ttl:g,staleTtl:v,createdAt:Date.now(),data:u};return Promise.resolve(e.storage.set(t.id,r,o)).then(function(){var n=e.waiting.get(t.id);return n&&(n.resolve(),e.waiting.delete(t.id),e.debug({id:t.id,msg:"Found waiting deferred(s) and resolved them"})),e.debug({id:t.id,msg:"Response cached",data:{cache:r,response:t}}),t})}var u=h(t,n.data),d=function(){if("function"==typeof g)return Promise.resolve(g(t)).then(function(e){g=e})}();return d&&d.then?d.then(c):c()}for(var d=0,f=Object.keys(t.headers);d<f.length;d++){var l=f[d];l.startsWith("x-axios-cache")&&delete t.headers[l]}i.etag&&!0!==i.etag&&(t.headers[a.XAxiosCacheEtag]=i.etag),i.modifiedSince&&(t.headers[a.XAxiosCacheLastModified]=!0===i.modifiedSince?"use-cache-timestamp":i.modifiedSince.toUTCString());var v,g=i.ttl||-1,m=function(){if(i.interpretHeader){var a=function(e){if(s)return e;"not enough headers"!==c&&("number"==typeof c?g=c:(g=c.cache,v=c.stale))},c=e.headerInterpreter(t.headers,e.location),u=function(){if("dont cache"===c)return Promise.resolve(r(t.id,o,!0)).then(function(){return e.debug({id:t.id,msg:"Cache header interpreted as 'dont cache'",data:{cache:n,response:t,expirationTime:c}}),s=1,t})}();return u&&u.then?u.then(a):a(u)}}();return m&&m.then?m.then(u):u(m)}var d=function(){if(s&&!c)return Promise.resolve(r(t.id,o,!0)).then(function(){return e.debug({id:t.id,msg:"Cache predicate rejected this response"}),t})}();return d&&d.then?d.then(u):u()}if("loading"!==n.state)return e.debug({id:t.id,msg:"Response not cached and storage isn't loading",data:{cache:n,response:t}}),t;var s=!n.data;return s?Promise.resolve(b(t,i.cachePredicate)).then(c):c(s)}):(e.debug({id:t.id,msg:"Ignored because method ("+o.method+") is not in cache.methods ("+i.methods+")",data:{config:o,cacheConfig:i}}),t)};if(null==t||!t.config)throw e.debug({msg:"Response interceptor received an unknown response.",data:t}),t;t.id=t.config.id,null!=t.cached||(t.cached=!1);var o=t.config,i=o.cache;if(t.cached)return e.debug({id:t.id,msg:"Returned cached response"}),Promise.resolve(t);if(!i)return e.debug({id:t.id,msg:"Response with config.cache falsy",data:t}),t.cached=!1,Promise.resolve(t);var c=function(){if(i.update)return Promise.resolve(I(e.storage,t,i.update)).then(function(){})}();return Promise.resolve(c&&c.then?c.then(n):n())}catch(e){return Promise.reject(e)}},onRejected:function(n){try{var o=function(o){return Promise.resolve(e.storage.get(c,i)).then(function(o){function d(d){var f;function h(t){return f?t:(e.debug({id:c,msg:"Received an unknown error that could not be handled",data:{error:n,config:i}}),Promise.resolve(r(c,i,!0)).then(function(){throw n}))}var l=function(){if(s.staleIfError){var r=function(t){return e.debug({id:c,msg:"Found cache if stale config for rejected response",data:{error:n,config:i,staleIfError:t}}),function(){if(!0===t||"number"==typeof t&&o.createdAt+t>Date.now())return Promise.resolve(e.storage.set(c,{state:"stale",createdAt:Date.now(),data:o.data},i)).then(function(){var t=e.waiting.get(c);return t&&(t.resolve(),e.waiting.delete(c),e.debug({id:c,msg:"Found waiting deferred(s) and resolved them"})),e.debug({id:c,msg:"staleIfError resolved this response with cached data",data:{error:n,config:i,cache:o}}),f=1,{cached:!0,stale:!0,config:i,id:c,data:o.data.data,headers:o.data.headers,status:o.data.status,statusText:o.data.statusText}})}()},d=String(null==u?void 0:u.headers[a.CacheControl]),h=d&&t.parse(d).staleIfError;return"function"==typeof s.staleIfError?Promise.resolve(s.staleIfError(u,o,n)).then(r):r(!0===s.staleIfError&&h?1e3*h:s.staleIfError)}}();return l&&l.then?l.then(h):h(l)}var f=function(){if("loading"!==o.state||"stale"!==o.previous)return e.debug({id:c,msg:"Caught an error in the request interceptor",data:{cache:o,error:n,config:i}}),Promise.resolve(r(c,i,"ERR_CANCELED"!==n.code||"ERR_CANCELED"===n.code&&"cached"!==o.state)).then(function(){throw n})}();return f&&f.then?f.then(d):d()})};if(!n.isAxiosError||!n.config)throw e.debug({msg:"FATAL: Received an non axios error in the rejected response interceptor, ignoring.",data:n}),n;var i=n.config,c=i.id,s=i.cache,u=n.response;if(!s||!c)throw e.debug({msg:"Web request returned an error but cache handling is not enabled",data:{error:n}}),n;var f=function(){if(!d(i.method,s.methods))return e.debug({id:c,msg:"Ignored because method ("+i.method+") is not in cache.methods ("+s.methods+")",data:{config:i,cacheConfig:s}}),Promise.resolve(r(c,i,!0)).then(function(){throw n})}();return Promise.resolve(f&&f.then?f.then(o):o())}catch(e){return Promise.reject(e)}}}}var C=function(e){return!!e&&!!e["is-storage"]};function j(e){var t=e.data.headers;return a.ETag in t||a.LastModified in t||a.XAxiosCacheEtag in t||a.XAxiosCacheLastModified in t}function A(e){return String(e.data.headers[a.CacheControl]).includes("must-revalidate")}function E(e){return!!j(e)||"cached"===e.state&&void 0!==e.staleTtl&&Math.abs(Date.now()-(e.createdAt+e.ttl))<=e.staleTtl}function T(e){return void 0!==e.ttl&&e.createdAt+e.ttl<=Date.now()}function R(e){var t=e.set,r=e.find,n=e.remove;return{"is-storage":1,set:t,remove:n,clear:e.clear,get:function(e,a){try{return Promise.resolve(r(e,a)).then(function(r){var o;function c(t){return o?t:T(r)?j(r)?r:Promise.resolve(n(e,a)).then(function(){return{state:"empty"}}):r}if(!r)return{state:"empty"};if("empty"===r.state||"loading"===r.state||"must-revalidate"===r.state)return r;var s=function(){if("cached"===r.state){var c=function(n){return o?n:(r={state:"stale",createdAt:r.createdAt,data:r.data,ttl:void 0!==r.staleTtl?r.staleTtl+r.ttl:void 0},Promise.resolve(t(e,r,a)).then(function(){if(A(r)){var e=i({},r,{state:"must-revalidate"});return o=1,e}}))};if(!T(r))return o=1,r;var s=function(){if(!E(r))return Promise.resolve(n(e,a)).then(function(){return o=1,{state:"empty"}})}();return s&&s.then?s.then(c):c(s)}}();return s&&s.then?s.then(c):c(s)})}catch(e){return Promise.reject(e)}}}}var O="function"==typeof structuredClone?structuredClone:function(e){return JSON.parse(JSON.stringify(e))};function q(e,t,r){void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===r&&(r=!1);var n=R({set:function(t,a){if(r){var o=Object.keys(n.data);if(o.length>=r)for(n.cleanup(),o=Object.keys(n.data);o.length>=r;)delete n.data[o.shift()]}n.data[t]="double"===e?O(a):a},remove:function(e){delete n.data[e]},find:function(t){var r=n.data[t];return e&&void 0!==r?O(r):r},clear:function(){n.data=Object.create(null)}});return n.data=Object.create(null),n.cleanup=function(){for(var e,t,r=Object.keys(n.data),a=-1;++a<r.length;)"empty"!==(e=n.data[t=r[a]]).state?"cached"===e.state&&T(e)&&!E(e)&&n.remove(t):n.remove(t)},t&&(n.cleaner=setInterval(n.cleanup,t)),n}var M=/^\/|\/$/g;function D(e){return function(t){if(t.id)return t.id;var r=e(t);return"string"==typeof r||"number"==typeof r?""+r:""+n.hash(r)}}var k=D(function(e){var t=e.baseURL,r=e.url,n=e.method,a=e.params,o=e.data;return t=void 0!==t?t.replace(M,""):"",r=void 0!==r?r.replace(M,""):"",{url:t+(t&&r?"/":"")+r,params:a,method:n=void 0!==n?n.toLowerCase():"get",data:o}});console.error("You are using a development build. Make sure to use the correct build in production\nhttps://axios-cache-interceptor.js.org/guide/getting-started\n\n"),e.Header=a,e.buildKeyGenerator=D,e.buildMemoryStorage=q,e.buildStorage=R,e.buildWebStorage=function(e,t){return void 0===t&&(t="axios-cache-"),R({clear:function(){for(var r in e)r.startsWith(t)&&e.removeItem(r)},find:function(r){var n=e.getItem(t+r);return n?JSON.parse(n):void 0},remove:function(r){e.removeItem(t+r)},set:function(r,n){var a=function(){return e.setItem(t+r,JSON.stringify(n))};try{return a()}catch(n){for(var o,i=Object.entries(e).filter(function(e){return e[0].startsWith(t)}).map(function(e){return[e[0],JSON.parse(e[1])]}),c=s(i);!(o=c()).done;){var u=o.value;"cached"===u[1].state&&T(u[1])&&!E(u[1])&&e.removeItem(u[0])}try{return a()}catch(t){for(var d,f=s(i.sort(function(e,t){return(e[1].createdAt||0)-(t[1].createdAt||0)}));!(d=f()).done;){e.removeItem(d.value[0]);try{return a()}catch(e){}}}e.removeItem(t+r)}}})},e.canStale=E,e.createCacheResponse=h,e.createValidateStatus=u,e.defaultHeaderInterpreter=o,e.defaultKeyGenerator=k,e.defaultRequestInterceptor=l,e.defaultResponseInterceptor=x,e.isExpired=T,e.isMethodIn=d,e.isStorage=C,e.mustRevalidate=A,e.setupCache=function(e,t){var r,n,a,i,c,s,u,d;void 0===t&&(t={});var f=e;if(f.defaults.cache)throw new Error("setupCache() should be called only once");if(f.location="undefined"==typeof window?"server":"client",f.storage=t.storage||q(),!C(f.storage))throw new Error("Use buildStorage() function");return f.waiting=t.waiting||new Map,f.generateKey=t.generateKey||k,f.headerInterpreter=t.headerInterpreter||o,f.requestInterceptor=t.requestInterceptor||l(f),f.responseInterceptor=t.responseInterceptor||x(f),f.debug=t.debug||function(){},f.defaults.cache={update:t.update||{},ttl:null!=(r=t.ttl)?r:3e5,methods:t.methods||["get","head"],cachePredicate:t.cachePredicate||{statusCheck:function(e){return[200,203,300,301,302,404,405,410,414,501].includes(e)}},etag:null==(n=t.etag)||n,modifiedSince:null!=(a=t.modifiedSince)?a:!1===t.etag,interpretHeader:null==(i=t.interpretHeader)||i,cacheTakeover:null==(c=t.cacheTakeover)||c,staleIfError:null==(s=t.staleIfError)||s,override:null!=(u=t.override)&&u,hydrate:null!=(d=t.hydrate)?d:void 0},f.interceptors.request.use(f.requestInterceptor.onFulfilled,f.requestInterceptor.onRejected),f.interceptors.response.use(f.responseInterceptor.onFulfilled,f.responseInterceptor.onRejected),f},e.testCachePredicate=b,e.updateCache=I,e.updateStaleRequest=f});
//# sourceMappingURL=index.bundle.js.map