axios-cache-interceptor
Advanced tools
Comparing version 0.9.1 to 0.9.2
@@ -1,2 +0,2 @@ | ||
(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Header:()=>r,buildKeyGenerator:()=>C,buildMemoryStorage:()=>y,buildStorage:()=>b,buildWebStorage:()=>A,canStale:()=>m,createCacheResponse:()=>c,createValidateStatus:()=>o,defaultHeaderInterpreter:()=>s,defaultKeyGenerator:()=>x,defaultRequestInterceptor:()=>u,defaultResponseInterceptor:()=>h,isExpired:()=>w,isMethodIn:()=>n,isStorage:()=>p,setupCache:()=>v,testCachePredicate:()=>g,updateCache:()=>f,updateStaleRequest:()=>d});const a=require("cache-parser"),r=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),s=e=>{if(!e)return"not enough headers";const t=e[r.CacheControl];if(t){const{noCache:s,noStore:i,mustRevalidate:o,maxAge:n,immutable:d}=(0,a.parse)(String(t));if(s||i)return"dont cache";if(d)return 31536e6;if(o)return 0;if(n){const t=e[r.Age];return t?1e3*(n-Number(t)):1e3*n}}const s=e[r.Expires];if(s){const e=Date.parse(String(s))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"},i=require("fast-defer");function o(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function n(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function d(e,t){t.headers||(t.headers={});const{etag:a,modifiedSince:s}=t.cache;if(a){const s=!0===a?e.data?.headers[r.ETag]:a;s&&(t.headers[r.IfNoneMatch]=s)}s&&(t.headers[r.IfModifiedSince]=!0===s?e.data.headers[r.LastModified]||new Date(e.createdAt).toUTCString():s.toUTCString())}function c(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers={...t.headers,...e.headers},t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function u(e){const t=async t=>{if(!1===t.cache)return e.debug?.({msg:"Ignoring cache because config.cache is false",data:t}),t;if(t.cache={...e.defaults.cache,...t.cache},!n(t.method,t.cache.methods))return e.debug?.({msg:`Ignored because method (${t.method}) is not in cache.methods (${t.cache.methods})`}),t;const a=t.id=e.generateKey(t);let r,s=await e.storage.get(a);e:if("empty"===s.state||"stale"===s.state){if(e.waiting[a]){s=await e.storage.get(a),e.debug?.({id:a,msg:"Waiting list had an deferred for this key, waiting for it to finish"});break e}return e.waiting[a]=(0,i.deferred)(),e.waiting[a]?.catch((()=>{})),await e.storage.set(a,{state:"loading",previous:s.state,data:s.data,createdAt:s.createdAt}),"stale"===s.state&&(d(s,t),e.debug?.({id:a,msg:"Updated stale request"})),t.validateStatus=o(t.validateStatus),e.debug?.({id:a,msg:"Sending request, waiting for response"}),t}if("loading"===s.state){const s=e.waiting[a];if(!s)return await e.storage.remove(a),t;e.debug?.({id:a,msg:"Detected concurrent request, waiting for it to finish"});try{r=await s}catch(r){return e.debug?.({id:a,msg:"Deferred rejected, requesting again",data:r}),t}}else r=s.data;return t.adapter=()=>Promise.resolve({config:t,data:r.data,headers:r.headers,status:r.status,statusText:r.statusText,cached:!0,id:a}),e.debug?.({id:a,msg:"Returning cached response"}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function g(e,t){if("function"==typeof t)return t(e);const{statusCheck:a,responseMatch:r,containsHeaders:s}=t;if(a&&!await a(e.status)||r&&!await r(e))return!1;if(s)for(const t in s){const a=s[t];if(a&&!await a(e.headers[t.toLowerCase()]??e.headers[t]))return!1}return!0}async function f(e,t,a){for(const r in a){const s=a[r];if("delete"===s){await e.remove(r);continue}const i=await e.get(r);if("loading"===i.state)continue;const o=await s(i,t);"delete"!==o?"ignore"!==o&&await e.set(r,o):await e.remove(r)}}function h(e){const t=async t=>{await e.storage.remove(t),e.waiting[t]?.reject(null),delete e.waiting[t]},a=async a=>{var s;if(a.id=(s=a.config).id??(s.id=e.generateKey(a.config)),a.cached??(a.cached=!1),a.cached)return e.debug?.({id:a.id,msg:"Returned cached response"}),a;if(!a.config.cache)return e.debug?.({id:a.id,msg:"Response with config.cache === false",data:a}),{...a,cached:!1};const i=a.config.cache,o=await e.storage.get(a.id);if("stale"===o.state||"empty"===o.state||"cached"===o.state)return e.debug?.({id:a.id,msg:"Response not cached but storage is not loading",data:{cache:o,response:a}}),a;if(!o.data&&!await g(a,i.cachePredicate))return await t(a.id),e.debug?.({id:a.id,msg:"Cache predicate rejected this response"}),a;for(const e in r)e.startsWith("XAxiosCache")&&delete a.headers[e];i.etag&&!0!==i.etag&&(a.headers[r.XAxiosCacheEtag]=i.etag),i.modifiedSince&&(a.headers[r.XAxiosCacheLastModified]=!0===i.modifiedSince?"use-cache-timestamp":i.modifiedSince.toUTCString());let n=i.ttl||-1;if(i?.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),e.debug?.({id:a.id,msg:"Cache header interpreted as 'dont cache'",data:{cache:o,response:a,expirationTime:r}}),a;n="not enough headers"===r?n:r}const d=c(a,o.data);"function"==typeof n&&(n=await n(a)),i.staleIfError&&(a.headers[r.XAxiosCacheStaleIfError]=String(n)),e.debug?.({id:a.id,msg:"Useful response configuration found",data:{cacheConfig:i,ttl:n,cacheResponse:d}}),i?.update&&await f(e.storage,a,i.update);const u={state:"cached",ttl:n,createdAt:Date.now(),data:d},h=e.waiting[a.id];return h&&(h.resolve(u.data),delete e.waiting[a.id],e.debug?.({id:a.id,msg:"Found waiting deferred(s) and resolved them"})),await e.storage.set(a.id,u),e.debug?.({id:a.id,msg:"Response cached",data:{cache:u,response:a}}),a},s=async a=>{const r=a.config;if(!r||!1===r.cache||!r.id)throw e.debug?.({msg:"Web request returned an error but cache handling is not enabled",data:{error:a,config:r}}),a;const s=await e.storage.get(r.id),i=r.cache;if("loading"!==s.state||"stale"!==s.previous)throw await t(r.id),e.debug?.({msg:"Caught an error in the request interceptor",data:{error:a,config:r}}),a;if(i?.staleIfError){const t="function"==typeof i.staleIfError?await i.staleIfError(a.response,s,a):i.staleIfError;if(e.debug?.({msg:"Found cache if stale config for rejected response",data:{error:a,config:r,staleIfError:t}}),!0===t||"number"==typeof t&&s.createdAt+t>Date.now())return e.waiting[r.id]?.resolve(s.data),delete e.waiting[r.id],await e.storage.set(r.id,{state:"stale",createdAt:Date.now(),data:s.data}),e.debug?.({msg:"staleIfError resolved this response with cached data",data:{error:a,config:r,cache:s}}),{cached:!0,config:r,id:r.id,data:s.data.data,headers:s.data.headers,status:s.data.status,statusText:s.data.statusText}}throw e.debug?.({msg:"Received an unknown error that could not be handled",data:{error:a,config:r}}),a};return{onFulfilled:a,onRejected:s,apply:()=>e.interceptors.response.use(a,s)}}const l=Symbol(),p=e=>!!e&&!!e[l];function m(e){const t=e.data.headers;return r.ETag in t||r.LastModified in t||r.XAxiosCacheEtag in t||r.XAxiosCacheStaleIfError in t||r.XAxiosCacheLastModified in t}function w(e){return e.createdAt+e.ttl<=Date.now()}function b({set:e,find:t,remove:a}){return{[l]:1,set:e,remove:a,get:async r=>{const s=await t(r);if(!s)return{state:"empty"};if("cached"!==s.state||!w(s))return s;if(m(s)){const t={state:"stale",createdAt:s.createdAt,data:s.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function y(){const e=b({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const S=require("object-code"),I=/^\/|\/$/g;function C(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(I,"")),a.url&&(a.url=a.url.replace(I,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?(0,S.hashCode)(r).toString():r}}const x=C(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:s})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:s})));function v(e,t={}){const a=e;if(a.storage=t.storage||y(),!p(a.storage))throw new Error("Use buildStorage() function");return a.generateKey=t.generateKey||x,a.waiting=t.waiting||{},a.headerInterpreter=t.headerInterpreter||s,a.requestInterceptor=t.requestInterceptor||u(a),a.responseInterceptor=t.responseInterceptor||h(a),a.debug=t.debug,a.defaults.cache={ttl:t.ttl??3e5,interpretHeader:t.interpretHeader??!1,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:t.etag??!1,modifiedSince:t.modifiedSince??!1,staleIfError:t.staleIfError??!1,update:t.update||{}},a.requestInterceptor.apply(),a.responseInterceptor.apply(),a}function A(e,t=""){return b({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const s=()=>e.setItem(t+a,JSON.stringify(r));try{return s()}catch(r){const i=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of i)"cached"===a.state&&w(a)&&!m(a)&&e.removeItem(t);try{return s()}catch(t){const a=i.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return s()}catch(e){}}}e.removeItem(t+a)}}})}console.error("You are using a development build. Make sure to use the correct build in production"),console.error("https://axios-cache-interceptor.js.org/#/pages/installing"),module.exports=t})(); | ||
(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Header:()=>r,buildKeyGenerator:()=>x,buildMemoryStorage:()=>y,buildStorage:()=>b,buildWebStorage:()=>A,canStale:()=>m,createCacheResponse:()=>c,createValidateStatus:()=>o,defaultHeaderInterpreter:()=>s,defaultKeyGenerator:()=>C,defaultRequestInterceptor:()=>u,defaultResponseInterceptor:()=>h,isExpired:()=>w,isMethodIn:()=>n,isStorage:()=>p,setupCache:()=>v,testCachePredicate:()=>g,updateCache:()=>f,updateStaleRequest:()=>d});const a=require("cache-parser"),r=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),s=e=>{if(!e)return"not enough headers";const t=e[r.CacheControl];if(t){const{noCache:s,noStore:i,mustRevalidate:o,maxAge:n,immutable:d}=(0,a.parse)(String(t));if(s||i)return"dont cache";if(d)return 31536e6;if(o)return 0;if(n){const t=e[r.Age];return t?1e3*(n-Number(t)):1e3*n}}const s=e[r.Expires];if(s){const e=Date.parse(String(s))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"},i=require("fast-defer");function o(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function n(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function d(e,t){t.headers||(t.headers={});const{etag:a,modifiedSince:s}=t.cache;if(a){const s=!0===a?e.data?.headers[r.ETag]:a;s&&(t.headers[r.IfNoneMatch]=s)}s&&(t.headers[r.IfModifiedSince]=!0===s?e.data.headers[r.LastModified]||new Date(e.createdAt).toUTCString():s.toUTCString())}function c(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers={...t.headers,...e.headers},t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function u(e){const t=async t=>{if(!1===t.cache)return e.debug?.({msg:"Ignoring cache because config.cache is false",data:t}),t;if(t.cache={...e.defaults.cache,...t.cache},!n(t.method,t.cache.methods))return e.debug?.({msg:`Ignored because method (${t.method}) is not in cache.methods (${t.cache.methods})`}),t;const a=t.id=e.generateKey(t);let r,s=await e.storage.get(a);e:if("empty"===s.state||"stale"===s.state){if(e.waiting[a]){s=await e.storage.get(a),e.debug?.({id:a,msg:"Waiting list had an deferred for this key, waiting for it to finish"});break e}return e.waiting[a]=(0,i.deferred)(),e.waiting[a]?.catch((()=>{})),await e.storage.set(a,{state:"loading",previous:s.state,data:s.data,createdAt:s.createdAt}),"stale"===s.state&&(d(s,t),e.debug?.({id:a,msg:"Updated stale request"})),t.validateStatus=o(t.validateStatus),e.debug?.({id:a,msg:"Sending request, waiting for response"}),t}if("loading"===s.state){const s=e.waiting[a];if(!s)return await e.storage.remove(a),t;e.debug?.({id:a,msg:"Detected concurrent request, waiting for it to finish"});try{r=await s}catch(r){return e.debug?.({id:a,msg:"Deferred rejected, requesting again",data:r}),t}}else r=s.data;return t.adapter=()=>Promise.resolve({config:t,data:r.data,headers:r.headers,status:r.status,statusText:r.statusText,cached:!0,id:a}),e.debug?.({id:a,msg:"Returning cached response"}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function g(e,t){if("function"==typeof t)return t(e);const{statusCheck:a,responseMatch:r,containsHeaders:s}=t;if(a&&!await a(e.status)||r&&!await r(e))return!1;if(s)for(const t in s){const a=s[t];if(a&&!await a(e.headers[t.toLowerCase()]??e.headers[t]))return!1}return!0}async function f(e,t,a){for(const r in a){const s=a[r];if("delete"===s){await e.remove(r);continue}const i=await e.get(r);if("loading"===i.state)continue;const o=await s(i,t);"delete"!==o?"ignore"!==o&&await e.set(r,o):await e.remove(r)}}function h(e){const t=async t=>{await e.storage.remove(t),e.waiting[t]?.reject(null),delete e.waiting[t]},a=async a=>{var s;if(a.id=(s=a.config).id??(s.id=e.generateKey(a.config)),a.cached??(a.cached=!1),a.cached)return e.debug?.({id:a.id,msg:"Returned cached response"}),a;if(!a.config.cache)return e.debug?.({id:a.id,msg:"Response with config.cache === false",data:a}),{...a,cached:!1};const i=a.config.cache,o=await e.storage.get(a.id);if("stale"===o.state||"empty"===o.state||"cached"===o.state)return e.debug?.({id:a.id,msg:"Response not cached but storage is not loading",data:{cache:o,response:a}}),a;if(!o.data&&!await g(a,i.cachePredicate))return await t(a.id),e.debug?.({id:a.id,msg:"Cache predicate rejected this response"}),a;for(const e in r)e.startsWith("XAxiosCache")&&delete a.headers[e];i.etag&&!0!==i.etag&&(a.headers[r.XAxiosCacheEtag]=i.etag),i.modifiedSince&&(a.headers[r.XAxiosCacheLastModified]=!0===i.modifiedSince?"use-cache-timestamp":i.modifiedSince.toUTCString());let n=i.ttl||-1;if(i?.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),e.debug?.({id:a.id,msg:"Cache header interpreted as 'dont cache'",data:{cache:o,response:a,expirationTime:r}}),a;n="not enough headers"===r?n:r}const d=c(a,o.data);"function"==typeof n&&(n=await n(a)),i.staleIfError&&(a.headers[r.XAxiosCacheStaleIfError]=String(n)),e.debug?.({id:a.id,msg:"Useful response configuration found",data:{cacheConfig:i,ttl:n,cacheResponse:d}}),i?.update&&await f(e.storage,a,i.update);const u={state:"cached",ttl:n,createdAt:Date.now(),data:d},h=e.waiting[a.id];return h&&(h.resolve(u.data),delete e.waiting[a.id],e.debug?.({id:a.id,msg:"Found waiting deferred(s) and resolved them"})),await e.storage.set(a.id,u),e.debug?.({id:a.id,msg:"Response cached",data:{cache:u,response:a}}),a},s=async a=>{const r=a.config;if(!r||!1===r.cache||!r.id)throw e.debug?.({msg:"Web request returned an error but cache handling is not enabled",data:{error:a,config:r}}),a;const s=await e.storage.get(r.id),i=r.cache;if("loading"!==s.state||"stale"!==s.previous)throw await t(r.id),e.debug?.({msg:"Caught an error in the request interceptor",data:{error:a,config:r}}),a;if(i?.staleIfError){const t="function"==typeof i.staleIfError?await i.staleIfError(a.response,s,a):i.staleIfError;if(e.debug?.({msg:"Found cache if stale config for rejected response",data:{error:a,config:r,staleIfError:t}}),!0===t||"number"==typeof t&&s.createdAt+t>Date.now())return e.waiting[r.id]?.resolve(s.data),delete e.waiting[r.id],await e.storage.set(r.id,{state:"stale",createdAt:Date.now(),data:s.data}),e.debug?.({msg:"staleIfError resolved this response with cached data",data:{error:a,config:r,cache:s}}),{cached:!0,config:r,id:r.id,data:s.data.data,headers:s.data.headers,status:s.data.status,statusText:s.data.statusText}}throw e.debug?.({msg:"Received an unknown error that could not be handled",data:{error:a,config:r}}),a};return{onFulfilled:a,onRejected:s,apply:()=>e.interceptors.response.use(a,s)}}const l=Symbol(),p=e=>!!e&&!!e[l];function m(e){const t=e.data.headers;return r.ETag in t||r.LastModified in t||r.XAxiosCacheEtag in t||r.XAxiosCacheStaleIfError in t||r.XAxiosCacheLastModified in t}function w(e){return e.createdAt+e.ttl<=Date.now()}function b({set:e,find:t,remove:a}){return{[l]:1,set:e,remove:a,get:async r=>{const s=await t(r);if(!s)return{state:"empty"};if("cached"!==s.state||!w(s))return s;if(m(s)){const t={state:"stale",createdAt:s.createdAt,data:s.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function y(){const e=b({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const I=require("object-code"),S=/^\/|\/$/g;function x(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(S,"")),a.url&&(a.url=a.url.replace(S,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?`${(0,I.hash)(r)}`:r}}const C=x(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:s})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:s})));function v(e,t={}){const a=e;if(a.storage=t.storage||y(),!p(a.storage))throw new Error("Use buildStorage() function");return a.generateKey=t.generateKey||C,a.waiting=t.waiting||{},a.headerInterpreter=t.headerInterpreter||s,a.requestInterceptor=t.requestInterceptor||u(a),a.responseInterceptor=t.responseInterceptor||h(a),a.debug=t.debug,a.defaults.cache={ttl:t.ttl??3e5,interpretHeader:t.interpretHeader??!1,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:t.etag??!1,modifiedSince:t.modifiedSince??!1,staleIfError:t.staleIfError??!1,update:t.update||{}},a.requestInterceptor.apply(),a.responseInterceptor.apply(),a}function A(e,t=""){return b({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const s=()=>e.setItem(t+a,JSON.stringify(r));try{return s()}catch(r){const i=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of i)"cached"===a.state&&w(a)&&!m(a)&&e.removeItem(t);try{return s()}catch(t){const a=i.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return s()}catch(e){}}}e.removeItem(t+a)}}})}console.error("You are using a development build. Make sure to use the correct build in production"),console.error("https://axios-cache-interceptor.js.org/#/pages/installing"),module.exports=t})(); | ||
//# sourceMappingURL=dev.map |
@@ -1,1 +0,1 @@ | ||
(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Header:()=>r,buildKeyGenerator:()=>I,buildMemoryStorage:()=>y,buildStorage:()=>v,buildWebStorage:()=>A,canStale:()=>m,createCacheResponse:()=>d,createValidateStatus:()=>s,defaultHeaderInterpreter:()=>i,defaultKeyGenerator:()=>x,defaultRequestInterceptor:()=>u,defaultResponseInterceptor:()=>h,isExpired:()=>w,isMethodIn:()=>o,isStorage:()=>p,setupCache:()=>C,testCachePredicate:()=>f,updateCache:()=>l,updateStaleRequest:()=>c});const a=require("cache-parser"),r=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",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=e=>{if(!e)return"not enough headers";const t=e[r.CacheControl];if(t){const{noCache:i,noStore:n,mustRevalidate:s,maxAge:o,immutable:c}=(0,a.parse)(String(t));if(i||n)return"dont cache";if(c)return 31536e6;if(s)return 0;if(o){const t=e[r.Age];return t?1e3*(o-Number(t)):1e3*o}}const i=e[r.Expires];if(i){const e=Date.parse(String(i))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"},n=require("fast-defer");function s(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function o(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function c(e,t){var a;t.headers||(t.headers={});const{etag:i,modifiedSince:n}=t.cache;if(i){const n=!0===i?null===(a=e.data)||void 0===a?void 0:a.headers[r.ETag]:i;n&&(t.headers[r.IfNoneMatch]=n)}n&&(t.headers[r.IfModifiedSince]=!0===n?e.data.headers[r.LastModified]||new Date(e.createdAt).toUTCString():n.toUTCString())}function d(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function u(e){const t=async t=>{var a;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!o(t.method,t.cache.methods))return t;const r=t.id=e.generateKey(t);let i,d=await e.storage.get(r);e:if("empty"===d.state||"stale"===d.state){if(e.waiting[r]){d=await e.storage.get(r);break e}return e.waiting[r]=(0,n.deferred)(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),await e.storage.set(r,{state:"loading",previous:d.state,data:d.data,createdAt:d.createdAt}),"stale"===d.state&&c(d,t),t.validateStatus=s(t.validateStatus),t}if("loading"===d.state){const a=e.waiting[r];if(!a)return await e.storage.remove(r),t;0;try{i=await a}catch(e){return t}}else i=d.data;return t.adapter=()=>Promise.resolve({config:t,data:i.data,headers:i.headers,status:i.status,statusText:i.statusText,cached:!0,id:r}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function f(e,t){var a;if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:i,containsHeaders:n}=t;if(r&&!await r(e.status)||i&&!await i(e))return!1;if(n)for(const t in n){const r=n[t];if(r&&!await r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t]))return!1}return!0}async function l(e,t,a){for(const r in a){const i=a[r];if("delete"===i){await e.remove(r);continue}const n=await e.get(r);if("loading"===n.state)continue;const s=await i(n,t);"delete"!==s?"ignore"!==s&&await e.set(r,s):await e.remove(r)}}function h(e){const t=async t=>{var a;await e.storage.remove(t),null===(a=e.waiting[t])||void 0===a||a.reject(null),delete e.waiting[t]},a=async a=>{var i,n,s;if(a.id=null!==(i=(s=a.config).id)&&void 0!==i?i:s.id=e.generateKey(a.config),null!==(n=a.cached)&&void 0!==n||(a.cached=!1),a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const o=a.config.cache,c=await e.storage.get(a.id);if("stale"===c.state||"empty"===c.state||"cached"===c.state)return a;if(!c.data&&!await f(a,o.cachePredicate))return await t(a.id),a;for(const e in r)e.startsWith("XAxiosCache")&&delete a.headers[e];o.etag&&!0!==o.etag&&(a.headers[r.XAxiosCacheEtag]=o.etag),o.modifiedSince&&(a.headers[r.XAxiosCacheLastModified]=!0===o.modifiedSince?"use-cache-timestamp":o.modifiedSince.toUTCString());let u=o.ttl||-1;if(null==o?void 0:o.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),a;u="not enough headers"===r?u:r}const h=d(a,c.data);"function"==typeof u&&(u=await u(a)),o.staleIfError&&(a.headers[r.XAxiosCacheStaleIfError]=String(u)),(null==o?void 0:o.update)&&await l(e.storage,a,o.update);const g={state:"cached",ttl:u,createdAt:Date.now(),data:h},p=e.waiting[a.id];return p&&(p.resolve(g.data),delete e.waiting[a.id]),await e.storage.set(a.id,g),a},i=async a=>{var r;const i=a.config;if(!i||!1===i.cache||!i.id)throw a;const n=await e.storage.get(i.id),s=i.cache;if("loading"!==n.state||"stale"!==n.previous)throw await t(i.id),a;if(null==s?void 0:s.staleIfError){const t="function"==typeof s.staleIfError?await s.staleIfError(a.response,n,a):s.staleIfError;if(!0===t||"number"==typeof t&&n.createdAt+t>Date.now())return null===(r=e.waiting[i.id])||void 0===r||r.resolve(n.data),delete e.waiting[i.id],await e.storage.set(i.id,{state:"stale",createdAt:Date.now(),data:n.data}),{cached:!0,config:i,id:i.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}}throw a};return{onFulfilled:a,onRejected:i,apply:()=>e.interceptors.response.use(a,i)}}const g=Symbol(),p=e=>!!e&&!!e[g];function m(e){const t=e.data.headers;return r.ETag in t||r.LastModified in t||r.XAxiosCacheEtag in t||r.XAxiosCacheStaleIfError in t||r.XAxiosCacheLastModified in t}function w(e){return e.createdAt+e.ttl<=Date.now()}function v({set:e,find:t,remove:a}){return{[g]:1,set:e,remove:a,get:async r=>{const i=await t(r);if(!i)return{state:"empty"};if("cached"!==i.state||!w(i))return i;if(m(i)){const t={state:"stale",createdAt:i.createdAt,data:i.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function y(){const e=v({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const S=require("object-code"),b=/^\/|\/$/g;function I(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(b,"")),a.url&&(a.url=a.url.replace(b,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?(0,S.hashCode)(r).toString():r}}const x=I(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:i})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:i})));function C(e,t={}){var a,r,n,s,o;const c=e;if(c.storage=t.storage||y(),!p(c.storage))throw new Error("Use buildStorage() function");return c.generateKey=t.generateKey||x,c.waiting=t.waiting||{},c.headerInterpreter=t.headerInterpreter||i,c.requestInterceptor=t.requestInterceptor||u(c),c.responseInterceptor=t.responseInterceptor||h(c),c.debug=t.debug,c.defaults.cache={ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,interpretHeader:null!==(r=t.interpretHeader)&&void 0!==r&&r,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(n=t.etag)&&void 0!==n&&n,modifiedSince:null!==(s=t.modifiedSince)&&void 0!==s&&s,staleIfError:null!==(o=t.staleIfError)&&void 0!==o&&o,update:t.update||{}},c.requestInterceptor.apply(),c.responseInterceptor.apply(),c}function A(e,t=""){return v({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const i=()=>e.setItem(t+a,JSON.stringify(r));try{return i()}catch(r){const n=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of n)"cached"===a.state&&w(a)&&!m(a)&&e.removeItem(t);try{return i()}catch(t){const a=n.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return i()}catch(e){}}}e.removeItem(t+a)}}})}module.exports=t})(); | ||
(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Header:()=>r,buildKeyGenerator:()=>I,buildMemoryStorage:()=>y,buildStorage:()=>v,buildWebStorage:()=>A,canStale:()=>m,createCacheResponse:()=>d,createValidateStatus:()=>s,defaultHeaderInterpreter:()=>i,defaultKeyGenerator:()=>x,defaultRequestInterceptor:()=>u,defaultResponseInterceptor:()=>h,isExpired:()=>w,isMethodIn:()=>o,isStorage:()=>p,setupCache:()=>C,testCachePredicate:()=>f,updateCache:()=>l,updateStaleRequest:()=>c});const a=require("cache-parser"),r=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",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=e=>{if(!e)return"not enough headers";const t=e[r.CacheControl];if(t){const{noCache:i,noStore:n,mustRevalidate:s,maxAge:o,immutable:c}=(0,a.parse)(String(t));if(i||n)return"dont cache";if(c)return 31536e6;if(s)return 0;if(o){const t=e[r.Age];return t?1e3*(o-Number(t)):1e3*o}}const i=e[r.Expires];if(i){const e=Date.parse(String(i))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"},n=require("fast-defer");function s(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function o(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function c(e,t){var a;t.headers||(t.headers={});const{etag:i,modifiedSince:n}=t.cache;if(i){const n=!0===i?null===(a=e.data)||void 0===a?void 0:a.headers[r.ETag]:i;n&&(t.headers[r.IfNoneMatch]=n)}n&&(t.headers[r.IfModifiedSince]=!0===n?e.data.headers[r.LastModified]||new Date(e.createdAt).toUTCString():n.toUTCString())}function d(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function u(e){const t=async t=>{var a;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!o(t.method,t.cache.methods))return t;const r=t.id=e.generateKey(t);let i,d=await e.storage.get(r);e:if("empty"===d.state||"stale"===d.state){if(e.waiting[r]){d=await e.storage.get(r);break e}return e.waiting[r]=(0,n.deferred)(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),await e.storage.set(r,{state:"loading",previous:d.state,data:d.data,createdAt:d.createdAt}),"stale"===d.state&&c(d,t),t.validateStatus=s(t.validateStatus),t}if("loading"===d.state){const a=e.waiting[r];if(!a)return await e.storage.remove(r),t;0;try{i=await a}catch(e){return t}}else i=d.data;return t.adapter=()=>Promise.resolve({config:t,data:i.data,headers:i.headers,status:i.status,statusText:i.statusText,cached:!0,id:r}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function f(e,t){var a;if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:i,containsHeaders:n}=t;if(r&&!await r(e.status)||i&&!await i(e))return!1;if(n)for(const t in n){const r=n[t];if(r&&!await r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t]))return!1}return!0}async function l(e,t,a){for(const r in a){const i=a[r];if("delete"===i){await e.remove(r);continue}const n=await e.get(r);if("loading"===n.state)continue;const s=await i(n,t);"delete"!==s?"ignore"!==s&&await e.set(r,s):await e.remove(r)}}function h(e){const t=async t=>{var a;await e.storage.remove(t),null===(a=e.waiting[t])||void 0===a||a.reject(null),delete e.waiting[t]},a=async a=>{var i,n,s;if(a.id=null!==(i=(s=a.config).id)&&void 0!==i?i:s.id=e.generateKey(a.config),null!==(n=a.cached)&&void 0!==n||(a.cached=!1),a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const o=a.config.cache,c=await e.storage.get(a.id);if("stale"===c.state||"empty"===c.state||"cached"===c.state)return a;if(!c.data&&!await f(a,o.cachePredicate))return await t(a.id),a;for(const e in r)e.startsWith("XAxiosCache")&&delete a.headers[e];o.etag&&!0!==o.etag&&(a.headers[r.XAxiosCacheEtag]=o.etag),o.modifiedSince&&(a.headers[r.XAxiosCacheLastModified]=!0===o.modifiedSince?"use-cache-timestamp":o.modifiedSince.toUTCString());let u=o.ttl||-1;if(null==o?void 0:o.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),a;u="not enough headers"===r?u:r}const h=d(a,c.data);"function"==typeof u&&(u=await u(a)),o.staleIfError&&(a.headers[r.XAxiosCacheStaleIfError]=String(u)),(null==o?void 0:o.update)&&await l(e.storage,a,o.update);const g={state:"cached",ttl:u,createdAt:Date.now(),data:h},p=e.waiting[a.id];return p&&(p.resolve(g.data),delete e.waiting[a.id]),await e.storage.set(a.id,g),a},i=async a=>{var r;const i=a.config;if(!i||!1===i.cache||!i.id)throw a;const n=await e.storage.get(i.id),s=i.cache;if("loading"!==n.state||"stale"!==n.previous)throw await t(i.id),a;if(null==s?void 0:s.staleIfError){const t="function"==typeof s.staleIfError?await s.staleIfError(a.response,n,a):s.staleIfError;if(!0===t||"number"==typeof t&&n.createdAt+t>Date.now())return null===(r=e.waiting[i.id])||void 0===r||r.resolve(n.data),delete e.waiting[i.id],await e.storage.set(i.id,{state:"stale",createdAt:Date.now(),data:n.data}),{cached:!0,config:i,id:i.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}}throw a};return{onFulfilled:a,onRejected:i,apply:()=>e.interceptors.response.use(a,i)}}const g=Symbol(),p=e=>!!e&&!!e[g];function m(e){const t=e.data.headers;return r.ETag in t||r.LastModified in t||r.XAxiosCacheEtag in t||r.XAxiosCacheStaleIfError in t||r.XAxiosCacheLastModified in t}function w(e){return e.createdAt+e.ttl<=Date.now()}function v({set:e,find:t,remove:a}){return{[g]:1,set:e,remove:a,get:async r=>{const i=await t(r);if(!i)return{state:"empty"};if("cached"!==i.state||!w(i))return i;if(m(i)){const t={state:"stale",createdAt:i.createdAt,data:i.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function y(){const e=v({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const S=require("object-code"),b=/^\/|\/$/g;function I(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(b,"")),a.url&&(a.url=a.url.replace(b,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?`${(0,S.hash)(r)}`:r}}const x=I(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:i})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:i})));function C(e,t={}){var a,r,n,s,o;const c=e;if(c.storage=t.storage||y(),!p(c.storage))throw new Error("Use buildStorage() function");return c.generateKey=t.generateKey||x,c.waiting=t.waiting||{},c.headerInterpreter=t.headerInterpreter||i,c.requestInterceptor=t.requestInterceptor||u(c),c.responseInterceptor=t.responseInterceptor||h(c),c.debug=t.debug,c.defaults.cache={ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,interpretHeader:null!==(r=t.interpretHeader)&&void 0!==r&&r,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(n=t.etag)&&void 0!==n&&n,modifiedSince:null!==(s=t.modifiedSince)&&void 0!==s&&s,staleIfError:null!==(o=t.staleIfError)&&void 0!==o&&o,update:t.update||{}},c.requestInterceptor.apply(),c.responseInterceptor.apply(),c}function A(e,t=""){return v({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const i=()=>e.setItem(t+a,JSON.stringify(r));try{return i()}catch(r){const n=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of n)"cached"===a.state&&w(a)&&!m(a)&&e.removeItem(t);try{return i()}catch(t){const a=n.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return i()}catch(e){}}}e.removeItem(t+a)}}})}module.exports=t})(); |
@@ -1,2 +0,2 @@ | ||
import*as e from"cache-parser";import*as t from"fast-defer";import*as a from"object-code";var r={d:(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},s={};r.d(s,{h4:()=>n,UN:()=>A,uu:()=>S,Kd:()=>y,ZF:()=>L,nv:()=>I,p:()=>h,E7:()=>c,NQ:()=>o,xK:()=>E,G6:()=>f,LN:()=>m,Bw:()=>v,Ad:()=>u,$k:()=>b,v8:()=>R,Jk:()=>l,tI:()=>p,iS:()=>g});const i=(e=>{var t={};return r.d(t,e),t})({parse:()=>e.parse}),n=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",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=e=>{if(!e)return"not enough headers";const t=e[n.CacheControl];if(t){const{noCache:a,noStore:r,mustRevalidate:s,maxAge:o,immutable:d}=(0,i.parse)(String(t));if(a||r)return"dont cache";if(d)return 31536e6;if(s)return 0;if(o){const t=e[n.Age];return t?1e3*(o-Number(t)):1e3*o}}const a=e[n.Expires];if(a){const e=Date.parse(String(a))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};const d=(e=>{var t={};return r.d(t,e),t})({deferred:()=>t.deferred});function c(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function u(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function g(e,t){t.headers||(t.headers={});const{etag:a,modifiedSince:r}=t.cache;if(a){const r=!0===a?e.data?.headers[n.ETag]:a;r&&(t.headers[n.IfNoneMatch]=r)}r&&(t.headers[n.IfModifiedSince]=!0===r?e.data.headers[n.LastModified]||new Date(e.createdAt).toUTCString():r.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={...t.headers,...e.headers},t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function f(e){const t=async t=>{if(!1===t.cache)return e.debug?.({msg:"Ignoring cache because config.cache is false",data:t}),t;if(t.cache={...e.defaults.cache,...t.cache},!u(t.method,t.cache.methods))return e.debug?.({msg:`Ignored because method (${t.method}) is not in cache.methods (${t.cache.methods})`}),t;const a=t.id=e.generateKey(t);let r,s=await e.storage.get(a);e:if("empty"===s.state||"stale"===s.state){if(e.waiting[a]){s=await e.storage.get(a),e.debug?.({id:a,msg:"Waiting list had an deferred for this key, waiting for it to finish"});break e}return e.waiting[a]=(0,d.deferred)(),e.waiting[a]?.catch((()=>{})),await e.storage.set(a,{state:"loading",previous:s.state,data:s.data,createdAt:s.createdAt}),"stale"===s.state&&(g(s,t),e.debug?.({id:a,msg:"Updated stale request"})),t.validateStatus=c(t.validateStatus),e.debug?.({id:a,msg:"Sending request, waiting for response"}),t}if("loading"===s.state){const s=e.waiting[a];if(!s)return await e.storage.remove(a),t;e.debug?.({id:a,msg:"Detected concurrent request, waiting for it to finish"});try{r=await s}catch(r){return e.debug?.({id:a,msg:"Deferred rejected, requesting again",data:r}),t}}else r=s.data;return t.adapter=()=>Promise.resolve({config:t,data:r.data,headers:r.headers,status:r.status,statusText:r.statusText,cached:!0,id:a}),e.debug?.({id:a,msg:"Returning cached response"}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function l(e,t){if("function"==typeof t)return t(e);const{statusCheck:a,responseMatch:r,containsHeaders:s}=t;if(a&&!await a(e.status)||r&&!await r(e))return!1;if(s)for(const t in s){const a=s[t];if(a&&!await a(e.headers[t.toLowerCase()]??e.headers[t]))return!1}return!0}async function p(e,t,a){for(const r in a){const s=a[r];if("delete"===s){await e.remove(r);continue}const i=await e.get(r);if("loading"===i.state)continue;const n=await s(i,t);"delete"!==n?"ignore"!==n&&await e.set(r,n):await e.remove(r)}}function m(e){const t=async t=>{await e.storage.remove(t),e.waiting[t]?.reject(null),delete e.waiting[t]},a=async a=>{var r;if(a.id=(r=a.config).id??(r.id=e.generateKey(a.config)),a.cached??(a.cached=!1),a.cached)return e.debug?.({id:a.id,msg:"Returned cached response"}),a;if(!a.config.cache)return e.debug?.({id:a.id,msg:"Response with config.cache === false",data:a}),{...a,cached:!1};const s=a.config.cache,i=await e.storage.get(a.id);if("stale"===i.state||"empty"===i.state||"cached"===i.state)return e.debug?.({id:a.id,msg:"Response not cached but storage is not loading",data:{cache:i,response:a}}),a;if(!i.data&&!await l(a,s.cachePredicate))return await t(a.id),e.debug?.({id:a.id,msg:"Cache predicate rejected this response"}),a;for(const e in n)e.startsWith("XAxiosCache")&&delete a.headers[e];s.etag&&!0!==s.etag&&(a.headers[n.XAxiosCacheEtag]=s.etag),s.modifiedSince&&(a.headers[n.XAxiosCacheLastModified]=!0===s.modifiedSince?"use-cache-timestamp":s.modifiedSince.toUTCString());let o=s.ttl||-1;if(s?.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),e.debug?.({id:a.id,msg:"Cache header interpreted as 'dont cache'",data:{cache:i,response:a,expirationTime:r}}),a;o="not enough headers"===r?o:r}const d=h(a,i.data);"function"==typeof o&&(o=await o(a)),s.staleIfError&&(a.headers[n.XAxiosCacheStaleIfError]=String(o)),e.debug?.({id:a.id,msg:"Useful response configuration found",data:{cacheConfig:s,ttl:o,cacheResponse:d}}),s?.update&&await p(e.storage,a,s.update);const c={state:"cached",ttl:o,createdAt:Date.now(),data:d},u=e.waiting[a.id];return u&&(u.resolve(c.data),delete e.waiting[a.id],e.debug?.({id:a.id,msg:"Found waiting deferred(s) and resolved them"})),await e.storage.set(a.id,c),e.debug?.({id:a.id,msg:"Response cached",data:{cache:c,response:a}}),a},r=async a=>{const r=a.config;if(!r||!1===r.cache||!r.id)throw e.debug?.({msg:"Web request returned an error but cache handling is not enabled",data:{error:a,config:r}}),a;const s=await e.storage.get(r.id),i=r.cache;if("loading"!==s.state||"stale"!==s.previous)throw await t(r.id),e.debug?.({msg:"Caught an error in the request interceptor",data:{error:a,config:r}}),a;if(i?.staleIfError){const t="function"==typeof i.staleIfError?await i.staleIfError(a.response,s,a):i.staleIfError;if(e.debug?.({msg:"Found cache if stale config for rejected response",data:{error:a,config:r,staleIfError:t}}),!0===t||"number"==typeof t&&s.createdAt+t>Date.now())return e.waiting[r.id]?.resolve(s.data),delete e.waiting[r.id],await e.storage.set(r.id,{state:"stale",createdAt:Date.now(),data:s.data}),e.debug?.({msg:"staleIfError resolved this response with cached data",data:{error:a,config:r,cache:s}}),{cached:!0,config:r,id:r.id,data:s.data.data,headers:s.data.headers,status:s.data.status,statusText:s.data.statusText}}throw e.debug?.({msg:"Received an unknown error that could not be handled",data:{error:a,config:r}}),a};return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const w=Symbol(),b=e=>!!e&&!!e[w];function I(e){const t=e.data.headers;return n.ETag in t||n.LastModified in t||n.XAxiosCacheEtag in t||n.XAxiosCacheStaleIfError in t||n.XAxiosCacheLastModified in t}function v(e){return e.createdAt+e.ttl<=Date.now()}function y({set:e,find:t,remove:a}){return{[w]:1,set:e,remove:a,get:async r=>{const s=await t(r);if(!s)return{state:"empty"};if("cached"!==s.state||!v(s))return s;if(I(s)){const t={state:"stale",createdAt:s.createdAt,data:s.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function S(){const e=y({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const C=(e=>{var t={};return r.d(t,e),t})({hashCode:()=>a.hashCode}),x=/^\/|\/$/g;function A(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(x,"")),a.url&&(a.url=a.url.replace(x,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?(0,C.hashCode)(r).toString():r}}const E=A(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:s})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:s})));function R(e,t={}){const a=e;if(a.storage=t.storage||S(),!b(a.storage))throw new Error("Use buildStorage() function");return a.generateKey=t.generateKey||E,a.waiting=t.waiting||{},a.headerInterpreter=t.headerInterpreter||o,a.requestInterceptor=t.requestInterceptor||f(a),a.responseInterceptor=t.responseInterceptor||m(a),a.debug=t.debug,a.defaults.cache={ttl:t.ttl??3e5,interpretHeader:t.interpretHeader??!1,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:t.etag??!1,modifiedSince:t.modifiedSince??!1,staleIfError:t.staleIfError??!1,update:t.update||{}},a.requestInterceptor.apply(),a.responseInterceptor.apply(),a}function L(e,t=""){return y({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const s=()=>e.setItem(t+a,JSON.stringify(r));try{return s()}catch(r){const i=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of i)"cached"===a.state&&v(a)&&!I(a)&&e.removeItem(t);try{return s()}catch(t){const a=i.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return s()}catch(e){}}}e.removeItem(t+a)}}})}console.error("You are using a development build. Make sure to use the correct build in production"),console.error("https://axios-cache-interceptor.js.org/#/pages/installing");var T=s.h4,M=s.UN,j=s.uu,q=s.Kd,N=s.ZF,U=s.nv,k=s.p,K=s.E7,X=s.NQ,D=s.xK,O=s.G6,P=s.LN,F=s.Bw,H=s.Ad,J=s.$k,W=s.v8,$=s.Jk,G=s.tI,B=s.iS;export{T as Header,M as buildKeyGenerator,j as buildMemoryStorage,q as buildStorage,N as buildWebStorage,U as canStale,k as createCacheResponse,K as createValidateStatus,X as defaultHeaderInterpreter,D as defaultKeyGenerator,O as defaultRequestInterceptor,P as defaultResponseInterceptor,F as isExpired,H as isMethodIn,J as isStorage,W as setupCache,$ as testCachePredicate,G as updateCache,B as updateStaleRequest}; | ||
import*as e from"cache-parser";import*as t from"fast-defer";import*as a from"object-code";var r={d:(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},s={};r.d(s,{h4:()=>n,UN:()=>A,uu:()=>S,Kd:()=>y,ZF:()=>L,nv:()=>I,p:()=>g,E7:()=>c,NQ:()=>o,xK:()=>E,G6:()=>f,LN:()=>m,Bw:()=>v,Ad:()=>u,$k:()=>b,v8:()=>R,Jk:()=>l,tI:()=>p,iS:()=>h});const i=(e=>{var t={};return r.d(t,e),t})({parse:()=>e.parse}),n=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",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=e=>{if(!e)return"not enough headers";const t=e[n.CacheControl];if(t){const{noCache:a,noStore:r,mustRevalidate:s,maxAge:o,immutable:d}=(0,i.parse)(String(t));if(a||r)return"dont cache";if(d)return 31536e6;if(s)return 0;if(o){const t=e[n.Age];return t?1e3*(o-Number(t)):1e3*o}}const a=e[n.Expires];if(a){const e=Date.parse(String(a))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};const d=(e=>{var t={};return r.d(t,e),t})({deferred:()=>t.deferred});function c(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function u(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function h(e,t){t.headers||(t.headers={});const{etag:a,modifiedSince:r}=t.cache;if(a){const r=!0===a?e.data?.headers[n.ETag]:a;r&&(t.headers[n.IfNoneMatch]=r)}r&&(t.headers[n.IfModifiedSince]=!0===r?e.data.headers[n.LastModified]||new Date(e.createdAt).toUTCString():r.toUTCString())}function g(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers={...t.headers,...e.headers},t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function f(e){const t=async t=>{if(!1===t.cache)return e.debug?.({msg:"Ignoring cache because config.cache is false",data:t}),t;if(t.cache={...e.defaults.cache,...t.cache},!u(t.method,t.cache.methods))return e.debug?.({msg:`Ignored because method (${t.method}) is not in cache.methods (${t.cache.methods})`}),t;const a=t.id=e.generateKey(t);let r,s=await e.storage.get(a);e:if("empty"===s.state||"stale"===s.state){if(e.waiting[a]){s=await e.storage.get(a),e.debug?.({id:a,msg:"Waiting list had an deferred for this key, waiting for it to finish"});break e}return e.waiting[a]=(0,d.deferred)(),e.waiting[a]?.catch((()=>{})),await e.storage.set(a,{state:"loading",previous:s.state,data:s.data,createdAt:s.createdAt}),"stale"===s.state&&(h(s,t),e.debug?.({id:a,msg:"Updated stale request"})),t.validateStatus=c(t.validateStatus),e.debug?.({id:a,msg:"Sending request, waiting for response"}),t}if("loading"===s.state){const s=e.waiting[a];if(!s)return await e.storage.remove(a),t;e.debug?.({id:a,msg:"Detected concurrent request, waiting for it to finish"});try{r=await s}catch(r){return e.debug?.({id:a,msg:"Deferred rejected, requesting again",data:r}),t}}else r=s.data;return t.adapter=()=>Promise.resolve({config:t,data:r.data,headers:r.headers,status:r.status,statusText:r.statusText,cached:!0,id:a}),e.debug?.({id:a,msg:"Returning cached response"}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function l(e,t){if("function"==typeof t)return t(e);const{statusCheck:a,responseMatch:r,containsHeaders:s}=t;if(a&&!await a(e.status)||r&&!await r(e))return!1;if(s)for(const t in s){const a=s[t];if(a&&!await a(e.headers[t.toLowerCase()]??e.headers[t]))return!1}return!0}async function p(e,t,a){for(const r in a){const s=a[r];if("delete"===s){await e.remove(r);continue}const i=await e.get(r);if("loading"===i.state)continue;const n=await s(i,t);"delete"!==n?"ignore"!==n&&await e.set(r,n):await e.remove(r)}}function m(e){const t=async t=>{await e.storage.remove(t),e.waiting[t]?.reject(null),delete e.waiting[t]},a=async a=>{var r;if(a.id=(r=a.config).id??(r.id=e.generateKey(a.config)),a.cached??(a.cached=!1),a.cached)return e.debug?.({id:a.id,msg:"Returned cached response"}),a;if(!a.config.cache)return e.debug?.({id:a.id,msg:"Response with config.cache === false",data:a}),{...a,cached:!1};const s=a.config.cache,i=await e.storage.get(a.id);if("stale"===i.state||"empty"===i.state||"cached"===i.state)return e.debug?.({id:a.id,msg:"Response not cached but storage is not loading",data:{cache:i,response:a}}),a;if(!i.data&&!await l(a,s.cachePredicate))return await t(a.id),e.debug?.({id:a.id,msg:"Cache predicate rejected this response"}),a;for(const e in n)e.startsWith("XAxiosCache")&&delete a.headers[e];s.etag&&!0!==s.etag&&(a.headers[n.XAxiosCacheEtag]=s.etag),s.modifiedSince&&(a.headers[n.XAxiosCacheLastModified]=!0===s.modifiedSince?"use-cache-timestamp":s.modifiedSince.toUTCString());let o=s.ttl||-1;if(s?.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),e.debug?.({id:a.id,msg:"Cache header interpreted as 'dont cache'",data:{cache:i,response:a,expirationTime:r}}),a;o="not enough headers"===r?o:r}const d=g(a,i.data);"function"==typeof o&&(o=await o(a)),s.staleIfError&&(a.headers[n.XAxiosCacheStaleIfError]=String(o)),e.debug?.({id:a.id,msg:"Useful response configuration found",data:{cacheConfig:s,ttl:o,cacheResponse:d}}),s?.update&&await p(e.storage,a,s.update);const c={state:"cached",ttl:o,createdAt:Date.now(),data:d},u=e.waiting[a.id];return u&&(u.resolve(c.data),delete e.waiting[a.id],e.debug?.({id:a.id,msg:"Found waiting deferred(s) and resolved them"})),await e.storage.set(a.id,c),e.debug?.({id:a.id,msg:"Response cached",data:{cache:c,response:a}}),a},r=async a=>{const r=a.config;if(!r||!1===r.cache||!r.id)throw e.debug?.({msg:"Web request returned an error but cache handling is not enabled",data:{error:a,config:r}}),a;const s=await e.storage.get(r.id),i=r.cache;if("loading"!==s.state||"stale"!==s.previous)throw await t(r.id),e.debug?.({msg:"Caught an error in the request interceptor",data:{error:a,config:r}}),a;if(i?.staleIfError){const t="function"==typeof i.staleIfError?await i.staleIfError(a.response,s,a):i.staleIfError;if(e.debug?.({msg:"Found cache if stale config for rejected response",data:{error:a,config:r,staleIfError:t}}),!0===t||"number"==typeof t&&s.createdAt+t>Date.now())return e.waiting[r.id]?.resolve(s.data),delete e.waiting[r.id],await e.storage.set(r.id,{state:"stale",createdAt:Date.now(),data:s.data}),e.debug?.({msg:"staleIfError resolved this response with cached data",data:{error:a,config:r,cache:s}}),{cached:!0,config:r,id:r.id,data:s.data.data,headers:s.data.headers,status:s.data.status,statusText:s.data.statusText}}throw e.debug?.({msg:"Received an unknown error that could not be handled",data:{error:a,config:r}}),a};return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const w=Symbol(),b=e=>!!e&&!!e[w];function I(e){const t=e.data.headers;return n.ETag in t||n.LastModified in t||n.XAxiosCacheEtag in t||n.XAxiosCacheStaleIfError in t||n.XAxiosCacheLastModified in t}function v(e){return e.createdAt+e.ttl<=Date.now()}function y({set:e,find:t,remove:a}){return{[w]:1,set:e,remove:a,get:async r=>{const s=await t(r);if(!s)return{state:"empty"};if("cached"!==s.state||!v(s))return s;if(I(s)){const t={state:"stale",createdAt:s.createdAt,data:s.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function S(){const e=y({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const x=(e=>{var t={};return r.d(t,e),t})({hash:()=>a.hash}),C=/^\/|\/$/g;function A(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(C,"")),a.url&&(a.url=a.url.replace(C,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?`${(0,x.hash)(r)}`:r}}const E=A(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:s})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:s})));function R(e,t={}){const a=e;if(a.storage=t.storage||S(),!b(a.storage))throw new Error("Use buildStorage() function");return a.generateKey=t.generateKey||E,a.waiting=t.waiting||{},a.headerInterpreter=t.headerInterpreter||o,a.requestInterceptor=t.requestInterceptor||f(a),a.responseInterceptor=t.responseInterceptor||m(a),a.debug=t.debug,a.defaults.cache={ttl:t.ttl??3e5,interpretHeader:t.interpretHeader??!1,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:t.etag??!1,modifiedSince:t.modifiedSince??!1,staleIfError:t.staleIfError??!1,update:t.update||{}},a.requestInterceptor.apply(),a.responseInterceptor.apply(),a}function L(e,t=""){return y({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const s=()=>e.setItem(t+a,JSON.stringify(r));try{return s()}catch(r){const i=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of i)"cached"===a.state&&v(a)&&!I(a)&&e.removeItem(t);try{return s()}catch(t){const a=i.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return s()}catch(e){}}}e.removeItem(t+a)}}})}console.error("You are using a development build. Make sure to use the correct build in production"),console.error("https://axios-cache-interceptor.js.org/#/pages/installing");var T=s.h4,M=s.UN,j=s.uu,q=s.Kd,N=s.ZF,U=s.nv,k=s.p,K=s.E7,X=s.NQ,D=s.xK,O=s.G6,P=s.LN,F=s.Bw,H=s.Ad,$=s.$k,J=s.v8,W=s.Jk,G=s.tI,B=s.iS;export{T as Header,M as buildKeyGenerator,j as buildMemoryStorage,q as buildStorage,N as buildWebStorage,U as canStale,k as createCacheResponse,K as createValidateStatus,X as defaultHeaderInterpreter,D as defaultKeyGenerator,O as defaultRequestInterceptor,P as defaultResponseInterceptor,F as isExpired,H as isMethodIn,$ as isStorage,J as setupCache,W as testCachePredicate,G as updateCache,B as updateStaleRequest}; | ||
//# sourceMappingURL=dev.map |
@@ -1,1 +0,1 @@ | ||
import*as e from"cache-parser";import*as t from"fast-defer";import*as a from"object-code";var r={d:(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},s={};r.d(s,{h4:()=>i,UN:()=>A,uu:()=>x,Kd:()=>S,ZF:()=>O,nv:()=>I,p:()=>h,E7:()=>c,NQ:()=>o,xK:()=>E,G6:()=>l,LN:()=>m,Bw:()=>y,Ad:()=>u,$k:()=>v,v8:()=>L,Jk:()=>g,tI:()=>p,iS:()=>f});const n=(e=>{var t={};return r.d(t,e),t})({parse:()=>e.parse}),i=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",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=e=>{if(!e)return"not enough headers";const t=e[i.CacheControl];if(t){const{noCache:a,noStore:r,mustRevalidate:s,maxAge:o,immutable:d}=(0,n.parse)(String(t));if(a||r)return"dont cache";if(d)return 31536e6;if(s)return 0;if(o){const t=e[i.Age];return t?1e3*(o-Number(t)):1e3*o}}const a=e[i.Expires];if(a){const e=Date.parse(String(a))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};const d=(e=>{var t={};return r.d(t,e),t})({deferred:()=>t.deferred});function c(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function u(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function f(e,t){var a;t.headers||(t.headers={});const{etag:r,modifiedSince:s}=t.cache;if(r){const s=!0===r?null===(a=e.data)||void 0===a?void 0:a.headers[i.ETag]:r;s&&(t.headers[i.IfNoneMatch]=s)}s&&(t.headers[i.IfModifiedSince]=!0===s?e.data.headers[i.LastModified]||new Date(e.createdAt).toUTCString():s.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=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function l(e){const t=async t=>{var a;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!u(t.method,t.cache.methods))return t;const r=t.id=e.generateKey(t);let s,n=await e.storage.get(r);e:if("empty"===n.state||"stale"===n.state){if(e.waiting[r]){n=await e.storage.get(r);break e}return e.waiting[r]=(0,d.deferred)(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),await e.storage.set(r,{state:"loading",previous:n.state,data:n.data,createdAt:n.createdAt}),"stale"===n.state&&f(n,t),t.validateStatus=c(t.validateStatus),t}if("loading"===n.state){const a=e.waiting[r];if(!a)return await e.storage.remove(r),t;0;try{s=await a}catch(e){return t}}else s=n.data;return t.adapter=()=>Promise.resolve({config:t,data:s.data,headers:s.headers,status:s.status,statusText:s.statusText,cached:!0,id:r}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function g(e,t){var a;if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:s,containsHeaders:n}=t;if(r&&!await r(e.status)||s&&!await s(e))return!1;if(n)for(const t in n){const r=n[t];if(r&&!await r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t]))return!1}return!0}async function p(e,t,a){for(const r in a){const s=a[r];if("delete"===s){await e.remove(r);continue}const n=await e.get(r);if("loading"===n.state)continue;const i=await s(n,t);"delete"!==i?"ignore"!==i&&await e.set(r,i):await e.remove(r)}}function m(e){const t=async t=>{var a;await e.storage.remove(t),null===(a=e.waiting[t])||void 0===a||a.reject(null),delete e.waiting[t]},a=async a=>{var r,s,n;if(a.id=null!==(r=(n=a.config).id)&&void 0!==r?r:n.id=e.generateKey(a.config),null!==(s=a.cached)&&void 0!==s||(a.cached=!1),a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const o=a.config.cache,d=await e.storage.get(a.id);if("stale"===d.state||"empty"===d.state||"cached"===d.state)return a;if(!d.data&&!await g(a,o.cachePredicate))return await t(a.id),a;for(const e in i)e.startsWith("XAxiosCache")&&delete a.headers[e];o.etag&&!0!==o.etag&&(a.headers[i.XAxiosCacheEtag]=o.etag),o.modifiedSince&&(a.headers[i.XAxiosCacheLastModified]=!0===o.modifiedSince?"use-cache-timestamp":o.modifiedSince.toUTCString());let c=o.ttl||-1;if(null==o?void 0:o.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),a;c="not enough headers"===r?c:r}const u=h(a,d.data);"function"==typeof c&&(c=await c(a)),o.staleIfError&&(a.headers[i.XAxiosCacheStaleIfError]=String(c)),(null==o?void 0:o.update)&&await p(e.storage,a,o.update);const f={state:"cached",ttl:c,createdAt:Date.now(),data:u},l=e.waiting[a.id];return l&&(l.resolve(f.data),delete e.waiting[a.id]),await e.storage.set(a.id,f),a},r=async a=>{var r;const s=a.config;if(!s||!1===s.cache||!s.id)throw a;const n=await e.storage.get(s.id),i=s.cache;if("loading"!==n.state||"stale"!==n.previous)throw await t(s.id),a;if(null==i?void 0:i.staleIfError){const t="function"==typeof i.staleIfError?await i.staleIfError(a.response,n,a):i.staleIfError;if(!0===t||"number"==typeof t&&n.createdAt+t>Date.now())return null===(r=e.waiting[s.id])||void 0===r||r.resolve(n.data),delete e.waiting[s.id],await e.storage.set(s.id,{state:"stale",createdAt:Date.now(),data:n.data}),{cached:!0,config:s,id:s.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}}throw a};return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const w=Symbol(),v=e=>!!e&&!!e[w];function I(e){const t=e.data.headers;return i.ETag in t||i.LastModified in t||i.XAxiosCacheEtag in t||i.XAxiosCacheStaleIfError in t||i.XAxiosCacheLastModified in t}function y(e){return e.createdAt+e.ttl<=Date.now()}function S({set:e,find:t,remove:a}){return{[w]:1,set:e,remove:a,get:async r=>{const s=await t(r);if(!s)return{state:"empty"};if("cached"!==s.state||!y(s))return s;if(I(s)){const t={state:"stale",createdAt:s.createdAt,data:s.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function x(){const e=S({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const C=(e=>{var t={};return r.d(t,e),t})({hashCode:()=>a.hashCode}),b=/^\/|\/$/g;function A(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(b,"")),a.url&&(a.url=a.url.replace(b,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?(0,C.hashCode)(r).toString():r}}const E=A(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:s})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:s})));function L(e,t={}){var a,r,s,n,i;const d=e;if(d.storage=t.storage||x(),!v(d.storage))throw new Error("Use buildStorage() function");return d.generateKey=t.generateKey||E,d.waiting=t.waiting||{},d.headerInterpreter=t.headerInterpreter||o,d.requestInterceptor=t.requestInterceptor||l(d),d.responseInterceptor=t.responseInterceptor||m(d),d.debug=t.debug,d.defaults.cache={ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,interpretHeader:null!==(r=t.interpretHeader)&&void 0!==r&&r,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(s=t.etag)&&void 0!==s&&s,modifiedSince:null!==(n=t.modifiedSince)&&void 0!==n&&n,staleIfError:null!==(i=t.staleIfError)&&void 0!==i&&i,update:t.update||{}},d.requestInterceptor.apply(),d.responseInterceptor.apply(),d}function O(e,t=""){return S({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const s=()=>e.setItem(t+a,JSON.stringify(r));try{return s()}catch(r){const n=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of n)"cached"===a.state&&y(a)&&!I(a)&&e.removeItem(t);try{return s()}catch(t){const a=n.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return s()}catch(e){}}}e.removeItem(t+a)}}})}var j=s.h4,T=s.UN,M=s.uu,N=s.Kd,K=s.ZF,R=s.nv,U=s.p,X=s.E7,k=s.NQ,D=s.xK,P=s.G6,q=s.LN,H=s.Bw,J=s.Ad,F=s.$k,G=s.v8,W=s.Jk,$=s.tI,B=s.iS;export{j as Header,T as buildKeyGenerator,M as buildMemoryStorage,N as buildStorage,K as buildWebStorage,R as canStale,U as createCacheResponse,X as createValidateStatus,k as defaultHeaderInterpreter,D as defaultKeyGenerator,P as defaultRequestInterceptor,q as defaultResponseInterceptor,H as isExpired,J as isMethodIn,F as isStorage,G as setupCache,W as testCachePredicate,$ as updateCache,B as updateStaleRequest}; | ||
import*as e from"cache-parser";import*as t from"fast-defer";import*as a from"object-code";var r={d:(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},s={};r.d(s,{h4:()=>i,UN:()=>A,uu:()=>x,Kd:()=>S,ZF:()=>O,nv:()=>I,p:()=>h,E7:()=>c,NQ:()=>o,xK:()=>E,G6:()=>l,LN:()=>m,Bw:()=>y,Ad:()=>u,$k:()=>v,v8:()=>L,Jk:()=>g,tI:()=>p,iS:()=>f});const n=(e=>{var t={};return r.d(t,e),t})({parse:()=>e.parse}),i=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",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=e=>{if(!e)return"not enough headers";const t=e[i.CacheControl];if(t){const{noCache:a,noStore:r,mustRevalidate:s,maxAge:o,immutable:d}=(0,n.parse)(String(t));if(a||r)return"dont cache";if(d)return 31536e6;if(s)return 0;if(o){const t=e[i.Age];return t?1e3*(o-Number(t)):1e3*o}}const a=e[i.Expires];if(a){const e=Date.parse(String(a))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};const d=(e=>{var t={};return r.d(t,e),t})({deferred:()=>t.deferred});function c(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function u(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function f(e,t){var a;t.headers||(t.headers={});const{etag:r,modifiedSince:s}=t.cache;if(r){const s=!0===r?null===(a=e.data)||void 0===a?void 0:a.headers[i.ETag]:r;s&&(t.headers[i.IfNoneMatch]=s)}s&&(t.headers[i.IfModifiedSince]=!0===s?e.data.headers[i.LastModified]||new Date(e.createdAt).toUTCString():s.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=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function l(e){const t=async t=>{var a;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!u(t.method,t.cache.methods))return t;const r=t.id=e.generateKey(t);let s,n=await e.storage.get(r);e:if("empty"===n.state||"stale"===n.state){if(e.waiting[r]){n=await e.storage.get(r);break e}return e.waiting[r]=(0,d.deferred)(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),await e.storage.set(r,{state:"loading",previous:n.state,data:n.data,createdAt:n.createdAt}),"stale"===n.state&&f(n,t),t.validateStatus=c(t.validateStatus),t}if("loading"===n.state){const a=e.waiting[r];if(!a)return await e.storage.remove(r),t;0;try{s=await a}catch(e){return t}}else s=n.data;return t.adapter=()=>Promise.resolve({config:t,data:s.data,headers:s.headers,status:s.status,statusText:s.statusText,cached:!0,id:r}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function g(e,t){var a;if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:s,containsHeaders:n}=t;if(r&&!await r(e.status)||s&&!await s(e))return!1;if(n)for(const t in n){const r=n[t];if(r&&!await r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t]))return!1}return!0}async function p(e,t,a){for(const r in a){const s=a[r];if("delete"===s){await e.remove(r);continue}const n=await e.get(r);if("loading"===n.state)continue;const i=await s(n,t);"delete"!==i?"ignore"!==i&&await e.set(r,i):await e.remove(r)}}function m(e){const t=async t=>{var a;await e.storage.remove(t),null===(a=e.waiting[t])||void 0===a||a.reject(null),delete e.waiting[t]},a=async a=>{var r,s,n;if(a.id=null!==(r=(n=a.config).id)&&void 0!==r?r:n.id=e.generateKey(a.config),null!==(s=a.cached)&&void 0!==s||(a.cached=!1),a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const o=a.config.cache,d=await e.storage.get(a.id);if("stale"===d.state||"empty"===d.state||"cached"===d.state)return a;if(!d.data&&!await g(a,o.cachePredicate))return await t(a.id),a;for(const e in i)e.startsWith("XAxiosCache")&&delete a.headers[e];o.etag&&!0!==o.etag&&(a.headers[i.XAxiosCacheEtag]=o.etag),o.modifiedSince&&(a.headers[i.XAxiosCacheLastModified]=!0===o.modifiedSince?"use-cache-timestamp":o.modifiedSince.toUTCString());let c=o.ttl||-1;if(null==o?void 0:o.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),a;c="not enough headers"===r?c:r}const u=h(a,d.data);"function"==typeof c&&(c=await c(a)),o.staleIfError&&(a.headers[i.XAxiosCacheStaleIfError]=String(c)),(null==o?void 0:o.update)&&await p(e.storage,a,o.update);const f={state:"cached",ttl:c,createdAt:Date.now(),data:u},l=e.waiting[a.id];return l&&(l.resolve(f.data),delete e.waiting[a.id]),await e.storage.set(a.id,f),a},r=async a=>{var r;const s=a.config;if(!s||!1===s.cache||!s.id)throw a;const n=await e.storage.get(s.id),i=s.cache;if("loading"!==n.state||"stale"!==n.previous)throw await t(s.id),a;if(null==i?void 0:i.staleIfError){const t="function"==typeof i.staleIfError?await i.staleIfError(a.response,n,a):i.staleIfError;if(!0===t||"number"==typeof t&&n.createdAt+t>Date.now())return null===(r=e.waiting[s.id])||void 0===r||r.resolve(n.data),delete e.waiting[s.id],await e.storage.set(s.id,{state:"stale",createdAt:Date.now(),data:n.data}),{cached:!0,config:s,id:s.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}}throw a};return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const w=Symbol(),v=e=>!!e&&!!e[w];function I(e){const t=e.data.headers;return i.ETag in t||i.LastModified in t||i.XAxiosCacheEtag in t||i.XAxiosCacheStaleIfError in t||i.XAxiosCacheLastModified in t}function y(e){return e.createdAt+e.ttl<=Date.now()}function S({set:e,find:t,remove:a}){return{[w]:1,set:e,remove:a,get:async r=>{const s=await t(r);if(!s)return{state:"empty"};if("cached"!==s.state||!y(s))return s;if(I(s)){const t={state:"stale",createdAt:s.createdAt,data:s.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function x(){const e=S({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const b=(e=>{var t={};return r.d(t,e),t})({hash:()=>a.hash}),C=/^\/|\/$/g;function A(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(C,"")),a.url&&(a.url=a.url.replace(C,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?`${(0,b.hash)(r)}`:r}}const E=A(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:s})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:s})));function L(e,t={}){var a,r,s,n,i;const d=e;if(d.storage=t.storage||x(),!v(d.storage))throw new Error("Use buildStorage() function");return d.generateKey=t.generateKey||E,d.waiting=t.waiting||{},d.headerInterpreter=t.headerInterpreter||o,d.requestInterceptor=t.requestInterceptor||l(d),d.responseInterceptor=t.responseInterceptor||m(d),d.debug=t.debug,d.defaults.cache={ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,interpretHeader:null!==(r=t.interpretHeader)&&void 0!==r&&r,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(s=t.etag)&&void 0!==s&&s,modifiedSince:null!==(n=t.modifiedSince)&&void 0!==n&&n,staleIfError:null!==(i=t.staleIfError)&&void 0!==i&&i,update:t.update||{}},d.requestInterceptor.apply(),d.responseInterceptor.apply(),d}function O(e,t=""){return S({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const s=()=>e.setItem(t+a,JSON.stringify(r));try{return s()}catch(r){const n=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of n)"cached"===a.state&&y(a)&&!I(a)&&e.removeItem(t);try{return s()}catch(t){const a=n.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return s()}catch(e){}}}e.removeItem(t+a)}}})}var j=s.h4,T=s.UN,M=s.uu,N=s.Kd,K=s.ZF,R=s.nv,U=s.p,X=s.E7,k=s.NQ,D=s.xK,P=s.G6,q=s.LN,H=s.Bw,J=s.Ad,F=s.$k,G=s.v8,$=s.Jk,W=s.tI,B=s.iS;export{j as Header,T as buildKeyGenerator,M as buildMemoryStorage,N as buildStorage,K as buildWebStorage,R as canStale,U as createCacheResponse,X as createValidateStatus,k as defaultHeaderInterpreter,D as defaultKeyGenerator,P as defaultRequestInterceptor,q as defaultResponseInterceptor,H as isExpired,J as isMethodIn,F as isStorage,G as setupCache,$ as testCachePredicate,W as updateCache,B as updateStaleRequest}; |
{ | ||
"name": "axios-cache-interceptor", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Cache interceptor for axios", | ||
@@ -53,5 +53,5 @@ "main": "./cjs/index.js", | ||
"dependencies": { | ||
"cache-parser": "1.2.0", | ||
"fast-defer": "^1.1.3", | ||
"object-code": "^1.1.2" | ||
"cache-parser": "1.2.2", | ||
"fast-defer": "^1.1.5", | ||
"object-code": "^1.2.0" | ||
}, | ||
@@ -65,4 +65,4 @@ "resolutions": { | ||
"@types/webpack": "^5.28.0", | ||
"@typescript-eslint/eslint-plugin": "^5.12.0", | ||
"@typescript-eslint/parser": "^5.12.0", | ||
"@typescript-eslint/eslint-plugin": "^5.13.0", | ||
"@typescript-eslint/parser": "^5.13.0", | ||
"auto-changelog": "^2.4.0", | ||
@@ -69,0 +69,0 @@ "axios": "^0.26.0", |
import type { Method } from 'axios'; | ||
import { hashCode } from 'object-code'; | ||
import { hash } from 'object-code'; | ||
import type { CacheRequestConfig } from '../cache/axios'; | ||
@@ -14,3 +14,3 @@ import type { KeyGenerator } from './types'; | ||
export function buildKeyGenerator<R = unknown, D = unknown>( | ||
hash: false, | ||
shouldHash: false, | ||
generator: KeyGenerator | ||
@@ -36,3 +36,3 @@ ): KeyGenerator<R, D>; | ||
export function buildKeyGenerator<R = unknown, D = unknown>( | ||
hash: true, | ||
shouldHash: true, | ||
generator: (options: CacheRequestConfig<R, D>) => unknown | ||
@@ -42,3 +42,3 @@ ): KeyGenerator<R, D>; | ||
export function buildKeyGenerator<R = unknown, D = unknown>( | ||
hash: boolean, | ||
shouldHash: boolean, | ||
generator: (options: CacheRequestConfig<R, D>) => unknown | ||
@@ -59,3 +59,3 @@ ): KeyGenerator<R, D> { | ||
const result = generator(request) as string; | ||
return hash ? hashCode(result).toString() : result; | ||
return shouldHash ? `${hash(result)}` : result; | ||
}; | ||
@@ -62,0 +62,0 @@ } |
@@ -7,3 +7,3 @@ import type { CacheRequestConfig } from '../cache/axios'; | ||
*/ | ||
export declare function buildKeyGenerator<R = unknown, D = unknown>(hash: false, generator: KeyGenerator): KeyGenerator<R, D>; | ||
export declare function buildKeyGenerator<R = unknown, D = unknown>(shouldHash: false, generator: KeyGenerator): KeyGenerator<R, D>; | ||
/** | ||
@@ -25,4 +25,4 @@ * Builds an generator that received the {@link CacheRequestConfig} and has it's return | ||
*/ | ||
export declare function buildKeyGenerator<R = unknown, D = unknown>(hash: true, generator: (options: CacheRequestConfig<R, D>) => unknown): KeyGenerator<R, D>; | ||
export declare function buildKeyGenerator<R = unknown, D = unknown>(shouldHash: true, generator: (options: CacheRequestConfig<R, D>) => unknown): KeyGenerator<R, D>; | ||
export declare const defaultKeyGenerator: KeyGenerator<unknown, unknown>; | ||
//# sourceMappingURL=key-generator.d.ts.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{var e={549:(e,t)=>{var a,r;a=t,r=Symbol("fast-defer"),a.deferred=function(){var e,t,a=new Promise((function(a,r){e=a,t=r}));return a.resolve=e,a.reject=t,a[r]=1,a},a.isDeferred=function(e){return!!e&&!!e[r]}}},t={};function a(r){var n=t[r];if(void 0!==n)return n.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,a),o.exports}a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";a.r(r),a.d(r,{Header:()=>o,buildKeyGenerator:()=>A,buildMemoryStorage:()=>x,buildStorage:()=>v,buildWebStorage:()=>j,canStale:()=>w,createCacheResponse:()=>f,createValidateStatus:()=>d,defaultHeaderInterpreter:()=>s,defaultKeyGenerator:()=>E,defaultRequestInterceptor:()=>g,defaultResponseInterceptor:()=>p,isExpired:()=>y,isMethodIn:()=>c,isStorage:()=>b,setupCache:()=>R,testCachePredicate:()=>h,updateCache:()=>l,updateStaleRequest:()=>u});var e=Symbol("cache-parser");function t(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function n(e){return"number"==typeof e||!0===e||"string"==typeof e&&"false"!==e}const o=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),s=a=>{if(!a)return"not enough headers";const r=a[o.CacheControl];if(r){const{noCache:s,noStore:i,mustRevalidate:d,maxAge:c,immutable:u}=function(a){var r=Object.defineProperty({},e,{enumerable:!1,value:1});if(!a||"string"!=typeof a)return r;var o=function(e){var t=e.toLowerCase().replace(/\s+/g,"").split(","),a={};for(var r in t){var n=t[r].split("=",2);a[n[0]]=1===n.length||n[1]}return a}(a);return n(o.immutable)&&(r.immutable=!0),t(o["max-age"])&&(r.maxAge=Number(o["max-age"])),t(o["max-stale"])&&(r.maxStale=Number(o["max-stale"])),t(o["min-fresh"])&&(r.minFresh=Number(o["min-fresh"])),n(o["must-revalidate"])&&(r.mustRevalidate=!0),n(o["must-understand"])&&(r.mustUnderstand=!0),n(o["no-cache"])&&(r.noCache=!0),n(o["no-store"])&&(r.noStore=!0),n(o["no-transform"])&&(r.noTransform=!0),n(o["only-if-cached"])&&(r.onlyIfCached=!0),n(o.private)&&(r.private=!0),n(o["proxy-revalidate"])&&(r.proxyRevalidate=!0),n(o.public)&&(r.public=!0),t(o["s-maxage"])&&(r.sMaxAge=Number(o["s-maxage"])),t(o["stale-if-error"])&&(r.staleIfError=Number(o["stale-if-error"])),t(o["stale-while-revalidate"])&&(r.staleWhileRevalidate=Number(o["stale-while-revalidate"])),r}(String(r));if(s||i)return"dont cache";if(u)return 31536e6;if(d)return 0;if(c){const e=a[o.Age];return e?1e3*(c-Number(e)):1e3*c}}const s=a[o.Expires];if(s){const e=Date.parse(String(s))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};var i=a(549);function d(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function c(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function u(e,t){t.headers||(t.headers={});const{etag:a,modifiedSince:r}=t.cache;if(a){const r=!0===a?e.data?.headers[o.ETag]:a;r&&(t.headers[o.IfNoneMatch]=r)}r&&(t.headers[o.IfModifiedSince]=!0===r?e.data.headers[o.LastModified]||new Date(e.createdAt).toUTCString():r.toUTCString())}function f(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers={...t.headers,...e.headers},t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function g(e){const t=async t=>{if(!1===t.cache)return e.debug?.({msg:"Ignoring cache because config.cache is false",data:t}),t;if(t.cache={...e.defaults.cache,...t.cache},!c(t.method,t.cache.methods))return e.debug?.({msg:`Ignored because method (${t.method}) is not in cache.methods (${t.cache.methods})`}),t;const a=t.id=e.generateKey(t);let r,n=await e.storage.get(a);e:if("empty"===n.state||"stale"===n.state){if(e.waiting[a]){n=await e.storage.get(a),e.debug?.({id:a,msg:"Waiting list had an deferred for this key, waiting for it to finish"});break e}return e.waiting[a]=(0,i.deferred)(),e.waiting[a]?.catch((()=>{})),await e.storage.set(a,{state:"loading",previous:n.state,data:n.data,createdAt:n.createdAt}),"stale"===n.state&&(u(n,t),e.debug?.({id:a,msg:"Updated stale request"})),t.validateStatus=d(t.validateStatus),e.debug?.({id:a,msg:"Sending request, waiting for response"}),t}if("loading"===n.state){const n=e.waiting[a];if(!n)return await e.storage.remove(a),t;e.debug?.({id:a,msg:"Detected concurrent request, waiting for it to finish"});try{r=await n}catch(r){return e.debug?.({id:a,msg:"Deferred rejected, requesting again",data:r}),t}}else r=n.data;return t.adapter=()=>Promise.resolve({config:t,data:r.data,headers:r.headers,status:r.status,statusText:r.statusText,cached:!0,id:a}),e.debug?.({id:a,msg:"Returning cached response"}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function h(e,t){if("function"==typeof t)return t(e);const{statusCheck:a,responseMatch:r,containsHeaders:n}=t;if(a&&!await a(e.status)||r&&!await r(e))return!1;if(n)for(const t in n){const a=n[t];if(a&&!await a(e.headers[t.toLowerCase()]??e.headers[t]))return!1}return!0}async function l(e,t,a){for(const r in a){const n=a[r];if("delete"===n){await e.remove(r);continue}const o=await e.get(r);if("loading"===o.state)continue;const s=await n(o,t);"delete"!==s?"ignore"!==s&&await e.set(r,s):await e.remove(r)}}function p(e){const t=async t=>{await e.storage.remove(t),e.waiting[t]?.reject(null),delete e.waiting[t]},a=async a=>{var r;if(a.id=(r=a.config).id??(r.id=e.generateKey(a.config)),a.cached??(a.cached=!1),a.cached)return e.debug?.({id:a.id,msg:"Returned cached response"}),a;if(!a.config.cache)return e.debug?.({id:a.id,msg:"Response with config.cache === false",data:a}),{...a,cached:!1};const n=a.config.cache,s=await e.storage.get(a.id);if("stale"===s.state||"empty"===s.state||"cached"===s.state)return e.debug?.({id:a.id,msg:"Response not cached but storage is not loading",data:{cache:s,response:a}}),a;if(!s.data&&!await h(a,n.cachePredicate))return await t(a.id),e.debug?.({id:a.id,msg:"Cache predicate rejected this response"}),a;for(const e in o)e.startsWith("XAxiosCache")&&delete a.headers[e];n.etag&&!0!==n.etag&&(a.headers[o.XAxiosCacheEtag]=n.etag),n.modifiedSince&&(a.headers[o.XAxiosCacheLastModified]=!0===n.modifiedSince?"use-cache-timestamp":n.modifiedSince.toUTCString());let i=n.ttl||-1;if(n?.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),e.debug?.({id:a.id,msg:"Cache header interpreted as 'dont cache'",data:{cache:s,response:a,expirationTime:r}}),a;i="not enough headers"===r?i:r}const d=f(a,s.data);"function"==typeof i&&(i=await i(a)),n.staleIfError&&(a.headers[o.XAxiosCacheStaleIfError]=String(i)),e.debug?.({id:a.id,msg:"Useful response configuration found",data:{cacheConfig:n,ttl:i,cacheResponse:d}}),n?.update&&await l(e.storage,a,n.update);const c={state:"cached",ttl:i,createdAt:Date.now(),data:d},u=e.waiting[a.id];return u&&(u.resolve(c.data),delete e.waiting[a.id],e.debug?.({id:a.id,msg:"Found waiting deferred(s) and resolved them"})),await e.storage.set(a.id,c),e.debug?.({id:a.id,msg:"Response cached",data:{cache:c,response:a}}),a},r=async a=>{const r=a.config;if(!r||!1===r.cache||!r.id)throw e.debug?.({msg:"Web request returned an error but cache handling is not enabled",data:{error:a,config:r}}),a;const n=await e.storage.get(r.id),o=r.cache;if("loading"!==n.state||"stale"!==n.previous)throw await t(r.id),e.debug?.({msg:"Caught an error in the request interceptor",data:{error:a,config:r}}),a;if(o?.staleIfError){const t="function"==typeof o.staleIfError?await o.staleIfError(a.response,n,a):o.staleIfError;if(e.debug?.({msg:"Found cache if stale config for rejected response",data:{error:a,config:r,staleIfError:t}}),!0===t||"number"==typeof t&&n.createdAt+t>Date.now())return e.waiting[r.id]?.resolve(n.data),delete e.waiting[r.id],await e.storage.set(r.id,{state:"stale",createdAt:Date.now(),data:n.data}),e.debug?.({msg:"staleIfError resolved this response with cached data",data:{error:a,config:r,cache:n}}),{cached:!0,config:r,id:r.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}}throw e.debug?.({msg:"Received an unknown error that could not be handled",data:{error:a,config:r}}),a};return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const m=Symbol(),b=e=>!!e&&!!e[m];function w(e){const t=e.data.headers;return o.ETag in t||o.LastModified in t||o.XAxiosCacheEtag in t||o.XAxiosCacheStaleIfError in t||o.XAxiosCacheLastModified in t}function y(e){return e.createdAt+e.ttl<=Date.now()}function v({set:e,find:t,remove:a}){return{[m]:1,set:e,remove:a,get:async r=>{const n=await t(r);if(!n)return{state:"empty"};if("cached"!==n.state||!y(n))return n;if(w(n)){const t={state:"stale",createdAt:n.createdAt,data:n.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function x(){const e=v({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}function S(e){const t=typeof e;if(e&&"object"===t&&!(e instanceof Date||e instanceof RegExp)){const t=Array.isArray(e)?[]:{};for(const a in e)t[a]=S(e[a]);return`${e.constructor}${JSON.stringify(t,Object.keys(e).sort())}`}return`${t}${String(e)}`}function I(e){e=S(e);let t=5381;for(let a=0;a<e.length;a++)t=33*t^e.charCodeAt(a);return t>>>0}const C=/^\/|\/$/g;function A(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(C,"")),a.url&&(a.url=a.url.replace(C,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?I(r).toString():r}}const E=A(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:n})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:n})));function R(e,t={}){const a=e;if(a.storage=t.storage||x(),!b(a.storage))throw new Error("Use buildStorage() function");return a.generateKey=t.generateKey||E,a.waiting=t.waiting||{},a.headerInterpreter=t.headerInterpreter||s,a.requestInterceptor=t.requestInterceptor||g(a),a.responseInterceptor=t.responseInterceptor||p(a),a.debug=t.debug,a.defaults.cache={ttl:t.ttl??3e5,interpretHeader:t.interpretHeader??!1,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:t.etag??!1,modifiedSince:t.modifiedSince??!1,staleIfError:t.staleIfError??!1,update:t.update||{}},a.requestInterceptor.apply(),a.responseInterceptor.apply(),a}function j(e,t=""){return v({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const n=()=>e.setItem(t+a,JSON.stringify(r));try{return n()}catch(r){const o=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of o)"cached"===a.state&&y(a)&&!w(a)&&e.removeItem(t);try{return n()}catch(t){const a=o.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return n()}catch(e){}}}e.removeItem(t+a)}}})}console.error("You are using a development build. Make sure to use the correct build in production"),console.error("https://axios-cache-interceptor.js.org/#/pages/installing")})(),r})()})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Header:()=>s,buildKeyGenerator:()=>E,buildMemoryStorage:()=>I,buildStorage:()=>S,buildWebStorage:()=>T,canStale:()=>y,createCacheResponse:()=>g,createValidateStatus:()=>d,defaultHeaderInterpreter:()=>i,defaultKeyGenerator:()=>R,defaultRequestInterceptor:()=>h,defaultResponseInterceptor:()=>m,isExpired:()=>x,isMethodIn:()=>u,isStorage:()=>w,setupCache:()=>j,testCachePredicate:()=>l,updateCache:()=>p,updateStaleRequest:()=>f});const a=Symbol("cache-parser");function r(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function n(e){return!0===e||"number"==typeof e||"string"==typeof e&&"false"!==e}const o=Number;const s=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",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=e=>{if(!e)return"not enough headers";const t=e[s.CacheControl];if(t){const{noCache:i,noStore:c,mustRevalidate:d,maxAge:u,immutable:f}=function(e){const t=Object.defineProperty({},a,{enumerable:!1,value:1});if(!e||"string"!=typeof e)return t;const s=function(e){const t={},a=e.toLowerCase().replace(/\s+/g,"").split(",");for(const e in a){var r;const n=a[e].split("=",2);t[n[0]]=null==(r=n[1])||r}return t}(e),i=s["max-age"],c=s["max-stale"],d=s["min-fresh"],u=s["s-maxage"],f=s["stale-if-error"],g=s["stale-while-revalidate"];return n(s.immutable)&&(t.immutable=!0),r(i)&&(t.maxAge=o(i)),r(c)&&(t.maxStale=o(c)),r(d)&&(t.minFresh=o(d)),n(s["must-revalidate"])&&(t.mustRevalidate=!0),n(s["must-understand"])&&(t.mustUnderstand=!0),n(s["no-cache"])&&(t.noCache=!0),n(s["no-store"])&&(t.noStore=!0),n(s["no-transform"])&&(t.noTransform=!0),n(s["only-if-cached"])&&(t.onlyIfCached=!0),n(s.private)&&(t.private=!0),n(s["proxy-revalidate"])&&(t.proxyRevalidate=!0),n(s.public)&&(t.public=!0),r(u)&&(t.sMaxAge=o(u)),r(f)&&(t.staleIfError=o(f)),r(g)&&(t.staleWhileRevalidate=o(g)),t}(String(t));if(i||c)return"dont cache";if(f)return 31536e6;if(d)return 0;if(u){const t=e[s.Age];return t?1e3*(u-Number(t)):1e3*u}}const i=e[s.Expires];if(i){const e=Date.parse(String(i))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"},c=Symbol();function d(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function u(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function f(e,t){t.headers||(t.headers={});const{etag:a,modifiedSince:r}=t.cache;if(a){const r=!0===a?e.data?.headers[s.ETag]:a;r&&(t.headers[s.IfNoneMatch]=r)}r&&(t.headers[s.IfModifiedSince]=!0===r?e.data.headers[s.LastModified]||new Date(e.createdAt).toUTCString():r.toUTCString())}function g(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers={...t.headers,...e.headers},t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function h(e){const t=async t=>{if(!1===t.cache)return e.debug?.({msg:"Ignoring cache because config.cache is false",data:t}),t;if(t.cache={...e.defaults.cache,...t.cache},!u(t.method,t.cache.methods))return e.debug?.({msg:`Ignored because method (${t.method}) is not in cache.methods (${t.cache.methods})`}),t;const a=t.id=e.generateKey(t);let r,n=await e.storage.get(a);e:if("empty"===n.state||"stale"===n.state){if(e.waiting[a]){n=await e.storage.get(a),e.debug?.({id:a,msg:"Waiting list had an deferred for this key, waiting for it to finish"});break e}return e.waiting[a]=function(){let e,t;const a=new Promise(((a,r)=>{e=a,t=r}));return a.resolve=e,a.reject=t,a[c]=1,a}(),e.waiting[a]?.catch((()=>{})),await e.storage.set(a,{state:"loading",previous:n.state,data:n.data,createdAt:n.createdAt}),"stale"===n.state&&(f(n,t),e.debug?.({id:a,msg:"Updated stale request"})),t.validateStatus=d(t.validateStatus),e.debug?.({id:a,msg:"Sending request, waiting for response"}),t}if("loading"===n.state){const n=e.waiting[a];if(!n)return await e.storage.remove(a),t;e.debug?.({id:a,msg:"Detected concurrent request, waiting for it to finish"});try{r=await n}catch(r){return e.debug?.({id:a,msg:"Deferred rejected, requesting again",data:r}),t}}else r=n.data;return t.adapter=()=>Promise.resolve({config:t,data:r.data,headers:r.headers,status:r.status,statusText:r.statusText,cached:!0,id:a}),e.debug?.({id:a,msg:"Returning cached response"}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function l(e,t){if("function"==typeof t)return t(e);const{statusCheck:a,responseMatch:r,containsHeaders:n}=t;if(a&&!await a(e.status)||r&&!await r(e))return!1;if(n)for(const t in n){const a=n[t];if(a&&!await a(e.headers[t.toLowerCase()]??e.headers[t]))return!1}return!0}async function p(e,t,a){for(const r in a){const n=a[r];if("delete"===n){await e.remove(r);continue}const o=await e.get(r);if("loading"===o.state)continue;const s=await n(o,t);"delete"!==s?"ignore"!==s&&await e.set(r,s):await e.remove(r)}}function m(e){const t=async t=>{await e.storage.remove(t),e.waiting[t]?.reject(null),delete e.waiting[t]},a=async a=>{var r;if(a.id=(r=a.config).id??(r.id=e.generateKey(a.config)),a.cached??(a.cached=!1),a.cached)return e.debug?.({id:a.id,msg:"Returned cached response"}),a;if(!a.config.cache)return e.debug?.({id:a.id,msg:"Response with config.cache === false",data:a}),{...a,cached:!1};const n=a.config.cache,o=await e.storage.get(a.id);if("stale"===o.state||"empty"===o.state||"cached"===o.state)return e.debug?.({id:a.id,msg:"Response not cached but storage is not loading",data:{cache:o,response:a}}),a;if(!o.data&&!await l(a,n.cachePredicate))return await t(a.id),e.debug?.({id:a.id,msg:"Cache predicate rejected this response"}),a;for(const e in s)e.startsWith("XAxiosCache")&&delete a.headers[e];n.etag&&!0!==n.etag&&(a.headers[s.XAxiosCacheEtag]=n.etag),n.modifiedSince&&(a.headers[s.XAxiosCacheLastModified]=!0===n.modifiedSince?"use-cache-timestamp":n.modifiedSince.toUTCString());let i=n.ttl||-1;if(n?.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),e.debug?.({id:a.id,msg:"Cache header interpreted as 'dont cache'",data:{cache:o,response:a,expirationTime:r}}),a;i="not enough headers"===r?i:r}const c=g(a,o.data);"function"==typeof i&&(i=await i(a)),n.staleIfError&&(a.headers[s.XAxiosCacheStaleIfError]=String(i)),e.debug?.({id:a.id,msg:"Useful response configuration found",data:{cacheConfig:n,ttl:i,cacheResponse:c}}),n?.update&&await p(e.storage,a,n.update);const d={state:"cached",ttl:i,createdAt:Date.now(),data:c},u=e.waiting[a.id];return u&&(u.resolve(d.data),delete e.waiting[a.id],e.debug?.({id:a.id,msg:"Found waiting deferred(s) and resolved them"})),await e.storage.set(a.id,d),e.debug?.({id:a.id,msg:"Response cached",data:{cache:d,response:a}}),a},r=async a=>{const r=a.config;if(!r||!1===r.cache||!r.id)throw e.debug?.({msg:"Web request returned an error but cache handling is not enabled",data:{error:a,config:r}}),a;const n=await e.storage.get(r.id),o=r.cache;if("loading"!==n.state||"stale"!==n.previous)throw await t(r.id),e.debug?.({msg:"Caught an error in the request interceptor",data:{error:a,config:r}}),a;if(o?.staleIfError){const t="function"==typeof o.staleIfError?await o.staleIfError(a.response,n,a):o.staleIfError;if(e.debug?.({msg:"Found cache if stale config for rejected response",data:{error:a,config:r,staleIfError:t}}),!0===t||"number"==typeof t&&n.createdAt+t>Date.now())return e.waiting[r.id]?.resolve(n.data),delete e.waiting[r.id],await e.storage.set(r.id,{state:"stale",createdAt:Date.now(),data:n.data}),e.debug?.({msg:"staleIfError resolved this response with cached data",data:{error:a,config:r,cache:n}}),{cached:!0,config:r,id:r.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}}throw e.debug?.({msg:"Received an unknown error that could not be handled",data:{error:a,config:r}}),a};return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const b=Symbol(),w=e=>!!e&&!!e[b];function y(e){const t=e.data.headers;return s.ETag in t||s.LastModified in t||s.XAxiosCacheEtag in t||s.XAxiosCacheStaleIfError in t||s.XAxiosCacheLastModified in t}function x(e){return e.createdAt+e.ttl<=Date.now()}function S({set:e,find:t,remove:a}){return{[b]:1,set:e,remove:a,get:async r=>{const n=await t(r);if(!n)return{state:"empty"};if("cached"!==n.state||!x(n))return n;if(y(n)){const t={state:"stale",createdAt:n.createdAt,data:n.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function I(){const e=S({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}function v(e){const t=typeof e;if(e&&"object"==t&&!(e instanceof Date||e instanceof RegExp)){const t=Array.isArray(e)?[]:{};for(const a in e)t[a]=v(e[a]);return`${e.constructor}${JSON.stringify(t,Object.keys(e).sort())}`}return`${t}${String(e)}`}function C(e){e=v(e);let t=5381,a=0;for(;a<e.length;)t=33*t^e.charCodeAt(a++);return t}const A=/^\/|\/$/g;function E(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(A,"")),a.url&&(a.url=a.url.replace(A,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?`${C(r)}`:r}}const R=E(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:n})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:n})));function j(e,t={}){const a=e;if(a.storage=t.storage||I(),!w(a.storage))throw new Error("Use buildStorage() function");return a.generateKey=t.generateKey||R,a.waiting=t.waiting||{},a.headerInterpreter=t.headerInterpreter||i,a.requestInterceptor=t.requestInterceptor||h(a),a.responseInterceptor=t.responseInterceptor||m(a),a.debug=t.debug,a.defaults.cache={ttl:t.ttl??3e5,interpretHeader:t.interpretHeader??!1,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:t.etag??!1,modifiedSince:t.modifiedSince??!1,staleIfError:t.staleIfError??!1,update:t.update||{}},a.requestInterceptor.apply(),a.responseInterceptor.apply(),a}function T(e,t=""){return S({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const n=()=>e.setItem(t+a,JSON.stringify(r));try{return n()}catch(r){const o=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of o)"cached"===a.state&&x(a)&&!y(a)&&e.removeItem(t);try{return n()}catch(t){const a=o.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return n()}catch(e){}}}e.removeItem(t+a)}}})}return console.error("You are using a development build. Make sure to use the correct build in production"),console.error("https://axios-cache-interceptor.js.org/#/pages/installing"),t})()})); | ||
//# sourceMappingURL=dev.map |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return function(){var e={549:function(e,t){var r,n;r=t,n=Symbol("fast-defer"),r.deferred=function(){var e,t,r=new Promise((function(r,n){e=r,t=n}));return r.resolve=e,r.reject=t,r[n]=1,r},r.isDeferred=function(e){return!!e&&!!e[n]}}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return function(){"use strict";r.r(n),r.d(n,{Header:function(){return o},buildKeyGenerator:function(){return O},buildMemoryStorage:function(){return C},buildStorage:function(){return I},buildWebStorage:function(){return L},canStale:function(){return w},createCacheResponse:function(){return v},createValidateStatus:function(){return f},defaultHeaderInterpreter:function(){return i},defaultKeyGenerator:function(){return T},defaultRequestInterceptor:function(){return p},defaultResponseInterceptor:function(){return b},isExpired:function(){return S},isMethodIn:function(){return l},isStorage:function(){return x},setupCache:function(){return M},testCachePredicate:function(){return g},updateCache:function(){return m},updateStaleRequest:function(){return h}});var e=Symbol("cache-parser");function t(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function a(e){return"number"==typeof e||!0===e||"string"==typeof e&&"false"!==e}var o=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",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(r){if(!r)return"not enough headers";var n=r[o.CacheControl];if(n){var i=function(r){var n=Object.defineProperty({},e,{enumerable:!1,value:1});if(!r||"string"!=typeof r)return n;var o=function(e){var t=e.toLowerCase().replace(/\s+/g,"").split(","),r={};for(var n in t){var a=t[n].split("=",2);r[a[0]]=1===a.length||a[1]}return r}(r);return a(o.immutable)&&(n.immutable=!0),t(o["max-age"])&&(n.maxAge=Number(o["max-age"])),t(o["max-stale"])&&(n.maxStale=Number(o["max-stale"])),t(o["min-fresh"])&&(n.minFresh=Number(o["min-fresh"])),a(o["must-revalidate"])&&(n.mustRevalidate=!0),a(o["must-understand"])&&(n.mustUnderstand=!0),a(o["no-cache"])&&(n.noCache=!0),a(o["no-store"])&&(n.noStore=!0),a(o["no-transform"])&&(n.noTransform=!0),a(o["only-if-cached"])&&(n.onlyIfCached=!0),a(o.private)&&(n.private=!0),a(o["proxy-revalidate"])&&(n.proxyRevalidate=!0),a(o.public)&&(n.public=!0),t(o["s-maxage"])&&(n.sMaxAge=Number(o["s-maxage"])),t(o["stale-if-error"])&&(n.staleIfError=Number(o["stale-if-error"])),t(o["stale-while-revalidate"])&&(n.staleWhileRevalidate=Number(o["stale-while-revalidate"])),n}(String(n)),s=i.noCache,c=i.noStore,u=i.mustRevalidate,d=i.maxAge,f=i.immutable;if(s||c)return"dont cache";if(f)return 31536e6;if(u)return 0;if(d){var l=r[o.Age];return l?1e3*(d-Number(l)):1e3*d}}var h=r[o.Expires];if(h){var v=Date.parse(String(h))-Date.now();return v>=0?v:"dont cache"}return"not enough headers"};var s=function(){return s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},s.apply(this,arguments)};function c(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}c((n=n.apply(e,t||[])).next())}))}function u(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}Object.create;Object.create;var d=r(549);function f(e){return e?function(t){return e(t)||304===t}:function(e){return e>=200&&e<300||304===e}}function l(e,t){void 0===e&&(e="get"),void 0===t&&(t=[]),e=e.toLowerCase();for(var r=0,n=t;r<n.length;r++){if(n[r].toLowerCase()===e)return!0}return!1}function h(e,t){var r;t.headers||(t.headers={});var n=t.cache,a=n.etag,i=n.modifiedSince;if(a){var s=!0===a?null===(r=e.data)||void 0===r?void 0:r.headers[o.ETag]:a;s&&(t.headers[o.IfNoneMatch]=s)}i&&(t.headers[o.IfModifiedSince]=!0===i?e.data.headers[o.LastModified]||new Date(e.createdAt).toUTCString():i.toUTCString())}function v(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=s(s({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function p(e){var t=this,r=function(r){return c(t,void 0,void 0,(function(){var t,n,a,o,i;return u(this,(function(c){switch(c.label){case 0:return!1===r.cache?[2,r]:(r.cache=s(s({},e.defaults.cache),r.cache),l(r.method,r.cache.methods)?(t=r.id=e.generateKey(r),[4,e.storage.get(t)]):[2,r]);case 1:return"empty"!==(n=c.sent()).state&&"stale"!==n.state?[3,5]:e.waiting[t]?[4,e.storage.get(t)]:[3,3];case 2:return n=c.sent(),[3,5];case 3:return e.waiting[t]=(0,d.deferred)(),null===(i=e.waiting[t])||void 0===i||i.catch((function(){})),[4,e.storage.set(t,{state:"loading",previous:n.state,data:n.data,createdAt:n.createdAt})];case 4:return c.sent(),"stale"===n.state&&h(n,r),r.validateStatus=f(r.validateStatus),[2,r];case 5:return"loading"!==n.state?[3,12]:(o=e.waiting[t])?[3,7]:[4,e.storage.remove(t)];case 6:return c.sent(),[2,r];case 7:0,c.label=8;case 8:return c.trys.push([8,10,,11]),[4,o];case 9:return a=c.sent(),[3,11];case 10:return c.sent(),[2,r];case 11:return[3,13];case 12:a=n.data,c.label=13;case 13:return r.adapter=function(){return Promise.resolve({config:r,data:a.data,headers:a.headers,status:a.status,statusText:a.statusText,cached:!0,id:t})},[2,r]}}))}))};return{onFulfilled:r,apply:function(){return e.interceptors.request.use(r)}}}function g(e,t){var r;return c(this,void 0,void 0,(function(){var n,a,o,i,s,c,d,f,l,h,v,p;return u(this,(function(u){switch(u.label){case 0:return"function"==typeof t?[2,t(e)]:(n=t.statusCheck,a=t.responseMatch,o=t.containsHeaders,(s=n)?[4,n(e.status)]:[3,2]);case 1:s=!u.sent(),u.label=2;case 2:return(i=s)?[3,5]:(c=a)?[4,a(e)]:[3,4];case 3:c=!u.sent(),u.label=4;case 4:i=c,u.label=5;case 5:if(i)return[2,!1];if(!o)return[3,10];for(f in d=[],o)d.push(f);l=0,u.label=6;case 6:return l<d.length?(h=d[l],v=o[h],(p=v)?[4,v(null!==(r=e.headers[h.toLowerCase()])&&void 0!==r?r:e.headers[h])]:[3,8]):[3,10];case 7:p=!u.sent(),u.label=8;case 8:if(p)return[2,!1];u.label=9;case 9:return l++,[3,6];case 10:return[2,!0]}}))}))}function m(e,t,r){return c(this,void 0,void 0,(function(){var n,a,o,i,s,c,d;return u(this,(function(u){switch(u.label){case 0:for(a in n=[],r)n.push(a);o=0,u.label=1;case 1:return o<n.length?(i=n[o],"delete"!==(s=r[i])?[3,3]:[4,e.remove(i)]):[3,10];case 2:return u.sent(),[3,9];case 3:return[4,e.get(i)];case 4:return"loading"===(c=u.sent()).state?[3,9]:[4,s(c,t)];case 5:return"delete"!==(d=u.sent())?[3,7]:[4,e.remove(i)];case 6:return u.sent(),[3,9];case 7:return"ignore"===d?[3,9]:[4,e.set(i,d)];case 8:u.sent(),u.label=9;case 9:return o++,[3,1];case 10:return[2]}}))}))}function b(e){var t=this,r=function(r){return c(t,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return[4,e.storage.remove(r)];case 1:return n.sent(),null===(t=e.waiting[r])||void 0===t||t.reject(null),delete e.waiting[r],[2]}}))}))},n=function(n){return c(t,void 0,void 0,(function(){var t,a,i,c,d,f,l,h,p,b,y,x;return u(this,(function(u){switch(u.label){case 0:return n.id=null!==(b=(x=n.config).id)&&void 0!==b?b:x.id=e.generateKey(n.config),null!==(y=n.cached)&&void 0!==y||(n.cached=!1),n.cached?[2,n]:n.config.cache?(t=n.config.cache,[4,e.storage.get(n.id)]):[2,s(s({},n),{cached:!1})];case 1:return"stale"===(a=u.sent()).state||"empty"===a.state||"cached"===a.state?[2,n]:(i=!a.data)?[4,g(n,t.cachePredicate)]:[3,3];case 2:i=!u.sent(),u.label=3;case 3:return i?[4,r(n.id)]:[3,5];case 4:return u.sent(),[2,n];case 5:for(c in o)c.startsWith("XAxiosCache")&&delete n.headers[c];return t.etag&&!0!==t.etag&&(n.headers[o.XAxiosCacheEtag]=t.etag),t.modifiedSince&&(n.headers[o.XAxiosCacheLastModified]=!0===t.modifiedSince?"use-cache-timestamp":t.modifiedSince.toUTCString()),d=t.ttl||-1,(null==t?void 0:t.interpretHeader)?"dont cache"!==(f=e.headerInterpreter(n.headers))?[3,7]:[4,r(n.id)]:[3,8];case 6:return u.sent(),[2,n];case 7:d="not enough headers"===f?d:f,u.label=8;case 8:return l=v(n,a.data),"function"!=typeof d?[3,10]:[4,d(n)];case 9:d=u.sent(),u.label=10;case 10:return t.staleIfError&&(n.headers[o.XAxiosCacheStaleIfError]=String(d)),(null==t?void 0:t.update)?[4,m(e.storage,n,t.update)]:[3,12];case 11:u.sent(),u.label=12;case 12:return h={state:"cached",ttl:d,createdAt:Date.now(),data:l},(p=e.waiting[n.id])&&(p.resolve(h.data),delete e.waiting[n.id]),[4,e.storage.set(n.id,h)];case 13:return u.sent(),[2,n]}}))}))},a=function(n){return c(t,void 0,void 0,(function(){var t,a,o,i,s,c;return u(this,(function(u){switch(u.label){case 0:if(!(t=n.config)||!1===t.cache||!t.id)throw n;return[4,e.storage.get(t.id)];case 1:return a=u.sent(),o=t.cache,"loading"===a.state&&"stale"===a.previous?[3,3]:[4,r(t.id)];case 2:throw u.sent(),n;case 3:return(null==o?void 0:o.staleIfError)?"function"!=typeof o.staleIfError?[3,5]:[4,o.staleIfError(n.response,a,n)]:[3,8];case 4:return s=u.sent(),[3,6];case 5:s=o.staleIfError,u.label=6;case 6:return!0===(i=s)||"number"==typeof i&&a.createdAt+i>Date.now()?(null===(c=e.waiting[t.id])||void 0===c||c.resolve(a.data),delete e.waiting[t.id],[4,e.storage.set(t.id,{state:"stale",createdAt:Date.now(),data:a.data})]):[3,8];case 7:return u.sent(),[2,{cached:!0,config:t,id:t.id,data:a.data.data,headers:a.data.headers,status:a.data.status,statusText:a.data.statusText}];case 8:throw n}}))}))};return{onFulfilled:n,onRejected:a,apply:function(){return e.interceptors.response.use(n,a)}}}var y=Symbol(),x=function(e){return!!e&&!!e[y]};function w(e){var t=e.data.headers;return o.ETag in t||o.LastModified in t||o.XAxiosCacheEtag in t||o.XAxiosCacheStaleIfError in t||o.XAxiosCacheLastModified in t}function S(e){return e.createdAt+e.ttl<=Date.now()}function I(e){var t,r=this,n=e.set,a=e.find,o=e.remove;return(t={})[y]=1,t.set=n,t.remove=o,t.get=function(e){return c(r,void 0,void 0,(function(){var t,r;return u(this,(function(i){switch(i.label){case 0:return[4,a(e)];case 1:return(t=i.sent())?"cached"===t.state&&S(t)?w(t)?(r={state:"stale",createdAt:t.createdAt,data:t.data},[4,n(e,r)]):[3,3]:[2,t]:[2,{state:"empty"}];case 2:return i.sent(),[2,r];case 3:return[4,o(e)];case 4:return i.sent(),[2,{state:"empty"}]}}))}))},t}function C(){var e=I({find:function(t){return e.data[t]},set:function(t,r){e.data[t]=r},remove:function(t){delete e.data[t]}});return e.data=Object.create(null),e}function A(e){const t=typeof e;if(e&&"object"===t&&!(e instanceof Date||e instanceof RegExp)){const t=Array.isArray(e)?[]:{};for(const r in e)t[r]=A(e[r]);return`${e.constructor}${JSON.stringify(t,Object.keys(e).sort())}`}return`${t}${String(e)}`}function E(e){e=A(e);let t=5381;for(let r=0;r<e.length;r++)t=33*t^e.charCodeAt(r);return t>>>0}var j=/^\/|\/$/g;function O(e,t){return function(r){if(r.id)return r.id;r.baseURL&&(r.baseURL=r.baseURL.replace(j,"")),r.url&&(r.url=r.url.replace(j,"")),r.method&&(r.method=r.method.toLowerCase());var n=t(r);return e?E(n).toString():n}}var T=O(!0,(function(e){var t=e.baseURL,r=void 0===t?"":t,n=e.url,a=void 0===n?"":n,o=e.method;return{url:r+(r&&a?"/":"")+a,method:void 0===o?"get":o,params:e.params,data:e.data}}));function M(e,t){var r,n,a,o,s;void 0===t&&(t={});var c=e;if(c.storage=t.storage||C(),!x(c.storage))throw new Error("Use buildStorage() function");return c.generateKey=t.generateKey||T,c.waiting=t.waiting||{},c.headerInterpreter=t.headerInterpreter||i,c.requestInterceptor=t.requestInterceptor||p(c),c.responseInterceptor=t.responseInterceptor||b(c),c.debug=t.debug,c.defaults.cache={ttl:null!==(r=t.ttl)&&void 0!==r?r:3e5,interpretHeader:null!==(n=t.interpretHeader)&&void 0!==n&&n,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:function(e){return e>=200&&e<400}},etag:null!==(a=t.etag)&&void 0!==a&&a,modifiedSince:null!==(o=t.modifiedSince)&&void 0!==o&&o,staleIfError:null!==(s=t.staleIfError)&&void 0!==s&&s,update:t.update||{}},c.requestInterceptor.apply(),c.responseInterceptor.apply(),c}function L(e,t){return void 0===t&&(t=""),I({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=Object.entries(e).filter((function(r){var n=r[0];return n.startsWith(t)&&e.getItem(n)})).map((function(e){var t=e[0],r=e[1];return[t,JSON.parse(r)]})),i=0,s=o;i<s.length;i++){var c=s[i],u=c[0],d=c[1];"cached"===d.state&&S(d)&&!w(d)&&e.removeItem(u)}try{return a()}catch(t){for(var f=o.sort((function(e,t){var r=e[1],n=t[1];return(r.createdAt||0)-(n.createdAt||0)})),l=0,h=f;l<h.length;l++){u=h[l][0];e.removeItem(u);try{return a()}catch(e){}}}e.removeItem(t+r)}}})}}(),n}()})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return function(){"use strict";var e={d:function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Header:function(){return i},buildKeyGenerator:function(){return T},buildMemoryStorage:function(){return A},buildStorage:function(){return C},buildWebStorage:function(){return R},canStale:function(){return S},createCacheResponse:function(){return v},createValidateStatus:function(){return f},defaultHeaderInterpreter:function(){return s},defaultKeyGenerator:function(){return M},defaultRequestInterceptor:function(){return g},defaultResponseInterceptor:function(){return y},isExpired:function(){return I},isMethodIn:function(){return h},isStorage:function(){return x},setupCache:function(){return L},testCachePredicate:function(){return m},updateCache:function(){return b},updateStaleRequest:function(){return p}});const r=Symbol("cache-parser");function n(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function a(e){return!0===e||"number"==typeof e||"string"==typeof e&&"false"!==e}const o=Number;var i=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),s=function(e){if(!e)return"not enough headers";var t=e[i.CacheControl];if(t){var s=function(e){const t=Object.defineProperty({},r,{enumerable:!1,value:1});if(!e||"string"!=typeof e)return t;const i=function(e){const t={},r=e.toLowerCase().replace(/\s+/g,"").split(",");for(const e in r){var n;const a=r[e].split("=",2);t[a[0]]=null==(n=a[1])||n}return t}(e),s=i["max-age"],c=i["max-stale"],u=i["min-fresh"],d=i["s-maxage"],l=i["stale-if-error"],f=i["stale-while-revalidate"];return a(i.immutable)&&(t.immutable=!0),n(s)&&(t.maxAge=o(s)),n(c)&&(t.maxStale=o(c)),n(u)&&(t.minFresh=o(u)),a(i["must-revalidate"])&&(t.mustRevalidate=!0),a(i["must-understand"])&&(t.mustUnderstand=!0),a(i["no-cache"])&&(t.noCache=!0),a(i["no-store"])&&(t.noStore=!0),a(i["no-transform"])&&(t.noTransform=!0),a(i["only-if-cached"])&&(t.onlyIfCached=!0),a(i.private)&&(t.private=!0),a(i["proxy-revalidate"])&&(t.proxyRevalidate=!0),a(i.public)&&(t.public=!0),n(d)&&(t.sMaxAge=o(d)),n(l)&&(t.staleIfError=o(l)),n(f)&&(t.staleWhileRevalidate=o(f)),t}(String(t)),c=s.noCache,u=s.noStore,d=s.mustRevalidate,l=s.maxAge,f=s.immutable;if(c||u)return"dont cache";if(f)return 31536e6;if(d)return 0;if(l){var h=e[i.Age];return h?1e3*(l-Number(h)):1e3*l}}var p=e[i.Expires];if(p){var v=Date.parse(String(p))-Date.now();return v>=0?v:"dont cache"}return"not enough headers"};var c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},c.apply(this,arguments)};function u(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}c((n=n.apply(e,t||[])).next())}))}function d(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}Object.create;Object.create;const l=Symbol();function f(e){return e?function(t){return e(t)||304===t}:function(e){return e>=200&&e<300||304===e}}function h(e,t){void 0===e&&(e="get"),void 0===t&&(t=[]),e=e.toLowerCase();for(var r=0,n=t;r<n.length;r++){if(n[r].toLowerCase()===e)return!0}return!1}function p(e,t){var r;t.headers||(t.headers={});var n=t.cache,a=n.etag,o=n.modifiedSince;if(a){var s=!0===a?null===(r=e.data)||void 0===r?void 0:r.headers[i.ETag]:a;s&&(t.headers[i.IfNoneMatch]=s)}o&&(t.headers[i.IfModifiedSince]=!0===o?e.data.headers[i.LastModified]||new Date(e.createdAt).toUTCString():o.toUTCString())}function v(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=c(c({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function g(e){var t=this,r=function(r){return u(t,void 0,void 0,(function(){var t,n,a,o,i;return d(this,(function(s){switch(s.label){case 0:return!1===r.cache?[2,r]:(r.cache=c(c({},e.defaults.cache),r.cache),h(r.method,r.cache.methods)?(t=r.id=e.generateKey(r),[4,e.storage.get(t)]):[2,r]);case 1:return"empty"!==(n=s.sent()).state&&"stale"!==n.state?[3,5]:e.waiting[t]?[4,e.storage.get(t)]:[3,3];case 2:return n=s.sent(),[3,5];case 3:return e.waiting[t]=function(){let e,t;const r=new Promise(((r,n)=>{e=r,t=n}));return r.resolve=e,r.reject=t,r[l]=1,r}(),null===(i=e.waiting[t])||void 0===i||i.catch((function(){})),[4,e.storage.set(t,{state:"loading",previous:n.state,data:n.data,createdAt:n.createdAt})];case 4:return s.sent(),"stale"===n.state&&p(n,r),r.validateStatus=f(r.validateStatus),[2,r];case 5:return"loading"!==n.state?[3,12]:(o=e.waiting[t])?[3,7]:[4,e.storage.remove(t)];case 6:return s.sent(),[2,r];case 7:0,s.label=8;case 8:return s.trys.push([8,10,,11]),[4,o];case 9:return a=s.sent(),[3,11];case 10:return s.sent(),[2,r];case 11:return[3,13];case 12:a=n.data,s.label=13;case 13:return r.adapter=function(){return Promise.resolve({config:r,data:a.data,headers:a.headers,status:a.status,statusText:a.statusText,cached:!0,id:t})},[2,r]}}))}))};return{onFulfilled:r,apply:function(){return e.interceptors.request.use(r)}}}function m(e,t){var r;return u(this,void 0,void 0,(function(){var n,a,o,i,s,c,u,l,f,h,p,v;return d(this,(function(d){switch(d.label){case 0:return"function"==typeof t?[2,t(e)]:(n=t.statusCheck,a=t.responseMatch,o=t.containsHeaders,(s=n)?[4,n(e.status)]:[3,2]);case 1:s=!d.sent(),d.label=2;case 2:return(i=s)?[3,5]:(c=a)?[4,a(e)]:[3,4];case 3:c=!d.sent(),d.label=4;case 4:i=c,d.label=5;case 5:if(i)return[2,!1];if(!o)return[3,10];for(l in u=[],o)u.push(l);f=0,d.label=6;case 6:return f<u.length?(h=u[f],p=o[h],(v=p)?[4,p(null!==(r=e.headers[h.toLowerCase()])&&void 0!==r?r:e.headers[h])]:[3,8]):[3,10];case 7:v=!d.sent(),d.label=8;case 8:if(v)return[2,!1];d.label=9;case 9:return f++,[3,6];case 10:return[2,!0]}}))}))}function b(e,t,r){return u(this,void 0,void 0,(function(){var n,a,o,i,s,c,u;return d(this,(function(d){switch(d.label){case 0:for(a in n=[],r)n.push(a);o=0,d.label=1;case 1:return o<n.length?(i=n[o],"delete"!==(s=r[i])?[3,3]:[4,e.remove(i)]):[3,10];case 2:return d.sent(),[3,9];case 3:return[4,e.get(i)];case 4:return"loading"===(c=d.sent()).state?[3,9]:[4,s(c,t)];case 5:return"delete"!==(u=d.sent())?[3,7]:[4,e.remove(i)];case 6:return d.sent(),[3,9];case 7:return"ignore"===u?[3,9]:[4,e.set(i,u)];case 8:d.sent(),d.label=9;case 9:return o++,[3,1];case 10:return[2]}}))}))}function y(e){var t=this,r=function(r){return u(t,void 0,void 0,(function(){var t;return d(this,(function(n){switch(n.label){case 0:return[4,e.storage.remove(r)];case 1:return n.sent(),null===(t=e.waiting[r])||void 0===t||t.reject(null),delete e.waiting[r],[2]}}))}))},n=function(n){return u(t,void 0,void 0,(function(){var t,a,o,s,u,l,f,h,p,g,y,w;return d(this,(function(d){switch(d.label){case 0:return n.id=null!==(g=(w=n.config).id)&&void 0!==g?g:w.id=e.generateKey(n.config),null!==(y=n.cached)&&void 0!==y||(n.cached=!1),n.cached?[2,n]:n.config.cache?(t=n.config.cache,[4,e.storage.get(n.id)]):[2,c(c({},n),{cached:!1})];case 1:return"stale"===(a=d.sent()).state||"empty"===a.state||"cached"===a.state?[2,n]:(o=!a.data)?[4,m(n,t.cachePredicate)]:[3,3];case 2:o=!d.sent(),d.label=3;case 3:return o?[4,r(n.id)]:[3,5];case 4:return d.sent(),[2,n];case 5:for(s in i)s.startsWith("XAxiosCache")&&delete n.headers[s];return t.etag&&!0!==t.etag&&(n.headers[i.XAxiosCacheEtag]=t.etag),t.modifiedSince&&(n.headers[i.XAxiosCacheLastModified]=!0===t.modifiedSince?"use-cache-timestamp":t.modifiedSince.toUTCString()),u=t.ttl||-1,(null==t?void 0:t.interpretHeader)?"dont cache"!==(l=e.headerInterpreter(n.headers))?[3,7]:[4,r(n.id)]:[3,8];case 6:return d.sent(),[2,n];case 7:u="not enough headers"===l?u:l,d.label=8;case 8:return f=v(n,a.data),"function"!=typeof u?[3,10]:[4,u(n)];case 9:u=d.sent(),d.label=10;case 10:return t.staleIfError&&(n.headers[i.XAxiosCacheStaleIfError]=String(u)),(null==t?void 0:t.update)?[4,b(e.storage,n,t.update)]:[3,12];case 11:d.sent(),d.label=12;case 12:return h={state:"cached",ttl:u,createdAt:Date.now(),data:f},(p=e.waiting[n.id])&&(p.resolve(h.data),delete e.waiting[n.id]),[4,e.storage.set(n.id,h)];case 13:return d.sent(),[2,n]}}))}))},a=function(n){return u(t,void 0,void 0,(function(){var t,a,o,i,s,c;return d(this,(function(u){switch(u.label){case 0:if(!(t=n.config)||!1===t.cache||!t.id)throw n;return[4,e.storage.get(t.id)];case 1:return a=u.sent(),o=t.cache,"loading"===a.state&&"stale"===a.previous?[3,3]:[4,r(t.id)];case 2:throw u.sent(),n;case 3:return(null==o?void 0:o.staleIfError)?"function"!=typeof o.staleIfError?[3,5]:[4,o.staleIfError(n.response,a,n)]:[3,8];case 4:return s=u.sent(),[3,6];case 5:s=o.staleIfError,u.label=6;case 6:return!0===(i=s)||"number"==typeof i&&a.createdAt+i>Date.now()?(null===(c=e.waiting[t.id])||void 0===c||c.resolve(a.data),delete e.waiting[t.id],[4,e.storage.set(t.id,{state:"stale",createdAt:Date.now(),data:a.data})]):[3,8];case 7:return u.sent(),[2,{cached:!0,config:t,id:t.id,data:a.data.data,headers:a.data.headers,status:a.data.status,statusText:a.data.statusText}];case 8:throw n}}))}))};return{onFulfilled:n,onRejected:a,apply:function(){return e.interceptors.response.use(n,a)}}}var w=Symbol(),x=function(e){return!!e&&!!e[w]};function S(e){var t=e.data.headers;return i.ETag in t||i.LastModified in t||i.XAxiosCacheEtag in t||i.XAxiosCacheStaleIfError in t||i.XAxiosCacheLastModified in t}function I(e){return e.createdAt+e.ttl<=Date.now()}function C(e){var t,r=this,n=e.set,a=e.find,o=e.remove;return(t={})[w]=1,t.set=n,t.remove=o,t.get=function(e){return u(r,void 0,void 0,(function(){var t,r;return d(this,(function(i){switch(i.label){case 0:return[4,a(e)];case 1:return(t=i.sent())?"cached"===t.state&&I(t)?S(t)?(r={state:"stale",createdAt:t.createdAt,data:t.data},[4,n(e,r)]):[3,3]:[2,t]:[2,{state:"empty"}];case 2:return i.sent(),[2,r];case 3:return[4,o(e)];case 4:return i.sent(),[2,{state:"empty"}]}}))}))},t}function A(){var e=C({find:function(t){return e.data[t]},set:function(t,r){e.data[t]=r},remove:function(t){delete e.data[t]}});return e.data=Object.create(null),e}function E(e){const t=typeof e;if(e&&"object"==t&&!(e instanceof Date||e instanceof RegExp)){const t=Array.isArray(e)?[]:{};for(const r in e)t[r]=E(e[r]);return`${e.constructor}${JSON.stringify(t,Object.keys(e).sort())}`}return`${t}${String(e)}`}function j(e){e=E(e);let t=5381,r=0;for(;r<e.length;)t=33*t^e.charCodeAt(r++);return t}var O=/^\/|\/$/g;function T(e,t){return function(r){if(r.id)return r.id;r.baseURL&&(r.baseURL=r.baseURL.replace(O,"")),r.url&&(r.url=r.url.replace(O,"")),r.method&&(r.method=r.method.toLowerCase());var n=t(r);return e?"".concat(j(n)):n}}var M=T(!0,(function(e){var t=e.baseURL,r=void 0===t?"":t,n=e.url,a=void 0===n?"":n,o=e.method;return{url:r+(r&&a?"/":"")+a,method:void 0===o?"get":o,params:e.params,data:e.data}}));function L(e,t){var r,n,a,o,i;void 0===t&&(t={});var c=e;if(c.storage=t.storage||A(),!x(c.storage))throw new Error("Use buildStorage() function");return c.generateKey=t.generateKey||M,c.waiting=t.waiting||{},c.headerInterpreter=t.headerInterpreter||s,c.requestInterceptor=t.requestInterceptor||g(c),c.responseInterceptor=t.responseInterceptor||y(c),c.debug=t.debug,c.defaults.cache={ttl:null!==(r=t.ttl)&&void 0!==r?r:3e5,interpretHeader:null!==(n=t.interpretHeader)&&void 0!==n&&n,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:function(e){return e>=200&&e<400}},etag:null!==(a=t.etag)&&void 0!==a&&a,modifiedSince:null!==(o=t.modifiedSince)&&void 0!==o&&o,staleIfError:null!==(i=t.staleIfError)&&void 0!==i&&i,update:t.update||{}},c.requestInterceptor.apply(),c.responseInterceptor.apply(),c}function R(e,t){return void 0===t&&(t=""),C({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=Object.entries(e).filter((function(r){var n=r[0];return n.startsWith(t)&&e.getItem(n)})).map((function(e){var t=e[0],r=e[1];return[t,JSON.parse(r)]})),i=0,s=o;i<s.length;i++){var c=s[i],u=c[0],d=c[1];"cached"===d.state&&I(d)&&!S(d)&&e.removeItem(u)}try{return a()}catch(t){for(var l=o.sort((function(e,t){var r=e[1],n=t[1];return(r.createdAt||0)-(n.createdAt||0)})),f=0,h=l;f<h.length;f++){u=h[f][0];e.removeItem(u);try{return a()}catch(e){}}}e.removeItem(t+r)}}})}return t}()})); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{var e={549:(e,t)=>{var a,r;a=t,r=Symbol("fast-defer"),a.deferred=function(){var e,t,a=new Promise((function(a,r){e=a,t=r}));return a.resolve=e,a.reject=t,a[r]=1,a},a.isDeferred=function(e){return!!e&&!!e[r]}}},t={};function a(r){var n=t[r];if(void 0!==n)return n.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,a),o.exports}a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";a.r(r),a.d(r,{Header:()=>o,buildKeyGenerator:()=>A,buildMemoryStorage:()=>x,buildStorage:()=>b,buildWebStorage:()=>O,canStale:()=>y,createCacheResponse:()=>f,createValidateStatus:()=>c,defaultHeaderInterpreter:()=>i,defaultKeyGenerator:()=>j,defaultRequestInterceptor:()=>l,defaultResponseInterceptor:()=>p,isExpired:()=>w,isMethodIn:()=>d,isStorage:()=>v,setupCache:()=>E,testCachePredicate:()=>h,updateCache:()=>g,updateStaleRequest:()=>u});var e=Symbol("cache-parser");function t(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function n(e){return"number"==typeof e||!0===e||"string"==typeof e&&"false"!==e}const o=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",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=a=>{if(!a)return"not enough headers";const r=a[o.CacheControl];if(r){const{noCache:i,noStore:s,mustRevalidate:c,maxAge:d,immutable:u}=function(a){var r=Object.defineProperty({},e,{enumerable:!1,value:1});if(!a||"string"!=typeof a)return r;var o=function(e){var t=e.toLowerCase().replace(/\s+/g,"").split(","),a={};for(var r in t){var n=t[r].split("=",2);a[n[0]]=1===n.length||n[1]}return a}(a);return n(o.immutable)&&(r.immutable=!0),t(o["max-age"])&&(r.maxAge=Number(o["max-age"])),t(o["max-stale"])&&(r.maxStale=Number(o["max-stale"])),t(o["min-fresh"])&&(r.minFresh=Number(o["min-fresh"])),n(o["must-revalidate"])&&(r.mustRevalidate=!0),n(o["must-understand"])&&(r.mustUnderstand=!0),n(o["no-cache"])&&(r.noCache=!0),n(o["no-store"])&&(r.noStore=!0),n(o["no-transform"])&&(r.noTransform=!0),n(o["only-if-cached"])&&(r.onlyIfCached=!0),n(o.private)&&(r.private=!0),n(o["proxy-revalidate"])&&(r.proxyRevalidate=!0),n(o.public)&&(r.public=!0),t(o["s-maxage"])&&(r.sMaxAge=Number(o["s-maxage"])),t(o["stale-if-error"])&&(r.staleIfError=Number(o["stale-if-error"])),t(o["stale-while-revalidate"])&&(r.staleWhileRevalidate=Number(o["stale-while-revalidate"])),r}(String(r));if(i||s)return"dont cache";if(u)return 31536e6;if(c)return 0;if(d){const e=a[o.Age];return e?1e3*(d-Number(e)):1e3*d}}const i=a[o.Expires];if(i){const e=Date.parse(String(i))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};var s=a(549);function c(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function d(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function u(e,t){var a;t.headers||(t.headers={});const{etag:r,modifiedSince:n}=t.cache;if(r){const n=!0===r?null===(a=e.data)||void 0===a?void 0:a.headers[o.ETag]:r;n&&(t.headers[o.IfNoneMatch]=n)}n&&(t.headers[o.IfModifiedSince]=!0===n?e.data.headers[o.LastModified]||new Date(e.createdAt).toUTCString():n.toUTCString())}function f(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function l(e){const t=async t=>{var a;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!d(t.method,t.cache.methods))return t;const r=t.id=e.generateKey(t);let n,o=await e.storage.get(r);e:if("empty"===o.state||"stale"===o.state){if(e.waiting[r]){o=await e.storage.get(r);break e}return e.waiting[r]=(0,s.deferred)(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),await e.storage.set(r,{state:"loading",previous:o.state,data:o.data,createdAt:o.createdAt}),"stale"===o.state&&u(o,t),t.validateStatus=c(t.validateStatus),t}if("loading"===o.state){const a=e.waiting[r];if(!a)return await e.storage.remove(r),t;0;try{n=await a}catch(e){return t}}else n=o.data;return t.adapter=()=>Promise.resolve({config:t,data:n.data,headers:n.headers,status:n.status,statusText:n.statusText,cached:!0,id:r}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function h(e,t){var a;if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:n,containsHeaders:o}=t;if(r&&!await r(e.status)||n&&!await n(e))return!1;if(o)for(const t in o){const r=o[t];if(r&&!await r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t]))return!1}return!0}async function g(e,t,a){for(const r in a){const n=a[r];if("delete"===n){await e.remove(r);continue}const o=await e.get(r);if("loading"===o.state)continue;const i=await n(o,t);"delete"!==i?"ignore"!==i&&await e.set(r,i):await e.remove(r)}}function p(e){const t=async t=>{var a;await e.storage.remove(t),null===(a=e.waiting[t])||void 0===a||a.reject(null),delete e.waiting[t]},a=async a=>{var r,n,i;if(a.id=null!==(r=(i=a.config).id)&&void 0!==r?r:i.id=e.generateKey(a.config),null!==(n=a.cached)&&void 0!==n||(a.cached=!1),a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const s=a.config.cache,c=await e.storage.get(a.id);if("stale"===c.state||"empty"===c.state||"cached"===c.state)return a;if(!c.data&&!await h(a,s.cachePredicate))return await t(a.id),a;for(const e in o)e.startsWith("XAxiosCache")&&delete a.headers[e];s.etag&&!0!==s.etag&&(a.headers[o.XAxiosCacheEtag]=s.etag),s.modifiedSince&&(a.headers[o.XAxiosCacheLastModified]=!0===s.modifiedSince?"use-cache-timestamp":s.modifiedSince.toUTCString());let d=s.ttl||-1;if(null==s?void 0:s.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),a;d="not enough headers"===r?d:r}const u=f(a,c.data);"function"==typeof d&&(d=await d(a)),s.staleIfError&&(a.headers[o.XAxiosCacheStaleIfError]=String(d)),(null==s?void 0:s.update)&&await g(e.storage,a,s.update);const l={state:"cached",ttl:d,createdAt:Date.now(),data:u},p=e.waiting[a.id];return p&&(p.resolve(l.data),delete e.waiting[a.id]),await e.storage.set(a.id,l),a},r=async a=>{var r;const n=a.config;if(!n||!1===n.cache||!n.id)throw a;const o=await e.storage.get(n.id),i=n.cache;if("loading"!==o.state||"stale"!==o.previous)throw await t(n.id),a;if(null==i?void 0:i.staleIfError){const t="function"==typeof i.staleIfError?await i.staleIfError(a.response,o,a):i.staleIfError;if(!0===t||"number"==typeof t&&o.createdAt+t>Date.now())return null===(r=e.waiting[n.id])||void 0===r||r.resolve(o.data),delete e.waiting[n.id],await e.storage.set(n.id,{state:"stale",createdAt:Date.now(),data:o.data}),{cached:!0,config:n,id:n.id,data:o.data.data,headers:o.data.headers,status:o.data.status,statusText:o.data.statusText}}throw a};return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const m=Symbol(),v=e=>!!e&&!!e[m];function y(e){const t=e.data.headers;return o.ETag in t||o.LastModified in t||o.XAxiosCacheEtag in t||o.XAxiosCacheStaleIfError in t||o.XAxiosCacheLastModified in t}function w(e){return e.createdAt+e.ttl<=Date.now()}function b({set:e,find:t,remove:a}){return{[m]:1,set:e,remove:a,get:async r=>{const n=await t(r);if(!n)return{state:"empty"};if("cached"!==n.state||!w(n))return n;if(y(n)){const t={state:"stale",createdAt:n.createdAt,data:n.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function x(){const e=b({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}function S(e){const t=typeof e;if(e&&"object"===t&&!(e instanceof Date||e instanceof RegExp)){const t=Array.isArray(e)?[]:{};for(const a in e)t[a]=S(e[a]);return`${e.constructor}${JSON.stringify(t,Object.keys(e).sort())}`}return`${t}${String(e)}`}function I(e){e=S(e);let t=5381;for(let a=0;a<e.length;a++)t=33*t^e.charCodeAt(a);return t>>>0}const C=/^\/|\/$/g;function A(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(C,"")),a.url&&(a.url=a.url.replace(C,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?I(r).toString():r}}const j=A(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:n})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:n})));function E(e,t={}){var a,r,n,o,s;const c=e;if(c.storage=t.storage||x(),!v(c.storage))throw new Error("Use buildStorage() function");return c.generateKey=t.generateKey||j,c.waiting=t.waiting||{},c.headerInterpreter=t.headerInterpreter||i,c.requestInterceptor=t.requestInterceptor||l(c),c.responseInterceptor=t.responseInterceptor||p(c),c.debug=t.debug,c.defaults.cache={ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,interpretHeader:null!==(r=t.interpretHeader)&&void 0!==r&&r,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(n=t.etag)&&void 0!==n&&n,modifiedSince:null!==(o=t.modifiedSince)&&void 0!==o&&o,staleIfError:null!==(s=t.staleIfError)&&void 0!==s&&s,update:t.update||{}},c.requestInterceptor.apply(),c.responseInterceptor.apply(),c}function O(e,t=""){return b({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const n=()=>e.setItem(t+a,JSON.stringify(r));try{return n()}catch(r){const o=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of o)"cached"===a.state&&w(a)&&!y(a)&&e.removeItem(t);try{return n()}catch(t){const a=o.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return n()}catch(e){}}}e.removeItem(t+a)}}})}})(),r})()})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Header:()=>i,buildKeyGenerator:()=>j,buildMemoryStorage:()=>S,buildStorage:()=>x,buildWebStorage:()=>T,canStale:()=>w,createCacheResponse:()=>l,createValidateStatus:()=>d,defaultHeaderInterpreter:()=>s,defaultKeyGenerator:()=>E,defaultRequestInterceptor:()=>h,defaultResponseInterceptor:()=>m,isExpired:()=>b,isMethodIn:()=>u,isStorage:()=>v,setupCache:()=>O,testCachePredicate:()=>g,updateCache:()=>p,updateStaleRequest:()=>f});const a=Symbol("cache-parser");function r(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function n(e){return!0===e||"number"==typeof e||"string"==typeof e&&"false"!==e}const o=Number;const i=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),s=e=>{if(!e)return"not enough headers";const t=e[i.CacheControl];if(t){const{noCache:s,noStore:c,mustRevalidate:d,maxAge:u,immutable:f}=function(e){const t=Object.defineProperty({},a,{enumerable:!1,value:1});if(!e||"string"!=typeof e)return t;const i=function(e){const t={},a=e.toLowerCase().replace(/\s+/g,"").split(",");for(const e in a){var r;const n=a[e].split("=",2);t[n[0]]=null==(r=n[1])||r}return t}(e),s=i["max-age"],c=i["max-stale"],d=i["min-fresh"],u=i["s-maxage"],f=i["stale-if-error"],l=i["stale-while-revalidate"];return n(i.immutable)&&(t.immutable=!0),r(s)&&(t.maxAge=o(s)),r(c)&&(t.maxStale=o(c)),r(d)&&(t.minFresh=o(d)),n(i["must-revalidate"])&&(t.mustRevalidate=!0),n(i["must-understand"])&&(t.mustUnderstand=!0),n(i["no-cache"])&&(t.noCache=!0),n(i["no-store"])&&(t.noStore=!0),n(i["no-transform"])&&(t.noTransform=!0),n(i["only-if-cached"])&&(t.onlyIfCached=!0),n(i.private)&&(t.private=!0),n(i["proxy-revalidate"])&&(t.proxyRevalidate=!0),n(i.public)&&(t.public=!0),r(u)&&(t.sMaxAge=o(u)),r(f)&&(t.staleIfError=o(f)),r(l)&&(t.staleWhileRevalidate=o(l)),t}(String(t));if(s||c)return"dont cache";if(f)return 31536e6;if(d)return 0;if(u){const t=e[i.Age];return t?1e3*(u-Number(t)):1e3*u}}const s=e[i.Expires];if(s){const e=Date.parse(String(s))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"},c=Symbol();function d(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function u(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function f(e,t){var a;t.headers||(t.headers={});const{etag:r,modifiedSince:n}=t.cache;if(r){const n=!0===r?null===(a=e.data)||void 0===a?void 0:a.headers[i.ETag]:r;n&&(t.headers[i.IfNoneMatch]=n)}n&&(t.headers[i.IfModifiedSince]=!0===n?e.data.headers[i.LastModified]||new Date(e.createdAt).toUTCString():n.toUTCString())}function l(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function h(e){const t=async t=>{var a;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!u(t.method,t.cache.methods))return t;const r=t.id=e.generateKey(t);let n,o=await e.storage.get(r);e:if("empty"===o.state||"stale"===o.state){if(e.waiting[r]){o=await e.storage.get(r);break e}return e.waiting[r]=function(){let e,t;const a=new Promise(((a,r)=>{e=a,t=r}));return a.resolve=e,a.reject=t,a[c]=1,a}(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),await e.storage.set(r,{state:"loading",previous:o.state,data:o.data,createdAt:o.createdAt}),"stale"===o.state&&f(o,t),t.validateStatus=d(t.validateStatus),t}if("loading"===o.state){const a=e.waiting[r];if(!a)return await e.storage.remove(r),t;0;try{n=await a}catch(e){return t}}else n=o.data;return t.adapter=()=>Promise.resolve({config:t,data:n.data,headers:n.headers,status:n.status,statusText:n.statusText,cached:!0,id:r}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function g(e,t){var a;if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:n,containsHeaders:o}=t;if(r&&!await r(e.status)||n&&!await n(e))return!1;if(o)for(const t in o){const r=o[t];if(r&&!await r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t]))return!1}return!0}async function p(e,t,a){for(const r in a){const n=a[r];if("delete"===n){await e.remove(r);continue}const o=await e.get(r);if("loading"===o.state)continue;const i=await n(o,t);"delete"!==i?"ignore"!==i&&await e.set(r,i):await e.remove(r)}}function m(e){const t=async t=>{var a;await e.storage.remove(t),null===(a=e.waiting[t])||void 0===a||a.reject(null),delete e.waiting[t]},a=async a=>{var r,n,o;if(a.id=null!==(r=(o=a.config).id)&&void 0!==r?r:o.id=e.generateKey(a.config),null!==(n=a.cached)&&void 0!==n||(a.cached=!1),a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const s=a.config.cache,c=await e.storage.get(a.id);if("stale"===c.state||"empty"===c.state||"cached"===c.state)return a;if(!c.data&&!await g(a,s.cachePredicate))return await t(a.id),a;for(const e in i)e.startsWith("XAxiosCache")&&delete a.headers[e];s.etag&&!0!==s.etag&&(a.headers[i.XAxiosCacheEtag]=s.etag),s.modifiedSince&&(a.headers[i.XAxiosCacheLastModified]=!0===s.modifiedSince?"use-cache-timestamp":s.modifiedSince.toUTCString());let d=s.ttl||-1;if(null==s?void 0:s.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),a;d="not enough headers"===r?d:r}const u=l(a,c.data);"function"==typeof d&&(d=await d(a)),s.staleIfError&&(a.headers[i.XAxiosCacheStaleIfError]=String(d)),(null==s?void 0:s.update)&&await p(e.storage,a,s.update);const f={state:"cached",ttl:d,createdAt:Date.now(),data:u},h=e.waiting[a.id];return h&&(h.resolve(f.data),delete e.waiting[a.id]),await e.storage.set(a.id,f),a},r=async a=>{var r;const n=a.config;if(!n||!1===n.cache||!n.id)throw a;const o=await e.storage.get(n.id),i=n.cache;if("loading"!==o.state||"stale"!==o.previous)throw await t(n.id),a;if(null==i?void 0:i.staleIfError){const t="function"==typeof i.staleIfError?await i.staleIfError(a.response,o,a):i.staleIfError;if(!0===t||"number"==typeof t&&o.createdAt+t>Date.now())return null===(r=e.waiting[n.id])||void 0===r||r.resolve(o.data),delete e.waiting[n.id],await e.storage.set(n.id,{state:"stale",createdAt:Date.now(),data:o.data}),{cached:!0,config:n,id:n.id,data:o.data.data,headers:o.data.headers,status:o.data.status,statusText:o.data.statusText}}throw a};return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const y=Symbol(),v=e=>!!e&&!!e[y];function w(e){const t=e.data.headers;return i.ETag in t||i.LastModified in t||i.XAxiosCacheEtag in t||i.XAxiosCacheStaleIfError in t||i.XAxiosCacheLastModified in t}function b(e){return e.createdAt+e.ttl<=Date.now()}function x({set:e,find:t,remove:a}){return{[y]:1,set:e,remove:a,get:async r=>{const n=await t(r);if(!n)return{state:"empty"};if("cached"!==n.state||!b(n))return n;if(w(n)){const t={state:"stale",createdAt:n.createdAt,data:n.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function S(){const e=x({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}function I(e){const t=typeof e;if(e&&"object"==t&&!(e instanceof Date||e instanceof RegExp)){const t=Array.isArray(e)?[]:{};for(const a in e)t[a]=I(e[a]);return`${e.constructor}${JSON.stringify(t,Object.keys(e).sort())}`}return`${t}${String(e)}`}function C(e){e=I(e);let t=5381,a=0;for(;a<e.length;)t=33*t^e.charCodeAt(a++);return t}const A=/^\/|\/$/g;function j(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(A,"")),a.url&&(a.url=a.url.replace(A,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?`${C(r)}`:r}}const E=j(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:n})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:n})));function O(e,t={}){var a,r,n,o,i;const c=e;if(c.storage=t.storage||S(),!v(c.storage))throw new Error("Use buildStorage() function");return c.generateKey=t.generateKey||E,c.waiting=t.waiting||{},c.headerInterpreter=t.headerInterpreter||s,c.requestInterceptor=t.requestInterceptor||h(c),c.responseInterceptor=t.responseInterceptor||m(c),c.debug=t.debug,c.defaults.cache={ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,interpretHeader:null!==(r=t.interpretHeader)&&void 0!==r&&r,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(n=t.etag)&&void 0!==n&&n,modifiedSince:null!==(o=t.modifiedSince)&&void 0!==o&&o,staleIfError:null!==(i=t.staleIfError)&&void 0!==i&&i,update:t.update||{}},c.requestInterceptor.apply(),c.responseInterceptor.apply(),c}function T(e,t=""){return x({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const n=()=>e.setItem(t+a,JSON.stringify(r));try{return n()}catch(r){const o=Object.entries(e).filter((([a])=>a.startsWith(t)&&e.getItem(a))).map((([e,t])=>[e,JSON.parse(t)]));for(const[t,a]of o)"cached"===a.state&&b(a)&&!w(a)&&e.removeItem(t);try{return n()}catch(t){const a=o.sort((([,e],[,t])=>(e.createdAt||0)-(t.createdAt||0)));for(const[t]of a){e.removeItem(t);try{return n()}catch(e){}}}e.removeItem(t+a)}}})}return t})()})); |
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
357766
2417
+ Addedcache-parser@1.2.2(transitive)
- Removedcache-parser@1.2.0(transitive)
Updatedcache-parser@1.2.2
Updatedfast-defer@^1.1.5
Updatedobject-code@^1.2.0