@vtex/api 6.46.1 → 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 +4 -1
- package/lib/HttpClient/HttpClient.js +3 -3
- package/lib/HttpClient/middlewares/cache.d.ts +2 -1
- package/lib/HttpClient/middlewares/cache.js +18 -12
- package/lib/HttpClient/typings.d.ts +1 -0
- package/lib/service/worker/runtime/builtIn/handlers.js +6 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,9 @@ 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
|
+
|
|
10
13
|
## [6.46.1] - 2024-01-31
|
|
11
14
|
|
|
12
15
|
### Fixed
|
|
@@ -142,7 +145,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
142
145
|
|
|
143
146
|
## [6.54.5] - 2021-10-22
|
|
144
147
|
|
|
145
|
-
### Fixed
|
|
148
|
+
### Fixed
|
|
146
149
|
|
|
147
150
|
- Extract session cookie in a safe manner
|
|
148
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
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
};
|