@friggframework/devtools 2.0.0--canary.704.79d9a63.0 → 2.0.0--canary.680.daae24e.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/README.md +0 -14
- package/frigg-cli/README.md +0 -6
- package/frigg-cli/__tests__/unit/dependencies.test.js +5 -3
- package/frigg-cli/index.js +0 -3
- package/frigg-cli/package.json +3 -3
- package/infrastructure/README.md +4 -22
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +335 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +48 -56
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +7 -76
- package/infrastructure/domains/database/migration-builder.js +175 -182
- package/infrastructure/domains/database/migration-builder.test.js +5 -36
- package/infrastructure/domains/integration/integration-builder.js +61 -65
- package/infrastructure/domains/integration/integration-builder.test.js +8 -73
- package/infrastructure/domains/parameters/offload-utils.js +1 -0
- package/infrastructure/domains/shared/environment-builder.js +12 -1
- package/infrastructure/domains/shared/environment-builder.test.js +20 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +148 -86
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +87 -96
- package/infrastructure/domains/shared/utilities/logging-config.js +4 -3
- package/infrastructure/domains/shared/utilities/logging-config.test.js +2 -1
- package/infrastructure/infrastructure-composer.test.js +3 -3
- package/package.json +8 -11
- package/frigg-cli/__tests__/unit/utils/node-version.test.js +0 -66
- package/frigg-cli/utils/node-version.js +0 -51
- package/infrastructure/__tests__/package-patterns-composition.test.js +0 -153
- package/infrastructure/domains/shared/utilities/framework-version.js +0 -14
- package/infrastructure/domains/shared/utilities/framework-version.test.js +0 -27
- package/infrastructure/domains/shared/utilities/package-patterns.js +0 -35
- package/infrastructure/domains/shared/utilities/package-patterns.test.js +0 -112
package/README.md
CHANGED
|
@@ -12,20 +12,6 @@ The devtools package includes the following main components:
|
|
|
12
12
|
4. Local runner and deploy tooling
|
|
13
13
|
5. Infrastructure
|
|
14
14
|
|
|
15
|
-
## Requirements
|
|
16
|
-
|
|
17
|
-
- Node.js `^22.13.0 || >=24` on the machine that runs `frigg` (Node 23 and Node 22.0–22.12
|
|
18
|
-
are not supported by osls; the CLI exits with a message). Lambda functions run on
|
|
19
|
-
`nodejs22.x`.
|
|
20
|
-
- [osls](https://github.com/oss-serverless/osls) `^4.4.0` (installed with the CLI). Frigg
|
|
21
|
-
2.0.1 moved from osls 3 to osls 4; see
|
|
22
|
-
[ADR-050](../../docs/architecture-decisions/050-osls-4.md) and the
|
|
23
|
-
[upgrade notes](../../docs/reference/aws-sdk-v3-osls-migration.md#osls-4-frigg-201).
|
|
24
|
-
|
|
25
|
-
If your `infrastructure.js` wrapper changes the composed definition, use
|
|
26
|
-
`package.patterns` (never `package.include`/`package.exclude`), do not set
|
|
27
|
-
`useDotenv: false`, and do not pin `frameworkVersion` to 3.x. osls 4 rejects all three.
|
|
28
|
-
|
|
29
15
|
## Frigg CLI
|
|
30
16
|
|
|
31
17
|
The Frigg CLI is a command-line interface tool that helps developers manage and install API modules in their Frigg projects.
|
package/frigg-cli/README.md
CHANGED
|
@@ -6,12 +6,6 @@ The Frigg CLI provides tools for building, deploying, and managing serverless in
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
**Requirements:** Node.js `^22.13.0 || >=24`. The CLI drives
|
|
10
|
-
[osls](https://github.com/oss-serverless/osls) `^4.4.0` (Frigg 2.0.1+,
|
|
11
|
-
[ADR-050](../../../docs/architecture-decisions/050-osls-4.md)); osls refuses Node 23 and
|
|
12
|
-
Node 22.0–22.12, so the CLI checks the version first and exits with a message. Set
|
|
13
|
-
`FRIGG_SKIP_NODE_VERSION_CHECK=true` to skip the CLI check.
|
|
14
|
-
|
|
15
9
|
## Command Reference
|
|
16
10
|
|
|
17
11
|
### Core Commands
|
|
@@ -24,15 +24,17 @@ describe('frigg-cli dependencies', () => {
|
|
|
24
24
|
expect(oslsVersion).toMatch(/^[\^~]?\d+\.\d+\.\d+/);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
it('should use osls
|
|
27
|
+
it('should use osls version 3.40.1 or higher', () => {
|
|
28
28
|
const oslsVersion = packageJson.dependencies.osls;
|
|
29
29
|
|
|
30
30
|
// Extract version number (remove ^ or ~ prefix)
|
|
31
31
|
const versionNumber = oslsVersion.replace(/^[\^~]/, '');
|
|
32
32
|
const [major, minor] = versionNumber.split('.').map(Number);
|
|
33
33
|
|
|
34
|
-
expect(major).
|
|
35
|
-
|
|
34
|
+
expect(major).toBeGreaterThanOrEqual(3);
|
|
35
|
+
if (major === 3) {
|
|
36
|
+
expect(minor).toBeGreaterThanOrEqual(40);
|
|
37
|
+
}
|
|
36
38
|
});
|
|
37
39
|
});
|
|
38
40
|
|
package/frigg-cli/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// osls 4 needs Node ^22.13.0 || >=24 (ADR-050): fail early with a clear message.
|
|
4
|
-
require('./utils/node-version').enforceNodeVersion();
|
|
5
|
-
|
|
6
3
|
// Version Detection Wrapper
|
|
7
4
|
// This code runs when frigg-cli is installed globally
|
|
8
5
|
// It checks for a local installation and prefers it if newer
|
package/frigg-cli/package.json
CHANGED
|
@@ -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": "^
|
|
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": "
|
|
58
|
+
"node": ">=18"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|
package/infrastructure/README.md
CHANGED
|
@@ -163,9 +163,11 @@ const appDefinition = {
|
|
|
163
163
|
enableVPCEndpoints: true // Optional: create VPC endpoints
|
|
164
164
|
},
|
|
165
165
|
|
|
166
|
-
//
|
|
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,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Management API ↔ API Gateway route coverage
|
|
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.
|
|
12
|
+
*
|
|
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.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// Avoid AWS calls: hand the builders a fixed discovery result.
|
|
19
|
+
jest.mock('../domains/shared/resource-discovery', () => {
|
|
20
|
+
const actual = jest.requireActual('../domains/shared/resource-discovery');
|
|
21
|
+
return {
|
|
22
|
+
...actual,
|
|
23
|
+
gatherDiscoveredResources: jest.fn().mockResolvedValue({
|
|
24
|
+
defaultVpcId: 'vpc-123456',
|
|
25
|
+
vpcCidr: '172.31.0.0/16',
|
|
26
|
+
defaultSecurityGroupId: 'sg-123456',
|
|
27
|
+
privateSubnetId1: 'subnet-123456',
|
|
28
|
+
privateSubnetId2: 'subnet-789012',
|
|
29
|
+
publicSubnetId1: 'subnet-public-1',
|
|
30
|
+
publicSubnetId2: 'subnet-public-2',
|
|
31
|
+
defaultRouteTableId: 'rtb-123456',
|
|
32
|
+
defaultKmsKeyId:
|
|
33
|
+
'arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012',
|
|
34
|
+
existingNatGatewayId: 'nat-default123',
|
|
35
|
+
auroraClusterEndpoint:
|
|
36
|
+
'test-cluster.cluster-abc123.us-east-1.rds.amazonaws.com',
|
|
37
|
+
auroraPort: 5432,
|
|
38
|
+
auroraEngine: 'aurora-postgresql',
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
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.
|
|
46
|
+
jest.mock('@friggframework/core/handlers/app-definition-loader', () => ({
|
|
47
|
+
loadAppDefinition: () => ({
|
|
48
|
+
integrations: [],
|
|
49
|
+
userConfig: {},
|
|
50
|
+
managementApi: { proxy: { enable: true } },
|
|
51
|
+
}),
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
55
|
+
|
|
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
|
+
}
|
|
74
|
+
|
|
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) {
|
|
81
|
+
const previousDbType = process.env.DB_TYPE;
|
|
82
|
+
process.env.DB_TYPE = 'postgresql';
|
|
83
|
+
try {
|
|
84
|
+
return build();
|
|
85
|
+
} finally {
|
|
86
|
+
if (previousDbType === undefined) delete process.env.DB_TYPE;
|
|
87
|
+
else process.env.DB_TYPE = previousDbType;
|
|
88
|
+
}
|
|
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
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getGatewayRoutes(definition) {
|
|
110
|
+
const routes = [];
|
|
111
|
+
for (const [functionName, fn] of Object.entries(definition.functions)) {
|
|
112
|
+
for (const event of fn.events || []) {
|
|
113
|
+
if (!event.httpApi) continue;
|
|
114
|
+
routes.push({
|
|
115
|
+
functionName,
|
|
116
|
+
method: String(event.httpApi.method).toUpperCase(),
|
|
117
|
+
path: event.httpApi.path,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return routes;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const segmentsOf = (p) => p.split('/').filter(Boolean);
|
|
125
|
+
|
|
126
|
+
// Turn an Express path into a concrete request path, e.g.
|
|
127
|
+
// /api/entities/:entityId/options -> /api/entities/sample-entityId/options
|
|
128
|
+
const toConcretePath = (expressPath) =>
|
|
129
|
+
expressPath.replace(/:([A-Za-z0-9_]+)/g, 'sample-$1');
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* HTTP API path matching: literal segments match exactly, {param} matches
|
|
133
|
+
* one segment, a trailing {proxy+} greedily matches one or more segments.
|
|
134
|
+
* Returns null on no match, otherwise a specificity descriptor.
|
|
135
|
+
*/
|
|
136
|
+
function matchGatewayPath(gatewayPath, requestPath) {
|
|
137
|
+
const g = segmentsOf(gatewayPath);
|
|
138
|
+
const r = segmentsOf(requestPath);
|
|
139
|
+
let literals = 0;
|
|
140
|
+
for (let i = 0; i < g.length; i++) {
|
|
141
|
+
const seg = g[i];
|
|
142
|
+
if (/^\{[^}]+\+\}$/.test(seg)) {
|
|
143
|
+
if (i !== g.length - 1 || r.length <= i) return null;
|
|
144
|
+
return { greedy: true, literals, prefixLength: i };
|
|
145
|
+
}
|
|
146
|
+
if (i >= r.length) return null;
|
|
147
|
+
if (/^\{[^}]+\}$/.test(seg)) continue;
|
|
148
|
+
if (seg !== r[i]) return null;
|
|
149
|
+
literals++;
|
|
150
|
+
}
|
|
151
|
+
if (g.length !== r.length) return null;
|
|
152
|
+
return { greedy: false, literals, prefixLength: g.length };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Select the route API Gateway would invoke: a non-greedy match beats a
|
|
157
|
+
* greedy one, then more literal segments, then the longer greedy prefix,
|
|
158
|
+
* then an explicit method beats ANY.
|
|
159
|
+
*/
|
|
160
|
+
function selectGatewayRoute(gatewayRoutes, method, requestPath) {
|
|
161
|
+
const candidates = gatewayRoutes
|
|
162
|
+
.filter(
|
|
163
|
+
(r) => r.method === 'ANY' || method === 'ANY' || r.method === method
|
|
164
|
+
)
|
|
165
|
+
.map((r) => ({
|
|
166
|
+
route: r,
|
|
167
|
+
match: matchGatewayPath(r.path, requestPath),
|
|
168
|
+
}))
|
|
169
|
+
.filter((c) => c.match);
|
|
170
|
+
candidates.sort(
|
|
171
|
+
(a, b) =>
|
|
172
|
+
Number(a.match.greedy) - Number(b.match.greedy) ||
|
|
173
|
+
b.match.literals - a.match.literals ||
|
|
174
|
+
b.match.prefixLength - a.match.prefixLength ||
|
|
175
|
+
Number(a.route.method === 'ANY') - Number(b.route.method === 'ANY')
|
|
176
|
+
);
|
|
177
|
+
return candidates.length ? candidates[0].route : null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
describe('Management API routes are reachable through API Gateway', () => {
|
|
181
|
+
let gatewayRoutes;
|
|
182
|
+
let managementRoutes;
|
|
183
|
+
let metaRoutes;
|
|
184
|
+
const originalArgv = process.argv;
|
|
185
|
+
|
|
186
|
+
beforeAll(async () => {
|
|
187
|
+
process.argv = ['node', 'test'];
|
|
188
|
+
process.env.AWS_REGION = 'us-east-1';
|
|
189
|
+
// The builders narrate their progress; keep the test output quiet.
|
|
190
|
+
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
191
|
+
const warnSpy = jest
|
|
192
|
+
.spyOn(console, 'warn')
|
|
193
|
+
.mockImplementation(() => {});
|
|
194
|
+
try {
|
|
195
|
+
const definition = await composeServerlessDefinition({
|
|
196
|
+
name: 'route-coverage-app',
|
|
197
|
+
provider: 'aws',
|
|
198
|
+
usePrismaLambdaLayer: false,
|
|
199
|
+
database: { postgres: { enable: true } },
|
|
200
|
+
websockets: { enable: true },
|
|
201
|
+
adminScripts: [
|
|
202
|
+
class ExampleScript {
|
|
203
|
+
static Definition = { name: 'example-script' };
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
admin: { includeBuiltinReports: true },
|
|
207
|
+
integrations: [
|
|
208
|
+
{
|
|
209
|
+
Definition: {
|
|
210
|
+
name: 'acme',
|
|
211
|
+
webhooks: true,
|
|
212
|
+
extensions: {
|
|
213
|
+
inbound: {
|
|
214
|
+
extension: {
|
|
215
|
+
routes: [
|
|
216
|
+
{ path: '/events', method: 'POST' },
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
// Integration names share the /api/ namespace with the
|
|
224
|
+
// Management API; make sure they don't shadow it.
|
|
225
|
+
{ Definition: { name: 'entities' } },
|
|
226
|
+
],
|
|
227
|
+
});
|
|
228
|
+
gatewayRoutes = getGatewayRoutes(definition);
|
|
229
|
+
} finally {
|
|
230
|
+
logSpy.mockRestore();
|
|
231
|
+
warnSpy.mockRestore();
|
|
232
|
+
}
|
|
233
|
+
managementRoutes = getAuthLambdaRoutes();
|
|
234
|
+
metaRoutes = getMetaRoutes();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
afterAll(() => {
|
|
238
|
+
process.argv = originalArgv;
|
|
239
|
+
delete process.env.AWS_REGION;
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('reads the Management API routes from the live auth and health routers', () => {
|
|
243
|
+
const paths = managementRoutes.map((r) => r.path);
|
|
244
|
+
expect(paths).toEqual(
|
|
245
|
+
expect.arrayContaining([
|
|
246
|
+
'/api/integrations',
|
|
247
|
+
'/api/authorize',
|
|
248
|
+
'/api/entity',
|
|
249
|
+
'/api/entity/options/:credentialId',
|
|
250
|
+
'/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
|
+
])
|
|
258
|
+
);
|
|
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
|
+
});
|
|
281
|
+
|
|
282
|
+
it('routes every Management API route to the auth function', () => {
|
|
283
|
+
const unreachable = managementRoutes
|
|
284
|
+
.map(({ method, path: expressPath }) => {
|
|
285
|
+
const requestPath = toConcretePath(expressPath);
|
|
286
|
+
const selected = selectGatewayRoute(
|
|
287
|
+
gatewayRoutes,
|
|
288
|
+
method,
|
|
289
|
+
requestPath
|
|
290
|
+
);
|
|
291
|
+
return {
|
|
292
|
+
route: `${method} ${expressPath}`,
|
|
293
|
+
reachedBy: selected
|
|
294
|
+
? `${selected.method} ${selected.path} -> ${selected.functionName}`
|
|
295
|
+
: 'no API Gateway route',
|
|
296
|
+
ok: selected && selected.functionName === 'auth',
|
|
297
|
+
};
|
|
298
|
+
})
|
|
299
|
+
.filter((r) => !r.ok)
|
|
300
|
+
.map(({ route, reachedBy }) => `${route} (${reachedBy})`);
|
|
301
|
+
|
|
302
|
+
expect(unreachable).toEqual([]);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it.each([
|
|
306
|
+
['GET', '/api/v2/reports', 'reportRouter'],
|
|
307
|
+
['POST', '/api/v2/reports/daily/run', 'reportRouter'],
|
|
308
|
+
['GET', '/api/v2/reports/daily', 'reportRouter'],
|
|
309
|
+
['GET', '/admin/scripts/example-script', 'adminScriptRouter'],
|
|
310
|
+
['POST', '/api/acme-integration/webhooks', 'acmeWebhook'],
|
|
311
|
+
['POST', '/api/acme-integration/inbound/events', 'acme__inbound'],
|
|
312
|
+
['GET', '/api/acme-integration/custom', 'acme'],
|
|
313
|
+
['GET', '/api/entities-integration/custom', 'entities'],
|
|
314
|
+
['POST', '/user/login', 'user'],
|
|
315
|
+
['GET', '/health/ready', 'health'],
|
|
316
|
+
])('leaves %s %s on %s', (method, requestPath, functionName) => {
|
|
317
|
+
const selected = selectGatewayRoute(gatewayRoutes, method, requestPath);
|
|
318
|
+
expect(selected && selected.functionName).toBe(functionName);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('declares no method + path pair on more than one function', () => {
|
|
322
|
+
const seen = new Map();
|
|
323
|
+
const duplicates = [];
|
|
324
|
+
for (const r of gatewayRoutes) {
|
|
325
|
+
const key = `${r.method} ${r.path}`;
|
|
326
|
+
if (seen.has(key) && seen.get(key) !== r.functionName) {
|
|
327
|
+
duplicates.push(
|
|
328
|
+
`${key}: ${seen.get(key)} and ${r.functionName}`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
seen.set(key, r.functionName);
|
|
332
|
+
}
|
|
333
|
+
expect(duplicates).toEqual([]);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
|
|
17
17
|
const { isScopedEnvironmentActive } = require('../shared/function-environments');
|
|
18
18
|
const { nestedNodeModulesExcludes } = require('../shared/utilities/nested-node-modules');
|
|
19
|
-
const { toPackagePatterns } = require('../shared/utilities/package-patterns');
|
|
20
19
|
|
|
21
20
|
class AdminScriptBuilder extends InfrastructureBuilder {
|
|
22
21
|
constructor() {
|
|
@@ -142,12 +141,10 @@ class AdminScriptBuilder extends InfrastructureBuilder {
|
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
createAdminScriptQueue(result, appDefinition) {
|
|
145
|
-
// Registered under custom so the serverless plugin creates it in LocalStack offline
|
|
146
|
-
result.custom.AdminScriptQueue = '${self:service}-${self:provider.stage}-AdminScriptQueue';
|
|
147
144
|
result.resources.AdminScriptQueue = {
|
|
148
145
|
Type: 'AWS::SQS::Queue',
|
|
149
146
|
Properties: {
|
|
150
|
-
QueueName: '${self:
|
|
147
|
+
QueueName: '${self:service}-${self:provider.stage}-AdminScriptQueue',
|
|
151
148
|
MessageRetentionPeriod: 86400, // 1 day
|
|
152
149
|
VisibilityTimeout: 900, // 15 minutes (Lambda max)
|
|
153
150
|
RedrivePolicy: {
|
|
@@ -267,12 +264,10 @@ class AdminScriptBuilder extends InfrastructureBuilder {
|
|
|
267
264
|
}
|
|
268
265
|
|
|
269
266
|
createReportQueue(result, appDefinition) {
|
|
270
|
-
// Registered under custom so the serverless plugin creates it in LocalStack offline
|
|
271
|
-
result.custom.ReportQueue = '${self:service}-${self:provider.stage}-ReportQueue';
|
|
272
267
|
result.resources.ReportQueue = {
|
|
273
268
|
Type: 'AWS::SQS::Queue',
|
|
274
269
|
Properties: {
|
|
275
|
-
QueueName: '${self:
|
|
270
|
+
QueueName: '${self:service}-${self:provider.stage}-ReportQueue',
|
|
276
271
|
MessageRetentionPeriod: 86400, // 1 day
|
|
277
272
|
VisibilityTimeout: 900, // 15 minutes (Lambda max)
|
|
278
273
|
RedrivePolicy: {
|
|
@@ -398,55 +393,52 @@ class AdminScriptBuilder extends InfrastructureBuilder {
|
|
|
398
393
|
skipEsbuildPackageConfig(appDefinition, usePrismaLayer) {
|
|
399
394
|
const tlsCAFile = appDefinition?.database?.documentDB?.tlsCAFile;
|
|
400
395
|
return {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
'**/*.spec.js',
|
|
448
|
-
],
|
|
449
|
-
}),
|
|
396
|
+
include: [
|
|
397
|
+
// Handlers connect to the DB, so ship the DocumentDB CA cert.
|
|
398
|
+
...(tlsCAFile ? [tlsCAFile.replace(/^\.\//, '')] : []),
|
|
399
|
+
],
|
|
400
|
+
exclude: [
|
|
401
|
+
'node_modules/aws-sdk/**',
|
|
402
|
+
'node_modules/@aws-sdk/**',
|
|
403
|
+
...(usePrismaLayer
|
|
404
|
+
? [
|
|
405
|
+
'node_modules/@prisma/**',
|
|
406
|
+
'node_modules/.prisma/**',
|
|
407
|
+
'node_modules/prisma/**',
|
|
408
|
+
'node_modules/@friggframework/core/generated/**',
|
|
409
|
+
]
|
|
410
|
+
: []),
|
|
411
|
+
...nestedNodeModulesExcludes(appDefinition, usePrismaLayer),
|
|
412
|
+
'node_modules/@friggframework/test/**',
|
|
413
|
+
'node_modules/@friggframework/eslint-config/**',
|
|
414
|
+
'node_modules/@friggframework/prettier-config/**',
|
|
415
|
+
'node_modules/jest/**',
|
|
416
|
+
'node_modules/prettier/**',
|
|
417
|
+
'node_modules/eslint/**',
|
|
418
|
+
'node_modules/esbuild/**',
|
|
419
|
+
'node_modules/@esbuild/**',
|
|
420
|
+
'node_modules/typescript/**',
|
|
421
|
+
'node_modules/webpack/**',
|
|
422
|
+
'node_modules/osls/**',
|
|
423
|
+
'node_modules/serverless-esbuild/**',
|
|
424
|
+
'node_modules/serverless-jetpack/**',
|
|
425
|
+
'node_modules/serverless-offline/**',
|
|
426
|
+
'node_modules/serverless-offline-sqs/**',
|
|
427
|
+
'node_modules/serverless-dotenv-plugin/**',
|
|
428
|
+
'node_modules/serverless-kms-grants/**',
|
|
429
|
+
// Never deploy secrets or the lockfile.
|
|
430
|
+
'.env',
|
|
431
|
+
'.env.*',
|
|
432
|
+
'**/.env',
|
|
433
|
+
'**/.env.*',
|
|
434
|
+
'.frigg-credentials.json',
|
|
435
|
+
'package-lock.json',
|
|
436
|
+
'test/**',
|
|
437
|
+
'layers/**',
|
|
438
|
+
'coverage/**',
|
|
439
|
+
'**/*.test.js',
|
|
440
|
+
'**/*.spec.js',
|
|
441
|
+
],
|
|
450
442
|
};
|
|
451
443
|
}
|
|
452
444
|
|