@friggframework/devtools 2.0.0--canary.686.821f8a3.0 → 2.0.0--canary.705.9cfd819.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.
- package/frigg-cli/build-command/index.js +1 -32
- package/frigg-cli/deploy-command/index.js +2 -50
- package/frigg-cli/doctor-command/index.js +0 -7
- package/frigg-cli/generate-iam-command.js +0 -7
- package/frigg-cli/repair-command/index.js +0 -7
- package/frigg-cli/start-command/index.js +0 -58
- package/infrastructure/README.md +2 -4
- package/infrastructure/__tests__/template-generation.test.js +0 -7
- package/infrastructure/create-frigg-infrastructure.js +0 -14
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +6 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +30 -0
- package/infrastructure/domains/parameters/offload-utils.js +0 -1
- package/infrastructure/domains/shared/environment-builder.js +1 -12
- package/infrastructure/domains/shared/environment-builder.test.js +0 -20
- package/infrastructure/domains/shared/types/app-definition.js +1 -15
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +10 -28
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +1 -85
- package/infrastructure/infrastructure-composer.test.js +0 -7
- package/infrastructure/scripts/build-prisma-layer.js +5 -32
- package/infrastructure/scripts/build-prisma-layer.test.js +0 -35
- package/package.json +7 -7
- package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -140
- package/frigg-cli/utils/provider-helper.js +0 -80
- package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +0 -64
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -335
- package/infrastructure/provider-build.js +0 -119
- package/test/npm-install-guard.js +0 -104
- package/test/npm-install-guard.test.js +0 -53
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
const { spawnSync } = require('child_process');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
-
async function buildCommand(options
|
|
5
|
-
// A non-AWS provider (appDefinition.provider) builds through its plugin:
|
|
6
|
-
// platform config + function entry points, no serverless package
|
|
7
|
-
// (friggframework/frigg#545).
|
|
8
|
-
const providerResult = loadProviderIfConfigured();
|
|
9
|
-
if (providerResult) {
|
|
10
|
-
const { buildWithProvider } = require('../../infrastructure/provider-build');
|
|
11
|
-
buildWithProvider({
|
|
12
|
-
appDefinition: providerResult.appDefinition,
|
|
13
|
-
backendDir: providerResult.backendDir,
|
|
14
|
-
provider: providerResult.provider,
|
|
15
|
-
verbose: options.verbose,
|
|
16
|
-
});
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
4
|
+
async function buildCommand(options) {
|
|
20
5
|
console.log('Building the serverless application...');
|
|
21
6
|
|
|
22
7
|
// Suppress AWS SDK warning message about maintenance mode
|
|
@@ -78,20 +63,4 @@ async function buildCommand(options = {}) {
|
|
|
78
63
|
// });
|
|
79
64
|
}
|
|
80
65
|
|
|
81
|
-
/**
|
|
82
|
-
* The resolved non-AWS provider, or null for AWS / no app definition found.
|
|
83
|
-
*/
|
|
84
|
-
function loadProviderIfConfigured() {
|
|
85
|
-
const { loadProviderForCli } = require('../utils/provider-helper');
|
|
86
|
-
let result;
|
|
87
|
-
try {
|
|
88
|
-
result = loadProviderForCli();
|
|
89
|
-
} catch (error) {
|
|
90
|
-
// A non-AWS provider whose package is missing: say so, don't build for AWS.
|
|
91
|
-
console.error(error.message);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
return result && result.provider ? result : null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
66
|
module.exports = { buildCommand };
|
|
@@ -310,16 +310,9 @@ async function pushOffloadedParametersOrAbort(appDefinition, options) {
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
async function deployCommand(options) {
|
|
313
|
-
const appDefinition = loadAppDefinition();
|
|
314
|
-
|
|
315
|
-
// A non-AWS provider (appDefinition.provider) deploys through its plugin
|
|
316
|
-
// (friggframework/frigg#545).
|
|
317
|
-
const providerName = appDefinition?.provider;
|
|
318
|
-
if (providerName && providerName !== 'aws') {
|
|
319
|
-
return deployWithProvider(appDefinition, providerName, options);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
313
|
console.log('Deploying the serverless application...');
|
|
314
|
+
|
|
315
|
+
const appDefinition = loadAppDefinition();
|
|
323
316
|
const environment = validateAndBuildEnvironment(appDefinition, options);
|
|
324
317
|
|
|
325
318
|
await pushOffloadedParametersOrAbort(appDefinition, options);
|
|
@@ -353,45 +346,4 @@ async function deployCommand(options) {
|
|
|
353
346
|
}
|
|
354
347
|
}
|
|
355
348
|
|
|
356
|
-
/**
|
|
357
|
-
* Deploy with a provider plugin: validate(), then deploy() (which runs its
|
|
358
|
-
* own preflightCheck()).
|
|
359
|
-
*/
|
|
360
|
-
async function deployWithProvider(appDefinition, providerName, options = {}) {
|
|
361
|
-
let provider;
|
|
362
|
-
try {
|
|
363
|
-
const { resolveProvider } = require('@friggframework/core/providers/resolve-provider');
|
|
364
|
-
provider = resolveProvider(appDefinition);
|
|
365
|
-
} catch (error) {
|
|
366
|
-
console.error(`Failed to load provider '${providerName}': ${error.message}`);
|
|
367
|
-
process.exit(1);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
console.log(`Deploying with ${providerName} provider...`);
|
|
371
|
-
|
|
372
|
-
if (typeof provider.validate === 'function') {
|
|
373
|
-
const validation = provider.validate(appDefinition);
|
|
374
|
-
if (validation.errors?.length > 0) {
|
|
375
|
-
console.error(`\nValidation errors for ${providerName}:`);
|
|
376
|
-
for (const error of validation.errors) console.error(` - ${error}`);
|
|
377
|
-
process.exit(1);
|
|
378
|
-
}
|
|
379
|
-
for (const warning of validation.warnings || []) console.warn(` Warning: ${warning}`);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
try {
|
|
383
|
-
const result = await provider.deploy(appDefinition, {
|
|
384
|
-
stage: options.stage,
|
|
385
|
-
prod: options.stage === 'production' || options.stage === 'prod',
|
|
386
|
-
dryRun: options.dryRun || false,
|
|
387
|
-
});
|
|
388
|
-
console.log('\nDeployment completed successfully.');
|
|
389
|
-
if (result?.url) console.log(` URL: ${result.url}`);
|
|
390
|
-
} catch (error) {
|
|
391
|
-
console.error(`\nDeployment failed: ${error.message}`);
|
|
392
|
-
for (const item of error.missing || []) console.error(` - ${item}`);
|
|
393
|
-
process.exit(1);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
349
|
module.exports = { deployCommand };
|
|
@@ -246,13 +246,6 @@ async function promptForStackSelection(region) {
|
|
|
246
246
|
*/
|
|
247
247
|
async function doctorCommand(stackName, options = {}) {
|
|
248
248
|
try {
|
|
249
|
-
// AWS-only (CloudFormation); a non-AWS provider has nothing to inspect.
|
|
250
|
-
if (require('../utils/provider-helper').isNonAwsProject()) {
|
|
251
|
-
output.error('The doctor command is only available for AWS deployments.');
|
|
252
|
-
output.log('Your appDefinition uses a non-AWS provider.');
|
|
253
|
-
process.exit(1);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
249
|
// Extract options with defaults
|
|
257
250
|
const region = options.region || process.env.AWS_REGION || 'us-east-1';
|
|
258
251
|
const format = options.format || 'console';
|
|
@@ -9,13 +9,6 @@ const { generateIAMCloudFormation, getFeatureSummary } = require('../infrastruct
|
|
|
9
9
|
*/
|
|
10
10
|
async function generateIamCommand(options = {}) {
|
|
11
11
|
try {
|
|
12
|
-
// AWS-only (CloudFormation); a non-AWS provider has nothing to inspect.
|
|
13
|
-
if (require('./utils/provider-helper').isNonAwsProject()) {
|
|
14
|
-
console.error('The generate-iam command is only available for AWS deployments.');
|
|
15
|
-
console.log('Your appDefinition uses a non-AWS provider.');
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
console.log('🔍 Finding Frigg application...');
|
|
20
13
|
|
|
21
14
|
// Find the backend package.json
|
|
@@ -453,13 +453,6 @@ async function handleReconcileRepair(stackIdentifier, report, options) {
|
|
|
453
453
|
*/
|
|
454
454
|
async function repairCommand(stackName, options = {}) {
|
|
455
455
|
try {
|
|
456
|
-
// AWS-only (CloudFormation); a non-AWS provider has nothing to inspect.
|
|
457
|
-
if (require('../utils/provider-helper').isNonAwsProject()) {
|
|
458
|
-
output.error('The repair command is only available for AWS deployments.');
|
|
459
|
-
output.log('Your appDefinition uses a non-AWS provider.');
|
|
460
|
-
process.exit(1);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
456
|
// Validate required parameter
|
|
464
457
|
if (!stackName) {
|
|
465
458
|
console.error('Error: Stack name is required');
|
|
@@ -37,12 +37,6 @@ async function startCommand(options) {
|
|
|
37
37
|
console.log(chalk.green('✓ Database checks passed\n'));
|
|
38
38
|
console.log('Starting backend and optional frontend...');
|
|
39
39
|
|
|
40
|
-
// A non-AWS provider runs its own local dev server (friggframework/frigg#545).
|
|
41
|
-
const providerResult = loadNonAwsProvider();
|
|
42
|
-
if (providerResult) {
|
|
43
|
-
return startWithProvider(providerResult, options);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
40
|
// Suppress AWS SDK warning message about maintenance mode
|
|
47
41
|
process.env.AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE = '1';
|
|
48
42
|
// Skip AWS discovery for local development
|
|
@@ -152,56 +146,4 @@ async function performDatabaseChecks(verbose) {
|
|
|
152
146
|
// connection when it starts.
|
|
153
147
|
}
|
|
154
148
|
|
|
155
|
-
function loadNonAwsProvider() {
|
|
156
|
-
try {
|
|
157
|
-
const { loadProviderForCli } = require('../utils/provider-helper');
|
|
158
|
-
const result = loadProviderForCli();
|
|
159
|
-
return result && result.provider ? result : null;
|
|
160
|
-
} catch {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Local dev server per provider: Netlify -> `netlify dev` (reads netlify.toml
|
|
167
|
-
* and serves the generated functions), run from the project root that holds
|
|
168
|
-
* backend/ and netlify.toml.
|
|
169
|
-
*/
|
|
170
|
-
function startWithProvider({ providerName, backendDir }, options = {}) {
|
|
171
|
-
const DEV_COMMANDS = {
|
|
172
|
-
netlify: { command: 'netlify', args: ['dev'] },
|
|
173
|
-
};
|
|
174
|
-
const devCmd = DEV_COMMANDS[providerName];
|
|
175
|
-
if (!devCmd) {
|
|
176
|
-
console.error(chalk.red(
|
|
177
|
-
`Provider '${providerName}' does not have a local dev server configured.\n` +
|
|
178
|
-
` Supported providers for local dev: ${Object.keys(DEV_COMMANDS).join(', ')}, aws`
|
|
179
|
-
));
|
|
180
|
-
process.exit(1);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const cwd = require('node:path').dirname(backendDir);
|
|
184
|
-
console.log(chalk.blue(`Starting local dev server (${providerName})...`));
|
|
185
|
-
if (options.verbose) {
|
|
186
|
-
console.log(`Executing command: ${devCmd.command} ${devCmd.args.join(' ')}`);
|
|
187
|
-
console.log(`Working directory: ${cwd}`);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const childProcess = spawn(devCmd.command, devCmd.args, {
|
|
191
|
-
cwd,
|
|
192
|
-
stdio: 'inherit',
|
|
193
|
-
env: { ...process.env },
|
|
194
|
-
});
|
|
195
|
-
childProcess.on('error', (error) => {
|
|
196
|
-
if (error.code === 'ENOENT') {
|
|
197
|
-
console.error(chalk.red(`'${devCmd.command}' not found. Install it with: npm install -g ${devCmd.command}-cli`));
|
|
198
|
-
} else {
|
|
199
|
-
console.error(`Error executing command: ${error.message}`);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
childProcess.on('close', (code) => {
|
|
203
|
-
if (code !== 0) console.log(`Child process exited with code ${code}`);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
149
|
module.exports = { startCommand };
|
package/infrastructure/README.md
CHANGED
|
@@ -163,11 +163,9 @@ const appDefinition = {
|
|
|
163
163
|
enableVPCEndpoints: true // Optional: create VPC endpoints
|
|
164
164
|
},
|
|
165
165
|
|
|
166
|
-
//
|
|
167
|
-
// A deployed stage with no key refuses to start; 'none' is the explicit
|
|
168
|
-
// plaintext opt-out (sets FRIGG_ENCRYPTION_DISABLED=true).
|
|
166
|
+
// KMS encryption
|
|
169
167
|
encryption: {
|
|
170
|
-
fieldLevelEncryptionMethod: 'kms',
|
|
168
|
+
fieldLevelEncryptionMethod: 'kms',
|
|
171
169
|
createResourceIfNoneFound: true
|
|
172
170
|
},
|
|
173
171
|
|
|
@@ -5,13 +5,6 @@
|
|
|
5
5
|
* valid, consistent CloudFormation templates.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
// Composing must not build the real Prisma layer: that runs npm install
|
|
9
|
-
// under packages/devtools, and two workers doing it at once once pruned the
|
|
10
|
-
// repository's root node_modules (test/npm-install-guard.js).
|
|
11
|
-
jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
|
|
12
|
-
ensurePrismaLayerExists: jest.fn(async () => {}),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
8
|
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
16
9
|
|
|
17
10
|
describe('CloudFormation Template Generation', () => {
|
|
@@ -35,20 +35,6 @@ async function createFriggInfrastructure() {
|
|
|
35
35
|
throw new Error('Could not find index.js');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// A non-AWS provider (appDefinition.provider, e.g. 'netlify') builds
|
|
39
|
-
// through its provider plugin instead of serverless/CloudFormation
|
|
40
|
-
// (friggframework/frigg#545). Checked before the cache: the cache holds
|
|
41
|
-
// serverless definitions only. Returns an empty serverless definition,
|
|
42
|
-
// so an osls invocation has nothing to package.
|
|
43
|
-
{
|
|
44
|
-
const { isNonAwsProvider, buildWithProvider } = require('./provider-build');
|
|
45
|
-
const appDefinition = require(backendFilePath).Definition;
|
|
46
|
-
if (isNonAwsProvider(appDefinition)) {
|
|
47
|
-
buildWithProvider({ appDefinition, backendDir });
|
|
48
|
-
return {};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
38
|
const cachePath = getCachePath(backendDir);
|
|
53
39
|
const lockPath = getLockPath(backendDir);
|
|
54
40
|
|
|
@@ -141,10 +141,12 @@ class AdminScriptBuilder extends InfrastructureBuilder {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
createAdminScriptQueue(result, appDefinition) {
|
|
144
|
+
// Registered under custom so the serverless plugin creates it in LocalStack offline
|
|
145
|
+
result.custom.AdminScriptQueue = '${self:service}-${self:provider.stage}-AdminScriptQueue';
|
|
144
146
|
result.resources.AdminScriptQueue = {
|
|
145
147
|
Type: 'AWS::SQS::Queue',
|
|
146
148
|
Properties: {
|
|
147
|
-
QueueName: '${self:
|
|
149
|
+
QueueName: '${self:custom.AdminScriptQueue}',
|
|
148
150
|
MessageRetentionPeriod: 86400, // 1 day
|
|
149
151
|
VisibilityTimeout: 900, // 15 minutes (Lambda max)
|
|
150
152
|
RedrivePolicy: {
|
|
@@ -264,10 +266,12 @@ class AdminScriptBuilder extends InfrastructureBuilder {
|
|
|
264
266
|
}
|
|
265
267
|
|
|
266
268
|
createReportQueue(result, appDefinition) {
|
|
269
|
+
// Registered under custom so the serverless plugin creates it in LocalStack offline
|
|
270
|
+
result.custom.ReportQueue = '${self:service}-${self:provider.stage}-ReportQueue';
|
|
267
271
|
result.resources.ReportQueue = {
|
|
268
272
|
Type: 'AWS::SQS::Queue',
|
|
269
273
|
Properties: {
|
|
270
|
-
QueueName: '${self:
|
|
274
|
+
QueueName: '${self:custom.ReportQueue}',
|
|
271
275
|
MessageRetentionPeriod: 86400, // 1 day
|
|
272
276
|
VisibilityTimeout: 900, // 15 minutes (Lambda max)
|
|
273
277
|
RedrivePolicy: {
|
|
@@ -168,6 +168,21 @@ describe('AdminScriptBuilder', () => {
|
|
|
168
168
|
expect(result.resources.AdminScriptQueue.Properties.VisibilityTimeout).toBe(900); // 15 minutes
|
|
169
169
|
});
|
|
170
170
|
|
|
171
|
+
it('registers AdminScriptQueue under custom so frigg start creates it locally', async () => {
|
|
172
|
+
const appDefinition = {
|
|
173
|
+
adminScripts: [{ Definition: { name: 'test-script' } }],
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const result = await adminScriptBuilder.build(appDefinition, {});
|
|
177
|
+
|
|
178
|
+
expect(result.custom.AdminScriptQueue).toBe(
|
|
179
|
+
'${self:service}-${self:provider.stage}-AdminScriptQueue'
|
|
180
|
+
);
|
|
181
|
+
expect(result.resources.AdminScriptQueue.Properties.QueueName).toBe(
|
|
182
|
+
'${self:custom.AdminScriptQueue}'
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
171
186
|
it('should configure AdminScriptQueue redrive policy to InternalErrorQueue', async () => {
|
|
172
187
|
const appDefinition = {
|
|
173
188
|
adminScripts: [
|
|
@@ -621,6 +636,21 @@ describe('AdminScriptBuilder', () => {
|
|
|
621
636
|
});
|
|
622
637
|
|
|
623
638
|
describe('reports (ReportQueue + reportExecutor)', () => {
|
|
639
|
+
it('registers ReportQueue under custom so frigg start creates it locally', async () => {
|
|
640
|
+
const appDefinition = {
|
|
641
|
+
reports: [{ Definition: { name: 'my-report', version: '1.0.0' } }],
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
const result = await adminScriptBuilder.build(appDefinition, {});
|
|
645
|
+
|
|
646
|
+
expect(result.custom.ReportQueue).toBe(
|
|
647
|
+
'${self:service}-${self:provider.stage}-ReportQueue'
|
|
648
|
+
);
|
|
649
|
+
expect(result.resources.ReportQueue.Properties.QueueName).toBe(
|
|
650
|
+
'${self:custom.ReportQueue}'
|
|
651
|
+
);
|
|
652
|
+
});
|
|
653
|
+
|
|
624
654
|
it('creates ReportQueue + reportExecutor and wires REPORT_QUEUE_URL when reports are present', async () => {
|
|
625
655
|
const appDefinition = {
|
|
626
656
|
reports: [{ Definition: { name: 'my-report', version: '1.0.0' } }],
|
|
@@ -72,16 +72,6 @@ function addLoggingEnv(appDefinition, envVars) {
|
|
|
72
72
|
envVars.FRIGG_LOG_LEVEL = normalized;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
// Field-level encryption fails closed in a deployed stage with no key (core's
|
|
76
|
-
// encryption-config.js). `fieldLevelEncryptionMethod: 'none'` is the explicit,
|
|
77
|
-
// documented way to run a stage in plaintext; core logs a warning on every
|
|
78
|
-
// cold start while it is set.
|
|
79
|
-
function addEncryptionEnv(appDefinition, envVars) {
|
|
80
|
-
if (appDefinition?.encryption?.fieldLevelEncryptionMethod === 'none') {
|
|
81
|
-
envVars.FRIGG_ENCRYPTION_DISABLED = 'true';
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
75
|
/**
|
|
86
76
|
* Get environment variables from AppDefinition
|
|
87
77
|
*
|
|
@@ -159,7 +149,6 @@ function getAppEnvironmentVars(appDefinition) {
|
|
|
159
149
|
}
|
|
160
150
|
|
|
161
151
|
addLoggingEnv(appDefinition, envVars);
|
|
162
|
-
addEncryptionEnv(appDefinition, envVars);
|
|
163
152
|
|
|
164
153
|
if (envKeys.length > 0) {
|
|
165
154
|
console.log(
|
|
@@ -198,7 +187,7 @@ function getAppEnvironmentVars(appDefinition) {
|
|
|
198
187
|
function buildEnvironment(appEnvironmentVars, discoveredResources) {
|
|
199
188
|
const environment = {
|
|
200
189
|
...appEnvironmentVars,
|
|
201
|
-
STAGE: '${self:provider.stage}', //
|
|
190
|
+
STAGE: '${self:provider.stage}', // Used by encryption bypass logic
|
|
202
191
|
FRIGG_STACK: '${self:service}',
|
|
203
192
|
FRIGG_STAGE: '${self:provider.stage}',
|
|
204
193
|
FRIGG_REGION: '${self:provider.region}',
|
|
@@ -468,26 +468,6 @@ describe('Environment Builder', () => {
|
|
|
468
468
|
});
|
|
469
469
|
});
|
|
470
470
|
|
|
471
|
-
describe('field-level encryption opt-out', () => {
|
|
472
|
-
it("emits FRIGG_ENCRYPTION_DISABLED=true for fieldLevelEncryptionMethod: 'none'", () => {
|
|
473
|
-
const result = getAppEnvironmentVars({
|
|
474
|
-
encryption: { fieldLevelEncryptionMethod: 'none' },
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
expect(result.FRIGG_ENCRYPTION_DISABLED).toBe('true');
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
it.each([
|
|
481
|
-
['kms', { fieldLevelEncryptionMethod: 'kms' }],
|
|
482
|
-
['aes', { fieldLevelEncryptionMethod: 'aes' }],
|
|
483
|
-
['no encryption block', undefined],
|
|
484
|
-
])('does not opt out for %s', (_label, encryption) => {
|
|
485
|
-
const result = getAppEnvironmentVars({ encryption });
|
|
486
|
-
|
|
487
|
-
expect(result.FRIGG_ENCRYPTION_DISABLED).toBeUndefined();
|
|
488
|
-
});
|
|
489
|
-
});
|
|
490
|
-
|
|
491
471
|
describe('buildEnvironment()', () => {
|
|
492
472
|
it('should combine app vars with standard Frigg variables', () => {
|
|
493
473
|
const appEnvironmentVars = {
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
* @typedef {Object} AppDefinition
|
|
130
130
|
* @property {string} name - Application name
|
|
131
131
|
* @property {string} stage - Deployment stage (e.g., 'dev', 'production')
|
|
132
|
-
* @property {string} provider -
|
|
132
|
+
* @property {string} provider - Cloud provider (e.g., 'aws')
|
|
133
133
|
* @property {string} region - AWS region
|
|
134
134
|
*
|
|
135
135
|
* @property {VpcDefinition} [vpc] - VPC configuration
|
|
@@ -144,20 +144,6 @@
|
|
|
144
144
|
* @property {AdminConfig} [admin] - Admin configuration
|
|
145
145
|
*
|
|
146
146
|
* @property {Object} [environment] - Environment variables
|
|
147
|
-
*
|
|
148
|
-
* @property {ExtensionDefinition[]} [coreExtensions] - Core (app-level) extensions that add custom Prisma models, encrypted fields, admin routes and bootstrap hooks (not an integration's Definition.extensions, nor ADR-017's keyed appDefinition.extensions)
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* App-level extension: custom models, encryption, admin routes and bootstrap
|
|
153
|
-
* @typedef {Object} ExtensionDefinition
|
|
154
|
-
* @property {string} name - Unique identifier for this extension
|
|
155
|
-
* @property {string} [schema] - Absolute path to a .prisma schema fragment
|
|
156
|
-
* @property {Object<string, {fields: string[]}>} [encryption] - Model name → encrypted fields mapping
|
|
157
|
-
* @property {Object} [routes] - Express router configuration
|
|
158
|
-
* @property {string} routes.path - Base URL path for the extension routes: /admin/<segment>..., never /api (/admin/scripts, /admin/db-migrate and /admin/queue are reserved); served by the auth function
|
|
159
|
-
* @property {Function|Object} routes.handler - Router factory (prisma, appDefinition) → Router, or { router } object
|
|
160
|
-
* @property {Function} [bootstrap] - Async function (prisma, appDefinition) → void, run by initializeApp()
|
|
161
147
|
*/
|
|
162
148
|
|
|
163
149
|
/**
|
|
@@ -10,26 +10,6 @@
|
|
|
10
10
|
const { buildEnvironment } = require('../environment-builder');
|
|
11
11
|
const { nestedNodeModulesExcludes } = require('./nested-node-modules');
|
|
12
12
|
const { buildLoggingProviderConfig } = require('./logging-config');
|
|
13
|
-
const {
|
|
14
|
-
getGatewayRoutes,
|
|
15
|
-
} = require('@friggframework/core/management-api/route-registry');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* HTTP API events for one function, from core's route registry (ADR-053):
|
|
19
|
-
* the same registry mounts the Express routers and builds the OpenAPI
|
|
20
|
-
* documents, so the three cannot drift. It also lists /api/docs and the core
|
|
21
|
-
* extensions' admin routes (/admin/<name>, served by the auth Lambda).
|
|
22
|
-
*/
|
|
23
|
-
function managementApiEvents(AppDefinition, functionName) {
|
|
24
|
-
const managementApi = AppDefinition.managementApi || {};
|
|
25
|
-
return getGatewayRoutes({
|
|
26
|
-
v1: managementApi.v1 !== false,
|
|
27
|
-
proxy: managementApi.proxy?.enable === true,
|
|
28
|
-
coreExtensions: AppDefinition.coreExtensions,
|
|
29
|
-
})
|
|
30
|
-
.filter((route) => route.function === functionName)
|
|
31
|
-
.map(({ method, path }) => ({ httpApi: { path, method } }));
|
|
32
|
-
}
|
|
33
13
|
|
|
34
14
|
/**
|
|
35
15
|
* Create base serverless definition with core functions and resources
|
|
@@ -306,12 +286,16 @@ function createBaseDefinition(
|
|
|
306
286
|
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
307
287
|
skipEsbuild: true, // Handlers in node_modules don't need bundling
|
|
308
288
|
package: skipEsbuildPackageConfig,
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
289
|
+
events: [
|
|
290
|
+
{ httpApi: { path: '/api/integrations', method: 'ANY' } },
|
|
291
|
+
{
|
|
292
|
+
httpApi: {
|
|
293
|
+
path: '/api/integrations/{proxy+}',
|
|
294
|
+
method: 'ANY',
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
{ httpApi: { path: '/api/authorize', method: 'ANY' } },
|
|
298
|
+
],
|
|
315
299
|
},
|
|
316
300
|
user: {
|
|
317
301
|
handler: 'node_modules/@friggframework/core/handlers/routers/user.handler',
|
|
@@ -328,8 +312,6 @@ function createBaseDefinition(
|
|
|
328
312
|
events: [
|
|
329
313
|
{ httpApi: { path: '/health', method: 'GET' } },
|
|
330
314
|
{ httpApi: { path: '/health/{proxy+}', method: 'GET' } },
|
|
331
|
-
// GET /api/meta and the OpenAPI documents: public, DB-free.
|
|
332
|
-
...managementApiEvents(AppDefinition, 'health'),
|
|
333
315
|
],
|
|
334
316
|
},
|
|
335
317
|
// Reporting is an admin operation (ADR-010): the report router runs on the admin-scripts Lambda, not as a standalone function here.
|
|
@@ -94,91 +94,7 @@ describe('Base Definition Factory', () => {
|
|
|
94
94
|
|
|
95
95
|
expect(result.functions.auth.handler).toBe('node_modules/@friggframework/core/handlers/routers/auth.handler');
|
|
96
96
|
expect(result.functions.auth.layers).toEqual([{ Ref: 'PrismaLambdaLayer' }]);
|
|
97
|
-
expect(
|
|
98
|
-
result.functions.auth.events.map(
|
|
99
|
-
(e) => `${e.httpApi.method} ${e.httpApi.path}`
|
|
100
|
-
)
|
|
101
|
-
).toEqual([
|
|
102
|
-
// v1 (deprecated, ADR-053)
|
|
103
|
-
'ANY /api/integrations',
|
|
104
|
-
'ANY /api/integrations/{proxy+}',
|
|
105
|
-
'ANY /api/authorize',
|
|
106
|
-
'ANY /api/entity',
|
|
107
|
-
'ANY /api/entity/{proxy+}',
|
|
108
|
-
'ANY /api/entities/{proxy+}',
|
|
109
|
-
// v2, per resource: never ANY /api/v2/{proxy+}, which would
|
|
110
|
-
// shadow /api/v2/reports on the admin-scripts Lambda
|
|
111
|
-
'ANY /api/v2/integrations',
|
|
112
|
-
'ANY /api/v2/integrations/{proxy+}',
|
|
113
|
-
'ANY /api/v2/entities',
|
|
114
|
-
'ANY /api/v2/entities/{proxy+}',
|
|
115
|
-
'ANY /api/v2/credentials',
|
|
116
|
-
'ANY /api/v2/credentials/{proxy+}',
|
|
117
|
-
'ANY /api/v2/authorize',
|
|
118
|
-
]);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('takes the Management API routes from the core route registry', () => {
|
|
122
|
-
const { getGatewayRoutes } = require('@friggframework/core/management-api/route-registry');
|
|
123
|
-
const result = createBaseDefinition({}, {}, {});
|
|
124
|
-
const declared = (fn) =>
|
|
125
|
-
result.functions[fn].events
|
|
126
|
-
.map((e) => `${e.httpApi.method} ${e.httpApi.path}`)
|
|
127
|
-
.filter((route) => route.includes('/api/'));
|
|
128
|
-
const registry = (fn) =>
|
|
129
|
-
getGatewayRoutes()
|
|
130
|
-
.filter((r) => r.function === fn)
|
|
131
|
-
.map((r) => `${r.method} ${r.path}`);
|
|
132
|
-
expect(declared('auth')).toEqual(registry('auth'));
|
|
133
|
-
expect(declared('health')).toEqual(registry('health'));
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('serves /api/meta from the DB-free health function', () => {
|
|
137
|
-
const result = createBaseDefinition({}, {}, {});
|
|
138
|
-
expect(
|
|
139
|
-
result.functions.health.events.map((e) => `${e.httpApi.method} ${e.httpApi.path}`)
|
|
140
|
-
).toEqual([
|
|
141
|
-
'GET /health',
|
|
142
|
-
'GET /health/{proxy+}',
|
|
143
|
-
'GET /api/meta',
|
|
144
|
-
'GET /api/meta/{proxy+}',
|
|
145
|
-
// Redirects to /api/meta/openapi/v2.json (ADR-053 docs path)
|
|
146
|
-
'GET /api/docs',
|
|
147
|
-
]);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('routes each core extension admin path (and below) to the auth function', () => {
|
|
151
|
-
const result = createBaseDefinition(
|
|
152
|
-
{
|
|
153
|
-
coreExtensions: [
|
|
154
|
-
{ name: 'db-credentials', routes: { path: '/admin/oauth-credentials' } },
|
|
155
|
-
{ name: 'no-routes' },
|
|
156
|
-
],
|
|
157
|
-
},
|
|
158
|
-
{},
|
|
159
|
-
{}
|
|
160
|
-
);
|
|
161
|
-
const routes = result.functions.auth.events.map(
|
|
162
|
-
(e) => `${e.httpApi.method} ${e.httpApi.path}`
|
|
163
|
-
);
|
|
164
|
-
expect(routes).toContain('ANY /admin/oauth-credentials');
|
|
165
|
-
expect(routes).toContain('ANY /admin/oauth-credentials/{proxy+}');
|
|
166
|
-
// Never a catch-all that would shadow /admin/scripts or /admin/db-migrate.
|
|
167
|
-
expect(routes).not.toContain('ANY /admin/{proxy+}');
|
|
168
|
-
// The HTTP queue route is for hosts without SQS, never AWS.
|
|
169
|
-
expect(JSON.stringify(result.functions)).not.toContain('/admin/queue');
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('drops the v1 routes when managementApi.v1 is false, keeping the OAuth redirect', () => {
|
|
173
|
-
const result = createBaseDefinition({ managementApi: { v1: false } }, {}, {});
|
|
174
|
-
const routes = result.functions.auth.events.map(
|
|
175
|
-
(e) => `${e.httpApi.method} ${e.httpApi.path}`
|
|
176
|
-
);
|
|
177
|
-
expect(routes).not.toContain('ANY /api/integrations');
|
|
178
|
-
expect(routes).not.toContain('ANY /api/authorize');
|
|
179
|
-
expect(routes).not.toContain('ANY /api/entity');
|
|
180
|
-
expect(routes).toContain('GET /api/integrations/redirect/{appId}');
|
|
181
|
-
expect(routes).toContain('ANY /api/v2/integrations');
|
|
97
|
+
expect(result.functions.auth.events).toHaveLength(3);
|
|
182
98
|
});
|
|
183
99
|
|
|
184
100
|
it('should NOT include legacy dbMigrate function', () => {
|
|
@@ -2,13 +2,6 @@ const {
|
|
|
2
2
|
composeServerlessDefinition,
|
|
3
3
|
applySsmPreloadNodeOptions,
|
|
4
4
|
} = require('./infrastructure-composer');
|
|
5
|
-
// Composing must not build the real Prisma layer: that runs npm install
|
|
6
|
-
// under packages/devtools, and two workers doing it at once once pruned the
|
|
7
|
-
// repository's root node_modules (test/npm-install-guard.js).
|
|
8
|
-
jest.mock('./domains/shared/utilities/prisma-layer-manager', () => ({
|
|
9
|
-
ensurePrismaLayerExists: jest.fn(async () => {}),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
5
|
const {
|
|
13
6
|
SSM_PRELOAD_NODE_OPTIONS,
|
|
14
7
|
} = require('./domains/parameters/offload-utils');
|