@vtex/api 6.45.23 → 6.45.25-beta.0

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
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [6.45.24] - 2023-10-05
11
+ ### Added
12
+
13
+ - Allow disabling memoization for all requests of a client
10
14
  ## [6.45.23] - 2023-10-04
11
15
 
12
16
  ### Fixed
@@ -8,6 +8,7 @@ export declare class HttpClient {
8
8
  name: string;
9
9
  private logger;
10
10
  private cacheableType;
11
+ private memoizable;
11
12
  private runMiddlewares;
12
13
  constructor(opts: ClientOptions);
13
14
  get: <T = any>(url: string, config?: RequestConfig) => Promise<T>;
@@ -97,14 +97,15 @@ class HttpClient {
97
97
  };
98
98
  this.getConfig = (url, config = {}) => ({
99
99
  cacheable: this.cacheableType,
100
- memoizable: true,
100
+ memoizable: this.memoizable,
101
101
  ...config,
102
102
  url,
103
103
  });
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, cacheableType = cache_1.CacheType.Memory, } = opts;
104
+ const { baseURL, authToken, authType, memoryCache, diskCache, memoizable = true, 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, cacheableType = cache_1.CacheType.Memory, } = opts;
105
105
  this.name = name || baseURL || 'unknown';
106
106
  this.logger = logger;
107
107
  this.cacheableType = cacheableType;
108
+ this.memoizable = memoizable;
108
109
  const limit = concurrency && concurrency > 0 && p_limit_1.default(concurrency) || undefined;
109
110
  const headers = {
110
111
  ...defaultHeaders,
@@ -150,7 +150,7 @@ exports.cacheMiddleware = ({ type, storage }) => {
150
150
  ? data.toString(responseEncoding)
151
151
  : data;
152
152
  const expiration = Date.now() + (maxAge - currentAge) * 1000;
153
- await storage.set(setKey, {
153
+ storage.set(setKey, {
154
154
  etag,
155
155
  expiration,
156
156
  response: { data: cacheableData, headers, status },
@@ -74,6 +74,16 @@ export interface InstanceOptions {
74
74
  timeout?: number;
75
75
  memoryCache?: CacheLayer<string, Cached>;
76
76
  diskCache?: CacheLayer<string, Cached>;
77
+ /**
78
+ * Enables memoization, ephemeral within each request, for all requests of this client.
79
+ * Useful for services that makes recursive requests, like graphql resolvers, which
80
+ * might fetch the same endpoint more than once.
81
+ * If that's not the case for your service, disabling it might improve the CPU and
82
+ * memory usage.
83
+ *
84
+ * Default value: true
85
+ */
86
+ memoizable?: boolean;
77
87
  baseURL?: string;
78
88
  retries?: number;
79
89
  exponentialTimeoutCoefficient?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/api",
3
- "version": "6.45.23",
3
+ "version": "6.45.25-beta.0",
4
4
  "description": "VTEX I/O API client",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",