@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,158 @@
1
+ import { createRouteHandlers } from '../handlers/GenericRouteHandler.js';
2
+ import { schemaManager } from '../schema/SchemaManager.js';
3
+
4
+ /**
5
+ * Enhanced Router
6
+ * Supports both domain-specific routes and generic CRUD routes
7
+ *
8
+ * Framework-ready version: All data-service specific imports and routes removed.
9
+ * Domain-specific routes should be registered by the consuming application.
10
+ */
11
+
12
+ export class EnhancedRouter {
13
+ /**
14
+ * Create a new EnhancedRouter instance
15
+ * @param {Object} d1Client - D1 database client
16
+ * @param {Object} options - Router options
17
+ */
18
+ constructor(d1Client, options = {}) {
19
+ this.d1Client = d1Client;
20
+ this.options = options;
21
+ this.routes = new Map();
22
+ this.genericHandlers = createRouteHandlers(d1Client, options);
23
+
24
+ // Register generic routes for all models
25
+ this._registerGenericRoutes();
26
+
27
+ // Note: Domain-specific routes should be registered by the consuming application
28
+ }
29
+
30
+ /**
31
+ * Register a custom route
32
+ * @param {string} method - HTTP method
33
+ * @param {string} path - Route path
34
+ * @param {Function} handler - Route handler
35
+ */
36
+ registerRoute(method, path, handler) {
37
+ const key = `${method.toUpperCase()} ${path}`;
38
+ this.routes.set(key, handler);
39
+ }
40
+
41
+ /**
42
+ * Find and execute a route handler
43
+ * @param {string} method - HTTP method
44
+ * @param {string} path - Request path
45
+ * @param {Request} request - HTTP request
46
+ * @returns {Promise<Response>} HTTP response
47
+ */
48
+ async handleRequest(method, path, request) {
49
+ const key = `${method.toUpperCase()} ${path}`;
50
+
51
+ // Check for exact match first
52
+ if (this.routes.has(key)) {
53
+ const handler = this.routes.get(key);
54
+ return await handler(request);
55
+ }
56
+
57
+ // Check for parameterized routes
58
+ for (const [routeKey, handler] of this.routes.entries()) {
59
+ const [routeMethod, routePath] = routeKey.split(' ');
60
+ if (routeMethod !== method.toUpperCase()) continue;
61
+ const match = this._matchRoute(routePath, path);
62
+ if (match) {
63
+ // Add route parameters to request
64
+ // @ts-ignore - Extending Request object with params
65
+ request.params = match.params;
66
+ return await handler(request, ...match.args);
67
+ }
68
+ }
69
+
70
+ // No route found
71
+ return new Response('Not Found', {
72
+ status: 404
73
+ });
74
+ }
75
+
76
+ /**
77
+ * Register generic CRUD routes for all configured models
78
+ * @private
79
+ */
80
+ _registerGenericRoutes() {
81
+ for (const [modelName] of schemaManager.getAllModels()) {
82
+ const handler = this.genericHandlers[modelName];
83
+ const basePath = `/api/${modelName}`;
84
+
85
+ // CRUD routes
86
+ this.registerRoute('GET', basePath, req => handler.handleList(req));
87
+ this.registerRoute('POST', basePath, req => handler.handleCreate(req));
88
+ this.registerRoute('GET', `${basePath}/:id`, (req, id) => handler.handleGet(req, id));
89
+ this.registerRoute('PATCH', `${basePath}/:id`, (req, id) => handler.handleUpdate(req, id));
90
+ this.registerRoute('DELETE', `${basePath}/:id`, (req, id) => handler.handleDelete(req, id));
91
+ console.log(`✅ Registered generic routes for: ${modelName}`);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Match a route pattern against a path
97
+ * @param {string} pattern - Route pattern (e.g., '/users/:id')
98
+ * @param {string} path - Request path
99
+ * @returns {Object|null} Match result or null
100
+ * @private
101
+ */
102
+ _matchRoute(pattern, path) {
103
+ const patternParts = pattern.split('/');
104
+ const pathParts = path.split('/');
105
+ if (patternParts.length !== pathParts.length) {
106
+ return null;
107
+ }
108
+ const params = {};
109
+ const args = [];
110
+ for (let i = 0; i < patternParts.length; i++) {
111
+ const patternPart = patternParts[i];
112
+ const pathPart = pathParts[i];
113
+ if (patternPart.startsWith(':')) {
114
+ // Parameter
115
+ const paramName = patternPart.slice(1);
116
+ params[paramName] = pathPart;
117
+ args.push(pathPart);
118
+ } else if (patternPart !== pathPart) {
119
+ // No match
120
+ return null;
121
+ }
122
+ }
123
+ return {
124
+ params,
125
+ args
126
+ };
127
+ }
128
+
129
+ /**
130
+ * Get all registered routes
131
+ * @returns {Map} Route map
132
+ */
133
+ getRoutes() {
134
+ return this.routes;
135
+ }
136
+
137
+ /**
138
+ * Add middleware to the router
139
+ * @param {Function} middleware - Middleware function
140
+ */
141
+ use(middleware) {
142
+ // Store middleware for later use
143
+ if (!this.middleware) {
144
+ this.middleware = [];
145
+ }
146
+ this.middleware.push(middleware);
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Create an enhanced router instance
152
+ * @param {Object} d1Client - D1 database client
153
+ * @param {Object} options - Router options
154
+ * @returns {EnhancedRouter} Router instance
155
+ */
156
+ export function createEnhancedRouter(d1Client, options = {}) {
157
+ return new EnhancedRouter(d1Client, options);
158
+ }