@sentropic/cluster-mesh 0.24.0 → 0.26.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/README.md +5 -0
- package/dist/comments/storage-schema.d.ts +1 -1
- package/dist/comments/transport-contracts.d.ts +1 -1
- package/dist/compile/contract/diagnostics.d.ts +9 -0
- package/dist/compile/contract/diagnostics.d.ts.map +1 -0
- package/dist/compile/contract/diagnostics.js +82 -0
- package/dist/compile/contract/diagnostics.js.map +1 -0
- package/dist/compile/contract/encoding.d.ts +12 -0
- package/dist/compile/contract/encoding.d.ts.map +1 -0
- package/dist/compile/contract/encoding.js +95 -0
- package/dist/compile/contract/encoding.js.map +1 -0
- package/dist/compile/contract/index.d.ts +9 -0
- package/dist/compile/contract/index.d.ts.map +1 -0
- package/dist/compile/contract/index.js +9 -0
- package/dist/compile/contract/index.js.map +1 -0
- package/dist/compile/contract/json.d.ts +3 -0
- package/dist/compile/contract/json.d.ts.map +1 -0
- package/dist/compile/contract/json.js +75 -0
- package/dist/compile/contract/json.js.map +1 -0
- package/dist/compile/contract/output.d.ts +5 -0
- package/dist/compile/contract/output.d.ts.map +1 -0
- package/dist/compile/contract/output.js +57 -0
- package/dist/compile/contract/output.js.map +1 -0
- package/dist/compile/contract/recipe.d.ts +5 -0
- package/dist/compile/contract/recipe.d.ts.map +1 -0
- package/dist/compile/contract/recipe.js +86 -0
- package/dist/compile/contract/recipe.js.map +1 -0
- package/dist/compile/contract/schema.d.ts +26 -0
- package/dist/compile/contract/schema.d.ts.map +1 -0
- package/dist/compile/contract/schema.js +92 -0
- package/dist/compile/contract/schema.js.map +1 -0
- package/dist/compile/contract/types.d.ts +166 -0
- package/dist/compile/contract/types.d.ts.map +1 -0
- package/dist/compile/contract/types.js +21 -0
- package/dist/compile/contract/types.js.map +1 -0
- package/dist/compile/contract/vectors.d.ts +38 -0
- package/dist/compile/contract/vectors.d.ts.map +1 -0
- package/dist/compile/contract/vectors.js +29 -0
- package/dist/compile/contract/vectors.js.map +1 -0
- package/dist/engram-memory/wire-adaptation.d.ts +1 -1
- package/dist/engram-memory/wire-adaptation.d.ts.map +1 -1
- package/dist/engram-memory/wire-adaptation.js +24 -8
- package/dist/engram-memory/wire-adaptation.js.map +1 -1
- package/dist/forge/contracts.d.ts +60 -0
- package/dist/forge/contracts.d.ts.map +1 -0
- package/dist/forge/contracts.js +19 -0
- package/dist/forge/contracts.js.map +1 -0
- package/dist/forge/custody.d.ts +7 -0
- package/dist/forge/custody.d.ts.map +1 -0
- package/dist/forge/custody.js +76 -0
- package/dist/forge/custody.js.map +1 -0
- package/dist/forge/enrollment.d.ts +151 -0
- package/dist/forge/enrollment.d.ts.map +1 -0
- package/dist/forge/enrollment.js +98 -0
- package/dist/forge/enrollment.js.map +1 -0
- package/dist/forge/github-api.d.ts +6 -0
- package/dist/forge/github-api.d.ts.map +1 -0
- package/dist/forge/github-api.js +131 -0
- package/dist/forge/github-api.js.map +1 -0
- package/dist/forge/hono.d.ts +14 -0
- package/dist/forge/hono.d.ts.map +1 -0
- package/dist/forge/hono.js +141 -0
- package/dist/forge/hono.js.map +1 -0
- package/dist/forge/lifecycle.d.ts +108 -0
- package/dist/forge/lifecycle.d.ts.map +1 -0
- package/dist/forge/lifecycle.js +160 -0
- package/dist/forge/lifecycle.js.map +1 -0
- package/dist/forge/records.d.ts +70 -0
- package/dist/forge/records.d.ts.map +1 -0
- package/dist/forge/records.js +2 -0
- package/dist/forge/records.js.map +1 -0
- package/dist/forge/rotation.d.ts +46 -0
- package/dist/forge/rotation.d.ts.map +1 -0
- package/dist/forge/rotation.js +62 -0
- package/dist/forge/rotation.js.map +1 -0
- package/dist/identity/auth-abort.d.ts +9 -0
- package/dist/identity/auth-abort.d.ts.map +1 -0
- package/dist/identity/auth-abort.js +59 -0
- package/dist/identity/auth-abort.js.map +1 -0
- package/dist/identity/auth-binding.d.ts +3 -0
- package/dist/identity/auth-binding.d.ts.map +1 -0
- package/dist/identity/auth-binding.js +87 -0
- package/dist/identity/auth-binding.js.map +1 -0
- package/dist/identity/auth-boundary.d.ts +11 -0
- package/dist/identity/auth-boundary.d.ts.map +1 -0
- package/dist/identity/auth-boundary.js +73 -0
- package/dist/identity/auth-boundary.js.map +1 -0
- package/dist/identity/auth-completion.d.ts +9 -0
- package/dist/identity/auth-completion.d.ts.map +1 -0
- package/dist/identity/auth-completion.js +24 -0
- package/dist/identity/auth-completion.js.map +1 -0
- package/dist/identity/auth-credentials.d.ts +5 -0
- package/dist/identity/auth-credentials.d.ts.map +1 -0
- package/dist/identity/auth-credentials.js +82 -0
- package/dist/identity/auth-credentials.js.map +1 -0
- package/dist/identity/auth-email.d.ts +8 -0
- package/dist/identity/auth-email.d.ts.map +1 -0
- package/dist/identity/auth-email.js +104 -0
- package/dist/identity/auth-email.js.map +1 -0
- package/dist/identity/auth-hono.d.ts +5 -0
- package/dist/identity/auth-hono.d.ts.map +1 -0
- package/dist/identity/auth-hono.js +10 -0
- package/dist/identity/auth-hono.js.map +1 -0
- package/dist/identity/auth-proofs.d.ts +11 -0
- package/dist/identity/auth-proofs.d.ts.map +1 -0
- package/dist/identity/auth-proofs.js +107 -0
- package/dist/identity/auth-proofs.js.map +1 -0
- package/dist/identity/auth-service-tenant.d.ts +4 -0
- package/dist/identity/auth-service-tenant.d.ts.map +1 -0
- package/dist/identity/auth-service-tenant.js +54 -0
- package/dist/identity/auth-service-tenant.js.map +1 -0
- package/dist/identity/auth-sessions.d.ts +8 -0
- package/dist/identity/auth-sessions.d.ts.map +1 -0
- package/dist/identity/auth-sessions.js +141 -0
- package/dist/identity/auth-sessions.js.map +1 -0
- package/dist/identity/auth-social.d.ts +4 -0
- package/dist/identity/auth-social.d.ts.map +1 -0
- package/dist/identity/auth-social.js +82 -0
- package/dist/identity/auth-social.js.map +1 -0
- package/dist/identity/auth-users.d.ts +9 -0
- package/dist/identity/auth-users.d.ts.map +1 -0
- package/dist/identity/auth-users.js +116 -0
- package/dist/identity/auth-users.js.map +1 -0
- package/dist/identity/auth-webauthn.d.ts +22 -0
- package/dist/identity/auth-webauthn.d.ts.map +1 -0
- package/dist/identity/auth-webauthn.js +108 -0
- package/dist/identity/auth-webauthn.js.map +1 -0
- package/dist/identity/cascade.d.ts +12 -0
- package/dist/identity/cascade.d.ts.map +1 -0
- package/dist/identity/cascade.js +19 -0
- package/dist/identity/cascade.js.map +1 -0
- package/dist/identity/connector-custody.d.ts +85 -0
- package/dist/identity/connector-custody.d.ts.map +1 -0
- package/dist/identity/connector-custody.js +288 -0
- package/dist/identity/connector-custody.js.map +1 -0
- package/dist/identity/conversation.d.ts +50 -0
- package/dist/identity/conversation.d.ts.map +1 -0
- package/dist/identity/conversation.js +102 -0
- package/dist/identity/conversation.js.map +1 -0
- package/dist/identity/custody-crypto.d.ts +37 -0
- package/dist/identity/custody-crypto.d.ts.map +1 -0
- package/dist/identity/custody-crypto.js +173 -0
- package/dist/identity/custody-crypto.js.map +1 -0
- package/dist/identity/decision.d.ts +28 -0
- package/dist/identity/decision.d.ts.map +1 -0
- package/dist/identity/decision.js +97 -0
- package/dist/identity/decision.js.map +1 -0
- package/dist/identity/index.d.ts +9 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +13 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/ledger.d.ts +120 -0
- package/dist/identity/ledger.d.ts.map +1 -0
- package/dist/identity/ledger.js +226 -0
- package/dist/identity/ledger.js.map +1 -0
- package/dist/identity/postgres.d.ts +13 -0
- package/dist/identity/postgres.d.ts.map +1 -0
- package/dist/identity/postgres.js +207 -0
- package/dist/identity/postgres.js.map +1 -0
- package/dist/identity/sqlite.d.ts +14 -0
- package/dist/identity/sqlite.d.ts.map +1 -0
- package/dist/identity/sqlite.js +193 -0
- package/dist/identity/sqlite.js.map +1 -0
- package/dist/identity-contracts/access.d.ts +54 -0
- package/dist/identity-contracts/access.d.ts.map +1 -0
- package/dist/identity-contracts/access.js +168 -0
- package/dist/identity-contracts/access.js.map +1 -0
- package/dist/identity-contracts/accounts.d.ts +44 -0
- package/dist/identity-contracts/accounts.d.ts.map +1 -0
- package/dist/identity-contracts/accounts.js +150 -0
- package/dist/identity-contracts/accounts.js.map +1 -0
- package/dist/identity-contracts/boundary-resolution.d.ts +31 -0
- package/dist/identity-contracts/boundary-resolution.d.ts.map +1 -0
- package/dist/identity-contracts/boundary-resolution.js +56 -0
- package/dist/identity-contracts/boundary-resolution.js.map +1 -0
- package/dist/identity-contracts/composition-descriptors.d.ts +17 -0
- package/dist/identity-contracts/composition-descriptors.d.ts.map +1 -0
- package/dist/identity-contracts/composition-descriptors.js +77 -0
- package/dist/identity-contracts/composition-descriptors.js.map +1 -0
- package/dist/identity-contracts/custody-auth.d.ts +122 -0
- package/dist/identity-contracts/custody-auth.d.ts.map +1 -0
- package/dist/identity-contracts/custody-auth.js +2 -0
- package/dist/identity-contracts/custody-auth.js.map +1 -0
- package/dist/identity-contracts/custody-descriptors.d.ts +18 -0
- package/dist/identity-contracts/custody-descriptors.d.ts.map +1 -0
- package/dist/identity-contracts/custody-descriptors.js +83 -0
- package/dist/identity-contracts/custody-descriptors.js.map +1 -0
- package/dist/identity-contracts/custody-errors.d.ts +21 -0
- package/dist/identity-contracts/custody-errors.d.ts.map +1 -0
- package/dist/identity-contracts/custody-errors.js +80 -0
- package/dist/identity-contracts/custody-errors.js.map +1 -0
- package/dist/identity-contracts/custody-operations.d.ts +79 -0
- package/dist/identity-contracts/custody-operations.d.ts.map +1 -0
- package/dist/identity-contracts/custody-operations.js +2 -0
- package/dist/identity-contracts/custody-operations.js.map +1 -0
- package/dist/identity-contracts/custody.d.ts +587 -0
- package/dist/identity-contracts/custody.d.ts.map +1 -0
- package/dist/identity-contracts/custody.js +7 -0
- package/dist/identity-contracts/custody.js.map +1 -0
- package/dist/identity-contracts/descriptors.d.ts +12 -0
- package/dist/identity-contracts/descriptors.d.ts.map +1 -0
- package/dist/identity-contracts/descriptors.js +57 -0
- package/dist/identity-contracts/descriptors.js.map +1 -0
- package/dist/identity-contracts/doubles.d.ts +124 -0
- package/dist/identity-contracts/doubles.d.ts.map +1 -0
- package/dist/identity-contracts/doubles.js +360 -0
- package/dist/identity-contracts/doubles.js.map +1 -0
- package/dist/identity-contracts/enforcement.d.ts +27 -0
- package/dist/identity-contracts/enforcement.d.ts.map +1 -0
- package/dist/identity-contracts/enforcement.js +155 -0
- package/dist/identity-contracts/enforcement.js.map +1 -0
- package/dist/identity-contracts/errors.d.ts +71 -0
- package/dist/identity-contracts/errors.d.ts.map +1 -0
- package/dist/identity-contracts/errors.js +129 -0
- package/dist/identity-contracts/errors.js.map +1 -0
- package/dist/identity-contracts/index.d.ts +22 -0
- package/dist/identity-contracts/index.d.ts.map +1 -0
- package/dist/identity-contracts/index.js +23 -0
- package/dist/identity-contracts/index.js.map +1 -0
- package/dist/identity-contracts/oauth-reads.d.ts +42 -0
- package/dist/identity-contracts/oauth-reads.d.ts.map +1 -0
- package/dist/identity-contracts/oauth-reads.js +38 -0
- package/dist/identity-contracts/oauth-reads.js.map +1 -0
- package/dist/identity-contracts/ports.d.ts +116 -0
- package/dist/identity-contracts/ports.d.ts.map +1 -0
- package/dist/identity-contracts/ports.js +7 -0
- package/dist/identity-contracts/ports.js.map +1 -0
- package/dist/identity-contracts/replica-sync.d.ts +89 -0
- package/dist/identity-contracts/replica-sync.d.ts.map +1 -0
- package/dist/identity-contracts/replica-sync.js +7 -0
- package/dist/identity-contracts/replica-sync.js.map +1 -0
- package/dist/identity-contracts/resolution.d.ts +56 -0
- package/dist/identity-contracts/resolution.d.ts.map +1 -0
- package/dist/identity-contracts/resolution.js +87 -0
- package/dist/identity-contracts/resolution.js.map +1 -0
- package/dist/identity-contracts/service-tenancy.d.ts +43 -0
- package/dist/identity-contracts/service-tenancy.d.ts.map +1 -0
- package/dist/identity-contracts/service-tenancy.js +75 -0
- package/dist/identity-contracts/service-tenancy.js.map +1 -0
- package/dist/identity-contracts/tenancy.d.ts +52 -0
- package/dist/identity-contracts/tenancy.d.ts.map +1 -0
- package/dist/identity-contracts/tenancy.js +171 -0
- package/dist/identity-contracts/tenancy.js.map +1 -0
- package/dist/identity-contracts/types.d.ts +253 -0
- package/dist/identity-contracts/types.d.ts.map +1 -0
- package/dist/identity-contracts/types.js +7 -0
- package/dist/identity-contracts/types.js.map +1 -0
- package/dist/identity-contracts/workspace-deletion.d.ts +56 -0
- package/dist/identity-contracts/workspace-deletion.d.ts.map +1 -0
- package/dist/identity-contracts/workspace-deletion.js +7 -0
- package/dist/identity-contracts/workspace-deletion.js.map +1 -0
- package/dist/identity-contracts/workspaces.d.ts +37 -0
- package/dist/identity-contracts/workspaces.d.ts.map +1 -0
- package/dist/identity-contracts/workspaces.js +118 -0
- package/dist/identity-contracts/workspaces.js.map +1 -0
- package/dist/identity-stores/index.d.ts +4 -0
- package/dist/identity-stores/index.d.ts.map +1 -0
- package/dist/identity-stores/index.js +7 -0
- package/dist/identity-stores/index.js.map +1 -0
- package/dist/identity-stores/tenancy-postgres.d.ts +23 -0
- package/dist/identity-stores/tenancy-postgres.d.ts.map +1 -0
- package/dist/identity-stores/tenancy-postgres.js +294 -0
- package/dist/identity-stores/tenancy-postgres.js.map +1 -0
- package/dist/identity-stores/tenancy-schema.d.ts +11 -0
- package/dist/identity-stores/tenancy-schema.d.ts.map +1 -0
- package/dist/identity-stores/tenancy-schema.js +74 -0
- package/dist/identity-stores/tenancy-schema.js.map +1 -0
- package/dist/identity-stores/tenancy-sqlite.d.ts +24 -0
- package/dist/identity-stores/tenancy-sqlite.d.ts.map +1 -0
- package/dist/identity-stores/tenancy-sqlite.js +288 -0
- package/dist/identity-stores/tenancy-sqlite.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/mcp/memory-compose.d.ts +11 -0
- package/dist/integrations/mcp/memory-compose.d.ts.map +1 -0
- package/dist/integrations/mcp/memory-compose.js +79 -0
- package/dist/integrations/mcp/memory-compose.js.map +1 -0
- package/dist/integrations/mcp/memory-definition.d.ts +28 -0
- package/dist/integrations/mcp/memory-definition.d.ts.map +1 -0
- package/dist/integrations/mcp/memory-definition.js +2 -0
- package/dist/integrations/mcp/memory-definition.js.map +1 -0
- package/dist/integrations/mcp/memory-manifest.d.ts +4 -0
- package/dist/integrations/mcp/memory-manifest.d.ts.map +1 -0
- package/dist/integrations/mcp/memory-manifest.js +9 -0
- package/dist/integrations/mcp/memory-manifest.js.map +1 -0
- package/dist/integrations/mcp/memory-transport.d.ts +21 -0
- package/dist/integrations/mcp/memory-transport.d.ts.map +1 -0
- package/dist/integrations/mcp/memory-transport.js +47 -0
- package/dist/integrations/mcp/memory-transport.js.map +1 -0
- package/dist/integrations/mcp/memory.d.ts +19 -0
- package/dist/integrations/mcp/memory.d.ts.map +1 -0
- package/dist/integrations/mcp/memory.js +40 -0
- package/dist/integrations/mcp/memory.js.map +1 -0
- package/dist/loaders/mcp/index.d.ts +1 -0
- package/dist/loaders/mcp/index.d.ts.map +1 -1
- package/dist/loaders/mcp/index.js +1 -0
- package/dist/loaders/mcp/index.js.map +1 -1
- package/dist/loaders/mcp/memory.d.ts +6 -0
- package/dist/loaders/mcp/memory.d.ts.map +1 -0
- package/dist/loaders/mcp/memory.js +9 -0
- package/dist/loaders/mcp/memory.js.map +1 -0
- package/dist/loaders/notifications/index.d.ts +5 -0
- package/dist/loaders/notifications/index.d.ts.map +1 -0
- package/dist/loaders/notifications/index.js +6 -0
- package/dist/loaders/notifications/index.js.map +1 -0
- package/dist/mcp/stateful-preflight.d.ts +1 -1
- package/dist/messaging/email-port.d.ts +49 -0
- package/dist/messaging/email-port.d.ts.map +1 -0
- package/dist/messaging/email-port.js +92 -0
- package/dist/messaging/email-port.js.map +1 -0
- package/dist/messaging/index.d.ts +1 -0
- package/dist/messaging/index.d.ts.map +1 -1
- package/dist/messaging/index.js +1 -0
- package/dist/messaging/index.js.map +1 -1
- package/dist/modules/catalog.d.ts +7 -4
- package/dist/modules/catalog.d.ts.map +1 -1
- package/dist/modules/catalog.js +24 -5
- package/dist/modules/catalog.js.map +1 -1
- package/dist/modules/contracts.d.ts +1 -1
- package/dist/modules/contracts.d.ts.map +1 -1
- package/dist/modules/contracts.js +3 -0
- package/dist/modules/contracts.js.map +1 -1
- package/dist/notifications/incident-policy.d.ts +6 -0
- package/dist/notifications/incident-policy.d.ts.map +1 -0
- package/dist/notifications/incident-policy.js +119 -0
- package/dist/notifications/incident-policy.js.map +1 -0
- package/dist/notifications/incident-schedule.d.ts +14 -0
- package/dist/notifications/incident-schedule.d.ts.map +1 -0
- package/dist/notifications/incident-schedule.js +36 -0
- package/dist/notifications/incident-schedule.js.map +1 -0
- package/dist/notifications/incident-state.d.ts +72 -0
- package/dist/notifications/incident-state.d.ts.map +1 -0
- package/dist/notifications/incident-state.js +72 -0
- package/dist/notifications/incident-state.js.map +1 -0
- package/dist/notifications/index.d.ts +9 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +9 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/ops-job-failure-contract.d.ts +19 -0
- package/dist/notifications/ops-job-failure-contract.d.ts.map +1 -0
- package/dist/notifications/ops-job-failure-contract.js +183 -0
- package/dist/notifications/ops-job-failure-contract.js.map +1 -0
- package/dist/notifications/ops-job-failure-types.d.ts +81 -0
- package/dist/notifications/ops-job-failure-types.d.ts.map +1 -0
- package/dist/notifications/ops-job-failure-types.js +73 -0
- package/dist/notifications/ops-job-failure-types.js.map +1 -0
- package/dist/notifications/recipients-http.d.ts +66 -0
- package/dist/notifications/recipients-http.d.ts.map +1 -0
- package/dist/notifications/recipients-http.js +148 -0
- package/dist/notifications/recipients-http.js.map +1 -0
- package/dist/notifications/recipients.d.ts +50 -0
- package/dist/notifications/recipients.d.ts.map +1 -0
- package/dist/notifications/recipients.js +59 -0
- package/dist/notifications/recipients.js.map +1 -0
- package/dist/prompts/registry.d.ts +55 -0
- package/dist/prompts/registry.d.ts.map +1 -0
- package/dist/prompts/registry.js +76 -0
- package/dist/prompts/registry.js.map +1 -0
- package/dist/runtime/heavy-phase-queue.d.ts +101 -0
- package/dist/runtime/heavy-phase-queue.d.ts.map +1 -0
- package/dist/runtime/heavy-phase-queue.js +129 -0
- package/dist/runtime/heavy-phase-queue.js.map +1 -0
- package/dist/sessions/content-policy.d.ts +55 -0
- package/dist/sessions/content-policy.d.ts.map +1 -0
- package/dist/sessions/content-policy.js +133 -0
- package/dist/sessions/content-policy.js.map +1 -0
- package/dist/sessions/registry-admin.d.ts +19 -0
- package/dist/sessions/registry-admin.d.ts.map +1 -0
- package/dist/sessions/registry-admin.js +42 -0
- package/dist/sessions/registry-admin.js.map +1 -0
- package/dist/sessions/registry-freshness.d.ts +8 -0
- package/dist/sessions/registry-freshness.d.ts.map +1 -0
- package/dist/sessions/registry-freshness.js +108 -0
- package/dist/sessions/registry-freshness.js.map +1 -0
- package/dist/sessions/registry-ingest.d.ts +5 -0
- package/dist/sessions/registry-ingest.d.ts.map +1 -0
- package/dist/sessions/registry-ingest.js +113 -0
- package/dist/sessions/registry-ingest.js.map +1 -0
- package/dist/sessions/registry-publish.d.ts +18 -0
- package/dist/sessions/registry-publish.d.ts.map +1 -0
- package/dist/sessions/registry-publish.js +134 -0
- package/dist/sessions/registry-publish.js.map +1 -0
- package/dist/sessions/registry-store.d.ts +51 -0
- package/dist/sessions/registry-store.d.ts.map +1 -0
- package/dist/sessions/registry-store.js +134 -0
- package/dist/sessions/registry-store.js.map +1 -0
- package/dist/sessions/registry-types.d.ts +180 -0
- package/dist/sessions/registry-types.d.ts.map +1 -0
- package/dist/sessions/registry-types.js +32 -0
- package/dist/sessions/registry-types.js.map +1 -0
- package/dist/sessions/registry.d.ts +45 -0
- package/dist/sessions/registry.d.ts.map +1 -0
- package/dist/sessions/registry.js +74 -0
- package/dist/sessions/registry.js.map +1 -0
- package/dist/sessions/relay-bind.d.ts +38 -0
- package/dist/sessions/relay-bind.d.ts.map +1 -0
- package/dist/sessions/relay-bind.js +74 -0
- package/dist/sessions/relay-bind.js.map +1 -0
- package/dist/sessions/relay-brand.d.ts +2 -0
- package/dist/sessions/relay-brand.d.ts.map +1 -0
- package/dist/sessions/relay-brand.js +7 -0
- package/dist/sessions/relay-brand.js.map +1 -0
- package/dist/sessions/relay-capsule.d.ts +50 -0
- package/dist/sessions/relay-capsule.d.ts.map +1 -0
- package/dist/sessions/relay-capsule.js +72 -0
- package/dist/sessions/relay-capsule.js.map +1 -0
- package/dist/sessions/relay-chain-failure.d.ts +25 -0
- package/dist/sessions/relay-chain-failure.d.ts.map +1 -0
- package/dist/sessions/relay-chain-failure.js +23 -0
- package/dist/sessions/relay-chain-failure.js.map +1 -0
- package/dist/sessions/relay-chain.d.ts +74 -0
- package/dist/sessions/relay-chain.d.ts.map +1 -0
- package/dist/sessions/relay-chain.js +71 -0
- package/dist/sessions/relay-chain.js.map +1 -0
- package/dist/sessions/relay-composition.d.ts +8 -0
- package/dist/sessions/relay-composition.d.ts.map +1 -0
- package/dist/sessions/relay-composition.js +65 -0
- package/dist/sessions/relay-composition.js.map +1 -0
- package/dist/sessions/relay-credit.d.ts +40 -0
- package/dist/sessions/relay-credit.d.ts.map +1 -0
- package/dist/sessions/relay-credit.js +68 -0
- package/dist/sessions/relay-credit.js.map +1 -0
- package/dist/sessions/relay-engine.d.ts +19 -0
- package/dist/sessions/relay-engine.d.ts.map +1 -0
- package/dist/sessions/relay-engine.js +34 -0
- package/dist/sessions/relay-engine.js.map +1 -0
- package/dist/sessions/relay-frames.d.ts +28 -0
- package/dist/sessions/relay-frames.d.ts.map +1 -0
- package/dist/sessions/relay-frames.js +72 -0
- package/dist/sessions/relay-frames.js.map +1 -0
- package/dist/sessions/relay-lane-client.d.ts +7 -0
- package/dist/sessions/relay-lane-client.d.ts.map +1 -0
- package/dist/sessions/relay-lane-client.js +137 -0
- package/dist/sessions/relay-lane-client.js.map +1 -0
- package/dist/sessions/relay-lane-lease.d.ts +20 -0
- package/dist/sessions/relay-lane-lease.d.ts.map +1 -0
- package/dist/sessions/relay-lane-lease.js +74 -0
- package/dist/sessions/relay-lane-lease.js.map +1 -0
- package/dist/sessions/relay-lane-record.d.ts +28 -0
- package/dist/sessions/relay-lane-record.d.ts.map +1 -0
- package/dist/sessions/relay-lane-record.js +28 -0
- package/dist/sessions/relay-lane-record.js.map +1 -0
- package/dist/sessions/relay-lane-stream.d.ts +13 -0
- package/dist/sessions/relay-lane-stream.d.ts.map +1 -0
- package/dist/sessions/relay-lane-stream.js +148 -0
- package/dist/sessions/relay-lane-stream.js.map +1 -0
- package/dist/sessions/relay-routes.d.ts +368 -0
- package/dist/sessions/relay-routes.d.ts.map +1 -0
- package/dist/sessions/relay-routes.js +46 -0
- package/dist/sessions/relay-routes.js.map +1 -0
- package/dist/sessions/relay-skeleton.d.ts +4 -0
- package/dist/sessions/relay-skeleton.d.ts.map +1 -0
- package/dist/sessions/relay-skeleton.js +85 -0
- package/dist/sessions/relay-skeleton.js.map +1 -0
- package/dist/sessions/relay-types.d.ts +107 -0
- package/dist/sessions/relay-types.d.ts.map +1 -0
- package/dist/sessions/relay-types.js +2 -0
- package/dist/sessions/relay-types.js.map +1 -0
- package/dist/sessions/relay-validate.d.ts +8 -0
- package/dist/sessions/relay-validate.d.ts.map +1 -0
- package/dist/sessions/relay-validate.js +169 -0
- package/dist/sessions/relay-validate.js.map +1 -0
- package/dist/sessions/relay-wire.d.ts +8 -0
- package/dist/sessions/relay-wire.d.ts.map +1 -0
- package/dist/sessions/relay-wire.js +37 -0
- package/dist/sessions/relay-wire.js.map +1 -0
- package/dist/sessions/relay-wiring.d.ts +26 -0
- package/dist/sessions/relay-wiring.d.ts.map +1 -0
- package/dist/sessions/relay-wiring.js +13 -0
- package/dist/sessions/relay-wiring.js.map +1 -0
- package/dist/sessions/relay.d.ts +11 -0
- package/dist/sessions/relay.d.ts.map +1 -0
- package/dist/sessions/relay.js +71 -0
- package/dist/sessions/relay.js.map +1 -0
- package/dist/storage/descriptor.d.ts +1 -1
- package/dist/storage/errors.d.ts +1 -1
- package/dist/storage/identity/atomic-deletion.d.ts +4 -0
- package/dist/storage/identity/atomic-deletion.d.ts.map +1 -0
- package/dist/storage/identity/atomic-deletion.js +235 -0
- package/dist/storage/identity/atomic-deletion.js.map +1 -0
- package/dist/storage/identity/custody-composition.d.ts +9 -0
- package/dist/storage/identity/custody-composition.d.ts.map +1 -0
- package/dist/storage/identity/custody-composition.js +31 -0
- package/dist/storage/identity/custody-composition.js.map +1 -0
- package/dist/storage/identity/custody-delivery-record.d.ts +4 -0
- package/dist/storage/identity/custody-delivery-record.d.ts.map +1 -0
- package/dist/storage/identity/custody-delivery-record.js +11 -0
- package/dist/storage/identity/custody-delivery-record.js.map +1 -0
- package/dist/storage/identity/custody-host.d.ts +16 -0
- package/dist/storage/identity/custody-host.d.ts.map +1 -0
- package/dist/storage/identity/custody-host.js +5 -0
- package/dist/storage/identity/custody-host.js.map +1 -0
- package/dist/storage/identity/custody-import-deliveries.d.ts +6 -0
- package/dist/storage/identity/custody-import-deliveries.d.ts.map +1 -0
- package/dist/storage/identity/custody-import-deliveries.js +46 -0
- package/dist/storage/identity/custody-import-deliveries.js.map +1 -0
- package/dist/storage/identity/custody-import.d.ts +4 -0
- package/dist/storage/identity/custody-import.d.ts.map +1 -0
- package/dist/storage/identity/custody-import.js +364 -0
- package/dist/storage/identity/custody-import.js.map +1 -0
- package/dist/storage/identity/custody-journal-postgres.d.ts +125 -0
- package/dist/storage/identity/custody-journal-postgres.d.ts.map +1 -0
- package/dist/storage/identity/custody-journal-postgres.js +428 -0
- package/dist/storage/identity/custody-journal-postgres.js.map +1 -0
- package/dist/storage/identity/custody-journal-sqlite.d.ts +121 -0
- package/dist/storage/identity/custody-journal-sqlite.d.ts.map +1 -0
- package/dist/storage/identity/custody-journal-sqlite.js +345 -0
- package/dist/storage/identity/custody-journal-sqlite.js.map +1 -0
- package/dist/storage/identity/custody-lifecycle.d.ts +4 -0
- package/dist/storage/identity/custody-lifecycle.d.ts.map +1 -0
- package/dist/storage/identity/custody-lifecycle.js +42 -0
- package/dist/storage/identity/custody-lifecycle.js.map +1 -0
- package/dist/storage/identity/custody-postgres.d.ts +96 -0
- package/dist/storage/identity/custody-postgres.d.ts.map +1 -0
- package/dist/storage/identity/custody-postgres.js +726 -0
- package/dist/storage/identity/custody-postgres.js.map +1 -0
- package/dist/storage/identity/custody-records.d.ts +17 -0
- package/dist/storage/identity/custody-records.d.ts.map +1 -0
- package/dist/storage/identity/custody-records.js +260 -0
- package/dist/storage/identity/custody-records.js.map +1 -0
- package/dist/storage/identity/custody-shared.d.ts +28 -0
- package/dist/storage/identity/custody-shared.d.ts.map +1 -0
- package/dist/storage/identity/custody-shared.js +24 -0
- package/dist/storage/identity/custody-shared.js.map +1 -0
- package/dist/storage/identity/custody-sqlite.d.ts +93 -0
- package/dist/storage/identity/custody-sqlite.d.ts.map +1 -0
- package/dist/storage/identity/custody-sqlite.js +568 -0
- package/dist/storage/identity/custody-sqlite.js.map +1 -0
- package/dist/storage/identity/custody-tombstone-record.d.ts +3 -0
- package/dist/storage/identity/custody-tombstone-record.d.ts.map +1 -0
- package/dist/storage/identity/custody-tombstone-record.js +8 -0
- package/dist/storage/identity/custody-tombstone-record.js.map +1 -0
- package/dist/storage/identity/custody-transaction-guards.d.ts +16 -0
- package/dist/storage/identity/custody-transaction-guards.d.ts.map +1 -0
- package/dist/storage/identity/custody-transaction-guards.js +64 -0
- package/dist/storage/identity/custody-transaction-guards.js.map +1 -0
- package/dist/storage/identity/custody-transaction-ports.d.ts +9 -0
- package/dist/storage/identity/custody-transaction-ports.d.ts.map +1 -0
- package/dist/storage/identity/custody-transaction-ports.js +106 -0
- package/dist/storage/identity/custody-transaction-ports.js.map +1 -0
- package/dist/storage/identity/deletion-planes.d.ts +10 -0
- package/dist/storage/identity/deletion-planes.d.ts.map +1 -0
- package/dist/storage/identity/deletion-planes.js +54 -0
- package/dist/storage/identity/deletion-planes.js.map +1 -0
- package/dist/storage/identity/index.d.ts +18 -0
- package/dist/storage/identity/index.d.ts.map +1 -0
- package/dist/storage/identity/index.js +22 -0
- package/dist/storage/identity/index.js.map +1 -0
- package/dist/storage/identity/postgres.d.ts +16 -0
- package/dist/storage/identity/postgres.d.ts.map +1 -0
- package/dist/storage/identity/postgres.js +345 -0
- package/dist/storage/identity/postgres.js.map +1 -0
- package/dist/storage/identity/records.d.ts +12 -0
- package/dist/storage/identity/records.d.ts.map +1 -0
- package/dist/storage/identity/records.js +84 -0
- package/dist/storage/identity/records.js.map +1 -0
- package/dist/storage/identity/replica-sync.d.ts +4 -0
- package/dist/storage/identity/replica-sync.d.ts.map +1 -0
- package/dist/storage/identity/replica-sync.js +402 -0
- package/dist/storage/identity/replica-sync.js.map +1 -0
- package/dist/storage/identity/schema.d.ts +13 -0
- package/dist/storage/identity/schema.d.ts.map +1 -0
- package/dist/storage/identity/schema.js +418 -0
- package/dist/storage/identity/schema.js.map +1 -0
- package/dist/storage/identity/sqlite-schema.d.ts +4 -0
- package/dist/storage/identity/sqlite-schema.d.ts.map +1 -0
- package/dist/storage/identity/sqlite-schema.js +17 -0
- package/dist/storage/identity/sqlite-schema.js.map +1 -0
- package/dist/storage/identity/sqlite.d.ts +25 -0
- package/dist/storage/identity/sqlite.d.ts.map +1 -0
- package/dist/storage/identity/sqlite.js +233 -0
- package/dist/storage/identity/sqlite.js.map +1 -0
- package/dist/storage/identity/stores.d.ts +10 -0
- package/dist/storage/identity/stores.d.ts.map +1 -0
- package/dist/storage/identity/stores.js +5 -0
- package/dist/storage/identity/stores.js.map +1 -0
- package/dist/storage/identity/wiring.d.ts +20 -0
- package/dist/storage/identity/wiring.d.ts.map +1 -0
- package/dist/storage/identity/wiring.js +26 -0
- package/dist/storage/identity/wiring.js.map +1 -0
- package/dist/storage/identity/workspace-deletion.d.ts +3 -0
- package/dist/storage/identity/workspace-deletion.d.ts.map +1 -0
- package/dist/storage/identity/workspace-deletion.js +100 -0
- package/dist/storage/identity/workspace-deletion.js.map +1 -0
- package/dist/storage/postgres/journal.d.ts +1 -1
- package/dist/storage/postgres/profiles.d.ts +2 -2
- package/dist/storage/postgres/scope.d.ts +1 -1
- package/dist/storage/root-facade.d.ts +1 -1
- package/dist/storage/root-journal.d.ts +1 -1
- package/dist/storage/root-profiles.d.ts +1 -1
- package/docs/memory-mcp-candidate.md +46 -0
- package/docs/memory-mcp.md +98 -0
- package/examples/memory-mcp-stdio.mjs +42 -0
- package/package.json +66 -5
- package/ui/AdminUsersScreen.svelte +197 -0
- package/ui/AdminUsersScreen.svelte.d.ts +4 -0
- package/ui/LoginScreen.svelte +15 -0
- package/ui/LoginScreen.svelte.d.ts +4 -0
- package/ui/MembershipDecisionsScreen.svelte +76 -0
- package/ui/MembershipDecisionsScreen.svelte.d.ts +4 -0
- package/ui/RegistrationScreen.svelte +15 -0
- package/ui/RegistrationScreen.svelte.d.ts +4 -0
- package/ui/WorkspaceMembersScreen.svelte +86 -0
- package/ui/WorkspaceMembersScreen.svelte.d.ts +4 -0
- package/ui/auth-flow.ts +44 -0
- package/ui/management-ports.ts +36 -0
- package/ui/management-transport.ts +29 -0
- package/contracts/engram-memory-neutral-contract-v1.d.ts +0 -367
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// A2.3 identity slice: the SQLite profile of this lot's store slice — the
|
|
2
|
+
// conversation authority store and the audit/escalation ledger over the
|
|
3
|
+
// kernel's published `SqliteConnection` contract (opened via
|
|
4
|
+
// `openSqliteEngine({ path, moduleId })`, which owns process isolation and
|
|
5
|
+
// the module identity). The `cm_identity_*` schema is idempotent; entries
|
|
6
|
+
// seal through the same shared digest and verifier as the in-memory double
|
|
7
|
+
// and the PostgreSQL profile, so chain tamper detection is one behavior.
|
|
8
|
+
import { applyAtomicSqliteDdl } from '../storage/identity/sqlite-schema.js';
|
|
9
|
+
import { ConversationSessionError } from './conversation.js';
|
|
10
|
+
import { escalationEntryDigest, verifyEscalationChainsOf, } from './ledger.js';
|
|
11
|
+
/** Idempotent `cm_identity_*` schema set; safe on every open. */
|
|
12
|
+
export const IDENTITY_SQLITE_SCHEMA = [
|
|
13
|
+
`CREATE TABLE IF NOT EXISTS cm_identity_conversation_sessions (
|
|
14
|
+
conversation_session_id TEXT PRIMARY KEY,
|
|
15
|
+
user_id TEXT NOT NULL,
|
|
16
|
+
workspace_id TEXT NOT NULL,
|
|
17
|
+
status TEXT NOT NULL,
|
|
18
|
+
opened_at TEXT NOT NULL,
|
|
19
|
+
expires_at TEXT NOT NULL,
|
|
20
|
+
revoked_at TEXT)`,
|
|
21
|
+
`CREATE INDEX IF NOT EXISTS cm_identity_conversation_sessions_user
|
|
22
|
+
ON cm_identity_conversation_sessions (user_id)`,
|
|
23
|
+
`CREATE TABLE IF NOT EXISTS cm_identity_audit_events (
|
|
24
|
+
ordinal INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
25
|
+
at TEXT NOT NULL,
|
|
26
|
+
kind TEXT NOT NULL,
|
|
27
|
+
actor_id TEXT,
|
|
28
|
+
subject_id TEXT,
|
|
29
|
+
detail TEXT)`,
|
|
30
|
+
`CREATE TABLE IF NOT EXISTS cm_identity_escalation_entries (
|
|
31
|
+
ordinal INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
32
|
+
escalation_id TEXT NOT NULL,
|
|
33
|
+
owner_user_id TEXT NOT NULL,
|
|
34
|
+
workspace_id TEXT NOT NULL,
|
|
35
|
+
target_ref TEXT NOT NULL,
|
|
36
|
+
entry_json TEXT NOT NULL,
|
|
37
|
+
prev_entry_hash TEXT,
|
|
38
|
+
entry_hash TEXT NOT NULL)`,
|
|
39
|
+
`CREATE INDEX IF NOT EXISTS cm_identity_escalation_entries_escalation
|
|
40
|
+
ON cm_identity_escalation_entries (escalation_id)`,
|
|
41
|
+
];
|
|
42
|
+
export function applyIdentitySqliteSchema(db) {
|
|
43
|
+
applyAtomicSqliteDdl(db, IDENTITY_SQLITE_SCHEMA);
|
|
44
|
+
}
|
|
45
|
+
const rowToConversationSession = (row) => ({
|
|
46
|
+
conversationSessionId: row.conversation_session_id,
|
|
47
|
+
userId: row.user_id,
|
|
48
|
+
workspaceId: row.workspace_id,
|
|
49
|
+
status: row.status,
|
|
50
|
+
openedAt: row.opened_at,
|
|
51
|
+
expiresAt: row.expires_at,
|
|
52
|
+
revokedAt: row.revoked_at ?? undefined,
|
|
53
|
+
});
|
|
54
|
+
const rowToEscalationEntry = (row) => ({
|
|
55
|
+
...JSON.parse(row.entry_json),
|
|
56
|
+
prevEntryHash: row.prev_entry_hash ?? null,
|
|
57
|
+
entryHash: row.entry_hash,
|
|
58
|
+
});
|
|
59
|
+
const rowToAuditEvent = (row) => ({
|
|
60
|
+
at: row.at,
|
|
61
|
+
kind: row.kind,
|
|
62
|
+
actorId: row.actor_id ?? undefined,
|
|
63
|
+
subjectId: row.subject_id ?? undefined,
|
|
64
|
+
detail: row.detail ?? undefined,
|
|
65
|
+
});
|
|
66
|
+
/** One transaction per call; the engine's exclusive lock serializes writers. */
|
|
67
|
+
const withTransaction = (db, operation) => {
|
|
68
|
+
db.exec('BEGIN IMMEDIATE');
|
|
69
|
+
try {
|
|
70
|
+
const result = operation();
|
|
71
|
+
db.exec('COMMIT');
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
db.exec('ROLLBACK');
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export function createIdentityEnforcementSqliteStores(input) {
|
|
80
|
+
const db = input.db;
|
|
81
|
+
if (!input.transactionBound)
|
|
82
|
+
applyIdentitySqliteSchema(db);
|
|
83
|
+
const run = (operation) => input.transactionBound ? operation() : withTransaction(db, operation);
|
|
84
|
+
const conversations = {
|
|
85
|
+
async saveSession(record) {
|
|
86
|
+
run(() => db
|
|
87
|
+
.prepare(`INSERT INTO cm_identity_conversation_sessions
|
|
88
|
+
(conversation_session_id, user_id, workspace_id, status, opened_at, expires_at, revoked_at)
|
|
89
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
90
|
+
ON CONFLICT (conversation_session_id) DO UPDATE SET
|
|
91
|
+
user_id = excluded.user_id,
|
|
92
|
+
workspace_id = excluded.workspace_id,
|
|
93
|
+
status = excluded.status,
|
|
94
|
+
opened_at = excluded.opened_at,
|
|
95
|
+
expires_at = excluded.expires_at,
|
|
96
|
+
revoked_at = excluded.revoked_at`)
|
|
97
|
+
.run(record.conversationSessionId, record.userId, record.workspaceId, record.status, record.openedAt, record.expiresAt, record.revokedAt ?? null));
|
|
98
|
+
},
|
|
99
|
+
async findSession(conversationSessionId) {
|
|
100
|
+
const row = run(() => db
|
|
101
|
+
.prepare('SELECT * FROM cm_identity_conversation_sessions WHERE conversation_session_id = ?')
|
|
102
|
+
.get(conversationSessionId));
|
|
103
|
+
return row ? rowToConversationSession(row) : null;
|
|
104
|
+
},
|
|
105
|
+
async revokeSession(conversationSessionId, at) {
|
|
106
|
+
const row = run(() => {
|
|
107
|
+
const existing = db
|
|
108
|
+
.prepare('SELECT * FROM cm_identity_conversation_sessions WHERE conversation_session_id = ?')
|
|
109
|
+
.get(conversationSessionId);
|
|
110
|
+
if (!existing)
|
|
111
|
+
return undefined;
|
|
112
|
+
db.prepare(`UPDATE cm_identity_conversation_sessions
|
|
113
|
+
SET status = 'revoked', revoked_at = ?
|
|
114
|
+
WHERE conversation_session_id = ?`).run(at, conversationSessionId);
|
|
115
|
+
return db
|
|
116
|
+
.prepare('SELECT * FROM cm_identity_conversation_sessions WHERE conversation_session_id = ?')
|
|
117
|
+
.get(conversationSessionId);
|
|
118
|
+
});
|
|
119
|
+
if (!row)
|
|
120
|
+
throw new ConversationSessionError('not_found');
|
|
121
|
+
return rowToConversationSession(row);
|
|
122
|
+
},
|
|
123
|
+
async listSessionsForUser(userId) {
|
|
124
|
+
const rows = run(() => db
|
|
125
|
+
.prepare('SELECT * FROM cm_identity_conversation_sessions WHERE user_id = ? ORDER BY opened_at, conversation_session_id')
|
|
126
|
+
.all(userId));
|
|
127
|
+
return rows.map(rowToConversationSession);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
const ledger = {
|
|
131
|
+
async append(event) {
|
|
132
|
+
run(() => db
|
|
133
|
+
.prepare(`INSERT INTO cm_identity_audit_events (at, kind, actor_id, subject_id, detail)
|
|
134
|
+
VALUES (?, ?, ?, ?, ?)`)
|
|
135
|
+
.run(event.at, event.kind, event.actorId ?? null, event.subjectId ?? null, event.detail ?? null));
|
|
136
|
+
},
|
|
137
|
+
async listAuditEvents() {
|
|
138
|
+
const rows = run(() => db.prepare('SELECT * FROM cm_identity_audit_events ORDER BY ordinal').all());
|
|
139
|
+
return rows.map(rowToAuditEvent);
|
|
140
|
+
},
|
|
141
|
+
async appendEscalationEntry(draft) {
|
|
142
|
+
return run(() => {
|
|
143
|
+
const tail = db
|
|
144
|
+
.prepare(`SELECT entry_hash FROM cm_identity_escalation_entries
|
|
145
|
+
WHERE escalation_id = ? ORDER BY ordinal DESC LIMIT 1`)
|
|
146
|
+
.get(draft.escalationId);
|
|
147
|
+
const prevEntryHash = tail?.entry_hash ?? null;
|
|
148
|
+
const entry = {
|
|
149
|
+
...draft,
|
|
150
|
+
prevEntryHash,
|
|
151
|
+
entryHash: escalationEntryDigest(draft, prevEntryHash),
|
|
152
|
+
};
|
|
153
|
+
db.prepare(`INSERT INTO cm_identity_escalation_entries
|
|
154
|
+
(escalation_id, owner_user_id, workspace_id, target_ref, entry_json, prev_entry_hash, entry_hash)
|
|
155
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`).run(draft.escalationId, draft.ownerUserId, draft.workspaceId, draft.targetRef, JSON.stringify(draft), prevEntryHash, entry.entryHash);
|
|
156
|
+
return entry;
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
async listEscalationChain(escalationId) {
|
|
160
|
+
const rows = run(() => db
|
|
161
|
+
.prepare('SELECT * FROM cm_identity_escalation_entries WHERE escalation_id = ? ORDER BY ordinal')
|
|
162
|
+
.all(escalationId));
|
|
163
|
+
return rows.map(rowToEscalationEntry);
|
|
164
|
+
},
|
|
165
|
+
async listEscalations(query) {
|
|
166
|
+
const clauses = [];
|
|
167
|
+
const values = [];
|
|
168
|
+
if (query.ownerUserId !== undefined) {
|
|
169
|
+
values.push(query.ownerUserId);
|
|
170
|
+
clauses.push('owner_user_id = ?');
|
|
171
|
+
}
|
|
172
|
+
if (query.workspaceId !== undefined) {
|
|
173
|
+
values.push(query.workspaceId);
|
|
174
|
+
clauses.push('workspace_id = ?');
|
|
175
|
+
}
|
|
176
|
+
if (query.targetRef !== undefined) {
|
|
177
|
+
values.push(query.targetRef);
|
|
178
|
+
clauses.push('target_ref = ?');
|
|
179
|
+
}
|
|
180
|
+
const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';
|
|
181
|
+
const rows = run(() => db.prepare(`SELECT * FROM cm_identity_escalation_entries${where} ORDER BY ordinal`).all(...values));
|
|
182
|
+
return rows.map(rowToEscalationEntry);
|
|
183
|
+
},
|
|
184
|
+
async verifyEscalationChains() {
|
|
185
|
+
const rows = run(() => db
|
|
186
|
+
.prepare('SELECT * FROM cm_identity_escalation_entries ORDER BY escalation_id, ordinal')
|
|
187
|
+
.all());
|
|
188
|
+
return verifyEscalationChainsOf(rows.map(rowToEscalationEntry));
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
return { conversations, ledger };
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=sqlite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/identity/sqlite.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wEAAwE;AACxE,6DAA6D;AAC7D,2EAA2E;AAC3E,0EAA0E;AAC1E,2EAA2E;AAC3E,yEAAyE;AAGzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAmE,MAAM,mBAAmB,CAAC;AAC9H,OAAO,EACL,qBA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,CAAC;QAClE,CAAC;KACF,CAAC;IAEF,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { DeviceCodeStore, IdentityAuditPort, InvitationStore, InvitationTokenPort, LoginSessionStore, UserAccountStore } from './ports.js';
|
|
2
|
+
import { type ConsumeInvitationResult, type DeviceCodeIssuance, type DeviceCodeRecord, type DeviceCodePollOutcome, type IdentityClock, type InvitationInput, type InvitationRecord, type LoginSession, type LoginSessionInput } from './types.js';
|
|
3
|
+
export interface InvitationDomain {
|
|
4
|
+
issueInvitation(input: InvitationInput, actorId: string): Promise<InvitationRecord>;
|
|
5
|
+
consumeInvitation(token: string, now: string): Promise<ConsumeInvitationResult>;
|
|
6
|
+
revokeInvitation(invitationId: string, actorId: string): Promise<InvitationRecord>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createInvitations(input: {
|
|
9
|
+
readonly invitations: InvitationStore;
|
|
10
|
+
readonly tokens: InvitationTokenPort;
|
|
11
|
+
readonly audit: IdentityAuditPort;
|
|
12
|
+
readonly clock?: IdentityClock;
|
|
13
|
+
}): InvitationDomain;
|
|
14
|
+
/** F04 device-code triplet: the device polls with the device code; the user
|
|
15
|
+
approves with the user code. Approval binds the enrolment to an active
|
|
16
|
+
account; the codes are opaque values from the injected token port. */
|
|
17
|
+
export interface DeviceEnrolmentDomain {
|
|
18
|
+
issueDeviceCode(device: {
|
|
19
|
+
readonly deviceName?: string | null;
|
|
20
|
+
}, options: {
|
|
21
|
+
readonly now: string;
|
|
22
|
+
readonly ttlSeconds: number;
|
|
23
|
+
readonly intervalSec?: number;
|
|
24
|
+
}): Promise<DeviceCodeIssuance>;
|
|
25
|
+
pollDeviceCode(deviceCode: string, now: string): Promise<DeviceCodePollOutcome>;
|
|
26
|
+
approveDeviceCode(userCode: string, approval: {
|
|
27
|
+
readonly userId: string;
|
|
28
|
+
}, now: string): Promise<DeviceCodeRecord>;
|
|
29
|
+
}
|
|
30
|
+
export declare function createDeviceEnrolment(input: {
|
|
31
|
+
readonly deviceCodes: DeviceCodeStore;
|
|
32
|
+
readonly accounts: UserAccountStore;
|
|
33
|
+
readonly tokens: InvitationTokenPort;
|
|
34
|
+
readonly audit: IdentityAuditPort;
|
|
35
|
+
}): DeviceEnrolmentDomain;
|
|
36
|
+
export interface LoginSessionDomain {
|
|
37
|
+
createSession(input: LoginSessionInput, options: {
|
|
38
|
+
readonly now: string;
|
|
39
|
+
readonly ttlSeconds: number;
|
|
40
|
+
}): Promise<LoginSession>;
|
|
41
|
+
validateSession(sessionId: string, now: string): Promise<LoginSession>;
|
|
42
|
+
refreshSession(sessionId: string, options: {
|
|
43
|
+
readonly now: string;
|
|
44
|
+
readonly ttlSeconds: number;
|
|
45
|
+
}): Promise<LoginSession>;
|
|
46
|
+
revokeSession(sessionId: string, actorId: string): Promise<LoginSession>;
|
|
47
|
+
revokeAllSessionsForUser(userId: string, actorId: string): Promise<number>;
|
|
48
|
+
listSessionsForUser(userId: string): Promise<readonly LoginSession[]>;
|
|
49
|
+
}
|
|
50
|
+
export declare function createLoginSessions(input: {
|
|
51
|
+
readonly sessions: LoginSessionStore;
|
|
52
|
+
readonly clock?: IdentityClock;
|
|
53
|
+
}): LoginSessionDomain;
|
|
54
|
+
//# sourceMappingURL=access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/identity-contracts/access.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACj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@
|
|
|
1
|
+
// Identity core contracts: invitations, device enrolment entry and login
|
|
2
|
+
// sessions (F04, F05). Invitation tokens carry the `sit_` prefix; entropy comes
|
|
3
|
+
// from an injected port so tests stay deterministic. Login sessions are
|
|
4
|
+
// distinct from agent and runtime sessions; revoking one class never touches
|
|
5
|
+
// another directly.
|
|
6
|
+
import { AccountNotActiveError, DeviceCodeError, IdentityNotFoundError, InvitationError, LoginSessionError } from './errors.js';
|
|
7
|
+
import { systemIdentityClock, } from './types.js';
|
|
8
|
+
export function createInvitations(input) {
|
|
9
|
+
const clock = input.clock ?? systemIdentityClock;
|
|
10
|
+
return {
|
|
11
|
+
async issueInvitation(invitation, actorId) {
|
|
12
|
+
const record = {
|
|
13
|
+
...invitation,
|
|
14
|
+
token: `sit_${input.tokens.issue()}`,
|
|
15
|
+
status: 'pending',
|
|
16
|
+
};
|
|
17
|
+
await input.invitations.saveInvitation(record);
|
|
18
|
+
await input.audit.append({
|
|
19
|
+
at: clock(),
|
|
20
|
+
kind: 'invitation.issued',
|
|
21
|
+
actorId,
|
|
22
|
+
subjectId: invitation.invitationId,
|
|
23
|
+
});
|
|
24
|
+
return record;
|
|
25
|
+
},
|
|
26
|
+
async consumeInvitation(token, now) {
|
|
27
|
+
const invitation = await input.invitations.findInvitationByToken(token);
|
|
28
|
+
if (!invitation)
|
|
29
|
+
throw new InvitationError('not_found');
|
|
30
|
+
if (invitation.status === 'revoked')
|
|
31
|
+
throw new InvitationError('revoked');
|
|
32
|
+
if (invitation.status === 'consumed')
|
|
33
|
+
throw new InvitationError('consumed');
|
|
34
|
+
if (invitation.expiresAt <= now)
|
|
35
|
+
throw new InvitationError('expired');
|
|
36
|
+
const consumed = await input.invitations.markInvitationConsumed(token, now);
|
|
37
|
+
if (!consumed)
|
|
38
|
+
throw new InvitationError('consumed');
|
|
39
|
+
return {
|
|
40
|
+
invitation: { ...invitation, status: 'consumed', consumedAt: now },
|
|
41
|
+
emailVerified: true,
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
async revokeInvitation(invitationId, actorId) {
|
|
45
|
+
const invitation = await input.invitations.findInvitation(invitationId);
|
|
46
|
+
if (!invitation)
|
|
47
|
+
throw new IdentityNotFoundError('invitation', invitationId);
|
|
48
|
+
const revoked = await input.invitations.revokeInvitation(invitationId);
|
|
49
|
+
await input.audit.append({
|
|
50
|
+
at: clock(),
|
|
51
|
+
kind: 'invitation.revoked',
|
|
52
|
+
actorId,
|
|
53
|
+
subjectId: invitationId,
|
|
54
|
+
});
|
|
55
|
+
return revoked;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function createDeviceEnrolment(input) {
|
|
60
|
+
return {
|
|
61
|
+
async issueDeviceCode(device, options) {
|
|
62
|
+
const now = options.now;
|
|
63
|
+
const record = {
|
|
64
|
+
deviceCode: input.tokens.issue(),
|
|
65
|
+
userCode: input.tokens.issue(),
|
|
66
|
+
deviceName: device.deviceName ?? null,
|
|
67
|
+
status: 'pending',
|
|
68
|
+
issuedAt: now,
|
|
69
|
+
expiresAt: addSeconds(now, options.ttlSeconds),
|
|
70
|
+
};
|
|
71
|
+
await input.deviceCodes.saveDeviceCode(record);
|
|
72
|
+
const issuance = {
|
|
73
|
+
deviceCode: record.deviceCode,
|
|
74
|
+
userCode: record.userCode,
|
|
75
|
+
intervalSec: options.intervalSec ?? 5,
|
|
76
|
+
expiresAt: record.expiresAt,
|
|
77
|
+
};
|
|
78
|
+
await input.audit.append({ at: now, kind: 'device_code.issued', subjectId: record.deviceCode });
|
|
79
|
+
return issuance;
|
|
80
|
+
},
|
|
81
|
+
async pollDeviceCode(deviceCode, now) {
|
|
82
|
+
const record = await input.deviceCodes.findDeviceCode(deviceCode);
|
|
83
|
+
if (!record)
|
|
84
|
+
throw new DeviceCodeError('not_found');
|
|
85
|
+
if (record.status === 'approved') {
|
|
86
|
+
return { status: 'approved', userId: record.approvedUserId, deviceName: record.deviceName };
|
|
87
|
+
}
|
|
88
|
+
if (record.expiresAt <= now)
|
|
89
|
+
return { status: 'expired' };
|
|
90
|
+
return { status: 'authorization_pending' };
|
|
91
|
+
},
|
|
92
|
+
async approveDeviceCode(userCode, approval, now) {
|
|
93
|
+
const account = await input.accounts.findAccount(approval.userId);
|
|
94
|
+
if (!account || account.accountStatus !== 'active')
|
|
95
|
+
throw new AccountNotActiveError(approval.userId);
|
|
96
|
+
const record = await input.deviceCodes.findDeviceCodeByUser(userCode);
|
|
97
|
+
if (!record)
|
|
98
|
+
throw new DeviceCodeError('not_found');
|
|
99
|
+
if (record.expiresAt <= now)
|
|
100
|
+
throw new DeviceCodeError('expired');
|
|
101
|
+
const approved = await input.deviceCodes.approveDeviceCode(userCode, approval.userId, now);
|
|
102
|
+
if (!approved)
|
|
103
|
+
throw new DeviceCodeError('already_resolved');
|
|
104
|
+
await input.audit.append({ at: now, kind: 'device_code.approved', actorId: approval.userId, subjectId: userCode });
|
|
105
|
+
return { ...record, status: 'approved', approvedUserId: approval.userId, approvedAt: now };
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function addSeconds(now, ttlSeconds) {
|
|
110
|
+
return new Date(Date.parse(now) + ttlSeconds * 1000).toISOString();
|
|
111
|
+
}
|
|
112
|
+
export function createLoginSessions(input) {
|
|
113
|
+
const clock = input.clock ?? systemIdentityClock;
|
|
114
|
+
async function requireSession(sessionId) {
|
|
115
|
+
const session = await input.sessions.findSession(sessionId);
|
|
116
|
+
if (!session)
|
|
117
|
+
throw new LoginSessionError('not_found');
|
|
118
|
+
return session;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
async createSession(session, options) {
|
|
122
|
+
const record = {
|
|
123
|
+
sessionId: session.sessionId,
|
|
124
|
+
userId: session.userId,
|
|
125
|
+
status: 'active',
|
|
126
|
+
mfaState: session.mfaState ?? 'none',
|
|
127
|
+
createdAt: options.now,
|
|
128
|
+
expiresAt: addSeconds(options.now, options.ttlSeconds),
|
|
129
|
+
refreshCount: 0,
|
|
130
|
+
};
|
|
131
|
+
await input.sessions.createSession(record);
|
|
132
|
+
return record;
|
|
133
|
+
},
|
|
134
|
+
async validateSession(sessionId, now) {
|
|
135
|
+
const session = await requireSession(sessionId);
|
|
136
|
+
if (session.status === 'revoked')
|
|
137
|
+
throw new LoginSessionError('revoked');
|
|
138
|
+
if (session.status === 'expired' || session.expiresAt <= now) {
|
|
139
|
+
throw new LoginSessionError('expired');
|
|
140
|
+
}
|
|
141
|
+
return session;
|
|
142
|
+
},
|
|
143
|
+
async refreshSession(sessionId, options) {
|
|
144
|
+
const session = await requireSession(sessionId);
|
|
145
|
+
if (session.status === 'revoked')
|
|
146
|
+
throw new LoginSessionError('revoked');
|
|
147
|
+
if (session.expiresAt <= options.now)
|
|
148
|
+
throw new LoginSessionError('expired');
|
|
149
|
+
return input.sessions.touchSession(sessionId, {
|
|
150
|
+
expiresAt: addSeconds(options.now, options.ttlSeconds),
|
|
151
|
+
refreshCount: session.refreshCount + 1,
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
async revokeSession(sessionId, _actorId) {
|
|
155
|
+
const session = await requireSession(sessionId);
|
|
156
|
+
if (session.status === 'revoked')
|
|
157
|
+
return session;
|
|
158
|
+
return input.sessions.revokeSession(sessionId, clock());
|
|
159
|
+
},
|
|
160
|
+
async revokeAllSessionsForUser(userId, _actorId) {
|
|
161
|
+
return input.sessions.revokeAllSessionsForUser(userId, clock());
|
|
162
|
+
},
|
|
163
|
+
async listSessionsForUser(userId) {
|
|
164
|
+
return input.sessions.listSessionsForUser(userId);
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.js","sourceRoot":"","sources":["../../src/identity-contracts/access.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,gFAAgF;AAChF,wEAAwE;AACxE,6EAA6E;AAC7E,oBAAoB;AAEpB,OAAO,EAAE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MAAM,KAAK,SAAS;gBAAE,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC;YACzE,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG;gBAAE,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAC7E,OAAO,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,EAAE;gBAC5C,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC;gBACtD,YAAY,EAAE,OAAO,CAAC,YAAY,GAAG,CAAC;aACvC,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,QAAQ;YACrC,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC;YAChD,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC;YACjD,OAAO,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,KAAK,CAAC,wBAAwB,CAAC,MAAM,EAAE,QAAQ;YAC7C,OAAO,KAAK,CAAC,QAAQ,CAAC,wBAAwB,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAClE,CAAC;QACD,KAAK,CAAC,mBAAmB,CAAC,MAAM;YAC9B,OAAO,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACpD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { IdentityProofStore, UserAccountStore, IdentityAuditPort } from './ports.js';
|
|
2
|
+
import { type GlobalRole, type IdentityClock, type IdentityProof, type IdentityProofKind, type RegisterAccountInput, type UserAccount, type VerifiedProofSubject } from './types.js';
|
|
3
|
+
export interface UserAccountDomain {
|
|
4
|
+
register(input: RegisterAccountInput, options?: {
|
|
5
|
+
readonly firstAdmin?: boolean;
|
|
6
|
+
}): Promise<UserAccount>;
|
|
7
|
+
approveAccount(userId: string, input: {
|
|
8
|
+
readonly role: GlobalRole;
|
|
9
|
+
readonly actorId: string;
|
|
10
|
+
}): Promise<UserAccount>;
|
|
11
|
+
disableAccount(userId: string, actorId: string): Promise<UserAccount>;
|
|
12
|
+
reactivateAccount(userId: string, actorId: string): Promise<UserAccount>;
|
|
13
|
+
deleteAccount(userId: string, actorId: string): Promise<void>;
|
|
14
|
+
getAccount(userId: string): Promise<UserAccount>;
|
|
15
|
+
listUsers(): Promise<readonly UserAccount[]>;
|
|
16
|
+
/** Self-service surface (F02): the caller acts on its own account only. */
|
|
17
|
+
getSelf(userId: string): Promise<UserAccount>;
|
|
18
|
+
disableSelf(userId: string): Promise<UserAccount>;
|
|
19
|
+
deleteSelf(userId: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare function createUserAccounts(input: {
|
|
22
|
+
readonly accounts: UserAccountStore;
|
|
23
|
+
readonly audit: IdentityAuditPort;
|
|
24
|
+
readonly clock?: IdentityClock;
|
|
25
|
+
}): UserAccountDomain;
|
|
26
|
+
export interface IdentityProofDomain {
|
|
27
|
+
registerProof(input: {
|
|
28
|
+
readonly proofId: string;
|
|
29
|
+
readonly userId: string;
|
|
30
|
+
readonly kind: IdentityProofKind;
|
|
31
|
+
readonly provider?: string;
|
|
32
|
+
readonly expiresAt?: string;
|
|
33
|
+
}): Promise<IdentityProof>;
|
|
34
|
+
verifyProof(input: {
|
|
35
|
+
readonly proofId: string;
|
|
36
|
+
readonly userId: string;
|
|
37
|
+
}, now: string): Promise<VerifiedProofSubject>;
|
|
38
|
+
revokeProof(proofId: string, actorId: string): Promise<IdentityProof>;
|
|
39
|
+
}
|
|
40
|
+
export declare function createIdentityProofs(input: {
|
|
41
|
+
readonly proofs: IdentityProofStore;
|
|
42
|
+
readonly clock?: IdentityClock;
|
|
43
|
+
}): IdentityProofDomain;
|
|
44
|
+
//# sourceMappingURL=accounts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identity proofs (F02, F03).
|
|
2
|
+
// Account approval is the first approval; it never implies tenant membership.
|
|
3
|
+
import { AccountNotActiveError, AccountTransitionError, AdminUserProtectedError, IdentityConflictError, IdentityNotFoundError, ProofVerificationError, SelfActionForbiddenError, } from './errors.js';
|
|
4
|
+
import { systemIdentityClock, } from './types.js';
|
|
5
|
+
function isProtectedAdmin(role) {
|
|
6
|
+
return role === 'admin_app' || role === 'admin_org';
|
|
7
|
+
}
|
|
8
|
+
export function createUserAccounts(input) {
|
|
9
|
+
const clock = input.clock ?? systemIdentityClock;
|
|
10
|
+
async function requireAccount(userId) {
|
|
11
|
+
const account = await input.accounts.findAccount(userId);
|
|
12
|
+
if (!account)
|
|
13
|
+
throw new IdentityNotFoundError('user', userId);
|
|
14
|
+
return account;
|
|
15
|
+
}
|
|
16
|
+
function forbidSelfAction(userId, actorId, action) {
|
|
17
|
+
if (userId === actorId)
|
|
18
|
+
throw new SelfActionForbiddenError(action);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
async register(registerInput, options) {
|
|
22
|
+
const existing = await input.accounts.findAccountByEmail(registerInput.email);
|
|
23
|
+
if (existing)
|
|
24
|
+
throw new IdentityConflictError('email', `Email is already registered: ${registerInput.email}`);
|
|
25
|
+
const now = clock();
|
|
26
|
+
const record = {
|
|
27
|
+
userId: registerInput.userId,
|
|
28
|
+
email: registerInput.email,
|
|
29
|
+
accountStatus: options?.firstAdmin === true ? 'active' : 'pending_admin_approval',
|
|
30
|
+
globalRole: options?.firstAdmin === true ? 'admin_app' : 'guest',
|
|
31
|
+
createdAt: now,
|
|
32
|
+
updatedAt: now,
|
|
33
|
+
};
|
|
34
|
+
await input.accounts.createAccount(record);
|
|
35
|
+
await input.audit.append({ at: now, kind: 'account.registered', subjectId: record.userId });
|
|
36
|
+
return record;
|
|
37
|
+
},
|
|
38
|
+
async approveAccount(userId, approval) {
|
|
39
|
+
forbidSelfAction(userId, approval.actorId, 'approve');
|
|
40
|
+
const account = await requireAccount(userId);
|
|
41
|
+
if (account.accountStatus === 'deleted')
|
|
42
|
+
throw new AccountNotActiveError(userId);
|
|
43
|
+
const now = clock();
|
|
44
|
+
await input.accounts.setAccountStatus(userId, 'active', now);
|
|
45
|
+
const updated = await input.accounts.setGlobalRole(userId, approval.role, now);
|
|
46
|
+
await input.audit.append({ at: now, kind: 'account.approved', actorId: approval.actorId, subjectId: userId });
|
|
47
|
+
return updated;
|
|
48
|
+
},
|
|
49
|
+
async disableAccount(userId, actorId) {
|
|
50
|
+
forbidSelfAction(userId, actorId, 'disable');
|
|
51
|
+
const account = await requireAccount(userId);
|
|
52
|
+
if (isProtectedAdmin(account.globalRole))
|
|
53
|
+
throw new AdminUserProtectedError('disable');
|
|
54
|
+
if (account.accountStatus !== 'active' && account.accountStatus !== 'pending_admin_approval')
|
|
55
|
+
throw new AccountTransitionError();
|
|
56
|
+
const now = clock();
|
|
57
|
+
const updated = await input.accounts.setAccountStatus(userId, 'disabled', now);
|
|
58
|
+
await input.audit.append({ at: now, kind: 'account.disabled', actorId, subjectId: userId });
|
|
59
|
+
return updated;
|
|
60
|
+
},
|
|
61
|
+
async reactivateAccount(userId, actorId) {
|
|
62
|
+
forbidSelfAction(userId, actorId, 'reactivate');
|
|
63
|
+
const account = await requireAccount(userId);
|
|
64
|
+
if (account.accountStatus !== 'disabled')
|
|
65
|
+
throw new AccountTransitionError();
|
|
66
|
+
const now = clock();
|
|
67
|
+
const updated = await input.accounts.setAccountStatus(userId, 'active', now);
|
|
68
|
+
await input.audit.append({ at: now, kind: 'account.reactivated', actorId, subjectId: userId });
|
|
69
|
+
return updated;
|
|
70
|
+
},
|
|
71
|
+
async deleteAccount(userId, actorId) {
|
|
72
|
+
forbidSelfAction(userId, actorId, 'delete');
|
|
73
|
+
const account = await requireAccount(userId);
|
|
74
|
+
if (isProtectedAdmin(account.globalRole))
|
|
75
|
+
throw new AdminUserProtectedError('delete');
|
|
76
|
+
if (account.accountStatus !== 'disabled' && account.accountStatus !== 'pending_admin_approval') {
|
|
77
|
+
throw new AccountTransitionError('User must be pending or disabled before deletion');
|
|
78
|
+
}
|
|
79
|
+
const now = clock();
|
|
80
|
+
await input.accounts.deleteAccount(userId, now);
|
|
81
|
+
await input.audit.append({ at: now, kind: 'account.deleted', actorId, subjectId: userId });
|
|
82
|
+
},
|
|
83
|
+
async getAccount(userId) {
|
|
84
|
+
const account = await requireAccount(userId);
|
|
85
|
+
if (account.accountStatus === 'deleted')
|
|
86
|
+
throw new AccountNotActiveError(userId);
|
|
87
|
+
return account;
|
|
88
|
+
},
|
|
89
|
+
async listUsers() {
|
|
90
|
+
return input.accounts.listAccounts();
|
|
91
|
+
},
|
|
92
|
+
async getSelf(userId) {
|
|
93
|
+
const account = await requireAccount(userId);
|
|
94
|
+
if (account.accountStatus === 'deleted')
|
|
95
|
+
throw new AccountNotActiveError(userId);
|
|
96
|
+
return account;
|
|
97
|
+
},
|
|
98
|
+
async disableSelf(userId) {
|
|
99
|
+
const account = await requireAccount(userId);
|
|
100
|
+
if (account.accountStatus !== 'active')
|
|
101
|
+
throw new AccountTransitionError();
|
|
102
|
+
const now = clock();
|
|
103
|
+
const updated = await input.accounts.setAccountStatus(userId, 'disabled', now);
|
|
104
|
+
await input.audit.append({ at: now, kind: 'account.self_disabled', subjectId: userId });
|
|
105
|
+
return updated;
|
|
106
|
+
},
|
|
107
|
+
async deleteSelf(userId) {
|
|
108
|
+
const account = await requireAccount(userId);
|
|
109
|
+
if (account.accountStatus !== 'disabled')
|
|
110
|
+
throw new AccountTransitionError('User must be disabled before deletion');
|
|
111
|
+
const now = clock();
|
|
112
|
+
await input.accounts.deleteAccount(userId, now);
|
|
113
|
+
await input.audit.append({ at: now, kind: 'account.self_deleted', subjectId: userId });
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const SINGLE_USE_PROOFS = ['email_code', 'magic_link'];
|
|
118
|
+
export function createIdentityProofs(input) {
|
|
119
|
+
const clock = input.clock ?? systemIdentityClock;
|
|
120
|
+
return {
|
|
121
|
+
async registerProof(proof) {
|
|
122
|
+
const record = { ...proof, createdAt: clock() };
|
|
123
|
+
await input.proofs.addProof(record);
|
|
124
|
+
return record;
|
|
125
|
+
},
|
|
126
|
+
async verifyProof(lookup, now) {
|
|
127
|
+
const proof = await input.proofs.findProof(lookup.proofId);
|
|
128
|
+
if (!proof)
|
|
129
|
+
throw new ProofVerificationError('not_found');
|
|
130
|
+
if (proof.userId !== lookup.userId)
|
|
131
|
+
throw new ProofVerificationError('mismatch');
|
|
132
|
+
if (proof.revokedAt)
|
|
133
|
+
throw new ProofVerificationError('revoked');
|
|
134
|
+
if (proof.expiresAt && proof.expiresAt <= now)
|
|
135
|
+
throw new ProofVerificationError('expired');
|
|
136
|
+
if (proof.consumedAt)
|
|
137
|
+
throw new ProofVerificationError('consumed');
|
|
138
|
+
if (SINGLE_USE_PROOFS.includes(proof.kind))
|
|
139
|
+
await input.proofs.markProofConsumed(proof.proofId, now);
|
|
140
|
+
return { proofId: proof.proofId, userId: proof.userId, kind: proof.kind };
|
|
141
|
+
},
|
|
142
|
+
async revokeProof(proofId, _actorId) {
|
|
143
|
+
const proof = await input.proofs.findProof(proofId);
|
|
144
|
+
if (!proof)
|
|
145
|
+
throw new ProofVerificationError('not_found');
|
|
146
|
+
return input.proofs.revokeProof(proofId, clock());
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=accounts.js.map
|