@gravity-ui/gateway 4.1.1-alpha.0 → 4.2.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/{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 +18 -25
- 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 +12 -21
- package/{dist/commonjs → build}/utils/grpc.js +8 -7
- 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/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 -79
- 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 -68
- 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/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,32 +15,21 @@ 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])];
|
|
@@ -54,7 +43,7 @@ function getCachedClient(actionEndpoint, credentials, grpcOptions, descriptorExt
|
|
|
54
43
|
descriptorRoot.loadSync(descriptorExtensionProto);
|
|
55
44
|
}
|
|
56
45
|
else {
|
|
57
|
-
(0,
|
|
46
|
+
(0, proto_path_resolver_1.patchProtoPathResolver)(descriptorRoot, descriptorExtensionProto.includeProtoRoots);
|
|
58
47
|
descriptorRoot.loadSync(descriptorExtensionProto.filenames);
|
|
59
48
|
}
|
|
60
49
|
}
|
|
@@ -88,6 +77,7 @@ async function getCachedReflectionRoot(actionEndpoint, protoKey, credentials, gr
|
|
|
88
77
|
const loadedRoot = await cachedRootPromise;
|
|
89
78
|
return loadedRoot;
|
|
90
79
|
}
|
|
80
|
+
exports.getCachedReflectionRoot = getCachedReflectionRoot;
|
|
91
81
|
/**
|
|
92
82
|
* @param actionEndpoint
|
|
93
83
|
* @param protoKey
|
|
@@ -106,3 +96,4 @@ async function getReflectionRoot(actionEndpoint, protoKey, credentials, grpcOpti
|
|
|
106
96
|
}
|
|
107
97
|
return loadedRoot;
|
|
108
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
|
}
|
|
@@ -27,18 +25,21 @@ function decodeAnyMessageRecursively(root, message, decodeAnyMessageProtoLoaderO
|
|
|
27
25
|
}
|
|
28
26
|
const typeName = message.type_url.substring(lastSlashIndex + 1);
|
|
29
27
|
const type = root.lookupType(typeName);
|
|
30
|
-
const decodedMessage = type.toObject(type.decode(message.value), Object.assign(Object.assign({},
|
|
28
|
+
const decodedMessage = type.toObject(type.decode(message.value), Object.assign(Object.assign({}, constants_1.DEFAULT_PROTO_LOADER_OPTIONS), decodeAnyMessageProtoLoaderOptions));
|
|
31
29
|
return decodeAnyMessageRecursively(root, decodedMessage, decodeAnyMessageProtoLoaderOptions);
|
|
32
30
|
}
|
|
31
|
+
exports.decodeAnyMessageRecursively = decodeAnyMessageRecursively;
|
|
33
32
|
function isRetryableError(error) {
|
|
34
33
|
if (!error) {
|
|
35
34
|
return false;
|
|
36
35
|
}
|
|
37
|
-
return
|
|
36
|
+
return constants_1.RETRYABLE_STATUS_CODES.includes(error.code);
|
|
38
37
|
}
|
|
38
|
+
exports.isRetryableError = isRetryableError;
|
|
39
39
|
function isRecreateServiceError(error) {
|
|
40
40
|
if (!error) {
|
|
41
41
|
return false;
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return constants_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 = 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;
|
package/package.json
CHANGED
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/gateway",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
7
|
-
"main": "./dist/commonjs/index.js",
|
|
8
|
-
"module": "./dist/esm/index.js",
|
|
9
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
10
|
-
"exports": {
|
|
11
|
-
"./package.json": "./package.json",
|
|
12
|
-
".": {
|
|
13
|
-
"import": {
|
|
14
|
-
"types": "./dist/esm/index.d.ts",
|
|
15
|
-
"default": "./dist/esm/index.js"
|
|
16
|
-
},
|
|
17
|
-
"require": {
|
|
18
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
19
|
-
"default": "./dist/commonjs/index.js"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
6
|
+
"main": "build/index.js",
|
|
23
7
|
"files": [
|
|
24
|
-
"
|
|
8
|
+
"build",
|
|
25
9
|
"proto",
|
|
26
10
|
"bin",
|
|
27
11
|
"patches"
|
|
28
12
|
],
|
|
13
|
+
"types": "build/index.d.ts",
|
|
29
14
|
"bin": {
|
|
30
|
-
"gateway-reflection-patch": "bin/patch.
|
|
15
|
+
"gateway-reflection-patch": "bin/patch.js"
|
|
31
16
|
},
|
|
32
17
|
"repository": {
|
|
33
18
|
"type": "git",
|
|
@@ -39,13 +24,13 @@
|
|
|
39
24
|
"homepage": "https://github.com/gravity-ui/gateway#readme",
|
|
40
25
|
"scripts": {
|
|
41
26
|
"prepare": "husky install",
|
|
42
|
-
"build": "
|
|
27
|
+
"build": "tsc",
|
|
43
28
|
"build-integration": "sh integration-test/build.sh",
|
|
44
|
-
"start-integration-server": "node build-integration/server",
|
|
29
|
+
"start-integration-server": "node build-integration/integration-test/server",
|
|
45
30
|
"build-and-run-integration": "npm run build-integration && npm run start-integration-server",
|
|
46
31
|
"clean": "rm -rf build && rm -rf build-integration",
|
|
47
32
|
"lint": "npm run lint:code && npm run lint:exports",
|
|
48
|
-
"lint:code": "eslint \"
|
|
33
|
+
"lint:code": "eslint \"lib/**/*.{js,ts}\" --quiet",
|
|
49
34
|
"lint:exports": "npm run build && attw --pack .",
|
|
50
35
|
"typecheck": "tsc --noEmit",
|
|
51
36
|
"prepublishOnly": "npm run build",
|
|
@@ -56,9 +41,9 @@
|
|
|
56
41
|
"dependencies": {
|
|
57
42
|
"@grpc/grpc-js": "^1.9.9",
|
|
58
43
|
"@grpc/proto-loader": "^0.7.8",
|
|
59
|
-
"ajv": "^8.
|
|
44
|
+
"ajv": "^8.12.0",
|
|
60
45
|
"axios": "^1.3.5",
|
|
61
|
-
"axios-retry": "^4.
|
|
46
|
+
"axios-retry": "^3.4.0",
|
|
62
47
|
"lodash": "^4.17.21",
|
|
63
48
|
"object-sizeof": "^2.6.5",
|
|
64
49
|
"protobufjs": "^7.2.5",
|
|
@@ -66,13 +51,13 @@
|
|
|
66
51
|
},
|
|
67
52
|
"devDependencies": {
|
|
68
53
|
"@arethetypeswrong/cli": "^0.17.3",
|
|
69
|
-
"@commitlint/cli": "^
|
|
70
|
-
"@commitlint/config-conventional": "^
|
|
54
|
+
"@commitlint/cli": "^17.7.1",
|
|
55
|
+
"@commitlint/config-conventional": "^17.7.0",
|
|
71
56
|
"@gravity-ui/eslint-config": "^2.0.0",
|
|
72
57
|
"@gravity-ui/prettier-config": "^1.0.1",
|
|
73
58
|
"@gravity-ui/tsconfig": "^1.0.0",
|
|
74
59
|
"@types/express": "^4.17.17",
|
|
75
|
-
"@types/jest": "^29.5.
|
|
60
|
+
"@types/jest": "^29.5.0",
|
|
76
61
|
"@types/lodash": "^4.14.192",
|
|
77
62
|
"@types/node": "^18.15.11",
|
|
78
63
|
"@types/uuid": "^9.0.1",
|
|
@@ -83,14 +68,13 @@
|
|
|
83
68
|
"grpc-server-reflection": "^0.1.5",
|
|
84
69
|
"grpc-tools": "^1.12.4",
|
|
85
70
|
"husky": "^8.0.3",
|
|
86
|
-
"jest": "^29.
|
|
71
|
+
"jest": "^29.5.0",
|
|
87
72
|
"nano-staged": "^0.8.0",
|
|
88
73
|
"prettier": "^2.8.6",
|
|
89
74
|
"start-server-and-test": "^2.0.0",
|
|
90
|
-
"ts-jest": "^29.
|
|
75
|
+
"ts-jest": "^29.1.1",
|
|
91
76
|
"tsc-watch": "^6.0.0",
|
|
92
|
-
"
|
|
93
|
-
"typescript": "^5.7.3"
|
|
77
|
+
"typescript": "^5.0.2"
|
|
94
78
|
},
|
|
95
79
|
"peerDependencies": {
|
|
96
80
|
"grpc-reflection-js": "^0.3.0"
|
|
@@ -107,14 +91,5 @@
|
|
|
107
91
|
"*.md": [
|
|
108
92
|
"prettier --write"
|
|
109
93
|
]
|
|
110
|
-
},
|
|
111
|
-
"tshy": {
|
|
112
|
-
"exclude": [
|
|
113
|
-
"src/**/*.test.ts"
|
|
114
|
-
],
|
|
115
|
-
"exports": {
|
|
116
|
-
"./package.json": "./package.json",
|
|
117
|
-
".": "./src/index.ts"
|
|
118
|
-
}
|
|
119
94
|
}
|
|
120
95
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ApiActionConfig, ApiByScope, ApiServiceMixedActionConfig, GatewayConfig, GatewayRequest, GatewayResponse, SchemasByScope } from '../models/common.js';
|
|
2
|
-
import { GatewayContext } from '../models/context.js';
|
|
3
|
-
import { AppErrorConstructor } from '../models/error.js';
|
|
4
|
-
import type { GrpcContext } from './grpc.js';
|
|
5
|
-
export declare function createMixedAction<TSchema extends SchemasByScope, Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse>(config: ApiServiceMixedActionConfig<Context, Req, Res, any, any, any>, api: ApiByScope<TSchema, Context, Req, Res>, serviceName: string, actionName: string, extra: {
|
|
6
|
-
config: GatewayConfig<Context, Req, Res>;
|
|
7
|
-
grpcContext: GrpcContext;
|
|
8
|
-
}, ErrorConstructor: AppErrorConstructor): (actionConfig: ApiActionConfig<Context, any>) => Promise<{
|
|
9
|
-
responseData: any;
|
|
10
|
-
debugHeaders: {};
|
|
11
|
-
}>;
|