feat(cli): port encryption commands to native TypeScript#5409
Merged
Conversation
Promote `supabase encryption get-root-key` and `encryption update-root-key`
from Go-proxy handlers to native Phase 1+ Effect handlers, following the
domains port precedent.
- get-root-key: GET /v1/projects/{ref}/pgsodium, prints the bare key to stdout
- update-root-key: reads the new key from stdin (masked TTY prompt or piped
bytes), PUTs it, prints the finished notice to stderr
- add encryption.errors.ts with a two-verb HTTP-error mapper over the shared
mapLegacyHttpError
- consolidate the two per-subcommand SIDE_EFFECTS docs into one group-level
file and correct the API route (was /config/database/vault, now /pgsodium)
- add integration tests (100% branch coverage) and golden-path e2e tests
- flip both subcommands to `ported` in the porting-status tracker
The cli-e2e parity suite diffs the native legacy binary against the Go binary. `encryption update-root-key` diverged on the piped (non-TTY) path: - Go's `credentials.PromptMasked` writes `"Enter a new root key: "` to stderr and a trailing newline to stdout (`defer fmt.Println()`) even when stdin is piped. The port emitted neither in the piped branch. - Go dev builds print a go-errors stack trace to stderr. `normalize()` strips these (rule 12b) only when each frame starts at line start. Because the prompt is written without a trailing newline, the first frame is glued to the prompt line and survives normalization, so Go and TS stderr differed. Reproduce the prompt + trailing newline in text mode, and add normalize rule 12c to strip a go-errors frame glued to a preceding prompt. Update the integration assertions to lock the new stdout/stderr bytes.
jgoux
approved these changes
Jun 1, 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.
Promotes
supabase encryption get-root-keyandencryption update-root-keyfrom Go-proxy handlers to native Phase 1+ TypeScript Effect handlers in the legacy shell. The command is still exposed in the Go CLI (cmd/encryption.go,GroupID: groupManagementAPI), so this is an in-scope strict 1:1 port. Closes CLI-1300.What changed
get-root-key— resolves the project ref, callsGET /v1/projects/{ref}/pgsodium, and prints the bare root key +\nto stdout (Gofmt.Printlnparity). JSON/stream-json modes emit a structuredresult.update-root-key— reads the new key from stdin (masked clack prompt on a TTY, trimmed piped bytes otherwise; empty/whitespace →"", matching Go'sio.Copy+strings.TrimSpace), callsPUT /v1/projects/{ref}/pgsodium, and printsFinished supabase root-key update.to stderr (Go'sutils.Aquarendered as plain text per the legacy convention).encryption.errors.ts— new family-root error module withmapLegacyEncryptionHttpError({ networkVerb, statusVerb })over the sharedmapLegacyHttpError. Go uses different verbs for the network vs status message of each subcommand, so the factory takes both.SIDE_EFFECTS.md— consolidates the two per-subcommand docs into one group-level file and corrects the API route: the old proxy docs listed/v1/projects/{ref}/config/database/vault; the real route is/v1/projects/{ref}/pgsodium.withLegacyCommandInstrumentation;--project-refis intentionally not telemetry-safe here (nomarkFlagTelemetrySafeon the Goencryptiongroup), so it is redacted. PersistentPostRun parity (linked-project cache + telemetry flush on success and failure) via theEffect.ensuringpair.wrapped→ported.Reviewer notes
update-root-keyis the first legacy command to wire theStdinservice. BecauseLayer.providedoes not share to siblings insideLayer.mergeAll, the command composesstdinLayerwith itsTty+Stdiodeps explicitly so the layer is self-contained. Verified against the bundled binary (./dist/supabase-legacy …) to rule out aService not foundpanic that in-process tests miss.SIDE_EFFECTS.md): the TTY masked prompt uses clack's framing rather than Go's bareEnter a new root key:stderr write; the label text matches. Piped mode reads stdin directly without printing the prompt, mirroring Go'sio.Copybranch.