@gravity-ui/gateway 4.7.1-alpha.0 → 4.7.2
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/esm → build}/components/grpc.d.ts +5 -5
- package/{dist/commonjs → build}/components/grpc.js +93 -97
- 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 +34 -35
- package/{dist/esm → build}/constants.d.ts +3 -2
- package/{dist/commonjs → build}/constants.js +21 -30
- package/{dist/commonjs → build}/index.d.ts +8 -9
- package/{dist/commonjs → build}/index.js +46 -35
- package/{dist/esm → build}/models/common.d.ts +7 -12
- package/{dist/esm → build}/models/context.d.ts +1 -0
- package/{dist/esm → build}/utils/axios.d.ts +1 -1
- package/{dist/commonjs → build}/utils/axios.js +4 -3
- package/{dist/esm → build}/utils/common.d.ts +4 -4
- package/{dist/commonjs → build}/utils/common.js +8 -8
- 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 +35 -15
- package/{dist/commonjs → build}/utils/grpc.d.ts +1 -1
- package/{dist/commonjs → build}/utils/grpc.js +11 -10
- package/build/utils/overrideEndpoints/index.d.ts +2 -0
- package/build/utils/overrideEndpoints/index.js +4 -0
- package/{dist/esm → build}/utils/overrideEndpoints/overrideEndpoints.d.ts +1 -1
- package/{dist/commonjs → build}/utils/overrideEndpoints/overrideEndpoints.js +2 -1
- package/{dist/commonjs → build}/utils/parse-error.d.ts +5 -5
- package/{dist/commonjs → build}/utils/parse-error.js +19 -19
- package/{dist/commonjs → build}/utils/proto-path-resolver.d.ts +1 -1
- package/{dist/commonjs → build}/utils/proto-path-resolver.js +15 -24
- 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.d.ts +0 -1
- package/{dist/commonjs → build}/utils/validate.js +20 -24
- package/package.json +16 -41
- package/dist/commonjs/components/grpc.d.ts +0 -24
- 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 -289
- package/dist/commonjs/models/context.d.ts +0 -22
- package/dist/commonjs/package.json +0 -3
- package/dist/commonjs/utils/axios.d.ts +0 -4
- package/dist/commonjs/utils/common.d.ts +0 -16
- package/dist/commonjs/utils/overrideEndpoints/index.d.ts +0 -2
- package/dist/commonjs/utils/overrideEndpoints/index.js +0 -4
- package/dist/commonjs/utils/overrideEndpoints/overrideEndpoints.d.ts +0 -17
- package/dist/commonjs/utils/package-root.d.ts +0 -1
- package/dist/commonjs/utils/package-root.js +0 -44
- package/dist/commonjs/utils/source-dir.d.ts +0 -1
- package/dist/commonjs/utils/source-dir.js +0 -41
- package/dist/esm/components/grpc.js +0 -691
- package/dist/esm/components/mixed.js +0 -62
- package/dist/esm/components/rest.d.ts +0 -8
- package/dist/esm/components/rest.js +0 -357
- package/dist/esm/constants.js +0 -82
- package/dist/esm/index.d.ts +0 -13
- package/dist/esm/index.js +0 -274
- 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.js +0 -24
- package/dist/esm/utils/common.js +0 -48
- 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 -15
- package/dist/esm/utils/grpc.js +0 -72
- 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.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.d.ts +0 -30
- package/dist/esm/utils/parse-error.js +0 -214
- 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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as grpc from '@grpc/grpc-js';
|
|
2
|
-
import protobufjs from 'protobufjs';
|
|
2
|
+
import * as protobufjs from 'protobufjs';
|
|
3
3
|
import type * as descriptor from 'protobufjs/ext/descriptor';
|
|
4
|
-
import { ApiActionConfig, ApiServiceGrpcActionConfig, EndpointsConfig, GatewayApiOptions } from '../models/common
|
|
5
|
-
import { GatewayContext } from '../models/context
|
|
6
|
-
import { AppErrorConstructor } from '../models/error
|
|
4
|
+
import { ApiActionConfig, ApiServiceGrpcActionConfig, EndpointsConfig, GatewayApiOptions } from '../models/common';
|
|
5
|
+
import { GatewayContext } from '../models/context';
|
|
6
|
+
import { AppErrorConstructor } from '../models/error';
|
|
7
7
|
declare module 'protobufjs' {
|
|
8
8
|
interface Root {
|
|
9
9
|
toDescriptor(protoVersion: string): protobufjs.Message<descriptor.IFileDescriptorSet> & descriptor.IFileDescriptorSet;
|
|
@@ -20,5 +20,5 @@ export interface GrpcContext {
|
|
|
20
20
|
}
|
|
21
21
|
export declare function createRoot(includeGrpcPaths?: string[]): protobufjs.Root;
|
|
22
22
|
export declare function getCredentialsMap(caCertificatePath?: string | null): CredentialsMap;
|
|
23
|
-
export
|
|
23
|
+
export default function createGrpcAction<Context extends GatewayContext>({ root, credentials }: GrpcContext, endpoints: EndpointsConfig | undefined, config: ApiServiceGrpcActionConfig<Context, any, any>, serviceKey: string, actionName: string, options: GatewayApiOptions<Context>, ErrorConstructor: AppErrorConstructor): (actionConfig: ApiActionConfig<Context, any, any>) => Promise<import("../models/common").GatewayActionClientStreamResponse<any> | import("../models/common").GatewayActionServerStreamResponse<any> | import("../models/common").GatewayActionDuplexStreamResponse<any> | import("../models/common").GatewayActionUnaryResponse<any>>;
|
|
24
24
|
export {};
|
|
@@ -16,61 +16,49 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
16
|
}) : function(o, v) {
|
|
17
17
|
o["default"] = v;
|
|
18
18
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) ||
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
36
26
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
28
|
};
|
|
39
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.createRoot =
|
|
41
|
-
exports.getCredentialsMap = getCredentialsMap;
|
|
42
|
-
exports.createGrpcAction = createGrpcAction;
|
|
30
|
+
exports.getCredentialsMap = exports.createRoot = void 0;
|
|
43
31
|
const fs_1 = __importDefault(require("fs"));
|
|
44
32
|
const path_1 = __importDefault(require("path"));
|
|
45
33
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
46
34
|
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
47
35
|
const lodash_1 = __importDefault(require("lodash"));
|
|
48
36
|
const object_sizeof_1 = __importDefault(require("object-sizeof"));
|
|
49
|
-
const
|
|
37
|
+
const protobufjs = __importStar(require("protobufjs"));
|
|
50
38
|
const uuid_1 = require("uuid");
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const grpcLoaderOptions = Object.assign(Object.assign({}, constants_js_1.DEFAULT_PROTO_LOADER_OPTIONS), { includeDirs: [path_1.default.join(package_root_js_1.packageRoot, 'proto')] });
|
|
39
|
+
const constants_1 = require("../constants");
|
|
40
|
+
const common_1 = require("../models/common");
|
|
41
|
+
const common_2 = require("../utils/common");
|
|
42
|
+
const grpc_1 = require("../utils/grpc");
|
|
43
|
+
const grpc_reflection_1 = require("../utils/grpc-reflection");
|
|
44
|
+
const parse_error_1 = require("../utils/parse-error");
|
|
45
|
+
const proto_path_resolver_1 = require("../utils/proto-path-resolver");
|
|
46
|
+
const redact_sensitive_headers_1 = require("../utils/redact-sensitive-headers");
|
|
47
|
+
const validate_1 = require("../utils/validate");
|
|
48
|
+
const grpcLoaderOptions = Object.assign(Object.assign({}, constants_1.DEFAULT_PROTO_LOADER_OPTIONS), { includeDirs: [path_1.default.join(__dirname, '../../proto')] });
|
|
62
49
|
function createRoot(includeGrpcPaths) {
|
|
63
|
-
const root = new
|
|
64
|
-
root.loadSync(path_1.default.resolve(
|
|
65
|
-
root.loadSync(path_1.default.resolve(
|
|
66
|
-
root.loadSync(path_1.default.resolve(
|
|
50
|
+
const root = new protobufjs.Root();
|
|
51
|
+
root.loadSync(path_1.default.resolve(__dirname, '../../proto/google/rpc/code.proto'));
|
|
52
|
+
root.loadSync(path_1.default.resolve(__dirname, '../../proto/google/rpc/error_details.proto'));
|
|
53
|
+
root.loadSync(path_1.default.resolve(__dirname, '../../proto/google/rpc/status.proto'));
|
|
67
54
|
// Load well-known internal protobufjs types
|
|
68
55
|
root.loadSync('google/protobuf/struct.proto');
|
|
69
56
|
root.loadSync('google/protobuf/wrappers.proto');
|
|
70
57
|
grpcLoaderOptions.includeDirs = [...grpcLoaderOptions.includeDirs, ...(includeGrpcPaths !== null && includeGrpcPaths !== void 0 ? includeGrpcPaths : [])];
|
|
71
|
-
(0,
|
|
58
|
+
(0, proto_path_resolver_1.patchProtoPathResolver)(root, grpcLoaderOptions.includeDirs);
|
|
72
59
|
return root;
|
|
73
60
|
}
|
|
61
|
+
exports.createRoot = createRoot;
|
|
74
62
|
function getCredentialsMap(caCertificatePath) {
|
|
75
63
|
let certificate;
|
|
76
64
|
if (caCertificatePath && fs_1.default.existsSync(caCertificatePath)) {
|
|
@@ -82,6 +70,7 @@ function getCredentialsMap(caCertificatePath) {
|
|
|
82
70
|
insecure: grpc.ChannelCredentials.createInsecure(),
|
|
83
71
|
};
|
|
84
72
|
}
|
|
73
|
+
exports.getCredentialsMap = getCredentialsMap;
|
|
85
74
|
function decodeResponse(response, packageRoot, ctx, encodedFields = [], ErrorConstructor, decodeAnyMessageProtoLoaderOptions) {
|
|
86
75
|
const systemFields = ['metadata', 'response', 'error.details'];
|
|
87
76
|
[...systemFields, ...encodedFields].forEach((fieldName) => {
|
|
@@ -89,21 +78,21 @@ function decodeResponse(response, packageRoot, ctx, encodedFields = [], ErrorCon
|
|
|
89
78
|
const parsedFieldName = fieldName.replace(/\.\*$/, '');
|
|
90
79
|
const fieldValue = lodash_1.default.get(response, parsedFieldName);
|
|
91
80
|
if (fieldValue) {
|
|
92
|
-
lodash_1.default.set(response, parsedFieldName, (0,
|
|
81
|
+
lodash_1.default.set(response, parsedFieldName, (0, grpc_1.decodeAnyMessageRecursively)(packageRoot, fieldValue, decodeAnyMessageProtoLoaderOptions));
|
|
93
82
|
}
|
|
94
83
|
}
|
|
95
84
|
catch (error) {
|
|
96
|
-
(0,
|
|
85
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'Message decoding failed', { fieldName });
|
|
97
86
|
}
|
|
98
87
|
});
|
|
99
88
|
}
|
|
100
89
|
function createMetadata({ options, actionConfig, config, params, serviceName, proxyHeadersCaller, ctx, }) {
|
|
101
90
|
var _a;
|
|
102
91
|
const { headers, requestId, authArgs } = actionConfig;
|
|
103
|
-
const proxyHeaders = [...
|
|
92
|
+
const proxyHeaders = [...constants_1.DEFAULT_PROXY_HEADERS];
|
|
104
93
|
let metadata = {
|
|
105
94
|
'x-request-id': requestId,
|
|
106
|
-
'accept-language': headers[
|
|
95
|
+
'accept-language': headers[constants_1.DEFAULT_LANG_HEADER] || constants_1.Lang.Ru,
|
|
107
96
|
};
|
|
108
97
|
if (typeof options.proxyHeaders === 'function') {
|
|
109
98
|
Object.assign(metadata, proxyHeadersCaller(options.proxyHeaders));
|
|
@@ -149,7 +138,7 @@ function createMetadata({ options, actionConfig, config, params, serviceName, pr
|
|
|
149
138
|
return serviceMetadata;
|
|
150
139
|
}
|
|
151
140
|
function createActionEndpoint(endpointData) {
|
|
152
|
-
return (0,
|
|
141
|
+
return (0, common_2.isExtendedActionEndpoint)(endpointData) ? endpointData.path : endpointData;
|
|
153
142
|
}
|
|
154
143
|
const packageObjectsMap = new Map();
|
|
155
144
|
const serviceInstancesMap = {};
|
|
@@ -181,7 +170,7 @@ function clearInstancesCache(service, instancesMap, cachePath, closeTimeout, ctx
|
|
|
181
170
|
function getChannelCredential(config, endpointData, credentials) {
|
|
182
171
|
let endpointInsecure;
|
|
183
172
|
let endpointSecureWithoutRootCert;
|
|
184
|
-
if ((0,
|
|
173
|
+
if ((0, common_2.isExtendedGrpcActionEndpoint)(endpointData)) {
|
|
185
174
|
endpointInsecure = endpointData === null || endpointData === void 0 ? void 0 : endpointData.insecure;
|
|
186
175
|
endpointSecureWithoutRootCert = endpointData === null || endpointData === void 0 ? void 0 : endpointData.secureWithoutRootCert;
|
|
187
176
|
}
|
|
@@ -230,7 +219,7 @@ async function refreshCache(actionEndpoint, config, endpointData, grpcOptions, c
|
|
|
230
219
|
}
|
|
231
220
|
}
|
|
232
221
|
function getServiceInstanceReflectCached(config, endpointData, grpcOptions, credentials) {
|
|
233
|
-
if (config.reflection ===
|
|
222
|
+
if (config.reflection === common_1.GrpcReflection.OnEveryRequest) {
|
|
234
223
|
return getServiceInstanceReflect(config, endpointData, grpcOptions, credentials);
|
|
235
224
|
}
|
|
236
225
|
const actionEndpoint = createActionEndpoint(endpointData);
|
|
@@ -252,24 +241,24 @@ function getServiceInstanceReflectCached(config, endpointData, grpcOptions, cred
|
|
|
252
241
|
}
|
|
253
242
|
async function getServiceInstanceReflect(config, endpointData, grpcOptions, credentials, isRefreshCache) {
|
|
254
243
|
const actionEndpoint = createActionEndpoint(endpointData);
|
|
255
|
-
const endpointInsecure = (0,
|
|
244
|
+
const endpointInsecure = (0, common_2.isExtendedGrpcActionEndpoint)(endpointData)
|
|
256
245
|
? endpointData === null || endpointData === void 0 ? void 0 : endpointData.insecure
|
|
257
246
|
: undefined;
|
|
258
247
|
const isInsecure = config.insecure || endpointInsecure;
|
|
259
248
|
const creds = isInsecure ? credentials.insecure : credentials.secure;
|
|
260
|
-
const endpointGrpcOptions = (0,
|
|
249
|
+
const endpointGrpcOptions = (0, common_2.isExtendedGrpcActionEndpoint)(endpointData)
|
|
261
250
|
? endpointData.grpcOptions || {}
|
|
262
251
|
: {};
|
|
263
|
-
const combinedGrpcOptions = Object.assign(Object.assign(Object.assign({},
|
|
252
|
+
const combinedGrpcOptions = Object.assign(Object.assign(Object.assign({}, constants_1.DEFAULT_GRPC_OPTIONS), grpcOptions), endpointGrpcOptions);
|
|
264
253
|
let loadedRoot;
|
|
265
|
-
if (config.reflection ===
|
|
266
|
-
loadedRoot = await (0,
|
|
254
|
+
if (config.reflection === common_1.GrpcReflection.OnEveryRequest || isRefreshCache) {
|
|
255
|
+
loadedRoot = await (0, grpc_reflection_1.getReflectionRoot)(actionEndpoint, config.protoKey, creds, combinedGrpcOptions, isRefreshCache);
|
|
267
256
|
}
|
|
268
257
|
else {
|
|
269
|
-
loadedRoot = await (0,
|
|
258
|
+
loadedRoot = await (0, grpc_reflection_1.getCachedReflectionRoot)(actionEndpoint, config.protoKey, creds, combinedGrpcOptions);
|
|
270
259
|
}
|
|
271
260
|
const descriptor = loadedRoot.toDescriptor('proto3');
|
|
272
|
-
const definition = protoLoader.loadFileDescriptorSetFromObject(descriptor,
|
|
261
|
+
const definition = protoLoader.loadFileDescriptorSetFromObject(descriptor, constants_1.DEFAULT_PROTO_LOADER_OPTIONS);
|
|
273
262
|
const packageObject = grpc.loadPackageDefinition(definition);
|
|
274
263
|
const Service = lodash_1.default.get(packageObject, config.protoKey);
|
|
275
264
|
const serviceInstance = new Service(actionEndpoint, creds, combinedGrpcOptions);
|
|
@@ -303,10 +292,10 @@ async function getServiceInstance(root, config, endpointData, grpcOptions, crede
|
|
|
303
292
|
const packageObject = loadAndCachePackageObject(root, config.protoPath);
|
|
304
293
|
const Service = lodash_1.default.get(packageObject, config.protoKey);
|
|
305
294
|
const creds = getChannelCredential(config, endpointData, credentials);
|
|
306
|
-
const endpointGrpcOptions = (0,
|
|
295
|
+
const endpointGrpcOptions = (0, common_2.isExtendedGrpcActionEndpoint)(endpointData)
|
|
307
296
|
? endpointData.grpcOptions || {}
|
|
308
297
|
: {};
|
|
309
|
-
serviceInstance = new Service(actionEndpoint, creds, Object.assign(Object.assign(Object.assign({},
|
|
298
|
+
serviceInstance = new Service(actionEndpoint, creds, Object.assign(Object.assign(Object.assign({}, constants_1.DEFAULT_GRPC_OPTIONS), grpcOptions), endpointGrpcOptions));
|
|
310
299
|
// Save pointer to service in cache
|
|
311
300
|
lodash_1.default.set(serviceInstancesMap, cacheKey, serviceInstance);
|
|
312
301
|
}
|
|
@@ -333,11 +322,17 @@ async function getResponseData({ config, response, ctx, packageRoot, args, Error
|
|
|
333
322
|
ctx.log('Transformed response data');
|
|
334
323
|
}
|
|
335
324
|
catch (error) {
|
|
336
|
-
(0,
|
|
325
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'Transform response data failed');
|
|
337
326
|
}
|
|
338
327
|
}
|
|
339
328
|
return responseData;
|
|
340
329
|
}
|
|
330
|
+
// Function to generate fresh serviceOptions with updated deadline for each attempt
|
|
331
|
+
function createServiceOptions(timeout) {
|
|
332
|
+
return {
|
|
333
|
+
deadline: Date.now() + timeout,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
341
336
|
function createGrpcAction({ root, credentials }, endpoints, config, serviceKey, actionName, options, ErrorConstructor) {
|
|
342
337
|
const serviceName = (options === null || options === void 0 ? void 0 : options.serviceName) || serviceKey;
|
|
343
338
|
let getService;
|
|
@@ -373,8 +368,8 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
373
368
|
if (endpointData) {
|
|
374
369
|
const actionEndpoint = createActionEndpoint(endpointData);
|
|
375
370
|
if ('reflection' in config &&
|
|
376
|
-
(config.reflection ===
|
|
377
|
-
config.reflection ===
|
|
371
|
+
(config.reflection === common_1.GrpcReflection.OnEveryRequest ||
|
|
372
|
+
config.reflection === common_1.GrpcReflection.OnFirstRequest)) {
|
|
378
373
|
getService = () => getServiceInstanceReflectCached(config, endpointData, grpcOptions, credentials);
|
|
379
374
|
recreateService = (service, closeTimeout, ctx) => {
|
|
380
375
|
const cachePath = [config.protoKey, actionEndpoint];
|
|
@@ -398,7 +393,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
398
393
|
var _a;
|
|
399
394
|
const { args, requestId, headers, ctx: parentCtx, userId, abortSignal } = actionConfig;
|
|
400
395
|
const { action } = config;
|
|
401
|
-
const lang = headers[
|
|
396
|
+
const lang = headers[constants_1.DEFAULT_LANG_HEADER] || constants_1.Lang.Ru; // header might be empty string
|
|
402
397
|
const ctx = parentCtx.create(`Gateway ${serviceName} ${actionName} [grpc]`, {
|
|
403
398
|
tags: {
|
|
404
399
|
action: actionName,
|
|
@@ -423,7 +418,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
423
418
|
'x-api-request-protokey': config.protoKey,
|
|
424
419
|
'x-api-request-lang': lang,
|
|
425
420
|
'x-request-id': requestId,
|
|
426
|
-
'x-gateway-version':
|
|
421
|
+
'x-gateway-version': constants_1.VERSION,
|
|
427
422
|
};
|
|
428
423
|
const protopath = 'protoPath' in config ? config.protoPath : undefined;
|
|
429
424
|
if (protopath) {
|
|
@@ -432,7 +427,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
432
427
|
let proxyHeadersExtra;
|
|
433
428
|
const proxyHeadersCaller = (proxyHeadersFunc) => {
|
|
434
429
|
if (proxyHeadersExtra === undefined) {
|
|
435
|
-
proxyHeadersExtra = (0,
|
|
430
|
+
proxyHeadersExtra = (0, common_2.getProxyHeadersArgs)(serviceName, actionName, config);
|
|
436
431
|
}
|
|
437
432
|
return proxyHeadersFunc(Object.assign({}, headers), 'rest', proxyHeadersExtra);
|
|
438
433
|
};
|
|
@@ -446,10 +441,10 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
446
441
|
}
|
|
447
442
|
}
|
|
448
443
|
}
|
|
449
|
-
ctx.log('Initiating request', { debugHeaders: (0,
|
|
444
|
+
ctx.log('Initiating request', { debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders) });
|
|
450
445
|
const sendStats = (status, data) => {
|
|
451
446
|
if (options === null || options === void 0 ? void 0 : options.sendStats) {
|
|
452
|
-
options.sendStats(Object.assign(Object.assign({}, data), { restStatus: status }), (0,
|
|
447
|
+
options.sendStats(Object.assign(Object.assign({}, data), { restStatus: status }), (0, redact_sensitive_headers_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders) });
|
|
453
448
|
}
|
|
454
449
|
else {
|
|
455
450
|
ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus: status }));
|
|
@@ -460,7 +455,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
460
455
|
const restStatus = lodash_1.default.get(grpcError.getGatewayError(), 'status', 500);
|
|
461
456
|
sendStats(restStatus, Object.assign(Object.assign({}, requestData), { responseSize: (_a = grpcError.getRawError()) === null || _a === void 0 ? void 0 : _a.metadata, grpcStatus: grpcError.getGatewayError().code }));
|
|
462
457
|
ctx.logError('Request failed', ErrorConstructor.wrap(grpcError.getAppError(ErrorConstructor)), Object.assign({ serviceName,
|
|
463
|
-
actionName, debugHeaders: (0,
|
|
458
|
+
actionName, debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders) }, grpcError.getGatewayError()));
|
|
464
459
|
ctx.end();
|
|
465
460
|
}
|
|
466
461
|
let params;
|
|
@@ -469,7 +464,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
469
464
|
params = await config.params(args, headers, { ctx });
|
|
470
465
|
}
|
|
471
466
|
catch (error) {
|
|
472
|
-
(0,
|
|
467
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'Getting config params failed');
|
|
473
468
|
}
|
|
474
469
|
}
|
|
475
470
|
let service;
|
|
@@ -477,7 +472,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
477
472
|
service = await getService(args);
|
|
478
473
|
}
|
|
479
474
|
catch (error) {
|
|
480
|
-
(0,
|
|
475
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'getService failed');
|
|
481
476
|
throw error;
|
|
482
477
|
}
|
|
483
478
|
let stopListeningForAbort = null;
|
|
@@ -493,7 +488,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
493
488
|
}
|
|
494
489
|
if (!endpointData) {
|
|
495
490
|
const errorText = `Gateway config error. Endpoint has been not found in service "${serviceKey}"`;
|
|
496
|
-
throw new
|
|
491
|
+
throw new parse_error_1.GrpcError(errorText, {
|
|
497
492
|
status: 400,
|
|
498
493
|
code: 'ENDPOINT_NOT_FOUND',
|
|
499
494
|
message: errorText,
|
|
@@ -502,9 +497,9 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
502
497
|
const actionEndpoint = getActionEndpoint(args);
|
|
503
498
|
debugHeaders['x-api-request-endpoint'] = actionEndpoint;
|
|
504
499
|
const validationSchema = config.validationSchema || options.validationSchema;
|
|
505
|
-
const invalidParams = validationSchema ? (0,
|
|
500
|
+
const invalidParams = validationSchema ? (0, validate_1.validateArgs)(args, validationSchema) : false;
|
|
506
501
|
if (invalidParams) {
|
|
507
|
-
throw new
|
|
502
|
+
throw new parse_error_1.GrpcError('Invalid params', {
|
|
508
503
|
status: 400,
|
|
509
504
|
code: 'INVALID_PARAMS',
|
|
510
505
|
message: 'Validation failed',
|
|
@@ -514,10 +509,8 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
514
509
|
},
|
|
515
510
|
});
|
|
516
511
|
}
|
|
517
|
-
const timeout = (_c = (_b = (_a = actionConfig === null || actionConfig === void 0 ? void 0 : actionConfig.timeout) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.timeout) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.timeout) !== null && _c !== void 0 ? _c :
|
|
518
|
-
|
|
519
|
-
deadline: Date.now() + timeout,
|
|
520
|
-
};
|
|
512
|
+
const timeout = (_c = (_b = (_a = actionConfig === null || actionConfig === void 0 ? void 0 : actionConfig.timeout) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.timeout) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.timeout) !== null && _c !== void 0 ? _c : constants_1.DEFAULT_TIMEOUT;
|
|
513
|
+
let serviceOptions = createServiceOptions(timeout);
|
|
521
514
|
const { body = null } = params !== null && params !== void 0 ? params : { body: args };
|
|
522
515
|
const serviceMetadata = createMetadata({
|
|
523
516
|
options,
|
|
@@ -529,7 +522,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
529
522
|
ctx,
|
|
530
523
|
});
|
|
531
524
|
if (!service[action]) {
|
|
532
|
-
reject(new
|
|
525
|
+
reject(new parse_error_1.GrpcError('Not found action', {
|
|
533
526
|
status: 400,
|
|
534
527
|
code: 'GRPC_ACTION_NOT_FOUND',
|
|
535
528
|
message: `Not found action ${action} in ${serviceKey}`,
|
|
@@ -539,11 +532,11 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
539
532
|
switch (config.type) {
|
|
540
533
|
case 'serverStream': {
|
|
541
534
|
ctx.log('Creating serverStream request', {
|
|
542
|
-
debugHeaders: (0,
|
|
535
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
543
536
|
});
|
|
544
537
|
const actionCall = service[action].bind(service);
|
|
545
538
|
const stream = actionCall(body, serviceMetadata, serviceOptions);
|
|
546
|
-
stopListeningForAbort = (0,
|
|
539
|
+
stopListeningForAbort = (0, grpc_1.listenForAbort)({
|
|
547
540
|
signal: abortSignal,
|
|
548
541
|
config,
|
|
549
542
|
call: stream,
|
|
@@ -551,9 +544,9 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
551
544
|
});
|
|
552
545
|
stream.on('error', (error) => {
|
|
553
546
|
ctx.log('ServerStream error', {
|
|
554
|
-
debugHeaders: (0,
|
|
547
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
555
548
|
});
|
|
556
|
-
processError(new
|
|
549
|
+
processError(new parse_error_1.GrpcError('ClientReadableStream error', (0, parse_error_1.parseGrpcError)(error, root, lang, config.decodeAnyMessageProtoLoaderOptions), error));
|
|
557
550
|
});
|
|
558
551
|
stream.on('status', (status) => {
|
|
559
552
|
ctx.log('ServerStream status changed', status);
|
|
@@ -561,7 +554,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
561
554
|
stream.on('end', () => {
|
|
562
555
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
563
556
|
ctx.log('ServerStream request completed', {
|
|
564
|
-
debugHeaders: (0,
|
|
557
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
565
558
|
});
|
|
566
559
|
ctx.end();
|
|
567
560
|
});
|
|
@@ -570,10 +563,10 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
570
563
|
}
|
|
571
564
|
case 'clientStream': {
|
|
572
565
|
ctx.log('Creating clientStream request', {
|
|
573
|
-
debugHeaders: (0,
|
|
566
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
574
567
|
});
|
|
575
568
|
if (!actionConfig.callback) {
|
|
576
|
-
throw new
|
|
569
|
+
throw new parse_error_1.GrpcError('Invalid action type', {
|
|
577
570
|
status: 400,
|
|
578
571
|
code: 'ACTION_CALLBACK_REQUIRED',
|
|
579
572
|
message: `Client stream actions require callback function`,
|
|
@@ -581,7 +574,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
581
574
|
}
|
|
582
575
|
const actionCall = service[action].bind(service);
|
|
583
576
|
const stream = actionCall(serviceMetadata, serviceOptions, actionConfig.callback);
|
|
584
|
-
stopListeningForAbort = (0,
|
|
577
|
+
stopListeningForAbort = (0, grpc_1.listenForAbort)({
|
|
585
578
|
signal: abortSignal,
|
|
586
579
|
config,
|
|
587
580
|
call: stream,
|
|
@@ -595,11 +588,11 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
595
588
|
}
|
|
596
589
|
case 'bidi': {
|
|
597
590
|
ctx.log('Creating serverStream request', {
|
|
598
|
-
debugHeaders: (0,
|
|
591
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
599
592
|
});
|
|
600
593
|
const actionCall = service[action].bind(service);
|
|
601
594
|
const stream = actionCall(serviceMetadata, serviceOptions);
|
|
602
|
-
stopListeningForAbort = (0,
|
|
595
|
+
stopListeningForAbort = (0, grpc_1.listenForAbort)({
|
|
603
596
|
signal: abortSignal,
|
|
604
597
|
config,
|
|
605
598
|
call: stream,
|
|
@@ -607,9 +600,9 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
607
600
|
});
|
|
608
601
|
stream.on('error', (error) => {
|
|
609
602
|
ctx.log('BidiStream error', {
|
|
610
|
-
debugHeaders: (0,
|
|
603
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
611
604
|
});
|
|
612
|
-
processError(new
|
|
605
|
+
processError(new parse_error_1.GrpcError('BidiStream error', (0, parse_error_1.parseGrpcError)(error, root, lang, config.decodeAnyMessageProtoLoaderOptions), error));
|
|
613
606
|
});
|
|
614
607
|
stream.on('status', (status) => {
|
|
615
608
|
ctx.log('BidiStream status changed', status);
|
|
@@ -617,7 +610,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
617
610
|
stream.on('end', () => {
|
|
618
611
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
619
612
|
ctx.log('BidiStream request completed', {
|
|
620
|
-
debugHeaders: (0,
|
|
613
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
621
614
|
});
|
|
622
615
|
ctx.end();
|
|
623
616
|
});
|
|
@@ -629,7 +622,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
629
622
|
}
|
|
630
623
|
default: {
|
|
631
624
|
ctx.log('Starting unary request', {
|
|
632
|
-
debugHeaders: (0,
|
|
625
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
633
626
|
});
|
|
634
627
|
let retries = (_d = config.retries) !== null && _d !== void 0 ? _d : 0;
|
|
635
628
|
let actionCall = service[action].bind(service);
|
|
@@ -641,37 +634,39 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
641
634
|
requestData.requestTime = endRequestTime - startRequestTime;
|
|
642
635
|
const shouldRecreateService = error &&
|
|
643
636
|
options.grpcRecreateService &&
|
|
644
|
-
(0,
|
|
637
|
+
(0, grpc_1.isRecreateServiceError)(error);
|
|
645
638
|
const shouldRetry = error &&
|
|
646
639
|
retries &&
|
|
647
|
-
((_b = (_a = options.grpcRetryCondition) === null || _a === void 0 ? void 0 : _a.call(options, error)) !== null && _b !== void 0 ? _b : (0,
|
|
640
|
+
((_b = (_a = options.grpcRetryCondition) === null || _a === void 0 ? void 0 : _a.call(options, error)) !== null && _b !== void 0 ? _b : (0, grpc_1.isRetryableGrpcError)(error));
|
|
648
641
|
if (shouldRecreateService) {
|
|
649
642
|
ctx.log(`Service client for ${config.protoKey} is going to be re-created`);
|
|
650
643
|
recreateService(service, timeout * 1.5, ctx, args);
|
|
651
644
|
}
|
|
652
645
|
if (shouldRetry) {
|
|
653
|
-
(0,
|
|
646
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, `Request failed, retrying ${retries--} more times`, {
|
|
654
647
|
serviceName,
|
|
655
648
|
actionName,
|
|
656
|
-
debugHeaders: (0,
|
|
649
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
657
650
|
});
|
|
658
651
|
// Update pointer to re-created client in local service variable
|
|
659
652
|
try {
|
|
660
653
|
service = await getService(args);
|
|
661
654
|
}
|
|
662
655
|
catch (error) {
|
|
663
|
-
(0,
|
|
656
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'getService failed');
|
|
664
657
|
throw error;
|
|
665
658
|
}
|
|
666
659
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
667
660
|
// Update service
|
|
668
661
|
actionCall = service[action].bind(service);
|
|
662
|
+
// Update serviceOptions with a fresh deadline for the retry
|
|
663
|
+
serviceOptions = createServiceOptions(timeout);
|
|
669
664
|
callAction();
|
|
670
665
|
return;
|
|
671
666
|
}
|
|
672
667
|
if (error) {
|
|
673
668
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
674
|
-
reject(new
|
|
669
|
+
reject(new parse_error_1.GrpcError('gRPC request error', (0, parse_error_1.parseGrpcError)(error, root, lang, config.decodeAnyMessageProtoLoaderOptions), error));
|
|
675
670
|
return;
|
|
676
671
|
}
|
|
677
672
|
const responseData = await getResponseData({
|
|
@@ -686,7 +681,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
686
681
|
const responseHeaders = {};
|
|
687
682
|
if (config.proxyResponseHeaders) {
|
|
688
683
|
const proxyResponseHeaders = [];
|
|
689
|
-
const headersFromMetadata = (0,
|
|
684
|
+
const headersFromMetadata = (0, common_2.getHeadersFromMetadata)(trailingMetadata);
|
|
690
685
|
if (typeof config.proxyResponseHeaders === 'function') {
|
|
691
686
|
Object.assign(responseHeaders, config.proxyResponseHeaders(headersFromMetadata, 'grpc'));
|
|
692
687
|
}
|
|
@@ -700,10 +695,10 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
700
695
|
}
|
|
701
696
|
}
|
|
702
697
|
}
|
|
703
|
-
Object.assign(debugHeaders, (0,
|
|
698
|
+
Object.assign(debugHeaders, (0, common_2.getHeadersFromMetadata)(trailingMetadata, 'x-metadata-'));
|
|
704
699
|
sendStats(200, Object.assign(Object.assign({}, requestData), { responseSize: (0, object_sizeof_1.default)(response), grpcStatus: 0 }));
|
|
705
700
|
ctx.log('Request completed', {
|
|
706
|
-
debugHeaders: (0,
|
|
701
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
707
702
|
});
|
|
708
703
|
ctx.end();
|
|
709
704
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
@@ -712,7 +707,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
712
707
|
call.on('status', (status) => {
|
|
713
708
|
trailingMetadata = status.metadata.toJSON();
|
|
714
709
|
});
|
|
715
|
-
stopListeningForAbort = (0,
|
|
710
|
+
stopListeningForAbort = (0, grpc_1.listenForAbort)({
|
|
716
711
|
signal: abortSignal,
|
|
717
712
|
config,
|
|
718
713
|
call,
|
|
@@ -723,10 +718,11 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
723
718
|
}
|
|
724
719
|
}
|
|
725
720
|
}).catch((error) => {
|
|
726
|
-
const grpcError = (0,
|
|
721
|
+
const grpcError = (0, parse_error_1.isGrpcError)(error) ? error : (0, parse_error_1.grpcErrorFactory)(error);
|
|
727
722
|
processError(grpcError);
|
|
728
723
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
729
724
|
return Promise.reject({ error: grpcError.getGatewayError(), debugHeaders });
|
|
730
725
|
});
|
|
731
726
|
};
|
|
732
727
|
}
|
|
728
|
+
exports.default = createGrpcAction;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ApiActionConfig, ApiByScope, ApiServiceMixedActionConfig, GatewayConfig, GatewayRequest, GatewayResponse, SchemasByScope } from '../models/common
|
|
2
|
-
import { GatewayContext } from '../models/context
|
|
3
|
-
import { AppErrorConstructor } from '../models/error
|
|
4
|
-
import type { GrpcContext } from './grpc
|
|
1
|
+
import { ApiActionConfig, ApiByScope, ApiServiceMixedActionConfig, GatewayConfig, GatewayRequest, GatewayResponse, SchemasByScope } from '../models/common';
|
|
2
|
+
import { GatewayContext } from '../models/context';
|
|
3
|
+
import { AppErrorConstructor } from '../models/error';
|
|
4
|
+
import type { GrpcContext } from './grpc';
|
|
5
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
6
|
config: GatewayConfig<Context, Req, Res>;
|
|
7
7
|
grpcContext: GrpcContext;
|
|
@@ -11,11 +11,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.createMixedAction =
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
14
|
+
exports.createMixedAction = void 0;
|
|
15
|
+
const constants_1 = require("../constants");
|
|
16
|
+
const common_1 = require("../utils/common");
|
|
17
|
+
const create_context_api_1 = require("../utils/create-context-api");
|
|
18
|
+
const parse_error_1 = require("../utils/parse-error");
|
|
19
19
|
function createMixedAction(config, api, serviceName, actionName, extra, ErrorConstructor) {
|
|
20
20
|
return async (actionConfig) => {
|
|
21
21
|
const { args } = actionConfig, context = __rest(actionConfig, ["args"]);
|
|
@@ -26,9 +26,9 @@ function createMixedAction(config, api, serviceName, actionName, extra, ErrorCon
|
|
|
26
26
|
type: 'mixed',
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
|
-
const contextApi = (0,
|
|
29
|
+
const contextApi = (0, create_context_api_1.generateContextApi)(api, Object.assign(Object.assign({}, context), { ctx }));
|
|
30
30
|
try {
|
|
31
|
-
const responseData = await config(contextApi, args, Object.assign(Object.assign({ headers: actionConfig.headers, lang: actionConfig.headers[
|
|
31
|
+
const responseData = await config(contextApi, args, Object.assign(Object.assign({ headers: actionConfig.headers, lang: actionConfig.headers[constants_1.DEFAULT_LANG_HEADER] || constants_1.Lang.Ru, ctx }, extra), { abortSignal: actionConfig.abortSignal }));
|
|
32
32
|
ctx.log('Request completed');
|
|
33
33
|
return {
|
|
34
34
|
responseData,
|
|
@@ -37,15 +37,15 @@ function createMixedAction(config, api, serviceName, actionName, extra, ErrorCon
|
|
|
37
37
|
}
|
|
38
38
|
catch (e) {
|
|
39
39
|
if (e instanceof Object && 'error' in e) {
|
|
40
|
-
(0,
|
|
40
|
+
(0, common_1.handleError)(ErrorConstructor, e, ctx, 'Request failed', {
|
|
41
41
|
actionName,
|
|
42
42
|
serviceName,
|
|
43
43
|
});
|
|
44
44
|
throw e;
|
|
45
45
|
}
|
|
46
46
|
if (e instanceof Error) {
|
|
47
|
-
const parsedError = (0,
|
|
48
|
-
(0,
|
|
47
|
+
const parsedError = (0, parse_error_1.parseMixedError)(e);
|
|
48
|
+
(0, common_1.handleError)(ErrorConstructor, e, ctx, 'Request failed', {
|
|
49
49
|
actionName,
|
|
50
50
|
serviceName,
|
|
51
51
|
});
|
|
@@ -53,7 +53,7 @@ function createMixedAction(config, api, serviceName, actionName, extra, ErrorCon
|
|
|
53
53
|
error: parsedError,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
(0,
|
|
56
|
+
(0, common_1.handleError)(ErrorConstructor, e, ctx, 'Request failed');
|
|
57
57
|
throw {
|
|
58
58
|
error: e,
|
|
59
59
|
};
|
|
@@ -63,3 +63,4 @@ function createMixedAction(config, api, serviceName, actionName, extra, ErrorCon
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
+
exports.createMixedAction = createMixedAction;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ApiActionConfig, ApiServiceRestActionConfig, EndpointsConfig, GatewayApiOptions, Headers } from '../models/common
|
|
2
|
-
import { GatewayContext } from '../models/context
|
|
3
|
-
import { AppErrorConstructor } from '../models/error
|
|
4
|
-
export
|
|
1
|
+
import { ApiActionConfig, ApiServiceRestActionConfig, EndpointsConfig, GatewayApiOptions, Headers } from '../models/common';
|
|
2
|
+
import { GatewayContext } from '../models/context';
|
|
3
|
+
import { AppErrorConstructor } from '../models/error';
|
|
4
|
+
export default function createRestAction<Context extends GatewayContext>(endpoints: EndpointsConfig | undefined, config: ApiServiceRestActionConfig<Context, any, any>, serviceKey: string, actionName: string, options: GatewayApiOptions<Context>, ErrorConstructor: AppErrorConstructor): (actionConfig: ApiActionConfig<Context, any>) => Promise<{
|
|
5
5
|
responseData: unknown;
|
|
6
|
-
responseHeaders?: Headers;
|
|
6
|
+
responseHeaders?: Headers | undefined;
|
|
7
7
|
debugHeaders: Headers;
|
|
8
8
|
}>;
|