@gravity-ui/gateway 4.1.1-alpha.0 → 4.1.2-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.
@@ -53,17 +53,17 @@ const common_js_1 = require("../models/common.js");
53
53
  const common_js_2 = require("../utils/common.js");
54
54
  const grpc_reflection_js_1 = require("../utils/grpc-reflection.js");
55
55
  const grpc_js_1 = require("../utils/grpc.js");
56
+ const package_root_js_1 = require("../utils/package-root.js");
56
57
  const parse_error_js_1 = require("../utils/parse-error.js");
57
58
  const proto_path_resolver_js_1 = require("../utils/proto-path-resolver.js");
58
59
  const redact_sensitive_headers_js_1 = require("../utils/redact-sensitive-headers.js");
59
- const source_dir_js_1 = require("../utils/source-dir.js");
60
60
  const validate_js_1 = require("../utils/validate.js");
61
- const grpcLoaderOptions = Object.assign(Object.assign({}, constants_js_1.DEFAULT_PROTO_LOADER_OPTIONS), { includeDirs: [path_1.default.join(source_dir_js_1.sourceDir, '../proto')] });
61
+ const grpcLoaderOptions = Object.assign(Object.assign({}, constants_js_1.DEFAULT_PROTO_LOADER_OPTIONS), { includeDirs: [path_1.default.join(package_root_js_1.packageRoot, 'proto')] });
62
62
  function createRoot(includeGrpcPaths) {
63
63
  const root = new protobufjs.Root();
64
- root.loadSync(path_1.default.resolve(source_dir_js_1.sourceDir, '../proto/google/rpc/code.proto'));
65
- root.loadSync(path_1.default.resolve(source_dir_js_1.sourceDir, '../proto/google/rpc/error_details.proto'));
66
- root.loadSync(path_1.default.resolve(source_dir_js_1.sourceDir, '../proto/google/rpc/status.proto'));
64
+ root.loadSync(path_1.default.resolve(package_root_js_1.packageRoot, 'proto/google/rpc/code.proto'));
65
+ root.loadSync(path_1.default.resolve(package_root_js_1.packageRoot, 'proto/google/rpc/error_details.proto'));
66
+ root.loadSync(path_1.default.resolve(package_root_js_1.packageRoot, 'proto/google/rpc/status.proto'));
67
67
  // Load well-known internal protobufjs types
68
68
  root.loadSync('google/protobuf/struct.proto');
69
69
  root.loadSync('google/protobuf/wrappers.proto');
@@ -34,10 +34,13 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
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;
37
+ const fs = __importStar(require("fs"));
37
38
  const http = __importStar(require("http"));
38
39
  const https = __importStar(require("https"));
40
+ const path = __importStar(require("path"));
39
41
  const grpc = __importStar(require("@grpc/grpc-js"));
40
- 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'));
41
44
  exports.VERSION = packageJson.version;
42
45
  var Lang;
43
46
  (function (Lang) {
@@ -42,14 +42,16 @@ const lodash_1 = __importDefault(require("lodash"));
42
42
  const protobufjs = __importStar(require("protobufjs"));
43
43
  const proto_path_resolver_js_1 = require("./proto-path-resolver.js");
44
44
  const reflectionClientsMap = {};
45
- function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto) {
45
+ async function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto) {
46
46
  const cacheKey = [actionEndpoint, JSON.stringify([grpcOptions, descriptorExtensionProto])];
47
47
  let clientWithCache = lodash_1.default.get(reflectionClientsMap, cacheKey);
48
48
  if (!clientWithCache) {
49
- const grpcReflection = require('grpc-reflection-js');
49
+ const grpcReflection = await import('grpc-reflection-js');
50
50
  let descriptorRoot;
51
51
  if (descriptorExtensionProto) {
52
- descriptorRoot = protobufjs.Root.fromJSON(require('protobufjs/ext/descriptor'));
52
+ descriptorRoot = protobufjs.Root.fromJSON(
53
+ // @ts-expect-error no typings for default export
54
+ (await import('protobufjs/ext/descriptor/index.js')).default);
53
55
  if (Array.isArray(descriptorExtensionProto)) {
54
56
  descriptorRoot.loadSync(descriptorExtensionProto);
55
57
  }
@@ -58,7 +60,9 @@ function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExt
58
60
  descriptorRoot.loadSync(descriptorExtensionProto.filenames);
59
61
  }
60
62
  }
61
- const client = new grpcReflection.Client(actionEndpoint, credentials, grpcOptions, undefined, descriptorRoot);
63
+ const client = new grpcReflection.Client(actionEndpoint, credentials, grpcOptions, undefined,
64
+ // @ts-ignore this parameter is present only in the patched version
65
+ descriptorRoot);
62
66
  clientWithCache = { client, reflectionRootPromiseMap: {} };
63
67
  lodash_1.default.set(reflectionClientsMap, cacheKey, clientWithCache);
64
68
  }
@@ -75,7 +79,7 @@ function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExt
75
79
  * use toJSON for get a JSON descriptor.
76
80
  */
77
81
  async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, grpcOptions, descriptorExtensionProto) {
78
- const { client, reflectionRootPromiseMap } = getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto);
82
+ const { client, reflectionRootPromiseMap } = await getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto);
79
83
  const cacheKey = [actionEndpoint, protoKey];
80
84
  let cachedRootPromise = lodash_1.default.get(reflectionRootPromiseMap, cacheKey);
81
85
  if (!cachedRootPromise) {
@@ -99,7 +103,7 @@ async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, gr
99
103
  * use toJSON for get a JSON descriptor.
100
104
  */
101
105
  async function getReflectionRoot(actionEndpoint, protoKey, credentials, grpcOptions, addToCache) {
102
- const { client, reflectionRootPromiseMap } = getCachedClient(actionEndpoint, credentials, grpcOptions);
106
+ const { client, reflectionRootPromiseMap } = await getCachedClient(actionEndpoint, credentials, grpcOptions);
103
107
  const loadedRoot = await client.fileContainingSymbol(protoKey);
104
108
  if (addToCache) {
105
109
  lodash_1.default.set(reflectionRootPromiseMap, [actionEndpoint, protoKey], Promise.resolve(loadedRoot));
@@ -0,0 +1 @@
1
+ export declare const packageRoot: string;
@@ -0,0 +1,44 @@
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 () {
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.packageRoot = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const source_dir_js_1 = require("./source-dir.js");
40
+ let packageRootTest = path.resolve(source_dir_js_1.sourceDir, '../package.json');
41
+ if (!fs.existsSync(packageRootTest)) {
42
+ packageRootTest = path.resolve(source_dir_js_1.sourceDir, '../../package.json');
43
+ }
44
+ exports.packageRoot = path.dirname(packageRootTest);
@@ -12,17 +12,17 @@ import { GrpcReflection, } from '../models/common.js';
12
12
  import { getHeadersFromMetadata, handleError, isExtendedActionEndpoint, isExtendedGrpcActionEndpoint, sanitizeDebugHeaders, } from '../utils/common.js';
13
13
  import { getCachedReflectionRoot, getReflectionRoot } from '../utils/grpc-reflection.js';
14
14
  import { decodeAnyMessageRecursively, isRecreateServiceError, isRetryableError, } from '../utils/grpc.js';
15
+ import { packageRoot } from '../utils/package-root.js';
15
16
  import { GrpcError, grpcErrorFactory, isGrpcError, parseGrpcError } from '../utils/parse-error.js';
16
17
  import { patchProtoPathResolver } from '../utils/proto-path-resolver.js';
17
18
  import { redactSensitiveHeaders } from '../utils/redact-sensitive-headers.js';
18
- import { sourceDir } from '../utils/source-dir.js';
19
19
  import { validateArgs } from '../utils/validate.js';
20
- const grpcLoaderOptions = Object.assign(Object.assign({}, DEFAULT_PROTO_LOADER_OPTIONS), { includeDirs: [path.join(sourceDir, '../proto')] });
20
+ const grpcLoaderOptions = Object.assign(Object.assign({}, DEFAULT_PROTO_LOADER_OPTIONS), { includeDirs: [path.join(packageRoot, 'proto')] });
21
21
  export function createRoot(includeGrpcPaths) {
22
22
  const root = new protobufjs.Root();
23
- root.loadSync(path.resolve(sourceDir, '../proto/google/rpc/code.proto'));
24
- root.loadSync(path.resolve(sourceDir, '../proto/google/rpc/error_details.proto'));
25
- root.loadSync(path.resolve(sourceDir, '../proto/google/rpc/status.proto'));
23
+ root.loadSync(path.resolve(packageRoot, 'proto/google/rpc/code.proto'));
24
+ root.loadSync(path.resolve(packageRoot, 'proto/google/rpc/error_details.proto'));
25
+ root.loadSync(path.resolve(packageRoot, 'proto/google/rpc/status.proto'));
26
26
  // Load well-known internal protobufjs types
27
27
  root.loadSync('google/protobuf/struct.proto');
28
28
  root.loadSync('google/protobuf/wrappers.proto');
@@ -1,7 +1,10 @@
1
+ import * as fs from 'fs';
1
2
  import * as http from 'http';
2
3
  import * as https from 'https';
4
+ import * as path from 'path';
3
5
  import * as grpc from '@grpc/grpc-js';
4
- const packageJson = require('../package.json');
6
+ import { packageRoot } from './utils/package-root.js';
7
+ const packageJson = JSON.parse(fs.readFileSync(path.resolve(packageRoot, 'package.json'), 'utf-8'));
5
8
  export const VERSION = packageJson.version;
6
9
  export var Lang;
7
10
  (function (Lang) {
@@ -2,14 +2,16 @@ import _ from 'lodash';
2
2
  import * as protobufjs from 'protobufjs';
3
3
  import { patchProtoPathResolver } from './proto-path-resolver.js';
4
4
  const reflectionClientsMap = {};
5
- function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto) {
5
+ async function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto) {
6
6
  const cacheKey = [actionEndpoint, JSON.stringify([grpcOptions, descriptorExtensionProto])];
7
7
  let clientWithCache = _.get(reflectionClientsMap, cacheKey);
8
8
  if (!clientWithCache) {
9
- const grpcReflection = require('grpc-reflection-js');
9
+ const grpcReflection = await import('grpc-reflection-js');
10
10
  let descriptorRoot;
11
11
  if (descriptorExtensionProto) {
12
- descriptorRoot = protobufjs.Root.fromJSON(require('protobufjs/ext/descriptor'));
12
+ descriptorRoot = protobufjs.Root.fromJSON(
13
+ // @ts-expect-error no typings for default export
14
+ (await import('protobufjs/ext/descriptor/index.js')).default);
13
15
  if (Array.isArray(descriptorExtensionProto)) {
14
16
  descriptorRoot.loadSync(descriptorExtensionProto);
15
17
  }
@@ -18,7 +20,9 @@ function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExt
18
20
  descriptorRoot.loadSync(descriptorExtensionProto.filenames);
19
21
  }
20
22
  }
21
- const client = new grpcReflection.Client(actionEndpoint, credentials, grpcOptions, undefined, descriptorRoot);
23
+ const client = new grpcReflection.Client(actionEndpoint, credentials, grpcOptions, undefined,
24
+ // @ts-ignore this parameter is present only in the patched version
25
+ descriptorRoot);
22
26
  clientWithCache = { client, reflectionRootPromiseMap: {} };
23
27
  _.set(reflectionClientsMap, cacheKey, clientWithCache);
24
28
  }
@@ -35,7 +39,7 @@ function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExt
35
39
  * use toJSON for get a JSON descriptor.
36
40
  */
37
41
  export async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, grpcOptions, descriptorExtensionProto) {
38
- const { client, reflectionRootPromiseMap } = getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto);
42
+ const { client, reflectionRootPromiseMap } = await getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExtensionProto);
39
43
  const cacheKey = [actionEndpoint, protoKey];
40
44
  let cachedRootPromise = _.get(reflectionRootPromiseMap, cacheKey);
41
45
  if (!cachedRootPromise) {
@@ -59,7 +63,7 @@ export async function getCachedReflectionRoot(actionEndpoint, protoKey, credenti
59
63
  * use toJSON for get a JSON descriptor.
60
64
  */
61
65
  export async function getReflectionRoot(actionEndpoint, protoKey, credentials, grpcOptions, addToCache) {
62
- const { client, reflectionRootPromiseMap } = getCachedClient(actionEndpoint, credentials, grpcOptions);
66
+ const { client, reflectionRootPromiseMap } = await getCachedClient(actionEndpoint, credentials, grpcOptions);
63
67
  const loadedRoot = await client.fileContainingSymbol(protoKey);
64
68
  if (addToCache) {
65
69
  _.set(reflectionRootPromiseMap, [actionEndpoint, protoKey], Promise.resolve(loadedRoot));
@@ -0,0 +1 @@
1
+ export declare const packageRoot: string;
@@ -0,0 +1,8 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { sourceDir } from './source-dir.js';
4
+ let packageRootTest = path.resolve(sourceDir, '../package.json');
5
+ if (!fs.existsSync(packageRootTest)) {
6
+ packageRootTest = path.resolve(sourceDir, '../../package.json');
7
+ }
8
+ export const packageRoot = path.dirname(packageRootTest);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/gateway",
3
- "version": "4.1.1-alpha.0",
3
+ "version": "4.1.2-alpha.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",