@ultimat3/pwa 31.48.0 → 31.50.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/CLAUDE.md +2 -2
- package/README.md +2 -2
- package/package.json +6 -6
- package/src/errors.ts +1 -1
- package/src/pages-cache-source.ts +3 -2
- package/src/push-actions.ts +9 -1
- package/src/push.ts +19 -4
- package/src/service-worker.ts +6 -2
- package/src/web-push.ts +5 -11
package/CLAUDE.md
CHANGED
|
@@ -29,7 +29,7 @@ role's boot loads, `@ultimat3/mcp/schema`'s shape; `serve-graph.test.ts` exempts
|
|
|
29
29
|
| Rule patterns | built from the DECODED route path, matched against the PERCENT-ENCODED `url.pathname`: a literal segment is `@ultimat3/core`'s `literalSegmentPattern` — render's compiler too, never a local one. Raw or escaped, either hex case, so `/a\|b` owns `canonicalPath`'s `/a%7Cb` (the WHATWG-serializer copy here missed it until 31.40). A catch-all is `(?:/.*)?`, so `/docs/*path` owns `/docs`. `route-rules.test.ts`; the e2e drives both in Chrome. |
|
|
30
30
|
| Runtime assets | `ServiceWorkerConfig.runtimeAssets` prefixes (`/islands/`) are `cache-first` runtime rules AHEAD of every page rule (`assetRules`, `route-rules.ts`), and go to the network as the browser asked — no build-id header, because a classic script is a `no-cors` request whose headers a worker may not extend. The precache names only what a precached page boots (the CLI chooses: `sw-precache-plan.ts`); all 43 islands (~1 MB) were precached on a first anonymous visit until 22.3.3. |
|
|
31
31
|
| Precached assets | answered from the precache AHEAD of every rule (`precached-asset-source.ts`): first when revision = url, else network first. No rule read them before, `As of 2026-11`: offline documents rendered unstyled. |
|
|
32
|
-
| Pages cache | ≤ `PAGES_CACHE_MAX` (50) documents per cache, oldest written evicted (`putPage`). |
|
|
32
|
+
| Pages cache | ≤ `PAGES_CACHE_MAX` (50) documents per cache, oldest written evicted (`putPage`). A `redirected` answer is stored via `plain(r)`: as fetched, a navigation errors. |
|
|
33
33
|
| Locales | the worker matches pathnames and the server strips `/en/` before it matches, so the CALLER spells every route once per routed locale (`@ultimat3/cli`'s `sw-precache-plan.ts`). `localePrefixes` is only for the offline document: a navigation under `/en/` tries `/en` + `OFFLINE_DOC` first. |
|
|
34
34
|
| What is a navigation | to `offlineFallback`: `mode === 'navigate'`, or the client router's soft visit — a `fetch` carrying `CLIENT_NAVIGATION_HEADER: soft` (core's constant, interpolated). Its `prefetch` is a guess: the 503, or the offline page would be cached as a later click's answer. `offline-fallback.test.ts`. |
|
|
35
35
|
| Precache revision | content hash. Never the build id — that re-downloads everything per deploy. |
|
|
@@ -56,7 +56,7 @@ role's boot loads, `@ultimat3/mcp/schema`'s shape; `serve-graph.test.ts` exempts
|
|
|
56
56
|
| Push strings | i18n keys only, rendered per subscriber locale. Never a literal. The runtime's `translate` defaults to `@ultimat3/i18n`'s `translatorFor(subscription.locale)` — the app's registered catalogs. |
|
|
57
57
|
| Web Push crypto | WebCrypto only, no dependency (`docs/idea/18-build-vs-wrap.md`). `push-encrypt.ts` is RFC 8291 + RFC 8188 (one `aes128gcm` record, delimiter `0x02`, no padding) and is pinned by RFC 8291 Appendix A byte for byte, every intermediate included; it is `scripts/seal-calls.ts`'s `STANDARD_CIPHERS` row, because the key is agreed with the subscriber's browser and is never the app's — `seal()` cannot be what it calls. `vapid.ts` is RFC 8292: `aud` is the endpoint's ORIGIN, `exp` 12 h (≤ 24 h), the signature WebCrypto's raw `r‖s` (= JWS ES256). WebCrypto does not check that `d` belongs to `x`/`y`, so `assertVapidPair` signs and verifies a probe — the boot runs it once. |
|
|
58
58
|
| VAPID keys | env, never config: `ULTIMATE_VAPID_PUBLIC_KEY` + `ULTIMATE_VAPID_PRIVATE_KEY`, printable formats (`web-push`'s). `resolveVapidKeys(env)`: both set → checked pair; neither, locally → `DEV_VAPID_KEYS` (published); neither or the dev key when `devSecretsRefused` (core's rule, fails closed), or half a pair anywhere → `X_PWA_VAPID_KEY_MISSING`. `pwa.vapid` holds the `subject` only. |
|
|
59
|
-
| Push sending | `sendPushMessage` → `delivered` (2xx), `gone` (404/410 — delete, never retry), or a throw: `X_PWA_PUSH_FAILED` (`retry-after`: 429 / 5xx / no connection, `Retry-After` in `meta`), `X_PWA_PUSH_REJECTED` (terminal). `pushToActor` tries EVERY device, deletes the gone
|
|
59
|
+
| Push sending | `sendPushMessage` → `delivered` (2xx), `gone` (404/410 — delete, never retry), or a throw: `X_PWA_PUSH_FAILED` (`retry-after`: 429 / 5xx / no connection, `Retry-After` in `meta`), `X_PWA_PUSH_REJECTED` (terminal). `pushToActor` tries EVERY device, deletes the gone and the expired, never a 401/403 (OUR token's fault as often as a rotated key), logs the refused, and rethrows the first retryable failure LAST — so the notifier job retries, and devices that got it get it again; the `tag` is what makes that a replacement. The endpoint must be `https:` on a LISTED push service (`push-hosts.ts`: the built-in four plus `pwa.vapid.pushHosts`, dot-boundary suffix match), checked at subscribe and at send: it came from a request body, and a hostname resolves wherever its owner points it — the list, never the name's shape or its DNS answer, is the screen. `redirect: 'manual'`, a `PUSH_SEND_TIMEOUT_MS` deadline per POST, and a caller's abort rethrown as is — never the retryable class. |
|
|
60
60
|
| Subscriptions | keyed by ENDPOINT (a browser subscribed by a second person is theirs now), stored against `ctx.actor.id` — never an id from the body. `pushSubscribe` / `pushUnsubscribe` are factories over `action` (`PRIMITIVE_FACTORIES` rows); an agent is refused in the policy. `x_push_subscriptions` is DDL applied by the boot (`FRAMEWORK_SCHEMA`), never an `entity()`. |
|
|
61
61
|
| `renotify` | never without a `tag`, at BOTH ends. The Notifications spec makes `showNotification` reject with a `TypeError` for the pair, so the device shows **nothing** — the failure a `renotify: true` with no collapse key produces is the whole notification disappearing. `renderPushPayload` drops the flag and files a `warnings` entry (a knob with no effect is worse than no knob), and the emitted handler recomputes it as `!!d.renotify&&!!d.tag` because a push body is composed by whatever holds the VAPID key. `push.test.ts`'s `showNotification` stub throws the spec's TypeError, so a stub that tolerates the pair cannot go green. |
|
|
62
62
|
| Push URLs | `PushPayload.url` is a PATH and `WindowClient.url` is absolute, so `notificationclick` resolves against `self.location.origin` before comparing. Unresolved, the focus-existing-tab loop matched nothing and every tap opened a second window. A URL that does not resolve to `self.location.origin` (another host, a scheme, malformed, a non-string) opens the root instead (`tapTarget`). The `push` body is parsed INSIDE `waitUntil` (`pushData`): plain text is the body, JSON that is no object is `{}`. `push-handler.test.ts`. |
|
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ export const channel = pushChannel<{ postId: string }>({
|
|
|
175
175
|
| Strings | catalog keys (`titleKey`, `bodyKey`, `actions[].titleKey`), rendered per subscription locale through `@ultimat3/i18n`'s `translatorFor` |
|
|
176
176
|
| Size | one 4096-byte record: 3993 bytes of notification (`X_PWA_PUSH_PAYLOAD_TOO_LARGE`). Send a path, never the content |
|
|
177
177
|
| Travel | `ttlSeconds` (default 86 400), `urgency`, `topic` — RFC 8030 headers; the topic is any string, sent as 32 URL-safe characters of its SHA-256 |
|
|
178
|
-
| 201 / 404, 410 / 429, 5xx / 400, 401, 403, 413 | delivered / subscription deleted / `X_PWA_PUSH_FAILED`, retried by the job after every other device was tried / `X_PWA_PUSH_REJECTED`, logged, never retried — and on 401/403
|
|
178
|
+
| 201 / 404, 410 / 429, 5xx / 400, 401, 403, 413 | delivered / subscription deleted / `X_PWA_PUSH_FAILED`, retried by the job after every other device was tried / `X_PWA_PUSH_REJECTED`, logged, never retried — and the subscription is **kept**, on 401/403 too: that answer is as often a fault in this server's own token (a `pwa.vapid.subject` the service refuses, a skewed clock) as a rotated key, so only 404/410 deletes (`As of 2026-11-19`) |
|
|
179
179
|
| Key rotation | `subscribeToPush` compares a browser's existing subscription with the page's `x-push-key`; one made with another key is unsubscribed and replaced, never re-saved |
|
|
180
180
|
| Endpoints | dialled only on a push service: `https:`, and a host that is one of `PUSH_SERVICE_HOSTS` (FCM, Mozilla, Apple, WNS) or `pwa.vapid.pushHosts`, or a subdomain of one on a dot boundary — checked when stored and before every send (`assertPushEndpoint`), never by where the name resolves, since the endpoint came from a request body (`X_PWA_PUSH_HOST_UNLISTED`; a stored one is deleted unsent). One POST waits at most `PUSH_SEND_TIMEOUT_MS` (30 s); a caller's abort is rethrown as is, never the retryable class |
|
|
181
181
|
| `renotify` | dropped, with a warning, without a `tag` — at both ends |
|
|
@@ -210,7 +210,7 @@ a job boundary the class is gone and the `code` is what survives — match on th
|
|
|
210
210
|
| `BuiltinImagePipeline` | renders that plan: one square PNG per entry, deterministic |
|
|
211
211
|
| `requireOfflineFallback` | the mandatory offline route |
|
|
212
212
|
| `backgroundSyncSource`, `registerBackgroundSyncSource` | the Background Sync trigger. No retry policy: the handler rejects and the PLATFORM reschedules it |
|
|
213
|
-
| `renderPushPayload`, `pushSource`, `subscribeSource` | Web Push, per-locale bodies |
|
|
213
|
+
| `renderPushPayload`, `pushSource`, `subscribeSource` | Web Push, per-locale bodies. The emitted `subscribePush` reuses a browser's existing subscription unless it was made with another server key, which it unsubscribes and replaces — `subscribeToPush`'s rule |
|
|
214
214
|
| `pushSubscribe`, `pushUnsubscribe` | factories over `action`: store / forget this browser's subscription for `ctx.actor` |
|
|
215
215
|
| `webPush`, `pushToActor` | one notification to every device of one person — `webPush()` is notify's `Pusher` |
|
|
216
216
|
| `installWebPush`, `installedVapid`, `webPushRuntime`, `resetWebPush` | the runtime the boot installs (store, signer, transport, translator) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/pwa",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.50.0",
|
|
4
4
|
"description": "Generated service worker, web manifest, icons, push and version-skew handling.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"test": "bun test"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@ultimat3/action": "31.
|
|
49
|
-
"@ultimat3/core": "31.
|
|
50
|
-
"@ultimat3/i18n": "31.
|
|
51
|
-
"@ultimat3/policy": "31.
|
|
52
|
-
"@ultimat3/schema": "31.
|
|
48
|
+
"@ultimat3/action": "31.50.0",
|
|
49
|
+
"@ultimat3/core": "31.50.0",
|
|
50
|
+
"@ultimat3/i18n": "31.50.0",
|
|
51
|
+
"@ultimat3/policy": "31.50.0",
|
|
52
|
+
"@ultimat3/schema": "31.50.0"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/errors.ts
CHANGED
|
@@ -236,7 +236,7 @@ export class PwaPushRejectedError extends UltimateError {
|
|
|
236
236
|
cause: `the push service at ${input.origin} refused the message with status ${input.status}${input.body === '' ? '' : `: ${input.body}`}`,
|
|
237
237
|
fix:
|
|
238
238
|
input.status === 403 || input.status === 401
|
|
239
|
-
? 'x vapid show # the subscription was made with
|
|
239
|
+
? 'x vapid show # the service refused OUR token: a public key the subscription was not made with, a pwa.vapid.subject it rejects, or a server clock outside the 12 h the token is valid for — the subscription is kept'
|
|
240
240
|
: "vapid: { subject: 'mailto:ops@example.com' } # pwa.vapid in app.config.ts — the push service's answer in the cause names the field it refused",
|
|
241
241
|
meta: { origin: input.origin, status: input.status },
|
|
242
242
|
});
|
|
@@ -46,7 +46,7 @@ function isPrivate(r){
|
|
|
46
46
|
}
|
|
47
47
|
// Every cache but the pages cache is GUARDED in both modes: a private response is never stored there.
|
|
48
48
|
// A pages cache (\`bounded\`) is capped at PAGES_MAX documents, oldest WRITTEN out first.
|
|
49
|
-
function guarded(c,bounded){return{match:(req)=>c.match(req),put:async(req,r)=>{if(!isPrivate(r))return bounded?putPage(c,req,r):c.put(req,r)}}}
|
|
49
|
+
function guarded(c,bounded){return{match:(req)=>c.match(req),put:async(req,r)=>{if(!isPrivate(r))return bounded?putPage(c,req,r):c.put(req,plain(r))}}}
|
|
50
50
|
// keys() is insertion order and a put re-appends, so the head is the page least recently stored.
|
|
51
51
|
// One write at a time: a trim reads keys() and deletes by URL, so a refresh landing between the two
|
|
52
52
|
// re-appended a page the trim then deleted — the page just written gone, an older one kept.
|
|
@@ -54,7 +54,8 @@ const PAGES_MAX=${String(PAGES_CACHE_MAX)};
|
|
|
54
54
|
let paging=Promise.resolve();
|
|
55
55
|
function putPage(c,req,r){const run=paging.then(()=>putTrim(c,req,r));paging=run.catch(()=>{});return run}
|
|
56
56
|
async function putTrim(c,req,r){
|
|
57
|
-
|
|
57
|
+
// plain (the install block's): a redirected copy is a network error to a later navigation.
|
|
58
|
+
await c.put(req,plain(r));
|
|
58
59
|
const keys=await c.keys();
|
|
59
60
|
if(keys.length>PAGES_MAX)await Promise.all(keys.slice(0,keys.length-PAGES_MAX).map((k)=>c.delete(k)));
|
|
60
61
|
}
|
package/src/push-actions.ts
CHANGED
|
@@ -31,6 +31,14 @@ const subscribeInput = () =>
|
|
|
31
31
|
timeZone: t.timezone,
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* `expiration_time` is a Postgres `bigint`: a fraction or `1e30` was an uncoded driver error there
|
|
36
|
+
* and a stored row in memory. The input stays `number | null` — narrowing a published schema is a
|
|
37
|
+
* contract break — so a value that is not whole milliseconds states no expiry, for both stores.
|
|
38
|
+
*/
|
|
39
|
+
const storableExpiry = (at: number | null): number | null =>
|
|
40
|
+
at !== null && Number.isSafeInteger(at) && at >= 0 ? at : null;
|
|
41
|
+
|
|
34
42
|
const subscribeOutput = () => t.object({ endpoint: t.string });
|
|
35
43
|
const unsubscribeInput = () => t.object({ endpoint: t.string.min(1).max(2048) });
|
|
36
44
|
const unsubscribeOutput = () => t.object({ removed: t.boolean });
|
|
@@ -80,7 +88,7 @@ export function pushSubscribe(
|
|
|
80
88
|
timeZone: input.timeZone,
|
|
81
89
|
actorId: ctx.actor.id,
|
|
82
90
|
createdAt: ctx.now().getTime(),
|
|
83
|
-
expirationTime: input.expirationTime,
|
|
91
|
+
expirationTime: storableExpiry(input.expirationTime),
|
|
84
92
|
});
|
|
85
93
|
return { endpoint: input.endpoint };
|
|
86
94
|
},
|
package/src/push.ts
CHANGED
|
@@ -239,14 +239,29 @@ self.addEventListener('notificationclick',(event)=>{
|
|
|
239
239
|
});`.trim();
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
/**
|
|
242
|
+
/**
|
|
243
|
+
* Client-side subscribe. The locale travels with the subscription, by design. An existing
|
|
244
|
+
* subscription is reused UNLESS it was made with another server key (a VAPID rotation): no message
|
|
245
|
+
* signed with this one reaches it, so it is unsubscribed and replaced — `subscribeToPush`'s rule
|
|
246
|
+
* (`push-client.ts`), emitted here because this source is a module of its own with no import.
|
|
247
|
+
*/
|
|
243
248
|
export function subscribeSource(vapid: VapidConfig): string {
|
|
244
249
|
return `
|
|
250
|
+
function madeWith(sub,key){
|
|
251
|
+
const held=sub.options&&sub.options.applicationServerKey;
|
|
252
|
+
if(!held)return true;
|
|
253
|
+
const s=key.replace(/-/g,'+').replace(/_/g,'/'),bin=atob(s.padEnd(s.length+(4-s.length%4)%4,'='));
|
|
254
|
+
const b=new Uint8Array(held);
|
|
255
|
+
if(b.length!==bin.length)return false;
|
|
256
|
+
for(let i=0;i<b.length;i++)if(b[i]!==bin.charCodeAt(i))return false;
|
|
257
|
+
return true
|
|
258
|
+
}
|
|
245
259
|
export async function subscribePush(registration,locale,timeZone){
|
|
246
|
-
const
|
|
260
|
+
const key=${JSON.stringify(vapid.publicKey)};
|
|
261
|
+
let existing=await registration.pushManager.getSubscription();
|
|
262
|
+
if(existing&&!madeWith(existing,key)){await existing.unsubscribe();existing=null}
|
|
247
263
|
if(existing)return {subscription:existing.toJSON(),locale,timeZone};
|
|
248
|
-
const sub=await registration.pushManager.subscribe({userVisibleOnly:true,
|
|
249
|
-
applicationServerKey:${JSON.stringify(vapid.publicKey)}});
|
|
264
|
+
const sub=await registration.pushManager.subscribe({userVisibleOnly:true,applicationServerKey:key});
|
|
250
265
|
return {subscription:sub.toJSON(),locale,timeZone}
|
|
251
266
|
}`.trim();
|
|
252
267
|
}
|
package/src/service-worker.ts
CHANGED
|
@@ -275,13 +275,17 @@ self.addEventListener('install',(event)=>{
|
|
|
275
275
|
const r=await fetch(new Request(e.url+(e.url.indexOf('?')<0?'?':'&')+'v='+e.revision,{cache:'reload'}));
|
|
276
276
|
// Mid-rollout an OLD pod may answer: its document is not this build's offline copy.
|
|
277
277
|
const b=r.headers.get(BUILD_HEADER);
|
|
278
|
-
if(r.ok&&(b===null||b===BUILD_ID))await cache.put(new Request(e.url),r);
|
|
278
|
+
if(r.ok&&(b===null||b===BUILD_ID))await cache.put(new Request(e.url),plain(r));
|
|
279
279
|
}catch(err){}
|
|
280
280
|
}
|
|
281
281
|
};
|
|
282
282
|
await Promise.all(Array.from({length:${PRECACHE_CONCURRENCY}},next));
|
|
283
283
|
})());
|
|
284
|
-
})
|
|
284
|
+
});
|
|
285
|
+
// A response that followed a redirect answers a \`follow\` request only, and a navigation's mode is
|
|
286
|
+
// \`manual\`: stored as fetched, a precached or warmed document was a network error to the tab that
|
|
287
|
+
// navigated to it offline. Stored as a response of its own, with the same body, status and headers.
|
|
288
|
+
function plain(r){return r.redirected?new Response(r.body,{status:r.status,statusText:r.statusText,headers:r.headers}):r}`.trim();
|
|
285
289
|
|
|
286
290
|
function activateBlock(): string {
|
|
287
291
|
return `
|
package/src/web-push.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
// structurally (notify cannot import this package: same tier), so `notify(user, …)` reaches every
|
|
7
7
|
// subscription that user holds with no glue in the app.
|
|
8
8
|
|
|
9
|
-
import type { UltimateError } from '@ultimat3/core';
|
|
10
9
|
import { isUltimateError, logger } from '@ultimat3/core';
|
|
11
10
|
import type { PushPayload } from './push';
|
|
12
11
|
import { renderPushPayload, serializePushMessage, subscriptionState } from './push';
|
|
@@ -80,12 +79,13 @@ export async function pushToActor(
|
|
|
80
79
|
if (!isUltimateError(error)) throw error;
|
|
81
80
|
refused += 1;
|
|
82
81
|
// A stored subscription no send will ever reach is deleted, so the next notification does
|
|
83
|
-
// not pay for it again: a malformed key,
|
|
84
|
-
//
|
|
82
|
+
// not pay for it again: a malformed key, a host this app does not send to. A 401/403 is NOT
|
|
83
|
+
// one: it is what a push service answers a fault in OUR token (a `subject` it refuses, a
|
|
84
|
+
// skewed clock) as well as a rotated key, and deleting on it unsubscribed every device a
|
|
85
|
+
// send reached. Kept; a browser under an old key replaces its own (`subscribeToPush`).
|
|
85
86
|
if (
|
|
86
87
|
error.code === 'X_PWA_PUSH_SUBSCRIPTION_INVALID' ||
|
|
87
|
-
error.code === 'X_PWA_PUSH_HOST_UNLISTED'
|
|
88
|
-
unreachableUnderThisKey(error)
|
|
88
|
+
error.code === 'X_PWA_PUSH_HOST_UNLISTED'
|
|
89
89
|
) {
|
|
90
90
|
await runtime.store.remove(subscription.endpoint);
|
|
91
91
|
}
|
|
@@ -96,12 +96,6 @@ export async function pushToActor(
|
|
|
96
96
|
return { delivered, removed, refused };
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
/** A push service's 401/403: the subscription belongs to another VAPID key, for good. */
|
|
100
|
-
const unreachableUnderThisKey = (error: UltimateError): boolean => {
|
|
101
|
-
const status = (error.meta as { readonly status?: unknown } | undefined)?.status;
|
|
102
|
-
return error.code === 'X_PWA_PUSH_REJECTED' && (status === 401 || status === 403);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
99
|
/** The structural shape `@ultimat3/notify`'s `Pusher` declares. */
|
|
106
100
|
export interface WebPusher {
|
|
107
101
|
send(push: {
|