@vtex/api 1.9.0 → 1.9.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/CHANGELOG.md +8 -0
- package/lib/Logger.js +5 -3
- package/lib/utils/json.d.ts +5 -0
- package/lib/utils/json.js +18 -0
- package/lib/utils/log.d.ts +3 -0
- package/lib/utils/log.js +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.9.2] - 2022-03-08
|
|
11
|
+
### Fixed
|
|
12
|
+
- Only remove sensitive fields from logs.
|
|
13
|
+
|
|
14
|
+
## [1.9.1] - 2022-02-24
|
|
15
|
+
### Fixed
|
|
16
|
+
- Remove sensitive data from logs.
|
|
17
|
+
|
|
10
18
|
## [1.9.0] - 2019-02-25
|
|
11
19
|
### Added
|
|
12
20
|
- Functions that call new Apps API for dependency resolution.
|
package/lib/Logger.js
CHANGED
|
@@ -14,6 +14,7 @@ const PQueue = require("p-queue");
|
|
|
14
14
|
const ramda_1 = require("ramda");
|
|
15
15
|
const HttpClient_1 = require("./HttpClient");
|
|
16
16
|
const IODataSource_1 = require("./IODataSource");
|
|
17
|
+
const log_1 = require("./utils/log");
|
|
17
18
|
const DEFAULT_SUBJECT = '-';
|
|
18
19
|
const PICKED_AXIOS_PROPS = ['baseURL', 'cacheable', 'data', 'finished', 'headers', 'method', 'timeout', 'status', 'path', 'url'];
|
|
19
20
|
const queue = new PQueue({ concurrency: 1 });
|
|
@@ -46,11 +47,12 @@ class Logger extends IODataSource_1.IODataSource {
|
|
|
46
47
|
error.code = 'ERR_NIL_ERR';
|
|
47
48
|
console.error(error);
|
|
48
49
|
}
|
|
49
|
-
const { code: errorCode, message,
|
|
50
|
+
const { code: errorCode, message, response } = error, rest = __rest(error, ["code", "message", "response"]);
|
|
51
|
+
log_1.removeSensitiveData(rest);
|
|
50
52
|
const code = errorCode || response && `http-${response.status}`;
|
|
51
|
-
const pickedDetails = Object.assign({},
|
|
53
|
+
const pickedDetails = Object.assign({}, response ? { response: ramda_1.pick(PICKED_AXIOS_PROPS, response) } : undefined, JSON.parse(stringify(rest, errorReplacer)), details);
|
|
52
54
|
const hasDetails = Object.keys(pickedDetails).length > 0;
|
|
53
|
-
return this.sendLog(subject, { code, message,
|
|
55
|
+
return this.sendLog(subject, { code, message, details: hasDetails ? pickedDetails : undefined }, 'error');
|
|
54
56
|
};
|
|
55
57
|
this.sendLog = (subject, message, level) => {
|
|
56
58
|
return queue.add(() => this.http.put(routes.Log(level), message, { params: { subject } }));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function cleanJson(json, targetFields) {
|
|
4
|
+
for (const key of Object.keys(json)) {
|
|
5
|
+
let deleted = false;
|
|
6
|
+
for (const field of targetFields) {
|
|
7
|
+
if (key === field) {
|
|
8
|
+
delete json[key];
|
|
9
|
+
deleted = true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (!deleted && json[key] && typeof json[key] === 'object') {
|
|
13
|
+
json[key] = cleanJson(json[key], targetFields);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return json;
|
|
17
|
+
}
|
|
18
|
+
exports.cleanJson = cleanJson;
|
package/lib/utils/log.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const json_1 = require("./json");
|
|
4
|
+
const SENSITIVE_FIELDS = ['cookie', 'Cookie', 'vtexIdclientautcookie', 'error'];
|
|
5
|
+
exports.removeSensitiveData = (log) => {
|
|
6
|
+
return json_1.cleanJson(log, SENSITIVE_FIELDS);
|
|
7
|
+
};
|