@digitraffic/common 2025.4.10-1 → 2025.5.5-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/dist/__test__/runtime/dt-logger.test.js +10 -3
- package/dist/__test__/utils/logging.test.js +5 -5
- package/dist/aws/runtime/dt-logger.d.ts +1 -0
- package/dist/aws/runtime/dt-logger.js +33 -1
- package/dist/aws/runtime/secrets/secret-holder.d.ts +3 -1
- package/dist/aws/runtime/secrets/secret-holder.js +12 -8
- package/dist/utils/logging.js +17 -7
- package/package.json +27 -31
@@ -55,14 +55,20 @@ describe("dt-logger", () => {
|
|
55
55
|
}
|
56
56
|
expect(loggedLine).toMatchObject(expected);
|
57
57
|
}
|
58
|
-
test("custom values", () => {
|
58
|
+
test("custom date, number, text and '=' values", () => {
|
59
59
|
const date = new Date();
|
60
60
|
assertLog({}, {
|
61
61
|
...LOG_LINE,
|
62
62
|
customDate: date,
|
63
|
+
customNumber: 123,
|
64
|
+
customText: "abc",
|
65
|
+
customEqualsText: "foo=bar",
|
63
66
|
}, {
|
64
|
-
|
67
|
+
method: EXPECTED_LOG_LINE.method,
|
68
|
+
message: `${EXPECTED_LOG_LINE.message} date=${date.toISOString()} number=123 text=abc equalsText=\"foo=bar\"`,
|
65
69
|
date: date.toISOString(),
|
70
|
+
number: 123,
|
71
|
+
text: "abc",
|
66
72
|
});
|
67
73
|
});
|
68
74
|
test("custom count should be a number", () => {
|
@@ -70,7 +76,8 @@ describe("dt-logger", () => {
|
|
70
76
|
...LOG_LINE,
|
71
77
|
customFooCount: 123,
|
72
78
|
}, {
|
73
|
-
|
79
|
+
method: EXPECTED_LOG_LINE.method,
|
80
|
+
message: `${EXPECTED_LOG_LINE.message} fooCount=123`,
|
74
81
|
fooCount: 123,
|
75
82
|
});
|
76
83
|
});
|
@@ -2,7 +2,7 @@ import { Writable } from "stream";
|
|
2
2
|
import { DtLogger } from "../../aws/runtime/dt-logger.js";
|
3
3
|
import { logException } from "../../utils/logging.js";
|
4
4
|
const TEST_METHODNAME = "test.logException";
|
5
|
-
describe("
|
5
|
+
describe("logging-test", () => {
|
6
6
|
function assertLogError(error, expected, includeStack = false) {
|
7
7
|
assertWrite((logger) => {
|
8
8
|
logException(logger, error, includeStack);
|
@@ -40,7 +40,7 @@ describe("dt-logger", () => {
|
|
40
40
|
assertLogError(STRING_ERROR, {
|
41
41
|
type: "Error",
|
42
42
|
method: TEST_METHODNAME,
|
43
|
-
message: `${TEST_METHODNAME}
|
43
|
+
message: `${TEST_METHODNAME} error=${STRING_ERROR} type=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: `${TEST_METHODNAME}
|
52
|
+
message: `${TEST_METHODNAME} error=${ERROR.message} type=Error`,
|
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: `${TEST_METHODNAME}
|
61
|
+
message: `${TEST_METHODNAME} error=${ERROR.message} type=Error`,
|
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: `${TEST_METHODNAME}
|
72
|
+
message: `${TEST_METHODNAME} error=${ERROR.message} type=Error code=12`,
|
73
73
|
level: "ERROR",
|
74
74
|
code: ERROR.code,
|
75
75
|
});
|
@@ -102,8 +102,10 @@ export class DtLogger {
|
|
102
102
|
: message.error
|
103
103
|
? (message.error instanceof Error) ? message.error.stack : undefined
|
104
104
|
: undefined;
|
105
|
+
const messageFields = removePrefix("custom", message);
|
106
|
+
messageFields.message = this.appendMessageFieldsToMessage(messageFields);
|
105
107
|
const logMessage = {
|
106
|
-
...
|
108
|
+
...messageFields,
|
107
109
|
error,
|
108
110
|
stack,
|
109
111
|
lambdaName: this.lambdaName,
|
@@ -111,6 +113,18 @@ export class DtLogger {
|
|
111
113
|
};
|
112
114
|
this.writeStream.write(JSON.stringify(logMessage) + "\n");
|
113
115
|
}
|
116
|
+
appendMessageFieldsToMessage(message) {
|
117
|
+
// The order is not guaranteed to be alphabetical etc.
|
118
|
+
const fielValuePairs = Object.entries(message)
|
119
|
+
// Remove fields not logged in message field
|
120
|
+
.filter(([key]) => {
|
121
|
+
return !["message", "level", "method", "stack", "error"].includes(key) && !(message.message ?? "").includes(`${key}=`);
|
122
|
+
})
|
123
|
+
// Map value to string
|
124
|
+
.map(([key, value]) => `${key}=${valueToString(value)}`)
|
125
|
+
.join(" ");
|
126
|
+
return `${message.message ?? ""}${fielValuePairs ? " " + fielValuePairs : ""}`;
|
127
|
+
}
|
114
128
|
}
|
115
129
|
/**
|
116
130
|
* Removes given prefixes from the keys of the object.
|
@@ -118,4 +132,22 @@ export class DtLogger {
|
|
118
132
|
function removePrefix(prefix, loggable) {
|
119
133
|
return mapKeys(loggable, (_index, key) => key.startsWith(prefix) ? lowerFirst(key.replace(prefix, "")) : key);
|
120
134
|
}
|
135
|
+
function valueToString(value) {
|
136
|
+
if (value === undefined) {
|
137
|
+
return "undefined";
|
138
|
+
}
|
139
|
+
else if (value === null) {
|
140
|
+
return "null";
|
141
|
+
}
|
142
|
+
else if (value instanceof Date) {
|
143
|
+
return value.toISOString();
|
144
|
+
}
|
145
|
+
else if (typeof value !== "string") {
|
146
|
+
return JSON.stringify(value);
|
147
|
+
}
|
148
|
+
else if (value.includes("=")) {
|
149
|
+
return JSON.stringify(value);
|
150
|
+
}
|
151
|
+
return value;
|
152
|
+
}
|
121
153
|
//# sourceMappingURL=dt-logger.js.map
|
@@ -17,7 +17,9 @@ export declare class SecretHolder<Secret extends GenericSecret> {
|
|
17
17
|
private readonly secretId;
|
18
18
|
private readonly prefix;
|
19
19
|
private readonly expectedKeys;
|
20
|
-
private
|
20
|
+
private cachedSecret?;
|
21
|
+
private expirationTime;
|
22
|
+
private readonly ttl;
|
21
23
|
constructor(secretId: string, prefix?: string, expectedKeys?: string[], configuration?: typeof DEFAULT_CONFIGURATION);
|
22
24
|
private initSecret;
|
23
25
|
static create<S extends GenericSecret>(prefix?: string, expectedKeys?: string[]): SecretHolder<S>;
|
@@ -2,9 +2,7 @@ import { getSecret } from "./secret.js";
|
|
2
2
|
import { checkExpectedSecretKeys } from "./dbsecret.js";
|
3
3
|
import { getEnvVariable } from "../../../utils/utils.js";
|
4
4
|
import { logger } from "../dt-logger-default.js";
|
5
|
-
import NodeTtl from "node-ttl";
|
6
5
|
const DEFAULT_PREFIX = "";
|
7
|
-
const DEFAULT_SECRET_KEY = "SECRET";
|
8
6
|
const DEFAULT_CONFIGURATION = {
|
9
7
|
ttl: 5 * 60, // timeout secrets in 5 minutes
|
10
8
|
};
|
@@ -23,12 +21,15 @@ export class SecretHolder {
|
|
23
21
|
secretId;
|
24
22
|
prefix;
|
25
23
|
expectedKeys;
|
26
|
-
|
24
|
+
cachedSecret;
|
25
|
+
expirationTime;
|
26
|
+
ttl; // seconds
|
27
27
|
constructor(secretId, prefix = "", expectedKeys = [], configuration = DEFAULT_CONFIGURATION) {
|
28
28
|
this.secretId = secretId;
|
29
29
|
this.prefix = prefix;
|
30
30
|
this.expectedKeys = expectedKeys;
|
31
|
-
this.
|
31
|
+
this.expirationTime = new Date(0);
|
32
|
+
this.ttl = configuration.ttl;
|
32
33
|
}
|
33
34
|
async initSecret() {
|
34
35
|
const secretValue = await getSecret(this.secretId);
|
@@ -36,7 +37,8 @@ export class SecretHolder {
|
|
36
37
|
method: "SecretHolder.initSecret",
|
37
38
|
message: "Refreshing secret " + this.secretId,
|
38
39
|
});
|
39
|
-
this.
|
40
|
+
this.cachedSecret = secretValue;
|
41
|
+
this.expirationTime = new Date(Date.now() + this.ttl * 1000);
|
40
42
|
}
|
41
43
|
static create(prefix = DEFAULT_PREFIX, expectedKeys = []) {
|
42
44
|
return new SecretHolder(getEnvVariable("SECRET_ID"), prefix, expectedKeys);
|
@@ -67,11 +69,13 @@ export class SecretHolder {
|
|
67
69
|
return parsed;
|
68
70
|
}
|
69
71
|
async getSecret() {
|
70
|
-
|
71
|
-
if (!secret) {
|
72
|
+
if (this.expirationTime.getTime() < Date.now()) {
|
72
73
|
await this.initSecret();
|
73
74
|
}
|
74
|
-
|
75
|
+
if (this.cachedSecret === undefined) {
|
76
|
+
throw new Error("SecretHolder in illegal state");
|
77
|
+
}
|
78
|
+
return this.cachedSecret;
|
75
79
|
}
|
76
80
|
}
|
77
81
|
//# sourceMappingURL=secret-holder.js.map
|
package/dist/utils/logging.js
CHANGED
@@ -53,12 +53,22 @@ export function logException(logger, error, includeStack = false) {
|
|
53
53
|
// In case error is AxiosError, log the custom code property.
|
54
54
|
// eslint-disable-next-line dot-notation
|
55
55
|
const customCode = error["code"];
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
if (customCode) {
|
57
|
+
logger.error({
|
58
|
+
type: "Error",
|
59
|
+
method: `${functionName}.logException`,
|
60
|
+
message: `error=${message}`,
|
61
|
+
customCode,
|
62
|
+
stack,
|
63
|
+
});
|
64
|
+
}
|
65
|
+
else {
|
66
|
+
logger.error({
|
67
|
+
type: "Error",
|
68
|
+
method: `${functionName}.logException`,
|
69
|
+
message: `error=${message}`,
|
70
|
+
stack,
|
71
|
+
});
|
72
|
+
}
|
63
73
|
}
|
64
74
|
//# sourceMappingURL=logging.js.map
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitraffic/common",
|
3
|
-
"version": "2025.
|
3
|
+
"version": "2025.5.5-1",
|
4
4
|
"description": "",
|
5
5
|
"type": "module",
|
6
6
|
"repository": {
|
@@ -104,14 +104,14 @@
|
|
104
104
|
"./dist/aws/runtime/digitraffic-integration-response": "./dist/aws/runtime/digitraffic-integration-response.js"
|
105
105
|
},
|
106
106
|
"peerDependencies": {
|
107
|
-
"@aws-sdk/client-api-gateway": "^3.
|
108
|
-
"@aws-sdk/client-s3": "^3.
|
109
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
110
|
-
"@aws-sdk/client-sns": "^3.
|
111
|
-
"@aws-sdk/lib-storage": "^3.
|
107
|
+
"@aws-sdk/client-api-gateway": "^3.799.0",
|
108
|
+
"@aws-sdk/client-s3": "^3.799.0",
|
109
|
+
"@aws-sdk/client-secrets-manager": "^3.799.0",
|
110
|
+
"@aws-sdk/client-sns": "^3.799.0",
|
111
|
+
"@aws-sdk/lib-storage": "^3.799.0",
|
112
112
|
"@date-fns/tz": "1.2.0",
|
113
113
|
"@smithy/fetch-http-handler": "5.0.2",
|
114
|
-
"aws-cdk-lib": "^2.
|
114
|
+
"aws-cdk-lib": "^2.194.0",
|
115
115
|
"change-case": "^5.4.4",
|
116
116
|
"constructs": "~10.4.2",
|
117
117
|
"date-fns": "~4.1.0",
|
@@ -119,39 +119,37 @@
|
|
119
119
|
"geojson-validation": "^1.0.2",
|
120
120
|
"ky": "^1.7.5",
|
121
121
|
"lodash-es": "^4.17.21",
|
122
|
-
"
|
123
|
-
"pg-native": "^3.3.0",
|
122
|
+
"pg-native": "^3.4.5",
|
124
123
|
"pg-promise": "^11.13.0",
|
125
|
-
"
|
126
|
-
"zod": "^3.24.2"
|
124
|
+
"zod": "^3.24.3"
|
127
125
|
},
|
128
126
|
"devDependencies": {
|
129
|
-
"@aws-sdk/client-api-gateway": "^3.
|
130
|
-
"@aws-sdk/client-s3": "^3.
|
131
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
132
|
-
"@aws-sdk/client-sns": "^3.
|
133
|
-
"@aws-sdk/lib-storage": "^3.
|
127
|
+
"@aws-sdk/client-api-gateway": "^3.799.0",
|
128
|
+
"@aws-sdk/client-s3": "^3.800.0",
|
129
|
+
"@aws-sdk/client-secrets-manager": "^3.799.0",
|
130
|
+
"@aws-sdk/client-sns": "^3.799.0",
|
131
|
+
"@aws-sdk/lib-storage": "^3.800.0",
|
134
132
|
"@date-fns/tz": "1.2.0",
|
135
133
|
"@digitraffic/eslint-config": "^3.1.1",
|
136
134
|
"@jest/globals": "^29.7.0",
|
137
135
|
"@rushstack/eslint-config": "^3.7.1",
|
138
|
-
"@rushstack/heft": "^0.71.
|
136
|
+
"@rushstack/heft": "^0.71.2",
|
139
137
|
"@rushstack/heft-jest-plugin": "^0.15.3",
|
140
|
-
"@rushstack/heft-lint-plugin": "^0.5.
|
141
|
-
"@rushstack/heft-typescript-plugin": "^0.8.
|
138
|
+
"@rushstack/heft-lint-plugin": "^0.5.37",
|
139
|
+
"@rushstack/heft-typescript-plugin": "^0.8.2",
|
142
140
|
"@smithy/fetch-http-handler": "5.0.2",
|
143
141
|
"@smithy/types": "^4.2.0",
|
144
|
-
"@types/aws-lambda": "8.10.
|
142
|
+
"@types/aws-lambda": "8.10.149",
|
145
143
|
"@types/etag": "^1.8.3",
|
146
144
|
"@types/geojson": "7946.0.16",
|
147
145
|
"@types/geojson-validation": "^1.0.3",
|
148
146
|
"@types/jest": "29.5.14",
|
149
147
|
"@types/lodash-es": "4.17.12",
|
150
148
|
"@types/madge": "5.0.3",
|
151
|
-
"@types/node": "22.
|
149
|
+
"@types/node": "22.15.2",
|
152
150
|
"@typescript-eslint/eslint-plugin": "~7.14.1",
|
153
151
|
"@typescript-eslint/parser": "^7.18.0",
|
154
|
-
"aws-cdk-lib": "^2.
|
152
|
+
"aws-cdk-lib": "^2.194.0",
|
155
153
|
"aws-sdk": "^2.1692.0",
|
156
154
|
"change-case": "^5.4.4",
|
157
155
|
"constructs": "~10.4.2",
|
@@ -163,20 +161,18 @@
|
|
163
161
|
"geojson-validation": "^1.0.2",
|
164
162
|
"jest": "^29.7.0",
|
165
163
|
"jest-junit": "^16.0.0",
|
166
|
-
"ky": "^1.
|
167
|
-
"lefthook": "^1.11.
|
164
|
+
"ky": "^1.8.1",
|
165
|
+
"lefthook": "^1.11.12",
|
168
166
|
"lodash": "^4.17.21",
|
169
167
|
"lodash-es": "^4.17.21",
|
170
168
|
"madge": "^8.0.0",
|
171
|
-
"
|
172
|
-
"pg-native": "^3.3.0",
|
169
|
+
"pg-native": "^3.4.5",
|
173
170
|
"pg-promise": "^11.13.0",
|
174
|
-
"pg-query-stream": "4.8.1",
|
175
171
|
"rimraf": "^6.0.1",
|
176
|
-
"ts-jest": "^29.3.
|
177
|
-
"typescript": "~5.
|
178
|
-
"velocityjs": "^2.
|
179
|
-
"zod": "
|
172
|
+
"ts-jest": "^29.3.2",
|
173
|
+
"typescript": "~5.8.3",
|
174
|
+
"velocityjs": "^2.1.5",
|
175
|
+
"zod": "~3.24.3"
|
180
176
|
},
|
181
177
|
"scripts": {
|
182
178
|
"build": "heft build --clean",
|