@friggframework/devtools 2.0.0--canary.545.ae2019f.0 → 2.0.0--canary.549.a579cca.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 (127) hide show
  1. package/frigg-cli/README.md +1 -1
  2. package/frigg-cli/__tests__/unit/commands/build.test.js +1 -1
  3. package/frigg-cli/__tests__/unit/commands/doctor.test.js +2 -0
  4. package/frigg-cli/__tests__/unit/commands/install.test.js +19 -23
  5. package/frigg-cli/__tests__/unit/dependencies.test.js +2 -2
  6. package/frigg-cli/build-command/index.js +11 -123
  7. package/frigg-cli/deploy-command/index.js +1 -83
  8. package/frigg-cli/doctor-command/index.js +16 -37
  9. package/frigg-cli/generate-iam-command.js +1 -21
  10. package/frigg-cli/index.js +6 -21
  11. package/frigg-cli/index.test.js +2 -7
  12. package/frigg-cli/init-command/backend-first-handler.js +42 -124
  13. package/frigg-cli/init-command/index.js +1 -2
  14. package/frigg-cli/init-command/template-handler.js +3 -13
  15. package/frigg-cli/install-command/backend-js.js +3 -3
  16. package/frigg-cli/install-command/environment-variables.js +19 -16
  17. package/frigg-cli/install-command/environment-variables.test.js +13 -12
  18. package/frigg-cli/install-command/index.js +9 -14
  19. package/frigg-cli/install-command/integration-file.js +3 -3
  20. package/frigg-cli/install-command/logger.js +12 -0
  21. package/frigg-cli/install-command/validate-package.js +9 -5
  22. package/frigg-cli/jest.config.js +1 -4
  23. package/frigg-cli/repair-command/index.js +128 -121
  24. package/frigg-cli/start-command/index.js +2 -324
  25. package/frigg-cli/ui-command/index.js +36 -58
  26. package/frigg-cli/utils/repo-detection.js +37 -85
  27. package/infrastructure/create-frigg-infrastructure.js +0 -93
  28. package/infrastructure/docs/iam-policy-templates.md +1 -1
  29. package/infrastructure/domains/networking/vpc-builder.test.js +4 -2
  30. package/infrastructure/domains/networking/vpc-resolver.test.js +1 -1
  31. package/infrastructure/domains/shared/resource-discovery.js +5 -5
  32. package/infrastructure/domains/shared/types/app-definition.js +0 -21
  33. package/infrastructure/domains/shared/types/discovery-result.test.js +1 -1
  34. package/infrastructure/domains/shared/utilities/base-definition-factory.js +1 -10
  35. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +2 -2
  36. package/infrastructure/infrastructure-composer.js +0 -2
  37. package/infrastructure/infrastructure-composer.test.js +2 -2
  38. package/management-ui/README.md +109 -245
  39. package/package.json +7 -8
  40. package/frigg-cli/__tests__/application/use-cases/AddApiModuleToIntegrationUseCase.test.js +0 -326
  41. package/frigg-cli/__tests__/application/use-cases/CreateApiModuleUseCase.test.js +0 -337
  42. package/frigg-cli/__tests__/domain/entities/ApiModule.test.js +0 -373
  43. package/frigg-cli/__tests__/domain/entities/AppDefinition.test.js +0 -313
  44. package/frigg-cli/__tests__/domain/services/IntegrationValidator.test.js +0 -269
  45. package/frigg-cli/__tests__/domain/value-objects/IntegrationName.test.js +0 -82
  46. package/frigg-cli/__tests__/infrastructure/adapters/IntegrationJsUpdater.test.js +0 -408
  47. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemApiModuleRepository.test.js +0 -583
  48. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemAppDefinitionRepository.test.js +0 -314
  49. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemIntegrationRepository.test.js +0 -383
  50. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -406
  51. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -383
  52. package/frigg-cli/__tests__/unit/commands/repair.test.js +0 -275
  53. package/frigg-cli/__tests__/unit/start-command/application/RunPreflightChecksUseCase.test.js +0 -411
  54. package/frigg-cli/__tests__/unit/start-command/infrastructure/DatabaseAdapter.test.js +0 -405
  55. package/frigg-cli/__tests__/unit/start-command/infrastructure/DockerAdapter.test.js +0 -496
  56. package/frigg-cli/__tests__/unit/start-command/presentation/InteractivePromptAdapter.test.js +0 -474
  57. package/frigg-cli/__tests__/unit/utils/output.test.js +0 -196
  58. package/frigg-cli/application/use-cases/AddApiModuleToIntegrationUseCase.js +0 -93
  59. package/frigg-cli/application/use-cases/CreateApiModuleUseCase.js +0 -93
  60. package/frigg-cli/application/use-cases/CreateIntegrationUseCase.js +0 -103
  61. package/frigg-cli/container.js +0 -172
  62. package/frigg-cli/docs/OUTPUT_MIGRATION_GUIDE.md +0 -286
  63. package/frigg-cli/domain/entities/ApiModule.js +0 -272
  64. package/frigg-cli/domain/entities/AppDefinition.js +0 -227
  65. package/frigg-cli/domain/entities/Integration.js +0 -198
  66. package/frigg-cli/domain/exceptions/DomainException.js +0 -24
  67. package/frigg-cli/domain/ports/IApiModuleRepository.js +0 -53
  68. package/frigg-cli/domain/ports/IAppDefinitionRepository.js +0 -43
  69. package/frigg-cli/domain/ports/IIntegrationRepository.js +0 -61
  70. package/frigg-cli/domain/services/IntegrationValidator.js +0 -185
  71. package/frigg-cli/domain/value-objects/IntegrationId.js +0 -42
  72. package/frigg-cli/domain/value-objects/IntegrationName.js +0 -60
  73. package/frigg-cli/domain/value-objects/SemanticVersion.js +0 -70
  74. package/frigg-cli/infrastructure/UnitOfWork.js +0 -46
  75. package/frigg-cli/infrastructure/adapters/BackendJsUpdater.js +0 -197
  76. package/frigg-cli/infrastructure/adapters/FileSystemAdapter.js +0 -224
  77. package/frigg-cli/infrastructure/adapters/IntegrationJsUpdater.js +0 -249
  78. package/frigg-cli/infrastructure/adapters/SchemaValidator.js +0 -92
  79. package/frigg-cli/infrastructure/repositories/FileSystemApiModuleRepository.js +0 -373
  80. package/frigg-cli/infrastructure/repositories/FileSystemAppDefinitionRepository.js +0 -116
  81. package/frigg-cli/infrastructure/repositories/FileSystemIntegrationRepository.js +0 -277
  82. package/frigg-cli/package-lock.json +0 -16226
  83. package/frigg-cli/start-command/application/RunPreflightChecksUseCase.js +0 -376
  84. package/frigg-cli/start-command/infrastructure/DatabaseAdapter.js +0 -591
  85. package/frigg-cli/start-command/infrastructure/DockerAdapter.js +0 -306
  86. package/frigg-cli/start-command/presentation/InteractivePromptAdapter.js +0 -329
  87. package/frigg-cli/templates/backend/.env.example +0 -62
  88. package/frigg-cli/templates/backend/.eslintrc.json +0 -12
  89. package/frigg-cli/templates/backend/.prettierrc +0 -6
  90. package/frigg-cli/templates/backend/docker-compose.yml +0 -22
  91. package/frigg-cli/templates/backend/index.js +0 -96
  92. package/frigg-cli/templates/backend/infrastructure.js +0 -12
  93. package/frigg-cli/templates/backend/jest.config.js +0 -17
  94. package/frigg-cli/templates/backend/package.json +0 -50
  95. package/frigg-cli/templates/backend/src/api-modules/.gitkeep +0 -10
  96. package/frigg-cli/templates/backend/src/base/.gitkeep +0 -7
  97. package/frigg-cli/templates/backend/src/integrations/.gitkeep +0 -10
  98. package/frigg-cli/templates/backend/src/integrations/ExampleIntegration.js +0 -65
  99. package/frigg-cli/templates/backend/src/utils/.gitkeep +0 -7
  100. package/frigg-cli/templates/backend/test/setup.js +0 -30
  101. package/frigg-cli/templates/backend/ui-extensions/.gitkeep +0 -0
  102. package/frigg-cli/templates/backend/ui-extensions/README.md +0 -77
  103. package/frigg-cli/utils/__tests__/provider-helper.test.js +0 -55
  104. package/frigg-cli/utils/__tests__/repo-detection.test.js +0 -436
  105. package/frigg-cli/utils/output.js +0 -382
  106. package/frigg-cli/utils/provider-helper.js +0 -75
  107. package/frigg-cli/validate-command/__tests__/adapters/validate-command.test.js +0 -205
  108. package/frigg-cli/validate-command/__tests__/application/validate-app-use-case.test.js +0 -104
  109. package/frigg-cli/validate-command/__tests__/domain/fix-suggestion.test.js +0 -153
  110. package/frigg-cli/validate-command/__tests__/domain/validation-error.test.js +0 -162
  111. package/frigg-cli/validate-command/__tests__/domain/validation-result.test.js +0 -152
  112. package/frigg-cli/validate-command/__tests__/infrastructure/api-module-validator.test.js +0 -332
  113. package/frigg-cli/validate-command/__tests__/infrastructure/app-definition-validator.test.js +0 -191
  114. package/frigg-cli/validate-command/__tests__/infrastructure/integration-class-validator.test.js +0 -146
  115. package/frigg-cli/validate-command/__tests__/infrastructure/template-validation.test.js +0 -155
  116. package/frigg-cli/validate-command/adapters/cli/validate-command.js +0 -199
  117. package/frigg-cli/validate-command/application/use-cases/validate-app-use-case.js +0 -35
  118. package/frigg-cli/validate-command/domain/entities/validation-result.js +0 -74
  119. package/frigg-cli/validate-command/domain/value-objects/fix-suggestion.js +0 -74
  120. package/frigg-cli/validate-command/domain/value-objects/validation-error.js +0 -68
  121. package/frigg-cli/validate-command/infrastructure/validators/api-module-validator.js +0 -181
  122. package/frigg-cli/validate-command/infrastructure/validators/app-definition-validator.js +0 -128
  123. package/frigg-cli/validate-command/infrastructure/validators/integration-class-validator.js +0 -113
  124. package/infrastructure/domains/admin-scripts/admin-script-builder.js +0 -200
  125. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -499
  126. package/infrastructure/domains/admin-scripts/index.js +0 -5
  127. 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,128 +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
- return sanitized;
55
- }
56
-
57
- _convertPath(jsonPointerPath) {
58
- if (!jsonPointerPath) return '';
59
- return jsonPointerPath
60
- .replace(/^\//, '')
61
- .replace(/\/(\d+)/g, '[$1]')
62
- .replace(/\//g, '.');
63
- }
64
-
65
- _formatErrorMessage(error) {
66
- let message = error.message;
67
- if (error.params?.allowedValues) {
68
- message += ` (allowed: ${error.params.allowedValues.join(', ')})`;
69
- }
70
- if (error.params?.additionalProperty) {
71
- message += `: ${error.params.additionalProperty}`;
72
- }
73
- if (error.params?.missingProperty) {
74
- message = `must have required property '${error.params.missingProperty}'`;
75
- }
76
- return message;
77
- }
78
-
79
- _validateIntegrationDefinitions(definition, result) {
80
- if (!definition.integrations || !Array.isArray(definition.integrations)) {
81
- return;
82
- }
83
-
84
- definition.integrations.forEach((integration, index) => {
85
- if (typeof integration === 'function') {
86
- if (!integration.Definition) {
87
- result.addError(ValidationError.create({
88
- path: `integrations[${index}]`,
89
- message: 'Integration class must have a static Definition property',
90
- severity: 'error',
91
- code: 'MISSING_DEFINITION'
92
- }));
93
- } else if (!integration.Definition.name) {
94
- result.addError(ValidationError.create({
95
- path: `integrations[${index}].Definition.name`,
96
- message: 'Integration Definition must have a name property',
97
- severity: 'error',
98
- code: 'REQUIRED_FIELD'
99
- }));
100
- }
101
- }
102
- });
103
- }
104
-
105
- _validateIntegrationDuplicates(definition, result) {
106
- if (!definition.integrations || !Array.isArray(definition.integrations)) {
107
- return;
108
- }
109
-
110
- const names = [];
111
- definition.integrations.forEach((integration, index) => {
112
- const name = integration.Definition?.name;
113
- if (name) {
114
- if (names.includes(name)) {
115
- result.addError(ValidationError.create({
116
- path: `integrations[${index}].Definition.name`,
117
- message: `duplicate integration name: ${name}`,
118
- severity: 'warning',
119
- code: 'DUPLICATE_NAME'
120
- }));
121
- }
122
- names.push(name);
123
- }
124
- });
125
- }
126
- }
127
-
128
- 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 };