@friggframework/devtools 2.0.0--canary.686.219e1e7.0 → 2.0.0--canary.688.e850868.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/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/shared/types/app-definition.js +1 -15
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +10 -26
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +1 -61
- 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
|
@@ -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 };
|
|
@@ -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' } }],
|
|
@@ -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[]} [extensions] - App-level extensions that add custom Prisma models, encrypted fields, admin routes and bootstrap hooks (not an integration's Definition.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
|
|
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,24 +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 Management API route
|
|
19
|
-
* registry (ADR-053): the same registry mounts the Express routers and
|
|
20
|
-
* builds the OpenAPI documents, so the three cannot drift.
|
|
21
|
-
*/
|
|
22
|
-
function managementApiEvents(AppDefinition, functionName) {
|
|
23
|
-
const managementApi = AppDefinition.managementApi || {};
|
|
24
|
-
return getGatewayRoutes({
|
|
25
|
-
v1: managementApi.v1 !== false,
|
|
26
|
-
proxy: managementApi.proxy?.enable === true,
|
|
27
|
-
})
|
|
28
|
-
.filter((route) => route.function === functionName)
|
|
29
|
-
.map(({ method, path }) => ({ httpApi: { path, method } }));
|
|
30
|
-
}
|
|
31
13
|
|
|
32
14
|
/**
|
|
33
15
|
* Create base serverless definition with core functions and resources
|
|
@@ -304,12 +286,16 @@ function createBaseDefinition(
|
|
|
304
286
|
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
305
287
|
skipEsbuild: true, // Handlers in node_modules don't need bundling
|
|
306
288
|
package: skipEsbuildPackageConfig,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
+
],
|
|
313
299
|
},
|
|
314
300
|
user: {
|
|
315
301
|
handler: 'node_modules/@friggframework/core/handlers/routers/user.handler',
|
|
@@ -326,8 +312,6 @@ function createBaseDefinition(
|
|
|
326
312
|
events: [
|
|
327
313
|
{ httpApi: { path: '/health', method: 'GET' } },
|
|
328
314
|
{ httpApi: { path: '/health/{proxy+}', method: 'GET' } },
|
|
329
|
-
// GET /api/meta and the OpenAPI documents: public, DB-free.
|
|
330
|
-
...managementApiEvents(AppDefinition, 'health'),
|
|
331
315
|
],
|
|
332
316
|
},
|
|
333
317
|
// Reporting is an admin operation (ADR-010): the report router runs on the admin-scripts Lambda, not as a standalone function here.
|
|
@@ -94,67 +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
|
-
]);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('drops the v1 routes when managementApi.v1 is false, keeping the OAuth redirect', () => {
|
|
149
|
-
const result = createBaseDefinition({ managementApi: { v1: false } }, {}, {});
|
|
150
|
-
const routes = result.functions.auth.events.map(
|
|
151
|
-
(e) => `${e.httpApi.method} ${e.httpApi.path}`
|
|
152
|
-
);
|
|
153
|
-
expect(routes).not.toContain('ANY /api/integrations');
|
|
154
|
-
expect(routes).not.toContain('ANY /api/authorize');
|
|
155
|
-
expect(routes).not.toContain('ANY /api/entity');
|
|
156
|
-
expect(routes).toContain('GET /api/integrations/redirect/{appId}');
|
|
157
|
-
expect(routes).toContain('ANY /api/v2/integrations');
|
|
97
|
+
expect(result.functions.auth.events).toHaveLength(3);
|
|
158
98
|
});
|
|
159
99
|
|
|
160
100
|
it('should NOT include legacy dbMigrate function', () => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/devtools",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.
|
|
4
|
+
"version": "2.0.0--canary.688.e850868.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"frigg": "./frigg-cli/index.js"
|
|
7
7
|
},
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"@babel/eslint-parser": "^7.18.9",
|
|
27
27
|
"@babel/parser": "^7.25.3",
|
|
28
28
|
"@babel/traverse": "^7.25.3",
|
|
29
|
-
"@friggframework/core": "2.0.0--canary.
|
|
30
|
-
"@friggframework/schemas": "2.0.0--canary.
|
|
31
|
-
"@friggframework/test": "2.0.0--canary.
|
|
29
|
+
"@friggframework/core": "2.0.0--canary.688.e850868.0",
|
|
30
|
+
"@friggframework/schemas": "2.0.0--canary.688.e850868.0",
|
|
31
|
+
"@friggframework/test": "2.0.0--canary.688.e850868.0",
|
|
32
32
|
"@hapi/boom": "^10.0.1",
|
|
33
33
|
"@inquirer/prompts": "^5.3.8",
|
|
34
34
|
"axios": "^1.18.0",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"validate-npm-package-name": "^5.0.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
60
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
59
|
+
"@friggframework/eslint-config": "2.0.0--canary.688.e850868.0",
|
|
60
|
+
"@friggframework/prettier-config": "2.0.0--canary.688.e850868.0",
|
|
61
61
|
"aws-sdk-client-mock": "^4.1.0",
|
|
62
62
|
"aws-sdk-client-mock-jest": "^4.1.0",
|
|
63
63
|
"jest": "^30.1.3",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"publishConfig": {
|
|
90
90
|
"access": "public"
|
|
91
91
|
},
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "e850868f19706ee89566fd9724603dee1e03a711"
|
|
93
93
|
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provider dispatch (friggframework/frigg#545): appDefinition.provider
|
|
3
|
-
* decides whether a CLI command runs the AWS/serverless path or the
|
|
4
|
-
* provider plugin. Uses real temp projects and the real provider-netlify.
|
|
5
|
-
*/
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const os = require('os');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
|
|
10
|
-
function writeProject(definitionSource) {
|
|
11
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-dispatch-'));
|
|
12
|
-
const backend = path.join(dir, 'backend');
|
|
13
|
-
fs.mkdirSync(backend);
|
|
14
|
-
fs.writeFileSync(path.join(backend, 'package.json'), '{"name":"backend"}');
|
|
15
|
-
fs.writeFileSync(path.join(backend, 'index.js'), `module.exports = { Definition: ${definitionSource} };`);
|
|
16
|
-
return { dir, backend };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const NETLIFY_APP = `{
|
|
20
|
-
name: 'dispatch-app',
|
|
21
|
-
provider: 'netlify',
|
|
22
|
-
integrations: [],
|
|
23
|
-
database: { postgres: { enable: true } },
|
|
24
|
-
}`;
|
|
25
|
-
|
|
26
|
-
describe('provider-helper', () => {
|
|
27
|
-
const { loadProviderForCli, loadCliAppDefinition, isNonAwsProject } = require('../../../utils/provider-helper');
|
|
28
|
-
const dirs = [];
|
|
29
|
-
afterAll(() => dirs.forEach((d) => fs.rmSync(d, { recursive: true, force: true })));
|
|
30
|
-
|
|
31
|
-
it('returns null without an app definition', () => {
|
|
32
|
-
expect(loadProviderForCli({ cwd: os.tmpdir() })).toBeNull();
|
|
33
|
-
expect(loadCliAppDefinition('/nonexistent/path')).toBeNull();
|
|
34
|
-
expect(isNonAwsProject({ cwd: os.tmpdir() })).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('treats a missing provider as aws with no plugin', () => {
|
|
38
|
-
const { dir, backend } = writeProject(`{ integrations: [] }`);
|
|
39
|
-
dirs.push(dir);
|
|
40
|
-
expect(loadProviderForCli({ cwd: backend })).toEqual(
|
|
41
|
-
expect.objectContaining({ providerName: 'aws', provider: null, backendDir: backend })
|
|
42
|
-
);
|
|
43
|
-
expect(isNonAwsProject({ cwd: backend })).toBe(false);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('resolves the netlify plugin from the project root or from backend/', () => {
|
|
47
|
-
const { dir, backend } = writeProject(NETLIFY_APP);
|
|
48
|
-
dirs.push(dir);
|
|
49
|
-
for (const cwd of [dir, backend]) {
|
|
50
|
-
const result = loadProviderForCli({ cwd });
|
|
51
|
-
expect(result.providerName).toBe('netlify');
|
|
52
|
-
expect(result.provider.name).toBe('netlify');
|
|
53
|
-
expect(result.backendDir).toBe(backend);
|
|
54
|
-
}
|
|
55
|
-
expect(isNonAwsProject({ cwd: backend })).toBe(true);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('buildWithProvider', () => {
|
|
60
|
-
const { buildWithProvider } = require('../../../../infrastructure/provider-build');
|
|
61
|
-
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
jest.spyOn(console, 'log').mockImplementation();
|
|
64
|
-
jest.spyOn(console, 'warn').mockImplementation();
|
|
65
|
-
jest.spyOn(console, 'error').mockImplementation();
|
|
66
|
-
});
|
|
67
|
-
afterEach(() => jest.restoreAllMocks());
|
|
68
|
-
|
|
69
|
-
it('writes netlify.toml, functions and lib shims beside backend/, where their requires resolve', () => {
|
|
70
|
-
const { dir, backend } = writeProject(NETLIFY_APP);
|
|
71
|
-
try {
|
|
72
|
-
const appDefinition = require(path.join(backend, 'index.js')).Definition;
|
|
73
|
-
const { projectDir } = buildWithProvider({ appDefinition, backendDir: backend });
|
|
74
|
-
|
|
75
|
-
expect(projectDir).toBe(dir);
|
|
76
|
-
expect(fs.existsSync(path.join(dir, 'netlify.toml'))).toBe(true);
|
|
77
|
-
const auth = fs.readFileSync(path.join(dir, 'netlify/functions/auth.js'), 'utf8');
|
|
78
|
-
expect(auth).toContain("require('../../backend/index.js')");
|
|
79
|
-
expect(fs.existsSync(path.join(dir, 'netlify/lib/create-netlify-app-handler.js'))).toBe(true);
|
|
80
|
-
// Nothing is written into the backend directory itself.
|
|
81
|
-
expect(fs.existsSync(path.join(backend, 'netlify'))).toBe(false);
|
|
82
|
-
} finally {
|
|
83
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('stops on validation errors and writes nothing', () => {
|
|
88
|
-
const exit = jest.fn();
|
|
89
|
-
const { dir, backend } = writeProject(`{ provider: 'netlify', integrations: [] }`);
|
|
90
|
-
try {
|
|
91
|
-
const appDefinition = require(path.join(backend, 'index.js')).Definition;
|
|
92
|
-
const { written } = buildWithProvider({ appDefinition, backendDir: backend, exit });
|
|
93
|
-
expect(exit).toHaveBeenCalledWith(1);
|
|
94
|
-
expect(written).toEqual([]);
|
|
95
|
-
expect(fs.existsSync(path.join(dir, 'netlify.toml'))).toBe(false);
|
|
96
|
-
} finally {
|
|
97
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('frigg build dispatch', () => {
|
|
103
|
-
beforeEach(() => {
|
|
104
|
-
jest.resetModules();
|
|
105
|
-
jest.spyOn(console, 'log').mockImplementation();
|
|
106
|
-
jest.spyOn(console, 'warn').mockImplementation();
|
|
107
|
-
});
|
|
108
|
-
afterEach(() => {
|
|
109
|
-
jest.restoreAllMocks();
|
|
110
|
-
jest.dontMock('child_process');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('builds a netlify app through the plugin, never through osls', async () => {
|
|
114
|
-
const spawnSync = jest.fn(() => ({ status: 0 }));
|
|
115
|
-
jest.doMock('child_process', () => ({ ...jest.requireActual('child_process'), spawnSync }));
|
|
116
|
-
const { dir, backend } = writeProject(NETLIFY_APP);
|
|
117
|
-
try {
|
|
118
|
-
jest.spyOn(process, 'cwd').mockReturnValue(backend);
|
|
119
|
-
await require('../../../build-command').buildCommand({});
|
|
120
|
-
expect(spawnSync).not.toHaveBeenCalled();
|
|
121
|
-
expect(fs.existsSync(path.join(dir, 'netlify/functions/worker-background.js'))).toBe(true);
|
|
122
|
-
} finally {
|
|
123
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('keeps the serverless path for an aws app', async () => {
|
|
128
|
-
const spawnSync = jest.fn(() => ({ status: 0 }));
|
|
129
|
-
jest.doMock('child_process', () => ({ ...jest.requireActual('child_process'), spawnSync }));
|
|
130
|
-
const { dir, backend } = writeProject(`{ integrations: [] }`);
|
|
131
|
-
try {
|
|
132
|
-
jest.spyOn(process, 'cwd').mockReturnValue(backend);
|
|
133
|
-
await require('../../../build-command').buildCommand({});
|
|
134
|
-
expect(spawnSync).toHaveBeenCalledWith('osls', expect.any(Array), expect.any(Object));
|
|
135
|
-
expect(fs.existsSync(path.join(dir, 'netlify'))).toBe(false);
|
|
136
|
-
} finally {
|
|
137
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Provider Helper (friggframework/frigg#545, 88cf983e / c8705715)
|
|
3
|
-
*
|
|
4
|
-
* Loads the app definition from the user's project and resolves its
|
|
5
|
-
* provider plugin, so CLI commands can delegate to it (Netlify, ...) or fall
|
|
6
|
-
* through to the AWS/serverless behaviour.
|
|
7
|
-
*/
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Find the backend: <cwd>/backend/index.js, then <cwd>/index.js.
|
|
13
|
-
* @param {string} cwd
|
|
14
|
-
* @returns {{ appDefinition: Object, backendDir: string } | null}
|
|
15
|
-
*/
|
|
16
|
-
function loadCliBackend(cwd) {
|
|
17
|
-
for (const dir of [path.join(cwd, 'backend'), cwd]) {
|
|
18
|
-
const indexPath = path.join(dir, 'index.js');
|
|
19
|
-
if (!fs.existsSync(indexPath)) continue;
|
|
20
|
-
try {
|
|
21
|
-
const exported = require(indexPath);
|
|
22
|
-
if (exported && exported.Definition) {
|
|
23
|
-
return { appDefinition: exported.Definition, backendDir: dir };
|
|
24
|
-
}
|
|
25
|
-
} catch {
|
|
26
|
-
// Failed to load, try next
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param {string} cwd
|
|
34
|
-
* @returns {Object|null} the app Definition
|
|
35
|
-
*/
|
|
36
|
-
function loadCliAppDefinition(cwd) {
|
|
37
|
-
return loadCliBackend(cwd)?.appDefinition || null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Load the app definition and resolve the provider plugin for CLI commands.
|
|
42
|
-
*
|
|
43
|
-
* @param {Object} [options]
|
|
44
|
-
* @param {string} [options.cwd] - Working directory (default: process.cwd())
|
|
45
|
-
* @returns {{ appDefinition: Object, backendDir: string, provider: Object|null, providerName: string } | null}
|
|
46
|
-
* null when no app definition is found; provider null for 'aws' (the
|
|
47
|
-
* caller keeps its existing behaviour).
|
|
48
|
-
*/
|
|
49
|
-
function loadProviderForCli(options = {}) {
|
|
50
|
-
const cwd = options.cwd || process.cwd();
|
|
51
|
-
const backend = loadCliBackend(cwd);
|
|
52
|
-
if (!backend) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const providerName = backend.appDefinition.provider || 'aws';
|
|
57
|
-
if (providerName === 'aws') {
|
|
58
|
-
return { ...backend, provider: null, providerName: 'aws' };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
resolveProvider,
|
|
63
|
-
} = require('@friggframework/core/providers/resolve-provider');
|
|
64
|
-
return { ...backend, provider: resolveProvider(backend.appDefinition), providerName };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* True when the project's app definition names a non-AWS provider. Used to
|
|
69
|
-
* guard the AWS-only commands (doctor, repair, generate-iam).
|
|
70
|
-
*/
|
|
71
|
-
function isNonAwsProject(options = {}) {
|
|
72
|
-
try {
|
|
73
|
-
const result = loadProviderForCli(options);
|
|
74
|
-
return Boolean(result && result.providerName !== 'aws');
|
|
75
|
-
} catch {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
module.exports = { loadProviderForCli, loadCliAppDefinition, loadCliBackend, isNonAwsProject };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `node infrastructure.js package` (what a backend's `npm run build` runs)
|
|
3
|
-
* for an app with provider 'netlify': createFriggInfrastructure() builds
|
|
4
|
-
* through provider-netlify and returns an empty serverless definition
|
|
5
|
-
* instead of composing CloudFormation (friggframework/frigg#545, 302ab9ba).
|
|
6
|
-
*/
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const os = require('os');
|
|
9
|
-
const path = require('path');
|
|
10
|
-
|
|
11
|
-
jest.mock('../infrastructure-composer', () => ({
|
|
12
|
-
composeServerlessDefinition: jest.fn(async () => ({ service: 'aws-app' })),
|
|
13
|
-
}));
|
|
14
|
-
jest.mock('@friggframework/core', () => ({
|
|
15
|
-
findNearestBackendPackageJson: jest.fn(),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
19
|
-
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
20
|
-
const { createFriggInfrastructure } = require('../create-frigg-infrastructure');
|
|
21
|
-
|
|
22
|
-
function writeProject(definitionSource) {
|
|
23
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-infra-'));
|
|
24
|
-
const backend = path.join(dir, 'backend');
|
|
25
|
-
fs.mkdirSync(backend);
|
|
26
|
-
fs.writeFileSync(path.join(backend, 'package.json'), '{"name":"backend"}');
|
|
27
|
-
fs.writeFileSync(path.join(backend, 'index.js'), `module.exports = { Definition: ${definitionSource} };`);
|
|
28
|
-
findNearestBackendPackageJson.mockReturnValue(path.join(backend, 'package.json'));
|
|
29
|
-
return dir;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe('createFriggInfrastructure with a non-AWS provider', () => {
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
jest.clearAllMocks();
|
|
35
|
-
jest.spyOn(console, 'log').mockImplementation();
|
|
36
|
-
jest.spyOn(console, 'warn').mockImplementation();
|
|
37
|
-
});
|
|
38
|
-
afterEach(() => jest.restoreAllMocks());
|
|
39
|
-
|
|
40
|
-
it('generates the Netlify project and composes no serverless definition', async () => {
|
|
41
|
-
const dir = writeProject(`{
|
|
42
|
-
provider: 'netlify', integrations: [], database: { postgres: { enable: true } }
|
|
43
|
-
}`);
|
|
44
|
-
try {
|
|
45
|
-
await expect(createFriggInfrastructure()).resolves.toEqual({});
|
|
46
|
-
expect(composeServerlessDefinition).not.toHaveBeenCalled();
|
|
47
|
-
expect(fs.existsSync(path.join(dir, 'netlify.toml'))).toBe(true);
|
|
48
|
-
expect(fs.existsSync(path.join(dir, 'netlify/functions/auth.js'))).toBe(true);
|
|
49
|
-
expect(fs.existsSync(path.join(dir, 'netlify/lib/routers.js'))).toBe(true);
|
|
50
|
-
} finally {
|
|
51
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('keeps composing the serverless definition for AWS', async () => {
|
|
56
|
-
const dir = writeProject(`{ provider: 'aws', integrations: [] }`);
|
|
57
|
-
try {
|
|
58
|
-
await expect(createFriggInfrastructure()).resolves.toEqual({ service: 'aws-app' });
|
|
59
|
-
expect(fs.existsSync(path.join(dir, 'netlify.toml'))).toBe(false);
|
|
60
|
-
} finally {
|
|
61
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Management API ↔ API Gateway route coverage
|
|
3
|
-
*
|
|
4
|
-
* The Management API (ADR-053) is served by the `auth` Lambda (v1, v2 and
|
|
5
|
-
* the OAuth redirect) and, for /api/meta, by the DB-free `health` Lambda.
|
|
6
|
-
* API Gateway HTTP APIs have no implicit catch-all: a request whose path
|
|
7
|
-
* matches no declared route gets a gateway 404 and never reaches Express.
|
|
8
|
-
* So every route those routers register must be covered by an httpApi event
|
|
9
|
-
* on the right function, and no more-specific route on another function may
|
|
10
|
-
* shadow it. Both the routers and the gateway routes come from core's route
|
|
11
|
-
* registry; this test proves the outcome end to end.
|
|
12
|
-
*
|
|
13
|
-
* The Express routes are read from the live routers (not a hard-coded
|
|
14
|
-
* list), so a route added to core later fails this test until the gateway
|
|
15
|
-
* routes follow.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
// Avoid AWS calls: hand the builders a fixed discovery result.
|
|
19
|
-
jest.mock('../domains/shared/resource-discovery', () => {
|
|
20
|
-
const actual = jest.requireActual('../domains/shared/resource-discovery');
|
|
21
|
-
return {
|
|
22
|
-
...actual,
|
|
23
|
-
gatherDiscoveredResources: jest.fn().mockResolvedValue({
|
|
24
|
-
defaultVpcId: 'vpc-123456',
|
|
25
|
-
vpcCidr: '172.31.0.0/16',
|
|
26
|
-
defaultSecurityGroupId: 'sg-123456',
|
|
27
|
-
privateSubnetId1: 'subnet-123456',
|
|
28
|
-
privateSubnetId2: 'subnet-789012',
|
|
29
|
-
publicSubnetId1: 'subnet-public-1',
|
|
30
|
-
publicSubnetId2: 'subnet-public-2',
|
|
31
|
-
defaultRouteTableId: 'rtb-123456',
|
|
32
|
-
defaultKmsKeyId:
|
|
33
|
-
'arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012',
|
|
34
|
-
existingNatGatewayId: 'nat-default123',
|
|
35
|
-
auroraClusterEndpoint:
|
|
36
|
-
'test-cluster.cluster-abc123.us-east-1.rds.amazonaws.com',
|
|
37
|
-
auroraPort: 5432,
|
|
38
|
-
auroraEngine: 'aurora-postgresql',
|
|
39
|
-
}),
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// The Management API routers load the app definition from the consuming
|
|
44
|
-
// backend; give them one so they can be built in isolation. The entity proxy
|
|
45
|
-
// is enabled so its route is checked too.
|
|
46
|
-
jest.mock('@friggframework/core/handlers/app-definition-loader', () => ({
|
|
47
|
-
loadAppDefinition: () => ({
|
|
48
|
-
integrations: [],
|
|
49
|
-
userConfig: {},
|
|
50
|
-
managementApi: { proxy: { enable: true } },
|
|
51
|
-
}),
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
|
-
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
55
|
-
|
|
56
|
-
/** Routes registered on an Express router, including nested routers. */
|
|
57
|
-
function collectRoutes(router, routes = new Map()) {
|
|
58
|
-
const stack = (router._router || router).stack || [];
|
|
59
|
-
for (const layer of stack) {
|
|
60
|
-
if (layer.route) {
|
|
61
|
-
for (const method of Object.keys(layer.route.methods)) {
|
|
62
|
-
const route = {
|
|
63
|
-
method: method === '_all' ? 'ANY' : method.toUpperCase(),
|
|
64
|
-
path: layer.route.path,
|
|
65
|
-
};
|
|
66
|
-
routes.set(`${route.method} ${route.path}`, route);
|
|
67
|
-
}
|
|
68
|
-
} else if (layer.handle && Array.isArray(layer.handle.stack)) {
|
|
69
|
-
collectRoutes(layer.handle, routes);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return routes;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Builds a core router with DB_TYPE set: the repository factories pick an
|
|
77
|
-
* adapter from it (or the backend's app definition, which doesn't exist
|
|
78
|
-
* here). Nothing connects.
|
|
79
|
-
*/
|
|
80
|
-
function withDbType(build) {
|
|
81
|
-
const previousDbType = process.env.DB_TYPE;
|
|
82
|
-
process.env.DB_TYPE = 'postgresql';
|
|
83
|
-
try {
|
|
84
|
-
return build();
|
|
85
|
-
} finally {
|
|
86
|
-
if (previousDbType === undefined) delete process.env.DB_TYPE;
|
|
87
|
-
else process.env.DB_TYPE = previousDbType;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** Every route the auth Lambda's router (core/handlers/routers/auth.js) serves. */
|
|
92
|
-
function getAuthLambdaRoutes() {
|
|
93
|
-
const { router } = withDbType(() =>
|
|
94
|
-
require('@friggframework/core/handlers/routers/auth')
|
|
95
|
-
);
|
|
96
|
-
return [...collectRoutes(router).values()];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Every route the health Lambda serves under /api/meta. */
|
|
100
|
-
function getMetaRoutes() {
|
|
101
|
-
const { router } = withDbType(() =>
|
|
102
|
-
require('@friggframework/core/handlers/routers/health')
|
|
103
|
-
);
|
|
104
|
-
return [...collectRoutes(router).values()].filter((r) =>
|
|
105
|
-
r.path.startsWith('/api/meta')
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function getGatewayRoutes(definition) {
|
|
110
|
-
const routes = [];
|
|
111
|
-
for (const [functionName, fn] of Object.entries(definition.functions)) {
|
|
112
|
-
for (const event of fn.events || []) {
|
|
113
|
-
if (!event.httpApi) continue;
|
|
114
|
-
routes.push({
|
|
115
|
-
functionName,
|
|
116
|
-
method: String(event.httpApi.method).toUpperCase(),
|
|
117
|
-
path: event.httpApi.path,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return routes;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const segmentsOf = (p) => p.split('/').filter(Boolean);
|
|
125
|
-
|
|
126
|
-
// Turn an Express path into a concrete request path, e.g.
|
|
127
|
-
// /api/entities/:entityId/options -> /api/entities/sample-entityId/options
|
|
128
|
-
const toConcretePath = (expressPath) =>
|
|
129
|
-
expressPath.replace(/:([A-Za-z0-9_]+)/g, 'sample-$1');
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* HTTP API path matching: literal segments match exactly, {param} matches
|
|
133
|
-
* one segment, a trailing {proxy+} greedily matches one or more segments.
|
|
134
|
-
* Returns null on no match, otherwise a specificity descriptor.
|
|
135
|
-
*/
|
|
136
|
-
function matchGatewayPath(gatewayPath, requestPath) {
|
|
137
|
-
const g = segmentsOf(gatewayPath);
|
|
138
|
-
const r = segmentsOf(requestPath);
|
|
139
|
-
let literals = 0;
|
|
140
|
-
for (let i = 0; i < g.length; i++) {
|
|
141
|
-
const seg = g[i];
|
|
142
|
-
if (/^\{[^}]+\+\}$/.test(seg)) {
|
|
143
|
-
if (i !== g.length - 1 || r.length <= i) return null;
|
|
144
|
-
return { greedy: true, literals, prefixLength: i };
|
|
145
|
-
}
|
|
146
|
-
if (i >= r.length) return null;
|
|
147
|
-
if (/^\{[^}]+\}$/.test(seg)) continue;
|
|
148
|
-
if (seg !== r[i]) return null;
|
|
149
|
-
literals++;
|
|
150
|
-
}
|
|
151
|
-
if (g.length !== r.length) return null;
|
|
152
|
-
return { greedy: false, literals, prefixLength: g.length };
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Select the route API Gateway would invoke: a non-greedy match beats a
|
|
157
|
-
* greedy one, then more literal segments, then the longer greedy prefix,
|
|
158
|
-
* then an explicit method beats ANY.
|
|
159
|
-
*/
|
|
160
|
-
function selectGatewayRoute(gatewayRoutes, method, requestPath) {
|
|
161
|
-
const candidates = gatewayRoutes
|
|
162
|
-
.filter(
|
|
163
|
-
(r) => r.method === 'ANY' || method === 'ANY' || r.method === method
|
|
164
|
-
)
|
|
165
|
-
.map((r) => ({
|
|
166
|
-
route: r,
|
|
167
|
-
match: matchGatewayPath(r.path, requestPath),
|
|
168
|
-
}))
|
|
169
|
-
.filter((c) => c.match);
|
|
170
|
-
candidates.sort(
|
|
171
|
-
(a, b) =>
|
|
172
|
-
Number(a.match.greedy) - Number(b.match.greedy) ||
|
|
173
|
-
b.match.literals - a.match.literals ||
|
|
174
|
-
b.match.prefixLength - a.match.prefixLength ||
|
|
175
|
-
Number(a.route.method === 'ANY') - Number(b.route.method === 'ANY')
|
|
176
|
-
);
|
|
177
|
-
return candidates.length ? candidates[0].route : null;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
describe('Management API routes are reachable through API Gateway', () => {
|
|
181
|
-
let gatewayRoutes;
|
|
182
|
-
let managementRoutes;
|
|
183
|
-
let metaRoutes;
|
|
184
|
-
const originalArgv = process.argv;
|
|
185
|
-
|
|
186
|
-
beforeAll(async () => {
|
|
187
|
-
process.argv = ['node', 'test'];
|
|
188
|
-
process.env.AWS_REGION = 'us-east-1';
|
|
189
|
-
// The builders narrate their progress; keep the test output quiet.
|
|
190
|
-
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
191
|
-
const warnSpy = jest
|
|
192
|
-
.spyOn(console, 'warn')
|
|
193
|
-
.mockImplementation(() => {});
|
|
194
|
-
try {
|
|
195
|
-
const definition = await composeServerlessDefinition({
|
|
196
|
-
name: 'route-coverage-app',
|
|
197
|
-
provider: 'aws',
|
|
198
|
-
usePrismaLambdaLayer: false,
|
|
199
|
-
database: { postgres: { enable: true } },
|
|
200
|
-
websockets: { enable: true },
|
|
201
|
-
adminScripts: [
|
|
202
|
-
class ExampleScript {
|
|
203
|
-
static Definition = { name: 'example-script' };
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
admin: { includeBuiltinReports: true },
|
|
207
|
-
integrations: [
|
|
208
|
-
{
|
|
209
|
-
Definition: {
|
|
210
|
-
name: 'acme',
|
|
211
|
-
webhooks: true,
|
|
212
|
-
extensions: {
|
|
213
|
-
inbound: {
|
|
214
|
-
extension: {
|
|
215
|
-
routes: [
|
|
216
|
-
{ path: '/events', method: 'POST' },
|
|
217
|
-
],
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
// Integration names share the /api/ namespace with the
|
|
224
|
-
// Management API; make sure they don't shadow it.
|
|
225
|
-
{ Definition: { name: 'entities' } },
|
|
226
|
-
],
|
|
227
|
-
});
|
|
228
|
-
gatewayRoutes = getGatewayRoutes(definition);
|
|
229
|
-
} finally {
|
|
230
|
-
logSpy.mockRestore();
|
|
231
|
-
warnSpy.mockRestore();
|
|
232
|
-
}
|
|
233
|
-
managementRoutes = getAuthLambdaRoutes();
|
|
234
|
-
metaRoutes = getMetaRoutes();
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
afterAll(() => {
|
|
238
|
-
process.argv = originalArgv;
|
|
239
|
-
delete process.env.AWS_REGION;
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('reads the Management API routes from the live auth and health routers', () => {
|
|
243
|
-
const paths = managementRoutes.map((r) => r.path);
|
|
244
|
-
expect(paths).toEqual(
|
|
245
|
-
expect.arrayContaining([
|
|
246
|
-
'/api/integrations',
|
|
247
|
-
'/api/authorize',
|
|
248
|
-
'/api/entity',
|
|
249
|
-
'/api/entity/options/:credentialId',
|
|
250
|
-
'/api/entities/:entityId',
|
|
251
|
-
'/api/integrations/redirect/:appId',
|
|
252
|
-
'/api/v2/integrations',
|
|
253
|
-
'/api/v2/entities/types/:entityType/requirements',
|
|
254
|
-
'/api/v2/entities/:entityId/proxy',
|
|
255
|
-
'/api/v2/credentials/:credentialId/reauthorize',
|
|
256
|
-
'/api/v2/authorize',
|
|
257
|
-
])
|
|
258
|
-
);
|
|
259
|
-
expect(metaRoutes.map((r) => r.path)).toEqual(
|
|
260
|
-
expect.arrayContaining(['/api/meta', '/api/meta/openapi/v2.json'])
|
|
261
|
-
);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('routes /api/meta to the DB-free health function', () => {
|
|
265
|
-
const unreachable = metaRoutes
|
|
266
|
-
.map(({ method, path: requestPath }) => {
|
|
267
|
-
const selected = selectGatewayRoute(gatewayRoutes, method, requestPath);
|
|
268
|
-
return { route: `${method} ${requestPath}`, ok: selected?.functionName === 'health' };
|
|
269
|
-
})
|
|
270
|
-
.filter((r) => !r.ok)
|
|
271
|
-
.map((r) => r.route);
|
|
272
|
-
expect(unreachable).toEqual([]);
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('declares no /api/v2 catch-all', () => {
|
|
276
|
-
expect(
|
|
277
|
-
gatewayRoutes.filter((r) => r.path === '/api/v2/{proxy+}' || r.path === '/api/v2')
|
|
278
|
-
).toEqual([]);
|
|
279
|
-
expect(selectGatewayRoute(gatewayRoutes, 'PATCH', '/api/v2/reports/daily')).toBeNull();
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it('routes every Management API route to the auth function', () => {
|
|
283
|
-
const unreachable = managementRoutes
|
|
284
|
-
.map(({ method, path: expressPath }) => {
|
|
285
|
-
const requestPath = toConcretePath(expressPath);
|
|
286
|
-
const selected = selectGatewayRoute(
|
|
287
|
-
gatewayRoutes,
|
|
288
|
-
method,
|
|
289
|
-
requestPath
|
|
290
|
-
);
|
|
291
|
-
return {
|
|
292
|
-
route: `${method} ${expressPath}`,
|
|
293
|
-
reachedBy: selected
|
|
294
|
-
? `${selected.method} ${selected.path} -> ${selected.functionName}`
|
|
295
|
-
: 'no API Gateway route',
|
|
296
|
-
ok: selected && selected.functionName === 'auth',
|
|
297
|
-
};
|
|
298
|
-
})
|
|
299
|
-
.filter((r) => !r.ok)
|
|
300
|
-
.map(({ route, reachedBy }) => `${route} (${reachedBy})`);
|
|
301
|
-
|
|
302
|
-
expect(unreachable).toEqual([]);
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it.each([
|
|
306
|
-
['GET', '/api/v2/reports', 'reportRouter'],
|
|
307
|
-
['POST', '/api/v2/reports/daily/run', 'reportRouter'],
|
|
308
|
-
['GET', '/api/v2/reports/daily', 'reportRouter'],
|
|
309
|
-
['GET', '/admin/scripts/example-script', 'adminScriptRouter'],
|
|
310
|
-
['POST', '/api/acme-integration/webhooks', 'acmeWebhook'],
|
|
311
|
-
['POST', '/api/acme-integration/inbound/events', 'acme__inbound'],
|
|
312
|
-
['GET', '/api/acme-integration/custom', 'acme'],
|
|
313
|
-
['GET', '/api/entities-integration/custom', 'entities'],
|
|
314
|
-
['POST', '/user/login', 'user'],
|
|
315
|
-
['GET', '/health/ready', 'health'],
|
|
316
|
-
])('leaves %s %s on %s', (method, requestPath, functionName) => {
|
|
317
|
-
const selected = selectGatewayRoute(gatewayRoutes, method, requestPath);
|
|
318
|
-
expect(selected && selected.functionName).toBe(functionName);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('declares no method + path pair on more than one function', () => {
|
|
322
|
-
const seen = new Map();
|
|
323
|
-
const duplicates = [];
|
|
324
|
-
for (const r of gatewayRoutes) {
|
|
325
|
-
const key = `${r.method} ${r.path}`;
|
|
326
|
-
if (seen.has(key) && seen.get(key) !== r.functionName) {
|
|
327
|
-
duplicates.push(
|
|
328
|
-
`${key}: ${seen.get(key)} and ${r.functionName}`
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
seen.set(key, r.functionName);
|
|
332
|
-
}
|
|
333
|
-
expect(duplicates).toEqual([]);
|
|
334
|
-
});
|
|
335
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build for a non-AWS provider (friggframework/frigg#545, 302ab9ba /
|
|
3
|
-
* c8705715).
|
|
4
|
-
*
|
|
5
|
-
* Instead of the serverless/CloudFormation pipeline, the provider plugin
|
|
6
|
-
* (resolved from appDefinition.provider) does the build:
|
|
7
|
-
* 1. validate(appDefinition) - errors abort, warnings print
|
|
8
|
-
* 2. generateConfig(appDefinition) - e.g. netlify.toml
|
|
9
|
-
* 3. getFunctionEntryPoints(appDefinition) - written to <project>/netlify/functions
|
|
10
|
-
* 4. getLibEntryPoints(appDefinition) - written to <project>/netlify/lib
|
|
11
|
-
*
|
|
12
|
-
* <project> is the directory that holds backend/: the generated entry points
|
|
13
|
-
* require '../../backend/...', so they must sit beside it. #545 had two
|
|
14
|
-
* copies of this, and the CLI one wrote into the backend directory itself,
|
|
15
|
-
* where those relative requires do not resolve.
|
|
16
|
-
*
|
|
17
|
-
* Shared by createFriggInfrastructure() (`node infrastructure.js package`,
|
|
18
|
-
* what a backend's `npm run build` runs) and `frigg build`.
|
|
19
|
-
*/
|
|
20
|
-
const path = require('path');
|
|
21
|
-
const fs = require('fs');
|
|
22
|
-
|
|
23
|
-
const CONFIG_FILE_NAMES = { netlify: 'netlify.toml' };
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @param {Object} params
|
|
27
|
-
* @param {Object} params.appDefinition
|
|
28
|
-
* @param {string} params.backendDir - directory containing the backend's index.js
|
|
29
|
-
* @param {Object} [params.provider] - resolved plugin; defaults to resolveProvider(appDefinition)
|
|
30
|
-
* @param {boolean} [params.verbose]
|
|
31
|
-
* @param {Function} [params.exit] - called with 1 on validation errors (default process.exit)
|
|
32
|
-
* @returns {{ projectDir: string, written: string[] }}
|
|
33
|
-
*/
|
|
34
|
-
function buildWithProvider({
|
|
35
|
-
appDefinition,
|
|
36
|
-
backendDir,
|
|
37
|
-
provider,
|
|
38
|
-
verbose = false,
|
|
39
|
-
exit = (code) => process.exit(code),
|
|
40
|
-
}) {
|
|
41
|
-
const providerName = appDefinition.provider;
|
|
42
|
-
const plugin =
|
|
43
|
-
provider ||
|
|
44
|
-
require('@friggframework/core/providers/resolve-provider').resolveProvider(
|
|
45
|
-
appDefinition
|
|
46
|
-
);
|
|
47
|
-
const projectDir = path.dirname(path.resolve(backendDir));
|
|
48
|
-
const written = [];
|
|
49
|
-
|
|
50
|
-
console.log(`Building for ${providerName} provider (skipping AWS infrastructure)...`);
|
|
51
|
-
|
|
52
|
-
if (typeof plugin.validate === 'function') {
|
|
53
|
-
const validation = plugin.validate(appDefinition);
|
|
54
|
-
if (validation.errors?.length > 0) {
|
|
55
|
-
console.error(`\nValidation errors for ${providerName}:`);
|
|
56
|
-
for (const error of validation.errors) {
|
|
57
|
-
console.error(` - ${error}`);
|
|
58
|
-
}
|
|
59
|
-
exit(1);
|
|
60
|
-
return { projectDir, written };
|
|
61
|
-
}
|
|
62
|
-
for (const warning of validation.warnings || []) {
|
|
63
|
-
console.warn(` Warning: ${warning}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const write = (filePath, content) => {
|
|
68
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
69
|
-
fs.writeFileSync(filePath, content, 'utf-8');
|
|
70
|
-
written.push(filePath);
|
|
71
|
-
if (verbose) console.log(` Written ${path.relative(projectDir, filePath)}`);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
if (typeof plugin.generateConfig === 'function') {
|
|
75
|
-
const fileName = CONFIG_FILE_NAMES[providerName] || `${providerName}.config`;
|
|
76
|
-
write(path.join(projectDir, fileName), plugin.generateConfig(appDefinition));
|
|
77
|
-
console.log(` Written ${fileName}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (typeof plugin.getFunctionEntryPoints === 'function') {
|
|
81
|
-
const entryPoints = plugin.getFunctionEntryPoints(appDefinition);
|
|
82
|
-
for (const [fileName, content] of Object.entries(entryPoints)) {
|
|
83
|
-
write(path.join(projectDir, 'netlify', 'functions', fileName), content);
|
|
84
|
-
}
|
|
85
|
-
console.log(` Generated ${Object.keys(entryPoints).length} function entry points`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (typeof plugin.getLibEntryPoints === 'function') {
|
|
89
|
-
const libEntryPoints = plugin.getLibEntryPoints(appDefinition);
|
|
90
|
-
for (const [fileName, content] of Object.entries(libEntryPoints)) {
|
|
91
|
-
write(path.join(projectDir, 'netlify', 'lib', fileName), content);
|
|
92
|
-
}
|
|
93
|
-
console.log(` Generated ${Object.keys(libEntryPoints).length} lib entry points`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (typeof plugin.generateEnvTemplate === 'function') {
|
|
97
|
-
const missing = Object.entries(plugin.generateEnvTemplate(appDefinition)).filter(
|
|
98
|
-
([key]) => !process.env[key]
|
|
99
|
-
);
|
|
100
|
-
if (missing.length > 0) {
|
|
101
|
-
console.log('\n Environment variables not set locally (configure them on the platform):');
|
|
102
|
-
for (const [key] of missing) console.log(` - ${key}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
console.log(`\nBuild complete for ${providerName}.`);
|
|
107
|
-
return { projectDir, written };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* True when the app definition names a provider other than AWS.
|
|
112
|
-
* @param {Object} [appDefinition]
|
|
113
|
-
*/
|
|
114
|
-
function isNonAwsProvider(appDefinition) {
|
|
115
|
-
const name = appDefinition?.provider;
|
|
116
|
-
return Boolean(name) && name !== 'aws';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
module.exports = { buildWithProvider, isNonAwsProvider };
|