@tamyla/clodo-framework 3.1.22 → 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 (208) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +230 -1
  3. package/dist/cli/commands/assess.js +183 -0
  4. package/dist/cli/commands/create.js +77 -0
  5. package/dist/{bin → cli}/commands/deploy.js +8 -8
  6. package/dist/cli/commands/diagnose.js +83 -0
  7. package/dist/{bin → cli}/commands/helpers/deployment-verification.js +2 -3
  8. package/dist/{bin → cli}/commands/helpers/error-recovery.js +1 -1
  9. package/dist/{bin → cli}/commands/helpers/resource-detection.js +1 -1
  10. package/dist/cli/commands/helpers.js +110 -0
  11. package/dist/cli/commands/init-config.js +57 -0
  12. package/dist/cli/commands/update.js +75 -0
  13. package/dist/{bin → cli}/commands/validate.js +5 -5
  14. package/dist/cli/security-cli.js +118 -0
  15. package/dist/config/FeatureManager.js +6 -0
  16. package/dist/config/clodo-create.example.json +26 -0
  17. package/dist/config/clodo-deploy.example.json +41 -0
  18. package/dist/config/clodo-update.example.json +46 -0
  19. package/dist/config/clodo-validate.example.json +41 -0
  20. package/dist/config/customers/template/development.env.template +37 -0
  21. package/dist/config/customers/template/production.env.template +39 -0
  22. package/dist/config/customers/template/staging.env.template +37 -0
  23. package/dist/config/customers.js +625 -0
  24. package/dist/config/domain-examples/README.md +464 -0
  25. package/dist/config/domain-examples/environment-mapped.json +168 -0
  26. package/dist/config/domain-examples/multi-domain.json +144 -0
  27. package/dist/config/domain-examples/single-domain.json +50 -0
  28. package/dist/config/domains.js +186 -0
  29. package/dist/config/examples +12 -0
  30. package/dist/config/features.js +61 -0
  31. package/dist/config/index.js +6 -0
  32. package/dist/config/staging-deployment.json +60 -0
  33. package/dist/config/validation-config.json +347 -0
  34. package/dist/database/database-orchestrator.js +795 -0
  35. package/dist/database/index.js +4 -0
  36. package/dist/deployment/index.js +11 -0
  37. package/dist/deployment/orchestration/BaseDeploymentOrchestrator.js +426 -0
  38. package/dist/deployment/orchestration/PortfolioOrchestrator.js +273 -0
  39. package/dist/deployment/orchestration/SingleServiceOrchestrator.js +231 -0
  40. package/dist/deployment/orchestration/UnifiedDeploymentOrchestrator.js +662 -0
  41. package/dist/deployment/orchestration/index.js +17 -0
  42. package/dist/deployment/rollback-manager.js +36 -0
  43. package/dist/deployment/wrangler-deployer.js +640 -0
  44. package/dist/handlers/GenericRouteHandler.js +532 -0
  45. package/dist/lib/database/deployment-db-manager.js +423 -0
  46. package/dist/lib/database/wrangler-d1-manager.js +685 -0
  47. package/dist/lib/deployment/modules/DeploymentConfiguration.js +395 -0
  48. package/dist/lib/deployment/modules/DeploymentOrchestrator.js +492 -0
  49. package/dist/lib/deployment/modules/EnvironmentManager.js +517 -0
  50. package/dist/lib/deployment/modules/MonitoringIntegration.js +560 -0
  51. package/dist/lib/deployment/modules/ValidationManager.js +342 -0
  52. package/dist/lib/deployment/orchestration/BaseDeploymentOrchestrator.js +426 -0
  53. package/dist/lib/deployment/orchestration/EnterpriseOrchestrator.js +21 -0
  54. package/dist/lib/deployment/orchestration/PortfolioOrchestrator.js +273 -0
  55. package/dist/lib/deployment/orchestration/SingleServiceOrchestrator.js +231 -0
  56. package/dist/lib/deployment/orchestration/UnifiedDeploymentOrchestrator.js +662 -0
  57. package/dist/{bin → lib}/shared/cloudflare/domain-discovery.js +1 -1
  58. package/dist/{bin → lib}/shared/cloudflare/domain-manager.js +1 -1
  59. package/dist/{bin → lib}/shared/cloudflare/ops.js +4 -4
  60. package/dist/{bin → lib}/shared/config/command-config-manager.js +1 -1
  61. package/dist/{bin → lib}/shared/config/index.js +1 -1
  62. package/dist/{bin → lib}/shared/deployment/credential-collector.js +1 -1
  63. package/dist/lib/shared/deployment/index.js +10 -0
  64. package/dist/{bin → lib}/shared/deployment/rollback-manager.js +1 -1
  65. package/dist/{bin → lib}/shared/deployment/utilities/d1-error-recovery.js +1 -1
  66. package/dist/{bin → lib}/shared/deployment/validator.js +1 -1
  67. package/dist/{bin → lib}/shared/deployment/workflows/interactive-database-workflow.js +1 -1
  68. package/dist/{bin → lib}/shared/monitoring/health-checker.js +2 -2
  69. package/dist/{bin → lib}/shared/routing/domain-router.js +1 -1
  70. package/dist/{bin → lib}/shared/validation/ValidationRegistry.js +1 -1
  71. package/dist/migration/MigrationAdapters.js +608 -0
  72. package/dist/modules/ModuleManager.js +668 -0
  73. package/dist/modules/security.js +96 -0
  74. package/dist/orchestration/cross-domain-coordinator.js +1083 -0
  75. package/dist/orchestration/index.js +5 -0
  76. package/dist/orchestration/modules/DeploymentCoordinator.js +368 -0
  77. package/dist/orchestration/modules/DomainResolver.js +198 -0
  78. package/dist/orchestration/modules/StateManager.js +332 -0
  79. package/dist/orchestration/multi-domain-orchestrator.js +765 -0
  80. package/dist/routing/EnhancedRouter.js +158 -0
  81. package/dist/schema/SchemaManager.js +778 -0
  82. package/dist/security/index.js +2 -2
  83. package/dist/service-management/ConfirmationEngine.js +412 -0
  84. package/dist/service-management/ErrorTracker.js +299 -0
  85. package/dist/service-management/GenerationEngine.js +447 -0
  86. package/dist/service-management/InputCollector.js +619 -0
  87. package/dist/service-management/ServiceCreator.js +21 -0
  88. package/dist/service-management/ServiceOrchestrator.js +631 -0
  89. package/dist/service-management/generators/BaseGenerator.js +233 -0
  90. package/dist/service-management/generators/GeneratorRegistry.js +254 -0
  91. package/dist/service-management/generators/cicd/CiWorkflowGenerator.js +87 -0
  92. package/dist/service-management/generators/cicd/DeployWorkflowGenerator.js +106 -0
  93. package/dist/service-management/generators/code/ServiceHandlersGenerator.js +235 -0
  94. package/dist/service-management/generators/code/ServiceMiddlewareGenerator.js +116 -0
  95. package/dist/service-management/generators/code/ServiceUtilsGenerator.js +246 -0
  96. package/dist/service-management/generators/code/WorkerIndexGenerator.js +143 -0
  97. package/dist/service-management/generators/config/DevelopmentEnvGenerator.js +101 -0
  98. package/dist/service-management/generators/config/DomainsConfigGenerator.js +175 -0
  99. package/dist/service-management/generators/config/EnvExampleGenerator.js +178 -0
  100. package/dist/service-management/generators/config/ProductionEnvGenerator.js +97 -0
  101. package/dist/service-management/generators/config/StagingEnvGenerator.js +97 -0
  102. package/dist/service-management/generators/config/WranglerTomlGenerator.js +238 -0
  103. package/dist/service-management/generators/core/PackageJsonGenerator.js +243 -0
  104. package/dist/service-management/generators/core/SiteConfigGenerator.js +115 -0
  105. package/dist/service-management/generators/documentation/ApiDocsGenerator.js +331 -0
  106. package/dist/service-management/generators/documentation/ConfigurationDocsGenerator.js +294 -0
  107. package/dist/service-management/generators/documentation/DeploymentDocsGenerator.js +244 -0
  108. package/dist/service-management/generators/documentation/ReadmeGenerator.js +196 -0
  109. package/dist/service-management/generators/schemas/ServiceSchemaGenerator.js +190 -0
  110. package/dist/service-management/generators/scripts/DeployScriptGenerator.js +123 -0
  111. package/dist/service-management/generators/scripts/HealthCheckScriptGenerator.js +101 -0
  112. package/dist/service-management/generators/scripts/SetupScriptGenerator.js +88 -0
  113. package/dist/service-management/generators/service-types/StaticSiteGenerator.js +342 -0
  114. package/dist/service-management/generators/testing/EslintConfigGenerator.js +85 -0
  115. package/dist/service-management/generators/testing/IntegrationTestsGenerator.js +237 -0
  116. package/dist/service-management/generators/testing/JestConfigGenerator.js +72 -0
  117. package/dist/service-management/generators/testing/UnitTestsGenerator.js +277 -0
  118. package/dist/service-management/generators/tooling/DockerComposeGenerator.js +71 -0
  119. package/dist/service-management/generators/tooling/GitignoreGenerator.js +143 -0
  120. package/dist/service-management/generators/utils/FileWriter.js +179 -0
  121. package/dist/service-management/generators/utils/PathResolver.js +157 -0
  122. package/dist/service-management/generators/utils/ServiceManifestGenerator.js +111 -0
  123. package/dist/service-management/generators/utils/TemplateEngine.js +185 -0
  124. package/dist/service-management/generators/utils/index.js +18 -0
  125. package/dist/service-management/handlers/ConfirmationHandler.js +71 -0
  126. package/dist/service-management/handlers/GenerationHandler.js +80 -0
  127. package/dist/service-management/handlers/InputHandler.js +59 -0
  128. package/dist/service-management/handlers/ValidationHandler.js +203 -0
  129. package/dist/service-management/index.js +14 -0
  130. package/dist/service-management/routing/DomainRouteMapper.js +311 -0
  131. package/dist/service-management/routing/RouteGenerator.js +266 -0
  132. package/dist/service-management/routing/WranglerRoutesBuilder.js +273 -0
  133. package/dist/service-management/routing/index.js +14 -0
  134. package/dist/service-management/services/DirectoryStructureService.js +56 -0
  135. package/dist/service-management/services/GenerationCoordinator.js +208 -0
  136. package/dist/service-management/services/GeneratorRegistry.js +174 -0
  137. package/dist/services/GenericDataService.js +501 -0
  138. package/dist/ui-structures/concepts/second-order-acquisition-strategy.md +286 -0
  139. package/dist/ui-structures/concepts/service-lifecycle-management.md +150 -0
  140. package/dist/ui-structures/concepts/service-manifest-guide.md +309 -0
  141. package/dist/ui-structures/concepts/three-tier-categorization-strategy.md +231 -0
  142. package/dist/ui-structures/creation/automated-generation-ui.json +246 -0
  143. package/dist/ui-structures/creation/core-inputs-ui.json +217 -0
  144. package/dist/ui-structures/creation/smart-confirmable-ui.json +451 -0
  145. package/dist/ui-structures/reference/absolutely-required-inputs.json +315 -0
  146. package/dist/ui-structures/reference/service-manifest-template.json +342 -0
  147. package/dist/utils/cloudflare/ops.js +1 -1
  148. package/dist/utils/file-manager.js +1 -1
  149. package/dist/utils/formatters.js +1 -1
  150. package/dist/utils/logger.js +1 -1
  151. package/dist/version/VersionDetector.js +813 -0
  152. package/dist/worker/index.js +4 -0
  153. package/dist/worker/integration.js +351 -0
  154. package/package.json +7 -15
  155. package/dist/bin/security/security-cli.js +0 -108
  156. package/dist/bin/shared/deployment/index.js +0 -10
  157. /package/dist/{bin → cli}/clodo-service.js +0 -0
  158. /package/dist/{bin → cli}/commands/helpers/deployment-ui.js +0 -0
  159. /package/dist/{bin → lib}/shared/cache/configuration-cache.js +0 -0
  160. /package/dist/{bin → lib}/shared/cloudflare/index.js +0 -0
  161. /package/dist/{bin → lib}/shared/config/ConfigurationManager.js +0 -0
  162. /package/dist/{bin → lib}/shared/config/cache.js +0 -0
  163. /package/dist/{bin → lib}/shared/config/cloudflare-service-validator.js +0 -0
  164. /package/dist/{bin → lib}/shared/config/manager.js +0 -0
  165. /package/dist/{bin → lib}/shared/config/manifest-loader.js +0 -0
  166. /package/dist/{bin → lib}/shared/database/connection-manager.js +0 -0
  167. /package/dist/{bin → lib}/shared/database/index.js +0 -0
  168. /package/dist/{bin → lib}/shared/database/orchestrator.js +0 -0
  169. /package/dist/{bin → lib}/shared/deployment/auditor.js +0 -0
  170. /package/dist/{bin → lib}/shared/deployment/workflows/deployment-summary.js +0 -0
  171. /package/dist/{bin → lib}/shared/deployment/workflows/interactive-confirmation.js +0 -0
  172. /package/dist/{bin → lib}/shared/deployment/workflows/interactive-domain-info-gatherer.js +0 -0
  173. /package/dist/{bin → lib}/shared/deployment/workflows/interactive-secret-workflow.js +0 -0
  174. /package/dist/{bin → lib}/shared/deployment/workflows/interactive-testing-workflow.js +0 -0
  175. /package/dist/{bin → lib}/shared/deployment/workflows/interactive-validation.js +0 -0
  176. /package/dist/{bin → lib}/shared/error-handling/error-classifier.js +0 -0
  177. /package/dist/{bin → lib}/shared/index.js +0 -0
  178. /package/dist/{bin → lib}/shared/logging/Logger.js +0 -0
  179. /package/dist/{bin → lib}/shared/monitoring/index.js +0 -0
  180. /package/dist/{bin → lib}/shared/monitoring/memory-manager.js +0 -0
  181. /package/dist/{bin → lib}/shared/monitoring/production-monitor.js +0 -0
  182. /package/dist/{bin → lib}/shared/production-tester/api-tester.js +0 -0
  183. /package/dist/{bin → lib}/shared/production-tester/auth-tester.js +0 -0
  184. /package/dist/{bin → lib}/shared/production-tester/core.js +0 -0
  185. /package/dist/{bin → lib}/shared/production-tester/database-tester.js +0 -0
  186. /package/dist/{bin → lib}/shared/production-tester/index.js +0 -0
  187. /package/dist/{bin → lib}/shared/production-tester/load-tester.js +0 -0
  188. /package/dist/{bin → lib}/shared/production-tester/performance-tester.js +0 -0
  189. /package/dist/{bin → lib}/shared/security/api-token-manager.js +0 -0
  190. /package/dist/{bin → lib}/shared/security/index.js +0 -0
  191. /package/dist/{bin → lib}/shared/security/secret-generator.js +0 -0
  192. /package/dist/{bin → lib}/shared/security/secure-token-manager.js +0 -0
  193. /package/dist/{bin → lib}/shared/utils/ErrorHandler.js +0 -0
  194. /package/dist/{bin → lib}/shared/utils/cli-options.js +0 -0
  195. /package/dist/{bin → lib}/shared/utils/config-loader.js +0 -0
  196. /package/dist/{bin → lib}/shared/utils/deployment-validator.js +0 -0
  197. /package/dist/{bin → lib}/shared/utils/error-recovery.js +0 -0
  198. /package/dist/{bin → lib}/shared/utils/file-manager.js +0 -0
  199. /package/dist/{bin → lib}/shared/utils/formatters.js +0 -0
  200. /package/dist/{bin → lib}/shared/utils/graceful-shutdown-manager.js +0 -0
  201. /package/dist/{bin → lib}/shared/utils/index.js +0 -0
  202. /package/dist/{bin → lib}/shared/utils/interactive-prompts.js +0 -0
  203. /package/dist/{bin → lib}/shared/utils/interactive-utils.js +0 -0
  204. /package/dist/{bin → lib}/shared/utils/output-formatter.js +0 -0
  205. /package/dist/{bin → lib}/shared/utils/progress-manager.js +0 -0
  206. /package/dist/{bin → lib}/shared/utils/progress-spinner.js +0 -0
  207. /package/dist/{bin → lib}/shared/utils/rate-limiter.js +0 -0
  208. /package/dist/{bin → lib}/shared/utils/sensitive-redactor.js +0 -0
@@ -0,0 +1,85 @@
1
+ import { BaseGenerator } from '../BaseGenerator.js';
2
+ import { join } from 'path';
3
+ import { writeFileSync } from 'fs';
4
+
5
+ /**
6
+ * ESLint Configuration Generator
7
+ * Generates ESLint linting configuration for code quality
8
+ */
9
+ export class EslintConfigGenerator extends BaseGenerator {
10
+ /**
11
+ * Generate ESLint configuration
12
+ * @param {Object} context - Generation context
13
+ * @returns {Promise<string>} Path to generated config file
14
+ */
15
+ async generate(context) {
16
+ const {
17
+ coreInputs,
18
+ confirmedValues,
19
+ servicePath
20
+ } = this.extractContext(context);
21
+ if (!this.shouldGenerate(context)) {
22
+ return null;
23
+ }
24
+ const eslintConfig = this._generateEslintConfig(coreInputs, confirmedValues);
25
+ const filePath = join(servicePath, '.eslintrc.js');
26
+ writeFileSync(filePath, eslintConfig, 'utf8');
27
+ return filePath;
28
+ }
29
+
30
+ /**
31
+ * Generate ESLint configuration content
32
+ * @private
33
+ */
34
+ _generateEslintConfig(coreInputs, confirmedValues) {
35
+ return `export default [
36
+ {
37
+ languageOptions: {
38
+ ecmaVersion: 2022,
39
+ sourceType: 'module',
40
+ globals: {
41
+ console: 'readonly',
42
+ process: 'readonly',
43
+ Buffer: 'readonly',
44
+ crypto: 'readonly',
45
+ fetch: 'readonly',
46
+ Request: 'readonly',
47
+ Response: 'readonly',
48
+ URL: 'readonly',
49
+ Headers: 'readonly',
50
+ describe: 'readonly',
51
+ test: 'readonly',
52
+ expect: 'readonly',
53
+ beforeAll: 'readonly',
54
+ afterAll: 'readonly',
55
+ beforeEach: 'readonly',
56
+ afterEach: 'readonly'
57
+ }
58
+ },
59
+ rules: {
60
+ 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
61
+ 'no-console': 'off', // Cloudflare Workers use console
62
+ 'prefer-const': 'error',
63
+ 'no-var': 'error',
64
+ 'object-shorthand': 'error',
65
+ 'prefer-arrow-callback': 'error',
66
+ 'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0 }],
67
+ 'semi': ['error', 'always'],
68
+ 'quotes': ['error', 'single', { avoidEscape: true }],
69
+ 'comma-dangle': ['error', 'never'],
70
+ 'indent': ['error', 2, { SwitchCase: 1 }],
71
+ 'linebreak-style': ['error', 'unix'],
72
+ 'eol-last': ['error', 'always']
73
+ }
74
+ }
75
+ ];
76
+ `;
77
+ }
78
+
79
+ /**
80
+ * Determine if generator should run
81
+ */
82
+ shouldGenerate(context) {
83
+ return true; // Always generate ESLint config
84
+ }
85
+ }
@@ -0,0 +1,237 @@
1
+ import { BaseGenerator } from '../BaseGenerator.js';
2
+ import { join } from 'path';
3
+ import { writeFileSync, mkdirSync } from 'fs';
4
+
5
+ /**
6
+ * Integration Tests Generator
7
+ * Generates integration tests for end-to-end service testing
8
+ */
9
+ export class IntegrationTestsGenerator extends BaseGenerator {
10
+ /**
11
+ * Generate integration tests
12
+ * @param {Object} context - Generation context
13
+ * @returns {Promise<string>} Path to generated test file
14
+ */
15
+ async generate(context) {
16
+ const {
17
+ coreInputs,
18
+ confirmedValues,
19
+ servicePath
20
+ } = this.extractContext(context);
21
+ if (!this.shouldGenerate(context)) {
22
+ return null;
23
+ }
24
+
25
+ // Ensure test/integration directory exists
26
+ const testDir = join(servicePath, 'test', 'integration');
27
+ mkdirSync(testDir, {
28
+ recursive: true
29
+ });
30
+ const integrationTestContent = this._generateIntegrationTestContent(coreInputs, confirmedValues);
31
+ const filePath = join(testDir, 'service.integration.test.js');
32
+ writeFileSync(filePath, integrationTestContent, 'utf8');
33
+ return filePath;
34
+ }
35
+
36
+ /**
37
+ * Generate integration test content
38
+ * @private
39
+ */
40
+ _generateIntegrationTestContent(coreInputs, confirmedValues) {
41
+ return `import { describe, test, expect, beforeAll, afterAll } from '@jest/globals';
42
+
43
+ describe('${confirmedValues.displayName} - Integration Tests', () => {
44
+ let baseUrl;
45
+
46
+ beforeAll(() => {
47
+ baseUrl = process.env.TEST_URL || '${confirmedValues.developmentUrl}';
48
+ });
49
+
50
+ afterAll(() => {
51
+ // Cleanup after tests
52
+ });
53
+
54
+ describe('Health Check Endpoint', () => {
55
+ test('responds with 200 status', async () => {
56
+ const response = await fetch(\`\${baseUrl}${confirmedValues.healthCheckPath}\`);
57
+ expect(response.status).toBe(200);
58
+ });
59
+
60
+ test('returns valid health check response', async () => {
61
+ const response = await fetch(\`\${baseUrl}${confirmedValues.healthCheckPath}\`);
62
+ const json = await response.json();
63
+
64
+ expect(json.status).toBe('healthy');
65
+ expect(json.service).toBe('${coreInputs.serviceName}');
66
+ expect(json.version).toBe('${confirmedValues.version}');
67
+ expect(json.timestamp).toBeDefined();
68
+ });
69
+
70
+ test('includes health checks', async () => {
71
+ const response = await fetch(\`\${baseUrl}${confirmedValues.healthCheckPath}\`);
72
+ const json = await response.json();
73
+
74
+ expect(Array.isArray(json.checks)).toBe(true);
75
+ expect(json.checks.length).toBeGreaterThan(0);
76
+ });
77
+ });
78
+
79
+ describe('API Endpoints', () => {
80
+ test('base API path is accessible', async () => {
81
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}\`);
82
+ expect(response.status).toBeLessThan(500); // Should not be a server error
83
+ });
84
+
85
+ ${this._generateServiceTypeTests(coreInputs.serviceType, confirmedValues)}
86
+ });
87
+
88
+ ${confirmedValues.features.caching ? `
89
+ describe('Caching', () => {
90
+ test('cache headers are present', async () => {
91
+ const response = await fetch(\`\${baseUrl}${confirmedValues.healthCheckPath}\`);
92
+
93
+ // Check for cache-related headers
94
+ const cacheControl = response.headers.get('cache-control');
95
+ expect(cacheControl).toBeDefined();
96
+ });
97
+
98
+ test('repeated requests use cache', async () => {
99
+ const response1 = await fetch(\`\${baseUrl}${confirmedValues.healthCheckPath}\`);
100
+ const response2 = await fetch(\`\${baseUrl}${confirmedValues.healthCheckPath}\`);
101
+
102
+ expect(response1.status).toBe(200);
103
+ expect(response2.status).toBe(200);
104
+ });
105
+ });` : ''}
106
+
107
+ ${confirmedValues.features.database ? `
108
+ describe('Database Integration', () => {
109
+ test('database connectivity', async () => {
110
+ const response = await fetch(\`\${baseUrl}${confirmedValues.healthCheckPath}\`);
111
+ const json = await response.json();
112
+
113
+ const dbCheck = json.checks.find(check => check.name === 'database');
114
+ expect(dbCheck).toBeDefined();
115
+ expect(dbCheck.status).toBe('healthy');
116
+ });
117
+
118
+ test('CRUD operations', async () => {
119
+ // Test Create, Read, Update, Delete operations
120
+ expect(true).toBe(true); // Placeholder
121
+ });
122
+ });` : `
123
+ describe('Database Integration', () => {
124
+ test.skip('database tests skipped - not enabled for this service type', () => {
125
+ expect(true).toBe(true);
126
+ });
127
+ });`}
128
+
129
+ describe('Middleware Integration', () => {
130
+ test('request headers added', async () => {
131
+ const response = await fetch(\`\${baseUrl}${confirmedValues.healthCheckPath}\`);
132
+
133
+ expect(response.headers.get('x-service')).toBe('${coreInputs.serviceName}');
134
+ expect(response.headers.get('x-version')).toBe('${confirmedValues.version}');
135
+ });
136
+
137
+ ${confirmedValues.features.authentication ? `
138
+ test('authentication middleware', async () => {
139
+ // Test authentication requirements
140
+ expect(true).toBe(true); // Placeholder
141
+ });` : ''}
142
+
143
+ ${confirmedValues.features.authorization ? `
144
+ test('authorization middleware', async () => {
145
+ // Test authorization checks
146
+ expect(true).toBe(true); // Placeholder
147
+ });` : ''}
148
+ });
149
+
150
+ describe('Error Handling', () => {
151
+ test('graceful error responses', async () => {
152
+ // Test error scenarios
153
+ expect(true).toBe(true); // Placeholder
154
+ });
155
+
156
+ test('error logging', async () => {
157
+ // Test error logging functionality
158
+ expect(true).toBe(true); // Placeholder
159
+ });
160
+ });
161
+ });
162
+ `;
163
+ }
164
+
165
+ /**
166
+ * Generate service-type specific integration tests
167
+ * @private
168
+ */
169
+ _generateServiceTypeTests(serviceType, confirmedValues) {
170
+ switch (serviceType) {
171
+ case 'data-service':
172
+ return `test('data retrieval endpoint', async () => {
173
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}/data\`);
174
+ expect(response.status).toBeLessThan(500);
175
+ });
176
+
177
+ test('data storage endpoint', async () => {
178
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}/data\`, {
179
+ method: 'POST',
180
+ headers: { 'Content-Type': 'application/json' },
181
+ body: JSON.stringify({ test: 'data' })
182
+ });
183
+ expect(response.status).toBeLessThan(500);
184
+ });`;
185
+ case 'auth-service':
186
+ return `test('login endpoint', async () => {
187
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}/login\`, {
188
+ method: 'POST',
189
+ headers: { 'Content-Type': 'application/json' },
190
+ body: JSON.stringify({ username: 'test', password: 'test' })
191
+ });
192
+ expect(response.status).toBeLessThan(500);
193
+ });
194
+
195
+ test('token validation endpoint', async () => {
196
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}/validate\`);
197
+ expect(response.status).toBeLessThan(500);
198
+ });`;
199
+ case 'content-service':
200
+ return `test('content retrieval endpoint', async () => {
201
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}/content\`);
202
+ expect(response.status).toBeLessThan(500);
203
+ });
204
+
205
+ test('content creation endpoint', async () => {
206
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}/content\`, {
207
+ method: 'POST',
208
+ headers: { 'Content-Type': 'application/json' },
209
+ body: JSON.stringify({ title: 'Test', body: 'Content' })
210
+ });
211
+ expect(response.status).toBeLessThan(500);
212
+ });`;
213
+ case 'api-gateway':
214
+ return `test('gateway routing', async () => {
215
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}/route\`);
216
+ expect(response.status).toBeLessThan(500);
217
+ });
218
+
219
+ test('service proxying', async () => {
220
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}/proxy\`);
221
+ expect(response.status).toBeLessThan(500);
222
+ });`;
223
+ default:
224
+ return `test('service endpoints are accessible', async () => {
225
+ const response = await fetch(\`\${baseUrl}${confirmedValues.apiBasePath}\`);
226
+ expect(response.status).toBeLessThan(500);
227
+ });`;
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Determine if generator should run
233
+ */
234
+ shouldGenerate(context) {
235
+ return true; // Always generate integration tests
236
+ }
237
+ }
@@ -0,0 +1,72 @@
1
+ import { BaseGenerator } from '../BaseGenerator.js';
2
+ import { join } from 'path';
3
+ import { writeFileSync } from 'fs';
4
+
5
+ /**
6
+ * Jest Configuration Generator
7
+ * Generates Jest test runner configuration
8
+ */
9
+ export class JestConfigGenerator extends BaseGenerator {
10
+ /**
11
+ * Generate Jest configuration
12
+ * @param {Object} context - Generation context
13
+ * @returns {Promise<string>} Path to generated config file
14
+ */
15
+ async generate(context) {
16
+ const {
17
+ coreInputs,
18
+ confirmedValues,
19
+ servicePath
20
+ } = this.extractContext(context);
21
+ if (!this.shouldGenerate(context)) {
22
+ return null;
23
+ }
24
+ const jestConfig = this._generateJestConfig(coreInputs, confirmedValues);
25
+ const filePath = join(servicePath, 'jest.config.js');
26
+ writeFileSync(filePath, jestConfig, 'utf8');
27
+ return filePath;
28
+ }
29
+
30
+ /**
31
+ * Generate Jest configuration content
32
+ * @private
33
+ */
34
+ _generateJestConfig(coreInputs, confirmedValues) {
35
+ return `/** @type {import('jest').Config} */
36
+ export default {
37
+ testEnvironment: 'node',
38
+ testMatch: [
39
+ '<rootDir>/test/**/*.test.js'
40
+ ],
41
+ collectCoverageFrom: [
42
+ 'src/**/*.js',
43
+ '!src/worker/index.js' // Worker code runs in different environment
44
+ ],
45
+ coverageDirectory: 'coverage',
46
+ coverageReporters: ['text', 'lcov', 'html'],
47
+ coverageThreshold: {
48
+ global: {
49
+ branches: 70,
50
+ functions: 80,
51
+ lines: 80,
52
+ statements: 80
53
+ }
54
+ },
55
+ setupFilesAfterEnv: ['<rootDir>/test/setup.js'],
56
+ testTimeout: 10000,
57
+ verbose: true,
58
+ transform: {},
59
+ moduleNameMapper: {
60
+ '^(\\.{1,2}/.*)\\.js$': '$1'
61
+ }
62
+ };
63
+ `;
64
+ }
65
+
66
+ /**
67
+ * Determine if generator should run
68
+ */
69
+ shouldGenerate(context) {
70
+ return true; // Always generate Jest config
71
+ }
72
+ }
@@ -0,0 +1,277 @@
1
+ import { BaseGenerator } from '../BaseGenerator.js';
2
+ import { join } from 'path';
3
+ import { writeFileSync, mkdirSync } from 'fs';
4
+
5
+ /**
6
+ * Unit Tests Generator
7
+ * Generates comprehensive unit test suites for service components
8
+ */
9
+ export class UnitTestsGenerator extends BaseGenerator {
10
+ /**
11
+ * Generate unit tests
12
+ * @param {Object} context - Generation context
13
+ * @param {Object} context.coreInputs - Core service inputs
14
+ * @param {Object} context.confirmedValues - Confirmed configuration values
15
+ * @param {string} context.servicePath - Service directory path
16
+ * @returns {Promise<string>} Path to generated test file
17
+ */
18
+ async generate(context) {
19
+ const {
20
+ coreInputs,
21
+ confirmedValues,
22
+ servicePath
23
+ } = this.extractContext(context);
24
+ if (!this.shouldGenerate(context)) {
25
+ return null;
26
+ }
27
+
28
+ // Ensure test/unit directory exists
29
+ const testDir = join(servicePath, 'test', 'unit');
30
+ mkdirSync(testDir, {
31
+ recursive: true
32
+ });
33
+ const unitTestContent = this._generateUnitTestContent(coreInputs, confirmedValues);
34
+ const filePath = join(testDir, 'service.test.js');
35
+ writeFileSync(filePath, unitTestContent, 'utf8');
36
+ return filePath;
37
+ }
38
+
39
+ /**
40
+ * Generate unit test content
41
+ * @private
42
+ */
43
+ _generateUnitTestContent(coreInputs, confirmedValues) {
44
+ return `import { describe, test, expect } from '@jest/globals';
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
+
50
+ describe('${confirmedValues.displayName} - Unit Tests', () => {
51
+ describe('Handlers', () => {
52
+ test('exports required handler functions', () => {
53
+ expect(typeof serviceHandlers.handleRequest).toBe('function');
54
+ expect(typeof serviceHandlers.handleError).toBe('function');
55
+ });
56
+
57
+ test('handleError returns proper error response', async () => {
58
+ const error = new Error('Test error');
59
+ const request = new Request('https://example.com/test');
60
+
61
+ const response = await serviceHandlers.handleError(error, request);
62
+ expect(response.status).toBeGreaterThanOrEqual(400);
63
+
64
+ const json = await response.json();
65
+ expect(json.success).toBe(false);
66
+ expect(json.error).toBeDefined();
67
+ });
68
+
69
+ ${confirmedValues.features.caching ? `
70
+ test('cache handlers work correctly', () => {
71
+ expect(typeof serviceHandlers.handleCacheHit).toBe('function');
72
+ expect(typeof serviceHandlers.handleCacheMiss).toBe('function');
73
+ });` : ''}
74
+
75
+ ${confirmedValues.features.database ? `
76
+ test('database handlers are defined', () => {
77
+ expect(typeof serviceHandlers.handleDatabaseQuery).toBe('function');
78
+ expect(typeof serviceHandlers.handleDatabaseError).toBe('function');
79
+ });` : ''}
80
+ });
81
+
82
+ describe('Middleware', () => {
83
+ test('exports middleware functions', () => {
84
+ expect(typeof serviceMiddleware.addHeaders).toBe('function');
85
+ expect(typeof serviceMiddleware.handleCors).toBe('function');
86
+ });
87
+
88
+ test('addHeaders adds service headers', () => {
89
+ const headers = new Headers();
90
+ serviceMiddleware.addHeaders(headers);
91
+
92
+ expect(headers.get('x-service')).toBe('${coreInputs.serviceName}');
93
+ expect(headers.get('x-version')).toBe('${confirmedValues.version}');
94
+ });
95
+
96
+ test('handleCors adds CORS headers', () => {
97
+ const headers = new Headers();
98
+ serviceMiddleware.handleCors(headers);
99
+
100
+ expect(headers.has('Access-Control-Allow-Origin')).toBe(true);
101
+ });
102
+
103
+ ${confirmedValues.features.authentication ? `
104
+ test('authentication middleware validates tokens', () => {
105
+ expect(typeof serviceMiddleware.authenticateRequest).toBe('function');
106
+ });` : ''}
107
+
108
+ ${confirmedValues.features.authorization ? `
109
+ test('authorization middleware checks permissions', () => {
110
+ expect(typeof serviceMiddleware.authorizeRequest).toBe('function');
111
+ });` : ''}
112
+
113
+ ${confirmedValues.features.rateLimiting ? `
114
+ test('rate limiting middleware tracks requests', () => {
115
+ expect(typeof serviceMiddleware.checkRateLimit).toBe('function');
116
+ });` : ''}
117
+ });
118
+
119
+ describe('Utilities', () => {
120
+ test('exports utility functions', () => {
121
+ expect(typeof serviceUtils.formatResponse).toBe('function');
122
+ expect(typeof serviceUtils.validateInput).toBe('function');
123
+ });
124
+
125
+ test('formatResponse creates proper response format', () => {
126
+ const data = { test: 'value' };
127
+ const formatted = serviceUtils.formatResponse(data);
128
+
129
+ expect(formatted.success).toBe(true);
130
+ expect(formatted.data).toEqual(data);
131
+ expect(formatted.timestamp).toBeDefined();
132
+ });
133
+
134
+ test('validateInput uses service schema', () => {
135
+ const result = serviceUtils.validateInput({}, serviceSchema);
136
+ expect(result).toBeDefined();
137
+ });
138
+
139
+ ${confirmedValues.features.database ? `
140
+ test('database utilities handle connections', () => {
141
+ expect(typeof serviceUtils.getDatabaseConnection).toBe('function');
142
+ });` : ''}
143
+
144
+ ${confirmedValues.features.caching ? `
145
+ test('cache utilities manage cache operations', () => {
146
+ expect(typeof serviceUtils.getCacheKey).toBe('function');
147
+ expect(typeof serviceUtils.setCacheValue).toBe('function');
148
+ });` : ''}
149
+ });
150
+
151
+ describe('Schema Validation', () => {
152
+ test('service schema is properly defined', () => {
153
+ expect(serviceSchema).toBeDefined();
154
+ expect(typeof serviceSchema.parse).toBe('function');
155
+ });
156
+
157
+ ${this._generateSchemaTests(coreInputs.serviceType, confirmedValues)}
158
+ });
159
+
160
+ describe('Configuration', () => {
161
+ test('service configuration is valid', () => {
162
+ expect('${coreInputs.serviceName}').toMatch(/^[a-z][a-z0-9-]*$/);
163
+ expect('${confirmedValues.version}').toMatch(/^\\d+\\.\\d+\\.\\d+$/);
164
+ });
165
+
166
+ test('environment variables are accessible', () => {
167
+ // Test environment variable access patterns
168
+ expect(typeof process.env).toBe('object');
169
+ });
170
+
171
+ test('domains configuration is valid', () => {
172
+ const domainsConfig = {
173
+ primary: '${coreInputs.domainName}',
174
+ environments: {
175
+ production: '${confirmedValues.productionUrl}',
176
+ staging: '${confirmedValues.stagingUrl}',
177
+ development: '${confirmedValues.developmentUrl}'
178
+ }
179
+ };
180
+
181
+ expect(domainsConfig.primary).toBeDefined();
182
+ expect(domainsConfig.environments.production).toContain('${coreInputs.domainName}');
183
+ });
184
+ });
185
+
186
+ describe('Error Handling', () => {
187
+ test('errors are properly formatted', () => {
188
+ const error = new Error('Test error');
189
+ const formatted = serviceUtils.formatError(error);
190
+
191
+ expect(formatted.success).toBe(false);
192
+ expect(formatted.error).toBeDefined();
193
+ expect(formatted.timestamp).toBeDefined();
194
+ });
195
+
196
+ test('handles validation errors', () => {
197
+ try {
198
+ serviceSchema.parse({ invalid: 'data' });
199
+ } catch (error) {
200
+ expect(error).toBeDefined();
201
+ }
202
+ });
203
+ });
204
+ });
205
+ `;
206
+ }
207
+
208
+ /**
209
+ * Generate service-type specific schema tests
210
+ * @private
211
+ */
212
+ _generateSchemaTests(serviceType, confirmedValues) {
213
+ switch (serviceType) {
214
+ case 'data-service':
215
+ return `test('data schema validates records', () => {
216
+ const validData = {
217
+ id: '123',
218
+ data: { test: 'value' },
219
+ timestamp: new Date().toISOString()
220
+ };
221
+ expect(() => serviceSchema.parse(validData)).not.toThrow();
222
+ });
223
+
224
+ test('data schema rejects invalid data', () => {
225
+ const invalidData = { invalid: 'structure' };
226
+ expect(() => serviceSchema.parse(invalidData)).toThrow();
227
+ });`;
228
+ case 'auth-service':
229
+ return `test('auth schema validates credentials', () => {
230
+ const validAuth = {
231
+ username: 'testuser',
232
+ password: 'testpass123'
233
+ };
234
+ expect(() => serviceSchema.parse(validAuth)).not.toThrow();
235
+ });
236
+
237
+ test('auth schema validates tokens', () => {
238
+ const validToken = {
239
+ token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
240
+ expiresAt: new Date().toISOString()
241
+ };
242
+ expect(() => serviceSchema.parse(validToken)).not.toThrow();
243
+ });`;
244
+ case 'content-service':
245
+ return `test('content schema validates content structure', () => {
246
+ const validContent = {
247
+ id: '123',
248
+ title: 'Test Content',
249
+ body: 'Content body',
250
+ author: 'test-author'
251
+ };
252
+ expect(() => serviceSchema.parse(validContent)).not.toThrow();
253
+ });`;
254
+ case 'api-gateway':
255
+ return `test('api schema validates requests', () => {
256
+ const validRequest = {
257
+ method: 'GET',
258
+ path: '/test',
259
+ headers: {}
260
+ };
261
+ expect(() => serviceSchema.parse(validRequest)).not.toThrow();
262
+ });`;
263
+ default:
264
+ return `test('service schema validates input', () => {
265
+ // Add service-specific schema tests
266
+ expect(serviceSchema).toBeDefined();
267
+ });`;
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Determine if generator should run
273
+ */
274
+ shouldGenerate(context) {
275
+ return true; // Always generate unit tests
276
+ }
277
+ }