@vtex/api 1.9.1-beta.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 +6 -2
- package/lib/HttpClient/index.js +0 -1
- package/lib/HttpClient/middlewares/cache.js +0 -1
- package/lib/HttpClient/middlewares/metrics.js +0 -1
- package/lib/HttpClient/middlewares/notFound.js +0 -2
- package/lib/HttpClient/middlewares/recorder.js +0 -1
- package/lib/HttpClient/middlewares/request.js +2 -4
- 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/#package.json# +0 -53
package/CHANGELOG.md
CHANGED
|
@@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [1.9.
|
|
10
|
+
## [1.9.2] - 2022-03-08
|
|
11
|
+
### Fixed
|
|
12
|
+
- Only remove sensitive fields from logs.
|
|
11
13
|
|
|
12
|
-
## [1.9.1
|
|
14
|
+
## [1.9.1] - 2022-02-24
|
|
15
|
+
### Fixed
|
|
16
|
+
- Remove sensitive data from logs.
|
|
13
17
|
|
|
14
18
|
## [1.9.0] - 2019-02-25
|
|
15
19
|
### Added
|
package/lib/HttpClient/index.js
CHANGED
|
@@ -73,7 +73,6 @@ class HttpClient {
|
|
|
73
73
|
this.request = (config) => __awaiter(this, void 0, void 0, function* () {
|
|
74
74
|
const context = { config };
|
|
75
75
|
yield this.runMiddlewares(context);
|
|
76
|
-
console.error('finished middlewares, returning response =', context.response);
|
|
77
76
|
return context.response;
|
|
78
77
|
});
|
|
79
78
|
const { baseURL, authToken, authType, cacheStorage, metrics, recorder, userAgent, timeout = DEFAULT_TIMEOUT_MS, segmentToken } = opts;
|
|
@@ -38,7 +38,6 @@ function isCacheable(arg) {
|
|
|
38
38
|
const addNotModified = (validateStatus) => (status) => validateStatus(status) || status === 304;
|
|
39
39
|
exports.cacheMiddleware = ({ cacheStorage, segmentToken }) => {
|
|
40
40
|
return (ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
console.error('cacheMiddleware');
|
|
42
41
|
if (!isCacheable(ctx.config)) {
|
|
43
42
|
return yield next();
|
|
44
43
|
}
|
|
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
const statusLabel = (status) => `${Math.floor(status / 100)}xx`;
|
|
12
12
|
exports.metricsMiddleware = (metrics) => {
|
|
13
13
|
return (ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
console.error('metricsMiddleware');
|
|
15
14
|
const start = ctx.config.metric && process.hrtime();
|
|
16
15
|
const production = ctx.config.production || false;
|
|
17
16
|
let status;
|
|
@@ -13,7 +13,6 @@ function nullIfNotFound(config) {
|
|
|
13
13
|
return config && config.nullIfNotFound;
|
|
14
14
|
}
|
|
15
15
|
exports.acceptNotFoundMiddleware = (ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
console.error('acceptNotFoundMiddleware');
|
|
17
16
|
const { config } = ctx;
|
|
18
17
|
if (nullIfNotFound(config)) {
|
|
19
18
|
ctx.config.validateStatus = addNotFound(config.validateStatus);
|
|
@@ -21,7 +20,6 @@ exports.acceptNotFoundMiddleware = (ctx, next) => __awaiter(this, void 0, void 0
|
|
|
21
20
|
yield next();
|
|
22
21
|
});
|
|
23
22
|
exports.notFoundFallbackMiddleware = (ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
console.error('notFoundFallbackMiddleware');
|
|
25
23
|
yield next();
|
|
26
24
|
const { config } = ctx;
|
|
27
25
|
if (nullIfNotFound(config) && ctx.response && ctx.response.status === 404) {
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.recorderMiddleware = (recorder) => {
|
|
12
12
|
return (ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
console.error('recorderMiddleware');
|
|
14
13
|
try {
|
|
15
14
|
yield next();
|
|
16
15
|
if (ctx.response) {
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
const axios_1 = require("axios");
|
|
12
|
-
|
|
12
|
+
const retry = require("axios-retry");
|
|
13
13
|
const http_1 = require("http");
|
|
14
14
|
const http = axios_1.default.create({
|
|
15
15
|
httpAgent: new http_1.Agent({
|
|
@@ -17,7 +17,7 @@ const http = axios_1.default.create({
|
|
|
17
17
|
maxFreeSockets: 50,
|
|
18
18
|
}),
|
|
19
19
|
});
|
|
20
|
-
|
|
20
|
+
retry(http);
|
|
21
21
|
http.interceptors.response.use(response => response, (err) => {
|
|
22
22
|
try {
|
|
23
23
|
delete err.response.request;
|
|
@@ -30,12 +30,10 @@ http.interceptors.response.use(response => response, (err) => {
|
|
|
30
30
|
});
|
|
31
31
|
exports.defaultsMiddleware = (baseURL, headers, timeout) => {
|
|
32
32
|
return (ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
console.error('defaultsMiddleware');
|
|
34
33
|
ctx.config = Object.assign({ baseURL, maxRedirects: 0, timeout, validateStatus: status => (status >= 200 && status < 300) }, ctx.config, { headers: Object.assign({}, headers, ctx.config.headers) });
|
|
35
34
|
yield next();
|
|
36
35
|
});
|
|
37
36
|
};
|
|
38
37
|
exports.requestMiddleware = (ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
console.error('requestMiddleware');
|
|
40
38
|
ctx.response = yield http.request(ctx.config);
|
|
41
39
|
});
|
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
|
+
};
|
package/package.json
CHANGED
package/#package.json#
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@vtex/api",
|
|
3
|
-
"version": "0.48.1-beta.6",
|
|
4
|
-
"description": "VTEX I/O API client",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"typings": "lib/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"clean": "rimraf lib/",
|
|
9
|
-
"watch": "tsc --watch",
|
|
10
|
-
"build": "tsc",
|
|
11
|
-
"lint": "tsc --noEmit && tslint src/*.ts",
|
|
12
|
-
"prepublish": "run-s clean build"
|
|
13
|
-
},
|
|
14
|
-
"engines": {
|
|
15
|
-
"node": ">=6"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"vtex"
|
|
19
|
-
],
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "git@github.com:vtex/node-vtex-api.git"
|
|
23
|
-
},
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@types/lru-cache": "^4.1.1",
|
|
27
|
-
"archiver": "^2.1.0",
|
|
28
|
-
"axios": "^0.16.0",
|
|
29
|
-
"axios-retry": "^1.2.0",
|
|
30
|
-
"koa-compose": "^4.1.0",
|
|
31
|
-
"lru-cache": "^4.1.3",
|
|
32
|
-
"mime-types": "^2.1.12",
|
|
33
|
-
"multipart-stream": "^2.0.1",
|
|
34
|
-
"qs": "^6.5.1",
|
|
35
|
-
"semver": "^5.5.1",
|
|
36
|
-
"tar-fs": "^1.15.3"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@types/archiver": "^2.0.1",
|
|
40
|
-
"@types/koa-compose": "^3.2.2",
|
|
41
|
-
"@types/lru-cache": "^4.1.1",
|
|
42
|
-
"@types/mime-types": "^2.1.0",
|
|
43
|
-
"@types/node": "^8.0.14",
|
|
44
|
-
"@types/qs": "^6.5.1",
|
|
45
|
-
"@types/semver": "^5.5.0",
|
|
46
|
-
"npm-run-all": "^2.3.0",
|
|
47
|
-
"rimraf": "^2.5.2",
|
|
48
|
-
"tslint": "^4.0.0",
|
|
49
|
-
"tslint-config-vtex": "^1.3.1",
|
|
50
|
-
"tslint-eslint-rules": "^4.1.1",
|
|
51
|
-
"typescript": "^2.7.1"
|
|
52
|
-
}
|
|
53
|
-
}
|