snow-flow 3.0.9 → 3.0.13

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 (302) hide show
  1. package/claude-flow.bat +0 -0
  2. package/claude-flow.ps1 +0 -0
  3. package/dist/mcp/intelligent-reporting-mcp.d.ts +7 -0
  4. package/dist/mcp/intelligent-reporting-mcp.js +379 -0
  5. package/dist/mcp/servicenow-automation-mcp.js +0 -0
  6. package/dist/mcp/servicenow-deployment-mcp.js +0 -0
  7. package/dist/mcp/servicenow-integration-mcp.js +0 -0
  8. package/dist/mcp/servicenow-mcp-server.js +0 -0
  9. package/dist/mcp/servicenow-operations-mcp.js +0 -0
  10. package/dist/mcp/servicenow-platform-development-mcp.js +0 -0
  11. package/dist/mcp/servicenow-progressive-indexer.js +0 -0
  12. package/dist/mcp/servicenow-reporting-analytics-mcp.js +280 -29
  13. package/dist/mcp/servicenow-security-compliance-mcp.js +0 -0
  14. package/dist/mcp/servicenow-update-set-mcp.js +0 -0
  15. package/dist/mcp/start-all-mcp-servers.js +0 -0
  16. package/dist/mcp/start-servicenow-mcp.js +0 -0
  17. package/dist/services/widget-deployment-service.d.ts +2 -1
  18. package/dist/services/widget-deployment-service.js +17 -16
  19. package/dist/utils/anti-mock-data-validator.d.ts +66 -0
  20. package/dist/utils/anti-mock-data-validator.js +316 -0
  21. package/dist/utils/servicenow-eventual-consistency.d.ts +120 -0
  22. package/dist/utils/servicenow-eventual-consistency.js +220 -0
  23. package/memory/agents/README.md +1 -1
  24. package/memory/claude-flow-data.json +1 -1
  25. package/memory/sessions/README.md +1 -1
  26. package/package.json +4 -3
  27. package/.mcp.json +0 -22
  28. package/claude-flow.config.json +0 -20
  29. package/dist/agents/app-creator.agent.d.ts +0 -55
  30. package/dist/agents/app-creator.agent.js +0 -1292
  31. package/dist/agents/base/base-snow-agent.d.ts +0 -75
  32. package/dist/agents/base/base-snow-agent.js +0 -169
  33. package/dist/agents/base-snow-agent.d.ts +0 -63
  34. package/dist/agents/base-snow-agent.js +0 -296
  35. package/dist/agents/coordinator.d.ts +0 -200
  36. package/dist/agents/coordinator.js +0 -777
  37. package/dist/agents/flow-builder-agent.d.ts +0 -18
  38. package/dist/agents/flow-builder-agent.js +0 -197
  39. package/dist/agents/queen-403-handler.d.ts +0 -47
  40. package/dist/agents/queen-403-handler.js +0 -175
  41. package/dist/agents/queen-agent-example.d.ts +0 -23
  42. package/dist/agents/queen-agent-example.js +0 -240
  43. package/dist/agents/queen-agent.test.d.ts +0 -6
  44. package/dist/agents/script-generator.agent.d.ts +0 -32
  45. package/dist/agents/script-generator.agent.js +0 -772
  46. package/dist/agents/script-writer-agent.d.ts +0 -22
  47. package/dist/agents/script-writer-agent.js +0 -695
  48. package/dist/agents/security-agent.d.ts +0 -23
  49. package/dist/agents/security-agent.js +0 -619
  50. package/dist/agents/specialists/automation-specialist.agent.d.ts +0 -44
  51. package/dist/agents/specialists/automation-specialist.agent.js +0 -204
  52. package/dist/agents/specialists/data-specialist.agent.d.ts +0 -165
  53. package/dist/agents/specialists/data-specialist.agent.js +0 -484
  54. package/dist/agents/specialists/integration-specialist.agent.d.ts +0 -227
  55. package/dist/agents/specialists/integration-specialist.agent.js +0 -725
  56. package/dist/agents/specialists/reporting-specialist.agent.d.ts +0 -54
  57. package/dist/agents/specialists/reporting-specialist.agent.js +0 -193
  58. package/dist/agents/specialists/security-specialist.agent.d.ts +0 -85
  59. package/dist/agents/specialists/security-specialist.agent.js +0 -309
  60. package/dist/agents/teams/adaptive/adaptive-coordinator.agent.d.ts +0 -111
  61. package/dist/agents/teams/adaptive/adaptive-coordinator.agent.js +0 -383
  62. package/dist/agents/teams/base-team.d.ts +0 -72
  63. package/dist/agents/teams/base-team.js +0 -253
  64. package/dist/agents/teams/team-types.d.ts +0 -265
  65. package/dist/agents/teams/team-types.js +0 -3
  66. package/dist/agents/teams/widget/widget-architect.agent.d.ts +0 -61
  67. package/dist/agents/teams/widget/widget-architect.agent.js +0 -436
  68. package/dist/agents/teams/widget/widget-backend.agent.d.ts +0 -74
  69. package/dist/agents/teams/widget/widget-backend.agent.js +0 -1531
  70. package/dist/agents/teams/widget/widget-frontend.agent.d.ts +0 -67
  71. package/dist/agents/teams/widget/widget-frontend.agent.js +0 -1014
  72. package/dist/agents/teams/widget/widget-platform.agent.d.ts +0 -90
  73. package/dist/agents/teams/widget/widget-platform.agent.js +0 -1190
  74. package/dist/agents/teams/widget/widget-uiux.agent.d.ts +0 -107
  75. package/dist/agents/teams/widget/widget-uiux.agent.js +0 -1033
  76. package/dist/agents/test-agent.d.ts +0 -26
  77. package/dist/agents/test-agent.js +0 -734
  78. package/dist/agents/test-agents.d.ts +0 -7
  79. package/dist/agents/test-agents.js +0 -64
  80. package/dist/agents/ui-builder.agent.d.ts +0 -50
  81. package/dist/agents/ui-builder.agent.js +0 -1539
  82. package/dist/agents/widget-builder.agent.d.ts +0 -32
  83. package/dist/agents/widget-builder.agent.js +0 -439
  84. package/dist/agents/widget-creator-agent.d.ts +0 -18
  85. package/dist/agents/widget-creator-agent.js +0 -498
  86. package/dist/agents/workflow-designer.agent.d.ts +0 -31
  87. package/dist/agents/workflow-designer.agent.js +0 -583
  88. package/dist/api/error-handling.d.ts +0 -325
  89. package/dist/api/error-handling.js +0 -1488
  90. package/dist/api/flow-designer-api.d.ts +0 -167
  91. package/dist/api/flow-designer-api.js +0 -554
  92. package/dist/api/natural-language-mapper.d.ts +0 -124
  93. package/dist/api/natural-language-mapper.js +0 -501
  94. package/dist/api/performance-optimizer.d.ts +0 -240
  95. package/dist/api/performance-optimizer.js +0 -706
  96. package/dist/api/transaction-manager.d.ts +0 -189
  97. package/dist/api/transaction-manager.js +0 -576
  98. package/dist/assembly/team-assembler.d.ts +0 -140
  99. package/dist/assembly/team-assembler.js +0 -502
  100. package/dist/benchmark-performance.d.ts +0 -41
  101. package/dist/benchmark-performance.js +0 -230
  102. package/dist/cli/snow-flow-cli-integration.d.ts +0 -30
  103. package/dist/cli/snow-flow-cli-integration.js +0 -396
  104. package/dist/coordination/coordination-engine.d.ts +0 -41
  105. package/dist/coordination/coordination-engine.js +0 -324
  106. package/dist/coordination/coordination.test.d.ts +0 -6
  107. package/dist/coordination/example.d.ts +0 -31
  108. package/dist/coordination/example.js +0 -394
  109. package/dist/coordination/execution-patterns.d.ts +0 -43
  110. package/dist/coordination/execution-patterns.js +0 -507
  111. package/dist/coordination/factory.d.ts +0 -94
  112. package/dist/coordination/factory.js +0 -433
  113. package/dist/coordination/index.d.ts +0 -71
  114. package/dist/coordination/index.js +0 -135
  115. package/dist/coordination/progress-monitor.d.ts +0 -71
  116. package/dist/coordination/progress-monitor.js +0 -505
  117. package/dist/coordination/quality-gates.d.ts +0 -124
  118. package/dist/coordination/quality-gates.js +0 -577
  119. package/dist/coordination/shared-memory.d.ts +0 -39
  120. package/dist/coordination/shared-memory.js +0 -289
  121. package/dist/coordination/task-dependencies.d.ts +0 -50
  122. package/dist/coordination/task-dependencies.js +0 -407
  123. package/dist/coordination/team-coordinator.d.ts +0 -59
  124. package/dist/coordination/team-coordinator.js +0 -550
  125. package/dist/coordination/types.d.ts +0 -152
  126. package/dist/coordination/types.js +0 -3
  127. package/dist/mcp/mcp-wrapper.d.ts +0 -8
  128. package/dist/mcp/mcp-wrapper.js +0 -77
  129. package/dist/mcp/servicenow-flow-composer-enhanced.js +0 -396
  130. package/dist/mcp/servicenow-flow-composer-mcp.d.ts +0 -7
  131. package/dist/mcp/servicenow-flow-composer-mcp.js +0 -3103
  132. package/dist/mcp/servicenow-graph-memory-mcp.d.ts +0 -7
  133. package/dist/mcp/servicenow-intelligent-mcp.d.ts +0 -143
  134. package/dist/mcp/servicenow-intelligent-mcp.js +0 -4156
  135. package/dist/mcp/servicenow-xml-flow-mcp.d.ts +0 -53
  136. package/dist/mcp/servicenow-xml-flow-mcp.js +0 -1704
  137. package/dist/mcp/singleton-check.js +0 -31
  138. package/dist/mcp/test-simple-mcp.d.ts +0 -6
  139. package/dist/mcp/test-simple-mcp.js +0 -63
  140. package/dist/memory/hierarchical-memory-system.d.ts +0 -90
  141. package/dist/memory/hierarchical-memory-system.js +0 -400
  142. package/dist/memory/index.d.ts +0 -9
  143. package/dist/memory/index.js +0 -20
  144. package/dist/memory/mcp-integration-example.d.ts +0 -6
  145. package/dist/memory/mcp-integration-example.js +0 -281
  146. package/dist/memory/memory-client.d.ts +0 -199
  147. package/dist/memory/memory-client.js +0 -364
  148. package/dist/memory/memory-manager.d.ts +0 -29
  149. package/dist/memory/memory-manager.js +0 -280
  150. package/dist/memory/memory-operations.d.ts +0 -179
  151. package/dist/memory/memory-operations.js +0 -691
  152. package/dist/memory/memory-system.d.ts +0 -153
  153. package/dist/memory/memory-system.js +0 -651
  154. package/dist/memory/memory-test.d.ts +0 -6
  155. package/dist/memory/memory-test.js +0 -161
  156. package/dist/memory/snow-flow-memory-patterns.d.ts +0 -213
  157. package/dist/memory/snow-flow-memory-patterns.js +0 -200
  158. package/dist/memory/snow-memory.d.ts +0 -54
  159. package/dist/memory/snow-memory.js +0 -301
  160. package/dist/memory/swarm-memory.d.ts +0 -135
  161. package/dist/memory/swarm-memory.js +0 -378
  162. package/dist/optimization/flow-performance-optimizer.js +0 -723
  163. package/dist/orchestration/discovery/service-discovery.d.ts +0 -81
  164. package/dist/orchestration/discovery/service-discovery.js +0 -808
  165. package/dist/orchestration/distributed-orchestrator.d.ts +0 -131
  166. package/dist/orchestration/distributed-orchestrator.js +0 -712
  167. package/dist/orchestration/distribution/task-distribution-engine.d.ts +0 -53
  168. package/dist/orchestration/distribution/task-distribution-engine.js +0 -586
  169. package/dist/orchestration/flow-update-orchestrator.js +0 -648
  170. package/dist/orchestration/interfaces/distributed-orchestration.interface.d.ts +0 -606
  171. package/dist/orchestration/interfaces/distributed-orchestration.interface.js +0 -65
  172. package/dist/orchestration/protocols/mcpx-protocol.d.ts +0 -71
  173. package/dist/orchestration/protocols/mcpx-protocol.js +0 -668
  174. package/dist/orchestration/state/distributed-state-manager.d.ts +0 -89
  175. package/dist/orchestration/state/distributed-state-manager.js +0 -716
  176. package/dist/orchestrator/flow-composer.d.ts +0 -105
  177. package/dist/orchestrator/flow-composer.js +0 -404
  178. package/dist/orchestrator/flow-pattern-templates.d.ts +0 -260
  179. package/dist/orchestrator/flow-pattern-templates.js +0 -908
  180. package/dist/orchestrator/flow-subflow-decision-engine.d.ts +0 -202
  181. package/dist/orchestrator/flow-subflow-decision-engine.js +0 -769
  182. package/dist/orchestrator/flow-validation-engine.d.ts +0 -169
  183. package/dist/orchestrator/flow-validation-engine.js +0 -913
  184. package/dist/orchestrator/snow-orchestrator.d.ts +0 -49
  185. package/dist/orchestrator/snow-orchestrator.js +0 -235
  186. package/dist/orchestrator/subflow-creation-handler.d.ts +0 -230
  187. package/dist/orchestrator/subflow-creation-handler.js +0 -791
  188. package/dist/patterns/adaptive-patterns.d.ts +0 -140
  189. package/dist/patterns/adaptive-patterns.js +0 -549
  190. package/dist/queen/advanced-integration-test.d.ts +0 -48
  191. package/dist/queen/advanced-integration-test.js +0 -473
  192. package/dist/queen/integration-example.d.ts +0 -82
  193. package/dist/queen/integration-example.js +0 -219
  194. package/dist/queen/integration-test.d.ts +0 -72
  195. package/dist/queen/integration-test.js +0 -563
  196. package/dist/queen/mock-mcp-client.d.ts +0 -71
  197. package/dist/queen/mock-mcp-client.js +0 -317
  198. package/dist/queen/run-integration-tests.d.ts +0 -9
  199. package/dist/queen/run-integration-tests.js +0 -27
  200. package/dist/sparc/coordinators/adaptive-coordinator.d.ts +0 -54
  201. package/dist/sparc/coordinators/adaptive-coordinator.js +0 -367
  202. package/dist/sparc/coordinators/team-coordinator.d.ts +0 -66
  203. package/dist/sparc/coordinators/team-coordinator.js +0 -402
  204. package/dist/sparc/modes/team-modes.d.ts +0 -33
  205. package/dist/sparc/modes/team-modes.js +0 -399
  206. package/dist/sparc/teams/application-team.d.ts +0 -73
  207. package/dist/sparc/teams/application-team.js +0 -463
  208. package/dist/sparc/teams/flow-team.d.ts +0 -67
  209. package/dist/sparc/teams/flow-team.js +0 -373
  210. package/dist/sparc/teams/widget-team.d.ts +0 -61
  211. package/dist/sparc/teams/widget-team.js +0 -280
  212. package/dist/specialists/app-specialists.d.ts +0 -93
  213. package/dist/specialists/app-specialists.js +0 -1639
  214. package/dist/specialists/base-specialist.d.ts +0 -19
  215. package/dist/specialists/base-specialist.js +0 -54
  216. package/dist/specialists/flow-specialists.d.ts +0 -113
  217. package/dist/specialists/flow-specialists.js +0 -1787
  218. package/dist/specialists/individual-specialists.d.ts +0 -67
  219. package/dist/specialists/individual-specialists.js +0 -632
  220. package/dist/specialists/widget-specialists.d.ts +0 -70
  221. package/dist/specialists/widget-specialists.js +0 -1264
  222. package/dist/src/utils/agent-detector.js +0 -655
  223. package/dist/teams/adaptive-team.d.ts +0 -81
  224. package/dist/teams/adaptive-team.js +0 -1153
  225. package/dist/teams/application-team.d.ts +0 -30
  226. package/dist/teams/application-team.js +0 -547
  227. package/dist/teams/base-team.d.ts +0 -55
  228. package/dist/teams/base-team.js +0 -243
  229. package/dist/teams/flow-team.d.ts +0 -28
  230. package/dist/teams/flow-team.js +0 -525
  231. package/dist/teams/widget-team.d.ts +0 -26
  232. package/dist/teams/widget-team.js +0 -459
  233. package/dist/templates/flow-template-system.js +0 -625
  234. package/dist/test-fetch-incidents.d.ts +0 -2
  235. package/dist/test-fetch-incidents.js +0 -84
  236. package/dist/test-incident-access.d.ts +0 -2
  237. package/dist/test-incident-access.js +0 -72
  238. package/dist/test-iphone-flow.js +0 -189
  239. package/dist/test-limit-problem.d.ts +0 -2
  240. package/dist/test-limit-problem.js +0 -60
  241. package/dist/test-ml-batch-fix.d.ts +0 -2
  242. package/dist/test-ml-batch-fix.js +0 -104
  243. package/dist/test-ml-batch.d.ts +0 -2
  244. package/dist/test-ml-batch.js +0 -87
  245. package/dist/test-ml-query.d.ts +0 -2
  246. package/dist/test-ml-query.js +0 -100
  247. package/dist/test-ml-training-fix.d.ts +0 -12
  248. package/dist/test-ml-training-fix.js +0 -113
  249. package/dist/test-ml-training.d.ts +0 -2
  250. package/dist/test-ml-training.js +0 -32
  251. package/dist/test-operations-query.d.ts +0 -2
  252. package/dist/test-operations-query.js +0 -84
  253. package/dist/test-performance-query.d.ts +0 -2
  254. package/dist/test-performance-query.js +0 -52
  255. package/dist/test-singleton-protection.d.ts +0 -8
  256. package/dist/test-singleton-protection.js +0 -110
  257. package/dist/test-smart-limits.d.ts +0 -13
  258. package/dist/test-smart-limits.js +0 -100
  259. package/dist/test-snow-query-incidents.d.ts +0 -2
  260. package/dist/test-snow-query-incidents.js +0 -66
  261. package/dist/test-universal-query.d.ts +0 -2
  262. package/dist/test-universal-query.js +0 -106
  263. package/dist/testing/flow-testing-automation.js +0 -641
  264. package/dist/utils/complete-flow-xml-generator.js +0 -1285
  265. package/dist/utils/file-storage-fallback.d.ts +0 -62
  266. package/dist/utils/file-storage-fallback.js +0 -289
  267. package/dist/utils/flow-api-discovery.d.ts +0 -151
  268. package/dist/utils/flow-api-discovery.js +0 -439
  269. package/dist/utils/flow-examples.js +0 -720
  270. package/dist/utils/flow-structure-builder.js +0 -677
  271. package/dist/utils/flow-xml-generator.d.ts +0 -41
  272. package/dist/utils/flow-xml-generator.js +0 -258
  273. package/dist/utils/improved-flow-xml-generator.js +0 -820
  274. package/dist/utils/mcp-process-manager.backup.d.ts +0 -58
  275. package/dist/utils/mcp-process-manager.backup.js +0 -220
  276. package/dist/utils/mcp-singleton-enforcer.d.ts +0 -36
  277. package/dist/utils/mcp-singleton-enforcer.js +0 -201
  278. package/dist/utils/mcp-timeout-fix.d.ts +0 -53
  279. package/dist/utils/mcp-timeout-fix.js +0 -221
  280. package/dist/utils/migrate-claude-flow.d.ts +0 -22
  281. package/dist/utils/migrate-claude-flow.js +0 -120
  282. package/dist/utils/scope-utils.d.ts +0 -72
  283. package/dist/utils/scope-utils.js +0 -386
  284. package/dist/utils/snow-oauth-old.d.ts +0 -65
  285. package/dist/utils/snow-oauth-old.js +0 -345
  286. package/dist/utils/xml-first-flow-generator.js +0 -513
  287. package/memory/servicenow_artifacts/000d9224c895221055906c7518aa2d3d.json +0 -30
  288. package/memory/servicenow_artifacts/0196b66173303010e46b4a2214f6a7a2.json +0 -36
  289. package/memory/servicenow_artifacts/125e5d1d837e2a102a7ea130ceaad397.json +0 -30
  290. package/memory/servicenow_artifacts/7637c1f2b7112210a5e5911cde11a972.json +0 -30
  291. package/memory/servicenow_artifacts/default_documentation_tables_1754056582292.json +0 -55
  292. package/memory/servicenow_artifacts/default_documentation_tables_1754057477189.json +0 -55
  293. package/memory/update-set-sessions/01f82af583faea102a7ea130ceaad3d4.json +0 -9
  294. package/memory/update-set-sessions/27718fb983faea102a7ea130ceaad34b.json +0 -9
  295. package/memory/update-set-sessions/412e9bf6833e22502a7ea130ceaad30a.json +0 -8
  296. package/memory/update-set-sessions/66fc5a79837aea102a7ea130ceaad3ab.json +0 -9
  297. package/memory/update-set-sessions/71a30ff5837eea102a7ea130ceaad37f.json +0 -9
  298. package/memory/update-set-sessions/74fba27983faea102a7ea130ceaad3bd.json +0 -9
  299. package/memory/update-set-sessions/a0b147b5837eea102a7ea130ceaad344.json +0 -58
  300. package/memory/update-set-sessions/b13f5eb983baea102a7ea130ceaad33e.json +0 -9
  301. package/reports/swarm-auto-centralized-1752649029776.json +0 -13
  302. package/src/memory/README.md +0 -240
@@ -1,576 +0,0 @@
1
- "use strict";
2
- /**
3
- * Transaction Management for Multi-Step Flow Creation
4
- * Provides ACID-like properties for complex flow operations
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.TransactionManager = exports.TransactionExecutionState = void 0;
8
- const logger_js_1 = require("../utils/logger.js");
9
- var TransactionExecutionState;
10
- (function (TransactionExecutionState) {
11
- TransactionExecutionState["PENDING"] = "pending";
12
- TransactionExecutionState["RUNNING"] = "running";
13
- TransactionExecutionState["COMPLETED"] = "completed";
14
- TransactionExecutionState["FAILED"] = "failed";
15
- TransactionExecutionState["COMPENSATING"] = "compensating";
16
- TransactionExecutionState["COMPENSATED"] = "compensated";
17
- TransactionExecutionState["TIMEOUT"] = "timeout";
18
- })(TransactionExecutionState || (exports.TransactionExecutionState = TransactionExecutionState = {}));
19
- class TransactionManager {
20
- constructor(client, errorHandler) {
21
- this.activeTransactions = new Map();
22
- this.sagaLog = new Map();
23
- this.client = client;
24
- this.errorHandler = errorHandler;
25
- this.logger = new logger_js_1.Logger('TransactionManager');
26
- this.lockManager = new SimpleLockManager();
27
- }
28
- /**
29
- * Execute a transaction with ACID properties
30
- */
31
- async executeTransaction(definition) {
32
- const execution = {
33
- id: definition.id,
34
- definition,
35
- state: TransactionExecutionState.PENDING,
36
- start_time: new Date(),
37
- completed_steps: [],
38
- failed_steps: [],
39
- results: new Map(),
40
- errors: new Map(),
41
- compensations: [],
42
- locks: new Set()
43
- };
44
- this.activeTransactions.set(definition.id, execution);
45
- try {
46
- // Initialize saga log
47
- this.sagaLog.set(definition.id, []);
48
- // Start transaction
49
- await this.startTransaction(execution);
50
- // Execute steps
51
- const result = await this.executeSteps(execution);
52
- if (result.success) {
53
- await this.commitTransaction(execution);
54
- return {
55
- success: true,
56
- transaction_id: execution.id,
57
- results: execution.results
58
- };
59
- }
60
- else {
61
- await this.rollbackTransaction(execution);
62
- return {
63
- success: false,
64
- transaction_id: execution.id,
65
- errors: Array.from(execution.errors.values()),
66
- compensation_applied: true
67
- };
68
- }
69
- }
70
- catch (error) {
71
- this.logger.error('Transaction execution failed', { transactionId: definition.id, error });
72
- await this.rollbackTransaction(execution);
73
- return {
74
- success: false,
75
- transaction_id: execution.id,
76
- errors: [error instanceof Error ? error : new Error(String(error))],
77
- compensation_applied: true
78
- };
79
- }
80
- finally {
81
- this.activeTransactions.delete(definition.id);
82
- }
83
- }
84
- /**
85
- * Execute a saga pattern transaction
86
- */
87
- async executeSaga(definition) {
88
- const execution = {
89
- id: definition.id,
90
- definition,
91
- state: TransactionExecutionState.PENDING,
92
- start_time: new Date(),
93
- completed_steps: [],
94
- failed_steps: [],
95
- results: new Map(),
96
- errors: new Map(),
97
- compensations: [],
98
- locks: new Set()
99
- };
100
- this.activeTransactions.set(definition.id, execution);
101
- try {
102
- execution.state = TransactionExecutionState.RUNNING;
103
- // Execute steps with saga pattern
104
- for (const step of definition.steps) {
105
- try {
106
- const stepResult = await this.executeStep(execution, step);
107
- execution.results.set(step.id, stepResult);
108
- execution.completed_steps.push(step.id);
109
- // Log successful step for saga
110
- this.logSagaStep(execution.id, step, stepResult);
111
- }
112
- catch (error) {
113
- execution.errors.set(step.id, error instanceof Error ? error : new Error(String(error)));
114
- execution.failed_steps.push(step.id);
115
- // If step failed, compensate previous steps
116
- await this.compensateSteps(execution);
117
- return {
118
- success: false,
119
- transaction_id: execution.id,
120
- compensations_applied: execution.compensations
121
- };
122
- }
123
- }
124
- execution.state = TransactionExecutionState.COMPLETED;
125
- execution.end_time = new Date();
126
- return {
127
- success: true,
128
- transaction_id: execution.id,
129
- results: execution.results
130
- };
131
- }
132
- catch (error) {
133
- execution.state = TransactionExecutionState.FAILED;
134
- execution.end_time = new Date();
135
- await this.compensateSteps(execution);
136
- return {
137
- success: false,
138
- transaction_id: execution.id,
139
- compensations_applied: execution.compensations
140
- };
141
- }
142
- finally {
143
- this.activeTransactions.delete(definition.id);
144
- this.sagaLog.delete(definition.id);
145
- }
146
- }
147
- /**
148
- * Create a distributed transaction across multiple ServiceNow instances
149
- */
150
- async executeDistributedTransaction(definition, participants) {
151
- const transactionId = definition.id;
152
- const participantResults = new Map();
153
- const failedParticipants = [];
154
- try {
155
- // Phase 1: Prepare all participants
156
- const prepareResults = await Promise.allSettled(participants.map(participant => this.prepareParticipant(participant, definition)));
157
- // Check if all participants are prepared
158
- const allPrepared = prepareResults.every(result => result.status === 'fulfilled');
159
- if (!allPrepared) {
160
- // Abort transaction - some participants failed to prepare
161
- await this.abortDistributedTransaction(transactionId, participants);
162
- prepareResults.forEach((result, index) => {
163
- if (result.status === 'rejected') {
164
- failedParticipants.push(participants[index]);
165
- }
166
- });
167
- return {
168
- success: false,
169
- transaction_id: transactionId,
170
- failed_participants: failedParticipants
171
- };
172
- }
173
- // Phase 2: Commit all participants
174
- const commitResults = await Promise.allSettled(participants.map(participant => this.commitParticipant(participant, transactionId)));
175
- // Check if all participants committed successfully
176
- const allCommitted = commitResults.every(result => result.status === 'fulfilled');
177
- if (!allCommitted) {
178
- // Some participants failed to commit - this is a critical situation
179
- this.logger.error('Distributed transaction commit failed', {
180
- transactionId,
181
- failedParticipants: commitResults
182
- .map((result, index) => result.status === 'rejected' ? participants[index] : null)
183
- .filter(Boolean)
184
- });
185
- // Attempt to rollback successful commits
186
- await this.rollbackDistributedTransaction(transactionId, participants);
187
- }
188
- commitResults.forEach((result, index) => {
189
- if (result.status === 'fulfilled') {
190
- participantResults.set(participants[index], result.value);
191
- }
192
- else {
193
- failedParticipants.push(participants[index]);
194
- }
195
- });
196
- return {
197
- success: allCommitted,
198
- transaction_id: transactionId,
199
- participant_results: participantResults,
200
- failed_participants: failedParticipants.length > 0 ? failedParticipants : undefined
201
- };
202
- }
203
- catch (error) {
204
- this.logger.error('Distributed transaction failed', { transactionId, error });
205
- await this.abortDistributedTransaction(transactionId, participants);
206
- return {
207
- success: false,
208
- transaction_id: transactionId,
209
- failed_participants: participants
210
- };
211
- }
212
- }
213
- /**
214
- * Start transaction with isolation
215
- */
216
- async startTransaction(execution) {
217
- execution.state = TransactionExecutionState.RUNNING;
218
- this.logger.info('Starting transaction', { transactionId: execution.id });
219
- // Acquire locks based on isolation level
220
- await this.acquireLocks(execution);
221
- // Start ServiceNow transaction tracking
222
- const transactionId = this.errorHandler.startTransaction(execution.definition.name);
223
- execution.id = transactionId;
224
- }
225
- /**
226
- * Execute all steps in the transaction
227
- */
228
- async executeSteps(execution) {
229
- const steps = this.orderStepsByDependencies(execution.definition.steps);
230
- for (const step of steps) {
231
- execution.current_step = step.id;
232
- try {
233
- // Check timeout
234
- if (this.isTransactionTimeout(execution)) {
235
- execution.state = TransactionExecutionState.TIMEOUT;
236
- throw new Error('Transaction timeout');
237
- }
238
- // Execute step with retry
239
- const result = await this.executeStepWithRetry(execution, step);
240
- execution.results.set(step.id, result);
241
- execution.completed_steps.push(step.id);
242
- // Add to rollback stack
243
- this.errorHandler.addOperation(execution.id, {
244
- type: step.operation,
245
- table: step.table,
246
- record_id: result?.sys_id,
247
- original_data: step.operation === 'update' ? step.data : undefined,
248
- new_data: result,
249
- dependencies: step.dependencies
250
- });
251
- }
252
- catch (error) {
253
- execution.errors.set(step.id, error instanceof Error ? error : new Error(String(error)));
254
- execution.failed_steps.push(step.id);
255
- if (step.critical || execution.definition.rollback_on_error) {
256
- return { success: false };
257
- }
258
- // Continue with non-critical steps
259
- this.logger.warn('Non-critical step failed, continuing', { stepId: step.id, error });
260
- }
261
- }
262
- return { success: execution.failed_steps.length === 0 };
263
- }
264
- /**
265
- * Execute a single step with retry logic
266
- */
267
- async executeStepWithRetry(execution, step) {
268
- const retryPolicy = execution.definition.retry_policy;
269
- let lastError = null;
270
- let delay = retryPolicy.initial_delay;
271
- for (let attempt = 1; attempt <= retryPolicy.max_attempts; attempt++) {
272
- try {
273
- return await this.executeStep(execution, step);
274
- }
275
- catch (error) {
276
- lastError = error instanceof Error ? error : new Error(String(error));
277
- // Check if error is retryable
278
- const isRetryable = retryPolicy.retryable_errors.some(retryableError => lastError.message.toLowerCase().includes(retryableError.toLowerCase()));
279
- if (!isRetryable || attempt === retryPolicy.max_attempts) {
280
- throw lastError;
281
- }
282
- // Wait before retry
283
- await new Promise(resolve => setTimeout(resolve, delay));
284
- delay = Math.min(delay * retryPolicy.backoff_multiplier, retryPolicy.max_delay);
285
- }
286
- }
287
- throw lastError;
288
- }
289
- /**
290
- * Execute a single step
291
- */
292
- async executeStep(execution, step) {
293
- this.logger.debug('Executing step', { transactionId: execution.id, stepId: step.id });
294
- // Check dependencies
295
- for (const dependency of step.dependencies) {
296
- if (!execution.completed_steps.includes(dependency)) {
297
- throw new Error(`Dependency ${dependency} not completed`);
298
- }
299
- }
300
- // Execute based on operation type
301
- switch (step.operation) {
302
- case 'create':
303
- return await this.client.createRecord(step.table, step.data);
304
- case 'update':
305
- if (!step.data?.sys_id) {
306
- throw new Error('sys_id required for update operation');
307
- }
308
- return await this.client.updateRecord(step.table, step.data.sys_id, step.data);
309
- case 'delete':
310
- if (!step.data?.sys_id) {
311
- throw new Error('sys_id required for delete operation');
312
- }
313
- return await this.client.deleteRecord(step.table, step.data.sys_id);
314
- case 'validate':
315
- return await this.validateData(step.table, step.data, step.condition);
316
- case 'custom':
317
- if (step.data?.custom_function) {
318
- return await step.data.custom_function();
319
- }
320
- throw new Error('Custom function not provided');
321
- default:
322
- throw new Error(`Unknown operation: ${step.operation}`);
323
- }
324
- }
325
- /**
326
- * Commit transaction
327
- */
328
- async commitTransaction(execution) {
329
- execution.state = TransactionExecutionState.COMPLETED;
330
- execution.end_time = new Date();
331
- // Commit ServiceNow transaction
332
- await this.errorHandler.commitTransaction(execution.id);
333
- // Release locks
334
- await this.releaseLocks(execution);
335
- this.logger.info('Transaction committed', { transactionId: execution.id });
336
- }
337
- /**
338
- * Rollback transaction
339
- */
340
- async rollbackTransaction(execution) {
341
- execution.state = TransactionExecutionState.COMPENSATING;
342
- try {
343
- // Rollback ServiceNow transaction
344
- await this.errorHandler.rollbackTransaction(execution.id);
345
- // Apply compensations
346
- await this.compensateSteps(execution);
347
- execution.state = TransactionExecutionState.COMPENSATED;
348
- }
349
- catch (error) {
350
- execution.state = TransactionExecutionState.FAILED;
351
- this.logger.error('Transaction rollback failed', { transactionId: execution.id, error });
352
- }
353
- finally {
354
- // Always release locks
355
- await this.releaseLocks(execution);
356
- execution.end_time = new Date();
357
- }
358
- }
359
- /**
360
- * Apply compensations for completed steps
361
- */
362
- async compensateSteps(execution) {
363
- const completedSteps = execution.definition.steps.filter(step => execution.completed_steps.includes(step.id));
364
- // Apply compensations in reverse order
365
- for (const step of completedSteps.reverse()) {
366
- if (step.compensation) {
367
- try {
368
- await this.applyCompensation(execution, step.compensation);
369
- execution.compensations.push(step.compensation);
370
- }
371
- catch (error) {
372
- this.logger.error('Compensation failed', { stepId: step.id, error });
373
- }
374
- }
375
- }
376
- }
377
- /**
378
- * Apply a compensation action
379
- */
380
- async applyCompensation(execution, compensation) {
381
- switch (compensation.type) {
382
- case 'delete':
383
- const result = execution.results.get(compensation.table);
384
- if (result?.sys_id) {
385
- await this.client.deleteRecord(compensation.table, result.sys_id);
386
- }
387
- break;
388
- case 'update':
389
- if (compensation.data?.sys_id) {
390
- await this.client.updateRecord(compensation.table, compensation.data.sys_id, compensation.data);
391
- }
392
- break;
393
- case 'restore':
394
- if (compensation.data) {
395
- await this.client.createRecord(compensation.table, compensation.data);
396
- }
397
- break;
398
- case 'custom':
399
- if (compensation.custom_function) {
400
- await compensation.custom_function();
401
- }
402
- break;
403
- }
404
- }
405
- /**
406
- * Acquire locks for transaction isolation
407
- */
408
- async acquireLocks(execution) {
409
- const resourcesToLock = new Set();
410
- // Collect resources to lock
411
- for (const step of execution.definition.steps) {
412
- if (step.operation === 'update' || step.operation === 'delete') {
413
- resourcesToLock.add(`${step.table}:${step.data?.sys_id}`);
414
- }
415
- else if (step.operation === 'create') {
416
- resourcesToLock.add(`${step.table}:create`);
417
- }
418
- }
419
- // Acquire locks
420
- for (const resource of resourcesToLock) {
421
- try {
422
- const lockId = await this.lockManager.acquire(resource, execution.definition.timeout);
423
- execution.locks.add(lockId);
424
- }
425
- catch (error) {
426
- // Release already acquired locks
427
- await this.releaseLocks(execution);
428
- throw new Error(`Failed to acquire lock for ${resource}: ${error}`);
429
- }
430
- }
431
- }
432
- /**
433
- * Release all locks
434
- */
435
- async releaseLocks(execution) {
436
- for (const lockId of execution.locks) {
437
- try {
438
- await this.lockManager.release(lockId);
439
- }
440
- catch (error) {
441
- this.logger.warn('Failed to release lock', { lockId, error });
442
- }
443
- }
444
- execution.locks.clear();
445
- }
446
- /**
447
- * Order steps by dependencies
448
- */
449
- orderStepsByDependencies(steps) {
450
- const ordered = [];
451
- const remaining = [...steps];
452
- while (remaining.length > 0) {
453
- const nextSteps = remaining.filter(step => step.dependencies.every(dep => ordered.some(orderedStep => orderedStep.id === dep)));
454
- if (nextSteps.length === 0) {
455
- throw new Error('Circular dependency detected in transaction steps');
456
- }
457
- ordered.push(...nextSteps);
458
- remaining.splice(0, remaining.length, ...remaining.filter(step => !nextSteps.includes(step)));
459
- }
460
- return ordered;
461
- }
462
- /**
463
- * Check if transaction has timed out
464
- */
465
- isTransactionTimeout(execution) {
466
- const elapsed = Date.now() - execution.start_time.getTime();
467
- return elapsed > execution.definition.timeout;
468
- }
469
- /**
470
- * Validate data against condition
471
- */
472
- async validateData(table, data, condition) {
473
- if (!condition)
474
- return true;
475
- // Simple validation logic - could be enhanced with more complex rules
476
- const record = await this.client.getRecord(table, data.sys_id);
477
- return record !== null;
478
- }
479
- /**
480
- * Log saga step
481
- */
482
- logSagaStep(transactionId, step, result) {
483
- const sagaLog = this.sagaLog.get(transactionId) || [];
484
- sagaLog.push({
485
- step_id: step.id,
486
- operation: step.operation,
487
- table: step.table,
488
- result: result,
489
- timestamp: new Date()
490
- });
491
- this.sagaLog.set(transactionId, sagaLog);
492
- }
493
- /**
494
- * Prepare participant for distributed transaction
495
- */
496
- async prepareParticipant(participant, definition) {
497
- // Implementation would send prepare request to participant
498
- // For now, return success
499
- return { prepared: true, participant };
500
- }
501
- /**
502
- * Commit participant in distributed transaction
503
- */
504
- async commitParticipant(participant, transactionId) {
505
- // Implementation would send commit request to participant
506
- return { committed: true, participant };
507
- }
508
- /**
509
- * Abort distributed transaction
510
- */
511
- async abortDistributedTransaction(transactionId, participants) {
512
- // Implementation would send abort request to all participants
513
- this.logger.info('Aborting distributed transaction', { transactionId, participants });
514
- }
515
- /**
516
- * Rollback distributed transaction
517
- */
518
- async rollbackDistributedTransaction(transactionId, participants) {
519
- // Implementation would send rollback request to all participants
520
- this.logger.info('Rolling back distributed transaction', { transactionId, participants });
521
- }
522
- /**
523
- * Get transaction status
524
- */
525
- getTransactionStatus(transactionId) {
526
- return this.activeTransactions.get(transactionId) || null;
527
- }
528
- /**
529
- * Get all active transactions
530
- */
531
- getActiveTransactions() {
532
- return Array.from(this.activeTransactions.values());
533
- }
534
- }
535
- exports.TransactionManager = TransactionManager;
536
- /**
537
- * Simple lock manager implementation
538
- */
539
- class SimpleLockManager {
540
- constructor() {
541
- this.locks = new Map();
542
- }
543
- async acquire(resource, timeout) {
544
- const lockId = `lock_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
545
- const startTime = Date.now();
546
- while (Date.now() - startTime < timeout) {
547
- if (!this.locks.has(resource)) {
548
- this.locks.set(resource, {
549
- lockId,
550
- owner: 'transaction_manager',
551
- timestamp: new Date()
552
- });
553
- return lockId;
554
- }
555
- // Wait before retry
556
- await new Promise(resolve => setTimeout(resolve, 100));
557
- }
558
- throw new Error(`Failed to acquire lock for ${resource}: timeout`);
559
- }
560
- async release(lockId) {
561
- for (const [resource, lock] of this.locks) {
562
- if (lock.lockId === lockId) {
563
- this.locks.delete(resource);
564
- return;
565
- }
566
- }
567
- }
568
- isLocked(resource) {
569
- return this.locks.has(resource);
570
- }
571
- getLockOwner(resource) {
572
- const lock = this.locks.get(resource);
573
- return lock ? lock.owner : null;
574
- }
575
- }
576
- //# sourceMappingURL=transaction-manager.js.map