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.
- package/claude-flow.bat +0 -0
- package/claude-flow.ps1 +0 -0
- package/dist/mcp/intelligent-reporting-mcp.d.ts +7 -0
- package/dist/mcp/intelligent-reporting-mcp.js +379 -0
- package/dist/mcp/servicenow-automation-mcp.js +0 -0
- package/dist/mcp/servicenow-deployment-mcp.js +0 -0
- package/dist/mcp/servicenow-integration-mcp.js +0 -0
- package/dist/mcp/servicenow-mcp-server.js +0 -0
- package/dist/mcp/servicenow-operations-mcp.js +0 -0
- package/dist/mcp/servicenow-platform-development-mcp.js +0 -0
- package/dist/mcp/servicenow-progressive-indexer.js +0 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp.js +280 -29
- package/dist/mcp/servicenow-security-compliance-mcp.js +0 -0
- package/dist/mcp/servicenow-update-set-mcp.js +0 -0
- package/dist/mcp/start-all-mcp-servers.js +0 -0
- package/dist/mcp/start-servicenow-mcp.js +0 -0
- package/dist/services/widget-deployment-service.d.ts +2 -1
- package/dist/services/widget-deployment-service.js +17 -16
- package/dist/utils/anti-mock-data-validator.d.ts +66 -0
- package/dist/utils/anti-mock-data-validator.js +316 -0
- package/dist/utils/servicenow-eventual-consistency.d.ts +120 -0
- package/dist/utils/servicenow-eventual-consistency.js +220 -0
- package/memory/agents/README.md +1 -1
- package/memory/claude-flow-data.json +1 -1
- package/memory/sessions/README.md +1 -1
- package/package.json +4 -3
- package/.mcp.json +0 -22
- package/claude-flow.config.json +0 -20
- package/dist/agents/app-creator.agent.d.ts +0 -55
- package/dist/agents/app-creator.agent.js +0 -1292
- package/dist/agents/base/base-snow-agent.d.ts +0 -75
- package/dist/agents/base/base-snow-agent.js +0 -169
- package/dist/agents/base-snow-agent.d.ts +0 -63
- package/dist/agents/base-snow-agent.js +0 -296
- package/dist/agents/coordinator.d.ts +0 -200
- package/dist/agents/coordinator.js +0 -777
- package/dist/agents/flow-builder-agent.d.ts +0 -18
- package/dist/agents/flow-builder-agent.js +0 -197
- package/dist/agents/queen-403-handler.d.ts +0 -47
- package/dist/agents/queen-403-handler.js +0 -175
- package/dist/agents/queen-agent-example.d.ts +0 -23
- package/dist/agents/queen-agent-example.js +0 -240
- package/dist/agents/queen-agent.test.d.ts +0 -6
- package/dist/agents/script-generator.agent.d.ts +0 -32
- package/dist/agents/script-generator.agent.js +0 -772
- package/dist/agents/script-writer-agent.d.ts +0 -22
- package/dist/agents/script-writer-agent.js +0 -695
- package/dist/agents/security-agent.d.ts +0 -23
- package/dist/agents/security-agent.js +0 -619
- package/dist/agents/specialists/automation-specialist.agent.d.ts +0 -44
- package/dist/agents/specialists/automation-specialist.agent.js +0 -204
- package/dist/agents/specialists/data-specialist.agent.d.ts +0 -165
- package/dist/agents/specialists/data-specialist.agent.js +0 -484
- package/dist/agents/specialists/integration-specialist.agent.d.ts +0 -227
- package/dist/agents/specialists/integration-specialist.agent.js +0 -725
- package/dist/agents/specialists/reporting-specialist.agent.d.ts +0 -54
- package/dist/agents/specialists/reporting-specialist.agent.js +0 -193
- package/dist/agents/specialists/security-specialist.agent.d.ts +0 -85
- package/dist/agents/specialists/security-specialist.agent.js +0 -309
- package/dist/agents/teams/adaptive/adaptive-coordinator.agent.d.ts +0 -111
- package/dist/agents/teams/adaptive/adaptive-coordinator.agent.js +0 -383
- package/dist/agents/teams/base-team.d.ts +0 -72
- package/dist/agents/teams/base-team.js +0 -253
- package/dist/agents/teams/team-types.d.ts +0 -265
- package/dist/agents/teams/team-types.js +0 -3
- package/dist/agents/teams/widget/widget-architect.agent.d.ts +0 -61
- package/dist/agents/teams/widget/widget-architect.agent.js +0 -436
- package/dist/agents/teams/widget/widget-backend.agent.d.ts +0 -74
- package/dist/agents/teams/widget/widget-backend.agent.js +0 -1531
- package/dist/agents/teams/widget/widget-frontend.agent.d.ts +0 -67
- package/dist/agents/teams/widget/widget-frontend.agent.js +0 -1014
- package/dist/agents/teams/widget/widget-platform.agent.d.ts +0 -90
- package/dist/agents/teams/widget/widget-platform.agent.js +0 -1190
- package/dist/agents/teams/widget/widget-uiux.agent.d.ts +0 -107
- package/dist/agents/teams/widget/widget-uiux.agent.js +0 -1033
- package/dist/agents/test-agent.d.ts +0 -26
- package/dist/agents/test-agent.js +0 -734
- package/dist/agents/test-agents.d.ts +0 -7
- package/dist/agents/test-agents.js +0 -64
- package/dist/agents/ui-builder.agent.d.ts +0 -50
- package/dist/agents/ui-builder.agent.js +0 -1539
- package/dist/agents/widget-builder.agent.d.ts +0 -32
- package/dist/agents/widget-builder.agent.js +0 -439
- package/dist/agents/widget-creator-agent.d.ts +0 -18
- package/dist/agents/widget-creator-agent.js +0 -498
- package/dist/agents/workflow-designer.agent.d.ts +0 -31
- package/dist/agents/workflow-designer.agent.js +0 -583
- package/dist/api/error-handling.d.ts +0 -325
- package/dist/api/error-handling.js +0 -1488
- package/dist/api/flow-designer-api.d.ts +0 -167
- package/dist/api/flow-designer-api.js +0 -554
- package/dist/api/natural-language-mapper.d.ts +0 -124
- package/dist/api/natural-language-mapper.js +0 -501
- package/dist/api/performance-optimizer.d.ts +0 -240
- package/dist/api/performance-optimizer.js +0 -706
- package/dist/api/transaction-manager.d.ts +0 -189
- package/dist/api/transaction-manager.js +0 -576
- package/dist/assembly/team-assembler.d.ts +0 -140
- package/dist/assembly/team-assembler.js +0 -502
- package/dist/benchmark-performance.d.ts +0 -41
- package/dist/benchmark-performance.js +0 -230
- package/dist/cli/snow-flow-cli-integration.d.ts +0 -30
- package/dist/cli/snow-flow-cli-integration.js +0 -396
- package/dist/coordination/coordination-engine.d.ts +0 -41
- package/dist/coordination/coordination-engine.js +0 -324
- package/dist/coordination/coordination.test.d.ts +0 -6
- package/dist/coordination/example.d.ts +0 -31
- package/dist/coordination/example.js +0 -394
- package/dist/coordination/execution-patterns.d.ts +0 -43
- package/dist/coordination/execution-patterns.js +0 -507
- package/dist/coordination/factory.d.ts +0 -94
- package/dist/coordination/factory.js +0 -433
- package/dist/coordination/index.d.ts +0 -71
- package/dist/coordination/index.js +0 -135
- package/dist/coordination/progress-monitor.d.ts +0 -71
- package/dist/coordination/progress-monitor.js +0 -505
- package/dist/coordination/quality-gates.d.ts +0 -124
- package/dist/coordination/quality-gates.js +0 -577
- package/dist/coordination/shared-memory.d.ts +0 -39
- package/dist/coordination/shared-memory.js +0 -289
- package/dist/coordination/task-dependencies.d.ts +0 -50
- package/dist/coordination/task-dependencies.js +0 -407
- package/dist/coordination/team-coordinator.d.ts +0 -59
- package/dist/coordination/team-coordinator.js +0 -550
- package/dist/coordination/types.d.ts +0 -152
- package/dist/coordination/types.js +0 -3
- package/dist/mcp/mcp-wrapper.d.ts +0 -8
- package/dist/mcp/mcp-wrapper.js +0 -77
- package/dist/mcp/servicenow-flow-composer-enhanced.js +0 -396
- package/dist/mcp/servicenow-flow-composer-mcp.d.ts +0 -7
- package/dist/mcp/servicenow-flow-composer-mcp.js +0 -3103
- package/dist/mcp/servicenow-graph-memory-mcp.d.ts +0 -7
- package/dist/mcp/servicenow-intelligent-mcp.d.ts +0 -143
- package/dist/mcp/servicenow-intelligent-mcp.js +0 -4156
- package/dist/mcp/servicenow-xml-flow-mcp.d.ts +0 -53
- package/dist/mcp/servicenow-xml-flow-mcp.js +0 -1704
- package/dist/mcp/singleton-check.js +0 -31
- package/dist/mcp/test-simple-mcp.d.ts +0 -6
- package/dist/mcp/test-simple-mcp.js +0 -63
- package/dist/memory/hierarchical-memory-system.d.ts +0 -90
- package/dist/memory/hierarchical-memory-system.js +0 -400
- package/dist/memory/index.d.ts +0 -9
- package/dist/memory/index.js +0 -20
- package/dist/memory/mcp-integration-example.d.ts +0 -6
- package/dist/memory/mcp-integration-example.js +0 -281
- package/dist/memory/memory-client.d.ts +0 -199
- package/dist/memory/memory-client.js +0 -364
- package/dist/memory/memory-manager.d.ts +0 -29
- package/dist/memory/memory-manager.js +0 -280
- package/dist/memory/memory-operations.d.ts +0 -179
- package/dist/memory/memory-operations.js +0 -691
- package/dist/memory/memory-system.d.ts +0 -153
- package/dist/memory/memory-system.js +0 -651
- package/dist/memory/memory-test.d.ts +0 -6
- package/dist/memory/memory-test.js +0 -161
- package/dist/memory/snow-flow-memory-patterns.d.ts +0 -213
- package/dist/memory/snow-flow-memory-patterns.js +0 -200
- package/dist/memory/snow-memory.d.ts +0 -54
- package/dist/memory/snow-memory.js +0 -301
- package/dist/memory/swarm-memory.d.ts +0 -135
- package/dist/memory/swarm-memory.js +0 -378
- package/dist/optimization/flow-performance-optimizer.js +0 -723
- package/dist/orchestration/discovery/service-discovery.d.ts +0 -81
- package/dist/orchestration/discovery/service-discovery.js +0 -808
- package/dist/orchestration/distributed-orchestrator.d.ts +0 -131
- package/dist/orchestration/distributed-orchestrator.js +0 -712
- package/dist/orchestration/distribution/task-distribution-engine.d.ts +0 -53
- package/dist/orchestration/distribution/task-distribution-engine.js +0 -586
- package/dist/orchestration/flow-update-orchestrator.js +0 -648
- package/dist/orchestration/interfaces/distributed-orchestration.interface.d.ts +0 -606
- package/dist/orchestration/interfaces/distributed-orchestration.interface.js +0 -65
- package/dist/orchestration/protocols/mcpx-protocol.d.ts +0 -71
- package/dist/orchestration/protocols/mcpx-protocol.js +0 -668
- package/dist/orchestration/state/distributed-state-manager.d.ts +0 -89
- package/dist/orchestration/state/distributed-state-manager.js +0 -716
- package/dist/orchestrator/flow-composer.d.ts +0 -105
- package/dist/orchestrator/flow-composer.js +0 -404
- package/dist/orchestrator/flow-pattern-templates.d.ts +0 -260
- package/dist/orchestrator/flow-pattern-templates.js +0 -908
- package/dist/orchestrator/flow-subflow-decision-engine.d.ts +0 -202
- package/dist/orchestrator/flow-subflow-decision-engine.js +0 -769
- package/dist/orchestrator/flow-validation-engine.d.ts +0 -169
- package/dist/orchestrator/flow-validation-engine.js +0 -913
- package/dist/orchestrator/snow-orchestrator.d.ts +0 -49
- package/dist/orchestrator/snow-orchestrator.js +0 -235
- package/dist/orchestrator/subflow-creation-handler.d.ts +0 -230
- package/dist/orchestrator/subflow-creation-handler.js +0 -791
- package/dist/patterns/adaptive-patterns.d.ts +0 -140
- package/dist/patterns/adaptive-patterns.js +0 -549
- package/dist/queen/advanced-integration-test.d.ts +0 -48
- package/dist/queen/advanced-integration-test.js +0 -473
- package/dist/queen/integration-example.d.ts +0 -82
- package/dist/queen/integration-example.js +0 -219
- package/dist/queen/integration-test.d.ts +0 -72
- package/dist/queen/integration-test.js +0 -563
- package/dist/queen/mock-mcp-client.d.ts +0 -71
- package/dist/queen/mock-mcp-client.js +0 -317
- package/dist/queen/run-integration-tests.d.ts +0 -9
- package/dist/queen/run-integration-tests.js +0 -27
- package/dist/sparc/coordinators/adaptive-coordinator.d.ts +0 -54
- package/dist/sparc/coordinators/adaptive-coordinator.js +0 -367
- package/dist/sparc/coordinators/team-coordinator.d.ts +0 -66
- package/dist/sparc/coordinators/team-coordinator.js +0 -402
- package/dist/sparc/modes/team-modes.d.ts +0 -33
- package/dist/sparc/modes/team-modes.js +0 -399
- package/dist/sparc/teams/application-team.d.ts +0 -73
- package/dist/sparc/teams/application-team.js +0 -463
- package/dist/sparc/teams/flow-team.d.ts +0 -67
- package/dist/sparc/teams/flow-team.js +0 -373
- package/dist/sparc/teams/widget-team.d.ts +0 -61
- package/dist/sparc/teams/widget-team.js +0 -280
- package/dist/specialists/app-specialists.d.ts +0 -93
- package/dist/specialists/app-specialists.js +0 -1639
- package/dist/specialists/base-specialist.d.ts +0 -19
- package/dist/specialists/base-specialist.js +0 -54
- package/dist/specialists/flow-specialists.d.ts +0 -113
- package/dist/specialists/flow-specialists.js +0 -1787
- package/dist/specialists/individual-specialists.d.ts +0 -67
- package/dist/specialists/individual-specialists.js +0 -632
- package/dist/specialists/widget-specialists.d.ts +0 -70
- package/dist/specialists/widget-specialists.js +0 -1264
- package/dist/src/utils/agent-detector.js +0 -655
- package/dist/teams/adaptive-team.d.ts +0 -81
- package/dist/teams/adaptive-team.js +0 -1153
- package/dist/teams/application-team.d.ts +0 -30
- package/dist/teams/application-team.js +0 -547
- package/dist/teams/base-team.d.ts +0 -55
- package/dist/teams/base-team.js +0 -243
- package/dist/teams/flow-team.d.ts +0 -28
- package/dist/teams/flow-team.js +0 -525
- package/dist/teams/widget-team.d.ts +0 -26
- package/dist/teams/widget-team.js +0 -459
- package/dist/templates/flow-template-system.js +0 -625
- package/dist/test-fetch-incidents.d.ts +0 -2
- package/dist/test-fetch-incidents.js +0 -84
- package/dist/test-incident-access.d.ts +0 -2
- package/dist/test-incident-access.js +0 -72
- package/dist/test-iphone-flow.js +0 -189
- package/dist/test-limit-problem.d.ts +0 -2
- package/dist/test-limit-problem.js +0 -60
- package/dist/test-ml-batch-fix.d.ts +0 -2
- package/dist/test-ml-batch-fix.js +0 -104
- package/dist/test-ml-batch.d.ts +0 -2
- package/dist/test-ml-batch.js +0 -87
- package/dist/test-ml-query.d.ts +0 -2
- package/dist/test-ml-query.js +0 -100
- package/dist/test-ml-training-fix.d.ts +0 -12
- package/dist/test-ml-training-fix.js +0 -113
- package/dist/test-ml-training.d.ts +0 -2
- package/dist/test-ml-training.js +0 -32
- package/dist/test-operations-query.d.ts +0 -2
- package/dist/test-operations-query.js +0 -84
- package/dist/test-performance-query.d.ts +0 -2
- package/dist/test-performance-query.js +0 -52
- package/dist/test-singleton-protection.d.ts +0 -8
- package/dist/test-singleton-protection.js +0 -110
- package/dist/test-smart-limits.d.ts +0 -13
- package/dist/test-smart-limits.js +0 -100
- package/dist/test-snow-query-incidents.d.ts +0 -2
- package/dist/test-snow-query-incidents.js +0 -66
- package/dist/test-universal-query.d.ts +0 -2
- package/dist/test-universal-query.js +0 -106
- package/dist/testing/flow-testing-automation.js +0 -641
- package/dist/utils/complete-flow-xml-generator.js +0 -1285
- package/dist/utils/file-storage-fallback.d.ts +0 -62
- package/dist/utils/file-storage-fallback.js +0 -289
- package/dist/utils/flow-api-discovery.d.ts +0 -151
- package/dist/utils/flow-api-discovery.js +0 -439
- package/dist/utils/flow-examples.js +0 -720
- package/dist/utils/flow-structure-builder.js +0 -677
- package/dist/utils/flow-xml-generator.d.ts +0 -41
- package/dist/utils/flow-xml-generator.js +0 -258
- package/dist/utils/improved-flow-xml-generator.js +0 -820
- package/dist/utils/mcp-process-manager.backup.d.ts +0 -58
- package/dist/utils/mcp-process-manager.backup.js +0 -220
- package/dist/utils/mcp-singleton-enforcer.d.ts +0 -36
- package/dist/utils/mcp-singleton-enforcer.js +0 -201
- package/dist/utils/mcp-timeout-fix.d.ts +0 -53
- package/dist/utils/mcp-timeout-fix.js +0 -221
- package/dist/utils/migrate-claude-flow.d.ts +0 -22
- package/dist/utils/migrate-claude-flow.js +0 -120
- package/dist/utils/scope-utils.d.ts +0 -72
- package/dist/utils/scope-utils.js +0 -386
- package/dist/utils/snow-oauth-old.d.ts +0 -65
- package/dist/utils/snow-oauth-old.js +0 -345
- package/dist/utils/xml-first-flow-generator.js +0 -513
- package/memory/servicenow_artifacts/000d9224c895221055906c7518aa2d3d.json +0 -30
- package/memory/servicenow_artifacts/0196b66173303010e46b4a2214f6a7a2.json +0 -36
- package/memory/servicenow_artifacts/125e5d1d837e2a102a7ea130ceaad397.json +0 -30
- package/memory/servicenow_artifacts/7637c1f2b7112210a5e5911cde11a972.json +0 -30
- package/memory/servicenow_artifacts/default_documentation_tables_1754056582292.json +0 -55
- package/memory/servicenow_artifacts/default_documentation_tables_1754057477189.json +0 -55
- package/memory/update-set-sessions/01f82af583faea102a7ea130ceaad3d4.json +0 -9
- package/memory/update-set-sessions/27718fb983faea102a7ea130ceaad34b.json +0 -9
- package/memory/update-set-sessions/412e9bf6833e22502a7ea130ceaad30a.json +0 -8
- package/memory/update-set-sessions/66fc5a79837aea102a7ea130ceaad3ab.json +0 -9
- package/memory/update-set-sessions/71a30ff5837eea102a7ea130ceaad37f.json +0 -9
- package/memory/update-set-sessions/74fba27983faea102a7ea130ceaad3bd.json +0 -9
- package/memory/update-set-sessions/a0b147b5837eea102a7ea130ceaad344.json +0 -58
- package/memory/update-set-sessions/b13f5eb983baea102a7ea130ceaad33e.json +0 -9
- package/reports/swarm-auto-centralized-1752649029776.json +0 -13
- package/src/memory/README.md +0 -240
|
@@ -1,625 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* 🚀 Flow Template System for Faster Development
|
|
4
|
-
*
|
|
5
|
-
* Revolutionary template system that generates perfect ServiceNow flows from
|
|
6
|
-
* predefined patterns, dramatically reducing development time and ensuring
|
|
7
|
-
* consistent, high-quality implementations.
|
|
8
|
-
*/
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.FlowTemplateSystem = void 0;
|
|
14
|
-
const logger_js_1 = require("../utils/logger.js");
|
|
15
|
-
const xml_first_flow_generator_js_1 = require("../utils/xml-first-flow-generator.js");
|
|
16
|
-
const servicenow_client_js_1 = require("../utils/servicenow-client.js");
|
|
17
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
class FlowTemplateSystem {
|
|
20
|
-
constructor(client) {
|
|
21
|
-
this.templates = new Map();
|
|
22
|
-
this.logger = new logger_js_1.Logger('FlowTemplateSystem');
|
|
23
|
-
this.xmlGenerator = new xml_first_flow_generator_js_1.XMLFirstFlowGenerator();
|
|
24
|
-
this.client = client || new servicenow_client_js_1.ServiceNowClient();
|
|
25
|
-
this.templatesPath = path_1.default.join(process.cwd(), 'src', 'templates', 'flows');
|
|
26
|
-
this.initializeTemplateSystem();
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Initialize template system with built-in templates
|
|
30
|
-
*/
|
|
31
|
-
async initializeTemplateSystem() {
|
|
32
|
-
try {
|
|
33
|
-
// Create templates directory if not exists
|
|
34
|
-
await promises_1.default.mkdir(this.templatesPath, { recursive: true });
|
|
35
|
-
// Load built-in templates
|
|
36
|
-
await this.loadBuiltInTemplates();
|
|
37
|
-
// Load custom templates from disk
|
|
38
|
-
await this.loadCustomTemplates();
|
|
39
|
-
this.logger.info('🚀 Flow Template System initialized', {
|
|
40
|
-
totalTemplates: this.templates.size,
|
|
41
|
-
categories: this.getTemplateCategories()
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
this.logger.error('❌ Failed to initialize template system:', error);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Get all available templates
|
|
50
|
-
*/
|
|
51
|
-
getTemplates() {
|
|
52
|
-
return Array.from(this.templates.values())
|
|
53
|
-
.sort((a, b) => b.metadata.usageCount - a.metadata.usageCount);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get templates by category
|
|
57
|
-
*/
|
|
58
|
-
getTemplatesByCategory(category) {
|
|
59
|
-
return this.getTemplates().filter(t => t.category === category);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Search templates by keywords
|
|
63
|
-
*/
|
|
64
|
-
searchTemplates(query) {
|
|
65
|
-
const lowerQuery = query.toLowerCase();
|
|
66
|
-
return this.getTemplates().filter(template => template.name.toLowerCase().includes(lowerQuery) ||
|
|
67
|
-
template.description.toLowerCase().includes(lowerQuery) ||
|
|
68
|
-
template.metadata.tags.some(tag => tag.toLowerCase().includes(lowerQuery)));
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get template by ID
|
|
72
|
-
*/
|
|
73
|
-
getTemplate(templateId) {
|
|
74
|
-
return this.templates.get(templateId) || null;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Generate flow from template
|
|
78
|
-
*/
|
|
79
|
-
async generateFlowFromTemplate(customization) {
|
|
80
|
-
const startTime = Date.now();
|
|
81
|
-
try {
|
|
82
|
-
this.logger.info('🎯 Generating flow from template', {
|
|
83
|
-
templateId: customization.templateId,
|
|
84
|
-
variables: Object.keys(customization.variables).length
|
|
85
|
-
});
|
|
86
|
-
// Get template
|
|
87
|
-
const template = this.getTemplate(customization.templateId);
|
|
88
|
-
if (!template) {
|
|
89
|
-
throw new Error(`Template not found: ${customization.templateId}`);
|
|
90
|
-
}
|
|
91
|
-
// Validate variables
|
|
92
|
-
const validationErrors = this.validateVariables(template, customization.variables);
|
|
93
|
-
if (validationErrors.length > 0) {
|
|
94
|
-
throw new Error(`Variable validation failed: ${validationErrors.join(', ')}`);
|
|
95
|
-
}
|
|
96
|
-
// Process template
|
|
97
|
-
const flowDefinition = await this.processTemplate(template, customization);
|
|
98
|
-
// Generate XML
|
|
99
|
-
const flowXML = this.xmlGenerator.generateCompleteFlowXML(flowDefinition);
|
|
100
|
-
// Deploy if client is available
|
|
101
|
-
let sys_id;
|
|
102
|
-
let url;
|
|
103
|
-
if (this.client) {
|
|
104
|
-
try {
|
|
105
|
-
const deployResult = await this.client.deployFlow(flowDefinition);
|
|
106
|
-
if (deployResult.success) {
|
|
107
|
-
sys_id = deployResult.sys_id;
|
|
108
|
-
url = deployResult.url;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (deployError) {
|
|
112
|
-
this.logger.warn('⚠️ Flow XML generated but deployment failed', deployError);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// Update template usage
|
|
116
|
-
template.metadata.usageCount++;
|
|
117
|
-
await this.saveTemplate(template);
|
|
118
|
-
const generationTime = Date.now() - startTime;
|
|
119
|
-
return {
|
|
120
|
-
success: true,
|
|
121
|
-
flowDefinition,
|
|
122
|
-
flowXML,
|
|
123
|
-
sys_id,
|
|
124
|
-
url,
|
|
125
|
-
metrics: {
|
|
126
|
-
generationTime,
|
|
127
|
-
templateUsed: template.name,
|
|
128
|
-
variablesCount: Object.keys(customization.variables).length,
|
|
129
|
-
activitiesCount: flowDefinition.activities.length
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
this.logger.error('❌ Flow generation failed', error);
|
|
135
|
-
return {
|
|
136
|
-
success: false,
|
|
137
|
-
error: error instanceof Error ? error.message : String(error),
|
|
138
|
-
metrics: {
|
|
139
|
-
generationTime: Date.now() - startTime,
|
|
140
|
-
templateUsed: customization.templateId,
|
|
141
|
-
variablesCount: Object.keys(customization.variables).length,
|
|
142
|
-
activitiesCount: 0
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Create custom template
|
|
149
|
-
*/
|
|
150
|
-
async createTemplate(template) {
|
|
151
|
-
const fullTemplate = {
|
|
152
|
-
...template,
|
|
153
|
-
metadata: {
|
|
154
|
-
version: '1.0.0',
|
|
155
|
-
author: 'Custom',
|
|
156
|
-
lastUpdated: new Date().toISOString(),
|
|
157
|
-
usageCount: 0,
|
|
158
|
-
successRate: 0,
|
|
159
|
-
tags: template.metadata?.tags || []
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
this.templates.set(template.id, fullTemplate);
|
|
163
|
-
await this.saveTemplate(fullTemplate);
|
|
164
|
-
this.logger.info('✅ Custom template created', { templateId: template.id });
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Preview template generation (without deployment)
|
|
168
|
-
*/
|
|
169
|
-
async previewTemplate(customization) {
|
|
170
|
-
const template = this.getTemplate(customization.templateId);
|
|
171
|
-
if (!template) {
|
|
172
|
-
throw new Error(`Template not found: ${customization.templateId}`);
|
|
173
|
-
}
|
|
174
|
-
const flowDefinition = await this.processTemplate(template, customization);
|
|
175
|
-
return {
|
|
176
|
-
flowDefinition,
|
|
177
|
-
estimatedComplexity: template.complexity,
|
|
178
|
-
requiredPermissions: this.calculateRequiredPermissions(flowDefinition),
|
|
179
|
-
warnings: this.analyzePotentialIssues(flowDefinition)
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Get template usage analytics
|
|
184
|
-
*/
|
|
185
|
-
getTemplateAnalytics() {
|
|
186
|
-
const templates = this.getTemplates();
|
|
187
|
-
const totalUsage = templates.reduce((sum, t) => sum + t.metadata.usageCount, 0);
|
|
188
|
-
const topTemplates = templates
|
|
189
|
-
.slice(0, 5)
|
|
190
|
-
.map(t => ({
|
|
191
|
-
id: t.id,
|
|
192
|
-
name: t.name,
|
|
193
|
-
usage: t.metadata.usageCount
|
|
194
|
-
}));
|
|
195
|
-
const categoriesUsage = templates.reduce((acc, t) => {
|
|
196
|
-
acc[t.category] = (acc[t.category] || 0) + t.metadata.usageCount;
|
|
197
|
-
return acc;
|
|
198
|
-
}, {});
|
|
199
|
-
return {
|
|
200
|
-
totalTemplates: templates.length,
|
|
201
|
-
totalUsage,
|
|
202
|
-
topTemplates,
|
|
203
|
-
categoriesUsage
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Private helper methods
|
|
208
|
-
*/
|
|
209
|
-
async loadBuiltInTemplates() {
|
|
210
|
-
// iPhone Approval Template
|
|
211
|
-
const iphoneApprovalTemplate = {
|
|
212
|
-
id: 'iphone_approval_flow',
|
|
213
|
-
name: 'iPhone Approval Flow',
|
|
214
|
-
description: 'Complete iPhone provisioning flow with manager approval and automated fulfillment',
|
|
215
|
-
category: 'approval',
|
|
216
|
-
complexity: 'moderate',
|
|
217
|
-
estimatedTime: '10-15 minutes',
|
|
218
|
-
prerequisites: ['iPhone catalog item', 'Manager approval group', 'Fulfillment team'],
|
|
219
|
-
variables: [
|
|
220
|
-
{
|
|
221
|
-
name: 'catalog_item',
|
|
222
|
-
displayName: 'iPhone Catalog Item',
|
|
223
|
-
type: 'table',
|
|
224
|
-
required: true,
|
|
225
|
-
description: 'ServiceNow catalog item for iPhone requests',
|
|
226
|
-
placeholder: 'sc_cat_item sys_id'
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
name: 'approval_group',
|
|
230
|
-
displayName: 'Manager Approval Group',
|
|
231
|
-
type: 'group',
|
|
232
|
-
required: true,
|
|
233
|
-
description: 'Group responsible for approving iPhone requests',
|
|
234
|
-
defaultValue: 'IT Managers'
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
name: 'fulfillment_group',
|
|
238
|
-
displayName: 'Fulfillment Team',
|
|
239
|
-
type: 'group',
|
|
240
|
-
required: true,
|
|
241
|
-
description: 'Team that handles iPhone provisioning',
|
|
242
|
-
defaultValue: 'IT Support'
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
name: 'notification_template',
|
|
246
|
-
displayName: 'Notification Template',
|
|
247
|
-
type: 'string',
|
|
248
|
-
required: false,
|
|
249
|
-
description: 'Custom notification template for updates',
|
|
250
|
-
defaultValue: 'Standard approval notification'
|
|
251
|
-
}
|
|
252
|
-
],
|
|
253
|
-
activities: [
|
|
254
|
-
{
|
|
255
|
-
id: 'initial_notification',
|
|
256
|
-
name: 'Send Initial Notification',
|
|
257
|
-
type: 'notification',
|
|
258
|
-
description: 'Notify requester that their request is being processed',
|
|
259
|
-
order: 1,
|
|
260
|
-
inputs: {
|
|
261
|
-
recipient: '${trigger.requested_for}',
|
|
262
|
-
subject: 'iPhone Request Received - ${trigger.number}',
|
|
263
|
-
message: 'Your iPhone request has been received and is being processed.'
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
id: 'manager_approval',
|
|
268
|
-
name: 'Manager Approval',
|
|
269
|
-
type: 'approval',
|
|
270
|
-
description: 'Get approval from manager for iPhone request',
|
|
271
|
-
order: 2,
|
|
272
|
-
inputs: {
|
|
273
|
-
approver: '${trigger.requested_for.manager}',
|
|
274
|
-
fallback_approver: '${approval_group}',
|
|
275
|
-
subject: 'iPhone Approval Required',
|
|
276
|
-
description: 'Please approve the iPhone request for ${trigger.requested_for.name}'
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
id: 'approved_check',
|
|
281
|
-
name: 'Check Approval Status',
|
|
282
|
-
type: 'condition',
|
|
283
|
-
description: 'Check if the request was approved',
|
|
284
|
-
order: 3,
|
|
285
|
-
condition: '${manager_approval.result} == "approved"',
|
|
286
|
-
inputs: {}
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
id: 'fulfillment_task',
|
|
290
|
-
name: 'Create Fulfillment Task',
|
|
291
|
-
type: 'create_record',
|
|
292
|
-
description: 'Create task for iPhone fulfillment team',
|
|
293
|
-
order: 4,
|
|
294
|
-
inputs: {
|
|
295
|
-
table: 'sc_task',
|
|
296
|
-
fields: {
|
|
297
|
-
short_description: 'Provision iPhone for ${trigger.requested_for.name}',
|
|
298
|
-
description: 'Request: ${trigger.number}\nUser: ${trigger.requested_for.name}\nApproved by: ${manager_approval.approver}',
|
|
299
|
-
assignment_group: '${fulfillment_group}',
|
|
300
|
-
priority: '3',
|
|
301
|
-
state: '1'
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
{
|
|
306
|
-
id: 'approval_notification',
|
|
307
|
-
name: 'Send Approval Notification',
|
|
308
|
-
type: 'notification',
|
|
309
|
-
description: 'Notify requester of approval and next steps',
|
|
310
|
-
order: 5,
|
|
311
|
-
inputs: {
|
|
312
|
-
recipient: '${trigger.requested_for}',
|
|
313
|
-
subject: 'iPhone Request Approved - ${trigger.number}',
|
|
314
|
-
message: 'Your iPhone request has been approved and assigned to the fulfillment team.'
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
id: 'rejection_notification',
|
|
319
|
-
name: 'Send Rejection Notification',
|
|
320
|
-
type: 'notification',
|
|
321
|
-
description: 'Notify requester of rejection',
|
|
322
|
-
order: 6,
|
|
323
|
-
condition: '${manager_approval.result} == "rejected"',
|
|
324
|
-
inputs: {
|
|
325
|
-
recipient: '${trigger.requested_for}',
|
|
326
|
-
subject: 'iPhone Request Declined - ${trigger.number}',
|
|
327
|
-
message: 'Your iPhone request has been declined. Please contact your manager for more information.'
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
],
|
|
331
|
-
metadata: {
|
|
332
|
-
version: '1.2.0',
|
|
333
|
-
author: 'Snow-Flow Templates',
|
|
334
|
-
lastUpdated: new Date().toISOString(),
|
|
335
|
-
usageCount: 0,
|
|
336
|
-
successRate: 95.5,
|
|
337
|
-
tags: ['approval', 'iphone', 'provisioning', 'catalog', 'popular']
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
// Incident Escalation Template
|
|
341
|
-
const incidentEscalationTemplate = {
|
|
342
|
-
id: 'incident_escalation_flow',
|
|
343
|
-
name: 'Incident Escalation Flow',
|
|
344
|
-
description: 'Automatic incident escalation based on priority and time thresholds',
|
|
345
|
-
category: 'utility',
|
|
346
|
-
complexity: 'simple',
|
|
347
|
-
estimatedTime: '5-8 minutes',
|
|
348
|
-
prerequisites: ['Incident table access', 'Escalation groups configured'],
|
|
349
|
-
variables: [
|
|
350
|
-
{
|
|
351
|
-
name: 'priority_threshold',
|
|
352
|
-
displayName: 'Priority Threshold',
|
|
353
|
-
type: 'choice',
|
|
354
|
-
required: true,
|
|
355
|
-
description: 'Minimum priority for escalation',
|
|
356
|
-
validation: {
|
|
357
|
-
options: ['1 - Critical', '2 - High', '3 - Moderate']
|
|
358
|
-
},
|
|
359
|
-
defaultValue: '2 - High'
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
name: 'escalation_time',
|
|
363
|
-
displayName: 'Escalation Time (minutes)',
|
|
364
|
-
type: 'number',
|
|
365
|
-
required: true,
|
|
366
|
-
description: 'Time before escalation in minutes',
|
|
367
|
-
defaultValue: 30,
|
|
368
|
-
validation: {
|
|
369
|
-
minLength: 1
|
|
370
|
-
}
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
name: 'escalation_group',
|
|
374
|
-
displayName: 'Escalation Group',
|
|
375
|
-
type: 'group',
|
|
376
|
-
required: true,
|
|
377
|
-
description: 'Group to escalate incidents to',
|
|
378
|
-
defaultValue: 'IT Management'
|
|
379
|
-
}
|
|
380
|
-
],
|
|
381
|
-
activities: [
|
|
382
|
-
{
|
|
383
|
-
id: 'check_priority',
|
|
384
|
-
name: 'Check Incident Priority',
|
|
385
|
-
type: 'condition',
|
|
386
|
-
description: 'Verify incident meets priority threshold',
|
|
387
|
-
order: 1,
|
|
388
|
-
condition: '${trigger.priority} <= ${priority_threshold}',
|
|
389
|
-
inputs: {}
|
|
390
|
-
},
|
|
391
|
-
{
|
|
392
|
-
id: 'wait_for_escalation',
|
|
393
|
-
name: 'Wait for Escalation Time',
|
|
394
|
-
type: 'script',
|
|
395
|
-
description: 'Wait for specified time before escalating',
|
|
396
|
-
order: 2,
|
|
397
|
-
inputs: {
|
|
398
|
-
script: 'gs.sleep(${escalation_time} * 60 * 1000);'
|
|
399
|
-
}
|
|
400
|
-
},
|
|
401
|
-
{
|
|
402
|
-
id: 'check_still_open',
|
|
403
|
-
name: 'Check if Still Open',
|
|
404
|
-
type: 'condition',
|
|
405
|
-
description: 'Verify incident is still open and unassigned',
|
|
406
|
-
order: 3,
|
|
407
|
-
condition: '${trigger.state} < 6 && ${trigger.assigned_to} == ""',
|
|
408
|
-
inputs: {}
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
id: 'escalate_incident',
|
|
412
|
-
name: 'Escalate Incident',
|
|
413
|
-
type: 'update_record',
|
|
414
|
-
description: 'Assign to escalation group and add escalation note',
|
|
415
|
-
order: 4,
|
|
416
|
-
inputs: {
|
|
417
|
-
table: 'incident',
|
|
418
|
-
sys_id: '${trigger.sys_id}',
|
|
419
|
-
fields: {
|
|
420
|
-
assignment_group: '${escalation_group}',
|
|
421
|
-
work_notes: 'Automatically escalated after ${escalation_time} minutes due to no assignment'
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
id: 'escalation_notification',
|
|
427
|
-
name: 'Send Escalation Notification',
|
|
428
|
-
type: 'notification',
|
|
429
|
-
description: 'Notify escalation group of new assignment',
|
|
430
|
-
order: 5,
|
|
431
|
-
inputs: {
|
|
432
|
-
recipient: '${escalation_group}',
|
|
433
|
-
subject: 'Incident Escalated - ${trigger.number}',
|
|
434
|
-
message: 'Incident ${trigger.number} has been escalated to your group after ${escalation_time} minutes.'
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
],
|
|
438
|
-
metadata: {
|
|
439
|
-
version: '1.1.0',
|
|
440
|
-
author: 'Snow-Flow Templates',
|
|
441
|
-
lastUpdated: new Date().toISOString(),
|
|
442
|
-
usageCount: 0,
|
|
443
|
-
successRate: 98.2,
|
|
444
|
-
tags: ['incident', 'escalation', 'automation', 'sla']
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
// Store templates
|
|
448
|
-
this.templates.set(iphoneApprovalTemplate.id, iphoneApprovalTemplate);
|
|
449
|
-
this.templates.set(incidentEscalationTemplate.id, incidentEscalationTemplate);
|
|
450
|
-
this.logger.info('✅ Built-in templates loaded', { count: 2 });
|
|
451
|
-
}
|
|
452
|
-
async loadCustomTemplates() {
|
|
453
|
-
try {
|
|
454
|
-
const files = await promises_1.default.readdir(this.templatesPath);
|
|
455
|
-
const jsonFiles = files.filter(f => f.endsWith('.json'));
|
|
456
|
-
for (const file of jsonFiles) {
|
|
457
|
-
try {
|
|
458
|
-
const filePath = path_1.default.join(this.templatesPath, file);
|
|
459
|
-
const content = await promises_1.default.readFile(filePath, 'utf-8');
|
|
460
|
-
const template = JSON.parse(content);
|
|
461
|
-
this.templates.set(template.id, template);
|
|
462
|
-
}
|
|
463
|
-
catch (error) {
|
|
464
|
-
this.logger.warn(`⚠️ Failed to load template ${file}:`, error);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
this.logger.info('✅ Custom templates loaded', { count: jsonFiles.length });
|
|
468
|
-
}
|
|
469
|
-
catch (error) {
|
|
470
|
-
// Templates directory doesn't exist yet - that's fine
|
|
471
|
-
this.logger.debug('Templates directory not found, creating...');
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
async saveTemplate(template) {
|
|
475
|
-
const filePath = path_1.default.join(this.templatesPath, `${template.id}.json`);
|
|
476
|
-
await promises_1.default.writeFile(filePath, JSON.stringify(template, null, 2));
|
|
477
|
-
}
|
|
478
|
-
validateVariables(template, variables) {
|
|
479
|
-
const errors = [];
|
|
480
|
-
for (const templateVar of template.variables) {
|
|
481
|
-
const value = variables[templateVar.name];
|
|
482
|
-
// Check required variables
|
|
483
|
-
if (templateVar.required && (value === undefined || value === null || value === '')) {
|
|
484
|
-
errors.push(`Required variable '${templateVar.name}' is missing`);
|
|
485
|
-
continue;
|
|
486
|
-
}
|
|
487
|
-
// Skip validation if variable is not provided and not required
|
|
488
|
-
if (value === undefined || value === null)
|
|
489
|
-
continue;
|
|
490
|
-
// Type validation
|
|
491
|
-
if (templateVar.type === 'number' && isNaN(Number(value))) {
|
|
492
|
-
errors.push(`Variable '${templateVar.name}' must be a number`);
|
|
493
|
-
}
|
|
494
|
-
if (templateVar.type === 'boolean' && typeof value !== 'boolean') {
|
|
495
|
-
errors.push(`Variable '${templateVar.name}' must be a boolean`);
|
|
496
|
-
}
|
|
497
|
-
// Validation rules
|
|
498
|
-
if (templateVar.validation) {
|
|
499
|
-
const val = templateVar.validation;
|
|
500
|
-
if (val.pattern && !new RegExp(val.pattern).test(String(value))) {
|
|
501
|
-
errors.push(`Variable '${templateVar.name}' does not match required pattern`);
|
|
502
|
-
}
|
|
503
|
-
if (val.minLength && String(value).length < val.minLength) {
|
|
504
|
-
errors.push(`Variable '${templateVar.name}' is too short (minimum ${val.minLength})`);
|
|
505
|
-
}
|
|
506
|
-
if (val.maxLength && String(value).length > val.maxLength) {
|
|
507
|
-
errors.push(`Variable '${templateVar.name}' is too long (maximum ${val.maxLength})`);
|
|
508
|
-
}
|
|
509
|
-
if (val.options && !val.options.includes(String(value))) {
|
|
510
|
-
errors.push(`Variable '${templateVar.name}' must be one of: ${val.options.join(', ')}`);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
return errors;
|
|
515
|
-
}
|
|
516
|
-
async processTemplate(template, customization) {
|
|
517
|
-
// Start with base flow definition
|
|
518
|
-
const flowDefinition = {
|
|
519
|
-
name: customization.customizations?.flowName || `${template.name} (Generated)`,
|
|
520
|
-
description: customization.customizations?.description || template.description,
|
|
521
|
-
trigger_type: 'record_created', // Default, will be customized based on template
|
|
522
|
-
activities: [],
|
|
523
|
-
run_as: 'user',
|
|
524
|
-
accessible_from: 'package_private'
|
|
525
|
-
};
|
|
526
|
-
// Process activities
|
|
527
|
-
let activities = template.activities.slice();
|
|
528
|
-
// Skip activities if specified
|
|
529
|
-
if (customization.customizations?.skipActivities) {
|
|
530
|
-
activities = activities.filter(a => !customization.customizations?.skipActivities.includes(a.id));
|
|
531
|
-
}
|
|
532
|
-
// Add additional activities if specified
|
|
533
|
-
if (customization.customizations?.additionalActivities) {
|
|
534
|
-
activities.push(...customization.customizations.additionalActivities);
|
|
535
|
-
}
|
|
536
|
-
// Sort by order
|
|
537
|
-
activities.sort((a, b) => a.order - b.order);
|
|
538
|
-
// Convert template activities to XML activities
|
|
539
|
-
flowDefinition.activities = activities.map(activity => {
|
|
540
|
-
// Apply modifications if specified
|
|
541
|
-
const modifications = customization.customizations?.modifyActivities?.[activity.id];
|
|
542
|
-
const finalActivity = modifications ? { ...activity, ...modifications } : activity;
|
|
543
|
-
// Process variable substitution in inputs
|
|
544
|
-
const processedInputs = this.processVariableSubstitution(finalActivity.inputs, customization.variables);
|
|
545
|
-
return {
|
|
546
|
-
name: finalActivity.name,
|
|
547
|
-
type: finalActivity.type,
|
|
548
|
-
inputs: processedInputs,
|
|
549
|
-
outputs: finalActivity.outputs,
|
|
550
|
-
condition: finalActivity.condition
|
|
551
|
-
};
|
|
552
|
-
});
|
|
553
|
-
return flowDefinition;
|
|
554
|
-
}
|
|
555
|
-
processVariableSubstitution(obj, variables) {
|
|
556
|
-
if (typeof obj === 'string') {
|
|
557
|
-
// Replace ${variable_name} patterns
|
|
558
|
-
return obj.replace(/\$\{([^}]+)\}/g, (match, varName) => {
|
|
559
|
-
return variables[varName] || match;
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
if (Array.isArray(obj)) {
|
|
563
|
-
return obj.map(item => this.processVariableSubstitution(item, variables));
|
|
564
|
-
}
|
|
565
|
-
if (typeof obj === 'object' && obj !== null) {
|
|
566
|
-
const result = {};
|
|
567
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
568
|
-
result[key] = this.processVariableSubstitution(value, variables);
|
|
569
|
-
}
|
|
570
|
-
return result;
|
|
571
|
-
}
|
|
572
|
-
return obj;
|
|
573
|
-
}
|
|
574
|
-
calculateRequiredPermissions(flowDefinition) {
|
|
575
|
-
const permissions = new Set();
|
|
576
|
-
// Base permissions
|
|
577
|
-
permissions.add('flow_designer');
|
|
578
|
-
// Check activities for required permissions
|
|
579
|
-
for (const activity of flowDefinition.activities) {
|
|
580
|
-
switch (activity.type) {
|
|
581
|
-
case 'create_record':
|
|
582
|
-
case 'update_record':
|
|
583
|
-
permissions.add(`${activity.inputs.table}_admin`);
|
|
584
|
-
break;
|
|
585
|
-
case 'approval':
|
|
586
|
-
permissions.add('approval_admin');
|
|
587
|
-
break;
|
|
588
|
-
case 'notification':
|
|
589
|
-
permissions.add('notification_admin');
|
|
590
|
-
break;
|
|
591
|
-
case 'script':
|
|
592
|
-
permissions.add('script_execution');
|
|
593
|
-
break;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
return Array.from(permissions);
|
|
597
|
-
}
|
|
598
|
-
analyzePotentialIssues(flowDefinition) {
|
|
599
|
-
const warnings = [];
|
|
600
|
-
// Check for complex flows
|
|
601
|
-
if (flowDefinition.activities.length > 10) {
|
|
602
|
-
warnings.push('Flow has many activities - consider breaking into sub-flows');
|
|
603
|
-
}
|
|
604
|
-
// Check for missing error handling
|
|
605
|
-
const hasErrorHandling = flowDefinition.activities.some(a => a.name.toLowerCase().includes('error') || a.name.toLowerCase().includes('exception'));
|
|
606
|
-
if (!hasErrorHandling) {
|
|
607
|
-
warnings.push('No error handling activities detected - consider adding try/catch logic');
|
|
608
|
-
}
|
|
609
|
-
// Check for performance issues
|
|
610
|
-
const hasLoops = flowDefinition.activities.some(a => a.condition?.includes('while') || a.type === 'script');
|
|
611
|
-
if (hasLoops) {
|
|
612
|
-
warnings.push('Potential loops detected - ensure proper exit conditions');
|
|
613
|
-
}
|
|
614
|
-
return warnings;
|
|
615
|
-
}
|
|
616
|
-
getTemplateCategories() {
|
|
617
|
-
const categories = new Set();
|
|
618
|
-
for (const template of this.templates.values()) {
|
|
619
|
-
categories.add(template.category);
|
|
620
|
-
}
|
|
621
|
-
return Array.from(categories);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
exports.FlowTemplateSystem = FlowTemplateSystem;
|
|
625
|
-
exports.default = FlowTemplateSystem;
|