ts-workflow-engine-lite 2.1.0

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 (525) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +352 -0
  3. package/dist/src/api/ConsoleWebSocketManager.d.ts +57 -0
  4. package/dist/src/api/ConsoleWebSocketManager.js +206 -0
  5. package/dist/src/api/ConsoleWebSocketManager.js.map +1 -0
  6. package/dist/src/api/ErrorHandler.d.ts +52 -0
  7. package/dist/src/api/ErrorHandler.js +115 -0
  8. package/dist/src/api/ErrorHandler.js.map +1 -0
  9. package/dist/src/api/EventHistory.d.ts +73 -0
  10. package/dist/src/api/EventHistory.js +309 -0
  11. package/dist/src/api/EventHistory.js.map +1 -0
  12. package/dist/src/api/WebhookManager.d.ts +67 -0
  13. package/dist/src/api/WebhookManager.js +568 -0
  14. package/dist/src/api/WebhookManager.js.map +1 -0
  15. package/dist/src/api/docsPage.d.ts +1 -0
  16. package/dist/src/api/docsPage.js +321 -0
  17. package/dist/src/api/docsPage.js.map +1 -0
  18. package/dist/src/api/index.d.ts +8 -0
  19. package/dist/src/api/index.js +8 -0
  20. package/dist/src/api/index.js.map +1 -0
  21. package/dist/src/api/middleware/auth.d.ts +19 -0
  22. package/dist/src/api/middleware/auth.js +122 -0
  23. package/dist/src/api/middleware/auth.js.map +1 -0
  24. package/dist/src/api/middleware/index.d.ts +3 -0
  25. package/dist/src/api/middleware/index.js +3 -0
  26. package/dist/src/api/middleware/index.js.map +1 -0
  27. package/dist/src/api/middleware/rateLimit.d.ts +6 -0
  28. package/dist/src/api/middleware/rateLimit.js +69 -0
  29. package/dist/src/api/middleware/rateLimit.js.map +1 -0
  30. package/dist/src/api/middleware/rateLimitStore.d.ts +14 -0
  31. package/dist/src/api/middleware/rateLimitStore.js +44 -0
  32. package/dist/src/api/middleware/rateLimitStore.js.map +1 -0
  33. package/dist/src/api/middleware/rbac.d.ts +12 -0
  34. package/dist/src/api/middleware/rbac.js +120 -0
  35. package/dist/src/api/middleware/rbac.js.map +1 -0
  36. package/dist/src/api/openapi.d.ts +1917 -0
  37. package/dist/src/api/openapi.js +1758 -0
  38. package/dist/src/api/openapi.js.map +1 -0
  39. package/dist/src/api/playgroundPage.d.ts +1 -0
  40. package/dist/src/api/playgroundPage.js +765 -0
  41. package/dist/src/api/playgroundPage.js.map +1 -0
  42. package/dist/src/api/response.d.ts +22 -0
  43. package/dist/src/api/response.js +119 -0
  44. package/dist/src/api/response.js.map +1 -0
  45. package/dist/src/api/router.d.ts +17 -0
  46. package/dist/src/api/router.js +94 -0
  47. package/dist/src/api/router.js.map +1 -0
  48. package/dist/src/api/routes/analytics.d.ts +10 -0
  49. package/dist/src/api/routes/analytics.js +144 -0
  50. package/dist/src/api/routes/analytics.js.map +1 -0
  51. package/dist/src/api/routes/dlq.d.ts +3 -0
  52. package/dist/src/api/routes/dlq.js +248 -0
  53. package/dist/src/api/routes/dlq.js.map +1 -0
  54. package/dist/src/api/routes/eventHistory.d.ts +3 -0
  55. package/dist/src/api/routes/eventHistory.js +48 -0
  56. package/dist/src/api/routes/eventHistory.js.map +1 -0
  57. package/dist/src/api/routes/events.d.ts +3 -0
  58. package/dist/src/api/routes/events.js +205 -0
  59. package/dist/src/api/routes/events.js.map +1 -0
  60. package/dist/src/api/routes/functions.d.ts +3 -0
  61. package/dist/src/api/routes/functions.js +85 -0
  62. package/dist/src/api/routes/functions.js.map +1 -0
  63. package/dist/src/api/routes/instances.d.ts +3 -0
  64. package/dist/src/api/routes/instances.js +790 -0
  65. package/dist/src/api/routes/instances.js.map +1 -0
  66. package/dist/src/api/routes/templates.d.ts +3 -0
  67. package/dist/src/api/routes/templates.js +195 -0
  68. package/dist/src/api/routes/templates.js.map +1 -0
  69. package/dist/src/api/routes/webhooks.d.ts +3 -0
  70. package/dist/src/api/routes/webhooks.js +263 -0
  71. package/dist/src/api/routes/webhooks.js.map +1 -0
  72. package/dist/src/api/routes/workflows/analysis.d.ts +2 -0
  73. package/dist/src/api/routes/workflows/analysis.js +112 -0
  74. package/dist/src/api/routes/workflows/analysis.js.map +1 -0
  75. package/dist/src/api/routes/workflows/crud.d.ts +2 -0
  76. package/dist/src/api/routes/workflows/crud.js +140 -0
  77. package/dist/src/api/routes/workflows/crud.js.map +1 -0
  78. package/dist/src/api/routes/workflows/execution.d.ts +2 -0
  79. package/dist/src/api/routes/workflows/execution.js +204 -0
  80. package/dist/src/api/routes/workflows/execution.js.map +1 -0
  81. package/dist/src/api/routes/workflows/graph.d.ts +2 -0
  82. package/dist/src/api/routes/workflows/graph.js +51 -0
  83. package/dist/src/api/routes/workflows/graph.js.map +1 -0
  84. package/dist/src/api/routes/workflows/import.d.ts +2 -0
  85. package/dist/src/api/routes/workflows/import.js +238 -0
  86. package/dist/src/api/routes/workflows/import.js.map +1 -0
  87. package/dist/src/api/routes/workflows/index.d.ts +3 -0
  88. package/dist/src/api/routes/workflows/index.js +18 -0
  89. package/dist/src/api/routes/workflows/index.js.map +1 -0
  90. package/dist/src/api/routes/workflows/shared.d.ts +64 -0
  91. package/dist/src/api/routes/workflows/shared.js +304 -0
  92. package/dist/src/api/routes/workflows/shared.js.map +1 -0
  93. package/dist/src/api/routes/workflows/variables.d.ts +2 -0
  94. package/dist/src/api/routes/workflows/variables.js +34 -0
  95. package/dist/src/api/routes/workflows/variables.js.map +1 -0
  96. package/dist/src/api/routes/workflows/versioning.d.ts +2 -0
  97. package/dist/src/api/routes/workflows/versioning.js +235 -0
  98. package/dist/src/api/routes/workflows/versioning.js.map +1 -0
  99. package/dist/src/api/server.d.ts +13 -0
  100. package/dist/src/api/server.js +311 -0
  101. package/dist/src/api/server.js.map +1 -0
  102. package/dist/src/api/services/InstanceApplicationService.d.ts +74 -0
  103. package/dist/src/api/services/InstanceApplicationService.js +215 -0
  104. package/dist/src/api/services/InstanceApplicationService.js.map +1 -0
  105. package/dist/src/api/services/WorkflowApplicationService.d.ts +92 -0
  106. package/dist/src/api/services/WorkflowApplicationService.js +282 -0
  107. package/dist/src/api/services/WorkflowApplicationService.js.map +1 -0
  108. package/dist/src/api/services/index.d.ts +4 -0
  109. package/dist/src/api/services/index.js +3 -0
  110. package/dist/src/api/services/index.js.map +1 -0
  111. package/dist/src/api/types.d.ts +118 -0
  112. package/dist/src/api/types.js +2 -0
  113. package/dist/src/api/types.js.map +1 -0
  114. package/dist/src/api/utils/IdempotencyStore.d.ts +36 -0
  115. package/dist/src/api/utils/IdempotencyStore.js +121 -0
  116. package/dist/src/api/utils/IdempotencyStore.js.map +1 -0
  117. package/dist/src/api/utils/authConfig.d.ts +2 -0
  118. package/dist/src/api/utils/authConfig.js +25 -0
  119. package/dist/src/api/utils/authConfig.js.map +1 -0
  120. package/dist/src/api/utils/requestContext.d.ts +14 -0
  121. package/dist/src/api/utils/requestContext.js +31 -0
  122. package/dist/src/api/utils/requestContext.js.map +1 -0
  123. package/dist/src/api/utils/routeHelper.d.ts +25 -0
  124. package/dist/src/api/utils/routeHelper.js +30 -0
  125. package/dist/src/api/utils/routeHelper.js.map +1 -0
  126. package/dist/src/api/welcomePage.d.ts +1 -0
  127. package/dist/src/api/welcomePage.js +259 -0
  128. package/dist/src/api/welcomePage.js.map +1 -0
  129. package/dist/src/bootstrap.d.ts +20 -0
  130. package/dist/src/bootstrap.js +128 -0
  131. package/dist/src/bootstrap.js.map +1 -0
  132. package/dist/src/cli.d.ts +2 -0
  133. package/dist/src/cli.js +32 -0
  134. package/dist/src/cli.js.map +1 -0
  135. package/dist/src/config/AppConfig.d.ts +102 -0
  136. package/dist/src/config/AppConfig.js +452 -0
  137. package/dist/src/config/AppConfig.js.map +1 -0
  138. package/dist/src/config/redis.config.d.ts +6 -0
  139. package/dist/src/config/redis.config.js +9 -0
  140. package/dist/src/config/redis.config.js.map +1 -0
  141. package/dist/src/container.d.ts +29 -0
  142. package/dist/src/container.js +62 -0
  143. package/dist/src/container.js.map +1 -0
  144. package/dist/src/debug/BreakpointManager.d.ts +17 -0
  145. package/dist/src/debug/BreakpointManager.js +59 -0
  146. package/dist/src/debug/BreakpointManager.js.map +1 -0
  147. package/dist/src/debug/WorkflowDebugger.d.ts +34 -0
  148. package/dist/src/debug/WorkflowDebugger.js +117 -0
  149. package/dist/src/debug/WorkflowDebugger.js.map +1 -0
  150. package/dist/src/debug/index.d.ts +2 -0
  151. package/dist/src/debug/index.js +3 -0
  152. package/dist/src/debug/index.js.map +1 -0
  153. package/dist/src/demo/demoWorkflow.d.ts +3 -0
  154. package/dist/src/demo/demoWorkflow.js +82 -0
  155. package/dist/src/demo/demoWorkflow.js.map +1 -0
  156. package/dist/src/demo/exampleWorkflow.d.ts +36 -0
  157. package/dist/src/demo/exampleWorkflow.js +184 -0
  158. package/dist/src/demo/exampleWorkflow.js.map +1 -0
  159. package/dist/src/demo/index.d.ts +2 -0
  160. package/dist/src/demo/index.js +3 -0
  161. package/dist/src/demo/index.js.map +1 -0
  162. package/dist/src/dlq/DeadLetterQueue.d.ts +62 -0
  163. package/dist/src/dlq/DeadLetterQueue.js +342 -0
  164. package/dist/src/dlq/DeadLetterQueue.js.map +1 -0
  165. package/dist/src/dlq/index.d.ts +2 -0
  166. package/dist/src/dlq/index.js +2 -0
  167. package/dist/src/dlq/index.js.map +1 -0
  168. package/dist/src/dsl/DSLParser.d.ts +7 -0
  169. package/dist/src/dsl/DSLParser.js +252 -0
  170. package/dist/src/dsl/DSLParser.js.map +1 -0
  171. package/dist/src/dsl/WorkflowDSL.d.ts +40 -0
  172. package/dist/src/dsl/WorkflowDSL.js +2 -0
  173. package/dist/src/dsl/WorkflowDSL.js.map +1 -0
  174. package/dist/src/engine/CanaryReleaseManager.d.ts +39 -0
  175. package/dist/src/engine/CanaryReleaseManager.js +192 -0
  176. package/dist/src/engine/CanaryReleaseManager.js.map +1 -0
  177. package/dist/src/engine/ConcurrencyControl.d.ts +38 -0
  178. package/dist/src/engine/ConcurrencyControl.js +181 -0
  179. package/dist/src/engine/ConcurrencyControl.js.map +1 -0
  180. package/dist/src/engine/ContinueAsNewManager.d.ts +18 -0
  181. package/dist/src/engine/ContinueAsNewManager.js +29 -0
  182. package/dist/src/engine/ContinueAsNewManager.js.map +1 -0
  183. package/dist/src/engine/DataValidator.d.ts +15 -0
  184. package/dist/src/engine/DataValidator.js +121 -0
  185. package/dist/src/engine/DataValidator.js.map +1 -0
  186. package/dist/src/engine/DryRunExecutor.d.ts +48 -0
  187. package/dist/src/engine/DryRunExecutor.js +256 -0
  188. package/dist/src/engine/DryRunExecutor.js.map +1 -0
  189. package/dist/src/engine/ExecutionOrchestrator.d.ts +19 -0
  190. package/dist/src/engine/ExecutionOrchestrator.js +579 -0
  191. package/dist/src/engine/ExecutionOrchestrator.js.map +1 -0
  192. package/dist/src/engine/ExpressionEvaluator.d.ts +44 -0
  193. package/dist/src/engine/ExpressionEvaluator.js +1046 -0
  194. package/dist/src/engine/ExpressionEvaluator.js.map +1 -0
  195. package/dist/src/engine/HeartbeatManager.d.ts +42 -0
  196. package/dist/src/engine/HeartbeatManager.js +209 -0
  197. package/dist/src/engine/HeartbeatManager.js.map +1 -0
  198. package/dist/src/engine/InstanceManager.d.ts +21 -0
  199. package/dist/src/engine/InstanceManager.js +165 -0
  200. package/dist/src/engine/InstanceManager.js.map +1 -0
  201. package/dist/src/engine/InstanceSearch.d.ts +30 -0
  202. package/dist/src/engine/InstanceSearch.js +119 -0
  203. package/dist/src/engine/InstanceSearch.js.map +1 -0
  204. package/dist/src/engine/LifecycleManager.d.ts +18 -0
  205. package/dist/src/engine/LifecycleManager.js +82 -0
  206. package/dist/src/engine/LifecycleManager.js.map +1 -0
  207. package/dist/src/engine/ParallelExecutor.d.ts +26 -0
  208. package/dist/src/engine/ParallelExecutor.js +138 -0
  209. package/dist/src/engine/ParallelExecutor.js.map +1 -0
  210. package/dist/src/engine/SandboxEvaluator.d.ts +18 -0
  211. package/dist/src/engine/SandboxEvaluator.js +200 -0
  212. package/dist/src/engine/SandboxEvaluator.js.map +1 -0
  213. package/dist/src/engine/SchemaValidator.d.ts +30 -0
  214. package/dist/src/engine/SchemaValidator.js +630 -0
  215. package/dist/src/engine/SchemaValidator.js.map +1 -0
  216. package/dist/src/engine/SearchAttributeManager.d.ts +48 -0
  217. package/dist/src/engine/SearchAttributeManager.js +119 -0
  218. package/dist/src/engine/SearchAttributeManager.js.map +1 -0
  219. package/dist/src/engine/StateMachine.d.ts +13 -0
  220. package/dist/src/engine/StateMachine.js +66 -0
  221. package/dist/src/engine/StateMachine.js.map +1 -0
  222. package/dist/src/engine/StickyExecutionManager.d.ts +34 -0
  223. package/dist/src/engine/StickyExecutionManager.js +163 -0
  224. package/dist/src/engine/StickyExecutionManager.js.map +1 -0
  225. package/dist/src/engine/SubworkflowExecutor.d.ts +17 -0
  226. package/dist/src/engine/SubworkflowExecutor.js +157 -0
  227. package/dist/src/engine/SubworkflowExecutor.js.map +1 -0
  228. package/dist/src/engine/TaskExecutor.d.ts +12 -0
  229. package/dist/src/engine/TaskExecutor.js +124 -0
  230. package/dist/src/engine/TaskExecutor.js.map +1 -0
  231. package/dist/src/engine/TaskQueueManager.d.ts +42 -0
  232. package/dist/src/engine/TaskQueueManager.js +175 -0
  233. package/dist/src/engine/TaskQueueManager.js.map +1 -0
  234. package/dist/src/engine/WorkflowEngine.d.ts +117 -0
  235. package/dist/src/engine/WorkflowEngine.js +443 -0
  236. package/dist/src/engine/WorkflowEngine.js.map +1 -0
  237. package/dist/src/engine/WorkflowInstanceControl.d.ts +21 -0
  238. package/dist/src/engine/WorkflowInstanceControl.js +306 -0
  239. package/dist/src/engine/WorkflowInstanceControl.js.map +1 -0
  240. package/dist/src/engine/WorkflowPersistenceCoordinator.d.ts +12 -0
  241. package/dist/src/engine/WorkflowPersistenceCoordinator.js +93 -0
  242. package/dist/src/engine/WorkflowPersistenceCoordinator.js.map +1 -0
  243. package/dist/src/engine/WorkflowRegistry.d.ts +38 -0
  244. package/dist/src/engine/WorkflowRegistry.js +130 -0
  245. package/dist/src/engine/WorkflowRegistry.js.map +1 -0
  246. package/dist/src/engine/WorkflowVersionManager.d.ts +24 -0
  247. package/dist/src/engine/WorkflowVersionManager.js +121 -0
  248. package/dist/src/engine/WorkflowVersionManager.js.map +1 -0
  249. package/dist/src/engine/createEngine.d.ts +8 -0
  250. package/dist/src/engine/createEngine.js +21 -0
  251. package/dist/src/engine/createEngine.js.map +1 -0
  252. package/dist/src/engine/errors.d.ts +18 -0
  253. package/dist/src/engine/errors.js +37 -0
  254. package/dist/src/engine/errors.js.map +1 -0
  255. package/dist/src/engine/executors/ApprovalNodeExecutor.d.ts +12 -0
  256. package/dist/src/engine/executors/ApprovalNodeExecutor.js +68 -0
  257. package/dist/src/engine/executors/ApprovalNodeExecutor.js.map +1 -0
  258. package/dist/src/engine/executors/ConditionNodeExecutor.d.ts +16 -0
  259. package/dist/src/engine/executors/ConditionNodeExecutor.js +63 -0
  260. package/dist/src/engine/executors/ConditionNodeExecutor.js.map +1 -0
  261. package/dist/src/engine/executors/HttpNodeExecutor.d.ts +27 -0
  262. package/dist/src/engine/executors/HttpNodeExecutor.js +179 -0
  263. package/dist/src/engine/executors/HttpNodeExecutor.js.map +1 -0
  264. package/dist/src/engine/executors/JoinNodeExecutor.d.ts +13 -0
  265. package/dist/src/engine/executors/JoinNodeExecutor.js +37 -0
  266. package/dist/src/engine/executors/JoinNodeExecutor.js.map +1 -0
  267. package/dist/src/engine/executors/LoopNodeExecutor.d.ts +20 -0
  268. package/dist/src/engine/executors/LoopNodeExecutor.js +165 -0
  269. package/dist/src/engine/executors/LoopNodeExecutor.js.map +1 -0
  270. package/dist/src/engine/executors/NotificationNodeExecutor.d.ts +8 -0
  271. package/dist/src/engine/executors/NotificationNodeExecutor.js +33 -0
  272. package/dist/src/engine/executors/NotificationNodeExecutor.js.map +1 -0
  273. package/dist/src/engine/executors/QueueNodeExecutor.d.ts +23 -0
  274. package/dist/src/engine/executors/QueueNodeExecutor.js +87 -0
  275. package/dist/src/engine/executors/QueueNodeExecutor.js.map +1 -0
  276. package/dist/src/engine/executors/RouterNodeExecutor.d.ts +20 -0
  277. package/dist/src/engine/executors/RouterNodeExecutor.js +82 -0
  278. package/dist/src/engine/executors/RouterNodeExecutor.js.map +1 -0
  279. package/dist/src/engine/executors/SqlNodeExecutor.d.ts +27 -0
  280. package/dist/src/engine/executors/SqlNodeExecutor.js +74 -0
  281. package/dist/src/engine/executors/SqlNodeExecutor.js.map +1 -0
  282. package/dist/src/engine/executors/TransformNodeExecutor.d.ts +9 -0
  283. package/dist/src/engine/executors/TransformNodeExecutor.js +44 -0
  284. package/dist/src/engine/executors/TransformNodeExecutor.js.map +1 -0
  285. package/dist/src/engine/functions/collectionFunctions.d.ts +2 -0
  286. package/dist/src/engine/functions/collectionFunctions.js +129 -0
  287. package/dist/src/engine/functions/collectionFunctions.js.map +1 -0
  288. package/dist/src/engine/functions/customFunctions.d.ts +11 -0
  289. package/dist/src/engine/functions/customFunctions.js +42 -0
  290. package/dist/src/engine/functions/customFunctions.js.map +1 -0
  291. package/dist/src/engine/functions/dateFunctions.d.ts +2 -0
  292. package/dist/src/engine/functions/dateFunctions.js +71 -0
  293. package/dist/src/engine/functions/dateFunctions.js.map +1 -0
  294. package/dist/src/engine/functions/index.d.ts +14 -0
  295. package/dist/src/engine/functions/index.js +35 -0
  296. package/dist/src/engine/functions/index.js.map +1 -0
  297. package/dist/src/engine/functions/stringFunctions.d.ts +2 -0
  298. package/dist/src/engine/functions/stringFunctions.js +66 -0
  299. package/dist/src/engine/functions/stringFunctions.js.map +1 -0
  300. package/dist/src/engine/functions/typeFunctions.d.ts +2 -0
  301. package/dist/src/engine/functions/typeFunctions.js +70 -0
  302. package/dist/src/engine/functions/typeFunctions.js.map +1 -0
  303. package/dist/src/engine/functions/types.d.ts +6 -0
  304. package/dist/src/engine/functions/types.js +2 -0
  305. package/dist/src/engine/functions/types.js.map +1 -0
  306. package/dist/src/engine/index.d.ts +21 -0
  307. package/dist/src/engine/index.js +18 -0
  308. package/dist/src/engine/index.js.map +1 -0
  309. package/dist/src/engine/nodeDispatch/controlNodes.d.ts +2 -0
  310. package/dist/src/engine/nodeDispatch/controlNodes.js +208 -0
  311. package/dist/src/engine/nodeDispatch/controlNodes.js.map +1 -0
  312. package/dist/src/engine/nodeDispatch/helpers.d.ts +27 -0
  313. package/dist/src/engine/nodeDispatch/helpers.js +185 -0
  314. package/dist/src/engine/nodeDispatch/helpers.js.map +1 -0
  315. package/dist/src/engine/nodeDispatch/ioNodes.d.ts +2 -0
  316. package/dist/src/engine/nodeDispatch/ioNodes.js +89 -0
  317. package/dist/src/engine/nodeDispatch/ioNodes.js.map +1 -0
  318. package/dist/src/engine/nodeDispatch/types.d.ts +13 -0
  319. package/dist/src/engine/nodeDispatch/types.js +2 -0
  320. package/dist/src/engine/nodeDispatch/types.js.map +1 -0
  321. package/dist/src/engine/nodeDispatch/workflowNodes.d.ts +2 -0
  322. package/dist/src/engine/nodeDispatch/workflowNodes.js +33 -0
  323. package/dist/src/engine/nodeDispatch/workflowNodes.js.map +1 -0
  324. package/dist/src/engine/worker/ActionSandboxMessage.d.ts +29 -0
  325. package/dist/src/engine/worker/ActionSandboxMessage.js +7 -0
  326. package/dist/src/engine/worker/ActionSandboxMessage.js.map +1 -0
  327. package/dist/src/engine/worker/ActionSandboxPool.d.ts +34 -0
  328. package/dist/src/engine/worker/ActionSandboxPool.js +204 -0
  329. package/dist/src/engine/worker/ActionSandboxPool.js.map +1 -0
  330. package/dist/src/engine/worker/ActionSandboxWorker.d.ts +1 -0
  331. package/dist/src/engine/worker/ActionSandboxWorker.js +25 -0
  332. package/dist/src/engine/worker/ActionSandboxWorker.js.map +1 -0
  333. package/dist/src/engine/worker/WorkerMessage.d.ts +35 -0
  334. package/dist/src/engine/worker/WorkerMessage.js +7 -0
  335. package/dist/src/engine/worker/WorkerMessage.js.map +1 -0
  336. package/dist/src/engine/worker/WorkerPool.d.ts +42 -0
  337. package/dist/src/engine/worker/WorkerPool.js +273 -0
  338. package/dist/src/engine/worker/WorkerPool.js.map +1 -0
  339. package/dist/src/engine/worker/WorkerProcess.d.ts +1 -0
  340. package/dist/src/engine/worker/WorkerProcess.js +76 -0
  341. package/dist/src/engine/worker/WorkerProcess.js.map +1 -0
  342. package/dist/src/event/EventBus.d.ts +11 -0
  343. package/dist/src/event/EventBus.js +44 -0
  344. package/dist/src/event/EventBus.js.map +1 -0
  345. package/dist/src/event/EventCoordinator.d.ts +26 -0
  346. package/dist/src/event/EventCoordinator.js +205 -0
  347. package/dist/src/event/EventCoordinator.js.map +1 -0
  348. package/dist/src/event/EventDeduplicator.d.ts +31 -0
  349. package/dist/src/event/EventDeduplicator.js +100 -0
  350. package/dist/src/event/EventDeduplicator.js.map +1 -0
  351. package/dist/src/event/HookManager.d.ts +31 -0
  352. package/dist/src/event/HookManager.js +88 -0
  353. package/dist/src/event/HookManager.js.map +1 -0
  354. package/dist/src/event/MessageBus.d.ts +39 -0
  355. package/dist/src/event/MessageBus.js +131 -0
  356. package/dist/src/event/MessageBus.js.map +1 -0
  357. package/dist/src/event/index.d.ts +3 -0
  358. package/dist/src/event/index.js +4 -0
  359. package/dist/src/event/index.js.map +1 -0
  360. package/dist/src/index.d.ts +40 -0
  361. package/dist/src/index.js +33 -0
  362. package/dist/src/index.js.map +1 -0
  363. package/dist/src/lifecycle.d.ts +17 -0
  364. package/dist/src/lifecycle.js +84 -0
  365. package/dist/src/lifecycle.js.map +1 -0
  366. package/dist/src/metrics/AnalyticsCollector.d.ts +57 -0
  367. package/dist/src/metrics/AnalyticsCollector.js +140 -0
  368. package/dist/src/metrics/AnalyticsCollector.js.map +1 -0
  369. package/dist/src/metrics/AnomalyDetector.d.ts +21 -0
  370. package/dist/src/metrics/AnomalyDetector.js +120 -0
  371. package/dist/src/metrics/AnomalyDetector.js.map +1 -0
  372. package/dist/src/metrics/MetricsAggregator.d.ts +43 -0
  373. package/dist/src/metrics/MetricsAggregator.js +243 -0
  374. package/dist/src/metrics/MetricsAggregator.js.map +1 -0
  375. package/dist/src/metrics/SlaMonitor.d.ts +48 -0
  376. package/dist/src/metrics/SlaMonitor.js +130 -0
  377. package/dist/src/metrics/SlaMonitor.js.map +1 -0
  378. package/dist/src/metrics/index.d.ts +75 -0
  379. package/dist/src/metrics/index.js +293 -0
  380. package/dist/src/metrics/index.js.map +1 -0
  381. package/dist/src/model/Instance.d.ts +38 -0
  382. package/dist/src/model/Instance.js +12 -0
  383. package/dist/src/model/Instance.js.map +1 -0
  384. package/dist/src/model/RetryPolicy.d.ts +11 -0
  385. package/dist/src/model/RetryPolicy.js +30 -0
  386. package/dist/src/model/RetryPolicy.js.map +1 -0
  387. package/dist/src/model/Schedule.d.ts +34 -0
  388. package/dist/src/model/Schedule.js +50 -0
  389. package/dist/src/model/Schedule.js.map +1 -0
  390. package/dist/src/model/Workflow.d.ts +73 -0
  391. package/dist/src/model/Workflow.js +2 -0
  392. package/dist/src/model/Workflow.js.map +1 -0
  393. package/dist/src/model/WorkflowGraph.d.ts +32 -0
  394. package/dist/src/model/WorkflowGraph.js +267 -0
  395. package/dist/src/model/WorkflowGraph.js.map +1 -0
  396. package/dist/src/model/WorkflowSchema.d.ts +154 -0
  397. package/dist/src/model/WorkflowSchema.js +233 -0
  398. package/dist/src/model/WorkflowSchema.js.map +1 -0
  399. package/dist/src/model/WorkflowVariables.d.ts +15 -0
  400. package/dist/src/model/WorkflowVariables.js +77 -0
  401. package/dist/src/model/WorkflowVariables.js.map +1 -0
  402. package/dist/src/notification/NotificationChannel.d.ts +19 -0
  403. package/dist/src/notification/NotificationChannel.js +2 -0
  404. package/dist/src/notification/NotificationChannel.js.map +1 -0
  405. package/dist/src/notification/NotificationManager.d.ts +20 -0
  406. package/dist/src/notification/NotificationManager.js +59 -0
  407. package/dist/src/notification/NotificationManager.js.map +1 -0
  408. package/dist/src/notification/channels/DingtalkChannel.d.ts +7 -0
  409. package/dist/src/notification/channels/DingtalkChannel.js +18 -0
  410. package/dist/src/notification/channels/DingtalkChannel.js.map +1 -0
  411. package/dist/src/notification/channels/EmailChannel.d.ts +21 -0
  412. package/dist/src/notification/channels/EmailChannel.js +32 -0
  413. package/dist/src/notification/channels/EmailChannel.js.map +1 -0
  414. package/dist/src/notification/channels/FeishuChannel.d.ts +7 -0
  415. package/dist/src/notification/channels/FeishuChannel.js +18 -0
  416. package/dist/src/notification/channels/FeishuChannel.js.map +1 -0
  417. package/dist/src/notification/channels/SlackChannel.d.ts +7 -0
  418. package/dist/src/notification/channels/SlackChannel.js +18 -0
  419. package/dist/src/notification/channels/SlackChannel.js.map +1 -0
  420. package/dist/src/notification/channels/SmsChannel.d.ts +24 -0
  421. package/dist/src/notification/channels/SmsChannel.js +37 -0
  422. package/dist/src/notification/channels/SmsChannel.js.map +1 -0
  423. package/dist/src/notification/channels/WebhookChannel.d.ts +17 -0
  424. package/dist/src/notification/channels/WebhookChannel.js +61 -0
  425. package/dist/src/notification/channels/WebhookChannel.js.map +1 -0
  426. package/dist/src/notification/index.d.ts +24 -0
  427. package/dist/src/notification/index.js +61 -0
  428. package/dist/src/notification/index.js.map +1 -0
  429. package/dist/src/scheduler/CronScheduler.d.ts +20 -0
  430. package/dist/src/scheduler/CronScheduler.js +82 -0
  431. package/dist/src/scheduler/CronScheduler.js.map +1 -0
  432. package/dist/src/scheduler/EnhancedCronScheduler.d.ts +27 -0
  433. package/dist/src/scheduler/EnhancedCronScheduler.js +177 -0
  434. package/dist/src/scheduler/EnhancedCronScheduler.js.map +1 -0
  435. package/dist/src/storage/ArchiveManager.d.ts +21 -0
  436. package/dist/src/storage/ArchiveManager.js +140 -0
  437. package/dist/src/storage/ArchiveManager.js.map +1 -0
  438. package/dist/src/storage/LocalFileStorage.d.ts +64 -0
  439. package/dist/src/storage/LocalFileStorage.js +470 -0
  440. package/dist/src/storage/LocalFileStorage.js.map +1 -0
  441. package/dist/src/storage/MemoryStorage.d.ts +65 -0
  442. package/dist/src/storage/MemoryStorage.js +422 -0
  443. package/dist/src/storage/MemoryStorage.js.map +1 -0
  444. package/dist/src/storage/StorageProvider.d.ts +223 -0
  445. package/dist/src/storage/StorageProvider.js +2 -0
  446. package/dist/src/storage/StorageProvider.js.map +1 -0
  447. package/dist/src/storage/builtin-adapters.d.ts +1 -0
  448. package/dist/src/storage/builtin-adapters.js +20 -0
  449. package/dist/src/storage/builtin-adapters.js.map +1 -0
  450. package/dist/src/storage/index.d.ts +17 -0
  451. package/dist/src/storage/index.js +52 -0
  452. package/dist/src/storage/index.js.map +1 -0
  453. package/dist/src/storage/registry.d.ts +6 -0
  454. package/dist/src/storage/registry.js +23 -0
  455. package/dist/src/storage/registry.js.map +1 -0
  456. package/dist/src/telemetry/index.d.ts +53 -0
  457. package/dist/src/telemetry/index.js +73 -0
  458. package/dist/src/telemetry/index.js.map +1 -0
  459. package/dist/src/telemetry/spanRegistry.d.ts +9 -0
  460. package/dist/src/telemetry/spanRegistry.js +14 -0
  461. package/dist/src/telemetry/spanRegistry.js.map +1 -0
  462. package/dist/src/templates/AutoExtract.d.ts +2 -0
  463. package/dist/src/templates/AutoExtract.js +124 -0
  464. package/dist/src/templates/AutoExtract.js.map +1 -0
  465. package/dist/src/templates/TemplateGallery.d.ts +54 -0
  466. package/dist/src/templates/TemplateGallery.js +139 -0
  467. package/dist/src/templates/TemplateGallery.js.map +1 -0
  468. package/dist/src/templates/TemplateRegistry.d.ts +16 -0
  469. package/dist/src/templates/TemplateRegistry.js +92 -0
  470. package/dist/src/templates/TemplateRegistry.js.map +1 -0
  471. package/dist/src/templates/WorkflowTemplate.d.ts +24 -0
  472. package/dist/src/templates/WorkflowTemplate.js +2 -0
  473. package/dist/src/templates/WorkflowTemplate.js.map +1 -0
  474. package/dist/src/templates/builtin/HttpCallbackTemplate.d.ts +2 -0
  475. package/dist/src/templates/builtin/HttpCallbackTemplate.js +47 -0
  476. package/dist/src/templates/builtin/HttpCallbackTemplate.js.map +1 -0
  477. package/dist/src/templates/builtin/index.d.ts +3 -0
  478. package/dist/src/templates/builtin/index.js +11 -0
  479. package/dist/src/templates/builtin/index.js.map +1 -0
  480. package/dist/src/templates/index.d.ts +3 -0
  481. package/dist/src/templates/index.js +3 -0
  482. package/dist/src/templates/index.js.map +1 -0
  483. package/dist/src/testing/MutationTester.d.ts +27 -0
  484. package/dist/src/testing/MutationTester.js +157 -0
  485. package/dist/src/testing/MutationTester.js.map +1 -0
  486. package/dist/src/testing/TestGenerator.d.ts +31 -0
  487. package/dist/src/testing/TestGenerator.js +345 -0
  488. package/dist/src/testing/TestGenerator.js.map +1 -0
  489. package/dist/src/testing/index.d.ts +2 -0
  490. package/dist/src/testing/index.js +3 -0
  491. package/dist/src/testing/index.js.map +1 -0
  492. package/dist/src/testing/testWorkflow.d.ts +51 -0
  493. package/dist/src/testing/testWorkflow.js +167 -0
  494. package/dist/src/testing/testWorkflow.js.map +1 -0
  495. package/dist/src/utils/AuditLogger.d.ts +36 -0
  496. package/dist/src/utils/AuditLogger.js +148 -0
  497. package/dist/src/utils/AuditLogger.js.map +1 -0
  498. package/dist/src/utils/BoundedMap.d.ts +34 -0
  499. package/dist/src/utils/BoundedMap.js +125 -0
  500. package/dist/src/utils/BoundedMap.js.map +1 -0
  501. package/dist/src/utils/LeaseStore.d.ts +7 -0
  502. package/dist/src/utils/LeaseStore.js +102 -0
  503. package/dist/src/utils/LeaseStore.js.map +1 -0
  504. package/dist/src/utils/Logger.d.ts +26 -0
  505. package/dist/src/utils/Logger.js +279 -0
  506. package/dist/src/utils/Logger.js.map +1 -0
  507. package/dist/src/utils/SecretManager.d.ts +41 -0
  508. package/dist/src/utils/SecretManager.js +139 -0
  509. package/dist/src/utils/SecretManager.js.map +1 -0
  510. package/dist/src/utils/StructuredLogger.d.ts +45 -0
  511. package/dist/src/utils/StructuredLogger.js +118 -0
  512. package/dist/src/utils/StructuredLogger.js.map +1 -0
  513. package/dist/src/utils/concurrency.d.ts +3 -0
  514. package/dist/src/utils/concurrency.js +22 -0
  515. package/dist/src/utils/concurrency.js.map +1 -0
  516. package/dist/src/utils/env.d.ts +5 -0
  517. package/dist/src/utils/env.js +15 -0
  518. package/dist/src/utils/env.js.map +1 -0
  519. package/dist/src/utils/index.d.ts +5 -0
  520. package/dist/src/utils/index.js +4 -0
  521. package/dist/src/utils/index.js.map +1 -0
  522. package/dist/src/utils/secrets.d.ts +5 -0
  523. package/dist/src/utils/secrets.js +27 -0
  524. package/dist/src/utils/secrets.js.map +1 -0
  525. package/package.json +159 -0
@@ -0,0 +1,790 @@
1
+ import express from "express";
2
+ import { body, param, validationResult } from "express-validator";
3
+ import { workflowDebugger } from "../../debug/WorkflowDebugger.js";
4
+ import { searchInstances, } from "../../engine/InstanceSearch.js";
5
+ import { searchAttributeManager, } from "../../engine/SearchAttributeManager.js";
6
+ import { errorMessage, errorStack, Logger } from "../../utils/Logger.js";
7
+ import { rbacMiddleware } from "../middleware/rbac.js";
8
+ import { sendError, sendSuccess } from "../response.js";
9
+ import { InstanceApplicationService } from "../services/InstanceApplicationService.js";
10
+ import { getRequestEngine, getRequestStorage } from "../utils/requestContext.js";
11
+ import { asyncHandler } from "../utils/routeHelper.js";
12
+ const router = express.Router();
13
+ function getService(req) {
14
+ const engine = getRequestEngine(req);
15
+ const storage = getRequestStorage(req) ?? null;
16
+ return new InstanceApplicationService(engine, storage);
17
+ }
18
+ function getEngine(req) {
19
+ return getRequestEngine(req);
20
+ }
21
+ function getStorage(req, engine) {
22
+ void engine;
23
+ return getRequestStorage(req);
24
+ }
25
+ function validateRequest(req, res) {
26
+ const errors = validationResult(req);
27
+ if (!errors.isEmpty()) {
28
+ sendError(res, 400, 400, errors.array()[0].msg);
29
+ return false;
30
+ }
31
+ return true;
32
+ }
33
+ function _getTotalNodes(workflow) {
34
+ const nodes = workflow?.nodes;
35
+ if (!nodes)
36
+ return 0;
37
+ if (Array.isArray(nodes))
38
+ return nodes.length;
39
+ if (typeof nodes === "object")
40
+ return Object.keys(nodes).length;
41
+ return 0;
42
+ }
43
+ router.post("/workflows/:id/dry-run", param("id").isString().notEmpty().withMessage("Workflow ID is required"), body("context")
44
+ .optional()
45
+ .isObject()
46
+ .withMessage("Context must be an object"), body("options")
47
+ .optional()
48
+ .isObject()
49
+ .withMessage("Options must be an object"), async (req, res) => {
50
+ if (!validateRequest(req, res)) {
51
+ return;
52
+ }
53
+ try {
54
+ const engine = getEngine(req);
55
+ const workflowId = req.params.id;
56
+ const result = await engine.dryRun(workflowId, req.body?.context ?? {}, req.body?.options ?? {});
57
+ return sendSuccess(res, 200, result, "Workflow dry run completed");
58
+ }
59
+ catch (error) {
60
+ Logger.error("api", "instances", `Error running dry run for ${req.params.id}: ${errorMessage(error)}`, errorStack(error));
61
+ return sendError(res, 500, 500, errorMessage(error) || "Failed to execute dry run");
62
+ }
63
+ });
64
+ function toEpochMs(value) {
65
+ if (value instanceof Date) {
66
+ return value.getTime();
67
+ }
68
+ if (typeof value === "number") {
69
+ return Number.isFinite(value) ? value : 0;
70
+ }
71
+ if (typeof value === "string") {
72
+ const parsedDate = Date.parse(value);
73
+ if (!Number.isNaN(parsedDate)) {
74
+ return parsedDate;
75
+ }
76
+ const parsedNumber = Number(value);
77
+ if (Number.isFinite(parsedNumber)) {
78
+ return parsedNumber;
79
+ }
80
+ }
81
+ return 0;
82
+ }
83
+ async function loadInstance(engine, storage, instanceId) {
84
+ const maybeInstance = await Promise.resolve(engine.getInstance(instanceId));
85
+ if (maybeInstance) {
86
+ return maybeInstance;
87
+ }
88
+ if (storage?.loadInstance) {
89
+ const stored = await storage.loadInstance(instanceId);
90
+ return stored ?? undefined;
91
+ }
92
+ return undefined;
93
+ }
94
+ async function _loadAllInstances(engine, storage) {
95
+ if (storage) {
96
+ const ids = await storage.listInstances();
97
+ const instances = await Promise.all(ids.map((instanceId) => storage.loadInstance(instanceId)));
98
+ return instances.filter((inst) => Boolean(inst));
99
+ }
100
+ return engine
101
+ .listInstances()
102
+ .map((id) => engine.getInstance(id))
103
+ .filter((inst) => Boolean(inst));
104
+ }
105
+ async function _invokeInstanceLifecycleMethod(engine, methodName, instanceId) {
106
+ switch (methodName) {
107
+ case "cancelInstance":
108
+ if (typeof engine.cancelInstance !== "function") {
109
+ break;
110
+ }
111
+ return await engine.cancelInstance(instanceId);
112
+ case "pauseInstance":
113
+ if (typeof engine.pauseInstance !== "function") {
114
+ break;
115
+ }
116
+ return await engine.pauseInstance(instanceId);
117
+ case "resumeInstance":
118
+ if (typeof engine.resumeInstance !== "function") {
119
+ break;
120
+ }
121
+ return await engine.resumeInstance(instanceId);
122
+ default:
123
+ break;
124
+ }
125
+ throw new Error(`${methodName} is not supported by the current engine`);
126
+ }
127
+ router.get("/", asyncHandler(async (req, res) => {
128
+ const service = getService(req);
129
+ const page = req.query.page
130
+ ? Number.parseInt(req.query.page, 10)
131
+ : 1;
132
+ const pageSize = req.query.pageSize
133
+ ? Number.parseInt(req.query.pageSize, 10)
134
+ : 50;
135
+ if (page < 1 || pageSize < 1 || pageSize > 100) {
136
+ res.status(400).json({
137
+ success: false,
138
+ error: "VALIDATION_ERROR",
139
+ message: "Invalid pagination parameters (page >= 1, 1 <= pageSize <= 100)",
140
+ });
141
+ return;
142
+ }
143
+ const result = await service.listInstances({
144
+ workflowId: req.query.workflowId,
145
+ status: req.query.status,
146
+ startTime: req.query.startTime
147
+ ? Number.parseInt(req.query.startTime, 10)
148
+ : undefined,
149
+ endTime: req.query.endTime
150
+ ? Number.parseInt(req.query.endTime, 10)
151
+ : undefined,
152
+ page,
153
+ pageSize,
154
+ sortBy: req.query.sortBy || "createdAt",
155
+ sortOrder: req.query.sortOrder || "desc",
156
+ parentId: req.query.parentId,
157
+ });
158
+ res.json({
159
+ success: true,
160
+ data: {
161
+ instances: result.instances,
162
+ pagination: {
163
+ page: result.page,
164
+ pageSize: result.pageSize,
165
+ totalCount: result.total,
166
+ totalPages: Math.ceil(result.total / result.pageSize),
167
+ },
168
+ },
169
+ message: "Instances retrieved",
170
+ });
171
+ }));
172
+ router.get("/search", asyncHandler(async (req, res) => {
173
+ const service = getService(req);
174
+ const workflowId = req.query.workflowId;
175
+ const status = typeof req.query.status === "string" && req.query.status.length > 0
176
+ ? req.query.status.split(",").map((s) => s.trim())
177
+ : undefined;
178
+ let attributes;
179
+ if (typeof req.query.attributes === "string") {
180
+ try {
181
+ attributes = JSON.parse(req.query.attributes);
182
+ }
183
+ catch {
184
+ res.status(400).json({
185
+ success: false,
186
+ error: "VALIDATION_ERROR",
187
+ message: "attributes must be a valid JSON object",
188
+ });
189
+ return;
190
+ }
191
+ }
192
+ const offset = req.query.offset
193
+ ? Number.parseInt(req.query.offset, 10)
194
+ : undefined;
195
+ const limit = req.query.limit
196
+ ? Number.parseInt(req.query.limit, 10)
197
+ : undefined;
198
+ const instanceIds = searchAttributeManager.query({
199
+ workflowId,
200
+ status,
201
+ attributes,
202
+ offset,
203
+ limit,
204
+ });
205
+ const instances = await Promise.all(instanceIds.map((id) => service.getInstance(id).catch(() => null)));
206
+ const results = instances
207
+ .filter((inst) => Boolean(inst))
208
+ .map((inst) => {
209
+ if (!inst)
210
+ return null;
211
+ return {
212
+ id: inst.instanceId,
213
+ workflowId: inst.workflowId,
214
+ status: inst.status,
215
+ createdAt: toEpochMs(inst.createdAt),
216
+ updatedAt: toEpochMs(inst.updatedAt),
217
+ currentNode: inst.currentNodes?.[0],
218
+ searchAttributes: inst.searchAttributes,
219
+ };
220
+ })
221
+ .filter(Boolean);
222
+ res.json({
223
+ success: true,
224
+ data: { instances: results, total: instanceIds.length },
225
+ message: "Instances retrieved",
226
+ });
227
+ }));
228
+ router.post("/search", asyncHandler(async (req, res) => {
229
+ const service = getService(req);
230
+ const query = (req.body ?? {});
231
+ if (query.filters !== undefined && !Array.isArray(query.filters)) {
232
+ res.status(400).json({
233
+ success: false,
234
+ error: "VALIDATION_ERROR",
235
+ message: "filters must be an array",
236
+ });
237
+ return;
238
+ }
239
+ const storage = getRequestStorage(req);
240
+ let allInstances = [];
241
+ if (storage && typeof storage.listInstances === "function") {
242
+ const ids = await storage.listInstances();
243
+ allInstances = (await Promise.all(ids.map((id) => storage.loadInstance(id)))).filter((inst) => Boolean(inst));
244
+ }
245
+ else {
246
+ const engine = getRequestEngine(req);
247
+ const rawIds = await engine.listInstances();
248
+ const ids = Array.isArray(rawIds) ? rawIds : [];
249
+ allInstances = (await Promise.all(ids.map(async (id) => {
250
+ try {
251
+ return await service.loadRawInstance(id);
252
+ }
253
+ catch {
254
+ return null;
255
+ }
256
+ }))).filter((inst) => Boolean(inst));
257
+ }
258
+ let result;
259
+ try {
260
+ result = searchInstances(allInstances, query);
261
+ }
262
+ catch (error) {
263
+ const msg = error instanceof Error ? errorMessage(error) : "Invalid search query";
264
+ res
265
+ .status(400)
266
+ .json({ success: false, error: "VALIDATION_ERROR", message: msg });
267
+ return;
268
+ }
269
+ res.json({
270
+ success: true,
271
+ data: {
272
+ instances: result.instances.map((inst) => ({
273
+ instanceId: inst.instanceId,
274
+ workflowId: inst.workflowId,
275
+ status: inst.status,
276
+ createdAt: toEpochMs(inst.createdAt),
277
+ updatedAt: toEpochMs(inst.updatedAt),
278
+ currentNodes: inst.currentNodes,
279
+ searchAttributes: inst.searchAttributes,
280
+ })),
281
+ pagination: result.pagination,
282
+ aggregations: result.aggregations,
283
+ },
284
+ message: "Instances retrieved",
285
+ });
286
+ }));
287
+ router.post("/batch/retry", asyncHandler(async (req, res) => {
288
+ const service = getService(req);
289
+ const ids = req.body?.ids;
290
+ if (!Array.isArray(ids) || ids.length === 0) {
291
+ res.status(400).json({
292
+ success: false,
293
+ error: "VALIDATION_ERROR",
294
+ message: "Body must contain a non-empty ids array",
295
+ });
296
+ return;
297
+ }
298
+ const batchMaxSize = Number.parseInt(process.env.BATCH_MAX_SIZE || "100", 10);
299
+ if (ids.length > batchMaxSize) {
300
+ res.status(400).json({
301
+ success: false,
302
+ error: "VALIDATION_ERROR",
303
+ message: `Batch size exceeds limit (${batchMaxSize})`,
304
+ });
305
+ return;
306
+ }
307
+ const results = [];
308
+ const newInstanceIds = [];
309
+ const engine = getRequestEngine(req);
310
+ for (const rawId of ids) {
311
+ const id = String(rawId);
312
+ try {
313
+ const instance = await service.getInstance(id);
314
+ if (!["failed", "cancelled"].includes(instance.status)) {
315
+ results.push({
316
+ id,
317
+ ok: false,
318
+ error: `Cannot retry instance with status '${instance.status}'`,
319
+ });
320
+ continue;
321
+ }
322
+ const newInstanceId = await engine.start(instance.workflowId, (instance.context ?? {}));
323
+ newInstanceIds.push(newInstanceId);
324
+ results.push({ id, ok: true, newInstanceId });
325
+ }
326
+ catch (error) {
327
+ const msg = error instanceof Error ? errorMessage(error) : String(error);
328
+ results.push({ id, ok: false, error: msg });
329
+ }
330
+ }
331
+ const succeeded = results.filter((r) => r.ok).length;
332
+ res.json({
333
+ success: true,
334
+ data: {
335
+ retried: succeeded,
336
+ failed: results.length - succeeded,
337
+ newInstanceIds,
338
+ results,
339
+ },
340
+ message: "Batch retry completed",
341
+ });
342
+ }));
343
+ router.post("/batch/delete", rbacMiddleware({ resource: "instance", action: "delete" }), asyncHandler(async (req, res) => {
344
+ const service = getService(req);
345
+ const ids = req.body?.ids;
346
+ const confirm = req.body?.confirm;
347
+ if (!Array.isArray(ids) || ids.length === 0) {
348
+ res.status(400).json({
349
+ success: false,
350
+ error: "VALIDATION_ERROR",
351
+ message: "Body must contain a non-empty ids array",
352
+ });
353
+ return;
354
+ }
355
+ if (confirm !== true) {
356
+ res.status(400).json({
357
+ success: false,
358
+ error: "VALIDATION_ERROR",
359
+ message: "Batch delete requires { confirm: true } to prevent accidental deletion",
360
+ });
361
+ return;
362
+ }
363
+ const batchMaxSize = Number.parseInt(process.env.BATCH_MAX_SIZE || "100", 10);
364
+ if (ids.length > batchMaxSize) {
365
+ res.status(400).json({
366
+ success: false,
367
+ error: "VALIDATION_ERROR",
368
+ message: `Batch size exceeds limit (${batchMaxSize})`,
369
+ });
370
+ return;
371
+ }
372
+ const results = [];
373
+ const TERMINAL = new Set(["completed", "failed", "cancelled"]);
374
+ for (const rawId of ids) {
375
+ const id = String(rawId);
376
+ try {
377
+ const instance = await service.getInstance(id);
378
+ if (!TERMINAL.has(instance.status)) {
379
+ results.push({
380
+ id,
381
+ ok: false,
382
+ error: `Cannot delete instance with status '${instance.status}'`,
383
+ });
384
+ continue;
385
+ }
386
+ await service.deleteInstance(id);
387
+ results.push({ id, ok: true });
388
+ }
389
+ catch (error) {
390
+ const msg = error instanceof Error ? errorMessage(error) : String(error);
391
+ results.push({ id, ok: false, error: msg });
392
+ }
393
+ }
394
+ const succeeded = results.filter((r) => r.ok).length;
395
+ res.json({
396
+ success: true,
397
+ data: { deleted: succeeded, failed: results.length - succeeded, results },
398
+ message: "Batch delete completed",
399
+ });
400
+ }));
401
+ const _BATCH_OPERATIONS = {
402
+ cancel: "cancelInstance",
403
+ pause: "pauseInstance",
404
+ resume: "resumeInstance",
405
+ };
406
+ router.post("/batch/:operation", asyncHandler(async (req, res) => {
407
+ const operation = req.params.operation;
408
+ const engine = getRequestEngine(req);
409
+ const BATCH_METHODS = {
410
+ cancel: "cancelInstance",
411
+ pause: "pauseInstance",
412
+ resume: "resumeInstance",
413
+ };
414
+ const methodName = BATCH_METHODS[operation];
415
+ if (!methodName) {
416
+ res.status(400).json({
417
+ success: false,
418
+ error: "VALIDATION_ERROR",
419
+ message: `Unknown batch operation: ${operation}. Supported: ${Object.keys(BATCH_METHODS).join(", ")}`,
420
+ });
421
+ return;
422
+ }
423
+ const ids = req.body?.ids;
424
+ if (!Array.isArray(ids) || ids.length === 0) {
425
+ res.status(400).json({
426
+ success: false,
427
+ error: "VALIDATION_ERROR",
428
+ message: "Body must contain a non-empty ids array",
429
+ });
430
+ return;
431
+ }
432
+ const batchMaxSize = Number.parseInt(process.env.BATCH_MAX_SIZE || "100", 10);
433
+ if (ids.length > batchMaxSize) {
434
+ res.status(400).json({
435
+ success: false,
436
+ error: "VALIDATION_ERROR",
437
+ message: `Batch size exceeds limit (${batchMaxSize})`,
438
+ });
439
+ return;
440
+ }
441
+ const results = [];
442
+ for (const rawId of ids) {
443
+ const id = String(rawId);
444
+ try {
445
+ const fn = engine[methodName];
446
+ if (typeof fn !== "function") {
447
+ results.push({
448
+ id,
449
+ ok: false,
450
+ error: `Method ${methodName} not supported`,
451
+ });
452
+ continue;
453
+ }
454
+ const success = await fn.call(engine, id);
455
+ results.push(success
456
+ ? { id, ok: true }
457
+ : { id, ok: false, error: "Instance not found or not eligible" });
458
+ }
459
+ catch (error) {
460
+ const msg = error instanceof Error ? errorMessage(error) : String(error);
461
+ results.push({ id, ok: false, error: msg });
462
+ }
463
+ }
464
+ const succeeded = results.filter((r) => r.ok).length;
465
+ res.json({
466
+ success: true,
467
+ data: { succeeded, failed: results.length - succeeded, results },
468
+ message: `Batch ${operation} completed`,
469
+ });
470
+ }));
471
+ router.get("/:id", param("id").isString().notEmpty().withMessage("Instance ID is required"), asyncHandler(async (req, res) => {
472
+ const service = getService(req);
473
+ const instance = await service.getInstance(req.params.id);
474
+ res.json({
475
+ success: true,
476
+ data: instance,
477
+ message: "Instance retrieved",
478
+ });
479
+ }));
480
+ router.get("/:id/history", param("id").isString().notEmpty().withMessage("Instance ID is required"), async (req, res) => {
481
+ const errors = validationResult(req);
482
+ if (!errors.isEmpty()) {
483
+ return sendError(res, 400, 400, errors.array()[0].msg);
484
+ }
485
+ try {
486
+ const engine = getEngine(req);
487
+ const storage = getStorage(req, engine);
488
+ const instanceId = req.params.id;
489
+ const instance = await loadInstance(engine, storage, instanceId);
490
+ if (!instance) {
491
+ return sendError(res, 404, 404, `Instance with ID ${instanceId} not found`);
492
+ }
493
+ const executionHistory = instance.history
494
+ .sort((a, b) => toEpochMs(a.timestamp) - toEpochMs(b.timestamp))
495
+ .map((log) => ({
496
+ nodeId: log.nodeId,
497
+ timestamp: toEpochMs(log.timestamp),
498
+ status: log.status,
499
+ duration: log.duration,
500
+ data: log.data,
501
+ error: log.error,
502
+ stack: log.stack,
503
+ }));
504
+ return sendSuccess(res, 200, {
505
+ instanceId,
506
+ workflowId: instance.workflowId,
507
+ history: executionHistory,
508
+ totalSteps: executionHistory.length,
509
+ }, "Instance history retrieved");
510
+ }
511
+ catch (error) {
512
+ Logger.error("api", "instances", `Error getting instance history ${req.params.id}: ${errorMessage(error)}`, errorStack(error));
513
+ return sendError(res, 500, 500, errorMessage(error) || "Failed to retrieve instance history");
514
+ }
515
+ });
516
+ router.post("/:id/debug/attach", param("id").isString().notEmpty().withMessage("Instance ID is required"), (req, res) => {
517
+ if (!validateRequest(req, res)) {
518
+ return;
519
+ }
520
+ const instanceId = req.params.id;
521
+ workflowDebugger.attach(instanceId);
522
+ return sendSuccess(res, 200, workflowDebugger.getSnapshot(), `Debugger attached to instance ${instanceId}`);
523
+ });
524
+ router.post("/:id/debug/detach", (req, res) => {
525
+ const instanceId = req.params.id;
526
+ workflowDebugger.detach();
527
+ return sendSuccess(res, 200, { instanceId }, `Debugger detached from instance ${instanceId}`);
528
+ });
529
+ router.get("/:id/debug/snapshot", (_req, res) => {
530
+ return sendSuccess(res, 200, workflowDebugger.getSnapshot(), "Debugger snapshot retrieved");
531
+ });
532
+ router.post("/:id/debug/breakpoints", param("id").isString().notEmpty().withMessage("Instance ID is required"), body("nodeId").isString().notEmpty().withMessage("nodeId is required"), body("condition")
533
+ .optional()
534
+ .isString()
535
+ .withMessage("condition must be a string"), (req, res) => {
536
+ if (!validateRequest(req, res)) {
537
+ return;
538
+ }
539
+ const instanceId = req.params.id;
540
+ if (workflowDebugger.getSnapshot().instanceId !== instanceId) {
541
+ workflowDebugger.attach(instanceId);
542
+ }
543
+ const breakpoint = workflowDebugger.addBreakpoint(req.body.nodeId, req.body.condition);
544
+ return sendSuccess(res, 201, breakpoint, "Breakpoint added");
545
+ });
546
+ router.delete("/:id/debug/breakpoints/:breakpointId", param("breakpointId")
547
+ .isString()
548
+ .notEmpty()
549
+ .withMessage("breakpointId is required"), (req, res) => {
550
+ if (!validateRequest(req, res)) {
551
+ return;
552
+ }
553
+ const removed = workflowDebugger.removeBreakpoint(req.params.breakpointId);
554
+ return sendSuccess(res, removed ? 200 : 404, { removed }, removed ? "Breakpoint removed" : "Breakpoint not found");
555
+ });
556
+ router.patch("/:id/debug/breakpoints/:breakpointId", param("breakpointId")
557
+ .isString()
558
+ .notEmpty()
559
+ .withMessage("breakpointId is required"), body("enabled")
560
+ .optional()
561
+ .isBoolean()
562
+ .withMessage("enabled must be a boolean"), (req, res) => {
563
+ if (!validateRequest(req, res)) {
564
+ return;
565
+ }
566
+ const breakpoint = workflowDebugger.toggleBreakpoint(req.params.breakpointId, req.body.enabled);
567
+ if (!breakpoint) {
568
+ return sendError(res, 404, 404, "Breakpoint not found");
569
+ }
570
+ return sendSuccess(res, 200, breakpoint, "Breakpoint updated");
571
+ });
572
+ router.post("/:id/debug/resume", (_req, res) => {
573
+ workflowDebugger.resume();
574
+ return sendSuccess(res, 200, workflowDebugger.getSnapshot(), "Debugger resumed");
575
+ });
576
+ router.post("/:id/debug/step", (_req, res) => {
577
+ void workflowDebugger.step();
578
+ return sendSuccess(res, 200, workflowDebugger.getSnapshot(), "Debugger step requested");
579
+ });
580
+ router.post("/:id/signal", param("id").isString().notEmpty().withMessage("Instance ID is required"), body("name").isString().notEmpty().withMessage("Signal name is required"), body("payload").optional(), asyncHandler(async (req, res) => {
581
+ const service = getService(req);
582
+ const result = await service.signalInstance(req.params.id, req.body.name, req.body.payload);
583
+ res.status(202).json({
584
+ success: true,
585
+ data: result,
586
+ message: `Signal ${req.body.name} sent to instance ${req.params.id}`,
587
+ });
588
+ }));
589
+ router.post("/:id/query", param("id").isString().notEmpty().withMessage("Instance ID is required"), body("name").isString().notEmpty().withMessage("Query name is required"), body("payload").optional(), asyncHandler(async (req, res) => {
590
+ const service = getService(req);
591
+ const result = await service.queryInstance(req.params.id, req.body.name, req.body.payload);
592
+ res.json({
593
+ success: true,
594
+ data: result,
595
+ message: `Query ${req.body.name} completed for instance ${req.params.id}`,
596
+ });
597
+ }));
598
+ router.post("/:id/update", param("id").isString().notEmpty().withMessage("Instance ID is required"), body("name").isString().notEmpty().withMessage("Update name is required"), body("payload").optional(), body("correlationId").optional().isString(), asyncHandler(async (req, res) => {
599
+ const service = getService(req);
600
+ const result = await service.updateInstance(req.params.id, req.body.name, req.body.payload, req.body.correlationId);
601
+ res.json({
602
+ success: true,
603
+ data: result,
604
+ message: `Update ${req.body.name} completed for instance ${req.params.id}`,
605
+ });
606
+ }));
607
+ router.post("/:id/pause", param("id").isString().notEmpty().withMessage("Instance ID is required"), asyncHandler(async (req, res) => {
608
+ const service = getService(req);
609
+ const result = await service.pauseInstance(req.params.id);
610
+ res.json({
611
+ success: true,
612
+ data: { instanceId: result.instanceId },
613
+ message: `Instance ${req.params.id} paused successfully`,
614
+ });
615
+ }));
616
+ router.post("/:id/resume", param("id").isString().notEmpty().withMessage("Instance ID is required"), asyncHandler(async (req, res) => {
617
+ const service = getService(req);
618
+ const result = await service.resumeInstance(req.params.id);
619
+ res.json({
620
+ success: true,
621
+ data: { instanceId: result.instanceId },
622
+ message: `Instance ${req.params.id} resumed successfully`,
623
+ });
624
+ }));
625
+ router.post("/:id/cancel", param("id").isString().notEmpty().withMessage("Instance ID is required"), asyncHandler(async (req, res) => {
626
+ const service = getService(req);
627
+ const result = await service.cancelInstance(req.params.id);
628
+ res.json({
629
+ success: true,
630
+ data: { instanceId: result.instanceId },
631
+ message: `Instance ${req.params.id} cancelled successfully`,
632
+ });
633
+ }));
634
+ router.post("/:id/terminate", param("id").isString().notEmpty().withMessage("Instance ID is required"), asyncHandler(async (req, res) => {
635
+ const service = getService(req);
636
+ const result = await service.terminateInstance(req.params.id);
637
+ res.json({
638
+ success: true,
639
+ data: { instanceId: result.instanceId },
640
+ message: result.success
641
+ ? `Instance ${req.params.id} terminated successfully`
642
+ : `Instance ${req.params.id} was already in a terminal state`,
643
+ });
644
+ }));
645
+ router.post("/:id/nodes/:nodeId/retry", param("id").isString().notEmpty().withMessage("Instance ID is required"), param("nodeId").isString().notEmpty().withMessage("Node ID is required"), body("preserveInput")
646
+ .optional()
647
+ .isBoolean()
648
+ .withMessage("preserveInput must be a boolean"), body("maxRetries")
649
+ .optional()
650
+ .isInt({ min: 1 })
651
+ .withMessage("maxRetries must be a positive integer"), async (req, res) => {
652
+ const errors = validationResult(req);
653
+ if (!errors.isEmpty()) {
654
+ return sendError(res, 400, 400, errors.array()[0].msg);
655
+ }
656
+ try {
657
+ const engine = getEngine(req);
658
+ const instanceId = req.params.id;
659
+ const nodeId = req.params.nodeId;
660
+ await engine.retryNode(instanceId, nodeId);
661
+ return sendSuccess(res, 200, {
662
+ instanceId,
663
+ nodeId,
664
+ }, `Node ${nodeId} in instance ${instanceId} retried successfully`);
665
+ }
666
+ catch (error) {
667
+ Logger.error("api", "instances", `Error retrying node ${req.params.nodeId} in instance ${req.params.id}: ${errorMessage(error)}`, errorStack(error));
668
+ const statusCode = errorMessage(error)?.includes("not in a failed state") ||
669
+ errorMessage(error)?.includes("not found")
670
+ ? 400
671
+ : 500;
672
+ return sendError(res, statusCode, statusCode, errorMessage(error) || "Failed to retry node");
673
+ }
674
+ });
675
+ router.post("/:id/nodes/:nodeId/skip", param("id").isString().notEmpty().withMessage("Instance ID is required"), param("nodeId").isString().notEmpty().withMessage("Node ID is required"), body("defaultOutput").optional(), async (req, res) => {
676
+ const errors = validationResult(req);
677
+ if (!errors.isEmpty()) {
678
+ return sendError(res, 400, 400, errors.array()[0].msg);
679
+ }
680
+ try {
681
+ const engine = getEngine(req);
682
+ const instanceId = req.params.id;
683
+ const nodeId = req.params.nodeId;
684
+ const defaultOutput = req.body.defaultOutput;
685
+ await engine.skipNode(instanceId, nodeId, defaultOutput);
686
+ return sendSuccess(res, 200, {
687
+ instanceId,
688
+ nodeId,
689
+ defaultOutput,
690
+ }, `Node ${nodeId} in instance ${instanceId} skipped successfully`);
691
+ }
692
+ catch (error) {
693
+ Logger.error("api", "instances", `Error skipping node ${req.params.nodeId} in instance ${req.params.id}: ${errorMessage(error)}`, errorStack(error));
694
+ const statusCode = errorMessage(error)?.includes("already completed") ||
695
+ errorMessage(error)?.includes("not found")
696
+ ? 400
697
+ : 500;
698
+ return sendError(res, statusCode, statusCode, errorMessage(error) || "Failed to skip node");
699
+ }
700
+ });
701
+ router.post("/:id/compensate", param("id").isString().notEmpty().withMessage("Instance ID is required"), body("reason").optional().isString().withMessage("reason must be a string"), body("fromNode")
702
+ .optional()
703
+ .isString()
704
+ .withMessage("fromNode must be a string"), async (req, res) => {
705
+ const errors = validationResult(req);
706
+ if (!errors.isEmpty()) {
707
+ return sendError(res, 400, 400, errors.array()[0].msg);
708
+ }
709
+ try {
710
+ const engine = getEngine(req);
711
+ const instanceId = req.params.id;
712
+ const reason = req.body.reason;
713
+ await engine.compensate(instanceId, reason);
714
+ return sendSuccess(res, 200, {
715
+ instanceId,
716
+ reason,
717
+ }, `Compensation triggered for instance ${instanceId}`);
718
+ }
719
+ catch (error) {
720
+ Logger.error("api", "instances", `Error triggering compensation for instance ${req.params.id}: ${errorMessage(error)}`, errorStack(error));
721
+ const statusCode = errorMessage(error)?.includes("not found") ? 400 : 500;
722
+ return sendError(res, statusCode, statusCode, errorMessage(error) || "Failed to trigger compensation");
723
+ }
724
+ });
725
+ router.get("/:id/nodes/:nodeId/status", param("id").isString().notEmpty().withMessage("Instance ID is required"), param("nodeId").isString().notEmpty().withMessage("Node ID is required"), async (req, res) => {
726
+ const errors = validationResult(req);
727
+ if (!errors.isEmpty()) {
728
+ return sendError(res, 400, 400, errors.array()[0].msg);
729
+ }
730
+ try {
731
+ const engine = getEngine(req);
732
+ const storage = getStorage(req, engine);
733
+ const instanceId = req.params.id;
734
+ const nodeId = req.params.nodeId;
735
+ const instance = await loadInstance(engine, storage, instanceId);
736
+ if (!instance) {
737
+ return sendError(res, 404, 404, `Instance with ID ${instanceId} not found`);
738
+ }
739
+ const nodeHistory = instance.history.filter((log) => log.nodeId === nodeId);
740
+ if (nodeHistory.length === 0) {
741
+ return sendError(res, 404, 404, `Node ${nodeId} not found in instance ${instanceId}`);
742
+ }
743
+ const lastExecution = nodeHistory[nodeHistory.length - 1];
744
+ let status;
745
+ if (lastExecution.status === "success") {
746
+ status = "completed";
747
+ }
748
+ else if (lastExecution.status === "failed") {
749
+ status = "failed";
750
+ }
751
+ else if (lastExecution.status === "skipped") {
752
+ status = "skipped";
753
+ }
754
+ else if (instance.currentNodes?.includes(nodeId)) {
755
+ status = "running";
756
+ }
757
+ else {
758
+ status = "pending";
759
+ }
760
+ let duration;
761
+ if (lastExecution.duration !== undefined) {
762
+ duration = lastExecution.duration;
763
+ }
764
+ const retryCount = instance.retries?.[nodeId] || 0;
765
+ const output = instance.state?.nodes?.[nodeId]?.output;
766
+ const nodeStatus = {
767
+ nodeId,
768
+ status,
769
+ startTime: toEpochMs(lastExecution.timestamp),
770
+ endTime: toEpochMs(lastExecution.timestamp) + (duration || 0),
771
+ duration,
772
+ retryCount,
773
+ error: lastExecution.status === "failed"
774
+ ? {
775
+ message: lastExecution.error || "Unknown error",
776
+ stack: lastExecution.stack,
777
+ timestamp: toEpochMs(lastExecution.timestamp),
778
+ }
779
+ : undefined,
780
+ output,
781
+ };
782
+ return sendSuccess(res, 200, nodeStatus, "Node status retrieved");
783
+ }
784
+ catch (error) {
785
+ Logger.error("api", "instances", `Error getting node status for ${req.params.nodeId} in instance ${req.params.id}: ${errorMessage(error)}`, errorStack(error));
786
+ return sendError(res, 500, 500, errorMessage(error) || "Failed to get node status");
787
+ }
788
+ });
789
+ export default router;
790
+ //# sourceMappingURL=instances.js.map