@prabhask5/stellar-engine 1.1.7 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -18
- package/dist/actions/remoteChange.d.ts +143 -18
- package/dist/actions/remoteChange.d.ts.map +1 -1
- package/dist/actions/remoteChange.js +182 -58
- package/dist/actions/remoteChange.js.map +1 -1
- package/dist/actions/truncateTooltip.d.ts +26 -12
- package/dist/actions/truncateTooltip.d.ts.map +1 -1
- package/dist/actions/truncateTooltip.js +89 -34
- package/dist/actions/truncateTooltip.js.map +1 -1
- package/dist/auth/crypto.d.ts +35 -8
- package/dist/auth/crypto.d.ts.map +1 -1
- package/dist/auth/crypto.js +38 -10
- package/dist/auth/crypto.js.map +1 -1
- package/dist/auth/deviceVerification.d.ts +236 -20
- package/dist/auth/deviceVerification.d.ts.map +1 -1
- package/dist/auth/deviceVerification.js +293 -40
- package/dist/auth/deviceVerification.js.map +1 -1
- package/dist/auth/displayUtils.d.ts +98 -0
- package/dist/auth/displayUtils.d.ts.map +1 -0
- package/dist/auth/displayUtils.js +133 -0
- package/dist/auth/displayUtils.js.map +1 -0
- package/dist/auth/loginGuard.d.ts +103 -16
- package/dist/auth/loginGuard.d.ts.map +1 -1
- package/dist/auth/loginGuard.js +163 -76
- package/dist/auth/loginGuard.js.map +1 -1
- package/dist/auth/offlineCredentials.d.ts +88 -24
- package/dist/auth/offlineCredentials.d.ts.map +1 -1
- package/dist/auth/offlineCredentials.js +114 -73
- package/dist/auth/offlineCredentials.js.map +1 -1
- package/dist/auth/offlineSession.d.ts +83 -9
- package/dist/auth/offlineSession.d.ts.map +1 -1
- package/dist/auth/offlineSession.js +104 -13
- package/dist/auth/offlineSession.js.map +1 -1
- package/dist/auth/resolveAuthState.d.ts +67 -9
- package/dist/auth/resolveAuthState.d.ts.map +1 -1
- package/dist/auth/resolveAuthState.js +125 -71
- package/dist/auth/resolveAuthState.js.map +1 -1
- package/dist/auth/singleUser.d.ts +390 -37
- package/dist/auth/singleUser.d.ts.map +1 -1
- package/dist/auth/singleUser.js +504 -103
- package/dist/auth/singleUser.js.map +1 -1
- package/dist/bin/install-pwa.d.ts +18 -2
- package/dist/bin/install-pwa.d.ts.map +1 -1
- package/dist/bin/install-pwa.js +2624 -77
- package/dist/bin/install-pwa.js.map +1 -1
- package/dist/config.d.ts +131 -15
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +87 -9
- package/dist/config.js.map +1 -1
- package/dist/conflicts.d.ts +246 -23
- package/dist/conflicts.d.ts.map +1 -1
- package/dist/conflicts.js +495 -46
- package/dist/conflicts.js.map +1 -1
- package/dist/data.d.ts +338 -18
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +385 -34
- package/dist/data.js.map +1 -1
- package/dist/database.d.ts +72 -14
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +120 -29
- package/dist/database.js.map +1 -1
- package/dist/debug.d.ts +77 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/debug.js +88 -1
- package/dist/debug.js.map +1 -1
- package/dist/deviceId.d.ts +38 -7
- package/dist/deviceId.d.ts.map +1 -1
- package/dist/deviceId.js +68 -10
- package/dist/deviceId.js.map +1 -1
- package/dist/engine.d.ts +175 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +756 -109
- package/dist/engine.js.map +1 -1
- package/dist/entries/actions.d.ts +13 -0
- package/dist/entries/actions.d.ts.map +1 -1
- package/dist/entries/actions.js +26 -1
- package/dist/entries/actions.js.map +1 -1
- package/dist/entries/auth.d.ts +15 -4
- package/dist/entries/auth.d.ts.map +1 -1
- package/dist/entries/auth.js +47 -4
- package/dist/entries/auth.js.map +1 -1
- package/dist/entries/config.d.ts +12 -0
- package/dist/entries/config.d.ts.map +1 -1
- package/dist/entries/config.js +18 -1
- package/dist/entries/config.js.map +1 -1
- package/dist/entries/kit.d.ts +11 -0
- package/dist/entries/kit.d.ts.map +1 -1
- package/dist/entries/kit.js +52 -2
- package/dist/entries/kit.js.map +1 -1
- package/dist/entries/stores.d.ts +11 -0
- package/dist/entries/stores.d.ts.map +1 -1
- package/dist/entries/stores.js +43 -2
- package/dist/entries/stores.js.map +1 -1
- package/dist/entries/types.d.ts +10 -1
- package/dist/entries/types.d.ts.map +1 -1
- package/dist/entries/types.js +10 -0
- package/dist/entries/types.js.map +1 -1
- package/dist/entries/utils.d.ts +6 -0
- package/dist/entries/utils.d.ts.map +1 -1
- package/dist/entries/utils.js +22 -1
- package/dist/entries/utils.js.map +1 -1
- package/dist/entries/vite.d.ts +17 -0
- package/dist/entries/vite.d.ts.map +1 -1
- package/dist/entries/vite.js +24 -1
- package/dist/entries/vite.js.map +1 -1
- package/dist/index.d.ts +32 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +166 -23
- package/dist/index.js.map +1 -1
- package/dist/kit/auth.d.ts +60 -5
- package/dist/kit/auth.d.ts.map +1 -1
- package/dist/kit/auth.js +45 -4
- package/dist/kit/auth.js.map +1 -1
- package/dist/kit/confirm.d.ts +93 -12
- package/dist/kit/confirm.d.ts.map +1 -1
- package/dist/kit/confirm.js +103 -16
- package/dist/kit/confirm.js.map +1 -1
- package/dist/kit/loads.d.ts +148 -23
- package/dist/kit/loads.d.ts.map +1 -1
- package/dist/kit/loads.js +136 -28
- package/dist/kit/loads.js.map +1 -1
- package/dist/kit/server.d.ts +142 -10
- package/dist/kit/server.d.ts.map +1 -1
- package/dist/kit/server.js +158 -15
- package/dist/kit/server.js.map +1 -1
- package/dist/kit/sw.d.ts +152 -23
- package/dist/kit/sw.d.ts.map +1 -1
- package/dist/kit/sw.js +182 -26
- package/dist/kit/sw.js.map +1 -1
- package/dist/queue.d.ts +274 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +556 -38
- package/dist/queue.js.map +1 -1
- package/dist/realtime.d.ts +241 -27
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +633 -109
- package/dist/realtime.js.map +1 -1
- package/dist/runtime/runtimeConfig.d.ts +91 -8
- package/dist/runtime/runtimeConfig.d.ts.map +1 -1
- package/dist/runtime/runtimeConfig.js +146 -19
- package/dist/runtime/runtimeConfig.js.map +1 -1
- package/dist/stores/authState.d.ts +150 -11
- package/dist/stores/authState.d.ts.map +1 -1
- package/dist/stores/authState.js +169 -17
- package/dist/stores/authState.js.map +1 -1
- package/dist/stores/network.d.ts +39 -0
- package/dist/stores/network.d.ts.map +1 -1
- package/dist/stores/network.js +169 -16
- package/dist/stores/network.js.map +1 -1
- package/dist/stores/remoteChanges.d.ts +327 -52
- package/dist/stores/remoteChanges.d.ts.map +1 -1
- package/dist/stores/remoteChanges.js +337 -75
- package/dist/stores/remoteChanges.js.map +1 -1
- package/dist/stores/sync.d.ts +130 -0
- package/dist/stores/sync.d.ts.map +1 -1
- package/dist/stores/sync.js +167 -7
- package/dist/stores/sync.js.map +1 -1
- package/dist/supabase/auth.d.ts +186 -46
- package/dist/supabase/auth.d.ts.map +1 -1
- package/dist/supabase/auth.js +238 -190
- package/dist/supabase/auth.js.map +1 -1
- package/dist/supabase/client.d.ts +79 -6
- package/dist/supabase/client.d.ts.map +1 -1
- package/dist/supabase/client.js +158 -15
- package/dist/supabase/client.js.map +1 -1
- package/dist/supabase/validate.d.ts +101 -7
- package/dist/supabase/validate.d.ts.map +1 -1
- package/dist/supabase/validate.js +117 -8
- package/dist/supabase/validate.js.map +1 -1
- package/dist/sw/build/vite-plugin.d.ts +55 -10
- package/dist/sw/build/vite-plugin.d.ts.map +1 -1
- package/dist/sw/build/vite-plugin.js +77 -18
- package/dist/sw/build/vite-plugin.js.map +1 -1
- package/dist/sw/sw.js +99 -44
- package/dist/types.d.ts +150 -26
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +12 -10
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +55 -13
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +83 -22
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/dist/auth/admin.d.ts +0 -12
- package/dist/auth/admin.d.ts.map +0 -1
- package/dist/auth/admin.js +0 -26
- package/dist/auth/admin.js.map +0 -1
- package/dist/auth/offlineLogin.d.ts +0 -34
- package/dist/auth/offlineLogin.d.ts.map +0 -1
- package/dist/auth/offlineLogin.js +0 -75
- package/dist/auth/offlineLogin.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../../../src/sw/build/vite-plugin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../../../src/sw/build/vite-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAWH;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAmED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,QAAQ;;;;EAyE1C"}
|
|
@@ -2,9 +2,30 @@
|
|
|
2
2
|
* @fileoverview Vite plugin that generates the service worker and asset manifest
|
|
3
3
|
* at build time. Projects import this instead of maintaining their own SW logic.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The plugin hooks into two Vite/Rollup lifecycle events:
|
|
6
|
+
* - **`buildStart`** — reads the compiled SW template from the stellar-engine
|
|
7
|
+
* package, patches in app-specific tokens, and writes `static/sw.js`.
|
|
8
|
+
* - **`closeBundle`** — after Rollup finishes writing chunks, scans the
|
|
9
|
+
* immutable output directory and writes `asset-manifest.json` listing
|
|
10
|
+
* all JS/CSS files for the service worker to precache.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // vite.config.ts
|
|
15
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
16
|
+
* import { stellarPWA } from '@prabhask5/stellar-engine/vite';
|
|
17
|
+
* import { defineConfig } from 'vite';
|
|
18
|
+
*
|
|
19
|
+
* export default defineConfig({
|
|
20
|
+
* plugins: [
|
|
21
|
+
* sveltekit(),
|
|
22
|
+
* stellarPWA({ prefix: 'myapp', name: 'My App' })
|
|
23
|
+
* ]
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @see {@link stellarPWA} for the main plugin factory
|
|
28
|
+
* @see {@link SWConfig} for configuration options
|
|
8
29
|
*/
|
|
9
30
|
import { readFileSync, writeFileSync, readdirSync, statSync, existsSync, mkdirSync } from 'fs';
|
|
10
31
|
import { resolve, join, dirname } from 'path';
|
|
@@ -18,6 +39,16 @@ import { createRequire } from 'module';
|
|
|
18
39
|
*
|
|
19
40
|
* Used after the build to enumerate all immutable assets so they can be written
|
|
20
41
|
* into the asset manifest consumed by the service worker.
|
|
42
|
+
*
|
|
43
|
+
* @param dir - The root directory to scan.
|
|
44
|
+
* @param files - Accumulator array (used internally for recursion).
|
|
45
|
+
* @returns A flat array of absolute file paths found under `dir`.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const allFiles = getAllFiles('/path/to/_app/immutable');
|
|
50
|
+
* // => ['/path/to/_app/immutable/chunks/foo.abc123.js', ...]
|
|
51
|
+
* ```
|
|
21
52
|
*/
|
|
22
53
|
function getAllFiles(dir, files = []) {
|
|
23
54
|
if (!existsSync(dir))
|
|
@@ -36,15 +67,26 @@ function getAllFiles(dir, files = []) {
|
|
|
36
67
|
}
|
|
37
68
|
/**
|
|
38
69
|
* Locates the compiled SW source (`dist/sw/sw.js`) within the installed package.
|
|
39
|
-
*
|
|
70
|
+
*
|
|
71
|
+
* Uses two resolution strategies:
|
|
72
|
+
* 1. **Relative resolution** — resolves relative to this file's compiled
|
|
73
|
+
* location in `dist/sw/build/vite-plugin.js`, navigating up to `dist/sw/sw.js`.
|
|
74
|
+
* Works for both installed packages and locally-linked development.
|
|
75
|
+
* 2. **`createRequire` fallback** — uses Node's module resolution to find
|
|
76
|
+
* the package root via `package.json`, then appends the known dist path.
|
|
77
|
+
*
|
|
78
|
+
* @returns The absolute path to the compiled `sw.js` source file.
|
|
79
|
+
*
|
|
80
|
+
* @throws {Error} If the SW source cannot be found via either strategy
|
|
81
|
+
* (will throw from the `readFileSync` call in the consumer).
|
|
40
82
|
*/
|
|
41
83
|
function findSwSource() {
|
|
42
|
-
|
|
84
|
+
/* Resolve relative to this file's location in dist/sw/build/vite-plugin.js */
|
|
43
85
|
const thisDir = dirname(fileURLToPath(import.meta.url));
|
|
44
86
|
const swPath = join(thisDir, '..', 'sw.js');
|
|
45
87
|
if (existsSync(swPath))
|
|
46
88
|
return swPath;
|
|
47
|
-
|
|
89
|
+
/* Fallback: use createRequire to resolve from the package */
|
|
48
90
|
const require = createRequire(import.meta.url);
|
|
49
91
|
const pkgDir = dirname(require.resolve('@prabhask5/stellar-engine/package.json'));
|
|
50
92
|
return join(pkgDir, 'dist', 'sw', 'sw.js');
|
|
@@ -53,32 +95,46 @@ function findSwSource() {
|
|
|
53
95
|
// VITE PLUGIN
|
|
54
96
|
// =============================================================================
|
|
55
97
|
/**
|
|
56
|
-
* Vite plugin that generates `static/sw.js` and `asset-manifest.json`
|
|
98
|
+
* Vite plugin factory that generates `static/sw.js` and `asset-manifest.json`
|
|
99
|
+
* at build time.
|
|
100
|
+
*
|
|
101
|
+
* **`buildStart` hook:**
|
|
102
|
+
* - Reads the compiled SW source from stellar-engine's `dist/sw/sw.js`.
|
|
103
|
+
* - Replaces placeholder tokens (`__SW_VERSION__`, `__SW_PREFIX__`, `__SW_NAME__`)
|
|
104
|
+
* with app-specific values and a unique version stamp (base-36 timestamp).
|
|
105
|
+
* - Strips the `export {};` that TypeScript adds (SW runs as a classic script).
|
|
106
|
+
* - Writes the final `static/sw.js`.
|
|
107
|
+
*
|
|
108
|
+
* **`closeBundle` hook:**
|
|
109
|
+
* - Scans SvelteKit's immutable output directory for JS and CSS files.
|
|
110
|
+
* - Writes `asset-manifest.json` to both `static/` and the build output
|
|
111
|
+
* directory so the service worker can precache all app chunks.
|
|
57
112
|
*
|
|
58
|
-
* -
|
|
59
|
-
*
|
|
60
|
-
* stamp, then writes the final `static/sw.js`.
|
|
113
|
+
* @param config - The {@link SWConfig} with `prefix` and `name` values.
|
|
114
|
+
* @returns A Vite plugin object with `name`, `buildStart`, and `closeBundle` hooks.
|
|
61
115
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* stellarPWA({ prefix: 'myapp', name: 'My App' })
|
|
119
|
+
* ```
|
|
65
120
|
*/
|
|
66
121
|
export function stellarPWA(config) {
|
|
67
122
|
return {
|
|
68
123
|
name: 'stellar-pwa',
|
|
69
124
|
/* ── buildStart — generate sw.js from compiled source ────────── */
|
|
70
125
|
buildStart() {
|
|
126
|
+
/* Generate a unique version stamp using base-36 timestamp */
|
|
71
127
|
const version = Date.now().toString(36);
|
|
72
128
|
const swSourcePath = findSwSource();
|
|
73
129
|
let swContent = readFileSync(swSourcePath, 'utf-8');
|
|
74
|
-
|
|
130
|
+
/* Replace placeholder tokens with app-specific values */
|
|
75
131
|
swContent = swContent
|
|
76
132
|
.replace(/__SW_VERSION__/g, version)
|
|
77
133
|
.replace(/__SW_PREFIX__/g, config.prefix)
|
|
78
134
|
.replace(/__SW_NAME__/g, config.name);
|
|
79
|
-
|
|
135
|
+
/* Strip the `export {};` that tsc adds (SW runs as a script, not a module) */
|
|
80
136
|
swContent = swContent.replace(/^export\s*\{\s*\}\s*;\s*$/m, '');
|
|
81
|
-
|
|
137
|
+
/* Ensure static/ directory exists */
|
|
82
138
|
const staticDir = resolve('static');
|
|
83
139
|
if (!existsSync(staticDir)) {
|
|
84
140
|
mkdirSync(staticDir, { recursive: true });
|
|
@@ -98,7 +154,8 @@ export function stellarPWA(config) {
|
|
|
98
154
|
const allFiles = getAllFiles(buildDir);
|
|
99
155
|
/**
|
|
100
156
|
* Only JS and CSS are worth precaching — images/fonts are better
|
|
101
|
-
* served on-demand via the SW's cache-first strategy
|
|
157
|
+
* served on-demand via the SW's cache-first strategy, keeping the
|
|
158
|
+
* manifest small and the initial precache fast.
|
|
102
159
|
*/
|
|
103
160
|
const assets = allFiles
|
|
104
161
|
.map((f) => f.replace(resolve('.svelte-kit/output/client'), ''))
|
|
@@ -110,7 +167,9 @@ export function stellarPWA(config) {
|
|
|
110
167
|
const manifestContent = JSON.stringify(manifest, null, 2);
|
|
111
168
|
/* Write to `static/` — available to the dev server and future builds */
|
|
112
169
|
writeFileSync(resolve('static/asset-manifest.json'), manifestContent);
|
|
113
|
-
/* Write to build output — static files are already copied before
|
|
170
|
+
/* Write to build output — static files are already copied before
|
|
171
|
+
* `closeBundle` runs, so the manifest must also land in the output
|
|
172
|
+
* directory for it to be served from the production build. */
|
|
114
173
|
const buildOutputPath = resolve('.svelte-kit/output/client/asset-manifest.json');
|
|
115
174
|
writeFileSync(buildOutputPath, manifestContent);
|
|
116
175
|
console.log(`[stellar-pwa] Generated asset manifest with ${assets.length} files`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../../../src/sw/build/vite-plugin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../../../src/sw/build/vite-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACp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every production build.
|
|
27
|
+
*
|
|
28
|
+
* @see {@link handleNavigationRequest} for HTML page caching (network-first)
|
|
29
|
+
* @see {@link handleImmutableAsset} for content-hashed asset caching (cache-first)
|
|
30
|
+
* @see {@link handleStaticAsset} for general static asset caching (cache-first)
|
|
31
|
+
* @see {@link backgroundPrecache} for offline-readiness precaching
|
|
32
|
+
* @see {@link cleanupOldAssets} for stale immutable asset removal
|
|
27
33
|
*/
|
|
28
34
|
// =============================================================================
|
|
29
35
|
// VERSIONING
|
|
30
36
|
// =============================================================================
|
|
31
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Build-stamped version string — updated automatically by the stellarPWA
|
|
39
|
+
* Vite plugin on each build. Used to key the shell cache and reported
|
|
40
|
+
* back to clients via the `GET_VERSION` message handler.
|
|
41
|
+
*/
|
|
32
42
|
const APP_VERSION = '__SW_VERSION__';
|
|
33
43
|
// =============================================================================
|
|
34
44
|
// CACHE NAMING
|
|
35
45
|
// =============================================================================
|
|
36
46
|
/**
|
|
37
47
|
* Persistent cache for immutable assets (`/_app/immutable/*`).
|
|
38
|
-
* These files contain content hashes
|
|
39
|
-
* NOT cleared on deploy — assets accumulate
|
|
48
|
+
* These files contain content hashes in their filenames, making them safe
|
|
49
|
+
* to cache indefinitely. NOT cleared on deploy — assets accumulate across
|
|
50
|
+
* builds and are pruned by {@link cleanupOldAssets} when triggered.
|
|
40
51
|
*/
|
|
41
52
|
const ASSET_CACHE = '__SW_PREFIX__-assets-v1';
|
|
42
53
|
/**
|
|
43
54
|
* Versioned cache for the app shell (HTML, manifest, icons) and other
|
|
44
55
|
* static assets. Re-created on each deploy; old versions are deleted
|
|
45
|
-
* during the `activate` event.
|
|
56
|
+
* during the `activate` event so only one shell cache exists at a time.
|
|
46
57
|
*/
|
|
47
58
|
const SHELL_CACHE = '__SW_PREFIX__-shell-' + APP_VERSION;
|
|
48
59
|
// =============================================================================
|
|
@@ -51,6 +62,9 @@ const SHELL_CACHE = '__SW_PREFIX__-shell-' + APP_VERSION;
|
|
|
51
62
|
/**
|
|
52
63
|
* Core app shell resources to precache during the `install` event.
|
|
53
64
|
* These are the minimum files needed for the app to render offline.
|
|
65
|
+
*
|
|
66
|
+
* Note: The root HTML (`/`) is cached separately in the install handler
|
|
67
|
+
* because its failure should abort the installation entirely.
|
|
54
68
|
*/
|
|
55
69
|
const PRECACHE_ASSETS = [
|
|
56
70
|
'/manifest.json',
|
|
@@ -65,7 +79,7 @@ const PRECACHE_ASSETS = [
|
|
|
65
79
|
/**
|
|
66
80
|
* Install handler — precaches the minimal app shell.
|
|
67
81
|
*
|
|
68
|
-
* Strategy
|
|
82
|
+
* **Strategy:**
|
|
69
83
|
* 1. The root HTML (`/`) is **required** — if it fails, install fails.
|
|
70
84
|
* Better to stay on the working old SW than activate with no cached HTML.
|
|
71
85
|
* 2. Other shell assets (icons, manifest) are **optional** — failures
|
|
@@ -74,6 +88,8 @@ const PRECACHE_ASSETS = [
|
|
|
74
88
|
* "update available" prompt.
|
|
75
89
|
* 4. Auto-promotes via `skipWaiting()` after 5 minutes as a fallback for
|
|
76
90
|
* iOS PWA where the update prompt may never be interacted with.
|
|
91
|
+
*
|
|
92
|
+
* @param event - The `install` {@link ExtendableEvent}.
|
|
77
93
|
*/
|
|
78
94
|
self.addEventListener('install', (event) => {
|
|
79
95
|
console.log(`[SW] Installing version: ${APP_VERSION}`);
|
|
@@ -106,14 +122,16 @@ self.addEventListener('install', (event) => {
|
|
|
106
122
|
/**
|
|
107
123
|
* Activate handler — cleans up stale caches and claims all clients.
|
|
108
124
|
*
|
|
109
|
-
* Deletes
|
|
125
|
+
* **Deletes:**
|
|
110
126
|
* - Old versioned shell caches (e.g., `__SW_PREFIX__-shell-<old-version>`)
|
|
111
127
|
* - The legacy `__SW_PREFIX__-cache-v1` cache (one-time migration from the
|
|
112
128
|
* original single-cache strategy)
|
|
113
129
|
*
|
|
114
|
-
* Keeps
|
|
130
|
+
* **Keeps:**
|
|
115
131
|
* - `ASSET_CACHE` — immutable assets persist across versions
|
|
116
132
|
* - `SHELL_CACHE` — the current deploy's shell cache
|
|
133
|
+
*
|
|
134
|
+
* @param event - The `activate` {@link ExtendableEvent}.
|
|
117
135
|
*/
|
|
118
136
|
self.addEventListener('activate', (event) => {
|
|
119
137
|
console.log(`[SW] Activating version: ${APP_VERSION}`);
|
|
@@ -144,14 +162,16 @@ self.addEventListener('activate', (event) => {
|
|
|
144
162
|
/**
|
|
145
163
|
* Fetch handler — routes requests to the appropriate caching strategy.
|
|
146
164
|
*
|
|
147
|
-
* Routing logic (in priority order):
|
|
165
|
+
* **Routing logic** (in priority order):
|
|
148
166
|
* 1. Skip non-GET requests (mutations should always hit the network)
|
|
149
167
|
* 2. Skip external origins (only cache same-origin resources)
|
|
150
168
|
* 3. Skip `/api/*` routes (backend data — never cache)
|
|
151
|
-
* 4. Navigation requests
|
|
152
|
-
* 5. Immutable assets
|
|
153
|
-
* 6. Static assets
|
|
154
|
-
* 7. Everything else
|
|
169
|
+
* 4. Navigation requests --> {@link handleNavigationRequest} (network-first)
|
|
170
|
+
* 5. Immutable assets --> {@link handleImmutableAsset} (cache-first, permanent)
|
|
171
|
+
* 6. Static assets --> {@link handleStaticAsset} (cache-first)
|
|
172
|
+
* 7. Everything else --> {@link handleOtherRequest} (network-first)
|
|
173
|
+
*
|
|
174
|
+
* @param event - The {@link FetchEvent} to handle.
|
|
155
175
|
*/
|
|
156
176
|
self.addEventListener('fetch', (event) => {
|
|
157
177
|
/* Only intercept GET requests — let POST/PUT/DELETE go straight to network */
|
|
@@ -190,8 +210,17 @@ self.addEventListener('fetch', (event) => {
|
|
|
190
210
|
* Determines whether a given pathname looks like a static asset
|
|
191
211
|
* (scripts, styles, images, fonts, data files).
|
|
192
212
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
213
|
+
* Matches by file extension or by the `/_app/` prefix (SvelteKit's
|
|
214
|
+
* client-side output directory).
|
|
215
|
+
*
|
|
216
|
+
* @param pathname - The URL pathname to test (e.g., `/_app/version.json`).
|
|
217
|
+
* @returns `true` if the path matches a known static-asset extension.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* isStaticAsset('/icon-192.png'); // true
|
|
222
|
+
* isStaticAsset('/api/config'); // false
|
|
223
|
+
* ```
|
|
195
224
|
*/
|
|
196
225
|
function isStaticAsset(pathname) {
|
|
197
226
|
return (pathname.startsWith('/_app/') ||
|
|
@@ -214,13 +243,17 @@ function isStaticAsset(pathname) {
|
|
|
214
243
|
/**
|
|
215
244
|
* Handles HTML navigation requests with a **network-first** strategy.
|
|
216
245
|
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
246
|
+
* **Flow:**
|
|
247
|
+
* 1. Attempt a network fetch with a 3-second timeout (abort via `AbortController`)
|
|
248
|
+
* 2. If successful --> cache the response as `/` and return it
|
|
249
|
+
* 3. If failed --> serve the cached root HTML for offline use
|
|
250
|
+
* 4. If nothing cached --> return a minimal offline fallback page
|
|
221
251
|
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
252
|
+
* The 3-second timeout prevents the user from staring at a blank screen
|
|
253
|
+
* on flaky connections while still preferring fresh content.
|
|
254
|
+
*
|
|
255
|
+
* @param request - The navigation `Request` object.
|
|
256
|
+
* @returns A `Response` (from network, cache, or inline fallback).
|
|
224
257
|
*/
|
|
225
258
|
async function handleNavigationRequest(request) {
|
|
226
259
|
const cache = await caches.open(SHELL_CACHE);
|
|
@@ -260,12 +293,15 @@ async function handleNavigationRequest(request) {
|
|
|
260
293
|
/**
|
|
261
294
|
* Handles requests for immutable assets (`/_app/immutable/*`).
|
|
262
295
|
*
|
|
263
|
-
* Strategy
|
|
296
|
+
* **Strategy:** cache-first, NEVER revalidate. These files have content
|
|
264
297
|
* hashes baked into their filenames — if the content changes, the filename
|
|
265
298
|
* changes, so a cached version is always correct.
|
|
266
299
|
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
300
|
+
* Uses `ASSET_CACHE` which persists across SW versions (not cleared on
|
|
301
|
+
* deploy). Old entries are pruned by {@link cleanupOldAssets}.
|
|
302
|
+
*
|
|
303
|
+
* @param request - The `Request` for an immutable asset.
|
|
304
|
+
* @returns The cached `Response`, or a freshly-fetched one (then cached).
|
|
269
305
|
*/
|
|
270
306
|
async function handleImmutableAsset(request) {
|
|
271
307
|
const cache = await caches.open(ASSET_CACHE);
|
|
@@ -294,12 +330,12 @@ async function handleImmutableAsset(request) {
|
|
|
294
330
|
* Handles requests for general static assets (non-immutable JS, CSS, images,
|
|
295
331
|
* fonts, JSON files).
|
|
296
332
|
*
|
|
297
|
-
* Strategy
|
|
333
|
+
* **Strategy:** cache-first, NO background revalidation. This saves
|
|
298
334
|
* bandwidth — the shell cache is versioned per deploy, so stale assets
|
|
299
335
|
* are cleaned up automatically when the new SW activates.
|
|
300
336
|
*
|
|
301
|
-
* @param request
|
|
302
|
-
* @returns The cached `Response`, or a freshly-fetched one (then cached)
|
|
337
|
+
* @param request - The `Request` for a static asset.
|
|
338
|
+
* @returns The cached `Response`, or a freshly-fetched one (then cached).
|
|
303
339
|
*/
|
|
304
340
|
async function handleStaticAsset(request) {
|
|
305
341
|
const cache = await caches.open(SHELL_CACHE);
|
|
@@ -327,13 +363,14 @@ async function handleStaticAsset(request) {
|
|
|
327
363
|
/**
|
|
328
364
|
* Handles all other same-origin GET requests with a **network-first** strategy.
|
|
329
365
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
366
|
+
* **Flow:**
|
|
367
|
+
* 1. Try the network
|
|
368
|
+
* 2. If successful --> cache and return
|
|
369
|
+
* 3. If failed --> return cached version
|
|
370
|
+
* 4. If nothing cached --> return a 503 "Offline" response
|
|
334
371
|
*
|
|
335
|
-
* @param request
|
|
336
|
-
* @returns A `Response` from network or cache
|
|
372
|
+
* @param request - The `Request` object.
|
|
373
|
+
* @returns A `Response` from network or cache.
|
|
337
374
|
*/
|
|
338
375
|
async function handleOtherRequest(request) {
|
|
339
376
|
const cache = await caches.open(SHELL_CACHE);
|
|
@@ -359,7 +396,7 @@ async function handleOtherRequest(request) {
|
|
|
359
396
|
* cached. This makes the entire app available offline without blocking the
|
|
360
397
|
* install event.
|
|
361
398
|
*
|
|
362
|
-
* Key
|
|
399
|
+
* **Key behaviours:**
|
|
363
400
|
* - Fetches the manifest with a cache-busting query param (`?_=<timestamp>`)
|
|
364
401
|
* - Checks both `ASSET_CACHE` and `SHELL_CACHE` to avoid redundant downloads
|
|
365
402
|
* - Downloads in batches of 5 with a 50 ms pause between batches to avoid
|
|
@@ -367,6 +404,10 @@ async function handleOtherRequest(request) {
|
|
|
367
404
|
* - Notifies all open windows with `PRECACHE_COMPLETE` when done
|
|
368
405
|
*
|
|
369
406
|
* Triggered by sending `{ type: 'PRECACHE_ALL' }` to the service worker.
|
|
407
|
+
*
|
|
408
|
+
* @returns A promise that resolves when precaching is complete (or fails).
|
|
409
|
+
*
|
|
410
|
+
* @see {@link cleanupOldAssets} for removing assets no longer in the manifest
|
|
370
411
|
*/
|
|
371
412
|
async function backgroundPrecache() {
|
|
372
413
|
try {
|
|
@@ -389,6 +430,7 @@ async function backgroundPrecache() {
|
|
|
389
430
|
/* ── Determine which assets still need caching ────────────────── */
|
|
390
431
|
const uncached = [];
|
|
391
432
|
for (const url of assets) {
|
|
433
|
+
/* Route to the correct cache based on whether the asset is immutable */
|
|
392
434
|
const isImmutable = url.includes('/_app/immutable/');
|
|
393
435
|
const cache = isImmutable ? assetCache : shellCache;
|
|
394
436
|
const cached = await cache.match(url);
|
|
@@ -442,6 +484,8 @@ async function backgroundPrecache() {
|
|
|
442
484
|
* versioned and cleaned during the `activate` event.
|
|
443
485
|
*
|
|
444
486
|
* Triggered by sending `{ type: 'CLEANUP_OLD' }` to the service worker.
|
|
487
|
+
*
|
|
488
|
+
* @returns A promise that resolves when cleanup is complete.
|
|
445
489
|
*/
|
|
446
490
|
async function cleanupOldAssets() {
|
|
447
491
|
try {
|
|
@@ -478,7 +522,12 @@ async function cleanupOldAssets() {
|
|
|
478
522
|
/**
|
|
479
523
|
* Broadcasts a message to all open windows/tabs.
|
|
480
524
|
*
|
|
481
|
-
* @param message
|
|
525
|
+
* @param message - The message object to send (e.g., `{ type: 'PRECACHE_COMPLETE', ... }`).
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```ts
|
|
529
|
+
* notifyClients({ type: 'PRECACHE_COMPLETE', cached: 42, total: 50 });
|
|
530
|
+
* ```
|
|
482
531
|
*/
|
|
483
532
|
function notifyClients(message) {
|
|
484
533
|
self.clients.matchAll({ type: 'window' }).then((clients) => {
|
|
@@ -496,7 +545,7 @@ function notifyClients(message) {
|
|
|
496
545
|
* styling — it will be precached and served automatically instead of
|
|
497
546
|
* this bare-bones fallback.
|
|
498
547
|
*
|
|
499
|
-
* @returns An unstyled HTML string for the offline fallback
|
|
548
|
+
* @returns An unstyled HTML string for the offline fallback.
|
|
500
549
|
*/
|
|
501
550
|
function getOfflineHTML() {
|
|
502
551
|
return `<!DOCTYPE html>
|
|
@@ -519,13 +568,15 @@ function getOfflineHTML() {
|
|
|
519
568
|
/**
|
|
520
569
|
* Listens for messages from the app's client-side code.
|
|
521
570
|
*
|
|
522
|
-
* Supported message types
|
|
523
|
-
* - `SKIP_WAITING`
|
|
524
|
-
* - `GET_VERSION`
|
|
525
|
-
* - `PRECACHE_ALL`
|
|
526
|
-
* - `CLEANUP_OLD`
|
|
527
|
-
* - `CACHE_URLS`
|
|
528
|
-
* - `GET_CACHE_STATUS`
|
|
571
|
+
* **Supported message types:**
|
|
572
|
+
* - `SKIP_WAITING` --> Immediately activate the waiting SW (user accepted update)
|
|
573
|
+
* - `GET_VERSION` --> Responds with the current `APP_VERSION` via `MessagePort`
|
|
574
|
+
* - `PRECACHE_ALL` --> Triggers {@link backgroundPrecache} to download all assets
|
|
575
|
+
* - `CLEANUP_OLD` --> Triggers {@link cleanupOldAssets} to remove stale cache entries
|
|
576
|
+
* - `CACHE_URLS` --> Caches a specific list of URLs (used for route prefetching)
|
|
577
|
+
* - `GET_CACHE_STATUS` --> Responds with cache completeness info via `MessagePort`
|
|
578
|
+
*
|
|
579
|
+
* @param event - The {@link ExtendableMessageEvent} from a client.
|
|
529
580
|
*/
|
|
530
581
|
self.addEventListener('message', (event) => {
|
|
531
582
|
const { type } = event.data || {};
|
|
@@ -552,6 +603,7 @@ self.addEventListener('message', (event) => {
|
|
|
552
603
|
const shellCachePromise = caches.open(SHELL_CACHE);
|
|
553
604
|
Promise.all([assetCachePromise, shellCachePromise]).then(([ac, sc]) => {
|
|
554
605
|
urls.forEach((url) => {
|
|
606
|
+
/* Route each URL to the correct cache based on immutability */
|
|
555
607
|
const isImmutable = url.includes('/_app/immutable/');
|
|
556
608
|
const cache = isImmutable ? ac : sc;
|
|
557
609
|
cache.add(url).catch(() => { });
|
|
@@ -572,11 +624,14 @@ self.addEventListener('message', (event) => {
|
|
|
572
624
|
* Computes the current cache completeness by comparing cached entries
|
|
573
625
|
* against the asset manifest.
|
|
574
626
|
*
|
|
575
|
-
*
|
|
627
|
+
* Attempts to find the manifest in cache first (for offline use), then
|
|
628
|
+
* falls back to a network fetch.
|
|
629
|
+
*
|
|
630
|
+
* @returns An object describing cache readiness:
|
|
576
631
|
* - `cached` — Number of manifest assets currently in cache
|
|
577
632
|
* - `total` — Total number of assets in the manifest
|
|
578
633
|
* - `ready` — `true` if every asset is cached (full offline support)
|
|
579
|
-
* - `version` — The manifest version string
|
|
634
|
+
* - `version` — The manifest version string (if available)
|
|
580
635
|
* - `error` — Error message string (only present if something went wrong)
|
|
581
636
|
*/
|
|
582
637
|
async function getCacheStatus() {
|