// The build supplies a content-based release and the project's public shell. const CACHE='dm-__PROJECT__-__RELEASE__'; const SHELL=__SHELL__; const OFFLINE=__OFFLINE__; const safe=request=>{const url=new URL(request.url);return request.method==='GET'&&url.origin===self.location.origin&&!url.search&&!/^\/(api|sso)(\/|$)/.test(url.pathname)&&!['/authorize','/health'].includes(url.pathname);}; self.addEventListener('install',event=>{event.waitUntil((async()=>{const cache=await caches.open(CACHE);await cache.addAll(['/_dm/offline','/_dm/platform.css','/_dm/platform.js','/_dm/icon-192.png',...SHELL].map(path=>new Request(new URL(path,self.location.origin),{credentials:'omit'})));})());}); self.addEventListener('message',event=>{if(event.data?.type==='SKIP_WAITING')event.waitUntil(self.skipWaiting());}); self.addEventListener('activate',event=>{event.waitUntil((async()=>{for(const key of await caches.keys())if((key.startsWith('dm-__PROJECT__-')||key.startsWith('__PROJECT__-'))&&key!==CACHE)await caches.delete(key);await self.clients.claim();})());}); self.addEventListener('fetch',event=>{ const request=event.request;if(!safe(request))return; const path=new URL(request.url).pathname; // Never store account pages or personalized application responses. const publicAsset=path.startsWith('/_dm/')||SHELL.includes(path); if(!publicAsset&&request.mode!=='navigate')return; event.respondWith((async()=>{try{const response=await fetch(request);if(response.ok&&publicAsset&&!response.headers.get('Cache-Control')?.includes('no-store')&&!response.headers.has('Set-Cookie')){const cache=await caches.open(CACHE);await cache.put(request,response.clone());}return response;}catch{const cache=await caches.open(CACHE);const cached=publicAsset?await cache.match(request):null;if(cached)return cached;if(request.mode==='navigate')return (OFFLINE&&await cache.match('/'))||await cache.match('/_dm/offline');return Response.error();}})()); });