@pwa-platform/engine-workbox 0.1.0-beta.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PWA Platform contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @pwa-platform/engine-workbox
2
+
3
+ Internal Workbox precache engine for PWA Platform.
4
+
5
+ Internal precache engine used by the platform worker. It does not expose raw Workbox configuration to applications.
6
+
7
+ This is a `0.1.0` prerelease. It provides online use, installation integration, static precaching, a safe offline fallback, and controlled updates. It does not enable runtime business API caching, private data caching, automatic write replay, or Push for applications. Production deployment requires the application and infrastructure checks described in the PWA Platform release runbook.
8
+
9
+ License: MIT.
@@ -0,0 +1,2 @@
1
+ export { injectPrecacheManifest, WORKBOX_INJECTION_POINT } from "./inject.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ // Build-time entry (`@pwa-platform/engine-workbox`): runs in Node and depends only on @pwa-platform/contracts.
2
+ export { injectPrecacheManifest, WORKBOX_INJECTION_POINT } from "./inject.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type PwaPlan } from "@pwa-platform/contracts";
2
+ /** Workbox's default injection point; the platform worker source must contain it exactly once. */
3
+ export declare const WORKBOX_INJECTION_POINT = "self.__WB_MANIFEST";
4
+ /**
5
+ * Replaces the injection point in `workerSource` with `plan.precache` serialized as a Workbox manifest
6
+ * (`[{"url": …, "revision": …}]`), in plan order and without adding, removing or rewriting entries. Call it on the
7
+ * bundled worker: the injection point must survive bundling unchanged (ADR-0011).
8
+ *
9
+ * Throws when the plan is invalid (the message lists diagnostic codes and paths only), when the precache holds
10
+ * entries the worker engine would reject at startup, or when the injection point does not occur exactly once.
11
+ * Pure and deterministic: no file access, bundling or minification.
12
+ */
13
+ export declare function injectPrecacheManifest(workerSource: string, plan: PwaPlan): string;
14
+ //# sourceMappingURL=inject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../../src/build/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAErE,kGAAkG;AAClG,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAE5D;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CA+BlF"}
@@ -0,0 +1,50 @@
1
+ import { validatePlan } from "@pwa-platform/contracts";
2
+ /** Workbox's default injection point; the platform worker source must contain it exactly once. */
3
+ export const WORKBOX_INJECTION_POINT = "self.__WB_MANIFEST";
4
+ /**
5
+ * Replaces the injection point in `workerSource` with `plan.precache` serialized as a Workbox manifest
6
+ * (`[{"url": …, "revision": …}]`), in plan order and without adding, removing or rewriting entries. Call it on the
7
+ * bundled worker: the injection point must survive bundling unchanged (ADR-0011).
8
+ *
9
+ * Throws when the plan is invalid (the message lists diagnostic codes and paths only), when the precache holds
10
+ * entries the worker engine would reject at startup, or when the injection point does not occur exactly once.
11
+ * Pure and deterministic: no file access, bundling or minification.
12
+ */
13
+ export function injectPrecacheManifest(workerSource, plan) {
14
+ if (typeof workerSource !== "string")
15
+ throw new TypeError("The worker source must be a string");
16
+ const result = validatePlan(plan);
17
+ if (!result.ok) {
18
+ const findings = result.diagnostics.map(({ code, path }) => `${code} at ${path === "" ? "(root)" : path}`);
19
+ throw new Error(`Cannot inject an invalid PwaPlan: ${findings.join(", ")}`);
20
+ }
21
+ // contracts accept an empty revision and repeated URLs, which createPrecacheEngine rejects; failing here keeps
22
+ // such a plan from shipping a worker that cannot start.
23
+ const seen = new Set();
24
+ const problems = result.value.precache.flatMap(({ url, revision }, index) => {
25
+ const found = [];
26
+ if (revision === "")
27
+ found.push(`/precache/${index}/revision must be null or a non-empty string`);
28
+ if (seen.has(url))
29
+ found.push(`/precache/${index}/url duplicates an earlier entry`);
30
+ seen.add(url);
31
+ return found;
32
+ });
33
+ if (problems.length > 0) {
34
+ throw new Error(`Cannot inject a precache manifest the worker engine would reject: ${problems.join(", ")}`);
35
+ }
36
+ const occurrences = countOccurrences(workerSource, WORKBOX_INJECTION_POINT);
37
+ if (occurrences !== 1) {
38
+ throw new Error(`Expected exactly one ${WORKBOX_INJECTION_POINT} injection point in the worker source, found ${occurrences}`);
39
+ }
40
+ const manifest = JSON.stringify(result.value.precache.map(({ url, revision }) => ({ url, revision })));
41
+ const index = workerSource.indexOf(WORKBOX_INJECTION_POINT);
42
+ return `${workerSource.slice(0, index)}${manifest}${workerSource.slice(index + WORKBOX_INJECTION_POINT.length)}`;
43
+ }
44
+ function countOccurrences(text, search) {
45
+ let count = 0;
46
+ for (let index = text.indexOf(search); index !== -1; index = text.indexOf(search, index + search.length))
47
+ count += 1;
48
+ return count;
49
+ }
50
+ //# sourceMappingURL=inject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.js","sourceRoot":"","sources":["../../src/build/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,yBAAyB,CAAC;AAErE,kGAAkG;AAClG,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,YAAoB,EAAE,IAAa;IACxE,IAAI,OAAO,YAAY,KAAK,QAAQ;QAAE,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;IAEhG,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3G,MAAM,IAAI,KAAK,CAAC,qCAAqC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,+GAA+G;IAC/G,wDAAwD;IACxD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC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C,KAAK,GAAG,uBAAuB,CAAC,MAAM,CAAC,EAAE,CAAC;AACnH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,MAAc;IACpD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;QAAE,KAAK,IAAI,CAAC,CAAC;IACrH,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { type PwaPrecacheEngineOptions } from "./options.js";
2
+ export type PwaPrecacheInstallResult = {
3
+ /** Absolute URLs, without `__WB_REVISION__`, of the manifest entries downloaded into the precache during this install. */
4
+ readonly updatedUrls: readonly string[];
5
+ /** Absolute URLs, without `__WB_REVISION__`, of the manifest entries that were already cached with the same revision. */
6
+ readonly notUpdatedUrls: readonly string[];
7
+ };
8
+ export type PwaPrecacheActivateResult = {
9
+ /**
10
+ * Cache keys removed from the precache because they are no longer in the manifest: absolute request URLs, including
11
+ * the `__WB_REVISION__` query of revisioned entries.
12
+ */
13
+ readonly deletedUrls: readonly string[];
14
+ };
15
+ /** Precache port used by the platform worker (sw-runtime); it only acts when one of its methods is called. */
16
+ export type PwaPrecacheEngine = {
17
+ /** Call from the install event; downloads new or changed manifest entries and fails if any request fails. */
18
+ install(event: ExtendableEvent): Promise<PwaPrecacheInstallResult>;
19
+ /** Call from the activate event; removes entries of this precache that are no longer in the manifest. */
20
+ activate(event: ExtendableEvent): Promise<PwaPrecacheActivateResult>;
21
+ /** Reads a manifest URL from this precache only; returns `undefined` otherwise, including for unparsable URLs, and never uses the network. */
22
+ match(url: string): Promise<Response | undefined>;
23
+ /** Manifest URLs in manifest order, exactly as given in `entries` (paths, not absolute URLs). */
24
+ urls(): readonly string[];
25
+ };
26
+ /**
27
+ * Creates the precache port for one plan. It registers no event listeners, never calls `skipWaiting` or
28
+ * `clients.claim`, and touches no cache other than `cacheName`.
29
+ */
30
+ export declare function createPrecacheEngine(options: PwaPrecacheEngineOptions): PwaPrecacheEngine;
31
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/worker/engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAqD,KAAK,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAEhH,MAAM,MAAM,wBAAwB,GAAG;IACrC,0HAA0H;IAC1H,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,yHAAyH;IACzH,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC,CAAC;AAEF,8GAA8G;AAC9G,MAAM,MAAM,iBAAiB,GAAG;IAC9B,6GAA6G;IAC7G,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACnE,yGAAyG;IACzG,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACrE,8IAA8I;IAC9I,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;IAClD,iGAAiG;IACjG,IAAI,IAAI,SAAS,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAkCzF"}
@@ -0,0 +1,42 @@
1
+ import { PrecacheController } from "workbox-precaching";
2
+ import { resolveManifestUrl, validatePrecacheEngineOptions } from "./options.js";
3
+ /**
4
+ * Creates the precache port for one plan. It registers no event listeners, never calls `skipWaiting` or
5
+ * `clients.claim`, and touches no cache other than `cacheName`.
6
+ */
7
+ export function createPrecacheEngine(options) {
8
+ const { cacheName, entries } = validatePrecacheEngineOptions(options);
9
+ const controller = new PrecacheController({ cacheName, fallbackToNetwork: false });
10
+ controller.addToCacheList(entries.map(({ url, revision }) => ({ url, revision })));
11
+ const urls = entries.map(({ url }) => url);
12
+ return {
13
+ async install(event) {
14
+ const { updatedURLs, notUpdatedURLs } = await controller.install(event);
15
+ return { updatedUrls: [...updatedURLs], notUpdatedUrls: [...notUpdatedURLs] };
16
+ },
17
+ async activate(event) {
18
+ // Workbox 7.4.1 declares the result as `{ deletedCacheRequests }` but returns `{ deletedURLs }`, so read the
19
+ // field it actually returns and fail loudly if a Workbox update changes it again.
20
+ const { deletedURLs } = (await controller.activate(event));
21
+ if (!Array.isArray(deletedURLs) || !deletedURLs.every((url) => typeof url === "string")) {
22
+ throw new Error("Workbox did not report the deleted precache requests");
23
+ }
24
+ return { deletedUrls: [...deletedURLs] };
25
+ },
26
+ async match(url) {
27
+ if (!URL.canParse(url, self.location.href))
28
+ return undefined;
29
+ // Workbox keys its URL-to-cache-key map by the exact absolute URL of each manifest entry, so any other URL
30
+ // (another query, a missing index.html, another origin) has no cache key and is never looked up.
31
+ const cacheKey = controller.getCacheKeyForURL(resolveManifestUrl(url, self.location.href));
32
+ if (cacheKey === undefined)
33
+ return undefined;
34
+ // CacheStorage.match with cacheName reads that cache only and, unlike caches.open, never creates it.
35
+ return (await self.caches.match(cacheKey, { cacheName })) ?? undefined;
36
+ },
37
+ urls() {
38
+ return [...urls];
39
+ },
40
+ };
41
+ }
42
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/worker/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAA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,GAAG,WAAW,CAAC,EAAE,CAAC;QAC3C,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,GAAG;YACb,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAAE,OAAO,SAAS,CAAC;YAC7D,2GAA2G;YAC3G,iGAAiG;YACjG,MAAM,QAAQ,GAAG,UAAU,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3F,IAAI,QAAQ,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;YAC7C,qGAAqG;YACrG,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,SAAS,CAAC;QACzE,CAAC;QACD,IAAI;YACF,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { createPrecacheEngine } from "./engine.js";
2
+ export type { PwaPrecacheActivateResult, PwaPrecacheEngine, PwaPrecacheInstallResult } from "./engine.js";
3
+ export type { PwaPrecacheEngineOptions, PwaPrecacheManifestEntry } from "./options.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC1G,YAAY,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ // Worker entry (`@pwa-platform/engine-workbox/worker`): runs in a service worker after bundling and depends only
2
+ // on workbox-precaching and workbox-core, never on Node modules.
3
+ export { createPrecacheEngine } from "./engine.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,iEAAiE;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,17 @@
1
+ /** One entry of the injected manifest (`self.__WB_MANIFEST`), mirroring `PwaPlan.precache`. */
2
+ export type PwaPrecacheManifestEntry = {
3
+ /** Canonical absolute path, as in `PwaPlan.precache`: no query, fragment, dot segments, `//` or backslashes. */
4
+ readonly url: string;
5
+ /** Content revision, or `null` when the URL itself is versioned (fingerprinted). */
6
+ readonly revision: string | null;
7
+ };
8
+ export type PwaPrecacheEngineOptions = {
9
+ /** The contracts `cacheName(identity, "precache")` for the running plan. */
10
+ readonly cacheName: string;
11
+ readonly entries: readonly PwaPrecacheManifestEntry[];
12
+ };
13
+ /** Validates engine options and returns a fresh copy. Messages name fields and indexes, never input values. */
14
+ export declare function validatePrecacheEngineOptions(options: unknown): PwaPrecacheEngineOptions;
15
+ /** Resolves `url` against `base` and drops the fragment; the query string is kept, so matching stays exact. */
16
+ export declare function resolveManifestUrl(url: string, base: string): string;
17
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/worker/options.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,MAAM,MAAM,wBAAwB,GAAG;IACrC,gHAAgH;IAChH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,wBAAwB,EAAE,CAAC;CACvD,CAAC;AAOF,+GAA+G;AAC/G,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO,GAAG,wBAAwB,CAqCxF;AAiBD,+GAA+G;AAC/G,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIpE"}
@@ -0,0 +1,63 @@
1
+ const CACHE_NAME_PREFIX = "pwa:";
2
+ const CACHE_NAME_SUFFIX = ":precache";
3
+ // Only used to check the form of paths; never requested.
4
+ const PATH_BASE = "https://engine-workbox.invalid/";
5
+ /** Validates engine options and returns a fresh copy. Messages name fields and indexes, never input values. */
6
+ export function validatePrecacheEngineOptions(options) {
7
+ if (!isRecord(options))
8
+ throw new TypeError("Precache engine options must be an object");
9
+ const { cacheName, entries } = options;
10
+ const hasPlatformShape = typeof cacheName === "string" &&
11
+ cacheName.startsWith(CACHE_NAME_PREFIX) &&
12
+ cacheName.endsWith(CACHE_NAME_SUFFIX) &&
13
+ cacheName.length > CACHE_NAME_PREFIX.length + CACHE_NAME_SUFFIX.length;
14
+ if (!hasPlatformShape) {
15
+ throw new Error('cacheName must be a contracts precache cache name of the form "pwa:<…>:precache"');
16
+ }
17
+ if (!Array.isArray(entries))
18
+ throw new TypeError("entries must be an array");
19
+ const seen = new Set();
20
+ const normalised = entries.map((entry, index) => {
21
+ if (!isRecord(entry))
22
+ throw new TypeError(`entries[${index}] must be an object`);
23
+ const keys = Object.keys(entry).sort();
24
+ if (keys.length !== 2 || keys[0] !== "revision" || keys[1] !== "url") {
25
+ throw new Error(`entries[${index}] must have exactly the fields url and revision`);
26
+ }
27
+ const { url, revision } = entry;
28
+ if (typeof url !== "string" || !isCanonicalPath(url)) {
29
+ throw new Error(`entries[${index}].url must be a canonical same-origin absolute path: no query, fragment, dot segments, "//", backslashes or characters the URL parser would change`);
30
+ }
31
+ if (revision !== null && (typeof revision !== "string" || revision === "")) {
32
+ throw new Error(`entries[${index}].revision must be a non-empty string or null`);
33
+ }
34
+ // Canonical paths have exactly one spelling, so equal strings are the only duplicates.
35
+ if (seen.has(url))
36
+ throw new Error(`entries[${index}].url duplicates an earlier entry`);
37
+ seen.add(url);
38
+ return { url, revision };
39
+ });
40
+ return { cacheName, entries: normalised };
41
+ }
42
+ /**
43
+ * The rule contracts' `isCanonicalPath` applies to `PwaPlan.precache` URLs, repeated here because the worker entry
44
+ * does not import contracts. The URL parser treats `\` as `/` and drops tabs and newlines, so without the final
45
+ * comparison `/\evil.example/a.js` would resolve to another origin.
46
+ */
47
+ function isCanonicalPath(value) {
48
+ return (value.startsWith("/") &&
49
+ !value.includes("//") &&
50
+ !value.includes("\\") &&
51
+ URL.canParse(value, PATH_BASE) &&
52
+ new URL(value, PATH_BASE).pathname === value);
53
+ }
54
+ /** Resolves `url` against `base` and drops the fragment; the query string is kept, so matching stays exact. */
55
+ export function resolveManifestUrl(url, base) {
56
+ const resolved = new URL(url, base);
57
+ resolved.hash = "";
58
+ return resolved.href;
59
+ }
60
+ function isRecord(value) {
61
+ return typeof value === "object" && value !== null && !Array.isArray(value);
62
+ }
63
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/worker/options.ts"],"names":[],"mappings":"AAcA,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACjC,MAAM,iBAAiB,GAAG,WAAW,CAAC;AACtC,yDAAyD;AACzD,MAAM,SAAS,GAAG,iCAAiC,CAAC;AAEpD,+GAA+G;AAC/G,MAAM,UAAU,6BAA6B,CAAC,OAAgB;IAC5D,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,2CAA2C,CAAC,CAAC;IAEzF,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,gBAAgB,GACpB,OAAO,SAAS,KAAK,QAAQ;QAC7B,SAAS,CAAC,UAAU,CAAC,iBAAiB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ine for PWA Platform.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/build/index.d.ts",
10
+ "import": "./dist/build/index.js"
11
+ },
12
+ "./worker": {
13
+ "types": "./dist/worker/index.d.ts",
14
+ "import": "./dist/worker/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "workbox-core": "7.4.1",
22
+ "workbox-precaching": "7.4.1",
23
+ "@pwa-platform/contracts": "0.1.0-beta.0"
24
+ },
25
+ "devDependencies": {
26
+ "@playwright/test": "1.63.0",
27
+ "@types/node": "24.13.4",
28
+ "vite": "8.3.0",
29
+ "@pwa-platform/browser-test-harness": "0.0.0"
30
+ },
31
+ "engines": {
32
+ "node": ">=22.0.0"
33
+ },
34
+ "publishConfig": {
35
+ "registry": "https://registry.npmjs.org/",
36
+ "access": "public",
37
+ "tag": "next"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc --project tsconfig.build.json && tsc --project tsconfig.worker.build.json",
41
+ "test": "vitest run",
42
+ "test:browser": "playwright test",
43
+ "typecheck": "tsc --noEmit --project tsconfig.json && tsc --noEmit --project tsconfig.worker.json && tsc --noEmit --project tsconfig.browser.json"
44
+ }
45
+ }