@gravity-ui/gateway 2.3.0 → 2.5.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 +10 -0
- package/build/components/rest.js +23 -1
- package/build/constants.d.ts +1 -0
- package/build/constants.js +2 -1
- package/build/index.js +2 -0
- package/build/models/common.d.ts +4 -2
- package/package.json +1 -1
package/build/components/grpc.js
CHANGED
|
@@ -426,6 +426,16 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
426
426
|
if ('protoPath' in config) {
|
|
427
427
|
debugHeaders['x-api-request-protopath'] = config.protoPath;
|
|
428
428
|
}
|
|
429
|
+
if (typeof options.proxyDebugHeaders === 'function') {
|
|
430
|
+
Object.assign(debugHeaders, options.proxyDebugHeaders(Object.assign({}, headers), 'grpc'));
|
|
431
|
+
}
|
|
432
|
+
else if (Array.isArray(options.proxyDebugHeaders)) {
|
|
433
|
+
for (const headerName of options.proxyDebugHeaders) {
|
|
434
|
+
if (headers[headerName] !== undefined) {
|
|
435
|
+
debugHeaders[`x-gateway-${headerName}`] = headers[headerName];
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
429
439
|
ctx.log('Initiating request', { debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders) });
|
|
430
440
|
const sendStats = (status, data) => {
|
|
431
441
|
if (options === null || options === void 0 ? void 0 : options.sendStats) {
|
package/build/components/rest.js
CHANGED
|
@@ -184,13 +184,24 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
184
184
|
if (headers['content-type']) {
|
|
185
185
|
debugHeaders['x-api-content-type'] = headers['content-type'];
|
|
186
186
|
}
|
|
187
|
+
if (typeof options.proxyDebugHeaders === 'function') {
|
|
188
|
+
Object.assign(debugHeaders, options.proxyDebugHeaders(Object.assign({}, requestHeaders), 'rest'));
|
|
189
|
+
}
|
|
190
|
+
else if (Array.isArray(options.proxyDebugHeaders)) {
|
|
191
|
+
for (const headerName of options.proxyDebugHeaders) {
|
|
192
|
+
if (headers[headerName] !== undefined) {
|
|
193
|
+
debugHeaders[`x-gateway-${headerName}`] = headers[headerName];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
187
197
|
const startRequestTime = Date.now();
|
|
188
198
|
let axiosClient = defaultAxiosClient;
|
|
199
|
+
const customActionTimeout = (_e = (_d = (_c = actionConfig.timeout) !== null && _c !== void 0 ? _c : config.timeout) !== null && _d !== void 0 ? _d : endpointAxiosConfig.timeout) !== null && _e !== void 0 ? _e : timeout;
|
|
189
200
|
if (actionConfig.timeout || endpointAxiosConfig) {
|
|
190
|
-
const customActionTimeout = (_e = (_d = (_c = actionConfig.timeout) !== null && _c !== void 0 ? _c : config.timeout) !== null && _d !== void 0 ? _d : endpointAxiosConfig.timeout) !== null && _e !== void 0 ? _e : timeout;
|
|
191
201
|
const customActionAxiosConfig = Object.assign(Object.assign({}, ((options === null || options === void 0 ? void 0 : options.axiosConfig) || {})), (endpointAxiosConfig || {}));
|
|
192
202
|
axiosClient = (0, axios_1.getAxiosClient)(customActionTimeout, config === null || config === void 0 ? void 0 : config.retries, customActionAxiosConfig);
|
|
193
203
|
}
|
|
204
|
+
headers['x-request-timeout'] = customActionTimeout !== null && customActionTimeout !== void 0 ? customActionTimeout : constants_1.DEFAULT_TIMEOUT;
|
|
194
205
|
ctx.log('Starting request', { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
195
206
|
const requestData = {
|
|
196
207
|
timestamp: startRequestTime,
|
|
@@ -218,6 +229,17 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
218
229
|
responseType: config.responseType,
|
|
219
230
|
});
|
|
220
231
|
}
|
|
232
|
+
axiosClient.interceptors.request.use((requestConfig) => {
|
|
233
|
+
var _a;
|
|
234
|
+
requestConfig.headers.set('x-request-attempt',
|
|
235
|
+
// according this issue https://github.com/softonic/axios-retry/issues/167
|
|
236
|
+
// 'axios-retry' doesn`t define retryCount field in exported type
|
|
237
|
+
// however in this issue https://github.com/softonic/axios-retry/issues/75#issuecomment-502151719
|
|
238
|
+
// people use it
|
|
239
|
+
// @ts-ignore
|
|
240
|
+
((_a = requestConfig[constants_1.AXIOS_RETRY_NAMESPACE]) === null || _a === void 0 ? void 0 : _a.retryCount) || 0);
|
|
241
|
+
return requestConfig;
|
|
242
|
+
});
|
|
221
243
|
try {
|
|
222
244
|
const response = await axiosClient.request(requestConfig);
|
|
223
245
|
const responseHeaders = {};
|
package/build/constants.d.ts
CHANGED
package/build/constants.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.DEFAULT_VALIDATION_SCHEMA = exports.RECREATE_SERVICE_CODES = exports.RETRYABLE_STATUS_CODES = exports.ANY_ACTION_SYMBOL = exports.ECMA_STRING_SIZE = exports.DEFAULT_GRPC_OPTIONS = exports.DEFAULT_AXIOS_OPTIONS = exports.DEFAULT_PROXY_HEADERS = exports.DEFAULT_LANG_HEADER = exports.DEFAULT_TIMEOUT = exports.Lang = exports.VERSION = void 0;
|
|
29
|
+
exports.AXIOS_RETRY_NAMESPACE = exports.DEFAULT_VALIDATION_SCHEMA = exports.RECREATE_SERVICE_CODES = exports.RETRYABLE_STATUS_CODES = exports.ANY_ACTION_SYMBOL = exports.ECMA_STRING_SIZE = exports.DEFAULT_GRPC_OPTIONS = exports.DEFAULT_AXIOS_OPTIONS = exports.DEFAULT_PROXY_HEADERS = exports.DEFAULT_LANG_HEADER = exports.DEFAULT_TIMEOUT = exports.Lang = exports.VERSION = void 0;
|
|
30
30
|
const http_1 = __importDefault(require("http"));
|
|
31
31
|
const https_1 = __importDefault(require("https"));
|
|
32
32
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
@@ -99,3 +99,4 @@ exports.DEFAULT_VALIDATION_SCHEMA = {
|
|
|
99
99
|
],
|
|
100
100
|
},
|
|
101
101
|
};
|
|
102
|
+
exports.AXIOS_RETRY_NAMESPACE = 'axios-retry';
|
package/build/index.js
CHANGED
|
@@ -75,6 +75,7 @@ function createApiAction(schema, config, serviceKey, actionName, api, grpcContex
|
|
|
75
75
|
timeout: config.timeout,
|
|
76
76
|
sendStats: config.sendStats,
|
|
77
77
|
proxyHeaders: config.proxyHeaders,
|
|
78
|
+
proxyDebugHeaders: config.proxyDebugHeaders,
|
|
78
79
|
axiosConfig: config.axiosConfig,
|
|
79
80
|
validationSchema: config.validationSchema,
|
|
80
81
|
encodePathArgs: config.encodePathArgs,
|
|
@@ -87,6 +88,7 @@ function createApiAction(schema, config, serviceKey, actionName, api, grpcContex
|
|
|
87
88
|
timeout: config.timeout,
|
|
88
89
|
sendStats: config.sendStats,
|
|
89
90
|
proxyHeaders: config.proxyHeaders,
|
|
91
|
+
proxyDebugHeaders: config.proxyDebugHeaders,
|
|
90
92
|
grpcOptions: config.grpcOptions,
|
|
91
93
|
grpcRecreateService,
|
|
92
94
|
getAuthHeaders: config.getAuthHeaders,
|
package/build/models/common.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export type ProxyHeaders = string[] | ProxyHeadersFunction;
|
|
|
65
65
|
export type ProxyResponseHeadersFunction = (headers: Headers, type: ControllerType) => Headers;
|
|
66
66
|
export type ProxyResponseHeaders = string[] | ProxyResponseHeadersFunction;
|
|
67
67
|
export type GetAuthHeadersParams<AuthArgs = Record<string, unknown>> = {
|
|
68
|
-
actionType:
|
|
68
|
+
actionType: ControllerType;
|
|
69
69
|
serviceName: string;
|
|
70
70
|
requestHeaders: Headers;
|
|
71
71
|
authArgs: AuthArgs | undefined;
|
|
@@ -80,6 +80,7 @@ export interface GatewayApiOptions<Context extends GatewayContext> {
|
|
|
80
80
|
grpcRecreateService?: boolean;
|
|
81
81
|
axiosConfig?: AxiosRequestConfig;
|
|
82
82
|
proxyHeaders?: ProxyHeaders;
|
|
83
|
+
proxyDebugHeaders?: ProxyHeaders;
|
|
83
84
|
validationSchema?: object;
|
|
84
85
|
encodePathArgs?: boolean;
|
|
85
86
|
expectedResponseContentType?: ResponseContentType | ResponseContentType[];
|
|
@@ -239,7 +240,8 @@ export interface GatewayConfig<Context extends GatewayContext, Req extends Gatew
|
|
|
239
240
|
includeProtoRoots?: string[];
|
|
240
241
|
caCertificatePath: string | null;
|
|
241
242
|
proxyHeaders: ProxyHeaders;
|
|
242
|
-
|
|
243
|
+
proxyDebugHeaders?: ProxyHeaders;
|
|
244
|
+
withDebugHeaders?: boolean | ((req: Req, res: Res) => boolean);
|
|
243
245
|
validationSchema?: object;
|
|
244
246
|
encodePathArgs?: boolean;
|
|
245
247
|
getAuthArgs: (req: Req, res: Res) => Record<string, unknown> | undefined;
|