@gravity-ui/gateway 4.7.0 → 4.7.1-alpha.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.
Files changed (95) hide show
  1. package/README.md +128 -3
  2. package/{build → dist/commonjs}/components/grpc.d.ts +5 -5
  3. package/{build → dist/commonjs}/components/grpc.js +94 -84
  4. package/{build → dist/commonjs}/components/mixed.d.ts +4 -4
  5. package/{build → dist/commonjs}/components/mixed.js +11 -12
  6. package/{build → dist/commonjs}/components/rest.d.ts +5 -5
  7. package/{build → dist/commonjs}/components/rest.js +33 -33
  8. package/{build → dist/commonjs}/constants.d.ts +2 -2
  9. package/{build → dist/commonjs}/constants.js +29 -19
  10. package/{build → dist/commonjs}/index.d.ts +9 -8
  11. package/{build → dist/commonjs}/index.js +35 -46
  12. package/{build → dist/commonjs}/models/common.d.ts +12 -7
  13. package/{build → dist/commonjs}/models/context.d.ts +0 -1
  14. package/dist/commonjs/package.json +3 -0
  15. package/dist/commonjs/utils/axios.d.ts +4 -0
  16. package/{build → dist/commonjs}/utils/axios.js +3 -4
  17. package/{build → dist/commonjs}/utils/common.d.ts +4 -4
  18. package/{build → dist/commonjs}/utils/common.js +8 -8
  19. package/{build → dist/commonjs}/utils/create-context-api.d.ts +2 -2
  20. package/{build → dist/commonjs}/utils/create-context-api.js +5 -6
  21. package/{build → dist/commonjs}/utils/grpc-reflection.js +15 -35
  22. package/{build → dist/commonjs}/utils/grpc.d.ts +1 -1
  23. package/{build → dist/commonjs}/utils/grpc.js +10 -11
  24. package/dist/commonjs/utils/overrideEndpoints/index.d.ts +2 -0
  25. package/dist/commonjs/utils/overrideEndpoints/index.js +4 -0
  26. package/{build → dist/commonjs}/utils/overrideEndpoints/overrideEndpoints.d.ts +1 -1
  27. package/{build → dist/commonjs}/utils/overrideEndpoints/overrideEndpoints.js +1 -2
  28. package/dist/commonjs/utils/package-root.d.ts +1 -0
  29. package/dist/commonjs/utils/package-root.js +44 -0
  30. package/{build → dist/commonjs}/utils/parse-error.d.ts +5 -5
  31. package/{build → dist/commonjs}/utils/parse-error.js +19 -19
  32. package/{build → dist/commonjs}/utils/proto-path-resolver.d.ts +1 -1
  33. package/{build → dist/commonjs}/utils/proto-path-resolver.js +24 -15
  34. package/{build → dist/commonjs}/utils/redact-sensitive-headers.d.ts +1 -2
  35. package/{build → dist/commonjs}/utils/redact-sensitive-headers.js +1 -2
  36. package/dist/commonjs/utils/source-dir.d.ts +1 -0
  37. package/dist/commonjs/utils/source-dir.js +41 -0
  38. package/{build → dist/commonjs}/utils/typed-api.d.ts +1 -1
  39. package/{build → dist/commonjs}/utils/typed-api.js +1 -2
  40. package/{build → dist/commonjs}/utils/validate.js +6 -10
  41. package/dist/esm/components/grpc.d.ts +24 -0
  42. package/dist/esm/components/grpc.js +691 -0
  43. package/dist/esm/components/mixed.d.ts +11 -0
  44. package/dist/esm/components/mixed.js +62 -0
  45. package/dist/esm/components/rest.d.ts +8 -0
  46. package/dist/esm/components/rest.js +357 -0
  47. package/dist/esm/constants.d.ts +53 -0
  48. package/dist/esm/constants.js +82 -0
  49. package/dist/esm/index.d.ts +13 -0
  50. package/dist/esm/index.js +274 -0
  51. package/dist/esm/models/common.d.ts +289 -0
  52. package/dist/esm/models/common.js +5 -0
  53. package/dist/esm/models/context.d.ts +22 -0
  54. package/dist/esm/models/context.js +1 -0
  55. package/dist/esm/models/error.d.ts +12 -0
  56. package/dist/esm/models/error.js +1 -0
  57. package/dist/esm/package.json +3 -0
  58. package/{build → dist/esm}/utils/axios.d.ts +1 -1
  59. package/dist/esm/utils/axios.js +24 -0
  60. package/dist/esm/utils/common.d.ts +16 -0
  61. package/dist/esm/utils/common.js +48 -0
  62. package/dist/esm/utils/create-context-api.d.ts +4 -0
  63. package/dist/esm/utils/create-context-api.js +38 -0
  64. package/dist/esm/utils/grpc-reflection.d.ts +28 -0
  65. package/dist/esm/utils/grpc-reflection.js +72 -0
  66. package/dist/esm/utils/grpc.d.ts +15 -0
  67. package/dist/esm/utils/grpc.js +72 -0
  68. package/dist/esm/utils/overrideEndpoints/index.d.ts +2 -0
  69. package/dist/esm/utils/overrideEndpoints/index.js +2 -0
  70. package/dist/esm/utils/overrideEndpoints/overrideEndpoints.d.ts +17 -0
  71. package/dist/esm/utils/overrideEndpoints/overrideEndpoints.js +96 -0
  72. package/dist/esm/utils/package-root.d.ts +1 -0
  73. package/dist/esm/utils/package-root.js +8 -0
  74. package/dist/esm/utils/parse-error.d.ts +30 -0
  75. package/dist/esm/utils/parse-error.js +214 -0
  76. package/dist/esm/utils/proto-path-resolver.d.ts +2 -0
  77. package/dist/esm/utils/proto-path-resolver.js +23 -0
  78. package/dist/esm/utils/redact-sensitive-headers.d.ts +3 -0
  79. package/dist/esm/utils/redact-sensitive-headers.js +12 -0
  80. package/dist/esm/utils/source-dir.d.ts +1 -0
  81. package/dist/esm/utils/source-dir.js +4 -0
  82. package/dist/esm/utils/typed-api.d.ts +2 -0
  83. package/dist/esm/utils/typed-api.js +3 -0
  84. package/dist/esm/utils/validate.d.ts +4 -0
  85. package/dist/esm/utils/validate.js +47 -0
  86. package/package.json +41 -16
  87. package/build/utils/overrideEndpoints/index.d.ts +0 -2
  88. package/build/utils/overrideEndpoints/index.js +0 -4
  89. /package/bin/{patch.js → patch.cjs} +0 -0
  90. /package/{build → dist/commonjs}/models/common.js +0 -0
  91. /package/{build → dist/commonjs}/models/context.js +0 -0
  92. /package/{build → dist/commonjs}/models/error.d.ts +0 -0
  93. /package/{build → dist/commonjs}/models/error.js +0 -0
  94. /package/{build → dist/commonjs}/utils/grpc-reflection.d.ts +0 -0
  95. /package/{build → dist/commonjs}/utils/validate.d.ts +0 -0
@@ -3,24 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createRestAction = createRestAction;
6
7
  const querystring_1 = __importDefault(require("querystring"));
7
8
  const url_1 = __importDefault(require("url"));
8
9
  const lodash_1 = __importDefault(require("lodash"));
9
10
  const uuid_1 = require("uuid");
10
- const constants_1 = require("../constants");
11
- const axios_1 = require("../utils/axios");
12
- const common_1 = require("../utils/common");
13
- const parse_error_1 = require("../utils/parse-error");
14
- const redact_sensitive_headers_1 = require("../utils/redact-sensitive-headers");
15
- const validate_1 = require("../utils/validate");
11
+ const constants_js_1 = require("../constants.js");
12
+ const axios_js_1 = require("../utils/axios.js");
13
+ const common_js_1 = require("../utils/common.js");
14
+ const parse_error_js_1 = require("../utils/parse-error.js");
15
+ const redact_sensitive_headers_js_1 = require("../utils/redact-sensitive-headers.js");
16
+ const validate_js_1 = require("../utils/validate.js");
16
17
  function getRestResponseSize(data, ctx, ErrorConstructor) {
17
18
  var _a;
18
19
  let responseSize = 0;
19
20
  try {
20
- responseSize = constants_1.ECMA_STRING_SIZE * ((_a = JSON.stringify(data)) === null || _a === void 0 ? void 0 : _a.length);
21
+ responseSize = constants_js_1.ECMA_STRING_SIZE * ((_a = JSON.stringify(data)) === null || _a === void 0 ? void 0 : _a.length);
21
22
  }
22
23
  catch (error) {
23
- (0, common_1.handleError)(ErrorConstructor, error, ctx, 'Calculate response size failed');
24
+ (0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Calculate response size failed');
24
25
  }
25
26
  return responseSize;
26
27
  }
@@ -36,13 +37,13 @@ function getConfigSerializerFunction(config) {
36
37
  function createRestAction(endpoints, config, serviceKey, actionName, options, ErrorConstructor) {
37
38
  var _a, _b, _c, _d;
38
39
  const timeout = (_c = (_a = config === null || config === void 0 ? void 0 : config.timeout) !== null && _a !== void 0 ? _a : (_b = options === null || options === void 0 ? void 0 : options.axiosConfig) === null || _b === void 0 ? void 0 : _b.timeout) !== null && _c !== void 0 ? _c : options === null || options === void 0 ? void 0 : options.timeout;
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
+ const defaultAxiosClient = (0, axios_js_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
41
  /* eslint-disable complexity */
41
42
  return async function action(actionConfig) {
42
43
  var _a, _b, _c, _d, _e, _f, _g, _h;
43
44
  const { args, requestId, headers: requestHeaders, ctx: parentCtx, authArgs, userId, abortSignal, } = actionConfig;
44
45
  const debugHeaders = {};
45
- const lang = requestHeaders[constants_1.DEFAULT_LANG_HEADER] || constants_1.Lang.Ru; // header might be empty string
46
+ const lang = requestHeaders[constants_js_1.DEFAULT_LANG_HEADER] || constants_js_1.Lang.Ru; // header might be empty string
46
47
  const serviceName = (options === null || options === void 0 ? void 0 : options.serviceName) || serviceKey;
47
48
  const idempotency = config.idempotency;
48
49
  const ctx = parentCtx.create(`Gateway ${serviceName} ${actionName} [rest]`, {
@@ -55,7 +56,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
55
56
  ctx.log('Initiating request');
56
57
  const validationSchema = config.validationSchema || options.validationSchema;
57
58
  if (validationSchema) {
58
- const invalidParams = (0, validate_1.validateArgs)(args, validationSchema);
59
+ const invalidParams = (0, validate_js_1.validateArgs)(args, validationSchema);
59
60
  if (invalidParams) {
60
61
  ctx.log('Invalid params', { invalidParams });
61
62
  ctx.end();
@@ -92,31 +93,31 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
92
93
  },
93
94
  });
94
95
  }
95
- const actionEndpoint = (0, common_1.isExtendedActionEndpoint)(endpointData)
96
+ const actionEndpoint = (0, common_js_1.isExtendedActionEndpoint)(endpointData)
96
97
  ? endpointData.path
97
98
  : endpointData;
98
- const endpointAxiosConfig = (0, common_1.isExtendedRestActionEndpoint)(endpointData)
99
+ const endpointAxiosConfig = (0, common_js_1.isExtendedRestActionEndpoint)(endpointData)
99
100
  ? endpointData.axiosConfig
100
101
  : undefined;
101
102
  const pathArgs = config.validationSchema
102
- ? (0, validate_1.encodePathParams)(args)
103
- : (0, validate_1.getPathArgsProxy)(args, options.encodePathArgs);
103
+ ? (0, validate_js_1.encodePathParams)(args)
104
+ : (0, validate_js_1.getPathArgsProxy)(args, options.encodePathArgs);
104
105
  const actionPath = typeof config.path === 'function' ? config.path(pathArgs) : config.path;
105
106
  const actionURL = actionEndpoint + actionPath;
106
107
  const parsedActionURL = url_1.default.parse(actionURL);
107
- const proxyHeaders = [...constants_1.DEFAULT_PROXY_HEADERS];
108
+ const proxyHeaders = [...constants_js_1.DEFAULT_PROXY_HEADERS];
108
109
  let actionHeaders = {
109
110
  // It's important not to lose the port in HOST header
110
111
  host: (_a = parsedActionURL.host) !== null && _a !== void 0 ? _a : undefined,
111
112
  accept: 'application/json, */*',
112
113
  'accept-encoding': 'gzip, deflate',
113
114
  'accept-language': lang,
114
- 'x-gateway-version': constants_1.VERSION,
115
+ 'x-gateway-version': constants_js_1.VERSION,
115
116
  };
116
117
  let proxyHeadersExtra;
117
118
  const proxyHeadersCaller = (proxyHeadersFunc) => {
118
119
  if (proxyHeadersExtra === undefined) {
119
- proxyHeadersExtra = (0, common_1.getProxyHeadersArgs)(serviceName, actionName);
120
+ proxyHeadersExtra = (0, common_js_1.getProxyHeadersArgs)(serviceName, actionName);
120
121
  }
121
122
  return proxyHeadersFunc(Object.assign({}, requestHeaders), 'rest', proxyHeadersExtra);
122
123
  };
@@ -157,7 +158,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
157
158
  params = await config.params(args, actionHeaders, { ctx });
158
159
  }
159
160
  catch (error) {
160
- (0, common_1.handleError)(ErrorConstructor, error, ctx, 'Getting config params failed');
161
+ (0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Getting config params failed');
161
162
  }
162
163
  }
163
164
  const { body = undefined, query = undefined, headers = actionHeaders } = params !== null && params !== void 0 ? params : {};
@@ -178,7 +179,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
178
179
  }
179
180
  }
180
181
  catch (error) {
181
- (0, common_1.handleError)(ErrorConstructor, error, ctx, 'Stringify request body failed');
182
+ (0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Stringify request body failed');
182
183
  }
183
184
  Object.assign(debugHeaders, {
184
185
  'x-api-request-method': config.method,
@@ -186,7 +187,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
186
187
  'x-api-request-body': requestBody ? requestBody : null,
187
188
  'x-api-request-lang': lang,
188
189
  'x-request-id': requestId,
189
- 'x-gateway-version': constants_1.VERSION,
190
+ 'x-gateway-version': constants_js_1.VERSION,
190
191
  });
191
192
  if (headers['content-type']) {
192
193
  debugHeaders['x-api-content-type'] = headers['content-type'];
@@ -206,10 +207,10 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
206
207
  const customActionTimeout = (_e = (_d = (_c = actionConfig.timeout) !== null && _c !== void 0 ? _c : config.timeout) !== null && _d !== void 0 ? _d : endpointAxiosConfig === null || endpointAxiosConfig === void 0 ? void 0 : endpointAxiosConfig.timeout) !== null && _e !== void 0 ? _e : timeout;
207
208
  if (actionConfig.timeout || endpointAxiosConfig) {
208
209
  const customActionAxiosConfig = Object.assign(Object.assign({}, ((options === null || options === void 0 ? void 0 : options.axiosConfig) || {})), (endpointAxiosConfig || {}));
209
- axiosClient = (0, axios_1.getAxiosClient)(customActionTimeout, config === null || config === void 0 ? void 0 : config.retries, options.axiosRetryCondition, customActionAxiosConfig, options === null || options === void 0 ? void 0 : options.axiosInterceptors);
210
+ axiosClient = (0, axios_js_1.getAxiosClient)(customActionTimeout, config === null || config === void 0 ? void 0 : config.retries, options.axiosRetryCondition, customActionAxiosConfig, options === null || options === void 0 ? void 0 : options.axiosInterceptors);
210
211
  }
211
- headers['x-request-timeout'] = customActionTimeout !== null && customActionTimeout !== void 0 ? customActionTimeout : constants_1.DEFAULT_TIMEOUT;
212
- ctx.log('Starting request', { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
212
+ headers['x-request-timeout'] = customActionTimeout !== null && customActionTimeout !== void 0 ? customActionTimeout : constants_js_1.DEFAULT_TIMEOUT;
213
+ ctx.log('Starting request', { debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders) });
213
214
  const requestData = {
214
215
  timestamp: startRequestTime,
215
216
  service: serviceName,
@@ -285,7 +286,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
285
286
  ctx.log('Transformed response data');
286
287
  }
287
288
  catch (error) {
288
- (0, common_1.handleError)(ErrorConstructor, error, ctx, 'Transform response data failed');
289
+ (0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Transform response data failed');
289
290
  }
290
291
  }
291
292
  if (config.proxyResponseHeaders) {
@@ -303,12 +304,12 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
303
304
  }
304
305
  }
305
306
  if (options === null || options === void 0 ? void 0 : options.sendStats) {
306
- options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize(response === null || response === void 0 ? void 0 : response.data, ctx, ErrorConstructor), restStatus: 200 }), (0, redact_sensitive_headers_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
307
+ options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize(response === null || response === void 0 ? void 0 : response.data, ctx, ErrorConstructor), restStatus: 200 }), (0, redact_sensitive_headers_js_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders) });
307
308
  }
308
309
  else {
309
310
  ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus: 200 }));
310
311
  }
311
- ctx.log('Request completed', { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
312
+ ctx.log('Request completed', { debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders) });
312
313
  ctx.end();
313
314
  return { responseData: response.data, responseHeaders, debugHeaders };
314
315
  }
@@ -328,20 +329,20 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
328
329
  ctx.log('Transformed response error');
329
330
  }
330
331
  catch (error) {
331
- (0, common_1.handleError)(ErrorConstructor, error, ctx, 'Transform response error failed');
332
+ (0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Transform response error failed');
332
333
  }
333
334
  }
334
335
  if (!parsedError) {
335
336
  try {
336
- parsedError = (0, parse_error_1.parseRestError)(error, lang);
337
+ parsedError = (0, parse_error_js_1.parseRestError)(error, lang);
337
338
  }
338
339
  catch (error) {
339
- (0, common_1.handleError)(ErrorConstructor, error, ctx, 'Error parse rest error');
340
+ (0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Error parse rest error');
340
341
  }
341
342
  }
342
343
  const responseStatus = lodash_1.default.get(parsedError, 'status') || lodash_1.default.get(error, 'status', 500);
343
344
  if (options === null || options === void 0 ? void 0 : options.sendStats) {
344
- 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) });
345
+ 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_js_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders) });
345
346
  }
346
347
  else {
347
348
  ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus }));
@@ -350,7 +351,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
350
351
  actionURL,
351
352
  parsedError,
352
353
  serviceName,
353
- debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders),
354
+ debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders),
354
355
  });
355
356
  ctx.end();
356
357
  return Promise.reject({
@@ -360,4 +361,3 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
360
361
  }
361
362
  };
362
363
  }
363
- exports.default = createRestAction;
@@ -1,5 +1,5 @@
1
- import http from 'http';
2
- import https from 'https';
1
+ import * as http from 'http';
2
+ import * as https from 'https';
3
3
  import * as grpc from '@grpc/grpc-js';
4
4
  export declare const VERSION: any;
5
5
  export declare enum Lang {
@@ -15,22 +15,32 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
28
35
  Object.defineProperty(exports, "__esModule", { value: true });
29
36
  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_PROTO_LOADER_OPTIONS = 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
- const http_1 = __importDefault(require("http"));
31
- const https_1 = __importDefault(require("https"));
37
+ const fs = __importStar(require("fs"));
38
+ const http = __importStar(require("http"));
39
+ const https = __importStar(require("https"));
40
+ const path = __importStar(require("path"));
32
41
  const grpc = __importStar(require("@grpc/grpc-js"));
33
- const packageJson = require('../package.json');
42
+ const package_root_js_1 = require("./utils/package-root.js");
43
+ const packageJson = JSON.parse(fs.readFileSync(path.resolve(package_root_js_1.packageRoot, 'package.json'), 'utf-8'));
34
44
  exports.VERSION = packageJson.version;
35
45
  var Lang;
36
46
  (function (Lang) {
@@ -47,18 +57,18 @@ exports.DEFAULT_PROXY_HEADERS = [
47
57
  'x-forwarded-for',
48
58
  ];
49
59
  exports.DEFAULT_AXIOS_OPTIONS = {
50
- maxContentLength: 1024 * 1024 * 100,
51
- httpAgent: new http_1.default.Agent({
52
- //@ts-ignore https://github.com/nodejs/node/blob/master/lib/_http_agent.js#L233
60
+ maxContentLength: 1024 * 1024 * 100, // 100 Mb
61
+ httpAgent: new http.Agent({
62
+ // https://github.com/nodejs/node/blob/master/lib/_http_agent.js#L233
53
63
  family: 6,
54
64
  }),
55
- httpsAgent: new https_1.default.Agent({
56
- //@ts-ignore https://github.com/nodejs/node/blob/master/lib/_http_agent.js#L233
65
+ httpsAgent: new https.Agent({
66
+ // https://github.com/nodejs/node/blob/master/lib/_http_agent.js#L233
57
67
  family: 6,
58
68
  }),
59
69
  };
60
70
  exports.DEFAULT_GRPC_OPTIONS = {
61
- 'grpc.max_receive_message_length': 1024 * 1024 * 100,
71
+ 'grpc.max_receive_message_length': 1024 * 1024 * 100, // 100 Mb
62
72
  'grpc.keepalive_time_ms': 10000,
63
73
  'grpc.keepalive_timeout_ms': 1000,
64
74
  'grpc.keepalive_permit_without_calls': 1,
@@ -1,12 +1,13 @@
1
- import { ApiWithRoot, GatewayConfig, GatewayRequest, GatewayResponse, SchemasByScope } from './models/common';
2
- import { GatewayContext } from './models/context';
3
- export * from './utils/typed-api';
4
- export * from './utils/grpc-reflection';
5
- export { isRetryableGrpcError } from './utils/grpc';
6
- export * from './models/common';
7
- export * from './models/context';
8
- export * from './models/error';
1
+ import { ApiWithRoot, GatewayConfig, GatewayRequest, GatewayResponse, SchemasByScope } from './models/common.js';
2
+ import { GatewayContext } from './models/context.js';
3
+ export * from './utils/typed-api.js';
4
+ export * from './utils/grpc-reflection.js';
5
+ export { isRetryableGrpcError } from './utils/grpc.js';
6
+ export * from './models/common.js';
7
+ export * from './models/context.js';
8
+ export * from './models/error.js';
9
9
  export declare function getGatewayControllers<TSchema extends SchemasByScope, Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse>(schemasByScope: TSchema, config: GatewayConfig<Context, Req, Res>): {
10
10
  controller: (req: Req, res: Res) => Promise<any>;
11
11
  api: ApiWithRoot<TSchema, Context, Req, Res>;
12
12
  };
13
+ export default getGatewayControllers;
@@ -10,18 +10,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
15
  };
@@ -29,21 +17,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
18
  };
31
19
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.getGatewayControllers = exports.isRetryableGrpcError = void 0;
20
+ exports.isRetryableGrpcError = void 0;
21
+ exports.getGatewayControllers = getGatewayControllers;
33
22
  const lodash_1 = __importDefault(require("lodash"));
34
- const grpc_1 = __importStar(require("./components/grpc"));
35
- const mixed_1 = require("./components/mixed");
36
- const rest_1 = __importDefault(require("./components/rest"));
37
- const constants_1 = require("./constants");
38
- const common_1 = require("./utils/common");
39
- const overrideEndpoints_1 = __importDefault(require("./utils/overrideEndpoints"));
40
- __exportStar(require("./utils/typed-api"), exports);
41
- __exportStar(require("./utils/grpc-reflection"), exports);
42
- var grpc_2 = require("./utils/grpc");
43
- Object.defineProperty(exports, "isRetryableGrpcError", { enumerable: true, get: function () { return grpc_2.isRetryableGrpcError; } });
44
- __exportStar(require("./models/common"), exports);
45
- __exportStar(require("./models/context"), exports);
46
- __exportStar(require("./models/error"), exports);
23
+ const grpc_js_1 = require("./components/grpc.js");
24
+ const mixed_js_1 = require("./components/mixed.js");
25
+ const rest_js_1 = require("./components/rest.js");
26
+ const constants_js_1 = require("./constants.js");
27
+ const common_js_1 = require("./utils/common.js");
28
+ const overrideEndpoints_js_1 = require("./utils/overrideEndpoints/overrideEndpoints.js");
29
+ __exportStar(require("./utils/typed-api.js"), exports);
30
+ __exportStar(require("./utils/grpc-reflection.js"), exports);
31
+ var grpc_js_2 = require("./utils/grpc.js");
32
+ Object.defineProperty(exports, "isRetryableGrpcError", { enumerable: true, get: function () { return grpc_js_2.isRetryableGrpcError; } });
33
+ __exportStar(require("./models/common.js"), exports);
34
+ __exportStar(require("./models/context.js"), exports);
35
+ __exportStar(require("./models/error.js"), exports);
47
36
  function isMixedActionConfig(actionConfig) {
48
37
  return typeof actionConfig === 'function';
49
38
  }
@@ -69,11 +58,11 @@ function createApiAction(schema, config, serviceKey, actionName, api, grpcContex
69
58
  const env = config.env || '';
70
59
  if (isMixedActionConfig(action)) {
71
60
  const resultServiceName = serviceName || serviceKey;
72
- return (0, mixed_1.createMixedAction)(action, api, resultServiceName, actionName, { config, grpcContext }, config.ErrorConstructor);
61
+ return (0, mixed_js_1.createMixedAction)(action, api, resultServiceName, actionName, { config, grpcContext }, config.ErrorConstructor);
73
62
  }
74
63
  const endpointsConfig = lodash_1.default.get(serviceSchema.endpoints, [installation, env]);
75
64
  if (isRestActionConfig(action)) {
76
- return (0, rest_1.default)(endpointsConfig, action, serviceKey, actionName, {
65
+ return (0, rest_js_1.createRestAction)(endpointsConfig, action, serviceKey, actionName, {
77
66
  serviceName,
78
67
  timeout: config.timeout,
79
68
  sendStats: config.sendStats,
@@ -88,7 +77,7 @@ function createApiAction(schema, config, serviceKey, actionName, api, grpcContex
88
77
  }, config.ErrorConstructor);
89
78
  }
90
79
  const grpcRecreateService = (_a = config.grpcRecreateService) !== null && _a !== void 0 ? _a : true;
91
- return (0, grpc_1.default)(grpcContext, endpointsConfig, action, serviceKey, actionName, {
80
+ return (0, grpc_js_1.createGrpcAction)(grpcContext, endpointsConfig, action, serviceKey, actionName, {
92
81
  serviceName,
93
82
  timeout: config.timeout,
94
83
  sendStats: config.sendStats,
@@ -165,8 +154,8 @@ function generateGatewayApiController(schemasByScope, Api, config, controllerAct
165
154
  });
166
155
  }
167
156
  if (controllerActions &&
168
- lodash_1.default.get(controllerActions, [scope]) !== constants_1.ANY_ACTION_SYMBOL &&
169
- lodash_1.default.get(controllerActions, [scope, service]) !== constants_1.ANY_ACTION_SYMBOL &&
157
+ lodash_1.default.get(controllerActions, [scope]) !== constants_js_1.ANY_ACTION_SYMBOL &&
158
+ lodash_1.default.get(controllerActions, [scope, service]) !== constants_js_1.ANY_ACTION_SYMBOL &&
170
159
  !lodash_1.default.get(controllerActions, [scope, service, action])) {
171
160
  return res.status(404).send({
172
161
  status: 404,
@@ -188,7 +177,7 @@ function generateGatewayApiController(schemasByScope, Api, config, controllerAct
188
177
  await onBeforeAction(req, res, scope, service, action, actionConfig);
189
178
  }
190
179
  catch (error) {
191
- (0, common_1.handleError)(config.ErrorConstructor, error, req.ctx, 'Before action handler error');
180
+ (0, common_js_1.handleError)(config.ErrorConstructor, error, req.ctx, 'Before action handler error');
192
181
  throw { error, debugHeaders: {} };
193
182
  }
194
183
  }
@@ -250,25 +239,25 @@ function getGatewayControllers(schemasByScope, config) {
250
239
  if (process.env.GATEWAY_ENDPOINTS_OVERRIDES) {
251
240
  try {
252
241
  // eslint-disable-next-line no-param-reassign
253
- schemasByScope = (0, overrideEndpoints_1.default)(schemasByScope, JSON.parse(process.env.GATEWAY_ENDPOINTS_OVERRIDES), config.installation, config.env);
242
+ schemasByScope = (0, overrideEndpoints_js_1.overrideEndpoints)(schemasByScope, JSON.parse(process.env.GATEWAY_ENDPOINTS_OVERRIDES), config.installation, config.env);
254
243
  }
255
244
  catch (err) {
256
245
  console.warn('Error when parse GATEWAY_ENDPOINTS_OVERRIDES', err);
257
246
  }
258
247
  }
259
- const credentials = (0, grpc_1.getCredentialsMap)(config.caCertificatePath);
260
- for (const scope of (0, common_1.getKeys)(schemasByScope)) {
261
- apiByScope[scope] = generateGatewayApi(schemasByScope[scope], config, { root: (0, grpc_1.createRoot)(config.includeProtoRoots), credentials }, apiByScope);
248
+ const credentials = (0, grpc_js_1.getCredentialsMap)(config.caCertificatePath);
249
+ for (const scope of (0, common_js_1.getKeys)(schemasByScope)) {
250
+ apiByScope[scope] = generateGatewayApi(schemasByScope[scope], config, { root: (0, grpc_js_1.createRoot)(config.includeProtoRoots), credentials }, apiByScope);
262
251
  }
263
252
  const api = Object.assign({}, apiByScope);
264
253
  const rootScope = apiByScope.root;
265
254
  if (rootScope) {
266
- for (const rootService of (0, common_1.getKeys)(rootScope)) {
255
+ for (const rootService of (0, common_js_1.getKeys)(rootScope)) {
267
256
  const curScope = (_a = api[rootService]) !== null && _a !== void 0 ? _a : {};
268
- for (const rootAction of (0, common_1.getKeys)(rootScope[rootService])) {
257
+ for (const rootAction of (0, common_js_1.getKeys)(rootScope[rootService])) {
269
258
  const rootServiceFunc = rootScope[rootService][rootAction];
270
259
  if (curScope[rootAction]) {
271
- for (const curScopeAction of (0, common_1.getKeys)(curScope[rootAction])) {
260
+ for (const curScopeAction of (0, common_js_1.getKeys)(curScope[rootAction])) {
272
261
  rootServiceFunc[curScopeAction] = curScope[rootAction][curScopeAction];
273
262
  }
274
263
  }
@@ -281,15 +270,15 @@ function getGatewayControllers(schemasByScope, config) {
281
270
  ? config.actions.reduce((acc, item) => {
282
271
  const [scope, service, action] = item.split('.');
283
272
  // Ignore option '*' for scopes
284
- if (scope === constants_1.ANY_ACTION_SYMBOL) {
273
+ if (scope === constants_js_1.ANY_ACTION_SYMBOL) {
285
274
  return acc;
286
275
  }
287
- if (service === constants_1.ANY_ACTION_SYMBOL) {
288
- lodash_1.default.set(acc, [scope], constants_1.ANY_ACTION_SYMBOL);
276
+ if (service === constants_js_1.ANY_ACTION_SYMBOL) {
277
+ lodash_1.default.set(acc, [scope], constants_js_1.ANY_ACTION_SYMBOL);
289
278
  }
290
- else if (action === constants_1.ANY_ACTION_SYMBOL) {
291
- if (acc[scope] !== constants_1.ANY_ACTION_SYMBOL) {
292
- lodash_1.default.set(acc, [scope, service], constants_1.ANY_ACTION_SYMBOL);
279
+ else if (action === constants_js_1.ANY_ACTION_SYMBOL) {
280
+ if (acc[scope] !== constants_js_1.ANY_ACTION_SYMBOL) {
281
+ lodash_1.default.set(acc, [scope, service], constants_js_1.ANY_ACTION_SYMBOL);
293
282
  }
294
283
  }
295
284
  else {
@@ -304,4 +293,4 @@ function getGatewayControllers(schemasByScope, config) {
304
293
  api,
305
294
  };
306
295
  }
307
- exports.getGatewayControllers = getGatewayControllers;
296
+ exports.default = getGatewayControllers;
@@ -1,15 +1,14 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'http';
3
2
  import { ClientDuplexStream, ClientReadableStream, ClientWritableStream, type ServiceError } from '@grpc/grpc-js';
4
- import { HandlerType } from '@grpc/grpc-js/build/src/server-call';
3
+ import type { HandlerType } from '@grpc/grpc-js/build/src/server-call.js';
5
4
  import { AxiosInterceptorManager, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
6
5
  import { IAxiosRetryConfig } from 'axios-retry';
7
6
  import type { Request, Response } from 'express';
8
- import * as protobufjs from 'protobufjs';
9
- import type { GrpcContext } from '../components/grpc';
10
- import { Lang } from '../constants';
11
- import { GatewayContext } from './context';
12
- import { AppErrorConstructor } from './error';
7
+ import protobufjs from 'protobufjs';
8
+ import type { GrpcContext } from '../components/grpc.js';
9
+ import { Lang } from '../constants.js';
10
+ import { GatewayContext } from './context.js';
11
+ import { AppErrorConstructor } from './error.js';
13
12
  export interface GatewayRequest<Context extends GatewayContext> extends Request {
14
13
  id: string;
15
14
  ctx: Context;
@@ -217,12 +216,18 @@ export interface GatewayActionUnaryResponse<TAction> extends GatewayActionHeader
217
216
  }
218
217
  export interface GatewayActionClientStreamResponse<TAction> extends GatewayActionHeaders {
219
218
  stream: ClientWritableStream<ApiActionResponseType<TAction>>;
219
+ responseData?: never;
220
+ responseHeaders?: never;
220
221
  }
221
222
  export interface GatewayActionServerStreamResponse<TAction> extends GatewayActionHeaders {
222
223
  stream: ClientReadableStream<ApiActionResponseType<TAction>>;
224
+ responseData?: never;
225
+ responseHeaders?: never;
223
226
  }
224
227
  export interface GatewayActionDuplexStreamResponse<TAction> extends GatewayActionHeaders {
225
228
  stream: ClientDuplexStream<ApiActionParams<TAction>, ApiActionResponseType<TAction>>;
229
+ responseData?: never;
230
+ responseHeaders?: never;
226
231
  }
227
232
  export type GatewayActionResponseData<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse, TAction extends ApiServiceActionConfig<Context, Req, Res, unknown, unknown, unknown>> = TAction extends ApiServiceGrpcActionConfig<Context, unknown, unknown, unknown> ? TAction['type'] extends 'clientStream' ? GatewayActionClientStreamResponse<TAction> : TAction['type'] extends 'serverStream' ? GatewayActionServerStreamResponse<TAction> : TAction['type'] extends 'bidi' ? GatewayActionDuplexStreamResponse<TAction> : GatewayActionUnaryResponse<TAction> : GatewayActionUnaryResponse<TAction>;
228
233
  type GatewayAction<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse, TAction extends ApiServiceActionConfig<Context, Req, Res, unknown, unknown, unknown>> = undefined extends ApiActionParams<TAction> ? (params?: ApiActionConfig<Context, ApiActionParams<TAction>, ApiActionResponseType<TAction>>) => Promise<GatewayActionResponseData<Context, Req, Res, TAction>> : (params: ApiActionConfig<Context, ApiActionParams<TAction>, ApiActionResponseType<TAction>>) => Promise<GatewayActionResponseData<Context, Req, Res, TAction>>;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'http';
3
2
  export interface GatewayContextParams {
4
3
  tags?: Record<string, string | number | boolean | undefined>;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,4 @@
1
+ import axios, { AxiosRequestConfig } from 'axios';
2
+ import { IAxiosRetryConfig } from 'axios-retry';
3
+ import { AxiosInterceptorsConfig } from '../models/common.js';
4
+ export declare function getAxiosClient(timeout?: number, retries?: number, customRetryCondition?: IAxiosRetryConfig['retryCondition'], axiosConfig?: AxiosRequestConfig, { request: reqInterceptors, response: resInterceptors }?: AxiosInterceptorsConfig): axios.AxiosInstance;
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getAxiosClient = void 0;
6
+ exports.getAxiosClient = getAxiosClient;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const axios_retry_1 = __importDefault(require("axios-retry"));
9
9
  const lodash_1 = __importDefault(require("lodash"));
10
- const constants_1 = require("../constants");
11
- function getAxiosClient(timeout = constants_1.DEFAULT_TIMEOUT, retries = 0, customRetryCondition, axiosConfig = constants_1.DEFAULT_AXIOS_OPTIONS, { request: reqInterceptors, response: resInterceptors } = {}) {
10
+ const constants_js_1 = require("../constants.js");
11
+ function getAxiosClient(timeout = constants_js_1.DEFAULT_TIMEOUT, retries = 0, customRetryCondition, axiosConfig = constants_js_1.DEFAULT_AXIOS_OPTIONS, { request: reqInterceptors, response: resInterceptors } = {}) {
12
12
  const client = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { timeout }));
13
13
  reqInterceptors === null || reqInterceptors === void 0 ? void 0 : reqInterceptors.forEach(({ callback, errorCallback }) => client.interceptors.request.use(callback, errorCallback));
14
14
  resInterceptors === null || resInterceptors === void 0 ? void 0 : resInterceptors.forEach(({ callback, errorCallback }) => client.interceptors.response.use(callback, errorCallback));
@@ -28,4 +28,3 @@ function getAxiosClient(timeout = constants_1.DEFAULT_TIMEOUT, retries = 0, cust
28
28
  });
29
29
  return client;
30
30
  }
31
- exports.getAxiosClient = getAxiosClient;
@@ -1,8 +1,8 @@
1
1
  import * as grpc from '@grpc/grpc-js';
2
2
  import _ from 'lodash';
3
- import { ActionEndpoint, ApiServiceGrpcActionConfig, ExtendedActionEndpoint, ExtendedGrpcActionEndpoint, ExtendedRestActionEndpoint, Headers, ProxyHeadersFunctionExtra } from '../models/common';
4
- import { Dict, GatewayContext } from '../models/context';
5
- import { AppErrorConstructor } from '../models/error';
3
+ import { ActionEndpoint, ApiServiceGrpcActionConfig, ExtendedActionEndpoint, ExtendedGrpcActionEndpoint, ExtendedRestActionEndpoint, Headers, ProxyHeadersFunctionExtra } from '../models/common.js';
4
+ import { Dict, GatewayContext } from '../models/context.js';
5
+ import { AppErrorConstructor } from '../models/error.js';
6
6
  export declare function isExtendedActionEndpoint(endpoint: ActionEndpoint): endpoint is ExtendedActionEndpoint;
7
7
  export declare function isExtendedGrpcActionEndpoint(endpoint: ActionEndpoint): endpoint is ExtendedGrpcActionEndpoint;
8
8
  export declare function isExtendedRestActionEndpoint(endpoint: ActionEndpoint): endpoint is ExtendedRestActionEndpoint;
@@ -13,4 +13,4 @@ export declare function getKeys<T extends object>(obj: T): (keyof T)[];
13
13
  export declare function sanitizeDebugHeaders(debugHeaders: Headers): _.Omit<Headers, "x-api-request-body">;
14
14
  export declare function getHeadersFromMetadata(metadata: Record<string, grpc.MetadataValue[]>, prefix?: string): Record<string, string>;
15
15
  export declare function handleError<Context extends GatewayContext>(ErrorConstructor: AppErrorConstructor, error: unknown, ctx: Context, message: string, extra?: Dict): void;
16
- export declare const getProxyHeadersArgs: <Context extends GatewayContext>(serviceName: string, actionName: string, grpcConfig?: ApiServiceGrpcActionConfig<Context, any, any> | undefined) => ProxyHeadersFunctionExtra;
16
+ export declare const getProxyHeadersArgs: <Context extends GatewayContext>(serviceName: string, actionName: string, grpcConfig?: ApiServiceGrpcActionConfig<Context, any, any>) => ProxyHeadersFunctionExtra;
@@ -3,40 +3,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getProxyHeadersArgs = exports.handleError = exports.getHeadersFromMetadata = exports.sanitizeDebugHeaders = exports.getKeys = exports.isExtendedRestActionEndpoint = exports.isExtendedGrpcActionEndpoint = exports.isExtendedActionEndpoint = void 0;
6
+ exports.getProxyHeadersArgs = void 0;
7
+ exports.isExtendedActionEndpoint = isExtendedActionEndpoint;
8
+ exports.isExtendedGrpcActionEndpoint = isExtendedGrpcActionEndpoint;
9
+ exports.isExtendedRestActionEndpoint = isExtendedRestActionEndpoint;
10
+ exports.getKeys = getKeys;
11
+ exports.sanitizeDebugHeaders = sanitizeDebugHeaders;
12
+ exports.getHeadersFromMetadata = getHeadersFromMetadata;
13
+ exports.handleError = handleError;
7
14
  const lodash_1 = __importDefault(require("lodash"));
8
15
  function isExtendedActionEndpoint(endpoint) {
9
16
  return (endpoint === null || endpoint === void 0 ? void 0 : endpoint.path) !== undefined;
10
17
  }
11
- exports.isExtendedActionEndpoint = isExtendedActionEndpoint;
12
18
  function isExtendedGrpcActionEndpoint(endpoint) {
13
19
  return ((endpoint === null || endpoint === void 0 ? void 0 : endpoint.grpcOptions) !== undefined ||
14
20
  (endpoint === null || endpoint === void 0 ? void 0 : endpoint.insecure) !== undefined ||
15
21
  (endpoint === null || endpoint === void 0 ? void 0 : endpoint.secureWithoutRootCert) !== undefined);
16
22
  }
17
- exports.isExtendedGrpcActionEndpoint = isExtendedGrpcActionEndpoint;
18
23
  function isExtendedRestActionEndpoint(endpoint) {
19
24
  return (endpoint === null || endpoint === void 0 ? void 0 : endpoint.axiosConfig) !== undefined;
20
25
  }
21
- exports.isExtendedRestActionEndpoint = isExtendedRestActionEndpoint;
22
26
  function getKeys(obj) {
23
27
  return Object.keys(obj);
24
28
  }
25
- exports.getKeys = getKeys;
26
29
  /**
27
30
  * This function should only use to sanitize debugHeaders that are creating in our code
28
31
  */
29
32
  function sanitizeDebugHeaders(debugHeaders) {
30
33
  return lodash_1.default.omit(debugHeaders, ['x-api-request-body']);
31
34
  }
32
- exports.sanitizeDebugHeaders = sanitizeDebugHeaders;
33
35
  function getHeadersFromMetadata(metadata, prefix = '') {
34
36
  return Object.entries(metadata).reduce((headers, [key, values]) => {
35
37
  headers[`${prefix}${key}`] = values.filter((value) => typeof value === 'string').join(' ');
36
38
  return headers;
37
39
  }, {});
38
40
  }
39
- exports.getHeadersFromMetadata = getHeadersFromMetadata;
40
41
  function handleError(ErrorConstructor, error, ctx, message, extra) {
41
42
  if (error instanceof Error) {
42
43
  ctx.logError(message, ErrorConstructor.wrap(error), extra);
@@ -48,7 +49,6 @@ function handleError(ErrorConstructor, error, ctx, message, extra) {
48
49
  ctx.logError(message, error, extra);
49
50
  }
50
51
  }
51
- exports.handleError = handleError;
52
52
  const getProxyHeadersArgs = (serviceName, actionName, grpcConfig) => {
53
53
  const protopath = grpcConfig && 'protoPath' in grpcConfig ? grpcConfig.protoPath : undefined;
54
54
  const protokey = grpcConfig === null || grpcConfig === void 0 ? void 0 : grpcConfig.protoKey;