@friggframework/devtools 2.0.0--canary.704.6a606c3.0 → 2.0.0--canary.707.2702ff3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +0 -14
  2. package/frigg-cli/README.md +30 -83
  3. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
  4. package/frigg-cli/__tests__/unit/commands/install.test.js +341 -594
  5. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +140 -0
  6. package/frigg-cli/__tests__/unit/dependencies.test.js +5 -3
  7. package/frigg-cli/build-command/index.js +32 -1
  8. package/frigg-cli/db-setup-command/index.js +25 -0
  9. package/frigg-cli/deploy-command/index.js +50 -2
  10. package/frigg-cli/doctor-command/index.js +7 -0
  11. package/frigg-cli/generate-command/index.js +0 -1
  12. package/frigg-cli/generate-iam-command.js +7 -1
  13. package/frigg-cli/index.js +4 -12
  14. package/frigg-cli/init-command/backend-first-handler.js +554 -397
  15. package/frigg-cli/init-command/index.js +35 -82
  16. package/frigg-cli/install-command/commit-changes.js +8 -40
  17. package/frigg-cli/install-command/environment-variables.js +0 -15
  18. package/frigg-cli/install-command/index.js +21 -96
  19. package/frigg-cli/install-command/install-package.js +4 -77
  20. package/frigg-cli/install-command/integration-file.js +11 -20
  21. package/frigg-cli/install-command/template.js +75 -102
  22. package/frigg-cli/install-command/validate-package.js +4 -36
  23. package/frigg-cli/package.json +3 -3
  24. package/frigg-cli/repair-command/index.js +7 -0
  25. package/frigg-cli/start-command/index.js +58 -0
  26. package/frigg-cli/test/init-command.test.js +2 -9
  27. package/frigg-cli/utils/provider-helper.js +80 -0
  28. package/infrastructure/README.md +4 -22
  29. package/infrastructure/__tests__/compose-extension-prisma.test.js +168 -0
  30. package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +64 -0
  31. package/infrastructure/__tests__/management-api-gateway-routes.test.js +335 -0
  32. package/infrastructure/__tests__/template-generation.test.js +7 -0
  33. package/infrastructure/compose-extension-prisma.js +73 -0
  34. package/infrastructure/create-frigg-infrastructure.js +14 -0
  35. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +1 -21
  36. package/infrastructure/domains/admin-scripts/admin-script-builder.js +48 -56
  37. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +7 -76
  38. package/infrastructure/domains/database/aurora-builder.js +2 -13
  39. package/infrastructure/domains/database/aurora-builder.test.js +0 -22
  40. package/infrastructure/domains/database/migration-builder.js +175 -182
  41. package/infrastructure/domains/database/migration-builder.test.js +5 -36
  42. package/infrastructure/domains/integration/integration-builder.js +61 -65
  43. package/infrastructure/domains/integration/integration-builder.test.js +8 -73
  44. package/infrastructure/domains/parameters/offload-utils.js +1 -0
  45. package/infrastructure/domains/security/iam-generator.js +5 -112
  46. package/infrastructure/domains/security/iam-generator.test.js +0 -94
  47. package/infrastructure/domains/shared/environment-builder.js +12 -1
  48. package/infrastructure/domains/shared/environment-builder.test.js +20 -0
  49. package/infrastructure/domains/shared/types/app-definition.js +15 -1
  50. package/infrastructure/domains/shared/utilities/base-definition-factory.js +152 -93
  51. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +111 -117
  52. package/infrastructure/domains/shared/utilities/logging-config.js +4 -3
  53. package/infrastructure/domains/shared/utilities/logging-config.test.js +2 -1
  54. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +10 -0
  55. package/infrastructure/infrastructure-composer.js +13 -1
  56. package/infrastructure/infrastructure-composer.test.js +10 -3
  57. package/infrastructure/provider-build.js +126 -0
  58. package/infrastructure/scripts/build-prisma-layer.js +32 -5
  59. package/infrastructure/scripts/build-prisma-layer.test.js +35 -0
  60. package/package.json +8 -13
  61. package/test/npm-install-guard.js +104 -0
  62. package/test/npm-install-guard.test.js +53 -0
  63. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
  64. package/frigg-cli/__tests__/unit/utils/node-version.test.js +0 -66
  65. package/frigg-cli/init-command/deployment-modes.js +0 -7
  66. package/frigg-cli/init-command/safe-path.js +0 -58
  67. package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
  68. package/frigg-cli/install-command/app-definition.js +0 -174
  69. package/frigg-cli/install-command/resolve-module.js +0 -69
  70. package/frigg-cli/templates/backend/README.md +0 -267
  71. package/frigg-cli/templates/backend/env.example +0 -20
  72. package/frigg-cli/templates/backend/gitignore +0 -10
  73. package/frigg-cli/templates/backend/index.js +0 -114
  74. package/frigg-cli/templates/backend/infrastructure.js +0 -20
  75. package/frigg-cli/utils/node-version.js +0 -51
  76. package/infrastructure/__tests__/package-patterns-composition.test.js +0 -153
  77. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
  78. package/infrastructure/domains/shared/utilities/framework-version.js +0 -14
  79. package/infrastructure/domains/shared/utilities/framework-version.test.js +0 -27
  80. package/infrastructure/domains/shared/utilities/package-patterns.js +0 -35
  81. package/infrastructure/domains/shared/utilities/package-patterns.test.js +0 -112
@@ -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
+ });
@@ -24,15 +24,17 @@ describe('frigg-cli dependencies', () => {
24
24
  expect(oslsVersion).toMatch(/^[\^~]?\d+\.\d+\.\d+/);
25
25
  });
26
26
 
27
- it('should use osls 4.4.0 or higher within major 4 (ADR-050)', () => {
27
+ it('should use osls version 3.40.1 or higher', () => {
28
28
  const oslsVersion = packageJson.dependencies.osls;
29
29
 
30
30
  // Extract version number (remove ^ or ~ prefix)
31
31
  const versionNumber = oslsVersion.replace(/^[\^~]/, '');
32
32
  const [major, minor] = versionNumber.split('.').map(Number);
33
33
 
34
- expect(major).toBe(4);
35
- expect(minor).toBeGreaterThanOrEqual(4);
34
+ expect(major).toBeGreaterThanOrEqual(3);
35
+ if (major === 3) {
36
+ expect(minor).toBeGreaterThanOrEqual(40);
37
+ }
36
38
  });
37
39
  });
38
40
 
@@ -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
 
@@ -310,9 +310,16 @@ async function pushOffloadedParametersOrAbort(appDefinition, options) {
310
310
  }
311
311
 
312
312
  async function deployCommand(options) {
313
- console.log('Deploying the serverless application...');
314
-
315
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...');
316
323
  const environment = validateAndBuildEnvironment(appDefinition, options);
317
324
 
318
325
  await pushOffloadedParametersOrAbort(appDefinition, options);
@@ -346,4 +353,45 @@ async function deployCommand(options) {
346
353
  }
347
354
  }
348
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
+
349
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';
@@ -118,7 +118,6 @@ async function generateCommand(options = {}) {
118
118
  if (options.format === 'cloudformation') {
119
119
  template = await generateCloudFormationTemplate({
120
120
  appName,
121
- serviceName: appDefinition.name || 'create-frigg-app',
122
121
  features,
123
122
  userPrefix: options.user || 'frigg-deployment-user',
124
123
  stackName: options.stackName || 'frigg-deployment-iam',
@@ -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
@@ -62,7 +69,6 @@ async function generateIamCommand(options = {}) {
62
69
  // Use the summary already extracted above (line 44)
63
70
  const cloudFormationYaml = generateIAMCloudFormation({
64
71
  appName: summary.appName,
65
- serviceName: summary.serviceName,
66
72
  features: summary.features,
67
73
  userPrefix: deploymentUserName,
68
74
  stackName,
@@ -1,8 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // osls 4 needs Node ^22.13.0 || >=24 (ADR-050): fail early with a clear message.
4
- require('./utils/node-version').enforceNodeVersion();
5
-
6
3
  // Version Detection Wrapper
7
4
  // This code runs when frigg-cli is installed globally
8
5
  // It checks for a local installation and prefers it if newer
@@ -94,16 +91,11 @@ const { ssmPushCommand } = require('./ssm-command');
94
91
  const program = new Command();
95
92
 
96
93
  program
97
- .command('init [projectName]')
94
+ .command('init [templateName]')
98
95
  .description('Initialize a new Frigg application')
99
- .option('-n, --name <name>', 'project name (alternative to the positional argument)')
100
- .option('-m, --mode <mode>', 'deployment mode: standalone or embedded')
101
- .option('-y, --yes', 'accept the default for every prompt (implied when stdin is not a TTY)')
102
- .option('--no-install', 'skip installing dependencies')
103
- .option('--no-git', 'skip initializing a git repository')
104
- .option('-f, --force', 'scaffold into a non-empty directory and overwrite README.md')
105
- .option('-v, --verbose', 'enable verbose output')
106
- .option('-t, --template <template>', 'legacy template (no longer supported)')
96
+ .option('-t, --template <template>', 'template to use', 'backend-only')
97
+ .option('-n, --name <name>', 'project name')
98
+ .option('-d, --directory <directory>', 'target directory')
107
99
  .action(initCommand);
108
100
 
109
101
  program