@tamyla/clodo-framework 3.1.21 → 3.1.22
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/CHANGELOG.md +9 -0
- package/README.md +53 -0
- package/dist/bin/clodo-service.js +47 -15
- package/dist/bin/commands/deploy.js +115 -83
- package/dist/bin/commands/helpers/deployment-ui.js +138 -0
- package/dist/bin/commands/helpers/deployment-verification.js +251 -0
- package/dist/bin/commands/helpers/error-recovery.js +80 -0
- package/dist/bin/commands/helpers/resource-detection.js +113 -0
- package/dist/bin/commands/validate.js +1 -1
- package/dist/bin/security/security-cli.js +1 -1
- package/dist/bin/shared/cache/configuration-cache.js +82 -0
- package/dist/bin/shared/cloudflare/domain-manager.js +1 -1
- package/dist/bin/shared/cloudflare/index.js +1 -1
- package/dist/bin/shared/cloudflare/ops.js +6 -4
- package/dist/bin/shared/config/ConfigurationManager.js +23 -1
- package/dist/bin/shared/config/command-config-manager.js +19 -3
- package/dist/bin/shared/config/index.js +1 -1
- package/dist/bin/shared/deployment/credential-collector.js +30 -7
- package/dist/bin/shared/deployment/index.js +2 -2
- package/dist/bin/shared/deployment/rollback-manager.js +4 -520
- package/dist/bin/shared/deployment/utilities/d1-error-recovery.js +177 -0
- package/dist/bin/shared/deployment/validator.js +40 -10
- package/dist/bin/shared/deployment/workflows/deployment-summary.js +214 -0
- package/dist/bin/shared/deployment/workflows/interactive-confirmation.js +188 -0
- package/dist/bin/shared/deployment/workflows/interactive-database-workflow.js +234 -0
- package/dist/bin/shared/deployment/workflows/interactive-domain-info-gatherer.js +240 -0
- package/dist/bin/shared/deployment/workflows/interactive-secret-workflow.js +228 -0
- package/dist/bin/shared/deployment/workflows/interactive-testing-workflow.js +235 -0
- package/dist/bin/shared/deployment/workflows/interactive-validation.js +218 -0
- package/dist/bin/shared/error-handling/error-classifier.js +46 -0
- package/dist/bin/shared/monitoring/health-checker.js +129 -1
- package/dist/bin/shared/monitoring/memory-manager.js +17 -6
- package/dist/bin/shared/routing/domain-router.js +1 -1
- package/dist/bin/shared/utils/deployment-validator.js +97 -0
- package/dist/bin/shared/utils/formatters.js +10 -0
- package/dist/bin/shared/utils/index.js +13 -1
- package/dist/bin/shared/utils/interactive-prompts.js +34 -18
- package/dist/bin/shared/utils/progress-manager.js +2 -2
- package/dist/bin/shared/utils/progress-spinner.js +53 -0
- package/dist/bin/shared/utils/sensitive-redactor.js +91 -0
- package/dist/bin/shared/validation/ValidationRegistry.js +1 -1
- package/dist/security/index.js +1 -1
- package/dist/security/patterns/insecure-patterns.js +1 -1
- package/dist/utils/constants.js +102 -0
- package/dist/utils/deployment/wrangler-config-manager.js +215 -48
- package/dist/utils/framework-config.js +2 -2
- package/dist/utils/interactive-prompts.js +10 -59
- package/package.json +16 -8
- package/dist/bin/clodo-service-old.js +0 -868
- package/dist/bin/clodo-service-test.js +0 -10
- package/dist/bin/commands/assess.js +0 -91
- package/dist/bin/commands/create.js +0 -77
- package/dist/bin/commands/diagnose.js +0 -83
- package/dist/bin/commands/helpers.js +0 -138
- package/dist/bin/commands/update.js +0 -75
- package/dist/bin/database/deployment-db-manager.js +0 -423
- package/dist/bin/database/enterprise-db-manager.js +0 -457
- package/dist/bin/database/wrangler-d1-manager.js +0 -685
- package/dist/bin/deployment/enterprise-deploy.js +0 -877
- package/dist/bin/deployment/master-deploy.js +0 -1376
- package/dist/bin/deployment/modular-enterprise-deploy.js +0 -466
- package/dist/bin/deployment/modules/DeploymentConfiguration.js +0 -395
- package/dist/bin/deployment/modules/DeploymentOrchestrator.js +0 -492
- package/dist/bin/deployment/modules/EnvironmentManager.js +0 -517
- package/dist/bin/deployment/modules/MonitoringIntegration.js +0 -560
- package/dist/bin/deployment/modules/ValidationManager.js +0 -342
- package/dist/bin/deployment/orchestration/BaseDeploymentOrchestrator.js +0 -426
- package/dist/bin/deployment/orchestration/EnterpriseOrchestrator.js +0 -401
- package/dist/bin/deployment/orchestration/PortfolioOrchestrator.js +0 -273
- package/dist/bin/deployment/orchestration/SingleServiceOrchestrator.js +0 -231
- package/dist/bin/deployment/orchestration/UnifiedDeploymentOrchestrator.js +0 -662
- package/dist/bin/deployment/test-interactive-utils.js +0 -66
- package/dist/bin/portfolio/portfolio-manager.js +0 -487
- package/dist/bin/service-management/create-service.js +0 -122
- package/dist/bin/service-management/init-service.js +0 -79
- package/dist/config/customers.js +0 -623
- package/dist/config/domains.js +0 -186
- package/dist/config/index.js +0 -6
- package/dist/database/database-orchestrator.js +0 -795
- package/dist/database/index.js +0 -4
- package/dist/deployment/index.js +0 -11
- package/dist/deployment/orchestration/BaseDeploymentOrchestrator.js +0 -426
- package/dist/deployment/orchestration/EnterpriseOrchestrator.js +0 -401
- package/dist/deployment/orchestration/PortfolioOrchestrator.js +0 -273
- package/dist/deployment/orchestration/SingleServiceOrchestrator.js +0 -231
- package/dist/deployment/orchestration/UnifiedDeploymentOrchestrator.js +0 -662
- package/dist/deployment/orchestration/index.js +0 -17
- package/dist/deployment/rollback-manager.js +0 -36
- package/dist/deployment/wrangler-deployer.js +0 -640
- package/dist/handlers/GenericRouteHandler.js +0 -532
- package/dist/migration/MigrationAdapters.js +0 -562
- package/dist/modules/ModuleManager.js +0 -668
- package/dist/modules/security.js +0 -96
- package/dist/orchestration/cross-domain-coordinator.js +0 -1083
- package/dist/orchestration/index.js +0 -5
- package/dist/orchestration/modules/DeploymentCoordinator.js +0 -368
- package/dist/orchestration/modules/DomainResolver.js +0 -198
- package/dist/orchestration/modules/StateManager.js +0 -332
- package/dist/orchestration/multi-domain-orchestrator.js +0 -724
- package/dist/routing/EnhancedRouter.js +0 -158
- package/dist/schema/SchemaManager.js +0 -778
- package/dist/service-management/ConfirmationEngine.js +0 -412
- package/dist/service-management/ErrorTracker.js +0 -299
- package/dist/service-management/GenerationEngine.js +0 -447
- package/dist/service-management/InputCollector.js +0 -619
- package/dist/service-management/ServiceCreator.js +0 -265
- package/dist/service-management/ServiceInitializer.js +0 -453
- package/dist/service-management/ServiceOrchestrator.js +0 -633
- package/dist/service-management/generators/BaseGenerator.js +0 -233
- package/dist/service-management/generators/GeneratorRegistry.js +0 -254
- package/dist/service-management/generators/cicd/CiWorkflowGenerator.js +0 -87
- package/dist/service-management/generators/cicd/DeployWorkflowGenerator.js +0 -106
- package/dist/service-management/generators/code/ServiceHandlersGenerator.js +0 -235
- package/dist/service-management/generators/code/ServiceMiddlewareGenerator.js +0 -116
- package/dist/service-management/generators/code/ServiceUtilsGenerator.js +0 -246
- package/dist/service-management/generators/code/WorkerIndexGenerator.js +0 -143
- package/dist/service-management/generators/config/DevelopmentEnvGenerator.js +0 -101
- package/dist/service-management/generators/config/DomainsConfigGenerator.js +0 -175
- package/dist/service-management/generators/config/EnvExampleGenerator.js +0 -178
- package/dist/service-management/generators/config/ProductionEnvGenerator.js +0 -97
- package/dist/service-management/generators/config/StagingEnvGenerator.js +0 -97
- package/dist/service-management/generators/config/WranglerTomlGenerator.js +0 -238
- package/dist/service-management/generators/core/PackageJsonGenerator.js +0 -243
- package/dist/service-management/generators/core/SiteConfigGenerator.js +0 -115
- package/dist/service-management/generators/documentation/ApiDocsGenerator.js +0 -331
- package/dist/service-management/generators/documentation/ConfigurationDocsGenerator.js +0 -294
- package/dist/service-management/generators/documentation/DeploymentDocsGenerator.js +0 -244
- package/dist/service-management/generators/documentation/ReadmeGenerator.js +0 -196
- package/dist/service-management/generators/schemas/ServiceSchemaGenerator.js +0 -190
- package/dist/service-management/generators/scripts/DeployScriptGenerator.js +0 -123
- package/dist/service-management/generators/scripts/HealthCheckScriptGenerator.js +0 -101
- package/dist/service-management/generators/scripts/SetupScriptGenerator.js +0 -88
- package/dist/service-management/generators/service-types/StaticSiteGenerator.js +0 -342
- package/dist/service-management/generators/testing/EslintConfigGenerator.js +0 -85
- package/dist/service-management/generators/testing/IntegrationTestsGenerator.js +0 -237
- package/dist/service-management/generators/testing/JestConfigGenerator.js +0 -72
- package/dist/service-management/generators/testing/UnitTestsGenerator.js +0 -277
- package/dist/service-management/generators/tooling/DockerComposeGenerator.js +0 -71
- package/dist/service-management/generators/tooling/GitignoreGenerator.js +0 -143
- package/dist/service-management/generators/utils/FileWriter.js +0 -179
- package/dist/service-management/generators/utils/PathResolver.js +0 -157
- package/dist/service-management/generators/utils/ServiceManifestGenerator.js +0 -111
- package/dist/service-management/generators/utils/TemplateEngine.js +0 -185
- package/dist/service-management/generators/utils/index.js +0 -18
- package/dist/service-management/handlers/ConfirmationHandler.js +0 -71
- package/dist/service-management/handlers/GenerationHandler.js +0 -80
- package/dist/service-management/handlers/InputHandler.js +0 -59
- package/dist/service-management/handlers/ValidationHandler.js +0 -203
- package/dist/service-management/index.js +0 -14
- package/dist/service-management/routing/DomainRouteMapper.js +0 -311
- package/dist/service-management/routing/RouteGenerator.js +0 -266
- package/dist/service-management/routing/WranglerRoutesBuilder.js +0 -273
- package/dist/service-management/routing/index.js +0 -14
- package/dist/service-management/services/DirectoryStructureService.js +0 -56
- package/dist/service-management/services/GenerationCoordinator.js +0 -208
- package/dist/service-management/services/GeneratorRegistry.js +0 -174
- package/dist/services/GenericDataService.js +0 -501
- package/dist/ui-structures/concepts/second-order-acquisition-strategy.md +0 -286
- package/dist/ui-structures/concepts/service-lifecycle-management.md +0 -150
- package/dist/ui-structures/concepts/service-manifest-guide.md +0 -309
- package/dist/ui-structures/concepts/three-tier-categorization-strategy.md +0 -231
- package/dist/ui-structures/creation/automated-generation-ui.json +0 -246
- package/dist/ui-structures/creation/core-inputs-ui.json +0 -217
- package/dist/ui-structures/creation/smart-confirmable-ui.json +0 -451
- package/dist/ui-structures/reference/absolutely-required-inputs.json +0 -315
- package/dist/ui-structures/reference/service-manifest-template.json +0 -342
- package/dist/version/VersionDetector.js +0 -723
- package/dist/worker/index.js +0 -4
- package/dist/worker/integration.js +0 -351
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* State Manager Module
|
|
3
|
-
* Handles portfolio state tracking, audit logging, and rollback planning
|
|
4
|
-
* Extracted from MultiDomainOrchestrator for focused responsibility
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { writeFile, mkdir, access } from 'fs/promises';
|
|
8
|
-
import { join } from 'path';
|
|
9
|
-
import { randomBytes } from 'crypto';
|
|
10
|
-
export class StateManager {
|
|
11
|
-
constructor(options = {}) {
|
|
12
|
-
this.environment = options.environment || 'production';
|
|
13
|
-
this.dryRun = options.dryRun || false;
|
|
14
|
-
this.logDirectory = options.logDirectory || 'deployments';
|
|
15
|
-
this.enablePersistence = options.enablePersistence !== false;
|
|
16
|
-
this.rollbackEnabled = options.rollbackEnabled !== false;
|
|
17
|
-
|
|
18
|
-
// Initialize portfolio state
|
|
19
|
-
this.portfolioState = this.initializePortfolioState(options);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Initialize portfolio state structure
|
|
24
|
-
* @param {Object} options - Initialization options
|
|
25
|
-
* @returns {Object} Portfolio state object
|
|
26
|
-
*/
|
|
27
|
-
initializePortfolioState(options = {}) {
|
|
28
|
-
return {
|
|
29
|
-
orchestrationId: this.generateOrchestrationId(),
|
|
30
|
-
startTime: new Date(),
|
|
31
|
-
endTime: null,
|
|
32
|
-
environment: this.environment,
|
|
33
|
-
totalDomains: options.domains?.length || 0,
|
|
34
|
-
completedDomains: 0,
|
|
35
|
-
failedDomains: 0,
|
|
36
|
-
domainStates: new Map(),
|
|
37
|
-
rollbackPlan: [],
|
|
38
|
-
auditLog: [],
|
|
39
|
-
metadata: {
|
|
40
|
-
dryRun: this.dryRun,
|
|
41
|
-
persistenceEnabled: this.enablePersistence,
|
|
42
|
-
rollbackEnabled: this.rollbackEnabled
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Generate unique orchestration ID for tracking portfolio deployments
|
|
49
|
-
* @returns {string} Unique orchestration identifier
|
|
50
|
-
*/
|
|
51
|
-
generateOrchestrationId() {
|
|
52
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
53
|
-
const random = randomBytes(6).toString('hex');
|
|
54
|
-
return `orchestration-${timestamp}-${random}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Generate deployment ID for individual domain
|
|
59
|
-
* @param {string} domain - Domain name
|
|
60
|
-
* @returns {string} Unique deployment identifier
|
|
61
|
-
*/
|
|
62
|
-
generateDeploymentId(domain) {
|
|
63
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
64
|
-
const random = randomBytes(4).toString('hex');
|
|
65
|
-
return `deploy-${domain}-${timestamp}-${random}`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Initialize domain states for portfolio
|
|
70
|
-
* @param {Array} domains - Array of domain names
|
|
71
|
-
* @returns {Promise<void>}
|
|
72
|
-
*/
|
|
73
|
-
async initializeDomainStates(domains) {
|
|
74
|
-
this.portfolioState.totalDomains = domains.length;
|
|
75
|
-
domains.forEach(domain => {
|
|
76
|
-
this.portfolioState.domainStates.set(domain, {
|
|
77
|
-
domain,
|
|
78
|
-
deploymentId: this.generateDeploymentId(domain),
|
|
79
|
-
phase: 'pending',
|
|
80
|
-
status: 'pending',
|
|
81
|
-
startTime: null,
|
|
82
|
-
endTime: null,
|
|
83
|
-
error: null,
|
|
84
|
-
rollbackActions: [],
|
|
85
|
-
metadata: {
|
|
86
|
-
created: new Date().toISOString(),
|
|
87
|
-
environment: this.environment
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
await this.logAuditEvent('PORTFOLIO_INITIALIZED', 'ALL', {
|
|
92
|
-
totalDomains: domains.length,
|
|
93
|
-
domains: domains
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Update domain state
|
|
99
|
-
* @param {string} domain - Domain name
|
|
100
|
-
* @param {Object} updates - State updates
|
|
101
|
-
* @returns {Object} Updated domain state
|
|
102
|
-
*/
|
|
103
|
-
updateDomainState(domain, updates) {
|
|
104
|
-
const domainState = this.portfolioState.domainStates.get(domain);
|
|
105
|
-
if (!domainState) {
|
|
106
|
-
throw new Error(`Domain state not found: ${domain}`);
|
|
107
|
-
}
|
|
108
|
-
Object.assign(domainState, updates, {
|
|
109
|
-
lastUpdated: new Date().toISOString()
|
|
110
|
-
});
|
|
111
|
-
return domainState;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Get domain state
|
|
116
|
-
* @param {string} domain - Domain name
|
|
117
|
-
* @returns {Object|null} Domain state or null if not found
|
|
118
|
-
*/
|
|
119
|
-
getDomainState(domain) {
|
|
120
|
-
return this.portfolioState.domainStates.get(domain) || null;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Get portfolio state summary
|
|
125
|
-
* @returns {Object} Portfolio state summary
|
|
126
|
-
*/
|
|
127
|
-
getPortfolioSummary() {
|
|
128
|
-
const states = Array.from(this.portfolioState.domainStates.values());
|
|
129
|
-
return {
|
|
130
|
-
orchestrationId: this.portfolioState.orchestrationId,
|
|
131
|
-
environment: this.environment,
|
|
132
|
-
totalDomains: this.portfolioState.totalDomains,
|
|
133
|
-
completed: states.filter(s => s.status === 'completed').length,
|
|
134
|
-
failed: states.filter(s => s.status === 'failed').length,
|
|
135
|
-
inProgress: states.filter(s => s.status === 'deploying').length,
|
|
136
|
-
pending: states.filter(s => s.status === 'pending').length,
|
|
137
|
-
startTime: this.portfolioState.startTime,
|
|
138
|
-
endTime: this.portfolioState.endTime,
|
|
139
|
-
duration: this.portfolioState.endTime ? this.portfolioState.endTime - this.portfolioState.startTime : Date.now() - this.portfolioState.startTime,
|
|
140
|
-
auditLogSize: this.portfolioState.auditLog.length
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Log audit event for tracking
|
|
146
|
-
* @param {string} event - Event type
|
|
147
|
-
* @param {string} domain - Domain or 'ALL' for portfolio events
|
|
148
|
-
* @param {Object} details - Event details
|
|
149
|
-
* @returns {Promise<void>}
|
|
150
|
-
*/
|
|
151
|
-
async logAuditEvent(event, domain, details = {}) {
|
|
152
|
-
const auditEntry = {
|
|
153
|
-
timestamp: new Date().toISOString(),
|
|
154
|
-
orchestrationId: this.portfolioState.orchestrationId,
|
|
155
|
-
event,
|
|
156
|
-
domain,
|
|
157
|
-
details,
|
|
158
|
-
sequenceNumber: this.portfolioState.auditLog.length + 1
|
|
159
|
-
};
|
|
160
|
-
this.portfolioState.auditLog.push(auditEntry);
|
|
161
|
-
|
|
162
|
-
// Save to file for persistence (fire and forget)
|
|
163
|
-
if (this.enablePersistence && !this.dryRun) {
|
|
164
|
-
try {
|
|
165
|
-
await this.saveAuditLog();
|
|
166
|
-
} catch (error) {
|
|
167
|
-
console.warn(`⚠️ Failed to save audit log: ${error.message}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Add rollback action for domain
|
|
174
|
-
* @param {string} domain - Domain name
|
|
175
|
-
* @param {Object} action - Rollback action
|
|
176
|
-
*/
|
|
177
|
-
addRollbackAction(domain, action) {
|
|
178
|
-
const domainState = this.getDomainState(domain);
|
|
179
|
-
if (domainState) {
|
|
180
|
-
domainState.rollbackActions.push({
|
|
181
|
-
...action,
|
|
182
|
-
timestamp: new Date().toISOString(),
|
|
183
|
-
id: randomBytes(4).toString('hex')
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Add to portfolio rollback plan
|
|
188
|
-
this.portfolioState.rollbackPlan.push({
|
|
189
|
-
domain,
|
|
190
|
-
action: {
|
|
191
|
-
...action,
|
|
192
|
-
timestamp: new Date().toISOString()
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Get rollback plan for portfolio or specific domain
|
|
199
|
-
* @param {string} [domain] - Optional domain filter
|
|
200
|
-
* @returns {Array} Rollback actions
|
|
201
|
-
*/
|
|
202
|
-
getRollbackPlan(domain = null) {
|
|
203
|
-
if (domain) {
|
|
204
|
-
return this.portfolioState.rollbackPlan.filter(item => item.domain === domain);
|
|
205
|
-
}
|
|
206
|
-
return this.portfolioState.rollbackPlan;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Mark deployment as started
|
|
211
|
-
* @param {string} domain - Domain name
|
|
212
|
-
*/
|
|
213
|
-
markDeploymentStarted(domain) {
|
|
214
|
-
this.updateDomainState(domain, {
|
|
215
|
-
status: 'deploying',
|
|
216
|
-
startTime: new Date()
|
|
217
|
-
});
|
|
218
|
-
this.portfolioState.completedDomains++;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Mark deployment as completed
|
|
223
|
-
* @param {string} domain - Domain name
|
|
224
|
-
* @param {Object} result - Deployment result
|
|
225
|
-
*/
|
|
226
|
-
markDeploymentCompleted(domain, result = {}) {
|
|
227
|
-
this.updateDomainState(domain, {
|
|
228
|
-
status: 'completed',
|
|
229
|
-
endTime: new Date(),
|
|
230
|
-
result
|
|
231
|
-
});
|
|
232
|
-
this.portfolioState.completedDomains++;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Mark deployment as failed
|
|
237
|
-
* @param {string} domain - Domain name
|
|
238
|
-
* @param {Error|string} error - Error details
|
|
239
|
-
*/
|
|
240
|
-
markDeploymentFailed(domain, error) {
|
|
241
|
-
this.updateDomainState(domain, {
|
|
242
|
-
status: 'failed',
|
|
243
|
-
endTime: new Date(),
|
|
244
|
-
error: error instanceof Error ? error.message : error
|
|
245
|
-
});
|
|
246
|
-
this.portfolioState.failedDomains++;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Mark portfolio as completed
|
|
251
|
-
*/
|
|
252
|
-
markPortfolioCompleted() {
|
|
253
|
-
this.portfolioState.endTime = new Date();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Save audit log to file
|
|
258
|
-
* @returns {Promise<void>}
|
|
259
|
-
*/
|
|
260
|
-
async saveAuditLog() {
|
|
261
|
-
if (!this.enablePersistence) return;
|
|
262
|
-
try {
|
|
263
|
-
// Ensure log directory exists
|
|
264
|
-
try {
|
|
265
|
-
await access(this.logDirectory);
|
|
266
|
-
} catch {
|
|
267
|
-
await mkdir(this.logDirectory, {
|
|
268
|
-
recursive: true
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
const logFile = join(this.logDirectory, `${this.portfolioState.orchestrationId}.json`);
|
|
272
|
-
const logData = {
|
|
273
|
-
orchestrationId: this.portfolioState.orchestrationId,
|
|
274
|
-
environment: this.environment,
|
|
275
|
-
startTime: this.portfolioState.startTime,
|
|
276
|
-
endTime: this.portfolioState.endTime,
|
|
277
|
-
summary: this.getPortfolioSummary(),
|
|
278
|
-
domainStates: Array.from(this.portfolioState.domainStates.entries()).reduce((obj, [key, value]) => {
|
|
279
|
-
obj[key] = value;
|
|
280
|
-
return obj;
|
|
281
|
-
}, {}),
|
|
282
|
-
rollbackPlan: this.portfolioState.rollbackPlan,
|
|
283
|
-
auditLog: this.portfolioState.auditLog,
|
|
284
|
-
metadata: this.portfolioState.metadata
|
|
285
|
-
};
|
|
286
|
-
await writeFile(logFile, JSON.stringify(logData, null, 2));
|
|
287
|
-
} catch (error) {
|
|
288
|
-
console.warn(`⚠️ Failed to save audit log: ${error.message}`);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Get audit log entries
|
|
294
|
-
* @param {Object} filter - Filter options
|
|
295
|
-
* @returns {Array} Filtered audit entries
|
|
296
|
-
*/
|
|
297
|
-
getAuditLog(filter = {}) {
|
|
298
|
-
let entries = this.portfolioState.auditLog;
|
|
299
|
-
if (filter.event) {
|
|
300
|
-
entries = entries.filter(entry => entry.event === filter.event);
|
|
301
|
-
}
|
|
302
|
-
if (filter.domain) {
|
|
303
|
-
entries = entries.filter(entry => entry.domain === filter.domain);
|
|
304
|
-
}
|
|
305
|
-
if (filter.since) {
|
|
306
|
-
entries = entries.filter(entry => new Date(entry.timestamp) >= filter.since);
|
|
307
|
-
}
|
|
308
|
-
return entries;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Clear state (for testing or reset)
|
|
313
|
-
*/
|
|
314
|
-
clearState() {
|
|
315
|
-
this.portfolioState = this.initializePortfolioState();
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Get state statistics
|
|
320
|
-
* @returns {Object} State statistics
|
|
321
|
-
*/
|
|
322
|
-
getStateStats() {
|
|
323
|
-
return {
|
|
324
|
-
orchestrationId: this.portfolioState.orchestrationId,
|
|
325
|
-
domainCount: this.portfolioState.domainStates.size,
|
|
326
|
-
auditLogSize: this.portfolioState.auditLog.length,
|
|
327
|
-
rollbackActionsCount: this.portfolioState.rollbackPlan.length,
|
|
328
|
-
persistenceEnabled: this.enablePersistence,
|
|
329
|
-
dryRun: this.dryRun
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
}
|