@tamyla/clodo-framework 4.3.3 → 4.3.4
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 +8 -0
- package/README.md +38 -3
- package/dist/api/frameworkCapabilities.js +44 -0
- package/dist/api/index.js +7 -0
- package/dist/api/versionCompatibility.js +78 -0
- package/dist/errors/index.js +5 -0
- package/dist/errors/integrationErrors.js +70 -0
- package/dist/index.js +9 -0
- package/dist/programmatic/deployService.js +5 -0
- package/dist/programmatic/index.js +8 -0
- package/dist/programmatic/validateService.js +5 -0
- package/dist/testing/index.js +6 -0
- package/dist/testing/mockFramework.js +236 -0
- package/dist/validation/index.js +6 -0
- package/dist/validation/payloadValidation.js +49 -8
- package/docs/00_START_HERE.md +524 -0
- package/docs/HOWTO_CONSUME_CLODO_FRAMEWORK.md +400 -0
- package/docs/MIGRATION.md +458 -0
- package/docs/README.md +131 -21
- package/docs/SIMPLE_API_GUIDE.md +230 -0
- package/docs/api/PROGRAMMATIC_API.md +270 -0
- package/docs/api/README.md +526 -0
- package/docs/api/parameter_reference.md +296 -0
- package/docs/errors.md +367 -0
- package/package.json +12 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Clodo Framework - Simple API Examples
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Clodo Framework now provides a **Simple API** that dramatically simplifies common operations while maintaining all the power and flexibility of the advanced APIs.
|
|
6
|
+
|
|
7
|
+
## Before vs After
|
|
8
|
+
|
|
9
|
+
### Service Creation
|
|
10
|
+
|
|
11
|
+
**Before (Complex):**
|
|
12
|
+
```javascript
|
|
13
|
+
import { ServiceOrchestrator } from '@tamyla/clodo-framework';
|
|
14
|
+
|
|
15
|
+
const orchestrator = new ServiceOrchestrator({
|
|
16
|
+
interactive: false,
|
|
17
|
+
outputPath: './my-service'
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const coreInputs = {
|
|
21
|
+
serviceName: 'my-api',
|
|
22
|
+
serviceType: 'api-gateway',
|
|
23
|
+
domainName: 'api.example.com',
|
|
24
|
+
environment: 'production',
|
|
25
|
+
cloudflareToken: 'token123',
|
|
26
|
+
cloudflareAccountId: 'account123',
|
|
27
|
+
cloudflareZoneId: 'zone123'
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
await orchestrator.runNonInteractive(coreInputs);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**After (Simple):**
|
|
34
|
+
```javascript
|
|
35
|
+
import { createService } from '@tamyla/clodo-framework';
|
|
36
|
+
|
|
37
|
+
await createService({
|
|
38
|
+
name: 'my-api',
|
|
39
|
+
type: 'api-gateway',
|
|
40
|
+
domain: 'api.example.com',
|
|
41
|
+
environment: 'production',
|
|
42
|
+
credentials: {
|
|
43
|
+
token: 'token123',
|
|
44
|
+
accountId: 'account123',
|
|
45
|
+
zoneId: 'zone123'
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Service Deployment
|
|
51
|
+
|
|
52
|
+
**Before (Complex):**
|
|
53
|
+
```javascript
|
|
54
|
+
import { MultiDomainOrchestrator } from '@tamyla/clodo-framework';
|
|
55
|
+
|
|
56
|
+
const orchestrator = new MultiDomainOrchestrator({
|
|
57
|
+
environment: 'production',
|
|
58
|
+
servicePath: './my-service',
|
|
59
|
+
cloudflareToken: 'token123',
|
|
60
|
+
cloudflareAccountId: 'account123',
|
|
61
|
+
cloudflareZoneId: 'zone123',
|
|
62
|
+
domains: ['api.example.com']
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
await orchestrator.initialize();
|
|
66
|
+
const result = await orchestrator.deployPortfolio();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**After (Simple):**
|
|
70
|
+
```javascript
|
|
71
|
+
import { deploy } from '@tamyla/clodo-framework';
|
|
72
|
+
|
|
73
|
+
await deploy({
|
|
74
|
+
servicePath: './my-service',
|
|
75
|
+
environment: 'production',
|
|
76
|
+
domain: 'api.example.com',
|
|
77
|
+
credentials: {
|
|
78
|
+
token: 'token123',
|
|
79
|
+
accountId: 'account123',
|
|
80
|
+
zoneId: 'zone123'
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Service Validation
|
|
86
|
+
|
|
87
|
+
**Before (Complex):**
|
|
88
|
+
```javascript
|
|
89
|
+
import { ServiceOrchestrator } from '@tamyla/clodo-framework';
|
|
90
|
+
|
|
91
|
+
const orchestrator = new ServiceOrchestrator();
|
|
92
|
+
const result = await orchestrator.validateService('./my-service', {
|
|
93
|
+
exportReport: true
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (!result.valid) {
|
|
97
|
+
console.log('Issues:', result.issues);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**After (Simple):**
|
|
102
|
+
```javascript
|
|
103
|
+
import { validate } from '@tamyla/clodo-framework';
|
|
104
|
+
|
|
105
|
+
const result = await validate({
|
|
106
|
+
servicePath: './my-service',
|
|
107
|
+
exportReport: true
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
if (!result.success) {
|
|
111
|
+
console.log('Issues:', result.issues);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Worker Integration
|
|
116
|
+
|
|
117
|
+
**Before (Complex):**
|
|
118
|
+
```javascript
|
|
119
|
+
import { initializeService } from '@tamyla/clodo-framework';
|
|
120
|
+
|
|
121
|
+
const domainConfigs = {
|
|
122
|
+
'api.example.com': {
|
|
123
|
+
name: 'api.example.com',
|
|
124
|
+
environment: 'production',
|
|
125
|
+
features: ['api-gateway', 'authentication']
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const context = initializeService(env, domainConfigs);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**After (Simple):**
|
|
133
|
+
```javascript
|
|
134
|
+
import { initialize } from '@tamyla/clodo-framework';
|
|
135
|
+
|
|
136
|
+
const context = initialize(env, {
|
|
137
|
+
domainConfigs: {
|
|
138
|
+
'api.example.com': {
|
|
139
|
+
name: 'api.example.com',
|
|
140
|
+
environment: 'production',
|
|
141
|
+
features: ['api-gateway', 'authentication']
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## CLI Usage
|
|
148
|
+
|
|
149
|
+
### Simple CLI Commands
|
|
150
|
+
|
|
151
|
+
The framework now includes simplified CLI commands:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Create a service
|
|
155
|
+
npx clodo-simple create my-api --domain api.example.com
|
|
156
|
+
|
|
157
|
+
# Deploy a service
|
|
158
|
+
npx clodo-simple deploy --env production
|
|
159
|
+
|
|
160
|
+
# Validate a service
|
|
161
|
+
npx clodo-simple validate
|
|
162
|
+
|
|
163
|
+
# Show framework info
|
|
164
|
+
npx clodo-simple info
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Before vs After CLI
|
|
168
|
+
|
|
169
|
+
**Before (Complex):**
|
|
170
|
+
```bash
|
|
171
|
+
npx clodo-service create \
|
|
172
|
+
--service-name my-api \
|
|
173
|
+
--service-type api-gateway \
|
|
174
|
+
--domain-name api.example.com \
|
|
175
|
+
--environment production \
|
|
176
|
+
--cloudflare-token token123 \
|
|
177
|
+
--cloudflare-account-id account123 \
|
|
178
|
+
--cloudflare-zone-id zone123 \
|
|
179
|
+
--output-path ./my-service \
|
|
180
|
+
--non-interactive
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**After (Simple):**
|
|
184
|
+
```bash
|
|
185
|
+
npx clodo-simple create my-api \
|
|
186
|
+
--domain api.example.com \
|
|
187
|
+
--env production \
|
|
188
|
+
--token token123 \
|
|
189
|
+
--account-id account123 \
|
|
190
|
+
--zone-id zone123
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Migration Guide
|
|
194
|
+
|
|
195
|
+
### For Existing Users
|
|
196
|
+
|
|
197
|
+
1. **Update imports**: Replace complex class instantiations with simple function calls
|
|
198
|
+
2. **Simplify options**: Use the simplified option structure with sensible defaults
|
|
199
|
+
3. **Use CLI**: Switch to `clodo-simple` commands for common operations
|
|
200
|
+
4. **Gradual migration**: The advanced APIs remain available for complex use cases
|
|
201
|
+
|
|
202
|
+
### Backward Compatibility
|
|
203
|
+
|
|
204
|
+
- All existing APIs continue to work unchanged
|
|
205
|
+
- Advanced features still available through the full APIs
|
|
206
|
+
- No breaking changes to existing code
|
|
207
|
+
|
|
208
|
+
## Benefits
|
|
209
|
+
|
|
210
|
+
- **80% less code** for common operations
|
|
211
|
+
- **Fewer configuration options** to manage
|
|
212
|
+
- **Sensible defaults** reduce decision fatigue
|
|
213
|
+
- **Consistent API patterns** across all operations
|
|
214
|
+
- **Better error messages** and validation
|
|
215
|
+
- **Easier testing** and development
|
|
216
|
+
|
|
217
|
+
## When to Use Simple API
|
|
218
|
+
|
|
219
|
+
Use the Simple API for:
|
|
220
|
+
- Quick prototyping
|
|
221
|
+
- Standard service setups
|
|
222
|
+
- CI/CD pipelines
|
|
223
|
+
- Learning the framework
|
|
224
|
+
- Most common use cases
|
|
225
|
+
|
|
226
|
+
Use the Advanced APIs for:
|
|
227
|
+
- Complex multi-domain deployments
|
|
228
|
+
- Custom orchestration logic
|
|
229
|
+
- Specialized configurations
|
|
230
|
+
- Framework extensions
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Programmatic API Guide
|
|
2
|
+
|
|
3
|
+
This guide covers how to use the clodo-framework programmatically for integration with clodo-application and other tools.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The clodo-framework provides comprehensive programmatic APIs for service creation, validation, and introspection. These APIs enable seamless integration without requiring interactive CLI usage.
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
import { createServiceProgrammatic } from '@tamyla/clodo-framework/programmatic';
|
|
13
|
+
import { validateServicePayload } from '@tamyla/clodo-framework/validation';
|
|
14
|
+
import { getFrameworkCapabilities } from '@tamyla/clodo-framework/api';
|
|
15
|
+
|
|
16
|
+
// Create a service programmatically
|
|
17
|
+
const payload = {
|
|
18
|
+
serviceName: 'my-api-service',
|
|
19
|
+
serviceType: 'api-service',
|
|
20
|
+
domain: 'myapp.example.com',
|
|
21
|
+
features: ['d1', 'metrics'],
|
|
22
|
+
description: 'My API service'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const result = await createServiceProgrammatic(payload, {
|
|
26
|
+
outputDir: './services'
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (result.success) {
|
|
30
|
+
console.log(`Service created at: ${result.servicePath}`);
|
|
31
|
+
} else {
|
|
32
|
+
console.error('Creation failed:', result.errors);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Core APIs
|
|
37
|
+
|
|
38
|
+
### Service Creation
|
|
39
|
+
|
|
40
|
+
#### `createServiceProgrammatic(payload, options)`
|
|
41
|
+
|
|
42
|
+
Creates a service programmatically without interactive prompts.
|
|
43
|
+
|
|
44
|
+
**Parameters:**
|
|
45
|
+
- `payload` (ServicePayload): Service configuration object
|
|
46
|
+
- `options` (Object): Creation options
|
|
47
|
+
|
|
48
|
+
**Options:**
|
|
49
|
+
- `outputDir` (string): Directory to create the service in (default: '.')
|
|
50
|
+
- `dryRun` (boolean): Validate without creating files (default: false)
|
|
51
|
+
- `force` (boolean): Continue despite validation errors (default: false)
|
|
52
|
+
|
|
53
|
+
**Returns:** Promise<ServiceCreationResult>
|
|
54
|
+
|
|
55
|
+
**Example:**
|
|
56
|
+
```javascript
|
|
57
|
+
const result = await createServiceProgrammatic({
|
|
58
|
+
serviceName: 'api-gateway',
|
|
59
|
+
serviceType: 'gateway',
|
|
60
|
+
domain: 'api.example.com',
|
|
61
|
+
features: ['durableObject', 'metrics']
|
|
62
|
+
}, {
|
|
63
|
+
outputDir: './services',
|
|
64
|
+
dryRun: false
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Payload Validation
|
|
69
|
+
|
|
70
|
+
#### `validateServicePayload(payload)`
|
|
71
|
+
|
|
72
|
+
Validates a service payload against the framework schema.
|
|
73
|
+
|
|
74
|
+
**Parameters:**
|
|
75
|
+
- `payload` (ServicePayload): Payload to validate
|
|
76
|
+
|
|
77
|
+
**Returns:** ValidationResult
|
|
78
|
+
|
|
79
|
+
**Example:**
|
|
80
|
+
```javascript
|
|
81
|
+
const validation = validateServicePayload({
|
|
82
|
+
serviceName: 'my-service',
|
|
83
|
+
serviceType: 'invalid-type', // This will fail
|
|
84
|
+
domain: 'example.com'
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (!validation.valid) {
|
|
88
|
+
console.log('Validation errors:', validation.errors);
|
|
89
|
+
console.log('Warnings:', validation.warnings);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Parameter Discovery
|
|
94
|
+
|
|
95
|
+
#### `getParameterDefinitions()`
|
|
96
|
+
|
|
97
|
+
Returns metadata about all supported parameters.
|
|
98
|
+
|
|
99
|
+
**Returns:** Record<string, ParameterDefinition>
|
|
100
|
+
|
|
101
|
+
**Example:**
|
|
102
|
+
```javascript
|
|
103
|
+
const params = getParameterDefinitions();
|
|
104
|
+
|
|
105
|
+
console.log('Required parameters:');
|
|
106
|
+
Object.entries(params)
|
|
107
|
+
.filter(([_, def]) => def.required)
|
|
108
|
+
.forEach(([name, def]) => {
|
|
109
|
+
console.log(`${name}: ${def.description}`);
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Framework Capabilities
|
|
114
|
+
|
|
115
|
+
#### `getFrameworkCapabilities()`
|
|
116
|
+
|
|
117
|
+
Returns information about framework capabilities and supported features.
|
|
118
|
+
|
|
119
|
+
**Returns:** FrameworkCapabilities
|
|
120
|
+
|
|
121
|
+
**Example:**
|
|
122
|
+
```javascript
|
|
123
|
+
const capabilities = getFrameworkCapabilities();
|
|
124
|
+
|
|
125
|
+
console.log(`Framework version: ${capabilities.version}`);
|
|
126
|
+
console.log(`Supports programmatic creation: ${capabilities.supportsProgrammaticCreation}`);
|
|
127
|
+
console.log(`Supported service types: ${capabilities.supportedServiceTypes.join(', ')}`);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Version Compatibility
|
|
131
|
+
|
|
132
|
+
#### `checkApplicationCompatibility(applicationVersion)`
|
|
133
|
+
|
|
134
|
+
Checks if an application version is compatible with the current framework.
|
|
135
|
+
|
|
136
|
+
**Parameters:**
|
|
137
|
+
- `applicationVersion` (string): Version to check
|
|
138
|
+
|
|
139
|
+
**Returns:** CompatibilityResult
|
|
140
|
+
|
|
141
|
+
**Example:**
|
|
142
|
+
```javascript
|
|
143
|
+
const compatibility = checkApplicationCompatibility('1.0.0');
|
|
144
|
+
|
|
145
|
+
if (!compatibility.compatible) {
|
|
146
|
+
console.log('Breaking changes:', compatibility.breakingChanges);
|
|
147
|
+
console.log('Recommendations:', compatibility.recommendations);
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Service Payload Schema
|
|
152
|
+
|
|
153
|
+
The `ServicePayload` object supports the following properties:
|
|
154
|
+
|
|
155
|
+
### Required Properties
|
|
156
|
+
|
|
157
|
+
- `serviceName` (string): Unique service identifier (3-50 chars, lowercase, numbers, hyphens)
|
|
158
|
+
- `serviceType` (string): Type of service (see supported types below)
|
|
159
|
+
- `domain` (string): Domain name for the service
|
|
160
|
+
|
|
161
|
+
### Optional Properties
|
|
162
|
+
|
|
163
|
+
- `description` (string): Human-readable description
|
|
164
|
+
- `template` (string): Template to use (default: 'generic')
|
|
165
|
+
- `features` (string[]): Array of features to enable
|
|
166
|
+
- `bindings` (string[]): Resource bindings
|
|
167
|
+
- `resources` (object): Resource configuration
|
|
168
|
+
- `specs` (object): Service specifications (memory, CPU, etc.)
|
|
169
|
+
- `clodo` (object): Passthrough data for clodo-application
|
|
170
|
+
|
|
171
|
+
## Supported Service Types
|
|
172
|
+
|
|
173
|
+
- `api-service`: REST API service
|
|
174
|
+
- `data-service`: Data processing service
|
|
175
|
+
- `worker`: Background worker service
|
|
176
|
+
- `pages`: Static site service
|
|
177
|
+
- `gateway`: API gateway service
|
|
178
|
+
|
|
179
|
+
## Supported Features
|
|
180
|
+
|
|
181
|
+
- `d1`: Cloudflare D1 database
|
|
182
|
+
- `upstash`: Upstash Redis
|
|
183
|
+
- `r2`: Cloudflare R2 storage
|
|
184
|
+
- `pages`: Cloudflare Pages
|
|
185
|
+
- `ws`: WebSocket support
|
|
186
|
+
- `durableObject`: Durable Objects
|
|
187
|
+
- `cron`: Cron triggers
|
|
188
|
+
- `metrics`: Metrics collection
|
|
189
|
+
|
|
190
|
+
## Error Handling
|
|
191
|
+
|
|
192
|
+
All programmatic APIs return structured error information:
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
const result = await createServiceProgrammatic(payload);
|
|
196
|
+
|
|
197
|
+
if (!result.success) {
|
|
198
|
+
// Handle errors
|
|
199
|
+
result.errors.forEach(error => {
|
|
200
|
+
console.error(`Error: ${error.message}`);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// Handle warnings
|
|
204
|
+
result.warnings.forEach(warning => {
|
|
205
|
+
console.warn(`Warning: ${warning.message}`);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Integration Testing
|
|
211
|
+
|
|
212
|
+
Use the mock framework for testing integrations:
|
|
213
|
+
|
|
214
|
+
```javascript
|
|
215
|
+
import { createMockFramework } from '@tamyla/clodo-framework/testing';
|
|
216
|
+
|
|
217
|
+
const mockFramework = createMockFramework();
|
|
218
|
+
|
|
219
|
+
// Test your integration
|
|
220
|
+
const result = await mockFramework.createService(payload);
|
|
221
|
+
expect(result.success).toBe(true);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Migration from CLI
|
|
225
|
+
|
|
226
|
+
### Before (CLI)
|
|
227
|
+
```bash
|
|
228
|
+
npx clodo-service create
|
|
229
|
+
# Interactive prompts...
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### After (Programmatic)
|
|
233
|
+
```javascript
|
|
234
|
+
import { createServiceProgrammatic } from '@tamyla/clodo-framework/programmatic';
|
|
235
|
+
|
|
236
|
+
const result = await createServiceProgrammatic({
|
|
237
|
+
serviceName: 'my-service',
|
|
238
|
+
serviceType: 'api-service',
|
|
239
|
+
domain: 'example.com'
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Best Practices
|
|
244
|
+
|
|
245
|
+
1. **Always validate payloads** before creation
|
|
246
|
+
2. **Check framework capabilities** before using advanced features
|
|
247
|
+
3. **Handle errors gracefully** with proper user feedback
|
|
248
|
+
4. **Use dry-run mode** for testing integrations
|
|
249
|
+
5. **Check version compatibility** in production deployments
|
|
250
|
+
6. **Test integrations** using the mock framework
|
|
251
|
+
|
|
252
|
+
## Troubleshooting
|
|
253
|
+
|
|
254
|
+
### Common Issues
|
|
255
|
+
|
|
256
|
+
**"Parameter not supported"**
|
|
257
|
+
- Check `getParameterDefinitions()` for supported parameters
|
|
258
|
+
- Verify parameter names and types
|
|
259
|
+
|
|
260
|
+
**"Service type not valid"**
|
|
261
|
+
- Use `getFrameworkCapabilities()` to get supported service types
|
|
262
|
+
- Check enum values against framework capabilities
|
|
263
|
+
|
|
264
|
+
**"Validation failed"**
|
|
265
|
+
- Use `validateServicePayload()` to get detailed error information
|
|
266
|
+
- Check parameter formats and required fields
|
|
267
|
+
|
|
268
|
+
**"Version incompatibility"**
|
|
269
|
+
- Use `checkApplicationCompatibility()` to verify version compatibility
|
|
270
|
+
- Update application or framework as recommended
|