@friggframework/devtools 2.0.0--canary.548.c8ae0ca.0 → 2.0.0--canary.545.c40eca4.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__/application/use-cases/AddApiModuleToIntegrationUseCase.test.js +326 -0
  3. package/frigg-cli/__tests__/application/use-cases/CreateApiModuleUseCase.test.js +337 -0
  4. package/frigg-cli/__tests__/domain/entities/ApiModule.test.js +373 -0
  5. package/frigg-cli/__tests__/domain/entities/AppDefinition.test.js +313 -0
  6. package/frigg-cli/__tests__/domain/services/IntegrationValidator.test.js +269 -0
  7. package/frigg-cli/__tests__/domain/value-objects/IntegrationName.test.js +82 -0
  8. package/frigg-cli/__tests__/infrastructure/adapters/IntegrationJsUpdater.test.js +408 -0
  9. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemApiModuleRepository.test.js +583 -0
  10. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemAppDefinitionRepository.test.js +314 -0
  11. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemIntegrationRepository.test.js +383 -0
  12. package/frigg-cli/__tests__/unit/commands/build.test.js +1 -1
  13. package/frigg-cli/__tests__/unit/commands/doctor.test.js +0 -2
  14. package/frigg-cli/__tests__/unit/commands/init.test.js +406 -0
  15. package/frigg-cli/__tests__/unit/commands/install.test.js +23 -19
  16. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +383 -0
  17. package/frigg-cli/__tests__/unit/commands/repair.test.js +275 -0
  18. package/frigg-cli/__tests__/unit/dependencies.test.js +2 -2
  19. package/frigg-cli/__tests__/unit/start-command/application/RunPreflightChecksUseCase.test.js +411 -0
  20. package/frigg-cli/__tests__/unit/start-command/infrastructure/DatabaseAdapter.test.js +405 -0
  21. package/frigg-cli/__tests__/unit/start-command/infrastructure/DockerAdapter.test.js +496 -0
  22. package/frigg-cli/__tests__/unit/start-command/presentation/InteractivePromptAdapter.test.js +474 -0
  23. package/frigg-cli/__tests__/unit/utils/output.test.js +196 -0
  24. package/frigg-cli/application/use-cases/AddApiModuleToIntegrationUseCase.js +93 -0
  25. package/frigg-cli/application/use-cases/CreateApiModuleUseCase.js +93 -0
  26. package/frigg-cli/application/use-cases/CreateIntegrationUseCase.js +103 -0
  27. package/frigg-cli/build-command/index.js +123 -11
  28. package/frigg-cli/container.js +172 -0
  29. package/frigg-cli/deploy-command/index.js +83 -1
  30. package/frigg-cli/docs/OUTPUT_MIGRATION_GUIDE.md +286 -0
  31. package/frigg-cli/doctor-command/index.js +37 -16
  32. package/frigg-cli/domain/entities/ApiModule.js +272 -0
  33. package/frigg-cli/domain/entities/AppDefinition.js +227 -0
  34. package/frigg-cli/domain/entities/Integration.js +198 -0
  35. package/frigg-cli/domain/exceptions/DomainException.js +24 -0
  36. package/frigg-cli/domain/ports/IApiModuleRepository.js +53 -0
  37. package/frigg-cli/domain/ports/IAppDefinitionRepository.js +43 -0
  38. package/frigg-cli/domain/ports/IIntegrationRepository.js +61 -0
  39. package/frigg-cli/domain/services/IntegrationValidator.js +185 -0
  40. package/frigg-cli/domain/value-objects/IntegrationId.js +42 -0
  41. package/frigg-cli/domain/value-objects/IntegrationName.js +60 -0
  42. package/frigg-cli/domain/value-objects/SemanticVersion.js +70 -0
  43. package/frigg-cli/generate-iam-command.js +21 -1
  44. package/frigg-cli/index.js +21 -6
  45. package/frigg-cli/index.test.js +7 -2
  46. package/frigg-cli/infrastructure/UnitOfWork.js +46 -0
  47. package/frigg-cli/infrastructure/adapters/BackendJsUpdater.js +197 -0
  48. package/frigg-cli/infrastructure/adapters/FileSystemAdapter.js +224 -0
  49. package/frigg-cli/infrastructure/adapters/IntegrationJsUpdater.js +249 -0
  50. package/frigg-cli/infrastructure/adapters/SchemaValidator.js +92 -0
  51. package/frigg-cli/infrastructure/repositories/FileSystemApiModuleRepository.js +373 -0
  52. package/frigg-cli/infrastructure/repositories/FileSystemAppDefinitionRepository.js +116 -0
  53. package/frigg-cli/infrastructure/repositories/FileSystemIntegrationRepository.js +277 -0
  54. package/frigg-cli/init-command/backend-first-handler.js +124 -42
  55. package/frigg-cli/init-command/index.js +2 -1
  56. package/frigg-cli/init-command/template-handler.js +13 -3
  57. package/frigg-cli/install-command/backend-js.js +3 -3
  58. package/frigg-cli/install-command/environment-variables.js +16 -19
  59. package/frigg-cli/install-command/environment-variables.test.js +12 -13
  60. package/frigg-cli/install-command/index.js +14 -9
  61. package/frigg-cli/install-command/integration-file.js +3 -3
  62. package/frigg-cli/install-command/validate-package.js +5 -9
  63. package/frigg-cli/jest.config.js +4 -1
  64. package/frigg-cli/package-lock.json +16226 -0
  65. package/frigg-cli/repair-command/index.js +121 -128
  66. package/frigg-cli/start-command/application/RunPreflightChecksUseCase.js +376 -0
  67. package/frigg-cli/start-command/index.js +324 -2
  68. package/frigg-cli/start-command/infrastructure/DatabaseAdapter.js +591 -0
  69. package/frigg-cli/start-command/infrastructure/DockerAdapter.js +306 -0
  70. package/frigg-cli/start-command/presentation/InteractivePromptAdapter.js +329 -0
  71. package/frigg-cli/templates/backend/.env.example +62 -0
  72. package/frigg-cli/templates/backend/.eslintrc.json +12 -0
  73. package/frigg-cli/templates/backend/.prettierrc +6 -0
  74. package/frigg-cli/templates/backend/docker-compose.yml +22 -0
  75. package/frigg-cli/templates/backend/index.js +96 -0
  76. package/frigg-cli/templates/backend/infrastructure.js +12 -0
  77. package/frigg-cli/templates/backend/jest.config.js +17 -0
  78. package/frigg-cli/templates/backend/package.json +50 -0
  79. package/frigg-cli/templates/backend/src/api-modules/.gitkeep +10 -0
  80. package/frigg-cli/templates/backend/src/base/.gitkeep +7 -0
  81. package/frigg-cli/templates/backend/src/integrations/.gitkeep +10 -0
  82. package/frigg-cli/templates/backend/src/integrations/ExampleIntegration.js +65 -0
  83. package/frigg-cli/templates/backend/src/utils/.gitkeep +7 -0
  84. package/frigg-cli/templates/backend/test/setup.js +30 -0
  85. package/frigg-cli/templates/backend/ui-extensions/.gitkeep +0 -0
  86. package/frigg-cli/templates/backend/ui-extensions/README.md +77 -0
  87. package/frigg-cli/ui-command/index.js +58 -36
  88. package/frigg-cli/utils/__tests__/provider-helper.test.js +55 -0
  89. package/frigg-cli/utils/__tests__/repo-detection.test.js +436 -0
  90. package/frigg-cli/utils/output.js +382 -0
  91. package/frigg-cli/utils/provider-helper.js +75 -0
  92. package/frigg-cli/utils/repo-detection.js +85 -37
  93. package/frigg-cli/validate-command/__tests__/adapters/validate-command.test.js +205 -0
  94. package/frigg-cli/validate-command/__tests__/application/validate-app-use-case.test.js +104 -0
  95. package/frigg-cli/validate-command/__tests__/domain/fix-suggestion.test.js +153 -0
  96. package/frigg-cli/validate-command/__tests__/domain/validation-error.test.js +162 -0
  97. package/frigg-cli/validate-command/__tests__/domain/validation-result.test.js +152 -0
  98. package/frigg-cli/validate-command/__tests__/infrastructure/api-module-validator.test.js +332 -0
  99. package/frigg-cli/validate-command/__tests__/infrastructure/app-definition-validator.test.js +191 -0
  100. package/frigg-cli/validate-command/__tests__/infrastructure/integration-class-validator.test.js +146 -0
  101. package/frigg-cli/validate-command/__tests__/infrastructure/template-validation.test.js +155 -0
  102. package/frigg-cli/validate-command/adapters/cli/validate-command.js +199 -0
  103. package/frigg-cli/validate-command/application/use-cases/validate-app-use-case.js +35 -0
  104. package/frigg-cli/validate-command/domain/entities/validation-result.js +74 -0
  105. package/frigg-cli/validate-command/domain/value-objects/fix-suggestion.js +74 -0
  106. package/frigg-cli/validate-command/domain/value-objects/validation-error.js +68 -0
  107. package/frigg-cli/validate-command/infrastructure/validators/api-module-validator.js +181 -0
  108. package/frigg-cli/validate-command/infrastructure/validators/app-definition-validator.js +128 -0
  109. package/frigg-cli/validate-command/infrastructure/validators/integration-class-validator.js +113 -0
  110. package/infrastructure/create-frigg-infrastructure.js +93 -0
  111. package/infrastructure/docs/iam-policy-templates.md +1 -1
  112. package/infrastructure/domains/admin-scripts/admin-script-builder.js +200 -0
  113. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +499 -0
  114. package/infrastructure/domains/admin-scripts/index.js +5 -0
  115. package/infrastructure/domains/networking/vpc-builder.test.js +2 -4
  116. package/infrastructure/domains/networking/vpc-resolver.test.js +1 -1
  117. package/infrastructure/domains/shared/resource-discovery.js +5 -5
  118. package/infrastructure/domains/shared/types/app-definition.js +21 -0
  119. package/infrastructure/domains/shared/types/discovery-result.test.js +1 -1
  120. package/infrastructure/domains/shared/utilities/base-definition-factory.js +10 -1
  121. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +2 -2
  122. package/infrastructure/infrastructure-composer.js +2 -0
  123. package/infrastructure/infrastructure-composer.test.js +2 -2
  124. package/infrastructure/jest.config.js +16 -0
  125. package/management-ui/README.md +245 -109
  126. package/package.json +8 -7
  127. package/frigg-cli/install-command/logger.js +0 -12
@@ -0,0 +1,68 @@
1
+ const VALID_SEVERITIES = ['error', 'warning', 'info'];
2
+
3
+ class ValidationError {
4
+ constructor({ path, message, severity, code, fix }) {
5
+ if (!path) {
6
+ throw new Error('path is required');
7
+ }
8
+ if (!message) {
9
+ throw new Error('message is required');
10
+ }
11
+ if (severity && !VALID_SEVERITIES.includes(severity)) {
12
+ throw new Error(`Invalid severity: ${severity}. Must be one of: ${VALID_SEVERITIES.join(', ')}`);
13
+ }
14
+
15
+ this.path = path;
16
+ this.message = message;
17
+ this.severity = severity || 'error';
18
+ this.code = code || null;
19
+ this.fix = fix || null;
20
+ }
21
+
22
+ static create(props) {
23
+ return new ValidationError(props);
24
+ }
25
+
26
+ getPathSegments() {
27
+ return this.path
28
+ .replace(/\[(\d+)\]/g, '.$1')
29
+ .split('.')
30
+ .filter(Boolean);
31
+ }
32
+
33
+ getRootPath() {
34
+ return this.getPathSegments()[0];
35
+ }
36
+
37
+ isError() {
38
+ return this.severity === 'error';
39
+ }
40
+
41
+ isWarning() {
42
+ return this.severity === 'warning';
43
+ }
44
+
45
+ isInfo() {
46
+ return this.severity === 'info';
47
+ }
48
+
49
+ hasFix() {
50
+ return this.fix !== null;
51
+ }
52
+
53
+ equals(other) {
54
+ return this.path === other.path && this.message === other.message;
55
+ }
56
+
57
+ toJSON() {
58
+ return {
59
+ path: this.path,
60
+ message: this.message,
61
+ severity: this.severity,
62
+ code: this.code,
63
+ fix: this.fix ? this.fix.toJSON() : null
64
+ };
65
+ }
66
+ }
67
+
68
+ module.exports = { ValidationError };
@@ -0,0 +1,181 @@
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 };
@@ -0,0 +1,128 @@
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 };
@@ -0,0 +1,113 @@
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 };
@@ -23,6 +23,92 @@ function isProcessRunning(pid) {
23
23
  }
24
24
  }
25
25
 
26
+ /**
27
+ * Build for a non-AWS provider.
28
+ *
29
+ * When infrastructure.js is invoked (e.g. `node infrastructure.js package`),
30
+ * but the appDefinition specifies a non-AWS provider, we skip the entire
31
+ * serverless/CloudFormation pipeline and instead:
32
+ * 1. Validate the appDefinition against the provider
33
+ * 2. Generate the provider-specific config (e.g. netlify.toml)
34
+ * 3. Generate function entry points
35
+ *
36
+ * This mirrors what the CLI's buildCommand does for non-AWS providers,
37
+ * but works when invoked directly via `node infrastructure.js package`.
38
+ */
39
+ async function buildWithProvider(appDefinition, providerName, backendDir) {
40
+ const { resolveProvider } = require('@friggframework/core/providers/resolve-provider');
41
+ const provider = resolveProvider(appDefinition);
42
+
43
+ console.log(`Building for ${providerName} provider (skipping AWS infrastructure)...`);
44
+
45
+ // 1. Validate
46
+ if (typeof provider.validate === 'function') {
47
+ const validation = provider.validate(appDefinition);
48
+ if (validation.errors?.length > 0) {
49
+ console.error(`\nValidation errors for ${providerName}:`);
50
+ for (const error of validation.errors) {
51
+ console.error(` - ${error}`);
52
+ }
53
+ process.exit(1);
54
+ }
55
+ if (validation.warnings?.length > 0) {
56
+ for (const warning of validation.warnings) {
57
+ console.warn(` Warning: ${warning}`);
58
+ }
59
+ }
60
+ }
61
+
62
+ // 2. Generate platform config (e.g. netlify.toml)
63
+ // Written to the project root (one level up from backend/)
64
+ const projectDir = path.dirname(backendDir);
65
+ if (typeof provider.generateConfig === 'function') {
66
+ const config = provider.generateConfig(appDefinition);
67
+ const configFileNames = { netlify: 'netlify.toml' };
68
+ const configFileName = configFileNames[providerName] || `${providerName}.config`;
69
+ const configPath = path.join(projectDir, configFileName);
70
+
71
+ fs.writeFileSync(configPath, config, 'utf-8');
72
+ console.log(` Written ${configFileName}`);
73
+ }
74
+
75
+ // 3. Generate function entry points
76
+ if (typeof provider.getFunctionEntryPoints === 'function') {
77
+ const entryPoints = provider.getFunctionEntryPoints(appDefinition);
78
+ const functionsDir = path.join(projectDir, 'netlify', 'functions');
79
+
80
+ fs.mkdirSync(functionsDir, { recursive: true });
81
+
82
+ for (const [filename, content] of Object.entries(entryPoints)) {
83
+ const filePath = path.join(functionsDir, filename);
84
+ fs.writeFileSync(filePath, content, 'utf-8');
85
+ }
86
+
87
+ console.log(` Generated ${Object.keys(entryPoints).length} function entry points`);
88
+ }
89
+
90
+ // 4. Generate lib entry points (re-export shims for runtime dependencies)
91
+ if (typeof provider.getLibEntryPoints === 'function') {
92
+ const libEntryPoints = provider.getLibEntryPoints(appDefinition);
93
+ const libDir = path.join(projectDir, 'netlify', 'lib');
94
+
95
+ fs.mkdirSync(libDir, { recursive: true });
96
+
97
+ for (const [filename, content] of Object.entries(libEntryPoints)) {
98
+ const filePath = path.join(libDir, filename);
99
+ fs.writeFileSync(filePath, content, 'utf-8');
100
+ }
101
+
102
+ console.log(` Generated ${Object.keys(libEntryPoints).length} lib entry points`);
103
+ }
104
+
105
+ console.log(`\nBuild complete for ${providerName}.`);
106
+
107
+ // Return an empty serverless definition — osls will see no functions
108
+ // and effectively no-op. The real deployment is handled by the provider.
109
+ return {};
110
+ }
111
+
26
112
  async function createFriggInfrastructure() {
27
113
  const backendPath = findNearestBackendPackageJson();
28
114
  if (!backendPath) {
@@ -104,6 +190,13 @@ async function createFriggInfrastructure() {
104
190
  const backend = require(backendFilePath);
105
191
  const appDefinition = backend.Definition;
106
192
 
193
+ // Check if a non-AWS provider is configured.
194
+ // If so, run the provider's build pipeline instead of AWS CloudFormation.
195
+ const providerName = appDefinition.provider || 'aws';
196
+ if (providerName !== 'aws') {
197
+ return buildWithProvider(appDefinition, providerName, backendDir);
198
+ }
199
+
107
200
  const definition = await composeServerlessDefinition(
108
201
  appDefinition,
109
202
  );
@@ -160,7 +160,7 @@ Consider separate policies for different environments:
160
160
  ### Validation
161
161
  Test your policy by deploying a simple Frigg app:
162
162
  ```bash
163
- npx create-frigg-app test-deployment
163
+ frigg init test-deployment
164
164
  cd test-deployment
165
165
  frigg deploy
166
166
  ```