Repository navigation
feat(sw): retain signed envelope + derive appVersion in loader + server-requested manifest upload - #113
Open
a-d-j-i wants to merge 6 commits into
Open
feat(sw): retain signed envelope + derive appVersion in loader + server-requested manifest upload#113a-d-j-i wants to merge 6 commits into
a-d-j-i wants to merge 6 commits into
Conversation
✅ Deploy Preview for dappfence-templates ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
a-d-j-i
force-pushed
the
feat/sw-signed-envelope
branch
from
November 18, 2026 18:39
3b5814b to
279bf6d
Compare
a-d-j-i
force-pushed
the
feat/sw-signed-envelope
branch
2 times, most recently
from
December 4, 2026 13:27
ea46361 to
bc759f5
Compare
…er-requested manifest upload
Store:
- addLatest({appVersion, signedEnvelope, manifest}) takes caller-computed
appVersion, drops the return value (caller has both inputs)
- new getSignedEnvelope(appVersion) for server-requested re-POST
- deleted createSyntheticAppVersion (moved to loader as deriveAppVersion)
Loader:
- deriveAppVersion(pay) hashes the raw signed payload, not the SW-normalized
manifest, so a server with the same envelope can compute the same id
- normalizeManifestData runs in the caller; store never reshapes input
Event stream:
- POST response header x-dappfence-request-manifest signals which appVersion
the server wants a copy of; uploadManifestIfRequested re-POSTs the matching
signedEnvelope best-effort (errors swallowed, doesn't affect primary POST)
Also: new HEADER_REQUEST_MANIFEST constant.
The SW logger buffers entries as {ts, level, args, count?} and log-stream was
shipping them verbatim as envelope.logs. The Worker's sanitizer expects
{ts, level, message, source?, context?, occurrenceCount?} and reads none of
the SW's fields, so every log row arrived with an empty message column in
df.mjs tail and lost its dedup count.
Add formatArgs(args) and toWireEntry(entry) helpers in log-stream.js and map
the drained batch through toWireEntry before buffering for POST. formatArgs
flattens the args array to a single string (Errors render as "Name: message";
objects JSON.stringify with String() fallback for circular refs), joins with
a space, and caps at 1024 chars with a trailing "..." marker — mirroring
MAX_LOG_MESSAGE_BYTES on the Worker so we never ship bytes the server would
discard.
deriveAppVersion collapses to calculateHash(encode(JSON.stringify(pay))):
same sha256-<base64> shape the codebase already uses for file hashes and SRI
attributes, so appVersion is directly comparable with other hashes without
reformatting. Drops the 96-bit truncation that earlier commits on this branch
emitted (manifest-<16 base64 chars>) — full SHA-256 is cheap (~26 extra chars
per envelope) and removes a birthday-collision concern on a content-addressed
identity.
…ants Problem: the stringly-typed fields in a signed manifest — `mode`, `pathRules[].type`, `contentRules[].action.type`, `signatureType`, `logsMinLevel` were authored as ad-hoc string literals in build configs and dropped silently if misspelled: the loader's permissive normalizer would warn+fallback at runtime, but the signer happily produced the broken manifest and operators had no way to catch the typo before deploy. This change: 1. Extracts the stringly-typed values into frozen enums in `@dappfence/core/constants` (`MODE`, `PATH_RULE_TYPE`, `CONTENT_ACTION_TYPE`, `SIGNATURE_TYPE`, `LOG_LEVEL`), each with a matching JSDoc `@typedef`. These are the single source of truth for both the signer and the SW loader. 2. Adds `@dappfence/manifest-tools/validate` — a strict `assertValidManifestPayload` that throws on any unknown enum value, malformed sha256 hash, malformed URL, or type mismatch. Exposed via `./validate` subpath export so build tools can call it directly. 3. Wires `signManifest` to call the validator by default (with a `skipValidation: true` escape for tests that exercise malformed payloads on purpose).
Wire the shared constants into the SW's manifest handling so string literals can't drift, and extend signManifest to honor the declared signatureType.
Mirrors the manifest-tools build-time validator on the SW side, but in permissive mode — the SW cannot throw at runtime without bricking every DF-protected site, so unknown values warn + drop + fall back instead of hard-failing. - `resolveMode` falls back to REPORTING on unknown/missing mode (log-only is the safer default when the integrator ships a typo). - `filterKnownPathRules` / `filterKnownContentRules` drop rules whose `type` / `action.type` isn't in the enum set, warning per drop. - `logsMinLevel` validation now uses Object.values(LOG_LEVEL) instead of an inline literal array — single source of truth with the enum. - Switch the "Resolved manifest from cache" line from logger.debug to logger.local.log; this one fires on every fetch during steady state and shouldn't flow through telemetry.
a-d-j-i
force-pushed
the
feat/sw-signed-envelope
branch
from
December 4, 2026 18:39
bc759f5 to
32d21ad
Compare
The mid-test `getPendingLogs()` drain caused the second `log('a')` to
start a fresh buffer entry, so `pending[0].ts` was a *new* `Date.now()`
call separate from the captured `firstTs`. The assertion
`pending[0].ts <= firstTs` only held when both calls landed in the
same millisecond — flaky on CI under load (1 ms off).
Drop the drain, log four times back-to-back, and keep the single
`before <= ts` bound. The assertion no longer depends on sub-ms
timing. Update count to 4 to match the new call count.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Store:
Loader:
Event stream:
Also: new HEADER_REQUEST_MANIFEST constant.