rvlib-shipkit 2.26.0 → 2.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/package.json +1 -1
- package/src/agent-time/diet.ts +77 -0
- package/src/agent-time/family.ts +72 -0
- package/src/agent-time/hooks.ts +16 -7
- package/src/agent-time/limits.ts +44 -0
- package/src/agent-time/live.ts +12 -8
- package/src/agent-time/mask.ts +96 -18
- package/src/agent-time/refused.ts +45 -0
- package/src/agent-time/registry.ts +289 -0
- package/src/agent-time/render.ts +122 -21
- package/src/agent-time/report-cache.ts +57 -0
- package/src/agent-time/report.ts +314 -40
- package/src/agent-time/shape.ts +50 -3
- package/src/agent-time/store.ts +322 -101
- package/src/agent-time/timeline.ts +140 -21
- package/src/agent-time/turns.ts +18 -8
- package/src/annex/born.ts +2 -2
- package/src/annex/offload.ts +29 -17
- package/src/annex/tidy.ts +70 -10
- package/src/asks/ask-after.ts +44 -0
- package/src/asks/ask-bar-fold.ts +57 -0
- package/src/asks/ask-migrate.ts +280 -0
- package/src/asks/ask-steps-fold.ts +166 -0
- package/src/asks/ask-store.ts +586 -0
- package/src/assets/kit-config.ts +7 -3
- package/src/assets/kits/identity-kit.ts +361 -14
- package/src/assets/kits/poster-thumbnail.ts +282 -0
- package/src/check.ts +3 -1
- package/src/checks/SK003-claude-md-shape.check.ts +92 -25
- package/src/checks/SK004-gitignore-policy.check.ts +20 -9
- package/src/checks/SK013-one-way-in-policy.check.ts +18 -3
- package/src/checks/SK026-asks-autoclose.check.ts +9 -23
- package/src/checks/SK028-readme.check.ts +7 -66
- package/src/checks/SK030-cache-audit.check.ts +6 -1
- package/src/checks/SK031-trace-audit.check.ts +2 -0
- package/src/checks/SK033-global-contribution.check.ts +3 -1
- package/src/checks/SK035-public-clean.check.ts +2 -2
- package/src/checks/SK038-speaks-as.check.ts +3 -3
- package/src/checks/SK042-post-kinds.check.ts +26 -24
- package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
- package/src/checks/SK047-login-in-description.check.ts +36 -0
- package/src/checks/SK048-one-local-file.check.ts +36 -0
- package/src/checks/SK049-thread-answers-hook.check.ts +81 -0
- package/src/checks/SK050-retired-commands.check.ts +127 -0
- package/src/cli/cmd_Asks.ts +244 -27
- package/src/cli/cmd_Backup.ts +153 -10
- package/src/cli/cmd_Calls.ts +1 -0
- package/src/cli/cmd_Capacity.ts +2 -2
- package/src/cli/cmd_Commands.ts +140 -34
- package/src/cli/cmd_Contracts.ts +1 -0
- package/src/cli/cmd_CrossRepoActivity.ts +5 -4
- package/src/cli/cmd_Db.ts +253 -0
- package/src/cli/cmd_History.ts +212 -0
- package/src/cli/cmd_Home.ts +31 -3
- package/src/cli/cmd_Hq.ts +516 -0
- package/src/cli/cmd_Keys.ts +1 -0
- package/src/cli/cmd_Lanes.ts +15 -4
- package/src/cli/cmd_Machines.ts +36 -0
- package/src/cli/cmd_Media.ts +38 -6
- package/src/cli/cmd_Messages.ts +152 -1
- package/src/cli/cmd_Needs.ts +1 -0
- package/src/cli/cmd_Reflect.ts +23 -2
- package/src/cli/cmd_Review.ts +1357 -223
- package/src/cli/cmd_Secret.ts +295 -24
- package/src/cli/cmd_Social.ts +113 -28
- package/src/cli/cmd_SocialDrafts.ts +235 -0
- package/src/cli/cmd_Sound.ts +22 -1
- package/src/cli/cmd_Space.ts +324 -0
- package/src/cli/cmd_Start.ts +3 -2
- package/src/cli/cmd_ThreadHolds.ts +34 -0
- package/src/cli/cmd_ThreadKinds.ts +146 -0
- package/src/cli/cmd_ThreadReflect.ts +83 -0
- package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
- package/src/cli/cmd_Time.ts +76 -5
- package/src/cli/cmd_Tmp.ts +28 -4
- package/src/cli/cmd_Trailer.ts +14 -10
- package/src/cli/cmd_Urls.ts +56 -0
- package/src/cli/cmd_Vault.ts +583 -0
- package/src/cli/cmd_When.ts +1 -0
- package/src/cli/family-help.ts +5 -3
- package/src/cli/family-pages.ts +1 -1
- package/src/cli/kit/builtins.ts +1 -0
- package/src/cli/kit/verb.ts +6 -2
- package/src/cli/registry.ts +44 -4
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +42 -41
- package/src/collections/collection-types.ts +30 -4
- package/src/collections/md-body.ts +5 -3
- package/src/collections/pings.ts +13 -6
- package/src/collections/providers.ts +147 -61
- package/src/collections/reflections.ts +9 -4
- package/src/collections/review.ts +4 -4
- package/src/contracts/contract-manifests.ts +6 -5
- package/src/contracts/contract-types.ts +6 -4
- package/src/contracts/contracts-engine.ts +11 -0
- package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
- package/src/core/budget.ts +12 -17
- package/src/core/capacity.ts +27 -18
- package/src/core/check-runner.ts +7 -4
- package/src/core/discover-checks.ts +18 -3
- package/src/core/git.ts +31 -0
- package/src/core/house-layout.ts +17 -0
- package/src/core/layout.ts +13 -5
- package/src/core/locked-write.ts +4 -1
- package/src/core/machine-busy.ts +127 -0
- package/src/core/machine-commit.ts +6 -1
- package/src/core/machine-db.ts +370 -20
- package/src/core/machine-layout.ts +137 -0
- package/src/core/machine-read.ts +81 -0
- package/src/core/migrate-layout.ts +9 -11
- package/src/core/one-way-in-policy.ts +64 -7
- package/src/core/polling-policy.ts +27 -0
- package/src/core/retention.ts +16 -2
- package/src/core/scope.ts +107 -14
- package/src/core/slots.ts +5 -4
- package/src/drill/clean.ts +25 -1
- package/src/drill/run.ts +1 -1
- package/src/drill/seal.ts +27 -4
- package/src/home/activity-shape.ts +2 -0
- package/src/home/activity.ts +59 -3
- package/src/home/app-sign.ts +15 -4
- package/src/home/daemon-jobs.ts +161 -7
- package/src/home/database-projects.ts +111 -0
- package/src/home/database-words.ts +203 -0
- package/src/home/databases.ts +460 -0
- package/src/home/global-units.ts +6 -0
- package/src/home/gui-app/ShipkitGui.swift +122 -1
- package/src/home/gui-app.ts +6 -3
- package/src/home/home-move.ts +514 -0
- package/src/home/home-paths.ts +18 -6
- package/src/home/home-routes.ts +76 -0
- package/src/home/inbox-shape.ts +234 -91
- package/src/home/inbox.ts +26 -71
- package/src/home/machine-fold.ts +815 -0
- package/src/home/machine-host.ts +38 -5
- package/src/home/machine-repair.ts +503 -0
- package/src/home/machine-stores.ts +66 -15
- package/src/home/machine-temp.ts +547 -86
- package/src/home/other-macs.ts +2 -2
- package/src/home/resume.ts +79 -0
- package/src/home/run-daemon.ts +25 -4
- package/src/home/run-pm.ts +18 -5
- package/src/home/serve-daemon.ts +18 -3
- package/src/home/serve-web.ts +179 -10
- package/src/home/space-job.ts +115 -0
- package/src/home/space-page.ts +257 -0
- package/src/home/space-route.ts +167 -0
- package/src/home/space-words.ts +103 -0
- package/src/home/time-page-shape.ts +202 -0
- package/src/home/time-page.ts +64 -0
- package/src/home/vault-page.ts +516 -0
- package/src/home/vault-words.ts +132 -0
- package/src/hooks/leak-guard.ts +40 -13
- package/src/hooks/one-way-in-guard.ts +41 -6
- package/src/hq/cards.ts +581 -0
- package/src/hq/door-route.ts +43 -0
- package/src/hq/door.ts +163 -0
- package/src/hq/files-send.ts +347 -0
- package/src/hq/forgotten-log.ts +35 -0
- package/src/hq/history-check.ts +255 -0
- package/src/hq/history-place.ts +146 -0
- package/src/hq/history-send.ts +487 -0
- package/src/hq/hq-db.ts +102 -0
- package/src/hq/hq-local.ts +502 -0
- package/src/hq/hq-routes.ts +204 -0
- package/src/hq/hq-store.ts +603 -0
- package/src/hq/kinds/ask.ts +147 -0
- package/src/hq/kinds/card-gone.ts +83 -0
- package/src/hq/kinds/card-msg.ts +66 -0
- package/src/hq/kinds/card.ts +99 -0
- package/src/hq/kinds/index.ts +21 -0
- package/src/hq/kinds/kind.ts +126 -0
- package/src/hq/kinds/media.ts +125 -0
- package/src/hq/kinds/prompt.ts +219 -0
- package/src/hq/kinds/reflection.ts +128 -0
- package/src/hq/kinds/report.ts +55 -0
- package/src/hq/kinds/time-day.ts +236 -0
- package/src/hq/ledger.ts +473 -0
- package/src/hq/machine-key.ts +44 -0
- package/src/hq/machine-notes.ts +131 -0
- package/src/hq/outbox.ts +374 -0
- package/src/hq/replica.ts +167 -0
- package/src/hq/repo-id.ts +4 -0
- package/src/hq/report-facts.ts +117 -0
- package/src/hq/report.ts +274 -0
- package/src/hq/switch.ts +151 -0
- package/src/hq/vault-grant.ts +92 -0
- package/src/hq/vault-route.ts +112 -0
- package/src/identities/collection.ts +2 -2
- package/src/identities/identities.ts +24 -11
- package/src/identities/machine-route.ts +8 -3
- package/src/identities/steps.ts +31 -0
- package/src/ledger/db.ts +81 -27
- package/src/ledger/gate-checks.ts +6 -2
- package/src/ledger/run-log.ts +11 -3
- package/src/ledger/store.ts +26 -4
- package/src/media-store/backup/daemon.ts +73 -25
- package/src/media-store/backup/kept.ts +241 -0
- package/src/media-store/backup/keys.ts +1 -1
- package/src/media-store/backup/manifest.ts +20 -2
- package/src/media-store/backup/prune.ts +365 -0
- package/src/media-store/backup/restore.ts +14 -4
- package/src/media-store/backup/retention.ts +122 -0
- package/src/media-store/backup/run.ts +25 -19
- package/src/media-store/backup/secret.ts +6 -4
- package/src/media-store/backup/snapshot.ts +4 -2
- package/src/media-store/backup/sources.ts +83 -31
- package/src/media-store/backup/thread-copy.ts +340 -0
- package/src/media-store/copy/config.ts +76 -0
- package/src/media-store/copy/copy.ts +194 -0
- package/src/media-store/copy/lifecycle.ts +43 -0
- package/src/media-store/copy/night.ts +90 -0
- package/src/media-store/copy/proof.ts +151 -0
- package/src/media-store/copy/snapshot.ts +152 -0
- package/src/media-store/copy/store.ts +62 -0
- package/src/media-store/copy/stream.ts +176 -0
- package/src/media-store/daemon.ts +66 -16
- package/src/media-store/db.ts +24 -13
- package/src/media-store/forget.ts +141 -3
- package/src/media-store/hand.ts +4 -3
- package/src/media-store/hq-find.ts +75 -0
- package/src/media-store/hq-send.ts +277 -0
- package/src/media-store/kind.ts +2 -0
- package/src/media-store/purge.ts +21 -17
- package/src/media-store/put.ts +24 -8
- package/src/media-store/remote.ts +16 -7
- package/src/media-store/space-listing.ts +256 -0
- package/src/media-store/space.ts +46 -26
- package/src/media-store/sync.ts +5 -5
- package/src/media-store/tidy.ts +98 -0
- package/src/media-store/upload.ts +3 -3
- package/src/media-store/webp.ts +66 -0
- package/src/messages/guard.ts +49 -0
- package/src/messages/model.ts +16 -7
- package/src/messages/objects.ts +201 -0
- package/src/messages/routes.ts +14 -4
- package/src/messages/score.ts +3 -3
- package/src/messages/write.ts +285 -0
- package/src/pages/frame-client.ts +191 -4
- package/src/plan/planner.ts +28 -17
- package/src/recordings/media-kind.ts +1 -0
- package/src/recordings/model.ts +1 -1
- package/src/recordings/recorder-app/Capture.swift +9 -7
- package/src/reflect/hq-corpus.ts +56 -0
- package/src/reflect/prompt-corpus.ts +3 -1
- package/src/reflect/transcript.ts +129 -37
- package/src/reflections/reflections-queue.ts +1 -1
- package/src/release/gate-checkout.ts +2 -1
- package/src/release/git-facts.ts +3 -2
- package/src/release/machine-words.ts +67 -0
- package/src/release/public-clean.ts +11 -5
- package/src/releases/from-card.ts +1 -1
- package/src/releases/routes.ts +10 -5
- package/src/releases/store.ts +10 -1
- package/src/repo-config.ts +71 -19
- package/src/review/anim.ts +3 -3
- package/src/review/answer-kinds.ts +131 -0
- package/src/review/auto.ts +2 -2
- package/src/review/band.ts +53 -0
- package/src/review/branch-hold.ts +84 -0
- package/src/review/card-db.ts +254 -0
- package/src/review/card-rows.ts +267 -0
- package/src/review/cells.ts +360 -57
- package/src/review/close.ts +92 -0
- package/src/review/draft-card.ts +33 -0
- package/src/review/draft-model.ts +78 -0
- package/src/review/events.ts +171 -0
- package/src/review/format.ts +152 -19
- package/src/review/glyphs.ts +63 -0
- package/src/review/gone.ts +98 -0
- package/src/review/holds-sync.ts +62 -0
- package/src/review/holds.ts +85 -0
- package/src/review/house-kind-defs.ts +41 -0
- package/src/review/inbox-hook.ts +23 -10
- package/src/review/inbox-read.ts +201 -0
- package/src/review/instructions.ts +199 -0
- package/src/review/kind-apply.ts +61 -0
- package/src/review/kind-catalog.ts +96 -0
- package/src/review/kinds.ts +278 -0
- package/src/review/lane-ask.ts +109 -0
- package/src/review/marks.ts +1 -1
- package/src/review/media-kind.ts +7 -5
- package/src/review/media-read.ts +9 -7
- package/src/review/media.ts +32 -5
- package/src/review/model.ts +582 -109
- package/src/review/move.ts +491 -0
- package/src/review/need-address.ts +15 -0
- package/src/review/need-threads.ts +93 -0
- package/src/review/notes.ts +12 -20
- package/src/review/object-card.ts +48 -0
- package/src/review/object-read.ts +31 -0
- package/src/review/owner-verdict.ts +36 -0
- package/src/review/parties.ts +182 -0
- package/src/review/previews.ts +18 -20
- package/src/review/project.ts +1 -1
- package/src/review/projections.ts +235 -0
- package/src/review/referring.ts +54 -0
- package/src/review/reflection-object.ts +195 -0
- package/src/review/rev.ts +8 -0
- package/src/review/role.ts +1 -1
- package/src/review/routes.ts +194 -38
- package/src/review/secret-route.ts +80 -0
- package/src/review/snooze.ts +38 -0
- package/src/review/stage-card.ts +12 -8
- package/src/review/stage-routes.ts +1 -1
- package/src/review/store.ts +851 -124
- package/src/review/supersede.ts +116 -0
- package/src/review/take-back.ts +52 -0
- package/src/review/thread-fold.ts +64 -0
- package/src/review/threads.ts +349 -14
- package/src/review/traces.ts +218 -0
- package/src/review/trailer-auto-mock.ts +63 -0
- package/src/review/trailer-card.ts +6 -6
- package/src/review/trailer-desk.ts +41 -7
- package/src/review/trailer-media.ts +1 -0
- package/src/review/trailer-model.ts +8 -0
- package/src/review/trailer-notes.ts +1 -1
- package/src/review/trailer-routes.ts +9 -1
- package/src/review/unit.ts +77 -11
- package/src/review/verdict-items.ts +73 -0
- package/src/review/verdict-write.ts +15 -0
- package/src/review/wait.ts +85 -0
- package/src/review/watchers.ts +23 -10
- package/src/rules/untrack-generated.ts +92 -8
- package/src/scaffold/files/claude-settings-local.json +2 -0
- package/src/secrets/archive-mark.ts +52 -0
- package/src/secrets/archive.ts +83 -0
- package/src/secrets/copy.ts +14 -14
- package/src/secrets/held.ts +16 -0
- package/src/secrets/keychain-write.ts +48 -0
- package/src/secrets/keychain.ts +116 -0
- package/src/secrets/lapse-mark.ts +33 -0
- package/src/secrets/lapse.ts +60 -0
- package/src/secrets/list.ts +21 -17
- package/src/secrets/manager.ts +55 -26
- package/src/secrets/read.ts +385 -0
- package/src/secrets/tail.ts +31 -0
- package/src/secrets/who-reads.ts +49 -0
- package/src/serve/door-forward.ts +268 -0
- package/src/serve/door-names.ts +47 -0
- package/src/serve/embed.ts +1 -1
- package/src/serve/hub-app/activity-view.tsx +56 -32
- package/src/serve/hub-app/activity.css +7 -1
- package/src/serve/hub-app/asks-page.tsx +49 -0
- package/src/serve/hub-app/asks-st.ts +25 -0
- package/src/serve/hub-app/auto-text.tsx +14 -6
- package/src/serve/hub-app/benign-errors.ts +15 -1
- package/src/serve/hub-app/card-head.tsx +49 -0
- package/src/serve/hub-app/check-view.tsx +3 -2
- package/src/serve/hub-app/clock-svc.ts +1 -2
- package/src/serve/hub-app/code-copy.ts +35 -0
- package/src/serve/hub-app/col-card.tsx +72 -30
- package/src/serve/hub-app/col-list-page.tsx +125 -0
- package/src/serve/hub-app/col-list-st.ts +103 -0
- package/src/serve/hub-app/col-tables-view.tsx +17 -45
- package/src/serve/hub-app/col-tables.ts +76 -8
- package/src/serve/hub-app/cols-svc.ts +18 -39
- package/src/serve/hub-app/commands/commands-page.tsx +2 -1
- package/src/serve/hub-app/controls.css +83 -0
- package/src/serve/hub-app/database-st.ts +260 -0
- package/src/serve/hub-app/database-view.tsx +289 -0
- package/src/serve/hub-app/database.css +32 -0
- package/src/serve/hub-app/entry-bar.css +14 -0
- package/src/serve/hub-app/entry-bar.tsx +33 -0
- package/src/serve/hub-app/entry-pick.ts +31 -0
- package/src/serve/hub-app/floating.tsx +1 -0
- package/src/serve/hub-app/frames-st.ts +17 -1
- package/src/serve/hub-app/git-view.tsx +3 -2
- package/src/serve/hub-app/hash-route.ts +11 -1
- package/src/serve/hub-app/header-bar.tsx +14 -18
- package/src/serve/hub-app/home-st.ts +142 -11
- package/src/serve/hub-app/home-strip.css +6 -25
- package/src/serve/hub-app/home-strip.tsx +60 -93
- package/src/serve/hub-app/home.html +10 -0
- package/src/serve/hub-app/house-wiki-view.tsx +20 -0
- package/src/serve/hub-app/hub-app.tsx +71 -166
- package/src/serve/hub-app/hub-types.ts +5 -1
- package/src/serve/hub-app/hub.css +146 -71
- package/src/serve/hub-app/icons.tsx +32 -5
- package/src/serve/hub-app/identities-st.ts +56 -6
- package/src/serve/hub-app/identities-view.tsx +104 -61
- package/src/serve/hub-app/identities.css +17 -15
- package/src/serve/hub-app/identity-address.ts +5 -0
- package/src/serve/hub-app/inbox-st.ts +227 -49
- package/src/serve/hub-app/inbox-view.tsx +204 -120
- package/src/serve/hub-app/inbox.css +47 -47
- package/src/serve/hub-app/index.html +10 -0
- package/src/serve/hub-app/instructions.css +30 -0
- package/src/serve/hub-app/kept-cols.tsx +7 -0
- package/src/serve/hub-app/keys.ts +32 -17
- package/src/serve/hub-app/later.tsx +26 -0
- package/src/serve/hub-app/list-filter.tsx +14 -0
- package/src/serve/hub-app/list-walk.ts +72 -3
- package/src/serve/hub-app/machine-st.ts +2 -2
- package/src/serve/hub-app/machines-st.ts +251 -0
- package/src/serve/hub-app/machines-view.tsx +217 -0
- package/src/serve/hub-app/machines.css +67 -0
- package/src/serve/hub-app/markdown.css +51 -0
- package/src/serve/hub-app/md-copy.tsx +57 -0
- package/src/serve/hub-app/md.ts +25 -9
- package/src/serve/hub-app/media-view.tsx +4 -2
- package/src/serve/hub-app/messages/messages-page.tsx +81 -8
- package/src/serve/hub-app/messages/messages-st.ts +99 -3
- package/src/serve/hub-app/messages.css +14 -1
- package/src/serve/hub-app/objects.css +51 -0
- package/src/serve/hub-app/page-keys.ts +175 -0
- package/src/serve/hub-app/pages-frames.tsx +21 -3
- package/src/serve/hub-app/palette-st.ts +58 -11
- package/src/serve/hub-app/palette-view.tsx +3 -1
- package/src/serve/hub-app/pane-boundary.tsx +72 -0
- package/src/serve/hub-app/pane-errors.ts +54 -0
- package/src/serve/hub-app/plan-view.tsx +3 -2
- package/src/serve/hub-app/planned-view.tsx +3 -3
- package/src/serve/hub-app/planned.css +0 -4
- package/src/serve/hub-app/processes-view.tsx +3 -2
- package/src/serve/hub-app/project-list.css +46 -8
- package/src/serve/hub-app/project-list.tsx +125 -59
- package/src/serve/hub-app/projects-svc.ts +83 -8
- package/src/serve/hub-app/reader-chips.tsx +13 -0
- package/src/serve/hub-app/readme-view.tsx +2 -3
- package/src/serve/hub-app/readme.css +22 -6
- package/src/serve/hub-app/reflections-page.tsx +95 -0
- package/src/serve/hub-app/reflections-st.ts +17 -0
- package/src/serve/hub-app/releases/releases-page.tsx +28 -4
- package/src/serve/hub-app/releases/releases-st.ts +1 -1
- package/src/serve/hub-app/releases.css +0 -1
- package/src/serve/hub-app/repo-sections.ts +9 -5
- package/src/serve/hub-app/repo-st.ts +35 -8
- package/src/serve/hub-app/review/code-colors.ts +30 -0
- package/src/serve/hub-app/review/diff-view.tsx +75 -0
- package/src/serve/hub-app/review/dock.tsx +104 -0
- package/src/serve/hub-app/review/draft-card.tsx +163 -0
- package/src/serve/hub-app/review/group-block.tsx +209 -0
- package/src/serve/hub-app/review/instructions-view.tsx +116 -0
- package/src/serve/hub-app/review/item-verdict.tsx +38 -0
- package/src/serve/hub-app/review/kind-states.tsx +193 -0
- package/src/serve/hub-app/review/kind-view.tsx +1 -37
- package/src/serve/hub-app/review/kit.tsx +75 -29
- package/src/serve/hub-app/review/lane-bar.tsx +64 -0
- package/src/serve/hub-app/review/note-place.ts +1 -1
- package/src/serve/hub-app/review/object-card.tsx +62 -0
- package/src/serve/hub-app/review/object-panel.tsx +179 -0
- package/src/serve/hub-app/review/question-views.tsx +385 -0
- package/src/serve/hub-app/review/review-board.tsx +2 -2
- package/src/serve/hub-app/review/review-cells.tsx +148 -87
- package/src/serve/hub-app/review/review-kit.ts +27 -1
- package/src/serve/hub-app/review/review-list.tsx +160 -65
- package/src/serve/hub-app/review/review-page.tsx +12 -12
- package/src/serve/hub-app/review/review-st.ts +174 -47
- package/src/serve/hub-app/review/review-thread.tsx +214 -53
- package/src/serve/hub-app/review/review-views.tsx +494 -159
- package/src/serve/hub-app/review/thread-close.tsx +124 -0
- package/src/serve/hub-app/review/thread-control-st.ts +115 -0
- package/src/serve/hub-app/review/thread-control.tsx +74 -0
- package/src/serve/hub-app/review/thread-st.ts +288 -41
- package/src/serve/hub-app/review/trailer-card.tsx +2 -2
- package/src/serve/hub-app/review/trailer-page.tsx +37 -16
- package/src/serve/hub-app/review/trailer-st.ts +41 -7
- package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
- package/src/serve/hub-app/review.css +462 -97
- package/src/serve/hub-app/section-head.tsx +51 -0
- package/src/serve/hub-app/side-lists.ts +72 -0
- package/src/serve/hub-app/sidebar.tsx +6 -3
- package/src/serve/hub-app/site/site-part.tsx +2 -8
- package/src/serve/hub-app/site/site-st.ts +4 -4
- package/src/serve/hub-app/social/calendar.tsx +5 -11
- package/src/serve/hub-app/social/comms-page.tsx +43 -15
- package/src/serve/hub-app/social/kit.tsx +32 -13
- package/src/serve/hub-app/social/next-release.tsx +3 -5
- package/src/serve/hub-app/social/post-card.tsx +142 -49
- package/src/serve/hub-app/social/post-page.tsx +80 -0
- package/src/serve/hub-app/social/problems.tsx +5 -9
- package/src/serve/hub-app/social/serial-writes.ts +13 -0
- package/src/serve/hub-app/social/social-model.ts +24 -5
- package/src/serve/hub-app/social/social-page.tsx +95 -36
- package/src/serve/hub-app/social/social-st.ts +162 -41
- package/src/serve/hub-app/social/stage-popup.tsx +1 -1
- package/src/serve/hub-app/social/stage-st.ts +1 -1
- package/src/serve/hub-app/social/step-layout.ts +1 -1
- package/src/serve/hub-app/social.css +10 -17
- package/src/serve/hub-app/space-st.ts +209 -0
- package/src/serve/hub-app/space-view.tsx +196 -0
- package/src/serve/hub-app/space.css +27 -0
- package/src/serve/hub-app/stores/stores-page.tsx +97 -25
- package/src/serve/hub-app/stores/stores-st.ts +44 -19
- package/src/serve/hub-app/stores.css +6 -1
- package/src/serve/hub-app/theme-st.ts +22 -9
- package/src/serve/hub-app/thread-row.tsx +101 -0
- package/src/serve/hub-app/time-ago.tsx +3 -2
- package/src/serve/hub-app/time-charts.tsx +291 -0
- package/src/serve/hub-app/time-pages.tsx +749 -0
- package/src/serve/hub-app/time-st.ts +162 -0
- package/src/serve/hub-app/time-view.tsx +77 -0
- package/src/serve/hub-app/time.css +135 -0
- package/src/serve/hub-app/tree-build.ts +52 -42
- package/src/serve/hub-app/tree-row.tsx +3 -11
- package/src/serve/hub-app/tree-svc.ts +18 -9
- package/src/serve/hub-app/urls-svc.ts +154 -0
- package/src/serve/hub-app/urls-view.tsx +117 -0
- package/src/serve/hub-app/urls.css +30 -0
- package/src/serve/hub-app/vault-st.ts +127 -0
- package/src/serve/hub-app/vault-view.tsx +154 -0
- package/src/serve/hub-app/vault.css +38 -0
- package/src/serve/hub-app/veille/veille-page.tsx +2 -11
- package/src/serve/hub-app/veille/veille-st.ts +12 -10
- package/src/serve/hub-app/veille.css +0 -1
- package/src/serve/hub-app/waiting-svc.ts +29 -0
- package/src/serve/hub-app/when-view.tsx +6 -3
- package/src/serve/hub-app/wiki-st.ts +30 -4
- package/src/serve/hub-app/wikis-view.tsx +6 -5
- package/src/serve/hub-runtime.ts +35 -8
- package/src/serve/project-gutter-route.ts +42 -19
- package/src/serve/project-gutter.ts +16 -50
- package/src/serve/same-origin.ts +13 -0
- package/src/serve/secret-gate.ts +21 -0
- package/src/serve/serve-hub.ts +38 -20
- package/src/serve/tailnet-caller.ts +117 -0
- package/src/shipkit-files.ts +16 -2
- package/src/shipkit.ts +3 -3
- package/src/shot/shooter.ts +616 -420
- package/src/shot/shot-ask.ts +246 -155
- package/src/site/desk.ts +4 -4
- package/src/smoke/run-smoke.ts +6 -6
- package/src/social/brands.ts +4 -0
- package/src/social/card-drafts.ts +11 -19
- package/src/social/cover.ts +202 -0
- package/src/social/desk-index.ts +34 -13
- package/src/social/discord-layout.ts +37 -13
- package/src/social/drafts.ts +7 -4
- package/src/social/import-drafts.ts +244 -0
- package/src/social/kind-pages.ts +3 -3
- package/src/social/kinds.ts +1 -1
- package/src/social/load.ts +111 -65
- package/src/social/media-kind.ts +68 -160
- package/src/social/media-of.ts +5 -4
- package/src/social/open.ts +3 -2
- package/src/social/post-object.ts +120 -0
- package/src/social/post-sources.ts +136 -0
- package/src/social/post-text.ts +103 -0
- package/src/social/posts.ts +378 -0
- package/src/social/presence.ts +7 -5
- package/src/social/publish/discord.ts +5 -2
- package/src/social/publish/index.ts +17 -5
- package/src/social/publish/secret.ts +4 -4
- package/src/social/release-stage.ts +79 -63
- package/src/social/routes.ts +89 -24
- package/src/social/stage.ts +43 -58
- package/src/social/stats.ts +12 -9
- package/src/social/strip.ts +4 -1
- package/src/social/text.ts +4 -3
- package/src/social/thumbnail.ts +347 -0
- package/src/social/tracker.ts +1 -1
- package/src/social/writes.ts +12 -29
- package/src/stores/collection.ts +15 -11
- package/src/stores/desk.ts +246 -47
- package/src/stores/model.ts +72 -6
- package/src/stores/routes.ts +37 -12
- package/src/stores/unit.ts +16 -10
- package/src/suite/judge-suites.ts +41 -11
- package/src/suite/select.ts +45 -3
- package/src/suite/suite-cli.ts +16 -10
- package/src/trailer/bed.ts +1 -1
- package/src/trailer/build.ts +134 -21
- package/src/trailer/ffmpeg.ts +7 -0
- package/src/trailer/fonts.ts +3 -2
- package/src/trailer/grammar.ts +201 -2
- package/src/trailer/graph.ts +42 -5
- package/src/trailer/look.ts +21 -0
- package/src/trailer/mock.ts +154 -0
- package/src/trailer/passage.ts +65 -26
- package/src/trailer/score/heard.ts +89 -0
- package/src/trailer/score/sound.ts +14 -8
- package/src/trailer/sound/eleven.ts +33 -3
- package/src/trailer/sound/run.ts +16 -6
- package/src/trailer/stitch.ts +26 -5
- package/src/trailer/titles.ts +82 -19
- package/src/trailer/versions.ts +1 -3
- package/src/trailer/vertical.ts +3 -1
- package/src/urls/frame.ts +195 -0
- package/src/urls/routes.ts +43 -0
- package/src/urls/rows.ts +171 -0
- package/src/urls/unit.ts +73 -0
- package/src/vault/house-keys.ts +42 -0
- package/src/vault/layout.ts +50 -0
- package/src/vault/policy.ts +165 -0
- package/src/vault/vault-audit.ts +276 -0
- package/src/vault/vault-client.ts +40 -0
- package/src/vault/vault-config.ts +159 -0
- package/src/vault/vault-destroy.ts +78 -0
- package/src/vault/vault-handover.ts +305 -0
- package/src/vault/vault-http.ts +360 -0
- package/src/vault/vault-import.ts +213 -0
- package/src/vault/vault-init.ts +328 -0
- package/src/vault/vault-minter.ts +271 -0
- package/src/vault/vault-restore.ts +333 -0
- package/src/vault/vault-serve.ts +342 -0
- package/src/vault/vault-snapshot.ts +281 -0
- package/src/veille/asks.ts +1 -1
- package/src/veille/desk.ts +2 -2
- package/src/veille/identity.ts +2 -2
- package/src/wiki/graph-pages.ts +13 -1
- package/src/wiki/scan-md.ts +1 -1
- package/src/asks/asks-queue.ts +0 -266
- package/src/social/migrate.ts +0 -123
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// the one way the vault's keys leave a process: the owner's clipboard, as one note for his password manager, held
|
|
2
|
+
// until he proves his copy. The guard owns SIGINT, SIGHUP and SIGTERM while a key exists: whatever ends the run,
|
|
3
|
+
// the clipboard does not keep the note, the echo comes back, no root token outlives it and the bao it started stops
|
|
4
|
+
import { SEAL_SERVICE } from './vault-config.ts'
|
|
5
|
+
import type { VaultApi } from './vault-http.ts'
|
|
6
|
+
import type { Bao } from './vault-serve.ts'
|
|
7
|
+
|
|
8
|
+
export type Clipboard = { write(text: string): void; read(): string }
|
|
9
|
+
|
|
10
|
+
/** a pasteboard through AppKit, the text on stdin. A write is for this Mac only (no Universal Clipboard to his
|
|
11
|
+
* other devices) and marked concealed and transient (nspasteboard.org), what clipboard managers read as « keep
|
|
12
|
+
* no copy » */
|
|
13
|
+
const PASTEBOARD_JXA = `ObjC.import('AppKit')
|
|
14
|
+
function run(argv) {
|
|
15
|
+
const pb = argv[1] === 'general' ? $.NSPasteboard.generalPasteboard : $.NSPasteboard.pasteboardWithName(argv[1])
|
|
16
|
+
if (argv[0] === 'read') {
|
|
17
|
+
const s = pb.stringForType($.NSPasteboardTypeString)
|
|
18
|
+
return JSON.stringify({ text: s.isNil() ? '' : s.js, types: ObjC.deepUnwrap(pb.types) || [] })
|
|
19
|
+
}
|
|
20
|
+
if (argv[0] === 'release') { pb.releaseGlobally; return 'released' }
|
|
21
|
+
const text = $.NSString.alloc.initWithDataEncoding($.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile, $.NSUTF8StringEncoding)
|
|
22
|
+
pb.prepareForNewContentsWithOptions($.NSPasteboardContentsCurrentHostOnly)
|
|
23
|
+
if (text.js === '') return 'cleared'
|
|
24
|
+
pb.declareTypesOwner($([$.NSPasteboardTypeString, 'org.nspasteboard.ConcealedType', 'org.nspasteboard.TransientType']), $())
|
|
25
|
+
pb.setStringForType(text, $.NSPasteboardTypeString)
|
|
26
|
+
pb.setStringForType($(''), 'org.nspasteboard.ConcealedType')
|
|
27
|
+
pb.setStringForType($(''), 'org.nspasteboard.TransientType')
|
|
28
|
+
return 'written'
|
|
29
|
+
}`
|
|
30
|
+
|
|
31
|
+
const jxa = (args: string[], stdin?: string): string => {
|
|
32
|
+
const p = Bun.spawnSync(['osascript', '-l', 'JavaScript', '-e', PASTEBOARD_JXA, ...args], { stdin: stdin == null ? 'ignore' : new TextEncoder().encode(stdin), stdout: 'pipe', stderr: 'pipe' })
|
|
33
|
+
if (p.exitCode !== 0) throw new Error(`the pasteboard refused (osascript exit ${p.exitCode})`)
|
|
34
|
+
return p.stdout.toString().trim()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** the Mac's clipboard, or a private pasteboard of that name (what a test uses: his clipboard is never touched) */
|
|
38
|
+
export const pasteboard = (board = 'general'): Clipboard & { types: () => string[]; release: () => void } => ({
|
|
39
|
+
write: (text) => void jxa(['write', board], text),
|
|
40
|
+
read: () => (JSON.parse(jxa(['read', board])) as { text: string }).text,
|
|
41
|
+
types: () => (JSON.parse(jxa(['read', board])) as { types: string[] }).types,
|
|
42
|
+
release: () => void jxa(['release', board]),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
export const macClipboard: Clipboard = pasteboard()
|
|
46
|
+
|
|
47
|
+
/** a round trip on a private pasteboard, before any key exists: why the pasteboard cannot hand a note, or null */
|
|
48
|
+
export function provePasteboard(): string | null {
|
|
49
|
+
const board = pasteboard(`shipkit-vault-proof-${process.pid}`)
|
|
50
|
+
const probe = `proof ${crypto.randomUUID()}`
|
|
51
|
+
try {
|
|
52
|
+
board.write(probe)
|
|
53
|
+
return board.read() === probe ? null : 'the pasteboard did not give back what was written to it'
|
|
54
|
+
} catch (e) {
|
|
55
|
+
return (e as Error).message
|
|
56
|
+
} finally {
|
|
57
|
+
try {
|
|
58
|
+
board.release()
|
|
59
|
+
} catch {
|
|
60
|
+
// a board that never opened has nothing to release
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const CLEAR_AFTER_MS = 90_000
|
|
66
|
+
/** a second ctrl c within this long drops the note */
|
|
67
|
+
export const SECOND_INT_MS = 5_000
|
|
68
|
+
|
|
69
|
+
const stamp = (d: Date): string => d.toISOString().slice(0, 16).replace('T', ' ')
|
|
70
|
+
|
|
71
|
+
/** the note for a secure note of his password manager: its title on the first line */
|
|
72
|
+
export function initNote(o: { machine: string; at: Date; sealKey: string; recoveryKey: string }): string {
|
|
73
|
+
return [
|
|
74
|
+
`shipkit vault (${o.machine})`,
|
|
75
|
+
`initialised ${stamp(o.at)} UTC on ${o.machine}`,
|
|
76
|
+
`seal key: ${o.sealKey}`,
|
|
77
|
+
`recovery key: ${o.recoveryKey}`,
|
|
78
|
+
`The seal key opens the vault and every snapshot of it; that Mac's login keychain holds it too (${SEAL_SERVICE}), and sk vault key --copy copies it again. The recovery key is kept nowhere else: after a dead disk, sk vault restore asks for it to make a new root token in the restored vault.`,
|
|
79
|
+
'',
|
|
80
|
+
].join('\n')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function sealNote(o: { machine: string; at: Date; sealKey: string }): string {
|
|
84
|
+
return [`shipkit vault (${o.machine}): seal key`, `copied ${stamp(o.at)} UTC from the login keychain of ${o.machine} (${SEAL_SERVICE})`, `seal key: ${o.sealKey}`, 'It opens the vault and every snapshot of it. The recovery key is in the note made at sk vault init.', ''].join('\n')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type Signals = { on(sig: NodeJS.Signals, f: () => void): void; off(sig: NodeJS.Signals, f: () => void): void; exit(code: number): void }
|
|
88
|
+
export const processSignals: Signals = { on: (s, f) => void process.on(s, f), off: (s, f) => void process.off(s, f), exit: (c) => process.exit(c) }
|
|
89
|
+
|
|
90
|
+
/** the terminal's echo, off while he types the 4 characters: a paste there would print both keys in the scrollback */
|
|
91
|
+
export type Terminal = { echo(on: boolean): void }
|
|
92
|
+
export const ttyTerminal: Terminal = { echo: (on) => void Bun.spawnSync(['stty', on ? 'echo' : '-echo'], { stdin: 'inherit', stdout: 'ignore', stderr: 'ignore' }) }
|
|
93
|
+
const noTerminal: Terminal = { echo: () => {} }
|
|
94
|
+
|
|
95
|
+
const SIGNALS: NodeJS.Signals[] = ['SIGINT', 'SIGHUP', 'SIGTERM']
|
|
96
|
+
const EXIT_OF: Record<string, number> = { SIGINT: 130, SIGHUP: 129, SIGTERM: 143 }
|
|
97
|
+
|
|
98
|
+
/** what a run must undo whatever ends it, held from before the first key to the end */
|
|
99
|
+
export class KeyGuard {
|
|
100
|
+
/** the bao this run started, stopped on the way out */
|
|
101
|
+
bao: Bao | null = null
|
|
102
|
+
/** the root token while it lives: revoked on the way out */
|
|
103
|
+
root: VaultApi | null = null
|
|
104
|
+
/** undo what was made before the vault held anything */
|
|
105
|
+
rollback: (() => void) | null = null
|
|
106
|
+
/** the text on the clipboard while it is the note */
|
|
107
|
+
note: string | null = null
|
|
108
|
+
/** while he is asked: a first ctrl c asks again */
|
|
109
|
+
prompting = false
|
|
110
|
+
/** set once a signal ended the run: the hand over stops asking */
|
|
111
|
+
ended = false
|
|
112
|
+
private lastInt = 0
|
|
113
|
+
private readonly onSig = new Map<NodeJS.Signals, () => void>()
|
|
114
|
+
|
|
115
|
+
constructor(
|
|
116
|
+
private readonly d: { signals?: Signals; terminal?: Terminal; clipboard: Clipboard; say: (l: string) => void },
|
|
117
|
+
) {}
|
|
118
|
+
|
|
119
|
+
private get signals(): Signals {
|
|
120
|
+
return this.d.signals ?? processSignals
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
install(): this {
|
|
124
|
+
for (const s of SIGNALS) {
|
|
125
|
+
const f = (): void => this.signal(s)
|
|
126
|
+
this.onSig.set(s, f)
|
|
127
|
+
this.signals.on(s, f)
|
|
128
|
+
}
|
|
129
|
+
return this
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
uninstall(): void {
|
|
133
|
+
for (const [s, f] of this.onSig) this.signals.off(s, f)
|
|
134
|
+
this.onSig.clear()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
echo(on: boolean): void {
|
|
138
|
+
try {
|
|
139
|
+
;(this.d.terminal ?? noTerminal).echo(on)
|
|
140
|
+
} catch {
|
|
141
|
+
// a terminal that is gone has no echo to set
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** the note off the clipboard, if it still holds it. Never throws */
|
|
146
|
+
clearNote(): boolean {
|
|
147
|
+
if (this.note == null) return false
|
|
148
|
+
try {
|
|
149
|
+
if (this.d.clipboard.read() !== this.note) return false
|
|
150
|
+
this.d.clipboard.write('')
|
|
151
|
+
return true
|
|
152
|
+
} catch {
|
|
153
|
+
return false
|
|
154
|
+
} finally {
|
|
155
|
+
this.note = null
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async revokeRoot(): Promise<boolean> {
|
|
160
|
+
const root = this.root
|
|
161
|
+
if (root == null) return true
|
|
162
|
+
try {
|
|
163
|
+
await Promise.race([root.revokeSelf(), Bun.sleep(10_000).then(() => Promise.reject(new Error('no answer in 10 s')))])
|
|
164
|
+
} catch {
|
|
165
|
+
// proved below
|
|
166
|
+
}
|
|
167
|
+
const dead = await root.lookupSelf().then(
|
|
168
|
+
() => false,
|
|
169
|
+
() => true,
|
|
170
|
+
)
|
|
171
|
+
if (dead) this.root = null
|
|
172
|
+
return dead
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** everything undone, in the order that keeps it safe: the echo, the clipboard, the root token while bao still
|
|
176
|
+
* answers, bao, then what was made before the vault held anything */
|
|
177
|
+
async cleanup(): Promise<void> {
|
|
178
|
+
this.echo(true)
|
|
179
|
+
this.clearNote()
|
|
180
|
+
if (!(await this.revokeRoot())) this.d.say('FAIL: the root token still answers: it is held by no one once this process ends')
|
|
181
|
+
await this.bao?.stop()
|
|
182
|
+
this.bao = null
|
|
183
|
+
this.rollback?.()
|
|
184
|
+
this.rollback = null
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private signal(s: NodeJS.Signals): void {
|
|
188
|
+
if (s === 'SIGINT' && this.prompting && Date.now() - this.lastInt > SECOND_INT_MS) {
|
|
189
|
+
this.lastInt = Date.now()
|
|
190
|
+
this.d.say(`ctrl c again within ${SECOND_INT_MS / 1000} s drops the recovery key for good. Type c to copy the note again, or the last 4 characters of the seal key once it is saved`)
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
if (this.ended) return
|
|
194
|
+
this.ended = true
|
|
195
|
+
const proved = !this.prompting
|
|
196
|
+
void this.cleanup().then(() => {
|
|
197
|
+
this.d.say(proved ? `stopped (${s}): undone` : `stopped (${s}) before your copy was proved: the clipboard is cleared, and the recovery key is gone if your password manager does not hold it. The seal key: sk vault key --copy`)
|
|
198
|
+
this.signals.exit(EXIT_OF[s] ?? 1)
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export type HandOverDeps = {
|
|
204
|
+
clipboard: Clipboard
|
|
205
|
+
ask: (question: string) => Promise<string>
|
|
206
|
+
say: (line: string) => void
|
|
207
|
+
clearAfterMs?: number
|
|
208
|
+
signals?: Signals
|
|
209
|
+
terminal?: Terminal
|
|
210
|
+
/** the run's guard, when one holds more than the note */
|
|
211
|
+
guard?: KeyGuard
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** the note in the clipboard until he proves his copy (the last 4 characters of the seal key, typed with no echo),
|
|
215
|
+
* cleared once he did or after `clearAfterMs`. `c` copies it again, `show` prints it on the screen (his explicit
|
|
216
|
+
* choice, the one way to the screen), `give up` drops it. Never throws: a clipboard that refuses keeps the note in
|
|
217
|
+
* memory and asks again. True once his copy is proved */
|
|
218
|
+
export async function handOver(text: string, sealKey: string, d: HandOverDeps): Promise<boolean> {
|
|
219
|
+
const after = d.clearAfterMs ?? CLEAR_AFTER_MS
|
|
220
|
+
const g = d.guard ?? new KeyGuard(d).install()
|
|
221
|
+
let timer: ReturnType<typeof setTimeout> | null = null
|
|
222
|
+
const stopTimer = (): void => {
|
|
223
|
+
if (timer != null) clearTimeout(timer)
|
|
224
|
+
timer = null
|
|
225
|
+
}
|
|
226
|
+
// an invented end of a key, never the real one's
|
|
227
|
+
const example = sealKey.endsWith('9f3c') ? '4d1a' : '9f3c'
|
|
228
|
+
let copies = 0
|
|
229
|
+
const copy = (): void => {
|
|
230
|
+
stopTimer()
|
|
231
|
+
try {
|
|
232
|
+
d.clipboard.write(text)
|
|
233
|
+
} catch (e) {
|
|
234
|
+
d.say(`the clipboard refused the note (${(e as Error).message}): type c to try again, or show to print it on this screen (it then stays in the scrollback: clear it with cmd K once it is saved)`)
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
g.note = text
|
|
238
|
+
timer = setTimeout(() => {
|
|
239
|
+
if (g.clearNote()) d.say('the clipboard is cleared: type c to copy the note again')
|
|
240
|
+
}, after)
|
|
241
|
+
const clears = `the clipboard clears in ${Math.round(after / 1000)} s (c copies the note again)`
|
|
242
|
+
if (copies++ > 0) {
|
|
243
|
+
d.say(`copied again. It still waits for the 4 characters: paste the note in your password manager, then type here the last 4 characters of its « seal key: » line. ${clears}`)
|
|
244
|
+
return
|
|
245
|
+
}
|
|
246
|
+
d.say('the two keys of the vault are in your clipboard, as one note. Three steps:')
|
|
247
|
+
d.say(' 1. in your password manager: a new secure note, paste (cmd V), save')
|
|
248
|
+
d.say(' 2. in that saved note, find the line that starts with « seal key: »')
|
|
249
|
+
d.say(` 3. back here, type the LAST 4 CHARACTERS of that line, then Enter: for example, for « seal key: 71c0…e4b2${example} » you type ${example}. What you type is not shown`)
|
|
250
|
+
d.say(`the note goes in your password manager and nowhere else: never in a chat, a message or a file. ${clears}`)
|
|
251
|
+
}
|
|
252
|
+
g.prompting = true
|
|
253
|
+
copy()
|
|
254
|
+
try {
|
|
255
|
+
while (!g.ended) {
|
|
256
|
+
g.echo(false)
|
|
257
|
+
let a: string
|
|
258
|
+
try {
|
|
259
|
+
a = (await d.ask('the last 4 characters of the « seal key: » line (or c, show, give up): ')).trim()
|
|
260
|
+
} catch (e) {
|
|
261
|
+
d.say(`FAIL: the terminal gave no answer (${(e as Error).message})`)
|
|
262
|
+
return false
|
|
263
|
+
} finally {
|
|
264
|
+
g.echo(true)
|
|
265
|
+
}
|
|
266
|
+
if (g.ended) return false
|
|
267
|
+
if (a === 'c') copy()
|
|
268
|
+
else if (a === 'show') d.say(text)
|
|
269
|
+
else if (a === 'give up') {
|
|
270
|
+
d.say('the note is dropped: the recovery key is gone if your password manager does not hold it. The seal key: sk vault key --copy')
|
|
271
|
+
return false
|
|
272
|
+
} else if (a.length !== 4) d.say('that answer is not 4 characters, and nothing of it was shown: type the last 4 characters of the seal key')
|
|
273
|
+
else if (sealKey.endsWith(a.toLowerCase())) return true
|
|
274
|
+
else d.say('that is not the end of the seal key: check the note in your password manager, or type c to copy it again')
|
|
275
|
+
}
|
|
276
|
+
return false
|
|
277
|
+
} finally {
|
|
278
|
+
stopTimer()
|
|
279
|
+
g.prompting = false
|
|
280
|
+
if (g.clearNote()) d.say('the clipboard is cleared')
|
|
281
|
+
if (d.guard == null) g.uninstall()
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** `sk vault key --copy`'s way out: the seal note in the clipboard, cleared after `clearAfterMs` or on any signal */
|
|
286
|
+
export async function holdSealNote(text: string, d: { clipboard: Clipboard; say: (l: string) => void; clearAfterMs?: number; signals?: Signals; sleep?: (ms: number) => Promise<void> }): Promise<number> {
|
|
287
|
+
const after = d.clearAfterMs ?? CLEAR_AFTER_MS
|
|
288
|
+
const g = new KeyGuard(d).install()
|
|
289
|
+
try {
|
|
290
|
+
try {
|
|
291
|
+
d.clipboard.write(text)
|
|
292
|
+
} catch (e) {
|
|
293
|
+
d.say(`FAIL: the clipboard refused the note (${(e as Error).message})`)
|
|
294
|
+
return 1
|
|
295
|
+
}
|
|
296
|
+
g.note = text
|
|
297
|
+
d.say(`the seal key is in your clipboard: paste it in your password manager. It clears in ${Math.round(after / 1000)} s (ctrl c clears it now)`)
|
|
298
|
+
await (d.sleep ?? Bun.sleep)(after)
|
|
299
|
+
return 0
|
|
300
|
+
} finally {
|
|
301
|
+
g.clearNote()
|
|
302
|
+
g.uninstall()
|
|
303
|
+
d.say('the clipboard is cleared')
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// the vault's http api on loopback, the few calls shipkit makes. An error carries the status and bao's own words,
|
|
2
|
+
// never a request body: a body may hold a token or a value
|
|
3
|
+
import { refuseRealVault } from './vault-config.ts'
|
|
4
|
+
export type VaultHealth = { code: number; initialized: boolean; sealed: boolean; version: string }
|
|
5
|
+
|
|
6
|
+
/** GET /v1/sys/health: 200 unsealed, 503 sealed, 501 not initialised. Null when nothing answers */
|
|
7
|
+
/** `headers`: what a vault behind the hq's vault route also wants (the node's hq token) */
|
|
8
|
+
export async function vaultHealth(url: string, timeoutMs = 1_000, headers: Record<string, string> = {}): Promise<VaultHealth | null> {
|
|
9
|
+
refuseRealVault({ url })
|
|
10
|
+
try {
|
|
11
|
+
const r = await fetch(`${url}/v1/sys/health`, { headers, signal: AbortSignal.timeout(timeoutMs) })
|
|
12
|
+
const j = (await r.json().catch(() => ({}))) as { initialized?: boolean; sealed?: boolean; version?: string }
|
|
13
|
+
return { code: r.status, initialized: j.initialized === true, sealed: j.sealed !== false, version: j.version ?? '' }
|
|
14
|
+
} catch {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** poll the health until `ok` holds, the last answer either way */
|
|
20
|
+
export async function waitHealth(url: string, ok: (h: VaultHealth | null) => boolean, o: { ms?: number; stepMs?: number; gone?: () => boolean } = {}): Promise<VaultHealth | null> {
|
|
21
|
+
const end = Date.now() + (o.ms ?? 15_000)
|
|
22
|
+
let h = await vaultHealth(url)
|
|
23
|
+
while (!ok(h) && Date.now() < end && o.gone?.() !== true) {
|
|
24
|
+
await Bun.sleep(o.stepMs ?? 150)
|
|
25
|
+
h = await vaultHealth(url)
|
|
26
|
+
}
|
|
27
|
+
return h
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class VaultError extends Error {
|
|
31
|
+
constructor(
|
|
32
|
+
readonly status: number,
|
|
33
|
+
what: string,
|
|
34
|
+
) {
|
|
35
|
+
super(what)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type Json = Record<string, unknown>
|
|
40
|
+
|
|
41
|
+
export class VaultApi {
|
|
42
|
+
constructor(
|
|
43
|
+
readonly url: string,
|
|
44
|
+
private token: string | null = null,
|
|
45
|
+
/** how long one call may take; a read on a reader's path passes a short one */
|
|
46
|
+
private readonly timeoutMs: number = 30_000,
|
|
47
|
+
/** sent with every call: the hq token of a node that reads the master through the vault route */
|
|
48
|
+
private readonly headers: Record<string, string> = {},
|
|
49
|
+
) {}
|
|
50
|
+
|
|
51
|
+
private async call(method: string, path: string, body?: unknown, raw?: Uint8Array<ArrayBuffer>): Promise<{ status: number; json: Json; bytes: Uint8Array<ArrayBuffer> }> {
|
|
52
|
+
refuseRealVault({ url: this.url })
|
|
53
|
+
const headers: Record<string, string> = { ...this.headers }
|
|
54
|
+
if (this.token != null) headers['X-Vault-Token'] = this.token
|
|
55
|
+
if (body !== undefined) headers['content-type'] = 'application/json'
|
|
56
|
+
const r = await fetch(`${this.url}/v1/${path}`, { method, headers, body: raw ?? (body === undefined ? undefined : JSON.stringify(body)), signal: AbortSignal.timeout(this.timeoutMs) })
|
|
57
|
+
const bytes: Uint8Array<ArrayBuffer> = new Uint8Array(await r.arrayBuffer())
|
|
58
|
+
let json: Json = {}
|
|
59
|
+
if ((r.headers.get('content-type') ?? '').includes('json') && bytes.length > 0) {
|
|
60
|
+
try {
|
|
61
|
+
json = JSON.parse(new TextDecoder().decode(bytes)) as Json
|
|
62
|
+
} catch {
|
|
63
|
+
json = {}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (r.status >= 400) {
|
|
67
|
+
const errs = Array.isArray(json['errors']) ? (json['errors'] as unknown[]).map(String).join('; ') : ''
|
|
68
|
+
throw new VaultError(r.status, `${method} /v1/${path}: ${r.status}${errs === '' ? '' : ` (${errs})`}`)
|
|
69
|
+
}
|
|
70
|
+
return { status: r.status, json, bytes }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** the one init: one recovery share, threshold one. The root token and the recovery key, held by the caller only */
|
|
74
|
+
async init(): Promise<{ rootToken: string; recoveryKey: string }> {
|
|
75
|
+
const { json } = await this.call('PUT', 'sys/init', { recovery_shares: 1, recovery_threshold: 1 })
|
|
76
|
+
const rootToken = json['root_token']
|
|
77
|
+
const recovery = json['recovery_keys_base64']
|
|
78
|
+
if (typeof rootToken !== 'string' || !Array.isArray(recovery) || typeof recovery[0] !== 'string') throw new VaultError(0, 'sys/init answered without a root token or a recovery key')
|
|
79
|
+
return { rootToken, recoveryKey: recovery[0] }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** a root token from the recovery key (one share): an attempt, the key, the encoded token decoded with the one
|
|
83
|
+
* time password the attempt gave. Any attempt left over is cancelled first. The token is the caller's alone */
|
|
84
|
+
/** a root token from the recovery key in a vault just restored: a restore seals it again while it swaps its keyring,
|
|
85
|
+
* and its node answers 500 until it is active again, so each such answer is tried again until `ms`. A 400 (a key
|
|
86
|
+
* that is not this vault's) ends at once */
|
|
87
|
+
async rootAfterRestore(recoveryKey: string, ms = 60_000): Promise<string> {
|
|
88
|
+
const end = Date.now() + ms
|
|
89
|
+
for (;;) {
|
|
90
|
+
await waitHealth(this.url, (h) => h?.code === 200, { ms: Math.max(1_000, end - Date.now()) })
|
|
91
|
+
try {
|
|
92
|
+
const token = await this.rootFromRecovery(recoveryKey)
|
|
93
|
+
await new VaultApi(this.url, token).lookupSelf()
|
|
94
|
+
return token
|
|
95
|
+
} catch (e) {
|
|
96
|
+
if (/recovery key|\b400\b/.test((e as Error).message) || Date.now() > end) throw e
|
|
97
|
+
await Bun.sleep(500)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async rootFromRecovery(recoveryKey: string): Promise<string> {
|
|
103
|
+
await this.call('DELETE', 'sys/generate-root/attempt').catch(() => undefined)
|
|
104
|
+
const { json: a } = await this.call('POST', 'sys/generate-root/attempt', {})
|
|
105
|
+
const nonce = a['nonce']
|
|
106
|
+
const otp = a['otp']
|
|
107
|
+
if (typeof nonce !== 'string' || typeof otp !== 'string' || otp === '') throw new VaultError(0, 'sys/generate-root/attempt gave no nonce or one time password')
|
|
108
|
+
const { json: u } = await this.call('POST', 'sys/generate-root/update', { key: recoveryKey, nonce })
|
|
109
|
+
const encoded = u['encoded_token'] ?? u['encoded_root_token']
|
|
110
|
+
if (u['complete'] !== true || typeof encoded !== 'string') throw new VaultError(0, 'the recovery key did not complete the root token: it is not this vault\'s')
|
|
111
|
+
const enc = Buffer.from(encoded, 'base64')
|
|
112
|
+
const pad = Buffer.from(otp, 'utf8')
|
|
113
|
+
if (enc.length !== pad.length) throw new VaultError(0, 'the encoded root token and its one time password differ in length')
|
|
114
|
+
return Buffer.from(enc.map((b, i) => b ^ pad[i]!)).toString('utf8')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
mount(path: string, type: string, options?: Record<string, string>): Promise<unknown> {
|
|
118
|
+
return this.call('POST', `sys/mounts/${path}`, { type, ...(options == null ? {} : { options }) })
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async mounts(): Promise<string[]> {
|
|
122
|
+
const { json } = await this.call('GET', 'sys/mounts')
|
|
123
|
+
const data = (json['data'] ?? json) as Json
|
|
124
|
+
return Object.keys(data).filter((k) => k.endsWith('/'))
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
writePolicy(name: string, hcl: string): Promise<unknown> {
|
|
128
|
+
return this.call('PUT', `sys/policies/acl/${name}`, { policy: hcl })
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
writeTokenRole(name: string, role: Json): Promise<unknown> {
|
|
132
|
+
return this.call('POST', `auth/token/roles/${name}`, role)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** a token, created as an orphan from `role` when one is named, else from the caller's own token. `entityAlias`
|
|
136
|
+
* ties it to the entity of that alias (made at the first mint), whose metadata a templated policy reads */
|
|
137
|
+
async createToken(o: { role?: string; policies?: string[]; period?: string; orphan?: boolean; displayName?: string; entityAlias?: string; explicitMaxTtl?: string }): Promise<{ token: string; accessor: string; entityId: string; ttlS: number }> {
|
|
138
|
+
const path = o.role != null ? `auth/token/create/${o.role}` : o.orphan === true ? 'auth/token/create-orphan' : 'auth/token/create'
|
|
139
|
+
const { json } = await this.call('POST', path, {
|
|
140
|
+
...(o.policies == null ? {} : { policies: o.policies }),
|
|
141
|
+
...(o.period == null ? {} : { period: o.period }),
|
|
142
|
+
...(o.displayName == null ? {} : { display_name: o.displayName }),
|
|
143
|
+
...(o.entityAlias == null ? {} : { entity_alias: o.entityAlias }),
|
|
144
|
+
...(o.explicitMaxTtl == null ? {} : { explicit_max_ttl: o.explicitMaxTtl }),
|
|
145
|
+
...(o.role == null ? { renewable: true } : {}),
|
|
146
|
+
})
|
|
147
|
+
const auth = json['auth'] as { client_token?: string; accessor?: string; entity_id?: string; lease_duration?: number } | undefined
|
|
148
|
+
if (typeof auth?.client_token !== 'string' || typeof auth.accessor !== 'string') throw new VaultError(0, `${path} answered without a token`)
|
|
149
|
+
return { token: auth.client_token, accessor: auth.accessor, entityId: auth.entity_id ?? '', ttlS: auth.lease_duration ?? 0 }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** what the caller's own token may do on each path (the default policy answers it) */
|
|
153
|
+
async capabilitiesSelf(paths: string[]): Promise<Record<string, string[]>> {
|
|
154
|
+
const { json } = await this.call('POST', 'sys/capabilities-self', { paths })
|
|
155
|
+
const out: Record<string, string[]> = {}
|
|
156
|
+
for (const p of paths) out[p] = ((json[p] ?? (paths.length === 1 ? json['capabilities'] : undefined)) as string[] | undefined) ?? []
|
|
157
|
+
return out
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** a policy's text, null when there is none */
|
|
161
|
+
async readPolicy(name: string): Promise<string | null> {
|
|
162
|
+
try {
|
|
163
|
+
const { json } = await this.call('GET', `sys/policies/acl/${name}`)
|
|
164
|
+
return ((json['data'] as { policy?: string } | undefined)?.policy ?? null) as string | null
|
|
165
|
+
} catch (e) {
|
|
166
|
+
if (e instanceof VaultError && e.status === 404) return null
|
|
167
|
+
throw e
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
listPolicies(): Promise<string[]> {
|
|
172
|
+
return this.listKeys('sys/policies/acl')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
deletePolicy(name: string): Promise<unknown> {
|
|
176
|
+
return this.call('DELETE', `sys/policies/acl/${name}`)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async readTokenRole(name: string): Promise<Json | null> {
|
|
180
|
+
try {
|
|
181
|
+
return ((await this.call('GET', `auth/token/roles/${name}`)).json['data'] as Json | undefined) ?? null
|
|
182
|
+
} catch (e) {
|
|
183
|
+
if (e instanceof VaultError && e.status === 404) return null
|
|
184
|
+
throw e
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** end a token by its accessor. A token already ended, or past its time, is no error */
|
|
189
|
+
async revokeAccessor(accessor: string): Promise<void> {
|
|
190
|
+
try {
|
|
191
|
+
await this.call('POST', 'auth/token/revoke-accessor', { accessor })
|
|
192
|
+
} catch (e) {
|
|
193
|
+
if (e instanceof VaultError && e.status === 400 && /invalid accessor|token not found/i.test(e.message)) return
|
|
194
|
+
throw e
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async readEntity(id: string): Promise<{ metadata: Record<string, string>; policies: string[]; disabled: boolean } | null> {
|
|
199
|
+
try {
|
|
200
|
+
const d = ((await this.call('GET', `identity/entity/id/${id}`)).json['data'] ?? {}) as { metadata?: Record<string, string> | null; policies?: string[] | null; disabled?: boolean }
|
|
201
|
+
return { metadata: d.metadata ?? {}, policies: d.policies ?? [], disabled: d.disabled === true }
|
|
202
|
+
} catch (e) {
|
|
203
|
+
if (e instanceof VaultError && e.status === 404) return null
|
|
204
|
+
throw e
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** an entity's metadata, replaced whole */
|
|
209
|
+
setEntityMetadata(id: string, metadata: Record<string, string>): Promise<unknown> {
|
|
210
|
+
return this.call('POST', `identity/entity/id/${id}`, { metadata })
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async lookupSelf(): Promise<{ policies: string[]; ttl: number }> {
|
|
214
|
+
const { json } = await this.call('GET', 'auth/token/lookup-self')
|
|
215
|
+
const d = (json['data'] ?? {}) as { policies?: string[]; ttl?: number }
|
|
216
|
+
return { policies: d.policies ?? [], ttl: d.ttl ?? 0 }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
renewSelf(): Promise<unknown> {
|
|
220
|
+
return this.call('POST', 'auth/token/renew-self', {})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
revokeSelf(): Promise<unknown> {
|
|
224
|
+
return this.call('POST', 'auth/token/revoke-self', {})
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** every token's accessor (sudo on auth/token/accessors) */
|
|
228
|
+
async accessors(): Promise<string[]> {
|
|
229
|
+
const { json } = await this.call('GET', 'auth/token/accessors?list=true')
|
|
230
|
+
return ((json['data'] as { keys?: string[] } | undefined)?.keys ?? []).map(String)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async lookupAccessor(accessor: string): Promise<{ policies: string[]; displayName: string; entityId: string; ttl: number }> {
|
|
234
|
+
const { json } = await this.call('POST', 'auth/token/lookup-accessor', { accessor })
|
|
235
|
+
const d = (json['data'] ?? {}) as { policies?: string[]; display_name?: string; entity_id?: string; ttl?: number }
|
|
236
|
+
return { policies: d.policies ?? [], displayName: d.display_name ?? '', entityId: d.entity_id ?? '', ttl: d.ttl ?? 0 }
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** the audit devices by path (sudo on sys/audit) */
|
|
240
|
+
async audits(): Promise<string[]> {
|
|
241
|
+
const { json } = await this.call('GET', 'sys/audit')
|
|
242
|
+
const data = (json['data'] ?? json) as Json
|
|
243
|
+
return Object.keys(data).filter((k) => k.endsWith('/'))
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** the file path of each file audit device the vault's own data holds, by its name */
|
|
247
|
+
async auditFiles(): Promise<Record<string, string>> {
|
|
248
|
+
const { json } = await this.call('GET', 'sys/audit')
|
|
249
|
+
const data = (json['data'] ?? json) as Record<string, { type?: string; options?: { file_path?: string } }>
|
|
250
|
+
return Object.fromEntries(Object.entries(data).flatMap(([k, v]) => (k.endsWith('/') && v?.type === 'file' && typeof v.options?.file_path === 'string' ? [[k, v.options.file_path]] : [])))
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async snapshot(): Promise<Uint8Array<ArrayBuffer>> {
|
|
254
|
+
return (await this.call('GET', 'sys/storage/raft/snapshot')).bytes
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** a snapshot into this vault. `force` is for one taken on another vault, whose keyring differs */
|
|
258
|
+
restore(snap: Uint8Array<ArrayBuffer>, o: { force: boolean }): Promise<unknown> {
|
|
259
|
+
return this.call('POST', `sys/storage/raft/${o.force ? 'snapshot-force' : 'snapshot'}`, undefined, snap)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** the current version of one path, 0 when it holds none. Metadata only, never a value */
|
|
263
|
+
async currentVersion(mount: string, path: string): Promise<number> {
|
|
264
|
+
try {
|
|
265
|
+
const { json } = await this.call('GET', `${mount}/metadata/${path}`)
|
|
266
|
+
return Number((json['data'] as { current_version?: number } | undefined)?.current_version ?? 0)
|
|
267
|
+
} catch (e) {
|
|
268
|
+
if (e instanceof VaultError && e.status === 404) return 0
|
|
269
|
+
throw e
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** the current version of one path and when it was written, null when it holds none (no path, or its current
|
|
274
|
+
* version deleted). Metadata only, never a value */
|
|
275
|
+
async writtenAt(mount: string, path: string): Promise<{ version: number; at: number | null } | null> {
|
|
276
|
+
try {
|
|
277
|
+
const { json } = await this.call('GET', `${mount}/metadata/${path}`)
|
|
278
|
+
const d = (json['data'] ?? {}) as { current_version?: number; updated_time?: string; versions?: Record<string, { created_time?: string; deletion_time?: string; destroyed?: boolean }> }
|
|
279
|
+
const version = Number(d.current_version ?? 0)
|
|
280
|
+
const v = d.versions?.[String(version)]
|
|
281
|
+
if (version === 0 || (v?.deletion_time ?? '') !== '' || v?.destroyed === true) return null
|
|
282
|
+
const at = Date.parse(v?.created_time ?? d.updated_time ?? '')
|
|
283
|
+
return { version, at: Number.isNaN(at) ? null : at }
|
|
284
|
+
} catch (e) {
|
|
285
|
+
if (e instanceof VaultError && e.status === 404) return null
|
|
286
|
+
throw e
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** a write that takes only on top of version `cas` (0: a path that holds none): its new version. A write made
|
|
291
|
+
* meanwhile elsewhere refuses it */
|
|
292
|
+
async writeKvCas(mount: string, path: string, data: Json, cas: number): Promise<number> {
|
|
293
|
+
const { json } = await this.call('POST', `${mount}/data/${path}`, { options: { cas }, data })
|
|
294
|
+
return Number((json['data'] as { version?: number } | undefined)?.version ?? 0)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
writeKv(mount: string, path: string, data: Json): Promise<unknown> {
|
|
298
|
+
return this.call('POST', `${mount}/data/${path}`, { data })
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** kv v2's metadata delete: every version and the key's metadata, for good. Only a root token may */
|
|
302
|
+
async destroyAll(mount: string, path: string): Promise<void> {
|
|
303
|
+
await this.call('DELETE', `${mount}/metadata/${path}`)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** kv v2's soft delete of the newest version: a read finds nothing, `undelete` brings it back */
|
|
307
|
+
async deleteKv(mount: string, path: string): Promise<void> {
|
|
308
|
+
await this.call('DELETE', `${mount}/data/${path}`)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** kv v2's undelete: these soft deleted versions read again */
|
|
312
|
+
async undeleteKv(mount: string, path: string, versions: number[]): Promise<void> {
|
|
313
|
+
await this.call('POST', `${mount}/undelete/${path}`, { versions })
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async readKv(mount: string, path: string): Promise<Json | null> {
|
|
317
|
+
try {
|
|
318
|
+
const { json } = await this.call('GET', `${mount}/data/${path}`)
|
|
319
|
+
return ((json['data'] as Json | undefined)?.['data'] as Json | undefined) ?? null
|
|
320
|
+
} catch (e) {
|
|
321
|
+
if (e instanceof VaultError && e.status === 404) return null
|
|
322
|
+
throw e
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** the names a LIST answers at `path`, none when it is absent */
|
|
327
|
+
async listKeys(path: string): Promise<string[]> {
|
|
328
|
+
try {
|
|
329
|
+
const { json } = await this.call('GET', `${path}?list=true`)
|
|
330
|
+
return ((json['data'] as { keys?: string[] } | undefined)?.keys ?? []).map(String)
|
|
331
|
+
} catch (e) {
|
|
332
|
+
if (e instanceof VaultError && e.status === 404) return []
|
|
333
|
+
throw e
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** the current version of each path under `prefix`, walked through the metadata: never a value */
|
|
338
|
+
async versions(mount: string, prefix = ''): Promise<Map<string, number>> {
|
|
339
|
+
const out = new Map<string, number>()
|
|
340
|
+
const walk = async (at: string): Promise<void> => {
|
|
341
|
+
let keys: string[] = []
|
|
342
|
+
try {
|
|
343
|
+
const { json } = await this.call('GET', `${mount}/metadata/${at}?list=true`)
|
|
344
|
+
keys = ((json['data'] as { keys?: string[] } | undefined)?.keys ?? []).map(String)
|
|
345
|
+
} catch (e) {
|
|
346
|
+
if (e instanceof VaultError && e.status === 404) return
|
|
347
|
+
throw e
|
|
348
|
+
}
|
|
349
|
+
for (const k of keys) {
|
|
350
|
+
if (k.endsWith('/')) await walk(`${at}${k}`)
|
|
351
|
+
else {
|
|
352
|
+
const { json } = await this.call('GET', `${mount}/metadata/${at}${k}`)
|
|
353
|
+
out.set(`${at}${k}`, Number((json['data'] as { current_version?: number } | undefined)?.current_version ?? 0))
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
await walk(prefix)
|
|
358
|
+
return out
|
|
359
|
+
}
|
|
360
|
+
}
|