@tamyla/clodo-framework 3.1.21 → 3.1.23

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 (150) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +283 -1
  3. package/dist/{bin → cli}/clodo-service.js +47 -15
  4. package/dist/cli/commands/assess.js +183 -0
  5. package/dist/{bin → cli}/commands/create.js +5 -5
  6. package/dist/{bin → cli}/commands/deploy.js +122 -90
  7. package/dist/{bin → cli}/commands/diagnose.js +5 -5
  8. package/dist/cli/commands/helpers/deployment-ui.js +138 -0
  9. package/dist/cli/commands/helpers/deployment-verification.js +250 -0
  10. package/dist/cli/commands/helpers/error-recovery.js +80 -0
  11. package/dist/cli/commands/helpers/resource-detection.js +113 -0
  12. package/dist/{bin → cli}/commands/helpers.js +0 -28
  13. package/dist/cli/commands/init-config.js +57 -0
  14. package/dist/{bin → cli}/commands/update.js +5 -5
  15. package/dist/{bin → cli}/commands/validate.js +5 -5
  16. package/dist/cli/security-cli.js +118 -0
  17. package/dist/config/FeatureManager.js +6 -0
  18. package/dist/config/clodo-create.example.json +26 -0
  19. package/dist/config/clodo-deploy.example.json +41 -0
  20. package/dist/config/clodo-update.example.json +46 -0
  21. package/dist/config/clodo-validate.example.json +41 -0
  22. package/dist/config/customers/template/development.env.template +37 -0
  23. package/dist/config/customers/template/production.env.template +39 -0
  24. package/dist/config/customers/template/staging.env.template +37 -0
  25. package/dist/config/customers.js +28 -26
  26. package/dist/config/domain-examples/README.md +464 -0
  27. package/dist/config/domain-examples/environment-mapped.json +168 -0
  28. package/dist/config/domain-examples/multi-domain.json +144 -0
  29. package/dist/config/domain-examples/single-domain.json +50 -0
  30. package/dist/config/examples +12 -0
  31. package/dist/config/features.js +61 -0
  32. package/dist/config/staging-deployment.json +60 -0
  33. package/dist/config/validation-config.json +347 -0
  34. package/dist/deployment/wrangler-deployer.js +1 -1
  35. package/dist/{bin → lib}/deployment/modules/DeploymentOrchestrator.js +2 -2
  36. package/dist/{bin → lib}/deployment/modules/EnvironmentManager.js +2 -2
  37. package/dist/lib/deployment/orchestration/EnterpriseOrchestrator.js +21 -0
  38. package/dist/lib/shared/cache/configuration-cache.js +82 -0
  39. package/dist/{bin → lib}/shared/cloudflare/domain-discovery.js +1 -1
  40. package/dist/{bin → lib}/shared/cloudflare/domain-manager.js +1 -1
  41. package/dist/{bin → lib}/shared/cloudflare/index.js +1 -1
  42. package/dist/{bin → lib}/shared/cloudflare/ops.js +10 -8
  43. package/dist/{bin → lib}/shared/config/ConfigurationManager.js +23 -1
  44. package/dist/{bin → lib}/shared/config/command-config-manager.js +19 -3
  45. package/dist/{bin → lib}/shared/config/index.js +1 -1
  46. package/dist/{bin → lib}/shared/deployment/credential-collector.js +30 -7
  47. package/dist/lib/shared/deployment/index.js +10 -0
  48. package/dist/lib/shared/deployment/rollback-manager.js +7 -0
  49. package/dist/lib/shared/deployment/utilities/d1-error-recovery.js +177 -0
  50. package/dist/{bin → lib}/shared/deployment/validator.js +40 -10
  51. package/dist/lib/shared/deployment/workflows/deployment-summary.js +214 -0
  52. package/dist/lib/shared/deployment/workflows/interactive-confirmation.js +188 -0
  53. package/dist/lib/shared/deployment/workflows/interactive-database-workflow.js +234 -0
  54. package/dist/lib/shared/deployment/workflows/interactive-domain-info-gatherer.js +240 -0
  55. package/dist/lib/shared/deployment/workflows/interactive-secret-workflow.js +228 -0
  56. package/dist/lib/shared/deployment/workflows/interactive-testing-workflow.js +235 -0
  57. package/dist/lib/shared/deployment/workflows/interactive-validation.js +218 -0
  58. package/dist/lib/shared/error-handling/error-classifier.js +46 -0
  59. package/dist/{bin → lib}/shared/monitoring/health-checker.js +129 -1
  60. package/dist/{bin → lib}/shared/monitoring/memory-manager.js +17 -6
  61. package/dist/{bin → lib}/shared/routing/domain-router.js +1 -1
  62. package/dist/lib/shared/utils/deployment-validator.js +97 -0
  63. package/dist/{bin → lib}/shared/utils/formatters.js +10 -0
  64. package/dist/{bin → lib}/shared/utils/index.js +13 -1
  65. package/dist/{bin → lib}/shared/utils/interactive-prompts.js +34 -18
  66. package/dist/{bin → lib}/shared/utils/progress-manager.js +2 -2
  67. package/dist/lib/shared/utils/progress-spinner.js +53 -0
  68. package/dist/lib/shared/utils/sensitive-redactor.js +91 -0
  69. package/dist/{bin → lib}/shared/validation/ValidationRegistry.js +1 -1
  70. package/dist/migration/MigrationAdapters.js +50 -4
  71. package/dist/orchestration/cross-domain-coordinator.js +5 -5
  72. package/dist/orchestration/multi-domain-orchestrator.js +63 -22
  73. package/dist/security/index.js +2 -2
  74. package/dist/security/patterns/insecure-patterns.js +1 -1
  75. package/dist/service-management/ConfirmationEngine.js +1 -1
  76. package/dist/service-management/ErrorTracker.js +1 -1
  77. package/dist/service-management/InputCollector.js +1 -1
  78. package/dist/service-management/ServiceCreator.js +11 -255
  79. package/dist/service-management/ServiceOrchestrator.js +0 -2
  80. package/dist/service-management/generators/testing/UnitTestsGenerator.js +4 -4
  81. package/dist/service-management/index.js +1 -1
  82. package/dist/utils/cloudflare/ops.js +1 -1
  83. package/dist/utils/constants.js +102 -0
  84. package/dist/utils/deployment/wrangler-config-manager.js +215 -48
  85. package/dist/utils/file-manager.js +1 -1
  86. package/dist/utils/formatters.js +1 -1
  87. package/dist/utils/framework-config.js +2 -2
  88. package/dist/utils/interactive-prompts.js +10 -59
  89. package/dist/utils/logger.js +1 -1
  90. package/dist/version/VersionDetector.js +99 -9
  91. package/dist/worker/integration.js +1 -1
  92. package/package.json +10 -10
  93. package/dist/bin/clodo-service-old.js +0 -868
  94. package/dist/bin/clodo-service-test.js +0 -10
  95. package/dist/bin/commands/assess.js +0 -91
  96. package/dist/bin/database/enterprise-db-manager.js +0 -457
  97. package/dist/bin/deployment/enterprise-deploy.js +0 -877
  98. package/dist/bin/deployment/master-deploy.js +0 -1376
  99. package/dist/bin/deployment/modular-enterprise-deploy.js +0 -466
  100. package/dist/bin/deployment/orchestration/EnterpriseOrchestrator.js +0 -401
  101. package/dist/bin/deployment/test-interactive-utils.js +0 -66
  102. package/dist/bin/portfolio/portfolio-manager.js +0 -487
  103. package/dist/bin/security/security-cli.js +0 -108
  104. package/dist/bin/service-management/create-service.js +0 -122
  105. package/dist/bin/service-management/init-service.js +0 -79
  106. package/dist/bin/shared/deployment/index.js +0 -10
  107. package/dist/bin/shared/deployment/rollback-manager.js +0 -523
  108. package/dist/deployment/orchestration/EnterpriseOrchestrator.js +0 -401
  109. package/dist/service-management/ServiceInitializer.js +0 -453
  110. /package/dist/{bin → lib}/database/deployment-db-manager.js +0 -0
  111. /package/dist/{bin → lib}/database/wrangler-d1-manager.js +0 -0
  112. /package/dist/{bin → lib}/deployment/modules/DeploymentConfiguration.js +0 -0
  113. /package/dist/{bin → lib}/deployment/modules/MonitoringIntegration.js +0 -0
  114. /package/dist/{bin → lib}/deployment/modules/ValidationManager.js +0 -0
  115. /package/dist/{bin → lib}/deployment/orchestration/BaseDeploymentOrchestrator.js +0 -0
  116. /package/dist/{bin → lib}/deployment/orchestration/PortfolioOrchestrator.js +0 -0
  117. /package/dist/{bin → lib}/deployment/orchestration/SingleServiceOrchestrator.js +0 -0
  118. /package/dist/{bin → lib}/deployment/orchestration/UnifiedDeploymentOrchestrator.js +0 -0
  119. /package/dist/{bin → lib}/shared/config/cache.js +0 -0
  120. /package/dist/{bin → lib}/shared/config/cloudflare-service-validator.js +0 -0
  121. /package/dist/{bin → lib}/shared/config/manager.js +0 -0
  122. /package/dist/{bin → lib}/shared/config/manifest-loader.js +0 -0
  123. /package/dist/{bin → lib}/shared/database/connection-manager.js +0 -0
  124. /package/dist/{bin → lib}/shared/database/index.js +0 -0
  125. /package/dist/{bin → lib}/shared/database/orchestrator.js +0 -0
  126. /package/dist/{bin → lib}/shared/deployment/auditor.js +0 -0
  127. /package/dist/{bin → lib}/shared/index.js +0 -0
  128. /package/dist/{bin → lib}/shared/logging/Logger.js +0 -0
  129. /package/dist/{bin → lib}/shared/monitoring/index.js +0 -0
  130. /package/dist/{bin → lib}/shared/monitoring/production-monitor.js +0 -0
  131. /package/dist/{bin → lib}/shared/production-tester/api-tester.js +0 -0
  132. /package/dist/{bin → lib}/shared/production-tester/auth-tester.js +0 -0
  133. /package/dist/{bin → lib}/shared/production-tester/core.js +0 -0
  134. /package/dist/{bin → lib}/shared/production-tester/database-tester.js +0 -0
  135. /package/dist/{bin → lib}/shared/production-tester/index.js +0 -0
  136. /package/dist/{bin → lib}/shared/production-tester/load-tester.js +0 -0
  137. /package/dist/{bin → lib}/shared/production-tester/performance-tester.js +0 -0
  138. /package/dist/{bin → lib}/shared/security/api-token-manager.js +0 -0
  139. /package/dist/{bin → lib}/shared/security/index.js +0 -0
  140. /package/dist/{bin → lib}/shared/security/secret-generator.js +0 -0
  141. /package/dist/{bin → lib}/shared/security/secure-token-manager.js +0 -0
  142. /package/dist/{bin → lib}/shared/utils/ErrorHandler.js +0 -0
  143. /package/dist/{bin → lib}/shared/utils/cli-options.js +0 -0
  144. /package/dist/{bin → lib}/shared/utils/config-loader.js +0 -0
  145. /package/dist/{bin → lib}/shared/utils/error-recovery.js +0 -0
  146. /package/dist/{bin → lib}/shared/utils/file-manager.js +0 -0
  147. /package/dist/{bin → lib}/shared/utils/graceful-shutdown-manager.js +0 -0
  148. /package/dist/{bin → lib}/shared/utils/interactive-utils.js +0 -0
  149. /package/dist/{bin → lib}/shared/utils/output-formatter.js +0 -0
  150. /package/dist/{bin → lib}/shared/utils/rate-limiter.js +0 -0
@@ -1,265 +1,21 @@
1
1
  /**
2
- * Clodo Framework - Service Creator
3
- * Programmatic API for creating services from templates
2
+ * Service Creator
3
+ * Stub implementation for missing ServiceCreator.js
4
4
  */
5
5
 
6
- import { readdirSync, statSync, cpSync, rmSync } from 'fs';
7
- import { join, dirname, resolve } from 'path';
8
- import { fileURLToPath } from 'url';
9
- import { FrameworkConfig } from '../utils/framework-config.js';
10
- import { FileManager } from "../../dist/bin/shared/utils/file-manager.js";
11
- const SERVICE_TYPES = ['data-service', 'auth-service', 'content-service', 'api-gateway', 'generic'];
12
6
  export class ServiceCreator {
13
7
  constructor(options = {}) {
14
- this.fileManager = new FileManager({
15
- enableCache: true
16
- });
17
- const templatesDir = (() => {
18
- try {
19
- return join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'templates');
20
- } catch (error) {
21
- // Fallback for test environments - use current working directory
22
- return join(process.cwd(), 'templates');
23
- }
24
- })();
25
- this.templatesDir = options.templatesDir || templatesDir;
26
- this.serviceTypes = options.serviceTypes || SERVICE_TYPES;
27
-
28
- // Load framework configuration
29
- this.frameworkConfig = options.frameworkConfig || new FrameworkConfig();
30
- }
31
-
32
- /**
33
- * Validate service name according to framework conventions
34
- * @param {string} name - Service name to validate
35
- * @throws {Error} If validation fails
36
- */
37
- validateServiceName(name) {
38
- if (!/^[a-z0-9-]+$/.test(name)) {
39
- throw new Error('Service name must contain only lowercase letters, numbers, and hyphens');
40
- }
41
- if (name.length < 3) {
42
- throw new Error('Service name must be at least 3 characters long');
43
- }
44
- if (name.length > 50) {
45
- throw new Error('Service name must be no more than 50 characters long');
46
- }
47
- }
48
-
49
- /**
50
- * Validate service type
51
- * @param {string} type - Service type to validate
52
- * @throws {Error} If type is invalid
53
- */
54
- validateServiceType(type) {
55
- if (!this.serviceTypes.includes(type)) {
56
- throw new Error(`Invalid service type. Must be one of: ${this.serviceTypes.join(', ')}`);
57
- }
8
+ this.options = options;
58
9
  }
59
-
60
- /**
61
- * Create a service from a template
62
- * @param {string} serviceName - Name of the service to create
63
- * @param {Object} options - Creation options
64
- * @param {string} options.type - Service type (default: 'generic')
65
- * @param {string} options.output - Output directory (default: current directory)
66
- * @param {boolean} options.force - Overwrite existing directory (default: false)
67
- * @param {Object} options.variables - Additional template variables
68
- * @returns {Object} Creation result with success status and metadata
69
- */
70
- async createService(serviceName, options = {}) {
71
- const config = {
72
- type: 'generic',
73
- output: process.cwd(),
74
- force: false,
75
- variables: {},
76
- ...options
10
+ async createService(type, config) {
11
+ return {
12
+ type,
13
+ config,
14
+ created: true
77
15
  };
78
- try {
79
- // Validate inputs
80
- this.validateServiceName(serviceName);
81
- this.validateServiceType(config.type);
82
- const templateDir = join(this.templatesDir, config.type);
83
- const serviceDir = join(config.output, serviceName);
84
-
85
- // Check if template exists, fall back to generic if not
86
- let actualTemplateDir = templateDir;
87
- if (!this.fileManager.exists(templateDir)) {
88
- const genericTemplate = join(this.templatesDir, 'generic');
89
- if (this.fileManager.exists(genericTemplate)) {
90
- console.log(`⚠️ Template for '${config.type}' not found, using 'generic' template as fallback`);
91
- actualTemplateDir = genericTemplate;
92
- } else {
93
- throw new Error(`Template not found: ${templateDir}. Available templates: ${this.serviceTypes.join(', ')}`);
94
- }
95
- }
96
-
97
- // Check if service directory already exists
98
- if (this.fileManager.exists(serviceDir) && !config.force) {
99
- throw new Error(`Service directory already exists: ${serviceDir}. Use force option to overwrite.`);
100
- }
101
-
102
- // Create service directory and copy template
103
- this.fileManager.ensureDir(dirname(serviceDir));
104
-
105
- // If service directory exists (force mode), remove it first
106
- if (this.fileManager.exists(serviceDir) && config.force) {
107
- rmSync(serviceDir, {
108
- recursive: true,
109
- force: true
110
- });
111
- }
112
-
113
- // Copy template to service directory
114
- cpSync(actualTemplateDir, serviceDir, {
115
- recursive: true
116
- });
117
-
118
- // Load template defaults from config
119
- const templateDefaults = this.frameworkConfig.config?.templates?.defaults || {};
120
-
121
- // Prepare template variables
122
- const defaultVariables = {
123
- '{{SERVICE_NAME}}': serviceName,
124
- '{{SERVICE_TYPE}}': config.type,
125
- '{{SERVICE_DISPLAY_NAME}}': this.toTitleCase(serviceName.replace(/-/g, ' ')),
126
- '{{DOMAIN_NAME}}': config.domain || templateDefaults.DOMAIN_NAME || 'example.com',
127
- '{{WORKERS_DEV_DOMAIN}}': templateDefaults.WORKERS_DEV_DOMAIN || 'workers.dev',
128
- '{{CURRENT_DATE}}': new Date().toISOString().split('T')[0],
129
- '{{CURRENT_YEAR}}': new Date().getFullYear().toString(),
130
- '{{FRAMEWORK_VERSION}}': this.getFrameworkVersion()
131
- };
132
- const allVariables = {
133
- ...defaultVariables,
134
- ...config.variables
135
- };
136
-
137
- // Replace template variables
138
- this.replaceTemplateVariables(serviceDir, allVariables);
139
- return {
140
- success: true,
141
- serviceName,
142
- serviceType: config.type,
143
- serviceDir,
144
- templateDir,
145
- variables: allVariables
146
- };
147
- } catch (error) {
148
- return {
149
- success: false,
150
- serviceName,
151
- error: error.message
152
- };
153
- }
154
- }
155
-
156
- /**
157
- * Replace template variables in all files within a directory
158
- * @param {string} dir - Directory to process
159
- * @param {Object} variables - Variable mappings
160
- */
161
- replaceTemplateVariables(dir, variables) {
162
- const files = this.getAllFiles(dir);
163
- for (const file of files) {
164
- try {
165
- let content = this.fileManager.readFile(file, 'utf8');
166
- let modified = false;
167
- for (const [placeholder, value] of Object.entries(variables)) {
168
- if (content.includes(placeholder)) {
169
- content = content.replace(new RegExp(this.escapeRegExp(placeholder), 'g'), value);
170
- modified = true;
171
- }
172
- }
173
- if (modified) {
174
- this.fileManager.writeFile(file, content, 'utf8');
175
- }
176
- } catch (error) {
177
- // Skip binary files or files that can't be read
178
- if (error.code !== 'EISDIR') {
179
- // In programmatic usage, we might want to collect warnings
180
- // For now, we'll silently skip problematic files
181
- }
182
- }
183
- }
184
- }
185
-
186
- /**
187
- * Get all files in a directory recursively
188
- * @param {string} dir - Directory to traverse
189
- * @returns {string[]} Array of file paths
190
- */
191
- getAllFiles(dir) {
192
- const files = [];
193
- function traverse(currentDir) {
194
- const items = readdirSync(currentDir);
195
- for (const item of items) {
196
- const fullPath = join(currentDir, item);
197
- const stat = statSync(fullPath);
198
- if (stat.isDirectory()) {
199
- // Skip node_modules and other unwanted directories
200
- if (!['node_modules', '.git', 'dist', 'build'].includes(item)) {
201
- traverse(fullPath);
202
- }
203
- } else {
204
- files.push(fullPath);
205
- }
206
- }
207
- }
208
- traverse(dir);
209
- return files;
210
- }
211
-
212
- /**
213
- * Escape special regex characters
214
- * @param {string} string - String to escape
215
- * @returns {string} Escaped string
216
- */
217
- escapeRegExp(string) {
218
- return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
219
- }
220
-
221
- /**
222
- * Convert string to title case
223
- * @param {string} str - String to convert
224
- * @returns {string} Title case string
225
- */
226
- toTitleCase(str) {
227
- return str.split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(' ');
228
- }
229
-
230
- /**
231
- * Get framework version from package.json
232
- * @returns {string} Framework version
233
- */
234
- getFrameworkVersion() {
235
- try {
236
- const packageJson = JSON.parse(this.fileManager.readFile(join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'package.json'), 'utf8'));
237
- return packageJson.version;
238
- } catch {
239
- return '1.0.0';
240
- }
241
- }
242
-
243
- /**
244
- * Get available service types
245
- * @returns {string[]} Array of available service types
246
- */
247
- getServiceTypes() {
248
- return [...this.serviceTypes];
249
- }
250
-
251
- /**
252
- * Check if a service type is available
253
- * @param {string} type - Service type to check
254
- * @returns {boolean} True if type is available
255
- */
256
- isServiceTypeAvailable(type) {
257
- return this.serviceTypes.includes(type);
258
16
  }
259
17
  }
260
-
261
- // Convenience function for quick service creation
262
- export async function createService(serviceName, options = {}) {
18
+ export const createService = (type, config) => {
263
19
  const creator = new ServiceCreator();
264
- return await creator.createService(serviceName, options);
265
- }
20
+ return creator.createService(type, config);
21
+ };
@@ -15,7 +15,6 @@ import { WranglerConfigManager } from '../utils/deployment/wrangler-config-manag
15
15
  import { ValidationHandler } from './handlers/ValidationHandler.js';
16
16
 
17
17
  // Legacy imports for backward compatibility
18
- import { ServiceCreator } from './ServiceCreator.js';
19
18
  import { ErrorTracker } from './ErrorTracker.js';
20
19
  import chalk from 'chalk';
21
20
  import fs from 'fs/promises';
@@ -41,7 +40,6 @@ export class ServiceOrchestrator {
41
40
  this.validationHandler = new ValidationHandler();
42
41
 
43
42
  // Initialize legacy components for backward compatibility
44
- this.serviceCreator = new ServiceCreator();
45
43
  this.errorTracker = new ErrorTracker();
46
44
  }
47
45
 
@@ -42,10 +42,10 @@ export class UnitTestsGenerator extends BaseGenerator {
42
42
  */
43
43
  _generateUnitTestContent(coreInputs, confirmedValues) {
44
44
  return `import { describe, test, expect } from '@jest/globals';
45
- import serviceHandlers from '../../src/handlers/service-handlers.js';
46
- import serviceMiddleware from '../../src/middleware/service-middleware.js';
47
- import serviceUtils from '../../src/utils/service-utils.js';
48
- import serviceSchema from '../../src/schemas/service-schema.js';
45
+ import serviceHandlers from '../handlers/service-handlers.js';
46
+ import serviceMiddleware from '../../middleware/service-middleware.js';
47
+ import serviceUtils from '../../utils/service-utils.js';
48
+ import serviceSchema from '../../schemas/service-schema.js';
49
49
 
50
50
  describe('${confirmedValues.displayName} - Unit Tests', () => {
51
51
  describe('Handlers', () => {
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  export { ServiceCreator, createService } from './ServiceCreator.js';
7
- export { ServiceInitializer, initializeService } from './ServiceInitializer.js';
7
+ export { ServiceOrchestrator } from './ServiceOrchestrator.js';
8
8
 
9
9
  // Assessment capabilities moved to @tamyla/clodo-orchestration
10
10
  // - AssessmentCache
@@ -5,4 +5,4 @@
5
5
  * It gets compiled to dist/ and is included in the published package.
6
6
  */
7
7
 
8
- export { checkAuth, authenticate, storeCloudflareToken, getCloudflareToken, listWorkers, workerExists, deployWorker, deploySecret, deleteSecret, listSecrets, listDatabases, databaseExists, createDatabase, deleteDatabase, runMigrations, executeSql, getDatabaseId, validatePrerequisites } from '../../bin/shared/cloudflare/ops.js';
8
+ export { checkAuth, authenticate, storeCloudflareToken, getCloudflareToken, listWorkers, workerExists, deployWorker, deploySecret, deleteSecret, listSecrets, listDatabases, databaseExists, createDatabase, deleteDatabase, runMigrations, executeSql, getDatabaseId, validatePrerequisites } from '../lib/shared/cloudflare/ops.js';
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Centralized Constants
3
+ * Loads constants from validation-config.json to avoid duplication
4
+ * Provides easy access to domain templates, timeouts, and other config
5
+ */
6
+
7
+ import { readFileSync } from 'fs';
8
+ import { join, dirname } from 'path';
9
+ import { fileURLToPath } from 'url';
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+
13
+ // Load validation config
14
+ let validationConfig;
15
+ try {
16
+ const configPath = join(__dirname, '..', '..', 'config', 'validation-config.json');
17
+ validationConfig = JSON.parse(readFileSync(configPath, 'utf-8'));
18
+ } catch (error) {
19
+ console.warn('⚠️ Could not load validation-config.json, using fallback constants');
20
+ validationConfig = null;
21
+ }
22
+
23
+ /**
24
+ * Get domain template for environment
25
+ * @param {string} environment - Environment name (development, staging, production)
26
+ * @returns {string} Domain template pattern
27
+ */
28
+ export function getDomainTemplate(environment = 'production') {
29
+ if (validationConfig?.environments?.[environment]?.domainTemplate) {
30
+ return validationConfig.environments[environment].domainTemplate;
31
+ }
32
+
33
+ // Fallback templates if config not available
34
+ const fallbacks = {
35
+ production: '{service}.{domain}',
36
+ staging: 'staging-{service}.{domain}',
37
+ development: 'dev-{service}.{domain}'
38
+ };
39
+ return fallbacks[environment] || fallbacks.production;
40
+ }
41
+
42
+ /**
43
+ * Build custom domain URL from template
44
+ * @param {string} serviceName - Service name
45
+ * @param {string} domain - Base domain (e.g., clodo.dev)
46
+ * @param {string} environment - Environment name
47
+ * @returns {string} Full custom domain URL
48
+ */
49
+ export function buildCustomDomain(serviceName, domain, environment = 'production') {
50
+ const template = getDomainTemplate(environment);
51
+ const subdomain = template.replace('{service}', serviceName).replace('{domain}', domain);
52
+ return `https://${subdomain}`;
53
+ }
54
+
55
+ /**
56
+ * Get environment-specific worker suffix
57
+ * @param {string} environment - Environment name
58
+ * @returns {string} Worker suffix (e.g., '-dev', '-staging', '')
59
+ */
60
+ export function getWorkerSuffix(environment = 'production') {
61
+ return validationConfig?.environments?.[environment]?.workerSuffix || '';
62
+ }
63
+
64
+ /**
65
+ * Get environment-specific database suffix
66
+ * @param {string} environment - Environment name
67
+ * @returns {string} Database suffix (e.g., '-dev', '-staging', '')
68
+ */
69
+ export function getDatabaseSuffix(environment = 'production') {
70
+ return validationConfig?.environments?.[environment]?.databaseSuffix || '';
71
+ }
72
+
73
+ /**
74
+ * Get timing configuration
75
+ * @param {string} key - Timing key
76
+ * @returns {number} Timeout in milliseconds
77
+ */
78
+ export function getTimeout(key) {
79
+ return validationConfig?.timing?.[key] || 30000; // Default 30s
80
+ }
81
+
82
+ /**
83
+ * Get all service types
84
+ * @returns {string[]} Array of valid service types
85
+ */
86
+ export function getServiceTypes() {
87
+ return validationConfig?.validation?.serviceTypes || ['data-service', 'auth-service', 'content-service', 'api-gateway', 'static-site', 'generic'];
88
+ }
89
+
90
+ /**
91
+ * Export full config for direct access if needed
92
+ */
93
+ export const VALIDATION_CONFIG = validationConfig;
94
+
95
+ /**
96
+ * Common constants
97
+ */
98
+ export const CONSTANTS = {
99
+ DEFAULT_ENVIRONMENT: 'production',
100
+ SUPPORTED_ENVIRONMENTS: ['development', 'staging', 'production'],
101
+ WORKERS_DEV_SUFFIX: '.workers.dev'
102
+ };