@vtex/api 6.49.2-beta.0 → 6.49.2-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/lib/HttpClient/middlewares/cache.js +8 -5
- package/lib/HttpClient/middlewares/request/index.js +1 -1
- package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +1 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +1 -1
- package/lib/HttpClient/typings.d.ts +1 -1
- package/lib/caches/MultilayeredCache.js +1 -1
- package/lib/clients/IOClient.js +0 -1
- package/lib/clients/infra/VBase.js +1 -1
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.js +1 -1
- package/lib/service/worker/runtime/http/middlewares/error.js +1 -1
- package/lib/utils/buildFullPath.d.ts +11 -0
- package/lib/utils/buildFullPath.js +54 -0
- package/package.json +24 -3
|
@@ -7,7 +7,7 @@ const RANGE_HEADER_QS_KEY = '__range_header';
|
|
|
7
7
|
const cacheableStatusCodes = [200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501]; // https://tools.ietf.org/html/rfc7231#section-6.1
|
|
8
8
|
const cacheKey = (config) => {
|
|
9
9
|
const { baseURL = '', url = '', params, headers } = config;
|
|
10
|
-
const locale = headers[constants_1.LOCALE_HEADER];
|
|
10
|
+
const locale = headers === null || headers === void 0 ? void 0 : headers[constants_1.LOCALE_HEADER];
|
|
11
11
|
const encodedBaseURL = baseURL.replace(/\//g, '\\');
|
|
12
12
|
const encodedURL = url.replace(/\//g, '\\');
|
|
13
13
|
let key = `${locale}--${encodedBaseURL}--${encodedURL}?`;
|
|
@@ -58,13 +58,13 @@ const cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
58
58
|
const CACHE_RESULT_TAG = type === CacheType.Disk ? "http.cache.disk" /* CustomHttpTags.HTTP_DISK_CACHE_RESULT */ : "http.cache.memory" /* CustomHttpTags.HTTP_MEMORY_CACHE_RESULT */;
|
|
59
59
|
const cacheType = CacheTypeNames[type];
|
|
60
60
|
return async (ctx, next) => {
|
|
61
|
-
var _a;
|
|
61
|
+
var _a, _b;
|
|
62
62
|
if (!isLocallyCacheable(ctx.config, type)) {
|
|
63
63
|
return await next();
|
|
64
64
|
}
|
|
65
65
|
const { rootSpan: span, tracer, logger } = (_a = ctx.tracing) !== null && _a !== void 0 ? _a : {};
|
|
66
66
|
const key = (0, exports.cacheKey)(ctx.config);
|
|
67
|
-
const segmentToken = ctx.config.headers[constants_1.SEGMENT_HEADER];
|
|
67
|
+
const segmentToken = (_b = ctx.config.headers) === null || _b === void 0 ? void 0 : _b[constants_1.SEGMENT_HEADER];
|
|
68
68
|
const keyWithSegment = key + segmentToken;
|
|
69
69
|
span === null || span === void 0 ? void 0 : span.log({
|
|
70
70
|
event: "cache-key-created" /* HttpLogEvents.CACHE_KEY_CREATE */,
|
|
@@ -112,7 +112,10 @@ const cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
112
112
|
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "STALE" /* CacheResult.STALE */);
|
|
113
113
|
const validateStatus = addNotModified(ctx.config.validateStatus);
|
|
114
114
|
if (cachedEtag && validateStatus(response.status)) {
|
|
115
|
-
ctx.config.headers
|
|
115
|
+
ctx.config.headers = {
|
|
116
|
+
...ctx.config.headers,
|
|
117
|
+
'if-none-match': cachedEtag
|
|
118
|
+
};
|
|
116
119
|
ctx.config.validateStatus = validateStatus;
|
|
117
120
|
}
|
|
118
121
|
}
|
|
@@ -177,7 +180,7 @@ const cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
177
180
|
etag,
|
|
178
181
|
expiration,
|
|
179
182
|
response: { data: cacheableData, headers, status },
|
|
180
|
-
responseEncoding,
|
|
183
|
+
responseEncoding: responseEncoding,
|
|
181
184
|
responseType,
|
|
182
185
|
});
|
|
183
186
|
if (asyncSet) {
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.requestMiddleware = exports.routerCacheMiddleware = exports.defaultsMiddleware = void 0;
|
|
7
|
-
const buildFullPath_1 = __importDefault(require("
|
|
7
|
+
const buildFullPath_1 = __importDefault(require("../../../utils/buildFullPath"));
|
|
8
8
|
const qs_1 = require("qs");
|
|
9
9
|
const ramda_1 = require("ramda");
|
|
10
10
|
const Tags_1 = require("../../../tracing/Tags");
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.injectResponseInfoOnSpan = exports.injectRequestInfoOnSpan = void 0;
|
|
7
|
-
const buildFullPath_1 = __importDefault(require("
|
|
7
|
+
const buildFullPath_1 = __importDefault(require("../../../../../../utils/buildFullPath"));
|
|
8
8
|
const constants_1 = require("../../../../../../constants");
|
|
9
9
|
const Tags_1 = require("../../../../../../tracing/Tags");
|
|
10
10
|
const utils_1 = require("../../../../../../tracing/utils");
|
|
@@ -44,7 +44,7 @@ export interface RequestConfig extends AxiosRequestConfig, RequestTracingConfig
|
|
|
44
44
|
memoizeable?: boolean;
|
|
45
45
|
inflightKey?: InflightKeyGenerator;
|
|
46
46
|
forceMaxAge?: number;
|
|
47
|
-
responseEncoding?: BufferEncoding;
|
|
47
|
+
responseEncoding?: BufferEncoding | string;
|
|
48
48
|
nullIfNotFound?: boolean;
|
|
49
49
|
ignoreRecorder?: boolean;
|
|
50
50
|
}
|
|
@@ -8,7 +8,7 @@ class MultilayeredCache {
|
|
|
8
8
|
this.hits = 0;
|
|
9
9
|
this.total = 0;
|
|
10
10
|
this.get = async (key, fetcher) => {
|
|
11
|
-
let value;
|
|
11
|
+
let value = undefined;
|
|
12
12
|
let maxAge;
|
|
13
13
|
let successIndex = await this.findIndex(async (cache) => {
|
|
14
14
|
const [getValue, hasKey] = await Promise.all([cache.get(key), cache.has(key)]);
|
package/lib/clients/IOClient.js
CHANGED
|
@@ -139,7 +139,7 @@ class VBase extends InfraClient_1.InfraClient {
|
|
|
139
139
|
return this.saveContent(bucket, path, stream, { unzip: true }, tracingConfig, ifMatch);
|
|
140
140
|
};
|
|
141
141
|
this.deleteFile = (bucket, path, tracingConfig, ifMatch) => {
|
|
142
|
-
const headers = ifMatch ? { 'If-Match': ifMatch } :
|
|
142
|
+
const headers = ifMatch ? { 'If-Match': ifMatch } : {};
|
|
143
143
|
const metric = 'vbase-delete-file';
|
|
144
144
|
return this.http.delete(routes.File(bucket, path), { headers, metric, tracing: {
|
|
145
145
|
requestSpanNameSuffix: metric,
|
|
@@ -41,7 +41,7 @@ async function auth(ctx, authArgs) {
|
|
|
41
41
|
throw new apollo_server_errors_1.AuthenticationError('VtexIdclientAutCookie not found.');
|
|
42
42
|
}
|
|
43
43
|
const parsedToken = await parseIdToken(ctx.vtex.authToken, vtexIdToken);
|
|
44
|
-
if (!parsedToken || parsedToken.account
|
|
44
|
+
if (!parsedToken || parsedToken.account !== ctx.vtex.account) {
|
|
45
45
|
throw new apollo_server_errors_1.AuthenticationError('Could not find user specified by VtexIdclientAutCookie.');
|
|
46
46
|
}
|
|
47
47
|
const userCanAccessResource = await getUserCanAccessResource(ctx.vtex.authToken, ctx.vtex.account, parsedToken.user, authArgs.productCode, authArgs.resourceCode);
|
|
@@ -62,7 +62,7 @@ async function error(ctx, next) {
|
|
|
62
62
|
console.error('[node-vtex-api error]', e);
|
|
63
63
|
const err = (0, error_1.cleanError)(e);
|
|
64
64
|
// Add response
|
|
65
|
-
ctx.status = e && e.status >= 400 && e.status <= 599
|
|
65
|
+
ctx.status = (e === null || e === void 0 ? void 0 : e.status) && e.status >= 400 && e.status <= 599
|
|
66
66
|
? e.status
|
|
67
67
|
: ctx.status >= 500 && ctx.status <= 599
|
|
68
68
|
? ctx.status
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
3
|
+
* only when the requestedURL is not already an absolute URL.
|
|
4
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} baseURL The base URL
|
|
7
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} The combined full path
|
|
10
|
+
*/
|
|
11
|
+
export default function (baseURL?: string, requestedURL?: string, allowAbsoluteUrls?: boolean): string | undefined;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This module is part of the Axios library.
|
|
3
|
+
// It is used to build a full URL by combining a base URL with a relative URL.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
// It is originally not intended to be used directly, but rather as a utility function within the Axios library.
|
|
6
|
+
// Since Axios 1.0, this function is not exported by default, and the team does not recommend using it directly,
|
|
7
|
+
// as it may not be available in future versions.
|
|
8
|
+
// The function takes a base URL and a relative URL as input, and returns the full URL.
|
|
9
|
+
// It handles both absolute and relative URLs, and ensures that the resulting URL is properly formatted.
|
|
10
|
+
// It is used internally by Axios to construct the full URL for HTTP requests.
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
13
|
+
* only when the requestedURL is not already an absolute URL.
|
|
14
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} baseURL The base URL
|
|
17
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
|
18
|
+
*
|
|
19
|
+
* @returns {string} The combined full path
|
|
20
|
+
*/
|
|
21
|
+
function default_1(baseURL, requestedURL, allowAbsoluteUrls) {
|
|
22
|
+
let isRelativeUrl = !isAbsoluteURL(requestedURL);
|
|
23
|
+
if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
|
|
24
|
+
return combineURLs(baseURL, requestedURL);
|
|
25
|
+
}
|
|
26
|
+
return requestedURL;
|
|
27
|
+
}
|
|
28
|
+
exports.default = default_1;
|
|
29
|
+
/**
|
|
30
|
+
* Determines whether the specified URL is absolute
|
|
31
|
+
*
|
|
32
|
+
* @param {string} url The URL to test
|
|
33
|
+
*
|
|
34
|
+
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
|
35
|
+
*/
|
|
36
|
+
function isAbsoluteURL(url) {
|
|
37
|
+
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
|
38
|
+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
|
39
|
+
// by any combination of letters, digits, plus, period, or hyphen.
|
|
40
|
+
return !!url && /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new URL by combining the specified URLs
|
|
44
|
+
*
|
|
45
|
+
* @param {string} baseURL The base URL
|
|
46
|
+
* @param {string} relativeURL The relative URL
|
|
47
|
+
*
|
|
48
|
+
* @returns {string} The combined URL
|
|
49
|
+
*/
|
|
50
|
+
function combineURLs(baseURL, relativeURL) {
|
|
51
|
+
return relativeURL && baseURL
|
|
52
|
+
? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
|
53
|
+
: baseURL;
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtex/api",
|
|
3
|
-
"version": "6.49.2-beta.
|
|
3
|
+
"version": "6.49.2-beta.1",
|
|
4
4
|
"description": "VTEX I/O API client",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@types/koa": "^2.11.0",
|
|
51
51
|
"@types/koa-compose": "^3.2.3",
|
|
52
|
-
"@vtex/diagnostics-nodejs": "0.1.0-beta.
|
|
52
|
+
"@vtex/diagnostics-nodejs": "0.1.0-beta.8",
|
|
53
53
|
"@vtex/node-error-report": "^0.0.3",
|
|
54
54
|
"@wry/equality": "^0.1.9",
|
|
55
55
|
"agentkeepalive": "^4.0.2",
|
|
56
56
|
"apollo-server-errors": "^2.2.1",
|
|
57
57
|
"archiver": "^3.0.0",
|
|
58
|
-
"axios": "^
|
|
58
|
+
"axios": "^1.8.4",
|
|
59
59
|
"axios-retry": "^3.1.2",
|
|
60
60
|
"bluebird": "^3.5.4",
|
|
61
61
|
"chalk": "^2.4.2",
|
|
@@ -124,5 +124,26 @@
|
|
|
124
124
|
"typemoq": "^2.1.0",
|
|
125
125
|
"typescript": "^4.4.4",
|
|
126
126
|
"typescript-json-schema": "^0.52.0"
|
|
127
|
+
},
|
|
128
|
+
"resolutions": {
|
|
129
|
+
"@opentelemetry/core": "1.30.1",
|
|
130
|
+
"@opentelemetry/exporter-metrics-otlp-grpc": "0.57.2",
|
|
131
|
+
"@opentelemetry/exporter-metrics-otlp-http": "0.57.2",
|
|
132
|
+
"@opentelemetry/exporter-logs-otlp-grpc": "0.57.2",
|
|
133
|
+
"@opentelemetry/exporter-logs-otlp-http": "0.57.2",
|
|
134
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "0.57.2",
|
|
135
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.57.2",
|
|
136
|
+
"@opentelemetry/instrumentation": "0.57.2",
|
|
137
|
+
"@opentelemetry/instrumentation-http": "0.57.2",
|
|
138
|
+
"@opentelemetry/instrumentation-grpc": "0.57.2",
|
|
139
|
+
"@opentelemetry/instrumentation-net": "0.43.1",
|
|
140
|
+
"@opentelemetry/propagator-b3": "1.30.1",
|
|
141
|
+
"@opentelemetry/resource-detector-aws": "1.12.0",
|
|
142
|
+
"@opentelemetry/resources": "1.30.1",
|
|
143
|
+
"@opentelemetry/sdk-node": "0.57.2",
|
|
144
|
+
"@opentelemetry/sdk-logs": "0.57.2",
|
|
145
|
+
"@opentelemetry/sdk-metrics": "1.30.1",
|
|
146
|
+
"@opentelemetry/sdk-trace-base": "1.30.1",
|
|
147
|
+
"@opentelemetry/sdk-trace-node": "1.30.1"
|
|
127
148
|
}
|
|
128
149
|
}
|