ibm-cloud-sdk-core 2.12.1 → 2.14.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/.secrets.baseline CHANGED
@@ -3,7 +3,7 @@
3
3
  "files": "package-lock.json|^.secrets.baseline$",
4
4
  "lines": null
5
5
  },
6
- "generated_at": "2021-08-05T20:39:19Z",
6
+ "generated_at": "2021-08-17T20:14:30Z",
7
7
  "plugins_used": [
8
8
  {
9
9
  "name": "AWSKeyDetector"
@@ -323,6 +323,14 @@
323
323
  "line_number": 29,
324
324
  "type": "Secret Keyword",
325
325
  "verified_result": null
326
+ },
327
+ {
328
+ "hashed_secret": "e38ad214943daad1d64c102faec29de4afe9da3d",
329
+ "is_secret": false,
330
+ "is_verified": false,
331
+ "line_number": 36,
332
+ "type": "Secret Keyword",
333
+ "verified_result": null
326
334
  }
327
335
  ],
328
336
  "test/resources/vcap.json": [
@@ -492,7 +500,7 @@
492
500
  "hashed_secret": "407bb564bd0e4d31368cb53004c9c42adf8f7be8",
493
501
  "is_secret": false,
494
502
  "is_verified": false,
495
- "line_number": 163,
503
+ "line_number": 174,
496
504
  "type": "Secret Keyword",
497
505
  "verified_result": null
498
506
  },
@@ -500,7 +508,7 @@
500
508
  "hashed_secret": "2863fa4b5510c46afc2bd2998dfbc0cf3d6df032",
501
509
  "is_secret": false,
502
510
  "is_verified": false,
503
- "line_number": 189,
511
+ "line_number": 200,
504
512
  "type": "Secret Keyword",
505
513
  "verified_result": null
506
514
  },
@@ -508,7 +516,7 @@
508
516
  "hashed_secret": "ed8c99e906cf3fdbae90a71e06142ebc72b4c056",
509
517
  "is_secret": false,
510
518
  "is_verified": false,
511
- "line_number": 207,
519
+ "line_number": 218,
512
520
  "type": "Secret Keyword",
513
521
  "verified_result": null
514
522
  }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [2.14.1](https://github.com/IBM/node-sdk-core/compare/v2.14.0...v2.14.1) (2021-08-31)
2
+
3
+
4
+ ### Performance Improvements
5
+
6
+ * 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))
7
+
8
+ # [2.14.0](https://github.com/IBM/node-sdk-core/compare/v2.13.0...v2.14.0) (2021-08-27)
9
+
10
+
11
+ ### Features
12
+
13
+ * add enableRetries and disableRetries ([#156](https://github.com/IBM/node-sdk-core/issues/156)) ([d6f12e7](https://github.com/IBM/node-sdk-core/commit/d6f12e76c91f9f0ddce4fef09f5ff024ca3947bc))
14
+
15
+ # [2.13.0](https://github.com/IBM/node-sdk-core/compare/v2.12.2...v2.13.0) (2021-08-18)
16
+
17
+
18
+ ### Features
19
+
20
+ * add method `getHttpClient` to get underlying axios instance of base service ([#155](https://github.com/IBM/node-sdk-core/issues/155)) ([2aede01](https://github.com/IBM/node-sdk-core/commit/2aede013cd398a2605fd67c0412e6ca5669c415e))
21
+
22
+ ## [2.12.2](https://github.com/IBM/node-sdk-core/compare/v2.12.1...v2.12.2) (2021-08-13)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * support 'AUTHTYPE' as alias for 'AUTH_TYPE' config property ([#153](https://github.com/IBM/node-sdk-core/issues/153)) ([fccf209](https://github.com/IBM/node-sdk-core/commit/fccf2093874835d9c77c08843809b79e57fb0e78))
28
+
1
29
  ## [2.12.1](https://github.com/IBM/node-sdk-core/compare/v2.12.0...v2.12.1) (2021-08-11)
2
30
 
3
31
 
@@ -53,6 +53,10 @@ function getAuthenticatorFromEnvironment(serviceName) {
53
53
  // if an apikey is provided, default to IAM
54
54
  // if not, default to container auth
55
55
  var authType = credentials.authType;
56
+ if (!authType) {
57
+ // Support the alternate "AUTHTYPE" config property.
58
+ authType = credentials.authtype;
59
+ }
56
60
  if (!authType || typeof authType !== 'string') {
57
61
  authType = credentials.apikey ? 'iam' : 'container';
58
62
  }
@@ -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
  /**
@@ -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: any;
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.
@@ -88,6 +92,21 @@ export declare class BaseService {
88
92
  * @param {boolean} setting Will turn it on if 'true', off if 'false'.
89
93
  */
90
94
  setEnableGzipCompression(setting: boolean): void;
95
+ /**
96
+ * Get the Axios instance set on the service.
97
+ * All requests will be made using this instance.
98
+ */
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;
91
110
  /**
92
111
  * Configure the service using external configuration
93
112
  *
@@ -109,10 +109,31 @@ 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.compressRequestData = setting;
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
  };
116
+ /**
117
+ * Get the Axios instance set on the service.
118
+ * All requests will be made using this instance.
119
+ */
120
+ BaseService.prototype.getHttpClient = function () {
121
+ return this.requestWrapperInstance.getHttpClient();
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
+ };
116
137
  /**
117
138
  * Configure the service using external configuration
118
139
  *
@@ -171,7 +192,7 @@ var BaseService = /** @class */ (function () {
171
192
  // - url
172
193
  // - disableSsl
173
194
  // - enableGzip
174
- 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;
175
196
  if (url) {
176
197
  results.serviceUrl = helper_1.stripTrailingSlash(url);
177
198
  }
@@ -181,6 +202,15 @@ var BaseService = /** @class */ (function () {
181
202
  if (enableGzip === true) {
182
203
  results.enableGzipCompression = enableGzip;
183
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
+ }
184
214
  }
185
215
  return results;
186
216
  };
@@ -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,5 +52,9 @@ export declare class RequestWrapper {
20
52
  * @returns {Error}
21
53
  */
22
54
  formatError(axiosError: any): Error;
55
+ getHttpClient(): AxiosInstance;
56
+ private static getRaxConfig;
57
+ enableRetries(retryOptions?: RetryOptions): void;
58
+ disableRetries(): void;
23
59
  private gzipRequestBody;
24
60
  }
@@ -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: Infinity,
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
- res.result = res.data;
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;
@@ -342,6 +359,45 @@ var RequestWrapper = /** @class */ (function () {
342
359
  }
343
360
  return error;
344
361
  };
362
+ RequestWrapper.prototype.getHttpClient = function () {
363
+ return this.axiosInstance;
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
+ };
345
401
  RequestWrapper.prototype.gzipRequestBody = function (data, headers) {
346
402
  return __awaiter(this, void 0, void 0, function () {
347
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.12.1",
3
+ "version": "2.14.1",
4
4
  "description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",
5
5
  "main": "index",
6
6
  "repository": {
@@ -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,