@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,47 @@
1
+ import { injectAll, injectable } from "@codemation/core";
2
+ import type { Command } from "../../application/bus/Command";
3
+ import type { CommandBus } from "../../application/bus/CommandBus";
4
+ import type { CommandHandler } from "../../application/bus/CommandHandler";
5
+ import { ApplicationTokens } from "../../applicationTokens";
6
+ import { commandHandlerMetadataKey } from "./HandlesCommandRegistry";
7
+
8
+ type CommandType = abstract new (...args: any[]) => Command<unknown>;
9
+
10
+ @injectable()
11
+ export class InMemoryCommandBus implements CommandBus {
12
+ private readonly handlersByCommandType: ReadonlyMap<CommandType, CommandHandler<Command<unknown>, unknown>>;
13
+
14
+ constructor(
15
+ @injectAll(ApplicationTokens.CommandHandler)
16
+ handlers: ReadonlyArray<CommandHandler<Command<unknown>, unknown>>,
17
+ ) {
18
+ this.handlersByCommandType = this.createHandlersByCommandType(handlers);
19
+ }
20
+
21
+ async execute<TResult>(command: Command<TResult>): Promise<TResult> {
22
+ const handler = this.handlersByCommandType.get(command.constructor as CommandType);
23
+ if (!handler) {
24
+ throw new Error(`No command handler registered for ${command.constructor.name}`);
25
+ }
26
+ return (await handler.execute(command as Command<unknown>)) as TResult;
27
+ }
28
+
29
+ private createHandlersByCommandType(
30
+ handlers: ReadonlyArray<CommandHandler<Command<unknown>, unknown>>,
31
+ ): ReadonlyMap<CommandType, CommandHandler<Command<unknown>, unknown>> {
32
+ const handlersByCommandType = new Map<CommandType, CommandHandler<Command<unknown>, unknown>>();
33
+ for (const handler of handlers) {
34
+ const commandType = Reflect.getMetadata(commandHandlerMetadataKey, handler.constructor) as
35
+ | CommandType
36
+ | undefined;
37
+ if (!commandType) {
38
+ throw new Error(`Command handler ${handler.constructor.name} is missing @HandlesCommand metadata.`);
39
+ }
40
+ if (handlersByCommandType.has(commandType)) {
41
+ throw new Error(`Duplicate command handler registered for ${commandType.name}.`);
42
+ }
43
+ handlersByCommandType.set(commandType, handler);
44
+ }
45
+ return handlersByCommandType;
46
+ }
47
+ }
@@ -0,0 +1,47 @@
1
+ import { injectAll, injectable } from "@codemation/core";
2
+ import type { DomainEvent } from "../../application/bus/DomainEvent";
3
+ import type { DomainEventBus } from "../../application/bus/DomainEventBus";
4
+ import type { DomainEventHandler } from "../../application/bus/DomainEventHandler";
5
+ import { ApplicationTokens } from "../../applicationTokens";
6
+ import { domainEventHandlerMetadataKey } from "./HandlesDomainEventRegistry";
7
+
8
+ type DomainEventType = abstract new (...args: any[]) => DomainEvent;
9
+
10
+ @injectable()
11
+ export class InMemoryDomainEventBus implements DomainEventBus {
12
+ private readonly handlersByEventType: ReadonlyMap<DomainEventType, ReadonlyArray<DomainEventHandler<DomainEvent>>>;
13
+
14
+ constructor(
15
+ @injectAll(ApplicationTokens.DomainEventHandler)
16
+ handlers: ReadonlyArray<DomainEventHandler<DomainEvent>>,
17
+ ) {
18
+ this.handlersByEventType = this.createHandlersByEventType(handlers);
19
+ }
20
+
21
+ async publish(event: DomainEvent): Promise<void> {
22
+ const handlers = this.handlersByEventType.get(event.constructor as DomainEventType) ?? [];
23
+ for (const handler of handlers) {
24
+ await handler.handle(event);
25
+ }
26
+ }
27
+
28
+ private createHandlersByEventType(
29
+ handlers: ReadonlyArray<DomainEventHandler<DomainEvent>>,
30
+ ): ReadonlyMap<DomainEventType, ReadonlyArray<DomainEventHandler<DomainEvent>>> {
31
+ const handlersByEventType = new Map<DomainEventType, Array<DomainEventHandler<DomainEvent>>>();
32
+ for (const handler of handlers) {
33
+ const eventType = Reflect.getMetadata(domainEventHandlerMetadataKey, handler.constructor) as
34
+ | DomainEventType
35
+ | undefined;
36
+ if (!eventType) {
37
+ throw new Error(`Domain event handler ${handler.constructor.name} is missing @HandlesDomainEvent metadata.`);
38
+ }
39
+ const currentHandlers = handlersByEventType.get(eventType) ?? [];
40
+ currentHandlers.push(handler);
41
+ handlersByEventType.set(eventType, currentHandlers);
42
+ }
43
+ return new Map(
44
+ [...handlersByEventType.entries()].map(([eventType, eventHandlers]) => [eventType, [...eventHandlers]] as const),
45
+ );
46
+ }
47
+ }
@@ -0,0 +1,45 @@
1
+ import { injectAll, injectable } from "@codemation/core";
2
+ import type { Query } from "../../application/bus/Query";
3
+ import type { QueryBus } from "../../application/bus/QueryBus";
4
+ import type { QueryHandler } from "../../application/bus/QueryHandler";
5
+ import { ApplicationTokens } from "../../applicationTokens";
6
+ import { queryHandlerMetadataKey } from "./HandlesQueryRegistry";
7
+
8
+ type QueryType = abstract new (...args: any[]) => Query<unknown>;
9
+
10
+ @injectable()
11
+ export class InMemoryQueryBus implements QueryBus {
12
+ private readonly handlersByQueryType: ReadonlyMap<QueryType, QueryHandler<Query<unknown>, unknown>>;
13
+
14
+ constructor(
15
+ @injectAll(ApplicationTokens.QueryHandler)
16
+ handlers: ReadonlyArray<QueryHandler<Query<unknown>, unknown>>,
17
+ ) {
18
+ this.handlersByQueryType = this.createHandlersByQueryType(handlers);
19
+ }
20
+
21
+ async execute<TResult>(query: Query<TResult>): Promise<TResult> {
22
+ const handler = this.handlersByQueryType.get(query.constructor as QueryType);
23
+ if (!handler) {
24
+ throw new Error(`No query handler registered for ${query.constructor.name}`);
25
+ }
26
+ return (await handler.execute(query as Query<unknown>)) as TResult;
27
+ }
28
+
29
+ private createHandlersByQueryType(
30
+ handlers: ReadonlyArray<QueryHandler<Query<unknown>, unknown>>,
31
+ ): ReadonlyMap<QueryType, QueryHandler<Query<unknown>, unknown>> {
32
+ const handlersByQueryType = new Map<QueryType, QueryHandler<Query<unknown>, unknown>>();
33
+ for (const handler of handlers) {
34
+ const queryType = Reflect.getMetadata(queryHandlerMetadataKey, handler.constructor) as QueryType | undefined;
35
+ if (!queryType) {
36
+ throw new Error(`Query handler ${handler.constructor.name} is missing @HandlesQuery metadata.`);
37
+ }
38
+ if (handlersByQueryType.has(queryType)) {
39
+ throw new Error(`Duplicate query handler registered for ${queryType.name}.`);
40
+ }
41
+ handlersByQueryType.set(queryType, handler);
42
+ }
43
+ return handlersByQueryType;
44
+ }
45
+ }
@@ -0,0 +1,12 @@
1
+ import { injectable } from "@codemation/core";
2
+
3
+ @injectable()
4
+ export class CodemationIdFactory {
5
+ makeRunId(): string {
6
+ return `run_${Date.now()}_${Math.random().toString(16).slice(2)}`;
7
+ }
8
+
9
+ makeActivationId(): string {
10
+ return `act_${Date.now()}_${Math.random().toString(16).slice(2)}`;
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ export { ConsoleLogger as BrowserLogger } from "./ConsoleLogger";
@@ -0,0 +1,14 @@
1
+ import type { Logger, LoggerFactory } from "../../application/logging/Logger";
2
+
3
+ import type { LogLevelPolicy } from "./LogLevelPolicy";
4
+ import { BrowserLogger } from "./BrowserLogger";
5
+
6
+ export class BrowserLoggerFactory implements LoggerFactory {
7
+ constructor(private readonly logLevelPolicy: LogLevelPolicy) {}
8
+
9
+ create(scope: string): Logger {
10
+ return new BrowserLogger(scope, this.logLevelPolicy);
11
+ }
12
+ }
13
+
14
+ export { BrowserLogger } from "./BrowserLogger";
@@ -0,0 +1,41 @@
1
+ import type { Logger } from "../../application/logging/Logger";
2
+ import type { LogLevelPolicy } from "./LogLevelPolicy";
3
+
4
+ export class ConsoleLogger implements Logger {
5
+ constructor(
6
+ private readonly scope: string,
7
+ private readonly logLevelPolicy: LogLevelPolicy,
8
+ ) {}
9
+
10
+ info(message: string, exception?: Error): void {
11
+ this.log("info", message, exception);
12
+ }
13
+
14
+ warn(message: string, exception?: Error): void {
15
+ this.log("warn", message, exception);
16
+ }
17
+
18
+ error(message: string, exception?: Error): void {
19
+ this.log("error", message, exception);
20
+ }
21
+
22
+ debug(message: string, exception?: Error): void {
23
+ this.log("debug", message, exception);
24
+ }
25
+
26
+ private formatTimestamp(): string {
27
+ return new Date().toISOString();
28
+ }
29
+
30
+ private log(level: "info" | "warn" | "error" | "debug", message: string, exception?: Error): void {
31
+ if (!this.logLevelPolicy.shouldEmit(level, this.scope)) {
32
+ return;
33
+ }
34
+ const line = `[${level}][${this.scope}][${this.formatTimestamp()}]: ${message}`;
35
+ if (exception) {
36
+ console[level](line, exception);
37
+ return;
38
+ }
39
+ console[level](line);
40
+ }
41
+ }
@@ -0,0 +1,38 @@
1
+ import type { LogFilter } from "../../application/logging/LogFilter";
2
+ import type { Logger } from "../../application/logging/Logger";
3
+
4
+ export class FilteringLogger implements Logger {
5
+ constructor(
6
+ private readonly inner: Logger,
7
+ private readonly scope: string,
8
+ private readonly filter: LogFilter,
9
+ ) {}
10
+
11
+ info(message: string, exception?: Error): void {
12
+ if (!this.filter({ scope: this.scope, level: "info", message })) {
13
+ return;
14
+ }
15
+ this.inner.info(message, exception);
16
+ }
17
+
18
+ warn(message: string, exception?: Error): void {
19
+ if (!this.filter({ scope: this.scope, level: "warn", message })) {
20
+ return;
21
+ }
22
+ this.inner.warn(message, exception);
23
+ }
24
+
25
+ error(message: string, exception?: Error): void {
26
+ if (!this.filter({ scope: this.scope, level: "error", message })) {
27
+ return;
28
+ }
29
+ this.inner.error(message, exception);
30
+ }
31
+
32
+ debug(message: string, exception?: Error): void {
33
+ if (!this.filter({ scope: this.scope, level: "debug", message })) {
34
+ return;
35
+ }
36
+ this.inner.debug(message, exception);
37
+ }
38
+ }
@@ -0,0 +1,148 @@
1
+ import type { CodemationLogConfig, CodemationLogRule } from "../../presentation/config/CodemationLogConfig";
2
+
3
+ export type LogLevel = "silent" | "debug" | "info" | "warn" | "error";
4
+
5
+ const levelRank: Record<Exclude<LogLevel, "silent">, number> = {
6
+ debug: 0,
7
+ info: 1,
8
+ warn: 2,
9
+ error: 3,
10
+ };
11
+
12
+ const globRegexMetaChars = new Set("\\^$+?()[]{}|.");
13
+
14
+ /**
15
+ * Minimum log level for @codemation/host loggers.
16
+ * - `CODEMATION_LOG_LEVEL` overrides when set to a known level (for namespaces not matched by `codemation.config` log rules).
17
+ * - Under Vitest, defaults to **warn** so routine `info`/`debug` noise stays off the terminal; `warn`/`error` still print.
18
+ * - Otherwise defaults to **info**.
19
+ *
20
+ * When {@link applyCodemationLogConfig} is set, the first matching rule wins per namespace; unmatched namespaces use env defaults.
21
+ *
22
+ * Resolve a shared instance via {@link LogLevelPolicyFactory} (DI or `logLevelPolicyFactory`).
23
+ */
24
+ export class LogLevelPolicy {
25
+ private cachedMin: LogLevel | undefined;
26
+
27
+ private codemationRules: ReadonlyArray<{ matchers: ReadonlyArray<RegExp>; minLevel: LogLevel }> | null = null;
28
+
29
+ resolveMin(): LogLevel {
30
+ const raw = process.env.CODEMATION_LOG_LEVEL?.toLowerCase();
31
+ if (raw === "silent" || raw === "debug" || raw === "info" || raw === "warn" || raw === "error") {
32
+ return raw;
33
+ }
34
+ if (process.env.VITEST === "true") {
35
+ return "warn";
36
+ }
37
+ return "info";
38
+ }
39
+
40
+ private minLevelCached(): LogLevel {
41
+ if (this.cachedMin === undefined) {
42
+ this.cachedMin = this.resolveMin();
43
+ }
44
+ return this.cachedMin;
45
+ }
46
+
47
+ resetForTests(): void {
48
+ this.cachedMin = undefined;
49
+ this.codemationRules = null;
50
+ }
51
+
52
+ /**
53
+ * Applies `codemation.config` log rules. Pass `undefined` to clear rules and use env-only behavior.
54
+ */
55
+ applyCodemationLogConfig(config: CodemationLogConfig | undefined): void {
56
+ this.codemationRules = null;
57
+ if (!config) {
58
+ return;
59
+ }
60
+ const rawRules = this.normalizeCodemationRules(config);
61
+ if (rawRules.length === 0) {
62
+ return;
63
+ }
64
+ const compiled: { matchers: ReadonlyArray<RegExp>; minLevel: LogLevel }[] = [];
65
+ for (const rule of rawRules) {
66
+ const minLevel = this.parseRuleLevel(rule.level);
67
+ const patterns = this.normalizeFilterPatterns(rule.filter);
68
+ if (patterns.length === 0) {
69
+ throw new Error("codemation.config log rule filter must include at least one pattern");
70
+ }
71
+ const matchers = patterns.map((pattern) => this.compileGlobPattern(pattern));
72
+ compiled.push({
73
+ matchers,
74
+ minLevel,
75
+ });
76
+ }
77
+ this.codemationRules = compiled;
78
+ }
79
+
80
+ shouldEmit(level: Exclude<LogLevel, "silent">, namespace: string): boolean {
81
+ if (this.codemationRules && this.codemationRules.length > 0) {
82
+ for (const rule of this.codemationRules) {
83
+ if (rule.matchers.some((regex) => regex.test(namespace))) {
84
+ return this.levelPassesAgainstMin(level, rule.minLevel);
85
+ }
86
+ }
87
+ }
88
+ return this.levelPassesAgainstMin(level, this.minLevelCached());
89
+ }
90
+
91
+ private normalizeCodemationRules(config: CodemationLogConfig): ReadonlyArray<CodemationLogRule> {
92
+ if ("rules" in config && Array.isArray(config.rules)) {
93
+ return [...config.rules];
94
+ }
95
+ return [config as CodemationLogRule];
96
+ }
97
+
98
+ private normalizeFilterPatterns(filter: string | ReadonlyArray<string>): ReadonlyArray<string> {
99
+ if (typeof filter === "string") {
100
+ return [filter];
101
+ }
102
+ return [...filter];
103
+ }
104
+
105
+ /**
106
+ * Glob: only `*` is special (matches any substring). A lone `*` matches all namespaces.
107
+ */
108
+ private compileGlobPattern(pattern: string): RegExp {
109
+ const trimmed = pattern.trim();
110
+ if (trimmed === "*") {
111
+ return /^.*$/;
112
+ }
113
+ let body = "";
114
+ for (const ch of trimmed) {
115
+ if (ch === "*") {
116
+ body += ".*";
117
+ continue;
118
+ }
119
+ if (globRegexMetaChars.has(ch)) {
120
+ body += "\\" + ch;
121
+ continue;
122
+ }
123
+ body += ch;
124
+ }
125
+ return new RegExp("^" + body + "$");
126
+ }
127
+
128
+ private parseRuleLevel(level: string): LogLevel {
129
+ const normalized = level.toLowerCase();
130
+ if (
131
+ normalized === "silent" ||
132
+ normalized === "debug" ||
133
+ normalized === "info" ||
134
+ normalized === "warn" ||
135
+ normalized === "error"
136
+ ) {
137
+ return normalized;
138
+ }
139
+ throw new Error(`Invalid codemation.config log level: ${level}`);
140
+ }
141
+
142
+ private levelPassesAgainstMin(level: Exclude<LogLevel, "silent">, min: LogLevel): boolean {
143
+ if (min === "silent") {
144
+ return false;
145
+ }
146
+ return levelRank[level] >= levelRank[min];
147
+ }
148
+ }
@@ -0,0 +1,16 @@
1
+ import { LogLevelPolicy } from "./LogLevelPolicy";
2
+
3
+ /**
4
+ * Process-wide {@link LogLevelPolicy} singleton for server and browser loggers.
5
+ * Plain class (no `@injectable` from `@codemation/core`): client components import this file; decorating would pull core into the browser bundle.
6
+ */
7
+ export class LogLevelPolicyFactory {
8
+ private readonly policy = new LogLevelPolicy();
9
+
10
+ create(): LogLevelPolicy {
11
+ return this.policy;
12
+ }
13
+ }
14
+
15
+ /** Shared factory for call sites outside the DI container (e.g. next-host bootstrap). */
16
+ export const logLevelPolicyFactory = new LogLevelPolicyFactory();
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Opt-in detailed timing / diagnostics lines (used with `ServerLoggerFactory#createPerformanceDiagnostics`).
3
+ *
4
+ * Set `CODEMATION_PERFORMANCE_LOGGING=true` to enable. Otherwise those loggers are silent regardless of level.
5
+ */
6
+ export class PerformanceLogPolicy {
7
+ shouldEmitDetailedTiming(): boolean {
8
+ return process.env.CODEMATION_PERFORMANCE_LOGGING === "true";
9
+ }
10
+ }
@@ -0,0 +1,14 @@
1
+ import { PerformanceLogPolicy } from "./PerformanceLogPolicy";
2
+
3
+ /**
4
+ * Process-wide {@link PerformanceLogPolicy} singleton (same pattern as {@link LogLevelPolicyFactory}).
5
+ */
6
+ export class PerformanceLogPolicyFactory {
7
+ private readonly policy = new PerformanceLogPolicy();
8
+
9
+ create(): PerformanceLogPolicy {
10
+ return this.policy;
11
+ }
12
+ }
13
+
14
+ export const performanceLogPolicyFactory = new PerformanceLogPolicyFactory();
@@ -0,0 +1 @@
1
+ export { ConsoleLogger as ServerLogger } from "./ConsoleLogger";
@@ -0,0 +1,28 @@
1
+ import { inject, injectable } from "@codemation/core";
2
+
3
+ import type { LogFilter } from "../../application/logging/LogFilter";
4
+ import type { Logger, LoggerFactory } from "../../application/logging/Logger";
5
+
6
+ import { FilteringLogger } from "./FilteringLogger";
7
+ import { LogLevelPolicyFactory } from "./LogLevelPolicyFactory";
8
+ import { performanceLogPolicyFactory } from "./PerformanceLogPolicyFactory";
9
+ import { ServerLogger } from "./ServerLogger";
10
+
11
+ @injectable()
12
+ export class ServerLoggerFactory implements LoggerFactory {
13
+ constructor(@inject(LogLevelPolicyFactory) private readonly logLevelPolicyFactory: LogLevelPolicyFactory) {}
14
+
15
+ create(scope: string): Logger {
16
+ return new ServerLogger(scope, this.logLevelPolicyFactory.create());
17
+ }
18
+
19
+ createFiltered(scope: string, filter: LogFilter): Logger {
20
+ return new FilteringLogger(this.create(scope), scope, filter);
21
+ }
22
+
23
+ createPerformanceDiagnostics(scope: string): Logger {
24
+ return this.createFiltered(scope, (_entry) => performanceLogPolicyFactory.create().shouldEmitDetailedTiming());
25
+ }
26
+ }
27
+
28
+ export { ServerLogger } from "./ServerLogger";
@@ -0,0 +1,9 @@
1
+ import { PrismaPg } from "@prisma/adapter-pg";
2
+ import { PrismaClient } from "./generated/prisma-client/client.js";
3
+
4
+ export class CodemationPostgresPrismaClientFactory {
5
+ static create(databaseUrl: string): PrismaClient {
6
+ const adapter = new PrismaPg({ connectionString: databaseUrl });
7
+ return new PrismaClient({ adapter });
8
+ }
9
+ }
@@ -0,0 +1,139 @@
1
+ import { injectable } from "@codemation/core";
2
+
3
+ import type {
4
+ CredentialInstanceRecord,
5
+ CredentialOAuth2MaterialMetadata,
6
+ CredentialOAuth2MaterialRecord,
7
+ CredentialOAuth2StateRecord,
8
+ CredentialSecretMaterialRecord,
9
+ CredentialStore,
10
+ CredentialTestRecord,
11
+ } from "../../domain/credentials/CredentialServices";
12
+
13
+ @injectable()
14
+ export class InMemoryCredentialStore implements CredentialStore {
15
+ private readonly instancesById = new Map<string, CredentialInstanceRecord>();
16
+ private readonly secretsByInstanceId = new Map<string, CredentialSecretMaterialRecord>();
17
+ private readonly oauth2MaterialsByInstanceId = new Map<string, CredentialOAuth2MaterialRecord>();
18
+ private readonly oauth2StatesByState = new Map<string, CredentialOAuth2StateRecord>();
19
+ private readonly bindingsByKey = new Map<string, import("@codemation/core").CredentialBinding>();
20
+ private readonly testRecordsByInstanceId = new Map<string, CredentialTestRecord>();
21
+
22
+ async listInstances(): Promise<ReadonlyArray<CredentialInstanceRecord>> {
23
+ return [...this.instancesById.values()].sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
24
+ }
25
+
26
+ async getInstance(instanceId: string): Promise<CredentialInstanceRecord | undefined> {
27
+ return this.instancesById.get(instanceId);
28
+ }
29
+
30
+ async saveInstance(
31
+ args: Readonly<{ instance: CredentialInstanceRecord; secretMaterial?: CredentialSecretMaterialRecord }>,
32
+ ): Promise<void> {
33
+ this.instancesById.set(args.instance.instanceId, args.instance);
34
+ if (args.secretMaterial) {
35
+ this.secretsByInstanceId.set(args.instance.instanceId, args.secretMaterial);
36
+ }
37
+ }
38
+
39
+ async deleteInstance(instanceId: string): Promise<void> {
40
+ this.instancesById.delete(instanceId);
41
+ this.secretsByInstanceId.delete(instanceId);
42
+ this.oauth2MaterialsByInstanceId.delete(instanceId);
43
+ this.testRecordsByInstanceId.delete(instanceId);
44
+ for (const [state, record] of this.oauth2StatesByState.entries()) {
45
+ if (record.instanceId === instanceId) {
46
+ this.oauth2StatesByState.delete(state);
47
+ }
48
+ }
49
+ for (const [key, binding] of this.bindingsByKey.entries()) {
50
+ if (binding.instanceId === instanceId) {
51
+ this.bindingsByKey.delete(key);
52
+ }
53
+ }
54
+ }
55
+
56
+ async getSecretMaterial(instanceId: string): Promise<CredentialSecretMaterialRecord | undefined> {
57
+ return this.secretsByInstanceId.get(instanceId);
58
+ }
59
+
60
+ async createOAuth2State(record: CredentialOAuth2StateRecord): Promise<void> {
61
+ this.oauth2StatesByState.set(record.state, record);
62
+ }
63
+
64
+ async consumeOAuth2State(state: string): Promise<CredentialOAuth2StateRecord | undefined> {
65
+ const record = this.oauth2StatesByState.get(state);
66
+ if (!record) {
67
+ return undefined;
68
+ }
69
+ this.oauth2StatesByState.delete(state);
70
+ return record;
71
+ }
72
+
73
+ async getOAuth2Material(instanceId: string): Promise<CredentialOAuth2MaterialRecord | undefined> {
74
+ return this.oauth2MaterialsByInstanceId.get(instanceId);
75
+ }
76
+
77
+ async saveOAuth2Material(
78
+ args: Readonly<{
79
+ instanceId: string;
80
+ encryptedJson: string;
81
+ encryptionKeyId: string;
82
+ schemaVersion: number;
83
+ metadata: CredentialOAuth2MaterialMetadata;
84
+ }>,
85
+ ): Promise<void> {
86
+ this.oauth2MaterialsByInstanceId.set(args.instanceId, {
87
+ instanceId: args.instanceId,
88
+ encryptedJson: args.encryptedJson,
89
+ encryptionKeyId: args.encryptionKeyId,
90
+ schemaVersion: args.schemaVersion,
91
+ providerId: args.metadata.providerId,
92
+ connectedEmail: args.metadata.connectedEmail,
93
+ connectedAt: args.metadata.connectedAt,
94
+ scopes: args.metadata.scopes,
95
+ updatedAt: args.metadata.updatedAt,
96
+ });
97
+ }
98
+
99
+ async deleteOAuth2Material(instanceId: string): Promise<void> {
100
+ this.oauth2MaterialsByInstanceId.delete(instanceId);
101
+ }
102
+
103
+ async upsertBinding(binding: import("@codemation/core").CredentialBinding): Promise<void> {
104
+ this.bindingsByKey.set(this.toBindingKey(binding.key), binding);
105
+ }
106
+
107
+ async getBinding(
108
+ key: import("@codemation/core").CredentialBindingKey,
109
+ ): Promise<import("@codemation/core").CredentialBinding | undefined> {
110
+ return this.bindingsByKey.get(this.toBindingKey(key));
111
+ }
112
+
113
+ async listBindingsByWorkflowId(
114
+ workflowId: string,
115
+ ): Promise<ReadonlyArray<import("@codemation/core").CredentialBinding>> {
116
+ return [...this.bindingsByKey.values()].filter((binding) => binding.key.workflowId === workflowId);
117
+ }
118
+
119
+ async saveTestResult(record: CredentialTestRecord): Promise<void> {
120
+ this.testRecordsByInstanceId.set(record.instanceId, record);
121
+ }
122
+
123
+ async getLatestTestResult(instanceId: string): Promise<CredentialTestRecord | undefined> {
124
+ return this.testRecordsByInstanceId.get(instanceId);
125
+ }
126
+
127
+ async getLatestTestResults(instanceIds: ReadonlyArray<string>): Promise<ReadonlyMap<string, CredentialTestRecord>> {
128
+ const entries = instanceIds
129
+ .map((instanceId) => [instanceId, this.testRecordsByInstanceId.get(instanceId)] as const)
130
+ .filter((entry): entry is readonly [string, CredentialTestRecord] => entry[1] !== undefined);
131
+ return new Map(entries);
132
+ }
133
+
134
+ private toBindingKey(key: import("@codemation/core").CredentialBindingKey): string {
135
+ return `${key.workflowId}:${key.nodeId}:${key.slotKey}`;
136
+ }
137
+ }
138
+
139
+ export { PrismaCredentialStore } from "./PrismaCredentialStore";