@vtex/api 6.48.1-beta.2 → 6.49.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/gen/manifest.schema +1 -1
- package/lib/HttpClient/middlewares/cache.js +5 -8
- package/lib/HttpClient/middlewares/metrics.js +0 -4
- package/lib/HttpClient/middlewares/recorder.js +0 -4
- package/lib/HttpClient/middlewares/tracing.js +0 -4
- package/lib/HttpClient/typings.d.ts +1 -1
- package/lib/caches/DiskCache.js +1 -1
- package/lib/caches/LRUDiskCache.js +1 -1
- package/lib/caches/MultilayeredCache.js +1 -1
- package/lib/clients/infra/Apps.js +0 -2
- package/lib/clients/infra/Registry.js +0 -1
- package/lib/clients/infra/VBase.js +1 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +2 -1
- package/lib/service/index.js +0 -3
- package/lib/service/logger/client.d.ts +2 -0
- package/lib/service/logger/client.js +48 -0
- package/lib/service/logger/console.d.ts +1 -1
- package/lib/service/logger/index.d.ts +2 -0
- package/lib/service/logger/index.js +2 -0
- package/lib/service/logger/logger.d.ts +4 -15
- package/lib/service/logger/logger.js +59 -16
- package/lib/service/logger/loggerTypes.d.ts +14 -0
- package/lib/service/logger/loggerTypes.js +10 -0
- package/lib/service/telemetry/client.d.ts +3 -0
- package/lib/service/telemetry/client.js +57 -0
- package/lib/service/telemetry/index.d.ts +1 -0
- package/lib/service/telemetry/index.js +17 -0
- package/lib/service/tracing/tracingMiddlewares.js +0 -6
- package/lib/service/worker/index.js +2 -2
- package/lib/service/worker/runtime/events/middlewares/body.js +1 -4
- package/lib/service/worker/runtime/graphql/middlewares/error.js +0 -3
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.js +1 -1
- package/lib/service/worker/runtime/http/middlewares/error.js +5 -8
- package/package.json +27 -5
package/gen/manifest.schema
CHANGED
|
@@ -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
|
|
10
|
+
const locale = 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;
|
|
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 =
|
|
67
|
+
const segmentToken = ctx.config.headers[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,10 +112,7 @@ 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 =
|
|
116
|
-
...ctx.config.headers,
|
|
117
|
-
'if-none-match': cachedEtag
|
|
118
|
-
};
|
|
115
|
+
ctx.config.headers['if-none-match'] = cachedEtag;
|
|
119
116
|
ctx.config.validateStatus = validateStatus;
|
|
120
117
|
}
|
|
121
118
|
}
|
|
@@ -180,7 +177,7 @@ const cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
180
177
|
etag,
|
|
181
178
|
expiration,
|
|
182
179
|
response: { data: cacheableData, headers, status },
|
|
183
|
-
responseEncoding
|
|
180
|
+
responseEncoding,
|
|
184
181
|
responseType,
|
|
185
182
|
});
|
|
186
183
|
if (asyncSet) {
|
|
@@ -6,7 +6,6 @@ const requestStats_1 = require("../../service/worker/runtime/http/middlewares/re
|
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const retry_1 = require("../../utils/retry");
|
|
8
8
|
const status_1 = require("../../utils/status");
|
|
9
|
-
const axios_1 = require("axios");
|
|
10
9
|
const metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
11
10
|
const serverTimingStart = process.hrtime();
|
|
12
11
|
const serverTimingLabel = (0, utils_1.shrinkTimings)((0, utils_1.formatTimingName)({
|
|
@@ -29,9 +28,6 @@ const metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
catch (err) {
|
|
32
|
-
if (!(err instanceof axios_1.AxiosError)) {
|
|
33
|
-
throw err;
|
|
34
|
-
}
|
|
35
31
|
const isCancelled = (err.message === requestStats_1.cancelMessage);
|
|
36
32
|
if (ctx.config.metric) {
|
|
37
33
|
errorCode = err.code;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.recorderMiddleware = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
4
|
const recorderMiddleware = (recorder) => async (ctx, next) => {
|
|
6
5
|
var _a;
|
|
7
6
|
if ((_a = ctx.config) === null || _a === void 0 ? void 0 : _a.ignoreRecorder) {
|
|
@@ -15,9 +14,6 @@ const recorderMiddleware = (recorder) => async (ctx, next) => {
|
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
catch (err) {
|
|
18
|
-
if (!(err instanceof axios_1.AxiosError)) {
|
|
19
|
-
throw err;
|
|
20
|
-
}
|
|
21
17
|
if (err.response && err.response.headers && err.response.status === 404) {
|
|
22
18
|
recorder.record(err.response.headers);
|
|
23
19
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createHttpClientTracingMiddleware = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
4
|
const tracing_1 = require("../../tracing");
|
|
6
5
|
const Tags_1 = require("../../tracing/Tags");
|
|
7
6
|
const cache_1 = require("./cache");
|
|
@@ -39,9 +38,6 @@ const createHttpClientTracingMiddleware = ({ tracer, logger, clientName, hasMemo
|
|
|
39
38
|
response = ctx.response;
|
|
40
39
|
}
|
|
41
40
|
catch (err) {
|
|
42
|
-
if (!(err instanceof axios_1.AxiosError)) {
|
|
43
|
-
throw err;
|
|
44
|
-
}
|
|
45
41
|
response = err.response;
|
|
46
42
|
if ((_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.isSampled) {
|
|
47
43
|
tracing_1.ErrorReport.create({ originalError: err }).injectOnSpan(span, logger);
|
|
@@ -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;
|
|
48
48
|
nullIfNotFound?: boolean;
|
|
49
49
|
ignoreRecorder?: boolean;
|
|
50
50
|
}
|
package/lib/caches/DiskCache.js
CHANGED
|
@@ -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;
|
|
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)]);
|
|
@@ -143,8 +143,6 @@ class Apps extends InfraClient_1.InfraClient {
|
|
|
143
143
|
return response;
|
|
144
144
|
}
|
|
145
145
|
catch (e) {
|
|
146
|
-
// Typing cast for compatibility with error handling in TS versions > 4.0
|
|
147
|
-
// Source: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#unknown-on-catch-clause-bindings
|
|
148
146
|
e.bundleSize = zip.pointer();
|
|
149
147
|
throw e;
|
|
150
148
|
}
|
|
@@ -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 } : null;
|
|
143
143
|
const metric = 'vbase-delete-file';
|
|
144
144
|
return this.http.delete(routes.File(bucket, path), { headers, metric, tracing: {
|
|
145
145
|
requestSpanNameSuffix: metric,
|
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cancellableMethods = exports.INSPECT_DEBUGGER_PORT = exports.PRODUCTION = exports.WORKSPACE = exports.ACCOUNT = exports.NODE_ENV = exports.APP = exports.PUBLIC_ENDPOINT = exports.REGION = exports.LINKED = exports.MAX_WORKERS = exports.HTTP_SERVER_PORT = exports.MAX_AGE = exports.UP_SIGNAL = exports.BODY_HASH = exports.PROVIDER_HEADER = exports.TRACE_ID_HEADER = exports.COLOSSUS_PARAMS_HEADER = exports.COLOSSUS_ROUTE_ID_HEADER = exports.COLOSSUS_ROUTE_DECLARER_HEADER = exports.EVENT_HANDLER_ID_HEADER = exports.EVENT_SUBJECT_HEADER = exports.EVENT_SENDER_HEADER = exports.EVENT_KEY_HEADER = exports.WORKSPACE_HEADER = exports.WORKSPACE_IS_PRODUCTION_HEADER = exports.PLATFORM_HEADER = exports.OPERATION_ID_HEADER = exports.ROUTER_CACHE_HEADER = exports.REQUEST_ID_HEADER = exports.CREDENTIAL_HEADER = exports.ACCOUNT_HEADER = exports.ETAG_HEADER = exports.META_HEADER_BUCKET = exports.META_HEADER = exports.BINDING_HEADER = exports.TENANT_HEADER = exports.FORWARDED_HOST_HEADER = exports.LOCALE_HEADER = exports.PRODUCT_HEADER = exports.SESSION_HEADER = exports.SEGMENT_HEADER = exports.CACHE_CONTROL_HEADER = exports.PID = exports.IS_IO = exports.DEFAULT_WORKSPACE = exports.NODE_VTEX_API_VERSION = void 0;
|
|
3
|
+
exports.LOG_CLIENT_INIT_TIMEOUT_MS = exports.cancellableMethods = exports.INSPECT_DEBUGGER_PORT = exports.PRODUCTION = exports.WORKSPACE = exports.ACCOUNT = exports.NODE_ENV = exports.APP = exports.PUBLIC_ENDPOINT = exports.REGION = exports.LINKED = exports.MAX_WORKERS = exports.HTTP_SERVER_PORT = exports.MAX_AGE = exports.UP_SIGNAL = exports.BODY_HASH = exports.PROVIDER_HEADER = exports.TRACE_ID_HEADER = exports.COLOSSUS_PARAMS_HEADER = exports.COLOSSUS_ROUTE_ID_HEADER = exports.COLOSSUS_ROUTE_DECLARER_HEADER = exports.EVENT_HANDLER_ID_HEADER = exports.EVENT_SUBJECT_HEADER = exports.EVENT_SENDER_HEADER = exports.EVENT_KEY_HEADER = exports.WORKSPACE_HEADER = exports.WORKSPACE_IS_PRODUCTION_HEADER = exports.PLATFORM_HEADER = exports.OPERATION_ID_HEADER = exports.ROUTER_CACHE_HEADER = exports.REQUEST_ID_HEADER = exports.CREDENTIAL_HEADER = exports.ACCOUNT_HEADER = exports.ETAG_HEADER = exports.META_HEADER_BUCKET = exports.META_HEADER = exports.BINDING_HEADER = exports.TENANT_HEADER = exports.FORWARDED_HOST_HEADER = exports.LOCALE_HEADER = exports.PRODUCT_HEADER = exports.SESSION_HEADER = exports.SEGMENT_HEADER = exports.CACHE_CONTROL_HEADER = exports.PID = exports.IS_IO = exports.DEFAULT_WORKSPACE = exports.NODE_VTEX_API_VERSION = void 0;
|
|
4
4
|
const app_1 = require("./utils/app");
|
|
5
5
|
// tslint:disable-next-line
|
|
6
6
|
const pkg = require('../package.json');
|
|
@@ -64,3 +64,4 @@ exports.WORKSPACE = process.env.VTEX_WORKSPACE;
|
|
|
64
64
|
exports.PRODUCTION = process.env.VTEX_PRODUCTION === 'true';
|
|
65
65
|
exports.INSPECT_DEBUGGER_PORT = 5858;
|
|
66
66
|
exports.cancellableMethods = new Set(['GET', 'OPTIONS', 'HEAD']);
|
|
67
|
+
exports.LOG_CLIENT_INIT_TIMEOUT_MS = 5000;
|
package/lib/service/index.js
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogClient = void 0;
|
|
4
|
+
const diagnostics_nodejs_1 = require("@vtex/diagnostics-nodejs");
|
|
5
|
+
const telemetry_1 = require("../telemetry");
|
|
6
|
+
let logClient;
|
|
7
|
+
let isInitializing = false;
|
|
8
|
+
let initPromise = undefined;
|
|
9
|
+
async function getLogClient(account, workspace, appName) {
|
|
10
|
+
if (logClient) {
|
|
11
|
+
return logClient;
|
|
12
|
+
}
|
|
13
|
+
if (initPromise) {
|
|
14
|
+
return initPromise;
|
|
15
|
+
}
|
|
16
|
+
isInitializing = true;
|
|
17
|
+
initPromise = initializeClient(account, workspace, appName);
|
|
18
|
+
return initPromise;
|
|
19
|
+
}
|
|
20
|
+
exports.getLogClient = getLogClient;
|
|
21
|
+
async function initializeClient(account, workspace, appName) {
|
|
22
|
+
try {
|
|
23
|
+
const telemetryClient = await (0, telemetry_1.getTelemetryClient)();
|
|
24
|
+
const logsConfig = diagnostics_nodejs_1.Exporters.CreateLogsExporterConfig({
|
|
25
|
+
endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
26
|
+
path: process.env.OTEL_EXPORTER_OTLP_PATH || '/v1/logs',
|
|
27
|
+
protocol: 'http',
|
|
28
|
+
interval: 5,
|
|
29
|
+
timeoutSeconds: 5,
|
|
30
|
+
headers: { 'Content-Type': 'application/json' },
|
|
31
|
+
});
|
|
32
|
+
const logsExporter = diagnostics_nodejs_1.Exporters.CreateExporter(logsConfig, 'otlp');
|
|
33
|
+
await logsExporter.initialize();
|
|
34
|
+
const clientKey = `${account}-${workspace}-${appName}`;
|
|
35
|
+
logClient = await telemetryClient.newLogsClient({
|
|
36
|
+
exporter: logsExporter,
|
|
37
|
+
loggerName: `node-vtex-api-${clientKey}`,
|
|
38
|
+
});
|
|
39
|
+
return logClient;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error('Failed to initialize logs client:', error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
isInitializing = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./console"), exports);
|
|
18
18
|
__exportStar(require("./logger"), exports);
|
|
19
|
+
__exportStar(require("./loggerTypes"), exports);
|
|
20
|
+
__exportStar(require("./client"), exports);
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IOContext } from '../worker/runtime/typings';
|
|
3
|
-
export interface LoggerTracingContext {
|
|
4
|
-
requestTracer: IUserLandTracer;
|
|
5
|
-
}
|
|
6
|
-
export declare enum LogLevel {
|
|
7
|
-
Debug = "debug",
|
|
8
|
-
Info = "info",
|
|
9
|
-
Warn = "warn",
|
|
10
|
-
Error = "error"
|
|
11
|
-
}
|
|
12
|
-
interface LoggerContext extends Pick<IOContext, 'account' | 'workspace' | 'requestId' | 'operationId' | 'production'> {
|
|
13
|
-
tracer?: IOContext['tracer'];
|
|
14
|
-
}
|
|
1
|
+
import { LoggerContext, LogLevel } from './loggerTypes';
|
|
15
2
|
export declare class Logger {
|
|
16
3
|
private account;
|
|
17
4
|
private workspace;
|
|
@@ -19,11 +6,13 @@ export declare class Logger {
|
|
|
19
6
|
private requestId;
|
|
20
7
|
private production;
|
|
21
8
|
private tracingState?;
|
|
9
|
+
private logClient;
|
|
10
|
+
private clientInitPromise;
|
|
22
11
|
constructor(ctx: LoggerContext);
|
|
12
|
+
private initLogClient;
|
|
23
13
|
debug: (message: any) => void;
|
|
24
14
|
info: (message: any) => void;
|
|
25
15
|
warn: (warning: any) => void;
|
|
26
16
|
error: (error: any) => void;
|
|
27
17
|
log: (message: any, level: LogLevel) => void;
|
|
28
18
|
}
|
|
29
|
-
export {};
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger =
|
|
3
|
+
exports.Logger = void 0;
|
|
4
4
|
const constants_1 = require("../../constants");
|
|
5
5
|
const error_1 = require("../../utils/error");
|
|
6
6
|
const log_1 = require("../../utils/log");
|
|
7
|
-
const
|
|
7
|
+
const loggerTypes_1 = require("./loggerTypes");
|
|
8
|
+
const client_1 = require("./client");
|
|
8
9
|
const app = constants_1.APP.ID;
|
|
9
10
|
const EMPTY_MESSAGE = 'Logger.log was called with null or undefined message';
|
|
10
|
-
var LogLevel;
|
|
11
|
-
(function (LogLevel) {
|
|
12
|
-
LogLevel["Debug"] = "debug";
|
|
13
|
-
LogLevel["Info"] = "info";
|
|
14
|
-
LogLevel["Warn"] = "warn";
|
|
15
|
-
LogLevel["Error"] = "error";
|
|
16
|
-
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
17
11
|
class Logger {
|
|
18
12
|
constructor(ctx) {
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
13
|
+
this.logClient = undefined;
|
|
14
|
+
this.clientInitPromise = undefined;
|
|
15
|
+
this.debug = (message) => this.log(message, loggerTypes_1.LogLevel.Debug);
|
|
16
|
+
this.info = (message) => this.log(message, loggerTypes_1.LogLevel.Info);
|
|
17
|
+
this.warn = (warning) => this.log(warning, loggerTypes_1.LogLevel.Warn);
|
|
18
|
+
this.error = (error) => this.log(error, loggerTypes_1.LogLevel.Error);
|
|
23
19
|
this.log = (message, level) => {
|
|
24
20
|
var _a;
|
|
25
21
|
const data = message ? (0, error_1.cleanError)(message) : EMPTY_MESSAGE;
|
|
@@ -40,11 +36,35 @@ class Logger {
|
|
|
40
36
|
// Mark third-party apps logs to send to skidder
|
|
41
37
|
if (constants_1.APP.IS_THIRD_PARTY()) {
|
|
42
38
|
Object.assign(inflatedLog, {
|
|
43
|
-
__SKIDDER_TOPIC_1: `skidder.vendor.${constants_1.APP.VENDOR}`,
|
|
44
|
-
__SKIDDER_TOPIC_2: `skidder.app.${constants_1.APP.VENDOR}.${constants_1.APP.NAME}`,
|
|
39
|
+
'__SKIDDER_TOPIC_1': `skidder.vendor.${constants_1.APP.VENDOR}`,
|
|
40
|
+
'__SKIDDER_TOPIC_2': `skidder.app.${constants_1.APP.VENDOR}.${constants_1.APP.NAME}`,
|
|
45
41
|
});
|
|
46
42
|
}
|
|
47
|
-
|
|
43
|
+
if (this.logClient) {
|
|
44
|
+
try {
|
|
45
|
+
let logMessage = typeof data === 'string' ? data : JSON.stringify(data);
|
|
46
|
+
switch (level) {
|
|
47
|
+
case loggerTypes_1.LogLevel.Debug:
|
|
48
|
+
this.logClient.debug(logMessage, inflatedLog);
|
|
49
|
+
break;
|
|
50
|
+
case loggerTypes_1.LogLevel.Info:
|
|
51
|
+
this.logClient.info(logMessage, inflatedLog);
|
|
52
|
+
break;
|
|
53
|
+
case loggerTypes_1.LogLevel.Warn:
|
|
54
|
+
this.logClient.warn(logMessage, inflatedLog);
|
|
55
|
+
break;
|
|
56
|
+
case loggerTypes_1.LogLevel.Error:
|
|
57
|
+
this.logClient.error(logMessage, inflatedLog);
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
this.logClient.info(logMessage, inflatedLog);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.error('Error using diagnostics client for logging:', e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
console.log(typeof inflatedLog === 'string' ? JSON.stringify(inflatedLog) : inflatedLog);
|
|
48
68
|
};
|
|
49
69
|
this.account = ctx.account;
|
|
50
70
|
this.workspace = ctx.workspace;
|
|
@@ -57,6 +77,29 @@ class Logger {
|
|
|
57
77
|
traceId: ctx.tracer.traceId,
|
|
58
78
|
};
|
|
59
79
|
}
|
|
80
|
+
// this.initLogClient();
|
|
81
|
+
}
|
|
82
|
+
initLogClient() {
|
|
83
|
+
if (this.clientInitPromise) {
|
|
84
|
+
return this.clientInitPromise;
|
|
85
|
+
}
|
|
86
|
+
this.clientInitPromise = (async () => {
|
|
87
|
+
try {
|
|
88
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
89
|
+
setTimeout(() => reject(new Error('Log client initialization timeout')), constants_1.LOG_CLIENT_INIT_TIMEOUT_MS);
|
|
90
|
+
});
|
|
91
|
+
this.logClient = await Promise.race([
|
|
92
|
+
(0, client_1.getLogClient)(this.account, this.workspace, constants_1.APP.NAME),
|
|
93
|
+
timeoutPromise
|
|
94
|
+
]);
|
|
95
|
+
return this.logClient;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error('Failed to initialize log client:', error);
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
})();
|
|
102
|
+
return this.clientInitPromise;
|
|
60
103
|
}
|
|
61
104
|
}
|
|
62
105
|
exports.Logger = Logger;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IOContext } from '../worker/runtime/typings';
|
|
2
|
+
export interface LoggerContext extends Pick<IOContext, 'account' | 'workspace' | 'requestId' | 'operationId' | 'production'> {
|
|
3
|
+
tracer?: IOContext['tracer'];
|
|
4
|
+
}
|
|
5
|
+
export interface TracingState {
|
|
6
|
+
isTraceSampled: boolean;
|
|
7
|
+
traceId?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare enum LogLevel {
|
|
10
|
+
Debug = "debug",
|
|
11
|
+
Info = "info",
|
|
12
|
+
Warn = "warn",
|
|
13
|
+
Error = "error"
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogLevel = void 0;
|
|
4
|
+
var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel["Debug"] = "debug";
|
|
7
|
+
LogLevel["Info"] = "info";
|
|
8
|
+
LogLevel["Warn"] = "warn";
|
|
9
|
+
LogLevel["Error"] = "error";
|
|
10
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetTelemetryClient = exports.getTelemetryClient = void 0;
|
|
4
|
+
const diagnostics_nodejs_1 = require("@vtex/diagnostics-nodejs");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
class TelemetryClientSingleton {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.initializationPromise = undefined;
|
|
9
|
+
}
|
|
10
|
+
static getInstance() {
|
|
11
|
+
if (!TelemetryClientSingleton.instance) {
|
|
12
|
+
TelemetryClientSingleton.instance = new TelemetryClientSingleton();
|
|
13
|
+
}
|
|
14
|
+
return TelemetryClientSingleton.instance;
|
|
15
|
+
}
|
|
16
|
+
async initTelemetryClient() {
|
|
17
|
+
try {
|
|
18
|
+
const telemetryClient = await (0, diagnostics_nodejs_1.NewTelemetryClient)('node-vtex-api', constants_1.APP.ID || 'vtex-app', {
|
|
19
|
+
additionalAttrs: {
|
|
20
|
+
'version': constants_1.APP.VERSION || '',
|
|
21
|
+
'environment': process.env.VTEX_WORKSPACE || 'development',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
this.telemetryClient = telemetryClient;
|
|
25
|
+
return telemetryClient;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error('Failed to initialize telemetry client:', error);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
this.initializationPromise = undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async getClient() {
|
|
36
|
+
if (this.telemetryClient) {
|
|
37
|
+
return this.telemetryClient;
|
|
38
|
+
}
|
|
39
|
+
if (this.initializationPromise) {
|
|
40
|
+
return this.initializationPromise;
|
|
41
|
+
}
|
|
42
|
+
this.initializationPromise = this.initTelemetryClient();
|
|
43
|
+
return this.initializationPromise;
|
|
44
|
+
}
|
|
45
|
+
reset() {
|
|
46
|
+
this.telemetryClient = undefined;
|
|
47
|
+
this.initializationPromise = undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function getTelemetryClient() {
|
|
51
|
+
return TelemetryClientSingleton.getInstance().getClient();
|
|
52
|
+
}
|
|
53
|
+
exports.getTelemetryClient = getTelemetryClient;
|
|
54
|
+
function resetTelemetryClient() {
|
|
55
|
+
TelemetryClientSingleton.getInstance().reset();
|
|
56
|
+
}
|
|
57
|
+
exports.resetTelemetryClient = resetTelemetryClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './client';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client"), exports);
|
|
@@ -30,9 +30,6 @@ const addTracingMiddleware = (tracer) => {
|
|
|
30
30
|
await next();
|
|
31
31
|
}
|
|
32
32
|
catch (err) {
|
|
33
|
-
if (!(err instanceof Error)) {
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
33
|
tracing_1.ErrorReport.create({ originalError: err }).injectOnSpan(currentSpan, (_a = ctx.vtex) === null || _a === void 0 ? void 0 : _a.logger);
|
|
37
34
|
throw err;
|
|
38
35
|
}
|
|
@@ -91,9 +88,6 @@ const traceUserLandRemainingPipelineMiddleware = () => {
|
|
|
91
88
|
await next();
|
|
92
89
|
}
|
|
93
90
|
catch (err) {
|
|
94
|
-
if (!(err instanceof Error)) {
|
|
95
|
-
throw err;
|
|
96
|
-
}
|
|
97
91
|
tracing_1.ErrorReport.create({ originalError: err }).injectOnSpan(span, ctx.vtex.logger);
|
|
98
92
|
throw err;
|
|
99
93
|
}
|
|
@@ -13,7 +13,7 @@ const constants_1 = require("../../constants");
|
|
|
13
13
|
const MetricsAccumulator_1 = require("../../metrics/MetricsAccumulator");
|
|
14
14
|
const loaders_1 = require("../loaders");
|
|
15
15
|
const console_1 = require("../logger/console");
|
|
16
|
-
const
|
|
16
|
+
const loggerTypes_1 = require("../logger/loggerTypes");
|
|
17
17
|
const requestMetricsMiddleware_1 = require("../metrics/requestMetricsMiddleware");
|
|
18
18
|
const TracerSingleton_1 = require("../tracing/TracerSingleton");
|
|
19
19
|
const tracingMiddlewares_1 = require("../tracing/tracingMiddlewares");
|
|
@@ -146,7 +146,7 @@ const scaleClientCaches = (scaleFactor, options) => Object.entries(options || {}
|
|
|
146
146
|
const previous = opts.memoryCache.storage.max;
|
|
147
147
|
const current = previous / scaleFactor;
|
|
148
148
|
opts.memoryCache.storage.max = current;
|
|
149
|
-
(0, console_1.logOnceToDevConsole)(`Scaling ${name} cache capacity from ${previous} to ${current}`,
|
|
149
|
+
(0, console_1.logOnceToDevConsole)(`Scaling ${name} cache capacity from ${previous} to ${current}`, loggerTypes_1.LogLevel.Warn);
|
|
150
150
|
}
|
|
151
151
|
});
|
|
152
152
|
const startWorker = (serviceJSON) => {
|
|
@@ -6,15 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.parseBodyMiddleware = void 0;
|
|
7
7
|
const co_body_1 = __importDefault(require("co-body"));
|
|
8
8
|
const logger_1 = require("../../../../logger");
|
|
9
|
-
const console_1 = require("
|
|
9
|
+
const console_1 = require("../../../../logger/console");
|
|
10
10
|
async function parseBodyMiddleware(ctx, next) {
|
|
11
11
|
try {
|
|
12
12
|
ctx.state.body = await (0, co_body_1.default)(ctx.req);
|
|
13
13
|
}
|
|
14
14
|
catch (err) {
|
|
15
|
-
if (!(err instanceof Error)) {
|
|
16
|
-
throw err;
|
|
17
|
-
}
|
|
18
15
|
const msg = `Error parsing event body: ${err.message || err}`;
|
|
19
16
|
ctx.status = 500;
|
|
20
17
|
ctx.body = msg;
|
|
@@ -53,9 +53,6 @@ async function graphqlError(ctx, next) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
catch (e) {
|
|
56
|
-
if (!(e instanceof apollo_server_errors_1.ApolloError)) {
|
|
57
|
-
throw e;
|
|
58
|
-
}
|
|
59
56
|
if (e.code === RequestCancelledError_1.cancelledErrorCode) {
|
|
60
57
|
ctx.status = RequestCancelledError_1.cancelledRequestStatus;
|
|
61
58
|
return;
|
|
@@ -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);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.error = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
4
|
const constants_1 = require("../../../../../constants");
|
|
6
5
|
const RequestCancelledError_1 = require("../../../../../errors/RequestCancelledError");
|
|
7
6
|
const TooManyRequestsError_1 = require("../../../../../errors/TooManyRequestsError");
|
|
@@ -63,13 +62,11 @@ async function error(ctx, next) {
|
|
|
63
62
|
console.error('[node-vtex-api error]', e);
|
|
64
63
|
const err = (0, error_1.cleanError)(e);
|
|
65
64
|
// Add response
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
: 500;
|
|
72
|
-
}
|
|
65
|
+
ctx.status = e && e.status >= 400 && e.status <= 599
|
|
66
|
+
? e.status
|
|
67
|
+
: ctx.status >= 500 && ctx.status <= 599
|
|
68
|
+
? ctx.status
|
|
69
|
+
: 500;
|
|
73
70
|
// Do not generate etag for errors
|
|
74
71
|
ctx.remove(META_HEADER);
|
|
75
72
|
ctx.remove(ETAG_HEADER);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtex/api",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.49.0",
|
|
4
4
|
"description": "VTEX I/O API client",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"clean": "rimraf lib/",
|
|
13
13
|
"watch": "yarn clean && tsc --watch",
|
|
14
14
|
"build": "yarn clean && tsc",
|
|
15
|
-
"gen": "typescript-json-schema
|
|
15
|
+
"gen": "typescript-json-schema src/responses.ts PublicAppManifest > gen/manifest.schema",
|
|
16
16
|
"test": "jest",
|
|
17
17
|
"lint": "tslint -c tslint.json './src/**/*.ts'",
|
|
18
18
|
"format": "prettier --config ./.prettierrc --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
@@ -49,12 +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.8",
|
|
52
53
|
"@vtex/node-error-report": "^0.0.3",
|
|
53
54
|
"@wry/equality": "^0.1.9",
|
|
54
55
|
"agentkeepalive": "^4.0.2",
|
|
55
56
|
"apollo-server-errors": "^2.2.1",
|
|
56
57
|
"archiver": "^3.0.0",
|
|
57
|
-
"axios": "^
|
|
58
|
+
"axios": "^0.21.1",
|
|
58
59
|
"axios-retry": "^3.1.2",
|
|
59
60
|
"bluebird": "^3.5.4",
|
|
60
61
|
"chalk": "^2.4.2",
|
|
@@ -121,7 +122,28 @@
|
|
|
121
122
|
"tslint-config-vtex": "^2.1.0",
|
|
122
123
|
"tslint-eslint-rules": "^5.4.0",
|
|
123
124
|
"typemoq": "^2.1.0",
|
|
124
|
-
"typescript": "4.
|
|
125
|
-
"typescript-json-schema": "^0.
|
|
125
|
+
"typescript": "^4.4.4",
|
|
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"
|
|
126
148
|
}
|
|
127
149
|
}
|