ibm-cloud-sdk-core 2.13.0 → 2.14.3
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/CHANGELOG.md +28 -0
- package/README.md +1 -1
- package/auth/utils/read-external-sources.js +9 -0
- package/lib/base-service.d.ts +16 -2
- package/lib/base-service.js +25 -2
- package/lib/request-wrapper.d.ts +36 -1
- package/lib/request-wrapper.js +55 -2
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [2.14.3](https://github.com/IBM/node-sdk-core/compare/v2.14.2...v2.14.3) (2021-09-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **build:** update dependencies ([#161](https://github.com/IBM/node-sdk-core/issues/161)) ([8a37ef0](https://github.com/IBM/node-sdk-core/commit/8a37ef030c5ea793e79ea451043f71cd860ff14b))
|
|
7
|
+
|
|
8
|
+
## [2.14.2](https://github.com/IBM/node-sdk-core/compare/v2.14.1...v2.14.2) (2021-09-09)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **build:** bump axios to 0.21.4 to avoid vulnerabilities ([#160](https://github.com/IBM/node-sdk-core/issues/160)) ([12a6c5b](https://github.com/IBM/node-sdk-core/commit/12a6c5b799ff349c9e5ad12df8f383f4f673417d))
|
|
14
|
+
|
|
15
|
+
## [2.14.1](https://github.com/IBM/node-sdk-core/compare/v2.14.0...v2.14.1) (2021-08-31)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Performance Improvements
|
|
19
|
+
|
|
20
|
+
* use maxContentLength -1 instead of Infinity ([#158](https://github.com/IBM/node-sdk-core/issues/158)) ([adbbb3b](https://github.com/IBM/node-sdk-core/commit/adbbb3bceb388b34753f9fe3579eec3f0520ddb3))
|
|
21
|
+
|
|
22
|
+
# [2.14.0](https://github.com/IBM/node-sdk-core/compare/v2.13.0...v2.14.0) (2021-08-27)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* add enableRetries and disableRetries ([#156](https://github.com/IBM/node-sdk-core/issues/156)) ([d6f12e7](https://github.com/IBM/node-sdk-core/commit/d6f12e76c91f9f0ddce4fef09f5ff024ca3947bc))
|
|
28
|
+
|
|
1
29
|
# [2.13.0](https://github.com/IBM/node-sdk-core/compare/v2.12.2...v2.13.0) (2021-08-18)
|
|
2
30
|
|
|
3
31
|
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://travis-ci.com/IBM/node-sdk-core)
|
|
1
|
+
[](https://app.travis-ci.com/IBM/node-sdk-core)
|
|
2
2
|
[](https://www.npmjs.com/package/ibm-cloud-sdk-core)
|
|
3
3
|
[](https://codecov.io/gh/IBM/node-sdk-core)
|
|
4
4
|
[](https://github.com/semantic-release/semantic-release)
|
|
@@ -83,6 +83,15 @@ function filterPropertiesByServiceName(envObj, serviceName) {
|
|
|
83
83
|
if (typeof credentials.enableGzip === 'string') {
|
|
84
84
|
credentials.enableGzip = credentials.enableGzip === 'true';
|
|
85
85
|
}
|
|
86
|
+
if (typeof credentials.enableRetries === 'string') {
|
|
87
|
+
credentials.enableRetries = credentials.enableRetries === 'true';
|
|
88
|
+
}
|
|
89
|
+
if (typeof credentials.maxRetries === 'string') {
|
|
90
|
+
credentials.maxRetries = parseInt(credentials.maxRetries, 10);
|
|
91
|
+
}
|
|
92
|
+
if (typeof credentials.retryInterval === 'string') {
|
|
93
|
+
credentials.retryInterval = parseInt(credentials.retryInterval, 10);
|
|
94
|
+
}
|
|
86
95
|
return credentials;
|
|
87
96
|
}
|
|
88
97
|
/**
|
package/lib/base-service.d.ts
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
/// <reference types="node" />
|
|
17
17
|
import { OutgoingHttpHeaders } from 'http';
|
|
18
18
|
import { AuthenticatorInterface } from '../auth';
|
|
19
|
+
import { RetryOptions } from './request-wrapper';
|
|
19
20
|
/**
|
|
20
21
|
* Configuration values for a service.
|
|
21
22
|
*/
|
|
@@ -42,7 +43,10 @@ export interface UserOptions {
|
|
|
42
43
|
*/
|
|
43
44
|
export interface BaseServiceOptions extends UserOptions {
|
|
44
45
|
/** Querystring to be sent with every request. If not a string will be stringified. */
|
|
45
|
-
qs
|
|
46
|
+
qs?: any;
|
|
47
|
+
enableRetries?: boolean;
|
|
48
|
+
maxRetries?: number;
|
|
49
|
+
retryInterval?: number;
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
48
52
|
* Common functionality shared by generated service classes.
|
|
@@ -92,7 +96,17 @@ export declare class BaseService {
|
|
|
92
96
|
* Get the Axios instance set on the service.
|
|
93
97
|
* All requests will be made using this instance.
|
|
94
98
|
*/
|
|
95
|
-
getHttpClient():
|
|
99
|
+
getHttpClient(): import("axios").AxiosInstance;
|
|
100
|
+
/**
|
|
101
|
+
* Enable retries for unfulfilled requests.
|
|
102
|
+
*
|
|
103
|
+
* @param {RetryOptions} retryOptions configuration for retries
|
|
104
|
+
*/
|
|
105
|
+
enableRetries(retryOptions?: RetryOptions): void;
|
|
106
|
+
/**
|
|
107
|
+
* Disables retries.
|
|
108
|
+
*/
|
|
109
|
+
disableRetries(): void;
|
|
96
110
|
/**
|
|
97
111
|
* Configure the service using external configuration
|
|
98
112
|
*
|
package/lib/base-service.js
CHANGED
|
@@ -109,7 +109,7 @@ var BaseService = /** @class */ (function () {
|
|
|
109
109
|
* @param {boolean} setting Will turn it on if 'true', off if 'false'.
|
|
110
110
|
*/
|
|
111
111
|
BaseService.prototype.setEnableGzipCompression = function (setting) {
|
|
112
|
-
this.requestWrapperInstance.
|
|
112
|
+
this.requestWrapperInstance.setCompressRequestData(setting);
|
|
113
113
|
// persist setting so that baseOptions accurately reflects the state of the flag
|
|
114
114
|
this.baseOptions.enableGzipCompression = setting;
|
|
115
115
|
};
|
|
@@ -120,6 +120,20 @@ var BaseService = /** @class */ (function () {
|
|
|
120
120
|
BaseService.prototype.getHttpClient = function () {
|
|
121
121
|
return this.requestWrapperInstance.getHttpClient();
|
|
122
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* Enable retries for unfulfilled requests.
|
|
125
|
+
*
|
|
126
|
+
* @param {RetryOptions} retryOptions configuration for retries
|
|
127
|
+
*/
|
|
128
|
+
BaseService.prototype.enableRetries = function (retryOptions) {
|
|
129
|
+
this.requestWrapperInstance.enableRetries(retryOptions);
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Disables retries.
|
|
133
|
+
*/
|
|
134
|
+
BaseService.prototype.disableRetries = function () {
|
|
135
|
+
this.requestWrapperInstance.disableRetries();
|
|
136
|
+
};
|
|
123
137
|
/**
|
|
124
138
|
* Configure the service using external configuration
|
|
125
139
|
*
|
|
@@ -178,7 +192,7 @@ var BaseService = /** @class */ (function () {
|
|
|
178
192
|
// - url
|
|
179
193
|
// - disableSsl
|
|
180
194
|
// - enableGzip
|
|
181
|
-
var url = properties.url, disableSsl = properties.disableSsl, enableGzip = properties.enableGzip;
|
|
195
|
+
var url = properties.url, disableSsl = properties.disableSsl, enableGzip = properties.enableGzip, enableRetries = properties.enableRetries, maxRetries = properties.maxRetries, retryInterval = properties.retryInterval;
|
|
182
196
|
if (url) {
|
|
183
197
|
results.serviceUrl = helper_1.stripTrailingSlash(url);
|
|
184
198
|
}
|
|
@@ -188,6 +202,15 @@ var BaseService = /** @class */ (function () {
|
|
|
188
202
|
if (enableGzip === true) {
|
|
189
203
|
results.enableGzipCompression = enableGzip;
|
|
190
204
|
}
|
|
205
|
+
if (enableRetries !== undefined) {
|
|
206
|
+
results.enableRetries = enableRetries;
|
|
207
|
+
}
|
|
208
|
+
if (maxRetries !== undefined) {
|
|
209
|
+
results.maxRetries = maxRetries;
|
|
210
|
+
}
|
|
211
|
+
if (retryInterval !== undefined) {
|
|
212
|
+
results.retryInterval = retryInterval;
|
|
213
|
+
}
|
|
191
214
|
}
|
|
192
215
|
return results;
|
|
193
216
|
};
|
package/lib/request-wrapper.d.ts
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2014 IBM Corp. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { AxiosInstance } from 'axios';
|
|
17
|
+
/**
|
|
18
|
+
* Retry configuration options.
|
|
19
|
+
*/
|
|
20
|
+
export interface RetryOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Maximum retries to attempt.
|
|
23
|
+
*/
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Ceiling for the retry delay (in seconds) - delay will not exceed this value.
|
|
27
|
+
*/
|
|
28
|
+
maxRetryInterval?: number;
|
|
29
|
+
}
|
|
1
30
|
export declare class RequestWrapper {
|
|
2
31
|
private axiosInstance;
|
|
3
32
|
private compressRequestData;
|
|
33
|
+
private retryInterceptorId;
|
|
34
|
+
private raxConfig;
|
|
4
35
|
constructor(axiosOptions?: any);
|
|
36
|
+
setCompressRequestData(setting: boolean): void;
|
|
5
37
|
/**
|
|
6
38
|
* Creates the request.
|
|
7
39
|
* 1. Merge default options with user provided options
|
|
@@ -20,6 +52,9 @@ export declare class RequestWrapper {
|
|
|
20
52
|
* @returns {Error}
|
|
21
53
|
*/
|
|
22
54
|
formatError(axiosError: any): Error;
|
|
23
|
-
getHttpClient():
|
|
55
|
+
getHttpClient(): AxiosInstance;
|
|
56
|
+
private static getRaxConfig;
|
|
57
|
+
enableRetries(retryOptions?: RetryOptions): void;
|
|
58
|
+
disableRetries(): void;
|
|
24
59
|
private gzipRequestBody;
|
|
25
60
|
}
|
package/lib/request-wrapper.js
CHANGED
|
@@ -64,6 +64,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
64
64
|
* limitations under the License.
|
|
65
65
|
*/
|
|
66
66
|
var axios_1 = require("axios");
|
|
67
|
+
var rax = require("retry-axios");
|
|
67
68
|
var axios_cookiejar_support_1 = require("axios-cookiejar-support");
|
|
68
69
|
var extend = require("extend");
|
|
69
70
|
var FormData = require("form-data");
|
|
@@ -83,7 +84,7 @@ var RequestWrapper = /** @class */ (function () {
|
|
|
83
84
|
// to 'application/x-www-form-urlencoded'. This causes problems, so overriding the
|
|
84
85
|
// defaults here
|
|
85
86
|
var axiosConfig = {
|
|
86
|
-
maxContentLength:
|
|
87
|
+
maxContentLength: -1,
|
|
87
88
|
maxBodyLength: Infinity,
|
|
88
89
|
headers: {
|
|
89
90
|
post: {
|
|
@@ -123,6 +124,17 @@ var RequestWrapper = /** @class */ (function () {
|
|
|
123
124
|
this.axiosInstance.defaults.withCredentials = true;
|
|
124
125
|
this.axiosInstance.defaults.jar = axiosOptions.jar;
|
|
125
126
|
}
|
|
127
|
+
// get retry config properties and conditionally enable retries
|
|
128
|
+
if (axiosOptions.enableRetries) {
|
|
129
|
+
var retryOptions = {};
|
|
130
|
+
if (axiosOptions.maxRetries !== undefined) {
|
|
131
|
+
retryOptions.maxRetries = axiosOptions.maxRetries;
|
|
132
|
+
}
|
|
133
|
+
if (axiosOptions.retryInterval !== undefined) {
|
|
134
|
+
retryOptions.maxRetryInterval = axiosOptions.retryInterval;
|
|
135
|
+
}
|
|
136
|
+
this.enableRetries(retryOptions);
|
|
137
|
+
}
|
|
126
138
|
// set debug interceptors
|
|
127
139
|
if (process.env.NODE_DEBUG === 'axios' || process.env.DEBUG) {
|
|
128
140
|
this.axiosInstance.interceptors.request.use(function (config) {
|
|
@@ -165,6 +177,9 @@ var RequestWrapper = /** @class */ (function () {
|
|
|
165
177
|
});
|
|
166
178
|
}
|
|
167
179
|
}
|
|
180
|
+
RequestWrapper.prototype.setCompressRequestData = function (setting) {
|
|
181
|
+
this.compressRequestData = setting;
|
|
182
|
+
};
|
|
168
183
|
/**
|
|
169
184
|
* Creates the request.
|
|
170
185
|
* 1. Merge default options with user provided options
|
|
@@ -253,6 +268,7 @@ var RequestWrapper = /** @class */ (function () {
|
|
|
253
268
|
headers: headers,
|
|
254
269
|
params: qs,
|
|
255
270
|
data: data,
|
|
271
|
+
raxConfig: this.raxConfig,
|
|
256
272
|
responseType: options.responseType || 'json',
|
|
257
273
|
paramsSerializer: function (params) { return querystring.stringify(params); },
|
|
258
274
|
};
|
|
@@ -266,7 +282,8 @@ var RequestWrapper = /** @class */ (function () {
|
|
|
266
282
|
delete res.config;
|
|
267
283
|
delete res.request;
|
|
268
284
|
// the other sdks use the interface `result` for the body
|
|
269
|
-
|
|
285
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
286
|
+
res['result'] = res.data;
|
|
270
287
|
delete res.data;
|
|
271
288
|
// return another promise that resolves with 'res' to be handled in generated code
|
|
272
289
|
return res;
|
|
@@ -345,6 +362,42 @@ var RequestWrapper = /** @class */ (function () {
|
|
|
345
362
|
RequestWrapper.prototype.getHttpClient = function () {
|
|
346
363
|
return this.axiosInstance;
|
|
347
364
|
};
|
|
365
|
+
RequestWrapper.getRaxConfig = function (axiosInstance, retryOptions) {
|
|
366
|
+
var config = {
|
|
367
|
+
retry: 4,
|
|
368
|
+
retryDelay: 1000,
|
|
369
|
+
instance: axiosInstance,
|
|
370
|
+
backoffType: 'exponential',
|
|
371
|
+
checkRetryAfter: true,
|
|
372
|
+
maxRetryDelay: 30 * 1000,
|
|
373
|
+
};
|
|
374
|
+
if (retryOptions) {
|
|
375
|
+
if (typeof retryOptions.maxRetries === 'number') {
|
|
376
|
+
config.retry = retryOptions.maxRetries;
|
|
377
|
+
}
|
|
378
|
+
if (typeof retryOptions.maxRetryInterval === 'number') {
|
|
379
|
+
// convert seconds to ms for retry-axios
|
|
380
|
+
config.maxRetryDelay = retryOptions.maxRetryInterval * 1000;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return config;
|
|
384
|
+
};
|
|
385
|
+
RequestWrapper.prototype.enableRetries = function (retryOptions) {
|
|
386
|
+
// avoid attaching the same interceptor multiple times
|
|
387
|
+
// to protect against user error and ensure disableRetries() always disables retries
|
|
388
|
+
if (typeof this.retryInterceptorId === 'number') {
|
|
389
|
+
this.disableRetries();
|
|
390
|
+
}
|
|
391
|
+
this.raxConfig = RequestWrapper.getRaxConfig(this.axiosInstance, retryOptions);
|
|
392
|
+
this.retryInterceptorId = rax.attach(this.axiosInstance);
|
|
393
|
+
};
|
|
394
|
+
RequestWrapper.prototype.disableRetries = function () {
|
|
395
|
+
if (typeof this.retryInterceptorId === 'number') {
|
|
396
|
+
rax.detach(this.retryInterceptorId, this.axiosInstance);
|
|
397
|
+
delete this.retryInterceptorId;
|
|
398
|
+
delete this.raxConfig;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
348
401
|
RequestWrapper.prototype.gzipRequestBody = function (data, headers) {
|
|
349
402
|
return __awaiter(this, void 0, void 0, function () {
|
|
350
403
|
var contentSetToGzip, reqBuffer, _a, _b, err_1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ibm-cloud-sdk-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.3",
|
|
4
4
|
"description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",
|
|
5
5
|
"main": "index",
|
|
6
6
|
"repository": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@types/isstream": "^0.1.0",
|
|
38
38
|
"@types/node": "~10.14.19",
|
|
39
39
|
"@types/tough-cookie": "^4.0.0",
|
|
40
|
-
"axios": "^0.21.
|
|
40
|
+
"axios": "^0.21.4",
|
|
41
41
|
"axios-cookiejar-support": "^1.0.0",
|
|
42
42
|
"camelcase": "^5.3.1",
|
|
43
43
|
"debug": "^4.1.1",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"mime-types": "~2.1.18",
|
|
53
53
|
"object.omit": "~3.0.0",
|
|
54
54
|
"object.pick": "~1.3.0",
|
|
55
|
+
"retry-axios": "^2.6.0",
|
|
55
56
|
"semver": "^6.2.0",
|
|
56
57
|
"tough-cookie": "^4.0.0"
|
|
57
58
|
},
|
|
@@ -74,7 +75,8 @@
|
|
|
74
75
|
"test-travis": "jest --runInBand test/unit/",
|
|
75
76
|
"report-coverage": "codecov",
|
|
76
77
|
"build": "tsc",
|
|
77
|
-
"postversion": "tsc-publish --no-checks --dry-run"
|
|
78
|
+
"postversion": "tsc-publish --no-checks --dry-run",
|
|
79
|
+
"all": "npm run build && npm run test && npm run lint"
|
|
78
80
|
},
|
|
79
81
|
"jest": {
|
|
80
82
|
"collectCoverage": true,
|