@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,91 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type {
|
|
3
|
+
CodemationApplicationRuntimeConfig,
|
|
4
|
+
CodemationDatabaseConfig,
|
|
5
|
+
CodemationDatabaseKind,
|
|
6
|
+
} from "../../presentation/config/CodemationConfig";
|
|
7
|
+
|
|
8
|
+
export type ResolvedDatabasePersistence =
|
|
9
|
+
| Readonly<{ kind: "none" }>
|
|
10
|
+
| Readonly<{ kind: "postgresql"; databaseUrl: string }>
|
|
11
|
+
| Readonly<{ kind: "pglite"; dataDir: string }>;
|
|
12
|
+
|
|
13
|
+
const DEFAULT_PGLITE_RELATIVE_DIR = ".codemation/pglite";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolves whether persistence uses TCP PostgreSQL, embedded PGlite, or in-memory stores.
|
|
17
|
+
* Uses {@link CodemationConfig.runtime.database} as the source of truth; optional `CODEMATION_DATABASE_KIND`
|
|
18
|
+
* and `CODEMATION_PGLITE_DATA_DIR` can override kind / PGlite directory. `DATABASE_URL` is not read here—put
|
|
19
|
+
* connection strings in `runtime.database.url` (often sourced from `process.env` inside `codemation.config.ts`).
|
|
20
|
+
*/
|
|
21
|
+
export class DatabasePersistenceResolver {
|
|
22
|
+
resolve(
|
|
23
|
+
args: Readonly<{ runtimeConfig: CodemationApplicationRuntimeConfig; env: NodeJS.ProcessEnv; consumerRoot: string }>,
|
|
24
|
+
): ResolvedDatabasePersistence {
|
|
25
|
+
const db = args.runtimeConfig.database;
|
|
26
|
+
if (!db) {
|
|
27
|
+
return { kind: "none" };
|
|
28
|
+
}
|
|
29
|
+
const kind = this.resolveDatabaseKind(this.inferDatabaseKind(db), args.env);
|
|
30
|
+
if (kind === "postgresql") {
|
|
31
|
+
const url = db.url?.trim() ?? "";
|
|
32
|
+
if (!url) {
|
|
33
|
+
throw new Error('runtime.database.kind is "postgresql" but no database URL was set (runtime.database.url).');
|
|
34
|
+
}
|
|
35
|
+
if (!this.isPostgresUrl(url)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`runtime.database.url must be a postgresql:// or postgres:// URL when kind is postgresql. Received: ${url}`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return { kind: "postgresql", databaseUrl: url };
|
|
41
|
+
}
|
|
42
|
+
const dataDir = this.resolvePgliteDataDirFromConfig(db, args.env, args.consumerRoot);
|
|
43
|
+
return { kind: "pglite", dataDir };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
resolveDatabaseKind(configured: CodemationDatabaseKind | undefined, env: NodeJS.ProcessEnv): CodemationDatabaseKind {
|
|
47
|
+
const fromEnv = env.CODEMATION_DATABASE_KIND?.trim();
|
|
48
|
+
if (fromEnv === "postgresql" || fromEnv === "pglite") {
|
|
49
|
+
return fromEnv;
|
|
50
|
+
}
|
|
51
|
+
if (configured) {
|
|
52
|
+
return configured;
|
|
53
|
+
}
|
|
54
|
+
return "pglite";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private inferDatabaseKind(db: CodemationDatabaseConfig): CodemationDatabaseKind {
|
|
58
|
+
if (db.kind) {
|
|
59
|
+
return db.kind;
|
|
60
|
+
}
|
|
61
|
+
const url = db.url?.trim();
|
|
62
|
+
if (url && this.isPostgresUrl(url)) {
|
|
63
|
+
return "postgresql";
|
|
64
|
+
}
|
|
65
|
+
return "pglite";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
isPostgresUrl(value: string): boolean {
|
|
69
|
+
return value.startsWith("postgresql://") || value.startsWith("postgres://");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
isPgliteUrl(value: string): boolean {
|
|
73
|
+
return value.startsWith("pglite:");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private resolvePgliteDataDirFromConfig(
|
|
77
|
+
db: NonNullable<CodemationApplicationRuntimeConfig["database"]>,
|
|
78
|
+
env: NodeJS.ProcessEnv,
|
|
79
|
+
consumerRoot: string,
|
|
80
|
+
): string {
|
|
81
|
+
const fromEnv = env.CODEMATION_PGLITE_DATA_DIR?.trim();
|
|
82
|
+
if (fromEnv && fromEnv.length > 0) {
|
|
83
|
+
return path.isAbsolute(fromEnv) ? fromEnv : path.resolve(consumerRoot, fromEnv);
|
|
84
|
+
}
|
|
85
|
+
const configured = db.pgliteDataDir?.trim();
|
|
86
|
+
if (configured && configured.length > 0) {
|
|
87
|
+
return path.isAbsolute(configured) ? configured : path.resolve(consumerRoot, configured);
|
|
88
|
+
}
|
|
89
|
+
return path.resolve(consumerRoot, DEFAULT_PGLITE_RELATIVE_DIR);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PersistedTriggerSetupState, TriggerInstanceId, TriggerSetupStateRepository } from "@codemation/core";
|
|
2
|
+
import { injectable } from "@codemation/core";
|
|
3
|
+
|
|
4
|
+
@injectable()
|
|
5
|
+
export class InMemoryTriggerSetupStateRepository implements TriggerSetupStateRepository {
|
|
6
|
+
private readonly statesByKey = new Map<string, PersistedTriggerSetupState>();
|
|
7
|
+
|
|
8
|
+
async load(trigger: TriggerInstanceId): Promise<PersistedTriggerSetupState | undefined> {
|
|
9
|
+
return this.statesByKey.get(this.toKey(trigger));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async save(state: PersistedTriggerSetupState): Promise<void> {
|
|
13
|
+
this.statesByKey.set(this.toKey(state.trigger), state);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async delete(trigger: TriggerInstanceId): Promise<void> {
|
|
17
|
+
this.statesByKey.delete(this.toKey(trigger));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private toKey(trigger: TriggerInstanceId): string {
|
|
21
|
+
return `${trigger.workflowId}:${trigger.nodeId}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { injectable } from "@codemation/core";
|
|
2
|
+
import type {
|
|
3
|
+
WorkflowActivationRepository,
|
|
4
|
+
WorkflowActivationRow,
|
|
5
|
+
} from "../../domain/workflows/WorkflowActivationRepository";
|
|
6
|
+
|
|
7
|
+
@injectable()
|
|
8
|
+
export class InMemoryWorkflowActivationRepository implements WorkflowActivationRepository {
|
|
9
|
+
private readonly rows = new Map<string, boolean>();
|
|
10
|
+
|
|
11
|
+
async loadAll(): Promise<ReadonlyArray<WorkflowActivationRow>> {
|
|
12
|
+
return [...this.rows.entries()].map(([workflowId, isActive]) => ({ workflowId, isActive }));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async upsert(workflowId: string, active: boolean): Promise<void> {
|
|
16
|
+
this.rows.set(decodeURIComponent(workflowId), active);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { injectable } from "@codemation/core";
|
|
2
|
+
import type { WorkflowDebuggerOverlayRepository } from "../../domain/workflows/WorkflowDebuggerOverlayRepository";
|
|
3
|
+
import type { WorkflowDebuggerOverlayState } from "../../domain/workflows/WorkflowDebuggerOverlayState";
|
|
4
|
+
|
|
5
|
+
@injectable()
|
|
6
|
+
export class InMemoryWorkflowDebuggerOverlayRepository implements WorkflowDebuggerOverlayRepository {
|
|
7
|
+
private readonly overlays = new Map<string, WorkflowDebuggerOverlayState>();
|
|
8
|
+
|
|
9
|
+
async load(workflowId: string): Promise<WorkflowDebuggerOverlayState | undefined> {
|
|
10
|
+
return this.overlays.get(decodeURIComponent(workflowId));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async save(state: WorkflowDebuggerOverlayState): Promise<void> {
|
|
14
|
+
this.overlays.set(state.workflowId, state);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RunFinishedAtFactory,
|
|
3
|
+
type NodeId,
|
|
4
|
+
type NodeOutputs,
|
|
5
|
+
type ParentExecutionRef,
|
|
6
|
+
type PersistedRunState,
|
|
7
|
+
type RunId,
|
|
8
|
+
type RunPruneCandidate,
|
|
9
|
+
type RunSummary,
|
|
10
|
+
type WorkflowExecutionRepository,
|
|
11
|
+
type WorkflowId,
|
|
12
|
+
} from "@codemation/core";
|
|
13
|
+
import { injectable } from "@codemation/core";
|
|
14
|
+
import { RunSummaryMapper } from "@codemation/core/bootstrap";
|
|
15
|
+
import type { WorkflowRunRepository } from "../../domain/runs/WorkflowRunRepository";
|
|
16
|
+
|
|
17
|
+
@injectable()
|
|
18
|
+
export class InMemoryWorkflowRunRepository implements WorkflowRunRepository, WorkflowExecutionRepository {
|
|
19
|
+
private readonly runs = new Map<RunId, PersistedRunState>();
|
|
20
|
+
|
|
21
|
+
async createRun(args: {
|
|
22
|
+
runId: RunId;
|
|
23
|
+
workflowId: WorkflowId;
|
|
24
|
+
startedAt: string;
|
|
25
|
+
parent?: ParentExecutionRef;
|
|
26
|
+
executionOptions?: PersistedRunState["executionOptions"];
|
|
27
|
+
control?: PersistedRunState["control"];
|
|
28
|
+
workflowSnapshot?: PersistedRunState["workflowSnapshot"];
|
|
29
|
+
mutableState?: PersistedRunState["mutableState"];
|
|
30
|
+
policySnapshot?: PersistedRunState["policySnapshot"];
|
|
31
|
+
engineCounters?: PersistedRunState["engineCounters"];
|
|
32
|
+
}): Promise<void> {
|
|
33
|
+
this.runs.set(args.runId, {
|
|
34
|
+
runId: args.runId,
|
|
35
|
+
workflowId: args.workflowId,
|
|
36
|
+
startedAt: args.startedAt,
|
|
37
|
+
parent: args.parent,
|
|
38
|
+
executionOptions: args.executionOptions,
|
|
39
|
+
control: args.control,
|
|
40
|
+
workflowSnapshot: args.workflowSnapshot,
|
|
41
|
+
mutableState: args.mutableState,
|
|
42
|
+
policySnapshot: args.policySnapshot,
|
|
43
|
+
engineCounters: args.engineCounters,
|
|
44
|
+
status: "running",
|
|
45
|
+
queue: [],
|
|
46
|
+
outputsByNode: {} as Record<NodeId, NodeOutputs>,
|
|
47
|
+
nodeSnapshotsByNodeId: {},
|
|
48
|
+
connectionInvocations: [],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async load(runId: string): Promise<PersistedRunState | undefined> {
|
|
53
|
+
return this.runs.get(decodeURIComponent(runId) as RunId);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async save(state: PersistedRunState): Promise<void> {
|
|
57
|
+
this.runs.set(state.runId, state);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async deleteRun(runId: RunId): Promise<void> {
|
|
61
|
+
this.runs.delete(runId);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async listRuns(args: Readonly<{ workflowId?: string; limit?: number }>): Promise<ReadonlyArray<RunSummary>> {
|
|
65
|
+
const limit = args?.limit ?? 50;
|
|
66
|
+
const workflowId = args?.workflowId ? decodeURIComponent(args.workflowId) : undefined;
|
|
67
|
+
const summaries = [...this.runs.values()]
|
|
68
|
+
.filter((s) => (workflowId ? s.workflowId === workflowId : true))
|
|
69
|
+
.sort((a, b) => b.startedAt.localeCompare(a.startedAt))
|
|
70
|
+
.slice(0, limit)
|
|
71
|
+
.map((s) => RunSummaryMapper.fromPersistedState(s));
|
|
72
|
+
return summaries;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async listRunsOlderThan(
|
|
76
|
+
args: Readonly<{ beforeIso: string; limit?: number }>,
|
|
77
|
+
): Promise<ReadonlyArray<RunPruneCandidate>> {
|
|
78
|
+
const limit = args.limit ?? 100;
|
|
79
|
+
const out: RunPruneCandidate[] = [];
|
|
80
|
+
for (const s of this.runs.values()) {
|
|
81
|
+
if (s.status !== "completed" && s.status !== "failed") continue;
|
|
82
|
+
const finishedAt = RunFinishedAtFactory.resolveIso(s);
|
|
83
|
+
if (!finishedAt || finishedAt >= args.beforeIso) continue;
|
|
84
|
+
out.push({
|
|
85
|
+
runId: s.runId,
|
|
86
|
+
workflowId: s.workflowId,
|
|
87
|
+
startedAt: s.startedAt,
|
|
88
|
+
finishedAt,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
out.sort((a, b) => a.finishedAt.localeCompare(b.finishedAt));
|
|
92
|
+
return out.slice(0, limit);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import { injectable } from "@codemation/core";
|
|
3
|
+
import { PrismaPg } from "@prisma/adapter-pg";
|
|
4
|
+
import { PrismaPGlite } from "pglite-prisma-adapter";
|
|
5
|
+
import { PrismaClient } from "./generated/prisma-client/client.js";
|
|
6
|
+
|
|
7
|
+
export type PglitePrismaClients = Readonly<{
|
|
8
|
+
prismaClient: PrismaClient;
|
|
9
|
+
pglite: PGlite;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
@injectable()
|
|
13
|
+
export class PrismaClientFactory {
|
|
14
|
+
createPostgres(databaseUrl: string): PrismaClient {
|
|
15
|
+
const adapter = new PrismaPg({ connectionString: databaseUrl });
|
|
16
|
+
return new PrismaClient({ adapter });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async createPglite(dataDir: string): Promise<PglitePrismaClients> {
|
|
20
|
+
const pglite = new PGlite(dataDir);
|
|
21
|
+
await pglite.waitReady;
|
|
22
|
+
const adapter = new PrismaPGlite(pglite);
|
|
23
|
+
const prismaClient = new PrismaClient({ adapter });
|
|
24
|
+
return { prismaClient, pglite };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { inject, injectable } from "@codemation/core";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
CredentialInstanceRecord,
|
|
5
|
+
CredentialOAuth2MaterialMetadata,
|
|
6
|
+
CredentialOAuth2MaterialRecord,
|
|
7
|
+
CredentialOAuth2StateRecord,
|
|
8
|
+
CredentialSecretMaterialRecord,
|
|
9
|
+
CredentialStore,
|
|
10
|
+
CredentialTestRecord,
|
|
11
|
+
} from "../../domain/credentials/CredentialServices";
|
|
12
|
+
|
|
13
|
+
import { PrismaClient } from "./generated/prisma-client/client.js";
|
|
14
|
+
|
|
15
|
+
@injectable()
|
|
16
|
+
export class PrismaCredentialStore implements CredentialStore {
|
|
17
|
+
constructor(@inject(PrismaClient) private readonly prisma: PrismaClient) {}
|
|
18
|
+
|
|
19
|
+
async listInstances(): Promise<ReadonlyArray<CredentialInstanceRecord>> {
|
|
20
|
+
const rows = await this.prisma.credentialInstance.findMany({
|
|
21
|
+
orderBy: { updatedAt: "desc" },
|
|
22
|
+
});
|
|
23
|
+
return rows.map((row) => this.toInstanceRecord(row));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getInstance(instanceId: string): Promise<CredentialInstanceRecord | undefined> {
|
|
27
|
+
const row = await this.prisma.credentialInstance.findUnique({
|
|
28
|
+
where: { instanceId },
|
|
29
|
+
});
|
|
30
|
+
return row ? this.toInstanceRecord(row) : undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async saveInstance(
|
|
34
|
+
args: Readonly<{ instance: CredentialInstanceRecord; secretMaterial?: CredentialSecretMaterialRecord }>,
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
await this.prisma.$transaction(async (transaction) => {
|
|
37
|
+
await transaction.credentialInstance.upsert({
|
|
38
|
+
where: { instanceId: args.instance.instanceId },
|
|
39
|
+
create: {
|
|
40
|
+
instanceId: args.instance.instanceId,
|
|
41
|
+
typeId: args.instance.typeId,
|
|
42
|
+
displayName: args.instance.displayName,
|
|
43
|
+
sourceKind: args.instance.sourceKind,
|
|
44
|
+
publicConfigJson: JSON.stringify(args.instance.publicConfig),
|
|
45
|
+
secretRefJson: JSON.stringify(args.instance.secretRef),
|
|
46
|
+
tagsJson: JSON.stringify(args.instance.tags),
|
|
47
|
+
setupStatus: args.instance.setupStatus,
|
|
48
|
+
createdAt: args.instance.createdAt,
|
|
49
|
+
updatedAt: args.instance.updatedAt,
|
|
50
|
+
},
|
|
51
|
+
update: {
|
|
52
|
+
typeId: args.instance.typeId,
|
|
53
|
+
displayName: args.instance.displayName,
|
|
54
|
+
sourceKind: args.instance.sourceKind,
|
|
55
|
+
publicConfigJson: JSON.stringify(args.instance.publicConfig),
|
|
56
|
+
secretRefJson: JSON.stringify(args.instance.secretRef),
|
|
57
|
+
tagsJson: JSON.stringify(args.instance.tags),
|
|
58
|
+
setupStatus: args.instance.setupStatus,
|
|
59
|
+
updatedAt: args.instance.updatedAt,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
if (args.secretMaterial) {
|
|
63
|
+
await transaction.credentialSecretMaterial.upsert({
|
|
64
|
+
where: { instanceId: args.secretMaterial.instanceId },
|
|
65
|
+
create: {
|
|
66
|
+
instanceId: args.secretMaterial.instanceId,
|
|
67
|
+
encryptedJson: args.secretMaterial.encryptedJson,
|
|
68
|
+
encryptionKeyId: args.secretMaterial.encryptionKeyId,
|
|
69
|
+
schemaVersion: args.secretMaterial.schemaVersion,
|
|
70
|
+
updatedAt: args.secretMaterial.updatedAt,
|
|
71
|
+
},
|
|
72
|
+
update: {
|
|
73
|
+
encryptedJson: args.secretMaterial.encryptedJson,
|
|
74
|
+
encryptionKeyId: args.secretMaterial.encryptionKeyId,
|
|
75
|
+
schemaVersion: args.secretMaterial.schemaVersion,
|
|
76
|
+
updatedAt: args.secretMaterial.updatedAt,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async deleteInstance(instanceId: string): Promise<void> {
|
|
84
|
+
await this.prisma.$transaction(async (transaction) => {
|
|
85
|
+
await transaction.credentialOAuth2State.deleteMany({ where: { instanceId } });
|
|
86
|
+
await transaction.credentialOAuth2Material.deleteMany({ where: { instanceId } });
|
|
87
|
+
await transaction.credentialTestResult.deleteMany({ where: { instanceId } });
|
|
88
|
+
await transaction.credentialBinding.deleteMany({ where: { instanceId } });
|
|
89
|
+
await transaction.credentialSecretMaterial.deleteMany({ where: { instanceId } });
|
|
90
|
+
await transaction.credentialInstance.deleteMany({ where: { instanceId } });
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async getSecretMaterial(instanceId: string): Promise<CredentialSecretMaterialRecord | undefined> {
|
|
95
|
+
const row = await this.prisma.credentialSecretMaterial.findUnique({
|
|
96
|
+
where: { instanceId },
|
|
97
|
+
});
|
|
98
|
+
return row
|
|
99
|
+
? {
|
|
100
|
+
instanceId: row.instanceId,
|
|
101
|
+
encryptedJson: row.encryptedJson,
|
|
102
|
+
encryptionKeyId: row.encryptionKeyId,
|
|
103
|
+
schemaVersion: row.schemaVersion,
|
|
104
|
+
updatedAt: row.updatedAt,
|
|
105
|
+
}
|
|
106
|
+
: undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async createOAuth2State(record: CredentialOAuth2StateRecord): Promise<void> {
|
|
110
|
+
await this.prisma.credentialOAuth2State.create({
|
|
111
|
+
data: {
|
|
112
|
+
state: record.state,
|
|
113
|
+
instanceId: record.instanceId,
|
|
114
|
+
codeVerifier: record.codeVerifier ?? null,
|
|
115
|
+
providerId: record.providerId ?? null,
|
|
116
|
+
requestedScopesJson: JSON.stringify(record.requestedScopes),
|
|
117
|
+
createdAt: record.createdAt,
|
|
118
|
+
expiresAt: record.expiresAt,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async consumeOAuth2State(state: string): Promise<CredentialOAuth2StateRecord | undefined> {
|
|
124
|
+
return await this.prisma.$transaction(async (transaction) => {
|
|
125
|
+
const row = await transaction.credentialOAuth2State.findUnique({
|
|
126
|
+
where: { state },
|
|
127
|
+
});
|
|
128
|
+
if (!row) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
await transaction.credentialOAuth2State.delete({
|
|
132
|
+
where: { state },
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
state: row.state,
|
|
136
|
+
instanceId: row.instanceId,
|
|
137
|
+
codeVerifier: row.codeVerifier ?? undefined,
|
|
138
|
+
providerId: row.providerId ?? undefined,
|
|
139
|
+
requestedScopes: JSON.parse(row.requestedScopesJson) as ReadonlyArray<string>,
|
|
140
|
+
createdAt: row.createdAt,
|
|
141
|
+
expiresAt: row.expiresAt,
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async getOAuth2Material(instanceId: string): Promise<CredentialOAuth2MaterialRecord | undefined> {
|
|
147
|
+
const row = await this.prisma.credentialOAuth2Material.findUnique({
|
|
148
|
+
where: { instanceId },
|
|
149
|
+
});
|
|
150
|
+
return row
|
|
151
|
+
? {
|
|
152
|
+
instanceId: row.instanceId,
|
|
153
|
+
encryptedJson: row.encryptedJson,
|
|
154
|
+
encryptionKeyId: row.encryptionKeyId,
|
|
155
|
+
schemaVersion: row.schemaVersion,
|
|
156
|
+
providerId: row.providerId,
|
|
157
|
+
connectedEmail: row.connectedEmail ?? undefined,
|
|
158
|
+
connectedAt: row.connectedAt ?? undefined,
|
|
159
|
+
scopes: JSON.parse(row.scopesJson) as ReadonlyArray<string>,
|
|
160
|
+
updatedAt: row.updatedAt,
|
|
161
|
+
}
|
|
162
|
+
: undefined;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async saveOAuth2Material(
|
|
166
|
+
args: Readonly<{
|
|
167
|
+
instanceId: string;
|
|
168
|
+
encryptedJson: string;
|
|
169
|
+
encryptionKeyId: string;
|
|
170
|
+
schemaVersion: number;
|
|
171
|
+
metadata: CredentialOAuth2MaterialMetadata;
|
|
172
|
+
}>,
|
|
173
|
+
): Promise<void> {
|
|
174
|
+
await this.prisma.credentialOAuth2Material.upsert({
|
|
175
|
+
where: { instanceId: args.instanceId },
|
|
176
|
+
create: {
|
|
177
|
+
instanceId: args.instanceId,
|
|
178
|
+
encryptedJson: args.encryptedJson,
|
|
179
|
+
encryptionKeyId: args.encryptionKeyId,
|
|
180
|
+
schemaVersion: args.schemaVersion,
|
|
181
|
+
providerId: args.metadata.providerId,
|
|
182
|
+
connectedEmail: args.metadata.connectedEmail ?? null,
|
|
183
|
+
connectedAt: args.metadata.connectedAt ?? null,
|
|
184
|
+
scopesJson: JSON.stringify(args.metadata.scopes),
|
|
185
|
+
updatedAt: args.metadata.updatedAt,
|
|
186
|
+
},
|
|
187
|
+
update: {
|
|
188
|
+
encryptedJson: args.encryptedJson,
|
|
189
|
+
encryptionKeyId: args.encryptionKeyId,
|
|
190
|
+
schemaVersion: args.schemaVersion,
|
|
191
|
+
providerId: args.metadata.providerId,
|
|
192
|
+
connectedEmail: args.metadata.connectedEmail ?? null,
|
|
193
|
+
connectedAt: args.metadata.connectedAt ?? null,
|
|
194
|
+
scopesJson: JSON.stringify(args.metadata.scopes),
|
|
195
|
+
updatedAt: args.metadata.updatedAt,
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async deleteOAuth2Material(instanceId: string): Promise<void> {
|
|
201
|
+
await this.prisma.credentialOAuth2Material.deleteMany({
|
|
202
|
+
where: { instanceId },
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async upsertBinding(binding: import("@codemation/core").CredentialBinding): Promise<void> {
|
|
207
|
+
await this.prisma.credentialBinding.upsert({
|
|
208
|
+
where: {
|
|
209
|
+
workflowId_nodeId_slotKey: {
|
|
210
|
+
workflowId: binding.key.workflowId,
|
|
211
|
+
nodeId: binding.key.nodeId,
|
|
212
|
+
slotKey: binding.key.slotKey,
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
create: {
|
|
216
|
+
workflowId: binding.key.workflowId,
|
|
217
|
+
nodeId: binding.key.nodeId,
|
|
218
|
+
slotKey: binding.key.slotKey,
|
|
219
|
+
instanceId: binding.instanceId,
|
|
220
|
+
updatedAt: binding.updatedAt,
|
|
221
|
+
},
|
|
222
|
+
update: {
|
|
223
|
+
instanceId: binding.instanceId,
|
|
224
|
+
updatedAt: binding.updatedAt,
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async getBinding(
|
|
230
|
+
key: import("@codemation/core").CredentialBindingKey,
|
|
231
|
+
): Promise<import("@codemation/core").CredentialBinding | undefined> {
|
|
232
|
+
const row = await this.prisma.credentialBinding.findUnique({
|
|
233
|
+
where: {
|
|
234
|
+
workflowId_nodeId_slotKey: {
|
|
235
|
+
workflowId: key.workflowId,
|
|
236
|
+
nodeId: key.nodeId,
|
|
237
|
+
slotKey: key.slotKey,
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
return row
|
|
242
|
+
? {
|
|
243
|
+
key: {
|
|
244
|
+
workflowId: row.workflowId,
|
|
245
|
+
nodeId: row.nodeId,
|
|
246
|
+
slotKey: row.slotKey,
|
|
247
|
+
},
|
|
248
|
+
instanceId: row.instanceId,
|
|
249
|
+
updatedAt: row.updatedAt,
|
|
250
|
+
}
|
|
251
|
+
: undefined;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async listBindingsByWorkflowId(
|
|
255
|
+
workflowId: string,
|
|
256
|
+
): Promise<ReadonlyArray<import("@codemation/core").CredentialBinding>> {
|
|
257
|
+
const rows = await this.prisma.credentialBinding.findMany({
|
|
258
|
+
where: { workflowId },
|
|
259
|
+
});
|
|
260
|
+
return rows.map((row) => ({
|
|
261
|
+
key: {
|
|
262
|
+
workflowId: row.workflowId,
|
|
263
|
+
nodeId: row.nodeId,
|
|
264
|
+
slotKey: row.slotKey,
|
|
265
|
+
},
|
|
266
|
+
instanceId: row.instanceId,
|
|
267
|
+
updatedAt: row.updatedAt,
|
|
268
|
+
}));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async saveTestResult(record: CredentialTestRecord): Promise<void> {
|
|
272
|
+
await this.prisma.credentialTestResult.create({
|
|
273
|
+
data: {
|
|
274
|
+
testId: record.testId,
|
|
275
|
+
instanceId: record.instanceId,
|
|
276
|
+
status: record.health.status,
|
|
277
|
+
message: record.health.message ?? null,
|
|
278
|
+
detailsJson: JSON.stringify(record.health.details ?? {}),
|
|
279
|
+
testedAt: record.testedAt,
|
|
280
|
+
expiresAt: record.expiresAt ?? null,
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async getLatestTestResult(instanceId: string): Promise<CredentialTestRecord | undefined> {
|
|
286
|
+
const row = await this.prisma.credentialTestResult.findFirst({
|
|
287
|
+
where: { instanceId },
|
|
288
|
+
orderBy: { testedAt: "desc" },
|
|
289
|
+
});
|
|
290
|
+
return row ? this.toTestRecord(row) : undefined;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async getLatestTestResults(instanceIds: ReadonlyArray<string>): Promise<ReadonlyMap<string, CredentialTestRecord>> {
|
|
294
|
+
if (instanceIds.length === 0) {
|
|
295
|
+
return new Map();
|
|
296
|
+
}
|
|
297
|
+
const rows = await this.prisma.credentialTestResult.findMany({
|
|
298
|
+
where: {
|
|
299
|
+
instanceId: {
|
|
300
|
+
in: [...instanceIds],
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
orderBy: [{ instanceId: "asc" }, { testedAt: "desc" }],
|
|
304
|
+
});
|
|
305
|
+
const latestByInstanceId = new Map<string, CredentialTestRecord>();
|
|
306
|
+
for (const row of rows) {
|
|
307
|
+
if (latestByInstanceId.has(row.instanceId)) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
latestByInstanceId.set(row.instanceId, this.toTestRecord(row));
|
|
311
|
+
}
|
|
312
|
+
return latestByInstanceId;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private toInstanceRecord(
|
|
316
|
+
row: Readonly<{
|
|
317
|
+
instanceId: string;
|
|
318
|
+
typeId: string;
|
|
319
|
+
displayName: string;
|
|
320
|
+
sourceKind: string;
|
|
321
|
+
publicConfigJson: string;
|
|
322
|
+
secretRefJson: string;
|
|
323
|
+
tagsJson: string;
|
|
324
|
+
setupStatus: string;
|
|
325
|
+
createdAt: string;
|
|
326
|
+
updatedAt: string;
|
|
327
|
+
}>,
|
|
328
|
+
): CredentialInstanceRecord {
|
|
329
|
+
return {
|
|
330
|
+
instanceId: row.instanceId,
|
|
331
|
+
typeId: row.typeId,
|
|
332
|
+
displayName: row.displayName,
|
|
333
|
+
sourceKind: row.sourceKind as CredentialInstanceRecord["sourceKind"],
|
|
334
|
+
publicConfig: JSON.parse(row.publicConfigJson) as CredentialInstanceRecord["publicConfig"],
|
|
335
|
+
secretRef: JSON.parse(row.secretRefJson) as CredentialInstanceRecord["secretRef"],
|
|
336
|
+
tags: JSON.parse(row.tagsJson) as CredentialInstanceRecord["tags"],
|
|
337
|
+
setupStatus: row.setupStatus as CredentialInstanceRecord["setupStatus"],
|
|
338
|
+
createdAt: row.createdAt,
|
|
339
|
+
updatedAt: row.updatedAt,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private toTestRecord(
|
|
344
|
+
row: Readonly<{
|
|
345
|
+
testId: string;
|
|
346
|
+
instanceId: string;
|
|
347
|
+
status: string;
|
|
348
|
+
message: string | null;
|
|
349
|
+
detailsJson: string;
|
|
350
|
+
testedAt: string;
|
|
351
|
+
expiresAt: string | null;
|
|
352
|
+
}>,
|
|
353
|
+
): CredentialTestRecord {
|
|
354
|
+
return {
|
|
355
|
+
testId: row.testId,
|
|
356
|
+
instanceId: row.instanceId,
|
|
357
|
+
health: {
|
|
358
|
+
status: row.status as CredentialTestRecord["health"]["status"],
|
|
359
|
+
message: row.message ?? undefined,
|
|
360
|
+
testedAt: row.testedAt,
|
|
361
|
+
expiresAt: row.expiresAt ?? undefined,
|
|
362
|
+
details: JSON.parse(row.detailsJson) as CredentialTestRecord["health"]["details"],
|
|
363
|
+
},
|
|
364
|
+
testedAt: row.testedAt,
|
|
365
|
+
expiresAt: row.expiresAt ?? undefined,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|