@vtex/api 6.45.14-beta.0 → 6.45.14-beta.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/CHANGELOG.md
CHANGED
|
@@ -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,7 +31,19 @@ class HttpClient {
|
|
|
31
31
|
return this.request(cacheableConfig);
|
|
32
32
|
};
|
|
33
33
|
this.getWithBody = (url, data, config = {}) => {
|
|
34
|
-
const
|
|
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
|
+
};
|
|
46
|
+
const bodyHash = crypto_1.createHash('md5').update(JSON.stringify(data, deterministicReplacer)).digest('hex');
|
|
35
47
|
const cacheableConfig = this.getConfig(url, {
|
|
36
48
|
...config,
|
|
37
49
|
data,
|
|
@@ -91,6 +103,7 @@ class HttpClient {
|
|
|
91
103
|
});
|
|
92
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;
|
|
93
105
|
this.name = name || baseURL || 'unknown';
|
|
106
|
+
this.logger = logger;
|
|
94
107
|
const limit = concurrency && concurrency > 0 && p_limit_1.default(concurrency) || undefined;
|
|
95
108
|
const headers = {
|
|
96
109
|
...defaultHeaders,
|
|
@@ -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">;
|