@tamyla/clodo-framework 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/CHANGELOG.md +564 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1393 -0
  4. package/bin/README.md +71 -0
  5. package/bin/clodo-service.js +416 -0
  6. package/bin/security/security-cli.js +96 -0
  7. package/bin/service-management/README.md +74 -0
  8. package/bin/service-management/create-service.js +129 -0
  9. package/bin/service-management/init-service.js +102 -0
  10. package/bin/service-management/init-service.js.backup +889 -0
  11. package/bin/shared/config/customer-cli.js +293 -0
  12. package/dist/config/ConfigurationManager.js +159 -0
  13. package/dist/config/CustomerConfigCLI.js +220 -0
  14. package/dist/config/FeatureManager.js +426 -0
  15. package/dist/config/customers.js +441 -0
  16. package/dist/config/domains.js +180 -0
  17. package/dist/config/features.js +225 -0
  18. package/dist/config/index.js +6 -0
  19. package/dist/database/database-orchestrator.js +730 -0
  20. package/dist/database/index.js +4 -0
  21. package/dist/deployment/auditor.js +971 -0
  22. package/dist/deployment/index.js +10 -0
  23. package/dist/deployment/rollback-manager.js +523 -0
  24. package/dist/deployment/testers/api-tester.js +80 -0
  25. package/dist/deployment/testers/auth-tester.js +129 -0
  26. package/dist/deployment/testers/core.js +217 -0
  27. package/dist/deployment/testers/database-tester.js +105 -0
  28. package/dist/deployment/testers/index.js +74 -0
  29. package/dist/deployment/testers/load-tester.js +120 -0
  30. package/dist/deployment/testers/performance-tester.js +105 -0
  31. package/dist/deployment/validator.js +558 -0
  32. package/dist/deployment/wrangler-deployer.js +574 -0
  33. package/dist/handlers/GenericRouteHandler.js +532 -0
  34. package/dist/index.js +39 -0
  35. package/dist/migration/MigrationAdapters.js +562 -0
  36. package/dist/modules/ModuleManager.js +668 -0
  37. package/dist/modules/security.js +98 -0
  38. package/dist/orchestration/cross-domain-coordinator.js +1083 -0
  39. package/dist/orchestration/index.js +5 -0
  40. package/dist/orchestration/modules/DeploymentCoordinator.js +258 -0
  41. package/dist/orchestration/modules/DomainResolver.js +196 -0
  42. package/dist/orchestration/modules/StateManager.js +332 -0
  43. package/dist/orchestration/multi-domain-orchestrator.js +255 -0
  44. package/dist/routing/EnhancedRouter.js +158 -0
  45. package/dist/schema/SchemaManager.js +778 -0
  46. package/dist/security/ConfigurationValidator.js +490 -0
  47. package/dist/security/DeploymentManager.js +208 -0
  48. package/dist/security/SecretGenerator.js +142 -0
  49. package/dist/security/SecurityCLI.js +228 -0
  50. package/dist/security/index.js +51 -0
  51. package/dist/security/patterns/environment-rules.js +66 -0
  52. package/dist/security/patterns/insecure-patterns.js +21 -0
  53. package/dist/service-management/ConfirmationEngine.js +411 -0
  54. package/dist/service-management/ErrorTracker.js +294 -0
  55. package/dist/service-management/GenerationEngine.js +3109 -0
  56. package/dist/service-management/InputCollector.js +237 -0
  57. package/dist/service-management/ServiceCreator.js +229 -0
  58. package/dist/service-management/ServiceInitializer.js +448 -0
  59. package/dist/service-management/ServiceOrchestrator.js +638 -0
  60. package/dist/service-management/handlers/ConfigMutator.js +130 -0
  61. package/dist/service-management/handlers/ConfirmationHandler.js +71 -0
  62. package/dist/service-management/handlers/GenerationHandler.js +80 -0
  63. package/dist/service-management/handlers/InputHandler.js +59 -0
  64. package/dist/service-management/handlers/ValidationHandler.js +203 -0
  65. package/dist/service-management/index.js +7 -0
  66. package/dist/services/GenericDataService.js +488 -0
  67. package/dist/shared/cloudflare/domain-discovery.js +562 -0
  68. package/dist/shared/cloudflare/domain-manager.js +912 -0
  69. package/dist/shared/cloudflare/index.js +8 -0
  70. package/dist/shared/cloudflare/ops.js +387 -0
  71. package/dist/shared/config/cache.js +1167 -0
  72. package/dist/shared/config/command-config-manager.js +174 -0
  73. package/dist/shared/config/customer-cli.js +258 -0
  74. package/dist/shared/config/index.js +9 -0
  75. package/dist/shared/config/manager.js +289 -0
  76. package/dist/shared/database/connection-manager.js +338 -0
  77. package/dist/shared/database/index.js +7 -0
  78. package/dist/shared/database/orchestrator.js +632 -0
  79. package/dist/shared/deployment/auditor.js +971 -0
  80. package/dist/shared/deployment/index.js +10 -0
  81. package/dist/shared/deployment/rollback-manager.js +523 -0
  82. package/dist/shared/deployment/validator.js +558 -0
  83. package/dist/shared/index.js +32 -0
  84. package/dist/shared/monitoring/health-checker.js +250 -0
  85. package/dist/shared/monitoring/index.js +8 -0
  86. package/dist/shared/monitoring/memory-manager.js +382 -0
  87. package/dist/shared/monitoring/production-monitor.js +390 -0
  88. package/dist/shared/production-tester/api-tester.js +80 -0
  89. package/dist/shared/production-tester/auth-tester.js +129 -0
  90. package/dist/shared/production-tester/core.js +217 -0
  91. package/dist/shared/production-tester/database-tester.js +105 -0
  92. package/dist/shared/production-tester/index.js +74 -0
  93. package/dist/shared/production-tester/load-tester.js +120 -0
  94. package/dist/shared/production-tester/performance-tester.js +105 -0
  95. package/dist/shared/security/api-token-manager.js +296 -0
  96. package/dist/shared/security/index.js +8 -0
  97. package/dist/shared/security/secret-generator.js +918 -0
  98. package/dist/shared/security/secure-token-manager.js +379 -0
  99. package/dist/shared/utils/error-recovery.js +240 -0
  100. package/dist/shared/utils/graceful-shutdown-manager.js +380 -0
  101. package/dist/shared/utils/index.js +9 -0
  102. package/dist/shared/utils/interactive-prompts.js +134 -0
  103. package/dist/shared/utils/rate-limiter.js +249 -0
  104. package/dist/utils/ErrorHandler.js +173 -0
  105. package/dist/utils/deployment/config-cache.js +1160 -0
  106. package/dist/utils/deployment/index.js +6 -0
  107. package/dist/utils/deployment/interactive-prompts.js +97 -0
  108. package/dist/utils/deployment/secret-generator.js +896 -0
  109. package/dist/utils/dirname-helper.js +35 -0
  110. package/dist/utils/domain-config.js +159 -0
  111. package/dist/utils/error-recovery.js +240 -0
  112. package/dist/utils/esm-helper.js +52 -0
  113. package/dist/utils/framework-config.js +481 -0
  114. package/dist/utils/graceful-shutdown-manager.js +379 -0
  115. package/dist/utils/health-checker.js +114 -0
  116. package/dist/utils/index.js +36 -0
  117. package/dist/utils/prompt-handler.js +98 -0
  118. package/dist/utils/usage-tracker.js +252 -0
  119. package/dist/utils/validation.js +112 -0
  120. package/dist/version/VersionDetector.js +723 -0
  121. package/dist/worker/index.js +4 -0
  122. package/dist/worker/integration.js +332 -0
  123. package/docs/FRAMEWORK-ARCHITECTURE-OVERVIEW.md +206 -0
  124. package/docs/INTEGRATION_GUIDE.md +2045 -0
  125. package/docs/README.md +82 -0
  126. package/docs/SECURITY.md +242 -0
  127. package/docs/deployment/deployment-guide.md +540 -0
  128. package/docs/overview.md +280 -0
  129. package/package.json +176 -0
  130. package/types/index.d.ts +575 -0
@@ -0,0 +1,558 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Advanced Deployment Validator Module
5
+ * Enterprise-grade validation system for comprehensive deployment verification
6
+ *
7
+ * Extracted from bulletproof-deploy.js and check-endpoint-structure.js with enhancements
8
+ */
9
+ import { access, readFile } from 'fs/promises';
10
+ import { readFileSync } from 'fs';
11
+ import { promisify } from 'util';
12
+ import { exec } from 'child_process';
13
+ import { join } from 'path';
14
+ import { getCommandConfig } from '../config/command-config-manager.js';
15
+ const execAsync = promisify(exec);
16
+
17
+ /**
18
+ * Advanced Deployment Validator
19
+ * Provides comprehensive validation pipeline for enterprise deployments
20
+ */
21
+ export class DeploymentValidator {
22
+ constructor(options = {}) {
23
+ this.options = options; // Store options for later merging
24
+ this.environment = options.environment || 'production';
25
+ this.strictMode = options.strictMode || false;
26
+ this.timeout = options.timeout || 30000;
27
+ this.retryAttempts = options.retryAttempts || 3;
28
+ this.retryDelay = options.retryDelay || 2000;
29
+
30
+ // Initialize command configuration
31
+ this.cmdConfig = getCommandConfig();
32
+
33
+ // Load validation configuration from file
34
+ this.validationConfig = this.loadValidationConfig();
35
+
36
+ // Validation results tracking
37
+ this.results = {
38
+ overall: 'pending',
39
+ categories: {
40
+ prerequisites: 'pending',
41
+ authentication: 'pending',
42
+ network: 'pending',
43
+ configuration: 'pending',
44
+ endpoints: 'pending',
45
+ deployment: 'pending'
46
+ },
47
+ details: [],
48
+ warnings: [],
49
+ errors: [],
50
+ startTime: null,
51
+ endTime: null
52
+ };
53
+ }
54
+
55
+ /**
56
+ * Load validation configuration from JSON file
57
+ */
58
+ loadValidationConfig() {
59
+ const configPath = join(process.cwd(), 'validation-config.json');
60
+ try {
61
+ const configData = readFileSync(configPath, 'utf-8');
62
+ const userConfig = JSON.parse(configData);
63
+
64
+ // Merge with defaults
65
+ const defaultConfig = {
66
+ requiredCommands: Object.keys(this.cmdConfig?.config?.requiredCommands || {}) || ['npx', 'node', 'npm', 'wrangler'],
67
+ requiredFiles: ['package.json', 'wrangler.toml'],
68
+ requiredEnvironmentVars: [],
69
+ networkEndpoints: ['https://api.cloudflare.com', 'https://registry.npmjs.org'],
70
+ expectedEndpoints: this.getExpectedEndpoints()
71
+ };
72
+
73
+ // Handle new format with command objects
74
+ if (userConfig.requiredCommands && typeof userConfig.requiredCommands === 'object' && !Array.isArray(userConfig.requiredCommands)) {
75
+ // Convert object format to array for backward compatibility
76
+ defaultConfig.requiredCommands = Object.values(userConfig.requiredCommands);
77
+ } else if (userConfig.requiredCommands) {
78
+ defaultConfig.requiredCommands = userConfig.requiredCommands;
79
+ }
80
+
81
+ // Override other config values
82
+ if (userConfig.requiredFiles) defaultConfig.requiredFiles = userConfig.requiredFiles;
83
+ if (userConfig.requiredEnvironmentVars) defaultConfig.requiredEnvironmentVars = userConfig.requiredEnvironmentVars;
84
+ if (userConfig.networkEndpoints) defaultConfig.networkEndpoints = userConfig.networkEndpoints;
85
+ console.log('šŸ“‹ Loaded validation config from validation-config.json');
86
+ return defaultConfig;
87
+ } catch (error) {
88
+ // Fall back to defaults if file doesn't exist or is invalid
89
+ console.log('šŸ“‹ Using default validation config (validation-config.json not found or invalid)');
90
+ return {
91
+ requiredCommands: Object.keys(this.cmdConfig?.config?.requiredCommands || {}) || ['npx', 'node', 'npm', 'wrangler'],
92
+ requiredFiles: ['package.json', 'wrangler.toml'],
93
+ requiredEnvironmentVars: [],
94
+ networkEndpoints: ['https://api.cloudflare.com', 'https://registry.npmjs.org'],
95
+ expectedEndpoints: this.getExpectedEndpoints()
96
+ };
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Get expected endpoints for validation
102
+ * @returns {Array<string>} List of expected endpoints
103
+ */
104
+ getExpectedEndpoints() {
105
+ return [
106
+ // Authentication
107
+ 'POST /register', 'POST /auth/magic-link', 'GET /auth/me', 'POST /auth/verify', 'POST /auth/session',
108
+ // User Management
109
+ 'GET /users', 'GET /users/profile', 'PATCH /users/profile',
110
+ // File Management
111
+ 'GET /files', 'POST /files', 'GET /files/stats', 'GET /files/:id', 'PATCH /files/:id', 'DELETE /files/:id',
112
+ // Logging
113
+ 'POST /logs/store', 'GET /logs', 'GET /logs/analytics',
114
+ // Enhanced Framework (Auto-generated CRUD)
115
+ 'GET /api/users', 'POST /api/users', 'GET /api/users/:id', 'PATCH /api/users/:id', 'DELETE /api/users/:id', 'GET /api/files', 'POST /api/files', 'GET /api/files/:id', 'PATCH /api/files/:id', 'DELETE /api/files/:id', 'GET /api/products', 'POST /api/products', 'GET /api/products/:id', 'PATCH /api/products/:id', 'DELETE /api/products/:id', 'GET /api/orders', 'POST /api/orders', 'GET /api/orders/:id', 'PATCH /api/orders/:id', 'DELETE /api/orders/:id',
116
+ // System
117
+ 'GET /health', 'GET /'];
118
+ }
119
+
120
+ /**
121
+ * Run comprehensive validation pipeline
122
+ * @param {string|Array<string>} domains - Domain(s) to validate
123
+ * @param {Object} options - Validation options
124
+ * @returns {Promise<Object>} Validation results
125
+ */
126
+ async validateDeployment(domains = [], options = {}) {
127
+ this.options = {
128
+ ...this.options,
129
+ ...options
130
+ }; // Merge with existing options
131
+ this.results.startTime = new Date();
132
+ const domainList = Array.isArray(domains) ? domains : [domains];
133
+ try {
134
+ console.log('šŸ” Advanced Deployment Validation');
135
+ console.log('=================================');
136
+ console.log(`šŸŒ Environment: ${this.environment}`);
137
+ console.log(`šŸ“‹ Domains: ${domainList.length > 0 ? domainList.join(', ') : 'Pre-deployment only'}`);
138
+ console.log(`āš™ļø Strict Mode: ${this.strictMode ? 'ON' : 'OFF'}`);
139
+ console.log('');
140
+
141
+ // Phase 1: Prerequisites Validation
142
+ await this.validatePrerequisites();
143
+
144
+ // Phase 2: Authentication Validation
145
+ await this.validateAuthentication();
146
+
147
+ // Phase 3: Network Connectivity
148
+ await this.validateNetworkConnectivity();
149
+
150
+ // Phase 4: Configuration Validation
151
+ await this.validateConfiguration();
152
+
153
+ // Phase 5: Endpoint Structure (if domains provided and not a new deployment)
154
+ if (domainList.length > 0 && domainList[0] && !this.options.skipEndpointCheck) {
155
+ await this.validateEndpointStructure(domainList);
156
+ } else if (this.options.skipEndpointCheck) {
157
+ console.log('šŸ”— Phase 5: Endpoint Structure Validation');
158
+ console.log(' ā­ļø Skipping endpoint validation for new deployment');
159
+ this.results.categories.endpoints = 'skipped';
160
+ this.addResult('endpoints', 'Skipped for new deployment', 'info');
161
+ } else {
162
+ // No domains to validate
163
+ console.log('šŸ”— Phase 5: Endpoint Structure Validation');
164
+ console.log(' ā­ļø No domains provided for validation');
165
+ this.results.categories.endpoints = 'skipped';
166
+ this.addResult('endpoints', 'No domains to validate', 'info');
167
+ }
168
+
169
+ // Phase 6: Deployment Readiness
170
+ await this.validateDeploymentReadiness();
171
+ this.results.overall = 'passed';
172
+ this.results.endTime = new Date();
173
+ console.log('\nāœ… VALIDATION COMPLETE');
174
+ this.printValidationSummary();
175
+ return this.results;
176
+ } catch (error) {
177
+ this.results.overall = 'failed';
178
+ this.results.endTime = new Date();
179
+ this.results.errors.push({
180
+ phase: 'validation',
181
+ message: error.message,
182
+ timestamp: new Date()
183
+ });
184
+ console.error('\nāŒ VALIDATION FAILED');
185
+ console.error(`Error: ${error.message}`);
186
+ this.printValidationSummary();
187
+ throw error;
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Validate system prerequisites
193
+ */
194
+ async validatePrerequisites() {
195
+ console.log('šŸ”§ Phase 1: Prerequisites Validation');
196
+ try {
197
+ // Check required commands
198
+ for (const cmd of this.validationConfig.requiredCommands) {
199
+ await this.validateCommand(cmd);
200
+ }
201
+
202
+ // Check required files
203
+ for (const file of this.validationConfig.requiredFiles) {
204
+ await this.validateFile(file);
205
+ }
206
+
207
+ // Check Node.js version
208
+ await this.validateNodeVersion();
209
+ this.results.categories.prerequisites = 'passed';
210
+ this.addResult('prerequisites', 'All prerequisites validated', 'success');
211
+ } catch (error) {
212
+ this.results.categories.prerequisites = 'failed';
213
+ throw new Error(`Prerequisites validation failed: ${error.message}`);
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Validate authentication systems
219
+ */
220
+ async validateAuthentication() {
221
+ console.log('šŸ” Phase 2: Authentication Validation');
222
+ try {
223
+ // Cloudflare authentication (optional for development)
224
+ try {
225
+ await this.validateCloudflareAuth();
226
+ } catch (error) {
227
+ console.log(` āš ļø Cloudflare: ${error.message} (optional for development)`);
228
+ this.addResult('cloudflare-auth', 'Cloudflare not authenticated (development mode)', 'warning');
229
+ }
230
+
231
+ // NPM authentication (if needed)
232
+ await this.validateNpmAuth();
233
+ this.results.categories.authentication = 'passed';
234
+ this.addResult('authentication', 'Authentication validation completed', 'success');
235
+ } catch (error) {
236
+ this.results.categories.authentication = 'failed';
237
+ throw new Error(`Authentication validation failed: ${error.message}`);
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Validate network connectivity
243
+ */
244
+ async validateNetworkConnectivity() {
245
+ console.log('🌐 Phase 3: Network Connectivity');
246
+ try {
247
+ for (const endpoint of this.validationConfig.networkEndpoints) {
248
+ await this.validateNetworkEndpoint(endpoint);
249
+ }
250
+ this.results.categories.network = 'passed';
251
+ this.addResult('network', 'Network connectivity verified', 'success');
252
+ } catch (error) {
253
+ this.results.categories.network = 'failed';
254
+ throw new Error(`Network validation failed: ${error.message}`);
255
+ }
256
+ }
257
+
258
+ /**
259
+ * Validate configuration files
260
+ */
261
+ async validateConfiguration() {
262
+ console.log('āš™ļø Phase 4: Configuration Validation');
263
+ try {
264
+ // Validate package.json
265
+ await this.validatePackageJson();
266
+
267
+ // Skip wrangler.toml validation for multi-service framework
268
+ // Each service has its own wrangler.toml
269
+ console.log(' ā­ļø Skipping wrangler.toml validation (per-service configuration)');
270
+
271
+ // Validate environment configuration
272
+ await this.validateEnvironmentConfig();
273
+ this.results.categories.configuration = 'passed';
274
+ this.addResult('configuration', 'Configuration files validated', 'success');
275
+ } catch (error) {
276
+ this.results.categories.configuration = 'failed';
277
+ throw new Error(`Configuration validation failed: ${error.message}`);
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Validate endpoint structure for deployed domains
283
+ * @param {Array<string>} domains - Domains to validate
284
+ */
285
+ async validateEndpointStructure(domains) {
286
+ console.log('šŸ”— Phase 5: Endpoint Structure Validation');
287
+
288
+ // Double-check skip condition
289
+ if (this.options?.skipEndpointCheck) {
290
+ console.log(' ā­ļø Skipping endpoint validation (skipEndpointCheck=true)');
291
+ this.results.categories.endpoints = 'skipped';
292
+ this.addResult('endpoints', 'Skipped for new deployment', 'info');
293
+ return;
294
+ }
295
+ try {
296
+ for (const domain of domains) {
297
+ await this.validateDomainEndpoints(domain);
298
+ }
299
+ this.results.categories.endpoints = 'passed';
300
+ this.addResult('endpoints', 'Endpoint structure validated', 'success');
301
+ } catch (error) {
302
+ this.results.categories.endpoints = 'failed';
303
+ throw new Error(`Endpoint validation failed: ${error.message}`);
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Validate deployment readiness
309
+ */
310
+ async validateDeploymentReadiness() {
311
+ console.log('šŸš€ Phase 6: Deployment Readiness');
312
+ try {
313
+ // Check disk space
314
+ await this.validateDiskSpace();
315
+
316
+ // Check memory usage
317
+ await this.validateMemoryUsage();
318
+
319
+ // Validate build process
320
+ await this.validateBuildProcess();
321
+ this.results.categories.deployment = 'passed';
322
+ this.addResult('deployment', 'Deployment readiness confirmed', 'success');
323
+ return {
324
+ valid: true
325
+ };
326
+ } catch (error) {
327
+ this.results.categories.deployment = 'failed';
328
+ this.addResult('deployment', `Deployment readiness failed: ${error.message}`, 'error');
329
+ return {
330
+ valid: false,
331
+ errors: [error.message]
332
+ };
333
+ }
334
+ }
335
+
336
+ // Individual validation methods
337
+
338
+ async validateCommand(command) {
339
+ console.log(` Checking ${command}...`);
340
+ try {
341
+ // Get command from configuration if available
342
+ let actualCommand = command;
343
+ try {
344
+ actualCommand = this.cmdConfig.getRequiredCommand(command);
345
+ } catch (error) {
346
+ // Use original command if not in config
347
+ }
348
+ const result = await this.executeWithRetry(`${actualCommand} --version`);
349
+ const version = result.trim().split('\\n')[0];
350
+ console.log(` āœ… ${command}: ${version}`);
351
+ this.addResult('command', `${command} available: ${version}`, 'info');
352
+ } catch (error) {
353
+ throw new Error(`Required command '${command}' not available: ${error.message}`);
354
+ }
355
+ }
356
+ async validateFile(filePath) {
357
+ console.log(` Checking ${filePath}...`);
358
+ try {
359
+ await access(filePath);
360
+ console.log(` āœ… ${filePath}: exists`);
361
+ this.addResult('file', `${filePath} exists`, 'info');
362
+ } catch {
363
+ throw new Error(`Required file '${filePath}' not found`);
364
+ }
365
+ }
366
+ async validateNodeVersion() {
367
+ console.log(' Checking Node.js version...');
368
+ try {
369
+ const version = process.version;
370
+ const majorVersion = parseInt(version.slice(1).split('.')[0]);
371
+ if (majorVersion < 16) {
372
+ throw new Error(`Node.js version ${version} is too old. Minimum required: v16.0.0`);
373
+ }
374
+ console.log(` āœ… Node.js: ${version}`);
375
+ this.addResult('node', `Node.js version: ${version}`, 'info');
376
+ } catch (error) {
377
+ throw new Error(`Node.js validation failed: ${error.message}`);
378
+ }
379
+ }
380
+ async validateCloudflareAuth() {
381
+ console.log(' Checking Cloudflare authentication...');
382
+ try {
383
+ const whoamiCmd = this.cmdConfig.getCloudflareCommand('whoami');
384
+ const result = await this.executeWithRetry(whoamiCmd);
385
+ if (result.includes('You are not authenticated') || result.includes('not logged in')) {
386
+ const authCmd = this.cmdConfig.getCloudflareCommand('auth_login');
387
+ throw new Error(`Cloudflare authentication required. Run: ${authCmd}`);
388
+ }
389
+ console.log(` āœ… Cloudflare: authenticated`);
390
+ this.addResult('cloudflare-auth', 'Cloudflare authenticated', 'success');
391
+ } catch (error) {
392
+ throw new Error(`Cloudflare authentication failed: ${error.message}`);
393
+ }
394
+ }
395
+ async validateNpmAuth() {
396
+ console.log(' Checking NPM authentication...');
397
+ try {
398
+ // NPM auth is optional for most deployments
399
+ const npmCmd = this.cmdConfig.getRequiredCommand('npm');
400
+ const result = await this.executeWithRetry(`${npmCmd} whoami`);
401
+ console.log(` āœ… NPM: authenticated as ${result.trim()}`);
402
+ this.addResult('npm-auth', `NPM authenticated: ${result.trim()}`, 'info');
403
+ } catch (error) {
404
+ // NPM auth failure is usually not critical
405
+ console.log(` āš ļø NPM: not authenticated (optional)`);
406
+ this.addResult('npm-auth', 'NPM not authenticated (optional)', 'warning');
407
+ }
408
+ }
409
+ async validateNetworkEndpoint(endpoint) {
410
+ console.log(` Testing connectivity to ${endpoint}...`);
411
+ try {
412
+ // Use configurable network test command
413
+ const command = this.cmdConfig.getNetworkTestCommand(endpoint);
414
+ await this.executeWithRetry(command, 15000);
415
+ console.log(` āœ… ${endpoint}: reachable`);
416
+ this.addResult('network', `${endpoint} reachable`, 'info');
417
+ } catch (error) {
418
+ throw new Error(`Cannot reach ${endpoint}: ${error.message}`);
419
+ }
420
+ }
421
+ async validatePackageJson() {
422
+ console.log(' Validating package.json...');
423
+ try {
424
+ const packageContent = await readFile('package.json', 'utf8');
425
+ const packageJson = JSON.parse(packageContent);
426
+
427
+ // Check required fields
428
+ const requiredFields = ['name', 'version', 'scripts'];
429
+ const missingFields = requiredFields.filter(field => !packageJson[field]);
430
+ if (missingFields.length > 0) {
431
+ throw new Error(`Missing required fields in package.json: ${missingFields.join(', ')}`);
432
+ }
433
+ console.log(` āœ… package.json: valid`);
434
+ this.addResult('package-json', 'package.json validation passed', 'info');
435
+ } catch (error) {
436
+ throw new Error(`package.json validation failed: ${error.message}`);
437
+ }
438
+ }
439
+ async validateWranglerConfig() {
440
+ console.log(' Validating wrangler.toml...');
441
+ try {
442
+ const wranglerContent = await readFile('wrangler.toml', 'utf8');
443
+
444
+ // Basic validation - check for required sections
445
+ if (!wranglerContent.includes('name') || !wranglerContent.includes('compatibility_date')) {
446
+ throw new Error('wrangler.toml missing required configuration');
447
+ }
448
+ console.log(` āœ… wrangler.toml: valid`);
449
+ this.addResult('wrangler-config', 'wrangler.toml validation passed', 'info');
450
+ } catch (error) {
451
+ throw new Error(`wrangler.toml validation failed: ${error.message}`);
452
+ }
453
+ }
454
+ async validateEnvironmentConfig() {
455
+ console.log(' Validating environment configuration...');
456
+ // Environment validation logic here
457
+ console.log(` āœ… Environment: ${this.environment} configuration valid`);
458
+ this.addResult('environment', `${this.environment} environment validated`, 'info');
459
+ }
460
+ async validateDomainEndpoints(domain) {
461
+ console.log(` Validating endpoints for ${domain}...`);
462
+ console.log(` šŸ”§ DEBUG: skipEndpointCheck = ${this.options?.skipEndpointCheck}`);
463
+ console.log(` šŸ”§ DEBUG: deploymentType = ${this.options?.deploymentType}`);
464
+ console.log(` šŸ”§ DEBUG: options = ${JSON.stringify(this.options)}`);
465
+
466
+ // Skip endpoint validation for new deployments
467
+ if (this.options?.skipEndpointCheck) {
468
+ console.log(` ā­ļø Skipping endpoint validation for new deployment`);
469
+ this.addResult('endpoints', 'Skipped for new deployment', 'info');
470
+ return;
471
+ }
472
+ try {
473
+ // Test health endpoint first
474
+ const healthUrl = `https://${domain}/health`;
475
+ const command = this.cmdConfig.getNetworkTestCommand(healthUrl);
476
+ await this.executeWithRetry(command, 15000);
477
+ console.log(` āœ… ${domain}: health endpoint responding`);
478
+ this.addResult('endpoints', `${domain} endpoints accessible`, 'success');
479
+ } catch (error) {
480
+ throw new Error(`Domain ${domain} endpoints validation failed: ${error.message}`);
481
+ }
482
+ }
483
+ async validateDiskSpace() {
484
+ console.log(' Checking disk space...');
485
+ // Disk space validation logic
486
+ console.log(` āœ… Disk space: sufficient`);
487
+ this.addResult('disk-space', 'Sufficient disk space available', 'info');
488
+ }
489
+ async validateMemoryUsage() {
490
+ console.log(' Checking memory usage...');
491
+ // Memory usage validation logic
492
+ console.log(` āœ… Memory: sufficient`);
493
+ this.addResult('memory', 'Sufficient memory available', 'info');
494
+ }
495
+ async validateBuildProcess() {
496
+ console.log(' Validating build process...');
497
+ try {
498
+ // Test build without deploying
499
+ await this.executeWithRetry('npm run build', 60000);
500
+ console.log(` āœ… Build: successful`);
501
+ this.addResult('build', 'Build process validated', 'success');
502
+ } catch (error) {
503
+ throw new Error(`Build validation failed: ${error.message}`);
504
+ }
505
+ }
506
+
507
+ // Utility methods
508
+
509
+ async executeWithRetry(command, timeout = this.timeout) {
510
+ for (let attempt = 1; attempt <= this.retryAttempts; attempt++) {
511
+ try {
512
+ const {
513
+ stdout
514
+ } = await execAsync(command, {
515
+ encoding: 'utf8',
516
+ stdio: 'pipe',
517
+ timeout
518
+ });
519
+ return stdout;
520
+ } catch (error) {
521
+ if (attempt === this.retryAttempts) {
522
+ throw error;
523
+ }
524
+ await new Promise(resolve => setTimeout(resolve, this.retryDelay));
525
+ }
526
+ }
527
+ }
528
+ addResult(category, message, level) {
529
+ this.results.details.push({
530
+ category,
531
+ message,
532
+ level,
533
+ timestamp: new Date()
534
+ });
535
+ if (level === 'warning') {
536
+ this.results.warnings.push(message);
537
+ } else if (level === 'error') {
538
+ this.results.errors.push(message);
539
+ }
540
+ }
541
+ printValidationSummary() {
542
+ console.log('\nšŸ“Š VALIDATION SUMMARY');
543
+ console.log('====================');
544
+ Object.entries(this.results.categories).forEach(([category, status]) => {
545
+ const icon = status === 'passed' ? 'āœ…' : status === 'failed' ? 'āŒ' : 'ā³';
546
+ console.log(`${icon} ${category}: ${status}`);
547
+ });
548
+ if (this.results.warnings.length > 0) {
549
+ console.log(`\nāš ļø Warnings: ${this.results.warnings.length}`);
550
+ }
551
+ if (this.results.errors.length > 0) {
552
+ console.log(`\nāŒ Errors: ${this.results.errors.length}`);
553
+ }
554
+ const duration = this.results.endTime ? ((this.results.endTime - this.results.startTime) / 1000).toFixed(1) : 'N/A';
555
+ console.log(`\nā±ļø Duration: ${duration}s`);
556
+ }
557
+ }
558
+ export default DeploymentValidator;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Shared Modules Index
3
+ * Organized exports from all shared utility modules
4
+ *
5
+ * Usage:
6
+ * import { DeploymentValidator, CloudflareDomainManager } from '../shared';
7
+ * import { ProductionTester } from '../shared/production-tester';
8
+ */
9
+
10
+ // Cloudflare Integration
11
+ export * from './cloudflare/index.js';
12
+
13
+ // Deployment Management
14
+ export * from './deployment/index.js';
15
+
16
+ // Security & Authentication
17
+ export * from './security/index.js';
18
+
19
+ // Configuration Management
20
+ export * from './config/index.js';
21
+
22
+ // Database Management
23
+ export * from './database/index.js';
24
+
25
+ // Monitoring & Health Checks
26
+ export * from './monitoring/index.js';
27
+
28
+ // General Utilities
29
+ export * from './utils/index.js';
30
+
31
+ // Production Testing (kept separate due to size)
32
+ export { ProductionTester } from './production-tester/index.js';