@vtex/api 6.46.0 → 6.47.0-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,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## Fixed
11
+ - Add handler name for runtime http handlers
12
+
13
+ ## [6.46.1] - 2024-01-31
14
+
15
+ ### Fixed
16
+ - Return type for the saveJSON method of VBase client
17
+
18
+ ### Changed
19
+ - Increase timeout for messagesGraphQL client
20
+
10
21
  ## [6.46.0] - 2023-10-25
11
22
  ### Added
12
23
  - Add disk cache steps and retry count to tracing
@@ -134,7 +145,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
134
145
 
135
146
  ## [6.54.5] - 2021-10-22
136
147
 
137
- ### Fixed
148
+ ### Fixed
138
149
 
139
150
  - Extract session cookie in a safe manner
140
151
 
@@ -101,7 +101,7 @@ class HttpClient {
101
101
  ...config,
102
102
  url,
103
103
  });
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;
104
+ const { baseURL, authToken, authType, memoryCache, diskCache, memoizable = true, asyncSetCache, 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;
@@ -134,8 +134,8 @@ class HttpClient {
134
134
  cancellationToken_1.cancellationToken(cancellation),
135
135
  inflight_1.singleFlightMiddleware,
136
136
  notFound_1.acceptNotFoundMiddleware,
137
- ...memoryCache ? [cache_1.cacheMiddleware({ type: cache_1.CacheType.Memory, storage: memoryCache })] : [],
138
- ...diskCache ? [cache_1.cacheMiddleware({ type: cache_1.CacheType.Disk, storage: diskCache })] : [],
137
+ ...memoryCache ? [cache_1.cacheMiddleware({ type: cache_1.CacheType.Memory, storage: memoryCache, asyncSet: asyncSetCache })] : [],
138
+ ...diskCache ? [cache_1.cacheMiddleware({ type: cache_1.CacheType.Disk, storage: diskCache, asyncSet: asyncSetCache })] : [],
139
139
  notFound_1.notFoundFallbackMiddleware,
140
140
  request_1.routerCacheMiddleware,
141
141
  request_1.requestMiddleware(limit),
@@ -18,8 +18,9 @@ export declare const enum CacheResult {
18
18
  interface CacheOptions {
19
19
  type: CacheType;
20
20
  storage: CacheLayer<string, Cached>;
21
+ asyncSet?: boolean;
21
22
  }
22
- export declare const cacheMiddleware: ({ type, storage }: CacheOptions) => (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
23
+ export declare const cacheMiddleware: ({ type, storage, asyncSet }: CacheOptions) => (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
23
24
  export interface Cached {
24
25
  etag: string;
25
26
  expiration: number;
@@ -52,7 +52,7 @@ const CacheTypeNames = {
52
52
  [CacheType.Disk]: 'disk',
53
53
  [CacheType.Any]: 'any',
54
54
  };
55
- exports.cacheMiddleware = ({ type, storage }) => {
55
+ exports.cacheMiddleware = ({ type, storage, asyncSet }) => {
56
56
  const CACHE_RESULT_TAG = type === CacheType.Disk ? "http.cache.disk" /* HTTP_DISK_CACHE_RESULT */ : "http.cache.memory" /* HTTP_MEMORY_CACHE_RESULT */;
57
57
  const cacheType = CacheTypeNames[type];
58
58
  return async (ctx, next) => {
@@ -171,23 +171,29 @@ exports.cacheMiddleware = ({ type, storage }) => {
171
171
  }
172
172
  const cacheWriteSpan = createCacheSpan(cacheType, 'write', tracer, span);
173
173
  try {
174
- await storage.set(setKey, {
174
+ const storageSet = () => storage.set(setKey, {
175
175
  etag,
176
176
  expiration,
177
177
  response: { data: cacheableData, headers, status },
178
178
  responseEncoding,
179
179
  responseType,
180
180
  });
181
- span === null || span === void 0 ? void 0 : span.log({
182
- event: "local-cache-saved" /* LOCAL_CACHE_SAVED */,
183
- ["cache-type" /* CACHE_TYPE */]: cacheType,
184
- ["key-set" /* KEY_SET */]: setKey,
185
- ["age" /* AGE */]: currentAge,
186
- ["etag" /* ETAG */]: etag,
187
- ["expiration-time" /* EXPIRATION_TIME */]: (expiration - Date.now()) / 1000,
188
- ["response-encoding" /* RESPONSE_ENCONDING */]: responseEncoding,
189
- ["response-type" /* RESPONSE_TYPE */]: responseType,
190
- });
181
+ if (asyncSet) {
182
+ storageSet();
183
+ }
184
+ else {
185
+ await storageSet();
186
+ span === null || span === void 0 ? void 0 : span.log({
187
+ event: "local-cache-saved" /* LOCAL_CACHE_SAVED */,
188
+ ["cache-type" /* CACHE_TYPE */]: cacheType,
189
+ ["key-set" /* KEY_SET */]: setKey,
190
+ ["age" /* AGE */]: currentAge,
191
+ ["etag" /* ETAG */]: etag,
192
+ ["expiration-time" /* EXPIRATION_TIME */]: (expiration - Date.now()) / 1000,
193
+ ["response-encoding" /* RESPONSE_ENCONDING */]: responseEncoding,
194
+ ["response-type" /* RESPONSE_TYPE */]: responseType,
195
+ });
196
+ }
191
197
  }
192
198
  catch (error) {
193
199
  tracing_1.ErrorReport.create({ originalError: error }).injectOnSpan(cacheWriteSpan);
@@ -74,6 +74,7 @@ export interface InstanceOptions {
74
74
  timeout?: number;
75
75
  memoryCache?: CacheLayer<string, Cached>;
76
76
  diskCache?: CacheLayer<string, Cached>;
77
+ asyncSetCache?: boolean;
77
78
  /**
78
79
  * Enables memoization, ephemeral within each request, for all requests of this client.
79
80
  * Useful for services that makes recursive requests, like graphql resolvers, which
@@ -3,7 +3,7 @@ import { IncomingMessage } from 'http';
3
3
  import { Readable } from 'stream';
4
4
  import { Logger } from './../../service/logger/logger';
5
5
  import { InstanceOptions, IOResponse, RequestTracingConfig } from '../../HttpClient';
6
- import { BucketMetadata, FileListItem } from '../../responses';
6
+ import { BucketMetadata, FileListItem, VBaseSaveResponse } from '../../responses';
7
7
  import { IOContext } from '../../service/worker/runtime/typings';
8
8
  import { InfraClient } from './InfraClient';
9
9
  export declare class VBase extends InfraClient {
@@ -20,7 +20,7 @@ export declare class VBase extends InfraClient {
20
20
  getFileStream: (bucket: string, path: string, tracingConfig?: RequestTracingConfig | undefined) => Promise<IncomingMessage>;
21
21
  saveFile: (bucket: string, path: string, stream: Readable, gzip?: boolean, ttl?: number | undefined, tracingConfig?: RequestTracingConfig | undefined, ifMatch?: string | undefined) => Promise<void>;
22
22
  getFileMetadata: (bucket: string, path: string, tracingConfig?: RequestTracingConfig | undefined) => Promise<IOResponse<void>>;
23
- saveJSON: <T>(bucket: string, path: string, data: T, tracingConfig?: RequestTracingConfig | undefined, ifMatch?: string | undefined) => Promise<void>;
23
+ saveJSON: <T>(bucket: string, path: string, data: T, tracingConfig?: RequestTracingConfig | undefined, ifMatch?: string | undefined) => Promise<VBaseSaveResponse>;
24
24
  saveZippedContent: (bucket: string, path: string, stream: Readable, tracingConfig?: RequestTracingConfig | undefined, ifMatch?: string | undefined) => Promise<void>;
25
25
  deleteFile: (bucket: string, path: string, tracingConfig?: RequestTracingConfig | undefined, ifMatch?: string | undefined) => Promise<IOResponse<void>>;
26
26
  getConflicts: <T>(bucket: string, tracingConfig?: RequestTracingConfig | undefined) => Promise<T>;
@@ -76,4 +76,5 @@ export interface HousekeeperStatesAndUpdates {
76
76
  state: HouseKeeperState;
77
77
  updates: HouseKeeperUpdates;
78
78
  }
79
+ export declare type VBaseSaveResponse = FileListItem[];
79
80
  export {};
@@ -33,9 +33,9 @@ const defaultClients = {
33
33
  timeout: 1000,
34
34
  },
35
35
  messagesGraphQL: {
36
- concurrency: 10,
36
+ concurrency: 12,
37
37
  retries: 2,
38
- timeout: 1000,
38
+ timeout: 2000,
39
39
  },
40
40
  },
41
41
  };
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.whoAmIHandler = ({ events, routes, }) => (ctx) => {
4
4
  var _a, _b;
5
- (_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName('builtin:whoami');
5
+ ctx.requestHandlerName = 'builtin:whoami';
6
+ (_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName(ctx.requestHandlerName);
6
7
  ctx.status = 200;
7
8
  ctx.body = {
8
9
  events,
@@ -12,7 +13,8 @@ exports.whoAmIHandler = ({ events, routes, }) => (ctx) => {
12
13
  };
13
14
  exports.healthcheckHandler = ({ events, routes, }) => (ctx) => {
14
15
  var _a, _b;
15
- (_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName('builtin:healthcheck');
16
+ ctx.requestHandlerName = 'builtin:healthcheck';
17
+ (_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName(ctx.requestHandlerName);
16
18
  ctx.status = 200;
17
19
  ctx.body = {
18
20
  events,
@@ -21,7 +23,8 @@ exports.healthcheckHandler = ({ events, routes, }) => (ctx) => {
21
23
  };
22
24
  exports.metricsLoggerHandler = (ctx) => {
23
25
  var _a, _b;
24
- (_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName('builtin:metrics-logger');
26
+ ctx.requestHandlerName = 'builtin:metrics-logger';
27
+ (_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName(ctx.requestHandlerName);
25
28
  ctx.status = 200;
26
29
  ctx.body = ctx.metricsLogger.getSummaries();
27
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/api",
3
- "version": "6.46.0",
3
+ "version": "6.47.0-beta.0",
4
4
  "description": "VTEX I/O API client",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",