@friggframework/devtools 2.0.0--canary.657.f16d20b.0 → 2.0.0--canary.737.83b4e17.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 (104) hide show
  1. package/frigg-cli/README.md +115 -31
  2. package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
  3. package/frigg-cli/__tests__/unit/commands/deploy.test.js +33 -24
  4. package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
  5. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
  6. package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
  7. package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
  8. package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
  9. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
  10. package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
  11. package/frigg-cli/build-command/index.js +6 -0
  12. package/frigg-cli/deploy-command/index.js +6 -0
  13. package/frigg-cli/generate-command/index.js +1 -0
  14. package/frigg-cli/generate-iam-command.js +1 -0
  15. package/frigg-cli/index.js +22 -5
  16. package/frigg-cli/init-command/backend-first-handler.js +395 -551
  17. package/frigg-cli/init-command/deployment-modes.js +7 -0
  18. package/frigg-cli/init-command/index.js +82 -35
  19. package/frigg-cli/init-command/safe-path.js +58 -0
  20. package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
  21. package/frigg-cli/install-command/app-definition.js +174 -0
  22. package/frigg-cli/install-command/commit-changes.js +40 -8
  23. package/frigg-cli/install-command/environment-variables.js +15 -0
  24. package/frigg-cli/install-command/index.js +96 -21
  25. package/frigg-cli/install-command/install-package.js +77 -4
  26. package/frigg-cli/install-command/integration-file.js +20 -11
  27. package/frigg-cli/install-command/resolve-module.js +69 -0
  28. package/frigg-cli/install-command/template.js +102 -75
  29. package/frigg-cli/install-command/validate-package.js +36 -4
  30. package/frigg-cli/package.json +1 -1
  31. package/frigg-cli/start-command/index.js +4 -0
  32. package/frigg-cli/start-command/start-command.test.js +3 -0
  33. package/frigg-cli/templates/backend/README.md +267 -0
  34. package/frigg-cli/templates/backend/env.example +20 -0
  35. package/frigg-cli/templates/backend/gitignore +10 -0
  36. package/frigg-cli/templates/backend/index.js +114 -0
  37. package/frigg-cli/templates/backend/infrastructure.js +20 -0
  38. package/frigg-cli/test/init-command.test.js +9 -2
  39. package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
  40. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
  41. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +443 -0
  42. package/frigg-cli/validate-command/__tests__/validate-command.test.js +262 -0
  43. package/frigg-cli/validate-command/checks/config.js +504 -0
  44. package/frigg-cli/validate-command/checks/integrations.js +274 -0
  45. package/frigg-cli/validate-command/format-report.js +58 -0
  46. package/frigg-cli/validate-command/index.js +107 -0
  47. package/frigg-cli/validate-command/load-app-definition.js +105 -0
  48. package/frigg-cli/validate-command/schema-issues.js +154 -0
  49. package/frigg-cli/validate-command/validate-app-definition.js +60 -0
  50. package/infrastructure/README.md +32 -5
  51. package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +39 -0
  52. package/infrastructure/__tests__/management-api-gateway-routes.test.js +284 -0
  53. package/infrastructure/__tests__/postgres-config.test.js +245 -836
  54. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +151 -0
  55. package/infrastructure/__tests__/scoped-environment.test.js +3 -0
  56. package/infrastructure/__tests__/ssm-preload-node-options.test.js +3 -0
  57. package/infrastructure/__tests__/template-generation.test.js +39 -8
  58. package/infrastructure/app-definition-schema-contract.test.js +634 -0
  59. package/infrastructure/create-frigg-infrastructure.js +4 -1
  60. package/infrastructure/create-frigg-infrastructure.test.js +51 -0
  61. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +80 -98
  62. package/infrastructure/domains/admin-scripts/admin-script-builder.js +8 -2
  63. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +52 -6
  64. package/infrastructure/domains/database/aurora-builder.js +13 -2
  65. package/infrastructure/domains/database/aurora-builder.test.js +22 -0
  66. package/infrastructure/domains/database/migration-builder.js +21 -2
  67. package/infrastructure/domains/database/migration-builder.test.js +61 -6
  68. package/infrastructure/domains/database/migration-engines.js +93 -0
  69. package/infrastructure/domains/database/migration-engines.test.js +142 -0
  70. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
  71. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
  72. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
  73. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
  74. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
  75. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
  76. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
  77. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
  78. package/infrastructure/domains/integration/integration-builder.js +2 -0
  79. package/infrastructure/domains/integration/integration-builder.test.js +22 -39
  80. package/infrastructure/domains/networking/vpc-builder.js +18 -8
  81. package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
  82. package/infrastructure/domains/scheduler/scheduler-builder.js +2 -19
  83. package/infrastructure/domains/scheduler/scheduler-builder.test.js +0 -99
  84. package/infrastructure/domains/security/iam-generator.js +112 -5
  85. package/infrastructure/domains/security/iam-generator.test.js +94 -0
  86. package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
  87. package/infrastructure/domains/shared/environment-builder.js +31 -5
  88. package/infrastructure/domains/shared/environment-builder.test.js +93 -7
  89. package/infrastructure/domains/shared/lambda-architectures.js +113 -0
  90. package/infrastructure/domains/shared/lambda-architectures.test.js +164 -0
  91. package/infrastructure/domains/shared/utilities/base-definition-factory.js +39 -4
  92. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +85 -17
  93. package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
  94. package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
  95. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +92 -12
  96. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +158 -6
  97. package/infrastructure/infrastructure-composer.js +12 -1
  98. package/infrastructure/infrastructure-composer.test.js +339 -794
  99. package/infrastructure/scripts/build-prisma-layer.js +136 -50
  100. package/infrastructure/scripts/build-prisma-layer.test.js +128 -7
  101. package/infrastructure/scripts/build-time-discovery.test.js +18 -3
  102. package/package.json +12 -10
  103. package/frigg-cli/index.test.js +0 -158
  104. package/infrastructure/integration.test.js +0 -381
@@ -0,0 +1,151 @@
1
+ /**
2
+ * The app scaffolded by `frigg init` must deploy with no always-on AWS cost.
3
+ *
4
+ * Scaffolds the backend template, loads its Definition and composes it the way
5
+ * `frigg deploy` does (AWS discovery stubbed), then asserts the template has
6
+ * no VPC, NAT gateway, Elastic IP, VPC endpoint or RDS/Aurora resource, that
7
+ * no Lambda is attached to a VPC, and that field-level encryption still gets
8
+ * its KMS key.
9
+ */
10
+
11
+ const os = require('os');
12
+ const path = require('path');
13
+ const fs = require('fs-extra');
14
+
15
+ jest.mock('../domains/shared/resource-discovery', () => ({
16
+ ...jest.requireActual('../domains/shared/resource-discovery'),
17
+ gatherDiscoveredResources: jest.fn(),
18
+ }));
19
+ jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
20
+ ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
21
+ }));
22
+
23
+ const {
24
+ gatherDiscoveredResources,
25
+ } = require('../domains/shared/resource-discovery');
26
+ const { composeServerlessDefinition } = require('../infrastructure-composer');
27
+ const BackendFirstHandler = require('../../frigg-cli/init-command/backend-first-handler');
28
+
29
+ const FORBIDDEN_RESOURCE_TYPES = [
30
+ 'AWS::EC2::VPC',
31
+ 'AWS::EC2::NatGateway',
32
+ 'AWS::EC2::EIP',
33
+ 'AWS::EC2::VPCEndpoint',
34
+ 'AWS::RDS::DBCluster',
35
+ 'AWS::RDS::DBInstance',
36
+ 'AWS::RDS::DBSubnetGroup',
37
+ ];
38
+
39
+ // An account that already holds a default VPC, subnets, a NAT gateway and an
40
+ // Aurora cluster: none of it may leak into the scaffolded app's template.
41
+ const BUSY_ACCOUNT_DISCOVERY = {
42
+ defaultVpcId: 'vpc-123456',
43
+ vpcCidr: '172.31.0.0/16',
44
+ defaultSecurityGroupId: 'sg-123456',
45
+ privateSubnetId1: 'subnet-123456',
46
+ privateSubnetId2: 'subnet-789012',
47
+ publicSubnetId1: 'subnet-public-1',
48
+ publicSubnetId2: 'subnet-public-2',
49
+ defaultRouteTableId: 'rtb-123456',
50
+ existingNatGatewayId: 'nat-default123',
51
+ auroraClusterEndpoint: 'c.cluster-abc123.us-east-1.rds.amazonaws.com',
52
+ auroraPort: 5432,
53
+ auroraEngine: 'aurora-postgresql',
54
+ };
55
+
56
+ describe('frigg init default infrastructure', () => {
57
+ let tmpDir;
58
+ let Definition;
59
+ let logSpy;
60
+
61
+ beforeAll(async () => {
62
+ logSpy = jest.spyOn(console, 'log').mockImplementation();
63
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-default-infra-'));
64
+ const target = path.join(tmpDir, 'demo-app');
65
+ await new BackendFirstHandler(target, {
66
+ yes: true,
67
+ install: false,
68
+ git: false,
69
+ }).initialize();
70
+ ({ Definition } = require(path.join(target, 'index.js')));
71
+ });
72
+
73
+ afterAll(() => {
74
+ fs.removeSync(tmpDir);
75
+ logSpy.mockRestore();
76
+ });
77
+
78
+ beforeEach(() => {
79
+ delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
80
+ process.argv = ['node', 'test'];
81
+ });
82
+
83
+ const compose = async (discovery) => {
84
+ gatherDiscoveredResources.mockResolvedValue(discovery);
85
+ // The composer mutates nested parts of the definition.
86
+ return composeServerlessDefinition(
87
+ JSON.parse(JSON.stringify(Definition))
88
+ );
89
+ };
90
+
91
+ const resourceTypes = (definition) =>
92
+ Object.values(definition.resources.Resources).map((r) => r.Type);
93
+
94
+ it('passes the app-definition schema', () => {
95
+ const { validateAppDefinition } = require('@friggframework/schemas');
96
+ expect(validateAppDefinition(Definition).valid).toBe(true);
97
+ });
98
+
99
+ it.each([
100
+ ['an empty account', {}],
101
+ ['an account with existing VPC/NAT/Aurora', BUSY_ACCOUNT_DISCOVERY],
102
+ ])('composes no always-on resources in %s', async (_label, discovery) => {
103
+ const definition = await compose(discovery);
104
+ const types = resourceTypes(definition);
105
+
106
+ for (const forbidden of FORBIDDEN_RESOURCE_TYPES) {
107
+ expect(types).not.toContain(forbidden);
108
+ }
109
+
110
+ // No Lambda is attached to a VPC.
111
+ expect(definition.provider.vpc).toBeUndefined();
112
+ for (const fn of Object.values(definition.functions)) {
113
+ expect(fn.vpc).toBeUndefined();
114
+ }
115
+ for (const resource of Object.values(definition.resources.Resources)) {
116
+ expect(resource.Properties?.VpcConfig).toBeUndefined();
117
+ }
118
+ });
119
+
120
+ it('keeps field-level encryption on with a per-stage KMS key', async () => {
121
+ const definition = await compose({});
122
+
123
+ expect(definition.resources.Resources.FriggKMSKey.Type).toBe(
124
+ 'AWS::KMS::Key'
125
+ );
126
+ expect(definition.provider.environment.KMS_KEY_ARN).toEqual({
127
+ 'Fn::GetAtt': ['FriggKMSKey', 'Arn'],
128
+ });
129
+ });
130
+
131
+ it('connects to the external database through DATABASE_URL', async () => {
132
+ const definition = await compose({});
133
+
134
+ expect(definition.provider.environment.DATABASE_URL).toBe(
135
+ "${env:DATABASE_URL, ''}"
136
+ );
137
+ expect(definition.provider.environment.DB_TYPE).toBe('postgresql');
138
+ expect(definition.resources.Resources.FriggDBSecret).toBeUndefined();
139
+ });
140
+
141
+ it('expires Lambda logs after 14 days', async () => {
142
+ // Without provider.logRetentionInDays, osls creates log groups that
143
+ // never expire, so CloudWatch storage grows forever.
144
+ const definition = await compose({});
145
+
146
+ expect(definition.provider.logRetentionInDays).toBe(14);
147
+ });
148
+ });
149
+ jest.mock('../domains/database/migration-engines', () => ({
150
+ ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
151
+ }));
@@ -24,6 +24,9 @@ jest.mock('../domains/shared/resource-discovery', () => {
24
24
  }),
25
25
  };
26
26
  });
27
+ jest.mock('../domains/database/migration-engines', () => ({
28
+ ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
29
+ }));
27
30
 
28
31
  const buildApp = (overrides = {}) => ({
29
32
  name: 'scoped-test-app',
@@ -23,6 +23,9 @@ jest.mock('../domains/shared/resource-discovery', () => {
23
23
  }),
24
24
  };
25
25
  });
26
+ jest.mock('../domains/database/migration-engines', () => ({
27
+ ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
28
+ }));
26
29
 
27
30
  const buildApp = (overrides = {}) => ({
28
31
  name: 'preload-test',
@@ -5,6 +5,17 @@
5
5
  * valid, consistent CloudFormation templates.
6
6
  */
7
7
 
8
+ // Never touch AWS or the real Prisma layer from a unit test: discovery returns
9
+ // nothing (a fresh account), and the layer build (npm install into
10
+ // layers/prisma) is stubbed out.
11
+ jest.mock('../domains/shared/resource-discovery', () => ({
12
+ ...jest.requireActual('../domains/shared/resource-discovery'),
13
+ gatherDiscoveredResources: jest.fn().mockResolvedValue({}),
14
+ }));
15
+ jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
16
+ ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
17
+ }));
18
+
8
19
  const { composeServerlessDefinition } = require('../infrastructure-composer');
9
20
 
10
21
  describe('CloudFormation Template Generation', () => {
@@ -86,11 +97,16 @@ describe('CloudFormation Template Generation', () => {
86
97
 
87
98
  // Framework-generated resources (created by Serverless Framework, not our builders)
88
99
  const frameworkResources = ['HttpApi', 'HttpApiLogGroup'];
100
+ // Serverless names each function's resource `<Name>LambdaFunction`
101
+ // (e.g. dbMigrationWorker -> DbMigrationWorkerLambdaFunction).
102
+ const functionResources = Object.keys(result.functions || {}).map(
103
+ (name) => `${name.charAt(0).toUpperCase()}${name.slice(1)}LambdaFunction`
104
+ );
89
105
 
90
- // Verify all Refs point to existing resources, layers, or framework resources
106
+ // Verify all Refs point to existing resources, layers, functions or framework resources
91
107
  refs.forEach(ref => {
92
108
  if (!frameworkResources.includes(ref)) {
93
- expect(allIds).toContain(ref);
109
+ expect([...allIds, ...functionResources]).toContain(ref);
94
110
  }
95
111
  });
96
112
  });
@@ -123,7 +139,9 @@ describe('CloudFormation Template Generation', () => {
123
139
  integrations: [
124
140
  { Definition: { name: 'slack' } }
125
141
  ],
126
- vpc: { enable: true },
142
+ // Discovery is stubbed to an empty account, so the VPC must be
143
+ // created explicitly; `auto` with no VPC found is a hard error.
144
+ vpc: { enable: true, management: 'create-new' },
127
145
  encryption: { fieldLevelEncryptionMethod: 'kms' }
128
146
  };
129
147
 
@@ -251,7 +269,9 @@ describe('CloudFormation Template Generation', () => {
251
269
  it('should create VPC resources when enabled', async () => {
252
270
  const appDefinition = {
253
271
  name: 'test-app',
254
- vpc: { enable: true },
272
+ // Discovery is stubbed to an empty account, so the VPC must be
273
+ // created explicitly; `auto` with no VPC found is a hard error.
274
+ vpc: { enable: true, management: 'create-new' },
255
275
  integrations: []
256
276
  };
257
277
 
@@ -264,7 +284,9 @@ describe('CloudFormation Template Generation', () => {
264
284
  it('should create subnets in VPC', async () => {
265
285
  const appDefinition = {
266
286
  name: 'test-app',
267
- vpc: { enable: true },
287
+ // Discovery is stubbed to an empty account, so the VPC must be
288
+ // created explicitly; `auto` with no VPC found is a hard error.
289
+ vpc: { enable: true, management: 'create-new' },
268
290
  integrations: []
269
291
  };
270
292
 
@@ -277,7 +299,9 @@ describe('CloudFormation Template Generation', () => {
277
299
  it('should create security group in VPC', async () => {
278
300
  const appDefinition = {
279
301
  name: 'test-app',
280
- vpc: { enable: true },
302
+ // Discovery is stubbed to an empty account, so the VPC must be
303
+ // created explicitly; `auto` with no VPC found is a hard error.
304
+ vpc: { enable: true, management: 'create-new' },
281
305
  integrations: []
282
306
  };
283
307
 
@@ -290,7 +314,9 @@ describe('CloudFormation Template Generation', () => {
290
314
  it('should configure Lambda functions with VPC', async () => {
291
315
  const appDefinition = {
292
316
  name: 'test-app',
293
- vpc: { enable: true },
317
+ // Discovery is stubbed to an empty account, so the VPC must be
318
+ // created explicitly; `auto` with no VPC found is a hard error.
319
+ vpc: { enable: true, management: 'create-new' },
294
320
  integrations: [
295
321
  { Definition: { name: 'slack' } }
296
322
  ]
@@ -427,7 +453,9 @@ describe('CloudFormation Template Generation', () => {
427
453
  { Definition: { name: 'slack' } },
428
454
  { Definition: { name: 'hubspot' } }
429
455
  ],
430
- vpc: { enable: true },
456
+ // Discovery is stubbed to an empty account, so the VPC must be
457
+ // created explicitly; `auto` with no VPC found is a hard error.
458
+ vpc: { enable: true, management: 'create-new' },
431
459
  encryption: { useDefaultKMSForFieldLevelEncryption: true },
432
460
  database: {
433
461
  type: 'postgresql',
@@ -603,6 +631,9 @@ describe('CloudFormation Template Generation', () => {
603
631
  });
604
632
  });
605
633
  });
634
+ jest.mock('../domains/database/migration-engines', () => ({
635
+ ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
636
+ }));
606
637
 
607
638
  // Helper functions
608
639
  function findAllRefs(obj, refs = []) {