@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.
Files changed (358) hide show
  1. package/README.md +75 -0
  2. package/dist/CodemationConfig-XCkSV2dj.d.ts +168 -0
  3. package/dist/CodemationConsumerConfigLoader-Dmm2TzAA.d.ts +61 -0
  4. package/dist/CodemationConsumerConfigLoader-scS_RQMy.js +334 -0
  5. package/dist/CodemationConsumerConfigLoader-scS_RQMy.js.map +1 -0
  6. package/dist/CodemationFrontendBootstrapRequest-CE6DjOWJ.js +5768 -0
  7. package/dist/CodemationFrontendBootstrapRequest-CE6DjOWJ.js.map +1 -0
  8. package/dist/CodemationPluginListMerger-BNmaoXQL.js +49 -0
  9. package/dist/CodemationPluginListMerger-BNmaoXQL.js.map +1 -0
  10. package/dist/CodemationPluginListMerger-BRYqEk0y.d.ts +793 -0
  11. package/dist/CodemationWhitelabelConfig-DgbjgtrR.d.ts +48 -0
  12. package/dist/ConsoleLogger-ClPU7jtc.js +35 -0
  13. package/dist/ConsoleLogger-ClPU7jtc.js.map +1 -0
  14. package/dist/CredentialServices-BKBGe7l3.js +1030 -0
  15. package/dist/CredentialServices-BKBGe7l3.js.map +1 -0
  16. package/dist/CredentialServices-DpDpm8mL.d.ts +291 -0
  17. package/dist/LogLevelPolicy-4cq9z0TI.d.ts +37 -0
  18. package/dist/PrismaMigrationDeployer-B1E_gYz7.js +8212 -0
  19. package/dist/PrismaMigrationDeployer-B1E_gYz7.js.map +1 -0
  20. package/dist/ServerLoggerFactory-BRHxIDS7.js +340 -0
  21. package/dist/ServerLoggerFactory-BRHxIDS7.js.map +1 -0
  22. package/dist/WorkflowViewContracts-DCLpTn25.d.ts +47 -0
  23. package/dist/chunk-7V6ThxGB.js +39 -0
  24. package/dist/client-Yh7-CQud.d.ts +21995 -0
  25. package/dist/client.d.ts +12 -0
  26. package/dist/client.js +15 -0
  27. package/dist/client.js.map +1 -0
  28. package/dist/consumer.d.ts +5 -0
  29. package/dist/consumer.js +7 -0
  30. package/dist/credentials.d.ts +50 -0
  31. package/dist/credentials.js +11 -0
  32. package/dist/credentials.js.map +1 -0
  33. package/dist/decorate-B-N_5S4p.js +10 -0
  34. package/dist/decorateParam-BTcc3KNk.js +15 -0
  35. package/dist/devServerSidecar.d.ts +52 -0
  36. package/dist/devServerSidecar.js +131 -0
  37. package/dist/devServerSidecar.js.map +1 -0
  38. package/dist/index-Bs4F1IsC.d.ts +1044 -0
  39. package/dist/index.d.ts +19 -0
  40. package/dist/index.js +14 -0
  41. package/dist/nextServer.d.ts +89 -0
  42. package/dist/nextServer.js +127 -0
  43. package/dist/nextServer.js.map +1 -0
  44. package/dist/persistenceServer-K5eqlZm3.d.ts +36 -0
  45. package/dist/persistenceServer-W9uRw0dJ.js +19 -0
  46. package/dist/persistenceServer-W9uRw0dJ.js.map +1 -0
  47. package/dist/persistenceServer.d.ts +6 -0
  48. package/dist/persistenceServer.js +6 -0
  49. package/dist/server-BBdsATju.d.ts +132 -0
  50. package/dist/server-BiHSuA13.js +175 -0
  51. package/dist/server-BiHSuA13.js.map +1 -0
  52. package/dist/server.d.ts +9 -0
  53. package/dist/server.js +13 -0
  54. package/package.json +152 -0
  55. package/playwright.config.ts +74 -0
  56. package/prisma/migrations/20260315063514_init/migration.sql +16 -0
  57. package/prisma/migrations/20260316090000_workflow_debugger_overlay/migration.sql +9 -0
  58. package/prisma/migrations/20260317120000_trigger_state_store/migration.sql +3 -0
  59. package/prisma/migrations/20260317153000_trigger_setup_state/migration.sql +8 -0
  60. package/prisma/migrations/20260318110000_credentials_v2/migration.sql +49 -0
  61. package/prisma/migrations/20260319110000_credential_oauth2_material/migration.sql +28 -0
  62. package/prisma/migrations/20260319200000_codemation_auth_tables/migration.sql +56 -0
  63. package/prisma/migrations/20260320140000_user_invites_account_status/migration.sql +20 -0
  64. package/prisma/migrations/20260325120000_workflow_activation/migration.sql +8 -0
  65. package/prisma/migrations/migration_lock.toml +3 -0
  66. package/prisma/schema.prisma +179 -0
  67. package/prisma.config.ts +12 -0
  68. package/scripts/ensure-prisma-runtime-sourcemaps.mjs +42 -0
  69. package/scripts/integration-database-global-setup.mjs +30 -0
  70. package/src/application/ApplicationRequestError.ts +12 -0
  71. package/src/application/auth/AuthenticatedPrincipal.ts +5 -0
  72. package/src/application/auth/SessionVerifier.ts +5 -0
  73. package/src/application/binary/OverlayPinnedBinaryUploadService.ts +119 -0
  74. package/src/application/binary/RunBinaryAttachmentLookupService.ts +139 -0
  75. package/src/application/binary/RunStateBinaryStorageKeysCollector.ts +57 -0
  76. package/src/application/bus/Command.ts +3 -0
  77. package/src/application/bus/CommandBus.ts +5 -0
  78. package/src/application/bus/CommandHandler.ts +5 -0
  79. package/src/application/bus/DomainEvent.ts +1 -0
  80. package/src/application/bus/DomainEventBus.ts +5 -0
  81. package/src/application/bus/DomainEventHandler.ts +5 -0
  82. package/src/application/bus/Query.ts +3 -0
  83. package/src/application/bus/QueryBus.ts +5 -0
  84. package/src/application/bus/QueryHandler.ts +5 -0
  85. package/src/application/commands/AcceptUserInviteCommand.ts +10 -0
  86. package/src/application/commands/AcceptUserInviteCommandHandler.ts +19 -0
  87. package/src/application/commands/CopyRunToWorkflowDebuggerCommand.ts +14 -0
  88. package/src/application/commands/CopyRunToWorkflowDebuggerCommandHandler.ts +56 -0
  89. package/src/application/commands/CreateCredentialInstanceCommand.ts +9 -0
  90. package/src/application/commands/CreateCredentialInstanceCommandHandler.ts +28 -0
  91. package/src/application/commands/CredentialCommandHandlers.ts +10 -0
  92. package/src/application/commands/DeleteCredentialInstanceCommand.ts +7 -0
  93. package/src/application/commands/DeleteCredentialInstanceCommandHandler.ts +27 -0
  94. package/src/application/commands/HandleWebhookInvocationCommand.ts +12 -0
  95. package/src/application/commands/HandleWebhookInvocationCommandHandler.ts +42 -0
  96. package/src/application/commands/InviteUserCommand.ts +12 -0
  97. package/src/application/commands/InviteUserCommandHandler.ts +22 -0
  98. package/src/application/commands/RegenerateUserInviteCommand.ts +12 -0
  99. package/src/application/commands/RegenerateUserInviteCommandHandler.ts +24 -0
  100. package/src/application/commands/ReplaceMutableRunWorkflowSnapshotCommand.ts +12 -0
  101. package/src/application/commands/ReplaceMutableRunWorkflowSnapshotCommandHandler.ts +47 -0
  102. package/src/application/commands/ReplaceWorkflowDebuggerOverlayCommand.ts +14 -0
  103. package/src/application/commands/ReplaceWorkflowDebuggerOverlayCommandHandler.ts +35 -0
  104. package/src/application/commands/ReplayWorkflowNodeCommand.ts +12 -0
  105. package/src/application/commands/ReplayWorkflowNodeCommandHandler.ts +164 -0
  106. package/src/application/commands/SetPinnedNodeInputCommand.ts +13 -0
  107. package/src/application/commands/SetPinnedNodeInputCommandHandler.ts +50 -0
  108. package/src/application/commands/SetWorkflowActivationCommand.ts +10 -0
  109. package/src/application/commands/SetWorkflowActivationCommandHandler.ts +39 -0
  110. package/src/application/commands/StartWorkflowRunCommand.ts +8 -0
  111. package/src/application/commands/StartWorkflowRunCommandHandler.ts +286 -0
  112. package/src/application/commands/TestCredentialInstanceCommand.ts +9 -0
  113. package/src/application/commands/TestCredentialInstanceCommandHandler.ts +28 -0
  114. package/src/application/commands/UpdateCredentialInstanceCommand.ts +12 -0
  115. package/src/application/commands/UpdateCredentialInstanceCommandHandler.ts +28 -0
  116. package/src/application/commands/UpdateUserAccountStatusCommand.ts +12 -0
  117. package/src/application/commands/UpdateUserAccountStatusCommandHandler.ts +24 -0
  118. package/src/application/commands/UploadOverlayPinnedBinaryCommand.ts +16 -0
  119. package/src/application/commands/UploadOverlayPinnedBinaryCommandHandler.ts +31 -0
  120. package/src/application/commands/UpsertCredentialBindingCommand.ts +11 -0
  121. package/src/application/commands/UpsertCredentialBindingCommandHandler.ts +28 -0
  122. package/src/application/commands/UpsertLocalBootstrapUserCommand.ts +12 -0
  123. package/src/application/commands/UpsertLocalBootstrapUserCommandHandler.ts +24 -0
  124. package/src/application/commands/UserAccountCommandHandlers.ts +10 -0
  125. package/src/application/contracts/CredentialContractsRegistry.ts +88 -0
  126. package/src/application/contracts/RunContracts.ts +41 -0
  127. package/src/application/contracts/WorkflowDebuggerContracts.ts +12 -0
  128. package/src/application/contracts/WorkflowViewContracts.ts +40 -0
  129. package/src/application/contracts/WorkflowWebsocketMessage.ts +8 -0
  130. package/src/application/contracts/userDirectoryContracts.types.ts +60 -0
  131. package/src/application/dev/BootRuntimeSnapshotHolder.ts +19 -0
  132. package/src/application/dev/BootRuntimeSummary.types.ts +11 -0
  133. package/src/application/dev/DevBootstrapSummaryAssembler.ts +84 -0
  134. package/src/application/dev/DevBootstrapSummaryJson.types.ts +9 -0
  135. package/src/application/logging/LogFilter.ts +7 -0
  136. package/src/application/logging/Logger.ts +10 -0
  137. package/src/application/mapping/DataMapper.ts +3 -0
  138. package/src/application/mapping/WorkflowDefinitionMapper.ts +171 -0
  139. package/src/application/mapping/WorkflowPolicyUiPresentationFactory.ts +39 -0
  140. package/src/application/queries/CredentialQueryHandlers.ts +12 -0
  141. package/src/application/queries/GetCredentialFieldEnvStatusQuery.ts +5 -0
  142. package/src/application/queries/GetCredentialFieldEnvStatusQueryHandler.ts +52 -0
  143. package/src/application/queries/GetCredentialInstanceQuery.ts +9 -0
  144. package/src/application/queries/GetCredentialInstanceQueryHandler.ts +27 -0
  145. package/src/application/queries/GetCredentialInstanceWithSecretsQuery.ts +9 -0
  146. package/src/application/queries/GetCredentialInstanceWithSecretsQueryHandler.ts +27 -0
  147. package/src/application/queries/GetRunBinaryAttachmentQuery.ts +11 -0
  148. package/src/application/queries/GetRunBinaryAttachmentQueryHandler.ts +23 -0
  149. package/src/application/queries/GetRunStateQuery.ts +8 -0
  150. package/src/application/queries/GetRunStateQueryHandler.ts +21 -0
  151. package/src/application/queries/GetWorkflowCredentialHealthQuery.ts +9 -0
  152. package/src/application/queries/GetWorkflowCredentialHealthQueryHandler.ts +27 -0
  153. package/src/application/queries/GetWorkflowDebuggerOverlayQuery.ts +8 -0
  154. package/src/application/queries/GetWorkflowDebuggerOverlayQueryHandler.ts +28 -0
  155. package/src/application/queries/GetWorkflowDetailQuery.ts +8 -0
  156. package/src/application/queries/GetWorkflowDetailQueryHandler.ts +24 -0
  157. package/src/application/queries/GetWorkflowOverlayBinaryAttachmentQuery.ts +11 -0
  158. package/src/application/queries/GetWorkflowOverlayBinaryAttachmentQueryHandler.ts +23 -0
  159. package/src/application/queries/GetWorkflowSummariesQuery.ts +4 -0
  160. package/src/application/queries/GetWorkflowSummariesQueryHandler.ts +23 -0
  161. package/src/application/queries/ListCredentialInstancesQuery.ts +5 -0
  162. package/src/application/queries/ListCredentialInstancesQueryHandler.ts +27 -0
  163. package/src/application/queries/ListCredentialTypesQuery.ts +5 -0
  164. package/src/application/queries/ListCredentialTypesQueryHandler.ts +28 -0
  165. package/src/application/queries/ListUserAccountsQuery.ts +5 -0
  166. package/src/application/queries/ListUserAccountsQueryHandler.ts +22 -0
  167. package/src/application/queries/ListWorkflowRunsQuery.ts +8 -0
  168. package/src/application/queries/ListWorkflowRunsQueryHandler.ts +21 -0
  169. package/src/application/queries/UserAccountQueryHandlers.ts +4 -0
  170. package/src/application/queries/VerifyUserInviteQuery.ts +9 -0
  171. package/src/application/queries/VerifyUserInviteQueryHandler.ts +21 -0
  172. package/src/application/runs/WorkflowRunRetentionPruneScheduler.ts +98 -0
  173. package/src/application/websocket/WorkflowRunEventWebsocketRelay.ts +36 -0
  174. package/src/application/websocket/WorkflowWebsocketPublisher.ts +5 -0
  175. package/src/application/workflows/WebhookEndpointPathValidator.ts +35 -0
  176. package/src/application/workflows/WorkflowDebuggerOverlayStateFactory.ts +122 -0
  177. package/src/applicationTokens.ts +72 -0
  178. package/src/bootstrap/CodemationBootstrapRequest.ts +27 -0
  179. package/src/bootstrap/CodemationContainerFactory.ts +310 -0
  180. package/src/bootstrap/CodemationContainerRegistration.ts +23 -0
  181. package/src/bootstrap/CodemationContainerRegistrationRegistrar.ts +42 -0
  182. package/src/bootstrap/CodemationFrontendBootstrapRequest.ts +16 -0
  183. package/src/bootstrap/CodemationWorkerBootstrapRequest.ts +19 -0
  184. package/src/bootstrap/PreparedCodemationRuntime.ts +37 -0
  185. package/src/bootstrap/PreparedCodemationRuntimeFactory.ts +308 -0
  186. package/src/bootstrap/boot/CliRuntimeBootService.ts +27 -0
  187. package/src/bootstrap/boot/FrontendRuntimeBootService.ts +86 -0
  188. package/src/bootstrap/boot/WorkerRuntimeBootService.ts +64 -0
  189. package/src/bootstrap/runtime/AppConfigFactory.ts +57 -0
  190. package/src/bootstrap/runtime/ResolvedImplementationSelectionFactory.ts +118 -0
  191. package/src/client.ts +3 -0
  192. package/src/codemationApplication.ts +311 -0
  193. package/src/consumer.ts +4 -0
  194. package/src/credentials.ts +24 -0
  195. package/src/devServerSidecar.ts +10 -0
  196. package/src/domain/credentials/CredentialBindingService.ts +139 -0
  197. package/src/domain/credentials/CredentialFieldEnvOverlayService.ts +60 -0
  198. package/src/domain/credentials/CredentialInstanceService.ts +391 -0
  199. package/src/domain/credentials/CredentialMaterialResolver.ts +55 -0
  200. package/src/domain/credentials/CredentialRuntimeMaterialService.ts +39 -0
  201. package/src/domain/credentials/CredentialSecretCipher.ts +70 -0
  202. package/src/domain/credentials/CredentialServices.ts +145 -0
  203. package/src/domain/credentials/CredentialSessionServiceImpl.ts +119 -0
  204. package/src/domain/credentials/CredentialTestService.ts +73 -0
  205. package/src/domain/credentials/CredentialTypeRegistryImpl.ts +29 -0
  206. package/src/domain/credentials/OAuth2ConnectServiceFactory.ts +396 -0
  207. package/src/domain/credentials/OAuth2ProviderRegistry.ts +75 -0
  208. package/src/domain/credentials/WorkflowCredentialNodeResolver.ts +246 -0
  209. package/src/domain/runs/WorkflowRunRepository.ts +11 -0
  210. package/src/domain/users/UserAccountServiceRegistry.ts +315 -0
  211. package/src/domain/users/userLoginMethodLabels.types.ts +29 -0
  212. package/src/domain/workflows/WorkflowActivationPreflight.ts +32 -0
  213. package/src/domain/workflows/WorkflowActivationPreflightRules.ts +77 -0
  214. package/src/domain/workflows/WorkflowActivationRepository.ts +9 -0
  215. package/src/domain/workflows/WorkflowDebuggerOverlayRepository.ts +7 -0
  216. package/src/domain/workflows/WorkflowDebuggerOverlayState.ts +8 -0
  217. package/src/domain/workflows/WorkflowDefinitionRepository.ts +11 -0
  218. package/src/index.ts +58 -0
  219. package/src/infrastructure/auth/AuthJsSessionVerifier.ts +26 -0
  220. package/src/infrastructure/auth/DevelopmentSessionBypassVerifier.ts +12 -0
  221. package/src/infrastructure/binary/BinaryBodyNodeReadableFactory.ts +22 -0
  222. package/src/infrastructure/binary/CountingSha256Transform.ts +26 -0
  223. package/src/infrastructure/binary/LocalFilesystemBinaryStorageRegistry.ts +86 -0
  224. package/src/infrastructure/config/CodemationPluginRegistrar.ts +44 -0
  225. package/src/infrastructure/credentials/FrameworkBuiltinCredentialTypesRegistrar.ts +21 -0
  226. package/src/infrastructure/credentials/OpenAiApiKeyCredentialHealthTester.ts +89 -0
  227. package/src/infrastructure/credentials/OpenAiApiKeyCredentialShapes.types.ts +15 -0
  228. package/src/infrastructure/credentials/OpenAiApiKeyCredentialTypeFactory.ts +47 -0
  229. package/src/infrastructure/di/HandlesCommandRegistry.ts +24 -0
  230. package/src/infrastructure/di/HandlesDomainEventRegistry.ts +24 -0
  231. package/src/infrastructure/di/HandlesQueryRegistry.ts +24 -0
  232. package/src/infrastructure/di/InMemoryCommandBus.ts +47 -0
  233. package/src/infrastructure/di/InMemoryDomainEventBus.ts +47 -0
  234. package/src/infrastructure/di/InMemoryQueryBus.ts +45 -0
  235. package/src/infrastructure/ids/CodemationIdFactory.ts +12 -0
  236. package/src/infrastructure/logging/BrowserLogger.ts +1 -0
  237. package/src/infrastructure/logging/BrowserLoggerFactory.ts +14 -0
  238. package/src/infrastructure/logging/ConsoleLogger.ts +41 -0
  239. package/src/infrastructure/logging/FilteringLogger.ts +38 -0
  240. package/src/infrastructure/logging/LogLevelPolicy.ts +148 -0
  241. package/src/infrastructure/logging/LogLevelPolicyFactory.ts +16 -0
  242. package/src/infrastructure/logging/PerformanceLogPolicy.ts +10 -0
  243. package/src/infrastructure/logging/PerformanceLogPolicyFactory.ts +14 -0
  244. package/src/infrastructure/logging/ServerLogger.ts +1 -0
  245. package/src/infrastructure/logging/ServerLoggerFactory.ts +28 -0
  246. package/src/infrastructure/persistence/CodemationPostgresPrismaClientFactory.ts +9 -0
  247. package/src/infrastructure/persistence/CredentialPersistenceStore.ts +139 -0
  248. package/src/infrastructure/persistence/DatabasePersistenceResolver.ts +91 -0
  249. package/src/infrastructure/persistence/InMemoryTriggerSetupStateRepository.ts +23 -0
  250. package/src/infrastructure/persistence/InMemoryWorkflowActivationRepository.ts +18 -0
  251. package/src/infrastructure/persistence/InMemoryWorkflowDebuggerOverlayRepository.ts +16 -0
  252. package/src/infrastructure/persistence/InMemoryWorkflowRunRepository.ts +94 -0
  253. package/src/infrastructure/persistence/PrismaClientFactory.ts +26 -0
  254. package/src/infrastructure/persistence/PrismaCredentialStore.ts +368 -0
  255. package/src/infrastructure/persistence/PrismaMigrationDeployer.ts +184 -0
  256. package/src/infrastructure/persistence/PrismaTriggerSetupStateRepository.ts +68 -0
  257. package/src/infrastructure/persistence/PrismaWorkflowActivationRepository.ts +36 -0
  258. package/src/infrastructure/persistence/PrismaWorkflowDebuggerOverlayRepository.ts +65 -0
  259. package/src/infrastructure/persistence/PrismaWorkflowRunRepository.ts +243 -0
  260. package/src/infrastructure/persistence/RuntimeWorkflowActivationPolicy.ts +27 -0
  261. package/src/infrastructure/persistence/SchedulerPersistenceCompatibilityValidator.ts +20 -0
  262. package/src/infrastructure/persistence/WorkflowDefinitionRepositoryAdapter.ts +31 -0
  263. package/src/infrastructure/persistence/WorkflowRunRepository.ts +46 -0
  264. package/src/infrastructure/persistence/generated/prisma/client.d.ts +1 -0
  265. package/src/infrastructure/persistence/generated/prisma/default.d.ts +1 -0
  266. package/src/infrastructure/persistence/generated/prisma/edge.d.ts +1 -0
  267. package/src/infrastructure/persistence/generated/prisma/index.d.ts +4766 -0
  268. package/src/infrastructure/persistence/generated/prisma/package.json +144 -0
  269. package/src/infrastructure/persistence/generated/prisma/query_compiler_fast_bg.wasm +0 -0
  270. package/src/infrastructure/persistence/generated/prisma/runtime/client.d.ts +3358 -0
  271. package/src/infrastructure/persistence/generated/prisma/runtime/index-browser.d.ts +90 -0
  272. package/src/infrastructure/persistence/generated/prisma/schema.prisma +35 -0
  273. package/src/infrastructure/persistence/generated/prisma/wasm-edge-light-loader.mjs +5 -0
  274. package/src/infrastructure/persistence/generated/prisma/wasm-worker-loader.mjs +5 -0
  275. package/src/infrastructure/persistence/generated/prisma-client/client.d.ts +1 -0
  276. package/src/infrastructure/persistence/generated/prisma-client/client.js +5 -0
  277. package/src/infrastructure/persistence/generated/prisma-client/default.d.ts +1 -0
  278. package/src/infrastructure/persistence/generated/prisma-client/default.js +5 -0
  279. package/src/infrastructure/persistence/generated/prisma-client/edge.d.ts +1 -0
  280. package/src/infrastructure/persistence/generated/prisma-client/edge.js +299 -0
  281. package/src/infrastructure/persistence/generated/prisma-client/index-browser.js +325 -0
  282. package/src/infrastructure/persistence/generated/prisma-client/index.d.ts +21623 -0
  283. package/src/infrastructure/persistence/generated/prisma-client/index.js +299 -0
  284. package/src/infrastructure/persistence/generated/prisma-client/package.json +144 -0
  285. package/src/infrastructure/persistence/generated/prisma-client/query_compiler_fast_bg.js +2 -0
  286. package/src/infrastructure/persistence/generated/prisma-client/query_compiler_fast_bg.wasm +0 -0
  287. package/src/infrastructure/persistence/generated/prisma-client/query_compiler_fast_bg.wasm-base64.js +2 -0
  288. package/src/infrastructure/persistence/generated/prisma-client/runtime/client.d.ts +3358 -0
  289. package/src/infrastructure/persistence/generated/prisma-client/runtime/client.js +86 -0
  290. package/src/infrastructure/persistence/generated/prisma-client/runtime/client.js.map +1 -0
  291. package/src/infrastructure/persistence/generated/prisma-client/runtime/index-browser.d.ts +90 -0
  292. package/src/infrastructure/persistence/generated/prisma-client/runtime/index-browser.js +6 -0
  293. package/src/infrastructure/persistence/generated/prisma-client/runtime/index-browser.js.map +1 -0
  294. package/src/infrastructure/persistence/generated/prisma-client/runtime/wasm-compiler-edge.js +76 -0
  295. package/src/infrastructure/persistence/generated/prisma-client/runtime/wasm-compiler-edge.js.map +1 -0
  296. package/src/infrastructure/persistence/generated/prisma-client/schema.prisma +179 -0
  297. package/src/infrastructure/persistence/generated/prisma-client/wasm-edge-light-loader.mjs +5 -0
  298. package/src/infrastructure/persistence/generated/prisma-client/wasm-worker-loader.mjs +5 -0
  299. package/src/infrastructure/runtime/LiveWorkflowRepository.ts +14 -0
  300. package/src/infrastructure/runtime/WorkerRuntimeScheduler.ts +35 -0
  301. package/src/infrastructure/server/http/ServerHttpRouteParams.ts +1 -0
  302. package/src/infrastructure/webhooks/RequestToWebhookItemMapper.ts +128 -0
  303. package/src/nextServer.ts +31 -0
  304. package/src/persistenceServer.ts +5 -0
  305. package/src/presentation/config/AppConfig.ts +25 -0
  306. package/src/presentation/config/CodemationAppContext.ts +19 -0
  307. package/src/presentation/config/CodemationApplicationFacade.ts +5 -0
  308. package/src/presentation/config/CodemationAuthConfig.ts +31 -0
  309. package/src/presentation/config/CodemationClassToken.ts +3 -0
  310. package/src/presentation/config/CodemationConfig.ts +86 -0
  311. package/src/presentation/config/CodemationConfigNormalizer.ts +179 -0
  312. package/src/presentation/config/CodemationLogConfig.ts +22 -0
  313. package/src/presentation/config/CodemationPackageManifest.ts +9 -0
  314. package/src/presentation/config/CodemationPlugin.ts +20 -0
  315. package/src/presentation/config/CodemationPluginListMerger.ts +46 -0
  316. package/src/presentation/config/CodemationWhitelabelConfig.ts +9 -0
  317. package/src/presentation/config/CodemationWorkflowDiscovery.ts +3 -0
  318. package/src/presentation/http/ApiPaths.ts +165 -0
  319. package/src/presentation/http/CodemationServerGatewayFactory.ts +120 -0
  320. package/src/presentation/http/HttpRequestJsonBodyReader.ts +12 -0
  321. package/src/presentation/http/ServerHttpErrorResponseFactory.ts +33 -0
  322. package/src/presentation/http/ServerHttpRouteParams.ts +1 -0
  323. package/src/presentation/http/hono/CodemationHonoApiAppFactory.ts +64 -0
  324. package/src/presentation/http/hono/HonoApiRouteRegistrar.ts +5 -0
  325. package/src/presentation/http/hono/HonoHttpAnonymousRoutePolicyRegistry.ts +27 -0
  326. package/src/presentation/http/hono/registrars/BinaryHonoApiRouteRegistrar.ts +21 -0
  327. package/src/presentation/http/hono/registrars/CredentialHonoApiRouteRegistrar.ts +34 -0
  328. package/src/presentation/http/hono/registrars/DevHonoApiRouteRegistrar.ts +17 -0
  329. package/src/presentation/http/hono/registrars/OAuth2HonoApiRouteRegistrar.ts +18 -0
  330. package/src/presentation/http/hono/registrars/RunHonoApiRouteRegistrar.ts +31 -0
  331. package/src/presentation/http/hono/registrars/UserHonoApiRouteRegistrar.ts +24 -0
  332. package/src/presentation/http/hono/registrars/WebhookHonoApiRouteRegistrar.ts +23 -0
  333. package/src/presentation/http/hono/registrars/WhitelabelHonoApiRouteRegistrar.ts +18 -0
  334. package/src/presentation/http/hono/registrars/WorkflowHonoApiRouteRegistrar.ts +33 -0
  335. package/src/presentation/http/routeHandlers/BinaryHttpRouteHandlerFactory.ts +101 -0
  336. package/src/presentation/http/routeHandlers/CredentialHttpRouteHandler.ts +129 -0
  337. package/src/presentation/http/routeHandlers/DevBootstrapSummaryHttpRouteHandler.ts +21 -0
  338. package/src/presentation/http/routeHandlers/OAuth2HttpRouteHandlerFactory.ts +129 -0
  339. package/src/presentation/http/routeHandlers/RunHttpRouteHandler.ts +82 -0
  340. package/src/presentation/http/routeHandlers/UserHttpRouteHandlerFactory.ts +109 -0
  341. package/src/presentation/http/routeHandlers/WebhookHttpRouteHandler.ts +42 -0
  342. package/src/presentation/http/routeHandlers/WhitelabelLogoHttpRouteHandler.ts +96 -0
  343. package/src/presentation/http/routeHandlers/WorkflowHttpRouteHandler.ts +104 -0
  344. package/src/presentation/server/CodemationConsumerAppResolver.ts +82 -0
  345. package/src/presentation/server/CodemationConsumerConfigExportsResolver.ts +33 -0
  346. package/src/presentation/server/CodemationConsumerConfigLoader.ts +270 -0
  347. package/src/presentation/server/CodemationPluginDiscovery.ts +151 -0
  348. package/src/presentation/server/CodemationTsyringeParamInfoReader.ts +26 -0
  349. package/src/presentation/server/CodemationTsyringeTypeInfoRegistrar.ts +121 -0
  350. package/src/presentation/server/DevelopmentRuntimeRouteGuard.ts +59 -0
  351. package/src/presentation/server/DiscoveredWorkflowsEmptyMessageFactory.ts +11 -0
  352. package/src/presentation/server/WorkflowDefinitionExportsResolver.ts +24 -0
  353. package/src/presentation/server/WorkflowDiscoveryPathSegmentsComputer.ts +53 -0
  354. package/src/presentation/server/WorkflowModulePathFinder.ts +47 -0
  355. package/src/presentation/websocket/WorkflowWebsocketServer.ts +169 -0
  356. package/src/server.ts +14 -0
  357. package/tsconfig.json +10 -0
  358. package/vitest.shared.ts +45 -0
@@ -0,0 +1,42 @@
1
+ import type { Container } from "@codemation/core";
2
+ import type {
3
+ CodemationClassRegistration,
4
+ CodemationContainerRegistration,
5
+ CodemationValueRegistration,
6
+ } from "./CodemationContainerRegistration";
7
+
8
+ export class CodemationContainerRegistrationRegistrar {
9
+ apply(container: Container, registrations: ReadonlyArray<CodemationContainerRegistration<unknown>>): void {
10
+ for (const registration of registrations) {
11
+ this.applyRegistration(container, registration);
12
+ }
13
+ }
14
+
15
+ private applyRegistration(container: Container, registration: CodemationContainerRegistration<unknown>): void {
16
+ if (this.isValueRegistration(registration)) {
17
+ container.registerInstance(registration.token, registration.useValue);
18
+ return;
19
+ }
20
+ if (this.isClassRegistration(registration)) {
21
+ container.register(registration.token, {
22
+ useClass: registration.useClass as never,
23
+ });
24
+ return;
25
+ }
26
+ container.register(registration.token, {
27
+ useFactory: (dependencyContainer) => registration.useFactory(dependencyContainer),
28
+ });
29
+ }
30
+
31
+ private isValueRegistration(
32
+ registration: CodemationContainerRegistration<unknown>,
33
+ ): registration is CodemationValueRegistration<unknown> {
34
+ return "useValue" in registration;
35
+ }
36
+
37
+ private isClassRegistration(
38
+ registration: CodemationContainerRegistration<unknown>,
39
+ ): registration is CodemationClassRegistration<unknown> {
40
+ return "useClass" in registration;
41
+ }
42
+ }
@@ -0,0 +1,16 @@
1
+ import { CodemationBootstrapRequest } from "./CodemationBootstrapRequest";
2
+
3
+ export class CodemationFrontendBootstrapRequest {
4
+ readonly bootstrap: CodemationBootstrapRequest;
5
+ readonly skipPresentationServers: boolean;
6
+
7
+ constructor(
8
+ args: Readonly<{
9
+ bootstrap: CodemationBootstrapRequest;
10
+ skipPresentationServers?: boolean;
11
+ }>,
12
+ ) {
13
+ this.bootstrap = args.bootstrap;
14
+ this.skipPresentationServers = args.skipPresentationServers ?? false;
15
+ }
16
+ }
@@ -0,0 +1,19 @@
1
+ import { CodemationBootstrapRequest } from "./CodemationBootstrapRequest";
2
+
3
+ export class CodemationWorkerBootstrapRequest {
4
+ readonly bootstrap: CodemationBootstrapRequest;
5
+ readonly queues: ReadonlyArray<string>;
6
+ readonly bootstrapSource?: string | null;
7
+
8
+ constructor(
9
+ args: Readonly<{
10
+ bootstrap: CodemationBootstrapRequest;
11
+ queues: ReadonlyArray<string>;
12
+ bootstrapSource?: string | null;
13
+ }>,
14
+ ) {
15
+ this.bootstrap = args.bootstrap;
16
+ this.queues = [...args.queues];
17
+ this.bootstrapSource = args.bootstrapSource;
18
+ }
19
+ }
@@ -0,0 +1,37 @@
1
+ import type { PGlite } from "@electric-sql/pglite";
2
+ import type { Container } from "@codemation/core";
3
+ import { Engine } from "@codemation/core/bootstrap";
4
+ import { WorkflowRunEventWebsocketRelay } from "../application/websocket/WorkflowRunEventWebsocketRelay";
5
+ import type { BootRuntimeSummary } from "../application/dev/BootRuntimeSummary.types";
6
+ import type { PrismaClient } from "../infrastructure/persistence/generated/prisma-client/client.js";
7
+ import { WorkflowWebsocketServer } from "../presentation/websocket/WorkflowWebsocketServer";
8
+ import type { ResolvedImplementationSelection } from "./runtime/ResolvedImplementationSelectionFactory";
9
+
10
+ export class PreparedCodemationRuntime {
11
+ constructor(
12
+ readonly container: Container,
13
+ readonly runtimeSummary: BootRuntimeSummary,
14
+ readonly implementationSelection: ResolvedImplementationSelection,
15
+ readonly usesProvidedPrismaClientOverride: boolean,
16
+ private readonly ownedPrismaClient: PrismaClient | null,
17
+ private readonly ownedPglite: PGlite | null,
18
+ ) {}
19
+
20
+ async stop(args?: Readonly<{ stopWebsocketServer?: boolean }>): Promise<void> {
21
+ if (this.container.isRegistered(Engine, true)) {
22
+ await this.container.resolve(Engine).stop();
23
+ }
24
+ if (this.container.isRegistered(WorkflowRunEventWebsocketRelay, true)) {
25
+ await this.container.resolve(WorkflowRunEventWebsocketRelay).stop();
26
+ }
27
+ if (args?.stopWebsocketServer !== false && this.container.isRegistered(WorkflowWebsocketServer, true)) {
28
+ await this.container.resolve(WorkflowWebsocketServer).stop();
29
+ }
30
+ if (this.ownedPrismaClient) {
31
+ await this.ownedPrismaClient.$disconnect();
32
+ }
33
+ if (this.ownedPglite) {
34
+ await this.ownedPglite.close();
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,308 @@
1
+ import type { PGlite } from "@electric-sql/pglite";
2
+ import path from "node:path";
3
+ import type {
4
+ Container,
5
+ RunEventBus,
6
+ TriggerSetupStateRepository,
7
+ WorkflowExecutionRepository,
8
+ } from "@codemation/core";
9
+ import {
10
+ CoreTokens,
11
+ EventPublishingWorkflowExecutionRepository,
12
+ InMemoryRunEventBus,
13
+ instanceCachingFactory,
14
+ SystemClock,
15
+ } from "@codemation/core";
16
+ import {
17
+ ConfigDrivenOffloadPolicy,
18
+ DefaultDrivingScheduler,
19
+ DefaultExecutionContextFactory,
20
+ InlineDrivingScheduler,
21
+ InMemoryBinaryStorage,
22
+ InMemoryRunDataFactory,
23
+ } from "@codemation/core/bootstrap";
24
+ import { RedisRunEventBus } from "@codemation/eventbus-redis";
25
+ import type { BootRuntimeSummary } from "../application/dev/BootRuntimeSummary.types";
26
+ import { BootRuntimeSnapshotHolder } from "../application/dev/BootRuntimeSnapshotHolder";
27
+ import { ApplicationTokens } from "../applicationTokens";
28
+ import { UserAccountService } from "../domain/users/UserAccountServiceRegistry";
29
+ import type { WorkflowRunRepository } from "../domain/runs/WorkflowRunRepository";
30
+ import type { WorkflowDebuggerOverlayRepository } from "../domain/workflows/WorkflowDebuggerOverlayRepository";
31
+ import type { CodemationAuthConfig } from "../presentation/config/CodemationAuthConfig";
32
+ import type { CodemationApplicationRuntimeConfig } from "../presentation/config/CodemationConfig";
33
+ import type { CodemationWhitelabelConfig } from "../presentation/config/CodemationWhitelabelConfig";
34
+ import { CredentialSessionServiceImpl } from "../domain/credentials/CredentialServices";
35
+ import { LocalFilesystemBinaryStorage } from "../infrastructure/binary/LocalFilesystemBinaryStorageRegistry";
36
+ import {
37
+ InMemoryCredentialStore,
38
+ PrismaCredentialStore,
39
+ } from "../infrastructure/persistence/CredentialPersistenceStore";
40
+ import { InMemoryTriggerSetupStateRepository } from "../infrastructure/persistence/InMemoryTriggerSetupStateRepository";
41
+ import { InMemoryWorkflowActivationRepository } from "../infrastructure/persistence/InMemoryWorkflowActivationRepository";
42
+ import { InMemoryWorkflowDebuggerOverlayRepository } from "../infrastructure/persistence/InMemoryWorkflowDebuggerOverlayRepository";
43
+ import { InMemoryWorkflowRunRepository } from "../infrastructure/persistence/InMemoryWorkflowRunRepository";
44
+ import { PrismaClientFactory } from "../infrastructure/persistence/PrismaClientFactory";
45
+ import { PrismaClient } from "../infrastructure/persistence/generated/prisma-client/client.js";
46
+ import { PrismaTriggerSetupStateRepository } from "../infrastructure/persistence/PrismaTriggerSetupStateRepository";
47
+ import { PrismaWorkflowActivationRepository } from "../infrastructure/persistence/PrismaWorkflowActivationRepository";
48
+ import { PrismaWorkflowDebuggerOverlayRepository } from "../infrastructure/persistence/PrismaWorkflowDebuggerOverlayRepository";
49
+ import { PrismaWorkflowRunRepository } from "../infrastructure/persistence/PrismaWorkflowRunRepository";
50
+ import type { ResolvedDatabasePersistence } from "../infrastructure/persistence/DatabasePersistenceResolver";
51
+ import { AppConfigFactory } from "./runtime/AppConfigFactory";
52
+ import type { ResolvedImplementationSelection } from "./runtime/ResolvedImplementationSelectionFactory";
53
+ import { ResolvedImplementationSelectionFactory } from "./runtime/ResolvedImplementationSelectionFactory";
54
+ import { PreparedCodemationRuntime } from "./PreparedCodemationRuntime";
55
+ import type { AppConfig } from "../presentation/config/AppConfig";
56
+
57
+ type PrismaClientResolution = Readonly<{
58
+ prismaClient: PrismaClient;
59
+ ownedPrismaClient?: PrismaClient;
60
+ ownedPglite?: PGlite;
61
+ }>;
62
+
63
+ type PreparedRuntimePersistence = Readonly<{
64
+ workflowExecutionRepository: WorkflowExecutionRepository;
65
+ triggerSetupStateRepository: TriggerSetupStateRepository;
66
+ workflowRunRepository?: WorkflowRunRepository;
67
+ workflowDebuggerOverlayRepository: WorkflowDebuggerOverlayRepository;
68
+ prismaClient?: PrismaClient;
69
+ ownedPrismaClient?: PrismaClient;
70
+ ownedPglite?: PGlite;
71
+ }>;
72
+
73
+ export class PreparedCodemationRuntimeFactory {
74
+ constructor(
75
+ private readonly implementationSelectionFactory: ResolvedImplementationSelectionFactory = new ResolvedImplementationSelectionFactory(),
76
+ private readonly appConfigFactory: AppConfigFactory = new AppConfigFactory(),
77
+ ) {}
78
+
79
+ async prepare(
80
+ args: Readonly<{
81
+ container: Container;
82
+ repoRoot: string;
83
+ consumerRoot: string;
84
+ env: NodeJS.ProcessEnv;
85
+ workflowSources: ReadonlyArray<string>;
86
+ runtimeConfig: CodemationApplicationRuntimeConfig;
87
+ applicationAuthConfig: CodemationAuthConfig | undefined;
88
+ whitelabelConfig: CodemationWhitelabelConfig;
89
+ hasConfiguredCredentialSessionServiceRegistration: boolean;
90
+ }>,
91
+ ): Promise<PreparedCodemationRuntime> {
92
+ const usesProvidedPrismaClientOverride = this.hasProvidedPrismaClientOverride(args.container);
93
+ const implementationSelection = this.implementationSelectionFactory.resolve({
94
+ consumerRoot: args.consumerRoot,
95
+ env: args.env,
96
+ runtimeConfig: args.runtimeConfig,
97
+ });
98
+ const runtimeSummary = this.createRuntimeSummary(implementationSelection);
99
+ args.container.resolve(BootRuntimeSnapshotHolder).set(runtimeSummary);
100
+ const eventBus = this.createRunEventBus(implementationSelection);
101
+ const persistence = await this.createRunPersistence(args.container, implementationSelection, eventBus);
102
+ const binaryStorage = this.createBinaryStorage(args.repoRoot);
103
+ const appConfig: AppConfig = this.appConfigFactory.create({
104
+ repoRoot: args.repoRoot,
105
+ consumerRoot: args.consumerRoot,
106
+ env: args.env,
107
+ workflowSources: args.workflowSources,
108
+ runtimeConfig: args.runtimeConfig,
109
+ authConfig: args.applicationAuthConfig,
110
+ whitelabelConfig: args.whitelabelConfig,
111
+ });
112
+
113
+ args.container.registerInstance(CoreTokens.RunEventBus, eventBus);
114
+ args.container.registerInstance(CoreTokens.WorkflowExecutionRepository, persistence.workflowExecutionRepository);
115
+ args.container.registerInstance(CoreTokens.TriggerSetupStateRepository, persistence.triggerSetupStateRepository);
116
+ args.container.registerInstance(CoreTokens.RunDataFactory, new InMemoryRunDataFactory());
117
+ args.container.registerInstance(CoreTokens.BinaryStorage, binaryStorage);
118
+ args.container.registerInstance(
119
+ CoreTokens.ExecutionContextFactory,
120
+ new DefaultExecutionContextFactory(binaryStorage),
121
+ );
122
+ args.container.registerInstance(ApplicationTokens.AppConfig, appConfig);
123
+ args.container.registerInstance(ApplicationTokens.Clock, new SystemClock());
124
+ args.container.registerInstance(ApplicationTokens.CodemationAuthConfig, args.applicationAuthConfig);
125
+ args.container.registerInstance(ApplicationTokens.CodemationWhitelabelConfig, args.whitelabelConfig);
126
+ args.container.registerInstance(ApplicationTokens.WebSocketPort, this.resolveWebSocketPort(args.env));
127
+ args.container.registerInstance(ApplicationTokens.WebSocketBindHost, args.env.CODEMATION_WS_BIND_HOST ?? "0.0.0.0");
128
+ args.container.register(UserAccountService, {
129
+ useFactory: instanceCachingFactory((dependencyContainer) => {
130
+ const prismaClient = dependencyContainer.isRegistered(PrismaClient, true)
131
+ ? dependencyContainer.resolve(PrismaClient)
132
+ : undefined;
133
+ return new UserAccountService(
134
+ dependencyContainer.resolve(ApplicationTokens.CodemationAuthConfig),
135
+ prismaClient,
136
+ );
137
+ }),
138
+ });
139
+ args.container.registerInstance(
140
+ ApplicationTokens.WorkflowDebuggerOverlayRepository,
141
+ persistence.workflowDebuggerOverlayRepository,
142
+ );
143
+ if (persistence.workflowRunRepository) {
144
+ args.container.registerInstance(ApplicationTokens.WorkflowRunRepository, persistence.workflowRunRepository);
145
+ }
146
+ if (persistence.prismaClient) {
147
+ args.container.registerInstance(PrismaClient, persistence.prismaClient);
148
+ args.container.registerInstance(ApplicationTokens.PrismaClient, persistence.prismaClient);
149
+ }
150
+ const workflowActivationRepository = persistence.prismaClient
151
+ ? args.container.resolve(PrismaWorkflowActivationRepository)
152
+ : args.container.resolve(InMemoryWorkflowActivationRepository);
153
+ args.container.registerInstance(ApplicationTokens.WorkflowActivationRepository, workflowActivationRepository);
154
+ if (implementationSelection.databasePersistence.kind !== "none") {
155
+ args.container.registerInstance(ApplicationTokens.CredentialStore, args.container.resolve(PrismaCredentialStore));
156
+ } else {
157
+ args.container.registerInstance(
158
+ ApplicationTokens.CredentialStore,
159
+ args.container.resolve(InMemoryCredentialStore),
160
+ );
161
+ }
162
+ if (!args.hasConfiguredCredentialSessionServiceRegistration) {
163
+ args.container.register(CoreTokens.CredentialSessionService, {
164
+ useFactory: instanceCachingFactory((dependencyContainer) =>
165
+ dependencyContainer.resolve(CredentialSessionServiceImpl),
166
+ ),
167
+ });
168
+ }
169
+ if (implementationSelection.workerRuntimeScheduler) {
170
+ args.container.registerInstance(
171
+ ApplicationTokens.WorkerRuntimeScheduler,
172
+ implementationSelection.workerRuntimeScheduler,
173
+ );
174
+ }
175
+ this.registerRuntimeNodeActivationScheduler(args.container);
176
+
177
+ return new PreparedCodemationRuntime(
178
+ args.container,
179
+ runtimeSummary,
180
+ implementationSelection,
181
+ usesProvidedPrismaClientOverride,
182
+ persistence.ownedPrismaClient ?? null,
183
+ persistence.ownedPglite ?? null,
184
+ );
185
+ }
186
+
187
+ private createRuntimeSummary(selection: ResolvedImplementationSelection): BootRuntimeSummary {
188
+ return {
189
+ databasePersistence: selection.databasePersistence,
190
+ eventBusKind: selection.eventBusKind,
191
+ queuePrefix: selection.queuePrefix,
192
+ schedulerKind: selection.schedulerKind,
193
+ redisUrl: selection.redisUrl,
194
+ };
195
+ }
196
+
197
+ private createRunEventBus(selection: ResolvedImplementationSelection): RunEventBus {
198
+ if (selection.eventBusKind === "redis") {
199
+ return new RedisRunEventBus(this.requireRedisUrl(selection.redisUrl), selection.queuePrefix);
200
+ }
201
+ return new InMemoryRunEventBus();
202
+ }
203
+
204
+ private async createRunPersistence(
205
+ container: Container,
206
+ selection: ResolvedImplementationSelection,
207
+ eventBus: RunEventBus,
208
+ ): Promise<PreparedRuntimePersistence> {
209
+ if (selection.databasePersistence.kind === "none") {
210
+ const workflowRunRepository = container.resolve(InMemoryWorkflowRunRepository);
211
+ return {
212
+ workflowRunRepository,
213
+ triggerSetupStateRepository: container.resolve(InMemoryTriggerSetupStateRepository),
214
+ workflowDebuggerOverlayRepository: container.resolve(InMemoryWorkflowDebuggerOverlayRepository),
215
+ workflowExecutionRepository: new EventPublishingWorkflowExecutionRepository(workflowRunRepository, eventBus),
216
+ };
217
+ }
218
+ const prismaClientResolution = await this.resolveInjectedOrOwnedPrismaClient(
219
+ container,
220
+ selection.databasePersistence,
221
+ );
222
+ const childContainer = container.createChildContainer();
223
+ childContainer.registerInstance(PrismaClient, prismaClientResolution.prismaClient);
224
+ const workflowRunRepository = childContainer.resolve(PrismaWorkflowRunRepository);
225
+ const triggerSetupStateRepository = childContainer.resolve(PrismaTriggerSetupStateRepository);
226
+ const workflowDebuggerOverlayRepository = childContainer.resolve(PrismaWorkflowDebuggerOverlayRepository);
227
+ return {
228
+ prismaClient: prismaClientResolution.prismaClient,
229
+ ownedPrismaClient: prismaClientResolution.ownedPrismaClient,
230
+ ownedPglite: prismaClientResolution.ownedPglite,
231
+ workflowRunRepository,
232
+ triggerSetupStateRepository,
233
+ workflowDebuggerOverlayRepository,
234
+ workflowExecutionRepository: new EventPublishingWorkflowExecutionRepository(workflowRunRepository, eventBus),
235
+ };
236
+ }
237
+
238
+ private hasProvidedPrismaClientOverride(container: Container): boolean {
239
+ return container.isRegistered(PrismaClient, true);
240
+ }
241
+
242
+ private async resolveInjectedOrOwnedPrismaClient(
243
+ container: Container,
244
+ persistence: Exclude<ResolvedDatabasePersistence, Readonly<{ kind: "none" }>>,
245
+ ): Promise<PrismaClientResolution> {
246
+ if (this.hasProvidedPrismaClientOverride(container)) {
247
+ return {
248
+ prismaClient: container.resolve(PrismaClient),
249
+ };
250
+ }
251
+ const factory = container.resolve(PrismaClientFactory);
252
+ if (persistence.kind === "postgresql") {
253
+ const prismaClient = factory.createPostgres(persistence.databaseUrl);
254
+ return {
255
+ prismaClient,
256
+ ownedPrismaClient: prismaClient,
257
+ };
258
+ }
259
+ if (persistence.kind !== "pglite") {
260
+ throw new Error("Unexpected database persistence mode for Prisma.");
261
+ }
262
+ const { prismaClient, pglite } = await factory.createPglite(persistence.dataDir);
263
+ return {
264
+ prismaClient,
265
+ ownedPrismaClient: prismaClient,
266
+ ownedPglite: pglite,
267
+ };
268
+ }
269
+
270
+ private registerRuntimeNodeActivationScheduler(container: Container): void {
271
+ container.register(CoreTokens.NodeActivationScheduler, {
272
+ useFactory: instanceCachingFactory((dependencyContainer) => {
273
+ const inlineScheduler = dependencyContainer.resolve(InlineDrivingScheduler);
274
+ if (!dependencyContainer.isRegistered(ApplicationTokens.WorkerRuntimeScheduler, true)) {
275
+ return inlineScheduler;
276
+ }
277
+ return new DefaultDrivingScheduler(
278
+ new ConfigDrivenOffloadPolicy(),
279
+ dependencyContainer.resolve(ApplicationTokens.WorkerRuntimeScheduler),
280
+ inlineScheduler,
281
+ );
282
+ }),
283
+ });
284
+ }
285
+
286
+ private createBinaryStorage(repoRoot: string): InMemoryBinaryStorage | LocalFilesystemBinaryStorage {
287
+ if (!repoRoot) {
288
+ return new InMemoryBinaryStorage();
289
+ }
290
+ return new LocalFilesystemBinaryStorage(path.join(repoRoot, ".codemation", "binary"));
291
+ }
292
+
293
+ private requireRedisUrl(redisUrl: string | undefined): string {
294
+ if (!redisUrl) {
295
+ throw new Error("Redis-backed runtime requires runtime.eventBus.redisUrl or REDIS_URL.");
296
+ }
297
+ return redisUrl;
298
+ }
299
+
300
+ private resolveWebSocketPort(env: Readonly<NodeJS.ProcessEnv>): number {
301
+ const rawPort = env.CODEMATION_WS_PORT ?? env.VITE_CODEMATION_WS_PORT;
302
+ const parsedPort = Number(rawPort);
303
+ if (Number.isInteger(parsedPort) && parsedPort > 0) {
304
+ return parsedPort;
305
+ }
306
+ return 3001;
307
+ }
308
+ }
@@ -0,0 +1,27 @@
1
+ import { PrismaMigrationDeployer } from "../../infrastructure/persistence/PrismaMigrationDeployer";
2
+ import { RuntimeWorkflowActivationPolicy } from "../../infrastructure/persistence/RuntimeWorkflowActivationPolicy";
3
+ import { ApplicationTokens } from "../../applicationTokens";
4
+ import { PreparedCodemationRuntime } from "../PreparedCodemationRuntime";
5
+
6
+ export class CliRuntimeBootService {
7
+ async boot(args: Readonly<{ preparedRuntime: PreparedCodemationRuntime }>): Promise<void> {
8
+ await this.applyDatabaseMigrations(args.preparedRuntime);
9
+ await args.preparedRuntime.container
10
+ .resolve(RuntimeWorkflowActivationPolicy)
11
+ .hydrateFromRepository(args.preparedRuntime.container.resolve(ApplicationTokens.WorkflowActivationRepository));
12
+ }
13
+
14
+ private async applyDatabaseMigrations(preparedRuntime: PreparedCodemationRuntime): Promise<void> {
15
+ const appConfig = preparedRuntime.container.resolve(ApplicationTokens.AppConfig);
16
+ if (
17
+ preparedRuntime.implementationSelection.databasePersistence.kind === "none" ||
18
+ preparedRuntime.usesProvidedPrismaClientOverride ||
19
+ appConfig.env.CODEMATION_SKIP_STARTUP_MIGRATIONS === "true"
20
+ ) {
21
+ return;
22
+ }
23
+ await preparedRuntime.container
24
+ .resolve(PrismaMigrationDeployer)
25
+ .deployPersistence(preparedRuntime.implementationSelection.databasePersistence, appConfig.env);
26
+ }
27
+ }
@@ -0,0 +1,86 @@
1
+ import { CoreTokens } from "@codemation/core";
2
+ import { instanceCachingFactory } from "@codemation/core";
3
+ import { Engine } from "@codemation/core/bootstrap";
4
+ import { PrismaMigrationDeployer } from "../../infrastructure/persistence/PrismaMigrationDeployer";
5
+ import { RuntimeWorkflowActivationPolicy } from "../../infrastructure/persistence/RuntimeWorkflowActivationPolicy";
6
+ import { DevelopmentSessionBypassVerifier } from "../../infrastructure/auth/DevelopmentSessionBypassVerifier";
7
+ import { AuthJsSessionVerifier } from "../../infrastructure/auth/AuthJsSessionVerifier";
8
+ import { ApplicationTokens } from "../../applicationTokens";
9
+ import { WorkflowRunEventWebsocketRelay } from "../../application/websocket/WorkflowRunEventWebsocketRelay";
10
+ import { ApiPaths } from "../../presentation/http/ApiPaths";
11
+ import { WorkflowWebsocketServer } from "../../presentation/websocket/WorkflowWebsocketServer";
12
+ import { PreparedCodemationRuntime } from "../PreparedCodemationRuntime";
13
+
14
+ export class FrontendRuntimeBootService {
15
+ async boot(
16
+ args: Readonly<{
17
+ preparedRuntime: PreparedCodemationRuntime;
18
+ skipPresentationServers?: boolean;
19
+ }>,
20
+ ): Promise<void> {
21
+ await this.applyDatabaseMigrations(args.preparedRuntime);
22
+ await this.hydrateWorkflowActivationPolicy(args.preparedRuntime);
23
+ this.registerSessionVerification(args.preparedRuntime);
24
+ args.preparedRuntime.container.registerInstance(CoreTokens.WebhookBasePath, ApiPaths.webhooks());
25
+ if (args.skipPresentationServers === true) {
26
+ return;
27
+ }
28
+ const workflowRepository = args.preparedRuntime.container.resolve(CoreTokens.WorkflowRepository);
29
+ await args.preparedRuntime.container.resolve(Engine).start([...workflowRepository.list()]);
30
+ await args.preparedRuntime.container.resolve(WorkflowWebsocketServer).start();
31
+ await args.preparedRuntime.container.resolve(WorkflowRunEventWebsocketRelay).start();
32
+ }
33
+
34
+ private async applyDatabaseMigrations(preparedRuntime: PreparedCodemationRuntime): Promise<void> {
35
+ const appConfig = preparedRuntime.container.resolve(ApplicationTokens.AppConfig);
36
+ if (
37
+ preparedRuntime.implementationSelection.databasePersistence.kind === "none" ||
38
+ preparedRuntime.usesProvidedPrismaClientOverride ||
39
+ appConfig.env.CODEMATION_SKIP_STARTUP_MIGRATIONS === "true"
40
+ ) {
41
+ return;
42
+ }
43
+ await preparedRuntime.container
44
+ .resolve(PrismaMigrationDeployer)
45
+ .deployPersistence(preparedRuntime.implementationSelection.databasePersistence, appConfig.env);
46
+ }
47
+
48
+ private async hydrateWorkflowActivationPolicy(preparedRuntime: PreparedCodemationRuntime): Promise<void> {
49
+ await preparedRuntime.container
50
+ .resolve(RuntimeWorkflowActivationPolicy)
51
+ .hydrateFromRepository(preparedRuntime.container.resolve(ApplicationTokens.WorkflowActivationRepository));
52
+ }
53
+
54
+ private registerSessionVerification(preparedRuntime: PreparedCodemationRuntime): void {
55
+ const appConfig = preparedRuntime.container.resolve(ApplicationTokens.AppConfig);
56
+ const env = appConfig.env;
57
+ const authConfig = appConfig.auth;
58
+ const isProduction = env.NODE_ENV === "production";
59
+ if (isProduction && !authConfig) {
60
+ throw new Error("CodemationConfig.auth is required when NODE_ENV is production.");
61
+ }
62
+ if (isProduction && authConfig?.allowUnauthenticatedInDevelopment === true) {
63
+ throw new Error(
64
+ "CodemationAuthConfig.allowUnauthenticatedInDevelopment is not allowed when NODE_ENV is production.",
65
+ );
66
+ }
67
+ const bypassAllowed = !isProduction && authConfig?.allowUnauthenticatedInDevelopment === true;
68
+ if (bypassAllowed) {
69
+ preparedRuntime.container.register(ApplicationTokens.SessionVerifier, {
70
+ useFactory: instanceCachingFactory((dependencyContainer) =>
71
+ dependencyContainer.resolve(DevelopmentSessionBypassVerifier),
72
+ ),
73
+ });
74
+ return;
75
+ }
76
+ const secret = env.AUTH_SECRET ?? "";
77
+ if (!secret) {
78
+ throw new Error(
79
+ "AUTH_SECRET is required unless CodemationAuthConfig.allowUnauthenticatedInDevelopment is enabled in a non-production environment.",
80
+ );
81
+ }
82
+ preparedRuntime.container.register(ApplicationTokens.SessionVerifier, {
83
+ useFactory: instanceCachingFactory((dependencyContainer) => dependencyContainer.resolve(AuthJsSessionVerifier)),
84
+ });
85
+ }
86
+ }
@@ -0,0 +1,64 @@
1
+ import { CoreTokens } from "@codemation/core";
2
+ import { Engine } from "@codemation/core/bootstrap";
3
+ import type { WorkerRuntimeHandle } from "../../infrastructure/runtime/WorkerRuntimeScheduler";
4
+ import { PrismaMigrationDeployer } from "../../infrastructure/persistence/PrismaMigrationDeployer";
5
+ import { RuntimeWorkflowActivationPolicy } from "../../infrastructure/persistence/RuntimeWorkflowActivationPolicy";
6
+ import { ApplicationTokens } from "../../applicationTokens";
7
+ import { ApiPaths } from "../../presentation/http/ApiPaths";
8
+ import { PreparedCodemationRuntime } from "../PreparedCodemationRuntime";
9
+
10
+ export class WorkerRuntimeBootService {
11
+ async boot(
12
+ args: Readonly<{
13
+ preparedRuntime: PreparedCodemationRuntime;
14
+ queues: ReadonlyArray<string>;
15
+ }>,
16
+ ): Promise<Readonly<{ stop: () => Promise<void> }>> {
17
+ await this.applyDatabaseMigrations(args.preparedRuntime);
18
+ await args.preparedRuntime.container
19
+ .resolve(RuntimeWorkflowActivationPolicy)
20
+ .hydrateFromRepository(args.preparedRuntime.container.resolve(ApplicationTokens.WorkflowActivationRepository));
21
+ args.preparedRuntime.container.registerInstance(CoreTokens.WebhookBasePath, ApiPaths.webhooks());
22
+ if (!args.preparedRuntime.container.isRegistered(ApplicationTokens.WorkerRuntimeScheduler, true)) {
23
+ throw new Error("Worker mode requires a BullMQ scheduler backed by a Redis event bus.");
24
+ }
25
+ const workflows = args.preparedRuntime.container.resolve(CoreTokens.WorkflowRepository).list();
26
+ const engine = args.preparedRuntime.container.resolve(Engine);
27
+ await engine.start([...workflows]);
28
+ const workflowsById = new Map(workflows.map((workflow) => [workflow.id, workflow] as const));
29
+ const scheduler = args.preparedRuntime.container.resolve(ApplicationTokens.WorkerRuntimeScheduler);
30
+ const executionLimitsPolicy = args.preparedRuntime.container.resolve(CoreTokens.EngineExecutionLimitsPolicy);
31
+ const worker: WorkerRuntimeHandle = scheduler.createWorker({
32
+ queues: args.queues,
33
+ workflowsById,
34
+ nodeResolver: args.preparedRuntime.container.resolve(CoreTokens.NodeResolver),
35
+ credentialSessions: args.preparedRuntime.container.resolve(CoreTokens.CredentialSessionService),
36
+ workflowExecutionRepository: args.preparedRuntime.container.resolve(CoreTokens.WorkflowExecutionRepository),
37
+ continuation: engine,
38
+ binaryStorage: args.preparedRuntime.container.resolve(CoreTokens.BinaryStorage),
39
+ workflows: args.preparedRuntime.container.resolve(CoreTokens.WorkflowRunnerService),
40
+ executionLimitsPolicy,
41
+ });
42
+ return {
43
+ stop: async () => {
44
+ await worker.stop();
45
+ await scheduler.close();
46
+ await args.preparedRuntime.stop({ stopWebsocketServer: false });
47
+ },
48
+ };
49
+ }
50
+
51
+ private async applyDatabaseMigrations(preparedRuntime: PreparedCodemationRuntime): Promise<void> {
52
+ const appConfig = preparedRuntime.container.resolve(ApplicationTokens.AppConfig);
53
+ if (
54
+ preparedRuntime.implementationSelection.databasePersistence.kind === "none" ||
55
+ preparedRuntime.usesProvidedPrismaClientOverride ||
56
+ appConfig.env.CODEMATION_SKIP_STARTUP_MIGRATIONS === "true"
57
+ ) {
58
+ return;
59
+ }
60
+ await preparedRuntime.container
61
+ .resolve(PrismaMigrationDeployer)
62
+ .deployPersistence(preparedRuntime.implementationSelection.databasePersistence, appConfig.env);
63
+ }
64
+ }
@@ -0,0 +1,57 @@
1
+ import type { AppConfig } from "../../presentation/config/AppConfig";
2
+ import type { CodemationAuthConfig } from "../../presentation/config/CodemationAuthConfig";
3
+ import type { CodemationApplicationRuntimeConfig } from "../../presentation/config/CodemationConfig";
4
+ import type { CodemationWhitelabelConfig } from "../../presentation/config/CodemationWhitelabelConfig";
5
+ import { ResolvedImplementationSelectionFactory } from "./ResolvedImplementationSelectionFactory";
6
+
7
+ export class AppConfigFactory {
8
+ constructor(
9
+ private readonly implementationSelectionFactory: ResolvedImplementationSelectionFactory = new ResolvedImplementationSelectionFactory(),
10
+ ) {}
11
+
12
+ create(
13
+ args: Readonly<{
14
+ repoRoot: string;
15
+ consumerRoot: string;
16
+ env: NodeJS.ProcessEnv;
17
+ workflowSources: ReadonlyArray<string>;
18
+ runtimeConfig: CodemationApplicationRuntimeConfig;
19
+ authConfig: CodemationAuthConfig | undefined;
20
+ whitelabelConfig: CodemationWhitelabelConfig;
21
+ }>,
22
+ ): AppConfig {
23
+ const selection = this.implementationSelectionFactory.resolve({
24
+ consumerRoot: args.consumerRoot,
25
+ env: args.env,
26
+ runtimeConfig: args.runtimeConfig,
27
+ });
28
+ const workerQueues = args.runtimeConfig.scheduler?.workerQueues ?? [];
29
+ const queuePrefix = args.runtimeConfig.scheduler?.queuePrefix ?? args.runtimeConfig.eventBus?.queuePrefix;
30
+ const databaseUrl =
31
+ selection.databasePersistence.kind === "postgresql"
32
+ ? selection.databasePersistence.databaseUrl
33
+ : args.runtimeConfig.database?.url?.trim() || undefined;
34
+
35
+ return {
36
+ consumerRoot: args.consumerRoot,
37
+ repoRoot: args.repoRoot,
38
+ env: args.env,
39
+ workflowSources: [...args.workflowSources],
40
+ databaseUrl,
41
+ database: args.runtimeConfig.database,
42
+ scheduler: {
43
+ kind: selection.schedulerKind,
44
+ queuePrefix,
45
+ workerQueues,
46
+ redisUrl: selection.redisUrl,
47
+ },
48
+ eventing: {
49
+ kind: selection.eventBusKind,
50
+ queuePrefix,
51
+ redisUrl: selection.redisUrl,
52
+ },
53
+ auth: args.authConfig,
54
+ whitelabel: args.whitelabelConfig,
55
+ };
56
+ }
57
+ }