@gravity-ui/gateway 2.5.4 → 3.0.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/build/components/grpc.js
CHANGED
|
@@ -384,7 +384,8 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
return async function action(actionConfig) {
|
|
387
|
-
|
|
387
|
+
var _a;
|
|
388
|
+
const { args, requestId, headers, ctx: parentCtx, userId } = actionConfig;
|
|
388
389
|
const { action } = config;
|
|
389
390
|
const lang = headers[constants_1.DEFAULT_LANG_HEADER] || constants_1.Lang.Ru; // header might be empty string
|
|
390
391
|
const ctx = parentCtx.create(`Gateway ${serviceName} ${actionName} [grpc]`, {
|
|
@@ -403,6 +404,8 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
403
404
|
requestId: actionConfig.requestId,
|
|
404
405
|
requestMethod: action,
|
|
405
406
|
requestUrl: config.protoKey,
|
|
407
|
+
traceId: ((_a = ctx.getTraceId) === null || _a === void 0 ? void 0 : _a.call(ctx)) || '',
|
|
408
|
+
userId: userId || '',
|
|
406
409
|
};
|
|
407
410
|
const debugHeaders = {
|
|
408
411
|
'x-api-request-action': action,
|
package/build/components/rest.js
CHANGED
|
@@ -39,8 +39,8 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
39
39
|
const defaultAxiosClient = (0, axios_1.getAxiosClient)(timeout, config === null || config === void 0 ? void 0 : config.retries, options === null || options === void 0 ? void 0 : options.axiosConfig);
|
|
40
40
|
/* eslint-disable complexity */
|
|
41
41
|
return async function action(actionConfig) {
|
|
42
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
43
|
-
const { args, requestId, headers: requestHeaders, ctx: parentCtx, authArgs } = actionConfig;
|
|
42
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
43
|
+
const { args, requestId, headers: requestHeaders, ctx: parentCtx, authArgs, userId, } = actionConfig;
|
|
44
44
|
const debugHeaders = {};
|
|
45
45
|
const lang = requestHeaders[constants_1.DEFAULT_LANG_HEADER] || constants_1.Lang.Ru; // header might be empty string
|
|
46
46
|
const serviceName = (options === null || options === void 0 ? void 0 : options.serviceName) || serviceKey;
|
|
@@ -210,6 +210,8 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
210
210
|
requestId,
|
|
211
211
|
requestMethod: config.method,
|
|
212
212
|
requestUrl: actionURL,
|
|
213
|
+
traceId: ((_f = ctx.getTraceId) === null || _f === void 0 ? void 0 : _f.call(ctx)) || '',
|
|
214
|
+
userId: userId || '',
|
|
213
215
|
};
|
|
214
216
|
const requestConfig = {
|
|
215
217
|
url: actionURL,
|
|
@@ -245,7 +247,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
245
247
|
const responseHeaders = {};
|
|
246
248
|
const endRequestTime = Date.now();
|
|
247
249
|
requestData.requestTime = endRequestTime - startRequestTime;
|
|
248
|
-
const actualResponseContentType = (
|
|
250
|
+
const actualResponseContentType = (_g = response.headers) === null || _g === void 0 ? void 0 : _g['Content-Type'];
|
|
249
251
|
const expectedResponseContentType = config.expectedResponseContentType || options.expectedResponseContentType;
|
|
250
252
|
if (actualResponseContentType && expectedResponseContentType) {
|
|
251
253
|
let isInvalidResponseContentType;
|
|
@@ -342,7 +344,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
342
344
|
}
|
|
343
345
|
const responseStatus = lodash_1.default.get(parsedError, 'status') || lodash_1.default.get(error, 'status', 500);
|
|
344
346
|
if (options === null || options === void 0 ? void 0 : options.sendStats) {
|
|
345
|
-
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize((
|
|
347
|
+
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize((_h = error === null || error === void 0 ? void 0 : error.response) === null || _h === void 0 ? void 0 : _h.data, ctx, ErrorConstructor), restStatus: responseStatus, userId }), (0, redact_sensitive_headers_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
346
348
|
}
|
|
347
349
|
else {
|
|
348
350
|
ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus }));
|
package/build/index.js
CHANGED
|
@@ -112,6 +112,7 @@ function generateGatewayApiController(schemasByScope, Api, config, controllerAct
|
|
|
112
112
|
// eslint-disable-next-line complexity
|
|
113
113
|
return async function gateway(req, res) {
|
|
114
114
|
var _a, _b, _c;
|
|
115
|
+
const { userId } = res.locals || {};
|
|
115
116
|
const { service, action, scope = 'root' } = req.params;
|
|
116
117
|
const withDebugHeaders = typeof config.withDebugHeaders === 'function'
|
|
117
118
|
? config.withDebugHeaders(req, res)
|
|
@@ -186,6 +187,7 @@ function generateGatewayApiController(schemasByScope, Api, config, controllerAct
|
|
|
186
187
|
ctx: req.ctx,
|
|
187
188
|
args,
|
|
188
189
|
authArgs: config.getAuthArgs(req, res),
|
|
190
|
+
userId,
|
|
189
191
|
});
|
|
190
192
|
if (withDebugHeaders) {
|
|
191
193
|
res.set(debugHeaders);
|
package/build/models/common.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export interface ApiActionConfig<Context extends GatewayContext, TRequestData, T
|
|
|
29
29
|
timeout?: number;
|
|
30
30
|
callback?: (response: TResponseData) => void;
|
|
31
31
|
authArgs?: Record<string, unknown>;
|
|
32
|
+
userId?: string;
|
|
32
33
|
}
|
|
33
34
|
export interface GRPCActionData {
|
|
34
35
|
[key: string]: unknown;
|
|
@@ -47,6 +48,8 @@ export interface Stats {
|
|
|
47
48
|
requestMethod: string;
|
|
48
49
|
requestUrl: string;
|
|
49
50
|
timestamp: number;
|
|
51
|
+
userId?: string;
|
|
52
|
+
traceId: string;
|
|
50
53
|
}
|
|
51
54
|
export type ControllerType = 'rest' | 'grpc';
|
|
52
55
|
export interface GatewayError {
|