diff --git a/apps/web/public/sw.js b/apps/web/public/sw.js index 12d2a8a..6d4460b 100644 --- a/apps/web/public/sw.js +++ b/apps/web/public/sw.js @@ -1 +1 @@ -"use strict";(()=>{try{self["workbox:core:7.0.0"]&&_()}catch{}var ce=(r,...e)=>{let t=r;return e.length>0&&(t+=` :: ${JSON.stringify(e)}`),t};var z=ce;var u=class extends Error{constructor(e,t){let o=z(e,t);super(o),this.name=e,this.details=t}};var S=new Set;function W(r){S.add(r)}var d={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"workbox",runtime:"runtime",suffix:typeof registration<"u"?registration.scope:""},M=r=>[d.prefix,r,d.suffix].filter(e=>e&&e.length>0).join("-"),ue=r=>{for(let e of Object.keys(d))r(e)},w={updateDetails:r=>{ue(e=>{typeof r[e]=="string"&&(d[e]=r[e])})},getGoogleAnalyticsName:r=>r||M(d.googleAnalytics),getPrecacheName:r=>r||M(d.precache),getPrefix:()=>d.prefix,getRuntimeName:r=>r||M(d.runtime),getSuffix:()=>d.suffix};function X(r,e){let t=new URL(r);for(let o of e)t.searchParams.delete(o);return t.href}async function F(r,e,t,o){let s=X(e.url,t);if(e.url===s)return r.match(e,o);let a=Object.assign(Object.assign({},o),{ignoreSearch:!0}),n=await r.keys(e,a);for(let i of n){let c=X(i.url,t);if(s===c)return r.match(i,o)}}function y(r){r.then(()=>{})}var x=class{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}};async function I(){for(let r of S)await r()}var U=r=>new URL(String(r),location.href).href.replace(new RegExp(`^${location.origin}`),"");function b(r){return new Promise(e=>setTimeout(e,r))}function B(){self.addEventListener("activate",()=>self.clients.claim())}var he=(r,e)=>e.some(t=>r instanceof t),Z,ee;function de(){return Z||(Z=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function fe(){return ee||(ee=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var te=new WeakMap,j=new WeakMap,re=new WeakMap,H=new WeakMap,K=new WeakMap;function ge(r){let e=new Promise((t,o)=>{let s=()=>{r.removeEventListener("success",a),r.removeEventListener("error",n)},a=()=>{t(p(r.result)),s()},n=()=>{o(r.error),s()};r.addEventListener("success",a),r.addEventListener("error",n)});return e.then(t=>{t instanceof IDBCursor&&te.set(t,r)}).catch(()=>{}),K.set(e,r),e}function we(r){if(j.has(r))return;let e=new Promise((t,o)=>{let s=()=>{r.removeEventListener("complete",a),r.removeEventListener("error",n),r.removeEventListener("abort",n)},a=()=>{t(),s()},n=()=>{o(r.error||new DOMException("AbortError","AbortError")),s()};r.addEventListener("complete",a),r.addEventListener("error",n),r.addEventListener("abort",n)});j.set(r,e)}var G={get(r,e,t){if(r instanceof IDBTransaction){if(e==="done")return j.get(r);if(e==="objectStoreNames")return r.objectStoreNames||re.get(r);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return p(r[e])},set(r,e,t){return r[e]=t,!0},has(r,e){return r instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in r}};function oe(r){G=r(G)}function Ee(r){return r===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...t){let o=r.call(q(this),e,...t);return re.set(o,e.sort?e.sort():[e]),p(o)}:fe().includes(r)?function(...e){return r.apply(q(this),e),p(te.get(this))}:function(...e){return p(r.apply(q(this),e))}}function Ne(r){return typeof r=="function"?Ee(r):(r instanceof IDBTransaction&&we(r),he(r,de())?new Proxy(r,G):r)}function p(r){if(r instanceof IDBRequest)return ge(r);if(H.has(r))return H.get(r);let e=Ne(r);return e!==r&&(H.set(r,e),K.set(e,r)),e}var q=r=>K.get(r);function ne(r,e,{blocked:t,upgrade:o,blocking:s,terminated:a}={}){let n=indexedDB.open(r,e),i=p(n);return o&&n.addEventListener("upgradeneeded",c=>{o(p(n.result),c.oldVersion,c.newVersion,p(n.transaction),c)}),t&&n.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),i.then(c=>{a&&c.addEventListener("close",()=>a()),s&&c.addEventListener("versionchange",l=>s(l.oldVersion,l.newVersion,l))}).catch(()=>{}),i}function ae(r,{blocked:e}={}){let t=indexedDB.deleteDatabase(r);return e&&t.addEventListener("blocked",o=>e(o.oldVersion,o)),p(t).then(()=>{})}var ye=["get","getKey","getAll","getAllKeys","count"],xe=["put","add","delete","clear"],Q=new Map;function se(r,e){if(!(r instanceof IDBDatabase&&!(e in r)&&typeof e=="string"))return;if(Q.get(e))return Q.get(e);let t=e.replace(/FromIndex$/,""),o=e!==t,s=xe.includes(t);if(!(t in(o?IDBIndex:IDBObjectStore).prototype)||!(s||ye.includes(t)))return;let a=async function(n,...i){let c=this.transaction(n,s?"readwrite":"readonly"),l=c.store;return o&&(l=l.index(i.shift())),(await Promise.all([l[t](...i),s&&c.done]))[0]};return Q.set(e,a),a}oe(r=>({...r,get:(e,t,o)=>se(e,t)||r.get(e,t,o),has:(e,t)=>!!se(e,t)||r.has(e,t)}));try{self["workbox:expiration:7.0.0"]&&_()}catch{}var be="workbox-expiration",R="cache-entries",ie=r=>{let e=new URL(r,location.href);return e.hash="",e.href},A=class{constructor(e){this._db=null,this._cacheName=e}_upgradeDb(e){let t=e.createObjectStore(R,{keyPath:"id"});t.createIndex("cacheName","cacheName",{unique:!1}),t.createIndex("timestamp","timestamp",{unique:!1})}_upgradeDbAndDeleteOldDbs(e){this._upgradeDb(e),this._cacheName&&ae(this._cacheName)}async setTimestamp(e,t){e=ie(e);let o={url:e,timestamp:t,cacheName:this._cacheName,id:this._getId(e)},a=(await this.getDb()).transaction(R,"readwrite",{durability:"relaxed"});await a.store.put(o),await a.done}async getTimestamp(e){let o=await(await this.getDb()).get(R,this._getId(e));return o?.timestamp}async expireEntries(e,t){let o=await this.getDb(),s=await o.transaction(R).store.index("timestamp").openCursor(null,"prev"),a=[],n=0;for(;s;){let c=s.value;c.cacheName===this._cacheName&&(e&&c.timestamp=t?a.push(s.value):n++),s=await s.continue()}let i=[];for(let c of a)await o.delete(R,c.id),i.push(c.url);return i}_getId(e){return this._cacheName+"|"+ie(e)}async getDb(){return this._db||(this._db=await ne(be,1,{upgrade:this._upgradeDbAndDeleteOldDbs.bind(this)})),this._db}};var k=class{constructor(e,t={}){this._isRunning=!1,this._rerunRequested=!1,this._maxEntries=t.maxEntries,this._maxAgeSeconds=t.maxAgeSeconds,this._matchOptions=t.matchOptions,this._cacheName=e,this._timestampModel=new A(e)}async expireEntries(){if(this._isRunning){this._rerunRequested=!0;return}this._isRunning=!0;let e=this._maxAgeSeconds?Date.now()-this._maxAgeSeconds*1e3:0,t=await this._timestampModel.expireEntries(e,this._maxEntries),o=await self.caches.open(this._cacheName);for(let s of t)await o.delete(s,this._matchOptions);this._isRunning=!1,this._rerunRequested&&(this._rerunRequested=!1,y(this.expireEntries()))}async updateTimestamp(e){await this._timestampModel.setTimestamp(e,Date.now())}async isURLExpired(e){if(this._maxAgeSeconds){let t=await this._timestampModel.getTimestamp(e),o=Date.now()-this._maxAgeSeconds*1e3;return t!==void 0?t{if(!a)return null;let n=this._isResponseDateFresh(a),i=this._getCacheExpiration(s);y(i.expireEntries());let c=i.updateTimestamp(o.url);if(t)try{t.waitUntil(c)}catch{}return n?a:null},this.cacheDidUpdate=async({cacheName:t,request:o})=>{let s=this._getCacheExpiration(t);await s.updateTimestamp(o.url),await s.expireEntries()},this._config=e,this._maxAgeSeconds=e.maxAgeSeconds,this._cacheExpirations=new Map,e.purgeOnQuotaError&&W(()=>this.deleteCacheAndMetadata())}_getCacheExpiration(e){if(e===w.getRuntimeName())throw new u("expire-custom-caches-only");let t=this._cacheExpirations.get(e);return t||(t=new k(e,this._config),this._cacheExpirations.set(e,t)),t}_isResponseDateFresh(e){if(!this._maxAgeSeconds)return!0;let t=this._getDateHeaderTimestamp(e);if(t===null)return!0;let o=Date.now();return t>=o-this._maxAgeSeconds*1e3}_getDateHeaderTimestamp(e){if(!e.headers.has("date"))return null;let t=e.headers.get("date"),s=new Date(t).getTime();return isNaN(s)?null:s}async deleteCacheAndMetadata(){for(let[e,t]of this._cacheExpirations)await self.caches.delete(e),await t.delete();this._cacheExpirations=new Map}};try{self["workbox:routing:7.0.0"]&&_()}catch{}var L="GET";var E=r=>r&&typeof r=="object"?r:{handle:r};var h=class{constructor(e,t,o=L){this.handler=E(t),this.match=e,this.method=o}setCatchHandler(e){this.catchHandler=E(e)}};var D=class extends h{constructor(e,t,o){let s=({url:a})=>{let n=e.exec(a.href);if(n&&!(a.origin!==location.origin&&n.index!==0))return n.slice(1)};super(s,t,o)}};var C=class{constructor(){this._routes=new Map,this._defaultHandlerMap=new Map}get routes(){return this._routes}addFetchListener(){self.addEventListener("fetch",e=>{let{request:t}=e,o=this.handleRequest({request:t,event:e});o&&e.respondWith(o)})}addCacheListener(){self.addEventListener("message",e=>{if(e.data&&e.data.type==="CACHE_URLS"){let{payload:t}=e.data,o=Promise.all(t.urlsToCache.map(s=>{typeof s=="string"&&(s=[s]);let a=new Request(...s);return this.handleRequest({request:a,event:e})}));e.waitUntil(o),e.ports&&e.ports[0]&&o.then(()=>e.ports[0].postMessage(!0))}})}handleRequest({request:e,event:t}){let o=new URL(e.url,location.href);if(!o.protocol.startsWith("http"))return;let s=o.origin===location.origin,{params:a,route:n}=this.findMatchingRoute({event:t,request:e,sameOrigin:s,url:o}),i=n&&n.handler,c=[],l=e.method;if(!i&&this._defaultHandlerMap.has(l)&&(i=this._defaultHandlerMap.get(l)),!i)return;let g;try{g=i.handle({url:o,request:e,event:t,params:a})}catch(N){g=Promise.reject(N)}let m=n&&n.catchHandler;return g instanceof Promise&&(this._catchHandler||m)&&(g=g.catch(async N=>{if(m)try{return await m.handle({url:o,request:e,event:t,params:a})}catch(Y){Y instanceof Error&&(N=Y)}if(this._catchHandler)return this._catchHandler.handle({url:o,request:e,event:t});throw N})),g}findMatchingRoute({url:e,sameOrigin:t,request:o,event:s}){let a=this._routes.get(o.method)||[];for(let n of a){let i,c=n.match({url:e,sameOrigin:t,request:o,event:s});if(c)return i=c,(Array.isArray(i)&&i.length===0||c.constructor===Object&&Object.keys(c).length===0||typeof c=="boolean")&&(i=void 0),{route:n,params:i}}return{}}setDefaultHandler(e,t=L){this._defaultHandlerMap.set(t,E(e))}setCatchHandler(e){this._catchHandler=E(e)}registerRoute(e){this._routes.has(e.method)||this._routes.set(e.method,[]),this._routes.get(e.method).push(e)}unregisterRoute(e){if(!this._routes.has(e.method))throw new u("unregister-route-but-not-found-with-method",{method:e.method});let t=this._routes.get(e.method).indexOf(e);if(t>-1)this._routes.get(e.method).splice(t,1);else throw new u("unregister-route-route-not-registered")}};var $,V=()=>($||($=new C,$.addFetchListener(),$.addCacheListener()),$);function J(r,e,t){let o;if(typeof r=="string"){let a=new URL(r,location.href),n=({url:i})=>i.href===a.href;o=new h(n,e,t)}else if(r instanceof RegExp)o=new D(r,e,t);else if(typeof r=="function")o=new h(r,e,t);else if(r instanceof h)o=r;else throw new u("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});return V().registerRoute(o),o}try{self["workbox:strategies:7.0.0"]&&_()}catch{}function P(r){return typeof r=="string"?new Request(r):r}var O=class{constructor(e,t){this._cacheKeys={},Object.assign(this,t),this.event=t.event,this._strategy=e,this._handlerDeferred=new x,this._extendLifetimePromises=[],this._plugins=[...e.plugins],this._pluginStateMap=new Map;for(let o of this._plugins)this._pluginStateMap.set(o,{});this.event.waitUntil(this._handlerDeferred.promise)}async fetch(e){let{event:t}=this,o=P(e);if(o.mode==="navigate"&&t instanceof FetchEvent&&t.preloadResponse){let n=await t.preloadResponse;if(n)return n}let s=this.hasCallback("fetchDidFail")?o.clone():null;try{for(let n of this.iterateCallbacks("requestWillFetch"))o=await n({request:o.clone(),event:t})}catch(n){if(n instanceof Error)throw new u("plugin-error-request-will-fetch",{thrownErrorMessage:n.message})}let a=o.clone();try{let n;n=await fetch(o,o.mode==="navigate"?void 0:this._strategy.fetchOptions);for(let i of this.iterateCallbacks("fetchDidSucceed"))n=await i({event:t,request:a,response:n});return n}catch(n){throw s&&await this.runCallbacks("fetchDidFail",{error:n,event:t,originalRequest:s.clone(),request:a.clone()}),n}}async fetchAndCachePut(e){let t=await this.fetch(e),o=t.clone();return this.waitUntil(this.cachePut(e,o)),t}async cacheMatch(e){let t=P(e),o,{cacheName:s,matchOptions:a}=this._strategy,n=await this.getCacheKey(t,"read"),i=Object.assign(Object.assign({},a),{cacheName:s});o=await caches.match(n,i);for(let c of this.iterateCallbacks("cachedResponseWillBeUsed"))o=await c({cacheName:s,matchOptions:a,cachedResponse:o,request:n,event:this.event})||void 0;return o}async cachePut(e,t){let o=P(e);await b(0);let s=await this.getCacheKey(o,"write");if(!t)throw new u("cache-put-with-no-response",{url:U(s.url)});let a=await this._ensureResponseSafeToCache(t);if(!a)return!1;let{cacheName:n,matchOptions:i}=this._strategy,c=await self.caches.open(n),l=this.hasCallback("cacheDidUpdate"),g=l?await F(c,s.clone(),["__WB_REVISION__"],i):null;try{await c.put(s,l?a.clone():a)}catch(m){if(m instanceof Error)throw m.name==="QuotaExceededError"&&await I(),m}for(let m of this.iterateCallbacks("cacheDidUpdate"))await m({cacheName:n,oldResponse:g,newResponse:a.clone(),request:s,event:this.event});return!0}async getCacheKey(e,t){let o=`${e.url} | ${t}`;if(!this._cacheKeys[o]){let s=e;for(let a of this.iterateCallbacks("cacheKeyWillBeUsed"))s=P(await a({mode:t,request:s,event:this.event,params:this.params}));this._cacheKeys[o]=s}return this._cacheKeys[o]}hasCallback(e){for(let t of this._strategy.plugins)if(e in t)return!0;return!1}async runCallbacks(e,t){for(let o of this.iterateCallbacks(e))await o(t)}*iterateCallbacks(e){for(let t of this._strategy.plugins)if(typeof t[e]=="function"){let o=this._pluginStateMap.get(t);yield a=>{let n=Object.assign(Object.assign({},a),{state:o});return t[e](n)}}}waitUntil(e){return this._extendLifetimePromises.push(e),e}async doneWaiting(){let e;for(;e=this._extendLifetimePromises.shift();)await e}destroy(){this._handlerDeferred.resolve(null)}async _ensureResponseSafeToCache(e){let t=e,o=!1;for(let s of this.iterateCallbacks("cacheWillUpdate"))if(t=await s({request:this.request,response:t,event:this.event})||void 0,o=!0,!t)break;return o||t&&t.status!==200&&(t=void 0),t}};var f=class{constructor(e={}){this.cacheName=w.getRuntimeName(e.cacheName),this.plugins=e.plugins||[],this.fetchOptions=e.fetchOptions,this.matchOptions=e.matchOptions}handle(e){let[t]=this.handleAll(e);return t}handleAll(e){e instanceof FetchEvent&&(e={event:e,request:e.request});let t=e.event,o=typeof e.request=="string"?new Request(e.request):e.request,s="params"in e?e.params:void 0,a=new O(this,{event:t,request:o,params:s}),n=this._getResponse(a,o,t),i=this._awaitComplete(n,a,o,t);return[n,i]}async _getResponse(e,t,o){await e.runCallbacks("handlerWillStart",{event:o,request:t});let s;try{if(s=await this._handle(t,e),!s||s.type==="error")throw new u("no-response",{url:t.url})}catch(a){if(a instanceof Error){for(let n of e.iterateCallbacks("handlerDidError"))if(s=await n({error:a,event:o,request:t}),s)break}if(!s)throw a}for(let a of e.iterateCallbacks("handlerWillRespond"))s=await a({event:o,request:t,response:s});return s}async _awaitComplete(e,t,o,s){let a,n;try{a=await e}catch{}try{await t.runCallbacks("handlerDidRespond",{event:s,request:o,response:a}),await t.doneWaiting()}catch(i){i instanceof Error&&(n=i)}if(await t.runCallbacks("handlerDidComplete",{event:s,request:o,response:a,error:n}),t.destroy(),n)throw n}};var T=class extends f{async _handle(e,t){let o=[],s=await t.cacheMatch(e),a;if(!s)try{s=await t.fetchAndCachePut(e)}catch(n){n instanceof Error&&(a=n)}if(!s)throw new u("no-response",{url:e.url,error:a});return s}};var Re="my-cache";self.addEventListener("install",()=>{self.skipWaiting()});B();var ke=["/","/unlimited"];J(({url:r})=>ke.includes(r.pathname),new T({cacheName:Re,plugins:[new v({maxAgeSeconds:1*60,maxEntries:8})]}));})(); +"use strict";(()=>{try{self["workbox:core:7.0.0"]&&_()}catch{}var ce=(r,...e)=>{let t=r;return e.length>0&&(t+=` :: ${JSON.stringify(e)}`),t};var z=ce;var u=class extends Error{constructor(e,t){let o=z(e,t);super(o),this.name=e,this.details=t}};var S=new Set;function W(r){S.add(r)}var d={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"workbox",runtime:"runtime",suffix:typeof registration<"u"?registration.scope:""},M=r=>[d.prefix,r,d.suffix].filter(e=>e&&e.length>0).join("-"),ue=r=>{for(let e of Object.keys(d))r(e)},w={updateDetails:r=>{ue(e=>{typeof r[e]=="string"&&(d[e]=r[e])})},getGoogleAnalyticsName:r=>r||M(d.googleAnalytics),getPrecacheName:r=>r||M(d.precache),getPrefix:()=>d.prefix,getRuntimeName:r=>r||M(d.runtime),getSuffix:()=>d.suffix};function X(r,e){let t=new URL(r);for(let o of e)t.searchParams.delete(o);return t.href}async function F(r,e,t,o){let s=X(e.url,t);if(e.url===s)return r.match(e,o);let a=Object.assign(Object.assign({},o),{ignoreSearch:!0}),n=await r.keys(e,a);for(let i of n){let c=X(i.url,t);if(s===c)return r.match(i,o)}}function y(r){r.then(()=>{})}var x=class{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}};async function I(){for(let r of S)await r()}var U=r=>new URL(String(r),location.href).href.replace(new RegExp(`^${location.origin}`),"");function b(r){return new Promise(e=>setTimeout(e,r))}function B(){self.addEventListener("activate",()=>self.clients.claim())}var he=(r,e)=>e.some(t=>r instanceof t),Z,ee;function de(){return Z||(Z=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function fe(){return ee||(ee=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var te=new WeakMap,j=new WeakMap,re=new WeakMap,H=new WeakMap,K=new WeakMap;function ge(r){let e=new Promise((t,o)=>{let s=()=>{r.removeEventListener("success",a),r.removeEventListener("error",n)},a=()=>{t(p(r.result)),s()},n=()=>{o(r.error),s()};r.addEventListener("success",a),r.addEventListener("error",n)});return e.then(t=>{t instanceof IDBCursor&&te.set(t,r)}).catch(()=>{}),K.set(e,r),e}function we(r){if(j.has(r))return;let e=new Promise((t,o)=>{let s=()=>{r.removeEventListener("complete",a),r.removeEventListener("error",n),r.removeEventListener("abort",n)},a=()=>{t(),s()},n=()=>{o(r.error||new DOMException("AbortError","AbortError")),s()};r.addEventListener("complete",a),r.addEventListener("error",n),r.addEventListener("abort",n)});j.set(r,e)}var G={get(r,e,t){if(r instanceof IDBTransaction){if(e==="done")return j.get(r);if(e==="objectStoreNames")return r.objectStoreNames||re.get(r);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return p(r[e])},set(r,e,t){return r[e]=t,!0},has(r,e){return r instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in r}};function oe(r){G=r(G)}function Ee(r){return r===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...t){let o=r.call(q(this),e,...t);return re.set(o,e.sort?e.sort():[e]),p(o)}:fe().includes(r)?function(...e){return r.apply(q(this),e),p(te.get(this))}:function(...e){return p(r.apply(q(this),e))}}function Ne(r){return typeof r=="function"?Ee(r):(r instanceof IDBTransaction&&we(r),he(r,de())?new Proxy(r,G):r)}function p(r){if(r instanceof IDBRequest)return ge(r);if(H.has(r))return H.get(r);let e=Ne(r);return e!==r&&(H.set(r,e),K.set(e,r)),e}var q=r=>K.get(r);function ne(r,e,{blocked:t,upgrade:o,blocking:s,terminated:a}={}){let n=indexedDB.open(r,e),i=p(n);return o&&n.addEventListener("upgradeneeded",c=>{o(p(n.result),c.oldVersion,c.newVersion,p(n.transaction),c)}),t&&n.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),i.then(c=>{a&&c.addEventListener("close",()=>a()),s&&c.addEventListener("versionchange",l=>s(l.oldVersion,l.newVersion,l))}).catch(()=>{}),i}function ae(r,{blocked:e}={}){let t=indexedDB.deleteDatabase(r);return e&&t.addEventListener("blocked",o=>e(o.oldVersion,o)),p(t).then(()=>{})}var ye=["get","getKey","getAll","getAllKeys","count"],xe=["put","add","delete","clear"],Q=new Map;function se(r,e){if(!(r instanceof IDBDatabase&&!(e in r)&&typeof e=="string"))return;if(Q.get(e))return Q.get(e);let t=e.replace(/FromIndex$/,""),o=e!==t,s=xe.includes(t);if(!(t in(o?IDBIndex:IDBObjectStore).prototype)||!(s||ye.includes(t)))return;let a=async function(n,...i){let c=this.transaction(n,s?"readwrite":"readonly"),l=c.store;return o&&(l=l.index(i.shift())),(await Promise.all([l[t](...i),s&&c.done]))[0]};return Q.set(e,a),a}oe(r=>({...r,get:(e,t,o)=>se(e,t)||r.get(e,t,o),has:(e,t)=>!!se(e,t)||r.has(e,t)}));try{self["workbox:expiration:7.0.0"]&&_()}catch{}var be="workbox-expiration",R="cache-entries",ie=r=>{let e=new URL(r,location.href);return e.hash="",e.href},A=class{constructor(e){this._db=null,this._cacheName=e}_upgradeDb(e){let t=e.createObjectStore(R,{keyPath:"id"});t.createIndex("cacheName","cacheName",{unique:!1}),t.createIndex("timestamp","timestamp",{unique:!1})}_upgradeDbAndDeleteOldDbs(e){this._upgradeDb(e),this._cacheName&&ae(this._cacheName)}async setTimestamp(e,t){e=ie(e);let o={url:e,timestamp:t,cacheName:this._cacheName,id:this._getId(e)},a=(await this.getDb()).transaction(R,"readwrite",{durability:"relaxed"});await a.store.put(o),await a.done}async getTimestamp(e){let o=await(await this.getDb()).get(R,this._getId(e));return o?.timestamp}async expireEntries(e,t){let o=await this.getDb(),s=await o.transaction(R).store.index("timestamp").openCursor(null,"prev"),a=[],n=0;for(;s;){let c=s.value;c.cacheName===this._cacheName&&(e&&c.timestamp=t?a.push(s.value):n++),s=await s.continue()}let i=[];for(let c of a)await o.delete(R,c.id),i.push(c.url);return i}_getId(e){return this._cacheName+"|"+ie(e)}async getDb(){return this._db||(this._db=await ne(be,1,{upgrade:this._upgradeDbAndDeleteOldDbs.bind(this)})),this._db}};var k=class{constructor(e,t={}){this._isRunning=!1,this._rerunRequested=!1,this._maxEntries=t.maxEntries,this._maxAgeSeconds=t.maxAgeSeconds,this._matchOptions=t.matchOptions,this._cacheName=e,this._timestampModel=new A(e)}async expireEntries(){if(this._isRunning){this._rerunRequested=!0;return}this._isRunning=!0;let e=this._maxAgeSeconds?Date.now()-this._maxAgeSeconds*1e3:0,t=await this._timestampModel.expireEntries(e,this._maxEntries),o=await self.caches.open(this._cacheName);for(let s of t)await o.delete(s,this._matchOptions);this._isRunning=!1,this._rerunRequested&&(this._rerunRequested=!1,y(this.expireEntries()))}async updateTimestamp(e){await this._timestampModel.setTimestamp(e,Date.now())}async isURLExpired(e){if(this._maxAgeSeconds){let t=await this._timestampModel.getTimestamp(e),o=Date.now()-this._maxAgeSeconds*1e3;return t!==void 0?t{if(!a)return null;let n=this._isResponseDateFresh(a),i=this._getCacheExpiration(s);y(i.expireEntries());let c=i.updateTimestamp(o.url);if(t)try{t.waitUntil(c)}catch{}return n?a:null},this.cacheDidUpdate=async({cacheName:t,request:o})=>{let s=this._getCacheExpiration(t);await s.updateTimestamp(o.url),await s.expireEntries()},this._config=e,this._maxAgeSeconds=e.maxAgeSeconds,this._cacheExpirations=new Map,e.purgeOnQuotaError&&W(()=>this.deleteCacheAndMetadata())}_getCacheExpiration(e){if(e===w.getRuntimeName())throw new u("expire-custom-caches-only");let t=this._cacheExpirations.get(e);return t||(t=new k(e,this._config),this._cacheExpirations.set(e,t)),t}_isResponseDateFresh(e){if(!this._maxAgeSeconds)return!0;let t=this._getDateHeaderTimestamp(e);if(t===null)return!0;let o=Date.now();return t>=o-this._maxAgeSeconds*1e3}_getDateHeaderTimestamp(e){if(!e.headers.has("date"))return null;let t=e.headers.get("date"),s=new Date(t).getTime();return isNaN(s)?null:s}async deleteCacheAndMetadata(){for(let[e,t]of this._cacheExpirations)await self.caches.delete(e),await t.delete();this._cacheExpirations=new Map}};try{self["workbox:routing:7.0.0"]&&_()}catch{}var L="GET";var E=r=>r&&typeof r=="object"?r:{handle:r};var h=class{constructor(e,t,o=L){this.handler=E(t),this.match=e,this.method=o}setCatchHandler(e){this.catchHandler=E(e)}};var D=class extends h{constructor(e,t,o){let s=({url:a})=>{let n=e.exec(a.href);if(n&&!(a.origin!==location.origin&&n.index!==0))return n.slice(1)};super(s,t,o)}};var C=class{constructor(){this._routes=new Map,this._defaultHandlerMap=new Map}get routes(){return this._routes}addFetchListener(){self.addEventListener("fetch",e=>{let{request:t}=e,o=this.handleRequest({request:t,event:e});o&&e.respondWith(o)})}addCacheListener(){self.addEventListener("message",e=>{if(e.data&&e.data.type==="CACHE_URLS"){let{payload:t}=e.data,o=Promise.all(t.urlsToCache.map(s=>{typeof s=="string"&&(s=[s]);let a=new Request(...s);return this.handleRequest({request:a,event:e})}));e.waitUntil(o),e.ports&&e.ports[0]&&o.then(()=>e.ports[0].postMessage(!0))}})}handleRequest({request:e,event:t}){let o=new URL(e.url,location.href);if(!o.protocol.startsWith("http"))return;let s=o.origin===location.origin,{params:a,route:n}=this.findMatchingRoute({event:t,request:e,sameOrigin:s,url:o}),i=n&&n.handler,c=[],l=e.method;if(!i&&this._defaultHandlerMap.has(l)&&(i=this._defaultHandlerMap.get(l)),!i)return;let g;try{g=i.handle({url:o,request:e,event:t,params:a})}catch(N){g=Promise.reject(N)}let m=n&&n.catchHandler;return g instanceof Promise&&(this._catchHandler||m)&&(g=g.catch(async N=>{if(m)try{return await m.handle({url:o,request:e,event:t,params:a})}catch(Y){Y instanceof Error&&(N=Y)}if(this._catchHandler)return this._catchHandler.handle({url:o,request:e,event:t});throw N})),g}findMatchingRoute({url:e,sameOrigin:t,request:o,event:s}){let a=this._routes.get(o.method)||[];for(let n of a){let i,c=n.match({url:e,sameOrigin:t,request:o,event:s});if(c)return i=c,(Array.isArray(i)&&i.length===0||c.constructor===Object&&Object.keys(c).length===0||typeof c=="boolean")&&(i=void 0),{route:n,params:i}}return{}}setDefaultHandler(e,t=L){this._defaultHandlerMap.set(t,E(e))}setCatchHandler(e){this._catchHandler=E(e)}registerRoute(e){this._routes.has(e.method)||this._routes.set(e.method,[]),this._routes.get(e.method).push(e)}unregisterRoute(e){if(!this._routes.has(e.method))throw new u("unregister-route-but-not-found-with-method",{method:e.method});let t=this._routes.get(e.method).indexOf(e);if(t>-1)this._routes.get(e.method).splice(t,1);else throw new u("unregister-route-route-not-registered")}};var $,V=()=>($||($=new C,$.addFetchListener(),$.addCacheListener()),$);function J(r,e,t){let o;if(typeof r=="string"){let a=new URL(r,location.href),n=({url:i})=>i.href===a.href;o=new h(n,e,t)}else if(r instanceof RegExp)o=new D(r,e,t);else if(typeof r=="function")o=new h(r,e,t);else if(r instanceof h)o=r;else throw new u("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});return V().registerRoute(o),o}try{self["workbox:strategies:7.0.0"]&&_()}catch{}function P(r){return typeof r=="string"?new Request(r):r}var O=class{constructor(e,t){this._cacheKeys={},Object.assign(this,t),this.event=t.event,this._strategy=e,this._handlerDeferred=new x,this._extendLifetimePromises=[],this._plugins=[...e.plugins],this._pluginStateMap=new Map;for(let o of this._plugins)this._pluginStateMap.set(o,{});this.event.waitUntil(this._handlerDeferred.promise)}async fetch(e){let{event:t}=this,o=P(e);if(o.mode==="navigate"&&t instanceof FetchEvent&&t.preloadResponse){let n=await t.preloadResponse;if(n)return n}let s=this.hasCallback("fetchDidFail")?o.clone():null;try{for(let n of this.iterateCallbacks("requestWillFetch"))o=await n({request:o.clone(),event:t})}catch(n){if(n instanceof Error)throw new u("plugin-error-request-will-fetch",{thrownErrorMessage:n.message})}let a=o.clone();try{let n;n=await fetch(o,o.mode==="navigate"?void 0:this._strategy.fetchOptions);for(let i of this.iterateCallbacks("fetchDidSucceed"))n=await i({event:t,request:a,response:n});return n}catch(n){throw s&&await this.runCallbacks("fetchDidFail",{error:n,event:t,originalRequest:s.clone(),request:a.clone()}),n}}async fetchAndCachePut(e){let t=await this.fetch(e),o=t.clone();return this.waitUntil(this.cachePut(e,o)),t}async cacheMatch(e){let t=P(e),o,{cacheName:s,matchOptions:a}=this._strategy,n=await this.getCacheKey(t,"read"),i=Object.assign(Object.assign({},a),{cacheName:s});o=await caches.match(n,i);for(let c of this.iterateCallbacks("cachedResponseWillBeUsed"))o=await c({cacheName:s,matchOptions:a,cachedResponse:o,request:n,event:this.event})||void 0;return o}async cachePut(e,t){let o=P(e);await b(0);let s=await this.getCacheKey(o,"write");if(!t)throw new u("cache-put-with-no-response",{url:U(s.url)});let a=await this._ensureResponseSafeToCache(t);if(!a)return!1;let{cacheName:n,matchOptions:i}=this._strategy,c=await self.caches.open(n),l=this.hasCallback("cacheDidUpdate"),g=l?await F(c,s.clone(),["__WB_REVISION__"],i):null;try{await c.put(s,l?a.clone():a)}catch(m){if(m instanceof Error)throw m.name==="QuotaExceededError"&&await I(),m}for(let m of this.iterateCallbacks("cacheDidUpdate"))await m({cacheName:n,oldResponse:g,newResponse:a.clone(),request:s,event:this.event});return!0}async getCacheKey(e,t){let o=`${e.url} | ${t}`;if(!this._cacheKeys[o]){let s=e;for(let a of this.iterateCallbacks("cacheKeyWillBeUsed"))s=P(await a({mode:t,request:s,event:this.event,params:this.params}));this._cacheKeys[o]=s}return this._cacheKeys[o]}hasCallback(e){for(let t of this._strategy.plugins)if(e in t)return!0;return!1}async runCallbacks(e,t){for(let o of this.iterateCallbacks(e))await o(t)}*iterateCallbacks(e){for(let t of this._strategy.plugins)if(typeof t[e]=="function"){let o=this._pluginStateMap.get(t);yield a=>{let n=Object.assign(Object.assign({},a),{state:o});return t[e](n)}}}waitUntil(e){return this._extendLifetimePromises.push(e),e}async doneWaiting(){let e;for(;e=this._extendLifetimePromises.shift();)await e}destroy(){this._handlerDeferred.resolve(null)}async _ensureResponseSafeToCache(e){let t=e,o=!1;for(let s of this.iterateCallbacks("cacheWillUpdate"))if(t=await s({request:this.request,response:t,event:this.event})||void 0,o=!0,!t)break;return o||t&&t.status!==200&&(t=void 0),t}};var f=class{constructor(e={}){this.cacheName=w.getRuntimeName(e.cacheName),this.plugins=e.plugins||[],this.fetchOptions=e.fetchOptions,this.matchOptions=e.matchOptions}handle(e){let[t]=this.handleAll(e);return t}handleAll(e){e instanceof FetchEvent&&(e={event:e,request:e.request});let t=e.event,o=typeof e.request=="string"?new Request(e.request):e.request,s="params"in e?e.params:void 0,a=new O(this,{event:t,request:o,params:s}),n=this._getResponse(a,o,t),i=this._awaitComplete(n,a,o,t);return[n,i]}async _getResponse(e,t,o){await e.runCallbacks("handlerWillStart",{event:o,request:t});let s;try{if(s=await this._handle(t,e),!s||s.type==="error")throw new u("no-response",{url:t.url})}catch(a){if(a instanceof Error){for(let n of e.iterateCallbacks("handlerDidError"))if(s=await n({error:a,event:o,request:t}),s)break}if(!s)throw a}for(let a of e.iterateCallbacks("handlerWillRespond"))s=await a({event:o,request:t,response:s});return s}async _awaitComplete(e,t,o,s){let a,n;try{a=await e}catch{}try{await t.runCallbacks("handlerDidRespond",{event:s,request:o,response:a}),await t.doneWaiting()}catch(i){i instanceof Error&&(n=i)}if(await t.runCallbacks("handlerDidComplete",{event:s,request:o,response:a,error:n}),t.destroy(),n)throw n}};var T=class extends f{async _handle(e,t){let o=[],s=await t.cacheMatch(e),a;if(!s)try{s=await t.fetchAndCachePut(e)}catch(n){n instanceof Error&&(a=n)}if(!s)throw new u("no-response",{url:e.url,error:a});return s}};var Re="my-cache";self.addEventListener("install",()=>{self.skipWaiting()});B();J(/\/(unlimited)?$/u,new T({cacheName:Re,plugins:[new v({maxAgeSeconds:1*60,maxEntries:8})]}));})(); diff --git a/apps/web/service-worker.ts b/apps/web/service-worker.ts index ce5827d..56df413 100644 --- a/apps/web/service-worker.ts +++ b/apps/web/service-worker.ts @@ -13,10 +13,8 @@ self.addEventListener('install', () => { clientsClaim(); -const routes = ['/', '/unlimited']; - registerRoute( - ({ url }) => routes.includes(url.pathname), + /\/(unlimited)?$/u, new CacheFirst({ cacheName, plugins: [