@gravity-ui/gateway 4.10.3 → 4.11.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
|
@@ -515,7 +515,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
515
515
|
let stopListeningForAbort = null;
|
|
516
516
|
// eslint-disable-next-line complexity
|
|
517
517
|
return new Promise((resolve, reject) => {
|
|
518
|
-
var _a, _b, _c, _d;
|
|
518
|
+
var _a, _b, _c, _d, _e;
|
|
519
519
|
let endpointData = (endpoints === null || endpoints === void 0 ? void 0 : endpoints.grpcEndpoint) || (endpoints === null || endpoints === void 0 ? void 0 : endpoints.endpoint);
|
|
520
520
|
if (typeof config.endpoint === 'function') {
|
|
521
521
|
endpointData = config.endpoint(endpoints, args);
|
|
@@ -662,7 +662,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
662
662
|
ctx.log('Starting unary request', {
|
|
663
663
|
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
664
664
|
});
|
|
665
|
-
let retries = (_d =
|
|
665
|
+
let retries = (_e = (_d = actionConfig.retries) !== null && _d !== void 0 ? _d : config.retries) !== null && _e !== void 0 ? _e : 0;
|
|
666
666
|
let actionCall = service[action].bind(service);
|
|
667
667
|
const callAction = () => {
|
|
668
668
|
let trailingMetadata = {};
|
package/build/components/rest.js
CHANGED
|
@@ -39,7 +39,7 @@ 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, (_d = config === null || config === void 0 ? void 0 : config.axiosRetryCondition) !== null && _d !== void 0 ? _d : options === null || options === void 0 ? void 0 : options.axiosRetryCondition, options === null || options === void 0 ? void 0 : options.axiosConfig, options === null || options === void 0 ? void 0 : options.axiosInterceptors);
|
|
40
40
|
/* eslint-disable complexity */
|
|
41
41
|
return async function action(actionConfig) {
|
|
42
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
42
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
43
43
|
const { args, requestId, headers: requestHeaders, ctx: parentCtx, authArgs, userId, abortSignal, } = actionConfig;
|
|
44
44
|
const debugHeaders = {};
|
|
45
45
|
const lang = requestHeaders[constants_1.DEFAULT_LANG_HEADER] || constants_1.Lang.Ru; // header might be empty string
|
|
@@ -206,9 +206,10 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
206
206
|
const startRequestTime = Date.now();
|
|
207
207
|
let axiosClient = defaultAxiosClient;
|
|
208
208
|
const customActionTimeout = (_f = (_e = (_d = actionConfig.timeout) !== null && _d !== void 0 ? _d : config.timeout) !== null && _e !== void 0 ? _e : endpointAxiosConfig === null || endpointAxiosConfig === void 0 ? void 0 : endpointAxiosConfig.timeout) !== null && _f !== void 0 ? _f : timeout;
|
|
209
|
-
|
|
209
|
+
const customActionRetries = (_g = actionConfig.retries) !== null && _g !== void 0 ? _g : config.retries;
|
|
210
|
+
if (actionConfig.timeout || actionConfig.retries || endpointAxiosConfig) {
|
|
210
211
|
const customActionAxiosConfig = Object.assign(Object.assign({}, ((options === null || options === void 0 ? void 0 : options.axiosConfig) || {})), (endpointAxiosConfig || {}));
|
|
211
|
-
axiosClient = (0, axios_1.getAxiosClient)(customActionTimeout, config === null || config === void 0 ? void 0 : config.
|
|
212
|
+
axiosClient = (0, axios_1.getAxiosClient)(customActionTimeout, customActionRetries, (_h = config === null || config === void 0 ? void 0 : config.axiosRetryCondition) !== null && _h !== void 0 ? _h : options === null || options === void 0 ? void 0 : options.axiosRetryCondition, customActionAxiosConfig, options === null || options === void 0 ? void 0 : options.axiosInterceptors);
|
|
212
213
|
}
|
|
213
214
|
headers['x-request-timeout'] = customActionTimeout !== null && customActionTimeout !== void 0 ? customActionTimeout : constants_1.DEFAULT_TIMEOUT;
|
|
214
215
|
ctx.log('Starting request', { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
@@ -219,7 +220,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
219
220
|
requestId,
|
|
220
221
|
requestMethod: config.method,
|
|
221
222
|
requestUrl: actionURL,
|
|
222
|
-
traceId: ((
|
|
223
|
+
traceId: ((_j = ctx.getTraceId) === null || _j === void 0 ? void 0 : _j.call(ctx)) || '',
|
|
223
224
|
userId: userId || '',
|
|
224
225
|
};
|
|
225
226
|
const requestConfig = {
|
|
@@ -246,7 +247,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
246
247
|
const responseHeaders = {};
|
|
247
248
|
const endRequestTime = Date.now();
|
|
248
249
|
requestData.requestTime = endRequestTime - startRequestTime;
|
|
249
|
-
const actualResponseContentType = (
|
|
250
|
+
const actualResponseContentType = (_k = response.headers) === null || _k === void 0 ? void 0 : _k['Content-Type'];
|
|
250
251
|
const expectedResponseContentType = config.expectedResponseContentType || options.expectedResponseContentType;
|
|
251
252
|
if (actualResponseContentType && expectedResponseContentType) {
|
|
252
253
|
let isInvalidResponseContentType;
|
|
@@ -343,7 +344,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
343
344
|
}
|
|
344
345
|
const responseStatus = lodash_1.default.get(parsedError, 'status') || lodash_1.default.get(error, 'status', 500);
|
|
345
346
|
if (options === null || options === void 0 ? void 0 : options.sendStats) {
|
|
346
|
-
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize((
|
|
347
|
+
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize((_l = error === null || error === void 0 ? void 0 : error.response) === null || _l === void 0 ? void 0 : _l.data, ctx, ErrorConstructor), restStatus: responseStatus, userId }), (0, redact_sensitive_headers_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
347
348
|
}
|
|
348
349
|
else {
|
|
349
350
|
ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus }));
|
package/build/index.js
CHANGED
|
@@ -117,7 +117,7 @@ function generateGatewayApi(schema, config, grpcContext, baseApi) {
|
|
|
117
117
|
function generateGatewayApiController(schemasByScope, Api, config, controllerActions) {
|
|
118
118
|
// eslint-disable-next-line complexity
|
|
119
119
|
return async function gateway(req, res) {
|
|
120
|
-
var _a, _b, _c, _d;
|
|
120
|
+
var _a, _b, _c, _d, _e;
|
|
121
121
|
const { userId } = res.locals || {};
|
|
122
122
|
const { service, action, scope = 'root' } = req.params;
|
|
123
123
|
const withDebugHeaders = typeof config.withDebugHeaders === 'function'
|
|
@@ -227,13 +227,15 @@ function generateGatewayApiController(schemasByScope, Api, config, controllerAct
|
|
|
227
227
|
else {
|
|
228
228
|
responseError = lodash_1.default.omit(error, ['debug']);
|
|
229
229
|
// Remove DebugInfo
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
const grpcDetails = (_e = responseError.details) === null || _e === void 0 ? void 0 : _e.details;
|
|
231
|
+
if (grpcDetails) {
|
|
232
|
+
lodash_1.default.forEach(grpcDetails, function (value, key) {
|
|
232
233
|
const DEBUG_INFO_TYPE = 'type.googleapis.com/google.rpc.DebugInfo';
|
|
233
234
|
if ((value === null || value === void 0 ? void 0 : value['@type']) === DEBUG_INFO_TYPE) {
|
|
234
|
-
|
|
235
|
+
grpcDetails[key] = undefined;
|
|
235
236
|
}
|
|
236
237
|
});
|
|
238
|
+
responseError.details.details = grpcDetails.filter(Boolean);
|
|
237
239
|
}
|
|
238
240
|
}
|
|
239
241
|
if (onRequestFailed) {
|
package/build/models/common.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export interface ApiActionConfig<Context extends GatewayContext, TRequestData, T
|
|
|
29
29
|
args: TRequestData;
|
|
30
30
|
ctx: Context;
|
|
31
31
|
timeout?: number;
|
|
32
|
+
retries?: number;
|
|
32
33
|
callback?: (response: TResponseData) => void;
|
|
33
34
|
authArgs?: Record<string, unknown>;
|
|
34
35
|
userId?: string;
|