rvlib-shipkit 2.31.0 → 2.33.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 +51 -0
- package/package.json +1 -1
- package/src/advisors/acts.ts +16 -15
- package/src/advisors/advice.ts +56 -102
- package/src/advisors/advisor-view.ts +122 -76
- package/src/advisors/app-graph.ts +1 -1
- package/src/advisors/app.ts +3 -11
- package/src/advisors/cf-api.ts +1 -1
- package/src/advisors/dir-bucket.ts +4 -3
- package/src/advisors/edge/api.ts +20 -221
- package/src/advisors/edge/bucket.ts +2 -2
- package/src/advisors/edge/handler.ts +13 -155
- package/src/advisors/edge/here.ts +5 -5
- package/src/advisors/edge/pages.ts +12 -9
- package/src/advisors/edge/shell.ts +6 -5
- package/src/advisors/edge/sign-in.ts +101 -36
- package/src/advisors/edge/status.ts +19 -6
- package/src/advisors/edge/types.ts +36 -60
- package/src/advisors/expose.ts +29 -29
- package/src/advisors/here.ts +12 -12
- package/src/advisors/invite-send.ts +79 -35
- package/src/advisors/invite.ts +31 -8
- package/src/advisors/job.ts +24 -16
- package/src/advisors/login.ts +40 -15
- package/src/advisors/owner-store.ts +46 -22
- package/src/advisors/photos.ts +3 -3
- package/src/advisors/project.ts +27 -25
- package/src/advisors/reach.ts +89 -0
- package/src/advisors/rights.ts +1 -1
- package/src/advisors/routes.ts +55 -74
- package/src/advisors/scan.ts +0 -4
- package/src/advisors/setup-run.ts +14 -14
- package/src/advisors/share-trace.ts +3 -3
- package/src/advisors/{door-probe.ts → sign-in-probe.ts} +7 -6
- package/src/advisors/speaks.ts +29 -0
- package/src/advisors/sync.ts +97 -183
- package/src/advisors/tunnel.ts +6 -5
- package/src/advisors/users-listen.ts +92 -0
- package/src/advisors/users-router.ts +261 -87
- package/src/advisors/users-store.ts +81 -0
- package/src/agent-time/blocked-scan.ts +181 -0
- package/src/agent-time/registry.ts +12 -5
- package/src/agent-time/store.ts +9 -109
- package/src/asks/ask-bar-fold.ts +2 -1
- package/src/asks/ask-close.ts +2 -1
- package/src/asks/ask-doc.ts +2 -1
- package/src/asks/ask-migrate.ts +3 -2
- package/src/asks/ask-steps-fold.ts +2 -1
- package/src/asks/ask-store.ts +4 -3
- package/src/check.ts +3 -43
- package/src/checks/SK001-package-json-shape.check.ts +4 -55
- package/src/checks/SK004-gitignore-policy.check.ts +24 -69
- package/src/checks/SK013-one-way-in-policy.check.ts +3 -7
- package/src/checks/SK017-vscode-hub-task.check.ts +4 -4
- package/src/checks/SK019-tests-run-in-units.check.ts +3 -14
- package/src/checks/SK020-self-spawning-check.check.ts +5 -7
- package/src/checks/SK035-public-clean.check.ts +1 -1
- package/src/checks/SK039-vscode-watch-generated.check.ts +1 -1
- package/src/checks/SK042-post-kinds.check.ts +5 -14
- package/src/checks/SK054-agent-allow-list.check.ts +5 -74
- package/src/checks/SK055-retired-config-keys.check.ts +45 -0
- package/src/cli/cmd_Advisors.ts +11 -45
- package/src/cli/cmd_Asks.ts +3 -10
- package/src/cli/cmd_Backup.ts +25 -127
- package/src/cli/cmd_BackupTargets.ts +1 -1
- package/src/cli/cmd_Capacity.ts +6 -2
- package/src/cli/cmd_Checks.ts +0 -14
- package/src/cli/cmd_Ci.ts +2 -1
- package/src/cli/cmd_Db.ts +3 -82
- package/src/cli/cmd_Home.ts +4 -32
- package/src/cli/cmd_Hq.ts +0 -17
- package/src/cli/cmd_Releases.ts +57 -4
- package/src/cli/cmd_Review.ts +333 -354
- package/src/cli/cmd_Shot.ts +26 -4
- package/src/cli/cmd_SocialDrafts.ts +6 -13
- package/src/cli/cmd_ThreadSyncNeeds.ts +6 -2
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_Trailer.ts +1 -1
- package/src/cli/inbox-hook-run.ts +5 -23
- package/src/cli/registry-heads.ts +5 -55
- package/src/cli/registry.ts +1 -5
- package/src/cli/review-here.ts +1 -1
- package/src/cli.ts +15 -4
- package/src/collections/collection-types.ts +1 -1
- package/src/collections/review.ts +5 -4
- package/src/core/admission.ts +268 -0
- package/src/core/agent-allow-policy.ts +32 -2
- package/src/core/agent-env.ts +8 -0
- package/src/core/allow-rows.ts +74 -0
- package/src/core/check-file-names.ts +19 -106
- package/src/core/code-lines.ts +36 -21
- package/src/core/footprint.ts +17 -13
- package/src/core/identities-root.ts +1 -4
- package/src/core/layout.ts +1 -2
- package/src/core/machine-db.ts +33 -208
- package/src/core/machine-layout.ts +14 -127
- package/src/core/machine-read.ts +5 -2
- package/src/core/mask-source.ts +60 -0
- package/src/core/memory-watch.ts +17 -14
- package/src/core/motherhome.ts +8 -35
- package/src/core/one-way-in-policy.ts +0 -3
- package/src/core/peer-sk.ts +8 -0
- package/src/core/repo-walk.ts +0 -9
- package/src/core/retention.ts +1 -9
- package/src/core/retired-checks.ts +2 -0
- package/src/core/tmux-policy.ts +1 -1
- package/src/core/tree-watch.ts +2 -2
- package/src/core/when.ts +7 -45
- package/src/gate/admit-heavy.ts +150 -0
- package/src/gate/check-runner.ts +6 -0
- package/src/gate/discover-checks.ts +42 -32
- package/src/gate/gate-checks.ts +21 -131
- package/src/gate/head-gate.ts +1 -1
- package/src/gate/job-run.ts +2 -1
- package/src/gate/pre-commit-discovery.ts +22 -28
- package/src/gate/run-check.ts +3 -4
- package/src/gate/run-ci.ts +4 -0
- package/src/gate/run-fix.ts +5 -17
- package/src/gate/run-fixers.ts +6 -42
- package/src/home/app-sign.ts +2 -2
- package/src/home/backup-status.ts +52 -92
- package/src/home/backup-verdict.ts +2 -2
- package/src/home/daemon-jobs.ts +51 -95
- package/src/home/database-words.ts +1 -2
- package/src/home/databases.ts +9 -25
- package/src/home/home-launchd.ts +0 -6
- package/src/home/home-paths.ts +8 -4
- package/src/home/home-routes.ts +3 -10
- package/src/home/home-state.ts +2 -14
- package/src/home/inbox-shape.ts +14 -15
- package/src/home/inbox.ts +1 -1
- package/src/home/machine-repair.ts +102 -103
- package/src/home/resume.ts +1 -15
- package/src/home/run-daemon.ts +7 -12
- package/src/home/space-page.ts +3 -2
- package/src/home/supervise.ts +3 -7
- package/src/hooks/commit-msg-run.ts +61 -0
- package/src/hooks/commit-run.ts +16 -166
- package/src/hooks/gate-outcome.ts +108 -0
- package/src/hooks/git-hook.ts +9 -9
- package/src/hooks/hook-config.ts +8 -8
- package/src/hooks/leak-guard.ts +1 -1
- package/src/hooks/pre-commit-checks.ts +1 -1
- package/src/hooks/run-hooks.ts +2 -6
- package/src/hooks/shared-file.ts +3 -2
- package/src/hq/daemon-db.ts +8 -8
- package/src/hq/door.ts +3 -16
- package/src/hq/hq-db.ts +4 -3
- package/src/hq/hq-local.ts +1 -2
- package/src/hq/hq-store.ts +0 -15
- package/src/hq/item-direct.ts +8 -10
- package/src/hq/item-fill.ts +37 -0
- package/src/hq/kinds/item-gone.ts +7 -10
- package/src/hq/kinds/item-msg.ts +12 -18
- package/src/hq/kinds/item.ts +13 -19
- package/src/hq/kinds/report.ts +3 -4
- package/src/hq/owner-switch.ts +3 -3
- package/src/hq/report.ts +5 -9
- package/src/hq/switch.ts +2 -11
- package/src/hq/thread-sync.ts +5 -17
- package/src/hq/{shapes-words.ts → threads-words.ts} +2 -12
- package/src/http/owner-word.ts +1 -1
- package/src/identities/machine.ts +16 -0
- package/src/init-repo.ts +0 -1
- package/src/ledger/check-stats.ts +6 -5
- package/src/ledger/db.ts +2 -4
- package/src/ledger/record-kept.ts +117 -48
- package/src/ledger/run-log.ts +21 -2
- package/src/ledger/slow-tests.ts +96 -0
- package/src/ledger/store.ts +3 -86
- package/src/ledger/suite-log.ts +8 -2
- package/src/media-store/backup/facts.ts +3 -37
- package/src/media-store/backup/keys.ts +1 -8
- package/src/media-store/backup/manifest.ts +6 -67
- package/src/media-store/backup/restore.ts +4 -13
- package/src/media-store/backup/retention.ts +13 -1
- package/src/media-store/backup/run.ts +6 -267
- package/src/media-store/backup/snapshot.ts +2 -38
- package/src/media-store/backup/sources.ts +3 -113
- package/src/media-store/backup/target-send.ts +5 -29
- package/src/media-store/db.ts +8 -7
- package/src/media-store/forget-one.ts +1 -1
- package/src/media-store/forget.ts +1 -80
- package/src/orchestrator/guards.ts +0 -1
- package/src/orchestrator/presence.ts +2 -2
- package/src/orchestrator/routes.ts +1 -1
- package/src/orchestrator/started.ts +0 -9
- package/src/orchestrator/talk-key.ts +3 -4
- package/src/orchestrator/unheard.ts +1 -1
- package/src/plan/planner.ts +3 -2
- package/src/recordings/edit.ts +3 -3
- package/src/recordings/marks-draw.ts +17 -6
- package/src/recordings/marks.ts +120 -9
- package/src/reflections/reflections-queue.ts +3 -10
- package/src/release/notes.ts +1 -1
- package/src/release/public-clean.ts +66 -6
- package/src/release/run-bump.ts +11 -0
- package/src/release/run-release.ts +4 -0
- package/src/releases/from-thread.ts +3 -3
- package/src/releases/model.ts +186 -36
- package/src/releases/store.ts +13 -3
- package/src/releases/validate.ts +83 -0
- package/src/repo-config.ts +36 -64
- package/src/review/answer-kinds.ts +63 -4
- package/src/review/blocked-guard.ts +11 -0
- package/src/review/blocked-object.ts +298 -0
- package/src/review/cells.ts +144 -230
- package/src/review/close.ts +39 -1
- package/src/review/doc-save.ts +3 -2
- package/src/review/draft-item.ts +1 -1
- package/src/review/events.ts +3 -7
- package/src/review/expect.ts +23 -39
- package/src/review/format.ts +79 -46
- package/src/review/glyphs.ts +1 -0
- package/src/review/hand-over.ts +3 -3
- package/src/review/heard.ts +1 -1
- package/src/review/holds-sync.ts +2 -1
- package/src/review/inbox-hook.ts +2 -2
- package/src/review/inbox-read.ts +39 -33
- package/src/review/instruction-guards.ts +12 -0
- package/src/review/instructions.ts +0 -1
- package/src/review/item-db.ts +13 -43
- package/src/review/item-hq.ts +2 -2
- package/src/review/item-rows.ts +3 -14
- package/src/review/kind-catalog.ts +3 -1
- package/src/review/kinds.ts +18 -8
- package/src/review/live-view.ts +3 -0
- package/src/review/media-kind.ts +1 -1
- package/src/review/mentions.ts +1 -2
- package/src/review/model.ts +158 -114
- package/src/review/move.ts +149 -0
- package/src/review/need-threads.ts +3 -2
- package/src/review/object-card.ts +11 -0
- package/src/review/object-read.ts +6 -1
- package/src/review/one-block.ts +1 -1
- package/src/review/owner-read.ts +1 -1
- package/src/review/phone-push.ts +10 -9
- package/src/review/previews.ts +32 -4
- package/src/review/push.ts +2 -2
- package/src/review/recap.ts +129 -0
- package/src/review/referring.ts +6 -3
- package/src/review/reflection-object.ts +4 -3
- package/src/review/routes.ts +51 -47
- package/src/review/secret-route.ts +3 -2
- package/src/review/settle.ts +0 -6
- package/src/review/snooze.ts +5 -3
- package/src/review/speaker.ts +68 -0
- package/src/review/start-title.ts +19 -0
- package/src/review/store-parties.ts +28 -0
- package/src/review/store.ts +94 -59
- package/src/review/{wakes.ts → thread-events.ts} +92 -7
- package/src/review/thread-md.ts +35 -14
- package/src/review/thread-state.ts +804 -0
- package/src/review/threads.ts +29 -347
- package/src/review/traces.ts +104 -7
- package/src/review/trailer-item.ts +1 -1
- package/src/review/unit.ts +7 -9
- package/src/review/verdict-items.ts +12 -10
- package/src/review/view-layout.ts +25 -1
- package/src/review/watch-feed.ts +1 -2
- package/src/review/working-guards.ts +2 -3
- package/src/rules/untrack-generated.ts +1 -15
- package/src/secrets/copy.ts +4 -4
- package/src/secrets/lapse.ts +2 -1
- package/src/serve/hub-app/advisor-app.tsx +4 -4
- package/src/serve/hub-app/advisor-face.tsx +9 -3
- package/src/serve/hub-app/advisor-host.ts +27 -27
- package/src/serve/hub-app/advisors-model.ts +17 -8
- package/src/serve/hub-app/advisors-rights.tsx +1 -1
- package/src/serve/hub-app/advisors-st.ts +15 -14
- package/src/serve/hub-app/advisors-view.tsx +13 -11
- package/src/serve/hub-app/app-bridge.ts +23 -3
- package/src/serve/hub-app/asks-page.tsx +1 -1
- package/src/serve/hub-app/auto-text.tsx +71 -16
- package/src/serve/hub-app/check-view.tsx +0 -8
- package/src/serve/hub-app/controls.css +14 -3
- package/src/serve/hub-app/database-view.tsx +1 -2
- package/src/serve/hub-app/dock-st.ts +1 -1
- package/src/serve/hub-app/git-view.tsx +3 -1
- package/src/serve/hub-app/hub.css +12 -5
- package/src/serve/hub-app/icons.tsx +1 -1
- package/src/serve/hub-app/inbox-view.tsx +1 -2
- package/src/serve/hub-app/live-sources.ts +2 -2
- package/src/serve/hub-app/main-panel.tsx +2 -1
- package/src/serve/hub-app/panel-repo.ts +0 -9
- package/src/serve/hub-app/pic.tsx +29 -12
- package/src/serve/hub-app/polled.ts +16 -2
- package/src/serve/hub-app/recordings-st.ts +23 -2
- package/src/serve/hub-app/recordings-view.tsx +68 -10
- package/src/serve/hub-app/ref-pill.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +1 -2
- package/src/serve/hub-app/review/advisor-add.tsx +1 -1
- package/src/serve/hub-app/review/advisor-invite.tsx +1 -1
- package/src/serve/hub-app/review/draft-body.tsx +2 -2
- package/src/serve/hub-app/review/heard-line.tsx +1 -1
- package/src/serve/hub-app/review/instructions-view.tsx +1 -8
- package/src/serve/hub-app/review/kind-states.tsx +14 -9
- package/src/serve/hub-app/review/kit.tsx +4 -11
- package/src/serve/hub-app/review/lane-bar.tsx +3 -3
- package/src/serve/hub-app/review/lightbox.tsx +15 -11
- package/src/serve/hub-app/review/line-window.ts +4 -1
- package/src/serve/hub-app/review/live-bar-st.ts +2 -2
- package/src/serve/hub-app/review/live-view.tsx +57 -1
- package/src/serve/hub-app/review/object-panel.tsx +20 -8
- package/src/serve/hub-app/review/question-views.tsx +191 -53
- package/src/serve/hub-app/review/recap-bar.tsx +40 -0
- package/src/serve/hub-app/review/request-cell.tsx +48 -0
- package/src/serve/hub-app/review/review-cells.tsx +154 -96
- package/src/serve/hub-app/review/review-host.ts +8 -4
- package/src/serve/hub-app/review/review-kit.ts +17 -11
- package/src/serve/hub-app/review/review-list.tsx +30 -35
- package/src/serve/hub-app/review/review-st.ts +32 -42
- package/src/serve/hub-app/review/review-thread.tsx +139 -85
- package/src/serve/hub-app/review/review-views.tsx +127 -68
- package/src/serve/hub-app/review/share-lines.tsx +4 -4
- package/src/serve/hub-app/review/start-st.ts +2 -5
- package/src/serve/hub-app/review/superseded-runs.ts +4 -3
- package/src/serve/hub-app/review/thread-close.tsx +10 -7
- package/src/serve/hub-app/review/thread-st.ts +381 -202
- package/src/serve/hub-app/review/tone-bar.tsx +129 -0
- package/src/serve/hub-app/review/tones.ts +53 -0
- package/src/serve/hub-app/review/trailer-body.tsx +2 -2
- package/src/serve/hub-app/review/trailer-st.ts +3 -2
- package/src/serve/hub-app/review/trailer-voices-st.ts +3 -2
- package/src/serve/hub-app/review.css +189 -106
- package/src/serve/hub-app/search-view.tsx +1 -1
- package/src/serve/hub-app/social/social-model.ts +0 -4
- package/src/serve/hub-app/source-acts.ts +2 -1
- package/src/serve/hub-app/stores/stores-page.tsx +2 -2
- package/src/serve/hub-app/terminal-sources.tsx +2 -1
- package/src/serve/hub-app/thread-row.tsx +3 -4
- package/src/serve/hub-app/tree-build.ts +0 -4
- package/src/serve/hub-app/urls-view.tsx +2 -1
- package/src/serve/hub-app/view-layout.css +13 -3
- package/src/serve/hub-app/wikis-view.tsx +5 -2
- package/src/serve/hub-runtime.ts +7 -37
- package/src/serve/project-gutter-route.ts +6 -2
- package/src/serve/read-thread.ts +20 -2
- package/src/serve/read-worker.ts +9 -1
- package/src/serve/record-pages.ts +46 -0
- package/src/serve/serve-hub.ts +2 -2
- package/src/serve/terminal-host.ts +1 -1
- package/src/serve/terminal-route.ts +1 -3
- package/src/serve/tracked-watch.ts +1 -3
- package/src/setup-house.ts +2 -2
- package/src/shipkit-files.ts +1 -1
- package/src/shipkit.ts +1 -6
- package/src/shot/client.ts +2 -1
- package/src/shot/film-box.ts +0 -20
- package/src/shot/on-place.ts +141 -0
- package/src/social/drafts.ts +1 -1
- package/src/social/kinds.ts +6 -29
- package/src/social/load.ts +2 -2
- package/src/social/post-object.ts +3 -2
- package/src/social/release-stage.ts +1 -1
- package/src/social/stage.ts +2 -2
- package/src/stores/model.ts +4 -0
- package/src/stores/routes.ts +11 -3
- package/src/suite/judge-suites.ts +58 -0
- package/src/suite/red-alone.ts +54 -18
- package/src/suite/runner-shapes.ts +2 -2
- package/src/suite/suite-cli.ts +67 -14
- package/src/suite/test-units.ts +2 -1
- package/src/urls/fill.ts +1 -1
- package/src/urls/places.ts +1 -2
- package/src/vault/vault-config.ts +2 -2
- package/src/vault/vault-init.ts +1 -5
- package/src/wiki/graph-page.ts +14 -2
- package/src/advisors/copy-truth.ts +0 -49
- package/src/advisors/door-child.ts +0 -112
- package/src/advisors/door-serve.ts +0 -52
- package/src/advisors/door.ts +0 -118
- package/src/checks/SK016-legacy-check-shapes.check.ts +0 -189
- package/src/checks/SK029-explicit-check-files.check.ts +0 -112
- package/src/checks/SK048-one-local-file.check.ts +0 -36
- package/src/core/config-rewrite.ts +0 -111
- package/src/core/daemon-port.ts +0 -10
- package/src/core/legacy-shapes.ts +0 -263
- package/src/core/migrate-layout.ts +0 -638
- package/src/core/port-check-cli.ts +0 -52
- package/src/core/port-check-file.ts +0 -295
- package/src/core/port-check-files.ts +0 -31
- package/src/gate/discover-legacy-checks.ts +0 -26
- package/src/home/home-move.ts +0 -527
- package/src/home/machine-fold.ts +0 -810
- package/src/hq/item-shapes.ts +0 -54
- package/src/hq/kinds/items-read.ts +0 -4
- package/src/media-store/backup/daemon.ts +0 -220
- package/src/media-store/backup/kept.ts +0 -241
- package/src/media-store/backup/prune.ts +0 -359
- package/src/media-store/backup/secret.ts +0 -88
- package/src/media-store/backup/ssh-space.ts +0 -202
- package/src/media-store/backup/watch.ts +0 -117
- package/src/review/band.ts +0 -182
- package/src/review/folders.ts +0 -216
- package/src/review/hook-ask.ts +0 -58
- package/src/review/role.ts +0 -48
- package/src/review/thread-fold.ts +0 -64
- package/src/review/wait.ts +0 -91
- package/src/rules/rule.ts +0 -43
- package/src/serve/hook-thread.ts +0 -37
- package/src/serve/hook-work.ts +0 -92
- package/src/serve/hook-worker.ts +0 -57
- package/src/serve/hub-app/review/dock.tsx +0 -147
- package/src/serve/hub-app/review/faces.tsx +0 -18
- package/src/serve/hub-app/review/item-verdict.tsx +0 -112
- package/src/serve/hub-app/review/review-board.tsx +0 -48
- /package/src/{scaffold → core}/jsonc-spans.ts +0 -0
package/src/advisors/here.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// where each advisor is
|
|
2
|
-
// files the
|
|
3
|
-
// servedShares). The one constraint a reader breaks first: the owner's hub alone reads this; no route
|
|
4
|
-
//
|
|
1
|
+
// where each advisor is on the advisors page, as the owner's hub reads it (wiki tools/shipkit/advisors.md, Who is here
|
|
2
|
+
// now): the files the users' port writes at each beat (edge/here.ts), kept to the shares it would open today
|
|
3
|
+
// (owner-store.ts servedShares). The one constraint a reader breaks first: the owner's hub alone reads this; no route
|
|
4
|
+
// of the users' port carries it
|
|
5
5
|
import { createHash } from 'node:crypto'
|
|
6
6
|
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
7
7
|
import { join } from 'node:path'
|
|
@@ -23,10 +23,10 @@ export interface HereRow {
|
|
|
23
23
|
|
|
24
24
|
const emailKey = (email: string): string => createHash('sha256').update(email).digest('hex')
|
|
25
25
|
|
|
26
|
-
/** every person's file the
|
|
27
|
-
function filesOf(
|
|
26
|
+
/** every person's file the users' port wrote, by the sha256 of their email; one that does not read is none */
|
|
27
|
+
function filesOf(users: string): Map<string, HereFile> {
|
|
28
28
|
const out = new Map<string, HereFile>()
|
|
29
|
-
const d = join(
|
|
29
|
+
const d = join(users, 'here')
|
|
30
30
|
if (!existsSync(d)) return out
|
|
31
31
|
for (const f of readdirSync(d)) {
|
|
32
32
|
const m = /^([0-9a-f]{64})\.json$/.exec(f)
|
|
@@ -35,15 +35,15 @@ function filesOf(door: string): Map<string, HereFile> {
|
|
|
35
35
|
const v = JSON.parse(readFileSync(join(d, f), 'utf8')) as HereFile
|
|
36
36
|
if (v?.v === 1 && typeof v.at === 'string' && typeof v.seen === 'object' && v.seen !== null) out.set(m[1]!, v)
|
|
37
37
|
} catch {
|
|
38
|
-
// a file the
|
|
38
|
+
// a file the port is writing reads at the next look
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
return out
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/** where each person is: one row a served share they were ever on, theirs only */
|
|
45
|
-
export function hereOf(s: OwnerState,
|
|
46
|
-
const files = filesOf(
|
|
45
|
+
export function hereOf(s: OwnerState, users: string, now: Date): HereRow[] {
|
|
46
|
+
const files = filesOf(users)
|
|
47
47
|
if (files.size === 0) return []
|
|
48
48
|
const rows: HereRow[] = []
|
|
49
49
|
for (const x of servedShares(s, now)) {
|
|
@@ -58,8 +58,8 @@ export function hereOf(s: OwnerState, door: string, now: Date): HereRow[] {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/** what the hub's stream says moved: who is on which thread now, never the beats' clock */
|
|
61
|
-
export const hereStamp = (s: OwnerState,
|
|
62
|
-
hereOf(s,
|
|
61
|
+
export const hereStamp = (s: OwnerState, users: string, now: Date): string =>
|
|
62
|
+
hereOf(s, users, now)
|
|
63
63
|
.filter((r) => r.on)
|
|
64
64
|
.map((r) => `${r.advisor}:${r.share}`)
|
|
65
65
|
.sort()
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
// the
|
|
2
|
-
// itself through Brevo's transactional API, from advisors@<the
|
|
3
|
-
// inviteMail's words, their one time code in it
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// the advisors' one sender (wiki tools/shipkit/advisors.md, What he does): on his share the daemon mails the invite
|
|
2
|
+
// itself through Brevo's transactional API, from advisors@<the advisors page's domain>, to that share's own person, in
|
|
3
|
+
// inviteMail's words, their one time code in it; and the code of a reset a person asked at the sign in, to that person
|
|
4
|
+
// (resetMail). The one constraint a reader breaks first: there is no generic send here and none may be added. The only
|
|
5
|
+
// input is a share, a person or a reset parked in the state, so the recipient, the sender and the words all come from
|
|
6
|
+
// the advisors state: an invite only his act sends, a reset only to the listed person it was asked for
|
|
6
7
|
import { createHash } from 'node:crypto'
|
|
7
|
-
import { AGENT_ENV } from '../
|
|
8
|
+
import { AGENT_ENV } from '../core/agent-env.ts'
|
|
8
9
|
import { ownerOnly, type Actor } from './acts.ts'
|
|
9
|
-
import { inviteDue, inviteMail } from './invite.ts'
|
|
10
|
+
import { inviteDue, inviteMail, resetMail } from './invite.ts'
|
|
10
11
|
import { codeToSend } from './login.ts'
|
|
11
|
-
import { identityOfRoot } from './
|
|
12
|
+
import { identityOfRoot } from './speaks.ts'
|
|
12
13
|
import { ownerNameOf } from './owner-name.ts'
|
|
13
|
-
import { advisorOf, granted, isLive, readState, withState } from './owner-store.ts'
|
|
14
|
+
import { advisorOf, granted, isLive, readState, resetWaits, withState } from './owner-store.ts'
|
|
15
|
+
import { maskHits } from './scan.ts'
|
|
14
16
|
|
|
15
17
|
// sk-disable-next-line RV045 -- the invite sender reads the house's own Brevo key by this name
|
|
16
18
|
export const BREVO_KEY = 'rv/brevo/api-key'
|
|
@@ -45,7 +47,7 @@ export interface InviteMailer {
|
|
|
45
47
|
/** one try: `missingKey` while the key is not stored, the hub then says invites go once it is */
|
|
46
48
|
export type InviteSent = { sent: true; to: string; at: string } | { sent: false; to: string; at: string; why: string; missingKey: boolean }
|
|
47
49
|
|
|
48
|
-
/** `advisors@<domain>`: the
|
|
50
|
+
/** `advisors@<domain>`: the advisors page's own name less its first label (advisors.example.org → advisors@example.org) */
|
|
49
51
|
export function senderOf(host: string): string {
|
|
50
52
|
const labels = host.split('.')
|
|
51
53
|
return `advisors@${labels.length > 2 ? labels.slice(1).join('.') : host}`
|
|
@@ -78,7 +80,7 @@ export function houseMailer(house: string, env: Record<string, string | undefine
|
|
|
78
80
|
},
|
|
79
81
|
fetch: (url, init) => fetch(url, init),
|
|
80
82
|
replyTo: async () => {
|
|
81
|
-
const { housePageFacts } = await import('./
|
|
83
|
+
const { housePageFacts } = await import('./speaks.ts')
|
|
82
84
|
return (await housePageFacts(house).catch(() => null))?.facts.contact ?? null
|
|
83
85
|
},
|
|
84
86
|
log: (l) => console.log(l),
|
|
@@ -136,41 +138,83 @@ export async function sendInvite(dir: string, what: { share: string } | { person
|
|
|
136
138
|
return { sent: false, to, at, why, missingKey }
|
|
137
139
|
}
|
|
138
140
|
if (claim.mail === null || claim.from === null) return fail('the advisors page is not set up yet, so an invite has no address to give')
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
const why = await brevoSend({ from: claim.from, owner: claim.owner, mail: claim.mail }, o.mailer)
|
|
142
|
+
if (why !== null) return fail(why.missingKey ? `invites go out by themselves once the Brevo key is stored (${BREVO_KEY})` : why.why, why.missingKey)
|
|
143
|
+
withState(dir, (s) => {
|
|
144
|
+
const a = s.advisors.find((y) => y.id === claim.advisor)
|
|
145
|
+
if (a !== undefined) delete a.inviteFailed
|
|
146
|
+
})
|
|
147
|
+
log(`advisors invite: sent, template=${INVITE_TEMPLATE} to=${recipientHash(claim.mail.to)}`)
|
|
148
|
+
return { sent: true, to: claim.mail.to, at }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** one mail of the advisors state through Brevo's transactional API: null once Brevo took it, else why not */
|
|
152
|
+
async function brevoSend(m: { from: string; owner: string; mail: { to: string; subject: string; body: string } }, mailer: InviteMailer): Promise<{ why: string; missingKey: boolean } | null> {
|
|
153
|
+
const key = await (mailer.key ?? (async (): Promise<KeyRead> => ({ refused: 'no key reader' })))().catch((e: unknown): KeyRead => ({ refused: (e as Error).message }))
|
|
154
|
+
if ('missing' in key) return { why: `the Brevo key is not stored yet (${BREVO_KEY})`, missingKey: true }
|
|
155
|
+
if ('refused' in key) return { why: `the Brevo key could not be read: ${key.refused}`, missingKey: false }
|
|
156
|
+
const replyTo = await (mailer.replyTo ?? (async () => null))().catch(() => null)
|
|
157
|
+
const name = m.owner.replace(/[\r\n]/g, ' ').trim().slice(0, SENDER_NAME_MAX)
|
|
145
158
|
const body = {
|
|
146
|
-
sender: { email:
|
|
147
|
-
to: [{ email: m.to }],
|
|
148
|
-
subject: m.subject,
|
|
149
|
-
htmlContent: htmlOf(m.body),
|
|
150
|
-
textContent: m.body,
|
|
159
|
+
sender: { email: m.from, ...(name !== '' ? { name } : {}) },
|
|
160
|
+
to: [{ email: m.mail.to }],
|
|
161
|
+
subject: m.mail.subject,
|
|
162
|
+
htmlContent: htmlOf(m.mail.body),
|
|
163
|
+
textContent: m.mail.body,
|
|
151
164
|
...(replyTo !== null ? { replyTo: { email: replyTo } } : {}),
|
|
152
165
|
}
|
|
153
166
|
let r: Response
|
|
154
167
|
try {
|
|
155
|
-
r = await (
|
|
168
|
+
r = await (mailer.fetch ?? fetch)(BREVO_URL, {
|
|
156
169
|
method: 'POST',
|
|
157
170
|
headers: { 'api-key': key.value, accept: 'application/json', 'content-type': 'application/json' },
|
|
158
171
|
body: JSON.stringify(body),
|
|
159
172
|
signal: AbortSignal.timeout(SEND_MS),
|
|
160
173
|
})
|
|
161
174
|
} catch (e) {
|
|
162
|
-
return
|
|
163
|
-
}
|
|
164
|
-
if (!r.ok) {
|
|
165
|
-
// Brevo's refusal is `{ code, message }`
|
|
166
|
-
const said = ((await r.json().catch(() => null)) as { message?: unknown } | null)?.message
|
|
167
|
-
const words = typeof said === 'string' ? said.split(m.to).join('the address').slice(0, 200) : ''
|
|
168
|
-
return fail(`Brevo answered ${r.status}${words === '' ? '' : `: ${words}`}`)
|
|
175
|
+
return { why: `Brevo was not reached: ${(e as Error).message}`, missingKey: false }
|
|
169
176
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
177
|
+
if (r.ok) return null
|
|
178
|
+
// Brevo's refusal is `{ code, message }`
|
|
179
|
+
const said = ((await r.json().catch(() => null)) as { message?: unknown } | null)?.message
|
|
180
|
+
const words = typeof said === 'string' ? said.split(m.mail.to).join('the address').slice(0, 200) : ''
|
|
181
|
+
return { why: `Brevo answered ${r.status}${words === '' ? '' : `: ${words}`}`, missingKey: false }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** the mail of each reset that waits (owner-store.ts resetWaits: a person asked it at the sign in, users-store.ts
|
|
185
|
+
* askedReset), from the daemon's job: the parked code to that person's own address, marked sent before it leaves, so
|
|
186
|
+
* two passes send it once; a failure kept on the ask for his hub. Nothing else is input, so the recipient is always the
|
|
187
|
+
* person the state names. Each mail's address, by how it went */
|
|
188
|
+
export async function sendResets(dir: string, o: { now: Date; words: readonly string[]; mailer: InviteMailer }): Promise<InviteSent[]> {
|
|
189
|
+
const log = o.mailer.log ?? ((l: string) => console.log(l))
|
|
190
|
+
const at = o.now.toISOString()
|
|
191
|
+
const claims = withState(dir, (s) => {
|
|
192
|
+
if (s.host === null) return []
|
|
193
|
+
const name = ownerNameOf(s)
|
|
194
|
+
const owner = maskHits(name, { advisorEmail: '', words: [...o.words] }).length === 0 ? name : 'the owner'
|
|
195
|
+
return s.advisors.flatMap((a) => {
|
|
196
|
+
if (!resetWaits(a, o.now)) return []
|
|
197
|
+
const r = a.resets!.at(-1)!
|
|
198
|
+
r.sent = at
|
|
199
|
+
return [{ advisor: a.id, asked: r.at, owner, from: senderOf(s.host!), mail: resetMail(a, { code: a.login!.reset!.code, owner, host: s.host! }) }]
|
|
200
|
+
})
|
|
173
201
|
})
|
|
174
|
-
|
|
175
|
-
|
|
202
|
+
const out: InviteSent[] = []
|
|
203
|
+
for (const c of claims) {
|
|
204
|
+
const why = await brevoSend(c, o.mailer)
|
|
205
|
+
if (why === null) {
|
|
206
|
+
log(`advisors reset: sent, to=${recipientHash(c.mail.to)}`)
|
|
207
|
+
out.push({ sent: true, to: c.mail.to, at })
|
|
208
|
+
continue
|
|
209
|
+
}
|
|
210
|
+
withState(dir, (s) => {
|
|
211
|
+
const r = s.advisors.find((y) => y.id === c.advisor)?.resets?.find((x) => x.at === c.asked)
|
|
212
|
+
if (r === undefined) return
|
|
213
|
+
delete r.sent
|
|
214
|
+
r.why = why.why
|
|
215
|
+
})
|
|
216
|
+
log(`WARN advisors reset: not sent, to=${recipientHash(c.mail.to)}: ${why.why}`)
|
|
217
|
+
out.push({ sent: false, to: c.mail.to, at, why: why.why, missingKey: why.missingKey })
|
|
218
|
+
}
|
|
219
|
+
return out
|
|
176
220
|
}
|
package/src/advisors/invite.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// the invite an advisor gets when
|
|
2
|
-
// invites, the
|
|
3
|
-
// it, in English. The daemon mails
|
|
4
|
-
// first: the code is never in a link, so a mail scanner that opens links cannot spend it
|
|
1
|
+
// the invite an advisor gets when the owner first shares with them (wiki tools/shipkit/advisors.md, What he does): who
|
|
2
|
+
// invites, the advisors page's sign in, their one time code while it is unused, the thread's title and nothing else of
|
|
3
|
+
// it, in English; and the mail of a reset they asked. The daemon mails both (invite-send.ts), « copy invite » copies
|
|
4
|
+
// the invite. The one constraint a reader breaks first: the code is never in a link, so a mail scanner that opens links cannot spend it
|
|
5
|
+
import { PASSWORD_MIN, RESET_MINUTES } from './edge/sign-in.ts'
|
|
5
6
|
import { CODE_DAYS, liveCode } from './login.ts'
|
|
6
7
|
import type { Advisor } from './owner-store.ts'
|
|
7
8
|
import { maskHits } from './scan.ts'
|
|
@@ -14,14 +15,14 @@ export interface InviteMail {
|
|
|
14
15
|
to: string
|
|
15
16
|
subject: string
|
|
16
17
|
body: string
|
|
17
|
-
/** the same invite in two lines, for any messenger: what
|
|
18
|
+
/** the same invite in two lines, for any messenger: what the owner copies from a share's line */
|
|
18
19
|
short: string
|
|
19
|
-
/** the thread
|
|
20
|
+
/** the thread on the advisors page, or the page itself: what « copy link » copies */
|
|
20
21
|
link: string
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
/** the invite for one advisor and one thread; null while the
|
|
24
|
-
* key, an email…) reads « a thread ». `head`: the
|
|
24
|
+
/** the invite for one advisor and one thread; null while the advisors page has no address. A title the scan holds (a
|
|
25
|
+
* path, a key, an email…) reads « a thread ». `head`: the view's head, the link opens the page on it */
|
|
25
26
|
export function inviteMail(advisor: Pick<Advisor, 'name' | 'email' | 'login'>, share: { title: string; owner: string; host: string | null; words?: readonly string[]; head?: string; now?: Date }): InviteMail | null {
|
|
26
27
|
if (share.host === null || share.host === '') return null
|
|
27
28
|
const title = share.title.trim()
|
|
@@ -44,6 +45,28 @@ export function inviteMail(advisor: Pick<Advisor, 'name' | 'email' | 'login'>, s
|
|
|
44
45
|
return { to: advisor.email, subject: `${share.owner} invites you to read a thread`, body, short, link }
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
/** the mail of a reset the person asked at the sign in: the sign in page, their email, the reset's code, and that
|
|
49
|
+
* nothing changes if they did not ask; nothing of any thread. The code is never in a link, as for the invite */
|
|
50
|
+
export function resetMail(advisor: Pick<Advisor, 'name' | 'email'>, o: { code: string; owner: string; host: string }): { to: string; subject: string; body: string } {
|
|
51
|
+
const signIn = `https://${o.host}/in`
|
|
52
|
+
const body = [
|
|
53
|
+
`Hello ${advisor.name},`,
|
|
54
|
+
'',
|
|
55
|
+
`Someone asked for a new password for your email on the advisors page of ${o.owner}. If it was you:`,
|
|
56
|
+
'',
|
|
57
|
+
`1. Open ${signIn}`,
|
|
58
|
+
`2. Type your email (${advisor.email}) and this code: ${o.code}`,
|
|
59
|
+
`3. Choose a new password of ${PASSWORD_MIN} characters at least.`,
|
|
60
|
+
'',
|
|
61
|
+
`The code works once, for ${RESET_MINUTES} minutes. When you use it, your old password stops working and you are signed out everywhere else.`,
|
|
62
|
+
'',
|
|
63
|
+
'If you did not ask for it, ignore this mail: your password stays as it is.',
|
|
64
|
+
'',
|
|
65
|
+
o.owner,
|
|
66
|
+
].join('\n')
|
|
67
|
+
return { to: advisor.email, subject: `Your code for a new password, from ${o.owner}`, body }
|
|
68
|
+
}
|
|
69
|
+
|
|
47
70
|
/** whether a share sends the invite: never sent, sent more than INVITE_DAYS ago, or a new code since */
|
|
48
71
|
export const inviteDue = (a: Pick<Advisor, 'lastInvited' | 'login'>, now: Date): boolean =>
|
|
49
72
|
a.lastInvited === undefined || now.getTime() - Date.parse(a.lastInvited) > INVITE_DAYS * DAY_MS || (a.login !== undefined && a.login.at > a.lastInvited)
|
package/src/advisors/job.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
// the daemon's advisors job (wiki tools/shipkit/advisors.md): every 10 s while a share is live or an ended one
|
|
2
|
-
//
|
|
3
|
-
// once when
|
|
4
|
-
//
|
|
5
|
-
|
|
1
|
+
// the daemon's advisors job (wiki tools/shipkit/advisors.md): every 10 s while a share is live or an ended one's reach
|
|
2
|
+
// is not yet said, every minute while a project's access is live on a set up advisors page (a thread they start), and
|
|
3
|
+
// once when the owner's setup token lands on the machine that carries the hq, and at its next look once a person asked
|
|
4
|
+
// a reset at the sign in. One pass: the setup when it is due (setup-run.ts), the mail of each reset that waits
|
|
5
|
+
// (invite-send.ts sendResets), then the owner's pass (sync.ts syncOnce): the logins kept equal to the grants, the read cursors pulled
|
|
6
6
|
import { DirBucket } from './dir-bucket.ts'
|
|
7
7
|
import type { Bucket } from './edge/bucket.ts'
|
|
8
8
|
import { privateWords, refreshLocal, syncOnce, type SyncReport } from './sync.ts'
|
|
9
|
-
import { advisorsDir,
|
|
9
|
+
import { advisorsDir, isLive, readState, resetWaits } from './owner-store.ts'
|
|
10
10
|
import { setOwner } from './acts.ts'
|
|
11
|
-
import {
|
|
11
|
+
import { SETUP_ASK } from './reach.ts'
|
|
12
|
+
import { houseHost, housePageFacts } from './speaks.ts'
|
|
12
13
|
import { setupDue, setupOnToken, type SetupRun } from './setup-run.ts'
|
|
13
14
|
import type { TunnelStart } from './tunnel.ts'
|
|
15
|
+
import { usersDir } from './users-store.ts'
|
|
14
16
|
|
|
15
17
|
const QUIET_MS = 60_000
|
|
16
18
|
let quietAt = 0
|
|
17
19
|
|
|
18
20
|
|
|
19
|
-
/** the
|
|
20
|
-
export const
|
|
21
|
+
/** the users' port's folder once it is set up (the state names its host), null before (users-store.ts) */
|
|
22
|
+
export const usersBucket = (dir = advisorsDir()): Bucket | null => (readState(dir).host === null ? null : new DirBucket(usersDir(dir)))
|
|
21
23
|
|
|
22
24
|
/** the « a secret landed » mark of this machine (secrets/changed-mark.ts), null with no machine db */
|
|
23
25
|
async function secretsMark(): Promise<number | null> {
|
|
@@ -32,11 +34,13 @@ async function secretsMark(): Promise<number | null> {
|
|
|
32
34
|
|
|
33
35
|
const carriesHere = async (): Promise<boolean> => (await import('../hq/hq-role.ts')).carriesHq()
|
|
34
36
|
|
|
37
|
+
|
|
35
38
|
/** a look of the daemon: the state file read (a few kB), the mark of a secret, no walk */
|
|
36
39
|
export async function advisorsDue(dir = advisorsDir(), now = new Date()): Promise<boolean> {
|
|
37
40
|
try {
|
|
38
41
|
const s = readState(dir)
|
|
39
42
|
if (setupDue(s, await secretsMark()) && (await carriesHere())) return true
|
|
43
|
+
if (s.advisors.some((a) => resetWaits(a, now))) return true
|
|
40
44
|
if (s.shares.some((x) => isLive(x, now) || (x.state !== 'pending' && x.reach?.ok !== true))) return true
|
|
41
45
|
const quiet = s.host !== null && s.access.some((x) => isLive(x, now))
|
|
42
46
|
if (!quiet || now.getTime() - quietAt < QUIET_MS) return false
|
|
@@ -51,13 +55,13 @@ export async function advisorsDue(dir = advisorsDir(), now = new Date()): Promis
|
|
|
51
55
|
* equal to it each pass; his own names are layers over it */
|
|
52
56
|
export async function nameOwner(dir: string, house: string | null): Promise<void> {
|
|
53
57
|
if (house === null) return
|
|
54
|
-
// a house config or identity that does not load leaves the name as it is: the
|
|
58
|
+
// a house config or identity that does not load leaves the name as it is: the pass never waits on it
|
|
55
59
|
const id = await housePageFacts(house).then((f) => f.id, () => null)
|
|
56
60
|
if (id !== null && readState(dir).owner !== id) setOwner(dir, { owner: id }, 'owner')
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
/** one pass:
|
|
60
|
-
*
|
|
63
|
+
/** one pass: the owner's pass over the users' port's folder once it is set up, else each live share's masked entries
|
|
64
|
+
* refreshed for the owner's preview */
|
|
61
65
|
export async function advisorsPass(o: { house: string | null; cwd: string; dir?: string; now?: Date; tunnel?: TunnelStart }): Promise<SyncReport | { local: true }> {
|
|
62
66
|
const dir = o.dir ?? advisorsDir()
|
|
63
67
|
await nameOwner(dir, o.house)
|
|
@@ -66,15 +70,19 @@ export async function advisorsPass(o: { house: string | null; cwd: string; dir?:
|
|
|
66
70
|
if (setupDue(readState(dir), mark) && (await carriesHere())) await setupHere(dir, o.house, { mark, ...(o.tunnel ? { tunnel: o.tunnel } : {}) })
|
|
67
71
|
}
|
|
68
72
|
const words = privateWords(o.house)
|
|
69
|
-
|
|
73
|
+
if (o.house !== null && readState(dir).advisors.some((a) => resetWaits(a, o.now ?? new Date()))) {
|
|
74
|
+
const { houseMailer, sendResets } = await import('./invite-send.ts')
|
|
75
|
+
await sendResets(dir, { now: o.now ?? new Date(), words, mailer: houseMailer(o.house) })
|
|
76
|
+
}
|
|
77
|
+
const bucket = usersBucket(dir)
|
|
70
78
|
if (bucket === null) {
|
|
71
79
|
await refreshLocal(dir, { words, ...(o.now ? { now: o.now } : {}) })
|
|
72
80
|
return { local: true }
|
|
73
81
|
}
|
|
74
|
-
return syncOnce(dir, { bucket, words,
|
|
82
|
+
return syncOnce(dir, { bucket, words, ...(o.now ? { now: o.now } : {}) })
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
/**
|
|
85
|
+
/** the owner's « set the advisors page up now »: one run whatever the marks say, on the machine that carries the hq, else why not.
|
|
78
86
|
* `run` ends with the run (null when one ran already); its lines land on the page's foot as they end */
|
|
79
87
|
export async function setupAsked(dir: string, house: string, tunnel?: TunnelStart): Promise<{ refused: string } | { run: Promise<SetupRun | null> }> {
|
|
80
88
|
if (!(await carriesHere())) return { refused: 'this Mac does not carry the hq: the advisors page is set up on the Mac that does' }
|
|
@@ -108,6 +116,6 @@ async function tellAsk(house: string, ok: boolean, text: string): Promise<void>
|
|
|
108
116
|
const { postUpdate, readAll, storeDir } = await import('../review/store.ts')
|
|
109
117
|
const { threadsOf } = await import('../review/threads.ts')
|
|
110
118
|
const { ownAddressOf } = await import('../review/model.ts')
|
|
111
|
-
const t = threadsOf(readAll(storeDir(house)).items).find((x) =>
|
|
119
|
+
const t = threadsOf(readAll(storeDir(house)).items).find((x) => SETUP_ASK.test(ownAddressOf(x.head.item) ?? ''))
|
|
112
120
|
if (t !== undefined) await postUpdate(storeDir(house), t.head.item.id, { who: 'advisors page', state: ok ? 'fixed' : 'broken', text, machine: true })
|
|
113
121
|
}
|
package/src/advisors/login.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
// a person's sign in
|
|
2
|
-
// sets the password they choose at `https://<host>/in`; then their email and that
|
|
3
|
-
// code's hash (
|
|
4
|
-
// breaks first: only a person with a live grant is in the
|
|
5
|
-
// sessions end; a new code (`gen` + 1) ends their password and every session
|
|
1
|
+
// a person's sign in on the advisors page (wiki tools/shipkit/advisors.md, Who calls: the users' port): a one
|
|
2
|
+
// time code the invite carries, which sets the password they choose at `https://<host>/in`; then their email and that
|
|
3
|
+
// password. The users' port reads only the code's hash (users-store.ts liveLogins) and keeps the password's argon2id
|
|
4
|
+
// hash in its folder. The one constraint a reader breaks first: only a person with a live grant is in the sign in's
|
|
5
|
+
// list, so with none they cannot sign in and their sessions end; a new code (`gen` + 1) ends their password and every session.
|
|
6
|
+
// A reset the person asks is that next generation parked on the login (`reset`): nothing ends until its code signs in
|
|
6
7
|
import { createHash, randomBytes } from 'node:crypto'
|
|
7
8
|
import { ownerOnly, type Actor } from './acts.ts'
|
|
9
|
+
import { RESET_MINUTES } from './edge/sign-in.ts'
|
|
8
10
|
import { advisorOf, granted, isLive, withState, type Advisor, type Login, type OwnerState } from './owner-store.ts'
|
|
9
11
|
|
|
10
12
|
export const sha256 = (s: string): string => createHash('sha256').update(s).digest('hex')
|
|
@@ -12,14 +14,16 @@ export const sha256 = (s: string): string => createHash('sha256').update(s).dige
|
|
|
12
14
|
export const CODE_DAYS = 7
|
|
13
15
|
const CODE_CHARS = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789'
|
|
14
16
|
|
|
15
|
-
/** 10 characters of 31, no look alikes: about 50 bits, behind the
|
|
17
|
+
/** 10 characters of 31, no look alikes: about 50 bits, behind the sign in's limits on tries */
|
|
16
18
|
export function newCode(): string {
|
|
17
19
|
let out = ''
|
|
18
20
|
while (out.length < 10) for (const b of randomBytes(16)) if (b < 248 && out.length < 10) out += CODE_CHARS[b % CODE_CHARS.length]
|
|
19
21
|
return out
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
const mint = (gen: number, now: Date): Login => ({ gen, code: newCode(), codeUntil: new Date(now.getTime() +
|
|
24
|
+
const mint = (gen: number, now: Date, ms = CODE_DAYS * 86_400_000): Login => ({ gen, code: newCode(), codeUntil: new Date(now.getTime() + ms).toISOString(), at: now.toISOString() })
|
|
25
|
+
/** the generation after the login and its parked reset: a code of a reset never shares a generation with another */
|
|
26
|
+
const nextGen = (l: Login | undefined): number => Math.max(l?.gen ?? 0, l?.reset?.gen ?? 0) + 1
|
|
23
27
|
|
|
24
28
|
/** the person's login, minted when they hold none; call inside withState */
|
|
25
29
|
export function ensureLogin(a: Advisor, now: Date): Login {
|
|
@@ -31,36 +35,57 @@ export function ensureLogin(a: Advisor, now: Date): Login {
|
|
|
31
35
|
* with no password to end); call inside withState */
|
|
32
36
|
export function codeToSend(a: Advisor, now: Date): Login {
|
|
33
37
|
const l = ensureLogin(a, now)
|
|
34
|
-
if (l.used !== true && liveCode(l, now) === null) a.login = mint(l
|
|
38
|
+
if (l.used !== true && liveCode(l, now) === null) a.login = mint(nextGen(l), now)
|
|
35
39
|
return a.login!
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
/** the code an invite carries: null once it was used or it ended */
|
|
39
43
|
export const liveCode = (l: Login | undefined, now: Date): string | null => (l === undefined || l.used === true || Date.parse(l.codeUntil) <= now.getTime() ? null : l.code)
|
|
40
44
|
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
* Call inside withState */
|
|
45
|
+
/** a password set at generation `gen`, as the users' port's folder holds it: the login's own code is spent, a parked
|
|
46
|
+
* reset of that generation becomes the login (the old password and its sessions end with the old generation); a reset
|
|
47
|
+
* past its end is dropped. Call inside withState */
|
|
48
|
+
export function spend(a: Advisor, gen: number | undefined, now: Date): void {
|
|
49
|
+
const l = a.login
|
|
50
|
+
if (l === undefined) return
|
|
51
|
+
if (gen === l.gen && l.used !== true) l.used = true
|
|
52
|
+
else if (l.reset !== undefined && gen === l.reset.gen) a.login = { ...l.reset, used: true }
|
|
53
|
+
if (a.login?.reset !== undefined && Date.parse(a.login.reset.codeUntil) <= now.getTime()) delete a.login.reset
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** each person with a live grant by email, their login minted when they hold none: its generation, the code's hash and
|
|
57
|
+
* end, the end of their last grant. `used`: the generation whose code set a password, by email, as the port's folder
|
|
58
|
+
* holds it. Call inside withState */
|
|
44
59
|
export function keepLogins(s: OwnerState, now: Date, used: ReadonlyMap<string, number> = new Map()): Record<string, { gen: number; code: string; codeUntil: string; until: string }> {
|
|
45
60
|
const live = granted(s, now)
|
|
46
61
|
const out: Record<string, { gen: number; code: string; codeUntil: string; until: string }> = {}
|
|
47
62
|
for (const a of s.advisors) {
|
|
48
63
|
if (!live.has(a.id)) continue
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
ensureLogin(a, now)
|
|
65
|
+
spend(a, used.get(a.email), now)
|
|
66
|
+
const l = a.login!
|
|
51
67
|
const until = [...s.shares, ...s.access].filter((x) => x.advisor === a.id && isLive(x, now)).map((x) => x.expires).sort().at(-1)!
|
|
52
68
|
out[a.email] = { gen: l.gen, code: sha256(l.code), codeUntil: l.codeUntil, until }
|
|
53
69
|
}
|
|
54
70
|
return out
|
|
55
71
|
}
|
|
56
72
|
|
|
57
|
-
/**
|
|
73
|
+
/** the owner's « send a new code »: the next generation, so their password and every session end at their next request */
|
|
58
74
|
export function renewLogin(dir: string, person: string, actor: Actor, now: Date): Advisor {
|
|
59
75
|
ownerOnly(actor, 'a new code')
|
|
60
76
|
return withState(dir, (s) => {
|
|
61
77
|
const a = advisorOf(s, person)
|
|
62
78
|
if (!granted(s, now).has(a.id)) throw new Error(`${a.name} holds nothing live: share something first`)
|
|
63
|
-
a.login = mint((a.login
|
|
79
|
+
a.login = mint(nextGen(a.login), now)
|
|
64
80
|
return a
|
|
65
81
|
})
|
|
66
82
|
}
|
|
83
|
+
|
|
84
|
+
/** a reset the person asked at the sign in: the next generation parked on their login with a code for RESET_MINUTES,
|
|
85
|
+
* null when they hold no live grant or no login. Their password and sessions stay until that code signs in. Call
|
|
86
|
+
* inside withState */
|
|
87
|
+
export function parkReset(s: OwnerState, a: Advisor, now: Date): Login | null {
|
|
88
|
+
if (a.login === undefined || !granted(s, now).has(a.id)) return null
|
|
89
|
+
a.login.reset = mint(nextGen(a.login), now, RESET_MINUTES * 60_000)
|
|
90
|
+
return a.login.reset
|
|
91
|
+
}
|