@friggframework/devtools 2.0.0--canary.545.e256e95.0 → 2.0.0--canary.553.dc5f898.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/frigg-cli/README.md +1 -1
- package/frigg-cli/__tests__/unit/commands/build.test.js +1 -1
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +2 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +19 -23
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -2
- package/frigg-cli/build-command/index.js +11 -123
- package/frigg-cli/deploy-command/index.js +1 -83
- package/frigg-cli/doctor-command/index.js +16 -37
- package/frigg-cli/generate-iam-command.js +1 -21
- package/frigg-cli/index.js +6 -21
- package/frigg-cli/index.test.js +2 -7
- package/frigg-cli/init-command/backend-first-handler.js +42 -124
- package/frigg-cli/init-command/index.js +1 -2
- package/frigg-cli/init-command/template-handler.js +3 -13
- package/frigg-cli/install-command/backend-js.js +3 -3
- package/frigg-cli/install-command/environment-variables.js +19 -16
- package/frigg-cli/install-command/environment-variables.test.js +13 -12
- package/frigg-cli/install-command/index.js +9 -14
- package/frigg-cli/install-command/integration-file.js +3 -3
- package/frigg-cli/install-command/logger.js +12 -0
- package/frigg-cli/install-command/validate-package.js +9 -5
- package/frigg-cli/jest.config.js +1 -4
- package/frigg-cli/repair-command/index.js +128 -121
- package/frigg-cli/start-command/index.js +2 -324
- package/frigg-cli/ui-command/index.js +36 -58
- package/frigg-cli/utils/repo-detection.js +37 -85
- package/infrastructure/create-frigg-infrastructure.js +0 -93
- package/infrastructure/docs/iam-policy-templates.md +1 -1
- package/infrastructure/domains/integration/integration-builder.js +3 -2
- package/infrastructure/domains/integration/integration-builder.test.js +54 -2
- package/infrastructure/domains/networking/vpc-builder.test.js +4 -2
- package/infrastructure/domains/networking/vpc-resolver.test.js +1 -1
- package/infrastructure/domains/shared/resource-discovery.js +5 -5
- package/infrastructure/domains/shared/types/app-definition.js +0 -35
- package/infrastructure/domains/shared/types/discovery-result.test.js +1 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +1 -10
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +2 -2
- package/infrastructure/infrastructure-composer.js +0 -2
- package/infrastructure/infrastructure-composer.test.js +6 -5
- package/management-ui/README.md +109 -245
- package/package.json +7 -8
- package/frigg-cli/__tests__/application/use-cases/AddApiModuleToIntegrationUseCase.test.js +0 -326
- package/frigg-cli/__tests__/application/use-cases/CreateApiModuleUseCase.test.js +0 -337
- package/frigg-cli/__tests__/domain/entities/ApiModule.test.js +0 -373
- package/frigg-cli/__tests__/domain/entities/AppDefinition.test.js +0 -313
- package/frigg-cli/__tests__/domain/services/IntegrationValidator.test.js +0 -269
- package/frigg-cli/__tests__/domain/value-objects/IntegrationName.test.js +0 -82
- package/frigg-cli/__tests__/infrastructure/adapters/IntegrationJsUpdater.test.js +0 -408
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemApiModuleRepository.test.js +0 -583
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemAppDefinitionRepository.test.js +0 -314
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemIntegrationRepository.test.js +0 -383
- package/frigg-cli/__tests__/unit/commands/init.test.js +0 -406
- package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -383
- package/frigg-cli/__tests__/unit/commands/repair.test.js +0 -275
- package/frigg-cli/__tests__/unit/start-command/application/RunPreflightChecksUseCase.test.js +0 -411
- package/frigg-cli/__tests__/unit/start-command/infrastructure/DatabaseAdapter.test.js +0 -405
- package/frigg-cli/__tests__/unit/start-command/infrastructure/DockerAdapter.test.js +0 -496
- package/frigg-cli/__tests__/unit/start-command/presentation/InteractivePromptAdapter.test.js +0 -474
- package/frigg-cli/__tests__/unit/utils/output.test.js +0 -196
- package/frigg-cli/application/use-cases/AddApiModuleToIntegrationUseCase.js +0 -93
- package/frigg-cli/application/use-cases/CreateApiModuleUseCase.js +0 -93
- package/frigg-cli/application/use-cases/CreateIntegrationUseCase.js +0 -103
- package/frigg-cli/container.js +0 -172
- package/frigg-cli/docs/OUTPUT_MIGRATION_GUIDE.md +0 -286
- package/frigg-cli/domain/entities/ApiModule.js +0 -272
- package/frigg-cli/domain/entities/AppDefinition.js +0 -227
- package/frigg-cli/domain/entities/Integration.js +0 -198
- package/frigg-cli/domain/exceptions/DomainException.js +0 -24
- package/frigg-cli/domain/ports/IApiModuleRepository.js +0 -53
- package/frigg-cli/domain/ports/IAppDefinitionRepository.js +0 -43
- package/frigg-cli/domain/ports/IIntegrationRepository.js +0 -61
- package/frigg-cli/domain/services/IntegrationValidator.js +0 -185
- package/frigg-cli/domain/value-objects/IntegrationId.js +0 -42
- package/frigg-cli/domain/value-objects/IntegrationName.js +0 -60
- package/frigg-cli/domain/value-objects/SemanticVersion.js +0 -70
- package/frigg-cli/infrastructure/UnitOfWork.js +0 -46
- package/frigg-cli/infrastructure/adapters/BackendJsUpdater.js +0 -197
- package/frigg-cli/infrastructure/adapters/FileSystemAdapter.js +0 -224
- package/frigg-cli/infrastructure/adapters/IntegrationJsUpdater.js +0 -249
- package/frigg-cli/infrastructure/adapters/SchemaValidator.js +0 -92
- package/frigg-cli/infrastructure/repositories/FileSystemApiModuleRepository.js +0 -373
- package/frigg-cli/infrastructure/repositories/FileSystemAppDefinitionRepository.js +0 -116
- package/frigg-cli/infrastructure/repositories/FileSystemIntegrationRepository.js +0 -277
- package/frigg-cli/package-lock.json +0 -16226
- package/frigg-cli/start-command/application/RunPreflightChecksUseCase.js +0 -376
- package/frigg-cli/start-command/infrastructure/DatabaseAdapter.js +0 -591
- package/frigg-cli/start-command/infrastructure/DockerAdapter.js +0 -306
- package/frigg-cli/start-command/presentation/InteractivePromptAdapter.js +0 -329
- package/frigg-cli/templates/backend/.env.example +0 -62
- package/frigg-cli/templates/backend/.eslintrc.json +0 -12
- package/frigg-cli/templates/backend/.prettierrc +0 -6
- package/frigg-cli/templates/backend/docker-compose.yml +0 -22
- package/frigg-cli/templates/backend/index.js +0 -96
- package/frigg-cli/templates/backend/infrastructure.js +0 -12
- package/frigg-cli/templates/backend/jest.config.js +0 -17
- package/frigg-cli/templates/backend/package.json +0 -50
- package/frigg-cli/templates/backend/src/api-modules/.gitkeep +0 -10
- package/frigg-cli/templates/backend/src/base/.gitkeep +0 -7
- package/frigg-cli/templates/backend/src/integrations/.gitkeep +0 -10
- package/frigg-cli/templates/backend/src/integrations/ExampleIntegration.js +0 -65
- package/frigg-cli/templates/backend/src/utils/.gitkeep +0 -7
- package/frigg-cli/templates/backend/test/setup.js +0 -30
- package/frigg-cli/templates/backend/ui-extensions/.gitkeep +0 -0
- package/frigg-cli/templates/backend/ui-extensions/README.md +0 -77
- package/frigg-cli/utils/__tests__/provider-helper.test.js +0 -55
- package/frigg-cli/utils/__tests__/repo-detection.test.js +0 -436
- package/frigg-cli/utils/output.js +0 -382
- package/frigg-cli/utils/provider-helper.js +0 -75
- package/frigg-cli/validate-command/__tests__/adapters/validate-command.test.js +0 -205
- package/frigg-cli/validate-command/__tests__/application/validate-app-use-case.test.js +0 -104
- package/frigg-cli/validate-command/__tests__/domain/fix-suggestion.test.js +0 -153
- package/frigg-cli/validate-command/__tests__/domain/validation-error.test.js +0 -162
- package/frigg-cli/validate-command/__tests__/domain/validation-result.test.js +0 -152
- package/frigg-cli/validate-command/__tests__/infrastructure/api-module-validator.test.js +0 -332
- package/frigg-cli/validate-command/__tests__/infrastructure/app-definition-validator.test.js +0 -191
- package/frigg-cli/validate-command/__tests__/infrastructure/integration-class-validator.test.js +0 -146
- package/frigg-cli/validate-command/__tests__/infrastructure/template-validation.test.js +0 -155
- package/frigg-cli/validate-command/adapters/cli/validate-command.js +0 -199
- package/frigg-cli/validate-command/application/use-cases/validate-app-use-case.js +0 -35
- package/frigg-cli/validate-command/domain/entities/validation-result.js +0 -74
- package/frigg-cli/validate-command/domain/value-objects/fix-suggestion.js +0 -74
- package/frigg-cli/validate-command/domain/value-objects/validation-error.js +0 -68
- package/frigg-cli/validate-command/infrastructure/validators/api-module-validator.js +0 -181
- package/frigg-cli/validate-command/infrastructure/validators/app-definition-validator.js +0 -145
- package/frigg-cli/validate-command/infrastructure/validators/integration-class-validator.js +0 -113
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +0 -200
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -499
- package/infrastructure/domains/admin-scripts/index.js +0 -5
- package/infrastructure/jest.config.js +0 -16
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
const { validateApiModuleDefinition } = require('@friggframework/schemas');
|
|
2
|
-
const { ValidationResult } = require('../../domain/entities/validation-result');
|
|
3
|
-
const { ValidationError } = require('../../domain/value-objects/validation-error');
|
|
4
|
-
|
|
5
|
-
const REQUIRED_MODULE_METHODS = ['getToken', 'getEntityDetails', 'getCredentialDetails'];
|
|
6
|
-
|
|
7
|
-
class ApiModuleValidator {
|
|
8
|
-
/**
|
|
9
|
-
* Validate API module definitions within an integration
|
|
10
|
-
* @param {object} integrationDefinition - The integration's Definition object
|
|
11
|
-
* @param {number} integrationIndex - Index of the integration in the app
|
|
12
|
-
* @returns {ValidationResult}
|
|
13
|
-
*/
|
|
14
|
-
validate(integrationDefinition, integrationIndex) {
|
|
15
|
-
const result = ValidationResult.create();
|
|
16
|
-
const prefix = `integrations[${integrationIndex}].Definition.modules`;
|
|
17
|
-
|
|
18
|
-
if (!integrationDefinition.modules || typeof integrationDefinition.modules !== 'object') {
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
Object.entries(integrationDefinition.modules).forEach(([moduleName, moduleConfig]) => {
|
|
23
|
-
const modulePath = `${prefix}.${moduleName}`;
|
|
24
|
-
|
|
25
|
-
if (!moduleConfig.definition) {
|
|
26
|
-
result.addError(ValidationError.create({
|
|
27
|
-
path: `${modulePath}.definition`,
|
|
28
|
-
message: `Module '${moduleName}' must have a definition property`,
|
|
29
|
-
severity: 'error',
|
|
30
|
-
code: 'MISSING_DEFINITION'
|
|
31
|
-
}));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this._validateModuleDefinitionWithSchema(moduleConfig.definition, modulePath, moduleName, result);
|
|
36
|
-
this._validateRequiredMethods(moduleConfig.definition, modulePath, moduleName, result);
|
|
37
|
-
this._validateApiPropertiesToPersist(moduleConfig.definition, modulePath, moduleName, result);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
_validateModuleDefinitionWithSchema(definition, modulePath, moduleName, result) {
|
|
44
|
-
// Sanitize the definition before JSON Schema validation
|
|
45
|
-
// API module definitions contain functions and classes that JSON Schema can't validate
|
|
46
|
-
const sanitizedDefinition = this._sanitizeForSchemaValidation(definition);
|
|
47
|
-
const schemaResult = validateApiModuleDefinition(sanitizedDefinition);
|
|
48
|
-
|
|
49
|
-
if (!schemaResult.valid && schemaResult.errors) {
|
|
50
|
-
schemaResult.errors.forEach(error => {
|
|
51
|
-
const path = error.instancePath
|
|
52
|
-
? `${modulePath}.definition${error.instancePath.replace(/\//g, '.')}`
|
|
53
|
-
: `${modulePath}.definition`;
|
|
54
|
-
|
|
55
|
-
result.addError(ValidationError.create({
|
|
56
|
-
path,
|
|
57
|
-
message: this._formatSchemaErrorMessage(error),
|
|
58
|
-
severity: 'error',
|
|
59
|
-
code: error.keyword?.toUpperCase() || 'SCHEMA_ERROR'
|
|
60
|
-
}));
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Create a copy of the module definition safe for JSON Schema validation.
|
|
67
|
-
* Converts functions to descriptors but preserves all properties so that
|
|
68
|
-
* unknown properties can be properly rejected by the schema.
|
|
69
|
-
*/
|
|
70
|
-
_sanitizeForSchemaValidation(definition) {
|
|
71
|
-
if (!definition) return definition;
|
|
72
|
-
|
|
73
|
-
const sanitized = {};
|
|
74
|
-
|
|
75
|
-
// Copy ALL properties, converting functions/classes to descriptors
|
|
76
|
-
// This allows JSON Schema to properly reject unknown properties
|
|
77
|
-
for (const key of Object.keys(definition)) {
|
|
78
|
-
sanitized[key] = this._sanitizeValue(definition[key]);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return sanitized;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Recursively sanitize a value for JSON Schema validation.
|
|
86
|
-
* Functions become {type: "function"} descriptors.
|
|
87
|
-
* Classes become {type: "object"} descriptors.
|
|
88
|
-
*/
|
|
89
|
-
_sanitizeValue(value) {
|
|
90
|
-
if (value === null || value === undefined) {
|
|
91
|
-
return value;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Convert functions to descriptors
|
|
95
|
-
if (typeof value === 'function') {
|
|
96
|
-
return { type: 'function', name: value.name || 'anonymous' };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Handle arrays
|
|
100
|
-
if (Array.isArray(value)) {
|
|
101
|
-
return value.map(item => this._sanitizeValue(item));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Handle objects (but not class instances with constructors other than Object)
|
|
105
|
-
if (typeof value === 'object') {
|
|
106
|
-
// Check if it's a class instance (not a plain object)
|
|
107
|
-
if (value.constructor && value.constructor.name !== 'Object') {
|
|
108
|
-
return { type: 'object', className: value.constructor.name };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Recursively sanitize plain objects
|
|
112
|
-
const sanitizedObj = {};
|
|
113
|
-
for (const [key, val] of Object.entries(value)) {
|
|
114
|
-
sanitizedObj[key] = this._sanitizeValue(val);
|
|
115
|
-
}
|
|
116
|
-
return sanitizedObj;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Primitives pass through unchanged
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
_formatSchemaErrorMessage(error) {
|
|
124
|
-
let message = error.message;
|
|
125
|
-
if (error.params?.allowedValues) {
|
|
126
|
-
message += ` (allowed: ${error.params.allowedValues.join(', ')})`;
|
|
127
|
-
}
|
|
128
|
-
if (error.params?.additionalProperty) {
|
|
129
|
-
message += `: ${error.params.additionalProperty}`;
|
|
130
|
-
}
|
|
131
|
-
if (error.params?.missingProperty) {
|
|
132
|
-
message = `must have required property '${error.params.missingProperty}'`;
|
|
133
|
-
}
|
|
134
|
-
return message;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
_validateRequiredMethods(definition, modulePath, moduleName, result) {
|
|
138
|
-
if (!definition.requiredAuthMethods) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
REQUIRED_MODULE_METHODS.forEach(method => {
|
|
143
|
-
if (!definition.requiredAuthMethods[method]) {
|
|
144
|
-
result.addError(ValidationError.create({
|
|
145
|
-
path: `${modulePath}.definition.requiredAuthMethods.${method}`,
|
|
146
|
-
message: `Module '${moduleName}' should implement ${method} method`,
|
|
147
|
-
severity: 'warning',
|
|
148
|
-
code: 'MISSING_METHOD'
|
|
149
|
-
}));
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
_validateApiPropertiesToPersist(definition, modulePath, moduleName, result) {
|
|
155
|
-
const props = definition.requiredAuthMethods?.apiPropertiesToPersist;
|
|
156
|
-
|
|
157
|
-
if (!props) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (!props.credential || !Array.isArray(props.credential) || props.credential.length === 0) {
|
|
162
|
-
result.addError(ValidationError.create({
|
|
163
|
-
path: `${modulePath}.definition.requiredAuthMethods.apiPropertiesToPersist.credential`,
|
|
164
|
-
message: `Module '${moduleName}' should specify credential properties to persist`,
|
|
165
|
-
severity: 'warning',
|
|
166
|
-
code: 'MISSING_CREDENTIAL_PROPS'
|
|
167
|
-
}));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (!props.entity || !Array.isArray(props.entity) || props.entity.length === 0) {
|
|
171
|
-
result.addError(ValidationError.create({
|
|
172
|
-
path: `${modulePath}.definition.requiredAuthMethods.apiPropertiesToPersist.entity`,
|
|
173
|
-
message: `Module '${moduleName}' should specify entity properties to persist`,
|
|
174
|
-
severity: 'warning',
|
|
175
|
-
code: 'MISSING_ENTITY_PROPS'
|
|
176
|
-
}));
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
module.exports = { ApiModuleValidator };
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
const { validateAppDefinition } = require('@friggframework/schemas');
|
|
2
|
-
const { ValidationResult } = require('../../domain/entities/validation-result');
|
|
3
|
-
const { ValidationError } = require('../../domain/value-objects/validation-error');
|
|
4
|
-
|
|
5
|
-
class AppDefinitionValidator {
|
|
6
|
-
validate(definition) {
|
|
7
|
-
const result = ValidationResult.create();
|
|
8
|
-
|
|
9
|
-
// Create a sanitized copy for JSON Schema validation
|
|
10
|
-
// Integrations contain classes/functions which JSON Schema can't validate
|
|
11
|
-
// IntegrationClassValidator handles those separately
|
|
12
|
-
const sanitizedDefinition = this._sanitizeForSchemaValidation(definition);
|
|
13
|
-
const schemaResult = validateAppDefinition(sanitizedDefinition);
|
|
14
|
-
|
|
15
|
-
if (!schemaResult.valid && schemaResult.errors) {
|
|
16
|
-
schemaResult.errors.forEach(error => {
|
|
17
|
-
result.addError(ValidationError.create({
|
|
18
|
-
path: this._convertPath(error.instancePath) || 'root',
|
|
19
|
-
message: this._formatErrorMessage(error),
|
|
20
|
-
severity: 'error',
|
|
21
|
-
code: error.keyword?.toUpperCase() || 'SCHEMA_ERROR'
|
|
22
|
-
}));
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
this._validateIntegrationDuplicates(definition, result);
|
|
27
|
-
this._validateIntegrationDefinitions(definition, result);
|
|
28
|
-
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Create a copy of the definition safe for JSON Schema validation.
|
|
34
|
-
* Replaces integration classes with stub objects since JSON Schema
|
|
35
|
-
* cannot validate JavaScript classes/functions.
|
|
36
|
-
*/
|
|
37
|
-
_sanitizeForSchemaValidation(definition) {
|
|
38
|
-
if (!definition) return definition;
|
|
39
|
-
|
|
40
|
-
const sanitized = { ...definition };
|
|
41
|
-
|
|
42
|
-
// Replace integration classes with stub objects
|
|
43
|
-
// The actual class validation is handled by IntegrationClassValidator
|
|
44
|
-
if (Array.isArray(definition.integrations)) {
|
|
45
|
-
sanitized.integrations = definition.integrations.map(integration => {
|
|
46
|
-
if (typeof integration === 'function') {
|
|
47
|
-
// Return a stub object representing the class
|
|
48
|
-
return { _isClass: true, name: integration.name };
|
|
49
|
-
}
|
|
50
|
-
return integration;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Sanitize extensions — strip functions (bootstrap, routes.handler)
|
|
55
|
-
// that JSON Schema cannot validate
|
|
56
|
-
if (Array.isArray(definition.extensions)) {
|
|
57
|
-
sanitized.extensions = definition.extensions.map(ext => {
|
|
58
|
-
const sanitizedExt = { ...ext };
|
|
59
|
-
// Remove function properties
|
|
60
|
-
if (typeof sanitizedExt.bootstrap === 'function') {
|
|
61
|
-
delete sanitizedExt.bootstrap;
|
|
62
|
-
}
|
|
63
|
-
if (sanitizedExt.routes && typeof sanitizedExt.routes.handler === 'function') {
|
|
64
|
-
sanitizedExt.routes = { ...sanitizedExt.routes };
|
|
65
|
-
delete sanitizedExt.routes.handler;
|
|
66
|
-
}
|
|
67
|
-
return sanitizedExt;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return sanitized;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
_convertPath(jsonPointerPath) {
|
|
75
|
-
if (!jsonPointerPath) return '';
|
|
76
|
-
return jsonPointerPath
|
|
77
|
-
.replace(/^\//, '')
|
|
78
|
-
.replace(/\/(\d+)/g, '[$1]')
|
|
79
|
-
.replace(/\//g, '.');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_formatErrorMessage(error) {
|
|
83
|
-
let message = error.message;
|
|
84
|
-
if (error.params?.allowedValues) {
|
|
85
|
-
message += ` (allowed: ${error.params.allowedValues.join(', ')})`;
|
|
86
|
-
}
|
|
87
|
-
if (error.params?.additionalProperty) {
|
|
88
|
-
message += `: ${error.params.additionalProperty}`;
|
|
89
|
-
}
|
|
90
|
-
if (error.params?.missingProperty) {
|
|
91
|
-
message = `must have required property '${error.params.missingProperty}'`;
|
|
92
|
-
}
|
|
93
|
-
return message;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
_validateIntegrationDefinitions(definition, result) {
|
|
97
|
-
if (!definition.integrations || !Array.isArray(definition.integrations)) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
definition.integrations.forEach((integration, index) => {
|
|
102
|
-
if (typeof integration === 'function') {
|
|
103
|
-
if (!integration.Definition) {
|
|
104
|
-
result.addError(ValidationError.create({
|
|
105
|
-
path: `integrations[${index}]`,
|
|
106
|
-
message: 'Integration class must have a static Definition property',
|
|
107
|
-
severity: 'error',
|
|
108
|
-
code: 'MISSING_DEFINITION'
|
|
109
|
-
}));
|
|
110
|
-
} else if (!integration.Definition.name) {
|
|
111
|
-
result.addError(ValidationError.create({
|
|
112
|
-
path: `integrations[${index}].Definition.name`,
|
|
113
|
-
message: 'Integration Definition must have a name property',
|
|
114
|
-
severity: 'error',
|
|
115
|
-
code: 'REQUIRED_FIELD'
|
|
116
|
-
}));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
_validateIntegrationDuplicates(definition, result) {
|
|
123
|
-
if (!definition.integrations || !Array.isArray(definition.integrations)) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const names = [];
|
|
128
|
-
definition.integrations.forEach((integration, index) => {
|
|
129
|
-
const name = integration.Definition?.name;
|
|
130
|
-
if (name) {
|
|
131
|
-
if (names.includes(name)) {
|
|
132
|
-
result.addError(ValidationError.create({
|
|
133
|
-
path: `integrations[${index}].Definition.name`,
|
|
134
|
-
message: `duplicate integration name: ${name}`,
|
|
135
|
-
severity: 'warning',
|
|
136
|
-
code: 'DUPLICATE_NAME'
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
names.push(name);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
module.exports = { AppDefinitionValidator };
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
const { validateIntegrationDefinition } = require('@friggframework/schemas');
|
|
2
|
-
const { ValidationResult } = require('../../domain/entities/validation-result');
|
|
3
|
-
const { ValidationError } = require('../../domain/value-objects/validation-error');
|
|
4
|
-
const { FixSuggestion } = require('../../domain/value-objects/fix-suggestion');
|
|
5
|
-
|
|
6
|
-
const LIFECYCLE_METHODS = ['onCreate', 'getConfigOptions', 'testAuth'];
|
|
7
|
-
|
|
8
|
-
class IntegrationClassValidator {
|
|
9
|
-
validate(integrationClass, index) {
|
|
10
|
-
const result = ValidationResult.create();
|
|
11
|
-
const prefix = `integrations[${index}]`;
|
|
12
|
-
|
|
13
|
-
if (typeof integrationClass !== 'function') {
|
|
14
|
-
result.addError(ValidationError.create({
|
|
15
|
-
path: prefix,
|
|
16
|
-
message: 'Integration must be a class (function)',
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'INVALID_TYPE'
|
|
19
|
-
}));
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!integrationClass.Definition) {
|
|
24
|
-
result.addError(ValidationError.create({
|
|
25
|
-
path: `${prefix}.Definition`,
|
|
26
|
-
message: 'Integration class must have a static Definition property',
|
|
27
|
-
severity: 'error',
|
|
28
|
-
code: 'MISSING_DEFINITION',
|
|
29
|
-
fix: FixSuggestion.create({
|
|
30
|
-
action: 'add',
|
|
31
|
-
description: 'Add static Definition property to integration class',
|
|
32
|
-
codeSnippet: `static Definition = {\n name: 'my-integration',\n version: '1.0.0',\n modules: {}\n};`
|
|
33
|
-
})
|
|
34
|
-
}));
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this._validateDefinitionWithSchema(integrationClass.Definition, prefix, result);
|
|
39
|
-
this._validateModuleNames(integrationClass.Definition, prefix, result);
|
|
40
|
-
this._validateLifecycleMethods(integrationClass, prefix, result);
|
|
41
|
-
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
_validateDefinitionWithSchema(definition, prefix, result) {
|
|
46
|
-
const schemaResult = validateIntegrationDefinition(definition);
|
|
47
|
-
|
|
48
|
-
if (!schemaResult.valid && schemaResult.errors) {
|
|
49
|
-
schemaResult.errors.forEach(error => {
|
|
50
|
-
const path = error.instancePath
|
|
51
|
-
? `${prefix}.Definition${error.instancePath.replace(/\//g, '.')}`
|
|
52
|
-
: `${prefix}.Definition`;
|
|
53
|
-
|
|
54
|
-
result.addError(ValidationError.create({
|
|
55
|
-
path,
|
|
56
|
-
message: this._formatSchemaErrorMessage(error),
|
|
57
|
-
severity: 'error',
|
|
58
|
-
code: error.keyword?.toUpperCase() || 'SCHEMA_ERROR'
|
|
59
|
-
}));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
_formatSchemaErrorMessage(error) {
|
|
65
|
-
let message = error.message;
|
|
66
|
-
if (error.params?.allowedValues) {
|
|
67
|
-
message += ` (allowed: ${error.params.allowedValues.join(', ')})`;
|
|
68
|
-
}
|
|
69
|
-
if (error.params?.additionalProperty) {
|
|
70
|
-
message += `: ${error.params.additionalProperty}`;
|
|
71
|
-
}
|
|
72
|
-
if (error.params?.missingProperty) {
|
|
73
|
-
message = `must have required property '${error.params.missingProperty}'`;
|
|
74
|
-
}
|
|
75
|
-
return message;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
_validateModuleNames(definition, prefix, result) {
|
|
79
|
-
if (!definition.modules) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
Object.entries(definition.modules).forEach(([moduleName, moduleConfig]) => {
|
|
84
|
-
// Check for moduleName (the correct property per API module schema and core Module class)
|
|
85
|
-
// Note: getName() method returns definition.moduleName, not definition.name
|
|
86
|
-
if (moduleConfig.definition && !moduleConfig.definition.moduleName) {
|
|
87
|
-
result.addError(ValidationError.create({
|
|
88
|
-
path: `${prefix}.Definition.modules.${moduleName}.definition.moduleName`,
|
|
89
|
-
message: `Module ${moduleName} definition should have a moduleName property`,
|
|
90
|
-
severity: 'warning',
|
|
91
|
-
code: 'MISSING_MODULE_NAME'
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
_validateLifecycleMethods(integrationClass, prefix, result) {
|
|
98
|
-
const proto = integrationClass.prototype;
|
|
99
|
-
|
|
100
|
-
LIFECYCLE_METHODS.forEach(method => {
|
|
101
|
-
if (typeof proto[method] !== 'function') {
|
|
102
|
-
result.addError(ValidationError.create({
|
|
103
|
-
path: `${prefix}.${method}`,
|
|
104
|
-
message: `Integration should implement ${method}() method`,
|
|
105
|
-
severity: 'warning',
|
|
106
|
-
code: 'MISSING_METHOD'
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
module.exports = { IntegrationClassValidator };
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Admin Script Builder
|
|
3
|
-
*
|
|
4
|
-
* Domain Layer - Hexagonal Architecture
|
|
5
|
-
*
|
|
6
|
-
* Responsible for:
|
|
7
|
-
* - Creating SQS queue for admin script execution
|
|
8
|
-
* - Creating Lambda function for script execution (worker)
|
|
9
|
-
* - Creating Lambda function for admin API routes (router)
|
|
10
|
-
* - Creating EventBridge Scheduler resources (Phase 2)
|
|
11
|
-
* - Creating IAM roles for scheduler to invoke Lambda
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
|
|
15
|
-
|
|
16
|
-
class AdminScriptBuilder extends InfrastructureBuilder {
|
|
17
|
-
constructor() {
|
|
18
|
-
super();
|
|
19
|
-
this.name = 'AdminScriptBuilder';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
shouldExecute(appDefinition) {
|
|
23
|
-
return Array.isArray(appDefinition.adminScripts) && appDefinition.adminScripts.length > 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getDependencies() {
|
|
27
|
-
return []; // Can run independently
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
validate(appDefinition) {
|
|
31
|
-
const result = new ValidationResult();
|
|
32
|
-
|
|
33
|
-
if (!appDefinition.adminScripts) {
|
|
34
|
-
return result; // Not an error, just no scripts
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!Array.isArray(appDefinition.adminScripts)) {
|
|
38
|
-
result.addError('adminScripts must be an array');
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Validate each script
|
|
43
|
-
appDefinition.adminScripts.forEach((script, index) => {
|
|
44
|
-
if (!script?.Definition?.name) {
|
|
45
|
-
result.addError(`Admin script at index ${index} is missing Definition or name`);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async build(appDefinition, discoveredResources) {
|
|
53
|
-
console.log(`\n[${this.name}] Configuring admin scripts...`);
|
|
54
|
-
console.log(` Processing ${appDefinition.adminScripts.length} scripts...`);
|
|
55
|
-
|
|
56
|
-
const usePrismaLayer = appDefinition.usePrismaLambdaLayer !== false;
|
|
57
|
-
const adminConfig = appDefinition.admin || {};
|
|
58
|
-
|
|
59
|
-
const result = {
|
|
60
|
-
functions: {},
|
|
61
|
-
resources: {},
|
|
62
|
-
environment: {},
|
|
63
|
-
custom: {},
|
|
64
|
-
iamStatements: [],
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// Create admin script queue
|
|
68
|
-
this.createAdminScriptQueue(result);
|
|
69
|
-
|
|
70
|
-
// Create Lambda function for script execution
|
|
71
|
-
this.createScriptExecutorFunction(result, usePrismaLayer);
|
|
72
|
-
|
|
73
|
-
// Create API routes for script management
|
|
74
|
-
this.createAdminScriptRoutes(result, usePrismaLayer);
|
|
75
|
-
|
|
76
|
-
// Phase 2: Create EventBridge Scheduler resources
|
|
77
|
-
if (adminConfig.enableScheduling) {
|
|
78
|
-
this.createSchedulerResources(appDefinition, result);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Log registered scripts
|
|
82
|
-
appDefinition.adminScripts.forEach(script => {
|
|
83
|
-
const name = script.Definition?.name || 'unknown';
|
|
84
|
-
const schedule = script.Definition?.schedule;
|
|
85
|
-
console.log(` ✓ Registered: ${name}${schedule?.enabled ? ' (scheduled)' : ''}`);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
console.log(`[${this.name}] ✅ Admin script configuration completed`);
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
createAdminScriptQueue(result) {
|
|
93
|
-
result.resources.AdminScriptQueue = {
|
|
94
|
-
Type: 'AWS::SQS::Queue',
|
|
95
|
-
Properties: {
|
|
96
|
-
QueueName: '${self:service}-${self:provider.stage}-AdminScriptQueue',
|
|
97
|
-
MessageRetentionPeriod: 86400, // 1 day
|
|
98
|
-
VisibilityTimeout: 900, // 15 minutes (Lambda max)
|
|
99
|
-
RedrivePolicy: {
|
|
100
|
-
maxReceiveCount: 3,
|
|
101
|
-
deadLetterTargetArn: {
|
|
102
|
-
'Fn::GetAtt': ['InternalErrorQueue', 'Arn'],
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
result.environment.ADMIN_SCRIPT_QUEUE_URL = { Ref: 'AdminScriptQueue' };
|
|
109
|
-
console.log(' ✓ Created AdminScriptQueue');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
createScriptExecutorFunction(result, usePrismaLayer) {
|
|
113
|
-
result.functions.adminScriptExecutor = {
|
|
114
|
-
handler: 'node_modules/@friggframework/admin-scripts/src/infrastructure/script-executor-handler.handler',
|
|
115
|
-
skipEsbuild: true,
|
|
116
|
-
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
117
|
-
timeout: 900, // 15 minutes max
|
|
118
|
-
memorySize: 1024,
|
|
119
|
-
events: [
|
|
120
|
-
{
|
|
121
|
-
sqs: {
|
|
122
|
-
arn: { 'Fn::GetAtt': ['AdminScriptQueue', 'Arn'] },
|
|
123
|
-
batchSize: 1,
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
};
|
|
128
|
-
console.log(' ✓ Created adminScriptExecutor function');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
createAdminScriptRoutes(result, usePrismaLayer) {
|
|
132
|
-
result.functions.adminScriptRouter = {
|
|
133
|
-
handler: 'node_modules/@friggframework/admin-scripts/src/infrastructure/admin-script-router.handler',
|
|
134
|
-
skipEsbuild: true,
|
|
135
|
-
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
136
|
-
timeout: 30,
|
|
137
|
-
events: [
|
|
138
|
-
// List scripts
|
|
139
|
-
{ httpApi: { path: '/admin/scripts', method: 'GET' } },
|
|
140
|
-
// Get script details
|
|
141
|
-
{ httpApi: { path: '/admin/scripts/{scriptName}', method: 'GET' } },
|
|
142
|
-
// Execute script (sync or async)
|
|
143
|
-
{ httpApi: { path: '/admin/scripts/{scriptName}/execute', method: 'POST' } },
|
|
144
|
-
// Get execution status
|
|
145
|
-
{ httpApi: { path: '/admin/executions/{executionId}', method: 'GET' } },
|
|
146
|
-
// List executions
|
|
147
|
-
{ httpApi: { path: '/admin/executions', method: 'GET' } },
|
|
148
|
-
// Schedule management (Phase 2)
|
|
149
|
-
{ httpApi: { path: '/admin/scripts/{scriptName}/schedule', method: 'GET' } },
|
|
150
|
-
{ httpApi: { path: '/admin/scripts/{scriptName}/schedule', method: 'PUT' } },
|
|
151
|
-
{ httpApi: { path: '/admin/scripts/{scriptName}/schedule', method: 'DELETE' } },
|
|
152
|
-
],
|
|
153
|
-
};
|
|
154
|
-
console.log(' ✓ Created adminScriptRouter function');
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
createSchedulerResources(appDefinition, result) {
|
|
158
|
-
// Create IAM role for EventBridge Scheduler
|
|
159
|
-
result.resources.AdminScriptSchedulerRole = {
|
|
160
|
-
Type: 'AWS::IAM::Role',
|
|
161
|
-
Properties: {
|
|
162
|
-
RoleName: '${self:service}-${self:provider.stage}-admin-script-scheduler',
|
|
163
|
-
AssumeRolePolicyDocument: {
|
|
164
|
-
Version: '2012-10-17',
|
|
165
|
-
Statement: [{
|
|
166
|
-
Effect: 'Allow',
|
|
167
|
-
Principal: { Service: 'scheduler.amazonaws.com' },
|
|
168
|
-
Action: 'sts:AssumeRole',
|
|
169
|
-
}],
|
|
170
|
-
},
|
|
171
|
-
Policies: [{
|
|
172
|
-
PolicyName: 'InvokeLambda',
|
|
173
|
-
PolicyDocument: {
|
|
174
|
-
Version: '2012-10-17',
|
|
175
|
-
Statement: [{
|
|
176
|
-
Effect: 'Allow',
|
|
177
|
-
Action: 'lambda:InvokeFunction',
|
|
178
|
-
Resource: { 'Fn::GetAtt': ['AdminScriptExecutorLambdaFunction', 'Arn'] },
|
|
179
|
-
}],
|
|
180
|
-
},
|
|
181
|
-
}],
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
// Create schedule group
|
|
186
|
-
result.resources.AdminScriptScheduleGroup = {
|
|
187
|
-
Type: 'AWS::Scheduler::ScheduleGroup',
|
|
188
|
-
Properties: {
|
|
189
|
-
Name: '${self:service}-${self:provider.stage}-admin-scripts',
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
result.environment.SCHEDULER_ROLE_ARN = { 'Fn::GetAtt': ['AdminScriptSchedulerRole', 'Arn'] };
|
|
194
|
-
result.environment.SCHEDULE_GROUP_NAME = { Ref: 'AdminScriptScheduleGroup' };
|
|
195
|
-
|
|
196
|
-
console.log(' ✓ Created EventBridge Scheduler resources');
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
module.exports = { AdminScriptBuilder };
|