Skip to content

feat(cli): port encryption commands to native TypeScript#5409

Merged
Coly010 merged 4 commits into
developfrom
cli/port-encryption
Jun 1, 2026
Merged

feat(cli): port encryption commands to native TypeScript#5409
Coly010 merged 4 commits into
developfrom
cli/port-encryption

Conversation

@Coly010
Copy link
Copy Markdown
Contributor

@Coly010 Coly010 commented Jun 1, 2026

Promotes supabase encryption get-root-key and encryption update-root-key from 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, calls GET /v1/projects/{ref}/pgsodium, and prints the bare root key + \n to stdout (Go fmt.Println parity). JSON/stream-json modes emit a structured result.
  • update-root-key — reads the new key from stdin (masked clack prompt on a TTY, trimmed piped bytes otherwise; empty/whitespace → "", matching Go's io.Copy + strings.TrimSpace), calls PUT /v1/projects/{ref}/pgsodium, and prints Finished supabase root-key update. to stderr (Go's utils.Aqua rendered as plain text per the legacy convention).
  • encryption.errors.ts — new family-root error module with mapLegacyEncryptionHttpError({ networkVerb, statusVerb }) over the shared mapLegacyHttpError. 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.
  • Telemetry — both commands wrap with withLegacyCommandInstrumentation; --project-ref is intentionally not telemetry-safe here (no markFlagTelemetrySafe on the Go encryption group), so it is redacted. PersistentPostRun parity (linked-project cache + telemetry flush on success and failure) via the Effect.ensuring pair.
  • Status tracker — both subcommands flipped wrappedported.

Reviewer notes

  • update-root-key is the first legacy command to wire the Stdin service. Because Layer.provide does not share to siblings inside Layer.mergeAll, the command composes stdinLayer with its Tty + Stdio deps explicitly so the layer is self-contained. Verified against the bundled binary (./dist/supabase-legacy …) to rule out a Service not found panic that in-process tests miss.
  • Known divergence (documented in SIDE_EFFECTS.md): the TTY masked prompt uses clack's framing rather than Go's bare Enter a new root key: stderr write; the label text matches. Piped mode reads stdin directly without printing the prompt, mirroring Go's io.Copy branch.

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
@Coly010 Coly010 requested a review from a team as a code owner June 1, 2026 10:33
@Coly010 Coly010 self-assigned this Jun 1, 2026
Coly010 added 2 commits June 1, 2026 12:10
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.
@Coly010 Coly010 merged commit 6410a03 into develop Jun 1, 2026
8 checks passed
@Coly010 Coly010 deleted the cli/port-encryption branch June 1, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants