@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
@@ -1,117 +1,90 @@
1
- /**
2
- * Source for a new integration class (`src/integrations/<Name>Integration.js`)
3
- * that wraps one installed API module.
4
- *
5
- * It follows the current IntegrationBase contract: a static `Definition`
6
- * (name, version, display, `modules: { <key>: { definition } }`) and event
7
- * handlers registered on `this.events` in the constructor. Calls to the API
8
- * module go through `this.<key>.api.<method>()`.
9
- */
1
+ const path = require('path');
10
2
 
11
- /** Turn an arbitrary label (e.g. "Google Drive", "Monday.com") into a JS identifier. */
12
- function toIdentifier(label) {
13
- const words = String(label)
14
- .split(/[^A-Za-z0-9]+/)
15
- .filter(Boolean);
16
- let identifier = words
17
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
18
- .join('');
19
- if (!identifier) {
20
- identifier = 'Module';
21
- }
22
- if (/^[0-9]/.test(identifier)) {
23
- identifier = `Module${identifier}`;
24
- }
25
- return identifier;
26
- }
3
+ function getIntegrationTemplate(apiModuleName, backendPath, ApiClass) {
4
+ // Find the sample data method
5
+ const apiMethods = Object.getOwnPropertyNames(ApiClass.prototype);
6
+ const sampleDataMethod =
7
+ apiMethods.find(
8
+ (method) =>
9
+ method.toLowerCase().includes('search') ||
10
+ method.toLowerCase().includes('list') ||
11
+ method.toLowerCase().includes('get')
12
+ ) || 'searchDeals';
27
13
 
28
- /** camelCase key for `Definition.modules` (e.g. "google-drive" -> "googleDrive"). */
29
- function toModuleKey(moduleName) {
30
- const words = String(moduleName)
31
- .split(/[^A-Za-z0-9]+/)
32
- .filter(Boolean);
33
- if (words.length === 0) {
34
- return 'module';
35
- }
36
- const key = words
37
- .map((word, i) =>
38
- i === 0
39
- ? word.charAt(0).toLowerCase() + word.slice(1)
40
- : word.charAt(0).toUpperCase() + word.slice(1)
41
- )
42
- .join('');
43
- return /^[0-9]/.test(key) ? `module${key}` : key;
44
- }
14
+ return `const { get, IntegrationBase, Options } = require('@friggframework/core');
15
+ const { Definition: ${apiModuleName}Module, Config: defaultConfig } = require('@friggframework/api-module-${apiModuleName.toLowerCase()}');
45
16
 
46
- const quote = (value) => JSON.stringify(value === undefined ? '' : value);
17
+ class ${apiModuleName}Integration extends IntegrationBase {
18
+ static Config = {
19
+ name: defaultConfig.name || '${apiModuleName.toLowerCase()}',
20
+ version: '1.0.0',
21
+ supportedVersions: ['1.0.0'],
22
+ events: ['SEARCH_DEALS'],
23
+ };
47
24
 
48
- /**
49
- * @param {object} params
50
- * @param {string} params.className - e.g. `HubSpotIntegration`
51
- * @param {string} params.packageName - e.g. `@friggframework/api-module-hubspot`
52
- * @param {string} params.moduleName - The module's `Definition.getName()`
53
- * @param {string} params.label - Human-readable name
54
- * @param {string} [params.description]
55
- * @param {string} [params.detailsUrl]
56
- * @param {string} [params.icon]
57
- * @param {string[]} [params.categories]
58
- * @returns {string}
59
- */
60
- function getIntegrationTemplate({
61
- className,
62
- packageName,
63
- moduleName,
64
- label,
65
- description,
66
- detailsUrl,
67
- icon,
68
- categories,
69
- }) {
70
- const moduleKey = toModuleKey(moduleName);
71
- const moduleVar = `${moduleKey}Module`;
72
- const category = Array.isArray(categories) ? categories.join(', ') : '';
25
+ static Options =
26
+ new Options({
27
+ module: ${apiModuleName}Module,
28
+ integrations: [${apiModuleName}Module],
29
+ display: {
30
+ name: defaultConfig.displayName || '${apiModuleName}',
31
+ description: defaultConfig.description || 'Sales & CRM, Marketing',
32
+ category: defaultConfig.category || 'Sales & CRM, Marketing',
33
+ detailsUrl: defaultConfig.detailsUrl || 'https://www.${apiModuleName.toLowerCase()}.com',
34
+ icon: defaultConfig.icon || 'https://friggframework.org/assets/img/${apiModuleName.toLowerCase()}.jpeg',
35
+ },
36
+ hasUserConfig: true,
37
+ });
73
38
 
74
- return `const { IntegrationBase } = require('@friggframework/core');
75
- const ${moduleVar} = require(${quote(packageName)});
39
+ static modules = {
40
+ ${apiModuleName.toLowerCase()}: ${apiModuleName}Module,
41
+ }
76
42
 
77
- class ${className} extends IntegrationBase {
78
- static Definition = {
79
- name: ${quote(moduleName)},
80
- version: '1.0.0',
81
- supportedVersions: ['1.0.0'],
82
- hasUserConfig: false,
43
+ /**
44
+ * HANDLE EVENTS
45
+ */
46
+ async receiveNotification(notifier, event, object = null) {
47
+ if (event === 'SEARCH_DEALS') {
48
+ return this.target.api.searchDeals(object);
49
+ }
50
+ }
83
51
 
84
- display: {
85
- label: ${quote(label)},
86
- description: ${quote(description)},
87
- category: ${quote(category)},
88
- detailsUrl: ${quote(detailsUrl)},
89
- icon: ${quote(icon)},
90
- },
52
+ /**
53
+ * ALL CUSTOM/OPTIONAL METHODS FOR AN INTEGRATION MANAGER
54
+ */
55
+ async getSampleData() {
56
+ const res = await this.target.api.${sampleDataMethod}();
57
+ return { data: res };
58
+ }
91
59
 
92
- // The API modules this integration uses. Each key becomes
93
- // \`this.<key>\` on an integration instance, e.g.
94
- // \`this.${moduleKey}.api\`.
95
- modules: {
96
- ${moduleKey}: { definition: ${moduleVar}.Definition },
97
- },
60
+ /**
61
+ * ALL REQUIRED METHODS FOR AN INTEGRATION MANAGER
62
+ */
63
+ async onCreate(params) {
64
+ // Validate that we have all of the data we need
65
+ // Set integration status as makes sense. Default ENABLED
66
+ // TODO turn this into a validateConfig method/function
67
+ this.record.status = 'ENABLED';
68
+ await this.record.save();
69
+ return this.record;
70
+ }
98
71
 
99
- // HTTP routes, served under /api/${moduleName}-integration/...
100
- // e.g. { path: '/sample', method: 'GET', event: 'GET_SAMPLE_DATA' }
101
- routes: [],
102
- };
72
+ async onUpdate(params) {
73
+ const newConfig = get(params, 'config');
74
+ const oldConfig = this.record.config;
75
+ // Just save whatever
76
+ this.record.markModified('config');
77
+ await this.record.save();
78
+ return this.validateConfig();
79
+ }
103
80
 
104
- constructor(params) {
105
- super(params);
106
- this.events = {
107
- // Map event names to handlers, e.g.
108
- // GET_SAMPLE_DATA: { handler: this.getSampleData.bind(this) },
109
- };
81
+ async getConfigOptions() {
82
+ const options = {}
83
+ return options;
110
84
  }
111
85
  }
112
86
 
113
- module.exports = ${className};
114
- `;
87
+ module.exports = ${apiModuleName}Integration;`;
115
88
  }
116
89
 
117
- module.exports = { getIntegrationTemplate, toIdentifier, toModuleKey };
90
+ module.exports = { getIntegrationTemplate };
@@ -1,28 +1,12 @@
1
- const spawn = require('cross-spawn');
1
+ const { execSync } = require('child_process');
2
2
  const axios = require('axios');
3
3
  const { logError } = require('./logger');
4
4
  const { checkbox } = require('@inquirer/prompts');
5
5
 
6
- const API_MODULE_PREFIX = '@friggframework/api-module-';
7
-
8
6
  async function searchPackages(apiModuleName) {
9
- // Arguments are passed as an array (no shell), so the search term can
10
- // never be interpreted as a command.
11
- const result = spawn.sync(
12
- 'npm',
13
- ['search', `${API_MODULE_PREFIX}${apiModuleName}`, '--json'],
14
- { encoding: 'utf8' }
15
- );
16
- if (result.error) {
17
- throw result.error;
18
- }
19
- if (result.status !== 0) {
20
- throw new Error(`npm search failed: ${result.stderr || result.status}`);
21
- }
22
- // npm search is a full-text search; keep only Frigg API modules.
23
- return JSON.parse(result.stdout || '[]').filter(
24
- (pkg) => pkg && pkg.name && pkg.name.startsWith(API_MODULE_PREFIX)
25
- );
7
+ const searchCommand = `npm search @friggframework/api-module-${apiModuleName} --json`;
8
+ const result = execSync(searchCommand, { encoding: 'utf8' });
9
+ return JSON.parse(result);
26
10
  }
27
11
 
28
12
  async function checkPackageExists(packageName) {
@@ -74,21 +58,6 @@ const searchAndSelectPackage = async (apiModuleName) => {
74
58
  };
75
59
  });
76
60
 
77
- // Without a terminal to prompt on, take the exact match
78
- // (`frigg install hubspot` -> @friggframework/api-module-hubspot).
79
- if (!process.stdin.isTTY) {
80
- const exact = `${API_MODULE_PREFIX}${apiModuleName}`;
81
- if (filteredResults.some((pkg) => pkg.name === exact)) {
82
- return [exact];
83
- }
84
- logError(
85
- `No exact match for ${exact}, and there is no terminal to choose from: ${filteredResults
86
- .map((pkg) => pkg.name)
87
- .join(', ')}`
88
- );
89
- process.exit(1);
90
- }
91
-
92
61
  const selectedPackages = await checkbox({
93
62
  message: 'Select the packages to install:',
94
63
  choices,
@@ -99,7 +68,6 @@ const searchAndSelectPackage = async (apiModuleName) => {
99
68
  };
100
69
 
101
70
  module.exports = {
102
- API_MODULE_PREFIX,
103
71
  validatePackageExists,
104
72
  checkPackageExists,
105
73
  searchPackages,
@@ -26,7 +26,7 @@
26
26
  "lodash": "4.18.1",
27
27
  "node-cache": "^5.1.2",
28
28
  "open": "^8.4.2",
29
- "osls": "^4.4.0",
29
+ "osls": "^3.58.0",
30
30
  "semver": "^7.6.0",
31
31
  "validate-npm-package-name": "^5.0.0"
32
32
  },
@@ -55,9 +55,9 @@
55
55
  },
56
56
  "homepage": "https://github.com/friggframework/frigg#readme",
57
57
  "engines": {
58
- "node": "^22.13.0 || >=24"
58
+ "node": ">=18"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public"
62
62
  }
63
- }
63
+ }
@@ -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 };
@@ -123,19 +123,12 @@ describe('Init Command', () => {
123
123
  );
124
124
  });
125
125
 
126
- it('forwards every supported init flag to BackendFirstHandler', async () => {
127
- // The flags `frigg init` registers and initCommand forwards
128
- // (see init-command/index.js). `yes` is the non-interactive flag
129
- // (`--yes`: accept defaults, no prompts); `install: false` and
130
- // `git: false` are what `--no-install` / `--no-git` produce. The
131
- // old `frontend` option is gone: init scaffolds a backend only.
126
+ it('should pass options to BackendFirstHandler', async () => {
132
127
  const options = {
133
128
  force: true,
134
129
  verbose: true,
135
130
  mode: 'standalone',
136
- yes: true,
137
- install: false,
138
- git: false
131
+ frontend: false
139
132
  };
140
133
 
141
134
  await initCommand(mockProjectName, options);
@@ -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 };
@@ -163,9 +163,11 @@ const appDefinition = {
163
163
  enableVPCEndpoints: true // Optional: create VPC endpoints
164
164
  },
165
165
 
166
- // KMS encryption
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
 
@@ -207,26 +209,6 @@ STAGE=production
207
209
  SERVICE_NAME=my-frigg-app
208
210
  ```
209
211
 
210
- ## Packaging (osls 4)
211
-
212
- The composed definition targets osls `^4.4.0`
213
- ([ADR-050](../../../docs/architecture-decisions/050-osls-4.md)):
214
-
215
- - `frameworkVersion` is `OSLS_FRAMEWORK_VERSION` (`^4.4.0`,
216
- `domains/shared/utilities/framework-version.js`). It is the single place the version is set.
217
- - Every packaged function gets `package.patterns`, built by `toPackagePatterns({ include, exclude })`
218
- (`domains/shared/utilities/package-patterns.js`): excludes negated first, then includes. Builders
219
- keep plain include/exclude lists and pass them through the helper; never emit
220
- `package.include`/`package.exclude`. `nestedNodeModulesExcludes()` output goes through the same
221
- helper.
222
- - `useDotenv: true` is emitted only for `osls offline` (`frigg start`); otherwise the key is absent.
223
- - `custom.esbuild.exclude` is a serverless-esbuild option and stays as it is.
224
-
225
- `__tests__/package-patterns-composition.test.js` walks every function of a fully featured
226
- definition and fails if any of these rules is broken. Size budget: each function under 100 MB
227
- unzipped, function + layers under 200 MB (Lambda's hard limit is 250 MB); see
228
- [the measurements](../../../docs/reference/aws-sdk-v3-osls-migration.md#package-size-budget).
229
-
230
212
  ## Lambda Layers
231
213
 
232
214
  ### Prisma Layer
@@ -0,0 +1,168 @@
1
+ /**
2
+ * The build step that composes core extension schemas into the backend's
3
+ * installed @friggframework/core. Uses a temp backend whose node_modules holds
4
+ * a core with the real composer and a minimal PostgreSQL schema.
5
+ */
6
+ const fs = require('fs');
7
+ const os = require('os');
8
+ const path = require('path');
9
+ const { composeAppExtensionPrisma } = require('../compose-extension-prisma');
10
+ const { buildWithProvider } = require('../provider-build');
11
+
12
+ const REAL_CORE = path.dirname(
13
+ require.resolve('@friggframework/core/package.json')
14
+ );
15
+
16
+ const BASE = `datasource db {
17
+ provider = "postgresql"
18
+ url = env("DATABASE_URL")
19
+ }
20
+
21
+ model User {
22
+ id Int @id
23
+ }
24
+ `;
25
+
26
+ function makeBackend({ withCore = true } = {}) {
27
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-compose-ext-'));
28
+ const backend = path.join(dir, 'backend');
29
+ fs.mkdirSync(backend);
30
+ fs.writeFileSync(path.join(backend, 'package.json'), '{"name":"backend"}');
31
+ const extSchema = path.join(dir, 'ext.prisma');
32
+ fs.writeFileSync(
33
+ extSchema,
34
+ 'model OAuthAppCredential {\n id Int @id\n}\n'
35
+ );
36
+ let core = null;
37
+ if (withCore) {
38
+ core = path.join(backend, 'node_modules', '@friggframework', 'core');
39
+ fs.mkdirSync(path.join(core, 'prisma-postgresql'), { recursive: true });
40
+ fs.writeFileSync(
41
+ path.join(core, 'package.json'),
42
+ '{"name":"@friggframework/core"}'
43
+ );
44
+ fs.writeFileSync(
45
+ path.join(core, 'prisma-postgresql', 'schema.prisma'),
46
+ BASE
47
+ );
48
+ fs.symlinkSync(
49
+ path.join(REAL_CORE, 'extensions'),
50
+ path.join(core, 'extensions'),
51
+ 'dir'
52
+ );
53
+ fs.symlinkSync(
54
+ path.join(REAL_CORE, 'management-api'),
55
+ path.join(core, 'management-api'),
56
+ 'dir'
57
+ );
58
+ }
59
+ return { dir, backend, core, extSchema };
60
+ }
61
+
62
+ const appDefinition = (extSchema) => ({
63
+ name: 'compose-app',
64
+ provider: 'netlify',
65
+ integrations: [],
66
+ database: { postgres: { enable: true } },
67
+ coreExtensions: [{ name: 'db-credentials', schema: extSchema }],
68
+ });
69
+
70
+ describe('composeAppExtensionPrisma', () => {
71
+ const dirs = [];
72
+ afterAll(() =>
73
+ dirs.forEach((d) => fs.rmSync(d, { recursive: true, force: true }))
74
+ );
75
+
76
+ it("composes into the backend's installed core, not devtools' copy", () => {
77
+ const { dir, backend, core, extSchema } = makeBackend();
78
+ dirs.push(dir);
79
+ const generated = [];
80
+ const result = composeAppExtensionPrisma({
81
+ appDefinition: appDefinition(extSchema),
82
+ backendDir: backend,
83
+ generate: ({ corePath }) => generated.push(corePath),
84
+ log: () => {},
85
+ });
86
+ expect(result.changed).toBe(true);
87
+ expect(generated).toEqual([core]);
88
+ expect(
89
+ fs.readFileSync(
90
+ path.join(core, 'prisma-postgresql', 'schema.prisma'),
91
+ 'utf-8'
92
+ )
93
+ ).toContain('model OAuthAppCredential');
94
+ });
95
+
96
+ it('is a no-op without an installed core when no extension declares a schema', () => {
97
+ const { dir, backend } = makeBackend({ withCore: false });
98
+ dirs.push(dir);
99
+ expect(
100
+ composeAppExtensionPrisma({
101
+ appDefinition: { coreExtensions: [{ name: 'x' }] },
102
+ backendDir: backend,
103
+ })
104
+ ).toEqual({ changed: false, results: [] });
105
+ });
106
+
107
+ it('refuses to build without an installed core when an extension declares a schema', () => {
108
+ const { dir, backend, extSchema } = makeBackend({ withCore: false });
109
+ dirs.push(dir);
110
+ expect(() =>
111
+ composeAppExtensionPrisma({
112
+ appDefinition: appDefinition(extSchema),
113
+ backendDir: backend,
114
+ })
115
+ ).toThrow(
116
+ /declare Prisma schemas, but @friggframework\/core is not installed/
117
+ );
118
+ });
119
+ });
120
+
121
+ describe('buildWithProvider composes extension schemas', () => {
122
+ const plugin = {
123
+ validate: () => ({ errors: [], warnings: [] }),
124
+ generateConfig: () => '# config',
125
+ };
126
+
127
+ it('composes before writing the provider files', () => {
128
+ const { dir, backend } = makeBackend({ withCore: false });
129
+ try {
130
+ const order = [];
131
+ const def = { provider: 'netlify', integrations: [] };
132
+ buildWithProvider({
133
+ appDefinition: def,
134
+ backendDir: backend,
135
+ provider: {
136
+ ...plugin,
137
+ generateConfig: () => (order.push('config'), '# config'),
138
+ },
139
+ composePrisma: (args) =>
140
+ order.push([
141
+ 'compose',
142
+ args.appDefinition,
143
+ args.backendDir,
144
+ ]),
145
+ });
146
+ expect(order).toEqual([['compose', def, backend], 'config']);
147
+ } finally {
148
+ fs.rmSync(dir, { recursive: true, force: true });
149
+ }
150
+ });
151
+
152
+ it('does not compose when validation fails', () => {
153
+ const { dir, backend } = makeBackend({ withCore: false });
154
+ try {
155
+ const compose = jest.fn();
156
+ buildWithProvider({
157
+ appDefinition: { provider: 'netlify' },
158
+ backendDir: backend,
159
+ provider: { validate: () => ({ errors: ['bad'] }) },
160
+ composePrisma: compose,
161
+ exit: () => {},
162
+ });
163
+ expect(compose).not.toHaveBeenCalled();
164
+ } finally {
165
+ fs.rmSync(dir, { recursive: true, force: true });
166
+ }
167
+ });
168
+ });