@friggframework/devtools 2.0.0--canary.743.d13a976.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 (29) 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/edge/cloudfront-builder.js +237 -0
  16. package/infrastructure/domains/edge/cloudfront-builder.test.js +273 -0
  17. package/infrastructure/domains/integration/integration-builder.js +1 -34
  18. package/infrastructure/domains/integration/integration-builder.test.js +0 -86
  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/utilities/base-definition-factory.js +9 -2
  25. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +11 -0
  26. package/infrastructure/infrastructure-composer.js +8 -0
  27. package/infrastructure/infrastructure-composer.test.js +35 -0
  28. package/package.json +7 -7
  29. package/infrastructure/domains/integration/queue-worker-concurrency.js +0 -85
@@ -9,7 +9,7 @@ const path = require('path');
9
9
  * granted for `*<serviceName>*`, because `frigg deploy` names the stack,
10
10
  * functions, role, queues, topics, alarms, log groups, layer and buckets
11
11
  * after the service, not after "frigg".
12
- * @param {Object} [options.features={}] - Enabled features { vpc, kms, ssm, websockets }
12
+ * @param {Object} [options.features={}] - Enabled features { vpc, kms, ssm, websockets, cloudFront }
13
13
  * @param {string} [options.userPrefix='frigg-deployment-user'] - IAM user name prefix
14
14
  * @param {string} [options.stackName='frigg-deployment-iam'] - CloudFormation stack name
15
15
  * @param {string} [options.ssmKmsKeyArn] - Customer-managed KMS key ARN for SecureString offload (appDefinition.ssm.kmsKeyArn)
@@ -28,7 +28,7 @@ function generateIAMCloudFormation(options = {}) {
28
28
  const deploymentUserName = userPrefix;
29
29
 
30
30
  // Features are already analyzed by caller (use getFeatureSummary to extract features from appDefinition)
31
- // Expected features: { vpc, kms, ssm, websockets }
31
+ // Expected features: { vpc, kms, ssm, websockets, cloudFront }
32
32
 
33
33
  // Build the CloudFormation template
34
34
  const template = {
@@ -576,6 +576,48 @@ function generateIAMCloudFormation(options = {}) {
576
576
  }
577
577
  );
578
578
 
579
+ // Opt-in CloudFront edge (cloudFront.enable): the distribution in front of
580
+ // the HTTP API that gives clients hybrid post-quantum TLS. Distribution
581
+ // ids are random, so the scope is the account's distributions.
582
+ if (features.cloudFront) {
583
+ coreStatements.push(
584
+ {
585
+ Sid: 'FriggCloudFrontDistributions',
586
+ Effect: 'Allow',
587
+ Action: [
588
+ 'cloudfront:CreateDistribution',
589
+ 'cloudfront:CreateDistributionWithTags',
590
+ 'cloudfront:UpdateDistribution',
591
+ 'cloudfront:DeleteDistribution',
592
+ 'cloudfront:GetDistribution',
593
+ 'cloudfront:GetDistributionConfig',
594
+ 'cloudfront:TagResource',
595
+ 'cloudfront:UntagResource',
596
+ 'cloudfront:ListTagsForResource',
597
+ ],
598
+ Resource: [
599
+ {
600
+ 'Fn::Sub':
601
+ 'arn:aws:cloudfront::${AWS::AccountId}:distribution/*',
602
+ },
603
+ ],
604
+ },
605
+ {
606
+ // Read-only: the AWS managed cache and origin request
607
+ // policies, and the ACM certificate of a custom domain.
608
+ Sid: 'FriggCloudFrontReadPolicies',
609
+ Effect: 'Allow',
610
+ Action: [
611
+ 'cloudfront:GetCachePolicy',
612
+ 'cloudfront:GetOriginRequestPolicy',
613
+ 'acm:DescribeCertificate',
614
+ 'acm:ListCertificates',
615
+ ],
616
+ Resource: '*',
617
+ }
618
+ );
619
+ }
620
+
579
621
  template.Resources.FriggCoreDeploymentPolicy = {
580
622
  Type: 'AWS::IAM::ManagedPolicy',
581
623
  Properties: {
@@ -899,6 +941,7 @@ function getFeatureSummary(appDefinition) {
899
941
  kms: appDefinition.encryption?.fieldLevelEncryptionMethod === 'kms',
900
942
  ssm: appDefinition.ssm?.enable === true,
901
943
  websockets: appDefinition.websockets?.enable === true,
944
+ cloudFront: appDefinition.cloudFront?.enable === true,
902
945
  };
903
946
 
904
947
  const integrationCount = appDefinition.integrations?.length || 0;
@@ -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(),
@@ -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.743.d13a976.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.743.d13a976.0",
32
- "@friggframework/schemas": "2.0.0--canary.743.d13a976.0",
33
- "@friggframework/test": "2.0.0--canary.743.d13a976.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.743.d13a976.0",
62
- "@friggframework/prettier-config": "2.0.0--canary.743.d13a976.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": "d13a976018ff2a673f3309523aa7c5a725bb97b6"
94
+ "gitHead": "0209482d12a8c95727025314afa125d406b56515"
95
95
  }
@@ -1,85 +0,0 @@
1
- /**
2
- * ADR-049 section 6, pacing 2a: the queue worker's maximum concurrency comes
3
- * from the `maxConcurrency` that the integration's API modules declare in
4
- * `static rateLimit`. The module only describes the provider; devtools
5
- * decides the deployment.
6
- *
7
- * `maximumConcurrency` limits the whole queue of the integration, for every
8
- * tenant, while `maxConcurrency` describes one key of the provider. So the
9
- * integration decides it: `Definition.queueWorker.maximumConcurrency` sets
10
- * it (an integer), or turns it off (`false`). When the integration sets
11
- * nothing, the value is the smallest `maxConcurrency` of its modules.
12
- * It becomes the SQS event source's `maximumConcurrency`, which AWS bounds to
13
- * 2..1000, and never more than the worker's reserved concurrency. An SQS
14
- * event source that hits `maximumConcurrency` leaves the messages in the
15
- * queue: unlike a lower reserved concurrency, it does not throttle them and
16
- * does not spend their receives.
17
- */
18
-
19
- const SQS_MIN_MAXIMUM_CONCURRENCY = 2;
20
-
21
- function moduleApiClasses(integration) {
22
- const modules = integration?.Definition?.modules ?? {};
23
- return Object.values(modules)
24
- .map((entry) => (entry?.definition ?? entry)?.API)
25
- .filter((API) => typeof API === 'function');
26
- }
27
-
28
- /** The smallest declared `maxConcurrency`, or undefined. */
29
- function declaredMaxConcurrency(integration) {
30
- let smallest;
31
- for (const API of moduleApiClasses(integration)) {
32
- let value;
33
- try {
34
- value = API.rateLimit?.maxConcurrency;
35
- } catch {
36
- value = undefined;
37
- }
38
- if (Number.isInteger(value) && value > 0) {
39
- smallest =
40
- smallest === undefined ? value : Math.min(smallest, value);
41
- }
42
- }
43
- return smallest;
44
- }
45
-
46
- /**
47
- * Where the value comes from: the integration's own setting, or its modules.
48
- * Throws for a setting that is neither a positive integer nor `false`.
49
- * @returns {{ value: number|undefined, source: 'integration'|'modules'|'off'|'none' }}
50
- */
51
- function queueWorkerConcurrencySource(integration) {
52
- const setting = integration?.Definition?.queueWorker?.maximumConcurrency;
53
- if (setting === false) return { value: undefined, source: 'off' };
54
- if (Number.isInteger(setting) && setting > 0) {
55
- return { value: setting, source: 'integration' };
56
- }
57
- if (setting !== undefined) {
58
- throw new Error(
59
- `Definition.queueWorker.maximumConcurrency of integration "${integration?.Definition?.name}" must be an integer from 2 to 1000, or false`
60
- );
61
- }
62
- const declared = declaredMaxConcurrency(integration);
63
- return declared === undefined
64
- ? { value: undefined, source: 'none' }
65
- : { value: declared, source: 'modules' };
66
- }
67
-
68
- /**
69
- * @returns {number|undefined} the SQS `maximumConcurrency` for the queue
70
- * worker, or undefined when it is off, nothing declares a value, or the
71
- * value is not below the reserved concurrency.
72
- */
73
- function queueWorkerMaximumConcurrency(integration, reservedConcurrency) {
74
- const declared = queueWorkerConcurrencySource(integration).value;
75
- if (declared === undefined) return undefined;
76
- const value = Math.max(declared, SQS_MIN_MAXIMUM_CONCURRENCY);
77
- return value < reservedConcurrency ? value : undefined;
78
- }
79
-
80
- module.exports = {
81
- SQS_MIN_MAXIMUM_CONCURRENCY,
82
- declaredMaxConcurrency,
83
- queueWorkerConcurrencySource,
84
- queueWorkerMaximumConcurrency,
85
- };