| /* AmanPay service worker β offline app shell. | |
| Network-first for the document/API, cache-first for static assets. */ | |
| const CACHE = "amanpay-v1"; | |
| const SHELL = ["/", "/manifest.json"]; | |
| self.addEventListener("install", (e) => { | |
| e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting())); | |
| }); | |
| self.addEventListener("activate", (e) => { | |
| e.waitUntil( | |
| caches.keys().then((keys) => | |
| Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))) | |
| ).then(() => self.clients.claim()) | |
| ); | |
| }); | |
| self.addEventListener("fetch", (e) => { | |
| const req = e.request; | |
| if (req.method !== "GET") return; // never cache POSTs (payments) | |
| const url = new URL(req.url); | |
| // API + biometric calls always go to the network (fresh, never stale). | |
| if (/^\/(health|wallet|unified|authenticate|enroll|verify|voice|liveness|webauthn|passkey|report-card|users)/.test(url.pathname)) { | |
| return; // default browser handling | |
| } | |
| e.respondWith( | |
| fetch(req).then((res) => { | |
| const copy = res.clone(); | |
| caches.open(CACHE).then((c) => c.put(req, copy)).catch(() => {}); | |
| return res; | |
| }).catch(() => caches.match(req).then((r) => r || caches.match("/"))) | |
| ); | |
| }); | |