@codemation/host 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/dist/CodemationConfig-XCkSV2dj.d.ts +168 -0
- package/dist/CodemationConsumerConfigLoader-Dmm2TzAA.d.ts +61 -0
- package/dist/CodemationConsumerConfigLoader-scS_RQMy.js +334 -0
- package/dist/CodemationConsumerConfigLoader-scS_RQMy.js.map +1 -0
- package/dist/CodemationFrontendBootstrapRequest-CE6DjOWJ.js +5768 -0
- package/dist/CodemationFrontendBootstrapRequest-CE6DjOWJ.js.map +1 -0
- package/dist/CodemationPluginListMerger-BNmaoXQL.js +49 -0
- package/dist/CodemationPluginListMerger-BNmaoXQL.js.map +1 -0
- package/dist/CodemationPluginListMerger-BRYqEk0y.d.ts +793 -0
- package/dist/CodemationWhitelabelConfig-DgbjgtrR.d.ts +48 -0
- package/dist/ConsoleLogger-ClPU7jtc.js +35 -0
- package/dist/ConsoleLogger-ClPU7jtc.js.map +1 -0
- package/dist/CredentialServices-BKBGe7l3.js +1030 -0
- package/dist/CredentialServices-BKBGe7l3.js.map +1 -0
- package/dist/CredentialServices-DpDpm8mL.d.ts +291 -0
- package/dist/LogLevelPolicy-4cq9z0TI.d.ts +37 -0
- package/dist/PrismaMigrationDeployer-B1E_gYz7.js +8212 -0
- package/dist/PrismaMigrationDeployer-B1E_gYz7.js.map +1 -0
- package/dist/ServerLoggerFactory-BRHxIDS7.js +340 -0
- package/dist/ServerLoggerFactory-BRHxIDS7.js.map +1 -0
- package/dist/WorkflowViewContracts-DCLpTn25.d.ts +47 -0
- package/dist/chunk-7V6ThxGB.js +39 -0
- package/dist/client-Yh7-CQud.d.ts +21995 -0
- package/dist/client.d.ts +12 -0
- package/dist/client.js +15 -0
- package/dist/client.js.map +1 -0
- package/dist/consumer.d.ts +5 -0
- package/dist/consumer.js +7 -0
- package/dist/credentials.d.ts +50 -0
- package/dist/credentials.js +11 -0
- package/dist/credentials.js.map +1 -0
- package/dist/decorate-B-N_5S4p.js +10 -0
- package/dist/decorateParam-BTcc3KNk.js +15 -0
- package/dist/devServerSidecar.d.ts +52 -0
- package/dist/devServerSidecar.js +131 -0
- package/dist/devServerSidecar.js.map +1 -0
- package/dist/index-Bs4F1IsC.d.ts +1044 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +14 -0
- package/dist/nextServer.d.ts +89 -0
- package/dist/nextServer.js +127 -0
- package/dist/nextServer.js.map +1 -0
- package/dist/persistenceServer-K5eqlZm3.d.ts +36 -0
- package/dist/persistenceServer-W9uRw0dJ.js +19 -0
- package/dist/persistenceServer-W9uRw0dJ.js.map +1 -0
- package/dist/persistenceServer.d.ts +6 -0
- package/dist/persistenceServer.js +6 -0
- package/dist/server-BBdsATju.d.ts +132 -0
- package/dist/server-BiHSuA13.js +175 -0
- package/dist/server-BiHSuA13.js.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +13 -0
- package/package.json +152 -0
- package/playwright.config.ts +74 -0
- package/prisma/migrations/20260315063514_init/migration.sql +16 -0
- package/prisma/migrations/20260316090000_workflow_debugger_overlay/migration.sql +9 -0
- package/prisma/migrations/20260317120000_trigger_state_store/migration.sql +3 -0
- package/prisma/migrations/20260317153000_trigger_setup_state/migration.sql +8 -0
- package/prisma/migrations/20260318110000_credentials_v2/migration.sql +49 -0
- package/prisma/migrations/20260319110000_credential_oauth2_material/migration.sql +28 -0
- package/prisma/migrations/20260319200000_codemation_auth_tables/migration.sql +56 -0
- package/prisma/migrations/20260320140000_user_invites_account_status/migration.sql +20 -0
- package/prisma/migrations/20260325120000_workflow_activation/migration.sql +8 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +179 -0
- package/prisma.config.ts +12 -0
- package/scripts/ensure-prisma-runtime-sourcemaps.mjs +42 -0
- package/scripts/integration-database-global-setup.mjs +30 -0
- package/src/application/ApplicationRequestError.ts +12 -0
- package/src/application/auth/AuthenticatedPrincipal.ts +5 -0
- package/src/application/auth/SessionVerifier.ts +5 -0
- package/src/application/binary/OverlayPinnedBinaryUploadService.ts +119 -0
- package/src/application/binary/RunBinaryAttachmentLookupService.ts +139 -0
- package/src/application/binary/RunStateBinaryStorageKeysCollector.ts +57 -0
- package/src/application/bus/Command.ts +3 -0
- package/src/application/bus/CommandBus.ts +5 -0
- package/src/application/bus/CommandHandler.ts +5 -0
- package/src/application/bus/DomainEvent.ts +1 -0
- package/src/application/bus/DomainEventBus.ts +5 -0
- package/src/application/bus/DomainEventHandler.ts +5 -0
- package/src/application/bus/Query.ts +3 -0
- package/src/application/bus/QueryBus.ts +5 -0
- package/src/application/bus/QueryHandler.ts +5 -0
- package/src/application/commands/AcceptUserInviteCommand.ts +10 -0
- package/src/application/commands/AcceptUserInviteCommandHandler.ts +19 -0
- package/src/application/commands/CopyRunToWorkflowDebuggerCommand.ts +14 -0
- package/src/application/commands/CopyRunToWorkflowDebuggerCommandHandler.ts +56 -0
- package/src/application/commands/CreateCredentialInstanceCommand.ts +9 -0
- package/src/application/commands/CreateCredentialInstanceCommandHandler.ts +28 -0
- package/src/application/commands/CredentialCommandHandlers.ts +10 -0
- package/src/application/commands/DeleteCredentialInstanceCommand.ts +7 -0
- package/src/application/commands/DeleteCredentialInstanceCommandHandler.ts +27 -0
- package/src/application/commands/HandleWebhookInvocationCommand.ts +12 -0
- package/src/application/commands/HandleWebhookInvocationCommandHandler.ts +42 -0
- package/src/application/commands/InviteUserCommand.ts +12 -0
- package/src/application/commands/InviteUserCommandHandler.ts +22 -0
- package/src/application/commands/RegenerateUserInviteCommand.ts +12 -0
- package/src/application/commands/RegenerateUserInviteCommandHandler.ts +24 -0
- package/src/application/commands/ReplaceMutableRunWorkflowSnapshotCommand.ts +12 -0
- package/src/application/commands/ReplaceMutableRunWorkflowSnapshotCommandHandler.ts +47 -0
- package/src/application/commands/ReplaceWorkflowDebuggerOverlayCommand.ts +14 -0
- package/src/application/commands/ReplaceWorkflowDebuggerOverlayCommandHandler.ts +35 -0
- package/src/application/commands/ReplayWorkflowNodeCommand.ts +12 -0
- package/src/application/commands/ReplayWorkflowNodeCommandHandler.ts +164 -0
- package/src/application/commands/SetPinnedNodeInputCommand.ts +13 -0
- package/src/application/commands/SetPinnedNodeInputCommandHandler.ts +50 -0
- package/src/application/commands/SetWorkflowActivationCommand.ts +10 -0
- package/src/application/commands/SetWorkflowActivationCommandHandler.ts +39 -0
- package/src/application/commands/StartWorkflowRunCommand.ts +8 -0
- package/src/application/commands/StartWorkflowRunCommandHandler.ts +286 -0
- package/src/application/commands/TestCredentialInstanceCommand.ts +9 -0
- package/src/application/commands/TestCredentialInstanceCommandHandler.ts +28 -0
- package/src/application/commands/UpdateCredentialInstanceCommand.ts +12 -0
- package/src/application/commands/UpdateCredentialInstanceCommandHandler.ts +28 -0
- package/src/application/commands/UpdateUserAccountStatusCommand.ts +12 -0
- package/src/application/commands/UpdateUserAccountStatusCommandHandler.ts +24 -0
- package/src/application/commands/UploadOverlayPinnedBinaryCommand.ts +16 -0
- package/src/application/commands/UploadOverlayPinnedBinaryCommandHandler.ts +31 -0
- package/src/application/commands/UpsertCredentialBindingCommand.ts +11 -0
- package/src/application/commands/UpsertCredentialBindingCommandHandler.ts +28 -0
- package/src/application/commands/UpsertLocalBootstrapUserCommand.ts +12 -0
- package/src/application/commands/UpsertLocalBootstrapUserCommandHandler.ts +24 -0
- package/src/application/commands/UserAccountCommandHandlers.ts +10 -0
- package/src/application/contracts/CredentialContractsRegistry.ts +88 -0
- package/src/application/contracts/RunContracts.ts +41 -0
- package/src/application/contracts/WorkflowDebuggerContracts.ts +12 -0
- package/src/application/contracts/WorkflowViewContracts.ts +40 -0
- package/src/application/contracts/WorkflowWebsocketMessage.ts +8 -0
- package/src/application/contracts/userDirectoryContracts.types.ts +60 -0
- package/src/application/dev/BootRuntimeSnapshotHolder.ts +19 -0
- package/src/application/dev/BootRuntimeSummary.types.ts +11 -0
- package/src/application/dev/DevBootstrapSummaryAssembler.ts +84 -0
- package/src/application/dev/DevBootstrapSummaryJson.types.ts +9 -0
- package/src/application/logging/LogFilter.ts +7 -0
- package/src/application/logging/Logger.ts +10 -0
- package/src/application/mapping/DataMapper.ts +3 -0
- package/src/application/mapping/WorkflowDefinitionMapper.ts +171 -0
- package/src/application/mapping/WorkflowPolicyUiPresentationFactory.ts +39 -0
- package/src/application/queries/CredentialQueryHandlers.ts +12 -0
- package/src/application/queries/GetCredentialFieldEnvStatusQuery.ts +5 -0
- package/src/application/queries/GetCredentialFieldEnvStatusQueryHandler.ts +52 -0
- package/src/application/queries/GetCredentialInstanceQuery.ts +9 -0
- package/src/application/queries/GetCredentialInstanceQueryHandler.ts +27 -0
- package/src/application/queries/GetCredentialInstanceWithSecretsQuery.ts +9 -0
- package/src/application/queries/GetCredentialInstanceWithSecretsQueryHandler.ts +27 -0
- package/src/application/queries/GetRunBinaryAttachmentQuery.ts +11 -0
- package/src/application/queries/GetRunBinaryAttachmentQueryHandler.ts +23 -0
- package/src/application/queries/GetRunStateQuery.ts +8 -0
- package/src/application/queries/GetRunStateQueryHandler.ts +21 -0
- package/src/application/queries/GetWorkflowCredentialHealthQuery.ts +9 -0
- package/src/application/queries/GetWorkflowCredentialHealthQueryHandler.ts +27 -0
- package/src/application/queries/GetWorkflowDebuggerOverlayQuery.ts +8 -0
- package/src/application/queries/GetWorkflowDebuggerOverlayQueryHandler.ts +28 -0
- package/src/application/queries/GetWorkflowDetailQuery.ts +8 -0
- package/src/application/queries/GetWorkflowDetailQueryHandler.ts +24 -0
- package/src/application/queries/GetWorkflowOverlayBinaryAttachmentQuery.ts +11 -0
- package/src/application/queries/GetWorkflowOverlayBinaryAttachmentQueryHandler.ts +23 -0
- package/src/application/queries/GetWorkflowSummariesQuery.ts +4 -0
- package/src/application/queries/GetWorkflowSummariesQueryHandler.ts +23 -0
- package/src/application/queries/ListCredentialInstancesQuery.ts +5 -0
- package/src/application/queries/ListCredentialInstancesQueryHandler.ts +27 -0
- package/src/application/queries/ListCredentialTypesQuery.ts +5 -0
- package/src/application/queries/ListCredentialTypesQueryHandler.ts +28 -0
- package/src/application/queries/ListUserAccountsQuery.ts +5 -0
- package/src/application/queries/ListUserAccountsQueryHandler.ts +22 -0
- package/src/application/queries/ListWorkflowRunsQuery.ts +8 -0
- package/src/application/queries/ListWorkflowRunsQueryHandler.ts +21 -0
- package/src/application/queries/UserAccountQueryHandlers.ts +4 -0
- package/src/application/queries/VerifyUserInviteQuery.ts +9 -0
- package/src/application/queries/VerifyUserInviteQueryHandler.ts +21 -0
- package/src/application/runs/WorkflowRunRetentionPruneScheduler.ts +98 -0
- package/src/application/websocket/WorkflowRunEventWebsocketRelay.ts +36 -0
- package/src/application/websocket/WorkflowWebsocketPublisher.ts +5 -0
- package/src/application/workflows/WebhookEndpointPathValidator.ts +35 -0
- package/src/application/workflows/WorkflowDebuggerOverlayStateFactory.ts +122 -0
- package/src/applicationTokens.ts +72 -0
- package/src/bootstrap/CodemationBootstrapRequest.ts +27 -0
- package/src/bootstrap/CodemationContainerFactory.ts +310 -0
- package/src/bootstrap/CodemationContainerRegistration.ts +23 -0
- package/src/bootstrap/CodemationContainerRegistrationRegistrar.ts +42 -0
- package/src/bootstrap/CodemationFrontendBootstrapRequest.ts +16 -0
- package/src/bootstrap/CodemationWorkerBootstrapRequest.ts +19 -0
- package/src/bootstrap/PreparedCodemationRuntime.ts +37 -0
- package/src/bootstrap/PreparedCodemationRuntimeFactory.ts +308 -0
- package/src/bootstrap/boot/CliRuntimeBootService.ts +27 -0
- package/src/bootstrap/boot/FrontendRuntimeBootService.ts +86 -0
- package/src/bootstrap/boot/WorkerRuntimeBootService.ts +64 -0
- package/src/bootstrap/runtime/AppConfigFactory.ts +57 -0
- package/src/bootstrap/runtime/ResolvedImplementationSelectionFactory.ts +118 -0
- package/src/client.ts +3 -0
- package/src/codemationApplication.ts +311 -0
- package/src/consumer.ts +4 -0
- package/src/credentials.ts +24 -0
- package/src/devServerSidecar.ts +10 -0
- package/src/domain/credentials/CredentialBindingService.ts +139 -0
- package/src/domain/credentials/CredentialFieldEnvOverlayService.ts +60 -0
- package/src/domain/credentials/CredentialInstanceService.ts +391 -0
- package/src/domain/credentials/CredentialMaterialResolver.ts +55 -0
- package/src/domain/credentials/CredentialRuntimeMaterialService.ts +39 -0
- package/src/domain/credentials/CredentialSecretCipher.ts +70 -0
- package/src/domain/credentials/CredentialServices.ts +145 -0
- package/src/domain/credentials/CredentialSessionServiceImpl.ts +119 -0
- package/src/domain/credentials/CredentialTestService.ts +73 -0
- package/src/domain/credentials/CredentialTypeRegistryImpl.ts +29 -0
- package/src/domain/credentials/OAuth2ConnectServiceFactory.ts +396 -0
- package/src/domain/credentials/OAuth2ProviderRegistry.ts +75 -0
- package/src/domain/credentials/WorkflowCredentialNodeResolver.ts +246 -0
- package/src/domain/runs/WorkflowRunRepository.ts +11 -0
- package/src/domain/users/UserAccountServiceRegistry.ts +315 -0
- package/src/domain/users/userLoginMethodLabels.types.ts +29 -0
- package/src/domain/workflows/WorkflowActivationPreflight.ts +32 -0
- package/src/domain/workflows/WorkflowActivationPreflightRules.ts +77 -0
- package/src/domain/workflows/WorkflowActivationRepository.ts +9 -0
- package/src/domain/workflows/WorkflowDebuggerOverlayRepository.ts +7 -0
- package/src/domain/workflows/WorkflowDebuggerOverlayState.ts +8 -0
- package/src/domain/workflows/WorkflowDefinitionRepository.ts +11 -0
- package/src/index.ts +58 -0
- package/src/infrastructure/auth/AuthJsSessionVerifier.ts +26 -0
- package/src/infrastructure/auth/DevelopmentSessionBypassVerifier.ts +12 -0
- package/src/infrastructure/binary/BinaryBodyNodeReadableFactory.ts +22 -0
- package/src/infrastructure/binary/CountingSha256Transform.ts +26 -0
- package/src/infrastructure/binary/LocalFilesystemBinaryStorageRegistry.ts +86 -0
- package/src/infrastructure/config/CodemationPluginRegistrar.ts +44 -0
- package/src/infrastructure/credentials/FrameworkBuiltinCredentialTypesRegistrar.ts +21 -0
- package/src/infrastructure/credentials/OpenAiApiKeyCredentialHealthTester.ts +89 -0
- package/src/infrastructure/credentials/OpenAiApiKeyCredentialShapes.types.ts +15 -0
- package/src/infrastructure/credentials/OpenAiApiKeyCredentialTypeFactory.ts +47 -0
- package/src/infrastructure/di/HandlesCommandRegistry.ts +24 -0
- package/src/infrastructure/di/HandlesDomainEventRegistry.ts +24 -0
- package/src/infrastructure/di/HandlesQueryRegistry.ts +24 -0
- package/src/infrastructure/di/InMemoryCommandBus.ts +47 -0
- package/src/infrastructure/di/InMemoryDomainEventBus.ts +47 -0
- package/src/infrastructure/di/InMemoryQueryBus.ts +45 -0
- package/src/infrastructure/ids/CodemationIdFactory.ts +12 -0
- package/src/infrastructure/logging/BrowserLogger.ts +1 -0
- package/src/infrastructure/logging/BrowserLoggerFactory.ts +14 -0
- package/src/infrastructure/logging/ConsoleLogger.ts +41 -0
- package/src/infrastructure/logging/FilteringLogger.ts +38 -0
- package/src/infrastructure/logging/LogLevelPolicy.ts +148 -0
- package/src/infrastructure/logging/LogLevelPolicyFactory.ts +16 -0
- package/src/infrastructure/logging/PerformanceLogPolicy.ts +10 -0
- package/src/infrastructure/logging/PerformanceLogPolicyFactory.ts +14 -0
- package/src/infrastructure/logging/ServerLogger.ts +1 -0
- package/src/infrastructure/logging/ServerLoggerFactory.ts +28 -0
- package/src/infrastructure/persistence/CodemationPostgresPrismaClientFactory.ts +9 -0
- package/src/infrastructure/persistence/CredentialPersistenceStore.ts +139 -0
- package/src/infrastructure/persistence/DatabasePersistenceResolver.ts +91 -0
- package/src/infrastructure/persistence/InMemoryTriggerSetupStateRepository.ts +23 -0
- package/src/infrastructure/persistence/InMemoryWorkflowActivationRepository.ts +18 -0
- package/src/infrastructure/persistence/InMemoryWorkflowDebuggerOverlayRepository.ts +16 -0
- package/src/infrastructure/persistence/InMemoryWorkflowRunRepository.ts +94 -0
- package/src/infrastructure/persistence/PrismaClientFactory.ts +26 -0
- package/src/infrastructure/persistence/PrismaCredentialStore.ts +368 -0
- package/src/infrastructure/persistence/PrismaMigrationDeployer.ts +184 -0
- package/src/infrastructure/persistence/PrismaTriggerSetupStateRepository.ts +68 -0
- package/src/infrastructure/persistence/PrismaWorkflowActivationRepository.ts +36 -0
- package/src/infrastructure/persistence/PrismaWorkflowDebuggerOverlayRepository.ts +65 -0
- package/src/infrastructure/persistence/PrismaWorkflowRunRepository.ts +243 -0
- package/src/infrastructure/persistence/RuntimeWorkflowActivationPolicy.ts +27 -0
- package/src/infrastructure/persistence/SchedulerPersistenceCompatibilityValidator.ts +20 -0
- package/src/infrastructure/persistence/WorkflowDefinitionRepositoryAdapter.ts +31 -0
- package/src/infrastructure/persistence/WorkflowRunRepository.ts +46 -0
- package/src/infrastructure/persistence/generated/prisma/client.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma/default.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma/edge.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma/index.d.ts +4766 -0
- package/src/infrastructure/persistence/generated/prisma/package.json +144 -0
- package/src/infrastructure/persistence/generated/prisma/query_compiler_fast_bg.wasm +0 -0
- package/src/infrastructure/persistence/generated/prisma/runtime/client.d.ts +3358 -0
- package/src/infrastructure/persistence/generated/prisma/runtime/index-browser.d.ts +90 -0
- package/src/infrastructure/persistence/generated/prisma/schema.prisma +35 -0
- package/src/infrastructure/persistence/generated/prisma/wasm-edge-light-loader.mjs +5 -0
- package/src/infrastructure/persistence/generated/prisma/wasm-worker-loader.mjs +5 -0
- package/src/infrastructure/persistence/generated/prisma-client/client.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/client.js +5 -0
- package/src/infrastructure/persistence/generated/prisma-client/default.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/default.js +5 -0
- package/src/infrastructure/persistence/generated/prisma-client/edge.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/edge.js +299 -0
- package/src/infrastructure/persistence/generated/prisma-client/index-browser.js +325 -0
- package/src/infrastructure/persistence/generated/prisma-client/index.d.ts +21623 -0
- package/src/infrastructure/persistence/generated/prisma-client/index.js +299 -0
- package/src/infrastructure/persistence/generated/prisma-client/package.json +144 -0
- package/src/infrastructure/persistence/generated/prisma-client/query_compiler_fast_bg.js +2 -0
- package/src/infrastructure/persistence/generated/prisma-client/query_compiler_fast_bg.wasm +0 -0
- package/src/infrastructure/persistence/generated/prisma-client/query_compiler_fast_bg.wasm-base64.js +2 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/client.d.ts +3358 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/client.js +86 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/client.js.map +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/index-browser.d.ts +90 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/index-browser.js +6 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/index-browser.js.map +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/wasm-compiler-edge.js +76 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/wasm-compiler-edge.js.map +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/schema.prisma +179 -0
- package/src/infrastructure/persistence/generated/prisma-client/wasm-edge-light-loader.mjs +5 -0
- package/src/infrastructure/persistence/generated/prisma-client/wasm-worker-loader.mjs +5 -0
- package/src/infrastructure/runtime/LiveWorkflowRepository.ts +14 -0
- package/src/infrastructure/runtime/WorkerRuntimeScheduler.ts +35 -0
- package/src/infrastructure/server/http/ServerHttpRouteParams.ts +1 -0
- package/src/infrastructure/webhooks/RequestToWebhookItemMapper.ts +128 -0
- package/src/nextServer.ts +31 -0
- package/src/persistenceServer.ts +5 -0
- package/src/presentation/config/AppConfig.ts +25 -0
- package/src/presentation/config/CodemationAppContext.ts +19 -0
- package/src/presentation/config/CodemationApplicationFacade.ts +5 -0
- package/src/presentation/config/CodemationAuthConfig.ts +31 -0
- package/src/presentation/config/CodemationClassToken.ts +3 -0
- package/src/presentation/config/CodemationConfig.ts +86 -0
- package/src/presentation/config/CodemationConfigNormalizer.ts +179 -0
- package/src/presentation/config/CodemationLogConfig.ts +22 -0
- package/src/presentation/config/CodemationPackageManifest.ts +9 -0
- package/src/presentation/config/CodemationPlugin.ts +20 -0
- package/src/presentation/config/CodemationPluginListMerger.ts +46 -0
- package/src/presentation/config/CodemationWhitelabelConfig.ts +9 -0
- package/src/presentation/config/CodemationWorkflowDiscovery.ts +3 -0
- package/src/presentation/http/ApiPaths.ts +165 -0
- package/src/presentation/http/CodemationServerGatewayFactory.ts +120 -0
- package/src/presentation/http/HttpRequestJsonBodyReader.ts +12 -0
- package/src/presentation/http/ServerHttpErrorResponseFactory.ts +33 -0
- package/src/presentation/http/ServerHttpRouteParams.ts +1 -0
- package/src/presentation/http/hono/CodemationHonoApiAppFactory.ts +64 -0
- package/src/presentation/http/hono/HonoApiRouteRegistrar.ts +5 -0
- package/src/presentation/http/hono/HonoHttpAnonymousRoutePolicyRegistry.ts +27 -0
- package/src/presentation/http/hono/registrars/BinaryHonoApiRouteRegistrar.ts +21 -0
- package/src/presentation/http/hono/registrars/CredentialHonoApiRouteRegistrar.ts +34 -0
- package/src/presentation/http/hono/registrars/DevHonoApiRouteRegistrar.ts +17 -0
- package/src/presentation/http/hono/registrars/OAuth2HonoApiRouteRegistrar.ts +18 -0
- package/src/presentation/http/hono/registrars/RunHonoApiRouteRegistrar.ts +31 -0
- package/src/presentation/http/hono/registrars/UserHonoApiRouteRegistrar.ts +24 -0
- package/src/presentation/http/hono/registrars/WebhookHonoApiRouteRegistrar.ts +23 -0
- package/src/presentation/http/hono/registrars/WhitelabelHonoApiRouteRegistrar.ts +18 -0
- package/src/presentation/http/hono/registrars/WorkflowHonoApiRouteRegistrar.ts +33 -0
- package/src/presentation/http/routeHandlers/BinaryHttpRouteHandlerFactory.ts +101 -0
- package/src/presentation/http/routeHandlers/CredentialHttpRouteHandler.ts +129 -0
- package/src/presentation/http/routeHandlers/DevBootstrapSummaryHttpRouteHandler.ts +21 -0
- package/src/presentation/http/routeHandlers/OAuth2HttpRouteHandlerFactory.ts +129 -0
- package/src/presentation/http/routeHandlers/RunHttpRouteHandler.ts +82 -0
- package/src/presentation/http/routeHandlers/UserHttpRouteHandlerFactory.ts +109 -0
- package/src/presentation/http/routeHandlers/WebhookHttpRouteHandler.ts +42 -0
- package/src/presentation/http/routeHandlers/WhitelabelLogoHttpRouteHandler.ts +96 -0
- package/src/presentation/http/routeHandlers/WorkflowHttpRouteHandler.ts +104 -0
- package/src/presentation/server/CodemationConsumerAppResolver.ts +82 -0
- package/src/presentation/server/CodemationConsumerConfigExportsResolver.ts +33 -0
- package/src/presentation/server/CodemationConsumerConfigLoader.ts +270 -0
- package/src/presentation/server/CodemationPluginDiscovery.ts +151 -0
- package/src/presentation/server/CodemationTsyringeParamInfoReader.ts +26 -0
- package/src/presentation/server/CodemationTsyringeTypeInfoRegistrar.ts +121 -0
- package/src/presentation/server/DevelopmentRuntimeRouteGuard.ts +59 -0
- package/src/presentation/server/DiscoveredWorkflowsEmptyMessageFactory.ts +11 -0
- package/src/presentation/server/WorkflowDefinitionExportsResolver.ts +24 -0
- package/src/presentation/server/WorkflowDiscoveryPathSegmentsComputer.ts +53 -0
- package/src/presentation/server/WorkflowModulePathFinder.ts +47 -0
- package/src/presentation/websocket/WorkflowWebsocketServer.ts +169 -0
- package/src/server.ts +14 -0
- package/tsconfig.json +10 -0
- package/vitest.shared.ts +45 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { BullmqScheduler } from "@codemation/queue-bullmq";
|
|
2
|
+
import type { WorkerRuntimeScheduler } from "../../infrastructure/runtime/WorkerRuntimeScheduler";
|
|
3
|
+
import type { ResolvedDatabasePersistence } from "../../infrastructure/persistence/DatabasePersistenceResolver";
|
|
4
|
+
import { DatabasePersistenceResolver } from "../../infrastructure/persistence/DatabasePersistenceResolver";
|
|
5
|
+
import { SchedulerPersistenceCompatibilityValidator } from "../../infrastructure/persistence/SchedulerPersistenceCompatibilityValidator";
|
|
6
|
+
import type {
|
|
7
|
+
CodemationApplicationRuntimeConfig,
|
|
8
|
+
CodemationEventBusKind,
|
|
9
|
+
CodemationSchedulerKind,
|
|
10
|
+
} from "../../presentation/config/CodemationConfig";
|
|
11
|
+
|
|
12
|
+
export type ResolvedImplementationSelection = Readonly<{
|
|
13
|
+
databasePersistence: ResolvedDatabasePersistence;
|
|
14
|
+
eventBusKind: CodemationEventBusKind;
|
|
15
|
+
queuePrefix: string;
|
|
16
|
+
redisUrl?: string;
|
|
17
|
+
schedulerKind: CodemationSchedulerKind;
|
|
18
|
+
workerRuntimeScheduler?: WorkerRuntimeScheduler;
|
|
19
|
+
}>;
|
|
20
|
+
|
|
21
|
+
export class ResolvedImplementationSelectionFactory {
|
|
22
|
+
constructor(
|
|
23
|
+
private readonly databasePersistenceResolver: DatabasePersistenceResolver = new DatabasePersistenceResolver(),
|
|
24
|
+
private readonly schedulerPersistenceCompatibilityValidator: SchedulerPersistenceCompatibilityValidator = new SchedulerPersistenceCompatibilityValidator(),
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
resolve(
|
|
28
|
+
args: Readonly<{
|
|
29
|
+
consumerRoot: string;
|
|
30
|
+
runtimeConfig: CodemationApplicationRuntimeConfig;
|
|
31
|
+
env: Readonly<NodeJS.ProcessEnv>;
|
|
32
|
+
}>,
|
|
33
|
+
): ResolvedImplementationSelection {
|
|
34
|
+
const databasePersistence = this.databasePersistenceResolver.resolve({
|
|
35
|
+
runtimeConfig: args.runtimeConfig,
|
|
36
|
+
env: args.env,
|
|
37
|
+
consumerRoot: args.consumerRoot,
|
|
38
|
+
});
|
|
39
|
+
const redisUrl = args.runtimeConfig.eventBus?.redisUrl ?? args.env.REDIS_URL;
|
|
40
|
+
const schedulerKind = this.resolveSchedulerKind(args.runtimeConfig, args.env, redisUrl);
|
|
41
|
+
const eventBusKind = this.resolveEventBusKind(args.runtimeConfig, args.env, schedulerKind, redisUrl);
|
|
42
|
+
const queuePrefix =
|
|
43
|
+
args.runtimeConfig.scheduler?.queuePrefix ??
|
|
44
|
+
args.runtimeConfig.eventBus?.queuePrefix ??
|
|
45
|
+
args.env.QUEUE_PREFIX ??
|
|
46
|
+
"codemation";
|
|
47
|
+
if (schedulerKind === "bullmq" && eventBusKind !== "redis") {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"BullMQ scheduling requires a Redis event bus so worker events can be forwarded to connected clients.",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (eventBusKind === "redis" && !redisUrl) {
|
|
53
|
+
throw new Error("Redis event bus requires runtime.eventBus.redisUrl or REDIS_URL.");
|
|
54
|
+
}
|
|
55
|
+
this.schedulerPersistenceCompatibilityValidator.validate({ schedulerKind, persistence: databasePersistence });
|
|
56
|
+
const workerRuntimeScheduler =
|
|
57
|
+
schedulerKind === "bullmq"
|
|
58
|
+
? new BullmqScheduler({ url: this.requireRedisUrl(redisUrl) }, queuePrefix)
|
|
59
|
+
: undefined;
|
|
60
|
+
return {
|
|
61
|
+
databasePersistence,
|
|
62
|
+
eventBusKind,
|
|
63
|
+
queuePrefix,
|
|
64
|
+
redisUrl,
|
|
65
|
+
schedulerKind,
|
|
66
|
+
workerRuntimeScheduler,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private resolveSchedulerKind(
|
|
71
|
+
runtimeConfig: CodemationApplicationRuntimeConfig,
|
|
72
|
+
env: Readonly<NodeJS.ProcessEnv>,
|
|
73
|
+
redisUrl: string | undefined,
|
|
74
|
+
): CodemationSchedulerKind {
|
|
75
|
+
const configuredKind = runtimeConfig.scheduler?.kind ?? this.readSchedulerKind(env.CODEMATION_SCHEDULER);
|
|
76
|
+
if (configuredKind) {
|
|
77
|
+
return configuredKind;
|
|
78
|
+
}
|
|
79
|
+
return redisUrl ? "bullmq" : "local";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private resolveEventBusKind(
|
|
83
|
+
runtimeConfig: CodemationApplicationRuntimeConfig,
|
|
84
|
+
env: Readonly<NodeJS.ProcessEnv>,
|
|
85
|
+
schedulerKind: CodemationSchedulerKind,
|
|
86
|
+
redisUrl: string | undefined,
|
|
87
|
+
): CodemationEventBusKind {
|
|
88
|
+
const configuredKind = runtimeConfig.eventBus?.kind ?? this.readEventBusKind(env.CODEMATION_EVENT_BUS);
|
|
89
|
+
if (configuredKind) {
|
|
90
|
+
return configuredKind;
|
|
91
|
+
}
|
|
92
|
+
if (schedulerKind === "bullmq") {
|
|
93
|
+
return "redis";
|
|
94
|
+
}
|
|
95
|
+
return redisUrl ? "redis" : "memory";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private readSchedulerKind(value: string | undefined): CodemationSchedulerKind | undefined {
|
|
99
|
+
if (value === "local" || value === "bullmq") {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private readEventBusKind(value: string | undefined): CodemationEventBusKind | undefined {
|
|
106
|
+
if (value === "memory" || value === "redis") {
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private requireRedisUrl(redisUrl: string | undefined): string {
|
|
113
|
+
if (!redisUrl) {
|
|
114
|
+
throw new Error("Redis-backed runtime requires runtime.eventBus.redisUrl or REDIS_URL.");
|
|
115
|
+
}
|
|
116
|
+
return redisUrl;
|
|
117
|
+
}
|
|
118
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
|
|
3
|
+
import type { Container, WorkflowDefinition } from "@codemation/core";
|
|
4
|
+
import { CoreTokens } from "@codemation/core";
|
|
5
|
+
import type { BootRuntimeSummary } from "./application/dev/BootRuntimeSummary.types";
|
|
6
|
+
import "./application/commands/CopyRunToWorkflowDebuggerCommandHandler";
|
|
7
|
+
import "./application/commands/CredentialCommandHandlers";
|
|
8
|
+
import "./application/commands/HandleWebhookInvocationCommandHandler";
|
|
9
|
+
import "./application/commands/ReplayWorkflowNodeCommandHandler";
|
|
10
|
+
import "./application/commands/ReplaceMutableRunWorkflowSnapshotCommandHandler";
|
|
11
|
+
import "./application/commands/ReplaceWorkflowDebuggerOverlayCommandHandler";
|
|
12
|
+
import "./application/commands/SetPinnedNodeInputCommandHandler";
|
|
13
|
+
import "./application/commands/SetWorkflowActivationCommandHandler";
|
|
14
|
+
import "./application/commands/StartWorkflowRunCommandHandler";
|
|
15
|
+
import "./application/commands/UploadOverlayPinnedBinaryCommandHandler";
|
|
16
|
+
import "./application/commands/UserAccountCommandHandlers";
|
|
17
|
+
import "./application/queries/CredentialQueryHandlers";
|
|
18
|
+
import "./application/queries/GetRunBinaryAttachmentQueryHandler";
|
|
19
|
+
import "./application/queries/GetRunStateQueryHandler";
|
|
20
|
+
import "./application/queries/GetWorkflowDebuggerOverlayQueryHandler";
|
|
21
|
+
import "./application/queries/GetWorkflowDetailQueryHandler";
|
|
22
|
+
import "./application/queries/GetWorkflowOverlayBinaryAttachmentQueryHandler";
|
|
23
|
+
import "./application/queries/GetWorkflowSummariesQueryHandler";
|
|
24
|
+
import "./application/queries/ListWorkflowRunsQueryHandler";
|
|
25
|
+
import "./application/queries/UserAccountQueryHandlers";
|
|
26
|
+
import "./application/binary/OverlayPinnedBinaryUploadService";
|
|
27
|
+
import "./presentation/http/hono/registrars/BinaryHonoApiRouteRegistrar";
|
|
28
|
+
import "./presentation/http/hono/registrars/CredentialHonoApiRouteRegistrar";
|
|
29
|
+
import "./presentation/http/hono/registrars/DevHonoApiRouteRegistrar";
|
|
30
|
+
import "./presentation/http/hono/registrars/OAuth2HonoApiRouteRegistrar";
|
|
31
|
+
import "./presentation/http/hono/registrars/RunHonoApiRouteRegistrar";
|
|
32
|
+
import "./presentation/http/hono/registrars/UserHonoApiRouteRegistrar";
|
|
33
|
+
import "./presentation/http/hono/registrars/WebhookHonoApiRouteRegistrar";
|
|
34
|
+
import "./presentation/http/hono/registrars/WhitelabelHonoApiRouteRegistrar";
|
|
35
|
+
import "./presentation/http/hono/registrars/WorkflowHonoApiRouteRegistrar";
|
|
36
|
+
import "./presentation/http/routeHandlers/BinaryHttpRouteHandlerFactory";
|
|
37
|
+
import "./presentation/http/routeHandlers/CredentialHttpRouteHandler";
|
|
38
|
+
import "./presentation/http/routeHandlers/OAuth2HttpRouteHandlerFactory";
|
|
39
|
+
import "./presentation/http/routeHandlers/RunHttpRouteHandler";
|
|
40
|
+
import "./presentation/http/routeHandlers/UserHttpRouteHandlerFactory";
|
|
41
|
+
import "./presentation/http/routeHandlers/WebhookHttpRouteHandler";
|
|
42
|
+
import "./presentation/http/routeHandlers/WorkflowHttpRouteHandler";
|
|
43
|
+
import { logLevelPolicyFactory } from "./infrastructure/logging/LogLevelPolicyFactory";
|
|
44
|
+
import { FrameworkBuiltinCredentialTypesRegistrar } from "./infrastructure/credentials/FrameworkBuiltinCredentialTypesRegistrar";
|
|
45
|
+
import { OpenAiApiKeyCredentialHealthTester } from "./infrastructure/credentials/OpenAiApiKeyCredentialHealthTester";
|
|
46
|
+
import { OpenAiApiKeyCredentialTypeFactory } from "./infrastructure/credentials/OpenAiApiKeyCredentialTypeFactory";
|
|
47
|
+
import { CodemationPluginRegistrar } from "./infrastructure/config/CodemationPluginRegistrar";
|
|
48
|
+
import type { CredentialType } from "./domain/credentials/CredentialServices";
|
|
49
|
+
import { CredentialTypeRegistryImpl } from "./domain/credentials/CredentialServices";
|
|
50
|
+
import type { CodemationAuthConfig } from "./presentation/config/CodemationAuthConfig";
|
|
51
|
+
import type { CodemationApplicationRuntimeConfig, CodemationConfig } from "./presentation/config/CodemationConfig";
|
|
52
|
+
import type { NormalizedCodemationConfig } from "./presentation/config/CodemationConfigNormalizer";
|
|
53
|
+
import { CodemationConfigNormalizer } from "./presentation/config/CodemationConfigNormalizer";
|
|
54
|
+
import type { CodemationPlugin } from "./presentation/config/CodemationPlugin";
|
|
55
|
+
import type { CodemationWhitelabelConfig } from "./presentation/config/CodemationWhitelabelConfig";
|
|
56
|
+
import { WorkflowWebsocketServer } from "./presentation/websocket/WorkflowWebsocketServer";
|
|
57
|
+
import { ApplicationTokens } from "./applicationTokens";
|
|
58
|
+
import { CodemationBootstrapRequest } from "./bootstrap/CodemationBootstrapRequest";
|
|
59
|
+
import type { CodemationContainerRegistration } from "./bootstrap/CodemationContainerRegistration";
|
|
60
|
+
import { CodemationFrontendBootstrapRequest } from "./bootstrap/CodemationFrontendBootstrapRequest";
|
|
61
|
+
import { PreparedCodemationRuntime } from "./bootstrap/PreparedCodemationRuntime";
|
|
62
|
+
import { PreparedCodemationRuntimeFactory } from "./bootstrap/PreparedCodemationRuntimeFactory";
|
|
63
|
+
import { CodemationContainerFactory } from "./bootstrap/CodemationContainerFactory";
|
|
64
|
+
import { CodemationWorkerBootstrapRequest } from "./bootstrap/CodemationWorkerBootstrapRequest";
|
|
65
|
+
import { AppConfigFactory } from "./bootstrap/runtime/AppConfigFactory";
|
|
66
|
+
import { CliRuntimeBootService } from "./bootstrap/boot/CliRuntimeBootService";
|
|
67
|
+
import { FrontendRuntimeBootService } from "./bootstrap/boot/FrontendRuntimeBootService";
|
|
68
|
+
import { WorkerRuntimeBootService } from "./bootstrap/boot/WorkerRuntimeBootService";
|
|
69
|
+
|
|
70
|
+
type StopHandle = Readonly<{ stop: () => Promise<void> }>;
|
|
71
|
+
|
|
72
|
+
export type CodemationStopHandle = StopHandle;
|
|
73
|
+
|
|
74
|
+
export type CodemationApplicationConfig = CodemationConfig;
|
|
75
|
+
|
|
76
|
+
export class CodemationApplication {
|
|
77
|
+
private readonly pluginRegistrar: CodemationPluginRegistrar;
|
|
78
|
+
private readonly containerFactory: CodemationContainerFactory;
|
|
79
|
+
private readonly preparedRuntimeFactory: PreparedCodemationRuntimeFactory;
|
|
80
|
+
private readonly configNormalizer: CodemationConfigNormalizer;
|
|
81
|
+
private readonly appConfigFactory: AppConfigFactory;
|
|
82
|
+
private readonly cliRuntimeBootService: CliRuntimeBootService;
|
|
83
|
+
private readonly frontendRuntimeBootService: FrontendRuntimeBootService;
|
|
84
|
+
private readonly workerRuntimeBootService: WorkerRuntimeBootService;
|
|
85
|
+
|
|
86
|
+
private configuredContainer: Container | null = null;
|
|
87
|
+
private preparedRuntime: PreparedCodemationRuntime | null = null;
|
|
88
|
+
private workflows: WorkflowDefinition[] = [];
|
|
89
|
+
private runtimeConfig: CodemationApplicationRuntimeConfig = {};
|
|
90
|
+
private containerRegistrations: ReadonlyArray<CodemationContainerRegistration<unknown>> = [];
|
|
91
|
+
private hasConfiguredCredentialSessionServiceRegistration = false;
|
|
92
|
+
private plugins: ReadonlyArray<CodemationPlugin> = [];
|
|
93
|
+
private sharedWorkflowWebsocketServer: WorkflowWebsocketServer | null = null;
|
|
94
|
+
private applicationAuthConfig: CodemationAuthConfig | undefined;
|
|
95
|
+
private whitelabelConfig: CodemationWhitelabelConfig = {};
|
|
96
|
+
private frameworkBuiltinCredentialTypesRegistered = false;
|
|
97
|
+
private credentialTypes: Array<CredentialType<any, any, unknown>> = [];
|
|
98
|
+
|
|
99
|
+
constructor(
|
|
100
|
+
pluginRegistrar: CodemationPluginRegistrar = new CodemationPluginRegistrar(),
|
|
101
|
+
containerFactory: CodemationContainerFactory = new CodemationContainerFactory(),
|
|
102
|
+
preparedRuntimeFactory: PreparedCodemationRuntimeFactory = new PreparedCodemationRuntimeFactory(),
|
|
103
|
+
configNormalizer: CodemationConfigNormalizer = new CodemationConfigNormalizer(),
|
|
104
|
+
appConfigFactory: AppConfigFactory = new AppConfigFactory(),
|
|
105
|
+
cliRuntimeBootService: CliRuntimeBootService = new CliRuntimeBootService(),
|
|
106
|
+
frontendRuntimeBootService: FrontendRuntimeBootService = new FrontendRuntimeBootService(),
|
|
107
|
+
workerRuntimeBootService: WorkerRuntimeBootService = new WorkerRuntimeBootService(),
|
|
108
|
+
) {
|
|
109
|
+
this.pluginRegistrar = pluginRegistrar;
|
|
110
|
+
this.containerFactory = containerFactory;
|
|
111
|
+
this.preparedRuntimeFactory = preparedRuntimeFactory;
|
|
112
|
+
this.configNormalizer = configNormalizer;
|
|
113
|
+
this.appConfigFactory = appConfigFactory;
|
|
114
|
+
this.cliRuntimeBootService = cliRuntimeBootService;
|
|
115
|
+
this.frontendRuntimeBootService = frontendRuntimeBootService;
|
|
116
|
+
this.workerRuntimeBootService = workerRuntimeBootService;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
useConfig(config: CodemationApplicationConfig): this {
|
|
120
|
+
const normalizedConfig: NormalizedCodemationConfig = this.configNormalizer.normalize(config);
|
|
121
|
+
logLevelPolicyFactory.create().applyCodemationLogConfig(normalizedConfig.log);
|
|
122
|
+
if (normalizedConfig.workflows) {
|
|
123
|
+
this.useWorkflows(normalizedConfig.workflows);
|
|
124
|
+
}
|
|
125
|
+
this.useContainerRegistrations(normalizedConfig.containerRegistrations);
|
|
126
|
+
if (!this.frameworkBuiltinCredentialTypesRegistered) {
|
|
127
|
+
new FrameworkBuiltinCredentialTypesRegistrar(
|
|
128
|
+
new OpenAiApiKeyCredentialTypeFactory(new OpenAiApiKeyCredentialHealthTester(globalThis.fetch)),
|
|
129
|
+
).register(this, normalizedConfig);
|
|
130
|
+
this.frameworkBuiltinCredentialTypesRegistered = true;
|
|
131
|
+
}
|
|
132
|
+
if (normalizedConfig.credentialTypes) {
|
|
133
|
+
for (const credentialType of normalizedConfig.credentialTypes) {
|
|
134
|
+
this.registerCredentialType(credentialType);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (normalizedConfig.plugins) {
|
|
138
|
+
this.usePlugins(normalizedConfig.plugins);
|
|
139
|
+
}
|
|
140
|
+
if (normalizedConfig.runtime) {
|
|
141
|
+
this.useRuntimeConfig(normalizedConfig.runtime);
|
|
142
|
+
}
|
|
143
|
+
if (normalizedConfig.auth !== undefined) {
|
|
144
|
+
this.applicationAuthConfig = normalizedConfig.auth;
|
|
145
|
+
}
|
|
146
|
+
this.whitelabelConfig = normalizedConfig.whitelabel ?? {};
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
useWorkflows(workflows: ReadonlyArray<WorkflowDefinition>): this {
|
|
151
|
+
this.workflows = [...workflows];
|
|
152
|
+
this.invalidatePreparedState();
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
useRuntimeConfig(runtimeConfig: CodemationApplicationRuntimeConfig): this {
|
|
157
|
+
this.runtimeConfig = {
|
|
158
|
+
...this.runtimeConfig,
|
|
159
|
+
...runtimeConfig,
|
|
160
|
+
...(runtimeConfig.engineExecutionLimits !== undefined
|
|
161
|
+
? {
|
|
162
|
+
engineExecutionLimits: {
|
|
163
|
+
...this.runtimeConfig.engineExecutionLimits,
|
|
164
|
+
...runtimeConfig.engineExecutionLimits,
|
|
165
|
+
},
|
|
166
|
+
}
|
|
167
|
+
: {}),
|
|
168
|
+
};
|
|
169
|
+
this.invalidatePreparedState();
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private useContainerRegistrations(registrations: ReadonlyArray<CodemationContainerRegistration<unknown>>): this {
|
|
174
|
+
this.containerRegistrations = [...registrations];
|
|
175
|
+
this.hasConfiguredCredentialSessionServiceRegistration = registrations.some(
|
|
176
|
+
(entry) => entry.token === CoreTokens.CredentialSessionService,
|
|
177
|
+
);
|
|
178
|
+
this.invalidatePreparedState();
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
usePlugins(plugins: ReadonlyArray<CodemationPlugin>): this {
|
|
183
|
+
this.plugins = [...plugins];
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
useSharedWorkflowWebsocketServer(workflowWebsocketServer: WorkflowWebsocketServer): this {
|
|
188
|
+
this.sharedWorkflowWebsocketServer = workflowWebsocketServer;
|
|
189
|
+
if (this.configuredContainer) {
|
|
190
|
+
this.configuredContainer.registerInstance(WorkflowWebsocketServer, workflowWebsocketServer);
|
|
191
|
+
this.configuredContainer.registerInstance(ApplicationTokens.WorkflowWebsocketPublisher, workflowWebsocketServer);
|
|
192
|
+
}
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
getRuntimeConfig(): CodemationApplicationRuntimeConfig {
|
|
197
|
+
return { ...this.runtimeConfig };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
getWorkflows(): ReadonlyArray<WorkflowDefinition> {
|
|
201
|
+
return [...this.workflows];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
getContainer(): Container {
|
|
205
|
+
return this.ensureConfiguredContainer();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
getBootRuntimeSummary(): BootRuntimeSummary | null {
|
|
209
|
+
return this.preparedRuntime?.runtimeSummary ?? null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
registerCredentialType(type: CredentialType<any, any, unknown>): void {
|
|
213
|
+
if (this.credentialTypes.some((entry) => entry.definition.typeId === type.definition.typeId)) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
this.credentialTypes.push(type);
|
|
217
|
+
if (this.configuredContainer) {
|
|
218
|
+
this.configuredContainer.resolve(CredentialTypeRegistryImpl).register(type);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async applyPlugins(request: CodemationBootstrapRequest): Promise<void> {
|
|
223
|
+
const container = this.ensureConfiguredContainer();
|
|
224
|
+
const env = request.resolveEnvironment();
|
|
225
|
+
await this.pluginRegistrar.apply({
|
|
226
|
+
plugins: this.plugins,
|
|
227
|
+
container,
|
|
228
|
+
appConfig: this.appConfigFactory.create({
|
|
229
|
+
repoRoot: request.repoRoot,
|
|
230
|
+
consumerRoot: request.consumerRoot,
|
|
231
|
+
env,
|
|
232
|
+
workflowSources: request.workflowSources,
|
|
233
|
+
runtimeConfig: this.runtimeConfig,
|
|
234
|
+
authConfig: this.applicationAuthConfig,
|
|
235
|
+
whitelabelConfig: this.whitelabelConfig,
|
|
236
|
+
}),
|
|
237
|
+
registerCredentialType: (type) => this.registerCredentialType(type),
|
|
238
|
+
loggerFactory: container.resolve(ApplicationTokens.LoggerFactory),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async prepareContainer(request: CodemationBootstrapRequest): Promise<PreparedCodemationRuntime> {
|
|
243
|
+
if (this.preparedRuntime) {
|
|
244
|
+
return this.preparedRuntime;
|
|
245
|
+
}
|
|
246
|
+
const env = request.resolveEnvironment();
|
|
247
|
+
this.preparedRuntime = await this.preparedRuntimeFactory.prepare({
|
|
248
|
+
container: this.ensureConfiguredContainer(),
|
|
249
|
+
repoRoot: request.repoRoot,
|
|
250
|
+
consumerRoot: request.consumerRoot,
|
|
251
|
+
env,
|
|
252
|
+
workflowSources: request.workflowSources,
|
|
253
|
+
runtimeConfig: this.runtimeConfig,
|
|
254
|
+
applicationAuthConfig: this.applicationAuthConfig,
|
|
255
|
+
whitelabelConfig: this.whitelabelConfig,
|
|
256
|
+
hasConfiguredCredentialSessionServiceRegistration: this.hasConfiguredCredentialSessionServiceRegistration,
|
|
257
|
+
});
|
|
258
|
+
return this.preparedRuntime;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async bootCli(request: CodemationBootstrapRequest): Promise<PreparedCodemationRuntime> {
|
|
262
|
+
const preparedRuntime = await this.prepareContainer(request);
|
|
263
|
+
await this.cliRuntimeBootService.boot({ preparedRuntime });
|
|
264
|
+
return preparedRuntime;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async bootFrontend(request: CodemationFrontendBootstrapRequest): Promise<PreparedCodemationRuntime> {
|
|
268
|
+
const preparedRuntime = await this.prepareContainer(request.bootstrap);
|
|
269
|
+
await this.frontendRuntimeBootService.boot({
|
|
270
|
+
preparedRuntime,
|
|
271
|
+
skipPresentationServers: request.skipPresentationServers,
|
|
272
|
+
});
|
|
273
|
+
return preparedRuntime;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async bootWorker(request: CodemationWorkerBootstrapRequest): Promise<CodemationStopHandle> {
|
|
277
|
+
const preparedRuntime = await this.prepareContainer(request.bootstrap);
|
|
278
|
+
void request.bootstrapSource;
|
|
279
|
+
return await this.workerRuntimeBootService.boot({
|
|
280
|
+
preparedRuntime,
|
|
281
|
+
queues: request.queues,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async stop(args?: Readonly<{ stopWebsocketServer?: boolean }>): Promise<void> {
|
|
286
|
+
if (!this.preparedRuntime) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
await this.preparedRuntime.stop(args);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private ensureConfiguredContainer(): Container {
|
|
293
|
+
if (this.configuredContainer) {
|
|
294
|
+
return this.configuredContainer;
|
|
295
|
+
}
|
|
296
|
+
this.configuredContainer = this.containerFactory.create({
|
|
297
|
+
application: this,
|
|
298
|
+
registrations: this.containerRegistrations,
|
|
299
|
+
runtimeConfig: this.runtimeConfig,
|
|
300
|
+
workflows: this.workflows,
|
|
301
|
+
credentialTypes: this.credentialTypes,
|
|
302
|
+
sharedWorkflowWebsocketServer: this.sharedWorkflowWebsocketServer,
|
|
303
|
+
});
|
|
304
|
+
return this.configuredContainer;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private invalidatePreparedState(): void {
|
|
308
|
+
this.configuredContainer = null;
|
|
309
|
+
this.preparedRuntime = null;
|
|
310
|
+
}
|
|
311
|
+
}
|
package/src/consumer.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CodemationConsumerAppResolver } from "./presentation/server/CodemationConsumerAppResolver";
|
|
2
|
+
export type { CodemationConsumerApp } from "./presentation/server/CodemationConsumerAppResolver";
|
|
3
|
+
export { CodemationConsumerConfigLoader } from "./presentation/server/CodemationConsumerConfigLoader";
|
|
4
|
+
export type { CodemationConsumerConfigResolution } from "./presentation/server/CodemationConsumerConfigLoader";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AnyCredentialType } from "./domain/credentials/CredentialServices";
|
|
2
|
+
import { OpenAiApiKeyCredentialHealthTester } from "./infrastructure/credentials/OpenAiApiKeyCredentialHealthTester";
|
|
3
|
+
import { OpenAiApiKeyCredentialTypeFactory } from "./infrastructure/credentials/OpenAiApiKeyCredentialTypeFactory";
|
|
4
|
+
|
|
5
|
+
export { CredentialBindingService, CredentialInstanceService } from "./domain/credentials/CredentialServices";
|
|
6
|
+
export type {
|
|
7
|
+
AnyCredentialType,
|
|
8
|
+
CredentialSessionFactoryArgs,
|
|
9
|
+
CredentialType,
|
|
10
|
+
} from "./domain/credentials/CredentialServices";
|
|
11
|
+
export { OpenAiApiKeyCredentialHealthTester } from "./infrastructure/credentials/OpenAiApiKeyCredentialHealthTester";
|
|
12
|
+
export { OpenAiApiKeyCredentialTypeFactory } from "./infrastructure/credentials/OpenAiApiKeyCredentialTypeFactory";
|
|
13
|
+
export type {
|
|
14
|
+
OpenAiApiKeyMaterial,
|
|
15
|
+
OpenAiApiKeyPublicConfig,
|
|
16
|
+
OpenAiApiKeySession,
|
|
17
|
+
} from "./infrastructure/credentials/OpenAiApiKeyCredentialShapes.types";
|
|
18
|
+
|
|
19
|
+
const defaultOpenAiApiKeyCredentialTypeFactory = new OpenAiApiKeyCredentialTypeFactory(
|
|
20
|
+
new OpenAiApiKeyCredentialHealthTester(globalThis.fetch),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const openAiApiKeyCredentialType: AnyCredentialType =
|
|
24
|
+
defaultOpenAiApiKeyCredentialTypeFactory.createCredentialType();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow entry for dev/runtime tooling (Next host, runtime-dev) without pulling the full
|
|
3
|
+
* server barrel (e.g. CodemationConsumerConfigLoader → tsx) into the Next bundle.
|
|
4
|
+
*/
|
|
5
|
+
export { CodemationTsyringeParamInfoReader } from "./presentation/server/CodemationTsyringeParamInfoReader";
|
|
6
|
+
export { CodemationTsyringeTypeInfoRegistrar } from "./presentation/server/CodemationTsyringeTypeInfoRegistrar";
|
|
7
|
+
export {
|
|
8
|
+
DevelopmentRuntimeRouteGuard,
|
|
9
|
+
type DevelopmentRuntimeSignal,
|
|
10
|
+
} from "./presentation/server/DevelopmentRuntimeRouteGuard";
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CredentialBinding,
|
|
3
|
+
CredentialBindingKey,
|
|
4
|
+
CredentialInstanceId,
|
|
5
|
+
CredentialRequirement,
|
|
6
|
+
WorkflowDefinition,
|
|
7
|
+
WorkflowRepository,
|
|
8
|
+
} from "@codemation/core";
|
|
9
|
+
|
|
10
|
+
import { CoreTokens, inject, injectable } from "@codemation/core";
|
|
11
|
+
|
|
12
|
+
import { ApplicationRequestError } from "../../application/ApplicationRequestError";
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
WorkflowCredentialHealthDto,
|
|
16
|
+
WorkflowCredentialHealthSlotDto,
|
|
17
|
+
} from "../../application/contracts/CredentialContractsRegistry";
|
|
18
|
+
|
|
19
|
+
import { ApplicationTokens } from "../../applicationTokens";
|
|
20
|
+
|
|
21
|
+
import { WorkflowCredentialNodeResolver } from "./WorkflowCredentialNodeResolver";
|
|
22
|
+
import { CredentialInstanceService } from "./CredentialInstanceService";
|
|
23
|
+
import type { CredentialStore, MutableCredentialSessionService } from "./CredentialServices";
|
|
24
|
+
|
|
25
|
+
@injectable()
|
|
26
|
+
export class CredentialBindingService {
|
|
27
|
+
constructor(
|
|
28
|
+
@inject(ApplicationTokens.CredentialStore)
|
|
29
|
+
private readonly credentialStore: CredentialStore,
|
|
30
|
+
@inject(CredentialInstanceService)
|
|
31
|
+
private readonly credentialInstanceService: CredentialInstanceService,
|
|
32
|
+
@inject(CoreTokens.WorkflowRepository)
|
|
33
|
+
private readonly workflowRepository: WorkflowRepository,
|
|
34
|
+
@inject(CoreTokens.CredentialSessionService)
|
|
35
|
+
private readonly credentialSessionService: MutableCredentialSessionService,
|
|
36
|
+
@inject(WorkflowCredentialNodeResolver)
|
|
37
|
+
private readonly workflowCredentialNodeResolver: WorkflowCredentialNodeResolver,
|
|
38
|
+
) {}
|
|
39
|
+
|
|
40
|
+
async upsertBinding(
|
|
41
|
+
args: Readonly<{ workflowId: string; nodeId: string; slotKey: string; instanceId: CredentialInstanceId }>,
|
|
42
|
+
): Promise<CredentialBinding> {
|
|
43
|
+
const workflow = this.requireWorkflow(args.workflowId);
|
|
44
|
+
const requirement = this.requireRequirement(workflow, args.nodeId, args.slotKey);
|
|
45
|
+
const instance = await this.credentialInstanceService.requireInstance(args.instanceId);
|
|
46
|
+
if (!requirement.acceptedTypes.includes(instance.typeId)) {
|
|
47
|
+
throw new ApplicationRequestError(
|
|
48
|
+
400,
|
|
49
|
+
`Credential instance ${instance.instanceId} (${instance.typeId}) is not compatible with slot ${args.slotKey}. Accepted types: ${requirement.acceptedTypes.join(", ")}`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const binding: CredentialBinding = {
|
|
53
|
+
key: {
|
|
54
|
+
workflowId: args.workflowId,
|
|
55
|
+
nodeId: args.nodeId,
|
|
56
|
+
slotKey: args.slotKey,
|
|
57
|
+
},
|
|
58
|
+
instanceId: args.instanceId,
|
|
59
|
+
updatedAt: new Date().toISOString(),
|
|
60
|
+
};
|
|
61
|
+
await this.credentialStore.upsertBinding(binding);
|
|
62
|
+
this.credentialSessionService.evictBinding(binding.key);
|
|
63
|
+
return binding;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async listWorkflowHealth(workflowId: string): Promise<WorkflowCredentialHealthDto> {
|
|
67
|
+
const workflow = this.requireWorkflow(workflowId);
|
|
68
|
+
const bindings = await this.credentialStore.listBindingsByWorkflowId(workflowId);
|
|
69
|
+
const bindingsByKey = new Map(bindings.map((binding) => [this.toBindingKeyString(binding.key), binding] as const));
|
|
70
|
+
const slots: WorkflowCredentialHealthSlotDto[] = [];
|
|
71
|
+
for (const slotRef of this.workflowCredentialNodeResolver.listSlots(workflow)) {
|
|
72
|
+
const requirement = slotRef.requirement;
|
|
73
|
+
const bindingKey = {
|
|
74
|
+
workflowId,
|
|
75
|
+
nodeId: slotRef.nodeId,
|
|
76
|
+
slotKey: requirement.slotKey,
|
|
77
|
+
} satisfies CredentialBindingKey;
|
|
78
|
+
const binding = bindingsByKey.get(this.toBindingKeyString(bindingKey));
|
|
79
|
+
if (!binding) {
|
|
80
|
+
slots.push({
|
|
81
|
+
workflowId,
|
|
82
|
+
nodeId: slotRef.nodeId,
|
|
83
|
+
nodeName: slotRef.nodeName,
|
|
84
|
+
requirement,
|
|
85
|
+
health: {
|
|
86
|
+
status: requirement.optional ? "optional-unbound" : "unbound",
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const instance = await this.credentialInstanceService.requireInstance(binding.instanceId);
|
|
92
|
+
const latestTestResult = await this.credentialStore.getLatestTestResult(instance.instanceId);
|
|
93
|
+
slots.push({
|
|
94
|
+
workflowId,
|
|
95
|
+
nodeId: slotRef.nodeId,
|
|
96
|
+
nodeName: slotRef.nodeName,
|
|
97
|
+
requirement,
|
|
98
|
+
instance: {
|
|
99
|
+
instanceId: instance.instanceId,
|
|
100
|
+
typeId: instance.typeId,
|
|
101
|
+
displayName: instance.displayName,
|
|
102
|
+
setupStatus: instance.setupStatus,
|
|
103
|
+
},
|
|
104
|
+
health: {
|
|
105
|
+
status: latestTestResult?.health.status ?? "unknown",
|
|
106
|
+
message: latestTestResult?.health.message,
|
|
107
|
+
testedAt: latestTestResult?.health.testedAt,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
workflowId,
|
|
113
|
+
slots,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private requireWorkflow(workflowId: string): WorkflowDefinition {
|
|
118
|
+
const workflow = this.workflowRepository.get(decodeURIComponent(workflowId));
|
|
119
|
+
if (!workflow) {
|
|
120
|
+
throw new ApplicationRequestError(404, `Unknown workflowId: ${workflowId}`);
|
|
121
|
+
}
|
|
122
|
+
return workflow;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private requireRequirement(workflow: WorkflowDefinition, nodeId: string, slotKey: string): CredentialRequirement {
|
|
126
|
+
const resolved = this.workflowCredentialNodeResolver.findRequirement(workflow, nodeId, slotKey);
|
|
127
|
+
if (!resolved) {
|
|
128
|
+
if (!this.workflowCredentialNodeResolver.isCredentialNodeIdInWorkflow(workflow, nodeId)) {
|
|
129
|
+
throw new ApplicationRequestError(404, `Unknown workflow node: ${nodeId}`);
|
|
130
|
+
}
|
|
131
|
+
throw new ApplicationRequestError(400, `Node ${nodeId} does not declare credential slot ${slotKey}.`);
|
|
132
|
+
}
|
|
133
|
+
return resolved.requirement;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private toBindingKeyString(bindingKey: CredentialBindingKey): string {
|
|
137
|
+
return `${bindingKey.workflowId}:${bindingKey.nodeId}:${bindingKey.slotKey}`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { CredentialFieldSchema, CredentialTypeDefinition } from "@codemation/core";
|
|
2
|
+
import { inject, injectable } from "@codemation/core";
|
|
3
|
+
|
|
4
|
+
import { ApplicationTokens } from "../../applicationTokens";
|
|
5
|
+
import type { AppConfig } from "../../presentation/config/AppConfig";
|
|
6
|
+
|
|
7
|
+
import type { JsonRecord } from "./CredentialServices";
|
|
8
|
+
|
|
9
|
+
@injectable()
|
|
10
|
+
export class CredentialFieldEnvOverlayService {
|
|
11
|
+
constructor(
|
|
12
|
+
@inject(ApplicationTokens.AppConfig)
|
|
13
|
+
private readonly appConfig: AppConfig,
|
|
14
|
+
) {}
|
|
15
|
+
|
|
16
|
+
/** True when the field declares an env var and process.env has a non-empty string for it. */
|
|
17
|
+
isFieldResolvedFromEnv(field: CredentialFieldSchema): boolean {
|
|
18
|
+
const name = field.envVarName?.trim();
|
|
19
|
+
if (!name) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const v = this.appConfig.env[name];
|
|
23
|
+
return typeof v === "string" && v.length > 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
apply(
|
|
27
|
+
args: Readonly<{
|
|
28
|
+
definition: CredentialTypeDefinition;
|
|
29
|
+
publicConfig: JsonRecord;
|
|
30
|
+
material: JsonRecord;
|
|
31
|
+
}>,
|
|
32
|
+
): Readonly<{ resolvedPublicConfig: JsonRecord; resolvedMaterial: JsonRecord }> {
|
|
33
|
+
const pub: Record<string, unknown> = { ...args.publicConfig };
|
|
34
|
+
const mat: Record<string, unknown> = { ...args.material };
|
|
35
|
+
for (const field of args.definition.publicFields ?? []) {
|
|
36
|
+
const name = field.envVarName?.trim();
|
|
37
|
+
if (!name) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const v = this.appConfig.env[name];
|
|
41
|
+
if (typeof v === "string" && v.length > 0) {
|
|
42
|
+
pub[field.key] = v;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const field of args.definition.secretFields ?? []) {
|
|
46
|
+
const name = field.envVarName?.trim();
|
|
47
|
+
if (!name) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const v = this.appConfig.env[name];
|
|
51
|
+
if (typeof v === "string" && v.length > 0) {
|
|
52
|
+
mat[field.key] = v;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return Object.freeze({
|
|
56
|
+
resolvedPublicConfig: Object.freeze(pub),
|
|
57
|
+
resolvedMaterial: Object.freeze(mat),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|