@digitraffic/common 2026.8.20-1 → 2026.8.31-2
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/dist/__test__/infra/stack/stack.test.d.ts +1 -0
- package/dist/__test__/infra/stack/stack.test.js +33 -0
- package/dist/__test__/stack/dt-function.test.js +1 -0
- package/dist/aws/infra/stack/dt-function.js +6 -4
- package/dist/aws/infra/stack/stack.js +9 -8
- package/dist/aws/runtime/dt-logger.d.ts +1 -0
- package/dist/aws/runtime/dt-logger.js +5 -0
- package/dist/aws/runtime/environment.d.ts +1 -0
- package/dist/aws/runtime/environment.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { App } from "aws-cdk-lib";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { DigitrafficStack } from "../../../aws/infra/stack/stack.js";
|
|
4
|
+
import { EnvKeys } from "../../../aws/runtime/environment.js";
|
|
5
|
+
import { TrafficType } from "../../../types/traffictype.js";
|
|
6
|
+
function createStack(secretId) {
|
|
7
|
+
const configuration = {
|
|
8
|
+
shortName: "VS",
|
|
9
|
+
trafficType: TrafficType.ROAD,
|
|
10
|
+
secretId,
|
|
11
|
+
alarmTopicArn: "",
|
|
12
|
+
warningTopicArn: "",
|
|
13
|
+
production: false,
|
|
14
|
+
stackProps: {},
|
|
15
|
+
};
|
|
16
|
+
return new DigitrafficStack(new App(), "TestStack", configuration);
|
|
17
|
+
}
|
|
18
|
+
describe("DigitrafficStack.createDefaultLambdaEnvironment", () => {
|
|
19
|
+
test("includes the application name without a secret", () => {
|
|
20
|
+
expect(createStack().createDefaultLambdaEnvironment("variable-signs")).toEqual({
|
|
21
|
+
[EnvKeys.APP_NAME]: "road-vs",
|
|
22
|
+
DB_APPLICATION: "variable-signs",
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
test("preserves the secret configuration", () => {
|
|
26
|
+
expect(createStack("test-secret").createDefaultLambdaEnvironment("variable-signs")).toEqual({
|
|
27
|
+
[EnvKeys.APP_NAME]: "road-vs",
|
|
28
|
+
DB_APPLICATION: "variable-signs",
|
|
29
|
+
SECRET_ID: "test-secret",
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=stack.test.js.map
|
|
@@ -3,7 +3,7 @@ import { Duration } from "aws-cdk-lib";
|
|
|
3
3
|
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
|
|
4
4
|
import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
5
5
|
import { ApplicationLogLevel, Architecture, AssetCode, Function as AwsFunction, Code, LoggingFormat, Runtime, SystemLogLevel, } from "aws-cdk-lib/aws-lambda";
|
|
6
|
-
import { camelCase, startCase } from "es-toolkit";
|
|
6
|
+
import { camelCase, kebabCase, startCase } from "es-toolkit";
|
|
7
7
|
import { DatabaseEnvironmentKeys } from "../../../database/database.js";
|
|
8
8
|
import { EnvKeys } from "../../runtime/environment.js";
|
|
9
9
|
import { DtFunctionAlarms } from "./dt-function-alarms.js";
|
|
@@ -260,14 +260,16 @@ export class FunctionBuilder {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
getEnvironment() {
|
|
263
|
-
let environment = {
|
|
264
|
-
|
|
263
|
+
let environment = {
|
|
264
|
+
[EnvKeys.APP_NAME]: `${this._stack.configuration.trafficType.toLowerCase()}-${kebabCase(this._stack.configuration.shortName)}`,
|
|
265
|
+
};
|
|
266
|
+
if (this._features.secretAccess && this._stack.configuration.secretId) {
|
|
265
267
|
environment = {
|
|
266
268
|
...environment,
|
|
267
269
|
[EnvKeys.SECRET_ID]: this._stack.configuration.secretId,
|
|
268
270
|
};
|
|
269
271
|
}
|
|
270
|
-
if (this._features.databaseAccess) {
|
|
272
|
+
if (this._features.databaseAccess && this._stack.configuration.shortName) {
|
|
271
273
|
environment = {
|
|
272
274
|
...environment,
|
|
273
275
|
[DatabaseEnvironmentKeys.DB_APPLICATION]: this._stack.configuration.shortName,
|
|
@@ -3,6 +3,8 @@ import { SecurityGroup, Vpc } from "aws-cdk-lib/aws-ec2";
|
|
|
3
3
|
import { Secret } from "aws-cdk-lib/aws-secretsmanager";
|
|
4
4
|
import { Topic } from "aws-cdk-lib/aws-sns";
|
|
5
5
|
import { StringParameter } from "aws-cdk-lib/aws-ssm";
|
|
6
|
+
import { kebabCase } from "es-toolkit";
|
|
7
|
+
import { EnvKeys } from "../../runtime/environment.js";
|
|
6
8
|
import { StackCheckingAspect } from "./stack-checking-aspect.js";
|
|
7
9
|
const SSM_ROOT = "/digitraffic";
|
|
8
10
|
export const SOLUTION_KEY = "Solution";
|
|
@@ -46,14 +48,13 @@ export class DigitrafficStack extends Stack {
|
|
|
46
48
|
return this.createDefaultLambdaEnvironment(this.configuration.shortName);
|
|
47
49
|
}
|
|
48
50
|
createDefaultLambdaEnvironment(dbApplication) {
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
51
|
+
return {
|
|
52
|
+
[EnvKeys.APP_NAME]: `${this.configuration.trafficType.toLowerCase()}-${kebabCase(this.configuration.shortName)}`,
|
|
53
|
+
DB_APPLICATION: dbApplication,
|
|
54
|
+
...(this.configuration.secretId
|
|
55
|
+
? { SECRET_ID: this.configuration.secretId }
|
|
56
|
+
: {}),
|
|
57
|
+
};
|
|
57
58
|
}
|
|
58
59
|
getSecret() {
|
|
59
60
|
if (this.secret === undefined) {
|
|
@@ -61,6 +61,7 @@ export interface LoggableType extends CustomParams {
|
|
|
61
61
|
* * the actual message (as json or as string)
|
|
62
62
|
*/
|
|
63
63
|
export declare class DtLogger {
|
|
64
|
+
readonly appName?: string;
|
|
64
65
|
readonly lambdaName?: string;
|
|
65
66
|
readonly runtime?: string;
|
|
66
67
|
readonly writeStream: Writable;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { lowerFirst, mapKeys } from "es-toolkit";
|
|
2
2
|
import { getEnvVariableOrElse } from "../../utils/utils.js";
|
|
3
|
+
import { EnvKeys } from "./environment.js";
|
|
3
4
|
/**
|
|
4
5
|
* Helper class for json-logging.
|
|
5
6
|
*
|
|
@@ -10,6 +11,7 @@ import { getEnvVariableOrElse } from "../../utils/utils.js";
|
|
|
10
11
|
* * the actual message (as json or as string)
|
|
11
12
|
*/
|
|
12
13
|
export class DtLogger {
|
|
14
|
+
appName;
|
|
13
15
|
lambdaName;
|
|
14
16
|
runtime;
|
|
15
17
|
writeStream;
|
|
@@ -19,6 +21,7 @@ export class DtLogger {
|
|
|
19
21
|
* @param {LoggerConfiguration?} [config] - Accepts configuration options @see {@link LoggerConfiguration}
|
|
20
22
|
*/
|
|
21
23
|
constructor(config) {
|
|
24
|
+
this.appName = getEnvVariableOrElse(EnvKeys.APP_NAME, undefined);
|
|
22
25
|
this.lambdaName =
|
|
23
26
|
config?.lambdaName ??
|
|
24
27
|
getEnvVariableOrElse("AWS_LAMBDA_FUNCTION_NAME", "unknown lambda name");
|
|
@@ -38,6 +41,7 @@ export class DtLogger {
|
|
|
38
41
|
const logMessage = {
|
|
39
42
|
message,
|
|
40
43
|
level: "DEBUG",
|
|
44
|
+
app: this.appName,
|
|
41
45
|
lambdaName: this.lambdaName,
|
|
42
46
|
runtime: this.runtime,
|
|
43
47
|
};
|
|
@@ -112,6 +116,7 @@ export class DtLogger {
|
|
|
112
116
|
...messageFields,
|
|
113
117
|
error,
|
|
114
118
|
stack,
|
|
119
|
+
app: this.appName,
|
|
115
120
|
lambdaName: this.lambdaName,
|
|
116
121
|
runtime: this.runtime,
|
|
117
122
|
};
|