@friggframework/devtools 2.0.0-next.123 → 2.0.0-next.124
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.
- package/frigg-cli/README.md +38 -1
- package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +3 -0
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
- package/frigg-cli/build-command/index.js +6 -0
- package/frigg-cli/deploy-command/index.js +6 -0
- package/frigg-cli/index.js +13 -1
- package/frigg-cli/init-command/backend-first-handler.js +48 -47
- package/frigg-cli/start-command/index.js +4 -0
- package/frigg-cli/start-command/start-command.test.js +3 -0
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +443 -0
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +262 -0
- package/frigg-cli/validate-command/checks/config.js +504 -0
- package/frigg-cli/validate-command/checks/integrations.js +274 -0
- package/frigg-cli/validate-command/format-report.js +58 -0
- package/frigg-cli/validate-command/index.js +107 -0
- package/frigg-cli/validate-command/load-app-definition.js +105 -0
- package/frigg-cli/validate-command/schema-issues.js +154 -0
- package/frigg-cli/validate-command/validate-app-definition.js +60 -0
- package/infrastructure/app-definition-schema-contract.test.js +629 -0
- package/infrastructure/create-frigg-infrastructure.js +4 -1
- package/infrastructure/create-frigg-infrastructure.test.js +51 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +60 -98
- package/package.json +7 -7
|
@@ -3,6 +3,7 @@ const fs = require('fs-extra');
|
|
|
3
3
|
const crypto = require('crypto');
|
|
4
4
|
const { composeServerlessDefinition } = require('./infrastructure-composer');
|
|
5
5
|
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
6
|
+
const { applyAppDefinitionDefaults } = require('@friggframework/schemas');
|
|
6
7
|
|
|
7
8
|
// Filesystem-based cache to persist across osls require cache clears
|
|
8
9
|
const getCachePath = (backendDir) => {
|
|
@@ -102,7 +103,9 @@ async function createFriggInfrastructure() {
|
|
|
102
103
|
|
|
103
104
|
try {
|
|
104
105
|
const backend = require(backendFilePath);
|
|
105
|
-
|
|
106
|
+
// Same defaults step as core's loadAppDefinition (ADR-051), so the
|
|
107
|
+
// builders and the runtime see the same definition.
|
|
108
|
+
const appDefinition = applyAppDefinitionDefaults(backend.Definition);
|
|
106
109
|
|
|
107
110
|
const definition = await composeServerlessDefinition(
|
|
108
111
|
appDefinition,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
jest.mock('@friggframework/core', () => ({
|
|
6
|
+
findNearestBackendPackageJson: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
jest.mock('./infrastructure-composer', () => ({
|
|
9
|
+
composeServerlessDefinition: jest.fn(async () => ({ service: 'composed' })),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
13
|
+
const { composeServerlessDefinition } = require('./infrastructure-composer');
|
|
14
|
+
const { createFriggInfrastructure } = require('./create-frigg-infrastructure');
|
|
15
|
+
|
|
16
|
+
describe('createFriggInfrastructure', () => {
|
|
17
|
+
let dir;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-infra-'));
|
|
21
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"backend"}');
|
|
22
|
+
fs.writeFileSync(
|
|
23
|
+
path.join(dir, 'index.js'),
|
|
24
|
+
`class Acme { static Definition = { name: 'acme' }; }
|
|
25
|
+
module.exports = { Definition: { name: 'app', integrations: [Acme], user: { usePassword: true } } };`
|
|
26
|
+
);
|
|
27
|
+
findNearestBackendPackageJson.mockReturnValue(
|
|
28
|
+
path.join(dir, 'package.json')
|
|
29
|
+
);
|
|
30
|
+
jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
35
|
+
jest.restoreAllMocks();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('composes the definition with the schema defaults applied (ADR-051)', async () => {
|
|
39
|
+
await createFriggInfrastructure();
|
|
40
|
+
|
|
41
|
+
const [definition] = composeServerlessDefinition.mock.calls[0];
|
|
42
|
+
expect(definition.user).toEqual(
|
|
43
|
+
expect.objectContaining({
|
|
44
|
+
usePassword: true,
|
|
45
|
+
individualUserRequired: true,
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
expect(definition.integrations[0].Definition.name).toBe('acme');
|
|
49
|
+
expect(typeof definition.integrations[0]).toBe('function');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -8,10 +8,10 @@ Frigg Framework supports automatic provisioning of Amazon Aurora Serverless v2 P
|
|
|
8
8
|
|
|
9
9
|
### Key Features
|
|
10
10
|
|
|
11
|
-
- **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-
|
|
11
|
+
- **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-4 ACU default)
|
|
12
12
|
- **VPC Integration**: Deployed in same private subnets as Lambda functions
|
|
13
13
|
- **Secrets Manager**: Automatic credential management and rotation
|
|
14
|
-
- **Management Modes**: discover,
|
|
14
|
+
- **Management Modes**: discover, managed, use-existing, external (bring your own `DATABASE_URL`)
|
|
15
15
|
- **Security**: Private subnet deployment with security group isolation
|
|
16
16
|
- **High Availability**: Multi-AZ deployment with automatic failover
|
|
17
17
|
|
|
@@ -41,12 +41,16 @@ Use `sslmode=require` in the URL. This is the default for apps scaffolded by
|
|
|
41
41
|
|
|
42
42
|
### App Definition Structure
|
|
43
43
|
|
|
44
|
+
These are the keys the Aurora builder reads (see `database.postgres` in
|
|
45
|
+
`packages/schemas/schemas/app-definition.schema.json`). `frigg validate`
|
|
46
|
+
rejects any other key under `database.postgres`.
|
|
47
|
+
|
|
44
48
|
```javascript
|
|
45
49
|
// backend/index.js
|
|
46
50
|
const appDefinition = {
|
|
47
51
|
name: 'my-frigg-app',
|
|
48
52
|
|
|
49
|
-
//
|
|
53
|
+
// VPC Configuration (required for Aurora)
|
|
50
54
|
vpc: {
|
|
51
55
|
enable: true,
|
|
52
56
|
},
|
|
@@ -56,34 +60,24 @@ const appDefinition = {
|
|
|
56
60
|
postgres: {
|
|
57
61
|
enable: true,
|
|
58
62
|
|
|
59
|
-
//
|
|
63
|
+
// 'discover' (also when omitted) | 'managed' | 'use-existing'
|
|
64
|
+
// Ignored when managementMode is 'managed' or 'existing'.
|
|
60
65
|
management: 'discover',
|
|
61
66
|
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// Engine Configuration
|
|
67
|
-
engine: 'aurora-postgresql',
|
|
68
|
-
engineVersion: '15.3',
|
|
69
|
-
|
|
70
|
-
// Scaling Configuration (Aurora Serverless v2)
|
|
71
|
-
scaling: {
|
|
72
|
-
minCapacity: 0.5, // ACUs (0.5 = ~1GB RAM, ~$43/month)
|
|
73
|
-
maxCapacity: 1.0, // ACUs (1.0 = ~2GB RAM, ~$87/month)
|
|
74
|
-
},
|
|
67
|
+
database: 'frigg', // database name (default 'frigg')
|
|
68
|
+
username: 'postgres', // master user (default 'postgres')
|
|
69
|
+
engineVersion: '15.13', // Aurora PostgreSQL version (default '15.13')
|
|
75
70
|
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
// Aurora Serverless v2 capacity, in ACUs (0.5-128)
|
|
72
|
+
minCapacity: 0.5, // default 0.5
|
|
73
|
+
maxCapacity: 4, // default 4
|
|
79
74
|
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
enablePerformanceInsights: false,
|
|
75
|
+
publiclyAccessible: false, // default false (private subnets)
|
|
76
|
+
autoCreateCredentials: false, // discover only: create a secret for a discovered cluster
|
|
83
77
|
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
// use-existing only
|
|
79
|
+
// endpoint: 'mydb.cluster-abc123.us-east-1.rds.amazonaws.com',
|
|
80
|
+
// port: 5432,
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
83
|
};
|
|
@@ -93,13 +87,17 @@ module.exports = {
|
|
|
93
87
|
};
|
|
94
88
|
```
|
|
95
89
|
|
|
90
|
+
Backup retention (7 days), the backup and maintenance windows and deletion
|
|
91
|
+
settings are fixed by the builder and are not configurable through the app
|
|
92
|
+
definition.
|
|
93
|
+
|
|
96
94
|
---
|
|
97
95
|
|
|
98
96
|
## Management Modes
|
|
99
97
|
|
|
100
98
|
### 1. Discover Mode (Default)
|
|
101
99
|
|
|
102
|
-
|
|
100
|
+
Discovers an existing Aurora cluster, or creates a new one in the stack if none is found.
|
|
103
101
|
|
|
104
102
|
```javascript
|
|
105
103
|
database: {
|
|
@@ -120,63 +118,56 @@ database: {
|
|
|
120
118
|
|
|
121
119
|
---
|
|
122
120
|
|
|
123
|
-
### 2.
|
|
121
|
+
### 2. Managed Mode
|
|
124
122
|
|
|
125
|
-
|
|
123
|
+
Creates the cluster, instance, subnet group and secret in the stack.
|
|
126
124
|
|
|
127
125
|
```javascript
|
|
128
126
|
database: {
|
|
129
127
|
postgres: {
|
|
130
128
|
enable: true,
|
|
131
|
-
management: '
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
databaseName: 'my_app_db',
|
|
135
|
-
masterUsername: 'admin',
|
|
136
|
-
engineVersion: '15.3',
|
|
137
|
-
scaling: {
|
|
138
|
-
minCapacity: 1.0,
|
|
139
|
-
maxCapacity: 2.0,
|
|
140
|
-
},
|
|
141
|
-
backupRetentionDays: 14,
|
|
142
|
-
deletionProtection: true,
|
|
129
|
+
management: 'managed',
|
|
130
|
+
minCapacity: 1,
|
|
131
|
+
maxCapacity: 2,
|
|
143
132
|
}
|
|
144
133
|
}
|
|
145
134
|
```
|
|
146
135
|
|
|
136
|
+
With the top-level `managementMode: 'managed'` (and `vpcIsolation: 'isolated'`),
|
|
137
|
+
Frigg manages the database per stage and `database.postgres.management` is ignored.
|
|
138
|
+
|
|
147
139
|
**Best For**: Production environments where you want dedicated database resources.
|
|
148
140
|
|
|
149
141
|
---
|
|
150
142
|
|
|
151
143
|
### 3. Use-Existing Mode
|
|
152
144
|
|
|
153
|
-
|
|
145
|
+
Connects to an existing PostgreSQL endpoint without creating database resources.
|
|
154
146
|
|
|
155
147
|
```javascript
|
|
156
148
|
database: {
|
|
157
149
|
postgres: {
|
|
158
150
|
enable: true,
|
|
159
151
|
management: 'use-existing',
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
// Optional: secret ARN (discovered if not provided)
|
|
165
|
-
secretArn: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:my-db-secret',
|
|
166
|
-
|
|
167
|
-
// Database name to connect to
|
|
168
|
-
databaseName: 'frigg_db',
|
|
152
|
+
endpoint: 'my-cluster.cluster-abc123.us-east-1.rds.amazonaws.com', // required
|
|
153
|
+
port: 5432,
|
|
154
|
+
database: 'frigg_db',
|
|
155
|
+
username: 'frigg_admin',
|
|
169
156
|
}
|
|
170
157
|
}
|
|
171
158
|
```
|
|
172
159
|
|
|
160
|
+
To use an existing cluster by identifier instead, use the ownership form:
|
|
161
|
+
`ownership: { cluster: 'external', instance: 'external' }` with
|
|
162
|
+
`external: { clusterIdentifier, instanceIdentifier, secretArn }`.
|
|
163
|
+
|
|
173
164
|
**Best For**: Shared database scenarios or when you manage Aurora outside of Frigg.
|
|
174
165
|
|
|
175
166
|
---
|
|
176
167
|
|
|
177
168
|
## Created AWS Resources
|
|
178
169
|
|
|
179
|
-
When provisioning Aurora (`
|
|
170
|
+
When provisioning Aurora (`managed`, or `discover` mode without an existing cluster), Frigg creates:
|
|
180
171
|
|
|
181
172
|
### 1. RDS DB Subnet Group
|
|
182
173
|
- **Name**: `{service}-{stage}-db-subnet-group`
|
|
@@ -241,17 +232,15 @@ database: {
|
|
|
241
232
|
database: {
|
|
242
233
|
postgres: {
|
|
243
234
|
enable: true,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
maxCapacity: 4.0, // Handle traffic spikes
|
|
247
|
-
},
|
|
248
|
-
backupRetentionDays: 30, // Longer retention
|
|
249
|
-
enablePerformanceInsights: true, // Monitoring
|
|
250
|
-
deletionProtection: true, // Prevent accidental deletion
|
|
235
|
+
minCapacity: 1, // Higher baseline for production
|
|
236
|
+
maxCapacity: 4, // Handle traffic spikes
|
|
251
237
|
}
|
|
252
238
|
}
|
|
253
239
|
```
|
|
254
240
|
|
|
241
|
+
Backup retention, Performance Insights and deletion protection are not
|
|
242
|
+
configurable through the app definition; change them on the cluster.
|
|
243
|
+
|
|
255
244
|
**Estimated Monthly Costs**:
|
|
256
245
|
- **Baseline**: $87/month (1.0 ACU minimum)
|
|
257
246
|
- **Peak Traffic**: $348/month (4.0 ACU maximum)
|
|
@@ -296,15 +285,9 @@ const users = await prismaClient.user.findMany();
|
|
|
296
285
|
|
|
297
286
|
### 4. Deletion Protection
|
|
298
287
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
deletionProtection: true, // Prevents accidental deletion
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
**Important**: When enabled, you must manually disable deletion protection in AWS console before stack deletion.
|
|
288
|
+
Deletion protection is not configurable through the app definition. Enable it
|
|
289
|
+
on the cluster in the AWS console (or with the AWS CLI); you must then disable
|
|
290
|
+
it before deleting the stack.
|
|
308
291
|
|
|
309
292
|
---
|
|
310
293
|
|
|
@@ -404,7 +387,7 @@ DB_TYPE=postgresql
|
|
|
404
387
|
database: {
|
|
405
388
|
postgres: {
|
|
406
389
|
enable: true,
|
|
407
|
-
management: '
|
|
390
|
+
management: 'managed',
|
|
408
391
|
}
|
|
409
392
|
}
|
|
410
393
|
```
|
|
@@ -431,7 +414,7 @@ DB_TYPE=postgresql
|
|
|
431
414
|
database: {
|
|
432
415
|
postgres: {
|
|
433
416
|
enable: true,
|
|
434
|
-
management: '
|
|
417
|
+
management: 'managed',
|
|
435
418
|
}
|
|
436
419
|
}
|
|
437
420
|
```
|
|
@@ -476,13 +459,13 @@ DB_TYPE=postgresql
|
|
|
476
459
|
|
|
477
460
|
**Error**:
|
|
478
461
|
```
|
|
479
|
-
No Aurora cluster found in discovery mode. Set management to "
|
|
462
|
+
No Aurora cluster found in discovery mode. Set management to "managed" or provide endpoint with "use-existing".
|
|
480
463
|
```
|
|
481
464
|
|
|
482
465
|
**Solution**:
|
|
483
466
|
1. Check VPC is enabled: `vpc.enable: true`
|
|
484
|
-
2. Set management mode: `management: '
|
|
485
|
-
3. Or
|
|
467
|
+
2. Set management mode: `management: 'managed'`
|
|
468
|
+
3. Or connect to a known endpoint: `management: 'use-existing'`, `endpoint: '...'`
|
|
486
469
|
|
|
487
470
|
---
|
|
488
471
|
|
|
@@ -564,41 +547,20 @@ Cannot create Aurora cluster: InsufficientDBInstanceCapacity
|
|
|
564
547
|
|
|
565
548
|
## Advanced Configuration
|
|
566
549
|
|
|
567
|
-
### Custom Backup Window
|
|
568
|
-
|
|
569
|
-
```javascript
|
|
570
|
-
database: {
|
|
571
|
-
postgres: {
|
|
572
|
-
enable: true,
|
|
573
|
-
backupRetentionDays: 30,
|
|
574
|
-
preferredBackupWindow: '02:00-03:00', // UTC
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
```
|
|
578
|
-
|
|
579
|
-
### Enhanced Monitoring
|
|
580
|
-
|
|
581
|
-
```javascript
|
|
582
|
-
database: {
|
|
583
|
-
postgres: {
|
|
584
|
-
enable: true,
|
|
585
|
-
enablePerformanceInsights: true,
|
|
586
|
-
// Performance Insights retention: 7 days (default) or 731 days
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
```
|
|
590
|
-
|
|
591
550
|
### Custom Engine Version
|
|
592
551
|
|
|
593
552
|
```javascript
|
|
594
553
|
database: {
|
|
595
554
|
postgres: {
|
|
596
555
|
enable: true,
|
|
597
|
-
engineVersion: '
|
|
556
|
+
engineVersion: '16.4', // Default: 15.13
|
|
598
557
|
}
|
|
599
558
|
}
|
|
600
559
|
```
|
|
601
560
|
|
|
561
|
+
The backup window, backup retention and Performance Insights are set by the
|
|
562
|
+
builder and are not configurable through the app definition.
|
|
563
|
+
|
|
602
564
|
### Read Replicas (Not Supported Yet)
|
|
603
565
|
|
|
604
566
|
Frigg currently provisions a single Aurora instance. For read replicas:
|
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-next.
|
|
4
|
+
"version": "2.0.0-next.124",
|
|
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-next.
|
|
32
|
-
"@friggframework/schemas": "2.0.0-next.
|
|
33
|
-
"@friggframework/test": "2.0.0-next.
|
|
31
|
+
"@friggframework/core": "2.0.0-next.124",
|
|
32
|
+
"@friggframework/schemas": "2.0.0-next.124",
|
|
33
|
+
"@friggframework/test": "2.0.0-next.124",
|
|
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-next.
|
|
62
|
-
"@friggframework/prettier-config": "2.0.0-next.
|
|
61
|
+
"@friggframework/eslint-config": "2.0.0-next.124",
|
|
62
|
+
"@friggframework/prettier-config": "2.0.0-next.124",
|
|
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": "
|
|
94
|
+
"gitHead": "679a3f0f550136151563c34f9a8c7680b88b6984"
|
|
95
95
|
}
|