feat(upload): onUploadInit callback exposes uuid + recoveryToken pre-chunk#71
Merged
Conversation
…chunk
Adds `onUploadInit?: (info: { uuid: string; recoveryToken: string }) => void`
to `UploadOptions` and `CreateEnvelopeOptions`. Fires once, synchronously
after `upload_init` resolves and before the first chunk PUT, so callers
(Outlook/Thunderbird addons) can persist `{uuid, recoveryToken}` to durable
storage and rehydrate via `resumeUpload` after a process restart.
Threaded through Sealed.upload → encryptPipeline → createUploadStream, and
forwarded through createEnvelope.
Closes #68
Refs encryption4all/postguard-tb-addon#103
Refs encryption4all/postguard-outlook-addon#82
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
rubenhensen
approved these changes
May 16, 2026
|
🎉 This PR is included in version 1.8.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Contributor
Author
There was a problem hiding this comment.
Post-merge review for the pipeline:
- Threading correct through Sealed.upload → encryptPipeline → createUploadStream, plus forwarding via createEnvelope.
- Callback fires inside the WritableStream start handler after initUpload resolves and before any chunk PUT — test asserts ordering (only the init fetch has happened when the callback runs).
- Failure path covered: when upload_init rejects, the callback is not invoked.
- JSDoc on both UploadOptions.onUploadInit and CreateEnvelopeOptions.onUploadInit correctly warns that a throw errors the stream and that it no-ops when no upload happens.
- API surface is purely additive — no breaking change.
Approving in spirit; cannot --approve own PR via the API.
This was referenced May 16, 2026
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.
Summary
onUploadInit?: (info: { uuid: string; recoveryToken: string }) => voidtoUploadOptionsandCreateEnvelopeOptions.upload_initresolves and before the first chunk PUT, so consumers (Outlook / Thunderbird addons) can persist{uuid, recoveryToken}to durable storage and rehydrate via the existingresumeUploadexport after a process restart.Sealed.upload→encryptPipeline→createUploadStream, and forwarded throughcreateEnvelope.Resolves #68. Unblocks encryption4all/postguard-tb-addon#103 and encryption4all/postguard-outlook-addon#82.
Why a callback rather than widening
UploadResult?The whole point is the restart-mid-upload case — the process can be killed, the network can drop permanently, or the chunk PUT can hang past the user closing the app. By the time
Sealed.uploadresolves it is too late; the token has to be persistable from the momentupload_initreturns. A future additive change can still widenUploadResult/EnvelopeResultto also includerecoveryTokenon the success path if useful for post-upload status queries — out of scope here.Notes
starthandler. A throw will error the stream — documented in the JSDoc. Consumers should keep the body short (achrome.storage.local.setis fine).Test plan
npm test— 91/91 pass (2 new tests intests/api.test.ts: callback fires once with the expected payload before the first PUT; callback is not called whenupload_initfails).npm run build— clean;dist/index.d.mtsnow carriesonUploadIniton bothUploadOptionsandCreateEnvelopeOptions.🤖 Generated with Claude Code