@myrialabs/clopen 0.4.47 → 0.4.49
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/README.md +11 -11
- package/backend/artifacts/project/sources.ts +1 -1
- package/backend/auth/auth-service.ts +52 -358
- package/backend/auth/onboarding.test.ts +2 -3
- package/backend/auth/permissions.test.ts +10 -20
- package/backend/auth/permissions.ts +4 -290
- package/backend/auth/rate-limiter.test.ts +8 -9
- package/backend/auth/rate-limiter.ts +0 -2
- package/backend/auth/tokens.ts +1 -8
- package/backend/bootstrap.ts +7 -0
- package/backend/chat/attachments.test.ts +88 -0
- package/backend/chat/attachments.ts +159 -0
- package/backend/chat/engine-handoff.test.ts +0 -2
- package/backend/chat/message-pages.test.ts +163 -0
- package/backend/chat/message-pages.ts +233 -0
- package/backend/chat/stream-manager.ts +91 -67
- package/backend/chat/turn-answer.test.ts +64 -0
- package/backend/chat/turn-answer.ts +125 -0
- package/backend/chat-apps/awaiting.test.ts +39 -0
- package/backend/chat-apps/awaiting.ts +49 -0
- package/backend/chat-apps/conversation.ts +746 -0
- package/backend/chat-apps/inbound.ts +324 -0
- package/backend/chat-apps/index.ts +309 -0
- package/backend/chat-apps/link-events.ts +20 -0
- package/backend/chat-apps/media.test.ts +62 -0
- package/backend/chat-apps/media.ts +208 -0
- package/backend/chat-apps/messages.test.ts +229 -0
- package/backend/chat-apps/messages.ts +365 -0
- package/backend/chat-apps/outbound.ts +243 -0
- package/backend/chat-apps/pairing.test.ts +45 -0
- package/backend/chat-apps/pairing.ts +74 -0
- package/backend/chat-apps/platforms/index.ts +20 -0
- package/backend/chat-apps/platforms/telegram.test.ts +35 -0
- package/backend/chat-apps/platforms/telegram.ts +191 -0
- package/backend/chat-apps/platforms/types.ts +114 -0
- package/backend/chat-apps/questions.ts +133 -0
- package/backend/chat-apps/runtime.ts +572 -0
- package/backend/chat-apps/storage.test.ts +201 -0
- package/backend/chat-apps/turns.test.ts +45 -0
- package/backend/chat-apps/turns.ts +208 -0
- package/backend/containers/pty.ts +3 -11
- package/backend/control/actions/accounts.ts +89 -0
- package/backend/control/actions/files.ts +116 -0
- package/backend/control/actions/models.ts +188 -0
- package/backend/control/actions/projects.ts +272 -0
- package/backend/control/actions/sessions.ts +280 -0
- package/backend/control/actions/skills.ts +111 -0
- package/backend/control/control.test.ts +169 -0
- package/backend/control/define.ts +20 -0
- package/backend/control/folders.test.ts +67 -0
- package/backend/control/index.ts +213 -0
- package/backend/control/invoke.ts +44 -0
- package/backend/control/links.ts +35 -0
- package/backend/control/paging.ts +26 -0
- package/backend/control/types.ts +117 -0
- package/backend/control/workspace.ts +127 -0
- package/backend/database/migrations/084_create_channel_links.ts +71 -0
- package/backend/database/migrations/085_add_home_projects.ts +36 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/087_create_blob_line_stats.ts +37 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- package/backend/database/queries/blob-line-stats-queries.ts +48 -0
- package/backend/database/queries/channel-queries.ts +270 -0
- package/backend/database/queries/db-client-connection-queries.ts +18 -56
- package/backend/database/queries/file-share-queries.ts +5 -23
- package/backend/database/queries/git-identity-queries.ts +31 -42
- package/backend/database/queries/graph-queries.ts +1 -1
- package/backend/database/queries/index.ts +15 -1
- package/backend/database/queries/message-queries.test.ts +146 -0
- package/backend/database/queries/message-queries.ts +42 -1
- package/backend/database/queries/permission-set-queries.ts +1 -1
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
- package/backend/database/queries/project-queries.ts +50 -63
- package/backend/database/queries/session-queries.ts +28 -56
- package/backend/database/queries/ssh-connection-queries.ts +18 -41
- package/backend/db-client/env/diff.ts +9 -33
- package/backend/db-client/env/env.test.ts +8 -8
- package/backend/db-client/env/service.ts +1 -1
- package/backend/db-client/integrations/projector.ts +0 -5
- package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
- package/backend/engine/adapters/claude/message-converter.ts +25 -2
- package/backend/engine/adapters/cline/message-converter.ts +0 -1
- package/backend/engine/adapters/cline/stream.ts +11 -15
- package/backend/engine/adapters/codex/message-converter.ts +0 -2
- package/backend/engine/adapters/copilot/message-converter.ts +1 -2
- package/backend/engine/adapters/cursor/message-converter.ts +0 -1
- package/backend/engine/adapters/opencode/message-converter.ts +2 -4
- package/backend/engine/adapters/opencode/stream.ts +11 -0
- package/backend/engine/adapters/parent-scope.test.ts +38 -0
- package/backend/engine/adapters/parent-scope.ts +44 -0
- package/backend/engine/adapters/pi/message-converter.ts +0 -1
- package/backend/engine/adapters/pi/stream.ts +4 -5
- package/backend/engine/adapters/qwen/message-converter.ts +0 -2
- package/backend/engine/bootstrap-default-engine.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +8 -1
- package/backend/engine/install-runner.ts +8 -17
- package/backend/files/file-shares.ts +20 -44
- package/backend/files/file-size-limit.ts +3 -3
- package/backend/files/file-watcher.ts +19 -0
- package/backend/files/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- package/backend/git/contributors.test.ts +35 -0
- package/backend/git/contributors.ts +46 -0
- package/backend/git/git-executor.ts +25 -5
- package/backend/git/git-service.ts +420 -19
- package/backend/git/identity/credential-helper.test.ts +2 -7
- package/backend/git/identity/import-local.test.ts +11 -16
- package/backend/git/identity/import-local.ts +12 -12
- package/backend/git/identity/index.ts +10 -24
- package/backend/git/identity/resolve.ts +13 -14
- package/backend/git/identity/scope-config.ts +33 -28
- package/backend/git/identity/service.ts +44 -47
- package/backend/git/op-lock.test.ts +111 -0
- package/backend/git/op-lock.ts +180 -0
- package/backend/git/remote-sync.test.ts +249 -0
- package/backend/host/metrics.ts +1 -1
- package/backend/http/bearer-auth.ts +1 -2
- package/backend/http/files-download.test.ts +8 -9
- package/backend/http/files-download.ts +2 -2
- package/backend/http/files-shared.test.ts +62 -89
- package/backend/http/files-shared.ts +2 -2
- package/backend/http/files-upload.test.ts +3 -7
- package/backend/http/files-upload.ts +3 -3
- package/backend/http/notes-images.test.ts +15 -38
- package/backend/http/notes-images.ts +6 -8
- package/backend/http/ssh-sftp.ts +5 -10
- package/backend/http/static-assets.test.ts +78 -0
- package/backend/http/static-assets.ts +104 -0
- package/backend/index.ts +32 -16
- package/backend/integrations/accounts.ts +61 -3
- package/backend/integrations/index.ts +2 -2
- package/backend/integrations/registry/define.ts +15 -0
- package/backend/integrations/registry/index.ts +2 -0
- package/backend/integrations/registry/providers/telegram.ts +54 -0
- package/backend/integrations/registry/types.ts +21 -1
- package/backend/integrations/webhooks/gateway.ts +7 -6
- package/backend/integrations/webhooks/verify.test.ts +30 -0
- package/backend/integrations/webhooks/verify.ts +4 -0
- package/backend/mcp/external/project.ts +1 -1
- package/backend/mcp/internal/remote-server.test.ts +1 -3
- package/backend/mcp/internal/remote-server.ts +4 -4
- package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
- package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
- package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
- package/backend/memory/redact.ts +1 -1
- package/backend/notes/access.test.ts +28 -29
- package/backend/notes/access.ts +6 -11
- package/backend/permissions/service.ts +1 -1
- package/backend/preview/browser/browser-clipboard.test.ts +46 -0
- package/backend/preview/browser/browser-clipboard.ts +67 -0
- package/backend/preview/browser/browser-dialog-handler.ts +95 -6
- package/backend/preview/browser/browser-host-bridge.ts +9 -0
- package/backend/preview/browser/browser-interaction-handler.ts +316 -86
- package/backend/preview/browser/browser-mcp-control.ts +34 -0
- package/backend/preview/browser/browser-pool.ts +67 -6
- package/backend/preview/browser/browser-preview-service.ts +383 -29
- package/backend/preview/browser/browser-tab-manager.ts +66 -23
- package/backend/preview/browser/browser-video-capture.ts +92 -5
- package/backend/preview/browser/element-locator.ts +190 -17
- package/backend/preview/browser/keyboard-chords.test.ts +68 -0
- package/backend/preview/browser/keyboard-chords.ts +132 -0
- package/backend/preview/browser/paste.ts +81 -0
- package/backend/preview/browser/process-usage.ts +142 -0
- package/backend/preview/browser/profile-lock.ts +209 -0
- package/backend/preview/browser/scripts/host-bridge.ts +59 -0
- package/backend/preview/browser/scripts/video-stream.ts +58 -0
- package/backend/preview/browser/types.ts +40 -2
- package/backend/preview/browser/viewport.test.ts +45 -0
- package/backend/preview/browser/viewport.ts +96 -0
- package/backend/profiles/service.ts +2 -2
- package/backend/project/status-manager.ts +43 -172
- package/backend/projects/home.ts +61 -0
- package/backend/projects/project-cleanup.integration.test.ts +2 -2
- package/backend/projects/project-cleanup.ts +0 -8
- package/backend/skills/service.ts +2 -3
- package/backend/snapshot/blob-store.ts +9 -1
- package/backend/snapshot/helpers.ts +3 -11
- package/backend/snapshot/line-stats.test.ts +80 -0
- package/backend/snapshot/line-stats.ts +64 -0
- package/backend/snapshot/restore.ts +252 -0
- package/backend/snapshot/snapshot-service.ts +14 -27
- package/backend/snapshot/turn-changes.test.ts +10 -5
- package/backend/snapshot/turn-changes.ts +78 -40
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +10 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws-wire.test.ts +87 -0
- package/backend/utils/ws-wire.ts +189 -0
- package/backend/utils/ws.ts +101 -192
- package/backend/worktrees/branching/engine.ts +3 -16
- package/backend/worktrees/branching/index.ts +1 -1
- package/backend/worktrees/branching/projector.ts +1 -1
- package/backend/worktrees/branching/service.ts +13 -25
- package/backend/ws/access.ts +12 -21
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/auth/device.ts +16 -71
- package/backend/ws/auth/index.ts +4 -22
- package/backend/ws/auth/login.test.ts +14 -60
- package/backend/ws/auth/login.ts +24 -124
- package/backend/ws/auth/status.ts +0 -1
- package/backend/ws/chat/composer.ts +118 -118
- package/backend/ws/chat/stream.ts +105 -57
- package/backend/ws/chat-apps/index.ts +117 -0
- package/backend/ws/containers/actions.ts +11 -25
- package/backend/ws/containers/index.ts +3 -4
- package/backend/ws/containers/list.ts +10 -36
- package/backend/ws/containers/logs.ts +2 -2
- package/backend/ws/containers/tunnel.ts +1 -2
- package/backend/ws/db-client/access.ts +2 -16
- package/backend/ws/db-client/accounts.ts +5 -15
- package/backend/ws/db-client/connections.ts +17 -25
- package/backend/ws/db-client/context.ts +1 -1
- package/backend/ws/db-client/env.ts +7 -10
- package/backend/ws/db-client/index.ts +2 -2
- package/backend/ws/db-client/io.ts +5 -5
- package/backend/ws/db-client/query-history-retention.test.ts +8 -8
- package/backend/ws/db-client/query.ts +18 -17
- package/backend/ws/db-client/schema.ts +13 -13
- package/backend/ws/db-client/structure.ts +35 -35
- package/backend/ws/db-client/supabase.ts +4 -21
- package/backend/ws/deployments/context.ts +1 -1
- package/backend/ws/deployments/crud.ts +0 -5
- package/backend/ws/engine/access.ts +7 -20
- package/backend/ws/engine/claude/accounts.ts +4 -4
- package/backend/ws/engine/cline/accounts.ts +5 -5
- package/backend/ws/engine/codex/accounts.ts +3 -3
- package/backend/ws/engine/pi/accounts.ts +5 -5
- package/backend/ws/files/clipboard.ts +8 -27
- package/backend/ws/files/image-edit.ts +6 -6
- package/backend/ws/files/index.ts +1 -1
- package/backend/ws/files/path-access.test.ts +32 -131
- package/backend/ws/files/path-access.ts +8 -87
- package/backend/ws/files/read.ts +45 -19
- package/backend/ws/files/reveal.ts +3 -3
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/share.ts +9 -13
- package/backend/ws/files/state.ts +9 -12
- package/backend/ws/files/watch.ts +3 -3
- package/backend/ws/files/write.ts +30 -31
- package/backend/ws/git/branch.ts +80 -59
- package/backend/ws/git/commit.ts +63 -44
- package/backend/ws/git/conflict.ts +16 -18
- package/backend/ws/git/identity-context.ts +8 -17
- package/backend/ws/git/identity.ts +17 -27
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/log.ts +52 -0
- package/backend/ws/git/op-state.ts +139 -0
- package/backend/ws/git/remote.ts +241 -141
- package/backend/ws/git/repo-context.ts +67 -0
- package/backend/ws/git/staging.ts +18 -28
- package/backend/ws/git/status.ts +5 -2
- package/backend/ws/index.ts +5 -1
- package/backend/ws/instructions/crud.ts +1 -1
- package/backend/ws/integrations/crud.ts +1 -3
- package/backend/ws/mcp/crud.ts +3 -5
- package/backend/ws/mcp/tools.ts +1 -1
- package/backend/ws/memory/crud.ts +14 -46
- package/backend/ws/memory/index.ts +2 -2
- package/backend/ws/messages/crud.ts +78 -8
- package/backend/ws/notes/index.ts +33 -39
- package/backend/ws/permissions/crud.ts +3 -4
- package/backend/ws/ports/index.ts +1 -2
- package/backend/ws/ports/kill.ts +5 -10
- package/backend/ws/ports/list.ts +4 -10
- package/backend/ws/preview/access.ts +1 -1
- package/backend/ws/preview/browser/interact.ts +52 -79
- package/backend/ws/preview/browser/native-ui.ts +24 -0
- package/backend/ws/preview/browser/stats.ts +98 -1
- package/backend/ws/preview/browser/tab-info.ts +15 -0
- package/backend/ws/preview/browser/tab.ts +19 -4
- package/backend/ws/preview/index.ts +29 -0
- package/backend/ws/preview/watchers.ts +84 -0
- package/backend/ws/profiles/crud.ts +6 -8
- package/backend/ws/project-artifacts/index.ts +30 -31
- package/backend/ws/projects/crud.ts +33 -35
- package/backend/ws/projects/index.ts +3 -8
- package/backend/ws/projects/info.ts +3 -3
- package/backend/ws/projects/overview.ts +19 -30
- package/backend/ws/projects/status.ts +17 -57
- package/backend/ws/sessions/crud.ts +42 -57
- package/backend/ws/sessions/index.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/skills/crud.ts +3 -4
- package/backend/ws/skills/index.ts +1 -1
- package/backend/ws/snapshot/changes.ts +12 -13
- package/backend/ws/snapshot/restore.ts +11 -295
- package/backend/ws/snapshot/timeline.ts +2 -4
- package/backend/ws/ssh/access.ts +6 -21
- package/backend/ws/ssh/connections.ts +21 -31
- package/backend/ws/ssh/forwards.ts +12 -12
- package/backend/ws/ssh/sftp.ts +34 -34
- package/backend/ws/ssh/tunnel.ts +1 -2
- package/backend/ws/stack/install.ts +7 -17
- package/backend/ws/subagents/crud.ts +1 -1
- package/backend/ws/terminal/tunnel.ts +2 -2
- package/backend/ws/tunnel/share.ts +0 -2
- package/backend/ws/user/crud.ts +1 -59
- package/backend/ws/user/index.ts +1 -1
- package/backend/ws/work/context.ts +1 -1
- package/backend/ws/work/crud.ts +0 -5
- package/backend/ws/workspace/state.ts +10 -13
- package/backend/ws/worktrees/branching.ts +7 -36
- package/backend/ws/worktrees/crud.ts +2 -2
- package/bin/clopen.ts +46 -41
- package/dist/assets/addon-clipboard-wHJhZAA4.js.br +0 -0
- package/dist/assets/addon-clipboard-wHJhZAA4.js.gz +0 -0
- package/dist/assets/addon-fit-DX4qG4td.js.br +1 -0
- package/dist/assets/addon-fit-DX4qG4td.js.gz +0 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js.br +0 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js.gz +0 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js.br +0 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js.gz +0 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js.br +0 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js.gz +0 -0
- package/dist/assets/diff.worker-BoHLxmr2.js +7 -0
- package/dist/assets/diff.worker-BoHLxmr2.js.br +0 -0
- package/dist/assets/diff.worker-BoHLxmr2.js.gz +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
- package/dist/assets/{index-CwuKQelV.js → index-CrVWZH_D.js} +1 -1
- package/dist/assets/index-CrVWZH_D.js.br +0 -0
- package/dist/assets/index-CrVWZH_D.js.gz +0 -0
- package/dist/assets/{index-BTcR1byF.js → index-DD0-3EWg.js} +1 -1
- package/dist/assets/index-DD0-3EWg.js.br +0 -0
- package/dist/assets/index-DD0-3EWg.js.gz +0 -0
- package/dist/assets/main-D2_TmcwQ.js +1240 -0
- package/dist/assets/main-D2_TmcwQ.js.br +0 -0
- package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
- package/dist/assets/main-Yucigcmf.css +1 -0
- package/dist/assets/main-Yucigcmf.css.br +0 -0
- package/dist/assets/main-Yucigcmf.css.gz +0 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js.br +0 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js.gz +0 -0
- package/dist/assets/xterm-B-qIQCd3.js.br +0 -0
- package/dist/assets/xterm-B-qIQCd3.js.gz +0 -0
- package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.br +0 -0
- package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.gz +0 -0
- package/dist/fonts/dm-sans.css.br +0 -0
- package/dist/fonts/dm-sans.css.gz +0 -0
- package/dist/index.html +2 -2
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/dist/sw.js.br +0 -0
- package/dist/sw.js.gz +0 -0
- package/package.json +3 -3
- package/shared/constants/attachments.ts +14 -0
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/preview.test.ts +259 -0
- package/shared/constants/preview.ts +1018 -57
- package/shared/constants/tool-icons.ts +5 -0
- package/shared/types/containers/container.ts +1 -1
- package/shared/types/database/schema.ts +9 -6
- package/shared/types/git-identity.ts +1 -1
- package/shared/types/git.ts +116 -0
- package/shared/types/integrations.ts +7 -0
- package/shared/types/stores/settings.ts +1 -1
- package/shared/types/unified/index.ts +1 -1
- package/shared/types/unified/message.ts +0 -7
- package/shared/types/unified/stream.ts +13 -5
- package/shared/types/unified/tool.ts +15 -1
- package/shared/utils/ask-user-question.test.ts +319 -0
- package/shared/utils/ask-user-question.ts +154 -0
- package/shared/utils/diff-calculator.test.ts +178 -41
- package/shared/utils/diff-calculator.ts +383 -100
- package/shared/utils/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/process-supervisor.test.ts +172 -0
- package/shared/utils/process-supervisor.ts +251 -0
- package/shared/utils/ws-chunk.test.ts +33 -0
- package/shared/utils/ws-chunk.ts +73 -0
- package/shared/utils/ws-client-chunks.test.ts +45 -0
- package/shared/utils/ws-client.ts +43 -0
- package/shared/utils/ws-server.ts +49 -21
- package/backend/auth/session-invalidation.test.ts +0 -112
- package/backend/auth/session-invalidation.ts +0 -77
- package/backend/project/status-manager.test.ts +0 -32
- package/backend/ws/auth/invites.ts +0 -94
- package/backend/ws/auth/users.ts +0 -112
- package/backend/ws/projects/presence.ts +0 -46
- package/backend/ws/stack/access.ts +0 -31
- package/dist/assets/main-BiDNMWb3.css +0 -1
- package/dist/assets/main-BlhKWz2B.js +0 -1241
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* sentence, using the caller-selected engine/model (the "Artifacts" model in
|
|
6
6
|
* Settings → Models). Returns loosely-typed fields the editor prefills.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Part of the artifact editors. The engine/model are chosen client-side,
|
|
9
|
+
* mirroring git:generate-commit-message.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { t } from 'elysia';
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* - auth:create-device-code — authenticated user mints a one-time code for a new
|
|
5
5
|
* device. The raw code is embedded in a share link; only its hash is stored.
|
|
6
6
|
* - auth:claim-device-code — PUBLIC. The scanning device exchanges the code for
|
|
7
|
-
* a session as the
|
|
8
|
-
*
|
|
9
|
-
* - auth:list-sessions / auth:revoke-session —
|
|
10
|
-
*
|
|
7
|
+
* a session as the owner. Single-use + short TTL, so a leaked link dies after
|
|
8
|
+
* one use. Rate-limited like other credential endpoints.
|
|
9
|
+
* - auth:list-sessions / auth:revoke-session — manage the signed-in devices
|
|
10
|
+
* (sessions).
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { t } from 'elysia';
|
|
@@ -16,10 +16,8 @@ import {
|
|
|
16
16
|
createDeviceCode,
|
|
17
17
|
claimDeviceCode,
|
|
18
18
|
revokeDeviceCode,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
revokeUserSession,
|
|
22
|
-
revokeAnySession,
|
|
19
|
+
listSessions,
|
|
20
|
+
revokeSession,
|
|
23
21
|
getRemoteAccessSummary
|
|
24
22
|
} from '$backend/auth/auth-service';
|
|
25
23
|
import { auditLogQueries } from '$backend/database/queries';
|
|
@@ -30,7 +28,6 @@ import { clientIpFromConnection } from '$backend/utils/client-ip';
|
|
|
30
28
|
const authUserSchema = t.Object({
|
|
31
29
|
id: t.String(),
|
|
32
30
|
name: t.String(),
|
|
33
|
-
role: t.Union([t.Literal('admin'), t.Literal('member')]),
|
|
34
31
|
color: t.String(),
|
|
35
32
|
avatar: t.String(),
|
|
36
33
|
createdAt: t.String()
|
|
@@ -58,7 +55,7 @@ export const deviceHandler = createRouter()
|
|
|
58
55
|
ipAddress: clientIpFromConnection(conn)
|
|
59
56
|
});
|
|
60
57
|
|
|
61
|
-
// Refresh the
|
|
58
|
+
// Refresh the Remote Access views on the other devices.
|
|
62
59
|
ws.emit.user(userId, 'remote-access:changed', { kind: 'device-created' });
|
|
63
60
|
|
|
64
61
|
return result;
|
|
@@ -95,14 +92,14 @@ export const deviceHandler = createRouter()
|
|
|
95
92
|
userId: result.user.id,
|
|
96
93
|
actorUserId: result.user.id,
|
|
97
94
|
eventType: 'auth:claim-device-code',
|
|
98
|
-
eventDetails:
|
|
95
|
+
eventDetails: 'A new device signed in',
|
|
99
96
|
ipAddress: clientIpFromConnection(conn)
|
|
100
97
|
});
|
|
101
98
|
|
|
102
|
-
ws.setAuth(conn, result.user.id, result.
|
|
99
|
+
ws.setAuth(conn, result.user.id, result.tokenHash);
|
|
103
100
|
|
|
104
|
-
// Notify the
|
|
105
|
-
//
|
|
101
|
+
// Notify the other devices: a device connected — refresh their device
|
|
102
|
+
// list and close the now-consumed link/QR.
|
|
106
103
|
ws.emit.user(result.user.id, 'remote-access:changed', { kind: 'device-claimed' });
|
|
107
104
|
|
|
108
105
|
return {
|
|
@@ -131,7 +128,7 @@ export const deviceHandler = createRouter()
|
|
|
131
128
|
return { success };
|
|
132
129
|
})
|
|
133
130
|
|
|
134
|
-
// List the
|
|
131
|
+
// List the signed-in devices
|
|
135
132
|
.http('auth:list-sessions', {
|
|
136
133
|
data: t.Object({}),
|
|
137
134
|
response: t.Array(t.Object({
|
|
@@ -146,31 +143,7 @@ export const deviceHandler = createRouter()
|
|
|
146
143
|
source: t.Union([t.String(), t.Null()])
|
|
147
144
|
}))
|
|
148
145
|
}, async ({ conn }) => {
|
|
149
|
-
|
|
150
|
-
return listUserSessions(userId, ws.getSessionTokenHash(conn) ?? undefined, ws.getOnlineSessionHashes());
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
// List every device signed in across the team (admin only) — the unified
|
|
154
|
-
// "Connected devices" view with owner + provenance.
|
|
155
|
-
.http('auth:list-all-sessions', {
|
|
156
|
-
data: t.Object({}),
|
|
157
|
-
response: t.Array(t.Object({
|
|
158
|
-
id: t.String(),
|
|
159
|
-
createdAt: t.String(),
|
|
160
|
-
lastActiveAt: t.String(),
|
|
161
|
-
expiresAt: t.String(),
|
|
162
|
-
current: t.Boolean(),
|
|
163
|
-
online: t.Boolean(),
|
|
164
|
-
userAgent: t.Union([t.String(), t.Null()]),
|
|
165
|
-
ipAddress: t.Union([t.String(), t.Null()]),
|
|
166
|
-
source: t.Union([t.String(), t.Null()]),
|
|
167
|
-
userId: t.String(),
|
|
168
|
-
userName: t.String(),
|
|
169
|
-
userColor: t.String(),
|
|
170
|
-
userRole: t.Union([t.Literal('admin'), t.Literal('member')])
|
|
171
|
-
}))
|
|
172
|
-
}, async ({ conn }) => {
|
|
173
|
-
return listAllSessions(ws.getSessionTokenHash(conn) ?? undefined, ws.getOnlineSessionHashes());
|
|
146
|
+
return listSessions(ws.getSessionTokenHash(conn) ?? undefined, ws.getOnlineSessionHashes());
|
|
174
147
|
})
|
|
175
148
|
|
|
176
149
|
// Remote Access summary — backs the sidebar indicator/count (online devices)
|
|
@@ -180,12 +153,10 @@ export const deviceHandler = createRouter()
|
|
|
180
153
|
activeConnections: t.Number()
|
|
181
154
|
})
|
|
182
155
|
}, async ({ conn }) => {
|
|
183
|
-
|
|
184
|
-
const isAdmin = ws.getRole(conn) === 'admin';
|
|
185
|
-
return getRemoteAccessSummary(userId, isAdmin, ws.getOnlineSessionHashes(), ws.getSessionTokenHash(conn) ?? undefined);
|
|
156
|
+
return getRemoteAccessSummary(ws.getOnlineSessionHashes(), ws.getSessionTokenHash(conn) ?? undefined);
|
|
186
157
|
})
|
|
187
158
|
|
|
188
|
-
//
|
|
159
|
+
// Sign out a device
|
|
189
160
|
.http('auth:revoke-session', {
|
|
190
161
|
data: t.Object({
|
|
191
162
|
id: t.String({ minLength: 1 })
|
|
@@ -193,7 +164,7 @@ export const deviceHandler = createRouter()
|
|
|
193
164
|
response: t.Object({ success: t.Boolean() })
|
|
194
165
|
}, async ({ data, conn }) => {
|
|
195
166
|
const userId = ws.getUserId(conn);
|
|
196
|
-
const result =
|
|
167
|
+
const result = revokeSession(data.id);
|
|
197
168
|
if (result.success) {
|
|
198
169
|
// Kick the live connection bound to that session immediately, so the
|
|
199
170
|
// signed-out device loses access now instead of at its next reconnect.
|
|
@@ -210,30 +181,4 @@ export const deviceHandler = createRouter()
|
|
|
210
181
|
ws.emit.user(userId, 'remote-access:changed', { kind: 'session-revoked' });
|
|
211
182
|
}
|
|
212
183
|
return { success: result.success };
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
// Revoke any user's session (admin only — sign out a device from the unified
|
|
216
|
-
// "Connected devices" list).
|
|
217
|
-
.http('auth:revoke-any-session', {
|
|
218
|
-
data: t.Object({
|
|
219
|
-
id: t.String({ minLength: 1 })
|
|
220
|
-
}),
|
|
221
|
-
response: t.Object({ success: t.Boolean() })
|
|
222
|
-
}, async ({ data, conn }) => {
|
|
223
|
-
const adminId = ws.getUserId(conn);
|
|
224
|
-
const result = revokeAnySession(data.id);
|
|
225
|
-
if (result.success) {
|
|
226
|
-
if (result.tokenHash) {
|
|
227
|
-
ws.invalidateSessionByHash(result.tokenHash, 'This device was signed out by an admin');
|
|
228
|
-
}
|
|
229
|
-
auditLogQueries.logEvent({
|
|
230
|
-
userId: adminId,
|
|
231
|
-
actorUserId: adminId,
|
|
232
|
-
eventType: 'auth:revoke-any-session',
|
|
233
|
-
eventDetails: `Admin revoked session ${data.id}`,
|
|
234
|
-
ipAddress: clientIpFromConnection(conn)
|
|
235
|
-
});
|
|
236
|
-
ws.emit.global('remote-access:changed', { kind: 'session-revoked' });
|
|
237
|
-
}
|
|
238
|
-
return { success: result.success };
|
|
239
184
|
});
|
package/backend/ws/auth/index.ts
CHANGED
|
@@ -2,15 +2,11 @@ import { createRouter } from '$shared/utils/ws-server';
|
|
|
2
2
|
import { t } from 'elysia';
|
|
3
3
|
import { statusHandler } from './status';
|
|
4
4
|
import { loginHandler } from './login';
|
|
5
|
-
import { inviteHandler } from './invites';
|
|
6
|
-
import { usersHandler } from './users';
|
|
7
5
|
import { deviceHandler } from './device';
|
|
8
6
|
|
|
9
7
|
export const authRouter = createRouter()
|
|
10
8
|
.merge(statusHandler)
|
|
11
9
|
.merge(loginHandler)
|
|
12
|
-
.merge(inviteHandler)
|
|
13
|
-
.merge(usersHandler)
|
|
14
10
|
.merge(deviceHandler)
|
|
15
11
|
// Declare auth:error event (emitted by auth gate in WSRouter)
|
|
16
12
|
.emit('auth:error', t.Object({
|
|
@@ -21,27 +17,13 @@ export const authRouter = createRouter()
|
|
|
21
17
|
.emit('auth:force-logout', t.Object({
|
|
22
18
|
reason: t.String()
|
|
23
19
|
}))
|
|
24
|
-
// Declare auth:force-logout-user event (emitted
|
|
20
|
+
// Declare auth:force-logout-user event (emitted to one device whose session ended)
|
|
25
21
|
.emit('auth:force-logout-user', t.Object({
|
|
26
22
|
reason: t.String()
|
|
27
23
|
}))
|
|
28
|
-
// Declare
|
|
29
|
-
// change
|
|
30
|
-
//
|
|
31
|
-
.emit('auth:user-projects-changed', t.Object({
|
|
32
|
-
type: t.Union([t.Literal('assigned'), t.Literal('unassigned')]),
|
|
33
|
-
userId: t.String(),
|
|
34
|
-
projectId: t.String()
|
|
35
|
-
}))
|
|
36
|
-
// Declare auth:users-changed event (broadcast when a user is created or
|
|
37
|
-
// removed, so any admin viewing the user list refreshes in realtime).
|
|
38
|
-
.emit('auth:users-changed', t.Object({
|
|
39
|
-
type: t.Union([t.Literal('added'), t.Literal('removed')]),
|
|
40
|
-
userId: t.String()
|
|
41
|
-
}))
|
|
42
|
-
// Declare remote-access:changed event (emitted to a user when their Remote
|
|
43
|
-
// Access shares/devices change — device code created/claimed/revoked, session
|
|
44
|
-
// revoked — so the sidebar count and panel lists refresh in realtime).
|
|
24
|
+
// Declare remote-access:changed event (emitted when Remote Access devices
|
|
25
|
+
// change — device code created/claimed/revoked, session revoked, a device
|
|
26
|
+
// came online — so the sidebar count and panel lists refresh in realtime).
|
|
45
27
|
.emit('remote-access:changed', t.Object({
|
|
46
28
|
kind: t.String()
|
|
47
29
|
}));
|
|
@@ -11,7 +11,6 @@ import { beforeEach, describe, expect, mock, test } from 'bun:test';
|
|
|
11
11
|
const mockUser = {
|
|
12
12
|
id: 'user-123',
|
|
13
13
|
name: 'Test User',
|
|
14
|
-
role: 'admin' as const,
|
|
15
14
|
color: '#FF5733',
|
|
16
15
|
avatar: 'avatar-url',
|
|
17
16
|
createdAt: new Date().toISOString()
|
|
@@ -31,26 +30,19 @@ const mockLogEvent = mock((entry: any) => {
|
|
|
31
30
|
});
|
|
32
31
|
|
|
33
32
|
// Mock auth-service functions
|
|
34
|
-
const
|
|
33
|
+
const mockCreateOwner = mock(() => ({
|
|
35
34
|
user: mockUser,
|
|
36
35
|
sessionToken: mockSessionToken,
|
|
37
36
|
personalAccessToken: mockPersonalAccessToken,
|
|
38
37
|
expiresAt: mockExpiresAt
|
|
39
38
|
}));
|
|
40
39
|
|
|
41
|
-
const
|
|
40
|
+
const mockCreateOrGetNoAuthOwner = mock(() => ({
|
|
42
41
|
user: mockUser,
|
|
43
42
|
sessionToken: mockSessionToken,
|
|
44
43
|
expiresAt: mockExpiresAt
|
|
45
44
|
}));
|
|
46
45
|
|
|
47
|
-
const mockCreateUserFromInvite = mock((inviteToken: string, name: string) => ({
|
|
48
|
-
user: mockUser,
|
|
49
|
-
sessionToken: mockSessionToken,
|
|
50
|
-
personalAccessToken: mockPersonalAccessToken,
|
|
51
|
-
expiresAt: mockExpiresAt
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
46
|
const mockNeedsSetup = mock(() => true);
|
|
55
47
|
const mockGetAuthMode = mock(() => 'none');
|
|
56
48
|
const mockMarkOnboardingPending = mock(() => {});
|
|
@@ -91,17 +83,14 @@ mock.module('$backend/settings/system-settings', () => ({
|
|
|
91
83
|
}));
|
|
92
84
|
|
|
93
85
|
mock.module('$backend/auth/auth-service', () => ({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
createUserFromInvite: mockCreateUserFromInvite,
|
|
86
|
+
createOwner: mockCreateOwner,
|
|
87
|
+
createOrGetNoAuthOwner: mockCreateOrGetNoAuthOwner,
|
|
97
88
|
needsSetup: mockNeedsSetup,
|
|
98
89
|
markOnboardingPending: mockMarkOnboardingPending,
|
|
99
90
|
loginWithToken: mock(() => ({})),
|
|
100
91
|
logout: mock(() => {}),
|
|
101
92
|
logoutAllSessions: mock(() => 0),
|
|
102
|
-
validateInviteToken: mock(() => ({ valid: true })),
|
|
103
93
|
regeneratePAT: mock(() => 'new-pat'),
|
|
104
|
-
updateUserName: mock(() => mockUser)
|
|
105
94
|
}));
|
|
106
95
|
|
|
107
96
|
mock.module('$backend/utils/ws', () => ({
|
|
@@ -136,9 +125,8 @@ describe('Session creation audit logging', () => {
|
|
|
136
125
|
// Clear all mock call history
|
|
137
126
|
logEventCalls = [];
|
|
138
127
|
mockLogEvent.mockClear();
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
mockCreateUserFromInvite.mockClear();
|
|
128
|
+
mockCreateOwner.mockClear();
|
|
129
|
+
mockCreateOrGetNoAuthOwner.mockClear();
|
|
142
130
|
mockSetAuth.mockClear();
|
|
143
131
|
mockGetRemoteAddress.mockClear();
|
|
144
132
|
mockEmitGlobal.mockClear();
|
|
@@ -152,12 +140,12 @@ describe('Session creation audit logging', () => {
|
|
|
152
140
|
// Call the handler
|
|
153
141
|
const handler = (loginHandler as any).httpRoutes.get('auth:setup');
|
|
154
142
|
await handler.handler({
|
|
155
|
-
data: {
|
|
143
|
+
data: {},
|
|
156
144
|
conn: mockConnection
|
|
157
145
|
});
|
|
158
146
|
|
|
159
|
-
// Verify
|
|
160
|
-
expect(
|
|
147
|
+
// Verify createOwner was called
|
|
148
|
+
expect(mockCreateOwner).toHaveBeenCalledWith(expect.anything());
|
|
161
149
|
|
|
162
150
|
// Verify logEvent was called with correct parameters
|
|
163
151
|
expect(mockLogEvent).toHaveBeenCalledTimes(1);
|
|
@@ -167,7 +155,6 @@ describe('Session creation audit logging', () => {
|
|
|
167
155
|
eventType: 'auth:setup',
|
|
168
156
|
ipAddress: mockIpAddress
|
|
169
157
|
});
|
|
170
|
-
expect(logEventCalls[0].eventDetails).toContain('Test User');
|
|
171
158
|
|
|
172
159
|
// Verify setAuth was called
|
|
173
160
|
expect(mockSetAuth).toHaveBeenCalled();
|
|
@@ -181,8 +168,8 @@ describe('Session creation audit logging', () => {
|
|
|
181
168
|
conn: mockConnection
|
|
182
169
|
});
|
|
183
170
|
|
|
184
|
-
// Verify
|
|
185
|
-
expect(
|
|
171
|
+
// Verify createOrGetNoAuthOwner was called
|
|
172
|
+
expect(mockCreateOrGetNoAuthOwner).toHaveBeenCalled();
|
|
186
173
|
|
|
187
174
|
// Verify logEvent was called with correct parameters
|
|
188
175
|
expect(mockLogEvent).toHaveBeenCalledTimes(1);
|
|
@@ -205,8 +192,8 @@ describe('Session creation audit logging', () => {
|
|
|
205
192
|
conn: mockConnection
|
|
206
193
|
});
|
|
207
194
|
|
|
208
|
-
// Verify
|
|
209
|
-
expect(
|
|
195
|
+
// Verify createOrGetNoAuthOwner was called
|
|
196
|
+
expect(mockCreateOrGetNoAuthOwner).toHaveBeenCalled();
|
|
210
197
|
|
|
211
198
|
// Verify logEvent was called with correct parameters
|
|
212
199
|
expect(mockLogEvent).toHaveBeenCalledTimes(1);
|
|
@@ -221,39 +208,6 @@ describe('Session creation audit logging', () => {
|
|
|
221
208
|
expect(mockSetAuth).toHaveBeenCalled();
|
|
222
209
|
});
|
|
223
210
|
|
|
224
|
-
test('logs auth:accept-invite event with IP address', async () => {
|
|
225
|
-
// Call the handler
|
|
226
|
-
const handler = (loginHandler as any).httpRoutes.get('auth:accept-invite');
|
|
227
|
-
await handler.handler({
|
|
228
|
-
data: {
|
|
229
|
-
inviteToken: 'invite-token-123',
|
|
230
|
-
name: 'New User'
|
|
231
|
-
},
|
|
232
|
-
conn: mockConnection
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
// Verify createUserFromInvite was called
|
|
236
|
-
expect(mockCreateUserFromInvite).toHaveBeenCalledWith('invite-token-123', 'New User', expect.anything());
|
|
237
|
-
|
|
238
|
-
// Verify logEvent was called with correct parameters
|
|
239
|
-
expect(mockLogEvent).toHaveBeenCalledTimes(1);
|
|
240
|
-
expect(logEventCalls[0]).toMatchObject({
|
|
241
|
-
userId: mockUser.id,
|
|
242
|
-
actorUserId: mockUser.id,
|
|
243
|
-
eventType: 'auth:accept-invite',
|
|
244
|
-
ipAddress: mockIpAddress
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// Verify emit.global was called for users-changed event
|
|
248
|
-
expect(mockEmitGlobal).toHaveBeenCalledWith('auth:users-changed', {
|
|
249
|
-
type: 'added',
|
|
250
|
-
userId: mockUser.id
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
// Verify setAuth was called
|
|
254
|
-
expect(mockSetAuth).toHaveBeenCalled();
|
|
255
|
-
});
|
|
256
|
-
|
|
257
211
|
test('auth flow ignores audit log failure result', async () => {
|
|
258
212
|
// logEvent signals a failed write with a falsy return (it never throws —
|
|
259
213
|
// the insert is wrapped internally). The handler must ignore that result.
|
|
@@ -262,7 +216,7 @@ describe('Session creation audit logging', () => {
|
|
|
262
216
|
// Call the auth:setup handler
|
|
263
217
|
const handler = (loginHandler as any).httpRoutes.get('auth:setup');
|
|
264
218
|
const result = await handler.handler({
|
|
265
|
-
data: {
|
|
219
|
+
data: {},
|
|
266
220
|
conn: mockConnection
|
|
267
221
|
});
|
|
268
222
|
|
package/backend/ws/auth/login.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { t } from 'elysia';
|
|
2
2
|
import { createRouter } from '$shared/utils/ws-server';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
createOwner,
|
|
5
5
|
loginWithToken,
|
|
6
|
-
createUserFromInvite,
|
|
7
6
|
logout,
|
|
8
7
|
logoutAllSessions,
|
|
9
|
-
validateInviteToken,
|
|
10
8
|
regeneratePAT,
|
|
11
|
-
|
|
12
|
-
createOrGetNoAuthAdmin,
|
|
9
|
+
createOrGetNoAuthOwner,
|
|
13
10
|
needsSetup,
|
|
14
11
|
markOnboardingPending
|
|
15
12
|
} from '$backend/auth/auth-service';
|
|
@@ -23,17 +20,15 @@ import { clientIpFromConnection } from '$backend/utils/client-ip';
|
|
|
23
20
|
const authUserSchema = t.Object({
|
|
24
21
|
id: t.String(),
|
|
25
22
|
name: t.String(),
|
|
26
|
-
role: t.Union([t.Literal('admin'), t.Literal('member')]),
|
|
27
23
|
color: t.String(),
|
|
28
24
|
avatar: t.String(),
|
|
29
25
|
createdAt: t.String()
|
|
30
26
|
});
|
|
31
27
|
|
|
32
28
|
export const loginHandler = createRouter()
|
|
33
|
-
// Setup — create
|
|
29
|
+
// Setup — create the owner (only works before setup)
|
|
34
30
|
.http('auth:setup', {
|
|
35
31
|
data: t.Object({
|
|
36
|
-
name: t.String({ minLength: 1 }),
|
|
37
32
|
userAgent: t.Optional(t.String())
|
|
38
33
|
}),
|
|
39
34
|
response: t.Object({
|
|
@@ -45,17 +40,17 @@ export const loginHandler = createRouter()
|
|
|
45
40
|
}, async ({ data, conn }) => {
|
|
46
41
|
// Refuse before touching any state. This route is public, so without the
|
|
47
42
|
// guard a stray call against a live instance would flip the onboarding
|
|
48
|
-
// marker below and send
|
|
43
|
+
// marker below and send the instance back through the wizard.
|
|
49
44
|
if (!needsSetup()) {
|
|
50
|
-
throw new Error('Setup already completed.
|
|
45
|
+
throw new Error('Setup already completed. The owner account exists.');
|
|
51
46
|
}
|
|
52
47
|
|
|
53
|
-
// Mark the wizard as in-progress BEFORE the
|
|
48
|
+
// Mark the wizard as in-progress BEFORE the owner exists, so a refresh
|
|
54
49
|
// between here and "Finish" resumes setup instead of looking like a
|
|
55
50
|
// completed install (which is how onboarding state is inferred).
|
|
56
51
|
markOnboardingPending();
|
|
57
52
|
|
|
58
|
-
const result =
|
|
53
|
+
const result = createOwner({ userAgent: data.userAgent, ipAddress: clientIpFromConnection(conn) });
|
|
59
54
|
|
|
60
55
|
// Save authMode to system settings
|
|
61
56
|
writeSystemSettings({ authMode: 'required' });
|
|
@@ -64,18 +59,18 @@ export const loginHandler = createRouter()
|
|
|
64
59
|
userId: result.user.id,
|
|
65
60
|
actorUserId: result.user.id,
|
|
66
61
|
eventType: 'auth:setup',
|
|
67
|
-
eventDetails:
|
|
62
|
+
eventDetails: 'Owner account created',
|
|
68
63
|
ipAddress: clientIpFromConnection(conn)
|
|
69
64
|
});
|
|
70
65
|
|
|
71
66
|
// Set auth on connection
|
|
72
67
|
const tokenHash = (await import('$backend/auth/tokens')).hashToken(result.sessionToken);
|
|
73
|
-
ws.setAuth(conn, result.user.id,
|
|
68
|
+
ws.setAuth(conn, result.user.id, tokenHash);
|
|
74
69
|
|
|
75
70
|
return result;
|
|
76
71
|
})
|
|
77
72
|
|
|
78
|
-
// Setup no-auth mode — create default
|
|
73
|
+
// Setup no-auth mode — create the default owner, save authMode setting
|
|
79
74
|
.http('auth:setup-no-auth', {
|
|
80
75
|
data: t.Object({}),
|
|
81
76
|
response: t.Object({
|
|
@@ -89,26 +84,25 @@ export const loginHandler = createRouter()
|
|
|
89
84
|
}
|
|
90
85
|
|
|
91
86
|
// Same ordering as auth:setup — record the in-progress wizard before the
|
|
92
|
-
//
|
|
87
|
+
// owner exists.
|
|
93
88
|
markOnboardingPending();
|
|
94
89
|
|
|
95
90
|
// Save authMode to system settings
|
|
96
91
|
writeSystemSettings({ authMode: 'none' });
|
|
97
92
|
|
|
98
|
-
|
|
99
|
-
const result = createOrGetNoAuthAdmin();
|
|
93
|
+
const result = createOrGetNoAuthOwner();
|
|
100
94
|
|
|
101
95
|
auditLogQueries.logEvent({
|
|
102
96
|
userId: result.user.id,
|
|
103
97
|
actorUserId: result.user.id,
|
|
104
98
|
eventType: 'auth:setup-no-auth',
|
|
105
|
-
eventDetails:
|
|
99
|
+
eventDetails: 'No-auth mode enabled',
|
|
106
100
|
ipAddress: clientIpFromConnection(conn)
|
|
107
101
|
});
|
|
108
102
|
|
|
109
103
|
// Set auth on connection
|
|
110
104
|
const tokenHash = (await import('$backend/auth/tokens')).hashToken(result.sessionToken);
|
|
111
|
-
ws.setAuth(conn, result.user.id,
|
|
105
|
+
ws.setAuth(conn, result.user.id, tokenHash);
|
|
112
106
|
|
|
113
107
|
return result;
|
|
114
108
|
})
|
|
@@ -126,19 +120,19 @@ export const loginHandler = createRouter()
|
|
|
126
120
|
throw new Error('Auto-login is only available in no-auth mode');
|
|
127
121
|
}
|
|
128
122
|
|
|
129
|
-
const result =
|
|
123
|
+
const result = createOrGetNoAuthOwner();
|
|
130
124
|
|
|
131
125
|
auditLogQueries.logEvent({
|
|
132
126
|
userId: result.user.id,
|
|
133
127
|
actorUserId: result.user.id,
|
|
134
128
|
eventType: 'auth:auto-login-no-auth',
|
|
135
|
-
eventDetails:
|
|
129
|
+
eventDetails: 'Auto-login in no-auth mode',
|
|
136
130
|
ipAddress: clientIpFromConnection(conn)
|
|
137
131
|
});
|
|
138
132
|
|
|
139
133
|
// Set auth on connection
|
|
140
134
|
const tokenHash = (await import('$backend/auth/tokens')).hashToken(result.sessionToken);
|
|
141
|
-
ws.setAuth(conn, result.user.id,
|
|
135
|
+
ws.setAuth(conn, result.user.id, tokenHash);
|
|
142
136
|
|
|
143
137
|
return result;
|
|
144
138
|
})
|
|
@@ -181,11 +175,11 @@ export const loginHandler = createRouter()
|
|
|
181
175
|
userId: result.user.id,
|
|
182
176
|
actorUserId: result.user.id,
|
|
183
177
|
eventType: 'auth:login',
|
|
184
|
-
eventDetails: `
|
|
178
|
+
eventDetails: `Signed in via ${tokenType} token`,
|
|
185
179
|
ipAddress: clientIpFromConnection(conn)
|
|
186
180
|
});
|
|
187
181
|
|
|
188
|
-
ws.setAuth(conn, result.user.id, result.
|
|
182
|
+
ws.setAuth(conn, result.user.id, result.tokenHash);
|
|
189
183
|
|
|
190
184
|
return {
|
|
191
185
|
user: result.user,
|
|
@@ -201,89 +195,6 @@ export const loginHandler = createRouter()
|
|
|
201
195
|
}
|
|
202
196
|
})
|
|
203
197
|
|
|
204
|
-
// Accept invite — create user from invite token
|
|
205
|
-
.http('auth:accept-invite', {
|
|
206
|
-
data: t.Object({
|
|
207
|
-
inviteToken: t.String({ minLength: 1 }),
|
|
208
|
-
name: t.String({ minLength: 1 }),
|
|
209
|
-
userAgent: t.Optional(t.String())
|
|
210
|
-
}),
|
|
211
|
-
response: t.Object({
|
|
212
|
-
user: authUserSchema,
|
|
213
|
-
sessionToken: t.String(),
|
|
214
|
-
personalAccessToken: t.String(),
|
|
215
|
-
expiresAt: t.String()
|
|
216
|
-
})
|
|
217
|
-
}, async ({ data, conn }) => {
|
|
218
|
-
const ip = ws.getRemoteAddress(conn);
|
|
219
|
-
|
|
220
|
-
// Rate limit check
|
|
221
|
-
const rateLimitError = authRateLimiter.check(ip, 'auth:accept-invite');
|
|
222
|
-
if (rateLimitError) {
|
|
223
|
-
throw new Error(rateLimitError);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
try {
|
|
227
|
-
const result = createUserFromInvite(data.inviteToken, data.name, { userAgent: data.userAgent, ipAddress: clientIpFromConnection(conn) });
|
|
228
|
-
|
|
229
|
-
authRateLimiter.recordSuccess(ip, 'auth:accept-invite');
|
|
230
|
-
|
|
231
|
-
auditLogQueries.logEvent({
|
|
232
|
-
userId: result.user.id,
|
|
233
|
-
actorUserId: result.user.id,
|
|
234
|
-
eventType: 'auth:accept-invite',
|
|
235
|
-
eventDetails: `User ${result.user.name} created account via invite`,
|
|
236
|
-
ipAddress: clientIpFromConnection(conn)
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
// Set auth on connection
|
|
240
|
-
const tokenHash = (await import('$backend/auth/tokens')).hashToken(result.sessionToken);
|
|
241
|
-
ws.setAuth(conn, result.user.id, result.user.role, tokenHash);
|
|
242
|
-
|
|
243
|
-
// Notify admin sessions so their User Management list refreshes.
|
|
244
|
-
ws.emit.global('auth:users-changed', { type: 'added', userId: result.user.id });
|
|
245
|
-
// A member just joined via an invite — close the admin's invite QR and
|
|
246
|
-
// refresh the invite/device lists (mirrors device-claimed).
|
|
247
|
-
ws.emit.global('remote-access:changed', { kind: 'invite-claimed' });
|
|
248
|
-
|
|
249
|
-
return result;
|
|
250
|
-
} catch (err) {
|
|
251
|
-
authRateLimiter.recordFailure(ip, 'auth:accept-invite');
|
|
252
|
-
throw err;
|
|
253
|
-
}
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
// Validate invite token (for UI, doesn't consume the invite)
|
|
257
|
-
.http('auth:validate-invite', {
|
|
258
|
-
data: t.Object({
|
|
259
|
-
inviteToken: t.String({ minLength: 1 })
|
|
260
|
-
}),
|
|
261
|
-
response: t.Object({
|
|
262
|
-
valid: t.Boolean(),
|
|
263
|
-
error: t.Optional(t.String())
|
|
264
|
-
})
|
|
265
|
-
}, async ({ data, conn }) => {
|
|
266
|
-
const ip = ws.getRemoteAddress(conn);
|
|
267
|
-
|
|
268
|
-
const rateLimitError = authRateLimiter.check(ip, 'auth:validate-invite');
|
|
269
|
-
if (rateLimitError) {
|
|
270
|
-
return { valid: false, error: rateLimitError };
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const result = validateInviteToken(data.inviteToken);
|
|
274
|
-
|
|
275
|
-
// Record failure if invalid token (probing). On a valid token, clear this
|
|
276
|
-
// route's record so someone who mistyped their link a couple of times
|
|
277
|
-
// doesn't carry those failures into a later attempt.
|
|
278
|
-
if (result.valid) {
|
|
279
|
-
authRateLimiter.recordSuccess(ip, 'auth:validate-invite');
|
|
280
|
-
} else {
|
|
281
|
-
authRateLimiter.recordFailure(ip, 'auth:validate-invite');
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return { valid: result.valid, error: result.error };
|
|
285
|
-
})
|
|
286
|
-
|
|
287
198
|
// Logout — clear session
|
|
288
199
|
.http('auth:logout', {
|
|
289
200
|
data: t.Object({}),
|
|
@@ -317,32 +228,21 @@ export const loginHandler = createRouter()
|
|
|
317
228
|
return { personalAccessToken: pat };
|
|
318
229
|
})
|
|
319
230
|
|
|
320
|
-
//
|
|
231
|
+
// Sign out every device (used when switching auth mode)
|
|
321
232
|
.http('auth:logout-all', {
|
|
322
233
|
data: t.Object({}),
|
|
323
234
|
response: t.Object({ count: t.Number() })
|
|
324
235
|
}, async ({ conn }) => {
|
|
325
|
-
const
|
|
236
|
+
const userId = ws.getUserId(conn);
|
|
326
237
|
const count = logoutAllSessions();
|
|
327
238
|
ws.emit.global('auth:force-logout', { reason: 'Auth mode changed' });
|
|
328
239
|
ws.clearAllAuth();
|
|
329
240
|
auditLogQueries.logEvent({
|
|
330
|
-
userId
|
|
331
|
-
actorUserId:
|
|
241
|
+
userId,
|
|
242
|
+
actorUserId: userId,
|
|
332
243
|
eventType: 'auth:logout-all',
|
|
333
|
-
eventDetails: `
|
|
244
|
+
eventDetails: `Signed out every device (${count} sessions cleared)`,
|
|
334
245
|
ipAddress: clientIpFromConnection(conn)
|
|
335
246
|
});
|
|
336
247
|
return { count };
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
// Update display name (authenticated user)
|
|
340
|
-
.http('auth:update-name', {
|
|
341
|
-
data: t.Object({
|
|
342
|
-
newName: t.String({ minLength: 1 })
|
|
343
|
-
}),
|
|
344
|
-
response: authUserSchema
|
|
345
|
-
}, async ({ data, conn }) => {
|
|
346
|
-
const userId = ws.getUserId(conn);
|
|
347
|
-
return updateUserName(userId, data.newName);
|
|
348
248
|
});
|