@vtex/api 3.77.4 → 3.77.5
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 +4 -0
- package/lib/service/graphql/middlewares/formatters.js +3 -2
- package/lib/service/http/middlewares/error.js +2 -1
- package/lib/service/logger/index.js +2 -0
- package/lib/utils/error.d.ts +0 -1
- package/lib/utils/error.js +0 -1
- package/lib/utils/log.d.ts +3 -0
- package/lib/utils/log.js +14 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const apollo_server_errors_1 = require("apollo-server-errors");
|
|
4
4
|
const ramda_1 = require("ramda");
|
|
5
5
|
const error_1 = require("../../../utils/error");
|
|
6
|
+
const log_1 = require("../../../utils/log");
|
|
6
7
|
const ERROR_FIELD_WHITELIST = ['message', 'path', 'stack', 'extensions', 'statusCode', 'name', 'headers', 'originalError', 'code'];
|
|
7
8
|
// formatError overrides the default option in runHttpQuery, which
|
|
8
9
|
// does not keep track of the error stack. All non-enumerable
|
|
@@ -21,11 +22,11 @@ const createFormatError = (details) => (error) => {
|
|
|
21
22
|
delete formattedError.originalError.stack;
|
|
22
23
|
}
|
|
23
24
|
if (!formattedError.extensions.exception) {
|
|
24
|
-
formattedError.extensions.exception = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(
|
|
25
|
+
formattedError.extensions.exception = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, formattedError.originalError), { sensitive: ramda_1.pick(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, formattedError.originalError) });
|
|
25
26
|
}
|
|
26
27
|
else {
|
|
27
28
|
const mergedExceptions = Object.assign({}, formattedError.originalError, formattedError.extensions.exception);
|
|
28
|
-
const extendedException = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(
|
|
29
|
+
const extendedException = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, mergedExceptions), { sensitive: ramda_1.pick(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, mergedExceptions) });
|
|
29
30
|
formattedError.extensions.exception = error_1.cleanError(extendedException);
|
|
30
31
|
}
|
|
31
32
|
// Make originalError not enumerable to prevent duplicated log and response information
|
|
@@ -5,6 +5,7 @@ const constants_1 = require("../../../constants");
|
|
|
5
5
|
const RequestCancelledError_1 = require("../../../errors/RequestCancelledError");
|
|
6
6
|
const TooManyRequestsError_1 = require("../../../errors/TooManyRequestsError");
|
|
7
7
|
const error_1 = require("../../../utils/error");
|
|
8
|
+
const log_1 = require("../../../utils/log");
|
|
8
9
|
const CACHE_CONTROL_HEADER = 'cache-control';
|
|
9
10
|
const META_HEADER = 'x-vtex-meta';
|
|
10
11
|
const ETAG_HEADER = 'etag';
|
|
@@ -32,7 +33,7 @@ const logAndRemoveSensitiveData = (ctx, err) => {
|
|
|
32
33
|
// Use sendLog directly to avoid cleaning error twice.
|
|
33
34
|
ctx.vtex.logger.log(log, level);
|
|
34
35
|
if (!constants_1.LINKED) {
|
|
35
|
-
|
|
36
|
+
log_1.FIRST_LEVEL_SENSITIVE_FIELDS.forEach(field => {
|
|
36
37
|
delete err[field];
|
|
37
38
|
});
|
|
38
39
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const error_1 = require("../../utils/error");
|
|
4
|
+
const log_1 = require("../../utils/log");
|
|
4
5
|
const linked = !!process.env.VTEX_APP_LINK;
|
|
5
6
|
const app = process.env.VTEX_APP_ID;
|
|
6
7
|
const EMPTY_MESSAGE = 'Logger.log was called with null or undefined message';
|
|
@@ -22,6 +23,7 @@ class Logger {
|
|
|
22
23
|
this.error = (error) => this.log(error, LogLevel.Error);
|
|
23
24
|
this.log = (message, level) => {
|
|
24
25
|
const data = message ? error_1.cleanError(message) : EMPTY_MESSAGE;
|
|
26
|
+
log_1.cleanLog(data);
|
|
25
27
|
/* tslint:disable:object-literal-sort-keys */
|
|
26
28
|
const inflatedLog = {
|
|
27
29
|
__VTEX_IO_LOG: true,
|
package/lib/utils/error.d.ts
CHANGED
package/lib/utils/error.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
// Inspired by https://github.com/sindresorhus/serialize-error
|
|
4
4
|
const ramda_1 = require("ramda");
|
|
5
5
|
exports.PICKED_AXIOS_PROPS = ['baseURL', 'cacheable', 'data', 'finished', 'headers', 'method', 'timeout', 'status', 'path', 'url', 'metric', 'inflightKey', 'forceMaxAge', 'params', 'responseType'];
|
|
6
|
-
exports.SENSITIVE_EXCEPTION_FIELDS = ['config', 'request', 'stack'];
|
|
7
6
|
const MAX_ERROR_STRING_LENGTH = process.env.MAX_ERROR_STRING_LENGTH ? parseInt(process.env.MAX_ERROR_STRING_LENGTH, 10) : 8 * 1024;
|
|
8
7
|
const findCaseInsensitive = (target, set) => ramda_1.find(t => t.toLocaleLowerCase() === target, set);
|
|
9
8
|
const destroyCircular = (from, seen) => {
|
package/lib/utils/log.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FIRST_LEVEL_SENSITIVE_FIELDS = ['config', 'request', 'stack', 'error'];
|
|
4
|
+
exports.SECOND_LEVEL_SENSITIVE_FIELDS = [['parsedInfo', 'requestConfig'], ['headers', 'cookie']];
|
|
5
|
+
exports.cleanLog = (log) => {
|
|
6
|
+
exports.FIRST_LEVEL_SENSITIVE_FIELDS.forEach(field => {
|
|
7
|
+
delete log[field];
|
|
8
|
+
});
|
|
9
|
+
exports.SECOND_LEVEL_SENSITIVE_FIELDS.forEach(field => {
|
|
10
|
+
if (field[0] in log) {
|
|
11
|
+
delete log[field[0]][field[1]];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
};
|