@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,179 @@
|
|
|
1
|
+
import type { AnyCredentialType, Container, TypeToken, WorkflowDefinition } from "@codemation/core";
|
|
2
|
+
import type { CodemationContainerRegistration } from "../../bootstrap/CodemationContainerRegistration";
|
|
3
|
+
import type { CodemationAppContext } from "./CodemationAppContext";
|
|
4
|
+
import type { CodemationClassToken } from "./CodemationClassToken";
|
|
5
|
+
import type {
|
|
6
|
+
CodemationApplicationRuntimeConfig,
|
|
7
|
+
CodemationConfig,
|
|
8
|
+
CodemationDatabaseConfig,
|
|
9
|
+
CodemationEventBusConfig,
|
|
10
|
+
CodemationSchedulerConfig,
|
|
11
|
+
} from "./CodemationConfig";
|
|
12
|
+
|
|
13
|
+
export type NormalizedCodemationConfig = CodemationConfig &
|
|
14
|
+
Readonly<{
|
|
15
|
+
containerRegistrations: ReadonlyArray<CodemationContainerRegistration<unknown>>;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
export class CodemationConfigNormalizer {
|
|
19
|
+
normalize(config: CodemationConfig): NormalizedCodemationConfig {
|
|
20
|
+
const collected = this.collectRegistration(config);
|
|
21
|
+
const normalizedRuntime = this.normalizeRuntimeConfig(config);
|
|
22
|
+
const normalizedWorkflowDiscoveryDirectories = [
|
|
23
|
+
...(config.workflowDiscovery?.directories ?? []),
|
|
24
|
+
...collected.workflowDirectories,
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
...config,
|
|
29
|
+
auth: config.app?.auth ?? config.auth,
|
|
30
|
+
containerRegistrations: collected.containerRegistrations,
|
|
31
|
+
credentialTypes: [...(config.credentialTypes ?? []), ...collected.credentialTypes],
|
|
32
|
+
log: config.app?.log ?? config.log,
|
|
33
|
+
runtime: normalizedRuntime,
|
|
34
|
+
whitelabel: config.app?.whitelabel ?? config.whitelabel,
|
|
35
|
+
workflowDiscovery:
|
|
36
|
+
normalizedWorkflowDiscoveryDirectories.length > 0
|
|
37
|
+
? { directories: normalizedWorkflowDiscoveryDirectories }
|
|
38
|
+
: config.workflowDiscovery,
|
|
39
|
+
workflows: this.mergeWorkflows(config.workflows ?? [], collected.workflows),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private collectRegistration(config: CodemationConfig): Readonly<{
|
|
44
|
+
containerRegistrations: ReadonlyArray<CodemationContainerRegistration<unknown>>;
|
|
45
|
+
credentialTypes: ReadonlyArray<AnyCredentialType>;
|
|
46
|
+
workflows: ReadonlyArray<WorkflowDefinition>;
|
|
47
|
+
workflowDirectories: ReadonlyArray<string>;
|
|
48
|
+
}> {
|
|
49
|
+
if (!config.register) {
|
|
50
|
+
return {
|
|
51
|
+
containerRegistrations: [],
|
|
52
|
+
credentialTypes: [],
|
|
53
|
+
workflows: [],
|
|
54
|
+
workflowDirectories: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const containerRegistrations: Array<CodemationContainerRegistration<unknown>> = [];
|
|
59
|
+
const credentialTypes: Array<AnyCredentialType> = [];
|
|
60
|
+
const workflows: Array<WorkflowDefinition> = [];
|
|
61
|
+
const workflowDirectories: Array<string> = [];
|
|
62
|
+
|
|
63
|
+
const context: CodemationAppContext = {
|
|
64
|
+
registerCredentialType(type) {
|
|
65
|
+
credentialTypes.push(type);
|
|
66
|
+
},
|
|
67
|
+
registerNode<TValue>(token: TypeToken<TValue>, implementation?: CodemationClassToken<TValue>) {
|
|
68
|
+
containerRegistrations.push({
|
|
69
|
+
token,
|
|
70
|
+
useClass: implementation ?? (token as CodemationClassToken<TValue>),
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
registerValue<TValue>(token: TypeToken<TValue>, value: TValue) {
|
|
74
|
+
containerRegistrations.push({ token, useValue: value });
|
|
75
|
+
},
|
|
76
|
+
registerClass<TValue>(token: TypeToken<TValue>, implementation: CodemationClassToken<TValue>) {
|
|
77
|
+
containerRegistrations.push({ token, useClass: implementation });
|
|
78
|
+
},
|
|
79
|
+
registerFactory<TValue>(token: TypeToken<TValue>, factory: (container: Container) => TValue) {
|
|
80
|
+
containerRegistrations.push({ token, useFactory: factory });
|
|
81
|
+
},
|
|
82
|
+
registerWorkflow(workflow: WorkflowDefinition) {
|
|
83
|
+
workflows.push(workflow);
|
|
84
|
+
},
|
|
85
|
+
registerWorkflows(nextWorkflows: ReadonlyArray<WorkflowDefinition>) {
|
|
86
|
+
workflows.push(...nextWorkflows);
|
|
87
|
+
},
|
|
88
|
+
discoverWorkflows(...directories: ReadonlyArray<string>) {
|
|
89
|
+
workflowDirectories.push(...directories);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
config.register(context);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
containerRegistrations,
|
|
97
|
+
credentialTypes,
|
|
98
|
+
workflows,
|
|
99
|
+
workflowDirectories,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private normalizeRuntimeConfig(config: CodemationConfig): CodemationApplicationRuntimeConfig | undefined {
|
|
104
|
+
if (!config.app) {
|
|
105
|
+
return config.runtime;
|
|
106
|
+
}
|
|
107
|
+
const nextRuntime: CodemationApplicationRuntimeConfig = {
|
|
108
|
+
...(config.runtime ?? {}),
|
|
109
|
+
frontendPort: config.app.frontendPort ?? config.runtime?.frontendPort,
|
|
110
|
+
database: this.normalizeDatabaseConfig(config),
|
|
111
|
+
eventBus: this.normalizeEventBusConfig(config),
|
|
112
|
+
scheduler: this.normalizeSchedulerConfig(config),
|
|
113
|
+
engineExecutionLimits: config.app.engineExecutionLimits ?? config.runtime?.engineExecutionLimits,
|
|
114
|
+
};
|
|
115
|
+
return nextRuntime;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private normalizeDatabaseConfig(config: CodemationConfig): CodemationDatabaseConfig | undefined {
|
|
119
|
+
if (!config.app) {
|
|
120
|
+
return config.runtime?.database;
|
|
121
|
+
}
|
|
122
|
+
if (config.app.database) {
|
|
123
|
+
return config.app.database;
|
|
124
|
+
}
|
|
125
|
+
if (!config.app.databaseUrl) {
|
|
126
|
+
return config.runtime?.database;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
...(config.runtime?.database ?? {}),
|
|
130
|
+
url: config.app.databaseUrl,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private normalizeSchedulerConfig(config: CodemationConfig): CodemationSchedulerConfig | undefined {
|
|
135
|
+
if (!config.app?.scheduler) {
|
|
136
|
+
return config.runtime?.scheduler;
|
|
137
|
+
}
|
|
138
|
+
const scheduler = config.app.scheduler;
|
|
139
|
+
return {
|
|
140
|
+
...(config.runtime?.scheduler ?? {}),
|
|
141
|
+
kind:
|
|
142
|
+
scheduler.kind === "queue" ? "bullmq" : scheduler.kind === "inline" ? "local" : config.runtime?.scheduler?.kind,
|
|
143
|
+
queuePrefix: scheduler.queuePrefix ?? config.runtime?.scheduler?.queuePrefix,
|
|
144
|
+
workerQueues: scheduler.workerQueues ?? config.runtime?.scheduler?.workerQueues,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private normalizeEventBusConfig(config: CodemationConfig): CodemationEventBusConfig | undefined {
|
|
149
|
+
if (!config.app?.scheduler) {
|
|
150
|
+
return config.runtime?.eventBus;
|
|
151
|
+
}
|
|
152
|
+
const scheduler = config.app.scheduler;
|
|
153
|
+
const eventBusKind =
|
|
154
|
+
scheduler.kind === "queue" ? "redis" : scheduler.kind === "inline" ? "memory" : config.runtime?.eventBus?.kind;
|
|
155
|
+
return {
|
|
156
|
+
...(config.runtime?.eventBus ?? {}),
|
|
157
|
+
kind: eventBusKind,
|
|
158
|
+
queuePrefix: scheduler.queuePrefix ?? config.runtime?.eventBus?.queuePrefix,
|
|
159
|
+
redisUrl: scheduler.redisUrl ?? config.runtime?.eventBus?.redisUrl,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private mergeWorkflows(
|
|
164
|
+
configuredWorkflows: ReadonlyArray<WorkflowDefinition>,
|
|
165
|
+
registeredWorkflows: ReadonlyArray<WorkflowDefinition>,
|
|
166
|
+
): ReadonlyArray<WorkflowDefinition> | undefined {
|
|
167
|
+
if (configuredWorkflows.length === 0 && registeredWorkflows.length === 0) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
const workflowsById = new Map<string, WorkflowDefinition>();
|
|
171
|
+
for (const workflow of registeredWorkflows) {
|
|
172
|
+
workflowsById.set(workflow.id, workflow);
|
|
173
|
+
}
|
|
174
|
+
for (const workflow of configuredWorkflows) {
|
|
175
|
+
workflowsById.set(workflow.id, workflow);
|
|
176
|
+
}
|
|
177
|
+
return [...workflowsById.values()];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimum level for namespaces matched by {@link CodemationLogRule.filter}.
|
|
3
|
+
* `silent` suppresses all log lines for matching namespaces.
|
|
4
|
+
*/
|
|
5
|
+
export type CodemationLogLevelName = "debug" | "info" | "warn" | "error" | "silent";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* One rule: {@link filter} is one glob or several (`*` = any substring; a lone `*` matches all namespaces).
|
|
9
|
+
* If multiple patterns are given, **any** match applies this rule’s level.
|
|
10
|
+
* Rules are evaluated in order; the **first** rule whose filter set matches wins.
|
|
11
|
+
*/
|
|
12
|
+
export type CodemationLogRule = Readonly<{
|
|
13
|
+
filter: string | ReadonlyArray<string>;
|
|
14
|
+
level: CodemationLogLevelName;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Either a single rule (`{ filter, level }`) or multiple `{ rules: [...] }`.
|
|
19
|
+
* Put broader patterns last, e.g. `{ filter: "codemation.webhooks.*", level: "info" }` then `{ filter: "*", level: "warn" }`.
|
|
20
|
+
* Use an array for `filter` to match several namespaces with the same level, e.g. `filter: ["codemation.webhooks.*", "codemation.engine.triggers"]`.
|
|
21
|
+
*/
|
|
22
|
+
export type CodemationLogConfig = Readonly<{ rules: ReadonlyArray<CodemationLogRule> }> | CodemationLogRule;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Container } from "@codemation/core";
|
|
2
|
+
import type { LoggerFactory } from "../../application/logging/Logger";
|
|
3
|
+
import type { AppConfig } from "./AppConfig";
|
|
4
|
+
import type { CodemationRegistrationContextBase } from "./CodemationAppContext";
|
|
5
|
+
|
|
6
|
+
export interface CodemationPluginContext extends CodemationRegistrationContextBase {
|
|
7
|
+
readonly container: Container;
|
|
8
|
+
readonly appConfig: AppConfig;
|
|
9
|
+
readonly loggerFactory: LoggerFactory;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CodemationPlugin {
|
|
13
|
+
/**
|
|
14
|
+
* Optional npm package name for this plugin (e.g. `"@codemation/core-nodes-gmail"`).
|
|
15
|
+
* When set, the host merges configured and discovered plugin lists by this id so the same package is not
|
|
16
|
+
* registered twice when separate module graphs load duplicate class instances (different `constructor` values).
|
|
17
|
+
*/
|
|
18
|
+
readonly pluginPackageId?: string;
|
|
19
|
+
register(context: CodemationPluginContext): void | Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CodemationPlugin } from "./CodemationPlugin";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges explicitly configured plugins with auto-discovered plugins.
|
|
5
|
+
* Configured plugins are applied first; discovered plugins fill in gaps.
|
|
6
|
+
* Plugins that declare `pluginPackageId` are deduped by that string so the same npm package is not
|
|
7
|
+
* registered twice when the consumer config lists a plugin and discovery also finds it, or when two
|
|
8
|
+
* module evaluations produce different `constructor` identities for the same logical plugin.
|
|
9
|
+
*/
|
|
10
|
+
export class CodemationPluginListMerger {
|
|
11
|
+
merge(
|
|
12
|
+
configuredPlugins: ReadonlyArray<CodemationPlugin>,
|
|
13
|
+
discoveredPlugins: ReadonlyArray<CodemationPlugin>,
|
|
14
|
+
): ReadonlyArray<CodemationPlugin> {
|
|
15
|
+
const pluginsByPackageId = new Map<string, CodemationPlugin>();
|
|
16
|
+
const pluginsByConstructor = new Map<unknown, CodemationPlugin>();
|
|
17
|
+
const result: CodemationPlugin[] = [];
|
|
18
|
+
|
|
19
|
+
const tryAdd = (plugin: CodemationPlugin): void => {
|
|
20
|
+
const packageId = plugin.pluginPackageId;
|
|
21
|
+
if (typeof packageId === "string" && packageId.trim().length > 0) {
|
|
22
|
+
const key = packageId.trim();
|
|
23
|
+
if (pluginsByPackageId.has(key)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
pluginsByPackageId.set(key, plugin);
|
|
27
|
+
result.push(plugin);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const constructorKey = Object.getPrototypeOf(plugin)?.constructor ?? plugin;
|
|
31
|
+
if (pluginsByConstructor.has(constructorKey)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
pluginsByConstructor.set(constructorKey, plugin);
|
|
35
|
+
result.push(plugin);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
for (const plugin of configuredPlugins) {
|
|
39
|
+
tryAdd(plugin);
|
|
40
|
+
}
|
|
41
|
+
for (const plugin of discoveredPlugins) {
|
|
42
|
+
tryAdd(plugin);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional host shell whitelabeling (sidebar, login, document title).
|
|
3
|
+
* `logoPath` is resolved relative to the consumer project root.
|
|
4
|
+
*/
|
|
5
|
+
export interface CodemationWhitelabelConfig {
|
|
6
|
+
readonly productName?: string;
|
|
7
|
+
/** Relative to consumer project root, e.g. `branding/logo.svg`. */
|
|
8
|
+
readonly logoPath?: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
export class ApiPaths {
|
|
2
|
+
private static readonly apiBasePath = "/api";
|
|
3
|
+
|
|
4
|
+
private static readonly workflowsBasePath = `${this.apiBasePath}/workflows`;
|
|
5
|
+
|
|
6
|
+
private static readonly runsBasePath = `${this.apiBasePath}/runs`;
|
|
7
|
+
|
|
8
|
+
private static readonly credentialsBasePath = `${this.apiBasePath}/credentials`;
|
|
9
|
+
|
|
10
|
+
private static readonly oauth2BasePath = `${this.apiBasePath}/oauth2`;
|
|
11
|
+
|
|
12
|
+
private static readonly webhooksBasePath = `${this.apiBasePath}/webhooks`;
|
|
13
|
+
|
|
14
|
+
private static readonly usersBasePath = `${this.apiBasePath}/users`;
|
|
15
|
+
|
|
16
|
+
private static readonly whitelabelBasePath = `${this.apiBasePath}/whitelabel`;
|
|
17
|
+
|
|
18
|
+
static workflows(): string {
|
|
19
|
+
return this.workflowsBasePath;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static workflow(workflowId: string): string {
|
|
23
|
+
return `${this.workflowsBasePath}/${encodeURIComponent(workflowId)}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static workflowActivation(workflowId: string): string {
|
|
27
|
+
return `${this.workflow(workflowId)}/activation`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static workflowRuns(workflowId: string): string {
|
|
31
|
+
return `${this.workflow(workflowId)}/runs`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static workflowCredentialHealth(workflowId: string): string {
|
|
35
|
+
return `${this.workflow(workflowId)}/credential-health`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static workflowDebuggerOverlay(workflowId: string): string {
|
|
39
|
+
return `${this.workflow(workflowId)}/debugger-overlay`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static workflowDebuggerOverlayCopyRun(workflowId: string): string {
|
|
43
|
+
return `${this.workflowDebuggerOverlay(workflowId)}/copy-run`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static workflowDebuggerOverlayBinaryUpload(workflowId: string): string {
|
|
47
|
+
return `${this.workflowDebuggerOverlay(workflowId)}/binary/upload`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static workflowOverlayBinaryContent(workflowId: string, binaryId: string): string {
|
|
51
|
+
return `${this.workflow(workflowId)}/debugger-overlay/binary/${encodeURIComponent(binaryId)}/content`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static runs(): string {
|
|
55
|
+
return this.runsBasePath;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static run(): string {
|
|
59
|
+
return this.runs();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static credentialTypes(): string {
|
|
63
|
+
return `${this.credentialsBasePath}/types`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static credentialsEnvStatus(): string {
|
|
67
|
+
return `${this.credentialsBasePath}/env-status`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static credentialInstances(): string {
|
|
71
|
+
return `${this.credentialsBasePath}/instances`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static credentialInstance(instanceId: string, withSecrets?: boolean): string {
|
|
75
|
+
const base = `${this.credentialInstances()}/${encodeURIComponent(instanceId)}`;
|
|
76
|
+
return withSecrets ? `${base}?withSecrets=1` : base;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static credentialInstanceTest(instanceId: string): string {
|
|
80
|
+
return `${this.credentialInstance(instanceId)}/test`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static credentialBindings(): string {
|
|
84
|
+
return `${this.apiBasePath}/credential-bindings`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static oauth2Auth(instanceId: string): string {
|
|
88
|
+
return `${this.oauth2BasePath}/auth?instanceId=${encodeURIComponent(instanceId)}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static oauth2RedirectUri(): string {
|
|
92
|
+
return `${this.oauth2BasePath}/redirect-uri`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static oauth2Disconnect(instanceId: string): string {
|
|
96
|
+
return `${this.oauth2BasePath}/disconnect?instanceId=${encodeURIComponent(instanceId)}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static workflowWebsocket(): string {
|
|
100
|
+
return `${this.workflowsBasePath}/ws`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Dev gateway: stable browser WebSocket for build lifecycle (CLI → gateway → browser). */
|
|
104
|
+
static devGatewaySocket(): string {
|
|
105
|
+
return `${this.apiBasePath}/dev/socket`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Dev gateway: HTTP notify endpoint used by the Codemation CLI during consumer rebuilds. */
|
|
109
|
+
static devGatewayNotify(): string {
|
|
110
|
+
return `${this.apiBasePath}/dev/notify`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static webhooks(): string {
|
|
114
|
+
return this.webhooksBasePath;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static users(): string {
|
|
118
|
+
return this.usersBasePath;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static userInviteVerify(): string {
|
|
122
|
+
return `${this.usersBasePath}/invites/verify`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static userInviteAccept(): string {
|
|
126
|
+
return `${this.usersBasePath}/invites/accept`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static userInvites(): string {
|
|
130
|
+
return `${this.usersBasePath}/invites`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static userInviteRegenerate(userId: string): string {
|
|
134
|
+
return `${this.usersBasePath}/${encodeURIComponent(userId)}/invites/regenerate`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static userStatus(userId: string): string {
|
|
138
|
+
return `${this.usersBasePath}/${encodeURIComponent(userId)}/status`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static runState(runId: string): string {
|
|
142
|
+
return `${this.runsBasePath}/${encodeURIComponent(runId)}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static runWorkflowSnapshot(runId: string): string {
|
|
146
|
+
return `${this.runState(runId)}/workflow-snapshot`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static runNodePin(runId: string, nodeId: string): string {
|
|
150
|
+
return `${this.runState(runId)}/nodes/${encodeURIComponent(nodeId)}/pin`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
static runNode(runId: string, nodeId: string): string {
|
|
154
|
+
return `${this.runState(runId)}/nodes/${encodeURIComponent(nodeId)}/run`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static runBinaryContent(runId: string, binaryId: string): string {
|
|
158
|
+
return `${this.runState(runId)}/binary/${encodeURIComponent(binaryId)}/content`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Anonymous: consumer logo from `codemation.config.ts` whitelabel.logoPath. */
|
|
162
|
+
static whitelabelLogo(): string {
|
|
163
|
+
return `${this.whitelabelBasePath}/logo`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { accessSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { QueryBus } from "../../application/bus/QueryBus";
|
|
4
|
+
import type { WorkflowDto, WorkflowSummary } from "../../application/contracts/WorkflowViewContracts";
|
|
5
|
+
import { WorkflowDefinitionMapper } from "../../application/mapping/WorkflowDefinitionMapper";
|
|
6
|
+
import { GetWorkflowDetailQuery } from "../../application/queries/GetWorkflowDetailQuery";
|
|
7
|
+
import { GetWorkflowSummariesQuery } from "../../application/queries/GetWorkflowSummariesQuery";
|
|
8
|
+
import { ApplicationTokens } from "../../applicationTokens";
|
|
9
|
+
import { CodemationApplication } from "../../codemationApplication";
|
|
10
|
+
import { CodemationBootstrapRequest } from "../../bootstrap/CodemationBootstrapRequest";
|
|
11
|
+
import { CodemationFrontendBootstrapRequest } from "../../bootstrap/CodemationFrontendBootstrapRequest";
|
|
12
|
+
import type { CodemationConfig } from "../config/CodemationConfig";
|
|
13
|
+
import { CodemationHonoApiApp } from "./hono/CodemationHonoApiAppFactory";
|
|
14
|
+
|
|
15
|
+
type ServerGatewayContext = Readonly<{
|
|
16
|
+
application: CodemationApplication;
|
|
17
|
+
httpApi: CodemationHonoApiApp;
|
|
18
|
+
queryBus: QueryBus;
|
|
19
|
+
workflowDefinitionMapper: WorkflowDefinitionMapper;
|
|
20
|
+
}>;
|
|
21
|
+
|
|
22
|
+
export class CodemationServerGateway {
|
|
23
|
+
private static readonly contextsByConfig = new WeakMap<object, Promise<ServerGatewayContext>>();
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private readonly config: CodemationConfig,
|
|
27
|
+
private readonly consumerRoot: string,
|
|
28
|
+
private readonly configSource?: string,
|
|
29
|
+
private readonly workflowSources: ReadonlyArray<string> = [],
|
|
30
|
+
private readonly env?: Readonly<NodeJS.ProcessEnv>,
|
|
31
|
+
) {}
|
|
32
|
+
|
|
33
|
+
async dispatch(request: Request): Promise<Response> {
|
|
34
|
+
return await (await this.getContext()).httpApi.fetch(request);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async prepare(): Promise<void> {
|
|
38
|
+
await this.getContext();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async close(): Promise<void> {
|
|
42
|
+
const cachedContext = CodemationServerGateway.contextsByConfig.get(this.config as object);
|
|
43
|
+
if (!cachedContext) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
CodemationServerGateway.contextsByConfig.delete(this.config as object);
|
|
47
|
+
await (await cachedContext).application.stop();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async loadWorkflowSummaries(): Promise<ReadonlyArray<WorkflowSummary>> {
|
|
51
|
+
const context = await this.getContext();
|
|
52
|
+
const workflows = await context.queryBus.execute(new GetWorkflowSummariesQuery());
|
|
53
|
+
return workflows.map((workflow) => context.workflowDefinitionMapper.toSummary(workflow));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async loadWorkflowDetail(workflowId: string): Promise<WorkflowDto> {
|
|
57
|
+
const context = await this.getContext();
|
|
58
|
+
const workflow = await context.queryBus.execute(new GetWorkflowDetailQuery(workflowId));
|
|
59
|
+
if (!workflow) {
|
|
60
|
+
throw new Error(`Unknown workflowId: ${workflowId}`);
|
|
61
|
+
}
|
|
62
|
+
return await context.workflowDefinitionMapper.map(workflow);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private getContext(): Promise<ServerGatewayContext> {
|
|
66
|
+
const cachedContext = CodemationServerGateway.contextsByConfig.get(this.config as object);
|
|
67
|
+
if (cachedContext) {
|
|
68
|
+
return cachedContext;
|
|
69
|
+
}
|
|
70
|
+
const nextContext = this.createContext();
|
|
71
|
+
CodemationServerGateway.contextsByConfig.set(this.config as object, nextContext);
|
|
72
|
+
return nextContext;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private async createContext(): Promise<ServerGatewayContext> {
|
|
76
|
+
const repoRoot = this.detectWorkspaceRoot(this.consumerRoot);
|
|
77
|
+
const bootstrapRequest = new CodemationBootstrapRequest({
|
|
78
|
+
repoRoot,
|
|
79
|
+
consumerRoot: this.consumerRoot,
|
|
80
|
+
env: this.env,
|
|
81
|
+
workflowSources: this.resolveWorkflowSources(),
|
|
82
|
+
});
|
|
83
|
+
const application = new CodemationApplication();
|
|
84
|
+
application.useConfig(this.config);
|
|
85
|
+
await application.applyPlugins(bootstrapRequest);
|
|
86
|
+
await application.prepareContainer(bootstrapRequest);
|
|
87
|
+
await application.bootFrontend(new CodemationFrontendBootstrapRequest({ bootstrap: bootstrapRequest }));
|
|
88
|
+
return {
|
|
89
|
+
application,
|
|
90
|
+
httpApi: application.getContainer().resolve(CodemationHonoApiApp),
|
|
91
|
+
queryBus: application.getContainer().resolve(ApplicationTokens.QueryBus),
|
|
92
|
+
workflowDefinitionMapper: application.getContainer().resolve(WorkflowDefinitionMapper),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private resolveWorkflowSources(): ReadonlyArray<string> {
|
|
97
|
+
if (this.workflowSources.length > 0) {
|
|
98
|
+
return [...this.workflowSources];
|
|
99
|
+
}
|
|
100
|
+
if (!this.configSource || !this.config.workflows || this.config.workflows.length === 0) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
return [this.configSource];
|
|
104
|
+
}
|
|
105
|
+
private detectWorkspaceRoot(startDirectory: string): string {
|
|
106
|
+
let currentDirectory = path.resolve(startDirectory);
|
|
107
|
+
while (true) {
|
|
108
|
+
try {
|
|
109
|
+
accessSync(path.resolve(currentDirectory, "pnpm-workspace.yaml"));
|
|
110
|
+
return currentDirectory;
|
|
111
|
+
} catch {
|
|
112
|
+
const parentDirectory = path.dirname(currentDirectory);
|
|
113
|
+
if (parentDirectory === currentDirectory) {
|
|
114
|
+
return startDirectory;
|
|
115
|
+
}
|
|
116
|
+
currentDirectory = parentDirectory;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApplicationRequestError } from "../../application/ApplicationRequestError";
|
|
2
|
+
|
|
3
|
+
export class HttpRequestJsonBodyReader {
|
|
4
|
+
static async readJsonBody<TBody>(request: Request): Promise<TBody> {
|
|
5
|
+
try {
|
|
6
|
+
return (await request.json()) as TBody;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9
|
+
throw new ApplicationRequestError(400, `Invalid JSON body: ${message}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ApplicationRequestError } from "../../application/ApplicationRequestError";
|
|
2
|
+
|
|
3
|
+
export class ServerHttpErrorResponseFactory {
|
|
4
|
+
static fromUnknown(error: unknown): Response {
|
|
5
|
+
if (error instanceof ApplicationRequestError) {
|
|
6
|
+
return Response.json(error.payload, { status: error.status });
|
|
7
|
+
}
|
|
8
|
+
this.logUnexpectedError(error);
|
|
9
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10
|
+
return Response.json({ error: message }, { status: 500 });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
private static logUnexpectedError(error: unknown): void {
|
|
14
|
+
if (error instanceof Error) {
|
|
15
|
+
const stack = error.stack ?? `${error.name}: ${error.message}`;
|
|
16
|
+
const causeText = this.formatCause(error);
|
|
17
|
+
console.error(`[codemation-http] unhandled route error\n${stack}${causeText}`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
console.error(`[codemation-http] unhandled route error\n${String(error)}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private static formatCause(error: Error): string {
|
|
24
|
+
if (!(error instanceof Error) || !("cause" in error) || !error.cause) {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
const cause = error.cause;
|
|
28
|
+
if (cause instanceof Error) {
|
|
29
|
+
return `\nCaused by:\n${cause.stack ?? `${cause.name}: ${cause.message}`}`;
|
|
30
|
+
}
|
|
31
|
+
return `\nCaused by:\n${String(cause)}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ServerHttpRouteParams = Readonly<Record<string, string>>;
|