@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,20 @@
1
+ -- AlterTable
2
+ ALTER TABLE "codemation_auth_user" ADD COLUMN "account_status" TEXT NOT NULL DEFAULT 'active';
3
+
4
+ -- CreateTable
5
+ CREATE TABLE "codemation_auth_user_invite" (
6
+ "id" TEXT NOT NULL,
7
+ "user_id" TEXT NOT NULL,
8
+ "token_hash" TEXT NOT NULL,
9
+ "expires_at" TIMESTAMP(3) NOT NULL,
10
+ "created_at" TIMESTAMP(3) NOT NULL,
11
+ "revoked_at" TIMESTAMP(3),
12
+
13
+ CONSTRAINT "codemation_auth_user_invite_pkey" PRIMARY KEY ("id")
14
+ );
15
+
16
+ CREATE UNIQUE INDEX "codemation_auth_user_invite_token_hash_key" ON "codemation_auth_user_invite"("token_hash");
17
+
18
+ CREATE INDEX "codemation_auth_user_invite_user_id_idx" ON "codemation_auth_user_invite"("user_id");
19
+
20
+ ALTER TABLE "codemation_auth_user_invite" ADD CONSTRAINT "codemation_auth_user_invite_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "codemation_auth_user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,8 @@
1
+ -- CreateTable
2
+ CREATE TABLE "WorkflowActivation" (
3
+ "workflow_id" TEXT NOT NULL,
4
+ "is_active" BOOLEAN NOT NULL DEFAULT false,
5
+ "updated_at" TEXT NOT NULL,
6
+
7
+ CONSTRAINT "WorkflowActivation_pkey" PRIMARY KEY ("workflow_id")
8
+ );
@@ -0,0 +1,3 @@
1
+ # Please do not edit this file manually
2
+ # It should be added in your version-control system (e.g., Git)
3
+ provider = "postgresql"
@@ -0,0 +1,179 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ output = "../src/infrastructure/persistence/generated/prisma-client"
4
+ }
5
+
6
+ datasource db {
7
+ provider = "postgresql"
8
+ }
9
+
10
+ model Run {
11
+ runId String @id @map("run_id")
12
+ workflowId String @map("workflow_id")
13
+ startedAt String @map("started_at")
14
+ status String
15
+ parentJson String? @map("parent_json")
16
+ executionOptionsJson String? @map("execution_options_json")
17
+ updatedAt String @map("updated_at")
18
+ stateJson String @map("state_json")
19
+ }
20
+
21
+ model WorkflowDebuggerOverlay {
22
+ workflowId String @id @map("workflow_id")
23
+ updatedAt String @map("updated_at")
24
+ copiedFromRunId String? @map("copied_from_run_id")
25
+ stateJson String @map("state_json")
26
+ }
27
+
28
+ model WorkflowActivation {
29
+ workflowId String @id @map("workflow_id")
30
+ isActive Boolean @default(false) @map("is_active")
31
+ updatedAt String @map("updated_at")
32
+ }
33
+
34
+ model TriggerSetupState {
35
+ workflowId String @map("workflow_id")
36
+ nodeId String @map("node_id")
37
+ updatedAt String @map("updated_at")
38
+ stateJson String @map("state_json")
39
+
40
+ @@id([workflowId, nodeId])
41
+ }
42
+
43
+ model CredentialInstance {
44
+ instanceId String @id @map("instance_id")
45
+ typeId String @map("type_id")
46
+ displayName String @map("display_name")
47
+ sourceKind String @map("source_kind")
48
+ publicConfigJson String @map("public_config_json")
49
+ secretRefJson String @map("secret_ref_json")
50
+ tagsJson String @map("tags_json")
51
+ setupStatus String @map("setup_status")
52
+ createdAt String @map("created_at")
53
+ updatedAt String @map("updated_at")
54
+ }
55
+
56
+ model CredentialSecretMaterial {
57
+ instanceId String @id @map("instance_id")
58
+ encryptedJson String @map("encrypted_json")
59
+ encryptionKeyId String @map("encryption_key_id")
60
+ schemaVersion Int @map("schema_version")
61
+ updatedAt String @map("updated_at")
62
+ }
63
+
64
+ model CredentialOAuth2Material {
65
+ instanceId String @id @map("instance_id")
66
+ encryptedJson String @map("encrypted_json")
67
+ encryptionKeyId String @map("encryption_key_id")
68
+ schemaVersion Int @map("schema_version")
69
+ providerId String @map("provider_id")
70
+ connectedEmail String? @map("connected_email")
71
+ connectedAt String? @map("connected_at")
72
+ scopesJson String @map("scopes_json")
73
+ updatedAt String @map("updated_at")
74
+ }
75
+
76
+ model CredentialOAuth2State {
77
+ state String @id
78
+ instanceId String @map("instance_id")
79
+ codeVerifier String? @map("code_verifier")
80
+ providerId String? @map("provider_id")
81
+ requestedScopesJson String @map("requested_scopes_json")
82
+ createdAt String @map("created_at")
83
+ expiresAt String @map("expires_at")
84
+
85
+ @@index([instanceId])
86
+ @@index([expiresAt])
87
+ }
88
+
89
+ model CredentialBinding {
90
+ workflowId String @map("workflow_id")
91
+ nodeId String @map("node_id")
92
+ slotKey String @map("slot_key")
93
+ instanceId String @map("instance_id")
94
+ updatedAt String @map("updated_at")
95
+
96
+ @@id([workflowId, nodeId, slotKey])
97
+ @@index([instanceId])
98
+ }
99
+
100
+ model CredentialTestResult {
101
+ testId String @id @map("test_id")
102
+ instanceId String @map("instance_id")
103
+ status String
104
+ message String?
105
+ detailsJson String @map("details_json")
106
+ testedAt String @map("tested_at")
107
+ expiresAt String? @map("expires_at")
108
+
109
+ @@index([instanceId, testedAt])
110
+ }
111
+
112
+ /// Auth.js / NextAuth user directory (JWT sessions; optional OAuth linking)
113
+ model User {
114
+ id String @id @default(cuid())
115
+ name String?
116
+ email String? @unique
117
+ emailVerified DateTime? @map("email_verified")
118
+ image String?
119
+ passwordHash String? @map("password_hash")
120
+ /// invited | active | inactive (local directory / invite flow)
121
+ accountStatus String @default("active") @map("account_status")
122
+ accounts Account[]
123
+ sessions Session[]
124
+ invites UserInvite[]
125
+
126
+ @@map("codemation_auth_user")
127
+ }
128
+
129
+ model UserInvite {
130
+ id String @id @default(cuid())
131
+ userId String @map("user_id")
132
+ tokenHash String @unique @map("token_hash")
133
+ expiresAt DateTime @map("expires_at")
134
+ createdAt DateTime @map("created_at")
135
+ revokedAt DateTime? @map("revoked_at")
136
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
137
+
138
+ @@index([userId])
139
+ @@map("codemation_auth_user_invite")
140
+ }
141
+
142
+ model Account {
143
+ id String @id @default(cuid())
144
+ userId String @map("user_id")
145
+ type String
146
+ provider String
147
+ providerAccountId String @map("provider_account_id")
148
+ refresh_token String? @db.Text
149
+ access_token String? @db.Text
150
+ expires_at Int?
151
+ token_type String?
152
+ scope String? @db.Text
153
+ id_token String? @db.Text
154
+ session_state String?
155
+
156
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
157
+
158
+ @@unique([provider, providerAccountId])
159
+ @@map("codemation_auth_account")
160
+ }
161
+
162
+ model Session {
163
+ id String @id @default(cuid())
164
+ sessionToken String @unique @map("session_token")
165
+ userId String @map("user_id")
166
+ expires DateTime
167
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
168
+
169
+ @@map("codemation_auth_session")
170
+ }
171
+
172
+ model VerificationToken {
173
+ identifier String
174
+ token String
175
+ expires DateTime
176
+
177
+ @@unique([identifier, token])
178
+ @@map("codemation_auth_verification_token")
179
+ }
@@ -0,0 +1,12 @@
1
+ import "dotenv/config";
2
+ import { defineConfig, env } from "prisma/config";
3
+
4
+ export default defineConfig({
5
+ schema: "prisma/schema.prisma",
6
+ migrations: {
7
+ path: "prisma/migrations",
8
+ },
9
+ datasource: {
10
+ url: env("DATABASE_URL"),
11
+ },
12
+ });
@@ -0,0 +1,42 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ /**
6
+ * Prisma's generated `runtime/*.js` files end with `//# sourceMappingURL=*.map`, but Prisma does not
7
+ * ship those `.map` files (see prisma/prisma#28373). Vite then logs ENOENT on every transform.
8
+ * We write minimal valid sourcemaps so the URL resolves and stack tooling stays stable.
9
+ */
10
+ const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
11
+ const runtimeDir = path.resolve(packageRoot, "src/infrastructure/persistence/generated/prisma-client/runtime");
12
+
13
+ function writeStub(mapFileName, jsFileName) {
14
+ const mapPath = path.join(runtimeDir, mapFileName);
15
+ const jsPath = path.join(runtimeDir, jsFileName);
16
+ if (!fs.existsSync(jsPath)) {
17
+ return;
18
+ }
19
+ const payload = JSON.stringify({
20
+ version: 3,
21
+ file: jsFileName,
22
+ sources: [],
23
+ names: [],
24
+ mappings: "",
25
+ });
26
+ fs.writeFileSync(mapPath, `${payload}\n`, "utf8");
27
+ }
28
+
29
+ export default function ensurePrismaRuntimeSourcemaps() {
30
+ if (!fs.existsSync(runtimeDir)) {
31
+ return;
32
+ }
33
+ writeStub("client.js.map", "client.js");
34
+ writeStub("index-browser.js.map", "index-browser.js");
35
+ writeStub("wasm-compiler-edge.js.map", "wasm-compiler-edge.js");
36
+ }
37
+
38
+ const selfPath = path.resolve(fileURLToPath(import.meta.url));
39
+ const invokedDirectly = path.resolve(process.argv[1] ?? "") === selfPath;
40
+ if (invokedDirectly) {
41
+ ensurePrismaRuntimeSourcemaps();
42
+ }
@@ -0,0 +1,30 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { spawnSync } from "node:child_process";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const hostPackageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
7
+ const repoRoot = path.resolve(hostPackageRoot, "..", "..");
8
+ const runner = path.join(hostPackageRoot, "test/http/testkit/IntegrationDatabaseGlobalSetupRunner.ts");
9
+ const cachePath = path.join(hostPackageRoot, ".cache", "integration-database.json");
10
+
11
+ export default function integrationDatabaseGlobalSetup() {
12
+ if (!process.env.DATABASE_URL?.trim()) {
13
+ return;
14
+ }
15
+ const result = spawnSync("pnpm", ["exec", "tsx", runner], {
16
+ cwd: repoRoot,
17
+ stdio: "inherit",
18
+ env: process.env,
19
+ shell: true,
20
+ });
21
+ if (result.status !== 0) {
22
+ throw new Error("Integration database global setup failed.");
23
+ }
24
+ if (existsSync(cachePath)) {
25
+ const payload = JSON.parse(readFileSync(cachePath, "utf8"));
26
+ if (payload?.databaseUrl && typeof payload.databaseUrl === "string") {
27
+ process.env.CODEMATION_INTEGRATION_SHARED_DATABASE_URL = payload.databaseUrl;
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,12 @@
1
+ export class ApplicationRequestError extends Error {
2
+ readonly status: number;
3
+
4
+ readonly payload: Readonly<{ error: string; errors?: ReadonlyArray<string> }>;
5
+
6
+ constructor(status: number, message: string, errors?: ReadonlyArray<string>) {
7
+ super(message);
8
+ this.name = "ApplicationRequestError";
9
+ this.status = status;
10
+ this.payload = errors && errors.length > 0 ? { error: message, errors } : { error: message };
11
+ }
12
+ }
@@ -0,0 +1,5 @@
1
+ export type AuthenticatedPrincipal = Readonly<{
2
+ id: string;
3
+ email: string | null;
4
+ name: string | null;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import type { AuthenticatedPrincipal } from "./AuthenticatedPrincipal";
2
+
3
+ export interface SessionVerifier {
4
+ verify(request: Request): Promise<AuthenticatedPrincipal | null>;
5
+ }
@@ -0,0 +1,119 @@
1
+ import type { BinaryAttachment, BinaryBody, BinaryPreviewKind, BinaryStorage } from "@codemation/core";
2
+ import { CoreTokens, inject, injectable } from "@codemation/core";
3
+ import sanitizeFilename from "sanitize-filename";
4
+
5
+ /** Sentinel run id for debugger-overlay pinned-output uploads (not a real execution). */
6
+ export const OVERLAY_PIN_BINARY_RUN_ID = "overlay-pin";
7
+
8
+ @injectable()
9
+ export class OverlayPinnedBinaryUploadService {
10
+ constructor(@inject(CoreTokens.BinaryStorage) private readonly binaryStorage: BinaryStorage) {}
11
+
12
+ async attach(
13
+ args: Readonly<{
14
+ workflowId: string;
15
+ nodeId: string;
16
+ itemIndex: number;
17
+ name: string;
18
+ body: BinaryBody;
19
+ mimeType: string;
20
+ filename?: string;
21
+ previewKind?: BinaryAttachment["previewKind"];
22
+ }>,
23
+ ): Promise<BinaryAttachment> {
24
+ const attachmentId = this.createAttachmentId();
25
+ const createdAt = new Date().toISOString();
26
+ const activationId = this.overlayActivationId(args.itemIndex);
27
+ const storageKey = this.createStorageKey({
28
+ workflowId: args.workflowId,
29
+ runId: OVERLAY_PIN_BINARY_RUN_ID,
30
+ nodeId: args.nodeId,
31
+ activationId,
32
+ attachmentId,
33
+ name: args.name,
34
+ filename: args.filename,
35
+ });
36
+ const stored = await this.binaryStorage.write({
37
+ storageKey,
38
+ body: args.body,
39
+ });
40
+ return {
41
+ id: attachmentId,
42
+ storageKey: stored.storageKey,
43
+ mimeType: args.mimeType,
44
+ size: stored.size,
45
+ storageDriver: this.binaryStorage.driverName,
46
+ previewKind: args.previewKind ?? this.resolvePreviewKind(args.mimeType),
47
+ createdAt,
48
+ runId: OVERLAY_PIN_BINARY_RUN_ID,
49
+ workflowId: args.workflowId,
50
+ nodeId: args.nodeId,
51
+ activationId,
52
+ filename: args.filename,
53
+ sha256: stored.sha256,
54
+ };
55
+ }
56
+
57
+ private overlayActivationId(itemIndex: number): string {
58
+ return `overlay-pin-i${itemIndex}`;
59
+ }
60
+
61
+ private createAttachmentId(): string {
62
+ const cryptoObject = globalThis.crypto;
63
+ if (cryptoObject && typeof cryptoObject.randomUUID === "function") {
64
+ return cryptoObject.randomUUID();
65
+ }
66
+ return `bin-${Date.now()}-${Math.random().toString(16).slice(2)}`;
67
+ }
68
+
69
+ private createStorageKey(
70
+ args: Readonly<{
71
+ workflowId: string;
72
+ runId: string;
73
+ nodeId: string;
74
+ activationId: string;
75
+ attachmentId: string;
76
+ name: string;
77
+ filename?: string;
78
+ }>,
79
+ ): string {
80
+ const safeName = this.sanitizeSegment(args.name);
81
+ const safeFilename = this.sanitizeFilenameForKey(args.filename);
82
+ const filenameSuffix = safeFilename ? `-${safeFilename}` : "";
83
+ return `${this.sanitizeSegment(args.workflowId)}/${this.sanitizeSegment(args.runId)}/${this.sanitizeSegment(args.nodeId)}/${this.sanitizeSegment(args.activationId)}/${args.attachmentId}-${safeName}${filenameSuffix}`;
84
+ }
85
+
86
+ private sanitizeSegment(value: string): string {
87
+ const normalized = value.trim();
88
+ if (!normalized) {
89
+ return "item";
90
+ }
91
+ const safe = sanitizeFilename(normalized);
92
+ return safe || "item";
93
+ }
94
+
95
+ private sanitizeFilenameForKey(value: string | undefined): string | undefined {
96
+ if (!value) {
97
+ return undefined;
98
+ }
99
+ const basename = value.trim().split("/").at(-1)?.split("\\").at(-1) ?? value.trim();
100
+ if (!basename) {
101
+ return undefined;
102
+ }
103
+ const safe = sanitizeFilename(basename);
104
+ return safe || undefined;
105
+ }
106
+
107
+ private resolvePreviewKind(mimeType: string): BinaryPreviewKind {
108
+ if (mimeType.startsWith("image/")) {
109
+ return "image";
110
+ }
111
+ if (mimeType.startsWith("audio/")) {
112
+ return "audio";
113
+ }
114
+ if (mimeType.startsWith("video/")) {
115
+ return "video";
116
+ }
117
+ return "download";
118
+ }
119
+ }
@@ -0,0 +1,139 @@
1
+ import type { BinaryAttachment, Items, PersistedRunState, RunCurrentState } from "@codemation/core";
2
+ import { inject, injectable } from "@codemation/core";
3
+ import { ApplicationTokens } from "../../applicationTokens";
4
+ import type { WorkflowRunRepository } from "../../domain/runs/WorkflowRunRepository";
5
+ import type { WorkflowDebuggerOverlayRepository } from "../../domain/workflows/WorkflowDebuggerOverlayRepository";
6
+
7
+ @injectable()
8
+ export class RunBinaryAttachmentLookupService {
9
+ constructor(
10
+ @inject(ApplicationTokens.WorkflowRunRepository)
11
+ private readonly workflowRunRepository: WorkflowRunRepository,
12
+ @inject(ApplicationTokens.WorkflowDebuggerOverlayRepository)
13
+ private readonly workflowDebuggerOverlayRepository: WorkflowDebuggerOverlayRepository,
14
+ ) {}
15
+
16
+ async findForRun(runId: string, binaryId: string): Promise<BinaryAttachment | undefined> {
17
+ const state = await this.workflowRunRepository.load(runId);
18
+ if (!state) {
19
+ return undefined;
20
+ }
21
+ return this.findInRunState(state, binaryId);
22
+ }
23
+
24
+ async findForWorkflowOverlay(workflowId: string, binaryId: string): Promise<BinaryAttachment | undefined> {
25
+ const state = await this.workflowDebuggerOverlayRepository.load(workflowId);
26
+ if (!state) {
27
+ return undefined;
28
+ }
29
+ return this.findInCurrentState(state.currentState, binaryId);
30
+ }
31
+
32
+ private findInRunState(state: PersistedRunState, binaryId: string): BinaryAttachment | undefined {
33
+ const inOutputs = this.findInOutputsByNode(state.outputsByNode, binaryId);
34
+ if (inOutputs) {
35
+ return inOutputs;
36
+ }
37
+ const inSnapshots = this.findInNodeSnapshots(state, binaryId);
38
+ if (inSnapshots) {
39
+ return inSnapshots;
40
+ }
41
+ return this.findInMutableState(state.mutableState, binaryId);
42
+ }
43
+
44
+ private findInCurrentState(state: RunCurrentState, binaryId: string): BinaryAttachment | undefined {
45
+ const inOutputs = this.findInOutputsByNode(state.outputsByNode, binaryId);
46
+ if (inOutputs) {
47
+ return inOutputs;
48
+ }
49
+ const inSnapshots = this.findInCurrentStateSnapshots(state, binaryId);
50
+ if (inSnapshots) {
51
+ return inSnapshots;
52
+ }
53
+ return this.findInMutableState(state.mutableState, binaryId);
54
+ }
55
+
56
+ private findInOutputsByNode(
57
+ outputsByNode: Readonly<Record<string, Readonly<Partial<Record<string, Items>>>>>,
58
+ binaryId: string,
59
+ ): BinaryAttachment | undefined {
60
+ for (const outputs of Object.values(outputsByNode)) {
61
+ for (const items of Object.values(outputs)) {
62
+ const attachment = this.findInItems(items, binaryId);
63
+ if (attachment) {
64
+ return attachment;
65
+ }
66
+ }
67
+ }
68
+ return undefined;
69
+ }
70
+
71
+ private findInNodeSnapshots(state: PersistedRunState, binaryId: string): BinaryAttachment | undefined {
72
+ for (const snapshot of Object.values(state.nodeSnapshotsByNodeId)) {
73
+ const inInputs = this.findInPortItemMap(snapshot.inputsByPort, binaryId);
74
+ if (inInputs) {
75
+ return inInputs;
76
+ }
77
+ const inOutputs = this.findInPortItemMap(snapshot.outputs, binaryId);
78
+ if (inOutputs) {
79
+ return inOutputs;
80
+ }
81
+ }
82
+ return undefined;
83
+ }
84
+
85
+ private findInCurrentStateSnapshots(state: RunCurrentState, binaryId: string): BinaryAttachment | undefined {
86
+ for (const snapshot of Object.values(state.nodeSnapshotsByNodeId)) {
87
+ const inInputs = this.findInPortItemMap(snapshot.inputsByPort, binaryId);
88
+ if (inInputs) {
89
+ return inInputs;
90
+ }
91
+ const inOutputs = this.findInPortItemMap(snapshot.outputs, binaryId);
92
+ if (inOutputs) {
93
+ return inOutputs;
94
+ }
95
+ }
96
+ return undefined;
97
+ }
98
+
99
+ private findInMutableState(
100
+ mutableState: PersistedRunState["mutableState"] | RunCurrentState["mutableState"] | undefined,
101
+ binaryId: string,
102
+ ): BinaryAttachment | undefined {
103
+ for (const nodeState of Object.values(mutableState?.nodesById ?? {})) {
104
+ const inPinned = this.findInPortItemMap(nodeState.pinnedOutputsByPort, binaryId);
105
+ if (inPinned) {
106
+ return inPinned;
107
+ }
108
+ const inDebugInput = this.findInItems(nodeState.lastDebugInput, binaryId);
109
+ if (inDebugInput) {
110
+ return inDebugInput;
111
+ }
112
+ }
113
+ return undefined;
114
+ }
115
+
116
+ private findInPortItemMap(
117
+ itemMap: Readonly<Partial<Record<string, Items>>> | undefined,
118
+ binaryId: string,
119
+ ): BinaryAttachment | undefined {
120
+ for (const items of Object.values(itemMap ?? {})) {
121
+ const attachment = this.findInItems(items, binaryId);
122
+ if (attachment) {
123
+ return attachment;
124
+ }
125
+ }
126
+ return undefined;
127
+ }
128
+
129
+ private findInItems(items: Items | undefined, binaryId: string): BinaryAttachment | undefined {
130
+ for (const item of items ?? []) {
131
+ for (const attachment of Object.values(item.binary ?? {})) {
132
+ if (attachment.id === binaryId) {
133
+ return attachment;
134
+ }
135
+ }
136
+ }
137
+ return undefined;
138
+ }
139
+ }
@@ -0,0 +1,57 @@
1
+ import type { BinaryAttachment, Items, PersistedRunState } from "@codemation/core";
2
+
3
+ /**
4
+ * Collects every `storageKey` referenced by binary attachments embedded in persisted run state
5
+ * (outputs, node snapshots, mutable debugger state).
6
+ */
7
+ export class RunStateBinaryStorageKeysCollector {
8
+ collectFromRunState(state: PersistedRunState): ReadonlySet<string> {
9
+ const keys = new Set<string>();
10
+ this.addFromOutputsByNode(state.outputsByNode, keys);
11
+ this.addFromNodeSnapshots(state, keys);
12
+ this.addFromMutableState(state.mutableState, keys);
13
+ return keys;
14
+ }
15
+
16
+ private addFromOutputsByNode(outputsByNode: PersistedRunState["outputsByNode"], keys: Set<string>): void {
17
+ for (const outputs of Object.values(outputsByNode)) {
18
+ for (const items of Object.values(outputs)) {
19
+ this.addFromItems(items, keys);
20
+ }
21
+ }
22
+ }
23
+
24
+ private addFromNodeSnapshots(state: PersistedRunState, keys: Set<string>): void {
25
+ for (const snapshot of Object.values(state.nodeSnapshotsByNodeId)) {
26
+ this.addFromPortMap(snapshot.inputsByPort, keys);
27
+ this.addFromPortMap(snapshot.outputs, keys);
28
+ }
29
+ }
30
+
31
+ private addFromMutableState(mutableState: PersistedRunState["mutableState"], keys: Set<string>): void {
32
+ for (const nodeState of Object.values(mutableState?.nodesById ?? {})) {
33
+ this.addFromPortMap(nodeState.pinnedOutputsByPort, keys);
34
+ this.addFromItems(nodeState.lastDebugInput, keys);
35
+ }
36
+ }
37
+
38
+ private addFromPortMap(itemMap: Readonly<Partial<Record<string, Items>>> | undefined, keys: Set<string>): void {
39
+ for (const items of Object.values(itemMap ?? {})) {
40
+ this.addFromItems(items, keys);
41
+ }
42
+ }
43
+
44
+ private addFromItems(items: Items | undefined, keys: Set<string>): void {
45
+ for (const item of items ?? []) {
46
+ for (const attachment of Object.values(item.binary ?? {})) {
47
+ this.addAttachment(attachment, keys);
48
+ }
49
+ }
50
+ }
51
+
52
+ private addAttachment(attachment: BinaryAttachment, keys: Set<string>): void {
53
+ if (attachment.storageKey.length > 0) {
54
+ keys.add(attachment.storageKey);
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,3 @@
1
+ export abstract class Command<TResult> {
2
+ protected readonly __resultType?: TResult;
3
+ }
@@ -0,0 +1,5 @@
1
+ import type { Command } from "./Command";
2
+
3
+ export interface CommandBus {
4
+ execute<TResult>(command: Command<TResult>): Promise<TResult>;
5
+ }
@@ -0,0 +1,5 @@
1
+ import type { Command } from "./Command";
2
+
3
+ export abstract class CommandHandler<TCommand extends Command<TResult>, TResult> {
4
+ abstract execute(command: TCommand): Promise<TResult>;
5
+ }
@@ -0,0 +1 @@
1
+ export abstract class DomainEvent {}
@@ -0,0 +1,5 @@
1
+ import type { DomainEvent } from "./DomainEvent";
2
+
3
+ export interface DomainEventBus {
4
+ publish(event: DomainEvent): Promise<void>;
5
+ }
@@ -0,0 +1,5 @@
1
+ import type { DomainEvent } from "./DomainEvent";
2
+
3
+ export abstract class DomainEventHandler<TEvent extends DomainEvent> {
4
+ abstract handle(event: TEvent): Promise<void>;
5
+ }