@gravity-ui/gateway 4.7.1-alpha.0 → 4.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{dist/esm → build}/components/grpc.d.ts +5 -5
- package/{dist/commonjs → build}/components/grpc.js +84 -94
- 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,7 +322,7 @@ 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;
|
|
@@ -373,8 +362,8 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
373
362
|
if (endpointData) {
|
|
374
363
|
const actionEndpoint = createActionEndpoint(endpointData);
|
|
375
364
|
if ('reflection' in config &&
|
|
376
|
-
(config.reflection ===
|
|
377
|
-
config.reflection ===
|
|
365
|
+
(config.reflection === common_1.GrpcReflection.OnEveryRequest ||
|
|
366
|
+
config.reflection === common_1.GrpcReflection.OnFirstRequest)) {
|
|
378
367
|
getService = () => getServiceInstanceReflectCached(config, endpointData, grpcOptions, credentials);
|
|
379
368
|
recreateService = (service, closeTimeout, ctx) => {
|
|
380
369
|
const cachePath = [config.protoKey, actionEndpoint];
|
|
@@ -398,7 +387,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
398
387
|
var _a;
|
|
399
388
|
const { args, requestId, headers, ctx: parentCtx, userId, abortSignal } = actionConfig;
|
|
400
389
|
const { action } = config;
|
|
401
|
-
const lang = headers[
|
|
390
|
+
const lang = headers[constants_1.DEFAULT_LANG_HEADER] || constants_1.Lang.Ru; // header might be empty string
|
|
402
391
|
const ctx = parentCtx.create(`Gateway ${serviceName} ${actionName} [grpc]`, {
|
|
403
392
|
tags: {
|
|
404
393
|
action: actionName,
|
|
@@ -423,7 +412,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
423
412
|
'x-api-request-protokey': config.protoKey,
|
|
424
413
|
'x-api-request-lang': lang,
|
|
425
414
|
'x-request-id': requestId,
|
|
426
|
-
'x-gateway-version':
|
|
415
|
+
'x-gateway-version': constants_1.VERSION,
|
|
427
416
|
};
|
|
428
417
|
const protopath = 'protoPath' in config ? config.protoPath : undefined;
|
|
429
418
|
if (protopath) {
|
|
@@ -432,7 +421,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
432
421
|
let proxyHeadersExtra;
|
|
433
422
|
const proxyHeadersCaller = (proxyHeadersFunc) => {
|
|
434
423
|
if (proxyHeadersExtra === undefined) {
|
|
435
|
-
proxyHeadersExtra = (0,
|
|
424
|
+
proxyHeadersExtra = (0, common_2.getProxyHeadersArgs)(serviceName, actionName, config);
|
|
436
425
|
}
|
|
437
426
|
return proxyHeadersFunc(Object.assign({}, headers), 'rest', proxyHeadersExtra);
|
|
438
427
|
};
|
|
@@ -446,10 +435,10 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
446
435
|
}
|
|
447
436
|
}
|
|
448
437
|
}
|
|
449
|
-
ctx.log('Initiating request', { debugHeaders: (0,
|
|
438
|
+
ctx.log('Initiating request', { debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders) });
|
|
450
439
|
const sendStats = (status, data) => {
|
|
451
440
|
if (options === null || options === void 0 ? void 0 : options.sendStats) {
|
|
452
|
-
options.sendStats(Object.assign(Object.assign({}, data), { restStatus: status }), (0,
|
|
441
|
+
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
442
|
}
|
|
454
443
|
else {
|
|
455
444
|
ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus: status }));
|
|
@@ -460,7 +449,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
460
449
|
const restStatus = lodash_1.default.get(grpcError.getGatewayError(), 'status', 500);
|
|
461
450
|
sendStats(restStatus, Object.assign(Object.assign({}, requestData), { responseSize: (_a = grpcError.getRawError()) === null || _a === void 0 ? void 0 : _a.metadata, grpcStatus: grpcError.getGatewayError().code }));
|
|
462
451
|
ctx.logError('Request failed', ErrorConstructor.wrap(grpcError.getAppError(ErrorConstructor)), Object.assign({ serviceName,
|
|
463
|
-
actionName, debugHeaders: (0,
|
|
452
|
+
actionName, debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders) }, grpcError.getGatewayError()));
|
|
464
453
|
ctx.end();
|
|
465
454
|
}
|
|
466
455
|
let params;
|
|
@@ -469,7 +458,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
469
458
|
params = await config.params(args, headers, { ctx });
|
|
470
459
|
}
|
|
471
460
|
catch (error) {
|
|
472
|
-
(0,
|
|
461
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'Getting config params failed');
|
|
473
462
|
}
|
|
474
463
|
}
|
|
475
464
|
let service;
|
|
@@ -477,7 +466,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
477
466
|
service = await getService(args);
|
|
478
467
|
}
|
|
479
468
|
catch (error) {
|
|
480
|
-
(0,
|
|
469
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'getService failed');
|
|
481
470
|
throw error;
|
|
482
471
|
}
|
|
483
472
|
let stopListeningForAbort = null;
|
|
@@ -493,7 +482,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
493
482
|
}
|
|
494
483
|
if (!endpointData) {
|
|
495
484
|
const errorText = `Gateway config error. Endpoint has been not found in service "${serviceKey}"`;
|
|
496
|
-
throw new
|
|
485
|
+
throw new parse_error_1.GrpcError(errorText, {
|
|
497
486
|
status: 400,
|
|
498
487
|
code: 'ENDPOINT_NOT_FOUND',
|
|
499
488
|
message: errorText,
|
|
@@ -502,9 +491,9 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
502
491
|
const actionEndpoint = getActionEndpoint(args);
|
|
503
492
|
debugHeaders['x-api-request-endpoint'] = actionEndpoint;
|
|
504
493
|
const validationSchema = config.validationSchema || options.validationSchema;
|
|
505
|
-
const invalidParams = validationSchema ? (0,
|
|
494
|
+
const invalidParams = validationSchema ? (0, validate_1.validateArgs)(args, validationSchema) : false;
|
|
506
495
|
if (invalidParams) {
|
|
507
|
-
throw new
|
|
496
|
+
throw new parse_error_1.GrpcError('Invalid params', {
|
|
508
497
|
status: 400,
|
|
509
498
|
code: 'INVALID_PARAMS',
|
|
510
499
|
message: 'Validation failed',
|
|
@@ -514,7 +503,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
514
503
|
},
|
|
515
504
|
});
|
|
516
505
|
}
|
|
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 :
|
|
506
|
+
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;
|
|
518
507
|
const serviceOptions = {
|
|
519
508
|
deadline: Date.now() + timeout,
|
|
520
509
|
};
|
|
@@ -529,7 +518,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
529
518
|
ctx,
|
|
530
519
|
});
|
|
531
520
|
if (!service[action]) {
|
|
532
|
-
reject(new
|
|
521
|
+
reject(new parse_error_1.GrpcError('Not found action', {
|
|
533
522
|
status: 400,
|
|
534
523
|
code: 'GRPC_ACTION_NOT_FOUND',
|
|
535
524
|
message: `Not found action ${action} in ${serviceKey}`,
|
|
@@ -539,11 +528,11 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
539
528
|
switch (config.type) {
|
|
540
529
|
case 'serverStream': {
|
|
541
530
|
ctx.log('Creating serverStream request', {
|
|
542
|
-
debugHeaders: (0,
|
|
531
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
543
532
|
});
|
|
544
533
|
const actionCall = service[action].bind(service);
|
|
545
534
|
const stream = actionCall(body, serviceMetadata, serviceOptions);
|
|
546
|
-
stopListeningForAbort = (0,
|
|
535
|
+
stopListeningForAbort = (0, grpc_1.listenForAbort)({
|
|
547
536
|
signal: abortSignal,
|
|
548
537
|
config,
|
|
549
538
|
call: stream,
|
|
@@ -551,9 +540,9 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
551
540
|
});
|
|
552
541
|
stream.on('error', (error) => {
|
|
553
542
|
ctx.log('ServerStream error', {
|
|
554
|
-
debugHeaders: (0,
|
|
543
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
555
544
|
});
|
|
556
|
-
processError(new
|
|
545
|
+
processError(new parse_error_1.GrpcError('ClientReadableStream error', (0, parse_error_1.parseGrpcError)(error, root, lang, config.decodeAnyMessageProtoLoaderOptions), error));
|
|
557
546
|
});
|
|
558
547
|
stream.on('status', (status) => {
|
|
559
548
|
ctx.log('ServerStream status changed', status);
|
|
@@ -561,7 +550,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
561
550
|
stream.on('end', () => {
|
|
562
551
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
563
552
|
ctx.log('ServerStream request completed', {
|
|
564
|
-
debugHeaders: (0,
|
|
553
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
565
554
|
});
|
|
566
555
|
ctx.end();
|
|
567
556
|
});
|
|
@@ -570,10 +559,10 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
570
559
|
}
|
|
571
560
|
case 'clientStream': {
|
|
572
561
|
ctx.log('Creating clientStream request', {
|
|
573
|
-
debugHeaders: (0,
|
|
562
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
574
563
|
});
|
|
575
564
|
if (!actionConfig.callback) {
|
|
576
|
-
throw new
|
|
565
|
+
throw new parse_error_1.GrpcError('Invalid action type', {
|
|
577
566
|
status: 400,
|
|
578
567
|
code: 'ACTION_CALLBACK_REQUIRED',
|
|
579
568
|
message: `Client stream actions require callback function`,
|
|
@@ -581,7 +570,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
581
570
|
}
|
|
582
571
|
const actionCall = service[action].bind(service);
|
|
583
572
|
const stream = actionCall(serviceMetadata, serviceOptions, actionConfig.callback);
|
|
584
|
-
stopListeningForAbort = (0,
|
|
573
|
+
stopListeningForAbort = (0, grpc_1.listenForAbort)({
|
|
585
574
|
signal: abortSignal,
|
|
586
575
|
config,
|
|
587
576
|
call: stream,
|
|
@@ -595,11 +584,11 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
595
584
|
}
|
|
596
585
|
case 'bidi': {
|
|
597
586
|
ctx.log('Creating serverStream request', {
|
|
598
|
-
debugHeaders: (0,
|
|
587
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
599
588
|
});
|
|
600
589
|
const actionCall = service[action].bind(service);
|
|
601
590
|
const stream = actionCall(serviceMetadata, serviceOptions);
|
|
602
|
-
stopListeningForAbort = (0,
|
|
591
|
+
stopListeningForAbort = (0, grpc_1.listenForAbort)({
|
|
603
592
|
signal: abortSignal,
|
|
604
593
|
config,
|
|
605
594
|
call: stream,
|
|
@@ -607,9 +596,9 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
607
596
|
});
|
|
608
597
|
stream.on('error', (error) => {
|
|
609
598
|
ctx.log('BidiStream error', {
|
|
610
|
-
debugHeaders: (0,
|
|
599
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
611
600
|
});
|
|
612
|
-
processError(new
|
|
601
|
+
processError(new parse_error_1.GrpcError('BidiStream error', (0, parse_error_1.parseGrpcError)(error, root, lang, config.decodeAnyMessageProtoLoaderOptions), error));
|
|
613
602
|
});
|
|
614
603
|
stream.on('status', (status) => {
|
|
615
604
|
ctx.log('BidiStream status changed', status);
|
|
@@ -617,7 +606,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
617
606
|
stream.on('end', () => {
|
|
618
607
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
619
608
|
ctx.log('BidiStream request completed', {
|
|
620
|
-
debugHeaders: (0,
|
|
609
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
621
610
|
});
|
|
622
611
|
ctx.end();
|
|
623
612
|
});
|
|
@@ -629,7 +618,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
629
618
|
}
|
|
630
619
|
default: {
|
|
631
620
|
ctx.log('Starting unary request', {
|
|
632
|
-
debugHeaders: (0,
|
|
621
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
633
622
|
});
|
|
634
623
|
let retries = (_d = config.retries) !== null && _d !== void 0 ? _d : 0;
|
|
635
624
|
let actionCall = service[action].bind(service);
|
|
@@ -641,26 +630,26 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
641
630
|
requestData.requestTime = endRequestTime - startRequestTime;
|
|
642
631
|
const shouldRecreateService = error &&
|
|
643
632
|
options.grpcRecreateService &&
|
|
644
|
-
(0,
|
|
633
|
+
(0, grpc_1.isRecreateServiceError)(error);
|
|
645
634
|
const shouldRetry = error &&
|
|
646
635
|
retries &&
|
|
647
|
-
((_b = (_a = options.grpcRetryCondition) === null || _a === void 0 ? void 0 : _a.call(options, error)) !== null && _b !== void 0 ? _b : (0,
|
|
636
|
+
((_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
637
|
if (shouldRecreateService) {
|
|
649
638
|
ctx.log(`Service client for ${config.protoKey} is going to be re-created`);
|
|
650
639
|
recreateService(service, timeout * 1.5, ctx, args);
|
|
651
640
|
}
|
|
652
641
|
if (shouldRetry) {
|
|
653
|
-
(0,
|
|
642
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, `Request failed, retrying ${retries--} more times`, {
|
|
654
643
|
serviceName,
|
|
655
644
|
actionName,
|
|
656
|
-
debugHeaders: (0,
|
|
645
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
657
646
|
});
|
|
658
647
|
// Update pointer to re-created client in local service variable
|
|
659
648
|
try {
|
|
660
649
|
service = await getService(args);
|
|
661
650
|
}
|
|
662
651
|
catch (error) {
|
|
663
|
-
(0,
|
|
652
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'getService failed');
|
|
664
653
|
throw error;
|
|
665
654
|
}
|
|
666
655
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
@@ -671,7 +660,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
671
660
|
}
|
|
672
661
|
if (error) {
|
|
673
662
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
674
|
-
reject(new
|
|
663
|
+
reject(new parse_error_1.GrpcError('gRPC request error', (0, parse_error_1.parseGrpcError)(error, root, lang, config.decodeAnyMessageProtoLoaderOptions), error));
|
|
675
664
|
return;
|
|
676
665
|
}
|
|
677
666
|
const responseData = await getResponseData({
|
|
@@ -686,7 +675,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
686
675
|
const responseHeaders = {};
|
|
687
676
|
if (config.proxyResponseHeaders) {
|
|
688
677
|
const proxyResponseHeaders = [];
|
|
689
|
-
const headersFromMetadata = (0,
|
|
678
|
+
const headersFromMetadata = (0, common_2.getHeadersFromMetadata)(trailingMetadata);
|
|
690
679
|
if (typeof config.proxyResponseHeaders === 'function') {
|
|
691
680
|
Object.assign(responseHeaders, config.proxyResponseHeaders(headersFromMetadata, 'grpc'));
|
|
692
681
|
}
|
|
@@ -700,10 +689,10 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
700
689
|
}
|
|
701
690
|
}
|
|
702
691
|
}
|
|
703
|
-
Object.assign(debugHeaders, (0,
|
|
692
|
+
Object.assign(debugHeaders, (0, common_2.getHeadersFromMetadata)(trailingMetadata, 'x-metadata-'));
|
|
704
693
|
sendStats(200, Object.assign(Object.assign({}, requestData), { responseSize: (0, object_sizeof_1.default)(response), grpcStatus: 0 }));
|
|
705
694
|
ctx.log('Request completed', {
|
|
706
|
-
debugHeaders: (0,
|
|
695
|
+
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
707
696
|
});
|
|
708
697
|
ctx.end();
|
|
709
698
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
@@ -712,7 +701,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
712
701
|
call.on('status', (status) => {
|
|
713
702
|
trailingMetadata = status.metadata.toJSON();
|
|
714
703
|
});
|
|
715
|
-
stopListeningForAbort = (0,
|
|
704
|
+
stopListeningForAbort = (0, grpc_1.listenForAbort)({
|
|
716
705
|
signal: abortSignal,
|
|
717
706
|
config,
|
|
718
707
|
call,
|
|
@@ -723,10 +712,11 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
723
712
|
}
|
|
724
713
|
}
|
|
725
714
|
}).catch((error) => {
|
|
726
|
-
const grpcError = (0,
|
|
715
|
+
const grpcError = (0, parse_error_1.isGrpcError)(error) ? error : (0, parse_error_1.grpcErrorFactory)(error);
|
|
727
716
|
processError(grpcError);
|
|
728
717
|
stopListeningForAbort === null || stopListeningForAbort === void 0 ? void 0 : stopListeningForAbort();
|
|
729
718
|
return Promise.reject({ error: grpcError.getGatewayError(), debugHeaders });
|
|
730
719
|
});
|
|
731
720
|
};
|
|
732
721
|
}
|
|
722
|
+
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
|
}>;
|