@vtex/api 6.49.3-beta.2 → 6.49.3-beta.4
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/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/tracing/utils.d.ts +5 -0
- package/lib/tracing/utils.js +53 -1
- package/lib/utils/buildFullPath.d.ts +11 -0
- package/lib/utils/buildFullPath.js +54 -0
- package/package.json +24 -7
|
@@ -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)]);
|
|
@@ -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
|
package/lib/tracing/utils.d.ts
CHANGED
|
@@ -3,9 +3,14 @@ export interface TraceInfo {
|
|
|
3
3
|
traceId?: string;
|
|
4
4
|
isSampled: boolean;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Headers that are interesting for tracing and debugging purposes
|
|
8
|
+
*/
|
|
9
|
+
export declare const INTERESTING_HEADERS: string[];
|
|
6
10
|
export declare function getTraceInfo(span?: Span): TraceInfo;
|
|
7
11
|
/**
|
|
8
12
|
* Do a shallow copy of a headers object and redacts sensitive information.
|
|
13
|
+
* Only includes headers that are in the INTERESTING_HEADERS whitelist.
|
|
9
14
|
*
|
|
10
15
|
* @param headersObj The headers object
|
|
11
16
|
* @param resultFieldsPrefix The prefix that will be added to each field on the result object
|
package/lib/tracing/utils.js
CHANGED
|
@@ -1,7 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cloneAndSanitizeHeaders = exports.getTraceInfo = void 0;
|
|
3
|
+
exports.cloneAndSanitizeHeaders = exports.getTraceInfo = exports.INTERESTING_HEADERS = void 0;
|
|
4
4
|
const node_error_report_1 = require("@vtex/node-error-report");
|
|
5
|
+
/**
|
|
6
|
+
* Headers that are interesting for tracing and debugging purposes
|
|
7
|
+
*/
|
|
8
|
+
exports.INTERESTING_HEADERS = [
|
|
9
|
+
// Request/Response Identification & Routing
|
|
10
|
+
'x-request-id',
|
|
11
|
+
'x-correlation-id',
|
|
12
|
+
'x-trace-id',
|
|
13
|
+
'x-span-id',
|
|
14
|
+
'x-forwarded-for',
|
|
15
|
+
'x-real-ip',
|
|
16
|
+
'host',
|
|
17
|
+
'referer',
|
|
18
|
+
// Content & Encoding
|
|
19
|
+
'content-type',
|
|
20
|
+
'content-length',
|
|
21
|
+
'content-encoding',
|
|
22
|
+
'accept',
|
|
23
|
+
'accept-encoding',
|
|
24
|
+
'accept-language',
|
|
25
|
+
// Caching & Performance
|
|
26
|
+
'cache-control',
|
|
27
|
+
'etag',
|
|
28
|
+
'if-none-match',
|
|
29
|
+
'expires',
|
|
30
|
+
'last-modified',
|
|
31
|
+
// Client Information
|
|
32
|
+
'user-agent',
|
|
33
|
+
'x-forwarded-proto',
|
|
34
|
+
'x-forwarded-host',
|
|
35
|
+
'x-forwarded-port',
|
|
36
|
+
// VTEX/E-commerce Specific (x-vtex-* headers are handled automatically)
|
|
37
|
+
'x-router-cache',
|
|
38
|
+
'x-powered-by-vtex-cache',
|
|
39
|
+
'jaeger-debug-id',
|
|
40
|
+
// API & Service Headers
|
|
41
|
+
'x-api-version',
|
|
42
|
+
'x-service-name',
|
|
43
|
+
'x-timeout',
|
|
44
|
+
'retry-after',
|
|
45
|
+
// Security (will be sanitized)
|
|
46
|
+
'authorization',
|
|
47
|
+
'cookie',
|
|
48
|
+
];
|
|
49
|
+
// Create the set once for performance
|
|
50
|
+
const INTERESTING_HEADERS_SET = new Set(exports.INTERESTING_HEADERS.map(h => h.toLowerCase()));
|
|
5
51
|
function getTraceInfo(span) {
|
|
6
52
|
var _a, _b;
|
|
7
53
|
const spanContext = span === null || span === void 0 ? void 0 : span.context();
|
|
@@ -13,6 +59,7 @@ function getTraceInfo(span) {
|
|
|
13
59
|
exports.getTraceInfo = getTraceInfo;
|
|
14
60
|
/**
|
|
15
61
|
* Do a shallow copy of a headers object and redacts sensitive information.
|
|
62
|
+
* Only includes headers that are in the INTERESTING_HEADERS whitelist.
|
|
16
63
|
*
|
|
17
64
|
* @param headersObj The headers object
|
|
18
65
|
* @param resultFieldsPrefix The prefix that will be added to each field on the result object
|
|
@@ -21,6 +68,11 @@ const cloneAndSanitizeHeaders = (headersObj, resultFieldsPrefix = '') => {
|
|
|
21
68
|
const ret = {};
|
|
22
69
|
const entries = Object.entries(headersObj);
|
|
23
70
|
for (const [key, val] of entries) {
|
|
71
|
+
const lowerKey = key.toLowerCase();
|
|
72
|
+
// Only include headers that are in our whitelist or start with x-vtex-
|
|
73
|
+
if (!INTERESTING_HEADERS_SET.has(lowerKey) && !lowerKey.startsWith('x-vtex-')) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
24
76
|
// Most of the time val is a string, but there are some cases, for example when we do a axios interceptor,
|
|
25
77
|
// that a header field can contain an object, for example:
|
|
26
78
|
// ```
|
|
@@ -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.3-beta.
|
|
3
|
+
"version": "6.49.3-beta.4",
|
|
4
4
|
"description": "VTEX I/O API client",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -18,8 +18,6 @@
|
|
|
18
18
|
"format": "prettier --config ./.prettierrc --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
19
19
|
"format-lint": "yarn format && yarn lint",
|
|
20
20
|
"prepublishOnly": "bash ./scripts/publishLock.sh",
|
|
21
|
-
"postinstall": "patch-package",
|
|
22
|
-
"prebuild": "patch-package",
|
|
23
21
|
"ci:build": "yarn build && yarn gen",
|
|
24
22
|
"ci:test": "yarn test --ci",
|
|
25
23
|
"ci:prettier-check": "prettier --check --config ./.prettierrc \"src/**/*.ts\" \"src/**/*.js\""
|
|
@@ -51,13 +49,13 @@
|
|
|
51
49
|
"dependencies": {
|
|
52
50
|
"@types/koa": "^2.11.0",
|
|
53
51
|
"@types/koa-compose": "^3.2.3",
|
|
54
|
-
"@vtex/diagnostics-nodejs": "0.1.0-beta.
|
|
52
|
+
"@vtex/diagnostics-nodejs": "0.1.0-beta.8",
|
|
55
53
|
"@vtex/node-error-report": "^0.0.3",
|
|
56
54
|
"@wry/equality": "^0.1.9",
|
|
57
55
|
"agentkeepalive": "^4.0.2",
|
|
58
56
|
"apollo-server-errors": "^2.2.1",
|
|
59
57
|
"archiver": "^3.0.0",
|
|
60
|
-
"axios": "^
|
|
58
|
+
"axios": "^1.8.4",
|
|
61
59
|
"axios-retry": "^3.1.2",
|
|
62
60
|
"bluebird": "^3.5.4",
|
|
63
61
|
"chalk": "^2.4.2",
|
|
@@ -79,8 +77,6 @@
|
|
|
79
77
|
"mime-types": "^2.1.12",
|
|
80
78
|
"opentracing": "^0.14.4",
|
|
81
79
|
"p-limit": "^2.2.0",
|
|
82
|
-
"patch-package": "^8.0.0",
|
|
83
|
-
"postinstall-postinstall": "^2.1.0",
|
|
84
80
|
"prom-client": "^14.2.0",
|
|
85
81
|
"qs": "^6.5.1",
|
|
86
82
|
"querystring": "^0.2.0",
|
|
@@ -128,5 +124,26 @@
|
|
|
128
124
|
"typemoq": "^2.1.0",
|
|
129
125
|
"typescript": "^4.4.4",
|
|
130
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"
|
|
131
148
|
}
|
|
132
149
|
}
|