@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.
@@ -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
@@ -61,6 +61,7 @@ describe("FunctionBuilder test", () => {
61
61
  template.hasResourceProperties("AWS::Lambda::Function", {
62
62
  Environment: {
63
63
  Variables: {
64
+ [EnvKeys.APP_NAME]: "road-test",
64
65
  [EnvKeys.SECRET_ID]: "testSecret",
65
66
  [TEST_ENV_VAR]: TEST_ENV_VALUE,
66
67
  },
@@ -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
- if (this._features.secretAccess) {
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 this.configuration.secretId
50
- ? {
51
- SECRET_ID: this.configuration.secretId,
52
- DB_APPLICATION: dbApplication,
53
- }
54
- : {
55
- DB_APPLICATION: dbApplication,
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
  };
@@ -1,4 +1,5 @@
1
1
  export declare enum EnvKeys {
2
+ APP_NAME = "APP_NAME",
2
3
  AWS_REGION = "AWS_REGION",
3
4
  SECRET_ID = "SECRET_ID",
4
5
  SECRET_OVERRIDE_AWS_REGION = "SECRET_OVERRIDE_AWS_REGION"
@@ -1,5 +1,6 @@
1
1
  export var EnvKeys;
2
2
  (function (EnvKeys) {
3
+ EnvKeys["APP_NAME"] = "APP_NAME";
3
4
  EnvKeys["AWS_REGION"] = "AWS_REGION";
4
5
  EnvKeys["SECRET_ID"] = "SECRET_ID";
5
6
  EnvKeys["SECRET_OVERRIDE_AWS_REGION"] = "SECRET_OVERRIDE_AWS_REGION";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2026.8.20-1",
3
+ "version": "2026.8.31-2",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "repository": {