ibm-cloud-sdk-core 5.0.1 → 5.1.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.
Files changed (98) hide show
  1. package/.secrets.baseline +128 -24
  2. package/Authentication.md +146 -21
  3. package/CHANGELOG.md +14 -0
  4. package/README.md +3 -2
  5. package/auth/authenticators/authenticator.d.ts +1 -0
  6. package/auth/authenticators/authenticator.js +1 -0
  7. package/auth/authenticators/basic-authenticator.d.ts +1 -1
  8. package/auth/authenticators/basic-authenticator.js +3 -1
  9. package/auth/authenticators/bearer-token-authenticator.js +2 -0
  10. package/auth/authenticators/container-authenticator.d.ts +6 -0
  11. package/auth/authenticators/container-authenticator.js +8 -0
  12. package/auth/authenticators/iam-assume-authenticator.d.ts +82 -0
  13. package/auth/authenticators/iam-assume-authenticator.js +92 -0
  14. package/auth/authenticators/iam-authenticator.d.ts +6 -0
  15. package/auth/authenticators/iam-authenticator.js +8 -0
  16. package/auth/authenticators/iam-request-based-authenticator-immutable.d.ts +64 -0
  17. package/auth/authenticators/iam-request-based-authenticator-immutable.js +74 -0
  18. package/auth/authenticators/iam-request-based-authenticator.d.ts +19 -47
  19. package/auth/authenticators/iam-request-based-authenticator.js +28 -36
  20. package/auth/authenticators/index.d.ts +4 -1
  21. package/auth/authenticators/index.js +3 -1
  22. package/auth/authenticators/token-request-based-authenticator-immutable.d.ts +71 -0
  23. package/auth/authenticators/token-request-based-authenticator-immutable.js +91 -0
  24. package/auth/authenticators/token-request-based-authenticator.d.ts +4 -42
  25. package/auth/authenticators/token-request-based-authenticator.js +5 -40
  26. package/auth/token-managers/container-token-manager.d.ts +6 -0
  27. package/auth/token-managers/container-token-manager.js +18 -50
  28. package/auth/token-managers/cp4d-token-manager.js +6 -1
  29. package/auth/token-managers/iam-assume-token-manager.d.ts +101 -0
  30. package/auth/token-managers/iam-assume-token-manager.js +220 -0
  31. package/auth/token-managers/iam-request-based-token-manager.d.ts +3 -9
  32. package/auth/token-managers/iam-request-based-token-manager.js +5 -9
  33. package/auth/token-managers/iam-token-manager.d.ts +8 -2
  34. package/auth/token-managers/iam-token-manager.js +10 -2
  35. package/auth/token-managers/index.d.ts +4 -2
  36. package/auth/token-managers/index.js +6 -3
  37. package/auth/token-managers/mcsp-token-manager.js +6 -1
  38. package/auth/token-managers/token-manager.js +7 -3
  39. package/auth/token-managers/vpc-instance-token-manager.js +4 -1
  40. package/auth/utils/get-authenticator-from-environment.js +3 -0
  41. package/auth/utils/helpers.d.ts +18 -23
  42. package/auth/utils/helpers.js +50 -30
  43. package/auth/utils/read-external-sources.js +2 -0
  44. package/docs/ibm-cloud-sdk-core.api.json +787 -404
  45. package/es/auth/authenticators/authenticator.d.ts +1 -0
  46. package/es/auth/authenticators/authenticator.js +1 -0
  47. package/es/auth/authenticators/basic-authenticator.d.ts +1 -1
  48. package/es/auth/authenticators/basic-authenticator.js +3 -1
  49. package/es/auth/authenticators/bearer-token-authenticator.js +2 -0
  50. package/es/auth/authenticators/container-authenticator.d.ts +6 -0
  51. package/es/auth/authenticators/container-authenticator.js +8 -0
  52. package/es/auth/authenticators/iam-assume-authenticator.d.ts +82 -0
  53. package/es/auth/authenticators/iam-assume-authenticator.js +70 -0
  54. package/es/auth/authenticators/iam-authenticator.d.ts +6 -0
  55. package/es/auth/authenticators/iam-authenticator.js +8 -0
  56. package/es/auth/authenticators/iam-request-based-authenticator-immutable.d.ts +64 -0
  57. package/es/auth/authenticators/iam-request-based-authenticator-immutable.js +51 -0
  58. package/es/auth/authenticators/iam-request-based-authenticator.d.ts +19 -47
  59. package/es/auth/authenticators/iam-request-based-authenticator.js +26 -35
  60. package/es/auth/authenticators/index.d.ts +4 -1
  61. package/es/auth/authenticators/index.js +1 -0
  62. package/es/auth/authenticators/token-request-based-authenticator-immutable.d.ts +71 -0
  63. package/es/auth/authenticators/token-request-based-authenticator-immutable.js +65 -0
  64. package/es/auth/authenticators/token-request-based-authenticator.d.ts +4 -42
  65. package/es/auth/authenticators/token-request-based-authenticator.js +3 -37
  66. package/es/auth/token-managers/container-token-manager.d.ts +6 -0
  67. package/es/auth/token-managers/container-token-manager.js +18 -24
  68. package/es/auth/token-managers/cp4d-token-manager.js +6 -1
  69. package/es/auth/token-managers/iam-assume-token-manager.d.ts +101 -0
  70. package/es/auth/token-managers/iam-assume-token-manager.js +164 -0
  71. package/es/auth/token-managers/iam-request-based-token-manager.d.ts +3 -9
  72. package/es/auth/token-managers/iam-request-based-token-manager.js +5 -9
  73. package/es/auth/token-managers/iam-token-manager.d.ts +8 -2
  74. package/es/auth/token-managers/iam-token-manager.js +10 -2
  75. package/es/auth/token-managers/index.d.ts +4 -2
  76. package/es/auth/token-managers/index.js +4 -2
  77. package/es/auth/token-managers/mcsp-token-manager.js +6 -1
  78. package/es/auth/token-managers/token-manager.js +7 -3
  79. package/es/auth/token-managers/vpc-instance-token-manager.js +4 -1
  80. package/es/auth/utils/get-authenticator-from-environment.js +4 -1
  81. package/es/auth/utils/helpers.d.ts +18 -23
  82. package/es/auth/utils/helpers.js +35 -27
  83. package/es/auth/utils/read-external-sources.js +2 -0
  84. package/es/lib/base-service.js +2 -0
  85. package/es/lib/private-helpers.d.ts +22 -0
  86. package/es/lib/private-helpers.js +58 -0
  87. package/es/lib/request-wrapper.d.ts +43 -1
  88. package/es/lib/request-wrapper.js +113 -14
  89. package/etc/ibm-cloud-sdk-core.api.md +46 -28
  90. package/ibm-cloud-sdk-core.d.ts +306 -68
  91. package/lib/base-service.js +2 -0
  92. package/lib/private-helpers.d.ts +22 -0
  93. package/lib/private-helpers.js +62 -0
  94. package/lib/request-wrapper.d.ts +43 -1
  95. package/lib/request-wrapper.js +113 -14
  96. package/package.json +5 -4
  97. package/sdk-test-utilities/package-lock.json +8 -5
  98. package/sdk-test-utilities/package.json +3 -0
@@ -76,7 +76,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
76
76
  Object.defineProperty(exports, "__esModule", { value: true });
77
77
  exports.RequestWrapper = void 0;
78
78
  /**
79
- * (C) Copyright IBM Corp. 2014, 2023.
79
+ * (C) Copyright IBM Corp. 2014, 2024.
80
80
  *
81
81
  * Licensed under the Apache License, Version 2.0 (the "License");
82
82
  * you may not use this file except in compliance with the License.
@@ -99,6 +99,7 @@ var isstream_1 = __importDefault(require("isstream"));
99
99
  var querystring_1 = require("querystring");
100
100
  var zlib_1 = require("zlib");
101
101
  var helper_1 = require("./helper");
102
+ var private_helpers_1 = require("./private-helpers");
102
103
  var logger_1 = __importDefault(require("./logger"));
103
104
  var stream_to_promise_1 = require("./stream-to-promise");
104
105
  var cookie_support_1 = require("./cookie-support");
@@ -154,28 +155,96 @@ var RequestWrapper = /** @class */ (function () {
154
155
  }
155
156
  this.enableRetries(retryOptions);
156
157
  }
157
- // set debug interceptors
158
- if (process.env.NODE_DEBUG === 'axios' || process.env.DEBUG) {
159
- this.axiosInstance.interceptors.request.use(function (config) {
160
- logger_1.default.debug('Request:');
161
- logger_1.default.debug(config);
162
- return config;
158
+ // If debug logging is requested, set up interceptors to log http request/response messages.
159
+ if (logger_1.default.debug.enabled || process.env.NODE_DEBUG === 'axios') {
160
+ this.axiosInstance.interceptors.request.use(function (request) {
161
+ logger_1.default.debug("--> HTTP Request:\n".concat(_this.formatAxiosRequest(request)));
162
+ return request;
163
163
  }, function (error) {
164
- logger_1.default.error('Error: ');
165
- logger_1.default.error(error);
164
+ logger_1.default.debug("<-- HTTP Error:\n".concat(_this.formatAxiosError(error)));
166
165
  return Promise.reject(error);
167
166
  });
168
167
  this.axiosInstance.interceptors.response.use(function (response) {
169
- logger_1.default.debug('Response:');
170
- logger_1.default.debug(response);
168
+ logger_1.default.debug("<-- HTTP Response:\n".concat(_this.formatAxiosResponse(response)));
171
169
  return response;
172
170
  }, function (error) {
173
- logger_1.default.error('Error: ');
174
- logger_1.default.error(error);
171
+ logger_1.default.debug("<-- HTTP Error:\n".concat(_this.formatAxiosError(error)));
175
172
  return Promise.reject(error);
176
173
  });
177
174
  }
178
175
  }
176
+ /**
177
+ * Formats the specified Axios request for debug logging.
178
+ * @param request - the request to be logged
179
+ * @returns the string representation of the request
180
+ */
181
+ RequestWrapper.prototype.formatAxiosRequest = function (request) {
182
+ var method = request.method, url = request.url, data = request.data, headers = request.headers;
183
+ var headersOutput = this.formatAxiosHeaders(headers);
184
+ var body = this.formatAxiosBody(data);
185
+ var output = "".concat((method || '??').toUpperCase(), " ").concat(url || '??', "\n").concat(headersOutput, "\n").concat(body);
186
+ return (0, private_helpers_1.redactSecrets)(output);
187
+ };
188
+ /**
189
+ * Formats the specified Axios response for debug logging.
190
+ * @param response - the response to be logged
191
+ * @returns the string representation of the response
192
+ */
193
+ RequestWrapper.prototype.formatAxiosResponse = function (response) {
194
+ var status = response.status, statusText = response.statusText, headers = response.headers, data = response.data;
195
+ var headersOutput = this.formatAxiosHeaders(headers);
196
+ var body = this.formatAxiosBody(data);
197
+ var statusMsg = statusText || "status_code_".concat(status);
198
+ var output = "".concat(status, " ").concat(statusMsg, "\n").concat(headersOutput, "\n").concat(body);
199
+ return (0, private_helpers_1.redactSecrets)(output);
200
+ };
201
+ /**
202
+ * Formats the specified Axios error for debug logging.
203
+ * @param error - the error to be logged
204
+ * @returns the string representation of the error
205
+ */
206
+ RequestWrapper.prototype.formatAxiosError = function (error) {
207
+ var response = error.response;
208
+ var output = "HTTP error message=".concat(error.message || '', ", code=").concat(error.code || '');
209
+ if (response) {
210
+ output = this.formatAxiosResponse(response);
211
+ }
212
+ return output;
213
+ };
214
+ /**
215
+ * Formats 'headers' to be included in the debug output
216
+ * like this:
217
+ * Accept: application/json
218
+ * Content-Type: application/json
219
+ * My-Header: my-value
220
+ * ...
221
+ * @param headers - the headers associated with an Axios request or response
222
+ * @returns the formatted output to be included in the HTTP message traces
223
+ */
224
+ RequestWrapper.prototype.formatAxiosHeaders = function (headers) {
225
+ var output = '';
226
+ if (headers) {
227
+ var lines_1 = [];
228
+ Object.keys(headers).forEach(function (key) {
229
+ lines_1.push("".concat(key, ": ").concat(headers[key]));
230
+ });
231
+ output = lines_1.join('\n');
232
+ }
233
+ return output;
234
+ };
235
+ /**
236
+ * Formats 'body' (either a string or object/array) to be included in the debug output
237
+ *
238
+ * @param body - a string, object or array that contains the request or response body
239
+ * @returns the formatted output to be included in the HTTP message traces
240
+ */
241
+ RequestWrapper.prototype.formatAxiosBody = function (body) {
242
+ var output = '';
243
+ if (body) {
244
+ output = typeof body === 'string' ? body : JSON.stringify(body);
245
+ }
246
+ return output;
247
+ };
179
248
  RequestWrapper.prototype.setCompressRequestData = function (setting) {
180
249
  this.compressRequestData = setting;
181
250
  };
@@ -381,7 +450,8 @@ var RequestWrapper = /** @class */ (function () {
381
450
  instance: axiosInstance,
382
451
  backoffType: 'exponential',
383
452
  checkRetryAfter: true,
384
- maxRetryDelay: 30 * 1000, // default to 30 sec max delay
453
+ maxRetryDelay: 30 * 1000,
454
+ shouldRetry: this.retryPolicy,
385
455
  };
386
456
  if (retryOptions) {
387
457
  if (typeof retryOptions.maxRetries === 'number') {
@@ -402,13 +472,42 @@ var RequestWrapper = /** @class */ (function () {
402
472
  }
403
473
  this.raxConfig = RequestWrapper.getRaxConfig(this.axiosInstance, retryOptions);
404
474
  this.retryInterceptorId = rax.attach(this.axiosInstance);
475
+ logger_1.default.debug("Enabled retries; maxRetries=".concat(this.raxConfig.retry, ", maxRetryInterval=").concat(this.raxConfig.maxRetryDelay));
405
476
  };
406
477
  RequestWrapper.prototype.disableRetries = function () {
407
478
  if (typeof this.retryInterceptorId === 'number') {
408
479
  rax.detach(this.retryInterceptorId, this.axiosInstance);
409
480
  delete this.retryInterceptorId;
410
481
  delete this.raxConfig;
482
+ logger_1.default.debug('Disabled retries');
483
+ }
484
+ };
485
+ /**
486
+ * Returns true iff the previously-failed request contained in "error" should be retried.
487
+ * @param error - an AxiosError instance that contains a previously-failed request
488
+ * @returns true iff the request should be retried
489
+ */
490
+ RequestWrapper.retryPolicy = function (error) {
491
+ if (logger_1.default.debug.enabled) {
492
+ var details = [];
493
+ if (error.response) {
494
+ var statusText = error.response.statusText || "";
495
+ details.push("status_code=".concat(error.response.status, " (").concat(statusText, ")"));
496
+ }
497
+ if (error.config) {
498
+ if (error.config.method) {
499
+ details.push("method=".concat(error.config.method.toUpperCase()));
500
+ }
501
+ if (error.config.url) {
502
+ details.push("url=".concat(error.config.url));
503
+ }
504
+ }
505
+ logger_1.default.debug("Considering retry attempt; ".concat(details.join(', ')));
411
506
  }
507
+ // Delegate to the default function defined by retry-axios.
508
+ var shouldRetry = rax.shouldRetryRequest(error);
509
+ logger_1.default.debug("Retry will ".concat(shouldRetry ? '' : 'not ', "be attempted"));
510
+ return shouldRetry;
412
511
  };
413
512
  RequestWrapper.prototype.gzipRequestBody = function (data, headers) {
414
513
  return __awaiter(this, void 0, void 0, function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ibm-cloud-sdk-core",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",
5
5
  "main": "index.js",
6
6
  "typings": "./es/index.d.ts",
@@ -51,7 +51,8 @@
51
51
  "tough-cookie": "^4.1.3"
52
52
  },
53
53
  "overrides": {
54
- "semver": "^7.5.3"
54
+ "semver": "^7.5.3",
55
+ "micromatch": "4.0.8"
55
56
  },
56
57
  "browser": {
57
58
  "./auth/utils/read-credentials-file": "./auth/utils/read-credentials-file.browser"
@@ -60,13 +61,13 @@
60
61
  "node": ">=18"
61
62
  },
62
63
  "scripts": {
63
- "clean": "rm -fr node_modules",
64
+ "clean": "rm -fr node_modules sdk-test-utilities/node_modules",
64
65
  "commitmsg": "commitlint -E GIT_PARAMS",
65
66
  "eslint:config": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
66
67
  "eslint:fix": "eslint . --fix",
67
68
  "eslint:check": "eslint . --cache",
68
69
  "lint": "npm run eslint:check",
69
- "lint:fix": "npm run eslint:fix",
70
+ "fix": "npm run eslint:fix",
70
71
  "jest": "jest",
71
72
  "test": "jest test/unit/",
72
73
  "test-travis": "jest --runInBand test/unit/",
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "@ibm-cloud/sdk-test-utilities",
3
- "version": "0.0.1",
3
+ "version": "1.0.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@ibm-cloud/sdk-test-utilities",
9
- "version": "0.0.1",
9
+ "version": "1.0.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "expect": "^29.7.0"
13
+ },
14
+ "engines": {
15
+ "node": ">=18"
13
16
  }
14
17
  },
15
18
  "node_modules/@babel/code-frame": {
@@ -410,9 +413,9 @@
410
413
  "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
411
414
  },
412
415
  "node_modules/micromatch": {
413
- "version": "4.0.7",
414
- "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz",
415
- "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==",
416
+ "version": "4.0.8",
417
+ "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
418
+ "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
416
419
  "dependencies": {
417
420
  "braces": "^3.0.3",
418
421
  "picomatch": "^2.3.1"
@@ -11,6 +11,9 @@
11
11
  "dependencies": {
12
12
  "expect": "^29.7.0"
13
13
  },
14
+ "overrides": {
15
+ "micromatch": "4.0.8"
16
+ },
14
17
  "engines": {
15
18
  "node": ">=18"
16
19
  }