axios-cache-interceptor
Advanced tools
Comparing version 1.6.1 to 1.6.2
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (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"}),i=function(e){if(!e)return"not enough headers";var r=e[a.CacheControl];if(r){var n=t.parse(String(r)),i=n.maxAge,o=n.maxStale,c=n.staleWhileRevalidate;if(n.noCache||n.noStore)return"dont cache";if(n.immutable)return{cache:31536e6};if(void 0!==i){var s=e[a.Age];return{cache:s?1e3*(i-Number(s)):1e3*i,stale:void 0!==o?1e3*o:void 0!==c?1e3*c:void 0}}}var u=e[a.Expires];if(u){var d=Date.parse(String(u))-Date.now();return d>=0?{cache:d}:"dont cache"}return"not enough headers"};function o(){return o=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},o.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,i=r.modifiedSince;if(n){var o,c=!0===n?null==(o=e.data)?void 0:o.headers[a.ETag]:n;c&&(t.headers[a.IfNoneMatch]=c)}i&&(t.headers[a.IfModifiedSince]=!0===i?e.data.headers[a.LastModified]||new Date(e.createdAt).toUTCString():i.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=o({},t.headers,e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function l(e){var t=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=o({},e.defaults.cache,n.cache),"object"==typeof n.cache.cachePredicate&&n.cache.cachePredicate.ignoreUrls&&n.url)for(var i,c=s(n.cache.cachePredicate.ignoreUrls);!(i=c()).done;){var h=i.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 i;function o(r){var o,c;if(i)return r;function s(t){return o?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 o?r:(e.debug({id:n.id,msg:"Detected concurrent request, waiting for it to finish"}),function(r,a){try{var s=Promise.resolve(i).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 o=1,a}c=r.data})})}catch(e){return a(e)}return s&&s.then?s.then(void 0,a):s}(0,function(r){function i(){var e=t(n);return o=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(i):i()}))},i=e.waiting.get(n.id),s=function(){if(!i){var e=function(){return o=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 i=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()})},o=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 o&&o.then?o.then(t):t()}}();return s&&s.then?s.then(o):o(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)}};return{onFulfilled:t,apply:function(){return e.interceptors.request.use(t)}}}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 i=1&a?t:r;if(i){try{g(n,1,i(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 o;if(n&&!t||a&&!r)return!1;var c=function(){if(i)return function(e,t,r){if("function"==typeof e[v]){var n,a,i,o=e[v]();if(function e(c){try{for(;!((n=o.next()).done||r&&r());)if((c=t(n.value))&&c.then){if(!p(c))return void c.then(e,i||(i=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)}}(),o.return){var c=function(e){try{n.done||o.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,i=-1;return function o(c){try{for(;++i<e.length&&(!r||!r());)if((c=t(i))&&c.then){if(!p(c))return void c.then(o,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(i),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 o=1,!1})},function(){return o})}();return c&&c.then?c.then(function(e){return!o||e}):!o||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,i=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 i=1&a?t:r;if(i){try{P(n,1,i(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,i,o=e[y]();if(function e(r){try{for(;!(n=o.next()).done;)if((r=t(n.value))&&r.then){if(!S(r))return void r.then(e,i||(i=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)}}(),o.return){var c=function(e){try{n.done||o.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,i=-1;return function r(o){try{for(;++i<e.length;)if((o=t(i))&&o.then){if(!S(o))return void o.then(r,a||(a=P.bind(null,n=new w,2)));o=o.v}n?P(n,1,o):n=o}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 i(){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 i=function(){if("delete"===r)return Promise.resolve(e.remove(n,t.config)).then(function(){})}();return i&&i.then?i.then(a):a()})})}var o=function(){if("delete"===a)return Promise.resolve(e.remove(n,t.config)).then(function(){})}();return o&&o.then?o.then(i):i()});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){try{return Promise.resolve(e.storage.remove(t,r)).then(function(){var r=e.waiting.get(t);r&&(r.reject(),e.waiting.delete(t))})}catch(e){return Promise.reject(e)}},n=function(t){try{var n=function(){return d(i.method,o.methods)?Promise.resolve(e.storage.get(t.id,i)).then(function(n){function c(c){function u(c){var s;function u(r){if(s)return r;function c(){o.staleIfError&&(t.headers[a.XAxiosCacheStaleIfError]=String(g)),e.debug({id:t.id,msg:"Useful response configuration found",data:{cacheConfig:o,cacheResponse:u}});var r={state:"cached",ttl:g,staleTtl:v,createdAt:Date.now(),data:u};return Promise.resolve(e.storage.set(t.id,r,i)).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]}o.etag&&!0!==o.etag&&(t.headers[a.XAxiosCacheEtag]=o.etag),o.modifiedSince&&(t.headers[a.XAxiosCacheLastModified]=!0===o.modifiedSince?"use-cache-timestamp":o.modifiedSince.toUTCString());var v,g=o.ttl||-1,m=function(){if(o.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),u=function(){if("dont cache"===c)return Promise.resolve(r(t.id,i)).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,i)).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,o.cachePredicate)).then(c):c(s)}):(e.debug({id:t.id,msg:"Ignored because method ("+i.method+") is not in cache.methods ("+o.methods+")",data:{config:i,cacheConfig:o}}),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 i=t.config,o=i.cache;if(t.cached)return e.debug({id:t.id,msg:"Returned cached response"}),Promise.resolve(t);if(!o)return e.debug({id:t.id,msg:"Response with config.cache falsy",data:t}),t.cached=!1,Promise.resolve(t);var c=function(){if(o.update)return Promise.resolve(I(e.storage,t,o.update)).then(function(){})}();return Promise.resolve(c&&c.then?c.then(n):n())}catch(e){return Promise.reject(e)}},i=function(n){try{var i=function(i){return Promise.resolve(e.storage.get(c,o)).then(function(i){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:o}}),Promise.resolve(r(c,o)).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:o,staleIfError:t}}),function(){if(!0===t||"number"==typeof t&&i.createdAt+t>Date.now())return Promise.resolve(e.storage.set(c,{state:"stale",createdAt:Date.now(),data:i.data},o)).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:o,cache:i}}),f=1,{cached:!0,stale:!0,config:o,id:c,data:i.data.data,headers:i.data.headers,status:i.data.status,statusText:i.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,i,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"!==i.state||"stale"!==i.previous)return e.debug({id:c,msg:"Caught an error in the request interceptor",data:{cache:i,error:n,config:o}}),Promise.resolve(r(c,o)).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 o=n.config,c=o.id,s=o.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(o.method,s.methods))return e.debug({id:c,msg:"Ignored because method ("+o.method+") is not in cache.methods ("+s.methods+")",data:{config:o,cacheConfig:s}}),Promise.resolve(r(c,o)).then(function(){throw n})}();return Promise.resolve(f&&f.then?f.then(i):i())}catch(e){return Promise.reject(e)}};return{onFulfilled:n,onRejected:i,apply:function(){return e.interceptors.response.use(n,i)}}}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 O(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 i;function c(t){return i?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 i?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=o({},r,{state:"must-revalidate"});return i=1,e}}))};if(!T(r))return i=1,r;var s=function(){if(!E(r))return Promise.resolve(n(e,a)).then(function(){return i=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 R="function"==typeof structuredClone?structuredClone:function(e){return JSON.parse(JSON.stringify(e))};function M(e,t,r){void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===r&&(r=!1);var n=O({set:function(t,a){if(r){var i=Object.keys(n.data);if(i.length>=r)for(n.cleanup(),i=Object.keys(n.data);i.length>=r;)delete n.data[i.shift()]}n.data[t]="double"===e?R(a):a},remove:function(e){delete n.data[e]},find:function(t){var r=n.data[t];return e&&void 0!==r?R(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 q=/^\/|\/$/g;function k(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 D=k(function(e){var t=e.baseURL,r=e.url,n=e.method,a=e.params,i=e.data;return t=void 0!==t?t.replace(q,""):"",r=void 0!==r?r.replace(q,""):"",{url:t+(t&&r?"/":"")+r,params:a,method:n=void 0!==n?n.toLowerCase():"get",data:i}});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=k,e.buildMemoryStorage=M,e.buildStorage=O,e.buildWebStorage=function(e,t){return void 0===t&&(t="axios-cache-"),O({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 i,o=Object.entries(e).filter(function(e){return e[0].startsWith(t)}).map(function(e){return[e[0],JSON.parse(e[1])]}),c=s(o);!(i=c()).done;){var u=i.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(o.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=i,e.defaultKeyGenerator=D,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,o,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.storage=t.storage||M(),!C(f.storage))throw new Error("Use buildStorage() function");return f.waiting=t.waiting||new Map,f.generateKey=t.generateKey||D,f.headerInterpreter=t.headerInterpreter||i,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==(o=t.interpretHeader)||o,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.requestInterceptor.apply(),f.responseInterceptor.apply(),f},e.testCachePredicate=b,e.updateCache=I,e.updateStaleRequest=f}); | ||
!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){if(!e)return"not enough headers";var r=e[a.CacheControl];if(r){var n=t.parse(String(r)),o=n.maxAge,i=n.maxStale,c=n.staleWhileRevalidate;if(n.noCache||n.noStore)return"dont cache";if(n.immutable)return{cache:31536e6};if(void 0!==o){var s=e[a.Age];return{cache:s?1e3*(o-Number(s)):1e3*o,stale:void 0!==i?1e3*i:void 0!==c?1e3*c:void 0}}}var u=e[a.Expires];if(u){var d=Date.parse(String(u))-Date.now();return d>=0?{cache:d}:"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){var t=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)}};return{onFulfilled:t,apply:function(){return e.interceptors.request.use(t)}}}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 C=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 I(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)}},n=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),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(C(e.storage,t,i.update)).then(function(){})}();return Promise.resolve(c&&c.then?c.then(n):n())}catch(e){return Promise.reject(e)}},o=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)}};return{onFulfilled:n,onRejected:o,apply:function(){return e.interceptors.response.use(n,o)}}}var x=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 E(e){return String(e.data.headers[a.CacheControl]).includes("must-revalidate")}function A(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 O(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(E(r)){var e=i({},r,{state:"must-revalidate"});return o=1,e}}))};if(!T(r))return o=1,r;var s=function(){if(!A(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 R="function"==typeof structuredClone?structuredClone:function(e){return JSON.parse(JSON.stringify(e))};function M(e,t,r){void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===r&&(r=!1);var n=O({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?R(a):a},remove:function(e){delete n.data[e]},find:function(t){var r=n.data[t];return e&&void 0!==r?R(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)&&!A(e)&&n.remove(t):n.remove(t)},t&&(n.cleaner=setInterval(n.cleanup,t)),n}var q=/^\/|\/$/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(q,""):"",r=void 0!==r?r.replace(q,""):"",{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=M,e.buildStorage=O,e.buildWebStorage=function(e,t){return void 0===t&&(t="axios-cache-"),O({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])&&!A(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=A,e.createCacheResponse=h,e.createValidateStatus=u,e.defaultHeaderInterpreter=o,e.defaultKeyGenerator=k,e.defaultRequestInterceptor=l,e.defaultResponseInterceptor=I,e.isExpired=T,e.isMethodIn=d,e.isStorage=x,e.mustRevalidate=E,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.storage=t.storage||M(),!x(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||I(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.requestInterceptor.apply(),f.responseInterceptor.apply(),f},e.testCachePredicate=b,e.updateCache=C,e.updateStaleRequest=f}); | ||
//# sourceMappingURL=index.bundle.js.map |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -511,5 +511,7 @@ * Released under the MIT License. | ||
*/ | ||
const rejectResponse = async (responseId, config) => { | ||
const rejectResponse = async (responseId, config, clearCache) => { | ||
// Updates the cache to empty to prevent infinite loading state | ||
await axios.storage.remove(responseId, config); | ||
if (clearCache) { | ||
await axios.storage.remove(responseId, config); | ||
} | ||
// Rejects the deferred, if present | ||
@@ -600,3 +602,3 @@ const deferred = axios.waiting.get(responseId); | ||
!cache.data && !(await testCachePredicate(response, cacheConfig.cachePredicate))) { | ||
await rejectResponse(response.id, config); | ||
await rejectResponse(response.id, config, true); | ||
{ | ||
@@ -628,3 +630,3 @@ axios.debug({ | ||
if (expirationTime === 'dont cache') { | ||
await rejectResponse(response.id, config); | ||
await rejectResponse(response.id, config, true); | ||
{ | ||
@@ -745,3 +747,3 @@ axios.debug({ | ||
// Rejects all other requests waiting for this response | ||
await rejectResponse(id, config); | ||
await rejectResponse(id, config, true); | ||
throw error; | ||
@@ -765,3 +767,5 @@ } | ||
// Rejects all other requests waiting for this response | ||
await rejectResponse(id, config); | ||
await rejectResponse(id, config, | ||
// Do not clear cache if this request is cached, but the request was cancelled before returning the cached response | ||
error.code !== 'ERR_CANCELED' || error.code === 'ERR_CANCELED' && cache.state !== 'cached'); | ||
throw error; | ||
@@ -840,3 +844,3 @@ } | ||
// Rejects all other requests waiting for this response | ||
await rejectResponse(id, config); | ||
await rejectResponse(id, config, true); | ||
throw error; | ||
@@ -843,0 +847,0 @@ }; |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (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){if(!e)return"not enough headers";var r=e[a.CacheControl];if(r){var n=t.parse(String(r)),o=n.maxAge,i=n.maxStale,u=n.staleWhileRevalidate;if(n.noCache||n.noStore)return"dont cache";if(n.immutable)return{cache:31536e6};if(void 0!==o){var c=e[a.Age];return{cache:c?1e3*(o-Number(c)):1e3*o,stale:void 0!==i?1e3*i:void 0!==u?1e3*u:void 0}}}var s=e[a.Expires];if(s){var f=Date.parse(String(s))-Date.now();return f>=0?{cache:f}:"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 u(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 c(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 u(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)?u(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 s(e){return e?function(t){return e(t)||304===t}:function(e){return e>=200&&e<300||304===e}}function f(e,t){return void 0===e&&(e="get"),void 0===t&&(t=[]),e=e.toLowerCase(),t.some(function(t){return t===e})}function d(e,t){t.headers||(t.headers={});var r=t.cache,n=r.etag,o=r.modifiedSince;if(n){var i,u=!0===n?null==(i=e.data)?void 0:i.headers[a.ETag]:n;u&&(t.headers[a.IfNoneMatch]=u)}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){var t=function t(n){try{if(n.id=e.generateKey(n),!1===n.cache)return 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,u=c(n.cache.cachePredicate.ignoreUrls);!(o=u()).done;){var h=o.value;if(h instanceof RegExp?(h.lastIndex=0,h.test(n.url)):n.url.includes(h))return Promise.resolve(n)}var l,v,m,g,p,y;return n.cache.cacheTakeover&&(null!=(l=n.headers)[v=a.CacheControl]||(l[v]="no-cache"),null!=(m=n.headers)[g=a.Pragma]||(m[g]="no-cache"),null!=(p=n.headers)[y=a.Expires]||(p[y]="0")),f(n.method,n.cache.methods)?Promise.resolve(e.storage.get(n.id,n)).then(function(a){var o;function i(r){var i,u;if(o)return r;function c(e){return i?e:(n.transformResponse=void 0,n.adapter=function(){return Promise.resolve({config:n,data:u.data,headers:u.headers,status:u.status,statusText:u.statusText,cached:!0,stale:"stale"===a.previous,id:n.id})},n)}var s=function(){if("loading"===a.state){var r=function(r){return i?r:function(r,a){try{var c=Promise.resolve(o).then(function(){return Promise.resolve(e.storage.get(n.id,n)).then(function(e){if(!e.data){var r=t(n);return i=1,r}u=e.data})})}catch(e){return a()}return c&&c.then?c.then(void 0,a):c}(0,function(e){function r(){var e=t(n);return i=1,e}var o=function(){if(a.data)return Promise.resolve(null==n.cache.hydrate?void 0:n.cache.hydrate(a)).then(function(){})}();return o&&o.then?o.then(r):r()})},o=e.waiting.get(n.id),c=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 c&&c.then?c.then(r):r(c)}u=a.data}();return s&&s.then?s.then(c):c(s)}var u=n.cache.override,c=function(){if("empty"===a.state||"stale"===a.state||"must-revalidate"===a.state||u){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:u?a.data?"stale":"empty":a.state,data:a.data,createdAt:u&&!a.createdAt?Date.now():a.createdAt},n)).then(function(){function e(){return o=1,n}"stale"!==a.state&&"must-revalidate"!==a.state||d(a,n),n.validateStatus=s(n.validateStatus);var t=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 t&&t.then?t.then(e):e()})},i=function(){if(e.waiting.has(n.id)&&!u)return Promise.resolve(e.storage.get(n.id,n)).then(function(e){a=e})}();return i&&i.then?i.then(t):t()}}();return c&&c.then?c.then(i):i(c)}):Promise.resolve(n)}catch(e){return Promise.reject(e)}};return{onFulfilled:t,apply:function(){return e.interceptors.request.use(t)}}}const v="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function m(e,t,r){if(!e.s){if(r instanceof g){if(!r.s)return void(r.o=m.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(m.bind(null,e,t),m.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var g=/*#__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{m(n,1,o(this.v))}catch(e){m(n,2,e)}return n}return this}return this.o=function(e){try{var a=e.v;1&e.s?m(n,1,t?t(a):a):r?m(n,1,r(a)):m(n,2,a)}catch(e){m(n,2,e)}},n},e}();function p(e){return e instanceof g&&1&e.s}var y=function(e,t){try{var r=function(t){function r(r){var i;if(n&&!t||a&&!r)return!1;var u=function(){if(o)return function(e,t,r){if("function"==typeof e[v]){var n,a,o,i=e[v]();if(function e(u){try{for(;!((n=i.next()).done||r&&r());)if((u=t(n.value))&&u.then){if(!p(u))return void u.then(e,o||(o=m.bind(null,a=new g,2)));u=u.v}a?m(a,1,u):a=u}catch(e){m(a||(a=new g),2,e)}}(),i.return){var u=function(e){try{n.done||i.return()}catch(e){}return e};if(a&&a.then)return a.then(u,function(e){throw u(e)});u()}return a}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);return function(e,t,r){var n,a,o=-1;return function i(u){try{for(;++o<e.length&&(!r||!r());)if((u=t(o))&&u.then){if(!p(u))return void u.then(i,a||(a=m.bind(null,n=new g,2)));u=u.v}n?m(n,1,u):n=u}catch(e){m(n||(n=new g),2,e)}}(),n}(c,function(e){return t(c[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 u&&u.then?u.then(function(e){return!i||e}):!i||u}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 b="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 x=function(e,t,r){try{if("function"==typeof r)return Promise.resolve(r(t));var n=function(e,t,r){if("function"==typeof e[b]){var n,a,o,i=e[b]();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 u=function(e){try{n.done||i.return()}catch(e){}return e};if(a&&a.then)return a.then(u,function(e){throw u(e)});u()}return a}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);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}(c,function(e){return t(c[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 I(e){var r=function(t,r){try{return Promise.resolve(e.storage.remove(t,r)).then(function(){var r=e.waiting.get(t);r&&(r.reject(),e.waiting.delete(t))})}catch(e){return Promise.reject(e)}},n=function(t){try{var n=function(){return f(o.method,i.methods)?Promise.resolve(e.storage.get(t.id,o)).then(function(n){function u(u){function s(u){var c;function s(r){if(c)return r;function u(){i.staleIfError&&(t.headers[a.XAxiosCacheStaleIfError]=String(m));var r={state:"cached",ttl:m,staleTtl:v,createdAt:Date.now(),data:s};return Promise.resolve(e.storage.set(t.id,r,o)).then(function(){var r=e.waiting.get(t.id);return r&&(r.resolve(),e.waiting.delete(t.id)),t})}var s=h(t,n.data),f=function(){if("function"==typeof m)return Promise.resolve(m(t)).then(function(e){m=e})}();return f&&f.then?f.then(u):u()}for(var f=0,d=Object.keys(t.headers);f<d.length;f++){var l=d[f];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,m=i.ttl||-1,g=function(){if(i.interpretHeader){var n=function(e){if(c)return e;"not enough headers"!==a&&("number"==typeof a?m=a:(m=a.cache,v=a.stale))},a=e.headerInterpreter(t.headers),u=function(){if("dont cache"===a)return Promise.resolve(r(t.id,o)).then(function(){return c=1,t})}();return u&&u.then?u.then(n):n(u)}}();return g&&g.then?g.then(s):s(g)}var f=function(){if(c&&!u)return Promise.resolve(r(t.id,o)).then(function(){return t})}();return f&&f.then?f.then(s):s()}if("loading"!==n.state)return t;var c=!n.data;return c?Promise.resolve(y(t,i.cachePredicate)).then(u):u(c)}):t};if(null==t||!t.config)throw t;t.id=t.config.id,null!=t.cached||(t.cached=!1);var o=t.config,i=o.cache;if(t.cached)return Promise.resolve(t);if(!i)return t.cached=!1,Promise.resolve(t);var u=function(){if(i.update)return Promise.resolve(x(e.storage,t,i.update)).then(function(){})}();return Promise.resolve(u&&u.then?u.then(n):n())}catch(e){return Promise.reject(e)}},o=function(n){try{var o=function(o){return Promise.resolve(e.storage.get(u,i)).then(function(o){function f(f){var d;function h(e){return d?e:Promise.resolve(r(u,i)).then(function(){throw n})}var l=function(){if(c.staleIfError){var r=function(t){return function(){if(!0===t||"number"==typeof t&&o.createdAt+t>Date.now())return Promise.resolve(e.storage.set(u,{state:"stale",createdAt:Date.now(),data:o.data},i)).then(function(){var t=e.waiting.get(u);return t&&(t.resolve(),e.waiting.delete(u)),d=1,{cached:!0,stale:!0,config:i,id:u,data:o.data.data,headers:o.data.headers,status:o.data.status,statusText:o.data.statusText}})}()},f=String(null==s?void 0:s.headers[a.CacheControl]),h=f&&t.parse(f).staleIfError;return"function"==typeof c.staleIfError?Promise.resolve(c.staleIfError(s,o,n)).then(r):r(!0===c.staleIfError&&h?1e3*h:c.staleIfError)}}();return l&&l.then?l.then(h):h(l)}var d=function(){if("loading"!==o.state||"stale"!==o.previous)return Promise.resolve(r(u,i)).then(function(){throw n})}();return d&&d.then?d.then(f):f()})};if(!n.isAxiosError||!n.config)throw n;var i=n.config,u=i.id,c=i.cache,s=n.response;if(!c||!u)throw n;var d=function(){if(!f(i.method,c.methods))return Promise.resolve(r(u,i)).then(function(){throw n})}();return Promise.resolve(d&&d.then?d.then(o):o())}catch(e){return Promise.reject(e)}};return{onFulfilled:n,onRejected:o,apply:function(){return e.interceptors.response.use(n,o)}}}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 O(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 u(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 c=function(){if("cached"===r.state){var u=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 c=function(){if(!E(r))return Promise.resolve(n(e,a)).then(function(){return o=1,{state:"empty"}})}();return c&&c.then?c.then(u):u(c)}}();return c&&c.then?c.then(u):u(c)})}catch(e){return Promise.reject(e)}}}}var M="function"==typeof structuredClone?structuredClone:function(e){return JSON.parse(JSON.stringify(e))};function D(e,t,r){void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===r&&(r=!1);var n=O({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?M(a):a},remove:function(e){delete n.data[e]},find:function(t){var r=n.data[t];return e&&void 0!==r?M(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 L=/^\/|\/$/g;function R(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=R(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(L,""):"",r=void 0!==r?r.replace(L,""):"",{url:t+(t&&r?"/":"")+r,params:a,method:n=void 0!==n?n.toLowerCase():"get",data:o}});e.Header=a,e.buildKeyGenerator=R,e.buildMemoryStorage=D,e.buildStorage=O,e.buildWebStorage=function(e,t){return void 0===t&&(t="axios-cache-"),O({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])]}),u=c(i);!(o=u()).done;){var s=o.value;"cached"===s[1].state&&T(s[1])&&!E(s[1])&&e.removeItem(s[0])}try{return a()}catch(t){for(var f,d=c(i.sort(function(e,t){return(e[1].createdAt||0)-(t[1].createdAt||0)}));!(f=d()).done;){e.removeItem(f.value[0]);try{return a()}catch(e){}}}e.removeItem(t+r)}}})},e.canStale=E,e.createCacheResponse=h,e.createValidateStatus=s,e.defaultHeaderInterpreter=o,e.defaultKeyGenerator=k,e.defaultRequestInterceptor=l,e.defaultResponseInterceptor=I,e.isExpired=T,e.isMethodIn=f,e.isStorage=C,e.mustRevalidate=A,e.setupCache=function(e,t){var r,n,a,i,u,c,s,f;void 0===t&&(t={});var d=e;if(d.defaults.cache)throw new Error("setupCache() should be called only once");if(d.storage=t.storage||D(),!C(d.storage))throw new Error("Use buildStorage() function");return d.waiting=t.waiting||new Map,d.generateKey=t.generateKey||k,d.headerInterpreter=t.headerInterpreter||o,d.requestInterceptor=t.requestInterceptor||l(d),d.responseInterceptor=t.responseInterceptor||I(d),d.debug=t.debug||function(){},d.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==(u=t.cacheTakeover)||u,staleIfError:null==(c=t.staleIfError)||c,override:null!=(s=t.override)&&s,hydrate:null!=(f=t.hydrate)?f:void 0},d.requestInterceptor.apply(),d.responseInterceptor.apply(),d},e.testCachePredicate=y,e.updateCache=x,e.updateStaleRequest=d}); | ||
!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){if(!e)return"not enough headers";var r=e[a.CacheControl];if(r){var n=t.parse(String(r)),o=n.maxAge,i=n.maxStale,u=n.staleWhileRevalidate;if(n.noCache||n.noStore)return"dont cache";if(n.immutable)return{cache:31536e6};if(void 0!==o){var c=e[a.Age];return{cache:c?1e3*(o-Number(c)):1e3*o,stale:void 0!==i?1e3*i:void 0!==u?1e3*u:void 0}}}var s=e[a.Expires];if(s){var f=Date.parse(String(s))-Date.now();return f>=0?{cache:f}:"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 u(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 c(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 u(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)?u(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 s(e){return e?function(t){return e(t)||304===t}:function(e){return e>=200&&e<300||304===e}}function f(e,t){return void 0===e&&(e="get"),void 0===t&&(t=[]),e=e.toLowerCase(),t.some(function(t){return t===e})}function d(e,t){t.headers||(t.headers={});var r=t.cache,n=r.etag,o=r.modifiedSince;if(n){var i,u=!0===n?null==(i=e.data)?void 0:i.headers[a.ETag]:n;u&&(t.headers[a.IfNoneMatch]=u)}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){var t=function t(n){try{if(n.id=e.generateKey(n),!1===n.cache)return 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,u=c(n.cache.cachePredicate.ignoreUrls);!(o=u()).done;){var h=o.value;if(h instanceof RegExp?(h.lastIndex=0,h.test(n.url)):n.url.includes(h))return Promise.resolve(n)}var l,v,m,g,p,y;return n.cache.cacheTakeover&&(null!=(l=n.headers)[v=a.CacheControl]||(l[v]="no-cache"),null!=(m=n.headers)[g=a.Pragma]||(m[g]="no-cache"),null!=(p=n.headers)[y=a.Expires]||(p[y]="0")),f(n.method,n.cache.methods)?Promise.resolve(e.storage.get(n.id,n)).then(function(a){var o;function i(r){var i,u;if(o)return r;function c(e){return i?e:(n.transformResponse=void 0,n.adapter=function(){return Promise.resolve({config:n,data:u.data,headers:u.headers,status:u.status,statusText:u.statusText,cached:!0,stale:"stale"===a.previous,id:n.id})},n)}var s=function(){if("loading"===a.state){var r=function(r){return i?r:function(r,a){try{var c=Promise.resolve(o).then(function(){return Promise.resolve(e.storage.get(n.id,n)).then(function(e){if(!e.data){var r=t(n);return i=1,r}u=e.data})})}catch(e){return a()}return c&&c.then?c.then(void 0,a):c}(0,function(e){function r(){var e=t(n);return i=1,e}var o=function(){if(a.data)return Promise.resolve(null==n.cache.hydrate?void 0:n.cache.hydrate(a)).then(function(){})}();return o&&o.then?o.then(r):r()})},o=e.waiting.get(n.id),c=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 c&&c.then?c.then(r):r(c)}u=a.data}();return s&&s.then?s.then(c):c(s)}var u=n.cache.override,c=function(){if("empty"===a.state||"stale"===a.state||"must-revalidate"===a.state||u){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:u?a.data?"stale":"empty":a.state,data:a.data,createdAt:u&&!a.createdAt?Date.now():a.createdAt},n)).then(function(){function e(){return o=1,n}"stale"!==a.state&&"must-revalidate"!==a.state||d(a,n),n.validateStatus=s(n.validateStatus);var t=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 t&&t.then?t.then(e):e()})},i=function(){if(e.waiting.has(n.id)&&!u)return Promise.resolve(e.storage.get(n.id,n)).then(function(e){a=e})}();return i&&i.then?i.then(t):t()}}();return c&&c.then?c.then(i):i(c)}):Promise.resolve(n)}catch(e){return Promise.reject(e)}};return{onFulfilled:t,apply:function(){return e.interceptors.request.use(t)}}}const v="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function m(e,t,r){if(!e.s){if(r instanceof g){if(!r.s)return void(r.o=m.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(m.bind(null,e,t),m.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var g=/*#__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{m(n,1,o(this.v))}catch(e){m(n,2,e)}return n}return this}return this.o=function(e){try{var a=e.v;1&e.s?m(n,1,t?t(a):a):r?m(n,1,r(a)):m(n,2,a)}catch(e){m(n,2,e)}},n},e}();function p(e){return e instanceof g&&1&e.s}var y=function(e,t){try{var r=function(t){function r(r){var i;if(n&&!t||a&&!r)return!1;var u=function(){if(o)return function(e,t,r){if("function"==typeof e[v]){var n,a,o,i=e[v]();if(function e(u){try{for(;!((n=i.next()).done||r&&r());)if((u=t(n.value))&&u.then){if(!p(u))return void u.then(e,o||(o=m.bind(null,a=new g,2)));u=u.v}a?m(a,1,u):a=u}catch(e){m(a||(a=new g),2,e)}}(),i.return){var u=function(e){try{n.done||i.return()}catch(e){}return e};if(a&&a.then)return a.then(u,function(e){throw u(e)});u()}return a}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);return function(e,t,r){var n,a,o=-1;return function i(u){try{for(;++o<e.length&&(!r||!r());)if((u=t(o))&&u.then){if(!p(u))return void u.then(i,a||(a=m.bind(null,n=new g,2)));u=u.v}n?m(n,1,u):n=u}catch(e){m(n||(n=new g),2,e)}}(),n}(c,function(e){return t(c[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 u&&u.then?u.then(function(e){return!i||e}):!i||u}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 b="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 x=function(e,t,r){try{if("function"==typeof r)return Promise.resolve(r(t));var n=function(e,t,r){if("function"==typeof e[b]){var n,a,o,i=e[b]();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 u=function(e){try{n.done||i.return()}catch(e){}return e};if(a&&a.then)return a.then(u,function(e){throw u(e)});u()}return a}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);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}(c,function(e){return t(c[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 C(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)}},n=function(t){try{var n=function(){return f(o.method,i.methods)?Promise.resolve(e.storage.get(t.id,o)).then(function(n){function u(u){function s(u){var c;function s(r){if(c)return r;function u(){i.staleIfError&&(t.headers[a.XAxiosCacheStaleIfError]=String(m));var r={state:"cached",ttl:m,staleTtl:v,createdAt:Date.now(),data:s};return Promise.resolve(e.storage.set(t.id,r,o)).then(function(){var r=e.waiting.get(t.id);return r&&(r.resolve(),e.waiting.delete(t.id)),t})}var s=h(t,n.data),f=function(){if("function"==typeof m)return Promise.resolve(m(t)).then(function(e){m=e})}();return f&&f.then?f.then(u):u()}for(var f=0,d=Object.keys(t.headers);f<d.length;f++){var l=d[f];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,m=i.ttl||-1,g=function(){if(i.interpretHeader){var n=function(e){if(c)return e;"not enough headers"!==a&&("number"==typeof a?m=a:(m=a.cache,v=a.stale))},a=e.headerInterpreter(t.headers),u=function(){if("dont cache"===a)return Promise.resolve(r(t.id,o,!0)).then(function(){return c=1,t})}();return u&&u.then?u.then(n):n(u)}}();return g&&g.then?g.then(s):s(g)}var f=function(){if(c&&!u)return Promise.resolve(r(t.id,o,!0)).then(function(){return t})}();return f&&f.then?f.then(s):s()}if("loading"!==n.state)return t;var c=!n.data;return c?Promise.resolve(y(t,i.cachePredicate)).then(u):u(c)}):t};if(null==t||!t.config)throw t;t.id=t.config.id,null!=t.cached||(t.cached=!1);var o=t.config,i=o.cache;if(t.cached)return Promise.resolve(t);if(!i)return t.cached=!1,Promise.resolve(t);var u=function(){if(i.update)return Promise.resolve(x(e.storage,t,i.update)).then(function(){})}();return Promise.resolve(u&&u.then?u.then(n):n())}catch(e){return Promise.reject(e)}},o=function(n){try{var o=function(o){return Promise.resolve(e.storage.get(u,i)).then(function(o){function f(f){var d;function h(e){return d?e:Promise.resolve(r(u,i,!0)).then(function(){throw n})}var l=function(){if(c.staleIfError){var r=function(t){return function(){if(!0===t||"number"==typeof t&&o.createdAt+t>Date.now())return Promise.resolve(e.storage.set(u,{state:"stale",createdAt:Date.now(),data:o.data},i)).then(function(){var t=e.waiting.get(u);return t&&(t.resolve(),e.waiting.delete(u)),d=1,{cached:!0,stale:!0,config:i,id:u,data:o.data.data,headers:o.data.headers,status:o.data.status,statusText:o.data.statusText}})}()},f=String(null==s?void 0:s.headers[a.CacheControl]),h=f&&t.parse(f).staleIfError;return"function"==typeof c.staleIfError?Promise.resolve(c.staleIfError(s,o,n)).then(r):r(!0===c.staleIfError&&h?1e3*h:c.staleIfError)}}();return l&&l.then?l.then(h):h(l)}var d=function(){if("loading"!==o.state||"stale"!==o.previous)return Promise.resolve(r(u,i,"ERR_CANCELED"!==n.code||"ERR_CANCELED"===n.code&&"cached"!==o.state)).then(function(){throw n})}();return d&&d.then?d.then(f):f()})};if(!n.isAxiosError||!n.config)throw n;var i=n.config,u=i.id,c=i.cache,s=n.response;if(!c||!u)throw n;var d=function(){if(!f(i.method,c.methods))return Promise.resolve(r(u,i,!0)).then(function(){throw n})}();return Promise.resolve(d&&d.then?d.then(o):o())}catch(e){return Promise.reject(e)}};return{onFulfilled:n,onRejected:o,apply:function(){return e.interceptors.response.use(n,o)}}}var I=function(e){return!!e&&!!e["is-storage"]};function E(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 j(e){return!!E(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 O(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 u(t){return o?t:T(r)?E(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 c=function(){if("cached"===r.state){var u=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 c=function(){if(!j(r))return Promise.resolve(n(e,a)).then(function(){return o=1,{state:"empty"}})}();return c&&c.then?c.then(u):u(c)}}();return c&&c.then?c.then(u):u(c)})}catch(e){return Promise.reject(e)}}}}var M="function"==typeof structuredClone?structuredClone:function(e){return JSON.parse(JSON.stringify(e))};function R(e,t,r){void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===r&&(r=!1);var n=O({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?M(a):a},remove:function(e){delete n.data[e]},find:function(t){var r=n.data[t];return e&&void 0!==r?M(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)&&!j(e)&&n.remove(t):n.remove(t)},t&&(n.cleaner=setInterval(n.cleanup,t)),n}var D=/^\/|\/$/g;function L(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 N=L(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(D,""):"",r=void 0!==r?r.replace(D,""):"",{url:t+(t&&r?"/":"")+r,params:a,method:n=void 0!==n?n.toLowerCase():"get",data:o}});e.Header=a,e.buildKeyGenerator=L,e.buildMemoryStorage=R,e.buildStorage=O,e.buildWebStorage=function(e,t){return void 0===t&&(t="axios-cache-"),O({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])]}),u=c(i);!(o=u()).done;){var s=o.value;"cached"===s[1].state&&T(s[1])&&!j(s[1])&&e.removeItem(s[0])}try{return a()}catch(t){for(var f,d=c(i.sort(function(e,t){return(e[1].createdAt||0)-(t[1].createdAt||0)}));!(f=d()).done;){e.removeItem(f.value[0]);try{return a()}catch(e){}}}e.removeItem(t+r)}}})},e.canStale=j,e.createCacheResponse=h,e.createValidateStatus=s,e.defaultHeaderInterpreter=o,e.defaultKeyGenerator=N,e.defaultRequestInterceptor=l,e.defaultResponseInterceptor=C,e.isExpired=T,e.isMethodIn=f,e.isStorage=I,e.mustRevalidate=A,e.setupCache=function(e,t){var r,n,a,i,u,c,s,f;void 0===t&&(t={});var d=e;if(d.defaults.cache)throw new Error("setupCache() should be called only once");if(d.storage=t.storage||R(),!I(d.storage))throw new Error("Use buildStorage() function");return d.waiting=t.waiting||new Map,d.generateKey=t.generateKey||N,d.headerInterpreter=t.headerInterpreter||o,d.requestInterceptor=t.requestInterceptor||l(d),d.responseInterceptor=t.responseInterceptor||C(d),d.debug=t.debug||function(){},d.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==(u=t.cacheTakeover)||u,staleIfError:null==(c=t.staleIfError)||c,override:null!=(s=t.override)&&s,hydrate:null!=(f=t.hydrate)?f:void 0},d.requestInterceptor.apply(),d.responseInterceptor.apply(),d},e.testCachePredicate=y,e.updateCache=x,e.updateStaleRequest=d}); | ||
//# sourceMappingURL=index.bundle.js.map |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -442,5 +442,7 @@ * Released under the MIT License. | ||
*/ | ||
const rejectResponse = async (responseId, config) => { | ||
const rejectResponse = async (responseId, config, clearCache) => { | ||
// Updates the cache to empty to prevent infinite loading state | ||
await axios.storage.remove(responseId, config); | ||
if (clearCache) { | ||
await axios.storage.remove(responseId, config); | ||
} | ||
// Rejects the deferred, if present | ||
@@ -492,3 +494,3 @@ const deferred = axios.waiting.get(responseId); | ||
!cache.data && !(await testCachePredicate(response, cacheConfig.cachePredicate))) { | ||
await rejectResponse(response.id, config); | ||
await rejectResponse(response.id, config, true); | ||
return response; | ||
@@ -514,3 +516,3 @@ } | ||
if (expirationTime === 'dont cache') { | ||
await rejectResponse(response.id, config); | ||
await rejectResponse(response.id, config, true); | ||
return response; | ||
@@ -570,3 +572,3 @@ } | ||
// Rejects all other requests waiting for this response | ||
await rejectResponse(id, config); | ||
await rejectResponse(id, config, true); | ||
throw error; | ||
@@ -579,3 +581,5 @@ } | ||
// Rejects all other requests waiting for this response | ||
await rejectResponse(id, config); | ||
await rejectResponse(id, config, | ||
// Do not clear cache if this request is cached, but the request was cancelled before returning the cached response | ||
error.code !== 'ERR_CANCELED' || error.code === 'ERR_CANCELED' && cache.state !== 'cached'); | ||
throw error; | ||
@@ -616,3 +620,3 @@ } | ||
// Rejects all other requests waiting for this response | ||
await rejectResponse(id, config); | ||
await rejectResponse(id, config, true); | ||
throw error; | ||
@@ -619,0 +623,0 @@ }; |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* Axios Cache Interceptor 1.6.1 | ||
* Axios Cache Interceptor 1.6.2 | ||
* (c) 2021-present Arthur Fiorette & Contributors | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
{ | ||
"name": "axios-cache-interceptor", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "Cache interceptor for axios", | ||
@@ -54,3 +54,3 @@ "keywords": [ | ||
"@types/jsdom": "21.1.7", | ||
"@types/node": "22.7.6", | ||
"@types/node": "22.7.8", | ||
"auto-changelog": "2.5.0", | ||
@@ -57,0 +57,0 @@ "axios": "1.7.7", |
@@ -18,5 +18,11 @@ import type { AxiosResponseHeaders } from 'axios'; | ||
*/ | ||
const rejectResponse = async (responseId: string, config: CacheRequestConfig) => { | ||
const rejectResponse = async ( | ||
responseId: string, | ||
config: CacheRequestConfig, | ||
clearCache: boolean | ||
) => { | ||
// Updates the cache to empty to prevent infinite loading state | ||
await axios.storage.remove(responseId, config); | ||
if (clearCache) { | ||
await axios.storage.remove(responseId, config); | ||
} | ||
@@ -120,3 +126,3 @@ // Rejects the deferred, if present | ||
) { | ||
await rejectResponse(response.id, config); | ||
await rejectResponse(response.id, config, true); | ||
@@ -159,3 +165,3 @@ if (__ACI_DEV__) { | ||
if (expirationTime === 'dont cache') { | ||
await rejectResponse(response.id, config); | ||
await rejectResponse(response.id, config, true); | ||
@@ -282,3 +288,3 @@ if (__ACI_DEV__) { | ||
// Rejects all other requests waiting for this response | ||
await rejectResponse(id, config); | ||
await rejectResponse(id, config, true); | ||
@@ -304,3 +310,8 @@ throw error; | ||
// Rejects all other requests waiting for this response | ||
await rejectResponse(id, config); | ||
await rejectResponse( | ||
id, | ||
config, | ||
// Do not clear cache if this request is cached, but the request was cancelled before returning the cached response | ||
error.code !== 'ERR_CANCELED' || (error.code === 'ERR_CANCELED' && cache.state !== 'cached') | ||
); | ||
@@ -389,3 +400,3 @@ throw error; | ||
// Rejects all other requests waiting for this response | ||
await rejectResponse(id, config); | ||
await rejectResponse(id, config, true); | ||
@@ -392,0 +403,0 @@ throw error; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
1147510
10485