refactor(upload): remove runtime option validator, trust the types#87
Conversation
|
Dobby has received the request! Routing to the right specialist now... |
There was a problem hiding this comment.
Code review
Minimal, correct fix: adds onUploadInit to the upload-options whitelist and a fail-loud type-check matching the existing style. Downstream wiring (sealed.ts:131 → encryptPipeline → cryptify.ts) was already in place; only the validator was rejecting the documented option. Tests cover happy and negative paths. Tests pass.
Rule compliance
Nit: Unblocks encryption4all/postguard-website#244. won't auto-close on merge — only Closes / Fixes / Resolves are GitHub keywords. Swap if you want the website issue to close automatically when this merges (cross-repo Closes works with the org/repo#N form you already use).
`validateUploadOptions` duplicated the shape of `UploadOptions` as a hand-maintained set of allowed keys + per-key value-type checks. The type already encodes all of that — and when we recently added `onUploadInit` to `UploadOptions` we updated the type but forgot the validator, so callers passing the documented option saw `TypeError: sealed.upload(opts): unknown option "onUploadInit"`. Two declarations of "what a valid option looks like" inside one package is a drift trap. Drop the runtime check: `tsc` already gives TS callers the friendly compile-time error, and untyped JS callers will get a downstream failure that's no worse than what most JS libraries provide. No public API change; the deleted code path was purely defensive.
6ad40c5 to
f24762c
Compare
|
🎉 This PR is included in version 2.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Picks up the upload-validator removal from encryption4all/postguard-js#87 (released as 2.0.1 via the follow-up fix: commit in #88), which unblocks the staging email-preview modal flow — passing `onUploadInit` no longer throws `TypeError: unknown option "onUploadInit"`.
…er (#246) * chore: bump @e4a/pg-js to ^2.0.1 Picks up the upload-validator removal from encryption4all/postguard-js#87 (released as 2.0.1 via the follow-up fix: commit in #88), which unblocks the staging email-preview modal flow — passing `onUploadInit` no longer throws `TypeError: unknown option "onUploadInit"`. * fix(i18n): move emailPreview keys out of encryptPanel The staging email-preview modal calls \`\$_('filesharing.emailPreview.*')\`, but the keys had been added one level deeper at \`filesharing.encryptPanel.emailPreview.*\` — the modal therefore rendered the raw key paths instead of the translated strings. The modal isn't part of the encrypt panel (it pops after a successful upload), so move the block up to live as a sibling of \`encryptPanel\` under \`filesharing\` in both en.json and nl.json. Path now matches the call sites, no component changes needed. * fix(emailPreview): open in-body links in a new tab via injected <base> Clicking the "Download your files" link (or the link-text link) inside the preview iframe tried to navigate the iframe itself. The sandbox deliberately omits `allow-top-navigation`, so the navigation was blocked and the iframe blanked out — leaving the modal open with an empty body. Splice `<base target="_blank" rel="noopener">` into the rendered email's `<head>` (or prepend it if the template ever stops having one) before handing the HTML to `srcdoc`. Anchors then open in a new top-level tab, which the existing `allow-popups` / `allow-popups-to-escape-sandbox` flags already permit. No cryptify change needed — the real email never needed `target="_blank"`, only the preview surface does. * feat(emailPreview): HTML / plain-text body switcher Cryptify already returns both MIME alternatives on `/staging/preview/<uuid>` (`html` and `text` on each `RenderedEmail`), but the modal only showed the HTML branch. Add a small tab strip above the body that toggles between the two — the plain-text view renders as a monospace `<pre>` (no iframe, no `<base>` injection needed) so what you see is exactly what a text-only client would receive. Defaults to HTML since that's what most clients pick. Tab state is per-modal-open and resets between recipients via the same active-idx binding (intentional — switching recipients usually means starting fresh). * chore(dev-stack): dedupe FileInput; bump cryptify + pkg submodules - `FileInput.svelte`: drop duplicate adds in the dropzone. A file already in the list (matched by name + size + lastModified) is silently removed from the dropzone instead of getting a second entry — same behaviour as Gmail's attach UI. - `cryptify` → v0.1.27-9-g63066a1 (picks up the staging preview endpoint that the email-preview modal depends on, plus the `build.rs` Cargo.lock-driven `PG_CORE_VERSION` change). - `postguard` (pg-pkg) → pg-ffi-v0.1.2-9-gcc47b60 (accepts Yivi condiscon in IrmaAuthRequest, which pg-js 2.0 emits for the optional name disjunction). - `docker-compose.yml`: mount `cryptify/build.rs` and `cryptify/Cargo.lock` into the dev container; the bumped cryptify needs both at compile time to set the `X-PostGuard` mail header.
Summary
Test plan
Unblocks encryption4all/postguard-website#244.