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
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
// the
|
|
2
|
-
// and the one time code of the invite set the password the person chooses; then
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// the sign in of the advisors page (wiki tools/shipkit/advisors.md, Who calls: the users' port): `/in`, one form,
|
|
2
|
+
// no script. The first time, an email and the one time code of the invite set the password the person chooses; then
|
|
3
|
+
// an email and that password. A lost password: `/reset` asks a code by mail, which sets a new password the same way.
|
|
4
|
+
// Each opens a session: a random id in an httpOnly cookie, its hash a file under the person. The one constraint a
|
|
5
|
+
// reader breaks first: every check reads the list the owner's store gives at the request (a person with no live grant
|
|
6
|
+
// is not in it), every failed try counts against the email and the caller, and no answer says whether an email has access
|
|
6
7
|
import { getJson, type Bucket } from './bucket.ts'
|
|
7
8
|
import { bytesOf } from './form.ts'
|
|
8
|
-
import { esc, renderPage, type Page } from './status.ts'
|
|
9
|
-
import { KEYS, type
|
|
9
|
+
import { boxOf, esc, renderPage, type Page } from './status.ts'
|
|
10
|
+
import { KEYS, type SignInList } from './types.ts'
|
|
10
11
|
|
|
11
|
-
/** what hashes and checks a password: argon2id, given by the
|
|
12
|
+
/** what hashes and checks a password: argon2id, given by the users' port (users-listen.ts) */
|
|
12
13
|
export interface PasswordHasher {
|
|
13
14
|
hash: (password: string) => Promise<string>
|
|
14
15
|
verify: (password: string, hash: string) => Promise<boolean>
|
|
@@ -34,24 +35,32 @@ export const sameText = (a: string, b: string): boolean => {
|
|
|
34
35
|
return d === 0
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
/** the tries in the last window that did not sign in, by key (`ip:<caller>`, `email:<email>`)
|
|
38
|
+
/** the tries in the last window that did not sign in, by key (`ip:<caller>`, `email:<email>`), and the resets asked
|
|
39
|
+
* (`reset-ip:<caller>`, `reset-email:<email>`) */
|
|
38
40
|
export interface Limits {
|
|
39
41
|
tries: Map<string, number[]>
|
|
40
42
|
}
|
|
41
43
|
export const limits = (): Limits => ({ tries: new Map() })
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
44
|
+
/** each kind of key: how many in how long, in the port's memory (a restart of the port starts them again). A reset
|
|
45
|
+
* asked mails a person at most 3 times an hour and 5 a day, whoever asks */
|
|
46
|
+
const CAPS: Record<string, { most: number; ms: number }> = {
|
|
47
|
+
email: { most: 10, ms: 10 * 60_000 },
|
|
48
|
+
ip: { most: 20, ms: 10 * 60_000 },
|
|
49
|
+
'reset-email': { most: 3, ms: 3_600_000 },
|
|
50
|
+
'reset-day': { most: 5, ms: 86_400_000 },
|
|
51
|
+
'reset-ip': { most: 10, ms: 3_600_000 },
|
|
52
|
+
}
|
|
53
|
+
const capOf = (k: string): { most: number; ms: number } => CAPS[k.slice(0, k.indexOf(':'))]!
|
|
45
54
|
|
|
46
55
|
const kept = (l: Limits, k: string, now: number): number[] => {
|
|
47
|
-
const ts = (l.tries.get(k) ?? []).filter((t) => t > now -
|
|
56
|
+
const ts = (l.tries.get(k) ?? []).filter((t) => t > now - capOf(k).ms)
|
|
48
57
|
if (ts.length === 0) l.tries.delete(k)
|
|
49
58
|
else l.tries.set(k, ts)
|
|
50
59
|
return ts
|
|
51
60
|
}
|
|
52
61
|
/** a try counted before any wait, so tries sent at once meet the limit too; a sign in takes its own back */
|
|
53
62
|
function take(l: Limits, keys: readonly string[], now: number): (() => void) | null {
|
|
54
|
-
if (keys.some((k) => kept(l, k, now).length >= (k.
|
|
63
|
+
if (keys.some((k) => kept(l, k, now).length >= capOf(k).most)) return null
|
|
55
64
|
for (const k of keys) l.tries.set(k, [...(l.tries.get(k) ?? []), now])
|
|
56
65
|
return () => {
|
|
57
66
|
for (const k of keys) {
|
|
@@ -66,31 +75,75 @@ function take(l: Limits, keys: readonly string[], now: number): (() => void) | n
|
|
|
66
75
|
let dummy: Promise<string> | null = null
|
|
67
76
|
const DUMMY_PASSWORD = 'no password matches this one'
|
|
68
77
|
|
|
69
|
-
/** the
|
|
70
|
-
export
|
|
71
|
-
|
|
78
|
+
/** the page that asks a reset: no session, no read of the folder */
|
|
79
|
+
export const RESET_PATH = '/reset'
|
|
80
|
+
/** the words of a sign in that did not match: which field is wrong is never said, so they say what to try */
|
|
81
|
+
export const NO_MATCH = 'Check your email and password. The code field is only for your first sign in or a reset.'
|
|
82
|
+
const FORGOT = { href: RESET_PATH, text: 'Forgot your password?' }
|
|
83
|
+
const FIELD = 'font:inherit;width:100%;max-width:360px;padding:6px;box-sizing:border-box'
|
|
84
|
+
const BUTTON = 'font:inherit;padding:6px 14px'
|
|
85
|
+
const field = (name: string, label: string, type: string, extra = ''): string => `<p><label>${esc(label)}<br><input name="${name}" type="${type}" ${extra} style="${FIELD}"></label></p>`
|
|
86
|
+
|
|
87
|
+
/** what went wrong on the sign in: the words, and whether the box offers the reset */
|
|
88
|
+
export type Said = { text: string; forgot: boolean }
|
|
89
|
+
|
|
90
|
+
/** the form, with a red box of what went wrong above it */
|
|
91
|
+
export function signInPage(owner: string, said?: Said): Page {
|
|
72
92
|
return renderPage(
|
|
73
93
|
'Sign in, rv advisors',
|
|
74
94
|
[
|
|
75
95
|
'<h1>Sign in</h1>',
|
|
76
|
-
said !== undefined ?
|
|
96
|
+
said !== undefined ? boxOf('bad', said.text, said.forgot ? FORGOT : undefined) : '',
|
|
77
97
|
'<form method="post" action="/in">',
|
|
78
98
|
field('email', 'Your email', 'email', 'required autocomplete="email"'),
|
|
79
|
-
field('code', '
|
|
80
|
-
field('password', `Your password (
|
|
81
|
-
|
|
99
|
+
field('code', 'A code: of your invite the first time, or of a reset', 'text', 'autocomplete="one-time-code"'),
|
|
100
|
+
field('password', `Your password (with a code, choose a new one: ${PASSWORD_MIN} characters at least)`, 'password', 'required autocomplete="current-password"'),
|
|
101
|
+
`<p><button type="submit" style="${BUTTON}">Sign in</button></p>`,
|
|
82
102
|
'</form>',
|
|
83
|
-
`<p class="dim">${esc(`A
|
|
103
|
+
`<p><a href="${RESET_PATH}">Forgot your password?</a> <span class="dim">${esc(`A code goes to your email. Or ask ${owner} for a new one.`)}</span></p>`,
|
|
104
|
+
'<p class="dim"><a href="/about">About rv advisors</a></p>',
|
|
84
105
|
].join(''),
|
|
85
106
|
// the page of the one form that navigates: under `no-referrer` a browser posts it with `Origin: null`
|
|
86
107
|
'same-origin',
|
|
87
108
|
)
|
|
88
109
|
}
|
|
89
110
|
|
|
90
|
-
|
|
111
|
+
/** a reset's code lives this long (login.ts parks it) */
|
|
112
|
+
export const RESET_MINUTES = 30
|
|
113
|
+
|
|
114
|
+
/** the reset's form, or its one answer once sent: the same words whatever the email, so the page says nothing of who
|
|
115
|
+
* has access */
|
|
116
|
+
export function resetPage(o: { sent: boolean; said?: string }): Page {
|
|
117
|
+
const minutes = RESET_MINUTES
|
|
118
|
+
const body = o.sent
|
|
119
|
+
? ['<h1>Check your email</h1>', boxOf('ok', `If this email has access, a code is on its way. It works once, for ${minutes} minutes.`), `<p>${esc('Then sign in with your email, that code and a new password. Your old password works until you use the code.')}</p>`, `<p><a href="/in">Sign in</a></p>`]
|
|
120
|
+
: [
|
|
121
|
+
'<h1>Forgot your password?</h1>',
|
|
122
|
+
o.said !== undefined ? boxOf('bad', o.said) : '',
|
|
123
|
+
`<p>${esc(`Type the email your invite went to. If it has access, a code goes to it, for ${minutes} minutes. Your old password works until you use the code.`)}</p>`,
|
|
124
|
+
`<form method="post" action="${RESET_PATH}">`,
|
|
125
|
+
field('email', 'Your email', 'email', 'required autocomplete="email"'),
|
|
126
|
+
`<p><button type="submit" style="${BUTTON}">Send me a code</button></p>`,
|
|
127
|
+
'</form>',
|
|
128
|
+
'<p><a href="/in">Back to the sign in</a></p>',
|
|
129
|
+
]
|
|
130
|
+
return renderPage('Reset your password, rv advisors', body.join(''), 'same-origin')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** one reset asked by the form: the email the owner's side mails a code to when it has access, null while the caller or
|
|
134
|
+
* the email asked too many. Counted before anything else, the same for every email, and never given back */
|
|
135
|
+
export async function askReset(req: Request, o: { limits: Limits; now: number }): Promise<{ email: string } | null> {
|
|
136
|
+
const body = await bytesOf(req, 4096)
|
|
137
|
+
const form = new URLSearchParams(body === null ? '' : new TextDecoder().decode(body))
|
|
138
|
+
const email = (form.get('email') ?? '').trim().toLowerCase()
|
|
139
|
+
if (take(o.limits, [`reset-ip:${req.headers.get('cf-connecting-ip') ?? 'local'}`, `reset-email:${email}`, `reset-day:${email}`], o.now) === null) return null
|
|
140
|
+
return { email: email.length <= 254 ? email : '' }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type SignIn = { ok: true; cookie: string } | { ok: false; status: number; said: Said }
|
|
91
144
|
|
|
92
145
|
/** one try of the form: a session, or why not */
|
|
93
|
-
export async function signIn(req: Request, o: { bucket: Bucket;
|
|
146
|
+
export async function signIn(req: Request, o: { bucket: Bucket; logins: SignInList; now: number; limits: Limits; password?: PasswordHasher | undefined }): Promise<SignIn> {
|
|
94
147
|
const body = await bytesOf(req, 4096)
|
|
95
148
|
const form = new URLSearchParams(body === null ? '' : new TextDecoder().decode(body))
|
|
96
149
|
const email = (form.get('email') ?? '').trim().toLowerCase()
|
|
@@ -98,22 +151,34 @@ export async function signIn(req: Request, o: { bucket: Bucket; file: SharesFile
|
|
|
98
151
|
const password = form.get('password') ?? ''
|
|
99
152
|
const keys = [`ip:${req.headers.get('cf-connecting-ip') ?? 'local'}`, `email:${email}`]
|
|
100
153
|
const back = take(o.limits, keys, o.now)
|
|
101
|
-
if (back === null) return { ok: false, status: 429, said: 'Too many tries: wait a few minutes.' }
|
|
154
|
+
if (back === null) return { ok: false, status: 429, said: { text: 'Too many tries: wait a few minutes.', forgot: true } }
|
|
102
155
|
const hasher = o.password
|
|
103
|
-
if (hasher === undefined) return { ok: false, status: 503, said: 'Signing in is not open right now.' }
|
|
104
|
-
const no = async (
|
|
156
|
+
if (hasher === undefined) return { ok: false, status: 503, said: { text: 'Signing in is not open right now.', forgot: false } }
|
|
157
|
+
const no = async (): Promise<SignIn> => {
|
|
105
158
|
await hasher.verify(DUMMY_PASSWORD, await (dummy ??= hasher.hash(DUMMY_PASSWORD))).catch(() => false)
|
|
106
|
-
return { ok: false, status: 401, said }
|
|
159
|
+
return { ok: false, status: 401, said: { text: NO_MATCH, forgot: true } }
|
|
107
160
|
}
|
|
108
|
-
const
|
|
161
|
+
const short: SignIn = { ok: false, status: 400, said: { text: `Choose a password of ${PASSWORD_MIN} characters at least.`, forgot: false } }
|
|
162
|
+
const entry = o.logins[email]
|
|
109
163
|
if (entry === undefined || Date.parse(entry.until) <= o.now || password.length > PASSWORD_MAX) return no()
|
|
110
164
|
const eh = await sha256(email)
|
|
111
165
|
const held = await getJson<{ gen: number; hash: string }>(o.bucket, KEYS.password(eh))
|
|
112
166
|
const has = held !== null && held.gen === entry.gen && typeof held.hash === 'string'
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
167
|
+
const typed = code === '' ? '' : await sha256(code)
|
|
168
|
+
const reset = entry.reset
|
|
169
|
+
let gen = entry.gen
|
|
170
|
+
if (reset !== undefined && typed !== '' && Date.parse(reset.codeUntil) > o.now && sameText(typed, reset.code)) {
|
|
171
|
+
// the code of a reset they asked: the new password is the next generation's, and every session of theirs ends
|
|
172
|
+
if (password.length < PASSWORD_MIN) return short
|
|
173
|
+
if (!(await o.bucket.claim(KEYS.claim(eh, reset.gen)))) return no()
|
|
174
|
+
await o.bucket.put(KEYS.password(eh), JSON.stringify({ gen: reset.gen, hash: await hasher.hash(password) }), 'application/json')
|
|
175
|
+
for (const k of await o.bucket.list(KEYS.sessions(eh))) await o.bucket.delete(k)
|
|
176
|
+
gen = reset.gen
|
|
177
|
+
} else if (typed !== '' && !has) {
|
|
178
|
+
// once a password is set the code field is ignored: a password manager that fills it never blocks the password.
|
|
179
|
+
// The code works once: a password set with it ends it, and so does its date
|
|
180
|
+
if (Date.parse(entry.codeUntil) <= o.now || !sameText(typed, entry.code)) return no()
|
|
181
|
+
if (password.length < PASSWORD_MIN) return short
|
|
117
182
|
// two first sign ins at once: only one claims the code
|
|
118
183
|
if (!(await o.bucket.claim(KEYS.claim(eh, entry.gen)))) return no()
|
|
119
184
|
await o.bucket.put(KEYS.password(eh), JSON.stringify({ gen: entry.gen, hash: await hasher.hash(password) }), 'application/json')
|
|
@@ -121,13 +186,13 @@ export async function signIn(req: Request, o: { bucket: Bucket; file: SharesFile
|
|
|
121
186
|
back()
|
|
122
187
|
const sid = b64url(crypto.getRandomValues(new Uint8Array(32)))
|
|
123
188
|
const until = Math.min(o.now + SESSION_MAX_MS, Date.parse(entry.until))
|
|
124
|
-
await o.bucket.put(KEYS.session(eh, await sha256(sid)), JSON.stringify({ email, gen
|
|
189
|
+
await o.bucket.put(KEYS.session(eh, await sha256(sid)), JSON.stringify({ email, gen, until: new Date(until).toISOString() }), 'application/json')
|
|
125
190
|
return { ok: true, cookie: `${SESSION_COOKIE}=${eh}.${sid}; Path=/; Max-Age=${Math.floor((until - o.now) / 1000)}; HttpOnly; Secure; SameSite=Lax` }
|
|
126
191
|
}
|
|
127
192
|
|
|
128
193
|
/** who a request's session is: their email and the hash of the session; null for none, a forged one, an ended one, or
|
|
129
194
|
* one of a person no longer in the list or past a new code */
|
|
130
|
-
export async function sessionOf(req: Request, o: { bucket: Bucket;
|
|
195
|
+
export async function sessionOf(req: Request, o: { bucket: Bucket; logins: SignInList; now: number }): Promise<{ email: string; login: string } | null> {
|
|
131
196
|
let raw = ''
|
|
132
197
|
for (const part of (req.headers.get('cookie') ?? '').split(';')) {
|
|
133
198
|
const [k, ...v] = part.trim().split('=')
|
|
@@ -138,7 +203,7 @@ export async function sessionOf(req: Request, o: { bucket: Bucket; file: SharesF
|
|
|
138
203
|
const sh = await sha256(m[2]!)
|
|
139
204
|
const s = await getJson<{ email: string; gen: number; until: string }>(o.bucket, KEYS.session(m[1]!, sh))
|
|
140
205
|
if (s === null || typeof s.email !== 'string' || (await sha256(s.email)) !== m[1]) return null
|
|
141
|
-
const entry = o.
|
|
206
|
+
const entry = o.logins[s.email]
|
|
142
207
|
if (entry === undefined || entry.gen !== s.gen || Date.parse(s.until) <= o.now || Date.parse(entry.until) <= o.now) return null
|
|
143
208
|
return { email: s.email, login: sh }
|
|
144
209
|
}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
// the
|
|
2
|
-
// and the two public pages, with no script, every text escaped. Every other page is the advisors' app
|
|
1
|
+
// the server rendered pages of the users' port (wiki tools/shipkit/advisors.md, Who calls: the users' port): 403,
|
|
2
|
+
// 404, 503, « method not allowed » and the two public pages, with no script, every text escaped. Every other page is the advisors' app
|
|
3
3
|
export const esc = (s: string): string => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''')
|
|
4
4
|
|
|
5
|
-
const STYLE =
|
|
5
|
+
const STYLE = [
|
|
6
|
+
':root{color-scheme:light dark;--bg:#fbfaf7;--fg:#1d1c1a;--dim:#6b6862;--bad-bg:#fdecea;--bad-line:#d93025;--bad-fg:#8c1d18;--ok-bg:#eaf3ec;--ok-line:#2e7d4f;--ok-fg:#1d4d31}',
|
|
7
|
+
'@media (prefers-color-scheme:dark){:root{--bg:#161614;--fg:#ecebe6;--dim:#9a978f;--bad-bg:#3a1714;--bad-line:#f2756a;--bad-fg:#ffd9d4;--ok-bg:#15301f;--ok-line:#6cc58e;--ok-fg:#d3f2de}}',
|
|
8
|
+
'body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.5 system-ui,-apple-system,sans-serif}main{max-width:640px;margin:0 auto;padding:32px 16px}h1{font-size:20px;margin:0 0 6px}h2{font-size:16px;margin:24px 0 4px}ul{margin:4px 0;padding-left:20px}.dim{color:var(--dim)}a{color:inherit}',
|
|
9
|
+
'.box{display:flex;gap:10px;align-items:flex-start;max-width:360px;margin:14px 0;padding:10px 12px;border:1px solid;border-left-width:4px;border-radius:6px}.box p{margin:0}.box a{white-space:nowrap}.box .ic{flex:none;width:20px;height:20px;border-radius:50%;color:var(--bg);font:700 13px/20px system-ui,sans-serif;text-align:center}',
|
|
10
|
+
'.box.bad{background:var(--bad-bg);border-color:var(--bad-line);color:var(--bad-fg)}.box.bad .ic{background:var(--bad-line)}.box.ok{background:var(--ok-bg);border-color:var(--ok-line);color:var(--ok-fg)}.box.ok .ic{background:var(--ok-line)}',
|
|
11
|
+
].join('')
|
|
12
|
+
|
|
13
|
+
/** a box above a form: `bad` what went wrong (`role="alert"`, read out as it shows), `ok` what happened (`role="status"`);
|
|
14
|
+
* `text` escaped, `link` a path of the page and its words */
|
|
15
|
+
export function boxOf(kind: 'bad' | 'ok', text: string, link?: { href: string; text: string }): string {
|
|
16
|
+
const more = link === undefined ? '' : ` <a href="${esc(link.href)}">${esc(link.text)}</a>`
|
|
17
|
+
return `<div class="box ${kind}" role="${kind === 'bad' ? 'alert' : 'status'}"><span class="ic" aria-hidden="true">${kind === 'bad' ? '!' : '✓'}</span><p>${esc(text)}${more}</p></div>`
|
|
18
|
+
}
|
|
6
19
|
|
|
7
20
|
/** `same-origin` on a page whose form navigates: under `no-referrer` a browser posts it with `Origin: null`, which the
|
|
8
|
-
*
|
|
21
|
+
* users' port refuses. Every other page sends none */
|
|
9
22
|
export type Referrer = 'no-referrer' | 'same-origin'
|
|
10
23
|
|
|
11
|
-
/** a page of the
|
|
12
|
-
* they never disagree (in a browser the meta wins over the header) */
|
|
24
|
+
/** a page of the advisors page and the referrer policy it carries: its meta and its response's header both read
|
|
25
|
+
* `referrer`, so they never disagree (in a browser the meta wins over the header) */
|
|
13
26
|
export interface Page {
|
|
14
27
|
html: string
|
|
15
28
|
referrer: Referrer
|
|
@@ -1,56 +1,41 @@
|
|
|
1
|
-
// the advisors
|
|
2
|
-
//
|
|
1
|
+
// the shapes of the advisors page (wiki tools/shipkit/advisors.md): the list the sign in reads, what a person sends,
|
|
2
|
+
// the keys of the users' port's folder. The edge folder imports its own siblings only, no node builtin (tests/advisors-edge.test.ts)
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
/** the advisor's email, lowercased: the session's login must be theirs */
|
|
7
|
-
email: string
|
|
8
|
-
name: string
|
|
9
|
-
/** ISO time: past it the door refuses the share on its own clock */
|
|
10
|
-
expires: string
|
|
11
|
-
project: string
|
|
12
|
-
title: string
|
|
13
|
-
/** the hash of the advisor's own photo at `photo/<sha>.webp`: served to that advisor alone */
|
|
14
|
-
photo?: string
|
|
15
|
-
/** his name as this share's project reads it, scanned */
|
|
16
|
-
owner?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** a project an advisor is enabled on, as the door reads it from `shares.json` on every request: the one place an
|
|
20
|
-
* advisor may start a thread, by its id (128 random bits). Gone the moment he disables the advisor there */
|
|
4
|
+
/** a project an advisor is enabled on, read from the owner's store at the request (sync.ts projectsOf): the one place
|
|
5
|
+
* an advisor may start a thread, by its id (128 random bits). Gone the moment the owner disables the advisor there */
|
|
21
6
|
export interface ServedProject {
|
|
22
7
|
email: string
|
|
23
8
|
name: string
|
|
24
9
|
/** the project's display name, scanned */
|
|
25
10
|
project: string
|
|
26
|
-
/**
|
|
11
|
+
/** the owner's name, as the advisor reads it */
|
|
27
12
|
owner: string
|
|
28
|
-
/** as ServedShare's */
|
|
29
|
-
photo?: string
|
|
30
13
|
}
|
|
31
14
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/** the page's two files the door serves, `<js sha>.<css sha>` */
|
|
42
|
-
app?: string
|
|
15
|
+
/** one person who may sign in: their login's generation, the sha256 (hex) of their one time code and its end, the
|
|
16
|
+
* end of their last grant; a reset they asked: the next generation, its code's hash and end. The code itself never
|
|
17
|
+
* leaves the owner's store */
|
|
18
|
+
export interface SignInEntry {
|
|
19
|
+
gen: number
|
|
20
|
+
code: string
|
|
21
|
+
codeUntil: string
|
|
22
|
+
until: string
|
|
23
|
+
reset?: { gen: number; code: string; codeUntil: string }
|
|
43
24
|
}
|
|
44
25
|
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
26
|
+
/** the list the sign in reads (edge/sign-in.ts): each person with a live grant, by email, built from the owner's store at
|
|
27
|
+
* each request (users-store.ts liveLogins) */
|
|
28
|
+
export type SignInList = Record<string, SignInEntry>
|
|
29
|
+
|
|
30
|
+
/** what the users' port checks a read or a write of one share against, made with its view at the request (sync.ts
|
|
31
|
+
* manifestOf): the ids its routes may name, the pictures it may serve, what may be answered. Opaque ids only (advisors/project.ts) */
|
|
47
32
|
export interface ShareManifest {
|
|
48
33
|
v: 1
|
|
49
|
-
/** the
|
|
34
|
+
/** the view's head: the thread's id on the advisors page */
|
|
50
35
|
head: string
|
|
51
|
-
/** every item and cell id of the
|
|
36
|
+
/** every item and cell id of the view */
|
|
52
37
|
ids: string[]
|
|
53
|
-
/** every served picture of the
|
|
38
|
+
/** every served picture of the view, by sha */
|
|
54
39
|
images: string[]
|
|
55
40
|
/** each version that waits for a verdict: its id, and its count of views in the store (an advice on fewer is stale) */
|
|
56
41
|
judge: { item: string; version: number }[]
|
|
@@ -61,7 +46,7 @@ export interface ShareManifest {
|
|
|
61
46
|
export const ADVICE_KINDS = ['pick', 'approve', 'change', 'words'] as const
|
|
62
47
|
export type AdviceKind = (typeof ADVICE_KINDS)[number]
|
|
63
48
|
|
|
64
|
-
/** one advice as
|
|
49
|
+
/** one advice as a person sends it (users-router.ts, advice.ts landAdvice): hostile input, read with a strict schema */
|
|
65
50
|
export interface AdviceWire {
|
|
66
51
|
v: 1
|
|
67
52
|
at: string
|
|
@@ -79,8 +64,8 @@ export interface AdviceWire {
|
|
|
79
64
|
files?: UploadWire[]
|
|
80
65
|
}
|
|
81
66
|
|
|
82
|
-
/** a file an advisor sent, as its
|
|
83
|
-
*
|
|
67
|
+
/** a file an advisor sent, as its entry names it: what the form said, never trusted. The bytes wait in the port's
|
|
68
|
+
* folder under the entry, quarantined, until the owner accepts or declines */
|
|
84
69
|
export interface UploadWire {
|
|
85
70
|
n: number
|
|
86
71
|
name: string
|
|
@@ -88,7 +73,8 @@ export interface UploadWire {
|
|
|
88
73
|
type: string
|
|
89
74
|
}
|
|
90
75
|
|
|
91
|
-
/** a thread an advisor proposes on a project
|
|
76
|
+
/** a thread an advisor proposes on a project (advice.ts landProposal): hostile input, pending in the owner's store or
|
|
77
|
+
* direct by the person's rights */
|
|
92
78
|
export interface ProposalWire {
|
|
93
79
|
v: 1
|
|
94
80
|
at: string
|
|
@@ -110,36 +96,26 @@ export const FILE_MAX = 25 * 1024 * 1024
|
|
|
110
96
|
export const FILES_MAX = 5
|
|
111
97
|
export const UPLOADS_PENDING_MAX = 40
|
|
112
98
|
export const FILE_NAME_MAX = 120
|
|
113
|
-
/** an
|
|
99
|
+
/** an entry's name, `<ms>-<random>`: the uploads of the entry sit under it */
|
|
114
100
|
export const ENTRY_RE = /^\d{13}-[A-Za-z0-9_-]{1,32}$/
|
|
115
101
|
|
|
116
102
|
export const KEYS = {
|
|
117
|
-
shares: 'shares.json',
|
|
118
103
|
csrf: 'csrf.key',
|
|
119
|
-
/** a person's password as the
|
|
104
|
+
/** a person's password as the sign in wrote it, by the sha256 of their email: `{ gen, hash }` */
|
|
120
105
|
password: (emailHash: string): string => `login/${emailHash}.json`,
|
|
121
106
|
/** a code's one use, made once by the sign in that spends it */
|
|
122
107
|
claim: (emailHash: string, gen: number): string => `login/${emailHash}.${gen}.claim`,
|
|
123
108
|
/** one session, under its person: `{ email, gen, until }`, by the sha256 of its id */
|
|
124
109
|
session: (emailHash: string, sidHash: string): string => `session/${emailHash}/${sidHash}.json`,
|
|
125
|
-
/**
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
files: (share: string): string => `files/${share}.json`,
|
|
129
|
-
/** the advisor's read cursor on a share, the one other key the door writes */
|
|
110
|
+
/** every session of one person: the prefix a reset clears */
|
|
111
|
+
sessions: (emailHash: string): string => `session/${emailHash}/`,
|
|
112
|
+
/** the advisor's read cursor on a share, which the owner's pass pulls into the owner's store */
|
|
130
113
|
reads: (share: string): string => `reads/${share}.json`,
|
|
131
|
-
/** where a person is
|
|
132
|
-
* (edge/here.ts); the owner's hub alone reads it */
|
|
114
|
+
/** where a person is on the advisors page, by the sha256 of their email: the thread open now and when they were
|
|
115
|
+
* last on each (edge/here.ts); the owner's hub alone reads it */
|
|
133
116
|
here: (emailHash: string): string => `here/${emailHash}.json`,
|
|
134
|
-
/** the beats the
|
|
117
|
+
/** the beats the users' port refused, counted */
|
|
135
118
|
hereRefused: 'here/refused.json',
|
|
136
|
-
/** the advisors' page: its script and its stylesheet, by the sha256 of their bytes */
|
|
137
|
-
app: (sha: string, ext: 'js' | 'css'): string => `app/${sha}.${ext}`,
|
|
138
|
-
media: (sha: string): string => `media/${sha}.webp`,
|
|
139
|
-
/** an advisor's own photo, 64 px, by the hash of its bytes */
|
|
140
|
-
photo: (sha: string): string => `photo/${sha}.webp`,
|
|
141
|
-
inbox: (share: string): string => `inbox/${share}/`,
|
|
142
|
-
proposals: (project: string): string => `inbox/p/${project}/`,
|
|
143
119
|
/** the files of one entry: `s` a share's words, `p` a project's proposal */
|
|
144
120
|
upload: (scope: 's' | 'p', id: string, entry: string): string => `upload/${scope}/${id}/${entry}/`,
|
|
145
121
|
} as const
|
package/src/advisors/expose.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
// the owner sets the advisors
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// nothing is written) and waits for it to connect, points the name at it LAST,
|
|
5
|
-
// then removes what the
|
|
1
|
+
// the owner sets the advisors page up, once, with a setup token that lives a day (wiki tools/shipkit/advisors.md, Who
|
|
2
|
+
// calls: the users' port): `sk advisors expose` makes the Cloudflare Tunnel `rv-advisors`, its one ingress (the name
|
|
3
|
+
// to the users' port on this Mac), stores its token in the vault, starts the process that runs cloudflared
|
|
4
|
+
// (cloudflared absent: nothing is written) and waits for it to connect, points the name at it LAST,
|
|
5
|
+
// then removes what the advisors page ran on before the tunnel (a Worker, a bucket, Access apps). Each step checks first and writes
|
|
6
6
|
// only what differs: a second run writes nothing. `check` proves from outside what the name answers
|
|
7
7
|
// the one constraint a reader breaks first: no agent's process runs this (the cli refuses an agent's shell), and the
|
|
8
8
|
// tunnel's token is never said: it goes from Cloudflare's answer to the vault
|
|
9
9
|
import { authRefused, CfError, client, type Cf, type Fetch } from './cf-api.ts'
|
|
10
|
-
import { TUNNEL_TOKEN } from './
|
|
10
|
+
import { TUNNEL_TOKEN } from './reach.ts'
|
|
11
11
|
import { PUBLIC_PAGES } from './edge/pages.ts'
|
|
12
|
-
import {
|
|
12
|
+
import { usersPort } from './users-store.ts'
|
|
13
13
|
import { TUNNEL_PROCESS, vaultRead, type TunnelStart } from './tunnel.ts'
|
|
14
14
|
import { withState } from './owner-store.ts'
|
|
15
15
|
|
|
16
16
|
export type { Fetch }
|
|
17
17
|
|
|
18
18
|
export const TUNNEL_NAME = 'rv-advisors'
|
|
19
|
-
/** what the
|
|
19
|
+
/** what the advisors page ran on before the tunnel, removed by the setup once the name points at the tunnel */
|
|
20
20
|
export const OLD_WORKER = 'rv-advisors'
|
|
21
21
|
export const OLD_BUCKET = 'rv-advisors'
|
|
22
|
-
// sk-disable-next-line RV045 -- the advisors
|
|
22
|
+
// sk-disable-next-line RV045 -- the advisors page's setup reads the house's own setup token by this name
|
|
23
23
|
export const SETUP_SECRET = 'rv/cloudflare/advisors-setup'
|
|
24
24
|
/** the token's rights, for its ask and for the words of a refused one */
|
|
25
25
|
export const SETUP_RIGHTS = 'Account: Cloudflare Tunnel Edit, Access: Apps and Policies Edit, Access: Organizations, Identity Providers, and Groups Edit, Workers Scripts Edit, Workers R2 Storage Edit; Zone: DNS Edit, Workers Routes Edit'
|
|
26
26
|
|
|
27
|
-
/** why the
|
|
27
|
+
/** why the advisors page was not set up, with what to do in its words; `token`: the setup token, missing or refused; `local`:
|
|
28
28
|
* this Mac lacks what the setup needs, nothing written at Cloudflare */
|
|
29
|
-
export class
|
|
29
|
+
export class SetupError extends Error {
|
|
30
30
|
constructor(message: string, readonly kind: 'token' | 'local' | 'other' = 'other') {
|
|
31
31
|
super(message)
|
|
32
32
|
}
|
|
@@ -62,11 +62,11 @@ export const NO_CLOUDFLARED = 'cloudflared is not on this Mac, so the tunnel can
|
|
|
62
62
|
type Tunnel = { id: string; name: string; status?: string; connections?: unknown[] }
|
|
63
63
|
type Dns = { id: string; type: string; name: string; content: string; proxied?: boolean }
|
|
64
64
|
|
|
65
|
-
/** the
|
|
66
|
-
export async function
|
|
65
|
+
/** the advisors page set up, or found set up: every step checks first and writes only what differs */
|
|
66
|
+
export async function setupAdvisors(o: SetupInput): Promise<{ account: string; tunnel: string }> {
|
|
67
67
|
const say = o.say ?? (() => undefined)
|
|
68
68
|
// before any write: a tunnel nothing here can connect is never made
|
|
69
|
-
if (o.tunnel.bin() === null) throw new
|
|
69
|
+
if (o.tunnel.bin() === null) throw new SetupError(NO_CLOUDFLARED, 'local')
|
|
70
70
|
const zoneName = o.host.slice(o.host.indexOf('.') + 1)
|
|
71
71
|
const cf = client(o.token, o.fetch ?? fetch)
|
|
72
72
|
const step = async <T>(run: () => Promise<{ value: T; words: string; wrote: boolean }>): Promise<T> => {
|
|
@@ -77,12 +77,12 @@ export async function setupDoor(o: SetupInput): Promise<{ account: string; tunne
|
|
|
77
77
|
}
|
|
78
78
|
// the token's first call: a refusal here is the token itself
|
|
79
79
|
const zones = await cf<{ id: string; account: { id: string } }[]>('GET', `/zones?name=${encodeURIComponent(zoneName)}`).catch((e: unknown) => {
|
|
80
|
-
throw authRefused(e) ? new
|
|
80
|
+
throw authRefused(e) ? new SetupError(`Cloudflare refuses the setup token ${SETUP_SECRET}: it expired or was revoked. ${FRESH_TOKEN}. (Cloudflare said: ${e.message})`, 'token') : e
|
|
81
81
|
})
|
|
82
82
|
const zone = zones[0]
|
|
83
83
|
if (zone === undefined) throw new Error(`no zone ${zoneName} for this token`)
|
|
84
84
|
const A = `/accounts/${zone.account.id}`
|
|
85
|
-
const service = `http://127.0.0.1:${
|
|
85
|
+
const service = `http://127.0.0.1:${usersPort()}`
|
|
86
86
|
|
|
87
87
|
const tunnel = await step(async () => {
|
|
88
88
|
const found = list<Tunnel>(await cf('GET', `${A}/cfd_tunnel?name=${TUNNEL_NAME}&is_deleted=false`)).find((t) => t.name === TUNNEL_NAME)
|
|
@@ -111,7 +111,7 @@ export async function setupDoor(o: SetupInput): Promise<{ account: string; tunne
|
|
|
111
111
|
if (refused !== null) throw new Error(`the process that runs cloudflared on this Mac (${TUNNEL_PROCESS}) did not start: ${refused}. The name still points where it did`)
|
|
112
112
|
return { value: null, words: `cloudflared runs on this Mac (${TUNNEL_PROCESS})`, wrote: false }
|
|
113
113
|
})
|
|
114
|
-
// the name moves only once a connector stands: until then
|
|
114
|
+
// the name moves only once a connector stands: until then whatever it points at keeps answering
|
|
115
115
|
await step(async () => {
|
|
116
116
|
const w = o.wait ?? { tries: 45, ms: 2_000 }
|
|
117
117
|
for (let i = 0; ; i++) {
|
|
@@ -148,8 +148,8 @@ export async function setupDoor(o: SetupInput): Promise<{ account: string; tunne
|
|
|
148
148
|
return { account: zone.account.id, tunnel }
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
/** what the
|
|
152
|
-
* run's failure: the
|
|
151
|
+
/** what the advisors page ran on before the tunnel: its Access apps and Google login, its Worker, its bucket. A refusal
|
|
152
|
+
* is a WARN, never the run's failure: the advisors page works without this */
|
|
153
153
|
async function leftovers(cf: Cf, A: string, host: string, say: (l: string) => void): Promise<void> {
|
|
154
154
|
const t = performance.now()
|
|
155
155
|
let wrote = 0
|
|
@@ -181,7 +181,7 @@ async function leftovers(cf: Cf, A: string, host: string, say: (l: string) => vo
|
|
|
181
181
|
// R2 never turned on: no bucket to remove
|
|
182
182
|
const r2 = await cf<{ buckets?: unknown }>('GET', `${A}/r2/buckets`).catch((e: unknown) => (e instanceof CfError && e.codes.includes(R2_OFF) ? { buckets: [] } : Promise.reject(e)))
|
|
183
183
|
if (!list<{ name: string }>(r2.buckets).some((b) => b.name === OLD_BUCKET)) return
|
|
184
|
-
//
|
|
184
|
+
// its objects first, then the bucket
|
|
185
185
|
for (;;) {
|
|
186
186
|
const objects = list<{ key: string }>(await cf('GET', `${A}/r2/buckets/${OLD_BUCKET}/objects`))
|
|
187
187
|
if (objects.length === 0) break
|
|
@@ -193,17 +193,17 @@ async function leftovers(cf: Cf, A: string, host: string, say: (l: string) => vo
|
|
|
193
193
|
say(`what the advisors page was before (its Access apps, its Worker, its bucket) ${wrote === 0 ? 'is gone, no change' : 'removed'} ${took(performance.now() - t)}`)
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
/** `sk advisors expose`: the setup token read, the setup run, where the
|
|
196
|
+
/** `sk advisors expose`: the setup token read, the setup run, where the advisors page stands recorded. The caller has
|
|
197
197
|
* refused an agent's process */
|
|
198
|
-
export async function
|
|
198
|
+
export async function exposeAdvisors(o: { dir: string; cwd: string; host: string; say: (l: string) => void }, d: { tunnel: TunnelStart; read?: (name: string) => Promise<string | null>; store?: (name: string, value: string) => Promise<string | null>; fetch?: Fetch; wait?: SetupInput['wait']; now?: () => Date }): Promise<void> {
|
|
199
199
|
if ((await import('../hq/hq-role.ts')).hqRole() === 'joined') throw new Error('this machine joined the hq: the advisors page runs on the machine that carries the hq, run it there')
|
|
200
200
|
const read = d.read ?? vaultRead(o.cwd)
|
|
201
201
|
const token = await read(SETUP_SECRET).catch((e: Error) => {
|
|
202
|
-
throw new
|
|
202
|
+
throw new SetupError(`the setup token ${SETUP_SECRET} could not be read: ${e.message}`, 'token')
|
|
203
203
|
})
|
|
204
|
-
if (token === null) throw new
|
|
204
|
+
if (token === null) throw new SetupError(`the setup token ${SETUP_SECRET} is not stored. ${FRESH_TOKEN}`, 'token')
|
|
205
205
|
const store = d.store ?? storeIn(o.cwd)
|
|
206
|
-
const r = await
|
|
206
|
+
const r = await setupAdvisors({ token, host: o.host, say: o.say, tunnel: d.tunnel, held: () => read(TUNNEL_TOKEN), store: (v) => store(TUNNEL_TOKEN, v), ...(d.fetch !== undefined ? { fetch: d.fetch } : {}), ...(d.wait !== undefined ? { wait: d.wait } : {}) })
|
|
207
207
|
const at = (d.now?.() ?? new Date()).toISOString()
|
|
208
208
|
withState(o.dir, (s) => {
|
|
209
209
|
s.host = o.host
|
|
@@ -218,16 +218,16 @@ const storeIn = (cwd: string) => async (name: string, value: string): Promise<st
|
|
|
218
218
|
return 'refused' in r ? r.refused : null
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
/** the routes `check` asks for with no session: each the
|
|
222
|
-
* sends a visitor to the sign in (
|
|
221
|
+
/** the routes `check` asks for with no session: each the users' port's 401. The front page is apart: with no session
|
|
222
|
+
* it sends a visitor to the sign in (users-router.ts liveAnswer) */
|
|
223
223
|
export const GUARDED_PROBES = ['/api/advisor/projects', '/api/advisor/photo', '/api/review/threads']
|
|
224
224
|
const SIGN_IN = '/in'
|
|
225
|
-
/** paths the
|
|
225
|
+
/** paths the users' port never answers: the owner's hub, lookalikes of the public pages, a made up login */
|
|
226
226
|
export const NOTHING_PROBES = ['/api/home/vault', '/api/home/advisors', '/r/game/', '/api/live', '/about/', '/About', '/about-x', '/privacy/x', '/about%2F..%2Fapi%2Fadvisor%2Fprojects', `/in/${'A'.repeat(43)}`]
|
|
227
227
|
|
|
228
228
|
/** from outside, with no session: the two public pages answer 200 with no script, the advisor's routes 401, everything
|
|
229
229
|
* else the 404. The reasons it does not, empty when it holds */
|
|
230
|
-
export async function
|
|
230
|
+
export async function checkAdvisors(host: string, f: Fetch = fetch): Promise<string[]> {
|
|
231
231
|
const out: string[] = []
|
|
232
232
|
const ask = async (path: string): Promise<Response | null> => {
|
|
233
233
|
try {
|