@gravity-ui/gateway 4.6.0 → 4.7.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -3
- package/{build → dist/commonjs}/components/grpc.d.ts +5 -5
- package/{build → dist/commonjs}/components/grpc.js +109 -90
- package/{build → dist/commonjs}/components/mixed.d.ts +4 -4
- package/{build → dist/commonjs}/components/mixed.js +11 -12
- package/{build → dist/commonjs}/components/rest.d.ts +5 -5
- package/{build → dist/commonjs}/components/rest.js +42 -35
- package/{build → dist/commonjs}/constants.d.ts +2 -2
- package/{build → dist/commonjs}/constants.js +29 -19
- package/{build → dist/commonjs}/index.d.ts +9 -8
- package/{build → dist/commonjs}/index.js +35 -46
- package/{build → dist/commonjs}/models/common.d.ts +19 -8
- package/{build → dist/commonjs}/models/context.d.ts +0 -1
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/utils/axios.d.ts +4 -0
- package/{build → dist/commonjs}/utils/axios.js +3 -4
- package/{build → dist/commonjs}/utils/common.d.ts +4 -3
- package/{build → dist/commonjs}/utils/common.js +19 -8
- package/{build → dist/commonjs}/utils/create-context-api.d.ts +2 -2
- package/{build → dist/commonjs}/utils/create-context-api.js +5 -6
- package/{build → dist/commonjs}/utils/grpc-reflection.js +15 -35
- package/{build → dist/commonjs}/utils/grpc.d.ts +1 -1
- package/{build → dist/commonjs}/utils/grpc.js +10 -11
- package/dist/commonjs/utils/overrideEndpoints/index.d.ts +2 -0
- package/dist/commonjs/utils/overrideEndpoints/index.js +4 -0
- package/{build → dist/commonjs}/utils/overrideEndpoints/overrideEndpoints.d.ts +1 -1
- package/{build → dist/commonjs}/utils/overrideEndpoints/overrideEndpoints.js +1 -2
- package/dist/commonjs/utils/package-root.d.ts +1 -0
- package/dist/commonjs/utils/package-root.js +44 -0
- package/{build → dist/commonjs}/utils/parse-error.d.ts +5 -5
- package/{build → dist/commonjs}/utils/parse-error.js +19 -19
- package/{build → dist/commonjs}/utils/proto-path-resolver.d.ts +1 -1
- package/{build → dist/commonjs}/utils/proto-path-resolver.js +24 -15
- package/{build → dist/commonjs}/utils/redact-sensitive-headers.d.ts +1 -2
- package/{build → dist/commonjs}/utils/redact-sensitive-headers.js +1 -2
- package/dist/commonjs/utils/source-dir.d.ts +1 -0
- package/dist/commonjs/utils/source-dir.js +41 -0
- package/{build → dist/commonjs}/utils/typed-api.d.ts +1 -1
- package/{build → dist/commonjs}/utils/typed-api.js +1 -2
- package/{build → dist/commonjs}/utils/validate.js +6 -10
- package/dist/esm/components/grpc.d.ts +24 -0
- package/dist/esm/components/grpc.js +691 -0
- package/dist/esm/components/mixed.d.ts +11 -0
- package/dist/esm/components/mixed.js +62 -0
- package/dist/esm/components/rest.d.ts +8 -0
- package/dist/esm/components/rest.js +357 -0
- package/dist/esm/constants.d.ts +53 -0
- package/dist/esm/constants.js +82 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.js +274 -0
- package/dist/esm/models/common.d.ts +289 -0
- package/dist/esm/models/common.js +5 -0
- package/dist/esm/models/context.d.ts +22 -0
- package/dist/esm/models/context.js +1 -0
- package/dist/esm/models/error.d.ts +12 -0
- package/dist/esm/models/error.js +1 -0
- package/dist/esm/package.json +3 -0
- package/{build → dist/esm}/utils/axios.d.ts +1 -1
- package/dist/esm/utils/axios.js +24 -0
- package/dist/esm/utils/common.d.ts +16 -0
- package/dist/esm/utils/common.js +48 -0
- package/dist/esm/utils/create-context-api.d.ts +4 -0
- package/dist/esm/utils/create-context-api.js +38 -0
- package/dist/esm/utils/grpc-reflection.d.ts +28 -0
- package/dist/esm/utils/grpc-reflection.js +72 -0
- package/dist/esm/utils/grpc.d.ts +15 -0
- package/dist/esm/utils/grpc.js +72 -0
- package/dist/esm/utils/overrideEndpoints/index.d.ts +2 -0
- package/dist/esm/utils/overrideEndpoints/index.js +2 -0
- package/dist/esm/utils/overrideEndpoints/overrideEndpoints.d.ts +17 -0
- package/dist/esm/utils/overrideEndpoints/overrideEndpoints.js +96 -0
- package/dist/esm/utils/package-root.d.ts +1 -0
- package/dist/esm/utils/package-root.js +8 -0
- package/dist/esm/utils/parse-error.d.ts +30 -0
- package/dist/esm/utils/parse-error.js +214 -0
- package/dist/esm/utils/proto-path-resolver.d.ts +2 -0
- package/dist/esm/utils/proto-path-resolver.js +23 -0
- package/dist/esm/utils/redact-sensitive-headers.d.ts +3 -0
- package/dist/esm/utils/redact-sensitive-headers.js +12 -0
- package/dist/esm/utils/source-dir.d.ts +1 -0
- package/dist/esm/utils/source-dir.js +4 -0
- package/dist/esm/utils/typed-api.d.ts +2 -0
- package/dist/esm/utils/typed-api.js +3 -0
- package/dist/esm/utils/validate.d.ts +4 -0
- package/dist/esm/utils/validate.js +47 -0
- package/package.json +41 -16
- package/build/utils/overrideEndpoints/index.d.ts +0 -2
- package/build/utils/overrideEndpoints/index.js +0 -4
- /package/bin/{patch.js → patch.cjs} +0 -0
- /package/{build → dist/commonjs}/models/common.js +0 -0
- /package/{build → dist/commonjs}/models/context.js +0 -0
- /package/{build → dist/commonjs}/models/error.d.ts +0 -0
- /package/{build → dist/commonjs}/models/error.js +0 -0
- /package/{build → dist/commonjs}/utils/grpc-reflection.d.ts +0 -0
- /package/{build → dist/commonjs}/utils/validate.d.ts +0 -0
|
@@ -3,24 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createRestAction = createRestAction;
|
|
6
7
|
const querystring_1 = __importDefault(require("querystring"));
|
|
7
8
|
const url_1 = __importDefault(require("url"));
|
|
8
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
10
|
const uuid_1 = require("uuid");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
11
|
+
const constants_js_1 = require("../constants.js");
|
|
12
|
+
const axios_js_1 = require("../utils/axios.js");
|
|
13
|
+
const common_js_1 = require("../utils/common.js");
|
|
14
|
+
const parse_error_js_1 = require("../utils/parse-error.js");
|
|
15
|
+
const redact_sensitive_headers_js_1 = require("../utils/redact-sensitive-headers.js");
|
|
16
|
+
const validate_js_1 = require("../utils/validate.js");
|
|
16
17
|
function getRestResponseSize(data, ctx, ErrorConstructor) {
|
|
17
18
|
var _a;
|
|
18
19
|
let responseSize = 0;
|
|
19
20
|
try {
|
|
20
|
-
responseSize =
|
|
21
|
+
responseSize = constants_js_1.ECMA_STRING_SIZE * ((_a = JSON.stringify(data)) === null || _a === void 0 ? void 0 : _a.length);
|
|
21
22
|
}
|
|
22
23
|
catch (error) {
|
|
23
|
-
(0,
|
|
24
|
+
(0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Calculate response size failed');
|
|
24
25
|
}
|
|
25
26
|
return responseSize;
|
|
26
27
|
}
|
|
@@ -36,13 +37,13 @@ function getConfigSerializerFunction(config) {
|
|
|
36
37
|
function createRestAction(endpoints, config, serviceKey, actionName, options, ErrorConstructor) {
|
|
37
38
|
var _a, _b, _c, _d;
|
|
38
39
|
const timeout = (_c = (_a = config === null || config === void 0 ? void 0 : config.timeout) !== null && _a !== void 0 ? _a : (_b = options === null || options === void 0 ? void 0 : options.axiosConfig) === null || _b === void 0 ? void 0 : _b.timeout) !== null && _c !== void 0 ? _c : options === null || options === void 0 ? void 0 : options.timeout;
|
|
39
|
-
const defaultAxiosClient = (0,
|
|
40
|
+
const defaultAxiosClient = (0, axios_js_1.getAxiosClient)(timeout, config === null || config === void 0 ? void 0 : config.retries, (_d = config === null || config === void 0 ? void 0 : config.axiosRetryCondition) !== null && _d !== void 0 ? _d : options === null || options === void 0 ? void 0 : options.axiosRetryCondition, options === null || options === void 0 ? void 0 : options.axiosConfig, options === null || options === void 0 ? void 0 : options.axiosInterceptors);
|
|
40
41
|
/* eslint-disable complexity */
|
|
41
42
|
return async function action(actionConfig) {
|
|
42
43
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
43
44
|
const { args, requestId, headers: requestHeaders, ctx: parentCtx, authArgs, userId, abortSignal, } = actionConfig;
|
|
44
45
|
const debugHeaders = {};
|
|
45
|
-
const lang = requestHeaders[
|
|
46
|
+
const lang = requestHeaders[constants_js_1.DEFAULT_LANG_HEADER] || constants_js_1.Lang.Ru; // header might be empty string
|
|
46
47
|
const serviceName = (options === null || options === void 0 ? void 0 : options.serviceName) || serviceKey;
|
|
47
48
|
const idempotency = config.idempotency;
|
|
48
49
|
const ctx = parentCtx.create(`Gateway ${serviceName} ${actionName} [rest]`, {
|
|
@@ -55,7 +56,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
55
56
|
ctx.log('Initiating request');
|
|
56
57
|
const validationSchema = config.validationSchema || options.validationSchema;
|
|
57
58
|
if (validationSchema) {
|
|
58
|
-
const invalidParams = (0,
|
|
59
|
+
const invalidParams = (0, validate_js_1.validateArgs)(args, validationSchema);
|
|
59
60
|
if (invalidParams) {
|
|
60
61
|
ctx.log('Invalid params', { invalidParams });
|
|
61
62
|
ctx.end();
|
|
@@ -92,35 +93,42 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
92
93
|
},
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
|
-
const actionEndpoint = (0,
|
|
96
|
+
const actionEndpoint = (0, common_js_1.isExtendedActionEndpoint)(endpointData)
|
|
96
97
|
? endpointData.path
|
|
97
98
|
: endpointData;
|
|
98
|
-
const endpointAxiosConfig = (0,
|
|
99
|
+
const endpointAxiosConfig = (0, common_js_1.isExtendedRestActionEndpoint)(endpointData)
|
|
99
100
|
? endpointData.axiosConfig
|
|
100
101
|
: undefined;
|
|
101
102
|
const pathArgs = config.validationSchema
|
|
102
|
-
? (0,
|
|
103
|
-
: (0,
|
|
103
|
+
? (0, validate_js_1.encodePathParams)(args)
|
|
104
|
+
: (0, validate_js_1.getPathArgsProxy)(args, options.encodePathArgs);
|
|
104
105
|
const actionPath = typeof config.path === 'function' ? config.path(pathArgs) : config.path;
|
|
105
106
|
const actionURL = actionEndpoint + actionPath;
|
|
106
107
|
const parsedActionURL = url_1.default.parse(actionURL);
|
|
107
|
-
const proxyHeaders = [...
|
|
108
|
+
const proxyHeaders = [...constants_js_1.DEFAULT_PROXY_HEADERS];
|
|
108
109
|
let actionHeaders = {
|
|
109
110
|
// It's important not to lose the port in HOST header
|
|
110
111
|
host: (_a = parsedActionURL.host) !== null && _a !== void 0 ? _a : undefined,
|
|
111
112
|
accept: 'application/json, */*',
|
|
112
113
|
'accept-encoding': 'gzip, deflate',
|
|
113
114
|
'accept-language': lang,
|
|
114
|
-
'x-gateway-version':
|
|
115
|
+
'x-gateway-version': constants_js_1.VERSION,
|
|
116
|
+
};
|
|
117
|
+
let proxyHeadersExtra;
|
|
118
|
+
const proxyHeadersCaller = (proxyHeadersFunc) => {
|
|
119
|
+
if (proxyHeadersExtra === undefined) {
|
|
120
|
+
proxyHeadersExtra = (0, common_js_1.getProxyHeadersArgs)(serviceName, actionName);
|
|
121
|
+
}
|
|
122
|
+
return proxyHeadersFunc(Object.assign({}, requestHeaders), 'rest', proxyHeadersExtra);
|
|
115
123
|
};
|
|
116
124
|
if (typeof options.proxyHeaders === 'function') {
|
|
117
|
-
Object.assign(actionHeaders, options.proxyHeaders
|
|
125
|
+
Object.assign(actionHeaders, proxyHeadersCaller(options.proxyHeaders));
|
|
118
126
|
}
|
|
119
127
|
else if (Array.isArray(options.proxyHeaders)) {
|
|
120
128
|
proxyHeaders.push(...options.proxyHeaders);
|
|
121
129
|
}
|
|
122
130
|
if (typeof config.proxyHeaders === 'function') {
|
|
123
|
-
Object.assign(actionHeaders, config.proxyHeaders
|
|
131
|
+
Object.assign(actionHeaders, proxyHeadersCaller(config.proxyHeaders));
|
|
124
132
|
}
|
|
125
133
|
else if (Array.isArray(config.proxyHeaders)) {
|
|
126
134
|
proxyHeaders.push(...config.proxyHeaders);
|
|
@@ -150,7 +158,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
150
158
|
params = await config.params(args, actionHeaders, { ctx });
|
|
151
159
|
}
|
|
152
160
|
catch (error) {
|
|
153
|
-
(0,
|
|
161
|
+
(0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Getting config params failed');
|
|
154
162
|
}
|
|
155
163
|
}
|
|
156
164
|
const { body = undefined, query = undefined, headers = actionHeaders } = params !== null && params !== void 0 ? params : {};
|
|
@@ -171,7 +179,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
171
179
|
}
|
|
172
180
|
}
|
|
173
181
|
catch (error) {
|
|
174
|
-
(0,
|
|
182
|
+
(0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Stringify request body failed');
|
|
175
183
|
}
|
|
176
184
|
Object.assign(debugHeaders, {
|
|
177
185
|
'x-api-request-method': config.method,
|
|
@@ -179,13 +187,13 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
179
187
|
'x-api-request-body': requestBody ? requestBody : null,
|
|
180
188
|
'x-api-request-lang': lang,
|
|
181
189
|
'x-request-id': requestId,
|
|
182
|
-
'x-gateway-version':
|
|
190
|
+
'x-gateway-version': constants_js_1.VERSION,
|
|
183
191
|
});
|
|
184
192
|
if (headers['content-type']) {
|
|
185
193
|
debugHeaders['x-api-content-type'] = headers['content-type'];
|
|
186
194
|
}
|
|
187
195
|
if (typeof options.proxyDebugHeaders === 'function') {
|
|
188
|
-
Object.assign(debugHeaders, options.proxyDebugHeaders
|
|
196
|
+
Object.assign(debugHeaders, proxyHeadersCaller(options.proxyDebugHeaders));
|
|
189
197
|
}
|
|
190
198
|
else if (Array.isArray(options.proxyDebugHeaders)) {
|
|
191
199
|
for (const headerName of options.proxyDebugHeaders) {
|
|
@@ -199,10 +207,10 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
199
207
|
const customActionTimeout = (_e = (_d = (_c = actionConfig.timeout) !== null && _c !== void 0 ? _c : config.timeout) !== null && _d !== void 0 ? _d : endpointAxiosConfig === null || endpointAxiosConfig === void 0 ? void 0 : endpointAxiosConfig.timeout) !== null && _e !== void 0 ? _e : timeout;
|
|
200
208
|
if (actionConfig.timeout || endpointAxiosConfig) {
|
|
201
209
|
const customActionAxiosConfig = Object.assign(Object.assign({}, ((options === null || options === void 0 ? void 0 : options.axiosConfig) || {})), (endpointAxiosConfig || {}));
|
|
202
|
-
axiosClient = (0,
|
|
210
|
+
axiosClient = (0, axios_js_1.getAxiosClient)(customActionTimeout, config === null || config === void 0 ? void 0 : config.retries, options.axiosRetryCondition, customActionAxiosConfig, options === null || options === void 0 ? void 0 : options.axiosInterceptors);
|
|
203
211
|
}
|
|
204
|
-
headers['x-request-timeout'] = customActionTimeout !== null && customActionTimeout !== void 0 ? customActionTimeout :
|
|
205
|
-
ctx.log('Starting request', { debugHeaders: (0,
|
|
212
|
+
headers['x-request-timeout'] = customActionTimeout !== null && customActionTimeout !== void 0 ? customActionTimeout : constants_js_1.DEFAULT_TIMEOUT;
|
|
213
|
+
ctx.log('Starting request', { debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
206
214
|
const requestData = {
|
|
207
215
|
timestamp: startRequestTime,
|
|
208
216
|
service: serviceName,
|
|
@@ -278,7 +286,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
278
286
|
ctx.log('Transformed response data');
|
|
279
287
|
}
|
|
280
288
|
catch (error) {
|
|
281
|
-
(0,
|
|
289
|
+
(0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Transform response data failed');
|
|
282
290
|
}
|
|
283
291
|
}
|
|
284
292
|
if (config.proxyResponseHeaders) {
|
|
@@ -296,12 +304,12 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
296
304
|
}
|
|
297
305
|
}
|
|
298
306
|
if (options === null || options === void 0 ? void 0 : options.sendStats) {
|
|
299
|
-
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize(response === null || response === void 0 ? void 0 : response.data, ctx, ErrorConstructor), restStatus: 200 }), (0,
|
|
307
|
+
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize(response === null || response === void 0 ? void 0 : response.data, ctx, ErrorConstructor), restStatus: 200 }), (0, redact_sensitive_headers_js_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
300
308
|
}
|
|
301
309
|
else {
|
|
302
310
|
ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus: 200 }));
|
|
303
311
|
}
|
|
304
|
-
ctx.log('Request completed', { debugHeaders: (0,
|
|
312
|
+
ctx.log('Request completed', { debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
305
313
|
ctx.end();
|
|
306
314
|
return { responseData: response.data, responseHeaders, debugHeaders };
|
|
307
315
|
}
|
|
@@ -321,20 +329,20 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
321
329
|
ctx.log('Transformed response error');
|
|
322
330
|
}
|
|
323
331
|
catch (error) {
|
|
324
|
-
(0,
|
|
332
|
+
(0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Transform response error failed');
|
|
325
333
|
}
|
|
326
334
|
}
|
|
327
335
|
if (!parsedError) {
|
|
328
336
|
try {
|
|
329
|
-
parsedError = (0,
|
|
337
|
+
parsedError = (0, parse_error_js_1.parseRestError)(error, lang);
|
|
330
338
|
}
|
|
331
339
|
catch (error) {
|
|
332
|
-
(0,
|
|
340
|
+
(0, common_js_1.handleError)(ErrorConstructor, error, ctx, 'Error parse rest error');
|
|
333
341
|
}
|
|
334
342
|
}
|
|
335
343
|
const responseStatus = lodash_1.default.get(parsedError, 'status') || lodash_1.default.get(error, 'status', 500);
|
|
336
344
|
if (options === null || options === void 0 ? void 0 : options.sendStats) {
|
|
337
|
-
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize((_h = error === null || error === void 0 ? void 0 : error.response) === null || _h === void 0 ? void 0 : _h.data, ctx, ErrorConstructor), restStatus: responseStatus, userId }), (0,
|
|
345
|
+
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize((_h = error === null || error === void 0 ? void 0 : error.response) === null || _h === void 0 ? void 0 : _h.data, ctx, ErrorConstructor), restStatus: responseStatus, userId }), (0, redact_sensitive_headers_js_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
338
346
|
}
|
|
339
347
|
else {
|
|
340
348
|
ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus }));
|
|
@@ -343,7 +351,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
343
351
|
actionURL,
|
|
344
352
|
parsedError,
|
|
345
353
|
serviceName,
|
|
346
|
-
debugHeaders: (0,
|
|
354
|
+
debugHeaders: (0, common_js_1.sanitizeDebugHeaders)(debugHeaders),
|
|
347
355
|
});
|
|
348
356
|
ctx.end();
|
|
349
357
|
return Promise.reject({
|
|
@@ -353,4 +361,3 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
353
361
|
}
|
|
354
362
|
};
|
|
355
363
|
}
|
|
356
|
-
exports.default = createRestAction;
|
|
@@ -15,22 +15,32 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
28
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
36
|
exports.AXIOS_RETRY_NAMESPACE = exports.DEFAULT_VALIDATION_SCHEMA = exports.RECREATE_SERVICE_CODES = exports.RETRYABLE_STATUS_CODES = exports.ANY_ACTION_SYMBOL = exports.ECMA_STRING_SIZE = exports.DEFAULT_PROTO_LOADER_OPTIONS = exports.DEFAULT_GRPC_OPTIONS = exports.DEFAULT_AXIOS_OPTIONS = exports.DEFAULT_PROXY_HEADERS = exports.DEFAULT_LANG_HEADER = exports.DEFAULT_TIMEOUT = exports.Lang = exports.VERSION = void 0;
|
|
30
|
-
const
|
|
31
|
-
const
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const http = __importStar(require("http"));
|
|
39
|
+
const https = __importStar(require("https"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
32
41
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
33
|
-
const
|
|
42
|
+
const package_root_js_1 = require("./utils/package-root.js");
|
|
43
|
+
const packageJson = JSON.parse(fs.readFileSync(path.resolve(package_root_js_1.packageRoot, 'package.json'), 'utf-8'));
|
|
34
44
|
exports.VERSION = packageJson.version;
|
|
35
45
|
var Lang;
|
|
36
46
|
(function (Lang) {
|
|
@@ -47,18 +57,18 @@ exports.DEFAULT_PROXY_HEADERS = [
|
|
|
47
57
|
'x-forwarded-for',
|
|
48
58
|
];
|
|
49
59
|
exports.DEFAULT_AXIOS_OPTIONS = {
|
|
50
|
-
maxContentLength: 1024 * 1024 * 100,
|
|
51
|
-
httpAgent: new
|
|
52
|
-
|
|
60
|
+
maxContentLength: 1024 * 1024 * 100, // 100 Mb
|
|
61
|
+
httpAgent: new http.Agent({
|
|
62
|
+
// https://github.com/nodejs/node/blob/master/lib/_http_agent.js#L233
|
|
53
63
|
family: 6,
|
|
54
64
|
}),
|
|
55
|
-
httpsAgent: new
|
|
56
|
-
|
|
65
|
+
httpsAgent: new https.Agent({
|
|
66
|
+
// https://github.com/nodejs/node/blob/master/lib/_http_agent.js#L233
|
|
57
67
|
family: 6,
|
|
58
68
|
}),
|
|
59
69
|
};
|
|
60
70
|
exports.DEFAULT_GRPC_OPTIONS = {
|
|
61
|
-
'grpc.max_receive_message_length': 1024 * 1024 * 100,
|
|
71
|
+
'grpc.max_receive_message_length': 1024 * 1024 * 100, // 100 Mb
|
|
62
72
|
'grpc.keepalive_time_ms': 10000,
|
|
63
73
|
'grpc.keepalive_timeout_ms': 1000,
|
|
64
74
|
'grpc.keepalive_permit_without_calls': 1,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { ApiWithRoot, GatewayConfig, GatewayRequest, GatewayResponse, SchemasByScope } from './models/common';
|
|
2
|
-
import { GatewayContext } from './models/context';
|
|
3
|
-
export * from './utils/typed-api';
|
|
4
|
-
export * from './utils/grpc-reflection';
|
|
5
|
-
export { isRetryableGrpcError } from './utils/grpc';
|
|
6
|
-
export * from './models/common';
|
|
7
|
-
export * from './models/context';
|
|
8
|
-
export * from './models/error';
|
|
1
|
+
import { ApiWithRoot, GatewayConfig, GatewayRequest, GatewayResponse, SchemasByScope } from './models/common.js';
|
|
2
|
+
import { GatewayContext } from './models/context.js';
|
|
3
|
+
export * from './utils/typed-api.js';
|
|
4
|
+
export * from './utils/grpc-reflection.js';
|
|
5
|
+
export { isRetryableGrpcError } from './utils/grpc.js';
|
|
6
|
+
export * from './models/common.js';
|
|
7
|
+
export * from './models/context.js';
|
|
8
|
+
export * from './models/error.js';
|
|
9
9
|
export declare function getGatewayControllers<TSchema extends SchemasByScope, Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse>(schemasByScope: TSchema, config: GatewayConfig<Context, Req, Res>): {
|
|
10
10
|
controller: (req: Req, res: Res) => Promise<any>;
|
|
11
11
|
api: ApiWithRoot<TSchema, Context, Req, Res>;
|
|
12
12
|
};
|
|
13
|
+
export default getGatewayControllers;
|
|
@@ -10,18 +10,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
15
|
};
|
|
@@ -29,21 +17,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
18
|
};
|
|
31
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.
|
|
20
|
+
exports.isRetryableGrpcError = void 0;
|
|
21
|
+
exports.getGatewayControllers = getGatewayControllers;
|
|
33
22
|
const lodash_1 = __importDefault(require("lodash"));
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
__exportStar(require("./utils/typed-api"), exports);
|
|
41
|
-
__exportStar(require("./utils/grpc-reflection"), exports);
|
|
42
|
-
var
|
|
43
|
-
Object.defineProperty(exports, "isRetryableGrpcError", { enumerable: true, get: function () { return
|
|
44
|
-
__exportStar(require("./models/common"), exports);
|
|
45
|
-
__exportStar(require("./models/context"), exports);
|
|
46
|
-
__exportStar(require("./models/error"), exports);
|
|
23
|
+
const grpc_js_1 = require("./components/grpc.js");
|
|
24
|
+
const mixed_js_1 = require("./components/mixed.js");
|
|
25
|
+
const rest_js_1 = require("./components/rest.js");
|
|
26
|
+
const constants_js_1 = require("./constants.js");
|
|
27
|
+
const common_js_1 = require("./utils/common.js");
|
|
28
|
+
const overrideEndpoints_js_1 = require("./utils/overrideEndpoints/overrideEndpoints.js");
|
|
29
|
+
__exportStar(require("./utils/typed-api.js"), exports);
|
|
30
|
+
__exportStar(require("./utils/grpc-reflection.js"), exports);
|
|
31
|
+
var grpc_js_2 = require("./utils/grpc.js");
|
|
32
|
+
Object.defineProperty(exports, "isRetryableGrpcError", { enumerable: true, get: function () { return grpc_js_2.isRetryableGrpcError; } });
|
|
33
|
+
__exportStar(require("./models/common.js"), exports);
|
|
34
|
+
__exportStar(require("./models/context.js"), exports);
|
|
35
|
+
__exportStar(require("./models/error.js"), exports);
|
|
47
36
|
function isMixedActionConfig(actionConfig) {
|
|
48
37
|
return typeof actionConfig === 'function';
|
|
49
38
|
}
|
|
@@ -69,11 +58,11 @@ function createApiAction(schema, config, serviceKey, actionName, api, grpcContex
|
|
|
69
58
|
const env = config.env || '';
|
|
70
59
|
if (isMixedActionConfig(action)) {
|
|
71
60
|
const resultServiceName = serviceName || serviceKey;
|
|
72
|
-
return (0,
|
|
61
|
+
return (0, mixed_js_1.createMixedAction)(action, api, resultServiceName, actionName, { config, grpcContext }, config.ErrorConstructor);
|
|
73
62
|
}
|
|
74
63
|
const endpointsConfig = lodash_1.default.get(serviceSchema.endpoints, [installation, env]);
|
|
75
64
|
if (isRestActionConfig(action)) {
|
|
76
|
-
return (0,
|
|
65
|
+
return (0, rest_js_1.createRestAction)(endpointsConfig, action, serviceKey, actionName, {
|
|
77
66
|
serviceName,
|
|
78
67
|
timeout: config.timeout,
|
|
79
68
|
sendStats: config.sendStats,
|
|
@@ -88,7 +77,7 @@ function createApiAction(schema, config, serviceKey, actionName, api, grpcContex
|
|
|
88
77
|
}, config.ErrorConstructor);
|
|
89
78
|
}
|
|
90
79
|
const grpcRecreateService = (_a = config.grpcRecreateService) !== null && _a !== void 0 ? _a : true;
|
|
91
|
-
return (0,
|
|
80
|
+
return (0, grpc_js_1.createGrpcAction)(grpcContext, endpointsConfig, action, serviceKey, actionName, {
|
|
92
81
|
serviceName,
|
|
93
82
|
timeout: config.timeout,
|
|
94
83
|
sendStats: config.sendStats,
|
|
@@ -165,8 +154,8 @@ function generateGatewayApiController(schemasByScope, Api, config, controllerAct
|
|
|
165
154
|
});
|
|
166
155
|
}
|
|
167
156
|
if (controllerActions &&
|
|
168
|
-
lodash_1.default.get(controllerActions, [scope]) !==
|
|
169
|
-
lodash_1.default.get(controllerActions, [scope, service]) !==
|
|
157
|
+
lodash_1.default.get(controllerActions, [scope]) !== constants_js_1.ANY_ACTION_SYMBOL &&
|
|
158
|
+
lodash_1.default.get(controllerActions, [scope, service]) !== constants_js_1.ANY_ACTION_SYMBOL &&
|
|
170
159
|
!lodash_1.default.get(controllerActions, [scope, service, action])) {
|
|
171
160
|
return res.status(404).send({
|
|
172
161
|
status: 404,
|
|
@@ -188,7 +177,7 @@ function generateGatewayApiController(schemasByScope, Api, config, controllerAct
|
|
|
188
177
|
await onBeforeAction(req, res, scope, service, action, actionConfig);
|
|
189
178
|
}
|
|
190
179
|
catch (error) {
|
|
191
|
-
(0,
|
|
180
|
+
(0, common_js_1.handleError)(config.ErrorConstructor, error, req.ctx, 'Before action handler error');
|
|
192
181
|
throw { error, debugHeaders: {} };
|
|
193
182
|
}
|
|
194
183
|
}
|
|
@@ -250,25 +239,25 @@ function getGatewayControllers(schemasByScope, config) {
|
|
|
250
239
|
if (process.env.GATEWAY_ENDPOINTS_OVERRIDES) {
|
|
251
240
|
try {
|
|
252
241
|
// eslint-disable-next-line no-param-reassign
|
|
253
|
-
schemasByScope = (0,
|
|
242
|
+
schemasByScope = (0, overrideEndpoints_js_1.overrideEndpoints)(schemasByScope, JSON.parse(process.env.GATEWAY_ENDPOINTS_OVERRIDES), config.installation, config.env);
|
|
254
243
|
}
|
|
255
244
|
catch (err) {
|
|
256
245
|
console.warn('Error when parse GATEWAY_ENDPOINTS_OVERRIDES', err);
|
|
257
246
|
}
|
|
258
247
|
}
|
|
259
|
-
const credentials = (0,
|
|
260
|
-
for (const scope of (0,
|
|
261
|
-
apiByScope[scope] = generateGatewayApi(schemasByScope[scope], config, { root: (0,
|
|
248
|
+
const credentials = (0, grpc_js_1.getCredentialsMap)(config.caCertificatePath);
|
|
249
|
+
for (const scope of (0, common_js_1.getKeys)(schemasByScope)) {
|
|
250
|
+
apiByScope[scope] = generateGatewayApi(schemasByScope[scope], config, { root: (0, grpc_js_1.createRoot)(config.includeProtoRoots), credentials }, apiByScope);
|
|
262
251
|
}
|
|
263
252
|
const api = Object.assign({}, apiByScope);
|
|
264
253
|
const rootScope = apiByScope.root;
|
|
265
254
|
if (rootScope) {
|
|
266
|
-
for (const rootService of (0,
|
|
255
|
+
for (const rootService of (0, common_js_1.getKeys)(rootScope)) {
|
|
267
256
|
const curScope = (_a = api[rootService]) !== null && _a !== void 0 ? _a : {};
|
|
268
|
-
for (const rootAction of (0,
|
|
257
|
+
for (const rootAction of (0, common_js_1.getKeys)(rootScope[rootService])) {
|
|
269
258
|
const rootServiceFunc = rootScope[rootService][rootAction];
|
|
270
259
|
if (curScope[rootAction]) {
|
|
271
|
-
for (const curScopeAction of (0,
|
|
260
|
+
for (const curScopeAction of (0, common_js_1.getKeys)(curScope[rootAction])) {
|
|
272
261
|
rootServiceFunc[curScopeAction] = curScope[rootAction][curScopeAction];
|
|
273
262
|
}
|
|
274
263
|
}
|
|
@@ -281,15 +270,15 @@ function getGatewayControllers(schemasByScope, config) {
|
|
|
281
270
|
? config.actions.reduce((acc, item) => {
|
|
282
271
|
const [scope, service, action] = item.split('.');
|
|
283
272
|
// Ignore option '*' for scopes
|
|
284
|
-
if (scope ===
|
|
273
|
+
if (scope === constants_js_1.ANY_ACTION_SYMBOL) {
|
|
285
274
|
return acc;
|
|
286
275
|
}
|
|
287
|
-
if (service ===
|
|
288
|
-
lodash_1.default.set(acc, [scope],
|
|
276
|
+
if (service === constants_js_1.ANY_ACTION_SYMBOL) {
|
|
277
|
+
lodash_1.default.set(acc, [scope], constants_js_1.ANY_ACTION_SYMBOL);
|
|
289
278
|
}
|
|
290
|
-
else if (action ===
|
|
291
|
-
if (acc[scope] !==
|
|
292
|
-
lodash_1.default.set(acc, [scope, service],
|
|
279
|
+
else if (action === constants_js_1.ANY_ACTION_SYMBOL) {
|
|
280
|
+
if (acc[scope] !== constants_js_1.ANY_ACTION_SYMBOL) {
|
|
281
|
+
lodash_1.default.set(acc, [scope, service], constants_js_1.ANY_ACTION_SYMBOL);
|
|
293
282
|
}
|
|
294
283
|
}
|
|
295
284
|
else {
|
|
@@ -304,4 +293,4 @@ function getGatewayControllers(schemasByScope, config) {
|
|
|
304
293
|
api,
|
|
305
294
|
};
|
|
306
295
|
}
|
|
307
|
-
exports.
|
|
296
|
+
exports.default = getGatewayControllers;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { IncomingHttpHeaders } from 'http';
|
|
3
2
|
import { ClientDuplexStream, ClientReadableStream, ClientWritableStream, type ServiceError } from '@grpc/grpc-js';
|
|
4
|
-
import { HandlerType } from '@grpc/grpc-js/build/src/server-call';
|
|
3
|
+
import type { HandlerType } from '@grpc/grpc-js/build/src/server-call.js';
|
|
5
4
|
import { AxiosInterceptorManager, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
6
5
|
import { IAxiosRetryConfig } from 'axios-retry';
|
|
7
6
|
import type { Request, Response } from 'express';
|
|
8
|
-
import
|
|
9
|
-
import type { GrpcContext } from '../components/grpc';
|
|
10
|
-
import { Lang } from '../constants';
|
|
11
|
-
import { GatewayContext } from './context';
|
|
12
|
-
import { AppErrorConstructor } from './error';
|
|
7
|
+
import protobufjs from 'protobufjs';
|
|
8
|
+
import type { GrpcContext } from '../components/grpc.js';
|
|
9
|
+
import { Lang } from '../constants.js';
|
|
10
|
+
import { GatewayContext } from './context.js';
|
|
11
|
+
import { AppErrorConstructor } from './error.js';
|
|
13
12
|
export interface GatewayRequest<Context extends GatewayContext> extends Request {
|
|
14
13
|
id: string;
|
|
15
14
|
ctx: Context;
|
|
@@ -68,7 +67,13 @@ export interface GatewayError {
|
|
|
68
67
|
}
|
|
69
68
|
export type GrpcRetryCondition = (error: ServiceError) => boolean;
|
|
70
69
|
export type AxiosRetryCondition = IAxiosRetryConfig['retryCondition'];
|
|
71
|
-
export type
|
|
70
|
+
export type ProxyHeadersFunctionExtra = {
|
|
71
|
+
service: string;
|
|
72
|
+
action: string;
|
|
73
|
+
protopath?: string;
|
|
74
|
+
protokey?: string;
|
|
75
|
+
};
|
|
76
|
+
export type ProxyHeadersFunction = (headers: IncomingHttpHeaders, type: ControllerType, extra: ProxyHeadersFunctionExtra) => IncomingHttpHeaders;
|
|
72
77
|
export type ProxyHeaders = string[] | ProxyHeadersFunction;
|
|
73
78
|
export type ProxyResponseHeadersFunction = (headers: Headers, type: ControllerType) => Headers;
|
|
74
79
|
export type ProxyResponseHeaders = string[] | ProxyResponseHeadersFunction;
|
|
@@ -211,12 +216,18 @@ export interface GatewayActionUnaryResponse<TAction> extends GatewayActionHeader
|
|
|
211
216
|
}
|
|
212
217
|
export interface GatewayActionClientStreamResponse<TAction> extends GatewayActionHeaders {
|
|
213
218
|
stream: ClientWritableStream<ApiActionResponseType<TAction>>;
|
|
219
|
+
responseData?: never;
|
|
220
|
+
responseHeaders?: never;
|
|
214
221
|
}
|
|
215
222
|
export interface GatewayActionServerStreamResponse<TAction> extends GatewayActionHeaders {
|
|
216
223
|
stream: ClientReadableStream<ApiActionResponseType<TAction>>;
|
|
224
|
+
responseData?: never;
|
|
225
|
+
responseHeaders?: never;
|
|
217
226
|
}
|
|
218
227
|
export interface GatewayActionDuplexStreamResponse<TAction> extends GatewayActionHeaders {
|
|
219
228
|
stream: ClientDuplexStream<ApiActionParams<TAction>, ApiActionResponseType<TAction>>;
|
|
229
|
+
responseData?: never;
|
|
230
|
+
responseHeaders?: never;
|
|
220
231
|
}
|
|
221
232
|
export type GatewayActionResponseData<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse, TAction extends ApiServiceActionConfig<Context, Req, Res, unknown, unknown, unknown>> = TAction extends ApiServiceGrpcActionConfig<Context, unknown, unknown, unknown> ? TAction['type'] extends 'clientStream' ? GatewayActionClientStreamResponse<TAction> : TAction['type'] extends 'serverStream' ? GatewayActionServerStreamResponse<TAction> : TAction['type'] extends 'bidi' ? GatewayActionDuplexStreamResponse<TAction> : GatewayActionUnaryResponse<TAction> : GatewayActionUnaryResponse<TAction>;
|
|
222
233
|
type GatewayAction<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse, TAction extends ApiServiceActionConfig<Context, Req, Res, unknown, unknown, unknown>> = undefined extends ApiActionParams<TAction> ? (params?: ApiActionConfig<Context, ApiActionParams<TAction>, ApiActionResponseType<TAction>>) => Promise<GatewayActionResponseData<Context, Req, Res, TAction>> : (params: ApiActionConfig<Context, ApiActionParams<TAction>, ApiActionResponseType<TAction>>) => Promise<GatewayActionResponseData<Context, Req, Res, TAction>>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import axios, { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { IAxiosRetryConfig } from 'axios-retry';
|
|
3
|
+
import { AxiosInterceptorsConfig } from '../models/common.js';
|
|
4
|
+
export declare function getAxiosClient(timeout?: number, retries?: number, customRetryCondition?: IAxiosRetryConfig['retryCondition'], axiosConfig?: AxiosRequestConfig, { request: reqInterceptors, response: resInterceptors }?: AxiosInterceptorsConfig): axios.AxiosInstance;
|
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAxiosClient =
|
|
6
|
+
exports.getAxiosClient = getAxiosClient;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
9
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
-
const
|
|
11
|
-
function getAxiosClient(timeout =
|
|
10
|
+
const constants_js_1 = require("../constants.js");
|
|
11
|
+
function getAxiosClient(timeout = constants_js_1.DEFAULT_TIMEOUT, retries = 0, customRetryCondition, axiosConfig = constants_js_1.DEFAULT_AXIOS_OPTIONS, { request: reqInterceptors, response: resInterceptors } = {}) {
|
|
12
12
|
const client = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { timeout }));
|
|
13
13
|
reqInterceptors === null || reqInterceptors === void 0 ? void 0 : reqInterceptors.forEach(({ callback, errorCallback }) => client.interceptors.request.use(callback, errorCallback));
|
|
14
14
|
resInterceptors === null || resInterceptors === void 0 ? void 0 : resInterceptors.forEach(({ callback, errorCallback }) => client.interceptors.response.use(callback, errorCallback));
|
|
@@ -28,4 +28,3 @@ function getAxiosClient(timeout = constants_1.DEFAULT_TIMEOUT, retries = 0, cust
|
|
|
28
28
|
});
|
|
29
29
|
return client;
|
|
30
30
|
}
|
|
31
|
-
exports.getAxiosClient = getAxiosClient;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as grpc from '@grpc/grpc-js';
|
|
2
2
|
import _ from 'lodash';
|
|
3
|
-
import { ActionEndpoint, ExtendedActionEndpoint, ExtendedGrpcActionEndpoint, ExtendedRestActionEndpoint, Headers } from '../models/common';
|
|
4
|
-
import { Dict, GatewayContext } from '../models/context';
|
|
5
|
-
import { AppErrorConstructor } from '../models/error';
|
|
3
|
+
import { ActionEndpoint, ApiServiceGrpcActionConfig, ExtendedActionEndpoint, ExtendedGrpcActionEndpoint, ExtendedRestActionEndpoint, Headers, ProxyHeadersFunctionExtra } from '../models/common.js';
|
|
4
|
+
import { Dict, GatewayContext } from '../models/context.js';
|
|
5
|
+
import { AppErrorConstructor } from '../models/error.js';
|
|
6
6
|
export declare function isExtendedActionEndpoint(endpoint: ActionEndpoint): endpoint is ExtendedActionEndpoint;
|
|
7
7
|
export declare function isExtendedGrpcActionEndpoint(endpoint: ActionEndpoint): endpoint is ExtendedGrpcActionEndpoint;
|
|
8
8
|
export declare function isExtendedRestActionEndpoint(endpoint: ActionEndpoint): endpoint is ExtendedRestActionEndpoint;
|
|
@@ -13,3 +13,4 @@ export declare function getKeys<T extends object>(obj: T): (keyof T)[];
|
|
|
13
13
|
export declare function sanitizeDebugHeaders(debugHeaders: Headers): _.Omit<Headers, "x-api-request-body">;
|
|
14
14
|
export declare function getHeadersFromMetadata(metadata: Record<string, grpc.MetadataValue[]>, prefix?: string): Record<string, string>;
|
|
15
15
|
export declare function handleError<Context extends GatewayContext>(ErrorConstructor: AppErrorConstructor, error: unknown, ctx: Context, message: string, extra?: Dict): void;
|
|
16
|
+
export declare const getProxyHeadersArgs: <Context extends GatewayContext>(serviceName: string, actionName: string, grpcConfig?: ApiServiceGrpcActionConfig<Context, any, any>) => ProxyHeadersFunctionExtra;
|