@gravity-ui/gateway 2.4.0 → 2.5.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/README.md +5 -0
- package/build/components/rest.js +13 -1
- package/build/constants.d.ts +1 -0
- package/build/constants.js +2 -1
- package/build/utils/validate.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -124,6 +124,11 @@ interface GatewayConfig {
|
|
|
124
124
|
}
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
+
#### validationSchema
|
|
128
|
+
|
|
129
|
+
By default, for path params in rest actions used the following regexp: `/^((?!(\.\.|\?|#|\\|\/)).)*$/i`.
|
|
130
|
+
If the parameter value does not pass validation, the `GATEWAY_INVALID_PARAM_VALUE` value is returned.
|
|
131
|
+
|
|
127
132
|
### Usage in Node.js
|
|
128
133
|
|
|
129
134
|
Upon gateway initialization, in addition to exporting the controller, it also exports an `api` object, which represents the core for executing requests to the backend.
|
package/build/components/rest.js
CHANGED
|
@@ -196,11 +196,12 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
196
196
|
}
|
|
197
197
|
const startRequestTime = Date.now();
|
|
198
198
|
let axiosClient = defaultAxiosClient;
|
|
199
|
+
const customActionTimeout = (_e = (_d = (_c = actionConfig.timeout) !== null && _c !== void 0 ? _c : config.timeout) !== null && _d !== void 0 ? _d : endpointAxiosConfig.timeout) !== null && _e !== void 0 ? _e : timeout;
|
|
199
200
|
if (actionConfig.timeout || endpointAxiosConfig) {
|
|
200
|
-
const customActionTimeout = (_e = (_d = (_c = actionConfig.timeout) !== null && _c !== void 0 ? _c : config.timeout) !== null && _d !== void 0 ? _d : endpointAxiosConfig.timeout) !== null && _e !== void 0 ? _e : timeout;
|
|
201
201
|
const customActionAxiosConfig = Object.assign(Object.assign({}, ((options === null || options === void 0 ? void 0 : options.axiosConfig) || {})), (endpointAxiosConfig || {}));
|
|
202
202
|
axiosClient = (0, axios_1.getAxiosClient)(customActionTimeout, config === null || config === void 0 ? void 0 : config.retries, customActionAxiosConfig);
|
|
203
203
|
}
|
|
204
|
+
headers['x-request-timeout'] = customActionTimeout !== null && customActionTimeout !== void 0 ? customActionTimeout : constants_1.DEFAULT_TIMEOUT;
|
|
204
205
|
ctx.log('Starting request', { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
205
206
|
const requestData = {
|
|
206
207
|
timestamp: startRequestTime,
|
|
@@ -228,6 +229,17 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
228
229
|
responseType: config.responseType,
|
|
229
230
|
});
|
|
230
231
|
}
|
|
232
|
+
axiosClient.interceptors.request.use((requestConfig) => {
|
|
233
|
+
var _a;
|
|
234
|
+
requestConfig.headers.set('x-request-attempt',
|
|
235
|
+
// according this issue https://github.com/softonic/axios-retry/issues/167
|
|
236
|
+
// 'axios-retry' doesn`t define retryCount field in exported type
|
|
237
|
+
// however in this issue https://github.com/softonic/axios-retry/issues/75#issuecomment-502151719
|
|
238
|
+
// people use it
|
|
239
|
+
// @ts-ignore
|
|
240
|
+
((_a = requestConfig[constants_1.AXIOS_RETRY_NAMESPACE]) === null || _a === void 0 ? void 0 : _a.retryCount) || 0);
|
|
241
|
+
return requestConfig;
|
|
242
|
+
});
|
|
231
243
|
try {
|
|
232
244
|
const response = await axiosClient.request(requestConfig);
|
|
233
245
|
const responseHeaders = {};
|
package/build/constants.d.ts
CHANGED
package/build/constants.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.DEFAULT_VALIDATION_SCHEMA = exports.RECREATE_SERVICE_CODES = exports.RETRYABLE_STATUS_CODES = exports.ANY_ACTION_SYMBOL = exports.ECMA_STRING_SIZE = 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;
|
|
29
|
+
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_GRPC_OPTIONS = exports.DEFAULT_AXIOS_OPTIONS = exports.DEFAULT_PROXY_HEADERS = exports.DEFAULT_LANG_HEADER = exports.DEFAULT_TIMEOUT = exports.Lang = exports.VERSION = void 0;
|
|
30
30
|
const http_1 = __importDefault(require("http"));
|
|
31
31
|
const https_1 = __importDefault(require("https"));
|
|
32
32
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
@@ -99,3 +99,4 @@ exports.DEFAULT_VALIDATION_SCHEMA = {
|
|
|
99
99
|
],
|
|
100
100
|
},
|
|
101
101
|
};
|
|
102
|
+
exports.AXIOS_RETRY_NAMESPACE = 'axios-retry';
|
package/build/utils/validate.js
CHANGED
|
@@ -29,7 +29,7 @@ function encodePathParams(params) {
|
|
|
29
29
|
}
|
|
30
30
|
exports.encodePathParams = encodePathParams;
|
|
31
31
|
function getPathParam(value) {
|
|
32
|
-
return /^((?!(\.\.|\?|#|\\|\/)).)*$/i.test(value) ? value : '';
|
|
32
|
+
return /^((?!(\.\.|\?|#|\\|\/)).)*$/i.test(value) ? value : 'GATEWAY_INVALID_PARAM_VALUE';
|
|
33
33
|
}
|
|
34
34
|
exports.getPathParam = getPathParam;
|
|
35
35
|
function getPathArgsProxy(args, encodePathArgs) {
|