@bevel-software/platform-core-backend 0.19.0 → 0.21.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/dist/core/catalog-cache-invalidation.d.ts +7 -2
- package/dist/core/catalog-cache-invalidation.d.ts.map +1 -1
- package/dist/core/catalog-cache-invalidation.js +8 -9
- package/dist/core/catalog-cache-invalidation.js.map +1 -1
- package/dist/core/core-ports.d.ts +19 -0
- package/dist/core/core-ports.d.ts.map +1 -1
- package/dist/core/core-ports.js.map +1 -1
- package/dist/core/create-core-server.d.ts +2 -0
- package/dist/core/create-core-server.d.ts.map +1 -1
- package/dist/core/create-core-server.js +45 -105
- package/dist/core/create-core-server.js.map +1 -1
- package/dist/core/create-core-services.d.ts +33 -5
- package/dist/core/create-core-services.d.ts.map +1 -1
- package/dist/core/create-core-services.js +146 -82
- package/dist/core/create-core-services.js.map +1 -1
- package/dist/core/lifecycle.d.ts +74 -28
- package/dist/core/lifecycle.d.ts.map +1 -1
- package/dist/core/lifecycle.js +157 -20
- package/dist/core/lifecycle.js.map +1 -1
- package/dist/core/public-config.d.ts +5 -1
- package/dist/core/public-config.d.ts.map +1 -1
- package/dist/core/public-config.js +7 -5
- package/dist/core/public-config.js.map +1 -1
- package/dist/core-config.d.ts +95 -1
- package/dist/core-config.d.ts.map +1 -1
- package/dist/core-config.js +24 -8
- package/dist/core-config.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/modules/access/access-control.service.d.ts +18 -1
- package/dist/modules/access/access-control.service.d.ts.map +1 -1
- package/dist/modules/access/access-control.service.js +19 -8
- package/dist/modules/access/access-control.service.js.map +1 -1
- package/dist/modules/access/access.routes.d.ts +2 -1
- package/dist/modules/access/access.routes.d.ts.map +1 -1
- package/dist/modules/access/access.routes.js +10 -10
- package/dist/modules/access/access.routes.js.map +1 -1
- package/dist/modules/access/change-read-gate.d.ts +6 -3
- package/dist/modules/access/change-read-gate.d.ts.map +1 -1
- package/dist/modules/access/change-read-gate.js +9 -6
- package/dist/modules/access/change-read-gate.js.map +1 -1
- package/dist/modules/access/creator-access.d.ts +4 -2
- package/dist/modules/access/creator-access.d.ts.map +1 -1
- package/dist/modules/access/creator-access.js +7 -4
- package/dist/modules/access/creator-access.js.map +1 -1
- package/dist/modules/agent-instructions/read-preamble.d.ts +2 -1
- package/dist/modules/agent-instructions/read-preamble.d.ts.map +1 -1
- package/dist/modules/agent-instructions/read-preamble.js +6 -9
- package/dist/modules/agent-instructions/read-preamble.js.map +1 -1
- package/dist/modules/audit/agent-audit.service.d.ts +54 -0
- package/dist/modules/audit/agent-audit.service.d.ts.map +1 -0
- package/dist/modules/audit/agent-audit.service.js +290 -0
- package/dist/modules/audit/agent-audit.service.js.map +1 -0
- package/dist/modules/audit/agent-rest-audit.middleware.d.ts +40 -0
- package/dist/modules/audit/agent-rest-audit.middleware.d.ts.map +1 -0
- package/dist/modules/audit/agent-rest-audit.middleware.js +75 -0
- package/dist/modules/audit/agent-rest-audit.middleware.js.map +1 -0
- package/dist/modules/audit/audit.contract.d.ts +145 -0
- package/dist/modules/audit/audit.contract.d.ts.map +1 -0
- package/dist/modules/audit/audit.contract.js +35 -0
- package/dist/modules/audit/audit.contract.js.map +1 -0
- package/dist/modules/audit/audit.routes.d.ts +21 -0
- package/dist/modules/audit/audit.routes.d.ts.map +1 -0
- package/dist/modules/audit/audit.routes.js +157 -0
- package/dist/modules/audit/audit.routes.js.map +1 -0
- package/dist/modules/audit/event-classifier.d.ts +52 -0
- package/dist/modules/audit/event-classifier.d.ts.map +1 -0
- package/dist/modules/audit/event-classifier.js +123 -0
- package/dist/modules/audit/event-classifier.js.map +1 -0
- package/dist/modules/audit/index.d.ts +7 -0
- package/dist/modules/audit/index.d.ts.map +1 -0
- package/dist/modules/audit/index.js +7 -0
- package/dist/modules/audit/index.js.map +1 -0
- package/dist/modules/audit/request-audit.d.ts +57 -0
- package/dist/modules/audit/request-audit.d.ts.map +1 -0
- package/dist/modules/audit/request-audit.js +117 -0
- package/dist/modules/audit/request-audit.js.map +1 -0
- package/dist/modules/auth/account-admission.d.ts +40 -0
- package/dist/modules/auth/account-admission.d.ts.map +1 -0
- package/dist/modules/auth/account-admission.js +17 -0
- package/dist/modules/auth/account-admission.js.map +1 -0
- package/dist/modules/auth/account.routes.d.ts.map +1 -1
- package/dist/modules/auth/account.routes.js +4 -1
- package/dist/modules/auth/account.routes.js.map +1 -1
- package/dist/modules/auth/auth.service.d.ts +19 -1
- package/dist/modules/auth/auth.service.d.ts.map +1 -1
- package/dist/modules/auth/auth.service.js +33 -1
- package/dist/modules/auth/auth.service.js.map +1 -1
- package/dist/modules/auth/oidc-auth-provider.d.ts.map +1 -1
- package/dist/modules/auth/oidc-auth-provider.js +9 -0
- package/dist/modules/auth/oidc-auth-provider.js.map +1 -1
- package/dist/modules/connection-probe/connection-probe.service.d.ts +13 -1
- package/dist/modules/connection-probe/connection-probe.service.d.ts.map +1 -1
- package/dist/modules/connection-probe/connection-probe.service.js +10 -2
- package/dist/modules/connection-probe/connection-probe.service.js.map +1 -1
- package/dist/modules/database/advisory-lock.d.ts +17 -0
- package/dist/modules/database/advisory-lock.d.ts.map +1 -1
- package/dist/modules/database/advisory-lock.js +24 -3
- package/dist/modules/database/advisory-lock.js.map +1 -1
- package/dist/modules/database/connection.d.ts +67 -2
- package/dist/modules/database/connection.d.ts.map +1 -1
- package/dist/modules/database/connection.js +118 -12
- package/dist/modules/database/connection.js.map +1 -1
- package/dist/modules/database/core-schema.d.ts +414 -0
- package/dist/modules/database/core-schema.d.ts.map +1 -1
- package/dist/modules/database/core-schema.js +99 -0
- package/dist/modules/database/core-schema.js.map +1 -1
- package/dist/modules/database/migrate.d.ts +1 -1
- package/dist/modules/database/migrate.d.ts.map +1 -1
- package/dist/modules/database/migrate.js +27 -3
- package/dist/modules/database/migrate.js.map +1 -1
- package/dist/modules/diff/diff.service.d.ts.map +1 -1
- package/dist/modules/diff/diff.service.js +6 -1
- package/dist/modules/diff/diff.service.js.map +1 -1
- package/dist/modules/kb-fs/branch-name.d.ts +0 -1
- package/dist/modules/kb-fs/branch-name.d.ts.map +1 -1
- package/dist/modules/kb-fs/branch-name.js +3 -3
- package/dist/modules/kb-fs/branch-name.js.map +1 -1
- package/dist/modules/kb-fs/clone-config.d.ts +9 -8
- package/dist/modules/kb-fs/clone-config.d.ts.map +1 -1
- package/dist/modules/kb-fs/clone-config.js +14 -12
- package/dist/modules/kb-fs/clone-config.js.map +1 -1
- package/dist/modules/kb-fs/git-guarded-filesystem.d.ts +9 -1
- package/dist/modules/kb-fs/git-guarded-filesystem.d.ts.map +1 -1
- package/dist/modules/kb-fs/git-guarded-filesystem.js +16 -3
- package/dist/modules/kb-fs/git-guarded-filesystem.js.map +1 -1
- package/dist/modules/mcp/mcp-auth.middleware.d.ts +1 -0
- package/dist/modules/mcp/mcp-auth.middleware.d.ts.map +1 -1
- package/dist/modules/mcp/mcp-auth.middleware.js +32 -0
- package/dist/modules/mcp/mcp-auth.middleware.js.map +1 -1
- package/dist/modules/mcp/mcp.routes.d.ts.map +1 -1
- package/dist/modules/mcp/mcp.routes.js +8 -1
- package/dist/modules/mcp/mcp.routes.js.map +1 -1
- package/dist/modules/mcp/mcp.service.d.ts +16 -1
- package/dist/modules/mcp/mcp.service.d.ts.map +1 -1
- package/dist/modules/mcp/mcp.service.js +52 -9
- package/dist/modules/mcp/mcp.service.js.map +1 -1
- package/dist/modules/mcp/oauth/bevel-oauth-provider.d.ts +59 -0
- package/dist/modules/mcp/oauth/bevel-oauth-provider.d.ts.map +1 -1
- package/dist/modules/mcp/oauth/bevel-oauth-provider.js +180 -8
- package/dist/modules/mcp/oauth/bevel-oauth-provider.js.map +1 -1
- package/dist/modules/plugins/compile/marketplace-compiler.service.d.ts +4 -4
- package/dist/modules/plugins/compile/marketplace-compiler.service.d.ts.map +1 -1
- package/dist/modules/plugins/compile/marketplace-compiler.service.js +7 -10
- package/dist/modules/plugins/compile/marketplace-compiler.service.js.map +1 -1
- package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.d.ts +4 -1
- package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.d.ts.map +1 -1
- package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.js +5 -3
- package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.js.map +1 -1
- package/dist/modules/plugins/discovery/kb-plugin-source.d.ts +6 -1
- package/dist/modules/plugins/discovery/kb-plugin-source.d.ts.map +1 -1
- package/dist/modules/plugins/discovery/kb-plugin-source.js +14 -9
- package/dist/modules/plugins/discovery/kb-plugin-source.js.map +1 -1
- package/dist/modules/plugins/discovery/native.source.d.ts +4 -1
- package/dist/modules/plugins/discovery/native.source.d.ts.map +1 -1
- package/dist/modules/plugins/discovery/native.source.js +4 -2
- package/dist/modules/plugins/discovery/native.source.js.map +1 -1
- package/dist/modules/plugins/index.d.ts +1 -1
- package/dist/modules/plugins/index.d.ts.map +1 -1
- package/dist/modules/plugins/index.js +1 -1
- package/dist/modules/plugins/index.js.map +1 -1
- package/dist/modules/plugins/join-request-jobs.service.d.ts +3 -1
- package/dist/modules/plugins/join-request-jobs.service.d.ts.map +1 -1
- package/dist/modules/plugins/join-request-jobs.service.js +6 -6
- package/dist/modules/plugins/join-request-jobs.service.js.map +1 -1
- package/dist/modules/plugins/join-requests.service.d.ts +3 -1
- package/dist/modules/plugins/join-requests.service.d.ts.map +1 -1
- package/dist/modules/plugins/join-requests.service.js +9 -8
- package/dist/modules/plugins/join-requests.service.js.map +1 -1
- package/dist/modules/plugins/plugin-links.d.ts +65 -10
- package/dist/modules/plugins/plugin-links.d.ts.map +1 -1
- package/dist/modules/plugins/plugin-links.js +136 -31
- package/dist/modules/plugins/plugin-links.js.map +1 -1
- package/dist/modules/plugins/plugin-links.service.d.ts +107 -5
- package/dist/modules/plugins/plugin-links.service.d.ts.map +1 -1
- package/dist/modules/plugins/plugin-links.service.js +151 -21
- package/dist/modules/plugins/plugin-links.service.js.map +1 -1
- package/dist/modules/plugins/plugin-provision.service.d.ts +10 -3
- package/dist/modules/plugins/plugin-provision.service.d.ts.map +1 -1
- package/dist/modules/plugins/plugin-provision.service.js +33 -26
- package/dist/modules/plugins/plugin-provision.service.js.map +1 -1
- package/dist/modules/plugins/plugin-rename.service.d.ts +4 -2
- package/dist/modules/plugins/plugin-rename.service.d.ts.map +1 -1
- package/dist/modules/plugins/plugin-rename.service.js +10 -12
- package/dist/modules/plugins/plugin-rename.service.js.map +1 -1
- package/dist/modules/plugins/plugins.routes.d.ts +3 -0
- package/dist/modules/plugins/plugins.routes.d.ts.map +1 -1
- package/dist/modules/plugins/plugins.routes.js +45 -15
- package/dist/modules/plugins/plugins.routes.js.map +1 -1
- package/dist/modules/plugins/plugins.service.d.ts +4 -4
- package/dist/modules/plugins/plugins.service.d.ts.map +1 -1
- package/dist/modules/plugins/plugins.service.js +7 -10
- package/dist/modules/plugins/plugins.service.js.map +1 -1
- package/dist/modules/plugins/teams.routes.d.ts +4 -1
- package/dist/modules/plugins/teams.routes.d.ts.map +1 -1
- package/dist/modules/plugins/teams.routes.js +11 -9
- package/dist/modules/plugins/teams.routes.js.map +1 -1
- package/dist/modules/secrets-vault/index.d.ts +1 -1
- package/dist/modules/secrets-vault/index.d.ts.map +1 -1
- package/dist/modules/secrets-vault/index.js +1 -1
- package/dist/modules/secrets-vault/index.js.map +1 -1
- package/dist/modules/secrets-vault/secrets-variable-loader.d.ts +29 -11
- package/dist/modules/secrets-vault/secrets-variable-loader.d.ts.map +1 -1
- package/dist/modules/secrets-vault/secrets-variable-loader.js +46 -21
- package/dist/modules/secrets-vault/secrets-variable-loader.js.map +1 -1
- package/dist/modules/secrets-vault/secrets-vault.routes.d.ts +3 -0
- package/dist/modules/secrets-vault/secrets-vault.routes.d.ts.map +1 -1
- package/dist/modules/secrets-vault/secrets-vault.routes.js +4 -6
- package/dist/modules/secrets-vault/secrets-vault.routes.js.map +1 -1
- package/dist/modules/settings/deployment-settings.service.d.ts +22 -10
- package/dist/modules/settings/deployment-settings.service.d.ts.map +1 -1
- package/dist/modules/settings/deployment-settings.service.js +52 -28
- package/dist/modules/settings/deployment-settings.service.js.map +1 -1
- package/dist/modules/settings/setup.routes.d.ts +9 -2
- package/dist/modules/settings/setup.routes.d.ts.map +1 -1
- package/dist/modules/settings/setup.routes.js +20 -14
- package/dist/modules/settings/setup.routes.js.map +1 -1
- package/dist/modules/skills/allowed-tools-check.d.ts +4 -3
- package/dist/modules/skills/allowed-tools-check.d.ts.map +1 -1
- package/dist/modules/skills/allowed-tools-check.js +8 -8
- package/dist/modules/skills/allowed-tools-check.js.map +1 -1
- package/dist/modules/skills/pending-skills.service.d.ts +3 -1
- package/dist/modules/skills/pending-skills.service.d.ts.map +1 -1
- package/dist/modules/skills/pending-skills.service.js +9 -6
- package/dist/modules/skills/pending-skills.service.js.map +1 -1
- package/dist/modules/skills/skill-access-requests.routes.d.ts +2 -1
- package/dist/modules/skills/skill-access-requests.routes.d.ts.map +1 -1
- package/dist/modules/skills/skill-access-requests.routes.js +6 -6
- package/dist/modules/skills/skill-access-requests.routes.js.map +1 -1
- package/dist/modules/skills/skills.routes.d.ts +4 -1
- package/dist/modules/skills/skills.routes.d.ts.map +1 -1
- package/dist/modules/skills/skills.routes.js +4 -4
- package/dist/modules/skills/skills.routes.js.map +1 -1
- package/dist/modules/skills/skills.service.d.ts +4 -2
- package/dist/modules/skills/skills.service.d.ts.map +1 -1
- package/dist/modules/skills/skills.service.js +13 -11
- package/dist/modules/skills/skills.service.js.map +1 -1
- package/dist/modules/tool-auth/external-api-key.interface.d.ts +21 -5
- package/dist/modules/tool-auth/external-api-key.interface.d.ts.map +1 -1
- package/dist/modules/tool-auth/external-api-key.interface.js.map +1 -1
- package/dist/modules/tool-auth/external-api-key.service.d.ts +1 -0
- package/dist/modules/tool-auth/external-api-key.service.d.ts.map +1 -1
- package/dist/modules/tool-auth/external-api-key.service.js +22 -9
- package/dist/modules/tool-auth/external-api-key.service.js.map +1 -1
- package/dist/modules/tool-auth/internal-token.service.d.ts +10 -0
- package/dist/modules/tool-auth/internal-token.service.d.ts.map +1 -1
- package/dist/modules/tool-auth/internal-token.service.js +1 -0
- package/dist/modules/tool-auth/internal-token.service.js.map +1 -1
- package/dist/modules/tool-auth/tool-auth.middleware.d.ts +8 -0
- package/dist/modules/tool-auth/tool-auth.middleware.d.ts.map +1 -1
- package/dist/modules/tool-auth/tool-auth.middleware.js +9 -1
- package/dist/modules/tool-auth/tool-auth.middleware.js.map +1 -1
- package/dist/modules/tool-manuals/mcp-json-discovery.d.ts +2 -1
- package/dist/modules/tool-manuals/mcp-json-discovery.d.ts.map +1 -1
- package/dist/modules/tool-manuals/mcp-json-discovery.js +6 -5
- package/dist/modules/tool-manuals/mcp-json-discovery.js.map +1 -1
- package/dist/modules/tool-manuals/mcp-server-edit.service.d.ts +4 -2
- package/dist/modules/tool-manuals/mcp-server-edit.service.d.ts.map +1 -1
- package/dist/modules/tool-manuals/mcp-server-edit.service.js +12 -10
- package/dist/modules/tool-manuals/mcp-server-edit.service.js.map +1 -1
- package/dist/modules/tool-manuals/pending-tools.service.d.ts +3 -1
- package/dist/modules/tool-manuals/pending-tools.service.d.ts.map +1 -1
- package/dist/modules/tool-manuals/pending-tools.service.js +19 -16
- package/dist/modules/tool-manuals/pending-tools.service.js.map +1 -1
- package/dist/modules/tool-manuals/tool-delete.service.d.ts +4 -2
- package/dist/modules/tool-manuals/tool-delete.service.d.ts.map +1 -1
- package/dist/modules/tool-manuals/tool-delete.service.js +14 -12
- package/dist/modules/tool-manuals/tool-delete.service.js.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.routes.d.ts +3 -1
- package/dist/modules/tool-manuals/tool-manuals.routes.d.ts.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.routes.js +7 -7
- package/dist/modules/tool-manuals/tool-manuals.routes.js.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.service.d.ts +4 -2
- package/dist/modules/tool-manuals/tool-manuals.service.d.ts.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.service.js +15 -12
- package/dist/modules/tool-manuals/tool-manuals.service.js.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.tools.d.ts +3 -0
- package/dist/modules/tool-manuals/tool-manuals.tools.d.ts.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.tools.js +4 -6
- package/dist/modules/tool-manuals/tool-manuals.tools.js.map +1 -1
- package/dist/modules/workflow/agent-tools/workflow.tools.d.ts +3 -2
- package/dist/modules/workflow/agent-tools/workflow.tools.d.ts.map +1 -1
- package/dist/modules/workflow/agent-tools/workflow.tools.js +9 -9
- package/dist/modules/workflow/agent-tools/workflow.tools.js.map +1 -1
- package/dist/modules/workflow/git/git.service.d.ts +11 -5
- package/dist/modules/workflow/git/git.service.d.ts.map +1 -1
- package/dist/modules/workflow/git/git.service.js +23 -14
- package/dist/modules/workflow/git/git.service.js.map +1 -1
- package/dist/modules/workflow/git/node-git-runner.d.ts +26 -2
- package/dist/modules/workflow/git/node-git-runner.d.ts.map +1 -1
- package/dist/modules/workflow/git/node-git-runner.js +35 -5
- package/dist/modules/workflow/git/node-git-runner.js.map +1 -1
- package/dist/modules/workflow/review-workflow/review-workflow.service.d.ts.map +1 -1
- package/dist/modules/workflow/review-workflow/review-workflow.service.js +9 -4
- package/dist/modules/workflow/review-workflow/review-workflow.service.js.map +1 -1
- package/dist/modules/workflow/session-ontology.service.d.ts +6 -1
- package/dist/modules/workflow/session-ontology.service.d.ts.map +1 -1
- package/dist/modules/workflow/session-ontology.service.js +6 -2
- package/dist/modules/workflow/session-ontology.service.js.map +1 -1
- package/dist/modules/workflow/workflow.service.d.ts +8 -3
- package/dist/modules/workflow/workflow.service.d.ts.map +1 -1
- package/dist/modules/workflow/workflow.service.js +33 -23
- package/dist/modules/workflow/workflow.service.js.map +1 -1
- package/dist/modules/workspace/session-ontology.gate.d.ts +3 -1
- package/dist/modules/workspace/session-ontology.gate.d.ts.map +1 -1
- package/dist/modules/workspace/session-ontology.gate.js +3 -3
- package/dist/modules/workspace/session-ontology.gate.js.map +1 -1
- package/dist/modules/workspace/startup/kb-git.d.ts +4 -3
- package/dist/modules/workspace/startup/kb-git.d.ts.map +1 -1
- package/dist/modules/workspace/startup/kb-git.js +15 -13
- package/dist/modules/workspace/startup/kb-git.js.map +1 -1
- package/dist/modules/workspace/startup/kb-startup-runner.d.ts +5 -8
- package/dist/modules/workspace/startup/kb-startup-runner.d.ts.map +1 -1
- package/dist/modules/workspace/startup/kb-startup-runner.js +35 -38
- package/dist/modules/workspace/startup/kb-startup-runner.js.map +1 -1
- package/dist/modules/workspace/startup/steps/groups-to-plugins.step.d.ts +7 -1
- package/dist/modules/workspace/startup/steps/groups-to-plugins.step.d.ts.map +1 -1
- package/dist/modules/workspace/startup/steps/groups-to-plugins.step.js +23 -16
- package/dist/modules/workspace/startup/steps/groups-to-plugins.step.js.map +1 -1
- package/dist/modules/workspace/startup/steps/personal-spaces.step.d.ts +7 -1
- package/dist/modules/workspace/startup/steps/personal-spaces.step.d.ts.map +1 -1
- package/dist/modules/workspace/startup/steps/personal-spaces.step.js +12 -5
- package/dist/modules/workspace/startup/steps/personal-spaces.step.js.map +1 -1
- package/dist/modules/workspace/startup/steps/plugin-display-names.step.d.ts +7 -1
- package/dist/modules/workspace/startup/steps/plugin-display-names.step.d.ts.map +1 -1
- package/dist/modules/workspace/startup/steps/plugin-display-names.step.js +12 -5
- package/dist/modules/workspace/startup/steps/plugin-display-names.step.js.map +1 -1
- package/dist/modules/workspace/startup/steps/plugin-manifests.step.d.ts +7 -1
- package/dist/modules/workspace/startup/steps/plugin-manifests.step.d.ts.map +1 -1
- package/dist/modules/workspace/startup/steps/plugin-manifests.step.js +12 -5
- package/dist/modules/workspace/startup/steps/plugin-manifests.step.js.map +1 -1
- package/dist/modules/workspace/startup/steps/seed-tree.d.ts +4 -1
- package/dist/modules/workspace/startup/steps/seed-tree.d.ts.map +1 -1
- package/dist/modules/workspace/startup/steps/seed-tree.js +14 -11
- package/dist/modules/workspace/startup/steps/seed-tree.js.map +1 -1
- package/dist/modules/workspace/startup/steps/template-files.step.d.ts +17 -3
- package/dist/modules/workspace/startup/steps/template-files.step.d.ts.map +1 -1
- package/dist/modules/workspace/startup/steps/template-files.step.js +36 -30
- package/dist/modules/workspace/startup/steps/template-files.step.js.map +1 -1
- package/dist/modules/workspace/startup/steps/template-source.d.ts +6 -1
- package/dist/modules/workspace/startup/steps/template-source.d.ts.map +1 -1
- package/dist/modules/workspace/startup/steps/template-source.js +10 -6
- package/dist/modules/workspace/startup/steps/template-source.js.map +1 -1
- package/dist/modules/workspace/workspace.routes.d.ts +2 -1
- package/dist/modules/workspace/workspace.routes.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.routes.js +8 -7
- package/dist/modules/workspace/workspace.routes.js.map +1 -1
- package/dist/modules/workspace/workspace.service.d.ts +26 -12
- package/dist/modules/workspace/workspace.service.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.service.js +41 -28
- package/dist/modules/workspace/workspace.service.js.map +1 -1
- package/dist/modules/workspace/workspace.tools.d.ts +2 -1
- package/dist/modules/workspace/workspace.tools.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.tools.js +69 -31
- package/dist/modules/workspace/workspace.tools.js.map +1 -1
- package/dist/modules/workspace/write-denial.d.ts +3 -2
- package/dist/modules/workspace/write-denial.d.ts.map +1 -1
- package/dist/modules/workspace/write-denial.js +6 -5
- package/dist/modules/workspace/write-denial.js.map +1 -1
- package/dist/shared/git-internals.d.ts +7 -1
- package/dist/shared/git-internals.d.ts.map +1 -1
- package/dist/shared/git-internals.js +67 -9
- package/dist/shared/git-internals.js.map +1 -1
- package/dist/shared/git.contract.d.ts +52 -7
- package/dist/shared/git.contract.d.ts.map +1 -1
- package/dist/shared/git.contract.js +30 -8
- package/dist/shared/git.contract.js.map +1 -1
- package/dist/shared/kb-context.d.ts +76 -0
- package/dist/shared/kb-context.d.ts.map +1 -0
- package/dist/shared/kb-context.js +108 -0
- package/dist/shared/kb-context.js.map +1 -0
- package/dist/shared/kb-layout.d.ts +3 -2
- package/dist/shared/kb-layout.d.ts.map +1 -1
- package/dist/shared/kb-layout.js +4 -3
- package/dist/shared/kb-layout.js.map +1 -1
- package/dist/shared/kb-layout.test.js +35 -27
- package/dist/shared/kb-layout.test.js.map +1 -1
- package/dist/shared/pending-proposals.d.ts +4 -1
- package/dist/shared/pending-proposals.d.ts.map +1 -1
- package/dist/shared/pending-proposals.js +3 -4
- package/dist/shared/pending-proposals.js.map +1 -1
- package/dist/shared/redact-secret.d.ts +5 -5
- package/dist/shared/redact-secret.js +5 -5
- package/dist/tenancy/index.d.ts +13 -0
- package/dist/tenancy/index.d.ts.map +1 -0
- package/dist/tenancy/index.js +13 -0
- package/dist/tenancy/index.js.map +1 -0
- package/dist/tenancy/static-tenant-source.d.ts +98 -0
- package/dist/tenancy/static-tenant-source.d.ts.map +1 -0
- package/dist/tenancy/static-tenant-source.js +220 -0
- package/dist/tenancy/static-tenant-source.js.map +1 -0
- package/dist/tenancy/tenant-host.d.ts +80 -0
- package/dist/tenancy/tenant-host.d.ts.map +1 -0
- package/dist/tenancy/tenant-host.js +217 -0
- package/dist/tenancy/tenant-host.js.map +1 -0
- package/dist/tenancy/tenant-runtime.d.ts +91 -0
- package/dist/tenancy/tenant-runtime.d.ts.map +1 -0
- package/dist/tenancy/tenant-runtime.js +174 -0
- package/dist/tenancy/tenant-runtime.js.map +1 -0
- package/dist/tenancy/tenant-secrets.d.ts +24 -0
- package/dist/tenancy/tenant-secrets.d.ts.map +1 -0
- package/dist/tenancy/tenant-secrets.js +30 -0
- package/dist/tenancy/tenant-secrets.js.map +1 -0
- package/dist/tenancy/tenant-source.contract.d.ts +45 -0
- package/dist/tenancy/tenant-source.contract.d.ts.map +1 -0
- package/dist/tenancy/tenant-source.contract.js +21 -0
- package/dist/tenancy/tenant-source.contract.js.map +1 -0
- package/migrations/0000_core_init.sql +14 -14
- package/migrations/0003_deployment_settings.sql +1 -1
- package/migrations/0005_github_facade.sql +1 -1
- package/migrations/0012_agent_audit.sql +41 -0
- package/migrations/0013_agent_identity_and_key_soft_delete.sql +29 -0
- package/migrations/meta/0012_snapshot.json +2247 -0
- package/migrations/meta/0013_snapshot.json +2259 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +4 -4
- package/src/__tests__/branch-model.test.ts +7 -6
- package/src/__tests__/kb-context.ts +30 -0
- package/src/__tests__/kb-layout-config.test.ts +35 -30
- package/src/core/__tests__/catalog-cache-invalidation.test.ts +2 -1
- package/src/core/__tests__/lifecycle.test.ts +78 -1
- package/src/core/__tests__/public-config.test.ts +5 -1
- package/src/core/catalog-cache-invalidation.ts +16 -11
- package/src/core/core-ports.ts +19 -0
- package/src/core/create-core-server.ts +55 -106
- package/src/core/create-core-services.ts +193 -95
- package/src/core/lifecycle.ts +214 -29
- package/src/core/public-config.ts +8 -5
- package/src/core-config.ts +107 -8
- package/src/index.ts +25 -2
- package/src/modules/access/__tests__/access-control.admin-root-floor.test.ts +2 -1
- package/src/modules/access/__tests__/access.routes.batch.test.ts +2 -1
- package/src/modules/access/__tests__/access.routes.folder-governs.test.ts +2 -1
- package/src/modules/access/__tests__/access.routes.group-grant.test.ts +2 -1
- package/src/modules/access/__tests__/access.routes.overrides.test.ts +2 -1
- package/src/modules/access/__tests__/access.routes.proposal-branch.test.ts +2 -1
- package/src/modules/access/__tests__/access.routes.prospective.test.ts +2 -1
- package/src/modules/access/__tests__/access.routes.revoke.test.ts +2 -1
- package/src/modules/access/__tests__/access.routes.unknown-email.test.ts +2 -1
- package/src/modules/access/__tests__/change-read-gate.test.ts +13 -11
- package/src/modules/access/__tests__/creator-access.test.ts +3 -2
- package/src/modules/access/__tests__/roles.routes.test.ts +2 -1
- package/src/modules/access/access-control.service.ts +20 -6
- package/src/modules/access/access.routes.ts +10 -13
- package/src/modules/access/change-read-gate.ts +10 -4
- package/src/modules/access/creator-access.ts +7 -2
- package/src/modules/agent-instructions/__tests__/read-preamble.test.ts +13 -12
- package/src/modules/agent-instructions/read-preamble.ts +10 -12
- package/src/modules/audit/__tests__/agent-audit.service.test.ts +370 -0
- package/src/modules/audit/__tests__/agent-rest-audit.middleware.test.ts +113 -0
- package/src/modules/audit/__tests__/audit.routes.test.ts +201 -0
- package/src/modules/audit/__tests__/event-classifier.test.ts +121 -0
- package/src/modules/audit/agent-audit.service.ts +316 -0
- package/src/modules/audit/agent-rest-audit.middleware.ts +83 -0
- package/src/modules/audit/audit.contract.ts +164 -0
- package/src/modules/audit/audit.routes.ts +168 -0
- package/src/modules/audit/event-classifier.ts +155 -0
- package/src/modules/audit/index.ts +14 -0
- package/src/modules/audit/request-audit.ts +141 -0
- package/src/modules/auth/__tests__/account.routes.test.ts +15 -0
- package/src/modules/auth/__tests__/auth.service.test.ts +60 -0
- package/src/modules/auth/account-admission.ts +44 -0
- package/src/modules/auth/account.routes.ts +4 -1
- package/src/modules/auth/auth.service.ts +33 -1
- package/src/modules/auth/oidc-auth-provider.ts +9 -0
- package/src/modules/connection-probe/connection-probe.service.ts +7 -1
- package/src/modules/database/__tests__/advisory-lock.test.ts +23 -1
- package/src/modules/database/__tests__/connection.test.ts +98 -0
- package/src/modules/database/__tests__/migrations-unqualified.test.ts +32 -0
- package/src/modules/database/advisory-lock.ts +28 -4
- package/src/modules/database/connection.ts +143 -13
- package/src/modules/database/core-schema.ts +104 -0
- package/src/modules/database/migrate.ts +48 -14
- package/src/modules/diff/__tests__/diff.service.seed-atomicity.test.ts +2 -1
- package/src/modules/diff/__tests__/diff.service.test.ts +2 -1
- package/src/modules/diff/diff.service.ts +6 -1
- package/src/modules/kb-fs/__tests__/branch-name.test.ts +6 -6
- package/src/modules/kb-fs/__tests__/clone-config.test.ts +24 -20
- package/src/modules/kb-fs/branch-name.ts +3 -3
- package/src/modules/kb-fs/clone-config.ts +15 -12
- package/src/modules/kb-fs/git-guarded-filesystem.ts +16 -3
- package/src/modules/marketplace/__tests__/marketplace-repo.head.test.ts +2 -1
- package/src/modules/mcp/__tests__/bevel-oauth-provider.test.ts +183 -13
- package/src/modules/mcp/__tests__/mcp-auth.middleware.test.ts +60 -2
- package/src/modules/mcp/__tests__/mcp.routes.local-token.test.ts +24 -4
- package/src/modules/mcp/__tests__/mcp.routes.stateless.test.ts +1 -1
- package/src/modules/mcp/__tests__/mcp.service.test.ts +120 -3
- package/src/modules/mcp/mcp-auth.middleware.ts +31 -0
- package/src/modules/mcp/mcp.routes.ts +11 -1
- package/src/modules/mcp/mcp.service.ts +73 -8
- package/src/modules/mcp/oauth/bevel-oauth-provider.ts +184 -6
- package/src/modules/plugins/__tests__/bundle-dialect.e2e.test.ts +12 -11
- package/src/modules/plugins/__tests__/bundle-dialect.test.ts +2 -1
- package/src/modules/plugins/__tests__/compile-marketplace.test.ts +6 -4
- package/src/modules/plugins/__tests__/join-request-jobs.service.test.ts +2 -1
- package/src/modules/plugins/__tests__/join-requests.service.test.ts +2 -1
- package/src/modules/plugins/__tests__/plugin-creation-display-name.test.ts +4 -3
- package/src/modules/plugins/__tests__/plugin-index.service.test.ts +6 -4
- package/src/modules/plugins/__tests__/plugin-links.service.test.ts +220 -5
- package/src/modules/plugins/__tests__/plugin-provision.service.test.ts +3 -1
- package/src/modules/plugins/__tests__/plugin-rename.service.test.ts +7 -6
- package/src/modules/plugins/__tests__/plugins.routes.test.ts +11 -2
- package/src/modules/plugins/__tests__/teams.routes.test.ts +2 -1
- package/src/modules/plugins/compile/marketplace-compiler.service.ts +7 -9
- package/src/modules/plugins/discovery/__tests__/kb-plugin-source.test.ts +20 -16
- package/src/modules/plugins/discovery/bundle-dialect/bundle.source.ts +9 -2
- package/src/modules/plugins/discovery/kb-plugin-source.ts +15 -8
- package/src/modules/plugins/discovery/native.source.ts +4 -1
- package/src/modules/plugins/index.ts +1 -1
- package/src/modules/plugins/join-request-jobs.service.ts +8 -7
- package/src/modules/plugins/join-requests.service.ts +7 -7
- package/src/modules/plugins/plugin-links.service.ts +192 -19
- package/src/modules/plugins/plugin-links.ts +147 -27
- package/src/modules/plugins/plugin-provision.service.ts +54 -27
- package/src/modules/plugins/plugin-rename.service.ts +10 -10
- package/src/modules/plugins/plugins.routes.ts +45 -15
- package/src/modules/plugins/plugins.service.ts +7 -11
- package/src/modules/plugins/teams.routes.ts +16 -8
- package/src/modules/secrets-vault/__tests__/connect-pending.route.test.ts +7 -0
- package/src/modules/secrets-vault/__tests__/secrets-variable-loader.test.ts +40 -0
- package/src/modules/secrets-vault/__tests__/tool-owner-gate.route.test.ts +2 -0
- package/src/modules/secrets-vault/index.ts +2 -0
- package/src/modules/secrets-vault/secrets-variable-loader.ts +51 -21
- package/src/modules/secrets-vault/secrets-vault.routes.ts +7 -6
- package/src/modules/settings/__tests__/deployment-settings.service.test.ts +59 -11
- package/src/modules/settings/__tests__/git-root-folders.test.ts +2 -1
- package/src/modules/settings/__tests__/setup.routes.boot-failure.test.ts +2 -1
- package/src/modules/settings/__tests__/setup.routes.layout-phase.test.ts +7 -4
- package/src/modules/settings/__tests__/setup.routes.oidc.test.ts +2 -0
- package/src/modules/settings/__tests__/setup.routes.sync-status.test.ts +2 -0
- package/src/modules/settings/__tests__/setup.routes.test.ts +33 -52
- package/src/modules/settings/deployment-settings.service.ts +68 -28
- package/src/modules/settings/setup.routes.ts +26 -16
- package/src/modules/skills/__tests__/allowed-tools-check.test.ts +11 -10
- package/src/modules/skills/__tests__/allowed-tools-warn.tools.test.ts +4 -3
- package/src/modules/skills/__tests__/pending-skills.service.test.ts +3 -1
- package/src/modules/skills/__tests__/skill-access-requests.routes.test.ts +2 -1
- package/src/modules/skills/__tests__/skills.routes.warnings.test.ts +2 -1
- package/src/modules/skills/__tests__/skills.service.test.ts +3 -2
- package/src/modules/skills/allowed-tools-check.ts +7 -6
- package/src/modules/skills/pending-skills.service.ts +9 -8
- package/src/modules/skills/skill-access-requests.routes.ts +7 -7
- package/src/modules/skills/skills.routes.ts +4 -3
- package/src/modules/skills/skills.service.ts +13 -9
- package/src/modules/tool-auth/__tests__/external-api-key.service.test.ts +29 -8
- package/src/modules/tool-auth/__tests__/internal-token.service.test.ts +6 -0
- package/src/modules/tool-auth/external-api-key.interface.ts +22 -5
- package/src/modules/tool-auth/external-api-key.service.ts +25 -8
- package/src/modules/tool-auth/internal-token.service.ts +11 -0
- package/src/modules/tool-auth/tool-auth.middleware.ts +17 -1
- package/src/modules/tool-helpers/__tests__/agent-roles-write.test.ts +3 -2
- package/src/modules/tool-helpers/__tests__/phase4-tools.test.ts +3 -2
- package/src/modules/tool-manuals/__tests__/mcp-json-discovery.test.ts +17 -12
- package/src/modules/tool-manuals/__tests__/mcp-server-edit.service.test.ts +2 -1
- package/src/modules/tool-manuals/__tests__/pending-tools.service.test.ts +4 -1
- package/src/modules/tool-manuals/__tests__/tool-delete.service.test.ts +2 -1
- package/src/modules/tool-manuals/__tests__/tool-manuals.archive.route.test.ts +2 -1
- package/src/modules/tool-manuals/__tests__/tool-manuals.cli.test.ts +5 -4
- package/src/modules/tool-manuals/__tests__/tool-manuals.detail.route.test.ts +2 -1
- package/src/modules/tool-manuals/__tests__/tool-manuals.invalid.routes.test.ts +4 -2
- package/src/modules/tool-manuals/__tests__/tool-manuals.invalid.test.ts +13 -5
- package/src/modules/tool-manuals/__tests__/tool-manuals.mcp-oauth.test.ts +2 -1
- package/src/modules/tool-manuals/__tests__/tool-manuals.restart.test.ts +9 -1
- package/src/modules/tool-manuals/__tests__/tool-manuals.service.test.ts +3 -2
- package/src/modules/tool-manuals/__tests__/tool-manuals.tools.test.ts +2 -0
- package/src/modules/tool-manuals/mcp-json-discovery.ts +6 -4
- package/src/modules/tool-manuals/mcp-server-edit.service.ts +13 -11
- package/src/modules/tool-manuals/pending-tools.service.ts +19 -16
- package/src/modules/tool-manuals/tool-delete.service.ts +13 -10
- package/src/modules/tool-manuals/tool-manuals.routes.ts +10 -8
- package/src/modules/tool-manuals/tool-manuals.service.ts +15 -13
- package/src/modules/tool-manuals/tool-manuals.tools.ts +7 -6
- package/src/modules/workflow/__tests__/apply-failure.test.ts +2 -1
- package/src/modules/workflow/__tests__/merge-announces-tree.test.ts +14 -26
- package/src/modules/workflow/__tests__/preserve-roles-yaml.test.ts +2 -1
- package/src/modules/workflow/__tests__/session-ontology.service.test.ts +3 -2
- package/src/modules/workflow/__tests__/workflow.routes.lock-path.test.ts +2 -1
- package/src/modules/workflow/__tests__/workflow.service.branch-in-use.test.ts +3 -10
- package/src/modules/workflow/__tests__/workflow.service.commitFileWhileLocked.test.ts +2 -1
- package/src/modules/workflow/__tests__/workflow.service.deleted-branch-sweep.test.ts +3 -10
- package/src/modules/workflow/__tests__/workflow.service.facade.test.ts +28 -27
- package/src/modules/workflow/__tests__/workflow.service.folder-proposals.test.ts +2 -1
- package/src/modules/workflow/__tests__/workflow.service.platform-restore.test.ts +2 -1
- package/src/modules/workflow/__tests__/workflow.service.read-gate.test.ts +3 -2
- package/src/modules/workflow/__tests__/workflow.service.releaseLock.test.ts +2 -1
- package/src/modules/workflow/__tests__/workflow.service.sync.test.ts +5 -4
- package/src/modules/workflow/__tests__/workflow.service.update-from-target.test.ts +2 -1
- package/src/modules/workflow/agent-tools/__tests__/workflow.tools.test.ts +2 -1
- package/src/modules/workflow/agent-tools/workflow.tools.ts +11 -9
- package/src/modules/workflow/git/__tests__/git.service.accessGating.test.ts +5 -4
- package/src/modules/workflow/git/__tests__/git.service.changedFilesForPr.test.ts +12 -11
- package/src/modules/workflow/git/__tests__/git.service.commitChanges.test.ts +9 -8
- package/src/modules/workflow/git/__tests__/git.service.commitFile.strayPath.test.ts +8 -7
- package/src/modules/workflow/git/__tests__/git.service.commitFile.test.ts +6 -5
- package/src/modules/workflow/git/__tests__/git.service.createBranch.test.ts +3 -2
- package/src/modules/workflow/git/__tests__/git.service.deleteBranch.test.ts +3 -2
- package/src/modules/workflow/git/__tests__/git.service.diffFileAtCommit.test.ts +7 -6
- package/src/modules/workflow/git/__tests__/git.service.diffFileBetweenBranches.test.ts +16 -15
- package/src/modules/workflow/git/__tests__/git.service.fileContentsAtCommit.test.ts +3 -2
- package/src/modules/workflow/git/__tests__/git.service.forkPoint.test.ts +2 -1
- package/src/modules/workflow/git/__tests__/git.service.history-guards.test.ts +2 -1
- package/src/modules/workflow/git/__tests__/git.service.list-branches.test.ts +10 -9
- package/src/modules/workflow/git/__tests__/git.service.listTrackedFiles.test.ts +2 -1
- package/src/modules/workflow/git/__tests__/git.service.logForFile.test.ts +6 -5
- package/src/modules/workflow/git/__tests__/git.service.mergeChangeRequest.test.ts +9 -8
- package/src/modules/workflow/git/__tests__/git.service.pendingChanges.test.ts +2 -1
- package/src/modules/workflow/git/__tests__/git.service.postMergePull.test.ts +4 -3
- package/src/modules/workflow/git/__tests__/git.service.pull.test.ts +9 -8
- package/src/modules/workflow/git/__tests__/git.service.readFileAtRef.test.ts +2 -1
- package/src/modules/workflow/git/__tests__/git.service.revertPathsAndPush.test.ts +2 -1
- package/src/modules/workflow/git/__tests__/git.service.status.test.ts +4 -3
- package/src/modules/workflow/git/__tests__/git.service.syncFromRemote.test.ts +8 -7
- package/src/modules/workflow/git/__tests__/node-git-runner.test.ts +41 -3
- package/src/modules/workflow/git/git.service.ts +24 -13
- package/src/modules/workflow/git/node-git-runner.ts +37 -4
- package/src/modules/workflow/review-workflow/review-workflow.service.ts +9 -6
- package/src/modules/workflow/session-ontology.service.ts +7 -2
- package/src/modules/workflow/workflow.service.ts +31 -24
- package/src/modules/workspace/__tests__/file-stat-access.test.ts +3 -2
- package/src/modules/workspace/__tests__/git-internals.security.test.ts +144 -52
- package/src/modules/workspace/__tests__/session-ontology.gate.test.ts +4 -2
- package/src/modules/workspace/__tests__/workspace-paths-inside-the-repo.test.ts +3 -2
- package/src/modules/workspace/__tests__/workspace.routes.branch-errors.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.routes.create-grant.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.routes.delete.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.routes.download-implies-read.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.routes.download.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.routes.file-writes.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.routes.folders.test.ts +5 -4
- package/src/modules/workspace/__tests__/workspace.routes.move-platform-files.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.routes.read-gate.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.service.ensure-remotes-fetched.test.ts +2 -2
- package/src/modules/workspace/__tests__/workspace.service.list-cloned.test.ts +6 -5
- package/src/modules/workspace/__tests__/workspace.service.move-never-overwrites.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.service.read-filter.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.service.test.ts +84 -50
- package/src/modules/workspace/__tests__/workspace.service.unknown-branch.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.tools.agents-file.test.ts +10 -7
- package/src/modules/workspace/__tests__/workspace.tools.branch-errors.test.ts +4 -3
- package/src/modules/workspace/__tests__/workspace.tools.test.ts +9 -8
- package/src/modules/workspace/__tests__/write-denial.test.ts +5 -4
- package/src/modules/workspace/session-ontology.gate.ts +6 -4
- package/src/modules/workspace/startup/__tests__/kb-startup-runner.degraded.test.ts +6 -2
- package/src/modules/workspace/startup/__tests__/kb-startup-runner.test.ts +29 -21
- package/src/modules/workspace/startup/kb-git.ts +15 -22
- package/src/modules/workspace/startup/kb-startup-runner.ts +40 -46
- package/src/modules/workspace/startup/steps/__tests__/steps.test.ts +104 -98
- package/src/modules/workspace/startup/steps/groups-to-plugins.step.ts +24 -16
- package/src/modules/workspace/startup/steps/personal-spaces.step.ts +14 -5
- package/src/modules/workspace/startup/steps/plugin-display-names.step.ts +13 -5
- package/src/modules/workspace/startup/steps/plugin-manifests.step.ts +14 -5
- package/src/modules/workspace/startup/steps/seed-tree.ts +11 -9
- package/src/modules/workspace/startup/steps/template-files.step.ts +43 -34
- package/src/modules/workspace/startup/steps/template-source.ts +8 -5
- package/src/modules/workspace/workspace.routes.ts +8 -7
- package/src/modules/workspace/workspace.service.ts +39 -27
- package/src/modules/workspace/workspace.tools.ts +68 -31
- package/src/modules/workspace/write-denial.ts +7 -5
- package/src/shared/__tests__/git-internals.test.ts +41 -0
- package/src/shared/__tests__/kb-layout.plugin.test.ts +19 -16
- package/src/shared/git-internals.ts +61 -6
- package/src/shared/git.contract.ts +70 -8
- package/src/shared/kb-context.ts +130 -0
- package/src/shared/kb-layout.test.ts +37 -27
- package/src/shared/kb-layout.ts +4 -3
- package/src/shared/pending-proposals.ts +7 -4
- package/src/shared/redact-secret.ts +5 -5
- package/src/tenancy/__tests__/static-tenant-source.test.ts +177 -0
- package/src/tenancy/__tests__/tenant-host.test.ts +372 -0
- package/src/tenancy/__tests__/tenant-runtime.test.ts +221 -0
- package/src/tenancy/__tests__/tenant-secrets.test.ts +35 -0
- package/src/tenancy/index.ts +35 -0
- package/src/tenancy/static-tenant-source.ts +296 -0
- package/src/tenancy/tenant-host.ts +261 -0
- package/src/tenancy/tenant-runtime.ts +208 -0
- package/src/tenancy/tenant-secrets.ts +41 -0
- package/src/tenancy/tenant-source.contract.ts +59 -0
- package/dist/modules/access/access-errors.d.ts +0 -34
- package/dist/modules/access/access-errors.d.ts.map +0 -1
- package/dist/modules/access/access-errors.js +0 -40
- package/dist/modules/access/access-errors.js.map +0 -1
- package/dist/modules/access/access-splice.d.ts +0 -140
- package/dist/modules/access/access-splice.d.ts.map +0 -1
- package/dist/modules/access/access-splice.js +0 -389
- package/dist/modules/access/access-splice.js.map +0 -1
- package/dist/modules/access/group-files.d.ts +0 -83
- package/dist/modules/access/group-files.d.ts.map +0 -1
- package/dist/modules/access/group-files.js +0 -167
- package/dist/modules/access/group-files.js.map +0 -1
- package/dist/modules/access/kb-read-filter.d.ts +0 -41
- package/dist/modules/access/kb-read-filter.d.ts.map +0 -1
- package/dist/modules/access/kb-read-filter.js +0 -60
- package/dist/modules/access/kb-read-filter.js.map +0 -1
- package/dist/modules/access/render-roles-yaml.d.ts +0 -22
- package/dist/modules/access/render-roles-yaml.d.ts.map +0 -1
- package/dist/modules/access/render-roles-yaml.js +0 -56
- package/dist/modules/access/render-roles-yaml.js.map +0 -1
- package/dist/modules/access/roles-yaml-guard.d.ts +0 -56
- package/dist/modules/access/roles-yaml-guard.d.ts.map +0 -1
- package/dist/modules/access/roles-yaml-guard.js +0 -79
- package/dist/modules/access/roles-yaml-guard.js.map +0 -1
- package/dist/modules/diff/diff-paths.d.ts +0 -2
- package/dist/modules/diff/diff-paths.d.ts.map +0 -1
- package/dist/modules/diff/diff-paths.js +0 -9
- package/dist/modules/diff/diff-paths.js.map +0 -1
- package/dist/modules/groups/group-provision.service.d.ts +0 -130
- package/dist/modules/groups/group-provision.service.d.ts.map +0 -1
- package/dist/modules/groups/group-provision.service.js +0 -288
- package/dist/modules/groups/group-provision.service.js.map +0 -1
- package/dist/modules/groups/groups.contract.d.ts +0 -106
- package/dist/modules/groups/groups.contract.d.ts.map +0 -1
- package/dist/modules/groups/groups.contract.js +0 -36
- package/dist/modules/groups/groups.contract.js.map +0 -1
- package/dist/modules/groups/groups.routes.d.ts +0 -42
- package/dist/modules/groups/groups.routes.d.ts.map +0 -1
- package/dist/modules/groups/groups.routes.js +0 -379
- package/dist/modules/groups/groups.routes.js.map +0 -1
- package/dist/modules/groups/groups.service.d.ts +0 -60
- package/dist/modules/groups/groups.service.d.ts.map +0 -1
- package/dist/modules/groups/groups.service.js +0 -172
- package/dist/modules/groups/groups.service.js.map +0 -1
- package/dist/modules/groups/index.d.ts +0 -7
- package/dist/modules/groups/index.d.ts.map +0 -1
- package/dist/modules/groups/index.js +0 -6
- package/dist/modules/groups/index.js.map +0 -1
- package/dist/modules/groups/join-proposals.d.ts +0 -53
- package/dist/modules/groups/join-proposals.d.ts.map +0 -1
- package/dist/modules/groups/join-proposals.js +0 -67
- package/dist/modules/groups/join-proposals.js.map +0 -1
- package/dist/modules/groups/join-requests.service.d.ts +0 -81
- package/dist/modules/groups/join-requests.service.d.ts.map +0 -1
- package/dist/modules/groups/join-requests.service.js +0 -135
- package/dist/modules/groups/join-requests.service.js.map +0 -1
- package/dist/modules/mcp/mcp-session-store.d.ts +0 -74
- package/dist/modules/mcp/mcp-session-store.d.ts.map +0 -1
- package/dist/modules/mcp/mcp-session-store.js +0 -131
- package/dist/modules/mcp/mcp-session-store.js.map +0 -1
- package/dist/modules/workflow/file-change-notifier.d.ts +0 -38
- package/dist/modules/workflow/file-change-notifier.d.ts.map +0 -1
- package/dist/modules/workflow/file-change-notifier.js +0 -22
- package/dist/modules/workflow/file-change-notifier.js.map +0 -1
- package/dist/modules/workflow/git/branch-name.d.ts +0 -10
- package/dist/modules/workflow/git/branch-name.d.ts.map +0 -1
- package/dist/modules/workflow/git/branch-name.js +0 -76
- package/dist/modules/workflow/git/branch-name.js.map +0 -1
- package/dist/modules/workflow/git/clone-config.d.ts +0 -61
- package/dist/modules/workflow/git/clone-config.d.ts.map +0 -1
- package/dist/modules/workflow/git/clone-config.js +0 -69
- package/dist/modules/workflow/git/clone-config.js.map +0 -1
- package/dist/modules/workflow/git/mutex.d.ts +0 -11
- package/dist/modules/workflow/git/mutex.d.ts.map +0 -1
- package/dist/modules/workflow/git/mutex.js +0 -23
- package/dist/modules/workflow/git/mutex.js.map +0 -1
- package/dist/modules/workflow/locking-filesystem.d.ts +0 -137
- package/dist/modules/workflow/locking-filesystem.d.ts.map +0 -1
- package/dist/modules/workflow/locking-filesystem.js +0 -553
- package/dist/modules/workflow/locking-filesystem.js.map +0 -1
- package/dist/modules/workflow/read-only-filesystem.d.ts +0 -24
- package/dist/modules/workflow/read-only-filesystem.d.ts.map +0 -1
- package/dist/modules/workflow/read-only-filesystem.js +0 -39
- package/dist/modules/workflow/read-only-filesystem.js.map +0 -1
- package/dist/modules/workflow/workflow.errors.d.ts +0 -197
- package/dist/modules/workflow/workflow.errors.d.ts.map +0 -1
- package/dist/modules/workflow/workflow.errors.js +0 -298
- package/dist/modules/workflow/workflow.errors.js.map +0 -1
- package/dist/modules/workspace/bevel-ignore.d.ts +0 -30
- package/dist/modules/workspace/bevel-ignore.d.ts.map +0 -1
- package/dist/modules/workspace/bevel-ignore.js +0 -61
- package/dist/modules/workspace/bevel-ignore.js.map +0 -1
- package/dist/modules/workspace/kb-seed.interface.d.ts +0 -36
- package/dist/modules/workspace/kb-seed.interface.d.ts.map +0 -1
- package/dist/modules/workspace/kb-seed.interface.js +0 -2
- package/dist/modules/workspace/kb-seed.interface.js.map +0 -1
- package/dist/modules/workspace/kb-seed.service.d.ts +0 -125
- package/dist/modules/workspace/kb-seed.service.d.ts.map +0 -1
- package/dist/modules/workspace/kb-seed.service.js +0 -535
- package/dist/modules/workspace/kb-seed.service.js.map +0 -1
- package/dist/modules/workspace/plugins-migration.d.ts +0 -50
- package/dist/modules/workspace/plugins-migration.d.ts.map +0 -1
- package/dist/modules/workspace/plugins-migration.js +0 -379
- package/dist/modules/workspace/plugins-migration.js.map +0 -1
- package/dist/shared/fs-errors.d.ts +0 -8
- package/dist/shared/fs-errors.d.ts.map +0 -1
- package/dist/shared/fs-errors.js +0 -11
- package/dist/shared/fs-errors.js.map +0 -1
- package/dist/shared/fs-walk.d.ts +0 -23
- package/dist/shared/fs-walk.d.ts.map +0 -1
- package/dist/shared/fs-walk.js +0 -42
- package/dist/shared/fs-walk.js.map +0 -1
- package/dist/shared/hash-email.d.ts +0 -11
- package/dist/shared/hash-email.d.ts.map +0 -1
- package/dist/shared/hash-email.js +0 -14
- package/dist/shared/hash-email.js.map +0 -1
- package/dist/shared/kb-walk.d.ts +0 -52
- package/dist/shared/kb-walk.d.ts.map +0 -1
- package/dist/shared/kb-walk.js +0 -76
- package/dist/shared/kb-walk.js.map +0 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isIP } from 'node:net';
|
|
4
|
+
import { GIT_SHA } from '../version.js';
|
|
5
|
+
import { logger } from '../shared/logging.js';
|
|
6
|
+
import { TenantRuntime } from './tenant-runtime.js';
|
|
7
|
+
import { TENANT_SLUG_PATTERN, normalizeHost } from './tenant-source.contract.js';
|
|
8
|
+
const log = logger('tenancy');
|
|
9
|
+
/**
|
|
10
|
+
* The path prefix under which a process reaches ONE of its own tenants over
|
|
11
|
+
* loopback: `http://127.0.0.1:<port>/_tenant/<slug>/api/...`. The MCP proxy
|
|
12
|
+
* and the UTCP manuals it seeds dial the tenant's own REST surface this way,
|
|
13
|
+
* because a loopback request carries no tenant host name and a header cannot
|
|
14
|
+
* ride a UTCP call (the proxy is a passthrough; it reshapes nothing).
|
|
15
|
+
*
|
|
16
|
+
* The host honours the prefix only for a request that came from this
|
|
17
|
+
* machine AND was forwarded by nobody: the socket peer is loopback and there
|
|
18
|
+
* is no `X-Forwarded-For`. A reverse proxy on the same host (nginx, a
|
|
19
|
+
* Coolify proxy) delivers every public request from a loopback socket, and
|
|
20
|
+
* every such proxy adds that header; the process's own dial never does.
|
|
21
|
+
* What the prefix could grant anyone who got past this is only what the
|
|
22
|
+
* tenant's host name grants already — sessions, keys and tokens are per
|
|
23
|
+
* tenant — but the addressing rule is stated so it can be relied on.
|
|
24
|
+
*/
|
|
25
|
+
export const LOOPBACK_TENANT_PREFIX = '/_tenant';
|
|
26
|
+
/** The base URL a tenant's graph dials itself at — see {@link LOOPBACK_TENANT_PREFIX}. */
|
|
27
|
+
export function loopbackTenantBaseUrl(port, slug) {
|
|
28
|
+
return `http://127.0.0.1:${port}${LOOPBACK_TENANT_PREFIX}/${slug}`;
|
|
29
|
+
}
|
|
30
|
+
/** Whether `address` is this machine talking to itself. */
|
|
31
|
+
export function isLoopbackAddress(address) {
|
|
32
|
+
if (!address)
|
|
33
|
+
return false;
|
|
34
|
+
const bare = address.startsWith('::ffff:') ? address.slice('::ffff:'.length) : address;
|
|
35
|
+
if (bare === '::1')
|
|
36
|
+
return true;
|
|
37
|
+
return isIP(bare) === 4 && bare.startsWith('127.');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Which tenant a request is for. The loopback prefix wins, but only from a
|
|
41
|
+
* loopback peer that no proxy forwarded (no `X-Forwarded-For`); everything
|
|
42
|
+
* else is decided by the host name (the `X-Forwarded-Host` a trusted proxy
|
|
43
|
+
* set, else `Host`), lowercase and without its port.
|
|
44
|
+
*/
|
|
45
|
+
export function selectTenant(req) {
|
|
46
|
+
const forwarded = Array.isArray(req.forwardedFor) ? req.forwardedFor.length > 0 : Boolean(req.forwardedFor);
|
|
47
|
+
if (isLoopbackAddress(req.peer) && !forwarded && req.url.startsWith(`${LOOPBACK_TENANT_PREFIX}/`)) {
|
|
48
|
+
const afterPrefix = req.url.slice(LOOPBACK_TENANT_PREFIX.length + 1);
|
|
49
|
+
const end = afterPrefix.search(/[/?#]/);
|
|
50
|
+
const slug = end === -1 ? afterPrefix : afterPrefix.slice(0, end);
|
|
51
|
+
if (TENANT_SLUG_PATTERN.test(slug)) {
|
|
52
|
+
const rest = end === -1 ? '/' : afterPrefix.slice(end).replace(/^(?=[?#])/, '/');
|
|
53
|
+
return { kind: 'slug', slug, rest };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { kind: 'host', host: normalizeHost(req.hostname || '') };
|
|
57
|
+
}
|
|
58
|
+
const DEFAULT_ACTIVATION_WAIT_MS = 60_000;
|
|
59
|
+
const DEFAULT_IDLE_MINUTES = 30;
|
|
60
|
+
const DEFAULT_SWEEP_INTERVAL_MS = 60_000;
|
|
61
|
+
/** `promise`, or `null` once `ms` have passed. */
|
|
62
|
+
function within(promise, ms) {
|
|
63
|
+
let timer;
|
|
64
|
+
const late = new Promise((resolve) => {
|
|
65
|
+
timer = setTimeout(() => resolve(null), ms);
|
|
66
|
+
});
|
|
67
|
+
return Promise.race([promise, late]).finally(() => clearTimeout(timer));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* One Express app in front of many tenants' apps. It answers process health
|
|
71
|
+
* itself, resolves each request to a tenant (see {@link selectTenant}),
|
|
72
|
+
* activates that tenant's graph on first use, hands the request to the
|
|
73
|
+
* tenant's app, and serves the SPA for whatever the tenant's app leaves
|
|
74
|
+
* unhandled. Nothing below it knows there are other tenants: each graph was
|
|
75
|
+
* built by the same composition root a single-tenant deployment uses.
|
|
76
|
+
*/
|
|
77
|
+
export function createTenantHost(opts) {
|
|
78
|
+
const runtimes = new Map();
|
|
79
|
+
const activationWaitMs = opts.activationWaitMs ?? DEFAULT_ACTIVATION_WAIT_MS;
|
|
80
|
+
const idleMs = (opts.idleMinutes ?? DEFAULT_IDLE_MINUTES) * 60_000;
|
|
81
|
+
const runtimeFor = (descriptor) => {
|
|
82
|
+
let runtime = runtimes.get(descriptor.slug);
|
|
83
|
+
if (!runtime) {
|
|
84
|
+
runtime = new TenantRuntime(descriptor, opts.runtime);
|
|
85
|
+
runtimes.set(descriptor.slug, runtime);
|
|
86
|
+
}
|
|
87
|
+
return runtime;
|
|
88
|
+
};
|
|
89
|
+
const app = express();
|
|
90
|
+
// Forwarded headers are honoured exactly as a single-tenant deployment
|
|
91
|
+
// honours them, and for the same reason: `req.hostname` is what picks the
|
|
92
|
+
// tenant, and behind a proxy it lives in `X-Forwarded-Host`.
|
|
93
|
+
if (opts.process.trustProxy) {
|
|
94
|
+
const raw = opts.process.trustProxy;
|
|
95
|
+
app.set('trust proxy', /^\d+$/.test(raw) ? Number(raw) : raw);
|
|
96
|
+
}
|
|
97
|
+
// The process's own health, before any tenant is involved: a load balancer
|
|
98
|
+
// asks with whatever host name it likes, and a process with no active
|
|
99
|
+
// tenant is still a healthy process.
|
|
100
|
+
app.get('/api/health', (_req, res) => {
|
|
101
|
+
res.json({ status: 'ok', sha: GIT_SHA, timestamp: Date.now(), tenants: runtimes.size });
|
|
102
|
+
});
|
|
103
|
+
app.use(async (req, res, next) => {
|
|
104
|
+
const selector = selectTenant({
|
|
105
|
+
hostname: req.hostname,
|
|
106
|
+
url: req.url,
|
|
107
|
+
peer: req.socket.remoteAddress,
|
|
108
|
+
forwardedFor: req.headers['x-forwarded-for'],
|
|
109
|
+
});
|
|
110
|
+
let descriptor;
|
|
111
|
+
try {
|
|
112
|
+
descriptor =
|
|
113
|
+
selector.kind === 'slug'
|
|
114
|
+
? await opts.source.describe(selector.slug)
|
|
115
|
+
: await opts.source.resolveByHost(selector.host);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
log.error('tenant lookup failed:', { err });
|
|
119
|
+
res.status(503).set('Retry-After', '5').json({ error: 'Tenant lookup failed' });
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!descriptor) {
|
|
123
|
+
if (req.path.startsWith('/api/') || req.path.startsWith(LOOPBACK_TENANT_PREFIX)) {
|
|
124
|
+
res.status(404).json({ error: 'No workspace at this address' });
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
res.status(404).type('text/plain').send('No workspace at this address.');
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (selector.kind === 'slug')
|
|
132
|
+
req.url = selector.rest;
|
|
133
|
+
const runtime = runtimeFor(descriptor);
|
|
134
|
+
// Counted from here, before the graph is even asked for, until the
|
|
135
|
+
// response closes however it ends — a 503 below included. An open
|
|
136
|
+
// response is what keeps a tenant from being evicted from under it.
|
|
137
|
+
// Left exactly once: a client that dropped during the tenant lookup
|
|
138
|
+
// above has had its `close` already, and that event will not come
|
|
139
|
+
// again, so the socket is asked directly; a socket destroyed but not
|
|
140
|
+
// yet closed would otherwise be left twice, once here and once by the
|
|
141
|
+
// listener, taking another request's count with it.
|
|
142
|
+
runtime.enter();
|
|
143
|
+
let left = false;
|
|
144
|
+
const leave = () => {
|
|
145
|
+
if (left)
|
|
146
|
+
return;
|
|
147
|
+
left = true;
|
|
148
|
+
runtime.leave();
|
|
149
|
+
};
|
|
150
|
+
res.on('close', leave);
|
|
151
|
+
if (req.socket.destroyed) {
|
|
152
|
+
leave();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
let graph;
|
|
156
|
+
try {
|
|
157
|
+
graph = await within(runtime.handle(), activationWaitMs);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Logged by the runtime; the caller learns only that it may try again.
|
|
161
|
+
res.status(503).set('Retry-After', '5').json({ error: 'This workspace could not be started; try again shortly' });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (!graph) {
|
|
165
|
+
res.status(503).set('Retry-After', '5').json({ error: 'This workspace is starting; try again shortly' });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
graph.app(req, res, next);
|
|
169
|
+
});
|
|
170
|
+
// Whatever a tenant's app left unhandled: the SPA, with the same rule a
|
|
171
|
+
// single-tenant deployment applies to the namespaces that must never
|
|
172
|
+
// resolve to `index.html` (see `createCoreServer`).
|
|
173
|
+
if (opts.staticDir) {
|
|
174
|
+
const frontendDist = opts.staticDir;
|
|
175
|
+
app.use(express.static(frontendDist));
|
|
176
|
+
app.get('{*path}', (req, res) => {
|
|
177
|
+
if (req.path.startsWith('/.well-known/') ||
|
|
178
|
+
req.path.startsWith('/api/') ||
|
|
179
|
+
req.path.startsWith('/login/oauth/')) {
|
|
180
|
+
res.status(404).json({ error: 'Not found' });
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
res.sendFile(path.join(frontendDist, 'index.html'));
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
// Idle tenants are stopped on a timer, never on the request that would
|
|
187
|
+
// have been their last: a graph whose last response closed `idleMs` ago,
|
|
188
|
+
// with none still open and no queued commit, is not worth its pool and
|
|
189
|
+
// its lease. `busy()` is what keeps an event stream's tenant alive.
|
|
190
|
+
const sweep = async () => {
|
|
191
|
+
for (const runtime of runtimes.values()) {
|
|
192
|
+
if (runtime.state !== 'active' || runtime.idleFor() < idleMs)
|
|
193
|
+
continue;
|
|
194
|
+
if (await runtime.busy())
|
|
195
|
+
continue;
|
|
196
|
+
await runtime.evict().catch((err) => log.warn(`evicting tenant "${runtime.slug}" failed:`, { err }));
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const sweeper = idleMs > 0
|
|
200
|
+
? setInterval(() => void sweep(), Math.min(opts.sweepIntervalMs ?? DEFAULT_SWEEP_INTERVAL_MS, idleMs))
|
|
201
|
+
: null;
|
|
202
|
+
sweeper?.unref();
|
|
203
|
+
const evictAll = async () => {
|
|
204
|
+
await Promise.all([...runtimes.values()].map((runtime) => runtime.evict().catch(() => undefined)));
|
|
205
|
+
};
|
|
206
|
+
return {
|
|
207
|
+
app,
|
|
208
|
+
runtimes: () => runtimes,
|
|
209
|
+
evictAll,
|
|
210
|
+
async stop() {
|
|
211
|
+
if (sweeper)
|
|
212
|
+
clearInterval(sweeper);
|
|
213
|
+
await evictAll();
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=tenant-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-host.js","sourceRoot":"","sources":["../../src/tenancy/tenant-host.ts"],"names":[],"mappings":"AAAA,OAAO,OAAuC,MAAM,SAAS,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAA0B,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAA4C,MAAM,6BAA6B,CAAC;AAE3H,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC;AAEjD,0FAA0F;AAC1F,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,IAAY;IAC9D,OAA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H,CAAC,CAAC;IACF,MAAM,OAAO,GACX,MAAM,GAAG,CAAC;QACR,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,KAAK,KAAK,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,IAAI,yBAAyB,EAAE,MAAM,CAAC,CAAC;QACtG,CAAC,CAAC,IAAI,CAAC;IACX,OAAO,EAAE,KAAK,EAAE,CAAC;IAEjB,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACrG,CAAC,CAAC;IAEF,OAAO;QACL,GAAG;QACH,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ;QACxB,QAAQ;QACR,KAAK,CAAC,IAAI;YACR,IAAI,OAAO;gBAAE,aAAa,CAAC,OAAO,CAAC,CAAC;YACpC,MAAM,QAAQ,EAAE,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Express } from 'express';
|
|
2
|
+
import { type CoreServices } from '../core/create-core-services.js';
|
|
3
|
+
import type { TenantDescriptor } from './tenant-source.contract.js';
|
|
4
|
+
/** A tenant's running graph: its services and the Express app that serves them. */
|
|
5
|
+
export interface TenantGraph {
|
|
6
|
+
core: CoreServices;
|
|
7
|
+
app: Express;
|
|
8
|
+
}
|
|
9
|
+
export type TenantState = 'idle' | 'activating' | 'active' | 'evicting';
|
|
10
|
+
/** The lifecycle seams, so a suite can drive a runtime without a database. */
|
|
11
|
+
export interface TenantRuntimeDeps {
|
|
12
|
+
/** Build and start the graph. Default: `createCoreServices` + `createCoreServer`. */
|
|
13
|
+
activate?: (descriptor: TenantDescriptor) => Promise<TenantGraph>;
|
|
14
|
+
/** Stop a graph. Default: `stopCore`. */
|
|
15
|
+
stop?: (graph: TenantGraph) => Promise<void>;
|
|
16
|
+
/** Whether the graph has work in flight that an eviction would strand. Default: queued commits. */
|
|
17
|
+
busy?: (graph: TenantGraph) => Promise<boolean>;
|
|
18
|
+
now?: () => number;
|
|
19
|
+
/**
|
|
20
|
+
* How long a failed activation is remembered before the next request tries
|
|
21
|
+
* again: `initialMs` after the first failure, doubling per consecutive
|
|
22
|
+
* failure up to `maxMs`. Defaults: 5 s to 60 s.
|
|
23
|
+
*/
|
|
24
|
+
retry?: {
|
|
25
|
+
initialMs?: number;
|
|
26
|
+
maxMs?: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* One tenant's graph, brought up on first use and stopped when the host
|
|
31
|
+
* says so: `idle → activating → active → evicting → idle`.
|
|
32
|
+
*
|
|
33
|
+
* ACTIVATE ONCE. Requests arriving while the graph is being built all await
|
|
34
|
+
* the one activation in flight. A failed activation is remembered for a
|
|
35
|
+
* short, growing window and answered from memory inside it, so a tenant
|
|
36
|
+
* whose remote is down or whose token is wrong costs one clone attempt per
|
|
37
|
+
* window rather than one per request; past the window the next request
|
|
38
|
+
* tries again, since the remote may be back or the token fixed. An eviction
|
|
39
|
+
* that lands mid-activation waits for the activation and then stops what it
|
|
40
|
+
* produced, so a graph is never left running behind an evicted runtime.
|
|
41
|
+
*
|
|
42
|
+
* IN USE MEANS A RESPONSE IS OPEN. The host tells the runtime when it hands
|
|
43
|
+
* a request over and when that response closes, so idleness counts from the
|
|
44
|
+
* last response that ENDED, and a tenant with any response still open — an
|
|
45
|
+
* event stream a browser holds, a clone in flight — is busy and never
|
|
46
|
+
* evicted from under it.
|
|
47
|
+
*/
|
|
48
|
+
export declare class TenantRuntime {
|
|
49
|
+
readonly descriptor: TenantDescriptor;
|
|
50
|
+
private graph;
|
|
51
|
+
private activation;
|
|
52
|
+
private eviction;
|
|
53
|
+
private failure;
|
|
54
|
+
private openResponses;
|
|
55
|
+
private lastUsedAt;
|
|
56
|
+
private readonly activate;
|
|
57
|
+
private readonly stopGraph;
|
|
58
|
+
private readonly isBusy;
|
|
59
|
+
private readonly now;
|
|
60
|
+
private readonly retryInitialMs;
|
|
61
|
+
private readonly retryMaxMs;
|
|
62
|
+
constructor(descriptor: TenantDescriptor, deps?: TenantRuntimeDeps);
|
|
63
|
+
/** A request was handed to this tenant; paired with {@link leave} when its response closes. */
|
|
64
|
+
enter(): void;
|
|
65
|
+
/** A response to this tenant closed, however it ended. */
|
|
66
|
+
leave(): void;
|
|
67
|
+
/** Responses handed over and not yet closed. */
|
|
68
|
+
get open(): number;
|
|
69
|
+
get slug(): string;
|
|
70
|
+
get state(): TenantState;
|
|
71
|
+
/** Milliseconds since a request last touched this tenant. */
|
|
72
|
+
idleFor(): number;
|
|
73
|
+
/**
|
|
74
|
+
* The graph, built if it is not running. Every caller of a concurrent
|
|
75
|
+
* first burst gets the same promise; a caller that arrives during an
|
|
76
|
+
* eviction waits for it, then starts the graph afresh.
|
|
77
|
+
*/
|
|
78
|
+
handle(): Promise<TenantGraph>;
|
|
79
|
+
/**
|
|
80
|
+
* Whether an eviction would strand something: a response still open, or
|
|
81
|
+
* work the graph reports (queued commits). False when nothing runs.
|
|
82
|
+
*/
|
|
83
|
+
busy(): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* Stop the graph, if one runs or is being built. Idempotent: a second call
|
|
86
|
+
* joins the eviction under way. Afterwards the runtime is idle and the
|
|
87
|
+
* next {@link handle} builds a fresh graph.
|
|
88
|
+
*/
|
|
89
|
+
evict(): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=tenant-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-runtime.d.ts","sourceRoot":"","sources":["../../src/tenancy/tenant-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KA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ClE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2C;IAClE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAGzB,UAAU,EAAE,gBAAgB,EACrC,IAAI,GAAE,iBAAsB;IAW9B,+FAA+F;IAC/F,KAAK,IAAI,IAAI;IAKb,0DAA0D;IAC1D,KAAK,IAAI,IAAI;IAKb,gDAAgD;IAChD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,KAAK,IAAI,WAAW,CAKvB;IAED,6DAA6D;IAC7D,OAAO,IAAI,MAAM;IAIjB;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC;IAwBpC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAK9B;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAyBvB"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createCoreServices } from '../core/create-core-services.js';
|
|
2
|
+
import { createCoreServer } from '../core/create-core-server.js';
|
|
3
|
+
import { stopCore } from '../core/lifecycle.js';
|
|
4
|
+
import { logger } from '../shared/logging.js';
|
|
5
|
+
const log = logger('tenancy');
|
|
6
|
+
const DEFAULT_RETRY_INITIAL_MS = 5_000;
|
|
7
|
+
const DEFAULT_RETRY_MAX_MS = 60_000;
|
|
8
|
+
/**
|
|
9
|
+
* How a tenant's graph is built with the composition root as a distribution
|
|
10
|
+
* calls it, plus the one thing a host must say: no mirroring onto the shared
|
|
11
|
+
* package's process-wide bindings, since this process has several graphs and
|
|
12
|
+
* no single value to put there.
|
|
13
|
+
*/
|
|
14
|
+
async function activateWithCore(descriptor) {
|
|
15
|
+
const core = await createCoreServices(descriptor.config, { ...descriptor.ports, mirrorSharedBindings: false });
|
|
16
|
+
try {
|
|
17
|
+
// No static dir: the host serves the SPA once, for every tenant.
|
|
18
|
+
const app = await createCoreServer(core, descriptor.extensions ?? {}, {});
|
|
19
|
+
return { core, app };
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
// A graph whose boot failed still holds a pool and a lease.
|
|
23
|
+
await stopCore(core).catch(() => undefined);
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function queuedCommits(graph) {
|
|
28
|
+
return (await graph.core.pendingCommitsService.oldestQueuedAt()) !== null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* One tenant's graph, brought up on first use and stopped when the host
|
|
32
|
+
* says so: `idle → activating → active → evicting → idle`.
|
|
33
|
+
*
|
|
34
|
+
* ACTIVATE ONCE. Requests arriving while the graph is being built all await
|
|
35
|
+
* the one activation in flight. A failed activation is remembered for a
|
|
36
|
+
* short, growing window and answered from memory inside it, so a tenant
|
|
37
|
+
* whose remote is down or whose token is wrong costs one clone attempt per
|
|
38
|
+
* window rather than one per request; past the window the next request
|
|
39
|
+
* tries again, since the remote may be back or the token fixed. An eviction
|
|
40
|
+
* that lands mid-activation waits for the activation and then stops what it
|
|
41
|
+
* produced, so a graph is never left running behind an evicted runtime.
|
|
42
|
+
*
|
|
43
|
+
* IN USE MEANS A RESPONSE IS OPEN. The host tells the runtime when it hands
|
|
44
|
+
* a request over and when that response closes, so idleness counts from the
|
|
45
|
+
* last response that ENDED, and a tenant with any response still open — an
|
|
46
|
+
* event stream a browser holds, a clone in flight — is busy and never
|
|
47
|
+
* evicted from under it.
|
|
48
|
+
*/
|
|
49
|
+
export class TenantRuntime {
|
|
50
|
+
descriptor;
|
|
51
|
+
graph = null;
|
|
52
|
+
activation = null;
|
|
53
|
+
eviction = null;
|
|
54
|
+
failure = null;
|
|
55
|
+
openResponses = 0;
|
|
56
|
+
lastUsedAt;
|
|
57
|
+
activate;
|
|
58
|
+
stopGraph;
|
|
59
|
+
isBusy;
|
|
60
|
+
now;
|
|
61
|
+
retryInitialMs;
|
|
62
|
+
retryMaxMs;
|
|
63
|
+
constructor(descriptor, deps = {}) {
|
|
64
|
+
this.descriptor = descriptor;
|
|
65
|
+
this.activate = deps.activate ?? activateWithCore;
|
|
66
|
+
this.stopGraph = deps.stop ?? ((graph) => stopCore(graph.core));
|
|
67
|
+
this.isBusy = deps.busy ?? queuedCommits;
|
|
68
|
+
this.now = deps.now ?? Date.now;
|
|
69
|
+
this.retryInitialMs = deps.retry?.initialMs ?? DEFAULT_RETRY_INITIAL_MS;
|
|
70
|
+
this.retryMaxMs = deps.retry?.maxMs ?? DEFAULT_RETRY_MAX_MS;
|
|
71
|
+
this.lastUsedAt = this.now();
|
|
72
|
+
}
|
|
73
|
+
/** A request was handed to this tenant; paired with {@link leave} when its response closes. */
|
|
74
|
+
enter() {
|
|
75
|
+
this.openResponses += 1;
|
|
76
|
+
this.lastUsedAt = this.now();
|
|
77
|
+
}
|
|
78
|
+
/** A response to this tenant closed, however it ended. */
|
|
79
|
+
leave() {
|
|
80
|
+
if (this.openResponses > 0)
|
|
81
|
+
this.openResponses -= 1;
|
|
82
|
+
this.lastUsedAt = this.now();
|
|
83
|
+
}
|
|
84
|
+
/** Responses handed over and not yet closed. */
|
|
85
|
+
get open() {
|
|
86
|
+
return this.openResponses;
|
|
87
|
+
}
|
|
88
|
+
get slug() {
|
|
89
|
+
return this.descriptor.slug;
|
|
90
|
+
}
|
|
91
|
+
get state() {
|
|
92
|
+
if (this.eviction)
|
|
93
|
+
return 'evicting';
|
|
94
|
+
if (this.graph)
|
|
95
|
+
return 'active';
|
|
96
|
+
if (this.activation)
|
|
97
|
+
return 'activating';
|
|
98
|
+
return 'idle';
|
|
99
|
+
}
|
|
100
|
+
/** Milliseconds since a request last touched this tenant. */
|
|
101
|
+
idleFor() {
|
|
102
|
+
return this.now() - this.lastUsedAt;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The graph, built if it is not running. Every caller of a concurrent
|
|
106
|
+
* first burst gets the same promise; a caller that arrives during an
|
|
107
|
+
* eviction waits for it, then starts the graph afresh.
|
|
108
|
+
*/
|
|
109
|
+
async handle() {
|
|
110
|
+
this.lastUsedAt = this.now();
|
|
111
|
+
if (this.eviction)
|
|
112
|
+
await this.eviction;
|
|
113
|
+
if (this.graph)
|
|
114
|
+
return this.graph;
|
|
115
|
+
if (this.failure && this.now() < this.failure.until)
|
|
116
|
+
throw this.failure.error;
|
|
117
|
+
this.activation ??= this.activate(this.descriptor).then((graph) => {
|
|
118
|
+
this.graph = graph;
|
|
119
|
+
this.activation = null;
|
|
120
|
+
this.failure = null;
|
|
121
|
+
log.info(`tenant "${this.slug}" activated`);
|
|
122
|
+
return graph;
|
|
123
|
+
}, (err) => {
|
|
124
|
+
this.activation = null;
|
|
125
|
+
const backoffMs = Math.min(this.failure ? this.failure.backoffMs * 2 : this.retryInitialMs, this.retryMaxMs);
|
|
126
|
+
this.failure = { error: err, until: this.now() + backoffMs, backoffMs };
|
|
127
|
+
log.error(`tenant "${this.slug}" failed to activate; not asked again for ${backoffMs}ms:`, { err });
|
|
128
|
+
throw err;
|
|
129
|
+
});
|
|
130
|
+
return this.activation;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Whether an eviction would strand something: a response still open, or
|
|
134
|
+
* work the graph reports (queued commits). False when nothing runs.
|
|
135
|
+
*/
|
|
136
|
+
async busy() {
|
|
137
|
+
if (this.openResponses > 0)
|
|
138
|
+
return true;
|
|
139
|
+
return this.graph ? this.isBusy(this.graph) : false;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Stop the graph, if one runs or is being built. Idempotent: a second call
|
|
143
|
+
* joins the eviction under way. Afterwards the runtime is idle and the
|
|
144
|
+
* next {@link handle} builds a fresh graph.
|
|
145
|
+
*/
|
|
146
|
+
evict() {
|
|
147
|
+
if (this.eviction)
|
|
148
|
+
return this.eviction;
|
|
149
|
+
const eviction = (async () => {
|
|
150
|
+
if (this.activation) {
|
|
151
|
+
// Whatever the build produces is stopped; a build that fails has
|
|
152
|
+
// stopped its own graph already.
|
|
153
|
+
await this.activation.catch(() => undefined);
|
|
154
|
+
}
|
|
155
|
+
const graph = this.graph;
|
|
156
|
+
this.graph = null;
|
|
157
|
+
if (graph) {
|
|
158
|
+
await this.stopGraph(graph);
|
|
159
|
+
log.info(`tenant "${this.slug}" evicted`);
|
|
160
|
+
}
|
|
161
|
+
})();
|
|
162
|
+
// Assigned, then cleared by identity: an eviction with nothing to stop
|
|
163
|
+
// settles before this line runs, and a `finally` inside it would have
|
|
164
|
+
// cleared a field that was not yet set — leaving the settled promise
|
|
165
|
+
// in place as an eviction forever under way.
|
|
166
|
+
this.eviction = eviction;
|
|
167
|
+
void eviction.finally(() => {
|
|
168
|
+
if (this.eviction === eviction)
|
|
169
|
+
this.eviction = null;
|
|
170
|
+
});
|
|
171
|
+
return eviction;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=tenant-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-runtime.js","sourceRoot":"","sources":["../../src/tenancy/tenant-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAqB,MAAM,iCAAiC,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AA2B9B,MAAM,wBAAwB,GAAG,KAAK,CAAC;AACvC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,KAAK,UAAU,gBAAgB,CAAC,UAA4B;IAC1D,MAAM,IAAI,GAAG,MAAM,kBAAkB,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,GAAG,UAAU,CA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
|
+
/** The three secrets every graph needs, derived rather than stored. */
|
|
2
|
+
export interface TenantSecrets {
|
|
3
|
+
/** Signs the tenant's login sessions and OAuth state. */
|
|
4
|
+
jwtSecret: string;
|
|
5
|
+
/** 32 bytes, base64: encrypts the tenant's vault values, MCP OAuth tokens and stored git credential. */
|
|
6
|
+
secretsEncKey: string;
|
|
7
|
+
/** HMAC key for the tenant's internal (loopback) tool tokens. */
|
|
8
|
+
internalTokenSecret: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A tenant's secrets from ONE master key and its slug, with HKDF-SHA256:
|
|
12
|
+
* the slug is the salt and each secret's name the info, so the three are
|
|
13
|
+
* independent of each other and of every other tenant's.
|
|
14
|
+
*
|
|
15
|
+
* Derived, not generated and stored, for the hand-over: a tenant that leaves
|
|
16
|
+
* for a dedicated deployment takes a `pg_dump` whose vault rows and stored
|
|
17
|
+
* git token are encrypted under its `secretsEncKey`. With derivation the key
|
|
18
|
+
* is reproducible from the master key and the slug on the day of the
|
|
19
|
+
* export, and nothing per tenant has to be kept safe in the meantime. The
|
|
20
|
+
* cloud app's registry calls this with the same inputs and gets the same
|
|
21
|
+
* answer.
|
|
22
|
+
*/
|
|
23
|
+
export declare function deriveTenantSecrets(masterKey: string, slug: string): TenantSecrets;
|
|
24
|
+
//# sourceMappingURL=tenant-secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-secrets.d.ts","sourceRoot":"","sources":["../../src/tenancy/tenant-secrets.ts"],"names":[],"mappings":"AAEA,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,wGAAwG;IACxG,aAAa,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAKD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAYlF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { hkdfSync } from 'node:crypto';
|
|
2
|
+
/** The least a master key may hold: 32 characters is 256 bits of a random string. */
|
|
3
|
+
const MIN_MASTER_KEY_LENGTH = 32;
|
|
4
|
+
/**
|
|
5
|
+
* A tenant's secrets from ONE master key and its slug, with HKDF-SHA256:
|
|
6
|
+
* the slug is the salt and each secret's name the info, so the three are
|
|
7
|
+
* independent of each other and of every other tenant's.
|
|
8
|
+
*
|
|
9
|
+
* Derived, not generated and stored, for the hand-over: a tenant that leaves
|
|
10
|
+
* for a dedicated deployment takes a `pg_dump` whose vault rows and stored
|
|
11
|
+
* git token are encrypted under its `secretsEncKey`. With derivation the key
|
|
12
|
+
* is reproducible from the master key and the slug on the day of the
|
|
13
|
+
* export, and nothing per tenant has to be kept safe in the meantime. The
|
|
14
|
+
* cloud app's registry calls this with the same inputs and gets the same
|
|
15
|
+
* answer.
|
|
16
|
+
*/
|
|
17
|
+
export function deriveTenantSecrets(masterKey, slug) {
|
|
18
|
+
if (masterKey.length < MIN_MASTER_KEY_LENGTH) {
|
|
19
|
+
throw new Error(`TENANT_MASTER_KEY must be at least ${MIN_MASTER_KEY_LENGTH} characters of random text`);
|
|
20
|
+
}
|
|
21
|
+
if (!slug)
|
|
22
|
+
throw new Error('A tenant slug is required to derive its secrets');
|
|
23
|
+
const derive = (info) => Buffer.from(hkdfSync('sha256', masterKey, `hexis-tenant:${slug}`, info, 32)).toString('base64');
|
|
24
|
+
return {
|
|
25
|
+
jwtSecret: derive('jwt-secret'),
|
|
26
|
+
secretsEncKey: derive('secrets-enc-key'),
|
|
27
|
+
internalTokenSecret: derive('internal-token-secret'),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=tenant-secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-secrets.js","sourceRoot":"","sources":["../../src/tenancy/tenant-secrets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAYvC,qFAAqF;AACrF,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiB,EAAE,IAAY;IACjE,IAAI,SAAS,CAAC,MAAM,GAAG,qBAAqB,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,sCAAsC,qBAAqB,4BAA4B,CAAC,CAAC;IAC3G,CAAC;IACD,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAC9E,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CACtC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,gBAAgB,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAClG,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,YAAY,CAAC;QAC/B,aAAa,EAAE,MAAM,CAAC,iBAAiB,CAAC;QACxC,mBAAmB,EAAE,MAAM,CAAC,uBAAuB,CAAC;KACrD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { TenantConfig } from '../core-config.js';
|
|
2
|
+
import type { CorePorts } from '../core/core-ports.js';
|
|
3
|
+
import type { ServerExtensions } from '../core/create-core-server.js';
|
|
4
|
+
/**
|
|
5
|
+
* A tenant, as the host needs to know it: which host names reach it, what
|
|
6
|
+
* its service graph is built from, and what a distribution adds to that
|
|
7
|
+
* graph. One of these is one `createCoreServices` + `createCoreServer`, run
|
|
8
|
+
* on demand and stopped again when idle — see `tenant-runtime.ts`.
|
|
9
|
+
*
|
|
10
|
+
* `ports` and `extensions` are per tenant on purpose: everything the
|
|
11
|
+
* enterprise overlay does per deployment (its SSO plugin, session sink,
|
|
12
|
+
* erasure participants, extra startup steps) it does per tenant here, through
|
|
13
|
+
* the same two seams, with nothing below the front door knowing the
|
|
14
|
+
* difference.
|
|
15
|
+
*/
|
|
16
|
+
export interface TenantDescriptor {
|
|
17
|
+
/** The tenant's stable name: lowercase, `[a-z][a-z0-9-]*`, at most 40 characters. */
|
|
18
|
+
readonly slug: string;
|
|
19
|
+
/** Host names (no port) whose requests belong to this tenant, lowercase. */
|
|
20
|
+
readonly hosts: readonly string[];
|
|
21
|
+
readonly config: TenantConfig;
|
|
22
|
+
readonly ports?: CorePorts;
|
|
23
|
+
readonly extensions?: ServerExtensions;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Where tenants come from. Core ships {@link StaticTenantSource}, which
|
|
27
|
+
* reads a file, for development and tests; the cloud app implements this
|
|
28
|
+
* over its own registry, where subdomains are provisioned and plans live.
|
|
29
|
+
* A source answers `null` for a host or slug it does not know, and the host
|
|
30
|
+
* turns that into a 404 without building anything.
|
|
31
|
+
*/
|
|
32
|
+
export interface TenantSource {
|
|
33
|
+
resolveByHost(host: string): Promise<TenantDescriptor | null>;
|
|
34
|
+
describe(slug: string): Promise<TenantDescriptor | null>;
|
|
35
|
+
}
|
|
36
|
+
/** What a slug may look like: it names a schema, a folder and a loopback path. */
|
|
37
|
+
export declare const TENANT_SLUG_PATTERN: RegExp;
|
|
38
|
+
export declare function assertTenantSlug(slug: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* A host name the way the host compares it: lowercase, without a port or a
|
|
41
|
+
* trailing dot. `Host` headers and `X-Forwarded-Host` values arrive in every
|
|
42
|
+
* spelling a client or proxy chooses.
|
|
43
|
+
*/
|
|
44
|
+
export declare function normalizeHost(host: string): string;
|
|
45
|
+
//# sourceMappingURL=tenant-source.contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-source.contract.d.ts","sourceRoot":"","sources":["../../src/tenancy/tenant-source.contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qFAAqF;IACrF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACxC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC9D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;CAC1D;AAED,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,QAA2B,CAAC;AAE5D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKlD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What a slug may look like: it names a schema, a folder and a loopback path. */
|
|
2
|
+
export const TENANT_SLUG_PATTERN = /^[a-z][a-z0-9-]{0,39}$/;
|
|
3
|
+
export function assertTenantSlug(slug) {
|
|
4
|
+
if (!TENANT_SLUG_PATTERN.test(slug)) {
|
|
5
|
+
throw new Error(`Tenant slug must match ${TENANT_SLUG_PATTERN} (lowercase, digits, hyphens); got "${slug}"`);
|
|
6
|
+
}
|
|
7
|
+
return slug;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A host name the way the host compares it: lowercase, without a port or a
|
|
11
|
+
* trailing dot. `Host` headers and `X-Forwarded-Host` values arrive in every
|
|
12
|
+
* spelling a client or proxy chooses.
|
|
13
|
+
*/
|
|
14
|
+
export function normalizeHost(host) {
|
|
15
|
+
const trimmed = host.trim().toLowerCase().replace(/\.$/, '');
|
|
16
|
+
// `[::1]:3001` keeps its brackets; `example.test:3001` loses its port.
|
|
17
|
+
if (trimmed.startsWith('['))
|
|
18
|
+
return trimmed.replace(/\]:\d+$/, ']');
|
|
19
|
+
return trimmed.replace(/:\d+$/, '');
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=tenant-source.contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-source.contract.js","sourceRoot":"","sources":["../../src/tenancy/tenant-source.contract.ts"],"names":[],"mappings":"AAsCA,kFAAkF;AAClF,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AAE5D,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,0BAA0B,mBAAmB,uCAAuC,IAAI,GAAG,CAAC,CAAC;IAC/G,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC7D,uEAAuE;IACvE,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACpE,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC"}
|