@friggframework/devtools 2.0.0--canary.643.45b1fbc.0 → 2.0.0--canary.645.2234921.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.
@@ -285,6 +285,24 @@ const appDefinition = {
285
285
 
286
286
  > ℹ️ When `usePrismaLambdaLayer: false`, Prisma stays inside each bundle and the runtime automatically loads the correct binary. No extra configuration is required.
287
287
 
288
+ **Keeping nested node_modules in Lambda packages:**
289
+
290
+ By default every function package excludes `node_modules/**/node_modules/**`. npm only nests a package when the root copy cannot satisfy a dependant, so the exclusion makes a package resolve whatever version is hoisted, and it removes the package entirely when the root copy is a dev dependency. The first `require` of such a package then fails at Lambda init with `Runtime.ImportModuleError`.
291
+
292
+ To ship the dependency tree the way npm resolved it, opt in per app:
293
+
294
+ ```javascript
295
+ const appDefinition = {
296
+ name: 'my-app',
297
+ lambda: {
298
+ keepNestedNodeModules: true,
299
+ },
300
+ integrations: [{ Definition: { name: 'salesforce' } }],
301
+ };
302
+ ```
303
+
304
+ Nested copies of `@friggframework/*`, `aws-sdk`, `@aws-sdk/*` and, when the Prisma layer is enabled, `@prisma/*` and `.prisma` stay excluded: the app's single core, the Lambda runtime and the layer provide them. Expect each function package to grow by the size of the nested directories that remain (a few MB compressed in a typical app). The default stays unchanged for apps that do not set the flag.
305
+
288
306
  ## Usage Examples
289
307
 
290
308
  ### Basic Deployment
@@ -15,6 +15,7 @@
15
15
 
16
16
  const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
17
17
  const { isScopedEnvironmentActive } = require('../shared/function-environments');
18
+ const { nestedNodeModulesExcludes } = require('../shared/utilities/nested-node-modules');
18
19
 
19
20
  class AdminScriptBuilder extends InfrastructureBuilder {
20
21
  constructor() {
@@ -407,7 +408,7 @@ class AdminScriptBuilder extends InfrastructureBuilder {
407
408
  'node_modules/@friggframework/core/generated/**',
408
409
  ]
409
410
  : []),
410
- 'node_modules/**/node_modules/**',
411
+ ...nestedNodeModulesExcludes(appDefinition, usePrismaLayer),
411
412
  'node_modules/@friggframework/test/**',
412
413
  'node_modules/@friggframework/eslint-config/**',
413
414
  'node_modules/@friggframework/prettier-config/**',
@@ -984,3 +984,34 @@ describe('AdminScriptBuilder', () => {
984
984
  });
985
985
  });
986
986
  });
987
+
988
+ describe('AdminScriptBuilder nested node_modules (lambda.keepNestedNodeModules)', () => {
989
+ const appDefinition = (lambda) => ({
990
+ adminScripts: [{ Definition: { name: 'test-script' } }],
991
+ ...(lambda && { lambda }),
992
+ });
993
+ const executorAndRouter = (result) => [
994
+ result.functions.adminScriptExecutor,
995
+ result.functions.adminScriptRouter,
996
+ ];
997
+
998
+ it('excludes every nested node_modules by default', async () => {
999
+ const result = await new AdminScriptBuilder().build(appDefinition(), {});
1000
+
1001
+ for (const fn of executorAndRouter(result)) {
1002
+ expect(fn.package.exclude).toContain('node_modules/**/node_modules/**');
1003
+ }
1004
+ });
1005
+
1006
+ it('keeps nested node_modules when the app opts in, still excluding nested Frigg copies', async () => {
1007
+ const result = await new AdminScriptBuilder().build(
1008
+ appDefinition({ keepNestedNodeModules: true }),
1009
+ {}
1010
+ );
1011
+
1012
+ for (const fn of executorAndRouter(result)) {
1013
+ expect(fn.package.exclude).not.toContain('node_modules/**/node_modules/**');
1014
+ expect(fn.package.exclude).toContain('node_modules/**/node_modules/@friggframework/**');
1015
+ }
1016
+ });
1017
+ });
@@ -94,206 +94,21 @@ class AuroraBuilder extends InfrastructureBuilder {
94
94
  }
95
95
 
96
96
  // Validate capacity settings
97
- // minCapacity accepts 0 (Aurora Serverless v2 scale-to-zero, GA Nov 2024)
98
- // OR a value in [0.5, 128]. Values in (0, 0.5) are not a valid Aurora
99
- // capacity — reject them explicitly. See ADR-033.
100
- if (
101
- dbConfig.minCapacity !== undefined &&
102
- dbConfig.minCapacity !== 0 &&
103
- (dbConfig.minCapacity < 0.5 || dbConfig.minCapacity > 128)
104
- ) {
105
- result.addError('database.postgres.minCapacity must be 0 (scale-to-zero) or between 0.5 and 128');
97
+ if (dbConfig.minCapacity !== undefined && (dbConfig.minCapacity < 0.5 || dbConfig.minCapacity > 128)) {
98
+ result.addError('database.postgres.minCapacity must be between 0.5 and 128');
106
99
  }
107
100
  if (dbConfig.maxCapacity !== undefined && (dbConfig.maxCapacity < 0.5 || dbConfig.maxCapacity > 128)) {
108
101
  result.addError('database.postgres.maxCapacity must be between 0.5 and 128');
109
102
  }
110
- // Cross-check: minCapacity must not exceed maxCapacity, or CloudFormation
111
- // rejects the ServerlessV2ScalingConfiguration at deploy time.
112
- if (
113
- dbConfig.minCapacity !== undefined &&
114
- dbConfig.maxCapacity !== undefined &&
115
- dbConfig.minCapacity > dbConfig.maxCapacity
116
- ) {
117
- result.addError(
118
- `database.postgres.minCapacity (${dbConfig.minCapacity}) must be <= maxCapacity (${dbConfig.maxCapacity})`
119
- );
120
- }
121
-
122
- // Validate scale-to-zero auto-pause window (seconds). AWS-valid range is
123
- // 300–86400 (5 minutes to 24 hours) and it must be an integer.
124
- if (dbConfig.secondsUntilAutoPause !== undefined) {
125
- const s = dbConfig.secondsUntilAutoPause;
126
- if (!Number.isInteger(s) || s < 300 || s > 86400) {
127
- result.addError('database.postgres.secondsUntilAutoPause must be an integer between 300 and 86400');
128
- }
129
- // secondsUntilAutoPause only takes effect for scale-to-zero clusters.
130
- if (dbConfig.minCapacity !== 0) {
131
- result.addWarning(
132
- 'database.postgres.secondsUntilAutoPause is ignored unless minCapacity is 0 (scale-to-zero).'
133
- );
134
- }
135
- }
136
-
137
- // Validate connectivity mode. 'vpc' (default) keeps today's behavior;
138
- // 'public' places Aurora in public subnets and leaves the Lambda out of
139
- // the VPC (NAT-free). See ADR-033.
140
- if (dbConfig.connectivity !== undefined) {
141
- const validConnectivity = ['vpc', 'public'];
142
- if (!validConnectivity.includes(dbConfig.connectivity)) {
143
- result.addError(
144
- `Invalid database.postgres.connectivity: "${dbConfig.connectivity}". Must be one of: ${validConnectivity.join(', ')}`
145
- );
146
- }
147
- }
148
-
149
- // Public connectivity requires an enabled VPC (Aurora must live in a VPC —
150
- // an AWS constraint — and the builder creates the public subnets there).
151
- // Validate it here so the failure is a clear message rather than a downstream
152
- // "Aurora requires 2 public subnets" throw.
153
- if (dbConfig.connectivity === 'public' && appDefinition.vpc?.enable !== true) {
154
- result.addError(
155
- 'database.postgres.connectivity="public" requires vpc.enable=true (Aurora needs public subnets in a VPC).'
156
- );
157
- }
158
-
159
- // Validate allowedCidrs is an array of syntactically valid IPv4 CIDRs when
160
- // present. NOTE: IPv4 only — IPv6 (CidrIpv6) is not supported here.
161
- if (dbConfig.allowedCidrs !== undefined) {
162
- if (!Array.isArray(dbConfig.allowedCidrs)) {
163
- result.addError('database.postgres.allowedCidrs must be an array of CIDR strings');
164
- } else {
165
- const bad = dbConfig.allowedCidrs.filter((c) => !this.isValidIpv4Cidr(c));
166
- if (bad.length > 0) {
167
- result.addError(
168
- `database.postgres.allowedCidrs contains invalid CIDR value(s): ${bad.join(', ')}`
169
- );
170
- }
171
- // An empty allowlist in public mode is almost always a mistake that
172
- // would silently fall back to 0.0.0.0/0 (full internet exposure) —
173
- // reject it so "allow nothing" cannot mean "allow everything".
174
- if (dbConfig.allowedCidrs.length === 0 && dbConfig.connectivity === 'public') {
175
- result.addError(
176
- 'database.postgres.allowedCidrs is empty with connectivity="public". List at least one CIDR ' +
177
- "(use ['0.0.0.0/0'] to intentionally allow the whole internet)."
178
- );
179
- }
180
- }
181
- }
182
-
183
- // Scale-to-zero requires a supported engine version. Warn (do not
184
- // hard-fail) if the user pins an older version with minCapacity: 0.
185
- // Frigg's default engineVersion (15.13) qualifies. Minimum
186
- // scale-to-zero-capable versions: Aurora PG 13.15 / 14.12 / 15.7 / 16.3.
187
- if (dbConfig.minCapacity === 0 && dbConfig.engineVersion) {
188
- if (!this.engineSupportsScaleToZero(dbConfig.engineVersion)) {
189
- result.addWarning(
190
- `database.postgres.engineVersion="${dbConfig.engineVersion}" may not support Aurora Serverless v2 scale-to-zero (minCapacity: 0). ` +
191
- 'Scale-to-zero requires Aurora PostgreSQL 13.15+/14.12+/15.7+/16.3+.'
192
- );
193
- }
194
- }
195
103
 
196
104
  // Warn about public accessibility in production
197
105
  if (dbConfig.publiclyAccessible === true) {
198
106
  result.addWarning('database.postgres.publiclyAccessible=true is not recommended for production');
199
107
  }
200
108
 
201
- // ADR-033 security posture: public connectivity exposes the DB endpoint
202
- // to the internet. Make the trade-off loud.
203
- if (dbConfig.connectivity === 'public') {
204
- result.addWarning(
205
- 'database.postgres.connectivity="public" exposes the Aurora endpoint to the internet. ' +
206
- 'TLS is enforced (sslmode=require) and access is restricted to allowedCidrs, but prefer "vpc" for production.'
207
- );
208
- // Only the default fallback (empty array is now an error above) or an
209
- // explicit 0.0.0.0/0 reaches here as "whole internet".
210
- const cidrs =
211
- Array.isArray(dbConfig.allowedCidrs) && dbConfig.allowedCidrs.length > 0
212
- ? dbConfig.allowedCidrs
213
- : ['0.0.0.0/0'];
214
- if (cidrs.includes('0.0.0.0/0')) {
215
- result.addWarning(
216
- 'database.postgres.allowedCidrs allows 0.0.0.0/0 (the whole internet). ' +
217
- 'Narrow this to known egress ranges wherever the deployment can.'
218
- );
219
- }
220
-
221
- // Public connectivity only makes Frigg place the cluster in public
222
- // subnets when Frigg CREATES the cluster (management='managed'). In
223
- // discover/use-existing mode Frigg cannot flip an existing cluster to
224
- // public subnets / PubliclyAccessible, yet the Lambda is still detached
225
- // from the VPC — so if the existing cluster is private it becomes
226
- // unreachable. Warn loudly. (management defaults to 'discover'.)
227
- const mgmt = dbConfig.management || 'discover';
228
- if (mgmt === 'discover' || mgmt === 'use-existing') {
229
- result.addWarning(
230
- `database.postgres.connectivity="public" with management="${mgmt}" assumes the EXISTING Aurora cluster ` +
231
- 'is already publicly accessible. Frigg detaches the Lambda from the VPC in public mode, so a private ' +
232
- 'existing cluster will be unreachable. Ensure the cluster has a public endpoint and open security group.'
233
- );
234
- }
235
- if (mgmt === 'use-existing') {
236
- result.addWarning(
237
- 'database.postgres.connectivity="public" with management="use-existing" only affects TLS (sslmode=require) on the ' +
238
- 'connection string — Frigg does not manage the existing cluster\'s subnets or ingress.'
239
- );
240
- }
241
- }
242
-
243
109
  return result;
244
110
  }
245
111
 
246
- /**
247
- * Validate an IPv4 CIDR string with real numeric range checks (each octet
248
- * 0–255, prefix 0–32) — not just shape — so values like 999.999.999.999/99
249
- * are rejected. IPv4 only; IPv6 is out of scope for allowedCidrs.
250
- * @param {string} cidr
251
- * @returns {boolean}
252
- */
253
- isValidIpv4Cidr(cidr) {
254
- if (typeof cidr !== 'string') {
255
- return false;
256
- }
257
- const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,2})$/.exec(cidr);
258
- if (!match) {
259
- return false;
260
- }
261
- const octets = [match[1], match[2], match[3], match[4]].map(Number);
262
- if (octets.some((o) => o > 255)) {
263
- return false;
264
- }
265
- const prefix = Number(match[5]);
266
- return prefix >= 0 && prefix <= 32;
267
- }
268
-
269
- /**
270
- * Determine whether an Aurora PostgreSQL engine version supports
271
- * Serverless v2 scale-to-zero (minCapacity: 0). Minimum capable versions:
272
- * 13.15+, 14.12+, 15.7+, 16.3+. Unknown/unparseable versions return true
273
- * (assume-capable) so we never hard-block on a version string we can't read;
274
- * this only gates a warning, never a hard failure.
275
- * @param {string} engineVersion e.g. '15.13'
276
- * @returns {boolean}
277
- */
278
- engineSupportsScaleToZero(engineVersion) {
279
- const minByMajor = { 13: 15, 14: 12, 15: 7, 16: 3 };
280
- const match = /^(\d+)\.(\d+)/.exec(String(engineVersion));
281
- if (!match) {
282
- return true; // can't parse — don't warn spuriously
283
- }
284
- const major = Number(match[1]);
285
- const minor = Number(match[2]);
286
- // Majors newer than the table are assumed capable.
287
- if (major > 16) {
288
- return true;
289
- }
290
- // Majors older than 13 never support scale-to-zero.
291
- if (!(major in minByMajor)) {
292
- return false;
293
- }
294
- return minor >= minByMajor[major];
295
- }
296
-
297
112
  /**
298
113
  * Build Aurora infrastructure using ownership-based architecture
299
114
  */
@@ -512,32 +327,16 @@ class AuroraBuilder extends InfrastructureBuilder {
512
327
  }
513
328
  }
514
329
 
515
- // Mirror config into translated.database.postgres.config for completeness.
516
- // NOTE: this is NOT the load-bearing path — createNewAurora/discoverAurora
517
- // read the TOP-LEVEL database.postgres fields (preserved by the deep clone
518
- // above), and 0-propagation for scale-to-zero comes from that clone plus the
519
- // `?? 0.5` in the scaling config, not from here. These `.config.*` copies are
520
- // kept only so any future consumer that reads `config` sees the same values;
521
- // `!== undefined` (not truthiness) is used so a minCapacity of 0 is mirrored
522
- // rather than dropped.
523
- if (appDefinition.database?.postgres?.minCapacity !== undefined) {
330
+ // Preserve other database config
331
+ if (appDefinition.database?.postgres?.minCapacity) {
524
332
  translated.database.postgres.config.minCapacity = appDefinition.database.postgres.minCapacity;
525
333
  }
526
- if (appDefinition.database?.postgres?.maxCapacity !== undefined) {
334
+ if (appDefinition.database?.postgres?.maxCapacity) {
527
335
  translated.database.postgres.config.maxCapacity = appDefinition.database.postgres.maxCapacity;
528
336
  }
529
- if (appDefinition.database?.postgres?.secondsUntilAutoPause !== undefined) {
530
- translated.database.postgres.config.secondsUntilAutoPause = appDefinition.database.postgres.secondsUntilAutoPause;
531
- }
532
337
  if (appDefinition.database?.postgres?.publiclyAccessible !== undefined) {
533
338
  translated.database.postgres.config.publiclyAccessible = appDefinition.database.postgres.publiclyAccessible;
534
339
  }
535
- if (appDefinition.database?.postgres?.connectivity !== undefined) {
536
- translated.database.postgres.config.connectivity = appDefinition.database.postgres.connectivity;
537
- }
538
- if (appDefinition.database?.postgres?.allowedCidrs !== undefined) {
539
- translated.database.postgres.config.allowedCidrs = appDefinition.database.postgres.allowedCidrs;
540
- }
541
340
 
542
341
  return translated;
543
342
  }
@@ -574,10 +373,7 @@ class AuroraBuilder extends InfrastructureBuilder {
574
373
  console.log(' Creating new Aurora Serverless v2 cluster...');
575
374
 
576
375
  const dbConfig = appDefinition.database.postgres;
577
- // ADR-033: connectivity 'public' implies a publicly-accessible cluster in
578
- // public subnets. It combines with the legacy publiclyAccessible flag.
579
- const publicConnectivity = dbConfig.connectivity === 'public';
580
- const publiclyAccessible = publicConnectivity || dbConfig.publiclyAccessible === true;
376
+ const publiclyAccessible = dbConfig.publiclyAccessible === true;
581
377
 
582
378
  // Get subnet IDs for DB Subnet Group
583
379
  const subnetIds = publiclyAccessible
@@ -656,16 +452,9 @@ class AuroraBuilder extends InfrastructureBuilder {
656
452
  // min when idle) and gives the DB enough headroom to
657
453
  // absorb bursty sync traffic. Apps can still override both
658
454
  // via app definition dbConfig.
659
- // ADR-033: use nullish coalescing — `|| 0.5` silently turned a
660
- // requested MinCapacity of 0 (scale-to-zero) back into 0.5.
661
- // When MinCapacity is 0, emit SecondsUntilAutoPause so the cluster
662
- // pauses to 0 ACU after the idle window (default 300s).
663
455
  ServerlessV2ScalingConfiguration: {
664
- MinCapacity: dbConfig.minCapacity ?? 0.5,
665
- MaxCapacity: dbConfig.maxCapacity ?? 4,
666
- ...(dbConfig.minCapacity === 0
667
- ? { SecondsUntilAutoPause: dbConfig.secondsUntilAutoPause ?? 300 }
668
- : {}),
456
+ MinCapacity: dbConfig.minCapacity || 0.5,
457
+ MaxCapacity: dbConfig.maxCapacity || 4,
669
458
  },
670
459
  EnableHttpEndpoint: false,
671
460
  BackupRetentionPeriod: 7,
@@ -693,15 +482,12 @@ class AuroraBuilder extends InfrastructureBuilder {
693
482
  },
694
483
  };
695
484
 
696
- // Environment variables.
697
- // ADR-033: public connectivity requires TLS (sslmode=require) since the
698
- // endpoint is reachable over the internet.
485
+ // Environment variables
699
486
  result.environment.DATABASE_URL = this.buildDatabaseUrl(
700
487
  { 'Fn::GetAtt': ['FriggAuroraCluster', 'Endpoint.Address'] },
701
488
  { 'Fn::GetAtt': ['FriggAuroraCluster', 'Endpoint.Port'] },
702
489
  dbConfig.database || 'frigg',
703
- { Ref: 'FriggDBSecret' },
704
- { requireTls: publicConnectivity }
490
+ { Ref: 'FriggDBSecret' }
705
491
  );
706
492
 
707
493
  // IAM permissions for Secrets Manager
@@ -711,46 +497,19 @@ class AuroraBuilder extends InfrastructureBuilder {
711
497
  Resource: { Ref: 'FriggDBSecret' },
712
498
  });
713
499
 
714
- if (publicConnectivity) {
715
- // ADR-033 NAT-free public connectivity: the Lambda is NOT attached to
716
- // the VPC (see vpc-builder), so FriggLambdaSecurityGroup is not on the
717
- // Lambda side and a SourceSecurityGroupId rule would authorize nothing.
718
- // Instead open 5432 to the configured CIDR allowlist (default
719
- // 0.0.0.0/0 for demos — narrow it in production). One ingress rule per
720
- // CIDR. GroupId stays FriggLambdaSecurityGroup because that is the SG
721
- // attached to the Aurora cluster (see VpcSecurityGroupIds above).
722
- const allowedCidrs =
723
- Array.isArray(dbConfig.allowedCidrs) && dbConfig.allowedCidrs.length > 0
724
- ? dbConfig.allowedCidrs
725
- : ['0.0.0.0/0'];
726
- allowedCidrs.forEach((cidr, index) => {
727
- result.resources[`FriggAuroraIngressRule${index}`] = {
728
- Type: 'AWS::EC2::SecurityGroupIngress',
729
- Properties: {
730
- GroupId: { Ref: 'FriggLambdaSecurityGroup' },
731
- IpProtocol: 'tcp',
732
- FromPort: 5432,
733
- ToPort: 5432,
734
- CidrIp: cidr,
735
- Description: `Allow PostgreSQL access from ${cidr} (public connectivity)`,
736
- },
737
- };
738
- });
739
- } else {
740
- // Add self-referencing security group ingress rule to allow Lambda to connect to Aurora
741
- // Since both Lambda and Aurora share the same security group, we need to allow the SG to accept traffic from itself
742
- result.resources.FriggAuroraIngressRule = {
743
- Type: 'AWS::EC2::SecurityGroupIngress',
744
- Properties: {
745
- GroupId: { Ref: 'FriggLambdaSecurityGroup' },
746
- IpProtocol: 'tcp',
747
- FromPort: 5432,
748
- ToPort: 5432,
749
- SourceSecurityGroupId: { Ref: 'FriggLambdaSecurityGroup' },
750
- Description: 'Allow Lambda functions to connect to Aurora PostgreSQL (self-referencing rule)',
751
- },
752
- };
753
- }
500
+ // Add self-referencing security group ingress rule to allow Lambda to connect to Aurora
501
+ // Since both Lambda and Aurora share the same security group, we need to allow the SG to accept traffic from itself
502
+ result.resources.FriggAuroraIngressRule = {
503
+ Type: 'AWS::EC2::SecurityGroupIngress',
504
+ Properties: {
505
+ GroupId: { Ref: 'FriggLambdaSecurityGroup' },
506
+ IpProtocol: 'tcp',
507
+ FromPort: 5432,
508
+ ToPort: 5432,
509
+ SourceSecurityGroupId: { Ref: 'FriggLambdaSecurityGroup' },
510
+ Description: 'Allow Lambda functions to connect to Aurora PostgreSQL (self-referencing rule)',
511
+ },
512
+ };
754
513
 
755
514
  console.log(' ✅ Aurora Serverless v2 cluster resources created');
756
515
  }
@@ -767,12 +526,6 @@ class AuroraBuilder extends InfrastructureBuilder {
767
526
  throw new Error('database.postgres.endpoint is required when management="use-existing"');
768
527
  }
769
528
 
770
- // ADR-033: for use-existing, `connectivity` only affects TLS on the
771
- // connection params — Frigg does not own the cluster, so it manages neither
772
- // its subnets nor its ingress (the validator warns about this). Public mode
773
- // still requires TLS, so append sslmode=require.
774
- const publicConnectivity = dbConfig.connectivity === 'public';
775
-
776
529
  // Set environment variables for existing cluster
777
530
  result.environment.DATABASE_HOST = dbConfig.endpoint;
778
531
  result.environment.DATABASE_PORT = String(dbConfig.port || 5432);
@@ -781,9 +534,7 @@ class AuroraBuilder extends InfrastructureBuilder {
781
534
  // Consumers that build DATABASE_URL from components at runtime MUST
782
535
  // append `?${DATABASE_URL_PARAMS}` to get the same hang-prevention
783
536
  // timeouts as the managed path.
784
- result.environment.DATABASE_URL_PARAMS = publicConnectivity
785
- ? `${LAMBDA_DATABASE_URL_QUERY_PARAMS}&sslmode=require`
786
- : LAMBDA_DATABASE_URL_QUERY_PARAMS;
537
+ result.environment.DATABASE_URL_PARAMS = LAMBDA_DATABASE_URL_QUERY_PARAMS;
787
538
 
788
539
  console.log(` ✅ Using existing cluster: ${dbConfig.endpoint}`);
789
540
  }
@@ -803,9 +554,6 @@ class AuroraBuilder extends InfrastructureBuilder {
803
554
  console.log(` ✅ Using discovered Aurora cluster: ${discoveredResources.auroraClusterEndpoint}`);
804
555
 
805
556
  const dbConfig = appDefinition.database.postgres;
806
- // ADR-033: public connectivity requires TLS on the connection string and a
807
- // CIDR-based ingress rule (the Lambda is not VPC-attached).
808
- const publicConnectivity = dbConfig.connectivity === 'public';
809
557
 
810
558
  // Use discovered cluster details
811
559
  result.environment.DATABASE_HOST = discoveredResources.auroraClusterEndpoint;
@@ -981,8 +729,7 @@ exports.handler = async (event, context) => {
981
729
  discoveredResources.auroraClusterEndpoint,
982
730
  discoveredResources.auroraPort || 5432,
983
731
  dbConfig.database || 'frigg',
984
- { Ref: 'FriggDBSecret' },
985
- { requireTls: publicConnectivity }
732
+ { Ref: 'FriggDBSecret' }
986
733
  );
987
734
 
988
735
  // Grant Lambda functions permission to read the secret
@@ -1000,8 +747,7 @@ exports.handler = async (event, context) => {
1000
747
  discoveredResources.auroraClusterEndpoint,
1001
748
  discoveredResources.auroraPort || 5432,
1002
749
  dbConfig.database || 'frigg',
1003
- discoveredResources.databaseSecretArn,
1004
- { requireTls: publicConnectivity }
750
+ discoveredResources.databaseSecretArn
1005
751
  );
1006
752
 
1007
753
  result.iamStatements.push({
@@ -1022,10 +768,7 @@ exports.handler = async (event, context) => {
1022
768
  // Consumers that build DATABASE_URL from components at runtime MUST
1023
769
  // append `?${DATABASE_URL_PARAMS}` to get the same hang-prevention
1024
770
  // timeouts as the managed path.
1025
- // ADR-033: public connectivity requires TLS — include sslmode=require.
1026
- result.environment.DATABASE_URL_PARAMS = publicConnectivity
1027
- ? `${LAMBDA_DATABASE_URL_QUERY_PARAMS}&sslmode=require`
1028
- : LAMBDA_DATABASE_URL_QUERY_PARAMS;
771
+ result.environment.DATABASE_URL_PARAMS = LAMBDA_DATABASE_URL_QUERY_PARAMS;
1029
772
 
1030
773
  // Note: DATABASE_URL is NOT set here to avoid Serverless variable resolution errors
1031
774
  // The application (Frigg Core) should construct it at runtime from:
@@ -1039,39 +782,17 @@ exports.handler = async (event, context) => {
1039
782
 
1040
783
  // Add security group ingress rule to allow Lambda to connect to Aurora
1041
784
  if (discoveredResources.auroraSecurityGroupId) {
1042
- if (publicConnectivity) {
1043
- // ADR-033 NAT-free public connectivity: the Lambda is not in the
1044
- // VPC, so authorize the CIDR allowlist instead of the Lambda SG.
1045
- const allowedCidrs =
1046
- Array.isArray(dbConfig.allowedCidrs) && dbConfig.allowedCidrs.length > 0
1047
- ? dbConfig.allowedCidrs
1048
- : ['0.0.0.0/0'];
1049
- allowedCidrs.forEach((cidr, index) => {
1050
- result.resources[`FriggAuroraIngressRule${index}`] = {
1051
- Type: 'AWS::EC2::SecurityGroupIngress',
1052
- Properties: {
1053
- GroupId: discoveredResources.auroraSecurityGroupId,
1054
- IpProtocol: 'tcp',
1055
- FromPort: discoveredResources.auroraPort || 5432,
1056
- ToPort: discoveredResources.auroraPort || 5432,
1057
- CidrIp: cidr,
1058
- Description: `Allow PostgreSQL access from ${cidr} (public connectivity)`,
1059
- },
1060
- };
1061
- });
1062
- } else {
1063
- result.resources.FriggAuroraIngressRule = {
1064
- Type: 'AWS::EC2::SecurityGroupIngress',
1065
- Properties: {
1066
- GroupId: discoveredResources.auroraSecurityGroupId,
1067
- IpProtocol: 'tcp',
1068
- FromPort: discoveredResources.auroraPort || 5432,
1069
- ToPort: discoveredResources.auroraPort || 5432,
1070
- SourceSecurityGroupId: { Ref: 'FriggLambdaSecurityGroup' },
1071
- Description: 'Allow Lambda functions to connect to Aurora PostgreSQL',
1072
- },
1073
- };
1074
- }
785
+ result.resources.FriggAuroraIngressRule = {
786
+ Type: 'AWS::EC2::SecurityGroupIngress',
787
+ Properties: {
788
+ GroupId: discoveredResources.auroraSecurityGroupId,
789
+ IpProtocol: 'tcp',
790
+ FromPort: discoveredResources.auroraPort || 5432,
791
+ ToPort: discoveredResources.auroraPort || 5432,
792
+ SourceSecurityGroupId: { Ref: 'FriggLambdaSecurityGroup' },
793
+ Description: 'Allow Lambda functions to connect to Aurora PostgreSQL',
794
+ },
795
+ };
1075
796
  console.log(` ✅ Added security group ingress rule for Lambda → Aurora connectivity`);
1076
797
  }
1077
798
 
@@ -1084,11 +805,8 @@ exports.handler = async (event, context) => {
1084
805
  * @param {string|number|object} port - Database port (string/number or CloudFormation intrinsic function)
1085
806
  * @param {string} database - Database name
1086
807
  * @param {string|object} secretRef - Secret ARN (string) or CloudFormation Ref object
1087
- * @param {object} [options]
1088
- * @param {boolean} [options.requireTls] - Append sslmode=require (ADR-033 public connectivity)
1089
808
  */
1090
- buildDatabaseUrl(host, port, database, secretRef, options = {}) {
1091
- const { requireTls = false } = options;
809
+ buildDatabaseUrl(host, port, database, secretRef) {
1092
810
  // Handle secretRef as either a string ARN or CloudFormation Ref object
1093
811
  const resolveSecretRef = (secretRefValue) => {
1094
812
  if (typeof secretRefValue === 'object' && secretRefValue.Ref) {
@@ -1120,16 +838,9 @@ exports.handler = async (event, context) => {
1120
838
 
1121
839
  // Query params are defined at module scope (LAMBDA_DATABASE_URL_QUERY_PARAMS)
1122
840
  // so runtime-URL-construction paths can emit the same timeouts as an env var.
1123
- // ADR-033: for public connectivity, TLS is mandatory — append sslmode=require
1124
- // unless it's already present in the base params.
1125
- const queryParams =
1126
- requireTls && !/(^|&)sslmode=/.test(LAMBDA_DATABASE_URL_QUERY_PARAMS)
1127
- ? `${LAMBDA_DATABASE_URL_QUERY_PARAMS}&sslmode=require`
1128
- : LAMBDA_DATABASE_URL_QUERY_PARAMS;
1129
-
1130
841
  return {
1131
842
  'Fn::Sub': [
1132
- `postgresql://\${Username}:\${Password}@\${Host}:\${Port}/\${Database}?${queryParams}`,
843
+ `postgresql://\${Username}:\${Password}@\${Host}:\${Port}/\${Database}?${LAMBDA_DATABASE_URL_QUERY_PARAMS}`,
1133
844
  {
1134
845
  Username: resolveSecretRef(secretRef),
1135
846
  Password: resolveSecretPassword(secretRef),
@@ -194,7 +194,7 @@ describe('AuroraBuilder', () => {
194
194
  const result = auroraBuilder.validate(appDefinition);
195
195
 
196
196
  expect(result.valid).toBe(false);
197
- expect(result.errors.some(e => e.includes('minCapacity must be 0 (scale-to-zero) or between 0.5 and 128'))).toBe(true);
197
+ expect(result.errors.some(e => e.includes('minCapacity must be between 0.5 and 128'))).toBe(true);
198
198
  });
199
199
 
200
200
  it('should error when maxCapacity is out of range', () => {
@@ -15,6 +15,7 @@
15
15
 
16
16
  const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
17
17
  const { isScopedEnvironmentActive } = require('../shared/function-environments');
18
+ const { nestedNodeModulesExcludes } = require('../shared/utilities/nested-node-modules');
18
19
  const { MigrationResourceResolver } = require('./migration-resolver');
19
20
  const { createEmptyDiscoveryResult, ResourceOwnership } = require('../shared/types');
20
21
 
@@ -235,7 +236,7 @@ class MigrationBuilder extends InfrastructureBuilder {
235
236
  * Create Lambda function definitions for database migrations
236
237
  * Based on refactor/add-better-support-for-commands branch implementation
237
238
  */
238
- async createFunctionDefinitions(result, usePrismaLayer = true) {
239
+ async createFunctionDefinitions(result, usePrismaLayer = true, appDefinition = {}) {
239
240
  console.log(' 🔍 DEBUG: createFunctionDefinitions called');
240
241
  console.log(' 🔍 DEBUG: result.functions is:', typeof result.functions, result.functions);
241
242
  // Migration WORKER package config (needs Prisma CLI WASM files)
@@ -250,8 +251,7 @@ class MigrationBuilder extends InfrastructureBuilder {
250
251
  ] : []),
251
252
  // But KEEP node_modules/prisma/** (the CLI with WASM)
252
253
 
253
- // Exclude ALL nested node_modules
254
- 'node_modules/**/node_modules/**',
254
+ ...nestedNodeModulesExcludes(appDefinition, usePrismaLayer),
255
255
 
256
256
  // Exclude AWS SDK (provided by Lambda runtime)
257
257
  'node_modules/aws-sdk/**',
@@ -343,8 +343,7 @@ class MigrationBuilder extends InfrastructureBuilder {
343
343
  // Router only skips Prisma CLI if Lambda Layer is enabled
344
344
  ...(usePrismaLayer ? ['node_modules/prisma/**'] : []),
345
345
 
346
- // Exclude ALL nested node_modules
347
- 'node_modules/**/node_modules/**',
346
+ ...nestedNodeModulesExcludes(appDefinition, usePrismaLayer),
348
347
 
349
348
  // Exclude AWS SDK (provided by Lambda runtime)
350
349
  'node_modules/aws-sdk/**',
@@ -516,7 +515,7 @@ class MigrationBuilder extends InfrastructureBuilder {
516
515
  console.log(' 🔍 DEBUG: result object before createFunctionDefinitions:', Object.keys(result));
517
516
 
518
517
  // Create Lambda function definitions first (they reference the queue)
519
- await this.createFunctionDefinitions(result, usePrismaLayer);
518
+ await this.createFunctionDefinitions(result, usePrismaLayer, appDefinition);
520
519
 
521
520
  console.log(' 🔍 DEBUG: result.functions after createFunctionDefinitions:', Object.keys(result.functions || {}));
522
521