@friggframework/devtools 2.0.0--canary.686.20eda6e.0 → 2.0.0--canary.710.9045bbc.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 (80) hide show
  1. package/frigg-cli/README.md +77 -30
  2. package/frigg-cli/__tests__/unit/commands/deploy.test.js +30 -24
  3. package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
  4. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
  5. package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
  6. package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
  7. package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
  8. package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
  9. package/frigg-cli/build-command/index.js +1 -32
  10. package/frigg-cli/deploy-command/index.js +2 -50
  11. package/frigg-cli/doctor-command/index.js +0 -7
  12. package/frigg-cli/generate-command/index.js +1 -0
  13. package/frigg-cli/generate-iam-command.js +1 -7
  14. package/frigg-cli/index.js +9 -4
  15. package/frigg-cli/init-command/backend-first-handler.js +397 -554
  16. package/frigg-cli/init-command/deployment-modes.js +7 -0
  17. package/frigg-cli/init-command/index.js +82 -35
  18. package/frigg-cli/init-command/safe-path.js +58 -0
  19. package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
  20. package/frigg-cli/install-command/app-definition.js +174 -0
  21. package/frigg-cli/install-command/commit-changes.js +40 -8
  22. package/frigg-cli/install-command/environment-variables.js +15 -0
  23. package/frigg-cli/install-command/index.js +96 -21
  24. package/frigg-cli/install-command/install-package.js +77 -4
  25. package/frigg-cli/install-command/integration-file.js +20 -11
  26. package/frigg-cli/install-command/resolve-module.js +69 -0
  27. package/frigg-cli/install-command/template.js +102 -75
  28. package/frigg-cli/install-command/validate-package.js +36 -4
  29. package/frigg-cli/package.json +1 -1
  30. package/frigg-cli/repair-command/index.js +0 -7
  31. package/frigg-cli/start-command/index.js +0 -58
  32. package/frigg-cli/templates/backend/README.md +267 -0
  33. package/frigg-cli/templates/backend/env.example +20 -0
  34. package/frigg-cli/templates/backend/gitignore +10 -0
  35. package/frigg-cli/templates/backend/index.js +114 -0
  36. package/frigg-cli/templates/backend/infrastructure.js +20 -0
  37. package/frigg-cli/test/init-command.test.js +9 -2
  38. package/infrastructure/README.md +2 -4
  39. package/infrastructure/__tests__/postgres-config.test.js +241 -835
  40. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
  41. package/infrastructure/__tests__/template-generation.test.js +33 -12
  42. package/infrastructure/create-frigg-infrastructure.js +0 -14
  43. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +21 -1
  44. package/infrastructure/domains/admin-scripts/admin-script-builder.js +6 -2
  45. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +30 -0
  46. package/infrastructure/domains/database/aurora-builder.js +13 -2
  47. package/infrastructure/domains/database/aurora-builder.test.js +22 -0
  48. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
  49. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
  50. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
  51. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
  52. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
  53. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
  54. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
  55. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
  56. package/infrastructure/domains/networking/vpc-builder.js +18 -8
  57. package/infrastructure/domains/networking/vpc-builder.test.js +32 -13
  58. package/infrastructure/domains/parameters/offload-utils.js +0 -1
  59. package/infrastructure/domains/security/iam-generator.js +112 -5
  60. package/infrastructure/domains/security/iam-generator.test.js +94 -0
  61. package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
  62. package/infrastructure/domains/shared/environment-builder.js +1 -12
  63. package/infrastructure/domains/shared/environment-builder.test.js +0 -20
  64. package/infrastructure/domains/shared/types/app-definition.js +1 -15
  65. package/infrastructure/domains/shared/utilities/base-definition-factory.js +17 -30
  66. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +22 -85
  67. package/infrastructure/infrastructure-composer.test.js +268 -801
  68. package/infrastructure/scripts/build-prisma-layer.js +5 -32
  69. package/infrastructure/scripts/build-prisma-layer.test.js +28 -42
  70. package/infrastructure/scripts/build-time-discovery.test.js +18 -3
  71. package/package.json +10 -8
  72. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -140
  73. package/frigg-cli/index.test.js +0 -158
  74. package/frigg-cli/utils/provider-helper.js +0 -80
  75. package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +0 -64
  76. package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -335
  77. package/infrastructure/integration.test.js +0 -381
  78. package/infrastructure/provider-build.js +0 -119
  79. package/test/npm-install-guard.js +0 -104
  80. package/test/npm-install-guard.test.js +0 -53
@@ -72,16 +72,6 @@ function addLoggingEnv(appDefinition, envVars) {
72
72
  envVars.FRIGG_LOG_LEVEL = normalized;
73
73
  }
74
74
 
75
- // Field-level encryption fails closed in a deployed stage with no key (core's
76
- // encryption-config.js). `fieldLevelEncryptionMethod: 'none'` is the explicit,
77
- // documented way to run a stage in plaintext; core logs a warning on every
78
- // cold start while it is set.
79
- function addEncryptionEnv(appDefinition, envVars) {
80
- if (appDefinition?.encryption?.fieldLevelEncryptionMethod === 'none') {
81
- envVars.FRIGG_ENCRYPTION_DISABLED = 'true';
82
- }
83
- }
84
-
85
75
  /**
86
76
  * Get environment variables from AppDefinition
87
77
  *
@@ -159,7 +149,6 @@ function getAppEnvironmentVars(appDefinition) {
159
149
  }
160
150
 
161
151
  addLoggingEnv(appDefinition, envVars);
162
- addEncryptionEnv(appDefinition, envVars);
163
152
 
164
153
  if (envKeys.length > 0) {
165
154
  console.log(
@@ -198,7 +187,7 @@ function getAppEnvironmentVars(appDefinition) {
198
187
  function buildEnvironment(appEnvironmentVars, discoveredResources) {
199
188
  const environment = {
200
189
  ...appEnvironmentVars,
201
- STAGE: '${self:provider.stage}', // Read by core: e.g. the local-only encryption bypass
190
+ STAGE: '${self:provider.stage}', // Used by encryption bypass logic
202
191
  FRIGG_STACK: '${self:service}',
203
192
  FRIGG_STAGE: '${self:provider.stage}',
204
193
  FRIGG_REGION: '${self:provider.region}',
@@ -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