@softistx/alxia-react-router 0.88.0 → 0.89.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.
Files changed (58) hide show
  1. package/README.md +5 -1
  2. package/dist/oidc/callback.d.ts +4 -0
  3. package/dist/oidc/callback.d.ts.map +1 -0
  4. package/dist/oidc/client.d.ts +57 -0
  5. package/dist/oidc/client.d.ts.map +1 -0
  6. package/dist/oidc/context.d.ts +42 -0
  7. package/dist/oidc/context.d.ts.map +1 -0
  8. package/dist/oidc/dpop-fetch.d.ts +2 -1
  9. package/dist/oidc/dpop-fetch.d.ts.map +1 -1
  10. package/dist/oidc/env.d.ts +1 -1
  11. package/dist/oidc/env.d.ts.map +1 -1
  12. package/dist/oidc/index.d.ts +2 -1
  13. package/dist/oidc/index.d.ts.map +1 -1
  14. package/dist/oidc/index.js +550 -486
  15. package/dist/oidc/index.js.map +18 -9
  16. package/dist/oidc/logout.d.ts +4 -0
  17. package/dist/oidc/logout.d.ts.map +1 -0
  18. package/dist/oidc/refresh.d.ts +10 -0
  19. package/dist/oidc/refresh.d.ts.map +1 -0
  20. package/dist/oidc/routes.d.ts +1 -1
  21. package/dist/oidc/routes.d.ts.map +1 -1
  22. package/dist/oidc/session.d.ts +7 -0
  23. package/dist/oidc/session.d.ts.map +1 -0
  24. package/dist/oidc/signin.d.ts +4 -0
  25. package/dist/oidc/signin.d.ts.map +1 -0
  26. package/dist/oidc/stored.d.ts +21 -0
  27. package/dist/oidc/stored.d.ts.map +1 -0
  28. package/dist/oidc/tokens.d.ts +13 -0
  29. package/dist/oidc/tokens.d.ts.map +1 -0
  30. package/dist/oidc/{oidc.d.ts → types.d.ts} +4 -59
  31. package/dist/oidc/{oidc.d.ts.map → types.d.ts.map} +1 -1
  32. package/dist/oidc/user.d.ts +6 -0
  33. package/dist/oidc/user.d.ts.map +1 -0
  34. package/dist/pwa/react/index.d.ts +2 -0
  35. package/dist/pwa/react/index.d.ts.map +1 -1
  36. package/dist/pwa/react/index.js +264 -3
  37. package/dist/pwa/react/index.js.map +6 -3
  38. package/dist/pwa/react/push-status.d.ts +31 -0
  39. package/dist/pwa/react/push-status.d.ts.map +1 -0
  40. package/dist/pwa/react/push-store.d.ts +55 -0
  41. package/dist/pwa/react/push-store.d.ts.map +1 -0
  42. package/dist/pwa/react/use-push-subscription.d.ts +15 -0
  43. package/dist/pwa/react/use-push-subscription.d.ts.map +1 -0
  44. package/dist/pwa/worker/index.d.ts +2 -0
  45. package/dist/pwa/worker/index.d.ts.map +1 -1
  46. package/dist/pwa/worker/index.js +94 -4
  47. package/dist/pwa/worker/index.js.map +7 -6
  48. package/dist/pwa/worker/plan.d.ts +7 -0
  49. package/dist/pwa/worker/plan.d.ts.map +1 -1
  50. package/dist/pwa/worker/push.d.ts +48 -0
  51. package/dist/pwa/worker/push.d.ts.map +1 -0
  52. package/dist/pwa/worker/scope.d.ts +23 -0
  53. package/dist/pwa/worker/scope.d.ts.map +1 -1
  54. package/dist/pwa/worker/start-worker.d.ts +2 -0
  55. package/dist/pwa/worker/start-worker.d.ts.map +1 -1
  56. package/docs/guide/pwa.md +101 -1
  57. package/docs/troubleshooting.md +18 -0
  58. package/package.json +1 -1
@@ -8,6 +8,92 @@ import {
8
8
  import {
9
9
  SKIP_WAITING2
10
10
  } from "../../chunks/index-rfr02vg4.js";
11
+ // src/pwa/worker/scope.ts
12
+ var workerScope = () => globalThis;
13
+
14
+ // src/pwa/worker/push.ts
15
+ var text = (value) => typeof value === "string" && value !== "" ? value : undefined;
16
+ function readPayload(event) {
17
+ let raw;
18
+ try {
19
+ raw = event.data?.json();
20
+ } catch {
21
+ return;
22
+ }
23
+ if (typeof raw !== "object" || raw === null)
24
+ return;
25
+ const record = raw;
26
+ const title = text(record["title"]);
27
+ if (!title)
28
+ return;
29
+ const body = text(record["body"]);
30
+ const url = text(record["url"]);
31
+ const tag = text(record["tag"]);
32
+ return {
33
+ title,
34
+ ...body && { body },
35
+ ...url && { url },
36
+ ...tag && { tag }
37
+ };
38
+ }
39
+ function handlePush(event, options = {}) {
40
+ const payload = readPayload(event);
41
+ const { registration } = workerScope();
42
+ event.waitUntil(registration.showNotification(payload?.title ?? options.fallbackTitle ?? "Notification", {
43
+ ...payload?.body && { body: payload.body },
44
+ ...payload?.tag && { tag: payload.tag },
45
+ ...options.icon && { icon: options.icon },
46
+ ...options.badge && { badge: options.badge },
47
+ data: { url: payload?.url }
48
+ }));
49
+ }
50
+ function sameOriginUrl(raw, origin) {
51
+ const value = text(raw);
52
+ if (!value)
53
+ return;
54
+ try {
55
+ const url = new URL(value, origin);
56
+ return url.origin === origin ? url.href : undefined;
57
+ } catch {
58
+ return;
59
+ }
60
+ }
61
+ function handleNotificationClick(event) {
62
+ event.notification.close();
63
+ const scope = workerScope();
64
+ const { origin } = scope.location;
65
+ const data = event.notification.data;
66
+ const target = sameOriginUrl(data?.url, origin);
67
+ event.waitUntil((async () => {
68
+ const windows = await scope.clients.matchAll({
69
+ type: "window",
70
+ includeUncontrolled: true
71
+ });
72
+ const open = windows.find((client) => {
73
+ try {
74
+ return new URL(client.url).origin === origin;
75
+ } catch {
76
+ return false;
77
+ }
78
+ });
79
+ if (!open) {
80
+ await scope.clients.openWindow(target ?? origin);
81
+ return;
82
+ }
83
+ let navigated = !target;
84
+ if (target && open.navigate) {
85
+ try {
86
+ await open.navigate(target);
87
+ navigated = true;
88
+ } catch {}
89
+ }
90
+ try {
91
+ await open.focus();
92
+ } catch {}
93
+ if (!navigated && target)
94
+ await scope.clients.openWindow(target);
95
+ })());
96
+ }
11
97
  // src/pwa/worker/start-worker.ts
12
98
  import {
13
99
  clientsClaim,
@@ -90,9 +176,6 @@ async function deleteObsoleteCaches(contract, storage) {
90
176
  await Promise.all(contract.obsoleteCaches(names).map((name) => storage.delete(name)));
91
177
  }
92
178
 
93
- // src/pwa/worker/scope.ts
94
- var workerScope = () => globalThis;
95
-
96
179
  // src/pwa/worker/start-worker.ts
97
180
  function startWorker(options) {
98
181
  const plan = workerPlan(options, injectedPrecache2());
@@ -134,11 +217,18 @@ function startWorker(options) {
134
217
  if (isSkipWaiting(event.data))
135
218
  scope.skipWaiting();
136
219
  });
220
+ if (options.push) {
221
+ const push = options.push === true ? {} : options.push;
222
+ scope.addEventListener("push", (event) => handlePush(event, push));
223
+ scope.addEventListener("notificationclick", handleNotificationClick);
224
+ }
137
225
  }
138
226
  export {
227
+ handleNotificationClick,
228
+ handlePush,
139
229
  injectedPrecache2 as injectedPrecache,
140
230
  startWorker
141
231
  };
142
232
 
143
- //# debugId=7DA3F7F688E186F864756E2164756E21
233
+ //# debugId=5667746300451FBE64756E2164756E21
144
234
  //# sourceMappingURL=index.js.map
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/pwa/worker/start-worker.ts", "../src/pwa/worker/plan.ts", "../src/pwa/worker/scope.ts"],
3
+ "sources": ["../src/pwa/worker/scope.ts", "../src/pwa/worker/push.ts", "../src/pwa/worker/start-worker.ts", "../src/pwa/worker/plan.ts"],
4
4
  "sourcesContent": [
5
- "import {\n\tclientsClaim,\n\tsetCacheNameDetails,\n\ttype WorkboxPlugin,\n} from 'workbox-core';\nimport { ExpirationPlugin } from 'workbox-expiration';\nimport * as navigationPreload from 'workbox-navigation-preload';\nimport { matchPrecache, precacheAndRoute } from 'workbox-precaching';\nimport { registerRoute } from 'workbox-routing';\nimport {\n\tCacheFirst,\n\tNetworkOnly,\n\tStaleWhileRevalidate,\n} from 'workbox-strategies';\nimport { injectedPrecache } from './injected';\nimport {\n\tdeleteObsoleteCaches,\n\tisSkipWaiting,\n\tmatcher,\n\tstorableOnly,\n\ttype WorkerOptions,\n\tworkerPlan,\n} from './plan';\nimport { workerScope } from './scope';\n\n/**\n * Starts the service worker on Workbox. Call it once, from the worker's entry.\n *\n * - The precache route is registered first: a precached URL is answered from\n * the precache before any route below. Exact URLs only (`cleanURLs: false`,\n * no directory index), so a page load still goes to the network.\n * - A navigation is never stored: with navigation preload the browser starts\n * the request alongside the worker, and `NetworkOnly` answers with it. The\n * offline page answers only when the network fails, never for an HTTP error.\n * - Hashed bundles are cache-first, other static files stale-while-revalidate;\n * both store only what `isStorable` accepts.\n * - A first install controls the open pages at once; an update waits until\n * the page posts `SKIP_WAITING`.\n */\nexport function startWorker(options: WorkerOptions): void {\n\tconst plan = workerPlan(options, injectedPrecache());\n\tconst scope = workerScope();\n\tconst { contract } = options;\n\tsetCacheNameDetails(plan.cacheNameDetails);\n\tprecacheAndRoute([...plan.precache], {\n\t\tcleanURLs: false,\n\t\tdirectoryIndex: '',\n\t});\n\tif (plan.navigationPreload) navigationPreload.enable();\n\n\tfor (const route of plan.routes) {\n\t\tconst match = matcher(route.caching, () => scope.location.origin, options);\n\t\tif (route.strategy === 'network-only') {\n\t\t\tconst { fallback } = route;\n\t\t\tregisterRoute(\n\t\t\t\tmatch,\n\t\t\t\tnew NetworkOnly({\n\t\t\t\t\tplugins: fallback\n\t\t\t\t\t\t? [{ handlerDidError: async () => matchPrecache(fallback) }]\n\t\t\t\t\t\t: [],\n\t\t\t\t}),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst Strategy =\n\t\t\troute.strategy === 'cache-first' ? CacheFirst : StaleWhileRevalidate;\n\t\tregisterRoute(\n\t\t\tmatch,\n\t\t\tnew Strategy({\n\t\t\t\tcacheName: route.cacheName,\n\t\t\t\tplugins: [\n\t\t\t\t\tstorableOnly,\n\t\t\t\t\tnew ExpirationPlugin({\n\t\t\t\t\t\t...route.expiration,\n\t\t\t\t\t\tpurgeOnQuotaError: true,\n\t\t\t\t\t}) as WorkboxPlugin, // ExpirationPlugin's optional hooks are not exact-optional under exactOptionalPropertyTypes; this states it is a plugin.\n\t\t\t\t],\n\t\t\t}),\n\t\t);\n\t}\n\n\tclientsClaim();\n\tscope.addEventListener('activate', (event) => {\n\t\tevent.waitUntil(deleteObsoleteCaches(contract, caches));\n\t});\n\tscope.addEventListener('message', (event) => {\n\t\tif (isSkipWaiting(event.data)) void scope.skipWaiting();\n\t});\n}\n",
6
- "import {\n\ttype Caching,\n\ttype CachingOptions,\n\tcachingFor,\n\ttype RequestFacts,\n} from '../model/caching';\nimport type { PrecacheEntry } from '../model/precache-list';\nimport { isStorable } from '../model/storable';\nimport { SKIP_WAITING, type WorkerContract } from '../model/worker-contract';\n\n/** How many files, and for how long, a runtime cache keeps. */\nexport interface ExpirationOptions {\n\tmaxEntries?: number;\n\tmaxAgeSeconds?: number;\n}\n\nexport interface WorkerOptions {\n\t/** The app's contract: cache names, offline page, the worker's URL. */\n\tcontract: WorkerContract;\n\t/** What `cachingFor` reads besides the contract: `never`, `immutable`, `manifestPath`, `serviceWorkerUrl`. */\n\tcaching?: Omit<CachingOptions, 'contract'>;\n\t/** The hashed bundles' cache. `{ maxEntries: 200 }` by default. */\n\tassets?: ExpirationOptions;\n\t/** The other static files' cache. `{ maxEntries: 100, maxAgeSeconds: 30 days }` by default. */\n\tstatic?: ExpirationOptions;\n\t/** Start the worker alongside a page load. `true` by default. */\n\tnavigationPreload?: boolean;\n\t/** The precache list. By default the one the build wrote into the worker. */\n\tprecache?: readonly PrecacheEntry[];\n}\n\nexport type WorkerRoute =\n\t| {\n\t\t\tcaching: 'navigation';\n\t\t\tstrategy: 'network-only';\n\t\t\tfallback: string | undefined;\n\t }\n\t| {\n\t\t\tcaching: 'immutable';\n\t\t\tstrategy: 'cache-first';\n\t\t\tcacheName: string;\n\t\t\texpiration: ExpirationOptions & { maxEntries: number };\n\t }\n\t| {\n\t\t\tcaching: 'static';\n\t\t\tstrategy: 'stale-while-revalidate';\n\t\t\tcacheName: string;\n\t\t\texpiration: ExpirationOptions;\n\t };\n\nexport interface WorkerPlan {\n\tcacheNameDetails: { prefix: string; precache: 'precache'; suffix: string };\n\tprecache: readonly PrecacheEntry[];\n\troutes: readonly WorkerRoute[];\n\tnavigationPreload: boolean;\n}\n\nconst THIRTY_DAYS = 30 * 24 * 60 * 60;\n\n/** What the worker does, decided without Workbox so that it is tested as data. */\nexport function workerPlan(\n\toptions: WorkerOptions,\n\tinjected: readonly PrecacheEntry[] | undefined,\n): WorkerPlan {\n\tconst { contract } = options;\n\tif (!contract) {\n\t\tthrow new TypeError(\n\t\t\t'startWorker(): contract is required: pass defineWorkerContract({ cachePrefix }) from @softistx/alxia-react-router/pwa.',\n\t\t);\n\t}\n\tconst precache = options.precache ?? injected;\n\tif (!precache) {\n\t\tthrow new Error(\n\t\t\t'startWorker(): no precache list. Build this worker with alxia() from @softistx/alxia-react-router/vite (app/service-worker.ts) or buildWorker() from @softistx/alxia-react-router/pwa/build, which write it in.',\n\t\t);\n\t}\n\tconst offlineUrl = contract.offlineUrl;\n\tconst hasOffline = precache.some(\n\t\t(entry) => entry.url.split('?')[0] === offlineUrl,\n\t);\n\treturn {\n\t\tcacheNameDetails: {\n\t\t\tprefix: contract.cachePrefix,\n\t\t\tprecache: 'precache',\n\t\t\tsuffix: contract.cacheVersion,\n\t\t},\n\t\tprecache,\n\t\troutes: [\n\t\t\t{\n\t\t\t\tcaching: 'navigation',\n\t\t\t\tstrategy: 'network-only',\n\t\t\t\tfallback: hasOffline ? offlineUrl : undefined,\n\t\t\t},\n\t\t\t{\n\t\t\t\tcaching: 'immutable',\n\t\t\t\tstrategy: 'cache-first',\n\t\t\t\tcacheName: contract.cacheNames.assets,\n\t\t\t\texpiration: { maxEntries: 200, ...options.assets },\n\t\t\t},\n\t\t\t{\n\t\t\t\tcaching: 'static',\n\t\t\t\tstrategy: 'stale-while-revalidate',\n\t\t\t\tcacheName: contract.cacheNames.static,\n\t\t\t\texpiration: {\n\t\t\t\t\tmaxEntries: 100,\n\t\t\t\t\tmaxAgeSeconds: THIRTY_DAYS,\n\t\t\t\t\t...options.static,\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tnavigationPreload: options.navigationPreload ?? true,\n\t};\n}\n\n/** Whether a request is answered the way `caching` says. */\nexport function matcher(\n\tcaching: Caching,\n\torigin: () => string,\n\toptions: WorkerOptions,\n): (o: { request: RequestFacts }) => boolean {\n\treturn ({ request }) =>\n\t\tcachingFor(request, origin(), {\n\t\t\t...options.caching,\n\t\t\tcontract: options.contract,\n\t\t}) === caching;\n}\n\n/** Stores only what `isStorable` accepts: a public, same-origin 200. */\nexport const storableOnly = {\n\tasync cacheWillUpdate({\n\t\tresponse,\n\t}: {\n\t\tresponse: Response;\n\t}): Promise<Response | null> {\n\t\treturn isStorable(response) ? response : null;\n\t},\n};\n\nexport function isSkipWaiting(data: unknown): boolean {\n\treturn (data as { type?: unknown } | null | undefined)?.type === SKIP_WAITING;\n}\n\n/** Deletes the caches an earlier version of the contract owned. */\nexport async function deleteObsoleteCaches(\n\tcontract: Pick<WorkerContract, 'obsoleteCaches'>,\n\tstorage: Pick<CacheStorage, 'keys' | 'delete'>,\n): Promise<void> {\n\tconst names = await storage.keys();\n\tawait Promise.all(\n\t\tcontract.obsoleteCaches(names).map((name) => storage.delete(name)),\n\t);\n}\n",
7
- "/**\n * The part of the service worker's global scope that `startWorker` reads,\n * declared here so no WebWorker-only type reaches the package's declarations\n * (the DOM lib has no `ServiceWorkerGlobalScope`).\n */\nexport interface WorkerScope {\n\treadonly location: { readonly origin: string };\n\tskipWaiting(): Promise<void>;\n\taddEventListener(\n\t\ttype: 'activate' | 'message',\n\t\tlistener: (event: {\n\t\t\tdata?: unknown;\n\t\t\twaitUntil(promise: Promise<unknown>): void;\n\t\t}) => void,\n\t): void;\n}\n\n/** The worker's scope. Called only inside `startWorker`, never at module load. */\nexport const workerScope = (): WorkerScope =>\n\tglobalThis as unknown as WorkerScope;\n"
5
+ "import type { NotificationClickEventLike, PushEventLike } from './push';\n\n/**\n * The part of the service worker's global scope that `startWorker` reads,\n * declared here so no WebWorker-only type reaches the package's declarations\n * (the DOM lib has no `ServiceWorkerGlobalScope`).\n */\nexport interface WorkerScope {\n\treadonly location: { readonly origin: string };\n\tskipWaiting(): Promise<void>;\n\treadonly registration: {\n\t\tshowNotification(\n\t\t\ttitle: string,\n\t\t\toptions?: {\n\t\t\t\tbody?: string;\n\t\t\t\ttag?: string;\n\t\t\t\ticon?: string;\n\t\t\t\tbadge?: string;\n\t\t\t\tdata?: unknown;\n\t\t\t},\n\t\t): Promise<void>;\n\t};\n\treadonly clients: {\n\t\tmatchAll(options: {\n\t\t\ttype: 'window';\n\t\t\tincludeUncontrolled: boolean;\n\t\t}): Promise<\n\t\t\tReadonlyArray<{\n\t\t\t\turl: string;\n\t\t\t\tfocus(): Promise<unknown>;\n\t\t\t\tnavigate?(url: string): Promise<unknown>;\n\t\t\t}>\n\t\t>;\n\t\topenWindow(url: string): Promise<unknown>;\n\t};\n\taddEventListener(\n\t\ttype: 'activate' | 'message',\n\t\tlistener: (event: {\n\t\t\tdata?: unknown;\n\t\t\twaitUntil(promise: Promise<unknown>): void;\n\t\t}) => void,\n\t): void;\n\taddEventListener(\n\t\ttype: 'push',\n\t\tlistener: (event: PushEventLike) => void,\n\t): void;\n\taddEventListener(\n\t\ttype: 'notificationclick',\n\t\tlistener: (event: NotificationClickEventLike) => void,\n\t): void;\n}\n\n/** The worker's scope. Called only inside `startWorker`, never at module load. */\nexport const workerScope = (): WorkerScope =>\n\tglobalThis as unknown as WorkerScope;\n",
6
+ "import { workerScope } from './scope';\n\n/** What a push notice carries: the JSON payload the sender wrote. */\nexport interface PushPayload {\n\ttitle: string;\n\tbody?: string;\n\turl?: string;\n\ttag?: string;\n}\n\nexport interface PushOptions {\n\t/** The title shown when a push has no payload or an unreadable one. `'Notification'` by default. */\n\tfallbackTitle?: string;\n\t/** The notification's icon URL. */\n\ticon?: string;\n\t/** The notification's badge URL. */\n\tbadge?: string;\n}\n\n/** The part of a `PushEvent` the helpers read. */\nexport interface PushEventLike {\n\tdata?: { json(): unknown } | null | undefined;\n\twaitUntil(promise: Promise<unknown>): void;\n}\n\n/** The part of a `NotificationEvent` the helpers read. */\nexport interface NotificationClickEventLike {\n\tnotification: { close(): void; data?: unknown };\n\twaitUntil(promise: Promise<unknown>): void;\n}\n\nconst text = (value: unknown): string | undefined =>\n\ttypeof value === 'string' && value !== '' ? value : undefined;\n\n/** Reads the payload; `undefined` when there is none, it is not JSON or it has no usable shape. */\nexport function readPayload(event: PushEventLike): PushPayload | undefined {\n\tlet raw: unknown;\n\ttry {\n\t\traw = event.data?.json();\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (typeof raw !== 'object' || raw === null) return undefined;\n\tconst record = raw as Record<string, unknown>;\n\tconst title = text(record['title']);\n\tif (!title) return undefined;\n\tconst body = text(record['body']);\n\tconst url = text(record['url']);\n\tconst tag = text(record['tag']);\n\treturn {\n\t\ttitle,\n\t\t...(body && { body }),\n\t\t...(url && { url }),\n\t\t...(tag && { tag }),\n\t};\n}\n\n/**\n * Shows the pushed notice. Reads `{ title, body?, url?, tag? }`; with no\n * payload, or one that is not that shape, shows `fallbackTitle` so a push is\n * never silent. The `url` travels in the notification's `data` for the click.\n */\nexport function handlePush(\n\tevent: PushEventLike,\n\toptions: PushOptions = {},\n): void {\n\tconst payload = readPayload(event);\n\tconst { registration } = workerScope();\n\tevent.waitUntil(\n\t\tregistration.showNotification(\n\t\t\tpayload?.title ?? options.fallbackTitle ?? 'Notification',\n\t\t\t{\n\t\t\t\t...(payload?.body && { body: payload.body }),\n\t\t\t\t...(payload?.tag && { tag: payload.tag }),\n\t\t\t\t...(options.icon && { icon: options.icon }),\n\t\t\t\t...(options.badge && { badge: options.badge }),\n\t\t\t\tdata: { url: payload?.url },\n\t\t\t},\n\t\t),\n\t);\n}\n\n/** The URL to open: absolute, same-origin, or `undefined` (a cross-origin or malformed URL is refused). */\nexport function sameOriginUrl(\n\traw: unknown,\n\torigin: string,\n): string | undefined {\n\tconst value = text(raw);\n\tif (!value) return undefined;\n\ttry {\n\t\tconst url = new URL(value, origin);\n\t\treturn url.origin === origin ? url.href : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Closes the notification, then focuses an open same-origin window\n * (navigating it to the notice's `url` when it can, else opening `url`) or\n * opens `url`. A cross-origin `url` is refused: the app's own page is focused\n * or opened instead.\n */\nexport function handleNotificationClick(\n\tevent: NotificationClickEventLike,\n): void {\n\tevent.notification.close();\n\tconst scope = workerScope();\n\tconst { origin } = scope.location;\n\tconst data = event.notification.data as { url?: unknown } | null | undefined;\n\tconst target = sameOriginUrl(data?.url, origin);\n\tevent.waitUntil(\n\t\t(async () => {\n\t\t\tconst windows = await scope.clients.matchAll({\n\t\t\t\ttype: 'window',\n\t\t\t\tincludeUncontrolled: true,\n\t\t\t});\n\t\t\tconst open = windows.find((client) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn new URL(client.url).origin === origin;\n\t\t\t\t} catch {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (!open) {\n\t\t\t\tawait scope.clients.openWindow(target ?? origin);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet navigated = !target;\n\t\t\tif (target && open.navigate) {\n\t\t\t\ttry {\n\t\t\t\t\tawait open.navigate(target);\n\t\t\t\t\tnavigated = true;\n\t\t\t\t} catch {\n\t\t\t\t\t// An uncontrolled window refuses navigate(): open the url instead.\n\t\t\t\t}\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait open.focus();\n\t\t\t} catch {\n\t\t\t\t// Focus is best effort.\n\t\t\t}\n\t\t\tif (!navigated && target) await scope.clients.openWindow(target);\n\t\t})(),\n\t);\n}\n",
7
+ "import {\n\tclientsClaim,\n\tsetCacheNameDetails,\n\ttype WorkboxPlugin,\n} from 'workbox-core';\nimport { ExpirationPlugin } from 'workbox-expiration';\nimport * as navigationPreload from 'workbox-navigation-preload';\nimport { matchPrecache, precacheAndRoute } from 'workbox-precaching';\nimport { registerRoute } from 'workbox-routing';\nimport {\n\tCacheFirst,\n\tNetworkOnly,\n\tStaleWhileRevalidate,\n} from 'workbox-strategies';\nimport { injectedPrecache } from './injected';\nimport {\n\tdeleteObsoleteCaches,\n\tisSkipWaiting,\n\tmatcher,\n\tstorableOnly,\n\ttype WorkerOptions,\n\tworkerPlan,\n} from './plan';\nimport { handleNotificationClick, handlePush, type PushOptions } from './push';\nimport { workerScope } from './scope';\n\n/**\n * Starts the service worker on Workbox. Call it once, from the worker's entry.\n *\n * - The precache route is registered first: a precached URL is answered from\n * the precache before any route below. Exact URLs only (`cleanURLs: false`,\n * no directory index), so a page load still goes to the network.\n * - A navigation is never stored: with navigation preload the browser starts\n * the request alongside the worker, and `NetworkOnly` answers with it. The\n * offline page answers only when the network fails, never for an HTTP error.\n * - Hashed bundles are cache-first, other static files stale-while-revalidate;\n * both store only what `isStorable` accepts.\n * - `push` (off by default) adds the `push` and `notificationclick` listeners:\n * `handlePush` shows the notice, `handleNotificationClick` opens it.\n * - A first install controls the open pages at once; an update waits until\n * the page posts `SKIP_WAITING`.\n */\nexport function startWorker(options: WorkerOptions): void {\n\tconst plan = workerPlan(options, injectedPrecache());\n\tconst scope = workerScope();\n\tconst { contract } = options;\n\tsetCacheNameDetails(plan.cacheNameDetails);\n\tprecacheAndRoute([...plan.precache], {\n\t\tcleanURLs: false,\n\t\tdirectoryIndex: '',\n\t});\n\tif (plan.navigationPreload) navigationPreload.enable();\n\n\tfor (const route of plan.routes) {\n\t\tconst match = matcher(route.caching, () => scope.location.origin, options);\n\t\tif (route.strategy === 'network-only') {\n\t\t\tconst { fallback } = route;\n\t\t\tregisterRoute(\n\t\t\t\tmatch,\n\t\t\t\tnew NetworkOnly({\n\t\t\t\t\tplugins: fallback\n\t\t\t\t\t\t? [{ handlerDidError: async () => matchPrecache(fallback) }]\n\t\t\t\t\t\t: [],\n\t\t\t\t}),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst Strategy =\n\t\t\troute.strategy === 'cache-first' ? CacheFirst : StaleWhileRevalidate;\n\t\tregisterRoute(\n\t\t\tmatch,\n\t\t\tnew Strategy({\n\t\t\t\tcacheName: route.cacheName,\n\t\t\t\tplugins: [\n\t\t\t\t\tstorableOnly,\n\t\t\t\t\tnew ExpirationPlugin({\n\t\t\t\t\t\t...route.expiration,\n\t\t\t\t\t\tpurgeOnQuotaError: true,\n\t\t\t\t\t}) as WorkboxPlugin, // ExpirationPlugin's optional hooks are not exact-optional under exactOptionalPropertyTypes; this states it is a plugin.\n\t\t\t\t],\n\t\t\t}),\n\t\t);\n\t}\n\n\tclientsClaim();\n\tscope.addEventListener('activate', (event) => {\n\t\tevent.waitUntil(deleteObsoleteCaches(contract, caches));\n\t});\n\tscope.addEventListener('message', (event) => {\n\t\tif (isSkipWaiting(event.data)) void scope.skipWaiting();\n\t});\n\tif (options.push) {\n\t\tconst push: PushOptions = options.push === true ? {} : options.push;\n\t\tscope.addEventListener('push', (event) => handlePush(event, push));\n\t\tscope.addEventListener('notificationclick', handleNotificationClick);\n\t}\n}\n",
8
+ "import {\n\ttype Caching,\n\ttype CachingOptions,\n\tcachingFor,\n\ttype RequestFacts,\n} from '../model/caching';\nimport type { PrecacheEntry } from '../model/precache-list';\nimport { isStorable } from '../model/storable';\nimport { SKIP_WAITING, type WorkerContract } from '../model/worker-contract';\nimport type { PushOptions } from './push';\n\n/** How many files, and for how long, a runtime cache keeps. */\nexport interface ExpirationOptions {\n\tmaxEntries?: number;\n\tmaxAgeSeconds?: number;\n}\n\nexport interface WorkerOptions {\n\t/** The app's contract: cache names, offline page, the worker's URL. */\n\tcontract: WorkerContract;\n\t/** What `cachingFor` reads besides the contract: `never`, `immutable`, `manifestPath`, `serviceWorkerUrl`. */\n\tcaching?: Omit<CachingOptions, 'contract'>;\n\t/** The hashed bundles' cache. `{ maxEntries: 200 }` by default. */\n\tassets?: ExpirationOptions;\n\t/** The other static files' cache. `{ maxEntries: 100, maxAgeSeconds: 30 days }` by default. */\n\tstatic?: ExpirationOptions;\n\t/** Start the worker alongside a page load. `true` by default. */\n\tnavigationPreload?: boolean;\n\t/** The precache list. By default the one the build wrote into the worker. */\n\tprecache?: readonly PrecacheEntry[];\n\t/**\n\t * Show pushed notices and open them on click (`handlePush`,\n\t * `handleNotificationClick`). Off by default: an app without push is\n\t * unchanged. `true` for the defaults, or the `PushOptions`.\n\t */\n\tpush?: boolean | PushOptions;\n}\n\nexport type WorkerRoute =\n\t| {\n\t\t\tcaching: 'navigation';\n\t\t\tstrategy: 'network-only';\n\t\t\tfallback: string | undefined;\n\t }\n\t| {\n\t\t\tcaching: 'immutable';\n\t\t\tstrategy: 'cache-first';\n\t\t\tcacheName: string;\n\t\t\texpiration: ExpirationOptions & { maxEntries: number };\n\t }\n\t| {\n\t\t\tcaching: 'static';\n\t\t\tstrategy: 'stale-while-revalidate';\n\t\t\tcacheName: string;\n\t\t\texpiration: ExpirationOptions;\n\t };\n\nexport interface WorkerPlan {\n\tcacheNameDetails: { prefix: string; precache: 'precache'; suffix: string };\n\tprecache: readonly PrecacheEntry[];\n\troutes: readonly WorkerRoute[];\n\tnavigationPreload: boolean;\n}\n\nconst THIRTY_DAYS = 30 * 24 * 60 * 60;\n\n/** What the worker does, decided without Workbox so that it is tested as data. */\nexport function workerPlan(\n\toptions: WorkerOptions,\n\tinjected: readonly PrecacheEntry[] | undefined,\n): WorkerPlan {\n\tconst { contract } = options;\n\tif (!contract) {\n\t\tthrow new TypeError(\n\t\t\t'startWorker(): contract is required: pass defineWorkerContract({ cachePrefix }) from @softistx/alxia-react-router/pwa.',\n\t\t);\n\t}\n\tconst precache = options.precache ?? injected;\n\tif (!precache) {\n\t\tthrow new Error(\n\t\t\t'startWorker(): no precache list. Build this worker with alxia() from @softistx/alxia-react-router/vite (app/service-worker.ts) or buildWorker() from @softistx/alxia-react-router/pwa/build, which write it in.',\n\t\t);\n\t}\n\tconst offlineUrl = contract.offlineUrl;\n\tconst hasOffline = precache.some(\n\t\t(entry) => entry.url.split('?')[0] === offlineUrl,\n\t);\n\treturn {\n\t\tcacheNameDetails: {\n\t\t\tprefix: contract.cachePrefix,\n\t\t\tprecache: 'precache',\n\t\t\tsuffix: contract.cacheVersion,\n\t\t},\n\t\tprecache,\n\t\troutes: [\n\t\t\t{\n\t\t\t\tcaching: 'navigation',\n\t\t\t\tstrategy: 'network-only',\n\t\t\t\tfallback: hasOffline ? offlineUrl : undefined,\n\t\t\t},\n\t\t\t{\n\t\t\t\tcaching: 'immutable',\n\t\t\t\tstrategy: 'cache-first',\n\t\t\t\tcacheName: contract.cacheNames.assets,\n\t\t\t\texpiration: { maxEntries: 200, ...options.assets },\n\t\t\t},\n\t\t\t{\n\t\t\t\tcaching: 'static',\n\t\t\t\tstrategy: 'stale-while-revalidate',\n\t\t\t\tcacheName: contract.cacheNames.static,\n\t\t\t\texpiration: {\n\t\t\t\t\tmaxEntries: 100,\n\t\t\t\t\tmaxAgeSeconds: THIRTY_DAYS,\n\t\t\t\t\t...options.static,\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tnavigationPreload: options.navigationPreload ?? true,\n\t};\n}\n\n/** Whether a request is answered the way `caching` says. */\nexport function matcher(\n\tcaching: Caching,\n\torigin: () => string,\n\toptions: WorkerOptions,\n): (o: { request: RequestFacts }) => boolean {\n\treturn ({ request }) =>\n\t\tcachingFor(request, origin(), {\n\t\t\t...options.caching,\n\t\t\tcontract: options.contract,\n\t\t}) === caching;\n}\n\n/** Stores only what `isStorable` accepts: a public, same-origin 200. */\nexport const storableOnly = {\n\tasync cacheWillUpdate({\n\t\tresponse,\n\t}: {\n\t\tresponse: Response;\n\t}): Promise<Response | null> {\n\t\treturn isStorable(response) ? response : null;\n\t},\n};\n\nexport function isSkipWaiting(data: unknown): boolean {\n\treturn (data as { type?: unknown } | null | undefined)?.type === SKIP_WAITING;\n}\n\n/** Deletes the caches an earlier version of the contract owned. */\nexport async function deleteObsoleteCaches(\n\tcontract: Pick<WorkerContract, 'obsoleteCaches'>,\n\tstorage: Pick<CacheStorage, 'keys' | 'delete'>,\n): Promise<void> {\n\tconst names = await storage.keys();\n\tawait Promise.all(\n\t\tcontract.obsoleteCaches(names).map((name) => storage.delete(name)),\n\t);\n}\n"
8
9
  ],
9
- "mappings": ";;;;;;;;;;;AAAA;AAAA;AAAA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ACf,SAAS,WACN,CAAC,EAAE,iBAAiB,YAAY,cAAc,QAAQ,EAAE,CAAC,IACzD,CAAC;AAAA,MACL,CAAC,CACF;AAAA,MACA;AAAA,IACD;AAAA,IACA,MAAM,WACL,MAAM,aAAa,gBAAgB,aAAa;AAAA,IACjD,cACC,OACA,IAAI,SAAS;AAAA,MACZ,WAAW,MAAM;AAAA,MACjB,SAAS;AAAA,QACR;AAAA,QACA,IAAI,iBAAiB;AAAA,aACjB,MAAM;AAAA,UACT,mBAAmB;AAAA,QACpB,CAAC;AAAA,MACF;AAAA,IACD,CAAC,CACF;AAAA,EACD;AAAA,EAEA,aAAa;AAAA,EACb,MAAM,iBAAiB,YAAY,CAAC,UAAU;AAAA,IAC7C,MAAM,UAAU,qBAAqB,UAAU,MAAM,CAAC;AAAA,GACtD;AAAA,EACD,MAAM,iBAAiB,WAAW,CAAC,UAAU;AAAA,IAC5C,IAAI,cAAc,MAAM,IAAI;AAAA,MAAQ,MAAM,YAAY;AAAA,GACtD;AAAA,EACD,IAAI,QAAQ,MAAM;AAAA,IACjB,MAAM,OAAoB,QAAQ,SAAS,OAAO,CAAC,IAAI,QAAQ;AAAA,IAC/D,MAAM,iBAAiB,QAAQ,CAAC,UAAU,WAAW,OAAO,IAAI,CAAC;AAAA,IACjE,MAAM,iBAAiB,qBAAqB,uBAAuB;AAAA,EACpE;AAAA;",
11
+ "debugId": "5667746300451FBE64756E2164756E21",
11
12
  "names": []
12
13
  }
@@ -1,6 +1,7 @@
1
1
  import { type Caching, type CachingOptions, type RequestFacts } from '../model/caching';
2
2
  import type { PrecacheEntry } from '../model/precache-list';
3
3
  import { type WorkerContract } from '../model/worker-contract';
4
+ import type { PushOptions } from './push';
4
5
  /** How many files, and for how long, a runtime cache keeps. */
5
6
  export interface ExpirationOptions {
6
7
  maxEntries?: number;
@@ -19,6 +20,12 @@ export interface WorkerOptions {
19
20
  navigationPreload?: boolean;
20
21
  /** The precache list. By default the one the build wrote into the worker. */
21
22
  precache?: readonly PrecacheEntry[];
23
+ /**
24
+ * Show pushed notices and open them on click (`handlePush`,
25
+ * `handleNotificationClick`). Off by default: an app without push is
26
+ * unchanged. `true` for the defaults, or the `PushOptions`.
27
+ */
28
+ push?: boolean | PushOptions;
22
29
  }
23
30
  export type WorkerRoute = {
24
31
  caching: 'navigation';
@@ -1 +1 @@
1
- {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../../src/pwa/worker/plan.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,cAAc,EAEnB,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE7E,+DAA+D;AAC/D,MAAM,WAAW,iBAAiB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC7B,uEAAuE;IACvE,QAAQ,EAAE,cAAc,CAAC;IACzB,8GAA8G;IAC9G,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAC3C,mEAAmE;IACnE,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,+FAA+F;IAC/F,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,iEAAiE;IACjE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CACpC;AAED,MAAM,MAAM,WAAW,GACpB;IACA,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,GACD;IACA,OAAO,EAAE,WAAW,CAAC;IACrB,QAAQ,EAAE,aAAa,CAAC;IACxB,SAAS,EAAE,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string;
4
+ body?: string;
5
+ url?: string;
6
+ tag?: string;
7
+ }
8
+ export interface PushOptions {
9
+ /** The title shown when a push has no payload or an unreadable one. `'Notification'` by default. */
10
+ fallbackTitle?: string;
11
+ /** The notification's icon URL. */
12
+ icon?: string;
13
+ /** The notification's badge URL. */
14
+ badge?: string;
15
+ }
16
+ /** The part of a `PushEvent` the helpers read. */
17
+ export interface PushEventLike {
18
+ data?: {
19
+ json(): unknown;
20
+ } | null | undefined;
21
+ waitUntil(promise: Promise<unknown>): void;
22
+ }
23
+ /** The part of a `NotificationEvent` the helpers read. */
24
+ export interface NotificationClickEventLike {
25
+ notification: {
26
+ close(): void;
27
+ data?: unknown;
28
+ };
29
+ waitUntil(promise: Promise<unknown>): void;
30
+ }
31
+ /** Reads the payload; `undefined` when there is none, it is not JSON or it has no usable shape. */
32
+ export declare function readPayload(event: PushEventLike): PushPayload | undefined;
33
+ /**
34
+ * Shows the pushed notice. Reads `{ title, body?, url?, tag? }`; with no
35
+ * payload, or one that is not that shape, shows `fallbackTitle` so a push is
36
+ * never silent. The `url` travels in the notification's `data` for the click.
37
+ */
38
+ export declare function handlePush(event: PushEventLike, options?: PushOptions): void;
39
+ /** The URL to open: absolute, same-origin, or `undefined` (a cross-origin or malformed URL is refused). */
40
+ export declare function sameOriginUrl(raw: unknown, origin: string): string | undefined;
41
+ /**
42
+ * Closes the notification, then focuses an open same-origin window
43
+ * (navigating it to the notice's `url` when it can, else opening `url`) or
44
+ * opens `url`. A cross-origin `url` is refused: the app's own page is focused
45
+ * or opened instead.
46
+ */
47
+ export declare function handleNotificationClick(event: NotificationClickEventLike): void;
48
+ //# sourceMappingURL=push.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../../src/pwa/worker/push.ts"],"names":[],"mappings":"AAEA,qEAAqE;AACrE,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IAC3B,oGAAoG;IACpG,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,kDAAkD;AAClD,MAAM,WAAW,aAAa;IAC7B,IAAI,CAAC,EAAE;QAAE,IAAI,IAAI,OAAO,CAAA;KAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9C,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC3C;AAED,0DAA0D;AAC1D,MAAM,WAAW,0BAA0B;IAC1C,YAAY,EAAE;QAAE,KAAK,IAAI,IAAI,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAChD,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC3C;AAKD,mGAAmG;AACnG,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAoBzE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACzB,KAAK,EAAE,aAAa,EACpB,OAAO,GAAE,WAAgB,GACvB,IAAI,CAeN;AAED,2GAA2G;AAC3G,wBAAgB,aAAa,CAC5B,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,MAAM,GACZ,MAAM,GAAG,SAAS,CASpB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,0BAA0B,GAC/B,IAAI,CAwCN"}
@@ -1,3 +1,4 @@
1
+ import type { NotificationClickEventLike, PushEventLike } from './push';
1
2
  /**
2
3
  * The part of the service worker's global scope that `startWorker` reads,
3
4
  * declared here so no WebWorker-only type reaches the package's declarations
@@ -8,10 +9,32 @@ export interface WorkerScope {
8
9
  readonly origin: string;
9
10
  };
10
11
  skipWaiting(): Promise<void>;
12
+ readonly registration: {
13
+ showNotification(title: string, options?: {
14
+ body?: string;
15
+ tag?: string;
16
+ icon?: string;
17
+ badge?: string;
18
+ data?: unknown;
19
+ }): Promise<void>;
20
+ };
21
+ readonly clients: {
22
+ matchAll(options: {
23
+ type: 'window';
24
+ includeUncontrolled: boolean;
25
+ }): Promise<ReadonlyArray<{
26
+ url: string;
27
+ focus(): Promise<unknown>;
28
+ navigate?(url: string): Promise<unknown>;
29
+ }>>;
30
+ openWindow(url: string): Promise<unknown>;
31
+ };
11
32
  addEventListener(type: 'activate' | 'message', listener: (event: {
12
33
  data?: unknown;
13
34
  waitUntil(promise: Promise<unknown>): void;
14
35
  }) => void): void;
36
+ addEventListener(type: 'push', listener: (event: PushEventLike) => void): void;
37
+ addEventListener(type: 'notificationclick', listener: (event: NotificationClickEventLike) => void): void;
15
38
  }
16
39
  /** The worker's scope. Called only inside `startWorker`, never at module load. */
17
40
  export declare const workerScope: () => WorkerScope;
@@ -1 +1 @@
1
- {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../src/pwa/worker/scope.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,gBAAgB,CACf,IAAI,EAAE,UAAU,GAAG,SAAS,EAC5B,QAAQ,EAAE,CAAC,KAAK,EAAE;QACjB,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;KAC3C,KAAK,IAAI,GACR,IAAI,CAAC;CACR;AAED,kFAAkF;AAClF,eAAO,MAAM,WAAW,QAAO,WACM,CAAC"}
1
+ {"version":3,"file":"scope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AAI,CAAC;KAC3C,KAAK,IAAI,GACR,IAAI,CAAC;IACR,gBAAgB,CACf,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,GACtC,IAAI,CAAC;IACR,gBAAgB,CACf,IAAI,EAAE,mBAAmB,EACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,GACnD,IAAI,CAAC;CACR;AAED,kFAAkF;AAClF,eAAO,MAAM,WAAW,QAAO,WACM,CAAC"}
@@ -10,6 +10,8 @@ import { type WorkerOptions } from './plan';
10
10
  * offline page answers only when the network fails, never for an HTTP error.
11
11
  * - Hashed bundles are cache-first, other static files stale-while-revalidate;
12
12
  * both store only what `isStorable` accepts.
13
+ * - `push` (off by default) adds the `push` and `notificationclick` listeners:
14
+ * `handlePush` shows the notice, `handleNotificationClick` opens it.
13
15
  * - A first install controls the open pages at once; an update waits until
14
16
  * the page posts `SKIP_WAITING`.
15
17
  */
@@ -1 +1 @@
1
- {"version":3,"file":"start-worker.d.ts","sourceRoot":"","sources":["../../../src/pwa/worker/start-worker.ts"],"names":[],"mappings":"AAeA,OAAO,EAKN,KAAK,aAAa,EAElB,MAAM,QAAQ,CAAC;AAGhB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAiDxD"}
1
+ {"version":3,"file":"start-worker.d.ts","sourceRoot":"","sources":["../../../src/pwa/worker/start-worker.ts"],"names":[],"mappings":"AAeA,OAAO,EAKN,KAAK,aAAa,EAElB,MAAM,QAAQ,CAAC;AAIhB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAsDxD"}
package/docs/guide/pwa.md CHANGED
@@ -32,7 +32,7 @@ globals only inside its functions, never at load.
32
32
  | subpath | for | needs |
33
33
  | --- | --- | --- |
34
34
  | `/pwa` | every runtime: the contract, `cachingFor`, `isStorable`, `registerServiceWorker`, `createUpdateNotice`, `manifestHref`, `webAppManifest`, `clearAppCaches`, the precache parts and `SERVICE_WORKER_URL` | nothing: it imports nothing |
35
- | `/pwa/react` | the page's hooks: `useServiceWorker`, `useUpdateNotice`, `useOnline` | `react` (`^19`), an optional peer. Keep it out of the worker, which would bundle React |
35
+ | `/pwa/react` | the page's hooks: `useServiceWorker`, `useUpdateNotice`, `useOnline`, `usePushSubscription`, `usePushStatus` | `react` (`^19`), an optional peer. Keep it out of the worker, which would bundle React |
36
36
  | `/pwa/server` | the server file alone: `noCache` and `revalidated` | `@softistx/alxia`, a peer the package already has |
37
37
  | `/pwa/worker` | the service worker bundle alone: `startWorker`, `injectedPrecache` | the six `workbox-*` packages (`core`, `expiration`, `navigation-preload`, `precaching`, `routing`, `strategies`), optional peers (`^7`) |
38
38
  | `/pwa/build` | a build pipeline of your own: `buildWorker` | Bun; Node's built-ins are its only imports, and it reads `Bun` only inside the function. The Workbox peers must be installed to bundle the worker |
@@ -107,6 +107,7 @@ the six `workbox-*` packages it bundles as development dependencies
107
107
  | `static` | `{ maxEntries: 100, maxAgeSeconds: 2592000 }` | the same for the other static files (30 days) |
108
108
  | `navigationPreload` | `true` | the browser starts a page load's request alongside the worker |
109
109
  | `precache` | the list the build wrote in | `[{ url, revision }]`; a worker with neither throws at once |
110
+ | `push` | off | `true` or `{ fallbackTitle, icon, badge }`: show pushed notices and open them on click ([Push notifications](#push-notifications)) |
110
111
 
111
112
  What each answer of `cachingFor` becomes:
112
113
 
@@ -132,6 +133,103 @@ own bundle). Read without the build it is `undefined`, so the
132
133
  worker's error is [`startWorker(): no precache list`](../troubleshooting.md#startworker-no-precache-list-)
133
134
  instead of a `ReferenceError`.
134
135
 
136
+ ### Push notifications
137
+
138
+ Opt in with `push: true` and the worker shows pushed notices and opens them on
139
+ click. An app without it is unchanged: no `push` or `notificationclick`
140
+ listener is added.
141
+
142
+ ```ts
143
+ startWorker({
144
+ contract: workerContract,
145
+ push: { fallbackTitle: 'My app', icon: '/icons/192.png' },
146
+ });
147
+ ```
148
+
149
+ - **`push` event.** `handlePush` reads the JSON payload
150
+ `{ title, body?, url?, tag? }` and calls `showNotification`. With no payload,
151
+ or one that is not JSON or has no `title`, it shows `fallbackTitle`
152
+ (`'Notification'` by default), so a push is never silent. `icon` and
153
+ `badge` apply to every notice.
154
+ - **`notificationclick` event.** `handleNotificationClick` closes the notice,
155
+ then focuses an open window of the app (navigating it to `url` when it can)
156
+ or opens `url`. Only a same-origin `url` is used: a cross-origin or
157
+ malformed one is refused and the app's own origin is focused or opened
158
+ instead.
159
+
160
+ `handlePush(event, options?)` and `handleNotificationClick(event)` are also
161
+ exported from `/pwa/worker`, for a worker of your own that registers its
162
+ listeners itself. The subscription (VAPID key, `pushManager.subscribe`) stays
163
+ the page's job: `usePushSubscription()` from `/pwa/react` does it
164
+ ([Subscribing from the page](#subscribing-from-the-page)).
165
+
166
+ #### Subscribing from the page
167
+
168
+ ```tsx
169
+ // file: app/push-button.tsx
170
+ import { type PushSubscriptionJson, usePushSubscription } from '@softistx/alxia-react-router/pwa/react';
171
+
172
+ // Your own calls to the server (the subscribePush / unsubscribePush mutations).
173
+ declare function sendToServer(subscription: PushSubscriptionJson): Promise<void>;
174
+ declare function sendEndpointToServer(endpoint: string | null): Promise<void>;
175
+
176
+ export function PushButton({ vapidPublicKey }: { vapidPublicKey: string }) {
177
+ const push = usePushSubscription();
178
+ if (push.status === 'unsupported') return null;
179
+ if (push.status === 'install-required') return <p>Add the app to your home screen to get notices.</p>;
180
+ if (push.status === 'denied') return <p>Notices are blocked in your browser settings.</p>;
181
+ if (push.status === 'granted') {
182
+ return <button type="button" onClick={() => push.unsubscribe().then(sendEndpointToServer)}>Turn off</button>;
183
+ }
184
+ return (
185
+ <button type="button" disabled={push.status === 'asking'} onClick={() => push.subscribe(vapidPublicKey).then((json) => json && sendToServer(json))}>
186
+ Turn on
187
+ </button>
188
+ );
189
+ }
190
+ ```
191
+
192
+ - **`status`** is `available | asking | granted | denied | install-required | unsupported`.
193
+ `granted` means permission is granted **and** this browser holds a
194
+ subscription; permission with no subscription is `available`. `asking` is
195
+ while `subscribe()` runs. `install-required` is iOS outside an installed
196
+ app (no `display-mode: standalone`, no `PushManager`). On the server and
197
+ while hydrating it is `unsupported`; the browser is read in an effect, so no
198
+ `window` access happens during render. `usePushStatus()` returns just the
199
+ status, for a presentational opt-in card's `status` prop; `derivePushStatus(facts)`
200
+ is the pure rule.
201
+ - **One shared state.** Every `usePushSubscription()` and `usePushStatus()` on
202
+ the page reads one store, so a card and a button always agree. It reads the
203
+ browser once something is mounted, and again when the tab shows or the
204
+ permission changes (`navigator.permissions` `onchange` where available, the
205
+ `visibilitychange` event as the fallback), so a change in the browser's
206
+ settings shows up.
207
+ - **Never prompts on mount.** `subscribe(vapidPublicKey)` calls
208
+ `Notification.requestPermission()` only inside the call, so call it from a
209
+ click. A second call while one runs returns the same promise. It first checks
210
+ that a service worker is registered (before the prompt, so the user is never
211
+ asked for nothing) and rejects otherwise with
212
+ `usePushSubscription: no service worker is registered; register the service worker first`
213
+ ([troubleshooting](../troubleshooting.md#usepushsubscription-no-service-worker-is-registered-register-the-service-worker-first)). If permission is not granted it resolves `null`. Otherwise it calls
214
+ `pushManager.subscribe({ userVisibleOnly: true, applicationServerKey })`
215
+ (the base64url key decoded to bytes) and resolves with the
216
+ subscription's `toJSON()` for the app to send to its server. On a browser
217
+ with no Web Push, `subscribe` and `unsubscribe` resolve `null`.
218
+ - **A new VAPID key replaces the old subscription.** A subscription made with
219
+ another key (or an `InvalidStateError` from the browser) is unsubscribed and
220
+ made again, and the old endpoint is in `replaced` so the app can tell its
221
+ server (`unsubscribePush`) to drop it. A subscription already made with the
222
+ same key is returned as it is.
223
+ - **`unsubscribe()`** unsubscribes and resolves with the endpoint (to tell the
224
+ server), or `null` when there was none.
225
+ - The state also has `supported`, `permission` (`default | granted | denied`),
226
+ `installedPwa`, `subscription` (`toJSON()` or `null`) and `replaced`.
227
+ - **Types and helpers.** `PushSubscriptionState` is the hook's return type,
228
+ `PushSubscriptionJson` the shape `subscribe()` resolves, `PushFacts` and
229
+ `PushPermission` what `derivePushStatus(facts)` reads, and
230
+ `urlBase64ToBytes(key)` decodes a base64url VAPID key to the bytes
231
+ `applicationServerKey` takes.
232
+
135
233
  ## What the worker caches
136
234
 
137
235
  `cachingFor(request, origin, options?)` answers with one of four words:
@@ -464,6 +562,8 @@ export function UpdateBanner() {
464
562
  `undefined` on the server and while hydrating.
465
563
  - **`useOnline()`** is `navigator.onLine`, `true` on the server and while
466
564
  hydrating, so the first client render matches the server's.
565
+ - **`usePushSubscription()`** and **`usePushStatus()`** are described under
566
+ [Push notifications](#push-notifications).
467
567
  - **`updateNotice`** is the page's one store. It is made in this subpath, not in
468
568
  `/pwa`, so the model a worker bundle imports does nothing at load. Both
469
569
  hooks use it unless given another `notice`; pass the same store to both
@@ -67,6 +67,7 @@ a loader, a message React Router or the browser prints, or an error from
67
67
  - [`TypeError: defineWorkerContract(): cacheVersion must be a non-empty name without '-', …`](#typeerror-defineworkercontract-cacheversion-must-be-a-non-empty-name-without---)
68
68
  - [`parseBrowserManifest(): not React Router's browser manifest …`](#parsebrowsermanifest-not-react-routers-browser-manifest-)
69
69
  - [`error: Cannot find package 'react' from '…/@softistx/alxia-react-router/dist/pwa/react/index.js'`](#error-cannot-find-package-react-from-softistxalxia-react-routerdistpwareactindexjs)
70
+ - [`usePushSubscription: no service worker is registered; register the service worker first`](#usepushsubscription-no-service-worker-is-registered-register-the-service-worker-first)
70
71
  - [`error: Cannot find package 'isbot' from '…/@softistx/alxia-react-router/dist/entry/index.js'`](#error-cannot-find-package-isbot-from-softistxalxia-react-routerdistentryindexjs)
71
72
  - [`error: Cannot find package '@softistx/alxia-proxy' from '…/@softistx/alxia-react-router/dist/mcp/index.js'`](#error-cannot-find-package-softistxalxia-proxy-from-softistxalxia-react-routerdistmcpindexjs)
72
73
  - [`TypeError: proxy(): the target must be an absolute URL, http:// or https://; got "…"`](#typeerror-proxy-the-target-must-be-an-absolute-url-http-or-https-got-)
@@ -1519,6 +1520,23 @@ this message too.
1519
1520
  `/pwa/react` from the page alone. The worker and a build script import
1520
1521
  `@softistx/alxia-react-router/pwa`, which imports nothing.
1521
1522
 
1523
+ ### `usePushSubscription: no service worker is registered; register the service worker first`
1524
+
1525
+ **When:** `subscribe(vapidPublicKey)` from `usePushSubscription()` is called
1526
+ on a page where no service worker is registered. The permission prompt is
1527
+ not shown.
1528
+
1529
+ **Why:** Web Push subscribes through the worker's registration, and
1530
+ `subscribe` checks for one before it asks the user, so nobody is prompted
1531
+ for a subscription that cannot be made. `useServiceWorker()` registers only
1532
+ when `enabled` is true (the app passes `import.meta.env.PROD`), so under
1533
+ `react-router dev` there is no worker.
1534
+
1535
+ **Fix:** call `useServiceWorker({ enabled: import.meta.env.PROD })` in the
1536
+ root route, and try push on a production build (`react-router build`, then
1537
+ start the server). Built with `push: true` in `startWorker()`, the worker
1538
+ also shows the notices it receives.
1539
+
1522
1540
  ### `error: Cannot find package 'isbot' from '…/@softistx/alxia-react-router/dist/entry/index.js'`
1523
1541
 
1524
1542
  **When:** a request with a user agent reaches `entry.server.tsx` re-exporting
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softistx/alxia-react-router",
3
- "version": "0.88.0",
3
+ "version": "0.89.0",
4
4
  "description": "alxia as the server of a React Router framework app: server rendering behind the app's hooks, loaders reading its typed context, the client's assets served; the code with no UI an installable app shares (`/pwa`), its hooks (`/pwa/react`), `noCache` for the worker's script (`/pwa/server`), the service worker on Workbox (`/pwa/worker`) and its build (`/pwa/build`), an API's refusals worded for the page (`/errors`), the BFF session: cookies, sign-in, step-up and mail links (`/session`), its page hooks (`/session/react`) and what it shares with the page (`/session/model`), a GraphQL subscription relayed to the browser over SSE (`/subscription`) and kept alive in the page (`/subscription/react`), an API's MCP and OAuth endpoints relayed on the app's origin (`/mcp`), per-role flow docs, the help panel's data and its lazy `HelpPanel`, and the role guide's `useGuideRole` (`/help`, `/help/check`), an API's media files read and uploaded through the app (`/media`) and uploaded from the page with progress (`/media/client`), the page's CSP nonce and inline boot scripts (`/document`) and a streaming `entry.server` (`/entry`), the consent screen of an OAuth server: a route's loader and action, the connected apps' list and revoke (`/oauth`) and the decision hook (`/oauth/react`), a user's API keys listed, created behind a step-up and revoked (`/api-keys`) and `/oidc`: a relying party of an external OpenID Connect issuer (authorization code + PKCE, id token validation, a sealed token cookie, refresh and RP-initiated logout)",
5
5
  "license": "MIT",
6
6
  "type": "module",