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