@plasius/offline-cache 0.1.8 → 0.1.10
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/CHANGELOG.md +35 -0
- package/README.md +45 -3
- package/dist/index.cjs +52 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -38
- package/dist/index.js.map +1 -1
- package/docs/adrs/adr-0002-hosted-oidc-package-publication.md +2 -1
- package/docs/adrs/adr-0003-approved-self-hosted-ci.md +67 -0
- package/docs/adrs/adr-0004-worker-consent-lifecycle.md +32 -0
- package/docs/adrs/index.md +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- **Added**
|
|
6
|
+
- (placeholder)
|
|
7
|
+
|
|
8
|
+
- **Changed**
|
|
9
|
+
- (placeholder)
|
|
10
|
+
|
|
11
|
+
- **Fixed**
|
|
12
|
+
- (placeholder)
|
|
13
|
+
|
|
14
|
+
- **Security**
|
|
15
|
+
- (placeholder)
|
|
16
|
+
|
|
17
|
+
## [0.1.10] - 2026-10-24
|
|
18
|
+
|
|
19
|
+
- Preserve successful online responses when optional worker cache operations reject, with controlled offline errors and unchanged consent/no-store safeguards (Task #27).
|
|
20
|
+
|
|
21
|
+
- **Added**
|
|
22
|
+
- (placeholder)
|
|
23
|
+
|
|
24
|
+
- **Changed**
|
|
25
|
+
- (placeholder)
|
|
26
|
+
|
|
27
|
+
- **Fixed**
|
|
28
|
+
- (placeholder)
|
|
29
|
+
|
|
30
|
+
- **Security**
|
|
31
|
+
- (placeholder)
|
|
32
|
+
|
|
33
|
+
## [0.1.9] - 2026-10-21
|
|
34
|
+
|
|
35
|
+
- Restore approved self-hosted, trusted-push CI with isolated runner admission,
|
|
36
|
+
clean installation, bounded jobs and final package-manifest verification.
|
|
37
|
+
|
|
5
38
|
- **Added**
|
|
6
39
|
- (placeholder)
|
|
7
40
|
|
|
@@ -172,3 +205,5 @@
|
|
|
172
205
|
[0.1.6]: https://github.com/Plasius-LTD/offline-cache/releases/tag/v0.1.6
|
|
173
206
|
[0.1.7]: https://github.com/Plasius-LTD/offline-cache/releases/tag/v0.1.7
|
|
174
207
|
[0.1.8]: https://github.com/Plasius-LTD/offline-cache/releases/tag/v0.1.8
|
|
208
|
+
[0.1.9]: https://github.com/Plasius-LTD/offline-cache/releases/tag/v0.1.9
|
|
209
|
+
[0.1.10]: https://github.com/Plasius-LTD/offline-cache/releases/tag/v0.1.10
|
package/README.md
CHANGED
|
@@ -72,13 +72,37 @@ npm run pack:check
|
|
|
72
72
|
## Release integrity
|
|
73
73
|
|
|
74
74
|
CI keeps the administrative contributor registry outside Git and npm package
|
|
75
|
-
artifacts using exact, case-normalised path checks. CI runs
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
artifacts using exact, case-normalised path checks. CI runs only for canonical
|
|
76
|
+
repository branch pushes on `Public CI - Quarantined` with literal
|
|
77
|
+
`[self-hosted, Linux, X64]` labels. Pull-request and manual triggers are absent.
|
|
78
|
+
Both jobs check the repository and event, have bounded timeouts, persist no
|
|
79
|
+
checkout credentials and disable package-manager caching. There is no hosted CI
|
|
80
|
+
fallback or caller-selected runner. Clean installation, lint, types, runtime
|
|
81
|
+
audit, build, 80% line coverage and final package-manifest checks remain required.
|
|
78
82
|
Publication uses the GitHub-hosted `production` job with Node 24 and a pinned
|
|
79
83
|
npm 11.6.2 client. It is token-free and proceeds only while the prepared SHA
|
|
80
84
|
is the exact `main` head after successful push-triggered CI. Do not dispatch CD
|
|
81
85
|
until the npm trusted-publisher binding is verified.
|
|
86
|
+
|
|
87
|
+
An authorised runner-group operator must review each source branch before adding
|
|
88
|
+
only `Plasius-LTD/offline-cache/.github/workflows/ci.yml@refs/heads/<branch>`
|
|
89
|
+
to the existing workflow allowlist. Preserve repository selection, public access
|
|
90
|
+
policy and unrelated refs. Keep the existing `main` admission.
|
|
91
|
+
Review the release-preparation App's exact metadata diff before admitting its
|
|
92
|
+
branch. Run metadata CI and required reviews/checks before merge where repository
|
|
93
|
+
policy holds the PR open. Existing preparation can auto-merge under a policy
|
|
94
|
+
without required checks; record that accurately and verify successful metadata
|
|
95
|
+
and exact-main CI before publication. If the App deleted the branch, restore only
|
|
96
|
+
its reviewed, unchanged PR-head SHA to the same absent branch by an ordinary
|
|
97
|
+
non-force push so its queued CI can execute. Remove temporary admissions and
|
|
98
|
+
branches after successful checks. Missing access is a blocker; never widen
|
|
99
|
+
admission with wildcards or change production/protection settings to pass.
|
|
100
|
+
|
|
101
|
+
The remote `platform.public-artifact-integrity.enabled` flag controls restoration
|
|
102
|
+
of public distribution. Mandatory integrity checks remain unconditional when it
|
|
103
|
+
is enabled, disabled or rolled back. Rollback disables the affected workflow or
|
|
104
|
+
distribution channel and removes temporary admissions; it never restores the
|
|
105
|
+
administrative path or hosted CI. No capability is introduced.
|
|
82
106
|
<!-- END PLASIUS RELEASE INTEGRITY -->
|
|
83
107
|
|
|
84
108
|
## Consent-aware workers
|
|
@@ -103,3 +127,21 @@ paths always win; host and generated worker preserve regex source and flags.
|
|
|
103
127
|
`warmAssetPack` propagates its `signal` to downloads and rejects with the abort
|
|
104
128
|
reason before further cache access after cancellation, including late responses.
|
|
105
129
|
Hosts should treat consent cancellation as a normal stop, not a renderer failure.
|
|
130
|
+
|
|
131
|
+
## Optional storage failures
|
|
132
|
+
|
|
133
|
+
Generated workers keep online responses usable when CacheStorage open, read,
|
|
134
|
+
write or eviction operations reject, including quota failures. A failed read is a
|
|
135
|
+
cache miss; a failed update cannot replace a successful network response with
|
|
136
|
+
stale content. Each intercepted request makes at most one network attempt. When
|
|
137
|
+
that attempt fails, only a currently permitted cached response/navigation fallback
|
|
138
|
+
may be returned; otherwise the worker returns `Response.error()`.
|
|
139
|
+
|
|
140
|
+
No-store entries remain ineligible even if eviction fails. Consent denial,
|
|
141
|
+
expiry and withdrawal still prohibit cache reuse/updates. Storage failures do not
|
|
142
|
+
produce provider-error logs or change the host's cleanup acknowledgement duties.
|
|
143
|
+
This handles rejected storage operations; permanently pending operations and
|
|
144
|
+
browser fetch lifetimes are unchanged. Stale refresh event-lifetime work is
|
|
145
|
+
tracked separately. Hosts continue to compose stored
|
|
146
|
+
`site.privacy.optional-processing.enabled` / `site.offline-cache.enabled` with
|
|
147
|
+
visitor consent, and withdraw/unregister the worker when disabled.
|
package/dist/index.cjs
CHANGED
|
@@ -486,63 +486,77 @@ self.addEventListener("activate", (event) => {
|
|
|
486
486
|
|
|
487
487
|
async function openPermittedCache(cacheName, generation) {
|
|
488
488
|
if (!permitted(generation)) return null;
|
|
489
|
-
|
|
490
|
-
|
|
489
|
+
try {
|
|
490
|
+
const cache = await caches.open(cacheName);
|
|
491
|
+
if (permitted(generation)) return cache;
|
|
491
492
|
await caches.delete(cacheName);
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
493
|
+
} catch { /* Optional storage must not prevent online delivery. */ }
|
|
494
|
+
return null;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
async function evictOptionalEntry(cache, request) {
|
|
498
|
+
try { await cache.delete(request); } catch { /* Never reuse an ineligible entry. */ }
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
async function readPermittedEntry(cache, request, generation) {
|
|
502
|
+
if (!cache || !permitted(generation)) return undefined;
|
|
503
|
+
try {
|
|
504
|
+
const candidate = await cache.match(request);
|
|
505
|
+
if (!permitted(generation)) return undefined;
|
|
506
|
+
if (candidate && !hasNoStore(candidate.headers)) return candidate;
|
|
507
|
+
if (candidate) await evictOptionalEntry(cache, request);
|
|
508
|
+
} catch { /* A failed read is an optional cache miss. */ }
|
|
509
|
+
return undefined;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
async function updateOptionalEntry(cache, request, response, generation) {
|
|
513
|
+
if (!cache || !permitted(generation)) return;
|
|
514
|
+
try {
|
|
515
|
+
if (hasNoStore(response.headers)) await evictOptionalEntry(cache, request);
|
|
516
|
+
else if (response.ok) await cache.put(request, response.clone());
|
|
517
|
+
} catch { /* Quota and other storage failures do not replace the response. */ }
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
async function fetchOrError(request) {
|
|
521
|
+
try { return await fetch(request); } catch { return Response.error(); }
|
|
495
522
|
}
|
|
496
523
|
|
|
497
524
|
async function cacheFirst(request, cacheName, generation) {
|
|
498
525
|
const cache = await openPermittedCache(cacheName, generation);
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if (cached) await cache.delete(request);
|
|
504
|
-
const response = await fetch(request);
|
|
505
|
-
if (!permitted(generation)) return response;
|
|
506
|
-
if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());
|
|
507
|
-
if (hasNoStore(response.headers)) await cache.delete(request);
|
|
526
|
+
const cached = await readPermittedEntry(cache, request, generation);
|
|
527
|
+
if (cached && permitted(generation)) return cached;
|
|
528
|
+
const response = await fetchOrError(request);
|
|
529
|
+
await updateOptionalEntry(cache, request, response, generation);
|
|
508
530
|
return response;
|
|
509
531
|
}
|
|
510
532
|
|
|
511
533
|
async function staleWhileRevalidate(request, cacheName, generation) {
|
|
512
534
|
const cache = await openPermittedCache(cacheName, generation);
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
const cached = candidate && !hasNoStore(candidate.headers) ? candidate : undefined;
|
|
517
|
-
if (candidate && !cached) await cache.delete(request);
|
|
518
|
-
const refresh = fetch(request).then(async response => {
|
|
519
|
-
if (!permitted(generation)) return response;
|
|
520
|
-
if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());
|
|
521
|
-
if (hasNoStore(response.headers)) await cache.delete(request);
|
|
535
|
+
const cached = await readPermittedEntry(cache, request, generation);
|
|
536
|
+
const refresh = fetchOrError(request).then(async response => {
|
|
537
|
+
await updateOptionalEntry(cache, request, response, generation);
|
|
522
538
|
return response;
|
|
523
539
|
});
|
|
524
|
-
if (cached
|
|
525
|
-
|
|
540
|
+
if (cached && permitted(generation)) {
|
|
541
|
+
void refresh.catch(() => undefined);
|
|
542
|
+
return cached;
|
|
543
|
+
}
|
|
544
|
+
return refresh;
|
|
526
545
|
}
|
|
527
546
|
|
|
528
547
|
async function networkFirst(request, cacheName, generation) {
|
|
529
548
|
const cache = await openPermittedCache(cacheName, generation);
|
|
530
|
-
|
|
549
|
+
let response;
|
|
531
550
|
try {
|
|
532
|
-
|
|
533
|
-
if (!permitted(generation)) return response;
|
|
534
|
-
if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());
|
|
535
|
-
if (hasNoStore(response.headers)) await cache.delete(request);
|
|
536
|
-
return response;
|
|
551
|
+
response = await fetch(request);
|
|
537
552
|
} catch {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
if (cached) await cache.delete(request);
|
|
543
|
-
const fallback = await cache.match(NAVIGATION_FALLBACK_URL);
|
|
544
|
-
return permitted(generation) && fallback && !hasNoStore(fallback.headers) ? fallback : Response.error();
|
|
553
|
+
const cached = await readPermittedEntry(cache, request, generation);
|
|
554
|
+
if (cached && permitted(generation)) return cached;
|
|
555
|
+
const fallback = await readPermittedEntry(cache, NAVIGATION_FALLBACK_URL, generation);
|
|
556
|
+
return permitted(generation) && fallback ? fallback : Response.error();
|
|
545
557
|
}
|
|
558
|
+
await updateOptionalEntry(cache, request, response, generation);
|
|
559
|
+
return response;
|
|
546
560
|
}
|
|
547
561
|
|
|
548
562
|
self.addEventListener("fetch", (event) => {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type OfflineCacheStatus =\n | \"unsupported\"\n | \"idle\"\n | \"warming\"\n | \"ready\"\n | \"partial\"\n | \"quota-risk\"\n | \"offline\"\n | \"error\";\n\nexport type OfflineCacheStrategy =\n | \"cache-first\"\n | \"stale-while-revalidate\"\n | \"network-first\"\n | \"no-cache\";\n\nexport interface OfflineCacheLogger {\n debug?: (...args: unknown[]) => void;\n info?: (...args: unknown[]) => void;\n warn?: (...args: unknown[]) => void;\n error?: (...args: unknown[]) => void;\n}\n\nexport interface OfflineCacheAssetPack {\n readonly id: string;\n readonly revision: string;\n readonly urls: readonly string[];\n readonly estimatedBytes?: number;\n}\n\nexport interface OfflineCacheUrlResult {\n readonly url: string;\n readonly cached: boolean;\n readonly error?: string;\n}\n\nexport interface OfflineCacheAssetPackResult {\n readonly id: string;\n readonly revision: string;\n readonly status: OfflineCacheStatus;\n readonly cacheName?: string;\n readonly cachedUrls: number;\n readonly totalUrls: number;\n readonly results: OfflineCacheUrlResult[];\n readonly estimatedBytes?: number;\n readonly availableBytes?: number;\n readonly error?: string;\n}\n\nexport interface OfflineCacheRequestPolicy {\n readonly sameOriginOnly?: boolean;\n readonly publicNavigationPaths?: readonly string[];\n readonly immutableAssetPathPrefixes?: readonly string[];\n readonly immutableAssetPathPatterns?: readonly RegExp[];\n readonly publicAssetPathPrefixes?: readonly string[];\n readonly publicApiPathPrefixes?: readonly string[];\n readonly deniedPathPrefixes?: readonly string[];\n readonly deniedPathPatterns?: readonly RegExp[];\n}\n\nexport interface OfflineCacheRequestDecision {\n readonly cacheable: boolean;\n readonly strategy: OfflineCacheStrategy;\n readonly reason: string;\n readonly cacheBucket?: \"navigation\" | \"immutable\" | \"public-asset\" | \"public-api\";\n}\n\nexport interface RegisterOfflineCacheWorkerOptions {\n readonly workerUrl?: string;\n readonly scope?: string;\n readonly buildId?: string;\n readonly enabled?: boolean;\n readonly logger?: OfflineCacheLogger;\n readonly serviceWorkerContainer?: ServiceWorkerContainer;\n}\n\nexport interface RegisterOfflineCacheWorkerResult {\n readonly status: \"registered\" | \"unsupported\" | \"disabled\" | \"error\";\n readonly registration?: ServiceWorkerRegistration;\n readonly error?: unknown;\n}\n\nexport interface OfflineCacheRuntime {\n readonly caches?: CacheStorage;\n readonly fetch?: typeof fetch;\n readonly location?: Pick<Location, \"origin\">;\n readonly navigatorStorage?: StorageManager;\n}\n\nexport interface OfflineCacheOperationOptions extends OfflineCacheRuntime {\n readonly cachePrefix?: string;\n readonly logger?: OfflineCacheLogger;\n readonly quotaRiskRatio?: number;\n readonly signal?: AbortSignal;\n}\n\nexport interface OfflineCacheWorkerScriptOptions {\n /** Require renewed host permission before any worker cache access (maximum 60 seconds). */\n readonly requireConsent?: boolean;\n readonly cachePrefix?: string;\n readonly buildId: string;\n readonly policy: OfflineCacheRequestPolicy;\n readonly navigationFallbackUrl?: string;\n}\n\nexport const DEFAULT_OFFLINE_CACHE_PREFIX = \"plasius-offline\";\n\nexport const DEFAULT_OFFLINE_CACHE_POLICY: Required<\n Pick<\n OfflineCacheRequestPolicy,\n | \"sameOriginOnly\"\n | \"publicNavigationPaths\"\n | \"immutableAssetPathPrefixes\"\n | \"publicAssetPathPrefixes\"\n | \"publicApiPathPrefixes\"\n | \"deniedPathPrefixes\"\n >\n> & Pick<OfflineCacheRequestPolicy, \"deniedPathPatterns\"> = Object.freeze({\n sameOriginOnly: true,\n publicNavigationPaths: Object.freeze([\"/\"]),\n immutableAssetPathPrefixes: Object.freeze([\"/assets/\", \"/favicon\", \"/manifest.json\"]),\n publicAssetPathPrefixes: Object.freeze([]),\n publicApiPathPrefixes: Object.freeze([]),\n deniedPathPrefixes: Object.freeze([\n \"/api/admin\",\n \"/api/ai\",\n \"/api/analytics\",\n \"/api/auth\",\n \"/api/game\",\n \"/api/oauth\",\n \"/api/player-system\",\n \"/api/profile\",\n \"/api/users\",\n \"/api/voice\",\n \"/admin\",\n \"/oauth\",\n \"/profile\",\n \"/player-system\",\n ]),\n deniedPathPatterns: Object.freeze([]),\n});\n\nconst SAFE_CACHE_SEGMENT_PATTERN = /[^a-z0-9._-]+/giu;\nconst DEFAULT_QUOTA_RISK_RATIO = 0.9;\n\nfunction sanitizeCacheSegment(value: string): string {\n const sanitized = value\n .trim()\n .toLowerCase()\n .replace(SAFE_CACHE_SEGMENT_PATTERN, \"-\")\n .replace(/^-+|-+$/gu, \"\");\n return sanitized || \"default\";\n}\n\nfunction resolveCacheStorage(runtime?: OfflineCacheRuntime): CacheStorage | undefined {\n return runtime?.caches ?? globalThis.caches;\n}\n\nfunction resolveFetch(runtime?: OfflineCacheRuntime): typeof fetch | undefined {\n return runtime?.fetch ?? globalThis.fetch;\n}\n\nfunction resolveNavigatorStorage(\n runtime?: OfflineCacheRuntime,\n): StorageManager | undefined {\n return runtime?.navigatorStorage ?? globalThis.navigator?.storage;\n}\n\nfunction resolveBaseOrigin(runtime?: OfflineCacheRuntime): string {\n return runtime?.location?.origin ?? globalThis.location?.origin ?? \"https://plasius.co.uk\";\n}\n\nfunction normalizeUrl(value: string, runtime?: OfflineCacheRuntime): string {\n return new URL(value, resolveBaseOrigin(runtime)).toString();\n}\n\nfunction toUrl(input: RequestInfo | URL, runtime?: OfflineCacheRuntime): URL | null {\n try {\n if (typeof input === \"string\") {\n return new URL(input, resolveBaseOrigin(runtime));\n }\n\n if (input instanceof URL) {\n return input;\n }\n\n const requestUrl = (input as Request).url;\n return typeof requestUrl === \"string\"\n ? new URL(requestUrl, resolveBaseOrigin(runtime))\n : null;\n } catch {\n return null;\n }\n}\n\nfunction getRequestMethod(input: RequestInfo | URL, init?: RequestInit): string {\n return (init?.method ?? (typeof input === \"object\" && \"method\" in input ? input.method : \"GET\"))\n .toString()\n .toUpperCase();\n}\n\nfunction hasNoStore(headers: Headers): boolean {\n return (headers.get(\"cache-control\") ?? \"\")\n .split(\",\")\n .some(directive => directive.trim().split(\"=\", 1)[0]?.toLowerCase() === \"no-store\");\n}\n\nfunction getRequestHeaders(input: RequestInfo | URL, init?: RequestInit): Headers {\n if (init?.headers) return new Headers(init.headers);\n return typeof input === \"object\" && \"headers\" in input ? new Headers(input.headers) : new Headers();\n}\n\nfunction pathStartsWith(pathname: string, prefixes: readonly string[] = []): boolean {\n return prefixes.some(prefix => pathname === prefix || pathname.startsWith(prefix));\n}\n\nfunction isNavigationRequest(input: RequestInfo | URL, init?: RequestInit): boolean {\n if (init?.headers) {\n const headers = new Headers(init.headers);\n if (headers.get(\"accept\")?.includes(\"text/html\")) {\n return true;\n }\n }\n\n return typeof input === \"object\" && \"mode\" in input && input.mode === \"navigate\";\n}\n\nexport function buildOfflineAssetCacheName(\n pack: Pick<OfflineCacheAssetPack, \"id\" | \"revision\">,\n cachePrefix = DEFAULT_OFFLINE_CACHE_PREFIX,\n): string {\n return [\n sanitizeCacheSegment(cachePrefix),\n \"asset-pack\",\n sanitizeCacheSegment(pack.id),\n sanitizeCacheSegment(pack.revision),\n ].join(\"-\");\n}\n\nexport function classifyOfflineCacheRequest(\n input: RequestInfo | URL,\n init?: RequestInit,\n policy: OfflineCacheRequestPolicy = DEFAULT_OFFLINE_CACHE_POLICY,\n runtime?: OfflineCacheRuntime,\n): OfflineCacheRequestDecision {\n const method = getRequestMethod(input, init);\n if (method !== \"GET\" && method !== \"HEAD\") {\n return { cacheable: false, strategy: \"no-cache\", reason: \"non-get-request\" };\n }\n if (hasNoStore(getRequestHeaders(input, init))) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"request-cache-control-no-store\" };\n }\n\n const url = toUrl(input, runtime);\n if (!url) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"invalid-url\" };\n }\n\n const sameOriginOnly = policy.sameOriginOnly ?? DEFAULT_OFFLINE_CACHE_POLICY.sameOriginOnly;\n if (sameOriginOnly && url.origin !== resolveBaseOrigin(runtime)) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"cross-origin\" };\n }\n\n const pathname = url.pathname;\n if ((policy.deniedPathPatterns ?? []).some(pattern => pattern.test(pathname))) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"denied-path-pattern\" };\n }\n\n if (\n pathStartsWith(\n pathname,\n policy.deniedPathPrefixes ?? DEFAULT_OFFLINE_CACHE_POLICY.deniedPathPrefixes,\n )\n ) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"denied-path-prefix\" };\n }\n\n if (policy.immutableAssetPathPatterns?.some(pattern => new RegExp(pattern.source, pattern.flags).test(pathname))) {\n return { cacheable: true, strategy: \"cache-first\", reason: \"immutable-asset-pattern\", cacheBucket: \"immutable\" };\n }\n\n if (pathStartsWith(pathname, policy.publicApiPathPrefixes)) {\n return {\n cacheable: true,\n strategy: \"stale-while-revalidate\",\n reason: \"public-api\",\n cacheBucket: \"public-api\",\n };\n }\n\n if (pathStartsWith(pathname, policy.publicAssetPathPrefixes)) {\n return {\n cacheable: true,\n strategy: \"stale-while-revalidate\",\n reason: \"public-asset\",\n cacheBucket: \"public-asset\",\n };\n }\n\n if (\n pathStartsWith(\n pathname,\n policy.immutableAssetPathPrefixes\n ?? DEFAULT_OFFLINE_CACHE_POLICY.immutableAssetPathPrefixes,\n )\n ) {\n return {\n cacheable: true,\n strategy: \"cache-first\",\n reason: \"immutable-asset\",\n cacheBucket: \"immutable\",\n };\n }\n\n if (\n isNavigationRequest(input, init)\n && (policy.publicNavigationPaths ?? DEFAULT_OFFLINE_CACHE_POLICY.publicNavigationPaths)\n .includes(pathname)\n ) {\n return {\n cacheable: true,\n strategy: \"network-first\",\n reason: \"public-navigation\",\n cacheBucket: \"navigation\",\n };\n }\n\n return { cacheable: false, strategy: \"no-cache\", reason: \"unmatched\" };\n}\n\nasync function resolveAvailableBytes(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions,\n): Promise<number | undefined> {\n if (typeof pack.estimatedBytes !== \"number\" || pack.estimatedBytes <= 0) {\n return undefined;\n }\n\n try {\n const estimate = await resolveNavigatorStorage(options)?.estimate?.();\n if (\n typeof estimate?.quota !== \"number\"\n || typeof estimate.usage !== \"number\"\n || estimate.quota <= estimate.usage\n ) {\n return undefined;\n }\n\n return estimate.quota - estimate.usage;\n } catch (error) {\n options.logger?.debug?.(\"offline cache quota estimate unavailable\", { error });\n return undefined;\n }\n}\n\nfunction resultStatus(results: readonly OfflineCacheUrlResult[]): OfflineCacheStatus {\n const cachedCount = results.filter(result => result.cached).length;\n if (cachedCount === results.length) {\n return \"ready\";\n }\n if (cachedCount > 0) {\n return \"partial\";\n }\n if (results.some(result => result.error === \"offline\")) {\n return \"offline\";\n }\n return \"error\";\n}\n\nexport async function warmAssetPack(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions = {},\n): Promise<OfflineCacheAssetPackResult> {\n const cacheStorage = resolveCacheStorage(options);\n const fetchImpl = resolveFetch(options);\n const totalUrls = pack.urls.length;\n const cacheName = buildOfflineAssetCacheName(pack, options.cachePrefix);\n\n if (!cacheStorage || typeof fetchImpl !== \"function\") {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"unsupported\",\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n if (totalUrls === 0) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"idle\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n const availableBytes = await resolveAvailableBytes(pack, options);\n const riskRatio = options.quotaRiskRatio ?? DEFAULT_QUOTA_RISK_RATIO;\n if (\n typeof availableBytes === \"number\"\n && typeof pack.estimatedBytes === \"number\"\n && pack.estimatedBytes > availableBytes * riskRatio\n ) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"quota-risk\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n availableBytes,\n };\n }\n\n options.signal?.throwIfAborted();\n const cache = await cacheStorage.open(cacheName);\n if (options.signal?.aborted) {\n await cacheStorage.delete(cacheName);\n options.signal.throwIfAborted();\n }\n const results: OfflineCacheUrlResult[] = [];\n\n for (const rawUrl of pack.urls) {\n const url = normalizeUrl(rawUrl, options);\n try {\n options.signal?.throwIfAborted();\n const request = new Request(url, {\n method: \"GET\",\n credentials: \"same-origin\",\n cache: \"reload\",\n signal: options.signal,\n });\n const response = await fetchImpl(request);\n options.signal?.throwIfAborted();\n if (!response.ok) {\n const existing = await cache.match(url);\n results.push({\n url,\n cached: Boolean(existing),\n error: existing ? undefined : `http-${response.status}`,\n });\n continue;\n }\n\n if (hasNoStore(response.headers)) {\n await cache.delete(url);\n results.push({ url, cached: false, error: \"cache-control-no-store\" });\n continue;\n }\n\n await cache.put(url, response.clone());\n results.push({ url, cached: true });\n } catch (error) {\n options.signal?.throwIfAborted();\n const existing = await cache.match(url);\n const isOffline =\n typeof globalThis.navigator !== \"undefined\" && globalThis.navigator.onLine === false;\n results.push({\n url,\n cached: Boolean(existing),\n error: existing ? undefined : isOffline ? \"offline\" : String(error),\n });\n }\n }\n\n return {\n id: pack.id,\n revision: pack.revision,\n status: resultStatus(results),\n cacheName,\n cachedUrls: results.filter(result => result.cached).length,\n totalUrls,\n results,\n estimatedBytes: pack.estimatedBytes,\n availableBytes,\n };\n}\n\nexport async function getAssetPackStatus(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions = {},\n): Promise<OfflineCacheAssetPackResult> {\n const cacheStorage = resolveCacheStorage(options);\n const totalUrls = pack.urls.length;\n const cacheName = buildOfflineAssetCacheName(pack, options.cachePrefix);\n\n if (!cacheStorage) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"unsupported\",\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n if (totalUrls === 0) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"idle\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n const cache = await cacheStorage.open(cacheName);\n const results = await Promise.all(\n pack.urls.map(async rawUrl => {\n const url = normalizeUrl(rawUrl, options);\n return {\n url,\n cached: Boolean(await cache.match(url)),\n };\n }),\n );\n\n return {\n id: pack.id,\n revision: pack.revision,\n status: resultStatus(results),\n cacheName,\n cachedUrls: results.filter(result => result.cached).length,\n totalUrls,\n results,\n estimatedBytes: pack.estimatedBytes,\n };\n}\n\nexport async function clearOfflineCaches(options: {\n readonly cachePrefix?: string;\n readonly caches?: CacheStorage;\n} = {}): Promise<string[]> {\n const cacheStorage = options.caches ?? globalThis.caches;\n if (!cacheStorage) {\n return [];\n }\n\n const prefix = sanitizeCacheSegment(options.cachePrefix ?? DEFAULT_OFFLINE_CACHE_PREFIX);\n const cacheNames = await cacheStorage.keys();\n const deleted: string[] = [];\n for (const cacheName of cacheNames) {\n if (cacheName.startsWith(prefix) && await cacheStorage.delete(cacheName)) {\n deleted.push(cacheName);\n }\n }\n return deleted;\n}\n\nexport async function registerOfflineCacheWorker(\n options: RegisterOfflineCacheWorkerOptions = {},\n): Promise<RegisterOfflineCacheWorkerResult> {\n if (options.enabled === false) {\n return { status: \"disabled\" };\n }\n\n const serviceWorkerContainer =\n options.serviceWorkerContainer ?? globalThis.navigator?.serviceWorker;\n if (!serviceWorkerContainer) {\n return { status: \"unsupported\" };\n }\n\n const workerUrl = new URL(\n options.workerUrl ?? \"/offline-cache-worker.js\",\n globalThis.location?.origin ?? \"https://plasius.co.uk\",\n );\n if (options.buildId) {\n workerUrl.searchParams.set(\"build\", options.buildId);\n }\n\n try {\n const registration = await serviceWorkerContainer.register(workerUrl.toString(), {\n scope: options.scope ?? \"/\",\n });\n options.logger?.info?.(\"offline cache worker registered\", {\n workerUrl: workerUrl.pathname,\n scope: registration.scope,\n });\n return {\n status: \"registered\",\n registration,\n };\n } catch (error) {\n options.logger?.warn?.(\"offline cache worker registration failed\", { error });\n return {\n status: \"error\",\n error,\n };\n }\n}\n\nexport function createOfflineCacheWorkerScript(\n options: OfflineCacheWorkerScriptOptions,\n): string {\n const cachePrefix = sanitizeCacheSegment(\n options.cachePrefix ?? DEFAULT_OFFLINE_CACHE_PREFIX,\n );\n const buildId = sanitizeCacheSegment(options.buildId);\n const policyJson = JSON.stringify({ ...options.policy,\n immutableAssetPathPatterns: options.policy.immutableAssetPathPatterns?.map(pattern => ({ source: pattern.source, flags: pattern.flags })),\n deniedPathPatterns: options.policy.deniedPathPatterns?.map(pattern => ({ source: pattern.source, flags: pattern.flags })),\n });\n const fallbackUrl = JSON.stringify(options.navigationFallbackUrl ?? \"/\");\n\n return `\nconst CACHE_PREFIX = ${JSON.stringify(cachePrefix)};\nconst BUILD_ID = ${JSON.stringify(buildId)};\nconst APP_CACHE = CACHE_PREFIX + \"-app-\" + BUILD_ID;\nconst PUBLIC_CACHE = CACHE_PREFIX + \"-public-\" + BUILD_ID;\nconst POLICY = ${policyJson};\nconst NAVIGATION_FALLBACK_URL = ${fallbackUrl};\nconst REQUIRE_CONSENT = ${options.requireConsent === true};\nlet permissionUntil = REQUIRE_CONSENT ? 0 : Infinity;\nlet permissionGeneration = 0;\nconst permitted = (generation) => generation === permissionGeneration && Date.now() < permissionUntil;\nasync function discardCaches() {\n const names = await caches.keys();\n await Promise.all(names.filter(name => name.startsWith(CACHE_PREFIX + \"-\")).map(name => caches.delete(name)));\n}\nself.addEventListener(\"message\", event => {\n if (!REQUIRE_CONSENT || event.data?.type !== \"plasius-offline-consent-v1\") return;\n try { if (new URL(event.source?.url).origin !== self.location.origin) return; } catch { return; }\n const requested = event.data.allowedUntil;\n permissionUntil = typeof requested === \"number\" && Number.isFinite(requested)\n ? Math.min(requested, Date.now() + 60_000) : 0;\n const disabled = permissionUntil <= Date.now();\n if (disabled) permissionGeneration++;\n event.waitUntil((async () => {\n if (disabled) await discardCaches();\n event.ports?.[0]?.postMessage({ type: \"plasius-offline-consent-v1\", disabled });\n })());\n});\n\nconst startsWithAny = (pathname, prefixes = []) => prefixes.some((prefix) => pathname === prefix || pathname.startsWith(prefix));\nconst matchesAny = (pathname, patterns = []) => patterns.some(pattern => new RegExp(pattern.source, pattern.flags).test(pathname));\nconst isDenied = (pathname) => startsWithAny(pathname, POLICY.deniedPathPrefixes || []) || matchesAny(pathname, POLICY.deniedPathPatterns);\nconst hasNoStore = (headers) => (headers.get(\"cache-control\") || \"\").split(\",\").some((directive) => directive.trim().split(\"=\", 1)[0].toLowerCase() === \"no-store\");\nconst classify = (request) => {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") return { cacheable: false, strategy: \"no-cache\" };\n if (hasNoStore(request.headers)) return { cacheable: false, strategy: \"no-cache\", reason: \"request-cache-control-no-store\" };\n const url = new URL(request.url);\n if (POLICY.sameOriginOnly !== false && url.origin !== self.location.origin) return { cacheable: false, strategy: \"no-cache\" };\n if (isDenied(url.pathname)) return { cacheable: false, strategy: \"no-cache\" };\n if (matchesAny(url.pathname, POLICY.immutableAssetPathPatterns)) return { cacheable: true, strategy: \"cache-first\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.publicApiPathPrefixes || [])) return { cacheable: true, strategy: \"stale-while-revalidate\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.publicAssetPathPrefixes || [])) return { cacheable: true, strategy: \"stale-while-revalidate\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.immutableAssetPathPrefixes || [])) return { cacheable: true, strategy: \"cache-first\", cacheName: APP_CACHE };\n if (request.mode === \"navigate\" && (POLICY.publicNavigationPaths || []).includes(url.pathname)) return { cacheable: true, strategy: \"network-first\", cacheName: APP_CACHE };\n return { cacheable: false, strategy: \"no-cache\" };\n};\n\nself.addEventListener(\"install\", (event) => {\n event.waitUntil(self.skipWaiting());\n});\n\nself.addEventListener(\"activate\", (event) => {\n event.waitUntil((async () => {\n const names = await caches.keys();\n await Promise.all(names.filter((name) => name.startsWith(CACHE_PREFIX + \"-\") && !name.endsWith(\"-\" + BUILD_ID) && !name.includes(\"-asset-pack-\")).map((name) => caches.delete(name)));\n await self.clients.claim();\n })());\n});\n\nasync function openPermittedCache(cacheName, generation) {\n if (!permitted(generation)) return null;\n const cache = await caches.open(cacheName);\n if (!permitted(generation)) {\n await caches.delete(cacheName);\n return null;\n }\n return cache;\n}\n\nasync function cacheFirst(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n if (!cache) return fetch(request);\n const cached = await cache.match(request);\n if (!permitted(generation)) return fetch(request);\n if (cached && !hasNoStore(cached.headers)) return cached;\n if (cached) await cache.delete(request);\n const response = await fetch(request);\n if (!permitted(generation)) return response;\n if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());\n if (hasNoStore(response.headers)) await cache.delete(request);\n return response;\n}\n\nasync function staleWhileRevalidate(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n if (!cache) return fetch(request);\n const candidate = await cache.match(request);\n if (!permitted(generation)) return fetch(request);\n const cached = candidate && !hasNoStore(candidate.headers) ? candidate : undefined;\n if (candidate && !cached) await cache.delete(request);\n const refresh = fetch(request).then(async response => {\n if (!permitted(generation)) return response;\n if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());\n if (hasNoStore(response.headers)) await cache.delete(request);\n return response;\n });\n if (cached) void refresh.catch(() => undefined);\n return cached || refresh;\n}\n\nasync function networkFirst(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n if (!cache) return fetch(request);\n try {\n const response = await fetch(request);\n if (!permitted(generation)) return response;\n if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());\n if (hasNoStore(response.headers)) await cache.delete(request);\n return response;\n } catch {\n if (!permitted(generation)) return Response.error();\n const cached = await cache.match(request);\n if (!permitted(generation)) return Response.error();\n if (cached && !hasNoStore(cached.headers)) return cached;\n if (cached) await cache.delete(request);\n const fallback = await cache.match(NAVIGATION_FALLBACK_URL);\n return permitted(generation) && fallback && !hasNoStore(fallback.headers) ? fallback : Response.error();\n }\n}\n\nself.addEventListener(\"fetch\", (event) => {\n const generation = permissionGeneration;\n if (!permitted(generation)) return;\n const decision = classify(event.request);\n if (!decision.cacheable) return;\n if (decision.strategy === \"cache-first\") event.respondWith(cacheFirst(event.request, decision.cacheName, generation));\n if (decision.strategy === \"stale-while-revalidate\") event.respondWith(staleWhileRevalidate(event.request, decision.cacheName, generation));\n if (decision.strategy === \"network-first\") event.respondWith(networkFirst(event.request, decision.cacheName, generation));\n});\n`.trimStart();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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0HvD,UAAU;AACZ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type OfflineCacheStatus =\n | \"unsupported\"\n | \"idle\"\n | \"warming\"\n | \"ready\"\n | \"partial\"\n | \"quota-risk\"\n | \"offline\"\n | \"error\";\n\nexport type OfflineCacheStrategy =\n | \"cache-first\"\n | \"stale-while-revalidate\"\n | \"network-first\"\n | \"no-cache\";\n\nexport interface OfflineCacheLogger {\n debug?: (...args: unknown[]) => void;\n info?: (...args: unknown[]) => void;\n warn?: (...args: unknown[]) => void;\n error?: (...args: unknown[]) => void;\n}\n\nexport interface OfflineCacheAssetPack {\n readonly id: string;\n readonly revision: string;\n readonly urls: readonly string[];\n readonly estimatedBytes?: number;\n}\n\nexport interface OfflineCacheUrlResult {\n readonly url: string;\n readonly cached: boolean;\n readonly error?: string;\n}\n\nexport interface OfflineCacheAssetPackResult {\n readonly id: string;\n readonly revision: string;\n readonly status: OfflineCacheStatus;\n readonly cacheName?: string;\n readonly cachedUrls: number;\n readonly totalUrls: number;\n readonly results: OfflineCacheUrlResult[];\n readonly estimatedBytes?: number;\n readonly availableBytes?: number;\n readonly error?: string;\n}\n\nexport interface OfflineCacheRequestPolicy {\n readonly sameOriginOnly?: boolean;\n readonly publicNavigationPaths?: readonly string[];\n readonly immutableAssetPathPrefixes?: readonly string[];\n readonly immutableAssetPathPatterns?: readonly RegExp[];\n readonly publicAssetPathPrefixes?: readonly string[];\n readonly publicApiPathPrefixes?: readonly string[];\n readonly deniedPathPrefixes?: readonly string[];\n readonly deniedPathPatterns?: readonly RegExp[];\n}\n\nexport interface OfflineCacheRequestDecision {\n readonly cacheable: boolean;\n readonly strategy: OfflineCacheStrategy;\n readonly reason: string;\n readonly cacheBucket?: \"navigation\" | \"immutable\" | \"public-asset\" | \"public-api\";\n}\n\nexport interface RegisterOfflineCacheWorkerOptions {\n readonly workerUrl?: string;\n readonly scope?: string;\n readonly buildId?: string;\n readonly enabled?: boolean;\n readonly logger?: OfflineCacheLogger;\n readonly serviceWorkerContainer?: ServiceWorkerContainer;\n}\n\nexport interface RegisterOfflineCacheWorkerResult {\n readonly status: \"registered\" | \"unsupported\" | \"disabled\" | \"error\";\n readonly registration?: ServiceWorkerRegistration;\n readonly error?: unknown;\n}\n\nexport interface OfflineCacheRuntime {\n readonly caches?: CacheStorage;\n readonly fetch?: typeof fetch;\n readonly location?: Pick<Location, \"origin\">;\n readonly navigatorStorage?: StorageManager;\n}\n\nexport interface OfflineCacheOperationOptions extends OfflineCacheRuntime {\n readonly cachePrefix?: string;\n readonly logger?: OfflineCacheLogger;\n readonly quotaRiskRatio?: number;\n readonly signal?: AbortSignal;\n}\n\nexport interface OfflineCacheWorkerScriptOptions {\n /** Require renewed host permission before any worker cache access (maximum 60 seconds). */\n readonly requireConsent?: boolean;\n readonly cachePrefix?: string;\n readonly buildId: string;\n readonly policy: OfflineCacheRequestPolicy;\n readonly navigationFallbackUrl?: string;\n}\n\nexport const DEFAULT_OFFLINE_CACHE_PREFIX = \"plasius-offline\";\n\nexport const DEFAULT_OFFLINE_CACHE_POLICY: Required<\n Pick<\n OfflineCacheRequestPolicy,\n | \"sameOriginOnly\"\n | \"publicNavigationPaths\"\n | \"immutableAssetPathPrefixes\"\n | \"publicAssetPathPrefixes\"\n | \"publicApiPathPrefixes\"\n | \"deniedPathPrefixes\"\n >\n> & Pick<OfflineCacheRequestPolicy, \"deniedPathPatterns\"> = Object.freeze({\n sameOriginOnly: true,\n publicNavigationPaths: Object.freeze([\"/\"]),\n immutableAssetPathPrefixes: Object.freeze([\"/assets/\", \"/favicon\", \"/manifest.json\"]),\n publicAssetPathPrefixes: Object.freeze([]),\n publicApiPathPrefixes: Object.freeze([]),\n deniedPathPrefixes: Object.freeze([\n \"/api/admin\",\n \"/api/ai\",\n \"/api/analytics\",\n \"/api/auth\",\n \"/api/game\",\n \"/api/oauth\",\n \"/api/player-system\",\n \"/api/profile\",\n \"/api/users\",\n \"/api/voice\",\n \"/admin\",\n \"/oauth\",\n \"/profile\",\n \"/player-system\",\n ]),\n deniedPathPatterns: Object.freeze([]),\n});\n\nconst SAFE_CACHE_SEGMENT_PATTERN = /[^a-z0-9._-]+/giu;\nconst DEFAULT_QUOTA_RISK_RATIO = 0.9;\n\nfunction sanitizeCacheSegment(value: string): string {\n const sanitized = value\n .trim()\n .toLowerCase()\n .replace(SAFE_CACHE_SEGMENT_PATTERN, \"-\")\n .replace(/^-+|-+$/gu, \"\");\n return sanitized || \"default\";\n}\n\nfunction resolveCacheStorage(runtime?: OfflineCacheRuntime): CacheStorage | undefined {\n return runtime?.caches ?? globalThis.caches;\n}\n\nfunction resolveFetch(runtime?: OfflineCacheRuntime): typeof fetch | undefined {\n return runtime?.fetch ?? globalThis.fetch;\n}\n\nfunction resolveNavigatorStorage(\n runtime?: OfflineCacheRuntime,\n): StorageManager | undefined {\n return runtime?.navigatorStorage ?? globalThis.navigator?.storage;\n}\n\nfunction resolveBaseOrigin(runtime?: OfflineCacheRuntime): string {\n return runtime?.location?.origin ?? globalThis.location?.origin ?? \"https://plasius.co.uk\";\n}\n\nfunction normalizeUrl(value: string, runtime?: OfflineCacheRuntime): string {\n return new URL(value, resolveBaseOrigin(runtime)).toString();\n}\n\nfunction toUrl(input: RequestInfo | URL, runtime?: OfflineCacheRuntime): URL | null {\n try {\n if (typeof input === \"string\") {\n return new URL(input, resolveBaseOrigin(runtime));\n }\n\n if (input instanceof URL) {\n return input;\n }\n\n const requestUrl = (input as Request).url;\n return typeof requestUrl === \"string\"\n ? new URL(requestUrl, resolveBaseOrigin(runtime))\n : null;\n } catch {\n return null;\n }\n}\n\nfunction getRequestMethod(input: RequestInfo | URL, init?: RequestInit): string {\n return (init?.method ?? (typeof input === \"object\" && \"method\" in input ? input.method : \"GET\"))\n .toString()\n .toUpperCase();\n}\n\nfunction hasNoStore(headers: Headers): boolean {\n return (headers.get(\"cache-control\") ?? \"\")\n .split(\",\")\n .some(directive => directive.trim().split(\"=\", 1)[0]?.toLowerCase() === \"no-store\");\n}\n\nfunction getRequestHeaders(input: RequestInfo | URL, init?: RequestInit): Headers {\n if (init?.headers) return new Headers(init.headers);\n return typeof input === \"object\" && \"headers\" in input ? new Headers(input.headers) : new Headers();\n}\n\nfunction pathStartsWith(pathname: string, prefixes: readonly string[] = []): boolean {\n return prefixes.some(prefix => pathname === prefix || pathname.startsWith(prefix));\n}\n\nfunction isNavigationRequest(input: RequestInfo | URL, init?: RequestInit): boolean {\n if (init?.headers) {\n const headers = new Headers(init.headers);\n if (headers.get(\"accept\")?.includes(\"text/html\")) {\n return true;\n }\n }\n\n return typeof input === \"object\" && \"mode\" in input && input.mode === \"navigate\";\n}\n\nexport function buildOfflineAssetCacheName(\n pack: Pick<OfflineCacheAssetPack, \"id\" | \"revision\">,\n cachePrefix = DEFAULT_OFFLINE_CACHE_PREFIX,\n): string {\n return [\n sanitizeCacheSegment(cachePrefix),\n \"asset-pack\",\n sanitizeCacheSegment(pack.id),\n sanitizeCacheSegment(pack.revision),\n ].join(\"-\");\n}\n\nexport function classifyOfflineCacheRequest(\n input: RequestInfo | URL,\n init?: RequestInit,\n policy: OfflineCacheRequestPolicy = DEFAULT_OFFLINE_CACHE_POLICY,\n runtime?: OfflineCacheRuntime,\n): OfflineCacheRequestDecision {\n const method = getRequestMethod(input, init);\n if (method !== \"GET\" && method !== \"HEAD\") {\n return { cacheable: false, strategy: \"no-cache\", reason: \"non-get-request\" };\n }\n if (hasNoStore(getRequestHeaders(input, init))) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"request-cache-control-no-store\" };\n }\n\n const url = toUrl(input, runtime);\n if (!url) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"invalid-url\" };\n }\n\n const sameOriginOnly = policy.sameOriginOnly ?? DEFAULT_OFFLINE_CACHE_POLICY.sameOriginOnly;\n if (sameOriginOnly && url.origin !== resolveBaseOrigin(runtime)) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"cross-origin\" };\n }\n\n const pathname = url.pathname;\n if ((policy.deniedPathPatterns ?? []).some(pattern => pattern.test(pathname))) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"denied-path-pattern\" };\n }\n\n if (\n pathStartsWith(\n pathname,\n policy.deniedPathPrefixes ?? DEFAULT_OFFLINE_CACHE_POLICY.deniedPathPrefixes,\n )\n ) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"denied-path-prefix\" };\n }\n\n if (policy.immutableAssetPathPatterns?.some(pattern => new RegExp(pattern.source, pattern.flags).test(pathname))) {\n return { cacheable: true, strategy: \"cache-first\", reason: \"immutable-asset-pattern\", cacheBucket: \"immutable\" };\n }\n\n if (pathStartsWith(pathname, policy.publicApiPathPrefixes)) {\n return {\n cacheable: true,\n strategy: \"stale-while-revalidate\",\n reason: \"public-api\",\n cacheBucket: \"public-api\",\n };\n }\n\n if (pathStartsWith(pathname, policy.publicAssetPathPrefixes)) {\n return {\n cacheable: true,\n strategy: \"stale-while-revalidate\",\n reason: \"public-asset\",\n cacheBucket: \"public-asset\",\n };\n }\n\n if (\n pathStartsWith(\n pathname,\n policy.immutableAssetPathPrefixes\n ?? DEFAULT_OFFLINE_CACHE_POLICY.immutableAssetPathPrefixes,\n )\n ) {\n return {\n cacheable: true,\n strategy: \"cache-first\",\n reason: \"immutable-asset\",\n cacheBucket: \"immutable\",\n };\n }\n\n if (\n isNavigationRequest(input, init)\n && (policy.publicNavigationPaths ?? DEFAULT_OFFLINE_CACHE_POLICY.publicNavigationPaths)\n .includes(pathname)\n ) {\n return {\n cacheable: true,\n strategy: \"network-first\",\n reason: \"public-navigation\",\n cacheBucket: \"navigation\",\n };\n }\n\n return { cacheable: false, strategy: \"no-cache\", reason: \"unmatched\" };\n}\n\nasync function resolveAvailableBytes(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions,\n): Promise<number | undefined> {\n if (typeof pack.estimatedBytes !== \"number\" || pack.estimatedBytes <= 0) {\n return undefined;\n }\n\n try {\n const estimate = await resolveNavigatorStorage(options)?.estimate?.();\n if (\n typeof estimate?.quota !== \"number\"\n || typeof estimate.usage !== \"number\"\n || estimate.quota <= estimate.usage\n ) {\n return undefined;\n }\n\n return estimate.quota - estimate.usage;\n } catch (error) {\n options.logger?.debug?.(\"offline cache quota estimate unavailable\", { error });\n return undefined;\n }\n}\n\nfunction resultStatus(results: readonly OfflineCacheUrlResult[]): OfflineCacheStatus {\n const cachedCount = results.filter(result => result.cached).length;\n if (cachedCount === results.length) {\n return \"ready\";\n }\n if (cachedCount > 0) {\n return \"partial\";\n }\n if (results.some(result => result.error === \"offline\")) {\n return \"offline\";\n }\n return \"error\";\n}\n\nexport async function warmAssetPack(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions = {},\n): Promise<OfflineCacheAssetPackResult> {\n const cacheStorage = resolveCacheStorage(options);\n const fetchImpl = resolveFetch(options);\n const totalUrls = pack.urls.length;\n const cacheName = buildOfflineAssetCacheName(pack, options.cachePrefix);\n\n if (!cacheStorage || typeof fetchImpl !== \"function\") {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"unsupported\",\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n if (totalUrls === 0) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"idle\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n const availableBytes = await resolveAvailableBytes(pack, options);\n const riskRatio = options.quotaRiskRatio ?? DEFAULT_QUOTA_RISK_RATIO;\n if (\n typeof availableBytes === \"number\"\n && typeof pack.estimatedBytes === \"number\"\n && pack.estimatedBytes > availableBytes * riskRatio\n ) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"quota-risk\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n availableBytes,\n };\n }\n\n options.signal?.throwIfAborted();\n const cache = await cacheStorage.open(cacheName);\n if (options.signal?.aborted) {\n await cacheStorage.delete(cacheName);\n options.signal.throwIfAborted();\n }\n const results: OfflineCacheUrlResult[] = [];\n\n for (const rawUrl of pack.urls) {\n const url = normalizeUrl(rawUrl, options);\n try {\n options.signal?.throwIfAborted();\n const request = new Request(url, {\n method: \"GET\",\n credentials: \"same-origin\",\n cache: \"reload\",\n signal: options.signal,\n });\n const response = await fetchImpl(request);\n options.signal?.throwIfAborted();\n if (!response.ok) {\n const existing = await cache.match(url);\n results.push({\n url,\n cached: Boolean(existing),\n error: existing ? undefined : `http-${response.status}`,\n });\n continue;\n }\n\n if (hasNoStore(response.headers)) {\n await cache.delete(url);\n results.push({ url, cached: false, error: \"cache-control-no-store\" });\n continue;\n }\n\n await cache.put(url, response.clone());\n results.push({ url, cached: true });\n } catch (error) {\n options.signal?.throwIfAborted();\n const existing = await cache.match(url);\n const isOffline =\n typeof globalThis.navigator !== \"undefined\" && globalThis.navigator.onLine === false;\n results.push({\n url,\n cached: Boolean(existing),\n error: existing ? undefined : isOffline ? \"offline\" : String(error),\n });\n }\n }\n\n return {\n id: pack.id,\n revision: pack.revision,\n status: resultStatus(results),\n cacheName,\n cachedUrls: results.filter(result => result.cached).length,\n totalUrls,\n results,\n estimatedBytes: pack.estimatedBytes,\n availableBytes,\n };\n}\n\nexport async function getAssetPackStatus(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions = {},\n): Promise<OfflineCacheAssetPackResult> {\n const cacheStorage = resolveCacheStorage(options);\n const totalUrls = pack.urls.length;\n const cacheName = buildOfflineAssetCacheName(pack, options.cachePrefix);\n\n if (!cacheStorage) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"unsupported\",\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n if (totalUrls === 0) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"idle\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n const cache = await cacheStorage.open(cacheName);\n const results = await Promise.all(\n pack.urls.map(async rawUrl => {\n const url = normalizeUrl(rawUrl, options);\n return {\n url,\n cached: Boolean(await cache.match(url)),\n };\n }),\n );\n\n return {\n id: pack.id,\n revision: pack.revision,\n status: resultStatus(results),\n cacheName,\n cachedUrls: results.filter(result => result.cached).length,\n totalUrls,\n results,\n estimatedBytes: pack.estimatedBytes,\n };\n}\n\nexport async function clearOfflineCaches(options: {\n readonly cachePrefix?: string;\n readonly caches?: CacheStorage;\n} = {}): Promise<string[]> {\n const cacheStorage = options.caches ?? globalThis.caches;\n if (!cacheStorage) {\n return [];\n }\n\n const prefix = sanitizeCacheSegment(options.cachePrefix ?? DEFAULT_OFFLINE_CACHE_PREFIX);\n const cacheNames = await cacheStorage.keys();\n const deleted: string[] = [];\n for (const cacheName of cacheNames) {\n if (cacheName.startsWith(prefix) && await cacheStorage.delete(cacheName)) {\n deleted.push(cacheName);\n }\n }\n return deleted;\n}\n\nexport async function registerOfflineCacheWorker(\n options: RegisterOfflineCacheWorkerOptions = {},\n): Promise<RegisterOfflineCacheWorkerResult> {\n if (options.enabled === false) {\n return { status: \"disabled\" };\n }\n\n const serviceWorkerContainer =\n options.serviceWorkerContainer ?? globalThis.navigator?.serviceWorker;\n if (!serviceWorkerContainer) {\n return { status: \"unsupported\" };\n }\n\n const workerUrl = new URL(\n options.workerUrl ?? \"/offline-cache-worker.js\",\n globalThis.location?.origin ?? \"https://plasius.co.uk\",\n );\n if (options.buildId) {\n workerUrl.searchParams.set(\"build\", options.buildId);\n }\n\n try {\n const registration = await serviceWorkerContainer.register(workerUrl.toString(), {\n scope: options.scope ?? \"/\",\n });\n options.logger?.info?.(\"offline cache worker registered\", {\n workerUrl: workerUrl.pathname,\n scope: registration.scope,\n });\n return {\n status: \"registered\",\n registration,\n };\n } catch (error) {\n options.logger?.warn?.(\"offline cache worker registration failed\", { error });\n return {\n status: \"error\",\n error,\n };\n }\n}\n\nexport function createOfflineCacheWorkerScript(\n options: OfflineCacheWorkerScriptOptions,\n): string {\n const cachePrefix = sanitizeCacheSegment(\n options.cachePrefix ?? DEFAULT_OFFLINE_CACHE_PREFIX,\n );\n const buildId = sanitizeCacheSegment(options.buildId);\n const policyJson = JSON.stringify({ ...options.policy,\n immutableAssetPathPatterns: options.policy.immutableAssetPathPatterns?.map(pattern => ({ source: pattern.source, flags: pattern.flags })),\n deniedPathPatterns: options.policy.deniedPathPatterns?.map(pattern => ({ source: pattern.source, flags: pattern.flags })),\n });\n const fallbackUrl = JSON.stringify(options.navigationFallbackUrl ?? \"/\");\n\n return `\nconst CACHE_PREFIX = ${JSON.stringify(cachePrefix)};\nconst BUILD_ID = ${JSON.stringify(buildId)};\nconst APP_CACHE = CACHE_PREFIX + \"-app-\" + BUILD_ID;\nconst PUBLIC_CACHE = CACHE_PREFIX + \"-public-\" + BUILD_ID;\nconst POLICY = ${policyJson};\nconst NAVIGATION_FALLBACK_URL = ${fallbackUrl};\nconst REQUIRE_CONSENT = ${options.requireConsent === true};\nlet permissionUntil = REQUIRE_CONSENT ? 0 : Infinity;\nlet permissionGeneration = 0;\nconst permitted = (generation) => generation === permissionGeneration && Date.now() < permissionUntil;\nasync function discardCaches() {\n const names = await caches.keys();\n await Promise.all(names.filter(name => name.startsWith(CACHE_PREFIX + \"-\")).map(name => caches.delete(name)));\n}\nself.addEventListener(\"message\", event => {\n if (!REQUIRE_CONSENT || event.data?.type !== \"plasius-offline-consent-v1\") return;\n try { if (new URL(event.source?.url).origin !== self.location.origin) return; } catch { return; }\n const requested = event.data.allowedUntil;\n permissionUntil = typeof requested === \"number\" && Number.isFinite(requested)\n ? Math.min(requested, Date.now() + 60_000) : 0;\n const disabled = permissionUntil <= Date.now();\n if (disabled) permissionGeneration++;\n event.waitUntil((async () => {\n if (disabled) await discardCaches();\n event.ports?.[0]?.postMessage({ type: \"plasius-offline-consent-v1\", disabled });\n })());\n});\n\nconst startsWithAny = (pathname, prefixes = []) => prefixes.some((prefix) => pathname === prefix || pathname.startsWith(prefix));\nconst matchesAny = (pathname, patterns = []) => patterns.some(pattern => new RegExp(pattern.source, pattern.flags).test(pathname));\nconst isDenied = (pathname) => startsWithAny(pathname, POLICY.deniedPathPrefixes || []) || matchesAny(pathname, POLICY.deniedPathPatterns);\nconst hasNoStore = (headers) => (headers.get(\"cache-control\") || \"\").split(\",\").some((directive) => directive.trim().split(\"=\", 1)[0].toLowerCase() === \"no-store\");\nconst classify = (request) => {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") return { cacheable: false, strategy: \"no-cache\" };\n if (hasNoStore(request.headers)) return { cacheable: false, strategy: \"no-cache\", reason: \"request-cache-control-no-store\" };\n const url = new URL(request.url);\n if (POLICY.sameOriginOnly !== false && url.origin !== self.location.origin) return { cacheable: false, strategy: \"no-cache\" };\n if (isDenied(url.pathname)) return { cacheable: false, strategy: \"no-cache\" };\n if (matchesAny(url.pathname, POLICY.immutableAssetPathPatterns)) return { cacheable: true, strategy: \"cache-first\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.publicApiPathPrefixes || [])) return { cacheable: true, strategy: \"stale-while-revalidate\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.publicAssetPathPrefixes || [])) return { cacheable: true, strategy: \"stale-while-revalidate\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.immutableAssetPathPrefixes || [])) return { cacheable: true, strategy: \"cache-first\", cacheName: APP_CACHE };\n if (request.mode === \"navigate\" && (POLICY.publicNavigationPaths || []).includes(url.pathname)) return { cacheable: true, strategy: \"network-first\", cacheName: APP_CACHE };\n return { cacheable: false, strategy: \"no-cache\" };\n};\n\nself.addEventListener(\"install\", (event) => {\n event.waitUntil(self.skipWaiting());\n});\n\nself.addEventListener(\"activate\", (event) => {\n event.waitUntil((async () => {\n const names = await caches.keys();\n await Promise.all(names.filter((name) => name.startsWith(CACHE_PREFIX + \"-\") && !name.endsWith(\"-\" + BUILD_ID) && !name.includes(\"-asset-pack-\")).map((name) => caches.delete(name)));\n await self.clients.claim();\n })());\n});\n\nasync function openPermittedCache(cacheName, generation) {\n if (!permitted(generation)) return null;\n try {\n const cache = await caches.open(cacheName);\n if (permitted(generation)) return cache;\n await caches.delete(cacheName);\n } catch { /* Optional storage must not prevent online delivery. */ }\n return null;\n}\n\nasync function evictOptionalEntry(cache, request) {\n try { await cache.delete(request); } catch { /* Never reuse an ineligible entry. */ }\n}\n\nasync function readPermittedEntry(cache, request, generation) {\n if (!cache || !permitted(generation)) return undefined;\n try {\n const candidate = await cache.match(request);\n if (!permitted(generation)) return undefined;\n if (candidate && !hasNoStore(candidate.headers)) return candidate;\n if (candidate) await evictOptionalEntry(cache, request);\n } catch { /* A failed read is an optional cache miss. */ }\n return undefined;\n}\n\nasync function updateOptionalEntry(cache, request, response, generation) {\n if (!cache || !permitted(generation)) return;\n try {\n if (hasNoStore(response.headers)) await evictOptionalEntry(cache, request);\n else if (response.ok) await cache.put(request, response.clone());\n } catch { /* Quota and other storage failures do not replace the response. */ }\n}\n\nasync function fetchOrError(request) {\n try { return await fetch(request); } catch { return Response.error(); }\n}\n\nasync function cacheFirst(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n const cached = await readPermittedEntry(cache, request, generation);\n if (cached && permitted(generation)) return cached;\n const response = await fetchOrError(request);\n await updateOptionalEntry(cache, request, response, generation);\n return response;\n}\n\nasync function staleWhileRevalidate(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n const cached = await readPermittedEntry(cache, request, generation);\n const refresh = fetchOrError(request).then(async response => {\n await updateOptionalEntry(cache, request, response, generation);\n return response;\n });\n if (cached && permitted(generation)) {\n void refresh.catch(() => undefined);\n return cached;\n }\n return refresh;\n}\n\nasync function networkFirst(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n let response;\n try {\n response = await fetch(request);\n } catch {\n const cached = await readPermittedEntry(cache, request, generation);\n if (cached && permitted(generation)) return cached;\n const fallback = await readPermittedEntry(cache, NAVIGATION_FALLBACK_URL, generation);\n return permitted(generation) && fallback ? fallback : Response.error();\n }\n await updateOptionalEntry(cache, request, response, generation);\n return response;\n}\n\nself.addEventListener(\"fetch\", (event) => {\n const generation = permissionGeneration;\n if (!permitted(generation)) return;\n const decision = classify(event.request);\n if (!decision.cacheable) return;\n if (decision.strategy === \"cache-first\") event.respondWith(cacheFirst(event.request, decision.cacheName, generation));\n if (decision.strategy === \"stale-while-revalidate\") event.respondWith(staleWhileRevalidate(event.request, decision.cacheName, generation));\n if (decision.strategy === \"network-first\") event.respondWith(networkFirst(event.request, decision.cacheName, generation));\n});\n`.trimStart();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyGO,IAAM,+BAA+B;AAErC,IAAM,+BAU+C,OAAO,OAAO;AAAA,EACxE,gBAAgB;AAAA,EAChB,uBAAuB,OAAO,OAAO,CAAC,GAAG,CAAC;AAAA,EAC1C,4BAA4B,OAAO,OAAO,CAAC,YAAY,YAAY,gBAAgB,CAAC;AAAA,EACpF,yBAAyB,OAAO,OAAO,CAAC,CAAC;AAAA,EACzC,uBAAuB,OAAO,OAAO,CAAC,CAAC;AAAA,EACvC,oBAAoB,OAAO,OAAO;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,oBAAoB,OAAO,OAAO,CAAC,CAAC;AACtC,CAA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;AAAA,0BACnB,QAAQ,mBAAmB,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwIvD,UAAU;AACZ;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -454,63 +454,77 @@ self.addEventListener("activate", (event) => {
|
|
|
454
454
|
|
|
455
455
|
async function openPermittedCache(cacheName, generation) {
|
|
456
456
|
if (!permitted(generation)) return null;
|
|
457
|
-
|
|
458
|
-
|
|
457
|
+
try {
|
|
458
|
+
const cache = await caches.open(cacheName);
|
|
459
|
+
if (permitted(generation)) return cache;
|
|
459
460
|
await caches.delete(cacheName);
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
461
|
+
} catch { /* Optional storage must not prevent online delivery. */ }
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
async function evictOptionalEntry(cache, request) {
|
|
466
|
+
try { await cache.delete(request); } catch { /* Never reuse an ineligible entry. */ }
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async function readPermittedEntry(cache, request, generation) {
|
|
470
|
+
if (!cache || !permitted(generation)) return undefined;
|
|
471
|
+
try {
|
|
472
|
+
const candidate = await cache.match(request);
|
|
473
|
+
if (!permitted(generation)) return undefined;
|
|
474
|
+
if (candidate && !hasNoStore(candidate.headers)) return candidate;
|
|
475
|
+
if (candidate) await evictOptionalEntry(cache, request);
|
|
476
|
+
} catch { /* A failed read is an optional cache miss. */ }
|
|
477
|
+
return undefined;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async function updateOptionalEntry(cache, request, response, generation) {
|
|
481
|
+
if (!cache || !permitted(generation)) return;
|
|
482
|
+
try {
|
|
483
|
+
if (hasNoStore(response.headers)) await evictOptionalEntry(cache, request);
|
|
484
|
+
else if (response.ok) await cache.put(request, response.clone());
|
|
485
|
+
} catch { /* Quota and other storage failures do not replace the response. */ }
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
async function fetchOrError(request) {
|
|
489
|
+
try { return await fetch(request); } catch { return Response.error(); }
|
|
463
490
|
}
|
|
464
491
|
|
|
465
492
|
async function cacheFirst(request, cacheName, generation) {
|
|
466
493
|
const cache = await openPermittedCache(cacheName, generation);
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (cached) await cache.delete(request);
|
|
472
|
-
const response = await fetch(request);
|
|
473
|
-
if (!permitted(generation)) return response;
|
|
474
|
-
if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());
|
|
475
|
-
if (hasNoStore(response.headers)) await cache.delete(request);
|
|
494
|
+
const cached = await readPermittedEntry(cache, request, generation);
|
|
495
|
+
if (cached && permitted(generation)) return cached;
|
|
496
|
+
const response = await fetchOrError(request);
|
|
497
|
+
await updateOptionalEntry(cache, request, response, generation);
|
|
476
498
|
return response;
|
|
477
499
|
}
|
|
478
500
|
|
|
479
501
|
async function staleWhileRevalidate(request, cacheName, generation) {
|
|
480
502
|
const cache = await openPermittedCache(cacheName, generation);
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
const cached = candidate && !hasNoStore(candidate.headers) ? candidate : undefined;
|
|
485
|
-
if (candidate && !cached) await cache.delete(request);
|
|
486
|
-
const refresh = fetch(request).then(async response => {
|
|
487
|
-
if (!permitted(generation)) return response;
|
|
488
|
-
if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());
|
|
489
|
-
if (hasNoStore(response.headers)) await cache.delete(request);
|
|
503
|
+
const cached = await readPermittedEntry(cache, request, generation);
|
|
504
|
+
const refresh = fetchOrError(request).then(async response => {
|
|
505
|
+
await updateOptionalEntry(cache, request, response, generation);
|
|
490
506
|
return response;
|
|
491
507
|
});
|
|
492
|
-
if (cached
|
|
493
|
-
|
|
508
|
+
if (cached && permitted(generation)) {
|
|
509
|
+
void refresh.catch(() => undefined);
|
|
510
|
+
return cached;
|
|
511
|
+
}
|
|
512
|
+
return refresh;
|
|
494
513
|
}
|
|
495
514
|
|
|
496
515
|
async function networkFirst(request, cacheName, generation) {
|
|
497
516
|
const cache = await openPermittedCache(cacheName, generation);
|
|
498
|
-
|
|
517
|
+
let response;
|
|
499
518
|
try {
|
|
500
|
-
|
|
501
|
-
if (!permitted(generation)) return response;
|
|
502
|
-
if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());
|
|
503
|
-
if (hasNoStore(response.headers)) await cache.delete(request);
|
|
504
|
-
return response;
|
|
519
|
+
response = await fetch(request);
|
|
505
520
|
} catch {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
if (cached) await cache.delete(request);
|
|
511
|
-
const fallback = await cache.match(NAVIGATION_FALLBACK_URL);
|
|
512
|
-
return permitted(generation) && fallback && !hasNoStore(fallback.headers) ? fallback : Response.error();
|
|
521
|
+
const cached = await readPermittedEntry(cache, request, generation);
|
|
522
|
+
if (cached && permitted(generation)) return cached;
|
|
523
|
+
const fallback = await readPermittedEntry(cache, NAVIGATION_FALLBACK_URL, generation);
|
|
524
|
+
return permitted(generation) && fallback ? fallback : Response.error();
|
|
513
525
|
}
|
|
526
|
+
await updateOptionalEntry(cache, request, response, generation);
|
|
527
|
+
return response;
|
|
514
528
|
}
|
|
515
529
|
|
|
516
530
|
self.addEventListener("fetch", (event) => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type OfflineCacheStatus =\n | \"unsupported\"\n | \"idle\"\n | \"warming\"\n | \"ready\"\n | \"partial\"\n | \"quota-risk\"\n | \"offline\"\n | \"error\";\n\nexport type OfflineCacheStrategy =\n | \"cache-first\"\n | \"stale-while-revalidate\"\n | \"network-first\"\n | \"no-cache\";\n\nexport interface OfflineCacheLogger {\n debug?: (...args: unknown[]) => void;\n info?: (...args: unknown[]) => void;\n warn?: (...args: unknown[]) => void;\n error?: (...args: unknown[]) => void;\n}\n\nexport interface OfflineCacheAssetPack {\n readonly id: string;\n readonly revision: string;\n readonly urls: readonly string[];\n readonly estimatedBytes?: number;\n}\n\nexport interface OfflineCacheUrlResult {\n readonly url: string;\n readonly cached: boolean;\n readonly error?: string;\n}\n\nexport interface OfflineCacheAssetPackResult {\n readonly id: string;\n readonly revision: string;\n readonly status: OfflineCacheStatus;\n readonly cacheName?: string;\n readonly cachedUrls: number;\n readonly totalUrls: number;\n readonly results: OfflineCacheUrlResult[];\n readonly estimatedBytes?: number;\n readonly availableBytes?: number;\n readonly error?: string;\n}\n\nexport interface OfflineCacheRequestPolicy {\n readonly sameOriginOnly?: boolean;\n readonly publicNavigationPaths?: readonly string[];\n readonly immutableAssetPathPrefixes?: readonly string[];\n readonly immutableAssetPathPatterns?: readonly RegExp[];\n readonly publicAssetPathPrefixes?: readonly string[];\n readonly publicApiPathPrefixes?: readonly string[];\n readonly deniedPathPrefixes?: readonly string[];\n readonly deniedPathPatterns?: readonly RegExp[];\n}\n\nexport interface OfflineCacheRequestDecision {\n readonly cacheable: boolean;\n readonly strategy: OfflineCacheStrategy;\n readonly reason: string;\n readonly cacheBucket?: \"navigation\" | \"immutable\" | \"public-asset\" | \"public-api\";\n}\n\nexport interface RegisterOfflineCacheWorkerOptions {\n readonly workerUrl?: string;\n readonly scope?: string;\n readonly buildId?: string;\n readonly enabled?: boolean;\n readonly logger?: OfflineCacheLogger;\n readonly serviceWorkerContainer?: ServiceWorkerContainer;\n}\n\nexport interface RegisterOfflineCacheWorkerResult {\n readonly status: \"registered\" | \"unsupported\" | \"disabled\" | \"error\";\n readonly registration?: ServiceWorkerRegistration;\n readonly error?: unknown;\n}\n\nexport interface OfflineCacheRuntime {\n readonly caches?: CacheStorage;\n readonly fetch?: typeof fetch;\n readonly location?: Pick<Location, \"origin\">;\n readonly navigatorStorage?: StorageManager;\n}\n\nexport interface OfflineCacheOperationOptions extends OfflineCacheRuntime {\n readonly cachePrefix?: string;\n readonly logger?: OfflineCacheLogger;\n readonly quotaRiskRatio?: number;\n readonly signal?: AbortSignal;\n}\n\nexport interface OfflineCacheWorkerScriptOptions {\n /** Require renewed host permission before any worker cache access (maximum 60 seconds). */\n readonly requireConsent?: boolean;\n readonly cachePrefix?: string;\n readonly buildId: string;\n readonly policy: OfflineCacheRequestPolicy;\n readonly navigationFallbackUrl?: string;\n}\n\nexport const DEFAULT_OFFLINE_CACHE_PREFIX = \"plasius-offline\";\n\nexport const DEFAULT_OFFLINE_CACHE_POLICY: Required<\n Pick<\n OfflineCacheRequestPolicy,\n | \"sameOriginOnly\"\n | \"publicNavigationPaths\"\n | \"immutableAssetPathPrefixes\"\n | \"publicAssetPathPrefixes\"\n | \"publicApiPathPrefixes\"\n | \"deniedPathPrefixes\"\n >\n> & Pick<OfflineCacheRequestPolicy, \"deniedPathPatterns\"> = Object.freeze({\n sameOriginOnly: true,\n publicNavigationPaths: Object.freeze([\"/\"]),\n immutableAssetPathPrefixes: Object.freeze([\"/assets/\", \"/favicon\", \"/manifest.json\"]),\n publicAssetPathPrefixes: Object.freeze([]),\n publicApiPathPrefixes: Object.freeze([]),\n deniedPathPrefixes: Object.freeze([\n \"/api/admin\",\n \"/api/ai\",\n \"/api/analytics\",\n \"/api/auth\",\n \"/api/game\",\n \"/api/oauth\",\n \"/api/player-system\",\n \"/api/profile\",\n \"/api/users\",\n \"/api/voice\",\n \"/admin\",\n \"/oauth\",\n \"/profile\",\n \"/player-system\",\n ]),\n deniedPathPatterns: Object.freeze([]),\n});\n\nconst SAFE_CACHE_SEGMENT_PATTERN = /[^a-z0-9._-]+/giu;\nconst DEFAULT_QUOTA_RISK_RATIO = 0.9;\n\nfunction sanitizeCacheSegment(value: string): string {\n const sanitized = value\n .trim()\n .toLowerCase()\n .replace(SAFE_CACHE_SEGMENT_PATTERN, \"-\")\n .replace(/^-+|-+$/gu, \"\");\n return sanitized || \"default\";\n}\n\nfunction resolveCacheStorage(runtime?: OfflineCacheRuntime): CacheStorage | undefined {\n return runtime?.caches ?? globalThis.caches;\n}\n\nfunction resolveFetch(runtime?: OfflineCacheRuntime): typeof fetch | undefined {\n return runtime?.fetch ?? globalThis.fetch;\n}\n\nfunction resolveNavigatorStorage(\n runtime?: OfflineCacheRuntime,\n): StorageManager | undefined {\n return runtime?.navigatorStorage ?? globalThis.navigator?.storage;\n}\n\nfunction resolveBaseOrigin(runtime?: OfflineCacheRuntime): string {\n return runtime?.location?.origin ?? globalThis.location?.origin ?? \"https://plasius.co.uk\";\n}\n\nfunction normalizeUrl(value: string, runtime?: OfflineCacheRuntime): string {\n return new URL(value, resolveBaseOrigin(runtime)).toString();\n}\n\nfunction toUrl(input: RequestInfo | URL, runtime?: OfflineCacheRuntime): URL | null {\n try {\n if (typeof input === \"string\") {\n return new URL(input, resolveBaseOrigin(runtime));\n }\n\n if (input instanceof URL) {\n return input;\n }\n\n const requestUrl = (input as Request).url;\n return typeof requestUrl === \"string\"\n ? new URL(requestUrl, resolveBaseOrigin(runtime))\n : null;\n } catch {\n return null;\n }\n}\n\nfunction getRequestMethod(input: RequestInfo | URL, init?: RequestInit): string {\n return (init?.method ?? (typeof input === \"object\" && \"method\" in input ? input.method : \"GET\"))\n .toString()\n .toUpperCase();\n}\n\nfunction hasNoStore(headers: Headers): boolean {\n return (headers.get(\"cache-control\") ?? \"\")\n .split(\",\")\n .some(directive => directive.trim().split(\"=\", 1)[0]?.toLowerCase() === \"no-store\");\n}\n\nfunction getRequestHeaders(input: RequestInfo | URL, init?: RequestInit): Headers {\n if (init?.headers) return new Headers(init.headers);\n return typeof input === \"object\" && \"headers\" in input ? new Headers(input.headers) : new Headers();\n}\n\nfunction pathStartsWith(pathname: string, prefixes: readonly string[] = []): boolean {\n return prefixes.some(prefix => pathname === prefix || pathname.startsWith(prefix));\n}\n\nfunction isNavigationRequest(input: RequestInfo | URL, init?: RequestInit): boolean {\n if (init?.headers) {\n const headers = new Headers(init.headers);\n if (headers.get(\"accept\")?.includes(\"text/html\")) {\n return true;\n }\n }\n\n return typeof input === \"object\" && \"mode\" in input && input.mode === \"navigate\";\n}\n\nexport function buildOfflineAssetCacheName(\n pack: Pick<OfflineCacheAssetPack, \"id\" | \"revision\">,\n cachePrefix = DEFAULT_OFFLINE_CACHE_PREFIX,\n): string {\n return [\n sanitizeCacheSegment(cachePrefix),\n \"asset-pack\",\n sanitizeCacheSegment(pack.id),\n sanitizeCacheSegment(pack.revision),\n ].join(\"-\");\n}\n\nexport function classifyOfflineCacheRequest(\n input: RequestInfo | URL,\n init?: RequestInit,\n policy: OfflineCacheRequestPolicy = DEFAULT_OFFLINE_CACHE_POLICY,\n runtime?: OfflineCacheRuntime,\n): OfflineCacheRequestDecision {\n const method = getRequestMethod(input, init);\n if (method !== \"GET\" && method !== \"HEAD\") {\n return { cacheable: false, strategy: \"no-cache\", reason: \"non-get-request\" };\n }\n if (hasNoStore(getRequestHeaders(input, init))) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"request-cache-control-no-store\" };\n }\n\n const url = toUrl(input, runtime);\n if (!url) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"invalid-url\" };\n }\n\n const sameOriginOnly = policy.sameOriginOnly ?? DEFAULT_OFFLINE_CACHE_POLICY.sameOriginOnly;\n if (sameOriginOnly && url.origin !== resolveBaseOrigin(runtime)) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"cross-origin\" };\n }\n\n const pathname = url.pathname;\n if ((policy.deniedPathPatterns ?? []).some(pattern => pattern.test(pathname))) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"denied-path-pattern\" };\n }\n\n if (\n pathStartsWith(\n pathname,\n policy.deniedPathPrefixes ?? DEFAULT_OFFLINE_CACHE_POLICY.deniedPathPrefixes,\n )\n ) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"denied-path-prefix\" };\n }\n\n if (policy.immutableAssetPathPatterns?.some(pattern => new RegExp(pattern.source, pattern.flags).test(pathname))) {\n return { cacheable: true, strategy: \"cache-first\", reason: \"immutable-asset-pattern\", cacheBucket: \"immutable\" };\n }\n\n if (pathStartsWith(pathname, policy.publicApiPathPrefixes)) {\n return {\n cacheable: true,\n strategy: \"stale-while-revalidate\",\n reason: \"public-api\",\n cacheBucket: \"public-api\",\n };\n }\n\n if (pathStartsWith(pathname, policy.publicAssetPathPrefixes)) {\n return {\n cacheable: true,\n strategy: \"stale-while-revalidate\",\n reason: \"public-asset\",\n cacheBucket: \"public-asset\",\n };\n }\n\n if (\n pathStartsWith(\n pathname,\n policy.immutableAssetPathPrefixes\n ?? DEFAULT_OFFLINE_CACHE_POLICY.immutableAssetPathPrefixes,\n )\n ) {\n return {\n cacheable: true,\n strategy: \"cache-first\",\n reason: \"immutable-asset\",\n cacheBucket: \"immutable\",\n };\n }\n\n if (\n isNavigationRequest(input, init)\n && (policy.publicNavigationPaths ?? DEFAULT_OFFLINE_CACHE_POLICY.publicNavigationPaths)\n .includes(pathname)\n ) {\n return {\n cacheable: true,\n strategy: \"network-first\",\n reason: \"public-navigation\",\n cacheBucket: \"navigation\",\n };\n }\n\n return { cacheable: false, strategy: \"no-cache\", reason: \"unmatched\" };\n}\n\nasync function resolveAvailableBytes(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions,\n): Promise<number | undefined> {\n if (typeof pack.estimatedBytes !== \"number\" || pack.estimatedBytes <= 0) {\n return undefined;\n }\n\n try {\n const estimate = await resolveNavigatorStorage(options)?.estimate?.();\n if (\n typeof estimate?.quota !== \"number\"\n || typeof estimate.usage !== \"number\"\n || estimate.quota <= estimate.usage\n ) {\n return undefined;\n }\n\n return estimate.quota - estimate.usage;\n } catch (error) {\n options.logger?.debug?.(\"offline cache quota estimate unavailable\", { error });\n return undefined;\n }\n}\n\nfunction resultStatus(results: readonly OfflineCacheUrlResult[]): OfflineCacheStatus {\n const cachedCount = results.filter(result => result.cached).length;\n if (cachedCount === results.length) {\n return \"ready\";\n }\n if (cachedCount > 0) {\n return \"partial\";\n }\n if (results.some(result => result.error === \"offline\")) {\n return \"offline\";\n }\n return \"error\";\n}\n\nexport async function warmAssetPack(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions = {},\n): Promise<OfflineCacheAssetPackResult> {\n const cacheStorage = resolveCacheStorage(options);\n const fetchImpl = resolveFetch(options);\n const totalUrls = pack.urls.length;\n const cacheName = buildOfflineAssetCacheName(pack, options.cachePrefix);\n\n if (!cacheStorage || typeof fetchImpl !== \"function\") {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"unsupported\",\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n if (totalUrls === 0) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"idle\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n const availableBytes = await resolveAvailableBytes(pack, options);\n const riskRatio = options.quotaRiskRatio ?? DEFAULT_QUOTA_RISK_RATIO;\n if (\n typeof availableBytes === \"number\"\n && typeof pack.estimatedBytes === \"number\"\n && pack.estimatedBytes > availableBytes * riskRatio\n ) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"quota-risk\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n availableBytes,\n };\n }\n\n options.signal?.throwIfAborted();\n const cache = await cacheStorage.open(cacheName);\n if (options.signal?.aborted) {\n await cacheStorage.delete(cacheName);\n options.signal.throwIfAborted();\n }\n const results: OfflineCacheUrlResult[] = [];\n\n for (const rawUrl of pack.urls) {\n const url = normalizeUrl(rawUrl, options);\n try {\n options.signal?.throwIfAborted();\n const request = new Request(url, {\n method: \"GET\",\n credentials: \"same-origin\",\n cache: \"reload\",\n signal: options.signal,\n });\n const response = await fetchImpl(request);\n options.signal?.throwIfAborted();\n if (!response.ok) {\n const existing = await cache.match(url);\n results.push({\n url,\n cached: Boolean(existing),\n error: existing ? undefined : `http-${response.status}`,\n });\n continue;\n }\n\n if (hasNoStore(response.headers)) {\n await cache.delete(url);\n results.push({ url, cached: false, error: \"cache-control-no-store\" });\n continue;\n }\n\n await cache.put(url, response.clone());\n results.push({ url, cached: true });\n } catch (error) {\n options.signal?.throwIfAborted();\n const existing = await cache.match(url);\n const isOffline =\n typeof globalThis.navigator !== \"undefined\" && globalThis.navigator.onLine === false;\n results.push({\n url,\n cached: Boolean(existing),\n error: existing ? undefined : isOffline ? \"offline\" : String(error),\n });\n }\n }\n\n return {\n id: pack.id,\n revision: pack.revision,\n status: resultStatus(results),\n cacheName,\n cachedUrls: results.filter(result => result.cached).length,\n totalUrls,\n results,\n estimatedBytes: pack.estimatedBytes,\n availableBytes,\n };\n}\n\nexport async function getAssetPackStatus(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions = {},\n): Promise<OfflineCacheAssetPackResult> {\n const cacheStorage = resolveCacheStorage(options);\n const totalUrls = pack.urls.length;\n const cacheName = buildOfflineAssetCacheName(pack, options.cachePrefix);\n\n if (!cacheStorage) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"unsupported\",\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n if (totalUrls === 0) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"idle\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n const cache = await cacheStorage.open(cacheName);\n const results = await Promise.all(\n pack.urls.map(async rawUrl => {\n const url = normalizeUrl(rawUrl, options);\n return {\n url,\n cached: Boolean(await cache.match(url)),\n };\n }),\n );\n\n return {\n id: pack.id,\n revision: pack.revision,\n status: resultStatus(results),\n cacheName,\n cachedUrls: results.filter(result => result.cached).length,\n totalUrls,\n results,\n estimatedBytes: pack.estimatedBytes,\n };\n}\n\nexport async function clearOfflineCaches(options: {\n readonly cachePrefix?: string;\n readonly caches?: CacheStorage;\n} = {}): Promise<string[]> {\n const cacheStorage = options.caches ?? globalThis.caches;\n if (!cacheStorage) {\n return [];\n }\n\n const prefix = sanitizeCacheSegment(options.cachePrefix ?? DEFAULT_OFFLINE_CACHE_PREFIX);\n const cacheNames = await cacheStorage.keys();\n const deleted: string[] = [];\n for (const cacheName of cacheNames) {\n if (cacheName.startsWith(prefix) && await cacheStorage.delete(cacheName)) {\n deleted.push(cacheName);\n }\n }\n return deleted;\n}\n\nexport async function registerOfflineCacheWorker(\n options: RegisterOfflineCacheWorkerOptions = {},\n): Promise<RegisterOfflineCacheWorkerResult> {\n if (options.enabled === false) {\n return { status: \"disabled\" };\n }\n\n const serviceWorkerContainer =\n options.serviceWorkerContainer ?? globalThis.navigator?.serviceWorker;\n if (!serviceWorkerContainer) {\n return { status: \"unsupported\" };\n }\n\n const workerUrl = new URL(\n options.workerUrl ?? \"/offline-cache-worker.js\",\n globalThis.location?.origin ?? \"https://plasius.co.uk\",\n );\n if (options.buildId) {\n workerUrl.searchParams.set(\"build\", options.buildId);\n }\n\n try {\n const registration = await serviceWorkerContainer.register(workerUrl.toString(), {\n scope: options.scope ?? \"/\",\n });\n options.logger?.info?.(\"offline cache worker registered\", {\n workerUrl: workerUrl.pathname,\n scope: registration.scope,\n });\n return {\n status: \"registered\",\n registration,\n };\n } catch (error) {\n options.logger?.warn?.(\"offline cache worker registration failed\", { error });\n return {\n status: \"error\",\n error,\n };\n }\n}\n\nexport function createOfflineCacheWorkerScript(\n options: OfflineCacheWorkerScriptOptions,\n): string {\n const cachePrefix = sanitizeCacheSegment(\n options.cachePrefix ?? DEFAULT_OFFLINE_CACHE_PREFIX,\n );\n const buildId = sanitizeCacheSegment(options.buildId);\n const policyJson = JSON.stringify({ ...options.policy,\n immutableAssetPathPatterns: options.policy.immutableAssetPathPatterns?.map(pattern => ({ source: pattern.source, flags: pattern.flags })),\n deniedPathPatterns: options.policy.deniedPathPatterns?.map(pattern => ({ source: pattern.source, flags: pattern.flags })),\n });\n const fallbackUrl = JSON.stringify(options.navigationFallbackUrl ?? \"/\");\n\n return `\nconst CACHE_PREFIX = ${JSON.stringify(cachePrefix)};\nconst BUILD_ID = ${JSON.stringify(buildId)};\nconst APP_CACHE = CACHE_PREFIX + \"-app-\" + BUILD_ID;\nconst PUBLIC_CACHE = CACHE_PREFIX + \"-public-\" + BUILD_ID;\nconst POLICY = ${policyJson};\nconst NAVIGATION_FALLBACK_URL = ${fallbackUrl};\nconst REQUIRE_CONSENT = ${options.requireConsent === true};\nlet permissionUntil = REQUIRE_CONSENT ? 0 : Infinity;\nlet permissionGeneration = 0;\nconst permitted = (generation) => generation === permissionGeneration && Date.now() < permissionUntil;\nasync function discardCaches() {\n const names = await caches.keys();\n await Promise.all(names.filter(name => name.startsWith(CACHE_PREFIX + \"-\")).map(name => caches.delete(name)));\n}\nself.addEventListener(\"message\", event => {\n if (!REQUIRE_CONSENT || event.data?.type !== \"plasius-offline-consent-v1\") return;\n try { if (new URL(event.source?.url).origin !== self.location.origin) return; } catch { return; }\n const requested = event.data.allowedUntil;\n permissionUntil = typeof requested === \"number\" && Number.isFinite(requested)\n ? Math.min(requested, Date.now() + 60_000) : 0;\n const disabled = permissionUntil <= Date.now();\n if (disabled) permissionGeneration++;\n event.waitUntil((async () => {\n if (disabled) await discardCaches();\n event.ports?.[0]?.postMessage({ type: \"plasius-offline-consent-v1\", disabled });\n })());\n});\n\nconst startsWithAny = (pathname, prefixes = []) => prefixes.some((prefix) => pathname === prefix || pathname.startsWith(prefix));\nconst matchesAny = (pathname, patterns = []) => patterns.some(pattern => new RegExp(pattern.source, pattern.flags).test(pathname));\nconst isDenied = (pathname) => startsWithAny(pathname, POLICY.deniedPathPrefixes || []) || matchesAny(pathname, POLICY.deniedPathPatterns);\nconst hasNoStore = (headers) => (headers.get(\"cache-control\") || \"\").split(\",\").some((directive) => directive.trim().split(\"=\", 1)[0].toLowerCase() === \"no-store\");\nconst classify = (request) => {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") return { cacheable: false, strategy: \"no-cache\" };\n if (hasNoStore(request.headers)) return { cacheable: false, strategy: \"no-cache\", reason: \"request-cache-control-no-store\" };\n const url = new URL(request.url);\n if (POLICY.sameOriginOnly !== false && url.origin !== self.location.origin) return { cacheable: false, strategy: \"no-cache\" };\n if (isDenied(url.pathname)) return { cacheable: false, strategy: \"no-cache\" };\n if (matchesAny(url.pathname, POLICY.immutableAssetPathPatterns)) return { cacheable: true, strategy: \"cache-first\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.publicApiPathPrefixes || [])) return { cacheable: true, strategy: \"stale-while-revalidate\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.publicAssetPathPrefixes || [])) return { cacheable: true, strategy: \"stale-while-revalidate\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.immutableAssetPathPrefixes || [])) return { cacheable: true, strategy: \"cache-first\", cacheName: APP_CACHE };\n if (request.mode === \"navigate\" && (POLICY.publicNavigationPaths || []).includes(url.pathname)) return { cacheable: true, strategy: \"network-first\", cacheName: APP_CACHE };\n return { cacheable: false, strategy: \"no-cache\" };\n};\n\nself.addEventListener(\"install\", (event) => {\n event.waitUntil(self.skipWaiting());\n});\n\nself.addEventListener(\"activate\", (event) => {\n event.waitUntil((async () => {\n const names = await caches.keys();\n await Promise.all(names.filter((name) => name.startsWith(CACHE_PREFIX + \"-\") && !name.endsWith(\"-\" + BUILD_ID) && !name.includes(\"-asset-pack-\")).map((name) => caches.delete(name)));\n await self.clients.claim();\n })());\n});\n\nasync function openPermittedCache(cacheName, generation) {\n if (!permitted(generation)) return null;\n const cache = await caches.open(cacheName);\n if (!permitted(generation)) {\n await caches.delete(cacheName);\n return null;\n }\n return cache;\n}\n\nasync function cacheFirst(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n if (!cache) return fetch(request);\n const cached = await cache.match(request);\n if (!permitted(generation)) return fetch(request);\n if (cached && !hasNoStore(cached.headers)) return cached;\n if (cached) await cache.delete(request);\n const response = await fetch(request);\n if (!permitted(generation)) return response;\n if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());\n if (hasNoStore(response.headers)) await cache.delete(request);\n return response;\n}\n\nasync function staleWhileRevalidate(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n if (!cache) return fetch(request);\n const candidate = await cache.match(request);\n if (!permitted(generation)) return fetch(request);\n const cached = candidate && !hasNoStore(candidate.headers) ? candidate : undefined;\n if (candidate && !cached) await cache.delete(request);\n const refresh = fetch(request).then(async response => {\n if (!permitted(generation)) return response;\n if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());\n if (hasNoStore(response.headers)) await cache.delete(request);\n return response;\n });\n if (cached) void refresh.catch(() => undefined);\n return cached || refresh;\n}\n\nasync function networkFirst(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n if (!cache) return fetch(request);\n try {\n const response = await fetch(request);\n if (!permitted(generation)) return response;\n if (response.ok && !hasNoStore(response.headers)) await cache.put(request, response.clone());\n if (hasNoStore(response.headers)) await cache.delete(request);\n return response;\n } catch {\n if (!permitted(generation)) return Response.error();\n const cached = await cache.match(request);\n if (!permitted(generation)) return Response.error();\n if (cached && !hasNoStore(cached.headers)) return cached;\n if (cached) await cache.delete(request);\n const fallback = await cache.match(NAVIGATION_FALLBACK_URL);\n return permitted(generation) && fallback && !hasNoStore(fallback.headers) ? fallback : Response.error();\n }\n}\n\nself.addEventListener(\"fetch\", (event) => {\n const generation = permissionGeneration;\n if (!permitted(generation)) return;\n const decision = classify(event.request);\n if (!decision.cacheable) return;\n if (decision.strategy === \"cache-first\") event.respondWith(cacheFirst(event.request, decision.cacheName, generation));\n if (decision.strategy === \"stale-while-revalidate\") event.respondWith(staleWhileRevalidate(event.request, decision.cacheName, generation));\n if (decision.strategy === \"network-first\") event.respondWith(networkFirst(event.request, decision.cacheName, generation));\n});\n`.trimStart();\n}\n"],"mappings":";AAyGO,IAAM,+BAA+B;AAErC,IAAM,+BAU+C,OAAO,OAAO;AAAA,EACxE,gBAAgB;AAAA,EAChB,uBAAuB,OAAO,OAAO,CAAC,GAAG,CAAC;AAAA,EAC1C,4BAA4B,OAAO,OAAO,CAAC,YAAY,YAAY,gBAAgB,CAAC;AAAA,EACpF,yBAAyB,OAAO,OAAO,CAAC,CAAC;AAAA,EACzC,uBAAuB,OAAO,OAAO,CAAC,CAAC;AAAA,EACvC,oBAAoB,OAAO,OAAO;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,oBAAoB,OAAO,OAAO,CAAC,CAAC;AACtC,CAAC;AAED,IAAM,6BAA6B;AACnC,IAAM,2BAA2B;AAEjC,SAA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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0HvD,UAAU;AACZ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type OfflineCacheStatus =\n | \"unsupported\"\n | \"idle\"\n | \"warming\"\n | \"ready\"\n | \"partial\"\n | \"quota-risk\"\n | \"offline\"\n | \"error\";\n\nexport type OfflineCacheStrategy =\n | \"cache-first\"\n | \"stale-while-revalidate\"\n | \"network-first\"\n | \"no-cache\";\n\nexport interface OfflineCacheLogger {\n debug?: (...args: unknown[]) => void;\n info?: (...args: unknown[]) => void;\n warn?: (...args: unknown[]) => void;\n error?: (...args: unknown[]) => void;\n}\n\nexport interface OfflineCacheAssetPack {\n readonly id: string;\n readonly revision: string;\n readonly urls: readonly string[];\n readonly estimatedBytes?: number;\n}\n\nexport interface OfflineCacheUrlResult {\n readonly url: string;\n readonly cached: boolean;\n readonly error?: string;\n}\n\nexport interface OfflineCacheAssetPackResult {\n readonly id: string;\n readonly revision: string;\n readonly status: OfflineCacheStatus;\n readonly cacheName?: string;\n readonly cachedUrls: number;\n readonly totalUrls: number;\n readonly results: OfflineCacheUrlResult[];\n readonly estimatedBytes?: number;\n readonly availableBytes?: number;\n readonly error?: string;\n}\n\nexport interface OfflineCacheRequestPolicy {\n readonly sameOriginOnly?: boolean;\n readonly publicNavigationPaths?: readonly string[];\n readonly immutableAssetPathPrefixes?: readonly string[];\n readonly immutableAssetPathPatterns?: readonly RegExp[];\n readonly publicAssetPathPrefixes?: readonly string[];\n readonly publicApiPathPrefixes?: readonly string[];\n readonly deniedPathPrefixes?: readonly string[];\n readonly deniedPathPatterns?: readonly RegExp[];\n}\n\nexport interface OfflineCacheRequestDecision {\n readonly cacheable: boolean;\n readonly strategy: OfflineCacheStrategy;\n readonly reason: string;\n readonly cacheBucket?: \"navigation\" | \"immutable\" | \"public-asset\" | \"public-api\";\n}\n\nexport interface RegisterOfflineCacheWorkerOptions {\n readonly workerUrl?: string;\n readonly scope?: string;\n readonly buildId?: string;\n readonly enabled?: boolean;\n readonly logger?: OfflineCacheLogger;\n readonly serviceWorkerContainer?: ServiceWorkerContainer;\n}\n\nexport interface RegisterOfflineCacheWorkerResult {\n readonly status: \"registered\" | \"unsupported\" | \"disabled\" | \"error\";\n readonly registration?: ServiceWorkerRegistration;\n readonly error?: unknown;\n}\n\nexport interface OfflineCacheRuntime {\n readonly caches?: CacheStorage;\n readonly fetch?: typeof fetch;\n readonly location?: Pick<Location, \"origin\">;\n readonly navigatorStorage?: StorageManager;\n}\n\nexport interface OfflineCacheOperationOptions extends OfflineCacheRuntime {\n readonly cachePrefix?: string;\n readonly logger?: OfflineCacheLogger;\n readonly quotaRiskRatio?: number;\n readonly signal?: AbortSignal;\n}\n\nexport interface OfflineCacheWorkerScriptOptions {\n /** Require renewed host permission before any worker cache access (maximum 60 seconds). */\n readonly requireConsent?: boolean;\n readonly cachePrefix?: string;\n readonly buildId: string;\n readonly policy: OfflineCacheRequestPolicy;\n readonly navigationFallbackUrl?: string;\n}\n\nexport const DEFAULT_OFFLINE_CACHE_PREFIX = \"plasius-offline\";\n\nexport const DEFAULT_OFFLINE_CACHE_POLICY: Required<\n Pick<\n OfflineCacheRequestPolicy,\n | \"sameOriginOnly\"\n | \"publicNavigationPaths\"\n | \"immutableAssetPathPrefixes\"\n | \"publicAssetPathPrefixes\"\n | \"publicApiPathPrefixes\"\n | \"deniedPathPrefixes\"\n >\n> & Pick<OfflineCacheRequestPolicy, \"deniedPathPatterns\"> = Object.freeze({\n sameOriginOnly: true,\n publicNavigationPaths: Object.freeze([\"/\"]),\n immutableAssetPathPrefixes: Object.freeze([\"/assets/\", \"/favicon\", \"/manifest.json\"]),\n publicAssetPathPrefixes: Object.freeze([]),\n publicApiPathPrefixes: Object.freeze([]),\n deniedPathPrefixes: Object.freeze([\n \"/api/admin\",\n \"/api/ai\",\n \"/api/analytics\",\n \"/api/auth\",\n \"/api/game\",\n \"/api/oauth\",\n \"/api/player-system\",\n \"/api/profile\",\n \"/api/users\",\n \"/api/voice\",\n \"/admin\",\n \"/oauth\",\n \"/profile\",\n \"/player-system\",\n ]),\n deniedPathPatterns: Object.freeze([]),\n});\n\nconst SAFE_CACHE_SEGMENT_PATTERN = /[^a-z0-9._-]+/giu;\nconst DEFAULT_QUOTA_RISK_RATIO = 0.9;\n\nfunction sanitizeCacheSegment(value: string): string {\n const sanitized = value\n .trim()\n .toLowerCase()\n .replace(SAFE_CACHE_SEGMENT_PATTERN, \"-\")\n .replace(/^-+|-+$/gu, \"\");\n return sanitized || \"default\";\n}\n\nfunction resolveCacheStorage(runtime?: OfflineCacheRuntime): CacheStorage | undefined {\n return runtime?.caches ?? globalThis.caches;\n}\n\nfunction resolveFetch(runtime?: OfflineCacheRuntime): typeof fetch | undefined {\n return runtime?.fetch ?? globalThis.fetch;\n}\n\nfunction resolveNavigatorStorage(\n runtime?: OfflineCacheRuntime,\n): StorageManager | undefined {\n return runtime?.navigatorStorage ?? globalThis.navigator?.storage;\n}\n\nfunction resolveBaseOrigin(runtime?: OfflineCacheRuntime): string {\n return runtime?.location?.origin ?? globalThis.location?.origin ?? \"https://plasius.co.uk\";\n}\n\nfunction normalizeUrl(value: string, runtime?: OfflineCacheRuntime): string {\n return new URL(value, resolveBaseOrigin(runtime)).toString();\n}\n\nfunction toUrl(input: RequestInfo | URL, runtime?: OfflineCacheRuntime): URL | null {\n try {\n if (typeof input === \"string\") {\n return new URL(input, resolveBaseOrigin(runtime));\n }\n\n if (input instanceof URL) {\n return input;\n }\n\n const requestUrl = (input as Request).url;\n return typeof requestUrl === \"string\"\n ? new URL(requestUrl, resolveBaseOrigin(runtime))\n : null;\n } catch {\n return null;\n }\n}\n\nfunction getRequestMethod(input: RequestInfo | URL, init?: RequestInit): string {\n return (init?.method ?? (typeof input === \"object\" && \"method\" in input ? input.method : \"GET\"))\n .toString()\n .toUpperCase();\n}\n\nfunction hasNoStore(headers: Headers): boolean {\n return (headers.get(\"cache-control\") ?? \"\")\n .split(\",\")\n .some(directive => directive.trim().split(\"=\", 1)[0]?.toLowerCase() === \"no-store\");\n}\n\nfunction getRequestHeaders(input: RequestInfo | URL, init?: RequestInit): Headers {\n if (init?.headers) return new Headers(init.headers);\n return typeof input === \"object\" && \"headers\" in input ? new Headers(input.headers) : new Headers();\n}\n\nfunction pathStartsWith(pathname: string, prefixes: readonly string[] = []): boolean {\n return prefixes.some(prefix => pathname === prefix || pathname.startsWith(prefix));\n}\n\nfunction isNavigationRequest(input: RequestInfo | URL, init?: RequestInit): boolean {\n if (init?.headers) {\n const headers = new Headers(init.headers);\n if (headers.get(\"accept\")?.includes(\"text/html\")) {\n return true;\n }\n }\n\n return typeof input === \"object\" && \"mode\" in input && input.mode === \"navigate\";\n}\n\nexport function buildOfflineAssetCacheName(\n pack: Pick<OfflineCacheAssetPack, \"id\" | \"revision\">,\n cachePrefix = DEFAULT_OFFLINE_CACHE_PREFIX,\n): string {\n return [\n sanitizeCacheSegment(cachePrefix),\n \"asset-pack\",\n sanitizeCacheSegment(pack.id),\n sanitizeCacheSegment(pack.revision),\n ].join(\"-\");\n}\n\nexport function classifyOfflineCacheRequest(\n input: RequestInfo | URL,\n init?: RequestInit,\n policy: OfflineCacheRequestPolicy = DEFAULT_OFFLINE_CACHE_POLICY,\n runtime?: OfflineCacheRuntime,\n): OfflineCacheRequestDecision {\n const method = getRequestMethod(input, init);\n if (method !== \"GET\" && method !== \"HEAD\") {\n return { cacheable: false, strategy: \"no-cache\", reason: \"non-get-request\" };\n }\n if (hasNoStore(getRequestHeaders(input, init))) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"request-cache-control-no-store\" };\n }\n\n const url = toUrl(input, runtime);\n if (!url) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"invalid-url\" };\n }\n\n const sameOriginOnly = policy.sameOriginOnly ?? DEFAULT_OFFLINE_CACHE_POLICY.sameOriginOnly;\n if (sameOriginOnly && url.origin !== resolveBaseOrigin(runtime)) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"cross-origin\" };\n }\n\n const pathname = url.pathname;\n if ((policy.deniedPathPatterns ?? []).some(pattern => pattern.test(pathname))) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"denied-path-pattern\" };\n }\n\n if (\n pathStartsWith(\n pathname,\n policy.deniedPathPrefixes ?? DEFAULT_OFFLINE_CACHE_POLICY.deniedPathPrefixes,\n )\n ) {\n return { cacheable: false, strategy: \"no-cache\", reason: \"denied-path-prefix\" };\n }\n\n if (policy.immutableAssetPathPatterns?.some(pattern => new RegExp(pattern.source, pattern.flags).test(pathname))) {\n return { cacheable: true, strategy: \"cache-first\", reason: \"immutable-asset-pattern\", cacheBucket: \"immutable\" };\n }\n\n if (pathStartsWith(pathname, policy.publicApiPathPrefixes)) {\n return {\n cacheable: true,\n strategy: \"stale-while-revalidate\",\n reason: \"public-api\",\n cacheBucket: \"public-api\",\n };\n }\n\n if (pathStartsWith(pathname, policy.publicAssetPathPrefixes)) {\n return {\n cacheable: true,\n strategy: \"stale-while-revalidate\",\n reason: \"public-asset\",\n cacheBucket: \"public-asset\",\n };\n }\n\n if (\n pathStartsWith(\n pathname,\n policy.immutableAssetPathPrefixes\n ?? DEFAULT_OFFLINE_CACHE_POLICY.immutableAssetPathPrefixes,\n )\n ) {\n return {\n cacheable: true,\n strategy: \"cache-first\",\n reason: \"immutable-asset\",\n cacheBucket: \"immutable\",\n };\n }\n\n if (\n isNavigationRequest(input, init)\n && (policy.publicNavigationPaths ?? DEFAULT_OFFLINE_CACHE_POLICY.publicNavigationPaths)\n .includes(pathname)\n ) {\n return {\n cacheable: true,\n strategy: \"network-first\",\n reason: \"public-navigation\",\n cacheBucket: \"navigation\",\n };\n }\n\n return { cacheable: false, strategy: \"no-cache\", reason: \"unmatched\" };\n}\n\nasync function resolveAvailableBytes(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions,\n): Promise<number | undefined> {\n if (typeof pack.estimatedBytes !== \"number\" || pack.estimatedBytes <= 0) {\n return undefined;\n }\n\n try {\n const estimate = await resolveNavigatorStorage(options)?.estimate?.();\n if (\n typeof estimate?.quota !== \"number\"\n || typeof estimate.usage !== \"number\"\n || estimate.quota <= estimate.usage\n ) {\n return undefined;\n }\n\n return estimate.quota - estimate.usage;\n } catch (error) {\n options.logger?.debug?.(\"offline cache quota estimate unavailable\", { error });\n return undefined;\n }\n}\n\nfunction resultStatus(results: readonly OfflineCacheUrlResult[]): OfflineCacheStatus {\n const cachedCount = results.filter(result => result.cached).length;\n if (cachedCount === results.length) {\n return \"ready\";\n }\n if (cachedCount > 0) {\n return \"partial\";\n }\n if (results.some(result => result.error === \"offline\")) {\n return \"offline\";\n }\n return \"error\";\n}\n\nexport async function warmAssetPack(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions = {},\n): Promise<OfflineCacheAssetPackResult> {\n const cacheStorage = resolveCacheStorage(options);\n const fetchImpl = resolveFetch(options);\n const totalUrls = pack.urls.length;\n const cacheName = buildOfflineAssetCacheName(pack, options.cachePrefix);\n\n if (!cacheStorage || typeof fetchImpl !== \"function\") {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"unsupported\",\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n if (totalUrls === 0) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"idle\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n const availableBytes = await resolveAvailableBytes(pack, options);\n const riskRatio = options.quotaRiskRatio ?? DEFAULT_QUOTA_RISK_RATIO;\n if (\n typeof availableBytes === \"number\"\n && typeof pack.estimatedBytes === \"number\"\n && pack.estimatedBytes > availableBytes * riskRatio\n ) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"quota-risk\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n availableBytes,\n };\n }\n\n options.signal?.throwIfAborted();\n const cache = await cacheStorage.open(cacheName);\n if (options.signal?.aborted) {\n await cacheStorage.delete(cacheName);\n options.signal.throwIfAborted();\n }\n const results: OfflineCacheUrlResult[] = [];\n\n for (const rawUrl of pack.urls) {\n const url = normalizeUrl(rawUrl, options);\n try {\n options.signal?.throwIfAborted();\n const request = new Request(url, {\n method: \"GET\",\n credentials: \"same-origin\",\n cache: \"reload\",\n signal: options.signal,\n });\n const response = await fetchImpl(request);\n options.signal?.throwIfAborted();\n if (!response.ok) {\n const existing = await cache.match(url);\n results.push({\n url,\n cached: Boolean(existing),\n error: existing ? undefined : `http-${response.status}`,\n });\n continue;\n }\n\n if (hasNoStore(response.headers)) {\n await cache.delete(url);\n results.push({ url, cached: false, error: \"cache-control-no-store\" });\n continue;\n }\n\n await cache.put(url, response.clone());\n results.push({ url, cached: true });\n } catch (error) {\n options.signal?.throwIfAborted();\n const existing = await cache.match(url);\n const isOffline =\n typeof globalThis.navigator !== \"undefined\" && globalThis.navigator.onLine === false;\n results.push({\n url,\n cached: Boolean(existing),\n error: existing ? undefined : isOffline ? \"offline\" : String(error),\n });\n }\n }\n\n return {\n id: pack.id,\n revision: pack.revision,\n status: resultStatus(results),\n cacheName,\n cachedUrls: results.filter(result => result.cached).length,\n totalUrls,\n results,\n estimatedBytes: pack.estimatedBytes,\n availableBytes,\n };\n}\n\nexport async function getAssetPackStatus(\n pack: OfflineCacheAssetPack,\n options: OfflineCacheOperationOptions = {},\n): Promise<OfflineCacheAssetPackResult> {\n const cacheStorage = resolveCacheStorage(options);\n const totalUrls = pack.urls.length;\n const cacheName = buildOfflineAssetCacheName(pack, options.cachePrefix);\n\n if (!cacheStorage) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"unsupported\",\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n if (totalUrls === 0) {\n return {\n id: pack.id,\n revision: pack.revision,\n status: \"idle\",\n cacheName,\n cachedUrls: 0,\n totalUrls,\n results: [],\n estimatedBytes: pack.estimatedBytes,\n };\n }\n\n const cache = await cacheStorage.open(cacheName);\n const results = await Promise.all(\n pack.urls.map(async rawUrl => {\n const url = normalizeUrl(rawUrl, options);\n return {\n url,\n cached: Boolean(await cache.match(url)),\n };\n }),\n );\n\n return {\n id: pack.id,\n revision: pack.revision,\n status: resultStatus(results),\n cacheName,\n cachedUrls: results.filter(result => result.cached).length,\n totalUrls,\n results,\n estimatedBytes: pack.estimatedBytes,\n };\n}\n\nexport async function clearOfflineCaches(options: {\n readonly cachePrefix?: string;\n readonly caches?: CacheStorage;\n} = {}): Promise<string[]> {\n const cacheStorage = options.caches ?? globalThis.caches;\n if (!cacheStorage) {\n return [];\n }\n\n const prefix = sanitizeCacheSegment(options.cachePrefix ?? DEFAULT_OFFLINE_CACHE_PREFIX);\n const cacheNames = await cacheStorage.keys();\n const deleted: string[] = [];\n for (const cacheName of cacheNames) {\n if (cacheName.startsWith(prefix) && await cacheStorage.delete(cacheName)) {\n deleted.push(cacheName);\n }\n }\n return deleted;\n}\n\nexport async function registerOfflineCacheWorker(\n options: RegisterOfflineCacheWorkerOptions = {},\n): Promise<RegisterOfflineCacheWorkerResult> {\n if (options.enabled === false) {\n return { status: \"disabled\" };\n }\n\n const serviceWorkerContainer =\n options.serviceWorkerContainer ?? globalThis.navigator?.serviceWorker;\n if (!serviceWorkerContainer) {\n return { status: \"unsupported\" };\n }\n\n const workerUrl = new URL(\n options.workerUrl ?? \"/offline-cache-worker.js\",\n globalThis.location?.origin ?? \"https://plasius.co.uk\",\n );\n if (options.buildId) {\n workerUrl.searchParams.set(\"build\", options.buildId);\n }\n\n try {\n const registration = await serviceWorkerContainer.register(workerUrl.toString(), {\n scope: options.scope ?? \"/\",\n });\n options.logger?.info?.(\"offline cache worker registered\", {\n workerUrl: workerUrl.pathname,\n scope: registration.scope,\n });\n return {\n status: \"registered\",\n registration,\n };\n } catch (error) {\n options.logger?.warn?.(\"offline cache worker registration failed\", { error });\n return {\n status: \"error\",\n error,\n };\n }\n}\n\nexport function createOfflineCacheWorkerScript(\n options: OfflineCacheWorkerScriptOptions,\n): string {\n const cachePrefix = sanitizeCacheSegment(\n options.cachePrefix ?? DEFAULT_OFFLINE_CACHE_PREFIX,\n );\n const buildId = sanitizeCacheSegment(options.buildId);\n const policyJson = JSON.stringify({ ...options.policy,\n immutableAssetPathPatterns: options.policy.immutableAssetPathPatterns?.map(pattern => ({ source: pattern.source, flags: pattern.flags })),\n deniedPathPatterns: options.policy.deniedPathPatterns?.map(pattern => ({ source: pattern.source, flags: pattern.flags })),\n });\n const fallbackUrl = JSON.stringify(options.navigationFallbackUrl ?? \"/\");\n\n return `\nconst CACHE_PREFIX = ${JSON.stringify(cachePrefix)};\nconst BUILD_ID = ${JSON.stringify(buildId)};\nconst APP_CACHE = CACHE_PREFIX + \"-app-\" + BUILD_ID;\nconst PUBLIC_CACHE = CACHE_PREFIX + \"-public-\" + BUILD_ID;\nconst POLICY = ${policyJson};\nconst NAVIGATION_FALLBACK_URL = ${fallbackUrl};\nconst REQUIRE_CONSENT = ${options.requireConsent === true};\nlet permissionUntil = REQUIRE_CONSENT ? 0 : Infinity;\nlet permissionGeneration = 0;\nconst permitted = (generation) => generation === permissionGeneration && Date.now() < permissionUntil;\nasync function discardCaches() {\n const names = await caches.keys();\n await Promise.all(names.filter(name => name.startsWith(CACHE_PREFIX + \"-\")).map(name => caches.delete(name)));\n}\nself.addEventListener(\"message\", event => {\n if (!REQUIRE_CONSENT || event.data?.type !== \"plasius-offline-consent-v1\") return;\n try { if (new URL(event.source?.url).origin !== self.location.origin) return; } catch { return; }\n const requested = event.data.allowedUntil;\n permissionUntil = typeof requested === \"number\" && Number.isFinite(requested)\n ? Math.min(requested, Date.now() + 60_000) : 0;\n const disabled = permissionUntil <= Date.now();\n if (disabled) permissionGeneration++;\n event.waitUntil((async () => {\n if (disabled) await discardCaches();\n event.ports?.[0]?.postMessage({ type: \"plasius-offline-consent-v1\", disabled });\n })());\n});\n\nconst startsWithAny = (pathname, prefixes = []) => prefixes.some((prefix) => pathname === prefix || pathname.startsWith(prefix));\nconst matchesAny = (pathname, patterns = []) => patterns.some(pattern => new RegExp(pattern.source, pattern.flags).test(pathname));\nconst isDenied = (pathname) => startsWithAny(pathname, POLICY.deniedPathPrefixes || []) || matchesAny(pathname, POLICY.deniedPathPatterns);\nconst hasNoStore = (headers) => (headers.get(\"cache-control\") || \"\").split(\",\").some((directive) => directive.trim().split(\"=\", 1)[0].toLowerCase() === \"no-store\");\nconst classify = (request) => {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") return { cacheable: false, strategy: \"no-cache\" };\n if (hasNoStore(request.headers)) return { cacheable: false, strategy: \"no-cache\", reason: \"request-cache-control-no-store\" };\n const url = new URL(request.url);\n if (POLICY.sameOriginOnly !== false && url.origin !== self.location.origin) return { cacheable: false, strategy: \"no-cache\" };\n if (isDenied(url.pathname)) return { cacheable: false, strategy: \"no-cache\" };\n if (matchesAny(url.pathname, POLICY.immutableAssetPathPatterns)) return { cacheable: true, strategy: \"cache-first\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.publicApiPathPrefixes || [])) return { cacheable: true, strategy: \"stale-while-revalidate\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.publicAssetPathPrefixes || [])) return { cacheable: true, strategy: \"stale-while-revalidate\", cacheName: PUBLIC_CACHE };\n if (startsWithAny(url.pathname, POLICY.immutableAssetPathPrefixes || [])) return { cacheable: true, strategy: \"cache-first\", cacheName: APP_CACHE };\n if (request.mode === \"navigate\" && (POLICY.publicNavigationPaths || []).includes(url.pathname)) return { cacheable: true, strategy: \"network-first\", cacheName: APP_CACHE };\n return { cacheable: false, strategy: \"no-cache\" };\n};\n\nself.addEventListener(\"install\", (event) => {\n event.waitUntil(self.skipWaiting());\n});\n\nself.addEventListener(\"activate\", (event) => {\n event.waitUntil((async () => {\n const names = await caches.keys();\n await Promise.all(names.filter((name) => name.startsWith(CACHE_PREFIX + \"-\") && !name.endsWith(\"-\" + BUILD_ID) && !name.includes(\"-asset-pack-\")).map((name) => caches.delete(name)));\n await self.clients.claim();\n })());\n});\n\nasync function openPermittedCache(cacheName, generation) {\n if (!permitted(generation)) return null;\n try {\n const cache = await caches.open(cacheName);\n if (permitted(generation)) return cache;\n await caches.delete(cacheName);\n } catch { /* Optional storage must not prevent online delivery. */ }\n return null;\n}\n\nasync function evictOptionalEntry(cache, request) {\n try { await cache.delete(request); } catch { /* Never reuse an ineligible entry. */ }\n}\n\nasync function readPermittedEntry(cache, request, generation) {\n if (!cache || !permitted(generation)) return undefined;\n try {\n const candidate = await cache.match(request);\n if (!permitted(generation)) return undefined;\n if (candidate && !hasNoStore(candidate.headers)) return candidate;\n if (candidate) await evictOptionalEntry(cache, request);\n } catch { /* A failed read is an optional cache miss. */ }\n return undefined;\n}\n\nasync function updateOptionalEntry(cache, request, response, generation) {\n if (!cache || !permitted(generation)) return;\n try {\n if (hasNoStore(response.headers)) await evictOptionalEntry(cache, request);\n else if (response.ok) await cache.put(request, response.clone());\n } catch { /* Quota and other storage failures do not replace the response. */ }\n}\n\nasync function fetchOrError(request) {\n try { return await fetch(request); } catch { return Response.error(); }\n}\n\nasync function cacheFirst(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n const cached = await readPermittedEntry(cache, request, generation);\n if (cached && permitted(generation)) return cached;\n const response = await fetchOrError(request);\n await updateOptionalEntry(cache, request, response, generation);\n return response;\n}\n\nasync function staleWhileRevalidate(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n const cached = await readPermittedEntry(cache, request, generation);\n const refresh = fetchOrError(request).then(async response => {\n await updateOptionalEntry(cache, request, response, generation);\n return response;\n });\n if (cached && permitted(generation)) {\n void refresh.catch(() => undefined);\n return cached;\n }\n return refresh;\n}\n\nasync function networkFirst(request, cacheName, generation) {\n const cache = await openPermittedCache(cacheName, generation);\n let response;\n try {\n response = await fetch(request);\n } catch {\n const cached = await readPermittedEntry(cache, request, generation);\n if (cached && permitted(generation)) return cached;\n const fallback = await readPermittedEntry(cache, NAVIGATION_FALLBACK_URL, generation);\n return permitted(generation) && fallback ? fallback : Response.error();\n }\n await updateOptionalEntry(cache, request, response, generation);\n return response;\n}\n\nself.addEventListener(\"fetch\", (event) => {\n const generation = permissionGeneration;\n if (!permitted(generation)) return;\n const decision = classify(event.request);\n if (!decision.cacheable) return;\n if (decision.strategy === \"cache-first\") event.respondWith(cacheFirst(event.request, decision.cacheName, generation));\n if (decision.strategy === \"stale-while-revalidate\") event.respondWith(staleWhileRevalidate(event.request, decision.cacheName, generation));\n if (decision.strategy === \"network-first\") event.respondWith(networkFirst(event.request, decision.cacheName, generation));\n});\n`.trimStart();\n}\n"],"mappings":";AAyGO,IAAM,+BAA+B;AAErC,IAAM,+BAU+C,OAAO,OAAO;AAAA,EACxE,gBAAgB;AAAA,EAChB,uBAAuB,OAAO,OAAO,CA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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwIvD,UAAU;AACZ;","names":[]}
|
|
@@ -16,7 +16,8 @@ Publish only from the GitHub-hosted `production` job using npm trusted
|
|
|
16
16
|
publishing. Prove the prepared SHA is still the exact remote `main` head and
|
|
17
17
|
that push-triggered `ci.yml` succeeded for it. Require Node 24 and npm 11.5.1 or
|
|
18
18
|
newer, request provenance, and prohibit npm write-token fallbacks. Reviewed CI
|
|
19
|
-
uses explicit
|
|
19
|
+
uses explicit approved self-hosted runners for canonical-repository pushes;
|
|
20
|
+
fork PR code is denied. ADR-0003 supersedes the former hosted-CI decision.
|
|
20
21
|
|
|
21
22
|
## Consequences
|
|
22
23
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# ADR-0003: Approved Self-Hosted CI and Hosted Publication
|
|
2
|
+
|
|
3
|
+
- Status: Accepted
|
|
4
|
+
- Date: 2026-10-21
|
|
5
|
+
- Task: Plasius-LTD/offline-cache#6
|
|
6
|
+
- Parent Story: Plasius-LTD/plasius-ltd-site#1626
|
|
7
|
+
- Parent Feature: Plasius-LTD/plasius-ltd-site#1597
|
|
8
|
+
- Feature flag: `platform.public-artifact-integrity.enabled`
|
|
9
|
+
|
|
10
|
+
## Context
|
|
11
|
+
|
|
12
|
+
Hosted CI contradicted the task and parent Story. The repository is already
|
|
13
|
+
selected by the `Public CI - Quarantined` group, whose workflow allowlist admits
|
|
14
|
+
its exact `ci.yml@refs/heads/main`. Public self-hosted capacity must never execute
|
|
15
|
+
external-fork or pull-request-target head code. Publication requires a separate
|
|
16
|
+
GitHub-hosted OIDC identity.
|
|
17
|
+
|
|
18
|
+
## Decision
|
|
19
|
+
|
|
20
|
+
Both CI jobs run only on canonical-repository branch pushes using the literal
|
|
21
|
+
`Public CI - Quarantined` group and `[self-hosted, Linux, X64]` labels. Remove
|
|
22
|
+
pull-request/manual triggers, persist no checkout credentials, disable caching,
|
|
23
|
+
and bound job timeouts. Keep clean `npm ci`, lint, typecheck, audit, build, coverage
|
|
24
|
+
at 80% or higher, source admission and final package-manifest checks. Reuse existing
|
|
25
|
+
package/admission tooling and the demonstrated oauth2-issuer CI pattern; no runtime
|
|
26
|
+
or public API/dependency changes are needed.
|
|
27
|
+
|
|
28
|
+
Operators review each source and generated release-metadata branch before admitting
|
|
29
|
+
its exact workflow ref; they preserve selected repositories and all unrelated refs.
|
|
30
|
+
Remove temporary refs after successful validation. README documents the existing
|
|
31
|
+
metadata auto-merge behavior, exact reviewed SHA restoration for a deleted branch,
|
|
32
|
+
and the requirement to verify metadata/main CI before publication. Missing access
|
|
33
|
+
is a blocker and cannot justify hosted fallback or wildcard workflow admission.
|
|
34
|
+
|
|
35
|
+
Keep CD phase-isolated and hosted on literal `ubuntu-latest`, publishing only via
|
|
36
|
+
`production`, npm OIDC, immutable artifact digests and successful exact-main push
|
|
37
|
+
CI. Keep the approved release preparation flow; it owns package/lockfile versions
|
|
38
|
+
and changelog promotion. Choose an unused version and verify registry provenance,
|
|
39
|
+
manifest, digest and consumer behavior before completion.
|
|
40
|
+
|
|
41
|
+
The remote backend flag controls restoration only. Enabled, disabled and rollback
|
|
42
|
+
states all retain unconditional integrity checks. Disable the workflow/channel and
|
|
43
|
+
remove temporary refs for rollback; never restore the administrative path. There
|
|
44
|
+
is no user-visible capability change.
|
|
45
|
+
|
|
46
|
+
## Alternatives
|
|
47
|
+
|
|
48
|
+
Hosted CI fails the authoritative runner requirement. Pull-request CI with a fork
|
|
49
|
+
guard does not meet the parent Story's trusted-push-only boundary. Caller-selected
|
|
50
|
+
runners or broad workflow refs would weaken isolation. Replacing the package or
|
|
51
|
+
runtime code is unnecessary because the remaining mismatch is CI policy.
|
|
52
|
+
|
|
53
|
+
## Consequences and validation
|
|
54
|
+
|
|
55
|
+
Every source/release branch needs exact workflow admission and may wait for shared
|
|
56
|
+
runner capacity. Release preparation remains hosted; it is outside the CI call
|
|
57
|
+
graph, as is the existing scheduled monthly dependency-maintenance workflow.
|
|
58
|
+
No repository selection, visibility, branch protection or production policy change
|
|
59
|
+
is part of this task. Do not claim required reviews or checks exist when absent.
|
|
60
|
+
|
|
61
|
+
Workflow regressions fail against the prior hosted/PR-triggered CI, then enforce
|
|
62
|
+
the trusted event, every job's runner/permissions/timeout/cache/checkout boundary,
|
|
63
|
+
and retained quality/artifact gates. Validate baseline and final lint, types,
|
|
64
|
+
coverage, build, package, audits, strict dependencies and actionlint. Runtime
|
|
65
|
+
source is unchanged, so changed-runtime-file LCOV is N/A; combined runtime
|
|
66
|
+
coverage remains required. Accessibility, browser/SEO and ACA secret references
|
|
67
|
+
are N/A because this delivers an npm package workflow with no UI or deployment.
|
|
@@ -12,3 +12,35 @@ is bounded by the lease, so hosts must not promise indefinite offline access.
|
|
|
12
12
|
Legacy controllers require a migration/detachment before revocation is verified.
|
|
13
13
|
|
|
14
14
|
Tracking: site Feature #2206, Story #2207; offline-cache Task #12.
|
|
15
|
+
|
|
16
|
+
## Optional storage failure isolation
|
|
17
|
+
|
|
18
|
+
Task #27 extends the worker boundary to isolate rejected CacheStorage open, read,
|
|
19
|
+
write and eviction operations. Cache failures become misses or skipped updates;
|
|
20
|
+
they never turn a successful network response into stale content or an error.
|
|
21
|
+
Each request makes at most one network attempt. Network-first handles only a
|
|
22
|
+
network rejection as an opportunity to use a permitted cached response or the
|
|
23
|
+
configured navigation fallback. Exhausted network/cache fallback returns
|
|
24
|
+
`Response.error()` without exposing provider exceptions or retrying.
|
|
25
|
+
|
|
26
|
+
Every cache read/update still checks the current permission generation and lease.
|
|
27
|
+
A no-store cached response remains ineligible even when deletion fails. Failed
|
|
28
|
+
cleanup does not grant permission to reuse retained data. Successful network
|
|
29
|
+
no-store responses reach the caller without being cached. Hosts retain their
|
|
30
|
+
existing scoped cleanup/withdrawal acknowledgement responsibilities. The worker
|
|
31
|
+
introduces no persisted identifier, new telemetry or additional asset buffer.
|
|
32
|
+
|
|
33
|
+
The host composes `site.privacy.optional-processing.enabled` with
|
|
34
|
+
`site.offline-cache.enabled` and visitor consent; rollback disables optional
|
|
35
|
+
processing and withdraws/unregisters the worker. The package does not query the
|
|
36
|
+
remote control plane itself or introduce an entitlement capability. Mandatory
|
|
37
|
+
consent, deny and no-store checks are unconditional. Existing worker generation
|
|
38
|
+
without `requireConsent` also isolates storage failures.
|
|
39
|
+
|
|
40
|
+
Generated-worker regression tests execute real worker code with CacheStorage
|
|
41
|
+
faults and verify response bodies, attempt counts, safe fallbacks, permission
|
|
42
|
+
expiry/withdrawal and rejected background writes. This decision addresses
|
|
43
|
+
rejections, not permanently pending browser storage operations. Browser-owned
|
|
44
|
+
fetch cancellation/lifetime is unchanged; stale-refresh fetch-event lifetime is
|
|
45
|
+
tracked separately in Task #28. Release through the existing main CD/OIDC path
|
|
46
|
+
before host adoption; no new dependency or public API is required.
|
package/docs/adrs/index.md
CHANGED
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
|
|
3
3
|
- [ADR 0001: Browser CacheStorage Package Boundary](./adr-0001-browser-cache-storage-package-boundary.md)
|
|
4
4
|
- [ADR-0002: Hosted OIDC Package Publication](./adr-0002-hosted-oidc-package-publication.md)
|
|
5
|
+
- [ADR-0003: Approved Self-Hosted CI and Hosted Publication](./adr-0003-approved-self-hosted-ci.md)
|
|
5
6
|
- [ADR 0004: Worker consent lifecycle](./adr-0004-worker-consent-lifecycle.md)
|