@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.
- package/CHANGELOG.md +564 -0
- package/LICENSE +21 -0
- package/README.md +1393 -0
- package/bin/README.md +71 -0
- package/bin/clodo-service.js +416 -0
- package/bin/security/security-cli.js +96 -0
- package/bin/service-management/README.md +74 -0
- package/bin/service-management/create-service.js +129 -0
- package/bin/service-management/init-service.js +102 -0
- package/bin/service-management/init-service.js.backup +889 -0
- package/bin/shared/config/customer-cli.js +293 -0
- package/dist/config/ConfigurationManager.js +159 -0
- package/dist/config/CustomerConfigCLI.js +220 -0
- package/dist/config/FeatureManager.js +426 -0
- package/dist/config/customers.js +441 -0
- package/dist/config/domains.js +180 -0
- package/dist/config/features.js +225 -0
- package/dist/config/index.js +6 -0
- package/dist/database/database-orchestrator.js +730 -0
- package/dist/database/index.js +4 -0
- package/dist/deployment/auditor.js +971 -0
- package/dist/deployment/index.js +10 -0
- package/dist/deployment/rollback-manager.js +523 -0
- package/dist/deployment/testers/api-tester.js +80 -0
- package/dist/deployment/testers/auth-tester.js +129 -0
- package/dist/deployment/testers/core.js +217 -0
- package/dist/deployment/testers/database-tester.js +105 -0
- package/dist/deployment/testers/index.js +74 -0
- package/dist/deployment/testers/load-tester.js +120 -0
- package/dist/deployment/testers/performance-tester.js +105 -0
- package/dist/deployment/validator.js +558 -0
- package/dist/deployment/wrangler-deployer.js +574 -0
- package/dist/handlers/GenericRouteHandler.js +532 -0
- package/dist/index.js +39 -0
- package/dist/migration/MigrationAdapters.js +562 -0
- package/dist/modules/ModuleManager.js +668 -0
- package/dist/modules/security.js +98 -0
- package/dist/orchestration/cross-domain-coordinator.js +1083 -0
- package/dist/orchestration/index.js +5 -0
- package/dist/orchestration/modules/DeploymentCoordinator.js +258 -0
- package/dist/orchestration/modules/DomainResolver.js +196 -0
- package/dist/orchestration/modules/StateManager.js +332 -0
- package/dist/orchestration/multi-domain-orchestrator.js +255 -0
- package/dist/routing/EnhancedRouter.js +158 -0
- package/dist/schema/SchemaManager.js +778 -0
- package/dist/security/ConfigurationValidator.js +490 -0
- package/dist/security/DeploymentManager.js +208 -0
- package/dist/security/SecretGenerator.js +142 -0
- package/dist/security/SecurityCLI.js +228 -0
- package/dist/security/index.js +51 -0
- package/dist/security/patterns/environment-rules.js +66 -0
- package/dist/security/patterns/insecure-patterns.js +21 -0
- package/dist/service-management/ConfirmationEngine.js +411 -0
- package/dist/service-management/ErrorTracker.js +294 -0
- package/dist/service-management/GenerationEngine.js +3109 -0
- package/dist/service-management/InputCollector.js +237 -0
- package/dist/service-management/ServiceCreator.js +229 -0
- package/dist/service-management/ServiceInitializer.js +448 -0
- package/dist/service-management/ServiceOrchestrator.js +638 -0
- package/dist/service-management/handlers/ConfigMutator.js +130 -0
- package/dist/service-management/handlers/ConfirmationHandler.js +71 -0
- package/dist/service-management/handlers/GenerationHandler.js +80 -0
- package/dist/service-management/handlers/InputHandler.js +59 -0
- package/dist/service-management/handlers/ValidationHandler.js +203 -0
- package/dist/service-management/index.js +7 -0
- package/dist/services/GenericDataService.js +488 -0
- package/dist/shared/cloudflare/domain-discovery.js +562 -0
- package/dist/shared/cloudflare/domain-manager.js +912 -0
- package/dist/shared/cloudflare/index.js +8 -0
- package/dist/shared/cloudflare/ops.js +387 -0
- package/dist/shared/config/cache.js +1167 -0
- package/dist/shared/config/command-config-manager.js +174 -0
- package/dist/shared/config/customer-cli.js +258 -0
- package/dist/shared/config/index.js +9 -0
- package/dist/shared/config/manager.js +289 -0
- package/dist/shared/database/connection-manager.js +338 -0
- package/dist/shared/database/index.js +7 -0
- package/dist/shared/database/orchestrator.js +632 -0
- package/dist/shared/deployment/auditor.js +971 -0
- package/dist/shared/deployment/index.js +10 -0
- package/dist/shared/deployment/rollback-manager.js +523 -0
- package/dist/shared/deployment/validator.js +558 -0
- package/dist/shared/index.js +32 -0
- package/dist/shared/monitoring/health-checker.js +250 -0
- package/dist/shared/monitoring/index.js +8 -0
- package/dist/shared/monitoring/memory-manager.js +382 -0
- package/dist/shared/monitoring/production-monitor.js +390 -0
- package/dist/shared/production-tester/api-tester.js +80 -0
- package/dist/shared/production-tester/auth-tester.js +129 -0
- package/dist/shared/production-tester/core.js +217 -0
- package/dist/shared/production-tester/database-tester.js +105 -0
- package/dist/shared/production-tester/index.js +74 -0
- package/dist/shared/production-tester/load-tester.js +120 -0
- package/dist/shared/production-tester/performance-tester.js +105 -0
- package/dist/shared/security/api-token-manager.js +296 -0
- package/dist/shared/security/index.js +8 -0
- package/dist/shared/security/secret-generator.js +918 -0
- package/dist/shared/security/secure-token-manager.js +379 -0
- package/dist/shared/utils/error-recovery.js +240 -0
- package/dist/shared/utils/graceful-shutdown-manager.js +380 -0
- package/dist/shared/utils/index.js +9 -0
- package/dist/shared/utils/interactive-prompts.js +134 -0
- package/dist/shared/utils/rate-limiter.js +249 -0
- package/dist/utils/ErrorHandler.js +173 -0
- package/dist/utils/deployment/config-cache.js +1160 -0
- package/dist/utils/deployment/index.js +6 -0
- package/dist/utils/deployment/interactive-prompts.js +97 -0
- package/dist/utils/deployment/secret-generator.js +896 -0
- package/dist/utils/dirname-helper.js +35 -0
- package/dist/utils/domain-config.js +159 -0
- package/dist/utils/error-recovery.js +240 -0
- package/dist/utils/esm-helper.js +52 -0
- package/dist/utils/framework-config.js +481 -0
- package/dist/utils/graceful-shutdown-manager.js +379 -0
- package/dist/utils/health-checker.js +114 -0
- package/dist/utils/index.js +36 -0
- package/dist/utils/prompt-handler.js +98 -0
- package/dist/utils/usage-tracker.js +252 -0
- package/dist/utils/validation.js +112 -0
- package/dist/version/VersionDetector.js +723 -0
- package/dist/worker/index.js +4 -0
- package/dist/worker/integration.js +332 -0
- package/docs/FRAMEWORK-ARCHITECTURE-OVERVIEW.md +206 -0
- package/docs/INTEGRATION_GUIDE.md +2045 -0
- package/docs/README.md +82 -0
- package/docs/SECURITY.md +242 -0
- package/docs/deployment/deployment-guide.md +540 -0
- package/docs/overview.md +280 -0
- package/package.json +176 -0
- 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
|
+
}
|