@gravity-ui/gateway 2.3.0 → 2.4.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.
@@ -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) {
@@ -184,6 +184,16 @@ 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;
189
199
  if (actionConfig.timeout || endpointAxiosConfig) {
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,
@@ -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: 'rest' | 'grpc';
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
- withDebugHeaders: boolean | ((req: Req, res: Res) => boolean);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/gateway",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/index.js",