@digitraffic/common 2025.4.2-1 → 2025.4.10-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.
@@ -4,6 +4,10 @@ const LOG_LINE = {
4
4
  method: "dt-logger.test",
5
5
  message: "FOO",
6
6
  };
7
+ const EXPECTED_LOG_LINE = {
8
+ method: "dt-logger.test",
9
+ message: "dt-logger.test FOO",
10
+ };
7
11
  describe("dt-logger", () => {
8
12
  function assertLog(config, message, expected) {
9
13
  assertWrite(config, (logger) => {
@@ -57,7 +61,7 @@ describe("dt-logger", () => {
57
61
  ...LOG_LINE,
58
62
  customDate: date,
59
63
  }, {
60
- ...LOG_LINE,
64
+ ...EXPECTED_LOG_LINE,
61
65
  date: date.toISOString(),
62
66
  });
63
67
  });
@@ -66,14 +70,21 @@ describe("dt-logger", () => {
66
70
  ...LOG_LINE,
67
71
  customFooCount: 123,
68
72
  }, {
69
- ...LOG_LINE,
73
+ ...EXPECTED_LOG_LINE,
70
74
  fooCount: 123,
71
75
  });
72
76
  });
73
77
  test("default values", () => {
74
78
  assertLog({}, LOG_LINE, {
75
- method: LOG_LINE.method,
76
- message: LOG_LINE.message,
79
+ method: EXPECTED_LOG_LINE.method,
80
+ message: EXPECTED_LOG_LINE.message,
81
+ level: "INFO",
82
+ });
83
+ });
84
+ test("method not duplicated", () => {
85
+ assertLog({}, EXPECTED_LOG_LINE, {
86
+ method: EXPECTED_LOG_LINE.method,
87
+ message: EXPECTED_LOG_LINE.message,
77
88
  level: "INFO",
78
89
  });
79
90
  });
@@ -81,16 +92,16 @@ describe("dt-logger", () => {
81
92
  const LAMBDA_NAME = "test_lambda_name";
82
93
  assertLog({ lambdaName: LAMBDA_NAME }, LOG_LINE, {
83
94
  lambdaName: LAMBDA_NAME,
84
- method: LOG_LINE.method,
85
- message: LOG_LINE.message,
95
+ method: EXPECTED_LOG_LINE.method,
96
+ message: EXPECTED_LOG_LINE.message,
86
97
  level: "INFO",
87
98
  });
88
99
  });
89
100
  test("set runtime", () => {
90
101
  const RUNTIME = "test_runtime";
91
102
  assertLog({ runTime: RUNTIME }, LOG_LINE, {
92
- message: LOG_LINE.message,
93
- method: LOG_LINE.method,
103
+ message: EXPECTED_LOG_LINE.message,
104
+ method: EXPECTED_LOG_LINE.method,
94
105
  level: "INFO",
95
106
  runtime: RUNTIME,
96
107
  });
@@ -121,7 +132,7 @@ describe("dt-logger", () => {
121
132
  ...LOG_LINE,
122
133
  error,
123
134
  }, {
124
- ...LOG_LINE,
135
+ ...EXPECTED_LOG_LINE,
125
136
  error: "FAIL!",
126
137
  level: "ERROR",
127
138
  });
@@ -135,7 +146,7 @@ describe("dt-logger", () => {
135
146
  ...LOG_LINE,
136
147
  error,
137
148
  }, {
138
- ...LOG_LINE,
149
+ ...EXPECTED_LOG_LINE,
139
150
  error: '{"errorMessage":"FAIL!","errorCode":123}',
140
151
  level: "ERROR",
141
152
  });
@@ -146,7 +157,7 @@ describe("dt-logger", () => {
146
157
  ...LOG_LINE,
147
158
  error,
148
159
  }, {
149
- ...LOG_LINE,
160
+ ...EXPECTED_LOG_LINE,
150
161
  error: "Error: FAIL!",
151
162
  level: "ERROR",
152
163
  });
@@ -167,7 +178,7 @@ describe("dt-logger", () => {
167
178
  ...LOG_LINE,
168
179
  error,
169
180
  }, {
170
- ...LOG_LINE,
181
+ ...EXPECTED_LOG_LINE,
171
182
  error: "TypeError: Cannot read properties of undefined (reading 'length')",
172
183
  level: "ERROR",
173
184
  stack: "TypeError: Cannot read properties of undefined (reading 'length')",
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import { decodeBase64ToAscii, decodeBase64ToUtf8, encodeAsciiToBase64, encodeUtf8ToBase64, } from "../../utils/base64.js";
2
+ describe("Base64UtilTest", () => {
3
+ const EXPECTED_ASCII = "0a9f4967-faaa-445a-ba11-078f7f9556b4";
4
+ const EXPECTED_ASCII_BASE64 = "MGE5ZjQ5NjctZmFhYS00NDVhLWJhMTEtMDc4ZjdmOTU1NmI0";
5
+ const EXPECTED_UTF8 = '욤頶ɠ_񝝉T񶅶𞜫7郣Ҧ㒢,"鏤ځ峡蟅͆뼐񭫟ؐԓ外󦸴ԉȺꥅ_񟵭';
6
+ const EXPECTED_UTF8_BASE64 = "7Jqk6aC2yaBf8Z2diVTxtoW28J6cqzfug6Ppg6PSpuOSou6Usywi6Y+k2oHls6Hon4XNhuu8kPGtq5/YkNST5aSW86a4tNSJyLrqpYVf8Z+1rQ==";
7
+ test("encode and decode ascii", () => {
8
+ const encodedAscii = encodeAsciiToBase64(EXPECTED_ASCII);
9
+ const decodedAscii = decodeBase64ToAscii(EXPECTED_ASCII_BASE64);
10
+ // encoding/decoding ascii with utf8 should be the same as ascii
11
+ const encodedUtf8 = encodeUtf8ToBase64(EXPECTED_ASCII);
12
+ const decodedUtf8 = decodeBase64ToUtf8(EXPECTED_ASCII_BASE64);
13
+ expect(encodedAscii).toEqual(EXPECTED_ASCII_BASE64);
14
+ expect(decodedAscii).toEqual(EXPECTED_ASCII);
15
+ expect(encodedUtf8).toEqual(EXPECTED_ASCII_BASE64);
16
+ expect(decodedUtf8).toEqual(EXPECTED_ASCII);
17
+ expect(encodedUtf8).toEqual(encodedAscii);
18
+ expect(decodedUtf8).toEqual(decodedAscii);
19
+ });
20
+ test("encode and decode utf8", () => {
21
+ const encodedUtf8 = encodeUtf8ToBase64(EXPECTED_UTF8);
22
+ const decodedUtf8 = decodeBase64ToUtf8(EXPECTED_UTF8_BASE64);
23
+ expect(encodedUtf8).toEqual(EXPECTED_UTF8_BASE64);
24
+ expect(decodedUtf8).toEqual(EXPECTED_UTF8);
25
+ });
26
+ });
27
+ //# sourceMappingURL=base64.test.js.map
@@ -40,7 +40,7 @@ describe("dt-logger", () => {
40
40
  assertLogError(STRING_ERROR, {
41
41
  type: "Error",
42
42
  method: TEST_METHODNAME,
43
- message: STRING_ERROR,
43
+ message: `${TEST_METHODNAME} ${STRING_ERROR}`,
44
44
  level: "ERROR",
45
45
  });
46
46
  });
@@ -49,7 +49,7 @@ describe("dt-logger", () => {
49
49
  assertLogError(ERROR, {
50
50
  type: "Error",
51
51
  method: TEST_METHODNAME,
52
- message: ERROR.message,
52
+ message: `${TEST_METHODNAME} ${ERROR.message}`,
53
53
  level: "ERROR",
54
54
  });
55
55
  });
@@ -58,7 +58,7 @@ describe("dt-logger", () => {
58
58
  assertLogError(ERROR, {
59
59
  type: "Error",
60
60
  method: TEST_METHODNAME,
61
- message: ERROR.message,
61
+ message: `${TEST_METHODNAME} ${ERROR.message}`,
62
62
  level: "ERROR",
63
63
  stack: true,
64
64
  }, true);
@@ -69,7 +69,7 @@ describe("dt-logger", () => {
69
69
  assertAxiosError(ERROR, {
70
70
  type: "Error",
71
71
  method: TEST_METHODNAME,
72
- message: ERROR.message,
72
+ message: `${TEST_METHODNAME} ${ERROR.message}`,
73
73
  level: "ERROR",
74
74
  code: ERROR.code,
75
75
  });
@@ -85,6 +85,11 @@ export class DtLogger {
85
85
  * @see {@link LoggableType}
86
86
  */
87
87
  log(message) {
88
+ // Append always method to message
89
+ if (!message.message || !message.message.length ||
90
+ !message.message.includes(message.method)) {
91
+ message.message = `${message.method} ${message.message ?? ""}`;
92
+ }
88
93
  const error = message.error
89
94
  ? (message.error instanceof Error)
90
95
  ? `${message.error.name}: ${message.error.message}`
@@ -1,11 +1,32 @@
1
1
  /**
2
- * Decode given string from base64 to ascii
3
- * @param str string
2
+ * Encode given string to base64
3
+ * @param str
4
+ * @param encoding
4
5
  */
5
- export declare function decodeBase64ToAscii(str: string): string;
6
+ export declare function encodeBase64(str: string, encoding: BufferEncoding): string;
6
7
  /**
7
8
  * Decode given string from base64 to given encoding
8
9
  * @param str
9
10
  * @param encoding
10
11
  */
11
12
  export declare function decodeBase64(str: string, encoding: BufferEncoding): string;
13
+ /**
14
+ * Encode given string from ascii to Base64 string
15
+ * @param token
16
+ */
17
+ export declare function encodeAsciiToBase64(token: string): string;
18
+ /**
19
+ * Decode given string from base64 to ascii
20
+ * @param str string
21
+ */
22
+ export declare function decodeBase64ToAscii(str: string): string;
23
+ /**
24
+ * Encode given string from base64 to utf8 string
25
+ * @param str
26
+ */
27
+ export declare function encodeUtf8ToBase64(str: string): string;
28
+ /**
29
+ * Decode given string from base64 to utf8 string
30
+ * @param str
31
+ */
32
+ export declare function decodeBase64ToUtf8(str: string): string;
@@ -1,9 +1,10 @@
1
1
  /**
2
- * Decode given string from base64 to ascii
3
- * @param str string
2
+ * Encode given string to base64
3
+ * @param str
4
+ * @param encoding
4
5
  */
5
- export function decodeBase64ToAscii(str) {
6
- return decodeBase64(str, "ascii");
6
+ export function encodeBase64(str, encoding) {
7
+ return Buffer.from(str, encoding).toString("base64");
7
8
  }
8
9
  /**
9
10
  * Decode given string from base64 to given encoding
@@ -13,4 +14,32 @@ export function decodeBase64ToAscii(str) {
13
14
  export function decodeBase64(str, encoding) {
14
15
  return Buffer.from(str, "base64").toString(encoding);
15
16
  }
17
+ /**
18
+ * Encode given string from ascii to Base64 string
19
+ * @param token
20
+ */
21
+ export function encodeAsciiToBase64(token) {
22
+ return encodeBase64(token, "ascii");
23
+ }
24
+ /**
25
+ * Decode given string from base64 to ascii
26
+ * @param str string
27
+ */
28
+ export function decodeBase64ToAscii(str) {
29
+ return decodeBase64(str, "ascii");
30
+ }
31
+ /**
32
+ * Encode given string from base64 to utf8 string
33
+ * @param str
34
+ */
35
+ export function encodeUtf8ToBase64(str) {
36
+ return encodeBase64(str, "utf8");
37
+ }
38
+ /**
39
+ * Decode given string from base64 to utf8 string
40
+ * @param str
41
+ */
42
+ export function decodeBase64ToUtf8(str) {
43
+ return decodeBase64(str, "utf8");
44
+ }
16
45
  //# sourceMappingURL=base64.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2025.4.2-1",
3
+ "version": "2025.4.10-1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {
@@ -111,7 +111,7 @@
111
111
  "@aws-sdk/lib-storage": "^3.777.0",
112
112
  "@date-fns/tz": "1.2.0",
113
113
  "@smithy/fetch-http-handler": "5.0.2",
114
- "aws-cdk-lib": "^2.186.0",
114
+ "aws-cdk-lib": "^2.188.0",
115
115
  "change-case": "^5.4.4",
116
116
  "constructs": "~10.4.2",
117
117
  "date-fns": "~4.1.0",
@@ -151,7 +151,7 @@
151
151
  "@types/node": "22.13.14",
152
152
  "@typescript-eslint/eslint-plugin": "~7.14.1",
153
153
  "@typescript-eslint/parser": "^7.18.0",
154
- "aws-cdk-lib": "^2.186.0",
154
+ "aws-cdk-lib": "^2.188.0",
155
155
  "aws-sdk": "^2.1692.0",
156
156
  "change-case": "^5.4.4",
157
157
  "constructs": "~10.4.2",