@flowdular/sdk 0.1.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/.ai/agents/README.md +27 -0
- package/.ai/agents/module-executor.md +36 -0
- package/.ai/agents/reviewer.md +23 -0
- package/.ai/agents/sandbox/agentic-engineer.md +31 -0
- package/.ai/agents/sandbox/backend-engineer.md +36 -0
- package/.ai/agents/sandbox/business-manager.md +23 -0
- package/.ai/agents/sandbox/frontend-engineer.md +27 -0
- package/.ai/agents/sandbox/ux-designer.md +23 -0
- package/.ai/agents/spec-author.md +29 -0
- package/.ai/blueprints/add-migration/README.md +5 -0
- package/.ai/blueprints/add-migration/allowed-paths.yaml +23 -0
- package/.ai/blueprints/add-migration/blueprint.json +14 -0
- package/.ai/blueprints/add-migration/examples/invalid/input-destructive.json +6 -0
- package/.ai/blueprints/add-migration/examples/invalid/plan-unnumbered-file.json +9 -0
- package/.ai/blueprints/add-migration/examples/valid/input.json +6 -0
- package/.ai/blueprints/add-migration/examples/valid/plan.json +9 -0
- package/.ai/blueprints/add-migration/gates.yaml +30 -0
- package/.ai/blueprints/add-migration/input.schema.json +23 -0
- package/.ai/blueprints/add-migration/plan.schema.json +54 -0
- package/.ai/blueprints/add-migration/required-files.yaml +18 -0
- package/.ai/blueprints/add-migration/spec-requirements.yaml +13 -0
- package/.ai/blueprints/add-migration/steps.yaml +62 -0
- package/.ai/blueprints/author-spec/README.md +5 -0
- package/.ai/blueprints/author-spec/allowed-paths.yaml +7 -0
- package/.ai/blueprints/author-spec/blueprint.json +14 -0
- package/.ai/blueprints/author-spec/examples/invalid/input-missing-outcome.json +5 -0
- package/.ai/blueprints/author-spec/examples/valid/input.json +6 -0
- package/.ai/blueprints/author-spec/gates.yaml +13 -0
- package/.ai/blueprints/author-spec/input.schema.json +20 -0
- package/.ai/blueprints/author-spec/plan.schema.json +14 -0
- package/.ai/blueprints/author-spec/required-files.yaml +6 -0
- package/.ai/blueprints/author-spec/spec-requirements.yaml +35 -0
- package/.ai/blueprints/author-spec/steps.yaml +28 -0
- package/.ai/blueprints/author-spec/templates/module.yaml +45 -0
- package/.ai/blueprints/bug-fix/README.md +5 -0
- package/.ai/blueprints/bug-fix/allowed-paths.yaml +29 -0
- package/.ai/blueprints/bug-fix/blueprint.json +14 -0
- package/.ai/blueprints/bug-fix/examples/invalid/input-no-symptom.json +4 -0
- package/.ai/blueprints/bug-fix/examples/invalid/plan-no-test.json +8 -0
- package/.ai/blueprints/bug-fix/examples/valid/input.json +6 -0
- package/.ai/blueprints/bug-fix/examples/valid/plan.json +8 -0
- package/.ai/blueprints/bug-fix/gates.yaml +30 -0
- package/.ai/blueprints/bug-fix/input.schema.json +25 -0
- package/.ai/blueprints/bug-fix/plan.schema.json +53 -0
- package/.ai/blueprints/bug-fix/required-files.yaml +7 -0
- package/.ai/blueprints/bug-fix/spec-requirements.yaml +7 -0
- package/.ai/blueprints/bug-fix/steps.yaml +51 -0
- package/.ai/blueprints/core-extend/README.md +5 -0
- package/.ai/blueprints/core-extend/allowed-paths.yaml +49 -0
- package/.ai/blueprints/core-extend/blueprint.json +14 -0
- package/.ai/blueprints/core-extend/examples/invalid/input-unknown-package.json +5 -0
- package/.ai/blueprints/core-extend/examples/invalid/plan-missing-gates.json +7 -0
- package/.ai/blueprints/core-extend/examples/valid/input.json +6 -0
- package/.ai/blueprints/core-extend/examples/valid/plan.json +10 -0
- package/.ai/blueprints/core-extend/gates.yaml +16 -0
- package/.ai/blueprints/core-extend/input.schema.json +54 -0
- package/.ai/blueprints/core-extend/plan.schema.json +39 -0
- package/.ai/blueprints/core-extend/required-files.yaml +36 -0
- package/.ai/blueprints/core-extend/spec-requirements.yaml +17 -0
- package/.ai/blueprints/core-extend/steps.yaml +54 -0
- package/.ai/blueprints/edit-module/README.md +9 -0
- package/.ai/blueprints/edit-module/allowed-paths.yaml +27 -0
- package/.ai/blueprints/edit-module/blueprint.json +20 -0
- package/.ai/blueprints/edit-module/examples/invalid/input-unknown-change.json +5 -0
- package/.ai/blueprints/edit-module/examples/invalid/plan-touches-platform.json +15 -0
- package/.ai/blueprints/edit-module/examples/valid/input.json +5 -0
- package/.ai/blueprints/edit-module/examples/valid/plan.json +25 -0
- package/.ai/blueprints/edit-module/gates.yaml +30 -0
- package/.ai/blueprints/edit-module/input.schema.json +31 -0
- package/.ai/blueprints/edit-module/plan.schema.json +65 -0
- package/.ai/blueprints/edit-module/required-files.yaml +80 -0
- package/.ai/blueprints/edit-module/spec-requirements.yaml +15 -0
- package/.ai/blueprints/edit-module/steps.yaml +115 -0
- package/.ai/blueprints/new-module/README.md +7 -0
- package/.ai/blueprints/new-module/allowed-paths.yaml +27 -0
- package/.ai/blueprints/new-module/blueprint.json +20 -0
- package/.ai/blueprints/new-module/examples/invalid/input-spec-outside-modules.json +4 -0
- package/.ai/blueprints/new-module/examples/invalid/plan-unknown-gate.json +8 -0
- package/.ai/blueprints/new-module/examples/valid/input.json +5 -0
- package/.ai/blueprints/new-module/examples/valid/plan.json +22 -0
- package/.ai/blueprints/new-module/gates.yaml +30 -0
- package/.ai/blueprints/new-module/input.schema.json +21 -0
- package/.ai/blueprints/new-module/plan.schema.json +58 -0
- package/.ai/blueprints/new-module/required-files.yaml +73 -0
- package/.ai/blueprints/new-module/spec-requirements.yaml +30 -0
- package/.ai/blueprints/new-module/steps.yaml +138 -0
- package/.ai/blueprints/release/README.md +5 -0
- package/.ai/blueprints/release/allowed-paths.yaml +19 -0
- package/.ai/blueprints/release/blueprint.json +14 -0
- package/.ai/blueprints/release/examples/invalid/input-bad-version.json +4 -0
- package/.ai/blueprints/release/examples/invalid/plan-bad-branch.json +7 -0
- package/.ai/blueprints/release/examples/valid/input.json +5 -0
- package/.ai/blueprints/release/examples/valid/plan.json +20 -0
- package/.ai/blueprints/release/gates.yaml +20 -0
- package/.ai/blueprints/release/input.schema.json +24 -0
- package/.ai/blueprints/release/plan.schema.json +46 -0
- package/.ai/blueprints/release/required-files.yaml +19 -0
- package/.ai/blueprints/release/spec-requirements.yaml +8 -0
- package/.ai/blueprints/release/steps.yaml +47 -0
- package/.ai/blueprints/security-review/README.md +5 -0
- package/.ai/blueprints/security-review/allowed-paths.yaml +6 -0
- package/.ai/blueprints/security-review/blueprint.json +14 -0
- package/.ai/blueprints/security-review/examples/invalid/input-unknown-kind.json +4 -0
- package/.ai/blueprints/security-review/examples/invalid/plan-finding-without-scenario.json +14 -0
- package/.ai/blueprints/security-review/examples/valid/input.json +4 -0
- package/.ai/blueprints/security-review/examples/valid/plan.json +19 -0
- package/.ai/blueprints/security-review/gates.yaml +22 -0
- package/.ai/blueprints/security-review/input.schema.json +20 -0
- package/.ai/blueprints/security-review/plan.schema.json +65 -0
- package/.ai/blueprints/security-review/required-files.yaml +6 -0
- package/.ai/blueprints/security-review/spec-requirements.yaml +9 -0
- package/.ai/blueprints/security-review/steps.yaml +38 -0
- package/.ai/policies/capabilities.yaml +164 -0
- package/.ai/policies/model-routing.yaml +72 -0
- package/.ai/policies/path-ownership.yaml +65 -0
- package/.ai/policies/task-budgets.yaml +37 -0
- package/.ai/references/catalog/LICENSE +21 -0
- package/.ai/references/catalog/migrations/0001_catalog_core.down.sql +2 -0
- package/.ai/references/catalog/migrations/0001_catalog_core.up.sql +21 -0
- package/.ai/references/catalog/migrations/0002_catalog_history.down.sql +3 -0
- package/.ai/references/catalog/migrations/0002_catalog_history.up.sql +20 -0
- package/.ai/references/catalog/migrations/0003_catalog_history_service_actors.down.sql +3 -0
- package/.ai/references/catalog/migrations/0003_catalog_history_service_actors.up.sql +36 -0
- package/.ai/references/catalog/migrations/0004_catalog_idempotency_ledger.down.sql +3 -0
- package/.ai/references/catalog/migrations/0004_catalog_idempotency_ledger.up.sql +19 -0
- package/.ai/references/catalog/migrations/README.md +3 -0
- package/.ai/references/catalog/module.json +27 -0
- package/.ai/references/catalog/package.json +49 -0
- package/.ai/references/catalog/spec/module.yaml +86 -0
- package/.ai/references/catalog/src/acl/permissions.ts +6 -0
- package/.ai/references/catalog/src/agent/tools.ts +164 -0
- package/.ai/references/catalog/src/api/endpoints.ts +243 -0
- package/.ai/references/catalog/src/client/CatalogHistoryDrawer.tsrx +123 -0
- package/.ai/references/catalog/src/client/CatalogItemForm.tsrx +190 -0
- package/.ai/references/catalog/src/client/CatalogView.tsrx +473 -0
- package/.ai/references/catalog/src/client/api.ts +111 -0
- package/.ai/references/catalog/src/client/contribution.tsrx +61 -0
- package/.ai/references/catalog/src/client/index.ts +18 -0
- package/.ai/references/catalog/src/client/navigation-copy.ts +9 -0
- package/.ai/references/catalog/src/client/state.ts +24 -0
- package/.ai/references/catalog/src/domain/types.ts +32 -0
- package/.ai/references/catalog/src/domain/variables.ts +111 -0
- package/.ai/references/catalog/src/index.ts +31 -0
- package/.ai/references/catalog/src/platform.ts +35 -0
- package/.ai/references/catalog/src/server/index.ts +4 -0
- package/.ai/references/catalog/src/server/runtime.ts +86 -0
- package/.ai/references/catalog/src/services/catalog-service.ts +306 -0
- package/.ai/references/catalog/src/services/database-repository.ts +440 -0
- package/.ai/references/catalog/src/services/index.ts +4 -0
- package/.ai/references/catalog/src/services/migration.ts +171 -0
- package/.ai/references/catalog/src/services/repository.ts +36 -0
- package/.ai/references/catalog/src/services/target-idempotency.ts +59 -0
- package/.ai/references/catalog/tests/agent-tools.test.ts +277 -0
- package/.ai/references/catalog/tests/endpoints.test.ts +320 -0
- package/.ai/references/catalog/tests/idempotency.test.ts +297 -0
- package/.ai/references/catalog/tests/migrations.test.ts +149 -0
- package/.ai/references/catalog/tests/module.test.ts +271 -0
- package/.ai/references/catalog/tests/support/database.ts +76 -0
- package/.ai/references/catalog/translations/en.json +101 -0
- package/.ai/references/catalog/translations/pl.json +101 -0
- package/.ai/references/catalog/tsconfig.json +15 -0
- package/.ai/references/catalog/vitest.config.ts +16 -0
- package/.ai/references/catalog.provenance.json +55 -0
- package/.ai/skills/README.md +36 -0
- package/.ai/skills/agent-tool-design/SKILL.md +209 -0
- package/.ai/skills/auth-security-review/SKILL.md +96 -0
- package/.ai/skills/auto-review/SKILL.md +112 -0
- package/.ai/skills/bug-hunt/SKILL.md +110 -0
- package/.ai/skills/business-agent-design/SKILL.md +188 -0
- package/.ai/skills/cli-extension/SKILL.md +114 -0
- package/.ai/skills/core-extend/SKILL.md +104 -0
- package/.ai/skills/database-adapter/SKILL.md +204 -0
- package/.ai/skills/database-adapter/references/first-run-and-matrix.md +105 -0
- package/.ai/skills/migration-authoring/SKILL.md +167 -0
- package/.ai/skills/module-new/SKILL.md +180 -0
- package/.ai/skills/module-update/SKILL.md +100 -0
- package/.ai/skills/perf-audit/SKILL.md +105 -0
- package/.ai/skills/release-eject-pr/SKILL.md +113 -0
- package/.ai/skills/spec-approval/SKILL.md +112 -0
- package/.ai/skills/test-hardening/SKILL.md +86 -0
- package/.ai/skills/translations-i18n/SKILL.md +85 -0
- package/.ai/skills/ux-design/SKILL.md +97 -0
- package/.ai/skills/variables/SKILL.md +164 -0
- package/.ai/skills/workflow-development/SKILL.md +199 -0
- package/AGENTS.md +59 -0
- package/LICENSE +21 -0
- package/README.md +24 -0
- package/docs/agent-contract.md +45 -0
- package/docs/design-system.md +217 -0
- package/modules/agents/migrations/0001_agents_core.down.sql +4 -0
- package/modules/agents/migrations/0001_agents_core.up.sql +106 -0
- package/modules/agents/migrations/0002_provider_connections.down.sql +1 -0
- package/modules/agents/migrations/0002_provider_connections.up.sql +34 -0
- package/modules/agents/migrations/0003_resource_audit.down.sql +1 -0
- package/modules/agents/migrations/0003_resource_audit.up.sql +25 -0
- package/modules/agents/migrations/0004_run_grants.down.sql +1 -0
- package/modules/agents/migrations/0004_run_grants.up.sql +19 -0
- package/modules/agents/migrations/0005_long_running_limits.down.sql +2 -0
- package/modules/agents/migrations/0005_long_running_limits.up.sql +14 -0
- package/modules/agents/migrations/0006_agent_skills.down.sql +3 -0
- package/modules/agents/migrations/0006_agent_skills.up.sql +44 -0
- package/modules/agents/migrations/0007_model_readiness.down.sql +1 -0
- package/modules/agents/migrations/0007_model_readiness.up.sql +18 -0
- package/modules/agents/migrations/0008_output_limits.down.sql +2 -0
- package/modules/agents/migrations/0008_output_limits.up.sql +8 -0
- package/modules/agents/migrations/0009_agent_audit_v3.down.sql +1 -0
- package/modules/agents/migrations/0009_agent_audit_v3.up.sql +25 -0
- package/modules/agents/migrations/0012_agent_run_costs.down.sql +3 -0
- package/modules/agents/migrations/0012_agent_run_costs.up.sql +32 -0
- package/modules/agents/migrations/0013_workflow_prerequisites.down.sql +3 -0
- package/modules/agents/migrations/0013_workflow_prerequisites.up.sql +97 -0
- package/modules/agents/migrations/0014_agent_action_audit.down.sql +1 -0
- package/modules/agents/migrations/0014_agent_action_audit.up.sql +25 -0
- package/modules/agents/migrations/0015_agent_run_actors.down.sql +1 -0
- package/modules/agents/migrations/0015_agent_run_actors.up.sql +17 -0
- package/modules/agents/migrations/0016_module_owned_agents.down.sql +6 -0
- package/modules/agents/migrations/0016_module_owned_agents.up.sql +68 -0
- package/modules/agents/migrations/0017_agent_authorization_subjects.down.sql +2 -0
- package/modules/agents/migrations/0017_agent_authorization_subjects.up.sql +18 -0
- package/modules/agents/migrations/0018_agent_child_tenant_isolation.down.sql +12 -0
- package/modules/agents/migrations/0018_agent_child_tenant_isolation.up.sql +88 -0
- package/modules/agents/migrations/0019_background_recovery_grants.down.sql +6 -0
- package/modules/agents/migrations/0019_background_recovery_grants.up.sql +17 -0
- package/modules/agents/migrations/0020_provider_summary_role.down.sql +2 -0
- package/modules/agents/migrations/0020_provider_summary_role.up.sql +17 -0
- package/modules/agents/migrations/0021_agents_agent_reconciliation_role.down.sql +4 -0
- package/modules/agents/migrations/0021_agents_agent_reconciliation_role.up.sql +7 -0
- package/modules/agents/migrations/README.md +39 -0
- package/modules/agents/module.json +38 -0
- package/modules/agents/package.json +56 -0
- package/modules/agents/spec/module.yaml +271 -0
- package/modules/agents/spec/procedures-compatibility.md +63 -0
- package/modules/agents/src/acl/permissions.ts +13 -0
- package/modules/agents/src/api/endpoints.ts +1122 -0
- package/modules/agents/src/cli/commands.json +29 -0
- package/modules/agents/src/cli/index.ts +162 -0
- package/modules/agents/src/client/AgentDashboardWidget.tsrx +32 -0
- package/modules/agents/src/client/AgentDefinitionForm.tsrx +362 -0
- package/modules/agents/src/client/AgentDefinitionList.tsrx +127 -0
- package/modules/agents/src/client/AgentPlaygroundView.tsrx +246 -0
- package/modules/agents/src/client/AgentProcedureForm.tsrx +182 -0
- package/modules/agents/src/client/AgentProcedureList.tsrx +118 -0
- package/modules/agents/src/client/AgentProceduresView.tsrx +253 -0
- package/modules/agents/src/client/AgentProvidersView.tsrx +248 -0
- package/modules/agents/src/client/AgentRunsView.tsrx +304 -0
- package/modules/agents/src/client/AgentUsageView.tsrx +233 -0
- package/modules/agents/src/client/AgentsView.tsrx +339 -0
- package/modules/agents/src/client/ModuleAgentBindingForm.tsrx +239 -0
- package/modules/agents/src/client/ModuleAgentList.tsrx +122 -0
- package/modules/agents/src/client/ProviderConnectionForm.tsrx +273 -0
- package/modules/agents/src/client/ProviderConnectionList.tsrx +229 -0
- package/modules/agents/src/client/ProviderModelEditor.tsrx +313 -0
- package/modules/agents/src/client/RunTimeline.tsrx +212 -0
- package/modules/agents/src/client/agents.css +349 -0
- package/modules/agents/src/client/api.ts +373 -0
- package/modules/agents/src/client/contribution.tsrx +181 -0
- package/modules/agents/src/client/index.ts +21 -0
- package/modules/agents/src/client/presentation.ts +162 -0
- package/modules/agents/src/client/state.ts +100 -0
- package/modules/agents/src/domain/context-variables.ts +58 -0
- package/modules/agents/src/domain/run-timeline.ts +145 -0
- package/modules/agents/src/domain/types.ts +481 -0
- package/modules/agents/src/index.ts +88 -0
- package/modules/agents/src/platform.ts +82 -0
- package/modules/agents/src/server/action-execution.ts +811 -0
- package/modules/agents/src/server/define-agent.ts +170 -0
- package/modules/agents/src/server/index.ts +67 -0
- package/modules/agents/src/server/run-execution.ts +231 -0
- package/modules/agents/src/server/run-queue.ts +96 -0
- package/modules/agents/src/server/runtime.ts +448 -0
- package/modules/agents/src/server/tools.ts +18 -0
- package/modules/agents/src/services/agent-service.ts +2167 -0
- package/modules/agents/src/services/credential-vault.ts +133 -0
- package/modules/agents/src/services/database-repository.ts +2786 -0
- package/modules/agents/src/services/index.ts +33 -0
- package/modules/agents/src/services/migration.ts +1152 -0
- package/modules/agents/src/services/module-agent-preflight.ts +76 -0
- package/modules/agents/src/services/outbound-policy.ts +136 -0
- package/modules/agents/src/services/provider-broker.ts +80 -0
- package/modules/agents/src/services/provider-repository.ts +589 -0
- package/modules/agents/src/services/provider-service.ts +968 -0
- package/modules/agents/src/services/repository.ts +294 -0
- package/modules/agents/src/services/run-grant.ts +305 -0
- package/modules/agents/src/services/usage-service.ts +119 -0
- package/modules/agents/src/services/worker.ts +442 -0
- package/modules/agents/src/settings.ts +244 -0
- package/modules/agents/translations/en.json +403 -0
- package/modules/agents/translations/pl.json +403 -0
- package/modules/auth/README.md +215 -0
- package/modules/auth/migrations/0001_auth_core.up.sql +108 -0
- package/modules/auth/migrations/0002_bundled_module_scopes.up.sql +26 -0
- package/modules/auth/migrations/0003_agent_core_scopes.up.sql +12 -0
- package/modules/auth/migrations/0004_owner_only_development_scopes.up.sql +8 -0
- package/modules/auth/migrations/0005_agent_provider_scopes.up.sql +13 -0
- package/modules/auth/migrations/0006_tenant_slug.up.sql +6 -0
- package/modules/auth/migrations/0007_sandbox_scopes.up.sql +13 -0
- package/modules/auth/migrations/0008_api_tokens.up.sql +43 -0
- package/modules/auth/migrations/0009_module_settings.up.sql +24 -0
- package/modules/auth/migrations/0010_sign_in_lockout.up.sql +11 -0
- package/modules/auth/migrations/0011_session_ids_and_password_reset.up.sql +7 -0
- package/modules/auth/migrations/0012_roles.up.sql +31 -0
- package/modules/auth/migrations/0013_audit.up.sql +27 -0
- package/modules/auth/migrations/0014_audit_actor.up.sql +4 -0
- package/modules/auth/migrations/0015_account_security.up.sql +81 -0
- package/modules/auth/module.json +26 -0
- package/modules/auth/package.json +61 -0
- package/modules/auth/spec/module.yaml +190 -0
- package/modules/auth/src/acl/scopes.ts +86 -0
- package/modules/auth/src/api/attempt-limiter.ts +42 -0
- package/modules/auth/src/api/client-address.ts +14 -0
- package/modules/auth/src/api/cookies.ts +52 -0
- package/modules/auth/src/api/origin.ts +40 -0
- package/modules/auth/src/cli/commands.json +74 -0
- package/modules/auth/src/cli/database.ts +51 -0
- package/modules/auth/src/cli/greenfield.ts +173 -0
- package/modules/auth/src/cli/index.ts +184 -0
- package/modules/auth/src/cli/provisioning.ts +211 -0
- package/modules/auth/src/client/AuthBackdrop.tsrx +137 -0
- package/modules/auth/src/client/AuthenticationCore.tsrx +630 -0
- package/modules/auth/src/client/PasswordChangeRequired.tsrx +145 -0
- package/modules/auth/src/client/PublicAuthFlows.tsrx +379 -0
- package/modules/auth/src/client/api.ts +464 -0
- package/modules/auth/src/client/audit/AuditView.tsrx +357 -0
- package/modules/auth/src/client/audit/api.ts +164 -0
- package/modules/auth/src/client/audit/audit-columns.tsrx +47 -0
- package/modules/auth/src/client/audit/audit-row.ts +38 -0
- package/modules/auth/src/client/auth.css +483 -0
- package/modules/auth/src/client/contribution.tsrx +100 -0
- package/modules/auth/src/client/index.ts +32 -0
- package/modules/auth/src/client/security/SecurityView.tsrx +253 -0
- package/modules/auth/src/client/settings/PreferencesCard.tsrx +65 -0
- package/modules/auth/src/client/settings/SettingsView.tsrx +212 -0
- package/modules/auth/src/client/settings/WorkspaceCard.tsrx +59 -0
- package/modules/auth/src/client/settings/api.ts +115 -0
- package/modules/auth/src/client/slug.ts +26 -0
- package/modules/auth/src/client/state.ts +115 -0
- package/modules/auth/src/client/tokens/ApiTokenForm.tsrx +153 -0
- package/modules/auth/src/client/tokens/ApiTokenSecret.tsrx +35 -0
- package/modules/auth/src/client/tokens/ApiTokensView.tsrx +216 -0
- package/modules/auth/src/client/tokens/api.ts +59 -0
- package/modules/auth/src/client/tokens/state.ts +26 -0
- package/modules/auth/src/client/tokens/token-columns.tsrx +64 -0
- package/modules/auth/src/client/translations.ts +23 -0
- package/modules/auth/src/domain/types.ts +152 -0
- package/modules/auth/src/index.ts +42 -0
- package/modules/auth/src/middleware/authentication.ts +97 -0
- package/modules/auth/src/platform.ts +0 -0
- package/modules/auth/src/server/actor.ts +12 -0
- package/modules/auth/src/server/audit-endpoints.ts +51 -0
- package/modules/auth/src/server/composition.ts +9 -0
- package/modules/auth/src/server/endpoints.ts +893 -0
- package/modules/auth/src/server/http.ts +153 -0
- package/modules/auth/src/server/index.ts +37 -0
- package/modules/auth/src/server/roles-endpoints.ts +120 -0
- package/modules/auth/src/server/runtime.ts +705 -0
- package/modules/auth/src/server/session-endpoints.ts +86 -0
- package/modules/auth/src/server/session-security.ts +62 -0
- package/modules/auth/src/server/token-endpoints.ts +106 -0
- package/modules/auth/src/services/auth-service-error.ts +11 -0
- package/modules/auth/src/services/auth-service.ts +2309 -0
- package/modules/auth/src/services/database-repository.ts +1825 -0
- package/modules/auth/src/services/mail-delivery.ts +27 -0
- package/modules/auth/src/services/migration.ts +591 -0
- package/modules/auth/src/services/password.ts +115 -0
- package/modules/auth/src/services/repository.ts +395 -0
- package/modules/auth/src/services/settings-store.ts +92 -0
- package/modules/auth/src/services/totp.ts +135 -0
- package/modules/auth/src/services/validation.ts +186 -0
- package/modules/auth/src/settings.ts +150 -0
- package/modules/auth/translations/en.json +263 -0
- package/modules/auth/translations/pl.json +263 -0
- package/modules/automations/migrations/0001_automations_core.down.sql +10 -0
- package/modules/automations/migrations/0001_automations_core.up.sql +76 -0
- package/modules/automations/migrations/0002_automations_targets.down.sql +9 -0
- package/modules/automations/migrations/0002_automations_targets.up.sql +37 -0
- package/modules/automations/migrations/0003_automations_scheduler_role.down.sql +3 -0
- package/modules/automations/migrations/0003_automations_scheduler_role.up.sql +19 -0
- package/modules/automations/migrations/0004_automations_trigger_routing_role.down.sql +3 -0
- package/modules/automations/migrations/0004_automations_trigger_routing_role.up.sql +18 -0
- package/modules/automations/migrations/README.md +3 -0
- package/modules/automations/module.json +31 -0
- package/modules/automations/package.json +55 -0
- package/modules/automations/spec/module.yaml +93 -0
- package/modules/automations/src/acl/permissions.ts +10 -0
- package/modules/automations/src/api/endpoints.ts +480 -0
- package/modules/automations/src/client/AutomationScheduleForm.tsrx +218 -0
- package/modules/automations/src/client/AutomationSchedulesView.tsrx +339 -0
- package/modules/automations/src/client/AutomationTriggerForm.tsrx +190 -0
- package/modules/automations/src/client/AutomationTriggersView.tsrx +329 -0
- package/modules/automations/src/client/api.ts +148 -0
- package/modules/automations/src/client/contribution.tsrx +70 -0
- package/modules/automations/src/client/index.ts +20 -0
- package/modules/automations/src/client/presentation.ts +38 -0
- package/modules/automations/src/client/state.ts +40 -0
- package/modules/automations/src/client/target-selection.ts +44 -0
- package/modules/automations/src/domain/cadence.ts +44 -0
- package/modules/automations/src/domain/types.ts +110 -0
- package/modules/automations/src/domain/variables.ts +178 -0
- package/modules/automations/src/index.ts +39 -0
- package/modules/automations/src/platform.ts +73 -0
- package/modules/automations/src/server/execution.ts +77 -0
- package/modules/automations/src/server/index.ts +39 -0
- package/modules/automations/src/server/runtime.ts +218 -0
- package/modules/automations/src/server/targets.ts +116 -0
- package/modules/automations/src/services/automations-service.ts +10 -0
- package/modules/automations/src/services/database-repository.ts +763 -0
- package/modules/automations/src/services/index.ts +5 -0
- package/modules/automations/src/services/migration.ts +223 -0
- package/modules/automations/src/services/repository.ts +119 -0
- package/modules/automations/src/services/schedule-service.ts +837 -0
- package/modules/automations/src/services/secret-vault.ts +124 -0
- package/modules/automations/src/services/trigger-service.ts +648 -0
- package/modules/automations/src/settings.ts +69 -0
- package/modules/automations/translations/en.json +126 -0
- package/modules/automations/translations/pl.json +126 -0
- package/modules/automations-workflows-integration/module.json +27 -0
- package/modules/automations-workflows-integration/package.json +48 -0
- package/modules/automations-workflows-integration/spec/module.yaml +93 -0
- package/modules/automations-workflows-integration/src/index.ts +14 -0
- package/modules/automations-workflows-integration/src/platform.ts +24 -0
- package/modules/automations-workflows-integration/src/server/adapter.ts +272 -0
- package/modules/automations-workflows-integration/src/server/index.ts +11 -0
- package/modules/automations-workflows-integration/src/server/tools.ts +0 -0
- package/modules/automations-workflows-integration/translations/en.json +21 -0
- package/modules/automations-workflows-integration/translations/pl.json +21 -0
- package/modules/profile/migrations/0001_profile_core.down.sql +1 -0
- package/modules/profile/migrations/0001_profile_core.up.sql +13 -0
- package/modules/profile/migrations/0002_profile_language.down.sql +1 -0
- package/modules/profile/migrations/0002_profile_language.up.sql +12 -0
- package/modules/profile/migrations/README.md +3 -0
- package/modules/profile/module.json +23 -0
- package/modules/profile/package.json +55 -0
- package/modules/profile/spec/module.yaml +136 -0
- package/modules/profile/src/acl/permissions.ts +5 -0
- package/modules/profile/src/api/endpoints.ts +184 -0
- package/modules/profile/src/client/DisplayNameCard.tsrx +59 -0
- package/modules/profile/src/client/LanguageCard.tsrx +89 -0
- package/modules/profile/src/client/PasswordCard.tsrx +79 -0
- package/modules/profile/src/client/ProfileView.tsrx +192 -0
- package/modules/profile/src/client/SessionsCard.tsrx +158 -0
- package/modules/profile/src/client/api.ts +134 -0
- package/modules/profile/src/client/contribution.tsrx +61 -0
- package/modules/profile/src/client/index.ts +15 -0
- package/modules/profile/src/client/password.ts +41 -0
- package/modules/profile/src/client/sessions-api.ts +52 -0
- package/modules/profile/src/client/state.ts +23 -0
- package/modules/profile/src/domain/types.ts +21 -0
- package/modules/profile/src/index.ts +21 -0
- package/modules/profile/src/platform.ts +23 -0
- package/modules/profile/src/server/index.ts +7 -0
- package/modules/profile/src/server/runtime.ts +84 -0
- package/modules/profile/src/services/database-repository.ts +154 -0
- package/modules/profile/src/services/index.ts +6 -0
- package/modules/profile/src/services/migration.ts +58 -0
- package/modules/profile/src/services/profile-service.ts +114 -0
- package/modules/profile/src/services/repository.ts +13 -0
- package/modules/profile/translations/en.json +58 -0
- package/modules/profile/translations/pl.json +58 -0
- package/modules/sandbox/migrations/0001_sandbox_core.down.sql +6 -0
- package/modules/sandbox/migrations/0001_sandbox_core.up.sql +70 -0
- package/modules/sandbox/migrations/0002_sandbox_session_lifecycle.down.sql +36 -0
- package/modules/sandbox/migrations/0002_sandbox_session_lifecycle.up.sql +37 -0
- package/modules/sandbox/migrations/README.md +7 -0
- package/modules/sandbox/module.json +31 -0
- package/modules/sandbox/package.json +56 -0
- package/modules/sandbox/spec/module.yaml +111 -0
- package/modules/sandbox/src/acl/permissions.ts +18 -0
- package/modules/sandbox/src/api/endpoints.ts +439 -0
- package/modules/sandbox/src/cli/commands.json +84 -0
- package/modules/sandbox/src/cli/index.ts +450 -0
- package/modules/sandbox/src/client/SandboxAccessView.tsrx +191 -0
- package/modules/sandbox/src/client/SandboxGrantForm.tsrx +134 -0
- package/modules/sandbox/src/client/SandboxGrantList.tsrx +83 -0
- package/modules/sandbox/src/client/SandboxSessionList.tsrx +56 -0
- package/modules/sandbox/src/client/api.ts +87 -0
- package/modules/sandbox/src/client/contribution.tsrx +47 -0
- package/modules/sandbox/src/client/index.ts +18 -0
- package/modules/sandbox/src/client/presentation.ts +47 -0
- package/modules/sandbox/src/client/state.ts +20 -0
- package/modules/sandbox/src/domain/types.ts +125 -0
- package/modules/sandbox/src/index.ts +33 -0
- package/modules/sandbox/src/platform.ts +28 -0
- package/modules/sandbox/src/server/index.ts +20 -0
- package/modules/sandbox/src/server/runtime.ts +119 -0
- package/modules/sandbox/src/services/database-repository.ts +567 -0
- package/modules/sandbox/src/services/directory.ts +33 -0
- package/modules/sandbox/src/services/index.ts +19 -0
- package/modules/sandbox/src/services/migration.ts +145 -0
- package/modules/sandbox/src/services/repository.ts +55 -0
- package/modules/sandbox/src/services/sandbox-service-error.ts +10 -0
- package/modules/sandbox/src/services/sandbox-service.ts +533 -0
- package/modules/sandbox/translations/en.json +77 -0
- package/modules/sandbox/translations/pl.json +77 -0
- package/modules/system/module.json +18 -0
- package/modules/system/package.json +56 -0
- package/modules/system/spec/module.yaml +104 -0
- package/modules/system/src/acl/permissions.ts +10 -0
- package/modules/system/src/client/ModuleSettingRow.tsrx +191 -0
- package/modules/system/src/client/ModuleSettingsSection.tsrx +155 -0
- package/modules/system/src/client/ModulesView.tsrx +241 -0
- package/modules/system/src/client/api.ts +36 -0
- package/modules/system/src/client/contribution.tsrx +48 -0
- package/modules/system/src/client/index.ts +26 -0
- package/modules/system/src/client/module-columns.tsrx +66 -0
- package/modules/system/src/client/overview-api.ts +30 -0
- package/modules/system/src/client/setting-copy.ts +30 -0
- package/modules/system/src/client/settings-api.ts +57 -0
- package/modules/system/src/client/state.ts +16 -0
- package/modules/system/src/index.ts +11 -0
- package/modules/system/src/platform.ts +11 -0
- package/modules/system/src/server/endpoints.ts +372 -0
- package/modules/system/src/server/index.ts +11 -0
- package/modules/system/src/server/module-catalog.ts +117 -0
- package/modules/system/translations/en.json +64 -0
- package/modules/system/translations/pl.json +64 -0
- package/modules/users/migrations/README.md +3 -0
- package/modules/users/module.json +27 -0
- package/modules/users/package.json +54 -0
- package/modules/users/spec/module.yaml +79 -0
- package/modules/users/src/acl/permissions.ts +6 -0
- package/modules/users/src/api/endpoints.ts +222 -0
- package/modules/users/src/client/InviteMemberForm.tsrx +62 -0
- package/modules/users/src/client/MemberDrawer.tsrx +298 -0
- package/modules/users/src/client/RoleForm.tsrx +140 -0
- package/modules/users/src/client/RolesView.tsrx +288 -0
- package/modules/users/src/client/UserAccountForm.tsrx +86 -0
- package/modules/users/src/client/UsersView.tsrx +486 -0
- package/modules/users/src/client/api.ts +172 -0
- package/modules/users/src/client/contribution.tsrx +92 -0
- package/modules/users/src/client/index.ts +19 -0
- package/modules/users/src/client/member-columns.tsrx +52 -0
- package/modules/users/src/client/roles-api.ts +90 -0
- package/modules/users/src/client/state.ts +42 -0
- package/modules/users/src/index.ts +27 -0
- package/modules/users/src/platform.ts +11 -0
- package/modules/users/src/services/index.ts +2 -0
- package/modules/users/src/services/users-service.ts +142 -0
- package/modules/users/translations/en.json +133 -0
- package/modules/users/translations/pl.json +133 -0
- package/modules/workflows/migrations/0001_workflows_core.down.sql +19 -0
- package/modules/workflows/migrations/0001_workflows_core.up.sql +228 -0
- package/modules/workflows/migrations/0002_workflows_authorization_subject.down.sql +1 -0
- package/modules/workflows/migrations/0002_workflows_authorization_subject.up.sql +9 -0
- package/modules/workflows/migrations/0003_workflows_worker_role.up.sql +34 -0
- package/modules/workflows/migrations/README.md +7 -0
- package/modules/workflows/module.json +31 -0
- package/modules/workflows/package.json +55 -0
- package/modules/workflows/spec/module.yaml +227 -0
- package/modules/workflows/src/acl/permissions.ts +10 -0
- package/modules/workflows/src/api/endpoints.ts +852 -0
- package/modules/workflows/src/client/WorkflowCanvas.tsrx +819 -0
- package/modules/workflows/src/client/WorkflowCreateForm.tsrx +111 -0
- package/modules/workflows/src/client/WorkflowEditor.tsrx +443 -0
- package/modules/workflows/src/client/WorkflowExecutionHistory.tsrx +169 -0
- package/modules/workflows/src/client/WorkflowFixtureDrawer.tsrx +206 -0
- package/modules/workflows/src/client/WorkflowInputForm.tsrx +125 -0
- package/modules/workflows/src/client/WorkflowInputSchemaEditor.tsrx +185 -0
- package/modules/workflows/src/client/WorkflowInspector.tsrx +471 -0
- package/modules/workflows/src/client/WorkflowLiveConfirmation.tsrx +67 -0
- package/modules/workflows/src/client/WorkflowMappingEditor.tsrx +283 -0
- package/modules/workflows/src/client/WorkflowNodePalette.tsrx +50 -0
- package/modules/workflows/src/client/WorkflowPointerField.tsrx +178 -0
- package/modules/workflows/src/client/WorkflowRevisionReview.tsrx +49 -0
- package/modules/workflows/src/client/WorkflowRunInspector.tsrx +143 -0
- package/modules/workflows/src/client/WorkflowTestPanel.tsrx +109 -0
- package/modules/workflows/src/client/WorkflowValidationPanel.tsrx +139 -0
- package/modules/workflows/src/client/WorkflowsView.tsrx +1060 -0
- package/modules/workflows/src/client/api.ts +312 -0
- package/modules/workflows/src/client/canvas-model.ts +472 -0
- package/modules/workflows/src/client/connected-node.ts +71 -0
- package/modules/workflows/src/client/contribution.tsrx +57 -0
- package/modules/workflows/src/client/create-model.ts +15 -0
- package/modules/workflows/src/client/draft-repair.ts +86 -0
- package/modules/workflows/src/client/index.ts +19 -0
- package/modules/workflows/src/client/input-model.ts +124 -0
- package/modules/workflows/src/client/mapping-model.ts +110 -0
- package/modules/workflows/src/client/pointer-model.ts +123 -0
- package/modules/workflows/src/client/presentation.ts +62 -0
- package/modules/workflows/src/client/run-actions.ts +19 -0
- package/modules/workflows/src/client/state.ts +57 -0
- package/modules/workflows/src/client/viewport.ts +107 -0
- package/modules/workflows/src/client/workflows.css +899 -0
- package/modules/workflows/src/domain/events.ts +399 -0
- package/modules/workflows/src/domain/graph.ts +1136 -0
- package/modules/workflows/src/domain/types.ts +563 -0
- package/modules/workflows/src/index.ts +27 -0
- package/modules/workflows/src/platform.ts +49 -0
- package/modules/workflows/src/server/index.ts +13 -0
- package/modules/workflows/src/server/runtime.ts +266 -0
- package/modules/workflows/src/services/cursor-codec.ts +62 -0
- package/modules/workflows/src/services/database-repository.ts +2407 -0
- package/modules/workflows/src/services/index.ts +6 -0
- package/modules/workflows/src/services/migration.ts +375 -0
- package/modules/workflows/src/services/payload-codec.ts +264 -0
- package/modules/workflows/src/services/repository.ts +285 -0
- package/modules/workflows/src/services/simulation.ts +359 -0
- package/modules/workflows/src/services/worker.ts +1196 -0
- package/modules/workflows/src/services/workflows-service.ts +1395 -0
- package/modules/workflows/translations/en.json +348 -0
- package/modules/workflows/translations/pl.json +348 -0
- package/modules.json +41 -0
- package/package.json +125 -0
- package/packages/ai-provider/package.json +46 -0
- package/packages/ai-provider/src/catalog.ts +102 -0
- package/packages/ai-provider/src/errors.ts +110 -0
- package/packages/ai-provider/src/index.ts +33 -0
- package/packages/ai-provider/src/model.ts +198 -0
- package/packages/ai-provider/src/pricing.ts +73 -0
- package/packages/cli-protocol/package.json +40 -0
- package/packages/cli-protocol/src/index.ts +113 -0
- package/packages/client/package.json +46 -0
- package/packages/client/src/ApplicationShell.tsrx +374 -0
- package/packages/client/src/contributions.ts +172 -0
- package/packages/client/src/i18n/index.ts +30 -0
- package/packages/client/src/i18n/locale.ts +25 -0
- package/packages/client/src/i18n/locales/en.json +66 -0
- package/packages/client/src/i18n/locales/pl.json +66 -0
- package/packages/client/src/i18n/runtime.ts +201 -0
- package/packages/client/src/i18n/translations.ts +88 -0
- package/packages/client/src/index.ts +55 -0
- package/packages/client/src/routing.ts +9 -0
- package/packages/client/src/shell/BrandMark.tsrx +10 -0
- package/packages/client/src/shell/CommandPalette.tsrx +79 -0
- package/packages/client/src/shell/ContributionOutlets.tsrx +31 -0
- package/packages/client/src/shell/DashboardView.tsrx +60 -0
- package/packages/client/src/shell/MobileHeader.tsrx +24 -0
- package/packages/client/src/shell/OrganizationSwitcher.tsrx +100 -0
- package/packages/client/src/shell/OverviewCharts.tsrx +167 -0
- package/packages/client/src/shell/PrimaryNavigation.tsrx +75 -0
- package/packages/client/src/shell/Sidebar.tsrx +76 -0
- package/packages/client/src/shell/Topbar.tsrx +44 -0
- package/packages/client/src/shell/UserMenu.tsrx +103 -0
- package/packages/client/src/shell/WorkspaceContent.tsrx +30 -0
- package/packages/client/src/shell/identity.ts +12 -0
- package/packages/client/src/shell/navigation.ts +68 -0
- package/packages/client/src/shell/shell.css +734 -0
- package/packages/client/src/shell/types.ts +29 -0
- package/packages/client/src/state.ts +63 -0
- package/packages/client/src/web.ts +39 -0
- package/packages/coding-agent/package.json +44 -0
- package/packages/coding-agent/src/drivers/byok.ts +322 -0
- package/packages/coding-agent/src/drivers/claude-code.ts +290 -0
- package/packages/coding-agent/src/drivers/codex.ts +281 -0
- package/packages/coding-agent/src/index.ts +56 -0
- package/packages/coding-agent/src/registry.ts +119 -0
- package/packages/coding-agent/src/roles/contract.ts +60 -0
- package/packages/coding-agent/src/roles/defaults.ts +134 -0
- package/packages/coding-agent/src/roles/handoff.ts +41 -0
- package/packages/coding-agent/src/roles/registry.ts +156 -0
- package/packages/coding-agent/src/roles/skills.ts +72 -0
- package/packages/coding-agent/src/roles/sync.ts +88 -0
- package/packages/coding-agent/src/types.ts +102 -0
- package/packages/coding-agent/src/workspace.ts +275 -0
- package/packages/contracts/package.json +38 -0
- package/packages/contracts/schemas/blueprint.schema.json +48 -0
- package/packages/contracts/schemas/cli-extension.schema.json +90 -0
- package/packages/contracts/schemas/module-artifact.schema.json +82 -0
- package/packages/contracts/schemas/module-catalog.schema.json +48 -0
- package/packages/contracts/schemas/module-spec.schema.json +111 -0
- package/packages/contracts/schemas/module.schema.json +156 -0
- package/packages/contracts/schemas/platform-spec.schema.json +17 -0
- package/packages/contracts/schemas/project.schema.json +270 -0
- package/packages/contracts/src/index.ts +191 -0
- package/packages/contracts/src/module-distribution.ts +47 -0
- package/packages/contracts/src/schemas.ts +18 -0
- package/packages/contracts/src/variables.ts +156 -0
- package/packages/contracts/src/web.ts +60 -0
- package/packages/database/package.json +43 -0
- package/packages/database/src/contracts.ts +399 -0
- package/packages/database/src/index.ts +112 -0
- package/packages/database/src/migrations.ts +444 -0
- package/packages/database/src/postgresql.ts +517 -0
- package/packages/database/src/provider.ts +639 -0
- package/packages/database/src/record-history.ts +201 -0
- package/packages/database/src/registry.ts +265 -0
- package/packages/database/src/reset.ts +87 -0
- package/packages/database-pglite/package.json +42 -0
- package/packages/database-pglite/src/driver.ts +168 -0
- package/packages/database-pglite/src/index.ts +2 -0
- package/packages/database-testing/package.json +44 -0
- package/packages/database-testing/src/index.ts +8 -0
- package/packages/database-testing/src/pglite.ts +124 -0
- package/packages/database-testing/src/postgres.ts +184 -0
- package/packages/database-testing/src/provider.ts +43 -0
- package/packages/database-testing/src/vitest-preset.ts +23 -0
- package/packages/dev-console/README.md +6 -0
- package/packages/dev-console/package.json +38 -0
- package/packages/dev-console/src/index.mjs +220 -0
- package/packages/harness/package.json +47 -0
- package/packages/harness/schemas/task-packet.schema.json +48 -0
- package/packages/harness/src/catalog.ts +24 -0
- package/packages/harness/src/errors.ts +9 -0
- package/packages/harness/src/index.ts +53 -0
- package/packages/harness/src/preamble.ts +31 -0
- package/packages/harness/src/runtime.ts +833 -0
- package/packages/harness/src/task-packet.ts +86 -0
- package/packages/harness/src/tool-adapters.ts +106 -0
- package/packages/harness/src/tool-contract.ts +242 -0
- package/packages/harness/src/vercel-ai-provider.ts +198 -0
- package/packages/kernel/package.json +44 -0
- package/packages/kernel/src/acl.ts +20 -0
- package/packages/kernel/src/actor.ts +139 -0
- package/packages/kernel/src/agent-registry.ts +81 -0
- package/packages/kernel/src/capability-registry.ts +28 -0
- package/packages/kernel/src/errors.ts +9 -0
- package/packages/kernel/src/index.ts +90 -0
- package/packages/kernel/src/legacy-local-state.ts +103 -0
- package/packages/kernel/src/module-compatibility.ts +70 -0
- package/packages/kernel/src/module-registry.ts +124 -0
- package/packages/kernel/src/module-settings.ts +403 -0
- package/packages/kernel/src/record-history.ts +146 -0
- package/packages/kernel/src/runtime-config.ts +51 -0
- package/packages/kernel/src/tool-registry.ts +25 -0
- package/packages/kernel/src/variable-registry.ts +339 -0
- package/packages/sandbox/README.md +691 -0
- package/packages/sandbox/bin/flowdular-sandbox.mjs +393 -0
- package/packages/sandbox/dist/client/assets/App-ClMOrpyg.js +11 -0
- package/packages/sandbox/dist/client/assets/PreviewHost-BHiHrfbQ.js +1 -0
- package/packages/sandbox/dist/client/assets/auto-buGEq6de.js +3 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/index-CvwhlQ87.js +4 -0
- package/packages/sandbox/dist/client/assets/styles-BPWaGf55.js +3 -0
- package/packages/sandbox/dist/client/assets/styles-Dx1_KOag.css +1 -0
- package/packages/sandbox/dist/client/favicon.svg +1 -0
- package/packages/sandbox/dist/server/assets/auto-CVGNYyb3.js +12785 -0
- package/packages/sandbox/dist/server/assets/chunk-DDJLRBDX-3OUNo51g.js +4125 -0
- package/packages/sandbox/dist/server/assets/nodefs-DVSI7kG0.js +24 -0
- package/packages/sandbox/dist/server/assets/opfs-ahp-D56iokt1.js +388 -0
- package/packages/sandbox/dist/server/assets/token-Bvaq7Anz.js +55 -0
- package/packages/sandbox/dist/server/assets/token-util-BqSvdIPQ.js +3 -0
- package/packages/sandbox/dist/server/assets/token-util-CktFFT4z.js +494 -0
- package/packages/sandbox/dist/server/entry.js +91671 -0
- package/packages/sandbox/dist/server/favicon.svg +1 -0
- package/packages/sandbox/dist/server/index.html +161 -0
- package/packages/sandbox/index.html +159 -0
- package/packages/sandbox/octane.config.ts +36 -0
- package/packages/sandbox/package.json +83 -0
- package/packages/sandbox/public/favicon.svg +1 -0
- package/packages/sandbox/public/og.png +0 -0
- package/packages/sandbox/src/App.tsrx +924 -0
- package/packages/sandbox/src/client/ApprovalHandoff.tsrx +39 -0
- package/packages/sandbox/src/client/ChatPane.tsrx +694 -0
- package/packages/sandbox/src/client/ConnectView.tsrx +86 -0
- package/packages/sandbox/src/client/DiffPane.tsrx +150 -0
- package/packages/sandbox/src/client/EjectModal.tsrx +571 -0
- package/packages/sandbox/src/client/GateResults.tsrx +60 -0
- package/packages/sandbox/src/client/GitHubSettingsModal.tsrx +219 -0
- package/packages/sandbox/src/client/NewSessionForm.tsrx +214 -0
- package/packages/sandbox/src/client/SessionBar.tsrx +151 -0
- package/packages/sandbox/src/client/SessionPicker.tsrx +472 -0
- package/packages/sandbox/src/client/SpecEditor.tsrx +109 -0
- package/packages/sandbox/src/client/SpecReviewCard.tsrx +321 -0
- package/packages/sandbox/src/client/WorkCard.tsrx +128 -0
- package/packages/sandbox/src/client/WorkbenchModal.tsrx +161 -0
- package/packages/sandbox/src/client/WorkspaceMenu.tsrx +100 -0
- package/packages/sandbox/src/client/api.ts +797 -0
- package/packages/sandbox/src/client/attachments.ts +73 -0
- package/packages/sandbox/src/client/dashboard.ts +46 -0
- package/packages/sandbox/src/client/github-settings.ts +48 -0
- package/packages/sandbox/src/client/highlight.ts +105 -0
- package/packages/sandbox/src/client/i18n.ts +32 -0
- package/packages/sandbox/src/client/locales/en.json +466 -0
- package/packages/sandbox/src/client/locales/pl.json +466 -0
- package/packages/sandbox/src/client/session-labels.ts +77 -0
- package/packages/sandbox/src/client/state.ts +108 -0
- package/packages/sandbox/src/index.ts +10 -0
- package/packages/sandbox/src/preview/PreviewHost.tsrx +373 -0
- package/packages/sandbox/src/preview/load-module.ts +16 -0
- package/packages/sandbox/src/server/attachments.ts +308 -0
- package/packages/sandbox/src/server/auto-review.ts +181 -0
- package/packages/sandbox/src/server/checkpoints.ts +90 -0
- package/packages/sandbox/src/server/config.ts +460 -0
- package/packages/sandbox/src/server/dashboard.ts +245 -0
- package/packages/sandbox/src/server/delivery/configuration.ts +193 -0
- package/packages/sandbox/src/server/delivery/git-pr.ts +1473 -0
- package/packages/sandbox/src/server/delivery/index.ts +83 -0
- package/packages/sandbox/src/server/delivery/local.ts +151 -0
- package/packages/sandbox/src/server/delivery/official-modules.ts +516 -0
- package/packages/sandbox/src/server/delivery/plan.ts +218 -0
- package/packages/sandbox/src/server/delivery/policies.ts +239 -0
- package/packages/sandbox/src/server/delivery/record.ts +41 -0
- package/packages/sandbox/src/server/delivery/steps.ts +464 -0
- package/packages/sandbox/src/server/delivery/types.ts +158 -0
- package/packages/sandbox/src/server/dependencies.ts +88 -0
- package/packages/sandbox/src/server/diff.ts +230 -0
- package/packages/sandbox/src/server/gates.ts +388 -0
- package/packages/sandbox/src/server/index.ts +139 -0
- package/packages/sandbox/src/server/path-guard.ts +282 -0
- package/packages/sandbox/src/server/planning.ts +749 -0
- package/packages/sandbox/src/server/platform-client.ts +189 -0
- package/packages/sandbox/src/server/preview-database-host.ts +340 -0
- package/packages/sandbox/src/server/preview-database-protocol.ts +163 -0
- package/packages/sandbox/src/server/preview-database-proxy.ts +356 -0
- package/packages/sandbox/src/server/preview-database.ts +109 -0
- package/packages/sandbox/src/server/preview-ipc.ts +15 -0
- package/packages/sandbox/src/server/preview-modules.ts +83 -0
- package/packages/sandbox/src/server/preview-revision.ts +44 -0
- package/packages/sandbox/src/server/preview-runtime.ts +467 -0
- package/packages/sandbox/src/server/preview-worker-manager.ts +436 -0
- package/packages/sandbox/src/server/preview-worker.ts +168 -0
- package/packages/sandbox/src/server/reference.ts +251 -0
- package/packages/sandbox/src/server/routes.ts +2258 -0
- package/packages/sandbox/src/server/runtime.ts +188 -0
- package/packages/sandbox/src/server/session-owner.ts +23 -0
- package/packages/sandbox/src/server/sessions.ts +849 -0
- package/packages/sandbox/src/server/spec.ts +471 -0
- package/packages/sandbox/src/server/turn-lifecycle.ts +56 -0
- package/packages/sandbox/src/server/turns.ts +993 -0
- package/packages/sandbox/src/server/workspace-install.ts +266 -0
- package/packages/sandbox/src/server/workspace-root.ts +73 -0
- package/packages/sandbox/src/styles.css +1573 -0
- package/packages/sandbox/vite.config.ts +133 -0
- package/packages/server/package.json +43 -0
- package/packages/server/src/application-routes.ts +21 -0
- package/packages/server/src/composition.ts +48 -0
- package/packages/server/src/endpoint.ts +142 -0
- package/packages/server/src/http.ts +128 -0
- package/packages/server/src/index.ts +46 -0
- package/packages/server/src/response-lifetime.ts +56 -0
- package/packages/server/src/security-headers.ts +130 -0
- package/packages/server/src/web-html.ts +55 -0
- package/packages/server/src/web.ts +361 -0
- package/packages/ui/package.json +46 -0
- package/packages/ui/src/brand/BrandMark.tsrx +66 -0
- package/packages/ui/src/brand/mark.ts +44 -0
- package/packages/ui/src/components/Alert.tsrx +17 -0
- package/packages/ui/src/components/Avatar.tsrx +18 -0
- package/packages/ui/src/components/Button.tsrx +29 -0
- package/packages/ui/src/components/Chart.tsrx +274 -0
- package/packages/ui/src/components/CheckGrid.tsrx +93 -0
- package/packages/ui/src/components/ConfirmDialog.tsrx +63 -0
- package/packages/ui/src/components/Drawer.tsrx +71 -0
- package/packages/ui/src/components/EmptyState.tsrx +26 -0
- package/packages/ui/src/components/Filters.tsrx +39 -0
- package/packages/ui/src/components/FormField.tsrx +27 -0
- package/packages/ui/src/components/Kpi.tsrx +36 -0
- package/packages/ui/src/components/PageHeader.tsrx +26 -0
- package/packages/ui/src/components/ScopeSummary.tsrx +76 -0
- package/packages/ui/src/components/SearchField.tsrx +24 -0
- package/packages/ui/src/components/SettingRow.tsrx +50 -0
- package/packages/ui/src/components/Switch.tsrx +21 -0
- package/packages/ui/src/components/Table.tsrx +267 -0
- package/packages/ui/src/components/TableCard.tsrx +52 -0
- package/packages/ui/src/components/Tag.tsrx +28 -0
- package/packages/ui/src/components/VariableField.tsrx +284 -0
- package/packages/ui/src/components/VariableInput.tsrx +7 -0
- package/packages/ui/src/components/VariableSelect.tsrx +72 -0
- package/packages/ui/src/components/VariableTextarea.tsrx +9 -0
- package/packages/ui/src/components/variable-field.ts +61 -0
- package/packages/ui/src/components/variable-select.ts +69 -0
- package/packages/ui/src/icons/Icon.tsrx +56 -0
- package/packages/ui/src/index.ts +81 -0
- package/packages/ui/src/initials.ts +10 -0
- package/packages/ui/src/styles/base.css +71 -0
- package/packages/ui/src/styles/components.css +1859 -0
- package/packages/ui/src/styles/index.css +3 -0
- package/packages/ui/src/styles/tokens.css +124 -0
- package/tsconfig.base.json +18 -0
|
@@ -0,0 +1,893 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHash,
|
|
3
|
+
createHmac,
|
|
4
|
+
randomBytes,
|
|
5
|
+
timingSafeEqual,
|
|
6
|
+
} from 'node:crypto';
|
|
7
|
+
import { ServerRoute, type Context } from '@octanejs/app-core';
|
|
8
|
+
import { readJsonObject } from '@flowdular/sdk/server';
|
|
9
|
+
import { BUNDLED_MODULE_SCOPES, PLATFORM_SCOPES } from '../acl/scopes.ts';
|
|
10
|
+
import type { SignInInput, SignUpInput } from '../domain/types.ts';
|
|
11
|
+
import { AttemptLimiter } from '../api/attempt-limiter.ts';
|
|
12
|
+
import { clientAddress } from '../api/client-address.ts';
|
|
13
|
+
import {
|
|
14
|
+
expiredSessionCookie,
|
|
15
|
+
readCookie,
|
|
16
|
+
sessionCookie,
|
|
17
|
+
} from '../api/cookies.ts';
|
|
18
|
+
import { assertSameOrigin } from '../api/origin.ts';
|
|
19
|
+
import { sessionFromContext } from '../middleware/authentication.ts';
|
|
20
|
+
import { AuthServiceError } from '../services/auth-service-error.ts';
|
|
21
|
+
import { normalizeEmail } from '../services/validation.ts';
|
|
22
|
+
import { createAuditRoutes } from './audit-endpoints.ts';
|
|
23
|
+
import {
|
|
24
|
+
actorOf,
|
|
25
|
+
errorResponse,
|
|
26
|
+
requireScope,
|
|
27
|
+
requireSession,
|
|
28
|
+
response,
|
|
29
|
+
sessionPayload,
|
|
30
|
+
stringField,
|
|
31
|
+
} from './http.ts';
|
|
32
|
+
import { createRoleRoutes } from './roles-endpoints.ts';
|
|
33
|
+
import type { AuthRuntime, OidcProvider } from './runtime.ts';
|
|
34
|
+
import { sessionMutationDenial } from './session-security.ts';
|
|
35
|
+
import { createSessionRoutes } from './session-endpoints.ts';
|
|
36
|
+
import { createApiTokenRoutes } from './token-endpoints.ts';
|
|
37
|
+
|
|
38
|
+
/* Credential guessing is throttled per submitted address and, when a trusted
|
|
39
|
+
proxy reports it, per client address. The account lockout in the service
|
|
40
|
+
is the durable second line. */
|
|
41
|
+
const emailAttempts = new AttemptLimiter();
|
|
42
|
+
const addressAttempts = new AttemptLimiter(20, 5 * 60 * 1000);
|
|
43
|
+
const availabilityAttempts = new AttemptLimiter(60, 60_000);
|
|
44
|
+
const passwordResetEmailAttempts = new AttemptLimiter(3, 15 * 60 * 1000);
|
|
45
|
+
const passwordResetAddressAttempts = new AttemptLimiter(20, 15 * 60 * 1000);
|
|
46
|
+
const MFA_CHALLENGE_COOKIE = 'coreloom_mfa_challenge';
|
|
47
|
+
const OIDC_STATE_COOKIE = 'coreloom_oidc_state';
|
|
48
|
+
const OIDC_REQUEST_TIMEOUT_MS = 10_000;
|
|
49
|
+
const OIDC_RESPONSE_MAX_BYTES = 64 * 1024;
|
|
50
|
+
|
|
51
|
+
interface OidcState {
|
|
52
|
+
readonly provider: string;
|
|
53
|
+
readonly state: string;
|
|
54
|
+
readonly verifier: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function oidcStateCookie(value: string, secure: boolean, maxAge = 600): string {
|
|
58
|
+
return [
|
|
59
|
+
`${OIDC_STATE_COOKIE}=${encodeURIComponent(value)}`,
|
|
60
|
+
'Path=/api/auth/oidc',
|
|
61
|
+
'HttpOnly',
|
|
62
|
+
'SameSite=Lax',
|
|
63
|
+
`Max-Age=${maxAge}`,
|
|
64
|
+
maxAge === 0 ? 'Expires=Thu, 01 Jan 1970 00:00:00 GMT' : '',
|
|
65
|
+
secure ? 'Secure' : '',
|
|
66
|
+
]
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.join('; ');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function sealOidcState(value: OidcState, provider: OidcProvider): string {
|
|
72
|
+
const payload = Buffer.from(JSON.stringify(value), 'utf8').toString(
|
|
73
|
+
'base64url',
|
|
74
|
+
);
|
|
75
|
+
const signature = createHmac('sha256', provider.clientSecret)
|
|
76
|
+
.update('flowdular:oidc-state:v1\0', 'utf8')
|
|
77
|
+
.update(payload, 'utf8')
|
|
78
|
+
.digest('base64url');
|
|
79
|
+
return `${payload}.${signature}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function openOidcState(value: string, provider: OidcProvider): OidcState {
|
|
83
|
+
if (value.length > 1024) throw new Error('invalid OIDC state');
|
|
84
|
+
const parts = value.split('.');
|
|
85
|
+
if (parts.length !== 2 || !parts[0] || !parts[1])
|
|
86
|
+
throw new Error('invalid OIDC state');
|
|
87
|
+
const expected = createHmac('sha256', provider.clientSecret)
|
|
88
|
+
.update('flowdular:oidc-state:v1\0', 'utf8')
|
|
89
|
+
.update(parts[0], 'utf8')
|
|
90
|
+
.digest('base64url');
|
|
91
|
+
if (!safeEqual(parts[1], expected)) throw new Error('invalid OIDC state');
|
|
92
|
+
let parsed: unknown;
|
|
93
|
+
try {
|
|
94
|
+
parsed = JSON.parse(Buffer.from(parts[0], 'base64url').toString('utf8'));
|
|
95
|
+
} catch {
|
|
96
|
+
throw new Error('invalid OIDC state');
|
|
97
|
+
}
|
|
98
|
+
if (!parsed || typeof parsed !== 'object')
|
|
99
|
+
throw new Error('invalid OIDC state');
|
|
100
|
+
const state = parsed as Partial<OidcState>;
|
|
101
|
+
if (
|
|
102
|
+
state.provider !== provider.id ||
|
|
103
|
+
typeof state.state !== 'string' ||
|
|
104
|
+
!/^[A-Za-z0-9_-]{32}$/.test(state.state) ||
|
|
105
|
+
typeof state.verifier !== 'string' ||
|
|
106
|
+
!/^[A-Za-z0-9_-]{43}$/.test(state.verifier)
|
|
107
|
+
) {
|
|
108
|
+
throw new Error('invalid OIDC state');
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
provider: state.provider,
|
|
112
|
+
state: state.state,
|
|
113
|
+
verifier: state.verifier,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function responseWithCookies(
|
|
118
|
+
response: Response,
|
|
119
|
+
...cookies: readonly string[]
|
|
120
|
+
): Response {
|
|
121
|
+
const headers = new Headers(response.headers);
|
|
122
|
+
for (const cookie of cookies) headers.append('set-cookie', cookie);
|
|
123
|
+
return new Response(response.body, {
|
|
124
|
+
status: response.status,
|
|
125
|
+
statusText: response.statusText,
|
|
126
|
+
headers,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function oidcFailure(): AuthServiceError {
|
|
131
|
+
return new AuthServiceError(
|
|
132
|
+
'OIDC_AUTHENTICATION_FAILED',
|
|
133
|
+
'External sign-in could not be completed.',
|
|
134
|
+
401,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function readOidcJson(response: Response): Promise<unknown> {
|
|
139
|
+
const declared = Number(response.headers.get('content-length') ?? 0);
|
|
140
|
+
if (
|
|
141
|
+
(Number.isFinite(declared) && declared > OIDC_RESPONSE_MAX_BYTES) ||
|
|
142
|
+
!response.body
|
|
143
|
+
)
|
|
144
|
+
throw oidcFailure();
|
|
145
|
+
const reader = response.body.getReader();
|
|
146
|
+
const chunks: Uint8Array[] = [];
|
|
147
|
+
let total = 0;
|
|
148
|
+
try {
|
|
149
|
+
for (;;) {
|
|
150
|
+
const chunk = await reader.read();
|
|
151
|
+
if (chunk.done) break;
|
|
152
|
+
total += chunk.value.byteLength;
|
|
153
|
+
if (total > OIDC_RESPONSE_MAX_BYTES) {
|
|
154
|
+
await reader.cancel();
|
|
155
|
+
throw oidcFailure();
|
|
156
|
+
}
|
|
157
|
+
chunks.push(chunk.value);
|
|
158
|
+
}
|
|
159
|
+
return JSON.parse(Buffer.concat(chunks, total).toString('utf8')) as unknown;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (error instanceof AuthServiceError) throw error;
|
|
162
|
+
throw oidcFailure();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function mfaChallengeCookie(
|
|
167
|
+
token: string,
|
|
168
|
+
secure: boolean,
|
|
169
|
+
maxAge = 300,
|
|
170
|
+
): string {
|
|
171
|
+
return `${MFA_CHALLENGE_COOKIE}=${encodeURIComponent(token)}; Path=/api/auth/mfa/challenge; HttpOnly; SameSite=Strict; Max-Age=${maxAge}${secure ? '; Secure' : ''}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function throttle(
|
|
175
|
+
context: Context,
|
|
176
|
+
runtime: AuthRuntime,
|
|
177
|
+
email: string,
|
|
178
|
+
): { readonly address: string | null; clear(): void } {
|
|
179
|
+
const key = normalizeEmail(email);
|
|
180
|
+
const address = clientAddress(context.request, runtime.trustProxy);
|
|
181
|
+
if (
|
|
182
|
+
!emailAttempts.consume(key) ||
|
|
183
|
+
(address !== null && !addressAttempts.consume(address))
|
|
184
|
+
) {
|
|
185
|
+
throw new AuthServiceError('RATE_LIMITED', 'Try again later.', 429);
|
|
186
|
+
}
|
|
187
|
+
return { address, clear: () => emailAttempts.clear(key) };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* Reset delivery remains non-enumerating even when throttled. The response is
|
|
191
|
+
always the same accepted envelope; only the deployment mail adapter is
|
|
192
|
+
skipped after the bounded email or trusted-address allowance is exhausted. */
|
|
193
|
+
function allowPasswordResetDelivery(
|
|
194
|
+
context: Context,
|
|
195
|
+
runtime: AuthRuntime,
|
|
196
|
+
email: string,
|
|
197
|
+
): boolean {
|
|
198
|
+
const emailAllowed = passwordResetEmailAttempts.consume(
|
|
199
|
+
`reset:${normalizeEmail(email)}`,
|
|
200
|
+
);
|
|
201
|
+
const address = clientAddress(context.request, runtime.trustProxy);
|
|
202
|
+
const addressAllowed =
|
|
203
|
+
address === null ||
|
|
204
|
+
passwordResetAddressAttempts.consume(`reset-address:${address}`);
|
|
205
|
+
return emailAllowed && addressAllowed;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function safeEqual(left: string, right: string): boolean {
|
|
209
|
+
const leftBuffer = Buffer.from(left, 'utf8');
|
|
210
|
+
const rightBuffer = Buffer.from(right, 'utf8');
|
|
211
|
+
return (
|
|
212
|
+
leftBuffer.byteLength === rightBuffer.byteLength &&
|
|
213
|
+
timingSafeEqual(leftBuffer, rightBuffer)
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function createAuthRoutes(runtime: AuthRuntime): readonly ServerRoute[] {
|
|
218
|
+
const configuration = new ServerRoute({
|
|
219
|
+
path: '/api/auth/config',
|
|
220
|
+
methods: ['GET'],
|
|
221
|
+
handler: () =>
|
|
222
|
+
response({
|
|
223
|
+
allowSignUp: runtime.settings.allowSignUp,
|
|
224
|
+
emailConfirmation: runtime.settings.emailConfirmation,
|
|
225
|
+
signInProviders: runtime.settings.signInProviders.filter((id) =>
|
|
226
|
+
runtime.oidcProviders.some((provider) => provider.id === id),
|
|
227
|
+
),
|
|
228
|
+
passwordMinLength: runtime.settings.passwordMinLength,
|
|
229
|
+
}),
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const oidcStart = new ServerRoute({
|
|
233
|
+
path: '/api/auth/oidc/:provider/start',
|
|
234
|
+
methods: ['GET'],
|
|
235
|
+
handler: (context) => {
|
|
236
|
+
try {
|
|
237
|
+
const provider = runtime.oidcProviders.find(
|
|
238
|
+
(entry) => entry.id === context.params.provider,
|
|
239
|
+
);
|
|
240
|
+
if (
|
|
241
|
+
!provider ||
|
|
242
|
+
!runtime.settings.signInProviders.includes(provider.id) ||
|
|
243
|
+
!runtime.publicBaseUrl
|
|
244
|
+
)
|
|
245
|
+
throw new AuthServiceError(
|
|
246
|
+
'OIDC_NOT_CONFIGURED',
|
|
247
|
+
'This sign-in provider is not configured.',
|
|
248
|
+
404,
|
|
249
|
+
);
|
|
250
|
+
const state = randomBytes(24).toString('base64url');
|
|
251
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
252
|
+
const challenge = createHash('sha256')
|
|
253
|
+
.update(verifier)
|
|
254
|
+
.digest('base64url');
|
|
255
|
+
const callback = `${runtime.publicBaseUrl.replace(/\/$/, '')}/api/auth/oidc/${provider.id}/callback`;
|
|
256
|
+
const authorization = new URL(provider.authorizationEndpoint);
|
|
257
|
+
authorization.searchParams.set('response_type', 'code');
|
|
258
|
+
authorization.searchParams.set('client_id', provider.clientId);
|
|
259
|
+
authorization.searchParams.set('redirect_uri', callback);
|
|
260
|
+
authorization.searchParams.set('scope', 'openid email profile');
|
|
261
|
+
authorization.searchParams.set('state', state);
|
|
262
|
+
authorization.searchParams.set('code_challenge', challenge);
|
|
263
|
+
authorization.searchParams.set('code_challenge_method', 'S256');
|
|
264
|
+
return new Response(null, {
|
|
265
|
+
status: 302,
|
|
266
|
+
headers: {
|
|
267
|
+
location: authorization.toString(),
|
|
268
|
+
'set-cookie': oidcStateCookie(
|
|
269
|
+
sealOidcState(
|
|
270
|
+
{ provider: provider.id, state, verifier },
|
|
271
|
+
provider,
|
|
272
|
+
),
|
|
273
|
+
runtime.cookie.secure,
|
|
274
|
+
),
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
} catch (error) {
|
|
278
|
+
return errorResponse(error);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
const oidcCallback = new ServerRoute({
|
|
284
|
+
path: '/api/auth/oidc/:provider/callback',
|
|
285
|
+
methods: ['GET'],
|
|
286
|
+
handler: async (context) => {
|
|
287
|
+
const expiredState = oidcStateCookie('', runtime.cookie.secure, 0);
|
|
288
|
+
try {
|
|
289
|
+
const provider = runtime.oidcProviders.find(
|
|
290
|
+
(entry) => entry.id === context.params.provider,
|
|
291
|
+
);
|
|
292
|
+
const callback = runtime.publicBaseUrl
|
|
293
|
+
? `${runtime.publicBaseUrl.replace(/\/$/, '')}/api/auth/oidc/${context.params.provider}/callback`
|
|
294
|
+
: null;
|
|
295
|
+
const url = new URL(context.request.url);
|
|
296
|
+
const encoded = readCookie(context.request, OIDC_STATE_COOKIE);
|
|
297
|
+
const code = url.searchParams.get('code');
|
|
298
|
+
const submittedState = url.searchParams.get('state') ?? '';
|
|
299
|
+
if (
|
|
300
|
+
!provider ||
|
|
301
|
+
!runtime.settings.signInProviders.includes(provider.id) ||
|
|
302
|
+
!callback ||
|
|
303
|
+
!encoded ||
|
|
304
|
+
url.searchParams.get('error') ||
|
|
305
|
+
!code ||
|
|
306
|
+
code.length > 4_096 ||
|
|
307
|
+
submittedState.length > 128
|
|
308
|
+
)
|
|
309
|
+
throw oidcFailure();
|
|
310
|
+
let state: OidcState;
|
|
311
|
+
try {
|
|
312
|
+
state = openOidcState(encoded, provider);
|
|
313
|
+
} catch {
|
|
314
|
+
throw oidcFailure();
|
|
315
|
+
}
|
|
316
|
+
if (!safeEqual(state.state, submittedState)) throw oidcFailure();
|
|
317
|
+
const tokenResponse = await fetch(provider.tokenEndpoint, {
|
|
318
|
+
method: 'POST',
|
|
319
|
+
headers: {
|
|
320
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
321
|
+
accept: 'application/json',
|
|
322
|
+
},
|
|
323
|
+
body: new URLSearchParams({
|
|
324
|
+
grant_type: 'authorization_code',
|
|
325
|
+
code,
|
|
326
|
+
redirect_uri: callback,
|
|
327
|
+
client_id: provider.clientId,
|
|
328
|
+
client_secret: provider.clientSecret,
|
|
329
|
+
code_verifier: state.verifier,
|
|
330
|
+
}),
|
|
331
|
+
signal: AbortSignal.timeout(OIDC_REQUEST_TIMEOUT_MS),
|
|
332
|
+
});
|
|
333
|
+
if (!tokenResponse.ok) throw oidcFailure();
|
|
334
|
+
const tokenBody = (await readOidcJson(tokenResponse)) as {
|
|
335
|
+
access_token?: unknown;
|
|
336
|
+
};
|
|
337
|
+
if (
|
|
338
|
+
typeof tokenBody.access_token !== 'string' ||
|
|
339
|
+
tokenBody.access_token.length > 8192
|
|
340
|
+
)
|
|
341
|
+
throw oidcFailure();
|
|
342
|
+
const profileResponse = await fetch(provider.userInfoEndpoint, {
|
|
343
|
+
headers: {
|
|
344
|
+
authorization: `Bearer ${tokenBody.access_token}`,
|
|
345
|
+
accept: 'application/json',
|
|
346
|
+
},
|
|
347
|
+
signal: AbortSignal.timeout(OIDC_REQUEST_TIMEOUT_MS),
|
|
348
|
+
});
|
|
349
|
+
if (!profileResponse.ok) throw oidcFailure();
|
|
350
|
+
const profile = (await readOidcJson(profileResponse)) as {
|
|
351
|
+
email?: unknown;
|
|
352
|
+
email_verified?: unknown;
|
|
353
|
+
};
|
|
354
|
+
if (
|
|
355
|
+
typeof profile.email !== 'string' ||
|
|
356
|
+
profile.email.length > 254 ||
|
|
357
|
+
profile.email_verified !== true
|
|
358
|
+
)
|
|
359
|
+
throw oidcFailure();
|
|
360
|
+
const issued = await (
|
|
361
|
+
await runtime.service()
|
|
362
|
+
).signInVerifiedExternalEmail(profile.email);
|
|
363
|
+
if ('mfaRequired' in issued) {
|
|
364
|
+
const headers = new Headers({ location: '/auth/mfa?mfa=oidc' });
|
|
365
|
+
headers.append(
|
|
366
|
+
'set-cookie',
|
|
367
|
+
mfaChallengeCookie(issued.token, runtime.cookie.secure),
|
|
368
|
+
);
|
|
369
|
+
headers.append('set-cookie', expiredState);
|
|
370
|
+
return new Response(null, { status: 302, headers });
|
|
371
|
+
}
|
|
372
|
+
const headers = new Headers({ location: '/app' });
|
|
373
|
+
headers.append(
|
|
374
|
+
'set-cookie',
|
|
375
|
+
sessionCookie(issued.token, runtime.cookie),
|
|
376
|
+
);
|
|
377
|
+
headers.append('set-cookie', expiredState);
|
|
378
|
+
return new Response(null, { status: 302, headers });
|
|
379
|
+
} catch (error) {
|
|
380
|
+
return responseWithCookies(
|
|
381
|
+
errorResponse(
|
|
382
|
+
error instanceof AuthServiceError ? error : oidcFailure(),
|
|
383
|
+
),
|
|
384
|
+
expiredState,
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const workspaceAvailability = new ServerRoute({
|
|
391
|
+
path: '/api/auth/workspace-availability',
|
|
392
|
+
methods: ['GET'],
|
|
393
|
+
handler: async (context) => {
|
|
394
|
+
try {
|
|
395
|
+
if (!runtime.settings.allowSignUp) {
|
|
396
|
+
throw new AuthServiceError(
|
|
397
|
+
'SIGN_UP_DISABLED',
|
|
398
|
+
'Account creation is disabled for this deployment.',
|
|
399
|
+
403,
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
const agent = context.request.headers.get('user-agent') ?? 'unknown';
|
|
403
|
+
if (
|
|
404
|
+
!availabilityAttempts.consume(`availability:${agent.slice(0, 120)}`)
|
|
405
|
+
) {
|
|
406
|
+
throw new AuthServiceError('RATE_LIMITED', 'Try again later.', 429);
|
|
407
|
+
}
|
|
408
|
+
const slug =
|
|
409
|
+
new URL(context.request.url).searchParams.get('slug') ?? '';
|
|
410
|
+
return response(
|
|
411
|
+
await (await runtime.service()).checkWorkspaceSlug(slug),
|
|
412
|
+
);
|
|
413
|
+
} catch (error) {
|
|
414
|
+
return errorResponse(error);
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
const session = new ServerRoute({
|
|
420
|
+
path: '/api/auth/session',
|
|
421
|
+
methods: ['GET'],
|
|
422
|
+
/* The shell polls this route. The authentication middleware already
|
|
423
|
+
resolved the session for this request, so reading it again would be a
|
|
424
|
+
second round trip for the same answer. */
|
|
425
|
+
handler: (context) => {
|
|
426
|
+
const current = sessionFromContext(context);
|
|
427
|
+
return current
|
|
428
|
+
? response(sessionPayload(current, runtime))
|
|
429
|
+
: response(
|
|
430
|
+
{
|
|
431
|
+
error: { code: 'UNAUTHENTICATED', message: 'No active session.' },
|
|
432
|
+
},
|
|
433
|
+
401,
|
|
434
|
+
);
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
const signUp = new ServerRoute({
|
|
439
|
+
path: '/api/auth/sign-up',
|
|
440
|
+
methods: ['POST'],
|
|
441
|
+
handler: async (context) => {
|
|
442
|
+
try {
|
|
443
|
+
if (!runtime.settings.allowSignUp) {
|
|
444
|
+
throw new AuthServiceError(
|
|
445
|
+
'SIGN_UP_DISABLED',
|
|
446
|
+
'Account creation is disabled for this deployment.',
|
|
447
|
+
403,
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
assertSameOrigin(context);
|
|
451
|
+
const body = await readJsonObject(context.request);
|
|
452
|
+
const input: SignUpInput = {
|
|
453
|
+
email: stringField(body, 'email'),
|
|
454
|
+
password: stringField(body, 'password'),
|
|
455
|
+
displayName: stringField(body, 'displayName'),
|
|
456
|
+
organizationName: stringField(body, 'organizationName'),
|
|
457
|
+
organizationSlug: stringField(body, 'organizationSlug'),
|
|
458
|
+
};
|
|
459
|
+
const attempt = throttle(context, runtime, input.email);
|
|
460
|
+
const issued = await (await runtime.service()).signUp(input);
|
|
461
|
+
attempt.clear();
|
|
462
|
+
return response(sessionPayload(issued, runtime), 201, {
|
|
463
|
+
'set-cookie': sessionCookie(issued.token, runtime.cookie),
|
|
464
|
+
});
|
|
465
|
+
} catch (error) {
|
|
466
|
+
return errorResponse(error);
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
const signIn = new ServerRoute({
|
|
472
|
+
path: '/api/auth/sign-in',
|
|
473
|
+
methods: ['POST'],
|
|
474
|
+
handler: async (context) => {
|
|
475
|
+
try {
|
|
476
|
+
assertSameOrigin(context);
|
|
477
|
+
const body = await readJsonObject(context.request);
|
|
478
|
+
const input: SignInInput = {
|
|
479
|
+
email: stringField(body, 'email'),
|
|
480
|
+
password: stringField(body, 'password'),
|
|
481
|
+
};
|
|
482
|
+
const attempt = throttle(context, runtime, input.email);
|
|
483
|
+
const issued = await (
|
|
484
|
+
await runtime.service()
|
|
485
|
+
).signIn(input, { address: attempt.address });
|
|
486
|
+
attempt.clear();
|
|
487
|
+
if ('mfaRequired' in issued) {
|
|
488
|
+
return response({
|
|
489
|
+
mfaRequired: true,
|
|
490
|
+
challengeToken: issued.token,
|
|
491
|
+
expiresAt: issued.expiresAt,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
return response(sessionPayload(issued, runtime), 200, {
|
|
495
|
+
'set-cookie': sessionCookie(issued.token, runtime.cookie),
|
|
496
|
+
});
|
|
497
|
+
} catch (error) {
|
|
498
|
+
return errorResponse(error);
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
const passwordResetRequest = new ServerRoute({
|
|
504
|
+
path: '/api/auth/password-reset/request',
|
|
505
|
+
methods: ['POST'],
|
|
506
|
+
handler: async (context) => {
|
|
507
|
+
try {
|
|
508
|
+
assertSameOrigin(context);
|
|
509
|
+
const body = await readJsonObject(context.request);
|
|
510
|
+
const email = stringField(body, 'email');
|
|
511
|
+
if (email.length > 254)
|
|
512
|
+
throw new AuthServiceError(
|
|
513
|
+
'INVALID_INPUT',
|
|
514
|
+
'Enter a valid email address.',
|
|
515
|
+
400,
|
|
516
|
+
);
|
|
517
|
+
if (allowPasswordResetDelivery(context, runtime, email)) {
|
|
518
|
+
await (await runtime.service()).requestPasswordReset(email);
|
|
519
|
+
}
|
|
520
|
+
return response({ accepted: true }, 202);
|
|
521
|
+
} catch (error) {
|
|
522
|
+
return errorResponse(error);
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
const passwordResetComplete = new ServerRoute({
|
|
528
|
+
path: '/api/auth/password-reset/complete',
|
|
529
|
+
methods: ['POST'],
|
|
530
|
+
handler: async (context) => {
|
|
531
|
+
try {
|
|
532
|
+
assertSameOrigin(context);
|
|
533
|
+
const body = await readJsonObject(context.request);
|
|
534
|
+
const token = stringField(body, 'token');
|
|
535
|
+
const password = stringField(body, 'password');
|
|
536
|
+
if (token.length > 128 || password.length > 1024)
|
|
537
|
+
throw new AuthServiceError(
|
|
538
|
+
'INVALID_INPUT',
|
|
539
|
+
'The reset request is invalid.',
|
|
540
|
+
400,
|
|
541
|
+
);
|
|
542
|
+
await (await runtime.service()).completePasswordReset(token, password);
|
|
543
|
+
return response({ reset: true });
|
|
544
|
+
} catch (error) {
|
|
545
|
+
return errorResponse(error);
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
const mfaChallenge = new ServerRoute({
|
|
551
|
+
path: '/api/auth/mfa/challenge',
|
|
552
|
+
methods: ['POST'],
|
|
553
|
+
handler: async (context) => {
|
|
554
|
+
try {
|
|
555
|
+
assertSameOrigin(context);
|
|
556
|
+
const body = await readJsonObject(context.request);
|
|
557
|
+
const token =
|
|
558
|
+
typeof body.challengeToken === 'string' &&
|
|
559
|
+
body.challengeToken.length > 0
|
|
560
|
+
? body.challengeToken
|
|
561
|
+
: (readCookie(context.request, MFA_CHALLENGE_COOKIE) ?? '');
|
|
562
|
+
const code = typeof body.code === 'string' ? body.code : undefined;
|
|
563
|
+
const recoveryCode =
|
|
564
|
+
typeof body.recoveryCode === 'string' ? body.recoveryCode : undefined;
|
|
565
|
+
if (
|
|
566
|
+
token.length > 128 ||
|
|
567
|
+
(code?.length ?? 0) > 16 ||
|
|
568
|
+
(recoveryCode?.length ?? 0) > 32
|
|
569
|
+
)
|
|
570
|
+
throw new AuthServiceError(
|
|
571
|
+
'INVALID_INPUT',
|
|
572
|
+
'The authentication request is invalid.',
|
|
573
|
+
400,
|
|
574
|
+
);
|
|
575
|
+
const issued = await (
|
|
576
|
+
await runtime.service()
|
|
577
|
+
).completeMfaChallenge(token, code, recoveryCode);
|
|
578
|
+
const headers = new Headers();
|
|
579
|
+
headers.append(
|
|
580
|
+
'set-cookie',
|
|
581
|
+
sessionCookie(issued.token, runtime.cookie),
|
|
582
|
+
);
|
|
583
|
+
headers.append(
|
|
584
|
+
'set-cookie',
|
|
585
|
+
mfaChallengeCookie('', runtime.cookie.secure, 0),
|
|
586
|
+
);
|
|
587
|
+
return response(sessionPayload(issued, runtime), 200, headers);
|
|
588
|
+
} catch (error) {
|
|
589
|
+
return responseWithCookies(
|
|
590
|
+
errorResponse(error),
|
|
591
|
+
mfaChallengeCookie('', runtime.cookie.secure, 0),
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
const mfaStatus = new ServerRoute({
|
|
598
|
+
path: '/api/auth/mfa/status',
|
|
599
|
+
methods: ['GET'],
|
|
600
|
+
handler: async (context) => {
|
|
601
|
+
try {
|
|
602
|
+
const session = requireSession(context);
|
|
603
|
+
return response(
|
|
604
|
+
await (
|
|
605
|
+
await runtime.service()
|
|
606
|
+
).mfaStatus(session.principal.accountId),
|
|
607
|
+
);
|
|
608
|
+
} catch (error) {
|
|
609
|
+
return errorResponse(error);
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
const mfaEnroll = new ServerRoute({
|
|
615
|
+
path: '/api/auth/mfa/enroll',
|
|
616
|
+
methods: ['POST'],
|
|
617
|
+
handler: async (context) => {
|
|
618
|
+
const denial = sessionMutationDenial(context, runtime);
|
|
619
|
+
if (denial) return denial;
|
|
620
|
+
try {
|
|
621
|
+
const session = requireSession(context);
|
|
622
|
+
const body = await readJsonObject(context.request);
|
|
623
|
+
const issuer =
|
|
624
|
+
typeof body.issuer === 'string' && body.issuer.length <= 64
|
|
625
|
+
? body.issuer
|
|
626
|
+
: 'Flowdular';
|
|
627
|
+
return response(
|
|
628
|
+
await (
|
|
629
|
+
await runtime.service()
|
|
630
|
+
).enrollTotp(session.principal.accountId, issuer),
|
|
631
|
+
);
|
|
632
|
+
} catch (error) {
|
|
633
|
+
return errorResponse(error);
|
|
634
|
+
}
|
|
635
|
+
},
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
const mfaConfirm = new ServerRoute({
|
|
639
|
+
path: '/api/auth/mfa/confirm',
|
|
640
|
+
methods: ['POST'],
|
|
641
|
+
handler: async (context) => {
|
|
642
|
+
const denial = sessionMutationDenial(context, runtime);
|
|
643
|
+
if (denial) return denial;
|
|
644
|
+
try {
|
|
645
|
+
const session = requireSession(context);
|
|
646
|
+
const body = await readJsonObject(context.request);
|
|
647
|
+
const code = stringField(body, 'code');
|
|
648
|
+
if (code.length > 16)
|
|
649
|
+
throw new AuthServiceError(
|
|
650
|
+
'INVALID_INPUT',
|
|
651
|
+
'The authentication code is invalid.',
|
|
652
|
+
400,
|
|
653
|
+
);
|
|
654
|
+
await (
|
|
655
|
+
await runtime.service()
|
|
656
|
+
).confirmTotp(session.principal.accountId, code);
|
|
657
|
+
return response({ confirmed: true });
|
|
658
|
+
} catch (error) {
|
|
659
|
+
return errorResponse(error);
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
const createInvitation = new ServerRoute({
|
|
665
|
+
path: '/api/auth/invitations',
|
|
666
|
+
methods: ['POST'],
|
|
667
|
+
handler: async (context) => {
|
|
668
|
+
const denial = sessionMutationDenial(context, runtime);
|
|
669
|
+
if (denial) return denial;
|
|
670
|
+
try {
|
|
671
|
+
const session = requireSession(context);
|
|
672
|
+
requireScope(session, BUNDLED_MODULE_SCOPES.usersManage);
|
|
673
|
+
const body = await readJsonObject(context.request);
|
|
674
|
+
const email = stringField(body, 'email');
|
|
675
|
+
const role = stringField(body, 'role');
|
|
676
|
+
if (email.length > 254 || role.length > 32)
|
|
677
|
+
throw new AuthServiceError(
|
|
678
|
+
'INVALID_INPUT',
|
|
679
|
+
'The invitation is invalid.',
|
|
680
|
+
400,
|
|
681
|
+
);
|
|
682
|
+
return response(
|
|
683
|
+
{
|
|
684
|
+
invitation: await (
|
|
685
|
+
await runtime.service()
|
|
686
|
+
).createTenantInvitation(actorOf(session), email, role),
|
|
687
|
+
},
|
|
688
|
+
201,
|
|
689
|
+
);
|
|
690
|
+
} catch (error) {
|
|
691
|
+
return errorResponse(error);
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
const acceptInvitation = new ServerRoute({
|
|
697
|
+
path: '/api/auth/invitations/accept',
|
|
698
|
+
methods: ['POST'],
|
|
699
|
+
handler: async (context) => {
|
|
700
|
+
try {
|
|
701
|
+
assertSameOrigin(context);
|
|
702
|
+
const body = await readJsonObject(context.request);
|
|
703
|
+
const token = stringField(body, 'token');
|
|
704
|
+
const displayName = stringField(body, 'displayName');
|
|
705
|
+
const password = stringField(body, 'password');
|
|
706
|
+
if (
|
|
707
|
+
token.length > 128 ||
|
|
708
|
+
displayName.length > 80 ||
|
|
709
|
+
password.length > 1024
|
|
710
|
+
)
|
|
711
|
+
throw new AuthServiceError(
|
|
712
|
+
'INVALID_INPUT',
|
|
713
|
+
'The invitation is invalid.',
|
|
714
|
+
400,
|
|
715
|
+
);
|
|
716
|
+
await (
|
|
717
|
+
await runtime.service()
|
|
718
|
+
).acceptTenantInvitation({ token, displayName, password });
|
|
719
|
+
return response({ accepted: true });
|
|
720
|
+
} catch (error) {
|
|
721
|
+
return errorResponse(error);
|
|
722
|
+
}
|
|
723
|
+
},
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
const signOut = new ServerRoute({
|
|
727
|
+
path: '/api/auth/sign-out',
|
|
728
|
+
methods: ['POST'],
|
|
729
|
+
handler: async (context) => {
|
|
730
|
+
try {
|
|
731
|
+
assertSameOrigin(context);
|
|
732
|
+
const token = readCookie(context.request, runtime.cookie.name);
|
|
733
|
+
const service = await runtime.service();
|
|
734
|
+
const current = token ? await service.resolveSession(token) : null;
|
|
735
|
+
if (!token || !current) {
|
|
736
|
+
throw new AuthServiceError(
|
|
737
|
+
'UNAUTHENTICATED',
|
|
738
|
+
'Authentication is required.',
|
|
739
|
+
401,
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
const submitted = context.request.headers.get('x-csrf-token') ?? '';
|
|
743
|
+
if (!safeEqual(submitted, current.csrfToken)) {
|
|
744
|
+
throw new AuthServiceError(
|
|
745
|
+
'CSRF_REJECTED',
|
|
746
|
+
'CSRF token is invalid.',
|
|
747
|
+
403,
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
await service.signOut(token);
|
|
751
|
+
return response({ ok: true }, 200, {
|
|
752
|
+
'set-cookie': expiredSessionCookie(runtime.cookie),
|
|
753
|
+
});
|
|
754
|
+
} catch (error) {
|
|
755
|
+
return errorResponse(error);
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
const switchTenant = new ServerRoute({
|
|
761
|
+
path: '/api/auth/switch-tenant',
|
|
762
|
+
methods: ['POST'],
|
|
763
|
+
handler: async (context) => {
|
|
764
|
+
try {
|
|
765
|
+
assertSameOrigin(context);
|
|
766
|
+
const token = readCookie(context.request, runtime.cookie.name);
|
|
767
|
+
const service = await runtime.service();
|
|
768
|
+
const current = token ? await service.resolveSession(token) : null;
|
|
769
|
+
if (!token || !current) {
|
|
770
|
+
throw new AuthServiceError(
|
|
771
|
+
'UNAUTHENTICATED',
|
|
772
|
+
'Authentication is required.',
|
|
773
|
+
401,
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
const submitted = context.request.headers.get('x-csrf-token') ?? '';
|
|
777
|
+
if (!safeEqual(submitted, current.csrfToken)) {
|
|
778
|
+
throw new AuthServiceError(
|
|
779
|
+
'CSRF_REJECTED',
|
|
780
|
+
'CSRF token is invalid.',
|
|
781
|
+
403,
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
const body = await readJsonObject(context.request);
|
|
785
|
+
const tenantId = stringField(body, 'tenantId');
|
|
786
|
+
if (!tenantId || tenantId.length > 128) {
|
|
787
|
+
throw new AuthServiceError(
|
|
788
|
+
'INVALID_INPUT',
|
|
789
|
+
'tenantId is invalid.',
|
|
790
|
+
400,
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
const issued = await service.switchTenant(token, tenantId);
|
|
794
|
+
return response(sessionPayload(issued, runtime), 200, {
|
|
795
|
+
'set-cookie': sessionCookie(issued.token, runtime.cookie),
|
|
796
|
+
});
|
|
797
|
+
} catch (error) {
|
|
798
|
+
return errorResponse(error);
|
|
799
|
+
}
|
|
800
|
+
},
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
const changePassword = new ServerRoute({
|
|
804
|
+
path: '/api/auth/password',
|
|
805
|
+
methods: ['POST'],
|
|
806
|
+
handler: async (context) => {
|
|
807
|
+
try {
|
|
808
|
+
assertSameOrigin(context);
|
|
809
|
+
const token = readCookie(context.request, runtime.cookie.name);
|
|
810
|
+
const service = await runtime.service();
|
|
811
|
+
const session = token ? await service.resolveSession(token) : null;
|
|
812
|
+
if (!session) {
|
|
813
|
+
throw new AuthServiceError(
|
|
814
|
+
'UNAUTHENTICATED',
|
|
815
|
+
'Authentication is required.',
|
|
816
|
+
401,
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
if (
|
|
820
|
+
!safeEqual(
|
|
821
|
+
context.request.headers.get('x-csrf-token') ?? '',
|
|
822
|
+
session.csrfToken,
|
|
823
|
+
)
|
|
824
|
+
) {
|
|
825
|
+
throw new AuthServiceError(
|
|
826
|
+
'CSRF_REJECTED',
|
|
827
|
+
'CSRF token is invalid.',
|
|
828
|
+
403,
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
const body = await readJsonObject(context.request);
|
|
832
|
+
await service.changePassword({
|
|
833
|
+
accountId: session.principal.accountId,
|
|
834
|
+
currentPassword: stringField(body, 'currentPassword'),
|
|
835
|
+
newPassword: stringField(body, 'newPassword'),
|
|
836
|
+
keepSessionToken: token,
|
|
837
|
+
});
|
|
838
|
+
return response({ changed: true });
|
|
839
|
+
} catch (error) {
|
|
840
|
+
return errorResponse(error);
|
|
841
|
+
}
|
|
842
|
+
},
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
/* The workspace name is a tenant attribute, not a module setting: the
|
|
846
|
+
principal already carries it, so there is one place it lives. */
|
|
847
|
+
const renameWorkspace = new ServerRoute({
|
|
848
|
+
path: '/api/auth/workspace',
|
|
849
|
+
methods: ['POST'],
|
|
850
|
+
handler: async (context) => {
|
|
851
|
+
const denial = sessionMutationDenial(context, runtime);
|
|
852
|
+
if (denial) return denial;
|
|
853
|
+
try {
|
|
854
|
+
const session = requireSession(context);
|
|
855
|
+
requireScope(session, PLATFORM_SCOPES.settingsManage);
|
|
856
|
+
const body = await readJsonObject(context.request);
|
|
857
|
+
return response({
|
|
858
|
+
tenant: await (
|
|
859
|
+
await runtime.service()
|
|
860
|
+
).renameTenant(actorOf(session), stringField(body, 'name')),
|
|
861
|
+
});
|
|
862
|
+
} catch (error) {
|
|
863
|
+
return errorResponse(error);
|
|
864
|
+
}
|
|
865
|
+
},
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
return [
|
|
869
|
+
configuration,
|
|
870
|
+
oidcStart,
|
|
871
|
+
oidcCallback,
|
|
872
|
+
changePassword,
|
|
873
|
+
workspaceAvailability,
|
|
874
|
+
session,
|
|
875
|
+
signUp,
|
|
876
|
+
signIn,
|
|
877
|
+
passwordResetRequest,
|
|
878
|
+
passwordResetComplete,
|
|
879
|
+
mfaChallenge,
|
|
880
|
+
mfaStatus,
|
|
881
|
+
mfaEnroll,
|
|
882
|
+
mfaConfirm,
|
|
883
|
+
createInvitation,
|
|
884
|
+
acceptInvitation,
|
|
885
|
+
switchTenant,
|
|
886
|
+
signOut,
|
|
887
|
+
renameWorkspace,
|
|
888
|
+
...createApiTokenRoutes(runtime),
|
|
889
|
+
...createRoleRoutes(runtime),
|
|
890
|
+
...createAuditRoutes(runtime),
|
|
891
|
+
...createSessionRoutes(runtime),
|
|
892
|
+
];
|
|
893
|
+
}
|