@vtex/api 6.45.13-beta.3 → 6.45.13
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 +9 -0
- package/lib/HttpClient/HttpClient.d.ts +1 -0
- package/lib/HttpClient/HttpClient.js +13 -2
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +1 -4
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +6 -13
- package/lib/service/worker/runtime/utils/context.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.45.13] - 2022-12-12
|
|
11
|
+
### Changed
|
|
12
|
+
- Deterministic cache for getWithBody
|
|
13
|
+
- Remove socket metrics per origin
|
|
14
|
+
|
|
10
15
|
## [6.45.12] - 2022-04-14
|
|
11
16
|
|
|
12
17
|
### Fixed
|
|
@@ -1734,3 +1739,7 @@ instead
|
|
|
1734
1739
|
### Changed
|
|
1735
1740
|
|
|
1736
1741
|
- `HttpClient` now adds `'Accept-Encoding': 'gzip'` header by default.
|
|
1742
|
+
|
|
1743
|
+
|
|
1744
|
+
[Unreleased]: https://github.com/vtex/node-vtex-api/compare/v6.45.13...HEAD
|
|
1745
|
+
[6.45.13]: https://github.com/vtex/node-vtex-api/compare/v6.45.12...v6.45.13
|
|
@@ -6,6 +6,7 @@ import { InstanceOptions, IOResponse, RequestConfig } from './typings';
|
|
|
6
6
|
declare type ClientOptions = IOContext & Partial<InstanceOptions>;
|
|
7
7
|
export declare class HttpClient {
|
|
8
8
|
name: string;
|
|
9
|
+
private logger;
|
|
9
10
|
private runMiddlewares;
|
|
10
11
|
constructor(opts: ClientOptions);
|
|
11
12
|
get: <T = any>(url: string, config?: RequestConfig) => Promise<T>;
|
|
@@ -31,8 +31,18 @@ class HttpClient {
|
|
|
31
31
|
return this.request(cacheableConfig);
|
|
32
32
|
};
|
|
33
33
|
this.getWithBody = (url, data, config = {}) => {
|
|
34
|
-
const deterministicReplacer = (_, v) =>
|
|
35
|
-
|
|
34
|
+
const deterministicReplacer = (_, v) => {
|
|
35
|
+
try {
|
|
36
|
+
return typeof v !== 'object' || v === null || Array.isArray(v) ? v :
|
|
37
|
+
Object.fromEntries(Object.entries(v).sort(([ka], [kb]) => ka < kb ? -1 : ka > kb ? 1 : 0));
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
// I don't believe this will ever happen, but just in case
|
|
41
|
+
// Also, I didn't include error as I am unsure if it would have sensitive information
|
|
42
|
+
this.logger.warn({ message: 'Error while sorting object for cache key' });
|
|
43
|
+
return v;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
36
46
|
const bodyHash = crypto_1.createHash('md5').update(JSON.stringify(data, deterministicReplacer)).digest('hex');
|
|
37
47
|
const cacheableConfig = this.getConfig(url, {
|
|
38
48
|
...config,
|
|
@@ -93,6 +103,7 @@ class HttpClient {
|
|
|
93
103
|
});
|
|
94
104
|
const { baseURL, authToken, authType, memoryCache, diskCache, locale, name, metrics, product, serverTiming, recorder, userAgent, timeout = DEFAULT_TIMEOUT_MS, segmentToken, sessionToken, retries, concurrency, headers: defaultHeaders, host, params, operationId, tenant, binding, verbose, cancellation, exponentialTimeoutCoefficient, initialBackoffDelay, exponentialBackoffCoefficient, httpsAgent, tracer, logger, } = opts;
|
|
95
105
|
this.name = name || baseURL || 'unknown';
|
|
106
|
+
this.logger = logger;
|
|
96
107
|
const limit = concurrency && concurrency > 0 && p_limit_1.default(concurrency) || undefined;
|
|
97
108
|
const headers = {
|
|
98
109
|
...defaultHeaders,
|
|
@@ -3,12 +3,9 @@ export declare class HttpAgentSingleton {
|
|
|
3
3
|
static getHttpAgent(): HttpAgent;
|
|
4
4
|
static httpAgentStats(): {
|
|
5
5
|
freeSockets: number;
|
|
6
|
-
freeSocketsPerOrigin: Record<string, number>;
|
|
7
6
|
pendingRequests: number;
|
|
8
|
-
pendingRequestsPerOrigin: Record<string, number>;
|
|
9
7
|
sockets: number;
|
|
10
|
-
socketsPerOrigin: Record<string, number>;
|
|
11
8
|
};
|
|
12
9
|
private static httpAgent;
|
|
13
|
-
private static
|
|
10
|
+
private static count;
|
|
14
11
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ramda_1 = require("ramda");
|
|
4
3
|
const agents_1 = require("../../agents");
|
|
5
4
|
class HttpAgentSingleton {
|
|
6
5
|
static getHttpAgent() {
|
|
@@ -10,27 +9,21 @@ class HttpAgentSingleton {
|
|
|
10
9
|
return HttpAgentSingleton.httpAgent;
|
|
11
10
|
}
|
|
12
11
|
static httpAgentStats() {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const freeSockets = ramda_1.sum(ramda_1.values(freeSocketsPerOrigin));
|
|
17
|
-
const pendingRequestsPerOrigin = HttpAgentSingleton.countPerOrigin(HttpAgentSingleton.httpAgent.requests);
|
|
18
|
-
const pendingRequests = ramda_1.sum(ramda_1.values(pendingRequestsPerOrigin));
|
|
12
|
+
const sockets = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.sockets);
|
|
13
|
+
const freeSockets = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.freeSockets);
|
|
14
|
+
const pendingRequests = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.requests);
|
|
19
15
|
return {
|
|
20
16
|
freeSockets,
|
|
21
|
-
freeSocketsPerOrigin,
|
|
22
17
|
pendingRequests,
|
|
23
|
-
pendingRequestsPerOrigin,
|
|
24
18
|
sockets,
|
|
25
|
-
socketsPerOrigin,
|
|
26
19
|
};
|
|
27
20
|
}
|
|
28
|
-
static
|
|
21
|
+
static count(obj) {
|
|
29
22
|
try {
|
|
30
|
-
return
|
|
23
|
+
return Object.values(obj).reduce((acc, val) => acc += val.length, 0);
|
|
31
24
|
}
|
|
32
25
|
catch (_) {
|
|
33
|
-
return
|
|
26
|
+
return 0;
|
|
34
27
|
}
|
|
35
28
|
}
|
|
36
29
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IOContext, TracingContext } from '../typings';
|
|
2
|
-
export declare const prepareHandlerCtx: (header: any, tracingContext: TracingContext) => Pick<IOContext, "host" | "
|
|
2
|
+
export declare const prepareHandlerCtx: (header: any, tracingContext: TracingContext) => Pick<IOContext, "host" | "serverTiming" | "locale" | "account" | "workspace" | "region" | "logger" | "requestId" | "operationId" | "production" | "platform" | "authToken" | "adminUserAuthToken" | "storeUserAuthToken" | "product" | "recorder" | "userAgent" | "segmentToken" | "sessionToken" | "janusEnv" | "eventInfo" | "tenant" | "binding" | "cancellation" | "settings" | "tracer">;
|