@friggframework/devtools 2.0.0--canary.744.e18e27f.0 → 2.0.0--canary.745.0209482d.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 (30) hide show
  1. package/frigg-cli/README.md +41 -1
  2. package/frigg-cli/generate-command/__tests__/generate-command.test.js +36 -0
  3. package/frigg-cli/generate-command/index.js +3 -1
  4. package/frigg-cli/generate-command/terraform-generator.js +48 -0
  5. package/frigg-cli/generate-iam-command.js +1 -0
  6. package/frigg-cli/index.js +8 -0
  7. package/frigg-cli/templates/backend/README.md +3 -2
  8. package/frigg-cli/tls-check-command/__tests__/check-post-quantum-tls.test.js +396 -0
  9. package/frigg-cli/tls-check-command/__tests__/tls-check-command.test.js +182 -0
  10. package/frigg-cli/tls-check-command/check-post-quantum-tls.js +194 -0
  11. package/frigg-cli/tls-check-command/index.js +136 -0
  12. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +69 -0
  13. package/frigg-cli/validate-command/checks/config.js +59 -0
  14. package/infrastructure/app-definition-schema-contract.test.js +10 -0
  15. package/infrastructure/domains/admin-scripts/admin-script-builder.js +8 -16
  16. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -27
  17. package/infrastructure/domains/edge/cloudfront-builder.js +237 -0
  18. package/infrastructure/domains/edge/cloudfront-builder.test.js +273 -0
  19. package/infrastructure/domains/security/iam-generator.js +45 -2
  20. package/infrastructure/domains/security/iam-generator.test.js +23 -0
  21. package/infrastructure/domains/security/templates/iam-policy-full.json +30 -1
  22. package/infrastructure/domains/shared/builder-orchestrator.js +6 -0
  23. package/infrastructure/domains/shared/builder-orchestrator.test.js +30 -0
  24. package/infrastructure/domains/shared/function-environments.js +6 -10
  25. package/infrastructure/domains/shared/function-environments.test.js +0 -9
  26. package/infrastructure/domains/shared/utilities/base-definition-factory.js +9 -2
  27. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +11 -0
  28. package/infrastructure/infrastructure-composer.js +8 -0
  29. package/infrastructure/infrastructure-composer.test.js +35 -0
  30. package/package.json +7 -7
@@ -98,6 +98,29 @@ describe('IAM Generator', () => {
98
98
  expect(yaml).toContain('FriggDiscoveryPolicy');
99
99
  });
100
100
 
101
+ it('detects the CloudFront edge feature', () => {
102
+ expect(getFeatureSummary({ cloudFront: { enable: true } }).features.cloudFront).toBe(true);
103
+ expect(getFeatureSummary({}).features.cloudFront).toBe(false);
104
+ });
105
+
106
+ it('grants CloudFront distribution permissions only when cloudFront is enabled', () => {
107
+ const withEdge = generateIAMCloudFormation({
108
+ appName: 'test-app',
109
+ features: getFeatureSummary({ cloudFront: { enable: true } }).features,
110
+ });
111
+ const withoutEdge = generateIAMCloudFormation({
112
+ appName: 'test-app',
113
+ features: getFeatureSummary({}).features,
114
+ });
115
+
116
+ expect(withEdge).toContain('FriggCloudFront');
117
+ expect(withEdge).toContain('cloudfront:CreateDistribution');
118
+ expect(withEdge).toContain('cloudfront:UpdateDistribution');
119
+ expect(withEdge).toContain('cloudfront:DeleteDistribution');
120
+ expect(withEdge).toContain('arn:aws:cloudfront::${AWS::AccountId}:distribution/*');
121
+ expect(withoutEdge).not.toContain('cloudfront:');
122
+ });
123
+
101
124
  it('should include VPC policy when VPC is enabled', () => {
102
125
  const appDefinition = {
103
126
  name: 'test-app',
@@ -289,6 +289,35 @@
289
289
  "arn:aws:ssm:*:*:parameter/*frigg*",
290
290
  "arn:aws:ssm:*:*:parameter/*frigg*/*"
291
291
  ]
292
+ },
293
+ {
294
+ "Sid": "FriggCloudFrontDistributions",
295
+ "Effect": "Allow",
296
+ "Action": [
297
+ "cloudfront:CreateDistribution",
298
+ "cloudfront:CreateDistributionWithTags",
299
+ "cloudfront:UpdateDistribution",
300
+ "cloudfront:DeleteDistribution",
301
+ "cloudfront:GetDistribution",
302
+ "cloudfront:GetDistributionConfig",
303
+ "cloudfront:TagResource",
304
+ "cloudfront:UntagResource",
305
+ "cloudfront:ListTagsForResource"
306
+ ],
307
+ "Resource": [
308
+ "arn:aws:cloudfront::*:distribution/*"
309
+ ]
310
+ },
311
+ {
312
+ "Sid": "FriggCloudFrontReadPolicies",
313
+ "Effect": "Allow",
314
+ "Action": [
315
+ "cloudfront:GetCachePolicy",
316
+ "cloudfront:GetOriginRequestPolicy",
317
+ "acm:DescribeCertificate",
318
+ "acm:ListCertificates"
319
+ ],
320
+ "Resource": "*"
292
321
  }
293
322
  ]
294
- }
323
+ }
@@ -148,6 +148,7 @@ class BuilderOrchestrator {
148
148
  layers: {},
149
149
  plugins: [],
150
150
  custom: {},
151
+ outputs: {},
151
152
  vpcConfig: null,
152
153
  };
153
154
 
@@ -204,6 +205,11 @@ class BuilderOrchestrator {
204
205
  Object.assign(merged.custom, result.custom);
205
206
  }
206
207
 
208
+ // Merge CloudFormation stack outputs
209
+ if (result.outputs) {
210
+ Object.assign(merged.outputs, result.outputs);
211
+ }
212
+
207
213
  // Capture VPC config (from VpcBuilder)
208
214
  if (result.vpcConfig) {
209
215
  merged.vpcConfig = result.vpcConfig;
@@ -180,6 +180,36 @@ describe('BuilderOrchestrator', () => {
180
180
  expect(result.merged.environment).toMatchObject({ VAR_B: 'value-b' });
181
181
  });
182
182
 
183
+ it('should merge CloudFormation outputs from builders', async () => {
184
+ class OutputBuilder extends InfrastructureBuilder {
185
+ getName() { return 'OutputBuilder'; }
186
+ shouldExecute() { return true; }
187
+ validate() { return new ValidationResult(); }
188
+ async build() {
189
+ return {
190
+ resources: { Thing: { Type: 'Test' } },
191
+ outputs: { ThingUrl: { Value: { Ref: 'Thing' } } },
192
+ };
193
+ }
194
+ }
195
+
196
+ orchestrator = new BuilderOrchestrator([new MockBuilderA(), new OutputBuilder()]);
197
+
198
+ const result = await orchestrator.buildAll({ featureA: true });
199
+
200
+ expect(result.merged.outputs).toEqual({
201
+ ThingUrl: { Value: { Ref: 'Thing' } },
202
+ });
203
+ });
204
+
205
+ it('should give an empty outputs map when no builder has outputs', async () => {
206
+ orchestrator = new BuilderOrchestrator([new MockBuilderA()]);
207
+
208
+ const result = await orchestrator.buildAll({ featureA: true });
209
+
210
+ expect(result.merged.outputs).toEqual({});
211
+ });
212
+
183
213
  it('should skip builders that should not execute', async () => {
184
214
  orchestrator = new BuilderOrchestrator([
185
215
  new MockBuilderA(),
@@ -74,21 +74,17 @@ function getIntegrationFunctionNames(integration) {
74
74
  }
75
75
 
76
76
  /**
77
- * Admin-script functions, when AdminScriptBuilder creates them: the app
78
- * declares admin scripts, or turns on the built-in scripts. Both can
79
- * instantiate arbitrary integrations, so they belong in every
80
- * integration's queue-URL consumer set.
77
+ * Admin-script functions, when the feature is on (mirrors
78
+ * AdminScriptBuilder.shouldExecute). Both can instantiate arbitrary
79
+ * integrations, so they belong in every integration's queue-URL consumer
80
+ * set.
81
81
  *
82
82
  * @param {Object} appDefinition
83
83
  * @returns {string[]}
84
84
  */
85
85
  function getAdminFunctionNames(appDefinition = {}) {
86
- const hasAppScripts =
87
- Array.isArray(appDefinition.adminScripts) &&
88
- appDefinition.adminScripts.length > 0;
89
- const hasBuiltinScripts =
90
- appDefinition.admin?.includeBuiltinScripts === true;
91
- return hasAppScripts || hasBuiltinScripts
86
+ return Array.isArray(appDefinition.adminScripts) &&
87
+ appDefinition.adminScripts.length > 0
92
88
  ? ['adminScriptRouter', 'adminScriptExecutor']
93
89
  : [];
94
90
  }
@@ -92,15 +92,6 @@ describe('function-environments', () => {
92
92
  expect(getAdminFunctionNames({})).toEqual([]);
93
93
  expect(getAdminFunctionNames({ adminScripts: [] })).toEqual([]);
94
94
  });
95
-
96
- it('returns the admin functions when only the built-in scripts are on', () => {
97
- expect(
98
- getAdminFunctionNames({ admin: { includeBuiltinScripts: true } })
99
- ).toEqual(['adminScriptRouter', 'adminScriptExecutor']);
100
- expect(
101
- getAdminFunctionNames({ admin: { includeBuiltinScripts: false } })
102
- ).toEqual([]);
103
- });
104
95
  });
105
96
 
106
97
  describe('applyFunctionEnvironments', () => {
@@ -15,6 +15,13 @@ const {
15
15
  bundledPrismaEngineExcludes,
16
16
  } = require('../lambda-architectures');
17
17
 
18
+ /**
19
+ * The Node.js runtime of every Frigg Lambda function and of the Prisma layer.
20
+ * Node.js 22.20 and later bundle OpenSSL 3.5, which offers hybrid
21
+ * post-quantum TLS key exchange (X25519MLKEM768) by default.
22
+ */
23
+ const LAMBDA_NODE_RUNTIME = 'nodejs22.x';
24
+
18
25
  /**
19
26
  * Create base serverless definition with core functions and resources
20
27
  *
@@ -185,7 +192,7 @@ function createBaseDefinition(
185
192
  provider: {
186
193
  name: AppDefinition.provider || 'aws',
187
194
  ...(process.env.AWS_PROFILE && { profile: process.env.AWS_PROFILE }),
188
- runtime: 'nodejs22.x', // Node.js 22.x (latest Lambda runtime with AWS SDK v3)
195
+ runtime: LAMBDA_NODE_RUNTIME,
189
196
  ...(architecture.explicit && { architecture: architecture.name }),
190
197
  timeout: 29, // Set to 29s to give buffer before API Gateway's 30s timeout
191
198
  region,
@@ -352,7 +359,7 @@ function createBaseDefinition(
352
359
  path: 'layers/prisma',
353
360
  name: '${self:service}-prisma-${sls:stage}',
354
361
  description: 'Prisma runtime client only (NO CLI) with the query engine for the deployed Lambda architecture (~10-15MB). CLI packaged separately in dbMigrate function.',
355
- compatibleRuntimes: ['nodejs20.x', 'nodejs22.x'],
362
+ compatibleRuntimes: [LAMBDA_NODE_RUNTIME],
356
363
  ...(architecture.explicit && {
357
364
  compatibleArchitectures: [architecture.name],
358
365
  }),
@@ -125,6 +125,17 @@ describe('Base Definition Factory', () => {
125
125
  expect(result.layers.prisma.description).toContain('runtime client only');
126
126
  });
127
127
 
128
+ it('marks the Prisma layer compatible only with the deployed Node.js runtime', () => {
129
+ // nodejs20.x is end-of-life and its OpenSSL 3.0 has no hybrid
130
+ // post-quantum TLS key exchange (X25519MLKEM768).
131
+ const result = createBaseDefinition({}, {}, {});
132
+
133
+ expect(result.layers.prisma.compatibleRuntimes).toEqual([
134
+ result.provider.runtime,
135
+ ]);
136
+ expect(result.layers.prisma.compatibleRuntimes).not.toContain('nodejs20.x');
137
+ });
138
+
128
139
  it('should include error handling resources', () => {
129
140
  const result = createBaseDefinition({}, {}, {});
130
141
 
@@ -18,6 +18,7 @@ const { WebsocketBuilder } = require('./domains/integration/websocket-builder');
18
18
  const { IntegrationBuilder } = require('./domains/integration/integration-builder');
19
19
  const { SchedulerBuilder } = require('./domains/scheduler/scheduler-builder');
20
20
  const { AdminScriptBuilder } = require('./domains/admin-scripts/admin-script-builder');
21
+ const { CloudFrontBuilder } = require('./domains/edge/cloudfront-builder');
21
22
 
22
23
  // Utilities
23
24
  const { applyFunctionEnvironments } = require('./domains/shared/function-environments');
@@ -104,6 +105,7 @@ const composeServerlessDefinition = async (AppDefinition) => {
104
105
  new IntegrationBuilder(),
105
106
  new SchedulerBuilder(), // Add scheduler after IntegrationBuilder (depends on it)
106
107
  new AdminScriptBuilder(),
108
+ new CloudFrontBuilder(), // Opt-in: hybrid post-quantum TLS for clients
107
109
  ]);
108
110
 
109
111
  // Build all infrastructure (orchestrator handles validation, dependencies, parallel execution)
@@ -121,6 +123,12 @@ const composeServerlessDefinition = async (AppDefinition) => {
121
123
 
122
124
  // Merge builder results into definition
123
125
  Object.assign(definition.resources.Resources, merged.resources);
126
+ if (Object.keys(merged.outputs).length > 0) {
127
+ definition.resources.Outputs = {
128
+ ...definition.resources.Outputs,
129
+ ...merged.outputs,
130
+ };
131
+ }
124
132
  definition.provider.iamRoleStatements.push(...merged.iamStatements);
125
133
  Object.assign(definition.provider.environment, merged.environment);
126
134
  Object.assign(definition.functions, merged.functions);
@@ -137,6 +137,41 @@ describe('composeServerlessDefinition', () => {
137
137
  });
138
138
  });
139
139
 
140
+ describe('CloudFront edge (hybrid post-quantum TLS for clients)', () => {
141
+ it('adds no distribution and no outputs by default', async () => {
142
+ const result = await composeServerlessDefinition({ name: 'test-app', integrations: [] });
143
+
144
+ expect(result.resources.Resources.FriggCloudFrontDistribution).toBeUndefined();
145
+ expect(result.resources.Outputs?.FriggCloudFrontUrl).toBeUndefined();
146
+ });
147
+
148
+ it('adds the distribution in front of the HttpApi and its URL output when enabled', async () => {
149
+ const result = await composeServerlessDefinition({
150
+ name: 'test-app',
151
+ integrations: [],
152
+ cloudFront: { enable: true },
153
+ });
154
+
155
+ const distribution = result.resources.Resources.FriggCloudFrontDistribution;
156
+ expect(distribution.Type).toBe('AWS::CloudFront::Distribution');
157
+ expect(
158
+ distribution.Properties.DistributionConfig.Origins[0].DomainName['Fn::Join'][1][0]
159
+ ).toEqual({ Ref: 'HttpApi' });
160
+ expect(result.resources.Outputs.FriggCloudFrontUrl).toBeDefined();
161
+ expect(result.resources.Outputs.FriggCloudFrontDistributionId).toBeDefined();
162
+ });
163
+
164
+ it('fails the build on an invalid cloudFront configuration', async () => {
165
+ await expect(
166
+ composeServerlessDefinition({
167
+ name: 'test-app',
168
+ integrations: [],
169
+ cloudFront: { enable: true, domainNames: ['api.example.com'] },
170
+ })
171
+ ).rejects.toThrow(/validation failed/i);
172
+ });
173
+ });
174
+
140
175
  describe('Basic Configuration', () => {
141
176
  it('should create basic serverless definition with minimal app definition', async () => {
142
177
  const appDefinition = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/devtools",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.744.e18e27f.0",
4
+ "version": "2.0.0--canary.745.0209482d.0",
5
5
  "bin": {
6
6
  "frigg": "./frigg-cli/index.js"
7
7
  },
@@ -28,9 +28,9 @@
28
28
  "@babel/eslint-parser": "^7.18.9",
29
29
  "@babel/parser": "^7.25.3",
30
30
  "@babel/traverse": "^7.25.3",
31
- "@friggframework/core": "2.0.0--canary.744.e18e27f.0",
32
- "@friggframework/schemas": "2.0.0--canary.744.e18e27f.0",
33
- "@friggframework/test": "2.0.0--canary.744.e18e27f.0",
31
+ "@friggframework/core": "2.0.0--canary.745.0209482d.0",
32
+ "@friggframework/schemas": "2.0.0--canary.745.0209482d.0",
33
+ "@friggframework/test": "2.0.0--canary.745.0209482d.0",
34
34
  "@hapi/boom": "^10.0.1",
35
35
  "@inquirer/prompts": "^5.3.8",
36
36
  "axios": "^1.18.0",
@@ -58,8 +58,8 @@
58
58
  "validate-npm-package-name": "^5.0.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@friggframework/eslint-config": "2.0.0--canary.744.e18e27f.0",
62
- "@friggframework/prettier-config": "2.0.0--canary.744.e18e27f.0",
61
+ "@friggframework/eslint-config": "2.0.0--canary.745.0209482d.0",
62
+ "@friggframework/prettier-config": "2.0.0--canary.745.0209482d.0",
63
63
  "aws-sdk-client-mock": "^4.1.0",
64
64
  "aws-sdk-client-mock-jest": "^4.1.0",
65
65
  "jest": "^30.1.3",
@@ -91,5 +91,5 @@
91
91
  "publishConfig": {
92
92
  "access": "public"
93
93
  },
94
- "gitHead": "e18e27f133f0afa7723d361b61ef8e7e80a830ef"
94
+ "gitHead": "0209482d12a8c95727025314afa125d406b56515"
95
95
  }