@friggframework/devtools 2.0.0--canary.686.df38e8e.0 → 2.0.0--canary.711.f8b6445.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 (61) hide show
  1. package/frigg-cli/README.md +77 -30
  2. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
  3. package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
  4. package/frigg-cli/__tests__/unit/commands/install.test.js +594 -341
  5. package/frigg-cli/build-command/index.js +1 -32
  6. package/frigg-cli/deploy-command/index.js +2 -50
  7. package/frigg-cli/doctor-command/index.js +0 -7
  8. package/frigg-cli/generate-command/index.js +1 -0
  9. package/frigg-cli/generate-iam-command.js +1 -7
  10. package/frigg-cli/index.js +9 -4
  11. package/frigg-cli/init-command/backend-first-handler.js +397 -554
  12. package/frigg-cli/init-command/deployment-modes.js +7 -0
  13. package/frigg-cli/init-command/index.js +82 -35
  14. package/frigg-cli/init-command/safe-path.js +58 -0
  15. package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
  16. package/frigg-cli/install-command/app-definition.js +174 -0
  17. package/frigg-cli/install-command/commit-changes.js +40 -8
  18. package/frigg-cli/install-command/environment-variables.js +15 -0
  19. package/frigg-cli/install-command/index.js +96 -21
  20. package/frigg-cli/install-command/install-package.js +77 -4
  21. package/frigg-cli/install-command/integration-file.js +20 -11
  22. package/frigg-cli/install-command/resolve-module.js +69 -0
  23. package/frigg-cli/install-command/template.js +102 -75
  24. package/frigg-cli/install-command/validate-package.js +36 -4
  25. package/frigg-cli/package.json +1 -1
  26. package/frigg-cli/repair-command/index.js +0 -7
  27. package/frigg-cli/start-command/index.js +0 -58
  28. package/frigg-cli/templates/backend/README.md +267 -0
  29. package/frigg-cli/templates/backend/env.example +20 -0
  30. package/frigg-cli/templates/backend/gitignore +10 -0
  31. package/frigg-cli/templates/backend/index.js +114 -0
  32. package/frigg-cli/templates/backend/infrastructure.js +20 -0
  33. package/frigg-cli/test/init-command.test.js +9 -2
  34. package/infrastructure/README.md +2 -4
  35. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
  36. package/infrastructure/__tests__/template-generation.test.js +0 -7
  37. package/infrastructure/create-frigg-infrastructure.js +0 -14
  38. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +21 -1
  39. package/infrastructure/domains/admin-scripts/admin-script-builder.js +6 -2
  40. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +30 -0
  41. package/infrastructure/domains/database/aurora-builder.js +13 -2
  42. package/infrastructure/domains/database/aurora-builder.test.js +22 -0
  43. package/infrastructure/domains/parameters/offload-utils.js +0 -1
  44. package/infrastructure/domains/security/iam-generator.js +112 -5
  45. package/infrastructure/domains/security/iam-generator.test.js +94 -0
  46. package/infrastructure/domains/shared/environment-builder.js +1 -12
  47. package/infrastructure/domains/shared/environment-builder.test.js +0 -20
  48. package/infrastructure/domains/shared/types/app-definition.js +1 -15
  49. package/infrastructure/domains/shared/utilities/base-definition-factory.js +17 -30
  50. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +22 -85
  51. package/infrastructure/infrastructure-composer.test.js +0 -7
  52. package/infrastructure/scripts/build-prisma-layer.js +5 -32
  53. package/infrastructure/scripts/build-prisma-layer.test.js +0 -35
  54. package/package.json +10 -8
  55. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -140
  56. package/frigg-cli/utils/provider-helper.js +0 -80
  57. package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +0 -64
  58. package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -335
  59. package/infrastructure/provider-build.js +0 -119
  60. package/test/npm-install-guard.js +0 -104
  61. package/test/npm-install-guard.test.js +0 -53
@@ -468,26 +468,6 @@ describe('Environment Builder', () => {
468
468
  });
469
469
  });
470
470
 
471
- describe('field-level encryption opt-out', () => {
472
- it("emits FRIGG_ENCRYPTION_DISABLED=true for fieldLevelEncryptionMethod: 'none'", () => {
473
- const result = getAppEnvironmentVars({
474
- encryption: { fieldLevelEncryptionMethod: 'none' },
475
- });
476
-
477
- expect(result.FRIGG_ENCRYPTION_DISABLED).toBe('true');
478
- });
479
-
480
- it.each([
481
- ['kms', { fieldLevelEncryptionMethod: 'kms' }],
482
- ['aes', { fieldLevelEncryptionMethod: 'aes' }],
483
- ['no encryption block', undefined],
484
- ])('does not opt out for %s', (_label, encryption) => {
485
- const result = getAppEnvironmentVars({ encryption });
486
-
487
- expect(result.FRIGG_ENCRYPTION_DISABLED).toBeUndefined();
488
- });
489
- });
490
-
491
471
  describe('buildEnvironment()', () => {
492
472
  it('should combine app vars with standard Frigg variables', () => {
493
473
  const appEnvironmentVars = {
@@ -129,7 +129,7 @@
129
129
  * @typedef {Object} AppDefinition
130
130
  * @property {string} name - Application name
131
131
  * @property {string} stage - Deployment stage (e.g., 'dev', 'production')
132
- * @property {string} provider - Deployment provider: 'aws' (serverless/Lambda) or 'netlify' (@friggframework/provider-netlify)
132
+ * @property {string} provider - Cloud provider (e.g., 'aws')
133
133
  * @property {string} region - AWS region
134
134
  *
135
135
  * @property {VpcDefinition} [vpc] - VPC configuration
@@ -144,20 +144,6 @@
144
144
  * @property {AdminConfig} [admin] - Admin configuration
145
145
  *
146
146
  * @property {Object} [environment] - Environment variables
147
- *
148
- * @property {ExtensionDefinition[]} [coreExtensions] - Core (app-level) extensions that add custom Prisma models, encrypted fields, admin routes and bootstrap hooks (not an integration's Definition.extensions, nor ADR-017's keyed appDefinition.extensions)
149
- */
150
-
151
- /**
152
- * App-level extension: custom models, encryption, admin routes and bootstrap
153
- * @typedef {Object} ExtensionDefinition
154
- * @property {string} name - Unique identifier for this extension
155
- * @property {string} [schema] - Absolute path to a .prisma schema fragment
156
- * @property {Object<string, {fields: string[]}>} [encryption] - Model name → encrypted fields mapping
157
- * @property {Object} [routes] - Express router configuration
158
- * @property {string} routes.path - Base URL path for the extension routes: /admin/<segment>..., never /api (/admin/scripts, /admin/db-migrate and /admin/queue are reserved); served by the auth function
159
- * @property {Function|Object} routes.handler - Router factory (prisma, appDefinition) → Router, or { router } object
160
- * @property {Function} [bootstrap] - Async function (prisma, appDefinition) → void, run by initializeApp()
161
147
  */
162
148
 
163
149
  /**
@@ -10,26 +10,6 @@
10
10
  const { buildEnvironment } = require('../environment-builder');
11
11
  const { nestedNodeModulesExcludes } = require('./nested-node-modules');
12
12
  const { buildLoggingProviderConfig } = require('./logging-config');
13
- const {
14
- getGatewayRoutes,
15
- } = require('@friggframework/core/management-api/route-registry');
16
-
17
- /**
18
- * HTTP API events for one function, from core's route registry (ADR-053):
19
- * the same registry mounts the Express routers and builds the OpenAPI
20
- * documents, so the three cannot drift. It also lists /api/docs and the core
21
- * extensions' admin routes (/admin/<name>, served by the auth Lambda).
22
- */
23
- function managementApiEvents(AppDefinition, functionName) {
24
- const managementApi = AppDefinition.managementApi || {};
25
- return getGatewayRoutes({
26
- v1: managementApi.v1 !== false,
27
- proxy: managementApi.proxy?.enable === true,
28
- coreExtensions: AppDefinition.coreExtensions,
29
- })
30
- .filter((route) => route.function === functionName)
31
- .map(({ method, path }) => ({ httpApi: { path, method } }));
32
- }
33
13
 
34
14
  /**
35
15
  * Create base serverless definition with core functions and resources
@@ -306,12 +286,16 @@ function createBaseDefinition(
306
286
  ...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
307
287
  skipEsbuild: true, // Handlers in node_modules don't need bundling
308
288
  package: skipEsbuildPackageConfig,
309
- // Every Management API path the auth Lambda serves (v1, v2 per
310
- // resource, the OAuth redirect) comes from core's route
311
- // registry. HTTP API has no implicit catch-all, so an unlisted
312
- // prefix 404s at the gateway before Express sees it. Guarded by
313
- // __tests__/management-api-gateway-routes.test.js.
314
- events: managementApiEvents(AppDefinition, 'auth'),
289
+ events: [
290
+ { httpApi: { path: '/api/integrations', method: 'ANY' } },
291
+ {
292
+ httpApi: {
293
+ path: '/api/integrations/{proxy+}',
294
+ method: 'ANY',
295
+ },
296
+ },
297
+ { httpApi: { path: '/api/authorize', method: 'ANY' } },
298
+ ],
315
299
  },
316
300
  user: {
317
301
  handler: 'node_modules/@friggframework/core/handlers/routers/user.handler',
@@ -328,8 +312,6 @@ function createBaseDefinition(
328
312
  events: [
329
313
  { httpApi: { path: '/health', method: 'GET' } },
330
314
  { httpApi: { path: '/health/{proxy+}', method: 'GET' } },
331
- // GET /api/meta and the OpenAPI documents: public, DB-free.
332
- ...managementApiEvents(AppDefinition, 'health'),
333
315
  ],
334
316
  },
335
317
  // Reporting is an admin operation (ADR-010): the report router runs on the admin-scripts Lambda, not as a standalone function here.
@@ -401,12 +383,18 @@ function createBaseDefinition(
401
383
  },
402
384
  },
403
385
  },
386
+ // The functions above use `httpApi` events, so osls creates
387
+ // an HTTP API (API Gateway v2, logical ID HttpApi) with only
388
+ // the `$default` stage. HTTP APIs publish `5xx`, not the REST
389
+ // API metric `5XXError`, and the ApiId dimension identifies
390
+ // this API (a Stage dimension would have to be `$default`).
391
+ // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-metrics.html
404
392
  ApiGatewayAlarm5xx: {
405
393
  Type: 'AWS::CloudWatch::Alarm',
406
394
  Properties: {
407
395
  AlarmDescription: 'API Gateway 5xx Errors',
408
396
  Namespace: 'AWS/ApiGateway',
409
- MetricName: '5XXError',
397
+ MetricName: '5xx',
410
398
  Statistic: 'Sum',
411
399
  Threshold: 0,
412
400
  ComparisonOperator: 'GreaterThanThreshold',
@@ -415,7 +403,6 @@ function createBaseDefinition(
415
403
  AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
416
404
  Dimensions: [
417
405
  { Name: 'ApiId', Value: { Ref: 'HttpApi' } },
418
- { Name: 'Stage', Value: '${self:provider.stage}' },
419
406
  ],
420
407
  },
421
408
  },
@@ -94,91 +94,7 @@ describe('Base Definition Factory', () => {
94
94
 
95
95
  expect(result.functions.auth.handler).toBe('node_modules/@friggframework/core/handlers/routers/auth.handler');
96
96
  expect(result.functions.auth.layers).toEqual([{ Ref: 'PrismaLambdaLayer' }]);
97
- expect(
98
- result.functions.auth.events.map(
99
- (e) => `${e.httpApi.method} ${e.httpApi.path}`
100
- )
101
- ).toEqual([
102
- // v1 (deprecated, ADR-053)
103
- 'ANY /api/integrations',
104
- 'ANY /api/integrations/{proxy+}',
105
- 'ANY /api/authorize',
106
- 'ANY /api/entity',
107
- 'ANY /api/entity/{proxy+}',
108
- 'ANY /api/entities/{proxy+}',
109
- // v2, per resource: never ANY /api/v2/{proxy+}, which would
110
- // shadow /api/v2/reports on the admin-scripts Lambda
111
- 'ANY /api/v2/integrations',
112
- 'ANY /api/v2/integrations/{proxy+}',
113
- 'ANY /api/v2/entities',
114
- 'ANY /api/v2/entities/{proxy+}',
115
- 'ANY /api/v2/credentials',
116
- 'ANY /api/v2/credentials/{proxy+}',
117
- 'ANY /api/v2/authorize',
118
- ]);
119
- });
120
-
121
- it('takes the Management API routes from the core route registry', () => {
122
- const { getGatewayRoutes } = require('@friggframework/core/management-api/route-registry');
123
- const result = createBaseDefinition({}, {}, {});
124
- const declared = (fn) =>
125
- result.functions[fn].events
126
- .map((e) => `${e.httpApi.method} ${e.httpApi.path}`)
127
- .filter((route) => route.includes('/api/'));
128
- const registry = (fn) =>
129
- getGatewayRoutes()
130
- .filter((r) => r.function === fn)
131
- .map((r) => `${r.method} ${r.path}`);
132
- expect(declared('auth')).toEqual(registry('auth'));
133
- expect(declared('health')).toEqual(registry('health'));
134
- });
135
-
136
- it('serves /api/meta from the DB-free health function', () => {
137
- const result = createBaseDefinition({}, {}, {});
138
- expect(
139
- result.functions.health.events.map((e) => `${e.httpApi.method} ${e.httpApi.path}`)
140
- ).toEqual([
141
- 'GET /health',
142
- 'GET /health/{proxy+}',
143
- 'GET /api/meta',
144
- 'GET /api/meta/{proxy+}',
145
- // Redirects to /api/meta/openapi/v2.json (ADR-053 docs path)
146
- 'GET /api/docs',
147
- ]);
148
- });
149
-
150
- it('routes each core extension admin path (and below) to the auth function', () => {
151
- const result = createBaseDefinition(
152
- {
153
- coreExtensions: [
154
- { name: 'db-credentials', routes: { path: '/admin/oauth-credentials' } },
155
- { name: 'no-routes' },
156
- ],
157
- },
158
- {},
159
- {}
160
- );
161
- const routes = result.functions.auth.events.map(
162
- (e) => `${e.httpApi.method} ${e.httpApi.path}`
163
- );
164
- expect(routes).toContain('ANY /admin/oauth-credentials');
165
- expect(routes).toContain('ANY /admin/oauth-credentials/{proxy+}');
166
- // Never a catch-all that would shadow /admin/scripts or /admin/db-migrate.
167
- expect(routes).not.toContain('ANY /admin/{proxy+}');
168
- // The HTTP queue route is for hosts without SQS, never AWS.
169
- expect(JSON.stringify(result.functions)).not.toContain('/admin/queue');
170
- });
171
-
172
- it('drops the v1 routes when managementApi.v1 is false, keeping the OAuth redirect', () => {
173
- const result = createBaseDefinition({ managementApi: { v1: false } }, {}, {});
174
- const routes = result.functions.auth.events.map(
175
- (e) => `${e.httpApi.method} ${e.httpApi.path}`
176
- );
177
- expect(routes).not.toContain('ANY /api/integrations');
178
- expect(routes).not.toContain('ANY /api/authorize');
179
- expect(routes).not.toContain('ANY /api/entity');
180
- expect(routes).toContain('GET /api/integrations/redirect/{appId}');
181
- expect(routes).toContain('ANY /api/v2/integrations');
97
+ expect(result.functions.auth.events).toHaveLength(3);
182
98
  });
183
99
 
184
100
  it('should NOT include legacy dbMigrate function', () => {
@@ -205,6 +121,27 @@ describe('Base Definition Factory', () => {
205
121
  expect(result.resources.Resources.ApiGatewayAlarm5xx).toBeDefined();
206
122
  });
207
123
 
124
+ it('alarms on the HTTP API 5xx metric of the API osls creates', () => {
125
+ // The Frigg functions use `httpApi` events, so osls creates an
126
+ // API Gateway v2 HTTP API (logical ID HttpApi) with only the
127
+ // `$default` stage. HTTP APIs publish `5xx` (REST APIs publish
128
+ // `5XXError`) with the ApiId dimension; a Stage dimension set to
129
+ // the deploy stage name would never match `$default`.
130
+ const result = createBaseDefinition({}, {}, {});
131
+ const usesHttpApi = Object.values(result.functions).some((fn) =>
132
+ (fn.events || []).some((event) => event.httpApi)
133
+ );
134
+ expect(usesHttpApi).toBe(true);
135
+
136
+ const alarm = result.resources.Resources.ApiGatewayAlarm5xx;
137
+ expect(alarm.Properties).toMatchObject({
138
+ Namespace: 'AWS/ApiGateway',
139
+ MetricName: '5xx',
140
+ Dimensions: [{ Name: 'ApiId', Value: { Ref: 'HttpApi' } }],
141
+ AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
142
+ });
143
+ });
144
+
208
145
  it('should include base IAM permissions', () => {
209
146
  const result = createBaseDefinition({}, {}, {});
210
147
 
@@ -2,13 +2,6 @@ const {
2
2
  composeServerlessDefinition,
3
3
  applySsmPreloadNodeOptions,
4
4
  } = require('./infrastructure-composer');
5
- // Composing must not build the real Prisma layer: that runs npm install
6
- // under packages/devtools, and two workers doing it at once once pruned the
7
- // repository's root node_modules (test/npm-install-guard.js).
8
- jest.mock('./domains/shared/utilities/prisma-layer-manager', () => ({
9
- ensurePrismaLayerExists: jest.fn(async () => {}),
10
- }));
11
-
12
5
  const {
13
6
  SSM_PRELOAD_NODE_OPTIONS,
14
7
  } = require('./domains/parameters/offload-utils');
@@ -249,36 +249,6 @@ async function createLayerStructure() {
249
249
  logSuccess(`Created ${LAYER_NODE_MODULES}`);
250
250
  }
251
251
 
252
- /**
253
- * Run `npm install --omit=dev` confined to the layer directory.
254
- *
255
- * npm resolves its project root by walking up from cwd to the nearest
256
- * package.json. If the layer's package.json is missing when npm starts (a
257
- * concurrent build cleaned the directory, as two jest workers composing at
258
- * once did), npm walked up into the enclosing workspace and ran
259
- * `install --omit=dev` there, pruning the devDependencies (jest, jest-util)
260
- * out of the repository's root node_modules. So: the package.json must exist,
261
- * and `--prefix` pins npm's root to the layer directory while
262
- * `--workspaces=false` stops it acting on an enclosing workspace.
263
- *
264
- * @param {string} layerNodejsDir - absolute path of <layer>/nodejs
265
- * @param {Object} [options]
266
- * @param {Object} [options.env]
267
- * @param {Function} [options.exec] - execSync stand-in (tests)
268
- */
269
- function runLayerInstall(layerNodejsDir, { env = process.env, exec = execSync } = {}) {
270
- const manifest = path.join(layerNodejsDir, 'package.json');
271
- if (!fs.existsSync(manifest)) {
272
- throw new Error(
273
- `Refusing to run npm install: ${manifest} does not exist (npm would install into an enclosing project)`
274
- );
275
- }
276
- exec(
277
- `npm install --omit=dev --no-package-lock --workspaces=false --prefix ${JSON.stringify(layerNodejsDir)}`,
278
- { cwd: layerNodejsDir, stdio: 'inherit', env }
279
- );
280
- }
281
-
282
252
  /**
283
253
  * Install Prisma client directly into layer (RUNTIME ONLY - NO CLI)
284
254
  *
@@ -315,7 +285,11 @@ async function installPrismaPackages() {
315
285
  PRISMA_CLI_BINARY_TARGETS: 'rhel-openssl-3.0.x',
316
286
  };
317
287
 
318
- runLayerInstall(path.join(LAYER_OUTPUT_PATH, 'nodejs'), { env });
288
+ execSync('npm install --omit=dev --no-package-lock', {
289
+ cwd: path.join(LAYER_OUTPUT_PATH, 'nodejs'),
290
+ stdio: 'inherit',
291
+ env,
292
+ });
319
293
  logSuccess('Prisma packages installed with Lambda binary target');
320
294
  } catch (error) {
321
295
  throw new Error(`Failed to install Prisma packages: ${error.message}`);
@@ -719,7 +693,6 @@ if (require.main === module) {
719
693
 
720
694
  module.exports = {
721
695
  buildPrismaLayer,
722
- runLayerInstall,
723
696
  getGeneratedClientPackages,
724
697
  getMigrationsPackages,
725
698
  getMigrationSourcePath,
@@ -168,38 +168,3 @@ describe('getMigrationDestinationPath()', () => {
168
168
  );
169
169
  });
170
170
  });
171
-
172
-
173
- describe('runLayerInstall', () => {
174
- const fs = require('fs');
175
- const os = require('os');
176
- const path = require('path');
177
- const { runLayerInstall } = require('./build-prisma-layer');
178
-
179
- it('refuses when the layer package.json is missing (npm would walk up into the workspace)', () => {
180
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'layer-'));
181
- const exec = jest.fn();
182
- try {
183
- expect(() => runLayerInstall(dir, { exec })).toThrow(/Refusing to run npm install/);
184
- expect(exec).not.toHaveBeenCalled();
185
- } finally {
186
- fs.rmSync(dir, { recursive: true, force: true });
187
- }
188
- });
189
-
190
- it('pins npm to the layer directory and off any enclosing workspace', () => {
191
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'layer-'));
192
- fs.writeFileSync(path.join(dir, 'package.json'), '{}');
193
- const exec = jest.fn();
194
- try {
195
- runLayerInstall(dir, { exec, env: { X: '1' } });
196
- const [command, options] = exec.mock.calls[0];
197
- expect(command).toContain('npm install --omit=dev');
198
- expect(command).toContain('--workspaces=false');
199
- expect(command).toContain(`--prefix ${JSON.stringify(dir)}`);
200
- expect(options).toMatchObject({ cwd: dir, env: { X: '1' } });
201
- } finally {
202
- fs.rmSync(dir, { recursive: true, force: true });
203
- }
204
- });
205
- });
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@friggframework/devtools",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.686.df38e8e.0",
4
+ "version": "2.0.0--canary.711.f8b6445.0",
5
5
  "bin": {
6
6
  "frigg": "./frigg-cli/index.js"
7
7
  },
8
8
  "files": [
9
9
  "frigg-cli/",
10
+ "frigg-cli/templates/",
10
11
  "infrastructure/",
11
12
  "migrations/",
12
13
  "management-ui/dist/",
@@ -18,6 +19,7 @@
18
19
  "@aws-sdk/client-cloudformation": "^3.705.0",
19
20
  "@aws-sdk/client-ec2": "^3.835.0",
20
21
  "@aws-sdk/client-kms": "^3.835.0",
22
+ "@aws-sdk/client-lambda": "^3.714.0",
21
23
  "@aws-sdk/client-rds": "^3.906.0",
22
24
  "@aws-sdk/client-s3": "^3.917.0",
23
25
  "@aws-sdk/client-secrets-manager": "^3.906.0",
@@ -26,9 +28,9 @@
26
28
  "@babel/eslint-parser": "^7.18.9",
27
29
  "@babel/parser": "^7.25.3",
28
30
  "@babel/traverse": "^7.25.3",
29
- "@friggframework/core": "2.0.0--canary.686.df38e8e.0",
30
- "@friggframework/schemas": "2.0.0--canary.686.df38e8e.0",
31
- "@friggframework/test": "2.0.0--canary.686.df38e8e.0",
31
+ "@friggframework/core": "2.0.0--canary.711.f8b6445.0",
32
+ "@friggframework/schemas": "2.0.0--canary.711.f8b6445.0",
33
+ "@friggframework/test": "2.0.0--canary.711.f8b6445.0",
32
34
  "@hapi/boom": "^10.0.1",
33
35
  "@inquirer/prompts": "^5.3.8",
34
36
  "axios": "^1.18.0",
@@ -56,12 +58,12 @@
56
58
  "validate-npm-package-name": "^5.0.0"
57
59
  },
58
60
  "devDependencies": {
59
- "@friggframework/eslint-config": "2.0.0--canary.686.df38e8e.0",
60
- "@friggframework/prettier-config": "2.0.0--canary.686.df38e8e.0",
61
+ "@friggframework/eslint-config": "2.0.0--canary.711.f8b6445.0",
62
+ "@friggframework/prettier-config": "2.0.0--canary.711.f8b6445.0",
61
63
  "aws-sdk-client-mock": "^4.1.0",
62
64
  "aws-sdk-client-mock-jest": "^4.1.0",
63
65
  "jest": "^30.1.3",
64
- "osls": "^3.58.0",
66
+ "osls": "^3.78.0",
65
67
  "prettier": "^2.7.1",
66
68
  "serverless-dotenv-plugin": "^6.0.0",
67
69
  "serverless-esbuild": "^1.54.3",
@@ -89,5 +91,5 @@
89
91
  "publishConfig": {
90
92
  "access": "public"
91
93
  },
92
- "gitHead": "df38e8e8ab471a23861fbdc3e35e99ddc249aef5"
94
+ "gitHead": "f8b64453af51d5a060c85bacb037b6cc9fc8943f"
93
95
  }
@@ -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 };