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