@gravity-ui/gateway 4.1.2-alpha.0 → 4.2.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.
- package/{dist/commonjs → build}/components/grpc.d.ts +4 -4
- package/{dist/commonjs → build}/components/grpc.js +78 -85
- package/{dist/esm → build}/components/mixed.d.ts +4 -4
- package/{dist/commonjs → build}/components/mixed.js +12 -11
- package/{dist/commonjs → build}/components/rest.d.ts +5 -5
- package/{dist/commonjs → build}/components/rest.js +32 -32
- package/{dist/esm → build}/constants.d.ts +2 -2
- package/{dist/commonjs → build}/constants.js +19 -29
- package/{dist/commonjs → build}/index.d.ts +7 -8
- package/{dist/commonjs → build}/index.js +46 -32
- package/{dist/esm → build}/models/common.d.ts +14 -12
- package/{dist/esm → build}/models/context.d.ts +1 -0
- package/build/utils/axios.d.ts +4 -0
- package/{dist/commonjs → build}/utils/axios.js +6 -4
- package/{dist/esm → build}/utils/common.d.ts +3 -3
- package/{dist/commonjs → build}/utils/common.js +8 -7
- package/{dist/commonjs → build}/utils/create-context-api.d.ts +2 -2
- package/{dist/commonjs → build}/utils/create-context-api.js +6 -5
- package/{dist/commonjs → build}/utils/grpc-reflection.js +18 -31
- package/{dist/commonjs → build}/utils/grpc.js +21 -9
- package/build/utils/overrideEndpoints/index.d.ts +2 -0
- package/build/utils/overrideEndpoints/index.js +4 -0
- package/{dist/commonjs → build}/utils/overrideEndpoints/overrideEndpoints.d.ts +1 -1
- package/{dist/commonjs → build}/utils/overrideEndpoints/overrideEndpoints.js +2 -1
- package/{dist/esm → build}/utils/parse-error.d.ts +4 -4
- package/{dist/commonjs → build}/utils/parse-error.js +18 -18
- package/{dist/commonjs → build}/utils/proto-path-resolver.js +17 -23
- package/{dist/commonjs → build}/utils/redact-sensitive-headers.d.ts +2 -1
- package/{dist/commonjs → build}/utils/redact-sensitive-headers.js +2 -1
- package/{dist/commonjs → build}/utils/typed-api.d.ts +1 -1
- package/{dist/commonjs → build}/utils/typed-api.js +2 -1
- package/{dist/commonjs → build}/utils/validate.js +10 -6
- package/package.json +16 -41
- package/dist/commonjs/components/mixed.d.ts +0 -11
- package/dist/commonjs/constants.d.ts +0 -53
- package/dist/commonjs/models/common.d.ts +0 -272
- package/dist/commonjs/models/context.d.ts +0 -22
- package/dist/commonjs/package.json +0 -3
- package/dist/commonjs/utils/axios.d.ts +0 -3
- package/dist/commonjs/utils/common.d.ts +0 -15
- package/dist/commonjs/utils/overrideEndpoints/index.d.ts +0 -2
- package/dist/commonjs/utils/overrideEndpoints/index.js +0 -4
- package/dist/commonjs/utils/package-root.d.ts +0 -1
- package/dist/commonjs/utils/package-root.js +0 -44
- package/dist/commonjs/utils/parse-error.d.ts +0 -30
- package/dist/commonjs/utils/source-dir.d.ts +0 -1
- package/dist/commonjs/utils/source-dir.js +0 -41
- package/dist/esm/components/grpc.d.ts +0 -24
- package/dist/esm/components/grpc.js +0 -641
- package/dist/esm/components/mixed.js +0 -62
- package/dist/esm/components/rest.d.ts +0 -8
- package/dist/esm/components/rest.js +0 -349
- package/dist/esm/constants.js +0 -82
- package/dist/esm/index.d.ts +0 -12
- package/dist/esm/index.js +0 -264
- package/dist/esm/models/common.js +0 -5
- package/dist/esm/models/context.js +0 -1
- package/dist/esm/models/error.d.ts +0 -12
- package/dist/esm/models/error.js +0 -1
- package/dist/esm/package.json +0 -3
- package/dist/esm/utils/axios.d.ts +0 -3
- package/dist/esm/utils/axios.js +0 -23
- package/dist/esm/utils/common.js +0 -38
- package/dist/esm/utils/create-context-api.d.ts +0 -4
- package/dist/esm/utils/create-context-api.js +0 -38
- package/dist/esm/utils/grpc-reflection.d.ts +0 -28
- package/dist/esm/utils/grpc-reflection.js +0 -72
- package/dist/esm/utils/grpc.d.ts +0 -5
- package/dist/esm/utils/grpc.js +0 -39
- package/dist/esm/utils/overrideEndpoints/index.d.ts +0 -2
- package/dist/esm/utils/overrideEndpoints/index.js +0 -2
- package/dist/esm/utils/overrideEndpoints/overrideEndpoints.d.ts +0 -17
- package/dist/esm/utils/overrideEndpoints/overrideEndpoints.js +0 -96
- package/dist/esm/utils/package-root.d.ts +0 -1
- package/dist/esm/utils/package-root.js +0 -8
- package/dist/esm/utils/parse-error.js +0 -210
- package/dist/esm/utils/proto-path-resolver.d.ts +0 -2
- package/dist/esm/utils/proto-path-resolver.js +0 -23
- package/dist/esm/utils/redact-sensitive-headers.d.ts +0 -3
- package/dist/esm/utils/redact-sensitive-headers.js +0 -12
- package/dist/esm/utils/source-dir.d.ts +0 -1
- package/dist/esm/utils/source-dir.js +0 -4
- package/dist/esm/utils/typed-api.d.ts +0 -2
- package/dist/esm/utils/typed-api.js +0 -3
- package/dist/esm/utils/validate.d.ts +0 -4
- package/dist/esm/utils/validate.js +0 -47
- /package/bin/{patch.cjs → patch.js} +0 -0
- /package/{dist/commonjs → build}/models/common.js +0 -0
- /package/{dist/commonjs → build}/models/context.js +0 -0
- /package/{dist/commonjs → build}/models/error.d.ts +0 -0
- /package/{dist/commonjs → build}/models/error.js +0 -0
- /package/{dist/commonjs → build}/utils/grpc-reflection.d.ts +0 -0
- /package/{dist/commonjs → build}/utils/grpc.d.ts +0 -0
- /package/{dist/commonjs → build}/utils/proto-path-resolver.d.ts +0 -0
- /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 =
|
|
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 {
|
|
2
|
-
import {
|
|
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 =
|
|
6
|
+
exports.generateContextApi = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const
|
|
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,
|
|
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,
|
|
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,
|
|
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) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 =
|
|
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
|
|
32
|
+
const proto_path_resolver_1 = require("./proto-path-resolver");
|
|
44
33
|
const reflectionClientsMap = {};
|
|
45
|
-
|
|
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 =
|
|
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,
|
|
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 } =
|
|
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 } =
|
|
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 =
|
|
5
|
-
|
|
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
|
}
|
|
@@ -26,19 +24,33 @@ function decodeAnyMessageRecursively(root, message, decodeAnyMessageProtoLoaderO
|
|
|
26
24
|
return message;
|
|
27
25
|
}
|
|
28
26
|
const typeName = message.type_url.substring(lastSlashIndex + 1);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
try {
|
|
28
|
+
const type = root.lookupType(typeName);
|
|
29
|
+
const decodedMessage = type.toObject(type.decode(message.value), Object.assign(Object.assign({}, constants_1.DEFAULT_PROTO_LOADER_OPTIONS), decodeAnyMessageProtoLoaderOptions));
|
|
30
|
+
if (typeof decodedMessage === 'object' &&
|
|
31
|
+
!Array.isArray(decodedMessage) &&
|
|
32
|
+
!decodedMessage['@type']) {
|
|
33
|
+
Object.assign(decodedMessage, { '@type': message.type_url });
|
|
34
|
+
}
|
|
35
|
+
return decodeAnyMessageRecursively(root, decodedMessage, decodeAnyMessageProtoLoaderOptions);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(`Failed to lookup ${typeName}`, error);
|
|
39
|
+
return message;
|
|
40
|
+
}
|
|
32
41
|
}
|
|
42
|
+
exports.decodeAnyMessageRecursively = decodeAnyMessageRecursively;
|
|
33
43
|
function isRetryableError(error) {
|
|
34
44
|
if (!error) {
|
|
35
45
|
return false;
|
|
36
46
|
}
|
|
37
|
-
return
|
|
47
|
+
return constants_1.RETRYABLE_STATUS_CODES.includes(error.code);
|
|
38
48
|
}
|
|
49
|
+
exports.isRetryableError = isRetryableError;
|
|
39
50
|
function isRecreateServiceError(error) {
|
|
40
51
|
if (!error) {
|
|
41
52
|
return false;
|
|
42
53
|
}
|
|
43
|
-
return
|
|
54
|
+
return constants_1.RECREATE_SERVICE_CODES.includes(error.code);
|
|
44
55
|
}
|
|
56
|
+
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 = 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
|
|
4
|
-
import { GatewayError } from '../models/common
|
|
5
|
-
import { AppErrorConstructor } from '../models/error
|
|
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
|
|
14
|
-
const
|
|
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 ===
|
|
109
|
+
title = lang === constants_1.Lang.Ru ? 'Доступ запрещен' : 'Access denied';
|
|
114
110
|
}
|
|
115
111
|
}
|
|
116
112
|
else {
|
|
117
113
|
code = prop('code');
|
|
118
|
-
title = lang ===
|
|
114
|
+
title = lang === constants_1.Lang.Ru ? 'Ошибка' : 'Error';
|
|
119
115
|
if (code === 'ECONNABORTED' || code === 'ETIMEDOUT') {
|
|
120
116
|
status = 504;
|
|
121
|
-
description = lang ===
|
|
117
|
+
description = lang === constants_1.Lang.Ru ? 'Превышено время ожидания ответа' : 'Timeout exceeded';
|
|
122
118
|
}
|
|
123
119
|
else {
|
|
124
120
|
status = 500;
|
|
125
121
|
description =
|
|
126
|
-
lang ===
|
|
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,
|
|
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 =
|
|
152
|
-
let title = lang ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
|
|
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 =
|
|
37
|
-
const
|
|
38
|
-
const
|
|
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 ||
|
|
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 =
|
|
41
|
+
const fullPath = path_1.default.join(directory, target);
|
|
49
42
|
try {
|
|
50
|
-
|
|
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
|
|
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 =
|
|
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 '
|
|
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 =
|
|
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 =
|
|
4
|
-
|
|
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.
|
|
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;
|