@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.
- package/frigg-cli/README.md +115 -31
- package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +33 -24
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
- package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
- package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
- package/frigg-cli/build-command/index.js +6 -0
- package/frigg-cli/deploy-command/index.js +6 -0
- package/frigg-cli/generate-command/index.js +1 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +22 -5
- package/frigg-cli/init-command/backend-first-handler.js +395 -551
- package/frigg-cli/init-command/deployment-modes.js +7 -0
- package/frigg-cli/init-command/index.js +82 -35
- package/frigg-cli/init-command/safe-path.js +58 -0
- package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
- package/frigg-cli/install-command/app-definition.js +174 -0
- package/frigg-cli/install-command/commit-changes.js +40 -8
- package/frigg-cli/install-command/environment-variables.js +15 -0
- package/frigg-cli/install-command/index.js +96 -21
- package/frigg-cli/install-command/install-package.js +77 -4
- package/frigg-cli/install-command/integration-file.js +20 -11
- package/frigg-cli/install-command/resolve-module.js +69 -0
- package/frigg-cli/install-command/template.js +102 -75
- package/frigg-cli/install-command/validate-package.js +36 -4
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/start-command/index.js +4 -0
- package/frigg-cli/start-command/start-command.test.js +3 -0
- package/frigg-cli/templates/backend/README.md +267 -0
- package/frigg-cli/templates/backend/env.example +20 -0
- package/frigg-cli/templates/backend/gitignore +10 -0
- package/frigg-cli/templates/backend/index.js +114 -0
- package/frigg-cli/templates/backend/infrastructure.js +20 -0
- package/frigg-cli/test/init-command.test.js +9 -2
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +443 -0
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +262 -0
- package/frigg-cli/validate-command/checks/config.js +504 -0
- package/frigg-cli/validate-command/checks/integrations.js +274 -0
- package/frigg-cli/validate-command/format-report.js +58 -0
- package/frigg-cli/validate-command/index.js +107 -0
- package/frigg-cli/validate-command/load-app-definition.js +105 -0
- package/frigg-cli/validate-command/schema-issues.js +154 -0
- package/frigg-cli/validate-command/validate-app-definition.js +60 -0
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +40 -94
- package/infrastructure/__tests__/postgres-config.test.js +241 -835
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
- package/infrastructure/__tests__/template-generation.test.js +36 -8
- package/infrastructure/app-definition-schema-contract.test.js +629 -0
- package/infrastructure/create-frigg-infrastructure.js +4 -1
- package/infrastructure/create-frigg-infrastructure.test.js +51 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +80 -98
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +6 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +30 -0
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
- package/infrastructure/domains/networking/vpc-builder.js +18 -8
- package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
- package/infrastructure/domains/security/iam-generator.js +112 -5
- package/infrastructure/domains/security/iam-generator.test.js +94 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +35 -27
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +22 -49
- package/infrastructure/infrastructure-composer.test.js +268 -794
- package/infrastructure/scripts/build-prisma-layer.test.js +28 -7
- package/infrastructure/scripts/build-time-discovery.test.js +18 -3
- package/package.json +10 -8
- package/frigg-cli/index.test.js +0 -158
- 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
|
|
5
|
-
* the
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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
|
-
//
|
|
44
|
-
// backend; give
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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 =
|
|
234
|
-
|
|
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
|
|
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'],
|