@gravity-ui/gateway 4.7.1-alpha.0 → 4.7.1

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 (94) hide show
  1. package/{dist/esm → build}/components/grpc.d.ts +5 -5
  2. package/{dist/commonjs → build}/components/grpc.js +84 -94
  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 +34 -35
  7. package/{dist/esm → build}/constants.d.ts +3 -2
  8. package/{dist/commonjs → build}/constants.js +21 -30
  9. package/{dist/commonjs → build}/index.d.ts +8 -9
  10. package/{dist/commonjs → build}/index.js +46 -35
  11. package/{dist/esm → build}/models/common.d.ts +7 -12
  12. package/{dist/esm → build}/models/context.d.ts +1 -0
  13. package/{dist/esm → build}/utils/axios.d.ts +1 -1
  14. package/{dist/commonjs → build}/utils/axios.js +4 -3
  15. package/{dist/esm → build}/utils/common.d.ts +4 -4
  16. package/{dist/commonjs → build}/utils/common.js +8 -8
  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 +35 -15
  20. package/{dist/commonjs → build}/utils/grpc.d.ts +1 -1
  21. package/{dist/commonjs → build}/utils/grpc.js +11 -10
  22. package/build/utils/overrideEndpoints/index.d.ts +2 -0
  23. package/build/utils/overrideEndpoints/index.js +4 -0
  24. package/{dist/esm → build}/utils/overrideEndpoints/overrideEndpoints.d.ts +1 -1
  25. package/{dist/commonjs → build}/utils/overrideEndpoints/overrideEndpoints.js +2 -1
  26. package/{dist/commonjs → build}/utils/parse-error.d.ts +5 -5
  27. package/{dist/commonjs → build}/utils/parse-error.js +19 -19
  28. package/{dist/commonjs → build}/utils/proto-path-resolver.d.ts +1 -1
  29. package/{dist/commonjs → build}/utils/proto-path-resolver.js +15 -24
  30. package/{dist/commonjs → build}/utils/redact-sensitive-headers.d.ts +2 -1
  31. package/{dist/commonjs → build}/utils/redact-sensitive-headers.js +2 -1
  32. package/{dist/commonjs → build}/utils/typed-api.d.ts +1 -1
  33. package/{dist/commonjs → build}/utils/typed-api.js +2 -1
  34. package/{dist/commonjs → build}/utils/validate.d.ts +0 -1
  35. package/{dist/commonjs → build}/utils/validate.js +20 -24
  36. package/package.json +16 -41
  37. package/dist/commonjs/components/grpc.d.ts +0 -24
  38. package/dist/commonjs/components/mixed.d.ts +0 -11
  39. package/dist/commonjs/constants.d.ts +0 -53
  40. package/dist/commonjs/models/common.d.ts +0 -289
  41. package/dist/commonjs/models/context.d.ts +0 -22
  42. package/dist/commonjs/package.json +0 -3
  43. package/dist/commonjs/utils/axios.d.ts +0 -4
  44. package/dist/commonjs/utils/common.d.ts +0 -16
  45. package/dist/commonjs/utils/overrideEndpoints/index.d.ts +0 -2
  46. package/dist/commonjs/utils/overrideEndpoints/index.js +0 -4
  47. package/dist/commonjs/utils/overrideEndpoints/overrideEndpoints.d.ts +0 -17
  48. package/dist/commonjs/utils/package-root.d.ts +0 -1
  49. package/dist/commonjs/utils/package-root.js +0 -44
  50. package/dist/commonjs/utils/source-dir.d.ts +0 -1
  51. package/dist/commonjs/utils/source-dir.js +0 -41
  52. package/dist/esm/components/grpc.js +0 -691
  53. package/dist/esm/components/mixed.js +0 -62
  54. package/dist/esm/components/rest.d.ts +0 -8
  55. package/dist/esm/components/rest.js +0 -357
  56. package/dist/esm/constants.js +0 -82
  57. package/dist/esm/index.d.ts +0 -13
  58. package/dist/esm/index.js +0 -274
  59. package/dist/esm/models/common.js +0 -5
  60. package/dist/esm/models/context.js +0 -1
  61. package/dist/esm/models/error.d.ts +0 -12
  62. package/dist/esm/models/error.js +0 -1
  63. package/dist/esm/package.json +0 -3
  64. package/dist/esm/utils/axios.js +0 -24
  65. package/dist/esm/utils/common.js +0 -48
  66. package/dist/esm/utils/create-context-api.d.ts +0 -4
  67. package/dist/esm/utils/create-context-api.js +0 -38
  68. package/dist/esm/utils/grpc-reflection.d.ts +0 -28
  69. package/dist/esm/utils/grpc-reflection.js +0 -72
  70. package/dist/esm/utils/grpc.d.ts +0 -15
  71. package/dist/esm/utils/grpc.js +0 -72
  72. package/dist/esm/utils/overrideEndpoints/index.d.ts +0 -2
  73. package/dist/esm/utils/overrideEndpoints/index.js +0 -2
  74. package/dist/esm/utils/overrideEndpoints/overrideEndpoints.js +0 -96
  75. package/dist/esm/utils/package-root.d.ts +0 -1
  76. package/dist/esm/utils/package-root.js +0 -8
  77. package/dist/esm/utils/parse-error.d.ts +0 -30
  78. package/dist/esm/utils/parse-error.js +0 -214
  79. package/dist/esm/utils/proto-path-resolver.d.ts +0 -2
  80. package/dist/esm/utils/proto-path-resolver.js +0 -23
  81. package/dist/esm/utils/redact-sensitive-headers.d.ts +0 -3
  82. package/dist/esm/utils/redact-sensitive-headers.js +0 -12
  83. package/dist/esm/utils/source-dir.d.ts +0 -1
  84. package/dist/esm/utils/source-dir.js +0 -4
  85. package/dist/esm/utils/typed-api.d.ts +0 -2
  86. package/dist/esm/utils/typed-api.js +0 -3
  87. package/dist/esm/utils/validate.d.ts +0 -4
  88. package/dist/esm/utils/validate.js +0 -47
  89. /package/bin/{patch.cjs → patch.js} +0 -0
  90. /package/{dist/commonjs → build}/models/common.js +0 -0
  91. /package/{dist/commonjs → build}/models/context.js +0 -0
  92. /package/{dist/commonjs → build}/models/error.d.ts +0 -0
  93. /package/{dist/commonjs → build}/models/error.js +0 -0
  94. /package/{dist/commonjs → build}/utils/grpc-reflection.d.ts +0 -0
@@ -3,41 +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.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;
6
+ exports.getProxyHeadersArgs = exports.handleError = exports.getHeadersFromMetadata = exports.sanitizeDebugHeaders = exports.getKeys = exports.isExtendedRestActionEndpoint = exports.isExtendedGrpcActionEndpoint = exports.isExtendedActionEndpoint = void 0;
14
7
  const lodash_1 = __importDefault(require("lodash"));
15
8
  function isExtendedActionEndpoint(endpoint) {
16
9
  return (endpoint === null || endpoint === void 0 ? void 0 : endpoint.path) !== undefined;
17
10
  }
11
+ exports.isExtendedActionEndpoint = isExtendedActionEndpoint;
18
12
  function isExtendedGrpcActionEndpoint(endpoint) {
19
13
  return ((endpoint === null || endpoint === void 0 ? void 0 : endpoint.grpcOptions) !== undefined ||
20
14
  (endpoint === null || endpoint === void 0 ? void 0 : endpoint.insecure) !== undefined ||
21
15
  (endpoint === null || endpoint === void 0 ? void 0 : endpoint.secureWithoutRootCert) !== undefined);
22
16
  }
17
+ exports.isExtendedGrpcActionEndpoint = isExtendedGrpcActionEndpoint;
23
18
  function isExtendedRestActionEndpoint(endpoint) {
24
19
  return (endpoint === null || endpoint === void 0 ? void 0 : endpoint.axiosConfig) !== undefined;
25
20
  }
21
+ exports.isExtendedRestActionEndpoint = isExtendedRestActionEndpoint;
26
22
  function getKeys(obj) {
27
23
  return Object.keys(obj);
28
24
  }
25
+ exports.getKeys = getKeys;
29
26
  /**
30
27
  * This function should only use to sanitize debugHeaders that are creating in our code
31
28
  */
32
29
  function sanitizeDebugHeaders(debugHeaders) {
33
30
  return lodash_1.default.omit(debugHeaders, ['x-api-request-body']);
34
31
  }
32
+ exports.sanitizeDebugHeaders = sanitizeDebugHeaders;
35
33
  function getHeadersFromMetadata(metadata, prefix = '') {
36
34
  return Object.entries(metadata).reduce((headers, [key, values]) => {
37
35
  headers[`${prefix}${key}`] = values.filter((value) => typeof value === 'string').join(' ');
38
36
  return headers;
39
37
  }, {});
40
38
  }
39
+ exports.getHeadersFromMetadata = getHeadersFromMetadata;
41
40
  function handleError(ErrorConstructor, error, ctx, message, extra) {
42
41
  if (error instanceof Error) {
43
42
  ctx.logError(message, ErrorConstructor.wrap(error), extra);
@@ -49,6 +48,7 @@ function handleError(ErrorConstructor, error, ctx, message, extra) {
49
48
  ctx.logError(message, error, extra);
50
49
  }
51
50
  }
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;
@@ -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;
@@ -1,35 +1,53 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getCachedReflectionRoot = getCachedReflectionRoot;
7
- exports.getReflectionRoot = getReflectionRoot;
29
+ exports.getReflectionRoot = exports.getCachedReflectionRoot = void 0;
8
30
  const lodash_1 = __importDefault(require("lodash"));
9
- const protobufjs_1 = __importDefault(require("protobufjs"));
10
- const proto_path_resolver_js_1 = require("./proto-path-resolver.js");
31
+ const protobufjs = __importStar(require("protobufjs"));
32
+ const proto_path_resolver_1 = require("./proto-path-resolver");
11
33
  const reflectionClientsMap = {};
12
- async function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto) {
34
+ function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto) {
13
35
  const cacheKey = [actionEndpoint, JSON.stringify([grpcOptions, descriptorExtensionProto])];
14
36
  let clientWithCache = lodash_1.default.get(reflectionClientsMap, cacheKey);
15
37
  if (!clientWithCache) {
16
- const grpcReflection = await import('grpc-reflection-js');
38
+ const grpcReflection = require('grpc-reflection-js');
17
39
  let descriptorRoot;
18
40
  if (descriptorExtensionProto) {
19
- descriptorRoot = protobufjs_1.default.Root.fromJSON(
20
- // @ts-expect-error no typings for default export
21
- (await import('protobufjs/ext/descriptor/index.js')).default);
41
+ descriptorRoot = protobufjs.Root.fromJSON(require('protobufjs/ext/descriptor'));
22
42
  if (Array.isArray(descriptorExtensionProto)) {
23
43
  descriptorRoot.loadSync(descriptorExtensionProto);
24
44
  }
25
45
  else {
26
- (0, proto_path_resolver_js_1.patchProtoPathResolver)(descriptorRoot, descriptorExtensionProto.includeProtoRoots);
46
+ (0, proto_path_resolver_1.patchProtoPathResolver)(descriptorRoot, descriptorExtensionProto.includeProtoRoots);
27
47
  descriptorRoot.loadSync(descriptorExtensionProto.filenames);
28
48
  }
29
49
  }
30
- const client = new grpcReflection.Client(actionEndpoint, credentials, grpcOptions, undefined,
31
- // @ts-ignore this parameter is present only in the patched version
32
- descriptorRoot);
50
+ const client = new grpcReflection.Client(actionEndpoint, credentials, grpcOptions, undefined, descriptorRoot);
33
51
  clientWithCache = { client, reflectionRootPromiseMap: {} };
34
52
  lodash_1.default.set(reflectionClientsMap, cacheKey, clientWithCache);
35
53
  }
@@ -46,7 +64,7 @@ async function getCachedClient(actionEndpoint, credentials, grpcOptions, descrip
46
64
  * use toJSON for get a JSON descriptor.
47
65
  */
48
66
  async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, grpcOptions, descriptorExtensionProto) {
49
- const { client, reflectionRootPromiseMap } = await getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto);
67
+ const { client, reflectionRootPromiseMap } = getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto);
50
68
  const cacheKey = [actionEndpoint, protoKey];
51
69
  let cachedRootPromise = lodash_1.default.get(reflectionRootPromiseMap, cacheKey);
52
70
  if (!cachedRootPromise) {
@@ -59,6 +77,7 @@ async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, gr
59
77
  const loadedRoot = await cachedRootPromise;
60
78
  return loadedRoot;
61
79
  }
80
+ exports.getCachedReflectionRoot = getCachedReflectionRoot;
62
81
  /**
63
82
  * @param actionEndpoint
64
83
  * @param protoKey
@@ -70,10 +89,11 @@ async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, gr
70
89
  * use toJSON for get a JSON descriptor.
71
90
  */
72
91
  async function getReflectionRoot(actionEndpoint, protoKey, credentials, grpcOptions, addToCache) {
73
- const { client, reflectionRootPromiseMap } = await getCachedClient(actionEndpoint, credentials, grpcOptions);
92
+ const { client, reflectionRootPromiseMap } = getCachedClient(actionEndpoint, credentials, grpcOptions);
74
93
  const loadedRoot = await client.fileContainingSymbol(protoKey);
75
94
  if (addToCache) {
76
95
  lodash_1.default.set(reflectionRootPromiseMap, [actionEndpoint, protoKey], Promise.resolve(loadedRoot));
77
96
  }
78
97
  return loadedRoot;
79
98
  }
99
+ exports.getReflectionRoot = getReflectionRoot;
@@ -1,6 +1,6 @@
1
1
  import * as grpc from '@grpc/grpc-js';
2
2
  import { ClientDuplexStream, ClientReadableStream, ClientUnaryCall, ClientWritableStream } from '@grpc/grpc-js';
3
- import protobufjs from 'protobufjs';
3
+ import * as protobufjs from 'protobufjs';
4
4
  export declare function decodeAnyMessageRecursively(root: protobufjs.Root, message?: unknown, decodeAnyMessageProtoLoaderOptions?: protobufjs.IConversionOptions): unknown;
5
5
  export declare function isRetryableGrpcError(error?: grpc.ServiceError): boolean;
6
6
  export declare function isRecreateServiceError(error?: grpc.ServiceError): boolean;
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  /* eslint-disable camelcase */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.decodeAnyMessageRecursively = decodeAnyMessageRecursively;
5
- exports.isRetryableGrpcError = isRetryableGrpcError;
6
- exports.isRecreateServiceError = isRecreateServiceError;
7
- exports.listenForAbort = listenForAbort;
8
- const constants_js_1 = require("../constants.js");
9
- const parse_error_js_1 = require("./parse-error.js");
4
+ exports.listenForAbort = exports.isRecreateServiceError = exports.isRetryableGrpcError = exports.decodeAnyMessageRecursively = void 0;
5
+ const constants_1 = require("../constants");
6
+ const parse_error_1 = require("./parse-error");
10
7
  function isEncodedMessage(message) {
11
8
  return Boolean(message.type_url && message.value);
12
9
  }
@@ -30,7 +27,7 @@ function decodeAnyMessageRecursively(root, message, decodeAnyMessageProtoLoaderO
30
27
  const typeName = message.type_url.substring(lastSlashIndex + 1);
31
28
  try {
32
29
  const type = root.lookupType(typeName);
33
- const decodedMessage = type.toObject(type.decode(message.value), Object.assign(Object.assign({}, constants_js_1.DEFAULT_PROTO_LOADER_OPTIONS), decodeAnyMessageProtoLoaderOptions));
30
+ const decodedMessage = type.toObject(type.decode(message.value), Object.assign(Object.assign({}, constants_1.DEFAULT_PROTO_LOADER_OPTIONS), decodeAnyMessageProtoLoaderOptions));
34
31
  if (typeof decodedMessage === 'object' &&
35
32
  !Array.isArray(decodedMessage) &&
36
33
  !decodedMessage['@type']) {
@@ -43,25 +40,28 @@ function decodeAnyMessageRecursively(root, message, decodeAnyMessageProtoLoaderO
43
40
  return message;
44
41
  }
45
42
  }
43
+ exports.decodeAnyMessageRecursively = decodeAnyMessageRecursively;
46
44
  function isRetryableGrpcError(error) {
47
45
  if (!error) {
48
46
  return false;
49
47
  }
50
- return constants_js_1.RETRYABLE_STATUS_CODES.includes(error.code);
48
+ return constants_1.RETRYABLE_STATUS_CODES.includes(error.code);
51
49
  }
50
+ exports.isRetryableGrpcError = isRetryableGrpcError;
52
51
  function isRecreateServiceError(error) {
53
52
  if (!error) {
54
53
  return false;
55
54
  }
56
- return constants_js_1.RECREATE_SERVICE_CODES.includes(error.code);
55
+ return constants_1.RECREATE_SERVICE_CODES.includes(error.code);
57
56
  }
57
+ exports.isRecreateServiceError = isRecreateServiceError;
58
58
  function listenForAbort({ signal, config, call, reject }) {
59
59
  if (!signal || !config.abortOnClientDisconnect) {
60
60
  return () => null;
61
61
  }
62
62
  const handleAbortSignal = () => {
63
63
  call.cancel();
64
- reject(new parse_error_js_1.GrpcError('Request was cancelled.', {
64
+ reject(new parse_error_1.GrpcError('Request was cancelled.', {
65
65
  status: 499,
66
66
  code: 'REQUEST_WAS_CANCELLED',
67
67
  message: 'Request was cancelled because the original connection was disconnected.',
@@ -76,3 +76,4 @@ function listenForAbort({ signal, config, call, reject }) {
76
76
  signal.removeEventListener('abort', handleAbortSignal);
77
77
  };
78
78
  }
79
+ exports.listenForAbort = listenForAbort;
@@ -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
- import protobufjs from 'protobufjs';
3
- import { Lang } from '../constants.js';
4
- import { GatewayError } from '../models/common.js';
5
- import { AppErrorConstructor } from '../models/error.js';
2
+ import * as protobufjs from 'protobufjs';
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,24 +106,24 @@ 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 if (code === 'ERR_CANCELED') {
124
120
  status = 499;
125
- description = lang === constants_js_1.Lang.Ru ? 'Запрос был отменен.' : 'Request was cancelled.';
121
+ description = lang === constants_1.Lang.Ru ? 'Запрос был отменен.' : 'Request was cancelled.';
126
122
  }
127
123
  else {
128
124
  status = 500;
129
125
  description =
130
- lang === constants_js_1.Lang.Ru
126
+ lang === constants_1.Lang.Ru
131
127
  ? 'Произошла непредвиденная ошибка. Попробуйте обновить страницу через некоторое время.'
132
128
  : 'An unexpected error has occurred. Try to refresh the page in a few moments.';
133
129
  }
@@ -142,21 +138,22 @@ function parseRestError(error, lang) {
142
138
  debug,
143
139
  };
144
140
  }
141
+ exports.parseRestError = parseRestError;
145
142
  function decodeGrpcStatusMessage(metadata, packageRoot, decodeAnyMessageProtoLoaderOptions) {
146
143
  const statusMessageBin = metadata.get('grpc-status-details-bin')[0];
147
144
  if (!statusMessageBin) {
148
145
  return undefined;
149
146
  }
150
- return (0, grpc_js_1.decodeAnyMessageRecursively)(packageRoot, {
147
+ return (0, grpc_1.decodeAnyMessageRecursively)(packageRoot, {
151
148
  type_url: 'type.googleapis.com/google.rpc.Status',
152
149
  value: statusMessageBin,
153
150
  }, decodeAnyMessageProtoLoaderOptions);
154
151
  }
155
- function parseGrpcError(error, packageRoot, lang = constants_js_1.Lang.Ru, decodeAnyMessageProtoLoaderOptions) {
156
- let title = lang === constants_js_1.Lang.Ru ? 'Ошибка' : 'Error';
152
+ function parseGrpcError(error, packageRoot, lang = constants_1.Lang.Ru, decodeAnyMessageProtoLoaderOptions) {
153
+ let title = lang === constants_1.Lang.Ru ? 'Ошибка' : 'Error';
157
154
  if (error.code === 7) {
158
155
  // Always redefine title for Access denied errors
159
- title = lang === constants_js_1.Lang.Ru ? 'Доступ запрещен' : 'Access denied';
156
+ title = lang === constants_1.Lang.Ru ? 'Доступ запрещен' : 'Access denied';
160
157
  }
161
158
  let code = error.code;
162
159
  let description = error.details;
@@ -174,12 +171,12 @@ function parseGrpcError(error, packageRoot, lang = constants_js_1.Lang.Ru, decod
174
171
  }
175
172
  // Always redefine description for Timeout exceeded errors
176
173
  if (error.code === 4) {
177
- description = lang === constants_js_1.Lang.Ru ? 'Превышено время ожидания ответа' : 'Timeout exceeded';
174
+ description = lang === constants_1.Lang.Ru ? 'Превышено время ожидания ответа' : 'Timeout exceeded';
178
175
  }
179
176
  // Use default description if description is undefined, but not for Access denied errors
180
177
  if (!description) {
181
178
  description =
182
- lang === constants_js_1.Lang.Ru
179
+ lang === constants_1.Lang.Ru
183
180
  ? 'Произошла непредвиденная ошибка. Попробуйте обновить страницу через некоторое время.'
184
181
  : 'An unexpected error has occurred. Try to refresh the page in a few moments.';
185
182
  }
@@ -192,6 +189,7 @@ function parseGrpcError(error, packageRoot, lang = constants_js_1.Lang.Ru, decod
192
189
  description, grpcCode: code }, (typeof details === 'object' && !Array.isArray(details) ? details : { details })),
193
190
  };
194
191
  }
192
+ exports.parseGrpcError = parseGrpcError;
195
193
  class GrpcError extends Error {
196
194
  constructor(message, parsedError, rawError) {
197
195
  super(message);
@@ -216,6 +214,7 @@ exports.GrpcError = GrpcError;
216
214
  function isGrpcError(error) {
217
215
  return error.getGatewayError !== undefined;
218
216
  }
217
+ exports.isGrpcError = isGrpcError;
219
218
  function grpcErrorFactory(error) {
220
219
  return new GrpcError(error.message, {
221
220
  status: 500,
@@ -224,3 +223,4 @@ function grpcErrorFactory(error) {
224
223
  details: {},
225
224
  });
226
225
  }
226
+ exports.grpcErrorFactory = grpcErrorFactory;
@@ -1,2 +1,2 @@
1
- import protobufjs from 'protobufjs';
1
+ import * as protobufjs from 'protobufjs';
2
2
  export declare function patchProtoPathResolver(root: protobufjs.Root, includeDirs: string[]): void;
@@ -15,42 +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
+ };
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.patchProtoPathResolver = patchProtoPathResolver;
40
- const fs = __importStar(require("fs"));
41
- const path = __importStar(require("path"));
42
- const protobufjs_1 = __importDefault(require("protobufjs"));
29
+ exports.patchProtoPathResolver = void 0;
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const path_1 = __importDefault(require("path"));
32
+ const protobufjs = __importStar(require("protobufjs"));
43
33
  function patchProtoPathResolver(root, includeDirs) {
44
34
  const originalResolvePath = root.resolvePath;
45
35
  root.resolvePath = function (origin, target) {
46
- if (target in protobufjs_1.default.common || path.isAbsolute(target)) {
36
+ if (target in protobufjs.common || path_1.default.isAbsolute(target)) {
47
37
  return target;
48
38
  }
49
39
  for (let i = 0; i < includeDirs.length; i++) {
50
40
  const directory = includeDirs[i];
51
- const fullPath = path.join(directory, target);
41
+ const fullPath = path_1.default.join(directory, target);
52
42
  try {
53
- fs.accessSync(fullPath, fs.constants.R_OK);
43
+ fs_1.default.accessSync(fullPath, fs_1.default.constants.R_OK);
54
44
  return fullPath;
55
45
  }
56
46
  catch (err) {
@@ -60,3 +50,4 @@ function patchProtoPathResolver(root, includeDirs) {
60
50
  return originalResolvePath(origin, target);
61
51
  };
62
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,4 +1,3 @@
1
1
  export declare function validateArgs<TParams>(args: TParams, schema: object): string | false;
2
- export declare function encodePathParams<TParams extends {}>(params: TParams): Record<string, any>;
3
2
  export declare function getPathParam(value: string): string;
4
3
  export declare function getPathArgsProxy<TParams extends {}>(args: TParams, encodePathArgs?: boolean): TParams;
@@ -1,34 +1,21 @@
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.validateArgs = void 0;
7
+ const ajv_1 = __importDefault(require("ajv"));
8
+ const constants_1 = require("../constants");
8
9
  function validateArgs(args, schema) {
9
- const ajv = new ajv_1.Ajv();
10
+ const ajv = new ajv_1.default();
10
11
  const validate = ajv.compile(schema);
11
12
  return validate(args) ? false : ajv.errorsText(validate.errors);
12
13
  }
13
- function encodePathParams(params) {
14
- const encodedParams = {};
15
- Object.keys(params).forEach((key) => {
16
- const value = params[key];
17
- if (value instanceof Buffer) {
18
- encodedParams[key] = value;
19
- }
20
- else if (typeof value === 'object' && value !== null) {
21
- encodedParams[key] = encodePathParams(value);
22
- }
23
- else {
24
- encodedParams[key] = encodeURIComponent(value);
25
- }
26
- });
27
- return encodedParams;
28
- }
14
+ exports.validateArgs = validateArgs;
29
15
  function getPathParam(value) {
30
- return /^((?!(\.\.|\?|#|\\|\/)).)*$/i.test(value) ? value : 'GATEWAY_INVALID_PARAM_VALUE';
16
+ return /^((?!(\.\.|\?|#|\\|\/)).)*$/i.test(value) ? value : constants_1.GATEWAY_INVALID_PARAM_VALUE;
31
17
  }
18
+ exports.getPathParam = getPathParam;
32
19
  function getPathArgsProxy(args, encodePathArgs) {
33
20
  const encodePathArgsVal = encodePathArgs !== null && encodePathArgs !== void 0 ? encodePathArgs : true;
34
21
  if (!args) {
@@ -45,9 +32,18 @@ function getPathArgsProxy(args, encodePathArgs) {
45
32
  }
46
33
  if (typeof value === 'string') {
47
34
  const pathParam = getPathParam(value);
48
- return encodePathArgsVal ? encodeURIComponent(pathParam) : pathParam;
35
+ if (encodePathArgsVal) {
36
+ try {
37
+ return encodeURIComponent(pathParam);
38
+ }
39
+ catch (error) {
40
+ return constants_1.GATEWAY_INVALID_PARAM_VALUE;
41
+ }
42
+ }
43
+ return pathParam;
49
44
  }
50
45
  return value; // TODO return error INVALID_PARAMS
51
46
  },
52
47
  });
53
48
  }
49
+ exports.getPathArgsProxy = getPathArgsProxy;