@gravity-ui/gateway 4.1.2-alpha.0 → 4.2.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/{dist/commonjs → build}/components/grpc.d.ts +4 -4
  2. package/{dist/commonjs → build}/components/grpc.js +78 -85
  3. package/{dist/esm → build}/components/mixed.d.ts +4 -4
  4. package/{dist/commonjs → build}/components/mixed.js +12 -11
  5. package/{dist/commonjs → build}/components/rest.d.ts +5 -5
  6. package/{dist/commonjs → build}/components/rest.js +32 -32
  7. package/{dist/esm → build}/constants.d.ts +2 -2
  8. package/{dist/commonjs → build}/constants.js +19 -29
  9. package/{dist/commonjs → build}/index.d.ts +7 -8
  10. package/{dist/commonjs → build}/index.js +46 -32
  11. package/{dist/esm → build}/models/common.d.ts +14 -12
  12. package/{dist/esm → build}/models/context.d.ts +1 -0
  13. package/build/utils/axios.d.ts +4 -0
  14. package/{dist/commonjs → build}/utils/axios.js +6 -4
  15. package/{dist/esm → build}/utils/common.d.ts +3 -3
  16. package/{dist/commonjs → build}/utils/common.js +8 -7
  17. package/{dist/commonjs → build}/utils/create-context-api.d.ts +2 -2
  18. package/{dist/commonjs → build}/utils/create-context-api.js +6 -5
  19. package/{dist/commonjs → build}/utils/grpc-reflection.js +18 -31
  20. package/{dist/commonjs → build}/utils/grpc.js +8 -7
  21. package/build/utils/overrideEndpoints/index.d.ts +2 -0
  22. package/build/utils/overrideEndpoints/index.js +4 -0
  23. package/{dist/commonjs → build}/utils/overrideEndpoints/overrideEndpoints.d.ts +1 -1
  24. package/{dist/commonjs → build}/utils/overrideEndpoints/overrideEndpoints.js +2 -1
  25. package/{dist/esm → build}/utils/parse-error.d.ts +4 -4
  26. package/{dist/commonjs → build}/utils/parse-error.js +18 -18
  27. package/{dist/commonjs → build}/utils/proto-path-resolver.js +17 -23
  28. package/{dist/commonjs → build}/utils/redact-sensitive-headers.d.ts +2 -1
  29. package/{dist/commonjs → build}/utils/redact-sensitive-headers.js +2 -1
  30. package/{dist/commonjs → build}/utils/typed-api.d.ts +1 -1
  31. package/{dist/commonjs → build}/utils/typed-api.js +2 -1
  32. package/{dist/commonjs → build}/utils/validate.js +10 -6
  33. package/package.json +16 -41
  34. package/dist/commonjs/components/mixed.d.ts +0 -11
  35. package/dist/commonjs/constants.d.ts +0 -53
  36. package/dist/commonjs/models/common.d.ts +0 -272
  37. package/dist/commonjs/models/context.d.ts +0 -22
  38. package/dist/commonjs/package.json +0 -3
  39. package/dist/commonjs/utils/axios.d.ts +0 -3
  40. package/dist/commonjs/utils/common.d.ts +0 -15
  41. package/dist/commonjs/utils/overrideEndpoints/index.d.ts +0 -2
  42. package/dist/commonjs/utils/overrideEndpoints/index.js +0 -4
  43. package/dist/commonjs/utils/package-root.d.ts +0 -1
  44. package/dist/commonjs/utils/package-root.js +0 -44
  45. package/dist/commonjs/utils/parse-error.d.ts +0 -30
  46. package/dist/commonjs/utils/source-dir.d.ts +0 -1
  47. package/dist/commonjs/utils/source-dir.js +0 -41
  48. package/dist/esm/components/grpc.d.ts +0 -24
  49. package/dist/esm/components/grpc.js +0 -641
  50. package/dist/esm/components/mixed.js +0 -62
  51. package/dist/esm/components/rest.d.ts +0 -8
  52. package/dist/esm/components/rest.js +0 -349
  53. package/dist/esm/constants.js +0 -82
  54. package/dist/esm/index.d.ts +0 -12
  55. package/dist/esm/index.js +0 -264
  56. package/dist/esm/models/common.js +0 -5
  57. package/dist/esm/models/context.js +0 -1
  58. package/dist/esm/models/error.d.ts +0 -12
  59. package/dist/esm/models/error.js +0 -1
  60. package/dist/esm/package.json +0 -3
  61. package/dist/esm/utils/axios.d.ts +0 -3
  62. package/dist/esm/utils/axios.js +0 -23
  63. package/dist/esm/utils/common.js +0 -38
  64. package/dist/esm/utils/create-context-api.d.ts +0 -4
  65. package/dist/esm/utils/create-context-api.js +0 -38
  66. package/dist/esm/utils/grpc-reflection.d.ts +0 -28
  67. package/dist/esm/utils/grpc-reflection.js +0 -72
  68. package/dist/esm/utils/grpc.d.ts +0 -5
  69. package/dist/esm/utils/grpc.js +0 -39
  70. package/dist/esm/utils/overrideEndpoints/index.d.ts +0 -2
  71. package/dist/esm/utils/overrideEndpoints/index.js +0 -2
  72. package/dist/esm/utils/overrideEndpoints/overrideEndpoints.d.ts +0 -17
  73. package/dist/esm/utils/overrideEndpoints/overrideEndpoints.js +0 -96
  74. package/dist/esm/utils/package-root.d.ts +0 -1
  75. package/dist/esm/utils/package-root.js +0 -8
  76. package/dist/esm/utils/parse-error.js +0 -210
  77. package/dist/esm/utils/proto-path-resolver.d.ts +0 -2
  78. package/dist/esm/utils/proto-path-resolver.js +0 -23
  79. package/dist/esm/utils/redact-sensitive-headers.d.ts +0 -3
  80. package/dist/esm/utils/redact-sensitive-headers.js +0 -12
  81. package/dist/esm/utils/source-dir.d.ts +0 -1
  82. package/dist/esm/utils/source-dir.js +0 -4
  83. package/dist/esm/utils/typed-api.d.ts +0 -2
  84. package/dist/esm/utils/typed-api.js +0 -3
  85. package/dist/esm/utils/validate.d.ts +0 -4
  86. package/dist/esm/utils/validate.js +0 -47
  87. /package/bin/{patch.cjs → patch.js} +0 -0
  88. /package/{dist/commonjs → build}/models/common.js +0 -0
  89. /package/{dist/commonjs → build}/models/context.js +0 -0
  90. /package/{dist/commonjs → build}/models/error.d.ts +0 -0
  91. /package/{dist/commonjs → build}/models/error.js +0 -0
  92. /package/{dist/commonjs → build}/utils/grpc-reflection.d.ts +0 -0
  93. /package/{dist/commonjs → build}/utils/grpc.d.ts +0 -0
  94. /package/{dist/commonjs → build}/utils/proto-path-resolver.d.ts +0 -0
  95. /package/{dist/commonjs → build}/utils/validate.d.ts +0 -0
@@ -3,40 +3,40 @@ 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.isExtendedActionEndpoint = isExtendedActionEndpoint;
7
- exports.isExtendedGrpcActionEndpoint = isExtendedGrpcActionEndpoint;
8
- exports.isExtendedRestActionEndpoint = isExtendedRestActionEndpoint;
9
- exports.getKeys = getKeys;
10
- exports.sanitizeDebugHeaders = sanitizeDebugHeaders;
11
- exports.getHeadersFromMetadata = getHeadersFromMetadata;
12
- exports.handleError = handleError;
6
+ exports.handleError = exports.getHeadersFromMetadata = exports.sanitizeDebugHeaders = exports.getKeys = exports.isExtendedRestActionEndpoint = exports.isExtendedGrpcActionEndpoint = exports.isExtendedActionEndpoint = void 0;
13
7
  const lodash_1 = __importDefault(require("lodash"));
14
8
  function isExtendedActionEndpoint(endpoint) {
15
9
  return (endpoint === null || endpoint === void 0 ? void 0 : endpoint.path) !== undefined;
16
10
  }
11
+ exports.isExtendedActionEndpoint = isExtendedActionEndpoint;
17
12
  function isExtendedGrpcActionEndpoint(endpoint) {
18
13
  return ((endpoint === null || endpoint === void 0 ? void 0 : endpoint.grpcOptions) !== undefined ||
19
14
  (endpoint === null || endpoint === void 0 ? void 0 : endpoint.insecure) !== undefined ||
20
15
  (endpoint === null || endpoint === void 0 ? void 0 : endpoint.secureWithoutRootCert) !== undefined);
21
16
  }
17
+ exports.isExtendedGrpcActionEndpoint = isExtendedGrpcActionEndpoint;
22
18
  function isExtendedRestActionEndpoint(endpoint) {
23
19
  return (endpoint === null || endpoint === void 0 ? void 0 : endpoint.axiosConfig) !== undefined;
24
20
  }
21
+ exports.isExtendedRestActionEndpoint = isExtendedRestActionEndpoint;
25
22
  function getKeys(obj) {
26
23
  return Object.keys(obj);
27
24
  }
25
+ exports.getKeys = getKeys;
28
26
  /**
29
27
  * This function should only use to sanitize debugHeaders that are creating in our code
30
28
  */
31
29
  function sanitizeDebugHeaders(debugHeaders) {
32
30
  return lodash_1.default.omit(debugHeaders, ['x-api-request-body']);
33
31
  }
32
+ exports.sanitizeDebugHeaders = sanitizeDebugHeaders;
34
33
  function getHeadersFromMetadata(metadata, prefix = '') {
35
34
  return Object.entries(metadata).reduce((headers, [key, values]) => {
36
35
  headers[`${prefix}${key}`] = values.filter((value) => typeof value === 'string').join(' ');
37
36
  return headers;
38
37
  }, {});
39
38
  }
39
+ exports.getHeadersFromMetadata = getHeadersFromMetadata;
40
40
  function handleError(ErrorConstructor, error, ctx, message, extra) {
41
41
  if (error instanceof Error) {
42
42
  ctx.logError(message, ErrorConstructor.wrap(error), extra);
@@ -48,3 +48,4 @@ function handleError(ErrorConstructor, error, ctx, message, extra) {
48
48
  ctx.logError(message, error, extra);
49
49
  }
50
50
  }
51
+ exports.handleError = handleError;
@@ -1,4 +1,4 @@
1
- import { ApiActionConfig, ApiByScope, ContextApiWithRoot, GatewayRequest, GatewayResponse, SchemasByScope } from '../models/common.js';
2
- import { GatewayContext } from '../models/context.js';
1
+ import { GatewayContext } from '../models/context';
2
+ import { ApiActionConfig, ApiByScope, ContextApiWithRoot, GatewayRequest, GatewayResponse, SchemasByScope } from './../models/common';
3
3
  export type RequestContext<Context extends GatewayContext> = Omit<ApiActionConfig<Context, never>, 'args'>;
4
4
  export declare function generateContextApi<TFullSchema extends SchemasByScope, Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse>(baseApi: ApiByScope<TFullSchema, Context, Req, Res>, requestContext: RequestContext<Context>): ContextApiWithRoot<TFullSchema>;
@@ -3,9 +3,9 @@ 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.generateContextApi = generateContextApi;
6
+ exports.generateContextApi = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
- const common_js_1 = require("./common.js");
8
+ const common_1 = require("./common");
9
9
  function createContextApiForScope(api, requestContext) {
10
10
  return lodash_1.default.reduce(api, (acc, service, serviceName) => {
11
11
  acc[serviceName] = lodash_1.default.reduce(service, (accService, action, actionName) => {
@@ -26,12 +26,12 @@ function generateContextApi(baseApi, requestContext) {
26
26
  const api = contextApi;
27
27
  const rootScope = contextApi.root;
28
28
  if (rootScope) {
29
- for (const rootService of (0, common_js_1.getKeys)(rootScope)) {
29
+ for (const rootService of (0, common_1.getKeys)(rootScope)) {
30
30
  const curScope = (_a = api[rootService]) !== null && _a !== void 0 ? _a : {};
31
- for (const rootAction of (0, common_js_1.getKeys)(rootScope[rootService])) {
31
+ for (const rootAction of (0, common_1.getKeys)(rootScope[rootService])) {
32
32
  const rootServiceFunc = rootScope[rootService][rootAction];
33
33
  if (curScope[rootAction]) {
34
- for (const curScopeAction of (0, common_js_1.getKeys)(curScope[rootAction])) {
34
+ for (const curScopeAction of (0, common_1.getKeys)(curScope[rootAction])) {
35
35
  rootServiceFunc[curScopeAction] = curScope[rootAction][curScopeAction];
36
36
  }
37
37
  }
@@ -42,3 +42,4 @@ function generateContextApi(baseApi, requestContext) {
42
42
  }
43
43
  return api;
44
44
  }
45
+ exports.generateContextApi = generateContextApi;
@@ -15,54 +15,39 @@ 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 () {
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
- })();
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
+ };
35
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
27
  };
38
28
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getCachedReflectionRoot = getCachedReflectionRoot;
40
- exports.getReflectionRoot = getReflectionRoot;
29
+ exports.getReflectionRoot = exports.getCachedReflectionRoot = void 0;
41
30
  const lodash_1 = __importDefault(require("lodash"));
42
31
  const protobufjs = __importStar(require("protobufjs"));
43
- const proto_path_resolver_js_1 = require("./proto-path-resolver.js");
32
+ const proto_path_resolver_1 = require("./proto-path-resolver");
44
33
  const reflectionClientsMap = {};
45
- async function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto) {
34
+ function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto) {
46
35
  const cacheKey = [actionEndpoint, JSON.stringify([grpcOptions, descriptorExtensionProto])];
47
36
  let clientWithCache = lodash_1.default.get(reflectionClientsMap, cacheKey);
48
37
  if (!clientWithCache) {
49
- const grpcReflection = await import('grpc-reflection-js');
38
+ const grpcReflection = require('grpc-reflection-js');
50
39
  let descriptorRoot;
51
40
  if (descriptorExtensionProto) {
52
- descriptorRoot = protobufjs.Root.fromJSON(
53
- // @ts-expect-error no typings for default export
54
- (await import('protobufjs/ext/descriptor/index.js')).default);
41
+ descriptorRoot = protobufjs.Root.fromJSON(require('protobufjs/ext/descriptor'));
55
42
  if (Array.isArray(descriptorExtensionProto)) {
56
43
  descriptorRoot.loadSync(descriptorExtensionProto);
57
44
  }
58
45
  else {
59
- (0, proto_path_resolver_js_1.patchProtoPathResolver)(descriptorRoot, descriptorExtensionProto.includeProtoRoots);
46
+ (0, proto_path_resolver_1.patchProtoPathResolver)(descriptorRoot, descriptorExtensionProto.includeProtoRoots);
60
47
  descriptorRoot.loadSync(descriptorExtensionProto.filenames);
61
48
  }
62
49
  }
63
- const client = new grpcReflection.Client(actionEndpoint, credentials, grpcOptions, undefined,
64
- // @ts-ignore this parameter is present only in the patched version
65
- descriptorRoot);
50
+ const client = new grpcReflection.Client(actionEndpoint, credentials, grpcOptions, undefined, descriptorRoot);
66
51
  clientWithCache = { client, reflectionRootPromiseMap: {} };
67
52
  lodash_1.default.set(reflectionClientsMap, cacheKey, clientWithCache);
68
53
  }
@@ -79,7 +64,7 @@ async function getCachedClient(actionEndpoint, credentials, grpcOptions, descrip
79
64
  * use toJSON for get a JSON descriptor.
80
65
  */
81
66
  async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, grpcOptions, descriptorExtensionProto) {
82
- const { client, reflectionRootPromiseMap } = await getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto);
67
+ const { client, reflectionRootPromiseMap } = getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto);
83
68
  const cacheKey = [actionEndpoint, protoKey];
84
69
  let cachedRootPromise = lodash_1.default.get(reflectionRootPromiseMap, cacheKey);
85
70
  if (!cachedRootPromise) {
@@ -92,6 +77,7 @@ async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, gr
92
77
  const loadedRoot = await cachedRootPromise;
93
78
  return loadedRoot;
94
79
  }
80
+ exports.getCachedReflectionRoot = getCachedReflectionRoot;
95
81
  /**
96
82
  * @param actionEndpoint
97
83
  * @param protoKey
@@ -103,10 +89,11 @@ async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, gr
103
89
  * use toJSON for get a JSON descriptor.
104
90
  */
105
91
  async function getReflectionRoot(actionEndpoint, protoKey, credentials, grpcOptions, addToCache) {
106
- const { client, reflectionRootPromiseMap } = await getCachedClient(actionEndpoint, credentials, grpcOptions);
92
+ const { client, reflectionRootPromiseMap } = getCachedClient(actionEndpoint, credentials, grpcOptions);
107
93
  const loadedRoot = await client.fileContainingSymbol(protoKey);
108
94
  if (addToCache) {
109
95
  lodash_1.default.set(reflectionRootPromiseMap, [actionEndpoint, protoKey], Promise.resolve(loadedRoot));
110
96
  }
111
97
  return loadedRoot;
112
98
  }
99
+ exports.getReflectionRoot = getReflectionRoot;
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  /* eslint-disable camelcase */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.decodeAnyMessageRecursively = decodeAnyMessageRecursively;
5
- exports.isRetryableError = isRetryableError;
6
- exports.isRecreateServiceError = isRecreateServiceError;
7
- const constants_js_1 = require("../constants.js");
4
+ exports.isRecreateServiceError = exports.isRetryableError = exports.decodeAnyMessageRecursively = void 0;
5
+ const constants_1 = require("../constants");
8
6
  function isEncodedMessage(message) {
9
7
  return Boolean(message.type_url && message.value);
10
8
  }
@@ -27,18 +25,21 @@ function decodeAnyMessageRecursively(root, message, decodeAnyMessageProtoLoaderO
27
25
  }
28
26
  const typeName = message.type_url.substring(lastSlashIndex + 1);
29
27
  const type = root.lookupType(typeName);
30
- const decodedMessage = type.toObject(type.decode(message.value), Object.assign(Object.assign({}, constants_js_1.DEFAULT_PROTO_LOADER_OPTIONS), decodeAnyMessageProtoLoaderOptions));
28
+ const decodedMessage = type.toObject(type.decode(message.value), Object.assign(Object.assign({}, constants_1.DEFAULT_PROTO_LOADER_OPTIONS), decodeAnyMessageProtoLoaderOptions));
31
29
  return decodeAnyMessageRecursively(root, decodedMessage, decodeAnyMessageProtoLoaderOptions);
32
30
  }
31
+ exports.decodeAnyMessageRecursively = decodeAnyMessageRecursively;
33
32
  function isRetryableError(error) {
34
33
  if (!error) {
35
34
  return false;
36
35
  }
37
- return constants_js_1.RETRYABLE_STATUS_CODES.includes(error.code);
36
+ return constants_1.RETRYABLE_STATUS_CODES.includes(error.code);
38
37
  }
38
+ exports.isRetryableError = isRetryableError;
39
39
  function isRecreateServiceError(error) {
40
40
  if (!error) {
41
41
  return false;
42
42
  }
43
- return constants_js_1.RECREATE_SERVICE_CODES.includes(error.code);
43
+ return constants_1.RECREATE_SERVICE_CODES.includes(error.code);
44
44
  }
45
+ exports.isRecreateServiceError = isRecreateServiceError;
@@ -0,0 +1,2 @@
1
+ import { overrideEndpoints } from './overrideEndpoints';
2
+ export default overrideEndpoints;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const overrideEndpoints_1 = require("./overrideEndpoints");
4
+ exports.default = overrideEndpoints_1.overrideEndpoints;
@@ -1,4 +1,4 @@
1
- import { ActionEndpoint, SchemasByScope } from '../../index.js';
1
+ import { ActionEndpoint, SchemasByScope } from '../..';
2
2
  export interface OverrideParams {
3
3
  [serviceKeyScope: string]: {
4
4
  [endpointName: string]: ActionEndpoint;
@@ -3,7 +3,7 @@ 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.overrideEndpoints = overrideEndpoints;
6
+ exports.overrideEndpoints = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  function parseOverrideEndpointsParams(params) {
9
9
  const parsedParams = [];
@@ -84,6 +84,7 @@ function overrideEndpoints(originalSchema, overrideParams, installation, env) {
84
84
  });
85
85
  return schema;
86
86
  }
87
+ exports.overrideEndpoints = overrideEndpoints;
87
88
  function isExtendedEndpointConfig(config) {
88
89
  return typeof config === 'object';
89
90
  }
@@ -1,8 +1,8 @@
1
1
  import * as grpc from '@grpc/grpc-js';
2
2
  import * as protobufjs from 'protobufjs';
3
- import { Lang } from '../constants.js';
4
- import { GatewayError } from '../models/common.js';
5
- import { AppErrorConstructor } from '../models/error.js';
3
+ import { Lang } from '../constants';
4
+ import { GatewayError } from '../models/common';
5
+ import { AppErrorConstructor } from '../models/error';
6
6
  export declare function parseMixedError(e: Error & {
7
7
  code?: string;
8
8
  }): {
@@ -11,7 +11,7 @@ export declare function parseMixedError(e: Error & {
11
11
  code: string;
12
12
  debug: {
13
13
  originalError: Error & {
14
- code?: string;
14
+ code?: string | undefined;
15
15
  };
16
16
  stack: string | undefined;
17
17
  };
@@ -3,15 +3,10 @@ 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.GrpcError = void 0;
7
- exports.parseMixedError = parseMixedError;
8
- exports.parseRestError = parseRestError;
9
- exports.parseGrpcError = parseGrpcError;
10
- exports.isGrpcError = isGrpcError;
11
- exports.grpcErrorFactory = grpcErrorFactory;
6
+ exports.grpcErrorFactory = exports.isGrpcError = exports.GrpcError = exports.parseGrpcError = exports.parseRestError = exports.parseMixedError = void 0;
12
7
  const lodash_1 = __importDefault(require("lodash"));
13
- const constants_js_1 = require("../constants.js");
14
- const grpc_js_1 = require("./grpc.js");
8
+ const constants_1 = require("../constants");
9
+ const grpc_1 = require("./grpc");
15
10
  const DEFAULT_GATEWAY_CODE = 'GATEWAY_REQUEST_ERROR';
16
11
  const DEFAULT_GATEWAY_MESSAGE = 'Gateway request error';
17
12
  function parseMixedError(e) {
@@ -25,6 +20,7 @@ function parseMixedError(e) {
25
20
  },
26
21
  };
27
22
  }
23
+ exports.parseMixedError = parseMixedError;
28
24
  function getErrorTitle(error) {
29
25
  const prop = lodash_1.default.propertyOf(error);
30
26
  const details = prop('details[0]');
@@ -110,20 +106,20 @@ function parseRestError(error, lang) {
110
106
  title = errorTitle ? errorTitle : statusTitle;
111
107
  description = getErrorMessage(responseData);
112
108
  if (status === 403) {
113
- title = lang === constants_js_1.Lang.Ru ? 'Доступ запрещен' : 'Access denied';
109
+ title = lang === constants_1.Lang.Ru ? 'Доступ запрещен' : 'Access denied';
114
110
  }
115
111
  }
116
112
  else {
117
113
  code = prop('code');
118
- title = lang === constants_js_1.Lang.Ru ? 'Ошибка' : 'Error';
114
+ title = lang === constants_1.Lang.Ru ? 'Ошибка' : 'Error';
119
115
  if (code === 'ECONNABORTED' || code === 'ETIMEDOUT') {
120
116
  status = 504;
121
- description = lang === constants_js_1.Lang.Ru ? 'Превышено время ожидания ответа' : 'Timeout exceeded';
117
+ description = lang === constants_1.Lang.Ru ? 'Превышено время ожидания ответа' : 'Timeout exceeded';
122
118
  }
123
119
  else {
124
120
  status = 500;
125
121
  description =
126
- lang === constants_js_1.Lang.Ru
122
+ lang === constants_1.Lang.Ru
127
123
  ? 'Произошла непредвиденная ошибка. Попробуйте обновить страницу через некоторое время.'
128
124
  : 'An unexpected error has occurred. Try to refresh the page in a few moments.';
129
125
  }
@@ -138,21 +134,22 @@ function parseRestError(error, lang) {
138
134
  debug,
139
135
  };
140
136
  }
137
+ exports.parseRestError = parseRestError;
141
138
  function decodeGrpcStatusMessage(metadata, packageRoot, decodeAnyMessageProtoLoaderOptions) {
142
139
  const statusMessageBin = metadata.get('grpc-status-details-bin')[0];
143
140
  if (!statusMessageBin) {
144
141
  return undefined;
145
142
  }
146
- return (0, grpc_js_1.decodeAnyMessageRecursively)(packageRoot, {
143
+ return (0, grpc_1.decodeAnyMessageRecursively)(packageRoot, {
147
144
  type_url: 'type.googleapis.com/google.rpc.Status',
148
145
  value: statusMessageBin,
149
146
  }, decodeAnyMessageProtoLoaderOptions);
150
147
  }
151
- function parseGrpcError(error, packageRoot, lang = constants_js_1.Lang.Ru, decodeAnyMessageProtoLoaderOptions) {
152
- let title = lang === constants_js_1.Lang.Ru ? 'Ошибка' : 'Error';
148
+ function parseGrpcError(error, packageRoot, lang = constants_1.Lang.Ru, decodeAnyMessageProtoLoaderOptions) {
149
+ let title = lang === constants_1.Lang.Ru ? 'Ошибка' : 'Error';
153
150
  if (error.code === 7) {
154
151
  // Always redefine title for Access denied errors
155
- title = lang === constants_js_1.Lang.Ru ? 'Доступ запрещен' : 'Access denied';
152
+ title = lang === constants_1.Lang.Ru ? 'Доступ запрещен' : 'Access denied';
156
153
  }
157
154
  let code = error.code;
158
155
  let description = error.details;
@@ -170,12 +167,12 @@ function parseGrpcError(error, packageRoot, lang = constants_js_1.Lang.Ru, decod
170
167
  }
171
168
  // Always redefine description for Timeout exceeded errors
172
169
  if (error.code === 4) {
173
- description = lang === constants_js_1.Lang.Ru ? 'Превышено время ожидания ответа' : 'Timeout exceeded';
170
+ description = lang === constants_1.Lang.Ru ? 'Превышено время ожидания ответа' : 'Timeout exceeded';
174
171
  }
175
172
  // Use default description if description is undefined, but not for Access denied errors
176
173
  if (!description) {
177
174
  description =
178
- lang === constants_js_1.Lang.Ru
175
+ lang === constants_1.Lang.Ru
179
176
  ? 'Произошла непредвиденная ошибка. Попробуйте обновить страницу через некоторое время.'
180
177
  : 'An unexpected error has occurred. Try to refresh the page in a few moments.';
181
178
  }
@@ -188,6 +185,7 @@ function parseGrpcError(error, packageRoot, lang = constants_js_1.Lang.Ru, decod
188
185
  description, grpcCode: code }, (typeof details === 'object' && !Array.isArray(details) ? details : { details })),
189
186
  };
190
187
  }
188
+ exports.parseGrpcError = parseGrpcError;
191
189
  class GrpcError extends Error {
192
190
  constructor(message, parsedError, rawError) {
193
191
  super(message);
@@ -212,6 +210,7 @@ exports.GrpcError = GrpcError;
212
210
  function isGrpcError(error) {
213
211
  return error.getGatewayError !== undefined;
214
212
  }
213
+ exports.isGrpcError = isGrpcError;
215
214
  function grpcErrorFactory(error) {
216
215
  return new GrpcError(error.message, {
217
216
  status: 500,
@@ -220,3 +219,4 @@ function grpcErrorFactory(error) {
220
219
  details: {},
221
220
  });
222
221
  }
222
+ exports.grpcErrorFactory = grpcErrorFactory;
@@ -15,39 +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 () {
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
- })();
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
+ };
35
28
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.patchProtoPathResolver = patchProtoPathResolver;
37
- const fs = __importStar(require("fs"));
38
- const path = __importStar(require("path"));
29
+ exports.patchProtoPathResolver = void 0;
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const path_1 = __importDefault(require("path"));
39
32
  const protobufjs = __importStar(require("protobufjs"));
40
33
  function patchProtoPathResolver(root, includeDirs) {
41
34
  const originalResolvePath = root.resolvePath;
42
35
  root.resolvePath = function (origin, target) {
43
- if (target in protobufjs.common || path.isAbsolute(target)) {
36
+ if (target in protobufjs.common || path_1.default.isAbsolute(target)) {
44
37
  return target;
45
38
  }
46
39
  for (let i = 0; i < includeDirs.length; i++) {
47
40
  const directory = includeDirs[i];
48
- const fullPath = path.join(directory, target);
41
+ const fullPath = path_1.default.join(directory, target);
49
42
  try {
50
- fs.accessSync(fullPath, fs.constants.R_OK);
43
+ fs_1.default.accessSync(fullPath, fs_1.default.constants.R_OK);
51
44
  return fullPath;
52
45
  }
53
46
  catch (err) {
@@ -57,3 +50,4 @@ function patchProtoPathResolver(root, includeDirs) {
57
50
  return originalResolvePath(origin, target);
58
51
  };
59
52
  }
53
+ exports.patchProtoPathResolver = patchProtoPathResolver;
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { IncomingHttpHeaders } from 'http';
2
- import { GatewayContext } from '../models/context.js';
3
+ import { GatewayContext } from '../models/context';
3
4
  export declare function redactSensitiveHeaders(ctx: GatewayContext, headers: IncomingHttpHeaders): IncomingHttpHeaders;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.redactSensitiveHeaders = redactSensitiveHeaders;
3
+ exports.redactSensitiveHeaders = void 0;
4
4
  function redactSensitiveHeaders(ctx, headers) {
5
5
  var _a, _b;
6
6
  if ((_a = ctx.utils) === null || _a === void 0 ? void 0 : _a.redactSensitiveHeaders) {
@@ -13,3 +13,4 @@ function redactSensitiveHeaders(ctx, headers) {
13
13
  return headers;
14
14
  }
15
15
  }
16
+ exports.redactSensitiveHeaders = redactSensitiveHeaders;
@@ -1,2 +1,2 @@
1
- import { ContextApiWithRoot, SchemasByScope } from '../models/common.js';
1
+ import { ContextApiWithRoot, SchemasByScope } from './../models/common';
2
2
  export declare function getTypedApiFactory<TSchema extends SchemasByScope>(): (api: unknown) => ContextApiWithRoot<TSchema>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTypedApiFactory = getTypedApiFactory;
3
+ exports.getTypedApiFactory = void 0;
4
4
  function getTypedApiFactory() {
5
5
  return (api) => api;
6
6
  }
7
+ exports.getTypedApiFactory = getTypedApiFactory;
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateArgs = validateArgs;
4
- exports.encodePathParams = encodePathParams;
5
- exports.getPathParam = getPathParam;
6
- exports.getPathArgsProxy = getPathArgsProxy;
7
- const ajv_1 = require("ajv");
6
+ exports.getPathArgsProxy = exports.getPathParam = exports.encodePathParams = exports.validateArgs = void 0;
7
+ const ajv_1 = __importDefault(require("ajv"));
8
8
  function validateArgs(args, schema) {
9
- const ajv = new ajv_1.Ajv();
9
+ const ajv = new ajv_1.default();
10
10
  const validate = ajv.compile(schema);
11
11
  return validate(args) ? false : ajv.errorsText(validate.errors);
12
12
  }
13
+ exports.validateArgs = validateArgs;
13
14
  function encodePathParams(params) {
14
15
  const encodedParams = {};
15
16
  Object.keys(params).forEach((key) => {
@@ -26,9 +27,11 @@ function encodePathParams(params) {
26
27
  });
27
28
  return encodedParams;
28
29
  }
30
+ exports.encodePathParams = encodePathParams;
29
31
  function getPathParam(value) {
30
32
  return /^((?!(\.\.|\?|#|\\|\/)).)*$/i.test(value) ? value : 'GATEWAY_INVALID_PARAM_VALUE';
31
33
  }
34
+ exports.getPathParam = getPathParam;
32
35
  function getPathArgsProxy(args, encodePathArgs) {
33
36
  const encodePathArgsVal = encodePathArgs !== null && encodePathArgs !== void 0 ? encodePathArgs : true;
34
37
  if (!args) {
@@ -51,3 +54,4 @@ function getPathArgsProxy(args, encodePathArgs) {
51
54
  },
52
55
  });
53
56
  }
57
+ exports.getPathArgsProxy = getPathArgsProxy;