@friggframework/devtools 2.0.0--canary.657.f16d20b.0 → 2.0.0--canary.737.83b4e17.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/README.md +32 -5
- package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +39 -0
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +284 -0
- package/infrastructure/__tests__/postgres-config.test.js +245 -836
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +151 -0
- package/infrastructure/__tests__/scoped-environment.test.js +3 -0
- package/infrastructure/__tests__/ssm-preload-node-options.test.js +3 -0
- package/infrastructure/__tests__/template-generation.test.js +39 -8
- package/infrastructure/app-definition-schema-contract.test.js +634 -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 +8 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +52 -6
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- package/infrastructure/domains/database/migration-builder.js +21 -2
- package/infrastructure/domains/database/migration-builder.test.js +61 -6
- package/infrastructure/domains/database/migration-engines.js +93 -0
- package/infrastructure/domains/database/migration-engines.test.js +142 -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/integration/integration-builder.js +2 -0
- package/infrastructure/domains/integration/integration-builder.test.js +22 -39
- package/infrastructure/domains/networking/vpc-builder.js +18 -8
- package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
- package/infrastructure/domains/scheduler/scheduler-builder.js +2 -19
- package/infrastructure/domains/scheduler/scheduler-builder.test.js +0 -99
- 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/environment-builder.js +31 -5
- package/infrastructure/domains/shared/environment-builder.test.js +93 -7
- package/infrastructure/domains/shared/lambda-architectures.js +113 -0
- package/infrastructure/domains/shared/lambda-architectures.test.js +164 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +39 -4
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +85 -17
- package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
- package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +92 -12
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +158 -6
- package/infrastructure/infrastructure-composer.js +12 -1
- package/infrastructure/infrastructure-composer.test.js +339 -794
- package/infrastructure/scripts/build-prisma-layer.js +136 -50
- package/infrastructure/scripts/build-prisma-layer.test.js +128 -7
- package/infrastructure/scripts/build-time-discovery.test.js +18 -3
- package/package.json +12 -10
- package/frigg-cli/index.test.js +0 -158
- package/infrastructure/integration.test.js +0 -381
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const micromatch = require('micromatch');
|
|
2
|
+
const {
|
|
3
|
+
LAMBDA_ARCHITECTURES,
|
|
4
|
+
resolveLambdaArchitecture,
|
|
5
|
+
prismaEngineFileNames,
|
|
6
|
+
foreignPrismaEngineExcludes,
|
|
7
|
+
bundledPrismaEngineExcludes,
|
|
8
|
+
} = require('./lambda-architectures');
|
|
9
|
+
|
|
10
|
+
describe('resolveLambdaArchitecture()', () => {
|
|
11
|
+
it('resolves to x86_64 with the rhel engine when the key is unset', () => {
|
|
12
|
+
expect(resolveLambdaArchitecture({})).toEqual({
|
|
13
|
+
name: 'x86_64',
|
|
14
|
+
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
15
|
+
explicit: false,
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('resolves an explicit x86_64', () => {
|
|
20
|
+
expect(resolveLambdaArchitecture({ architecture: 'x86_64' })).toEqual({
|
|
21
|
+
name: 'x86_64',
|
|
22
|
+
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
23
|
+
explicit: true,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('resolves arm64 to the linux-arm64 engine', () => {
|
|
28
|
+
expect(resolveLambdaArchitecture({ architecture: 'arm64' })).toEqual({
|
|
29
|
+
name: 'arm64',
|
|
30
|
+
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
31
|
+
explicit: true,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('throws on an unknown architecture, naming the accepted ones', () => {
|
|
36
|
+
expect(() =>
|
|
37
|
+
resolveLambdaArchitecture({ architecture: 'aarch64' })
|
|
38
|
+
).toThrow(/aarch64.*x86_64.*arm64/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('uses the AWS architecture names as registry keys', () => {
|
|
42
|
+
expect(Object.keys(LAMBDA_ARCHITECTURES)).toEqual(['x86_64', 'arm64']);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('prismaEngineFileNames()', () => {
|
|
47
|
+
it('names the schema engine and the query engine library the migrate CLI needs for a target', () => {
|
|
48
|
+
expect(prismaEngineFileNames('linux-arm64-openssl-3.0.x')).toEqual({
|
|
49
|
+
schemaEngine: 'schema-engine-linux-arm64-openssl-3.0.x',
|
|
50
|
+
queryEngineLibrary: 'libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('foreignPrismaEngineExcludes()', () => {
|
|
56
|
+
const matches = (name, filePath) =>
|
|
57
|
+
micromatch([filePath], foreignPrismaEngineExcludes(name), {
|
|
58
|
+
dot: true,
|
|
59
|
+
}).length > 0;
|
|
60
|
+
|
|
61
|
+
const foreignEngineFiles = {
|
|
62
|
+
x86_64: [
|
|
63
|
+
'node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node',
|
|
64
|
+
'node_modules/@prisma/engines/schema-engine-darwin-arm64',
|
|
65
|
+
'node_modules/.prisma/client/query_engine-windows.dll.node',
|
|
66
|
+
'node_modules/@prisma/engines/query-engine-debian-openssl-3.0.x',
|
|
67
|
+
'node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node',
|
|
68
|
+
'node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node',
|
|
69
|
+
'node_modules/@prisma/engines/schema-engine-linux-arm64-openssl-3.0.x',
|
|
70
|
+
'node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
71
|
+
],
|
|
72
|
+
arm64: [
|
|
73
|
+
'node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node',
|
|
74
|
+
'node_modules/.prisma/client/query_engine-windows.dll.node',
|
|
75
|
+
'node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node',
|
|
76
|
+
'node_modules/@prisma/engines/schema-engine-rhel-openssl-3.0.x',
|
|
77
|
+
'node_modules/@prisma/engines/libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const targetEngineFiles = {
|
|
82
|
+
x86_64: [
|
|
83
|
+
'node_modules/@prisma/engines/schema-engine-rhel-openssl-3.0.x',
|
|
84
|
+
'node_modules/@prisma/engines/libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
85
|
+
],
|
|
86
|
+
arm64: [
|
|
87
|
+
'node_modules/@prisma/engines/schema-engine-linux-arm64-openssl-3.0.x',
|
|
88
|
+
'node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const nonEngineFiles = [
|
|
93
|
+
'node_modules/is-windows/index.js',
|
|
94
|
+
'node_modules/is-windows/package.json',
|
|
95
|
+
'node_modules/darwin-utils/lib/index.js',
|
|
96
|
+
'node_modules/some-pkg/lib/debian-release.js',
|
|
97
|
+
'node_modules/some-pkg/linux-musl-detect.js',
|
|
98
|
+
'node_modules/@prisma/engines/query_engine_bg.wasm',
|
|
99
|
+
'node_modules/.prisma/client/query_engine_bg.js',
|
|
100
|
+
'node_modules/some-pkg/dist/linux-arm64-notes.js',
|
|
101
|
+
'src/handlers/windows-handler.js',
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
it.each(['x86_64', 'arm64'])(
|
|
105
|
+
'matches every foreign engine file for %s',
|
|
106
|
+
(name) => {
|
|
107
|
+
foreignEngineFiles[name].forEach((file) =>
|
|
108
|
+
expect({ name, file, hit: matches(name, file) }).toEqual({
|
|
109
|
+
name,
|
|
110
|
+
file,
|
|
111
|
+
hit: true,
|
|
112
|
+
})
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
it.each(['x86_64', 'arm64'])(
|
|
118
|
+
'keeps the engine files of the %s target',
|
|
119
|
+
(name) => {
|
|
120
|
+
targetEngineFiles[name].forEach((file) =>
|
|
121
|
+
expect({ file, hit: matches(name, file) }).toEqual({
|
|
122
|
+
file,
|
|
123
|
+
hit: false,
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
it.each(['x86_64', 'arm64'])(
|
|
130
|
+
'keeps runtime files that only share a platform word with an engine for %s',
|
|
131
|
+
(name) => {
|
|
132
|
+
nonEngineFiles.forEach((file) =>
|
|
133
|
+
expect({ file, hit: matches(name, file) }).toEqual({
|
|
134
|
+
file,
|
|
135
|
+
hit: false,
|
|
136
|
+
})
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
it('never uses negation', () => {
|
|
142
|
+
['x86_64', 'arm64'].forEach((name) =>
|
|
143
|
+
foreignPrismaEngineExcludes(name).forEach((pattern) =>
|
|
144
|
+
expect(pattern.startsWith('!')).toBe(false)
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('bundledPrismaEngineExcludes()', () => {
|
|
151
|
+
it('adds nothing when the Prisma layer carries the engines', () => {
|
|
152
|
+
expect(bundledPrismaEngineExcludes({ architecture: 'arm64' }, true)).toEqual([]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it.each([
|
|
156
|
+
[{}, 'x86_64'],
|
|
157
|
+
[{ architecture: 'x86_64' }, 'x86_64'],
|
|
158
|
+
[{ architecture: 'arm64' }, 'arm64'],
|
|
159
|
+
])('with the layer off, excludes the engines %j does not load', (appDefinition, name) => {
|
|
160
|
+
expect(bundledPrismaEngineExcludes(appDefinition, false)).toEqual(
|
|
161
|
+
foreignPrismaEngineExcludes(name)
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -10,6 +10,10 @@
|
|
|
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
|
+
resolveLambdaArchitecture,
|
|
15
|
+
bundledPrismaEngineExcludes,
|
|
16
|
+
} = require('../lambda-architectures');
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Create base serverless definition with core functions and resources
|
|
@@ -35,6 +39,8 @@ function createBaseDefinition(
|
|
|
35
39
|
) {
|
|
36
40
|
const region = process.env.AWS_REGION || 'us-east-1';
|
|
37
41
|
const loggingConfig = buildLoggingProviderConfig(AppDefinition.logging);
|
|
42
|
+
const architecture = resolveLambdaArchitecture(AppDefinition);
|
|
43
|
+
const bundledEngineExcludes = bundledPrismaEngineExcludes(AppDefinition, usePrismaLayer);
|
|
38
44
|
|
|
39
45
|
// Package config for handlers that skip esbuild (need node_modules dependencies)
|
|
40
46
|
// Include backend src/ and index.js since handlers load the app definition
|
|
@@ -54,6 +60,7 @@ function createBaseDefinition(
|
|
|
54
60
|
'node_modules/prisma/**',
|
|
55
61
|
'node_modules/@friggframework/core/generated/**',
|
|
56
62
|
] : []),
|
|
63
|
+
...bundledEngineExcludes,
|
|
57
64
|
|
|
58
65
|
// Exclude AWS SDK (provided by Lambda runtime)
|
|
59
66
|
'node_modules/aws-sdk/**',
|
|
@@ -127,6 +134,7 @@ function createBaseDefinition(
|
|
|
127
134
|
'node_modules/prisma/**',
|
|
128
135
|
'node_modules/@friggframework/core/generated/**',
|
|
129
136
|
] : []),
|
|
137
|
+
...bundledEngineExcludes,
|
|
130
138
|
|
|
131
139
|
// Exclude nested node_modules from symlinked frigg packages (for npm link development)
|
|
132
140
|
'node_modules/@friggframework/core/node_modules/**',
|
|
@@ -178,6 +186,7 @@ function createBaseDefinition(
|
|
|
178
186
|
name: AppDefinition.provider || 'aws',
|
|
179
187
|
...(process.env.AWS_PROFILE && { profile: process.env.AWS_PROFILE }),
|
|
180
188
|
runtime: 'nodejs22.x', // Node.js 22.x (latest Lambda runtime with AWS SDK v3)
|
|
189
|
+
...(architecture.explicit && { architecture: architecture.name }),
|
|
181
190
|
timeout: 29, // Set to 29s to give buffer before API Gateway's 30s timeout
|
|
182
191
|
region,
|
|
183
192
|
stage: '${opt:stage}',
|
|
@@ -195,7 +204,6 @@ function createBaseDefinition(
|
|
|
195
204
|
'sqs:SendMessageBatch',
|
|
196
205
|
'sqs:GetQueueUrl',
|
|
197
206
|
'sqs:GetQueueAttributes',
|
|
198
|
-
'sqs:ChangeMessageVisibility',
|
|
199
207
|
],
|
|
200
208
|
Resource: [
|
|
201
209
|
{ 'Fn::GetAtt': ['InternalErrorQueue', 'Arn'] },
|
|
@@ -287,6 +295,11 @@ function createBaseDefinition(
|
|
|
287
295
|
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
288
296
|
skipEsbuild: true, // Handlers in node_modules don't need bundling
|
|
289
297
|
package: skipEsbuildPackageConfig,
|
|
298
|
+
// Every path prefix the core integration router
|
|
299
|
+
// (createIntegrationRouter) registers must be routed here;
|
|
300
|
+
// HTTP API has no implicit catch-all, so an unlisted prefix
|
|
301
|
+
// 404s at the gateway before Express sees it. Guarded by
|
|
302
|
+
// __tests__/management-api-gateway-routes.test.js.
|
|
290
303
|
events: [
|
|
291
304
|
{ httpApi: { path: '/api/integrations', method: 'ANY' } },
|
|
292
305
|
{
|
|
@@ -296,6 +309,20 @@ function createBaseDefinition(
|
|
|
296
309
|
},
|
|
297
310
|
},
|
|
298
311
|
{ httpApi: { path: '/api/authorize', method: 'ANY' } },
|
|
312
|
+
{ httpApi: { path: '/api/entity', method: 'ANY' } },
|
|
313
|
+
{
|
|
314
|
+
httpApi: {
|
|
315
|
+
path: '/api/entity/{proxy+}',
|
|
316
|
+
method: 'ANY',
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
{ httpApi: { path: '/api/entities', method: 'ANY' } },
|
|
320
|
+
{
|
|
321
|
+
httpApi: {
|
|
322
|
+
path: '/api/entities/{proxy+}',
|
|
323
|
+
method: 'ANY',
|
|
324
|
+
},
|
|
325
|
+
},
|
|
299
326
|
],
|
|
300
327
|
},
|
|
301
328
|
user: {
|
|
@@ -323,8 +350,11 @@ function createBaseDefinition(
|
|
|
323
350
|
prisma: {
|
|
324
351
|
path: 'layers/prisma',
|
|
325
352
|
name: '${self:service}-prisma-${sls:stage}',
|
|
326
|
-
description: 'Prisma runtime client only (NO CLI) with
|
|
353
|
+
description: 'Prisma runtime client only (NO CLI) with the query engine for the deployed Lambda architecture (~10-15MB). CLI packaged separately in dbMigrate function.',
|
|
327
354
|
compatibleRuntimes: ['nodejs20.x', 'nodejs22.x'],
|
|
355
|
+
...(architecture.explicit && {
|
|
356
|
+
compatibleArchitectures: [architecture.name],
|
|
357
|
+
}),
|
|
328
358
|
retain: false,
|
|
329
359
|
},
|
|
330
360
|
} : {},
|
|
@@ -384,12 +414,18 @@ function createBaseDefinition(
|
|
|
384
414
|
},
|
|
385
415
|
},
|
|
386
416
|
},
|
|
417
|
+
// The functions above use `httpApi` events, so osls creates
|
|
418
|
+
// an HTTP API (API Gateway v2, logical ID HttpApi) with only
|
|
419
|
+
// the `$default` stage. HTTP APIs publish `5xx`, not the REST
|
|
420
|
+
// API metric `5XXError`, and the ApiId dimension identifies
|
|
421
|
+
// this API (a Stage dimension would have to be `$default`).
|
|
422
|
+
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-metrics.html
|
|
387
423
|
ApiGatewayAlarm5xx: {
|
|
388
424
|
Type: 'AWS::CloudWatch::Alarm',
|
|
389
425
|
Properties: {
|
|
390
426
|
AlarmDescription: 'API Gateway 5xx Errors',
|
|
391
427
|
Namespace: 'AWS/ApiGateway',
|
|
392
|
-
MetricName: '
|
|
428
|
+
MetricName: '5xx',
|
|
393
429
|
Statistic: 'Sum',
|
|
394
430
|
Threshold: 0,
|
|
395
431
|
ComparisonOperator: 'GreaterThanThreshold',
|
|
@@ -398,7 +434,6 @@ function createBaseDefinition(
|
|
|
398
434
|
AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
|
|
399
435
|
Dimensions: [
|
|
400
436
|
{ Name: 'ApiId', Value: { Ref: 'HttpApi' } },
|
|
401
|
-
{ Name: 'Stage', Value: '${self:provider.stage}' },
|
|
402
437
|
],
|
|
403
438
|
},
|
|
404
439
|
},
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const { createBaseDefinition } = require('./base-definition-factory');
|
|
8
|
+
const { itBundlesOnlyTheTargetPrismaEngine } = require('../../../__tests__/helpers/bundled-prisma-engine-excludes');
|
|
8
9
|
|
|
9
10
|
describe('Base Definition Factory', () => {
|
|
10
11
|
beforeEach(() => {
|
|
@@ -94,7 +95,19 @@ describe('Base Definition Factory', () => {
|
|
|
94
95
|
|
|
95
96
|
expect(result.functions.auth.handler).toBe('node_modules/@friggframework/core/handlers/routers/auth.handler');
|
|
96
97
|
expect(result.functions.auth.layers).toEqual([{ Ref: 'PrismaLambdaLayer' }]);
|
|
97
|
-
expect(
|
|
98
|
+
expect(
|
|
99
|
+
result.functions.auth.events.map(
|
|
100
|
+
(e) => `${e.httpApi.method} ${e.httpApi.path}`
|
|
101
|
+
)
|
|
102
|
+
).toEqual([
|
|
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',
|
|
109
|
+
'ANY /api/entities/{proxy+}',
|
|
110
|
+
]);
|
|
98
111
|
});
|
|
99
112
|
|
|
100
113
|
it('should NOT include legacy dbMigrate function', () => {
|
|
@@ -121,6 +134,27 @@ describe('Base Definition Factory', () => {
|
|
|
121
134
|
expect(result.resources.Resources.ApiGatewayAlarm5xx).toBeDefined();
|
|
122
135
|
});
|
|
123
136
|
|
|
137
|
+
it('alarms on the HTTP API 5xx metric of the API osls creates', () => {
|
|
138
|
+
// The Frigg functions use `httpApi` events, so osls creates an
|
|
139
|
+
// API Gateway v2 HTTP API (logical ID HttpApi) with only the
|
|
140
|
+
// `$default` stage. HTTP APIs publish `5xx` (REST APIs publish
|
|
141
|
+
// `5XXError`) with the ApiId dimension; a Stage dimension set to
|
|
142
|
+
// the deploy stage name would never match `$default`.
|
|
143
|
+
const result = createBaseDefinition({}, {}, {});
|
|
144
|
+
const usesHttpApi = Object.values(result.functions).some((fn) =>
|
|
145
|
+
(fn.events || []).some((event) => event.httpApi)
|
|
146
|
+
);
|
|
147
|
+
expect(usesHttpApi).toBe(true);
|
|
148
|
+
|
|
149
|
+
const alarm = result.resources.Resources.ApiGatewayAlarm5xx;
|
|
150
|
+
expect(alarm.Properties).toMatchObject({
|
|
151
|
+
Namespace: 'AWS/ApiGateway',
|
|
152
|
+
MetricName: '5xx',
|
|
153
|
+
Dimensions: [{ Name: 'ApiId', Value: { Ref: 'HttpApi' } }],
|
|
154
|
+
AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
124
158
|
it('should include base IAM permissions', () => {
|
|
125
159
|
const result = createBaseDefinition({}, {}, {});
|
|
126
160
|
|
|
@@ -135,18 +169,6 @@ describe('Base Definition Factory', () => {
|
|
|
135
169
|
expect(sqsPermission).toBeDefined();
|
|
136
170
|
});
|
|
137
171
|
|
|
138
|
-
it('should let a function extend the visibility timeout of a message on an integration queue', () => {
|
|
139
|
-
const result = createBaseDefinition({}, {}, {});
|
|
140
|
-
|
|
141
|
-
const sqsPermission = result.provider.iamRoleStatements.find(
|
|
142
|
-
(stmt) => stmt.Action.includes('sqs:SendMessage')
|
|
143
|
-
);
|
|
144
|
-
expect(sqsPermission.Action).toContain(
|
|
145
|
-
'sqs:ChangeMessageVisibility'
|
|
146
|
-
);
|
|
147
|
-
expect(JSON.stringify(sqsPermission.Resource)).toContain('*Queue');
|
|
148
|
-
});
|
|
149
|
-
|
|
150
172
|
it('should include required plugins', () => {
|
|
151
173
|
const result = createBaseDefinition({}, {}, {});
|
|
152
174
|
|
|
@@ -302,19 +324,65 @@ describe('Base Definition Factory', () => {
|
|
|
302
324
|
});
|
|
303
325
|
|
|
304
326
|
|
|
305
|
-
describe('
|
|
327
|
+
describe('Lambda architecture (architecture)', () => {
|
|
306
328
|
const build = (appDefinition) => createBaseDefinition(appDefinition, {}, {}, true);
|
|
307
329
|
|
|
308
|
-
it('
|
|
330
|
+
it('adds no architecture fields when the key is unset, so existing templates do not change', () => {
|
|
309
331
|
const result = build({ name: 'test-app' });
|
|
310
332
|
|
|
333
|
+
expect(result.provider.architecture).toBeUndefined();
|
|
334
|
+
expect(result.layers.prisma.compatibleArchitectures).toBeUndefined();
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it.each(['x86_64', 'arm64'])(
|
|
338
|
+
'sets provider.architecture and the layer compatibleArchitectures to %s when set',
|
|
339
|
+
(architecture) => {
|
|
340
|
+
const result = build({ name: 'test-app', architecture });
|
|
341
|
+
|
|
342
|
+
expect(result.provider.architecture).toBe(architecture);
|
|
343
|
+
expect(result.layers.prisma.compatibleArchitectures).toEqual([architecture]);
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
it('describes the layer without naming an engine, since the engine follows the architecture', () => {
|
|
348
|
+
const result = build({ name: 'test-app' });
|
|
349
|
+
|
|
350
|
+
expect(result.layers.prisma.description).not.toContain('rhel');
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('rejects an architecture the registry does not know', () => {
|
|
354
|
+
expect(() => build({ name: 'test-app', architecture: 'aarch64' })).toThrow(
|
|
355
|
+
/aarch64/
|
|
356
|
+
);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
describe('Lambda architecture with usePrismaLambdaLayer=false', () => {
|
|
361
|
+
const functionsOf = (usePrismaLayer, architecture) => {
|
|
362
|
+
const result = createBaseDefinition(
|
|
363
|
+
{ name: 'test-app', ...(architecture && { architecture }) },
|
|
364
|
+
{},
|
|
365
|
+
{},
|
|
366
|
+
usePrismaLayer
|
|
367
|
+
);
|
|
368
|
+
return Object.values(result.functions);
|
|
369
|
+
};
|
|
370
|
+
itBundlesOnlyTheTargetPrismaEngine(functionsOf);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
describe('nested node_modules (lambda.keepNestedNodeModules)', () => {
|
|
374
|
+
const build = (appDefinition) => createBaseDefinition(appDefinition, {}, {}, true);
|
|
375
|
+
|
|
376
|
+
it('excludes every nested node_modules from the core function packages when the app opts out', () => {
|
|
377
|
+
const result = build({ name: 'test-app', lambda: { keepNestedNodeModules: false } });
|
|
378
|
+
|
|
311
379
|
for (const fn of ['auth', 'user', 'health']) {
|
|
312
380
|
expect(result.functions[fn].package.exclude).toContain('node_modules/**/node_modules/**');
|
|
313
381
|
}
|
|
314
382
|
});
|
|
315
383
|
|
|
316
|
-
it('keeps nested node_modules
|
|
317
|
-
const result = build({ name: 'test-app'
|
|
384
|
+
it('keeps nested node_modules by default, still excluding nested Frigg, AWS SDK and Prisma copies', () => {
|
|
385
|
+
const result = build({ name: 'test-app' });
|
|
318
386
|
|
|
319
387
|
for (const fn of ['auth', 'user', 'health']) {
|
|
320
388
|
const { exclude } = result.functions[fn].package;
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
* npm nests a package only when the root copy cannot satisfy the dependant's
|
|
7
7
|
* range. Excluding every nested node_modules from a Lambda package therefore
|
|
8
8
|
* rewires module resolution to whatever is hoisted, and drops a package
|
|
9
|
-
* outright when the root copy is dev-only.
|
|
10
|
-
*
|
|
11
|
-
* copies of Frigg packages, the
|
|
12
|
-
* app's single core, the Lambda
|
|
9
|
+
* outright when the root copy is dev-only. Function packages ship the tree the
|
|
10
|
+
* way npm resolved it unless an app opts out with
|
|
11
|
+
* `lambda.keepNestedNodeModules: false`. Nested copies of Frigg packages, the
|
|
12
|
+
* AWS SDK and Prisma stay excluded because the app's single core, the Lambda
|
|
13
|
+
* runtime and the Prisma layer provide them.
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
const ALL_NESTED_NODE_MODULES = 'node_modules/**/node_modules/**';
|
|
@@ -19,7 +20,7 @@ const ALL_NESTED_NODE_MODULES = 'node_modules/**/node_modules/**';
|
|
|
19
20
|
* @returns {boolean}
|
|
20
21
|
*/
|
|
21
22
|
function keepsNestedNodeModules(appDefinition = {}) {
|
|
22
|
-
return appDefinition.lambda?.keepNestedNodeModules
|
|
23
|
+
return appDefinition.lambda?.keepNestedNodeModules !== false;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -8,20 +8,13 @@ const {
|
|
|
8
8
|
nestedNodeModulesExcludes,
|
|
9
9
|
} = require('./nested-node-modules');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
it('excludes every nested node_modules by default', () => {
|
|
13
|
-
expect(nestedNodeModulesExcludes({}, true)).toEqual([
|
|
14
|
-
'node_modules/**/node_modules/**',
|
|
15
|
-
]);
|
|
16
|
-
expect(ALL_NESTED_NODE_MODULES).toBe('node_modules/**/node_modules/**');
|
|
17
|
-
});
|
|
11
|
+
const OPT_OUT = { lambda: { keepNestedNodeModules: false } };
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const excludes = nestedNodeModulesExcludes(appDefinition, true);
|
|
13
|
+
describe('nestedNodeModulesExcludes', () => {
|
|
14
|
+
it('keeps nested node_modules by default, except Frigg, AWS SDK and Prisma copies', () => {
|
|
15
|
+
const excludes = nestedNodeModulesExcludes({}, true);
|
|
23
16
|
|
|
24
|
-
expect(excludes).not.toContain(
|
|
17
|
+
expect(excludes).not.toContain(ALL_NESTED_NODE_MODULES);
|
|
25
18
|
expect(excludes).toEqual([
|
|
26
19
|
'node_modules/**/node_modules/@friggframework/**',
|
|
27
20
|
'node_modules/**/node_modules/aws-sdk/**',
|
|
@@ -32,30 +25,31 @@ describe('nestedNodeModulesExcludes', () => {
|
|
|
32
25
|
});
|
|
33
26
|
|
|
34
27
|
it('keeps nested Prisma copies when the app bundles Prisma instead of using the layer', () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const excludes = nestedNodeModulesExcludes(appDefinition, false);
|
|
38
|
-
|
|
39
|
-
expect(excludes).toEqual([
|
|
28
|
+
expect(nestedNodeModulesExcludes({}, false)).toEqual([
|
|
40
29
|
'node_modules/**/node_modules/@friggframework/**',
|
|
41
30
|
'node_modules/**/node_modules/aws-sdk/**',
|
|
42
31
|
'node_modules/**/node_modules/@aws-sdk/**',
|
|
43
32
|
]);
|
|
44
33
|
});
|
|
34
|
+
|
|
35
|
+
it('excludes every nested node_modules when the app opts out', () => {
|
|
36
|
+
expect(nestedNodeModulesExcludes(OPT_OUT, true)).toEqual([
|
|
37
|
+
'node_modules/**/node_modules/**',
|
|
38
|
+
]);
|
|
39
|
+
expect(ALL_NESTED_NODE_MODULES).toBe('node_modules/**/node_modules/**');
|
|
40
|
+
});
|
|
45
41
|
});
|
|
46
42
|
|
|
47
43
|
describe('keepsNestedNodeModules', () => {
|
|
48
|
-
it('is only
|
|
49
|
-
expect(
|
|
50
|
-
keepsNestedNodeModules({ lambda: { keepNestedNodeModules: true } })
|
|
51
|
-
).toBe(true);
|
|
44
|
+
it('is only disabled by the boolean false', () => {
|
|
45
|
+
expect(keepsNestedNodeModules(OPT_OUT)).toBe(false);
|
|
52
46
|
expect(
|
|
53
47
|
keepsNestedNodeModules({
|
|
54
|
-
lambda: { keepNestedNodeModules:
|
|
48
|
+
lambda: { keepNestedNodeModules: true },
|
|
55
49
|
})
|
|
56
|
-
).toBe(
|
|
57
|
-
expect(keepsNestedNodeModules({ lambda: {} })).toBe(
|
|
58
|
-
expect(keepsNestedNodeModules({})).toBe(
|
|
59
|
-
expect(keepsNestedNodeModules()).toBe(
|
|
50
|
+
).toBe(true);
|
|
51
|
+
expect(keepsNestedNodeModules({ lambda: {} })).toBe(true);
|
|
52
|
+
expect(keepsNestedNodeModules({})).toBe(true);
|
|
53
|
+
expect(keepsNestedNodeModules()).toBe(true);
|
|
60
54
|
});
|
|
61
55
|
});
|