@digitraffic/common 2025.3.4-2 → 2025.3.11-1

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 CHANGED
@@ -10,6 +10,7 @@ Use `pnpm` to build the code i.e.
10
10
  pnpm install
11
11
  pnpm build
12
12
  pnpm test
13
+ pnpm test --test-path-pattern 'dt-logger.test'
13
14
 
14
15
  Format code
15
16
 
@@ -26,7 +26,7 @@ describe("integration tests", () => {
26
26
  },
27
27
  },
28
28
  input: {
29
- body: "{ body: \"'moi\" }",
29
+ body: '{ body: "\'moi" }',
30
30
  params: () => ({
31
31
  header: {
32
32
  h1: "header1",
@@ -58,7 +58,7 @@ describe("integration tests", () => {
58
58
  const app = new App();
59
59
  const stack = new Stack(app);
60
60
  const f = new Function(stack, "id", {
61
- runtime: Runtime.NODEJS_20_X,
61
+ runtime: Runtime.NODEJS_22_X,
62
62
  code: Code.fromInline("placeholder"),
63
63
  handler: "handler",
64
64
  });
@@ -15,6 +15,11 @@ describe("dt-logger", () => {
15
15
  logger.debug(message);
16
16
  }, expected);
17
17
  }
18
+ function assertError(config, message, expected) {
19
+ assertWrite(config, (logger) => {
20
+ logger.error(message);
21
+ }, expected);
22
+ }
18
23
  function assertWrite(config, writeFunction, expected) {
19
24
  const logged = [];
20
25
  const writeStream = new Writable({
@@ -33,10 +38,16 @@ describe("dt-logger", () => {
33
38
  if (typeof expected === "object" && "stack" in expected && expected.stack) {
34
39
  // eslint-disable-next-line dot-notation
35
40
  const stack = loggedLine["stack"];
41
+ expect(stack).toBeDefined();
42
+ // @ts-ignore // stack should be multiline string
43
+ const stackLines = stack.split("\n");
44
+ expect(stackLines.length).toBeGreaterThanOrEqual(2);
45
+ expect(stackLines[0]).toEqual(expected.stack);
46
+ // @ts-ignore
47
+ expect(stackLines[1].trim().startsWith("at ")).toBe(true);
36
48
  // eslint-disable-next-line dot-notation
37
49
  delete loggedLine["stack"];
38
50
  delete expected.stack;
39
- expect(stack).toBeDefined();
40
51
  }
41
52
  expect(loggedLine).toMatchObject(expected);
42
53
  }
@@ -104,5 +115,63 @@ describe("dt-logger", () => {
104
115
  level: "DEBUG",
105
116
  });
106
117
  });
118
+ test("error - Error string", () => {
119
+ const error = "FAIL!";
120
+ assertError({}, {
121
+ ...LOG_LINE,
122
+ error,
123
+ }, {
124
+ ...LOG_LINE,
125
+ error: "FAIL!",
126
+ level: "ERROR",
127
+ });
128
+ });
129
+ test("error - Error object", () => {
130
+ const error = {
131
+ errorMessage: "FAIL!",
132
+ errorCode: 123,
133
+ };
134
+ assertError({}, {
135
+ ...LOG_LINE,
136
+ error,
137
+ }, {
138
+ ...LOG_LINE,
139
+ error: '{"errorMessage":"FAIL!","errorCode":123}',
140
+ level: "ERROR",
141
+ });
142
+ });
143
+ test("error - Error", () => {
144
+ const error = new Error("FAIL!");
145
+ assertError({}, {
146
+ ...LOG_LINE,
147
+ error,
148
+ }, {
149
+ ...LOG_LINE,
150
+ error: "Error: FAIL!",
151
+ level: "ERROR",
152
+ });
153
+ });
154
+ test("error - Error with stack", () => {
155
+ let error;
156
+ try {
157
+ // @ts-ignore
158
+ console.log(`Result: ${undefined.length}`);
159
+ }
160
+ catch (e) {
161
+ // @ts-ignore
162
+ console.debug(`Failed message: ${e.message}`);
163
+ console.debug(`Failed stack: ${e.stack}`);
164
+ error = e;
165
+ }
166
+ assertError({}, {
167
+ ...LOG_LINE,
168
+ error,
169
+ }, {
170
+ ...LOG_LINE,
171
+ error: "TypeError: Cannot read properties of undefined (reading 'length')",
172
+ level: "ERROR",
173
+ stack: "TypeError: Cannot read properties of undefined (reading 'length')",
174
+ });
175
+ });
107
176
  });
108
177
  //# sourceMappingURL=dt-logger.test.js.map
@@ -70,7 +70,7 @@ export class DigitrafficDLQueue {
70
70
  });
71
71
  const dlqFunctionName = `${dlqName}-Function`;
72
72
  const lambda = MonitoredFunction.create(stack, dlqFunctionName, {
73
- runtime: Runtime.NODEJS_20_X,
73
+ runtime: Runtime.NODEJS_22_X,
74
74
  logRetention: RetentionDays.ONE_YEAR,
75
75
  functionName: dlqFunctionName,
76
76
  code: getDlqCode(dlqBucket.bucketName),
@@ -18,7 +18,7 @@ export function databaseFunctionProps(stack, environment, lambdaName, simpleLamb
18
18
  }
19
19
  export function lambdaFunctionProps(_, environment, lambdaName, simpleLambdaName, config) {
20
20
  return {
21
- runtime: config?.runtime ?? Runtime.NODEJS_20_X,
21
+ runtime: config?.runtime ?? Runtime.NODEJS_22_X,
22
22
  architecture: config?.architecture ?? Architecture.ARM_64,
23
23
  memorySize: config?.memorySize ?? 128,
24
24
  functionName: lambdaName,
@@ -39,7 +39,7 @@ function getAssetCode(simpleLambdaName, isSingleLambda) {
39
39
  }
40
40
  export function defaultLambdaConfiguration(config) {
41
41
  const props = {
42
- runtime: Runtime.NODEJS_20_X,
42
+ runtime: Runtime.NODEJS_22_X,
43
43
  memorySize: config.memorySize ?? 128,
44
44
  functionName: config.functionName,
45
45
  handler: config.handler,
@@ -86,13 +86,21 @@ export class DtLogger {
86
86
  */
87
87
  log(message) {
88
88
  const error = message.error
89
- ? typeof message.error === "string"
90
- ? message.error
91
- : JSON.stringify(message.error)
89
+ ? (message.error instanceof Error)
90
+ ? `${message.error.name}: ${message.error.message}`
91
+ : typeof message.error === "string"
92
+ ? message.error
93
+ : JSON.stringify(message.error)
92
94
  : undefined;
95
+ const stack = message.stack
96
+ ? message.stack
97
+ : message.error
98
+ ? (message.error instanceof Error) ? message.error.stack : undefined
99
+ : undefined;
93
100
  const logMessage = {
94
101
  ...removePrefix("custom", message),
95
102
  error,
103
+ stack,
96
104
  lambdaName: this.lambdaName,
97
105
  runtime: this.runtime,
98
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2025.3.4-2",
3
+ "version": "2025.3.11-1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {
@@ -8,7 +8,7 @@
8
8
  "url": "https://github.com/tmfg/digitraffic-common.git"
9
9
  },
10
10
  "engines": {
11
- "node": ">=20 <21"
11
+ "node": ">=22 <23"
12
12
  },
13
13
  "license": "EUPL-1.2",
14
14
  "private": false,