@friggframework/devtools 2.0.0--canary.703.12b980b.0 → 2.0.0--canary.707.df80bfd.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/__tests__/unit/commands/provider-dispatch.test.js +140 -0
- package/frigg-cli/build-command/index.js +32 -1
- package/frigg-cli/db-setup-command/index.js +25 -0
- package/frigg-cli/deploy-command/index.js +50 -5
- package/frigg-cli/doctor-command/index.js +7 -0
- package/frigg-cli/generate-iam-command.js +7 -0
- package/frigg-cli/index.js +0 -2
- package/frigg-cli/repair-command/index.js +7 -0
- package/frigg-cli/start-command/index.js +58 -0
- package/frigg-cli/utils/provider-helper.js +80 -0
- package/infrastructure/README.md +4 -2
- package/infrastructure/__tests__/compose-extension-prisma.test.js +168 -0
- package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +64 -0
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +335 -0
- package/infrastructure/__tests__/template-generation.test.js +7 -0
- package/infrastructure/compose-extension-prisma.js +73 -0
- package/infrastructure/create-frigg-infrastructure.js +14 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -6
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -30
- package/infrastructure/domains/integration/integration-builder.js +0 -19
- package/infrastructure/domains/integration/integration-builder.test.js +0 -22
- package/infrastructure/domains/parameters/offload-utils.js +1 -0
- package/infrastructure/domains/shared/environment-builder.js +12 -1
- package/infrastructure/domains/shared/environment-builder.test.js +20 -0
- package/infrastructure/domains/shared/function-environments.js +1 -9
- package/infrastructure/domains/shared/function-environments.test.js +0 -14
- package/infrastructure/domains/shared/types/app-definition.js +15 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +28 -10
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +85 -1
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +10 -0
- package/infrastructure/infrastructure-composer.js +13 -3
- package/infrastructure/infrastructure-composer.test.js +7 -0
- package/infrastructure/provider-build.js +126 -0
- package/infrastructure/scripts/build-prisma-layer.js +32 -5
- package/infrastructure/scripts/build-prisma-layer.test.js +35 -0
- package/package.json +7 -7
- package/test/npm-install-guard.js +104 -0
- package/test/npm-install-guard.test.js +53 -0
- package/frigg-cli/__tests__/unit/commands/deploy-subscriptions-step.test.js +0 -35
- package/frigg-cli/deploy-command/subscriptions-step.js +0 -44
- package/infrastructure/domains/integration/define-integration-provisioning.test.js +0 -59
- package/infrastructure/domains/scheduler/trigger-builder.js +0 -114
- package/infrastructure/domains/scheduler/trigger-builder.test.js +0 -82
|
@@ -0,0 +1,140 @@
|
|
|
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,7 +1,22 @@
|
|
|
1
1
|
const { spawnSync } = require('child_process');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
-
async function buildCommand(options) {
|
|
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
|
+
|
|
5
20
|
console.log('Building the serverless application...');
|
|
6
21
|
|
|
7
22
|
// Suppress AWS SDK warning message about maintenance mode
|
|
@@ -63,4 +78,20 @@ async function buildCommand(options) {
|
|
|
63
78
|
// });
|
|
64
79
|
}
|
|
65
80
|
|
|
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
|
+
|
|
66
97
|
module.exports = { buildCommand };
|
|
@@ -20,6 +20,27 @@ const {
|
|
|
20
20
|
getDatabaseSetupSuccess,
|
|
21
21
|
} = require('../utils/error-messages');
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Composes the backend's core extension schemas into core's Prisma client.
|
|
25
|
+
* A backend whose index.js cannot be found has no extensions to compose.
|
|
26
|
+
*/
|
|
27
|
+
function composeExtensionPrismaForBackend(verbose) {
|
|
28
|
+
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
29
|
+
const backendPackageJson = findNearestBackendPackageJson();
|
|
30
|
+
if (!backendPackageJson) return;
|
|
31
|
+
const backendDir = path.dirname(backendPackageJson);
|
|
32
|
+
const indexPath = path.join(backendDir, 'index.js');
|
|
33
|
+
if (!require('fs').existsSync(indexPath)) return;
|
|
34
|
+
const appDefinition = require(indexPath).Definition;
|
|
35
|
+
const { composeAppExtensionPrisma } = require('../../infrastructure/compose-extension-prisma');
|
|
36
|
+
const { results } = composeAppExtensionPrisma({ appDefinition, backendDir });
|
|
37
|
+
if (verbose) {
|
|
38
|
+
for (const r of results) {
|
|
39
|
+
console.log(chalk.gray(` Extension schemas (${r.dbType}): ${r.changed ? 'composed' : 'unchanged'}`));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
23
44
|
function getDatabaseDisplayName(dbType) {
|
|
24
45
|
switch (dbType) {
|
|
25
46
|
case 'postgresql':
|
|
@@ -109,6 +130,10 @@ async function dbSetupCommand(options = {}) {
|
|
|
109
130
|
console.log(chalk.gray('Step 3: Checking Prisma client...'));
|
|
110
131
|
}
|
|
111
132
|
|
|
133
|
+
// Core extensions' models must be in the client (and, on PostgreSQL,
|
|
134
|
+
// their migrations next to core's) before generating or migrating.
|
|
135
|
+
composeExtensionPrismaForBackend(verbose);
|
|
136
|
+
|
|
112
137
|
const clientCheck = checkPrismaClientGenerated(dbType);
|
|
113
138
|
const forceRegenerate = options.force || false;
|
|
114
139
|
|
|
@@ -4,7 +4,6 @@ const fs = require('fs');
|
|
|
4
4
|
|
|
5
5
|
// Import doctor command for post-deployment health check
|
|
6
6
|
const { doctorCommand } = require('../doctor-command');
|
|
7
|
-
const { reconcileSubscriptionsAfterDeploy } = require('./subscriptions-step');
|
|
8
7
|
|
|
9
8
|
// Configuration constants
|
|
10
9
|
const PATHS = {
|
|
@@ -311,9 +310,16 @@ async function pushOffloadedParametersOrAbort(appDefinition, options) {
|
|
|
311
310
|
}
|
|
312
311
|
|
|
313
312
|
async function deployCommand(options) {
|
|
314
|
-
console.log('Deploying the serverless application...');
|
|
315
|
-
|
|
316
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
|
+
console.log('Deploying the serverless application...');
|
|
317
323
|
const environment = validateAndBuildEnvironment(appDefinition, options);
|
|
318
324
|
|
|
319
325
|
await pushOffloadedParametersOrAbort(appDefinition, options);
|
|
@@ -329,8 +335,6 @@ async function deployCommand(options) {
|
|
|
329
335
|
|
|
330
336
|
console.log('\n✓ Deployment completed successfully!');
|
|
331
337
|
|
|
332
|
-
await reconcileSubscriptionsAfterDeploy(appDefinition, options);
|
|
333
|
-
|
|
334
338
|
const skipHealthCheck = options.skipDoctor || appDefinition?.deployment?.skipPostDeploymentHealthCheck;
|
|
335
339
|
|
|
336
340
|
// Run post-deployment health check (unless disabled)
|
|
@@ -349,4 +353,45 @@ async function deployCommand(options) {
|
|
|
349
353
|
}
|
|
350
354
|
}
|
|
351
355
|
|
|
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
|
+
|
|
352
397
|
module.exports = { deployCommand };
|
|
@@ -246,6 +246,13 @@ 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
|
+
|
|
249
256
|
// Extract options with defaults
|
|
250
257
|
const region = options.region || process.env.AWS_REGION || 'us-east-1';
|
|
251
258
|
const format = options.format || 'console';
|
|
@@ -9,6 +9,13 @@ 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
|
+
|
|
12
19
|
console.log('🔍 Finding Frigg application...');
|
|
13
20
|
|
|
14
21
|
// Find the backend package.json
|
package/frigg-cli/index.js
CHANGED
|
@@ -125,8 +125,6 @@ program
|
|
|
125
125
|
.option('-v, --verbose', 'enable verbose output')
|
|
126
126
|
.option('-f, --force', 'force deployment (bypasses caching for layers and functions)')
|
|
127
127
|
.option('--skip-doctor', 'skip post-deployment health check')
|
|
128
|
-
.option('--prune-subscriptions', 'after deploy, also remove app-scope webhook subscriptions no integration needs (one provider developer app per stage only)')
|
|
129
|
-
.option('--skip-subscriptions', 'skip the post-deploy webhook subscription reconcile')
|
|
130
128
|
.action(deployCommand);
|
|
131
129
|
|
|
132
130
|
program
|
|
@@ -453,6 +453,13 @@ 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
|
+
|
|
456
463
|
// Validate required parameter
|
|
457
464
|
if (!stackName) {
|
|
458
465
|
console.error('Error: Stack name is required');
|
|
@@ -37,6 +37,12 @@ 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
|
+
|
|
40
46
|
// Suppress AWS SDK warning message about maintenance mode
|
|
41
47
|
process.env.AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE = '1';
|
|
42
48
|
// Skip AWS discovery for local development
|
|
@@ -146,4 +152,56 @@ async function performDatabaseChecks(verbose) {
|
|
|
146
152
|
// connection when it starts.
|
|
147
153
|
}
|
|
148
154
|
|
|
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
|
+
|
|
149
207
|
module.exports = { startCommand };
|
|
@@ -0,0 +1,80 @@
|
|
|
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 };
|
package/infrastructure/README.md
CHANGED
|
@@ -163,9 +163,11 @@ const appDefinition = {
|
|
|
163
163
|
enableVPCEndpoints: true // Optional: create VPC endpoints
|
|
164
164
|
},
|
|
165
165
|
|
|
166
|
-
//
|
|
166
|
+
// Field-level encryption. 'kms' wires KMS_KEY_ARN on every stage (dev too).
|
|
167
|
+
// A deployed stage with no key refuses to start; 'none' is the explicit
|
|
168
|
+
// plaintext opt-out (sets FRIGG_ENCRYPTION_DISABLED=true).
|
|
167
169
|
encryption: {
|
|
168
|
-
fieldLevelEncryptionMethod: 'kms',
|
|
170
|
+
fieldLevelEncryptionMethod: 'kms', // 'kms' | 'aes' | 'none'
|
|
169
171
|
createResourceIfNoneFound: true
|
|
170
172
|
},
|
|
171
173
|
|