@friggframework/devtools 2.0.0--canary.682.451c957.0 → 2.0.0--canary.666.89f6545.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 (82) hide show
  1. package/frigg-cli/README.md +115 -31
  2. package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
  3. package/frigg-cli/__tests__/unit/commands/deploy.test.js +33 -24
  4. package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
  5. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
  6. package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
  7. package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
  8. package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
  9. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
  10. package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
  11. package/frigg-cli/build-command/index.js +6 -0
  12. package/frigg-cli/deploy-command/index.js +6 -0
  13. package/frigg-cli/generate-command/index.js +1 -0
  14. package/frigg-cli/generate-iam-command.js +1 -0
  15. package/frigg-cli/index.js +22 -5
  16. package/frigg-cli/init-command/backend-first-handler.js +395 -551
  17. package/frigg-cli/init-command/deployment-modes.js +7 -0
  18. package/frigg-cli/init-command/index.js +82 -35
  19. package/frigg-cli/init-command/safe-path.js +58 -0
  20. package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
  21. package/frigg-cli/install-command/app-definition.js +174 -0
  22. package/frigg-cli/install-command/commit-changes.js +40 -8
  23. package/frigg-cli/install-command/environment-variables.js +15 -0
  24. package/frigg-cli/install-command/index.js +96 -21
  25. package/frigg-cli/install-command/install-package.js +77 -4
  26. package/frigg-cli/install-command/integration-file.js +20 -11
  27. package/frigg-cli/install-command/resolve-module.js +69 -0
  28. package/frigg-cli/install-command/template.js +102 -75
  29. package/frigg-cli/install-command/validate-package.js +36 -4
  30. package/frigg-cli/package.json +1 -1
  31. package/frigg-cli/start-command/index.js +4 -0
  32. package/frigg-cli/start-command/start-command.test.js +3 -0
  33. package/frigg-cli/templates/backend/README.md +267 -0
  34. package/frigg-cli/templates/backend/env.example +20 -0
  35. package/frigg-cli/templates/backend/gitignore +10 -0
  36. package/frigg-cli/templates/backend/index.js +114 -0
  37. package/frigg-cli/templates/backend/infrastructure.js +20 -0
  38. package/frigg-cli/test/init-command.test.js +9 -2
  39. package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
  40. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
  41. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +443 -0
  42. package/frigg-cli/validate-command/__tests__/validate-command.test.js +262 -0
  43. package/frigg-cli/validate-command/checks/config.js +504 -0
  44. package/frigg-cli/validate-command/checks/integrations.js +274 -0
  45. package/frigg-cli/validate-command/format-report.js +58 -0
  46. package/frigg-cli/validate-command/index.js +107 -0
  47. package/frigg-cli/validate-command/load-app-definition.js +105 -0
  48. package/frigg-cli/validate-command/schema-issues.js +154 -0
  49. package/frigg-cli/validate-command/validate-app-definition.js +60 -0
  50. package/infrastructure/__tests__/management-api-gateway-routes.test.js +40 -94
  51. package/infrastructure/__tests__/postgres-config.test.js +241 -835
  52. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
  53. package/infrastructure/__tests__/template-generation.test.js +36 -8
  54. package/infrastructure/app-definition-schema-contract.test.js +629 -0
  55. package/infrastructure/create-frigg-infrastructure.js +4 -1
  56. package/infrastructure/create-frigg-infrastructure.test.js +51 -0
  57. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +80 -98
  58. package/infrastructure/domains/admin-scripts/admin-script-builder.js +6 -2
  59. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +30 -0
  60. package/infrastructure/domains/database/aurora-builder.js +13 -2
  61. package/infrastructure/domains/database/aurora-builder.test.js +22 -0
  62. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
  63. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
  64. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
  65. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
  66. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
  67. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
  68. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
  69. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
  70. package/infrastructure/domains/networking/vpc-builder.js +18 -8
  71. package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
  72. package/infrastructure/domains/security/iam-generator.js +112 -5
  73. package/infrastructure/domains/security/iam-generator.test.js +94 -0
  74. package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
  75. package/infrastructure/domains/shared/utilities/base-definition-factory.js +35 -27
  76. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +22 -49
  77. package/infrastructure/infrastructure-composer.test.js +268 -794
  78. package/infrastructure/scripts/build-prisma-layer.test.js +28 -7
  79. package/infrastructure/scripts/build-time-discovery.test.js +18 -3
  80. package/package.json +10 -8
  81. package/frigg-cli/index.test.js +0 -158
  82. package/infrastructure/integration.test.js +0 -381
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Validate an app definition: the JSON Schema (keys, types, enums) plus the
3
+ * semantic checks the schema cannot express (ADR-051). Pure: no I/O.
4
+ */
5
+
6
+ const {
7
+ validateAppDefinition,
8
+ applyAppDefinitionDefaults,
9
+ getSchema,
10
+ } = require('@friggframework/schemas');
11
+ const { schemaErrorsToIssues } = require('./schema-issues');
12
+ const { checkIntegrations } = require('./checks/integrations');
13
+ const { checkConfig } = require('./checks/config');
14
+
15
+ /**
16
+ * @param {object} params
17
+ * @param {object} params.definition the `Definition` exported by index.js
18
+ * @param {string} [params.stage] the stage being built or deployed
19
+ * @param {object} [params.env] environment variables (default process.env)
20
+ * @returns {{ errors: object[], warnings: object[] }}
21
+ */
22
+ function validateDefinition({ definition, stage, env = process.env }) {
23
+ const schemaResult = validateAppDefinition(definition);
24
+ // Integration entries are classes: checkIntegrations reports them more
25
+ // precisely than the schema's view of them can.
26
+ const issues = schemaErrorsToIssues(
27
+ schemaResult.errors,
28
+ getSchema('app-definition')
29
+ ).filter((issue) => !issue.pointer.startsWith('/integrations/'));
30
+
31
+ let semantic = [];
32
+ if (definition && typeof definition === 'object') {
33
+ semantic = [
34
+ ...checkIntegrations(definition),
35
+ ...checkConfig({
36
+ definition: applyAppDefinitionDefaults(definition),
37
+ raw: definition,
38
+ stage,
39
+ env,
40
+ }),
41
+ ];
42
+ }
43
+
44
+ // One issue per pointer and code; the schema's wins.
45
+ const seen = new Set(issues.map((i) => `${i.code}:${i.pointer}`));
46
+ for (const issue of semantic) {
47
+ const key = `${issue.code}:${issue.pointer}`;
48
+ if (!seen.has(key)) {
49
+ seen.add(key);
50
+ issues.push(issue);
51
+ }
52
+ }
53
+
54
+ return {
55
+ errors: issues.filter((i) => i.severity === 'error'),
56
+ warnings: issues.filter((i) => i.severity !== 'error'),
57
+ };
58
+ }
59
+
60
+ module.exports = { validateDefinition };
@@ -1,18 +1,16 @@
1
1
  /**
2
2
  * Management API ↔ API Gateway route coverage
3
3
  *
4
- * The Management API (ADR-053) is served by the `auth` Lambda (v1, v2 and
5
- * the OAuth redirect) and, for /api/meta, by the DB-free `health` Lambda.
6
- * API Gateway HTTP APIs have no implicit catch-all: a request whose path
7
- * matches no declared route gets a gateway 404 and never reaches Express.
8
- * So every route those routers register must be covered by an httpApi event
9
- * on the right function, and no more-specific route on another function may
10
- * shadow it. Both the routers and the gateway routes come from core's route
11
- * registry; this test proves the outcome end to end.
4
+ * The Management API is an Express app (core's createIntegrationRouter)
5
+ * served by the `auth` Lambda. API Gateway HTTP APIs have no implicit
6
+ * catch-all: a request whose path matches no declared route gets a gateway
7
+ * 404 and never reaches Express. So every route the integration router
8
+ * registers must be covered by an httpApi event on the `auth` function, and
9
+ * no more-specific route on another function may shadow it.
12
10
  *
13
- * The Express routes are read from the live routers (not a hard-coded
14
- * list), so a route added to core later fails this test until the gateway
15
- * routes follow.
11
+ * The Express routes are read from the live router (not a hard-coded list),
12
+ * so a route added to core later fails this test until the gateway routes
13
+ * are updated alongside it.
16
14
  */
17
15
 
18
16
  // Avoid AWS calls: hand the builders a fixed discovery result.
@@ -40,70 +38,45 @@ jest.mock('../domains/shared/resource-discovery', () => {
40
38
  };
41
39
  });
42
40
 
43
- // The Management API routers load the app definition from the consuming
44
- // backend; give them one so they can be built in isolation. The entity proxy
45
- // is enabled so its route is checked too.
41
+ // createIntegrationRouter loads the app definition from the consuming
42
+ // backend; give it an empty one so the router can be built in isolation.
46
43
  jest.mock('@friggframework/core/handlers/app-definition-loader', () => ({
47
- loadAppDefinition: () => ({
48
- integrations: [],
49
- userConfig: {},
50
- managementApi: { proxy: { enable: true } },
51
- }),
44
+ loadAppDefinition: () => ({ integrations: [], userConfig: {} }),
52
45
  }));
53
46
 
54
47
  const { composeServerlessDefinition } = require('../infrastructure-composer');
55
48
 
56
- /** Routes registered on an Express router, including nested routers. */
57
- function collectRoutes(router, routes = new Map()) {
58
- const stack = (router._router || router).stack || [];
59
- for (const layer of stack) {
60
- if (layer.route) {
61
- for (const method of Object.keys(layer.route.methods)) {
62
- const route = {
63
- method: method === '_all' ? 'ANY' : method.toUpperCase(),
64
- path: layer.route.path,
65
- };
66
- routes.set(`${route.method} ${route.path}`, route);
67
- }
68
- } else if (layer.handle && Array.isArray(layer.handle.stack)) {
69
- collectRoutes(layer.handle, routes);
70
- }
71
- }
72
- return routes;
73
- }
49
+ // Routes the auth Lambda's handler (core/handlers/routers/auth.js) adds on
50
+ // top of createIntegrationRouter().
51
+ const AUTH_HANDLER_EXTRA_ROUTES = [
52
+ { method: 'GET', path: '/api/integrations/redirect/:appId' },
53
+ ];
74
54
 
75
- /**
76
- * Builds a core router with DB_TYPE set: the repository factories pick an
77
- * adapter from it (or the backend's app definition, which doesn't exist
78
- * here). Nothing connects.
79
- */
80
- function withDbType(build) {
55
+ function getIntegrationRouterRoutes() {
56
+ const { createIntegrationRouter } = require('@friggframework/core');
57
+ // The repository factories pick an adapter from DB_TYPE (or the backend's
58
+ // app definition, which doesn't exist here). Nothing connects.
81
59
  const previousDbType = process.env.DB_TYPE;
82
60
  process.env.DB_TYPE = 'postgresql';
61
+ let app;
83
62
  try {
84
- return build();
63
+ app = createIntegrationRouter();
85
64
  } finally {
86
65
  if (previousDbType === undefined) delete process.env.DB_TYPE;
87
66
  else process.env.DB_TYPE = previousDbType;
88
67
  }
89
- }
90
-
91
- /** Every route the auth Lambda's router (core/handlers/routers/auth.js) serves. */
92
- function getAuthLambdaRoutes() {
93
- const { router } = withDbType(() =>
94
- require('@friggframework/core/handlers/routers/auth')
95
- );
96
- return [...collectRoutes(router).values()];
97
- }
98
-
99
- /** Every route the health Lambda serves under /api/meta. */
100
- function getMetaRoutes() {
101
- const { router } = withDbType(() =>
102
- require('@friggframework/core/handlers/routers/health')
103
- );
104
- return [...collectRoutes(router).values()].filter((r) =>
105
- r.path.startsWith('/api/meta')
106
- );
68
+ const stack = (app._router || app.router).stack;
69
+ const routes = [];
70
+ for (const layer of stack) {
71
+ if (!layer.route) continue;
72
+ for (const method of Object.keys(layer.route.methods)) {
73
+ routes.push({
74
+ method: method === '_all' ? 'ANY' : method.toUpperCase(),
75
+ path: layer.route.path,
76
+ });
77
+ }
78
+ }
79
+ return routes;
107
80
  }
108
81
 
109
82
  function getGatewayRoutes(definition) {
@@ -180,7 +153,6 @@ function selectGatewayRoute(gatewayRoutes, method, requestPath) {
180
153
  describe('Management API routes are reachable through API Gateway', () => {
181
154
  let gatewayRoutes;
182
155
  let managementRoutes;
183
- let metaRoutes;
184
156
  const originalArgv = process.argv;
185
157
 
186
158
  beforeAll(async () => {
@@ -230,8 +202,10 @@ describe('Management API routes are reachable through API Gateway', () => {
230
202
  logSpy.mockRestore();
231
203
  warnSpy.mockRestore();
232
204
  }
233
- managementRoutes = getAuthLambdaRoutes();
234
- metaRoutes = getMetaRoutes();
205
+ managementRoutes = [
206
+ ...getIntegrationRouterRoutes(),
207
+ ...AUTH_HANDLER_EXTRA_ROUTES,
208
+ ];
235
209
  });
236
210
 
237
211
  afterAll(() => {
@@ -239,7 +213,7 @@ describe('Management API routes are reachable through API Gateway', () => {
239
213
  delete process.env.AWS_REGION;
240
214
  });
241
215
 
242
- it('reads the Management API routes from the live auth and health routers', () => {
216
+ it('reads the Management API routes from the core integration router', () => {
243
217
  const paths = managementRoutes.map((r) => r.path);
244
218
  expect(paths).toEqual(
245
219
  expect.arrayContaining([
@@ -248,35 +222,8 @@ describe('Management API routes are reachable through API Gateway', () => {
248
222
  '/api/entity',
249
223
  '/api/entity/options/:credentialId',
250
224
  '/api/entities/:entityId',
251
- '/api/integrations/redirect/:appId',
252
- '/api/v2/integrations',
253
- '/api/v2/entities/types/:entityType/requirements',
254
- '/api/v2/entities/:entityId/proxy',
255
- '/api/v2/credentials/:credentialId/reauthorize',
256
- '/api/v2/authorize',
257
225
  ])
258
226
  );
259
- expect(metaRoutes.map((r) => r.path)).toEqual(
260
- expect.arrayContaining(['/api/meta', '/api/meta/openapi/v2.json'])
261
- );
262
- });
263
-
264
- it('routes /api/meta to the DB-free health function', () => {
265
- const unreachable = metaRoutes
266
- .map(({ method, path: requestPath }) => {
267
- const selected = selectGatewayRoute(gatewayRoutes, method, requestPath);
268
- return { route: `${method} ${requestPath}`, ok: selected?.functionName === 'health' };
269
- })
270
- .filter((r) => !r.ok)
271
- .map((r) => r.route);
272
- expect(unreachable).toEqual([]);
273
- });
274
-
275
- it('declares no /api/v2 catch-all', () => {
276
- expect(
277
- gatewayRoutes.filter((r) => r.path === '/api/v2/{proxy+}' || r.path === '/api/v2')
278
- ).toEqual([]);
279
- expect(selectGatewayRoute(gatewayRoutes, 'PATCH', '/api/v2/reports/daily')).toBeNull();
280
227
  });
281
228
 
282
229
  it('routes every Management API route to the auth function', () => {
@@ -305,7 +252,6 @@ describe('Management API routes are reachable through API Gateway', () => {
305
252
  it.each([
306
253
  ['GET', '/api/v2/reports', 'reportRouter'],
307
254
  ['POST', '/api/v2/reports/daily/run', 'reportRouter'],
308
- ['GET', '/api/v2/reports/daily', 'reportRouter'],
309
255
  ['GET', '/admin/scripts/example-script', 'adminScriptRouter'],
310
256
  ['POST', '/api/acme-integration/webhooks', 'acmeWebhook'],
311
257
  ['POST', '/api/acme-integration/inbound/events', 'acme__inbound'],