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