@tamyla/clodo-framework 3.1.10 → 3.1.12

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 (86) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/bin/clodo-service-old.js +2 -2
  3. package/dist/bin/commands/create.js +1 -1
  4. package/dist/bin/commands/diagnose.js +1 -1
  5. package/dist/bin/commands/update.js +1 -1
  6. package/dist/bin/commands/validate.js +1 -1
  7. package/dist/bin/database/enterprise-db-manager.js +3 -3
  8. package/dist/bin/deployment/enterprise-deploy.js +3 -3
  9. package/dist/bin/deployment/master-deploy.js +3 -3
  10. package/dist/bin/deployment/modular-enterprise-deploy.js +3 -3
  11. package/dist/bin/deployment/modules/DeploymentOrchestrator.js +1 -1
  12. package/dist/bin/deployment/modules/EnvironmentManager.js +2 -2
  13. package/dist/bin/portfolio/portfolio-manager.js +3 -3
  14. package/dist/bin/security/security-cli.js +1 -1
  15. package/dist/bin/service-management/create-service.js +1 -1
  16. package/dist/bin/service-management/init-service.js +1 -1
  17. package/dist/bin/shared/cloudflare/domain-manager.js +1 -1
  18. package/dist/bin/shared/validation/ValidationRegistry.js +1 -1
  19. package/dist/deployment/wrangler-deployer.js +1 -1
  20. package/dist/orchestration/cross-domain-coordinator.js +5 -5
  21. package/dist/security/index.js +1 -1
  22. package/dist/service-management/ConfirmationEngine.js +1 -1
  23. package/dist/service-management/ErrorTracker.js +1 -1
  24. package/dist/service-management/InputCollector.js +1 -1
  25. package/dist/service-management/ServiceCreator.js +1 -1
  26. package/dist/service-management/ServiceInitializer.js +1 -1
  27. package/dist/utils/config/unified-config-manager.js +1 -1
  28. package/dist/utils/deployment/config-cache.js +1 -1
  29. package/dist/utils/deployment/secret-generator.js +1 -1
  30. package/dist/utils/framework-config.js +1 -1
  31. package/dist/worker/integration.js +1 -1
  32. package/package.json +1 -6
  33. package/bin/README.md +0 -71
  34. package/bin/clodo-service.js +0 -72
  35. package/bin/database/README.md +0 -33
  36. package/bin/database/deployment-db-manager.js +0 -527
  37. package/bin/database/enterprise-db-manager.js +0 -738
  38. package/bin/database/wrangler-d1-manager.js +0 -775
  39. package/bin/security/security-cli.js +0 -117
  40. package/bin/service-management/README.md +0 -74
  41. package/bin/service-management/create-service.js +0 -129
  42. package/bin/service-management/init-service.js +0 -103
  43. package/bin/service-management/init-service.js.backup +0 -889
  44. package/bin/shared/cloudflare/domain-discovery.js +0 -637
  45. package/bin/shared/cloudflare/domain-manager.js +0 -952
  46. package/bin/shared/cloudflare/index.js +0 -8
  47. package/bin/shared/cloudflare/ops.js +0 -401
  48. package/bin/shared/config/ConfigurationManager.js +0 -539
  49. package/bin/shared/config/cache.js +0 -1230
  50. package/bin/shared/config/command-config-manager.js +0 -184
  51. package/bin/shared/config/index.js +0 -21
  52. package/bin/shared/config/manager.js +0 -315
  53. package/bin/shared/database/connection-manager.js +0 -374
  54. package/bin/shared/database/index.js +0 -7
  55. package/bin/shared/database/orchestrator.js +0 -727
  56. package/bin/shared/deployment/auditor.js +0 -970
  57. package/bin/shared/deployment/index.js +0 -10
  58. package/bin/shared/deployment/rollback-manager.js +0 -570
  59. package/bin/shared/deployment/validator.js +0 -779
  60. package/bin/shared/index.js +0 -32
  61. package/bin/shared/logging/Logger.js +0 -214
  62. package/bin/shared/monitoring/health-checker.js +0 -484
  63. package/bin/shared/monitoring/index.js +0 -8
  64. package/bin/shared/monitoring/memory-manager.js +0 -387
  65. package/bin/shared/monitoring/production-monitor.js +0 -403
  66. package/bin/shared/production-tester/api-tester.js +0 -82
  67. package/bin/shared/production-tester/auth-tester.js +0 -132
  68. package/bin/shared/production-tester/core.js +0 -197
  69. package/bin/shared/production-tester/database-tester.js +0 -109
  70. package/bin/shared/production-tester/index.js +0 -77
  71. package/bin/shared/production-tester/load-tester.js +0 -131
  72. package/bin/shared/production-tester/performance-tester.js +0 -103
  73. package/bin/shared/security/api-token-manager.js +0 -312
  74. package/bin/shared/security/index.js +0 -8
  75. package/bin/shared/security/secret-generator.js +0 -942
  76. package/bin/shared/security/secure-token-manager.js +0 -398
  77. package/bin/shared/utils/ErrorHandler.js +0 -675
  78. package/bin/shared/utils/error-recovery.js +0 -245
  79. package/bin/shared/utils/file-manager.js +0 -162
  80. package/bin/shared/utils/formatters.js +0 -247
  81. package/bin/shared/utils/graceful-shutdown-manager.js +0 -390
  82. package/bin/shared/utils/index.js +0 -19
  83. package/bin/shared/utils/interactive-prompts.js +0 -146
  84. package/bin/shared/utils/interactive-utils.js +0 -530
  85. package/bin/shared/utils/rate-limiter.js +0 -246
  86. package/bin/shared/validation/ValidationRegistry.js +0 -143
@@ -1,403 +0,0 @@
1
- /**
2
- * Production Monitoring Module
3
- * Implements structured logging, metrics collection, and alerting
4
- */
5
-
6
- import { writeFile, appendFile, mkdir } from 'fs/promises';
7
- import { join } from 'path';
8
- import { logger } from '../logging/Logger.js';
9
-
10
- export class ProductionMonitor {
11
- constructor(options = {}) {
12
- this.config = {
13
- logLevel: options.logLevel || 'info',
14
- logDir: options.logDir || 'logs',
15
- metricsInterval: options.metricsInterval || 60000, // 1 minute
16
- alertThresholds: {
17
- errorRate: options.errorRateThreshold || 0.05, // 5% error rate
18
- responseTime: options.responseTimeThreshold || 5000, // 5 seconds
19
- memoryUsage: options.memoryUsageThreshold || 0.8, // 80% memory usage
20
- ...options.alertThresholds
21
- },
22
- enableMetrics: options.enableMetrics !== false,
23
- enableAlerts: options.enableAlerts !== false,
24
- alertWebhook: options.alertWebhook,
25
- ...options
26
- };
27
-
28
- this.metrics = {
29
- startTime: new Date(),
30
- requests: { total: 0, successful: 0, failed: 0 },
31
- responseTimes: [],
32
- errors: [],
33
- memoryUsage: [],
34
- customMetrics: new Map()
35
- };
36
-
37
- this.logLevels = {
38
- debug: 0,
39
- info: 1,
40
- warn: 2,
41
- error: 3,
42
- fatal: 4
43
- };
44
-
45
- this.alerts = [];
46
- this.isMonitoring = false;
47
- }
48
-
49
- /**
50
- * Start monitoring
51
- */
52
- async startMonitoring() {
53
- if (this.isMonitoring) return;
54
-
55
- this.isMonitoring = true;
56
- await this.ensureLogDirectory();
57
-
58
- // Start metrics collection
59
- if (this.config.enableMetrics) {
60
- this.metricsInterval = setInterval(() => {
61
- this.collectSystemMetrics();
62
- this.checkAlertThresholds();
63
- }, this.config.metricsInterval);
64
- }
65
-
66
- this.log('info', 'Production monitoring started', {
67
- config: this.config,
68
- startTime: this.metrics.startTime
69
- });
70
- }
71
-
72
- /**
73
- * Stop monitoring
74
- */
75
- async stopMonitoring() {
76
- if (!this.isMonitoring) return;
77
-
78
- this.isMonitoring = false;
79
-
80
- if (this.metricsInterval) {
81
- clearInterval(this.metricsInterval);
82
- }
83
-
84
- await this.saveMetrics();
85
- this.log('info', 'Production monitoring stopped');
86
- }
87
-
88
- /**
89
- * Log a message with structured data
90
- */
91
- async log(level, message, data = {}) {
92
- if (this.logLevels[level] < this.logLevels[this.config.logLevel]) {
93
- return;
94
- }
95
-
96
- const logEntry = {
97
- timestamp: new Date(),
98
- level,
99
- message,
100
- data,
101
- process: {
102
- pid: process.pid,
103
- memory: process.memoryUsage(),
104
- uptime: process.uptime()
105
- }
106
- };
107
-
108
- // Use Logger for output
109
- const methodMap = {
110
- debug: 'debug',
111
- info: 'info',
112
- warn: 'warn',
113
- error: 'error',
114
- fatal: 'fatal'
115
- };
116
-
117
- const logMethod = methodMap[level] || 'info';
118
- logger[logMethod](message, data);
119
-
120
- // File logging through Logger
121
- if (!this.config.logDir) {
122
- this.config.logDir = 'logs';
123
- }
124
- try {
125
- const logFile = join(this.config.logDir, `${new Date().toISOString().split('T')[0]}.log`);
126
- if (!logger.logFile) {
127
- logger.setLogFile(logFile);
128
- }
129
- } catch (error) {
130
- logger.error('Failed to set up log file', { error: error.message });
131
- }
132
-
133
- // Track errors for metrics
134
- if (level === 'error' || level === 'fatal') {
135
- this.metrics.errors.push(logEntry);
136
- }
137
- }
138
-
139
- /**
140
- * Record a request
141
- */
142
- recordRequest(success = true, responseTime = 0, metadata = {}) {
143
- this.metrics.requests.total++;
144
-
145
- if (success) {
146
- this.metrics.requests.successful++;
147
- } else {
148
- this.metrics.requests.failed++;
149
- }
150
-
151
- if (responseTime > 0) {
152
- this.metrics.responseTimes.push({
153
- time: responseTime,
154
- timestamp: new Date(),
155
- success,
156
- ...metadata
157
- });
158
-
159
- // Keep only last 1000 response times
160
- if (this.metrics.responseTimes.length > 1000) {
161
- this.metrics.responseTimes.shift();
162
- }
163
- }
164
- }
165
-
166
- /**
167
- * Record a custom metric
168
- */
169
- recordMetric(name, value, tags = {}) {
170
- if (!this.metrics.customMetrics.has(name)) {
171
- this.metrics.customMetrics.set(name, []);
172
- }
173
-
174
- const metrics = this.metrics.customMetrics.get(name);
175
- metrics.push({
176
- value,
177
- timestamp: new Date(),
178
- tags
179
- });
180
-
181
- // Keep only last 100 values per metric
182
- if (metrics.length > 100) {
183
- metrics.shift();
184
- }
185
- }
186
-
187
- /**
188
- * Collect system metrics
189
- */
190
- collectSystemMetrics() {
191
- const memUsage = process.memoryUsage();
192
- const memoryData = {
193
- rss: memUsage.rss,
194
- heapUsed: memUsage.heapUsed,
195
- heapTotal: memUsage.heapTotal,
196
- external: memUsage.external,
197
- timestamp: new Date()
198
- };
199
-
200
- this.metrics.memoryUsage.push(memoryData);
201
-
202
- // Keep only last 100 memory readings
203
- if (this.metrics.memoryUsage.length > 100) {
204
- this.metrics.memoryUsage.shift();
205
- }
206
-
207
- // Record memory usage as custom metric
208
- this.recordMetric('memory_usage_percent', (memUsage.heapUsed / memUsage.heapTotal) * 100);
209
- this.recordMetric('memory_heap_used_mb', memUsage.heapUsed / 1024 / 1024);
210
- }
211
-
212
- /**
213
- * Check alert thresholds and trigger alerts
214
- */
215
- checkAlertThresholds() {
216
- const now = Date.now();
217
-
218
- // Check error rate
219
- const recentRequests = this.getRecentRequests(5 * 60 * 1000); // Last 5 minutes
220
- if (recentRequests.total > 10) { // Only check if we have enough data
221
- const errorRate = recentRequests.failed / recentRequests.total;
222
- if (errorRate > this.config.alertThresholds.errorRate) {
223
- this.triggerAlert('HIGH_ERROR_RATE', {
224
- errorRate: errorRate * 100,
225
- threshold: this.config.alertThresholds.errorRate * 100,
226
- recentRequests
227
- });
228
- }
229
- }
230
-
231
- // Check response time
232
- const avgResponseTime = this.getAverageResponseTime(5 * 60 * 1000);
233
- if (avgResponseTime > this.config.alertThresholds.responseTime) {
234
- this.triggerAlert('HIGH_RESPONSE_TIME', {
235
- averageResponseTime: avgResponseTime,
236
- threshold: this.config.alertThresholds.responseTime
237
- });
238
- }
239
-
240
- // Check memory usage
241
- const currentMemory = this.metrics.memoryUsage[this.metrics.memoryUsage.length - 1];
242
- if (currentMemory) {
243
- const memoryUsagePercent = currentMemory.heapUsed / currentMemory.heapTotal;
244
- if (memoryUsagePercent > this.config.alertThresholds.memoryUsage) {
245
- this.triggerAlert('HIGH_MEMORY_USAGE', {
246
- memoryUsagePercent: memoryUsagePercent * 100,
247
- threshold: this.config.alertThresholds.memoryUsage * 100,
248
- heapUsed: currentMemory.heapUsed,
249
- heapTotal: currentMemory.heapTotal
250
- });
251
- }
252
- }
253
- }
254
-
255
- /**
256
- * Trigger an alert
257
- */
258
- async triggerAlert(type, data) {
259
- const alert = {
260
- id: `alert_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
261
- type,
262
- timestamp: new Date(),
263
- data,
264
- acknowledged: false
265
- };
266
-
267
- this.alerts.push(alert);
268
-
269
- // Keep only last 100 alerts
270
- if (this.alerts.length > 100) {
271
- this.alerts.shift();
272
- }
273
-
274
- // Log the alert
275
- await this.log('error', `Alert triggered: ${type}`, data);
276
-
277
- // Send webhook if configured
278
- if (this.config.alertWebhook) {
279
- try {
280
- await this.sendWebhookAlert(alert);
281
- } catch (error) {
282
- await this.log('error', 'Failed to send alert webhook', { error: error.message });
283
- }
284
- }
285
- }
286
-
287
- /**
288
- * Send webhook alert
289
- */
290
- async sendWebhookAlert(alert) {
291
- if (!this.config.alertWebhook) return;
292
-
293
- // In a real implementation, you'd use fetch or axios to send the webhook
294
- // For now, just log it
295
- await this.log('info', 'Alert webhook would be sent', {
296
- webhook: this.config.alertWebhook,
297
- alert
298
- });
299
- }
300
-
301
- /**
302
- * Get recent requests within time window
303
- */
304
- getRecentRequests(timeWindowMs) {
305
- const cutoff = Date.now() - timeWindowMs;
306
- const recent = this.metrics.responseTimes.filter(r => r.timestamp.getTime() > cutoff);
307
-
308
- return {
309
- total: recent.length,
310
- successful: recent.filter(r => r.success).length,
311
- failed: recent.filter(r => !r.success).length
312
- };
313
- }
314
-
315
- /**
316
- * Get average response time within time window
317
- */
318
- getAverageResponseTime(timeWindowMs) {
319
- const cutoff = Date.now() - timeWindowMs;
320
- const recent = this.metrics.responseTimes.filter(r => r.timestamp.getTime() > cutoff);
321
-
322
- if (recent.length === 0) return 0;
323
-
324
- const totalTime = recent.reduce((sum, r) => sum + r.time, 0);
325
- return totalTime / recent.length;
326
- }
327
-
328
- /**
329
- * Get current metrics summary
330
- */
331
- getMetricsSummary() {
332
- const uptime = Date.now() - this.metrics.startTime.getTime();
333
-
334
- return {
335
- uptime,
336
- requests: { ...this.metrics.requests },
337
- errorRate: this.metrics.requests.total > 0 ?
338
- (this.metrics.requests.failed / this.metrics.requests.total) * 100 : 0,
339
- averageResponseTime: this.getAverageResponseTime(60 * 60 * 1000), // Last hour
340
- memoryUsage: this.metrics.memoryUsage[this.metrics.memoryUsage.length - 1],
341
- activeAlerts: this.alerts.filter(a => !a.acknowledged).length,
342
- totalAlerts: this.alerts.length
343
- };
344
- }
345
-
346
- /**
347
- * Get detailed metrics
348
- */
349
- getDetailedMetrics() {
350
- return {
351
- ...this.getMetricsSummary(),
352
- responseTimes: this.metrics.responseTimes.slice(-100), // Last 100
353
- memoryUsage: this.metrics.memoryUsage.slice(-20), // Last 20 readings
354
- errors: this.metrics.errors.slice(-50), // Last 50 errors
355
- alerts: this.alerts.slice(-20), // Last 20 alerts
356
- customMetrics: Object.fromEntries(this.metrics.customMetrics)
357
- };
358
- }
359
-
360
- /**
361
- * Save metrics to file
362
- */
363
- async saveMetrics() {
364
- try {
365
- const metricsFile = join(this.config.logDir, 'metrics.json');
366
- const metricsData = this.getDetailedMetrics();
367
- await writeFile(metricsFile, JSON.stringify(metricsData, null, 2));
368
- } catch (error) {
369
- logger.error('Failed to save metrics', { error: error.message });
370
- }
371
- }
372
-
373
- /**
374
- * Ensure log directory exists
375
- */
376
- async ensureLogDirectory() {
377
- try {
378
- await mkdir(this.config.logDir, { recursive: true });
379
- } catch (error) {
380
- if (error.code !== 'EEXIST') {
381
- throw error;
382
- }
383
- }
384
- }
385
-
386
- /**
387
- * Acknowledge an alert
388
- */
389
- acknowledgeAlert(alertId) {
390
- const alert = this.alerts.find(a => a.id === alertId);
391
- if (alert) {
392
- alert.acknowledged = true;
393
- alert.acknowledgedAt = new Date();
394
- }
395
- }
396
-
397
- /**
398
- * Get unacknowledged alerts
399
- */
400
- getUnacknowledgedAlerts() {
401
- return this.alerts.filter(a => !a.acknowledged);
402
- }
403
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * API Testing Module
3
- * Specialized module for API endpoint testing
4
- */
5
-
6
- import fetch from 'node-fetch';
7
-
8
- export class ApiTester {
9
- constructor(config) {
10
- this.config = config;
11
- }
12
-
13
- async runApiTests(environment) {
14
- const results = {
15
- passed: 0,
16
- failed: 0,
17
- endpoints: []
18
- };
19
-
20
- // Define API endpoints to test
21
- const endpoints = [
22
- { name: 'Health Check', url: `https://${environment}.api.example.com/health`, method: 'GET' },
23
- { name: 'API Status', url: `https://${environment}.api.example.com/status`, method: 'GET' },
24
- { name: 'User Profile', url: `https://${environment}.api.example.com/api/v1/user/profile`, method: 'GET', auth: true }
25
- ];
26
-
27
- for (const endpoint of endpoints) {
28
- try {
29
- const startTime = Date.now();
30
- const response = await this.testEndpoint(endpoint, environment);
31
- const responseTime = Date.now() - startTime;
32
-
33
- const result = {
34
- name: endpoint.name,
35
- url: endpoint.url,
36
- method: endpoint.method,
37
- status: response.status,
38
- responseTime,
39
- success: response.ok && responseTime < this.config.responseTimeThreshold
40
- };
41
-
42
- results.endpoints.push(result);
43
-
44
- if (result.success) {
45
- results.passed++;
46
- } else {
47
- results.failed++;
48
- }
49
-
50
- } catch (error) {
51
- results.endpoints.push({
52
- name: endpoint.name,
53
- url: endpoint.url,
54
- method: endpoint.method,
55
- error: error.message,
56
- success: false
57
- });
58
- results.failed++;
59
- }
60
- }
61
-
62
- return results;
63
- }
64
-
65
- async testEndpoint(endpoint, environment) {
66
- const options = {
67
- method: endpoint.method,
68
- timeout: this.config.timeout,
69
- headers: {
70
- 'User-Agent': 'ProductionTester/2.0',
71
- 'Accept': 'application/json'
72
- }
73
- };
74
-
75
- if (endpoint.auth) {
76
- // Add authentication headers if needed
77
- options.headers.Authorization = `Bearer ${process.env.TEST_API_TOKEN || 'test-token'}`;
78
- }
79
-
80
- return await fetch(endpoint.url, options);
81
- }
82
- }
@@ -1,132 +0,0 @@
1
- /**
2
- * Authentication Testing Module
3
- * Specialized module for authentication flow validation
4
- */
5
-
6
- import fetch from 'node-fetch';
7
-
8
- export class AuthTester {
9
- constructor(config) {
10
- this.config = config;
11
- }
12
-
13
- async runAuthTests(environment) {
14
- const results = {
15
- passed: 0,
16
- failed: 0,
17
- flows: []
18
- };
19
-
20
- // Authentication flows to test
21
- const flows = [
22
- { name: 'Login Flow', test: () => this.testLoginFlow(environment) },
23
- { name: 'Token Validation', test: () => this.testTokenValidation(environment) },
24
- { name: 'Logout Flow', test: () => this.testLogoutFlow(environment) }
25
- ];
26
-
27
- for (const flow of flows) {
28
- try {
29
- const startTime = Date.now();
30
- const result = await flow.test();
31
- const duration = Date.now() - startTime;
32
-
33
- const flowResult = {
34
- name: flow.name,
35
- duration,
36
- success: result.success && duration < this.config.authFlowThreshold,
37
- details: result
38
- };
39
-
40
- results.flows.push(flowResult);
41
-
42
- if (flowResult.success) {
43
- results.passed++;
44
- } else {
45
- results.failed++;
46
- }
47
-
48
- } catch (error) {
49
- results.flows.push({
50
- name: flow.name,
51
- error: error.message,
52
- success: false
53
- });
54
- results.failed++;
55
- }
56
- }
57
-
58
- return results;
59
- }
60
-
61
- async testLoginFlow(environment) {
62
- try {
63
- // Simulate login request
64
- const response = await fetch(`https://${environment}.api.example.com/auth/login`, {
65
- method: 'POST',
66
- headers: {
67
- 'Content-Type': 'application/json',
68
- 'User-Agent': 'AuthTester/2.0'
69
- },
70
- body: JSON.stringify({
71
- username: 'test@example.com',
72
- password: 'test-password'
73
- }),
74
- timeout: this.config.timeout
75
- });
76
-
77
- return {
78
- success: response.ok,
79
- status: response.status,
80
- hasToken: response.headers.has('authorization') || response.headers.has('x-auth-token')
81
- };
82
-
83
- } catch (error) {
84
- return { success: false, error: error.message };
85
- }
86
- }
87
-
88
- async testTokenValidation(environment) {
89
- try {
90
- const token = process.env.TEST_AUTH_TOKEN || 'test-jwt-token';
91
- const response = await fetch(`https://${environment}.api.example.com/auth/validate`, {
92
- method: 'GET',
93
- headers: {
94
- 'Authorization': `Bearer ${token}`,
95
- 'User-Agent': 'AuthTester/2.0'
96
- },
97
- timeout: this.config.timeout
98
- });
99
-
100
- return {
101
- success: response.ok,
102
- status: response.status,
103
- valid: response.status === 200
104
- };
105
-
106
- } catch (error) {
107
- return { success: false, error: error.message };
108
- }
109
- }
110
-
111
- async testLogoutFlow(environment) {
112
- try {
113
- const token = process.env.TEST_AUTH_TOKEN || 'test-jwt-token';
114
- const response = await fetch(`https://${environment}.api.example.com/auth/logout`, {
115
- method: 'POST',
116
- headers: {
117
- 'Authorization': `Bearer ${token}`,
118
- 'User-Agent': 'AuthTester/2.0'
119
- },
120
- timeout: this.config.timeout
121
- });
122
-
123
- return {
124
- success: response.ok,
125
- status: response.status
126
- };
127
-
128
- } catch (error) {
129
- return { success: false, error: error.message };
130
- }
131
- }
132
- }