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
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  /**
12
- * (C) Copyright IBM Corp. 2014, 2023.
12
+ * (C) Copyright IBM Corp. 2014, 2024.
13
13
  *
14
14
  * Licensed under the Apache License, Version 2.0 (the "License");
15
15
  * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import isStream from 'isstream';
32
32
  import { stringify } from 'querystring';
33
33
  import { gzipSync } from 'zlib';
34
34
  import { buildRequestFileObject, isEmptyObject, isFileData, isFileWithMetadata, isJsonMimeType, stripTrailingSlash, } from './helper';
35
+ import { redactSecrets } from './private-helpers';
35
36
  import logger from './logger';
36
37
  import { streamToPromise } from './stream-to-promise';
37
38
  import { createCookieInterceptor } from './cookie-support';
@@ -86,28 +87,96 @@ export class RequestWrapper {
86
87
  }
87
88
  this.enableRetries(retryOptions);
88
89
  }
89
- // set debug interceptors
90
- if (process.env.NODE_DEBUG === 'axios' || process.env.DEBUG) {
91
- this.axiosInstance.interceptors.request.use((config) => {
92
- logger.debug('Request:');
93
- logger.debug(config);
94
- return config;
90
+ // If debug logging is requested, set up interceptors to log http request/response messages.
91
+ if (logger.debug.enabled || process.env.NODE_DEBUG === 'axios') {
92
+ this.axiosInstance.interceptors.request.use((request) => {
93
+ logger.debug(`--> HTTP Request:\n${this.formatAxiosRequest(request)}`);
94
+ return request;
95
95
  }, (error) => {
96
- logger.error('Error: ');
97
- logger.error(error);
96
+ logger.debug(`<-- HTTP Error:\n${this.formatAxiosError(error)}`);
98
97
  return Promise.reject(error);
99
98
  });
100
99
  this.axiosInstance.interceptors.response.use((response) => {
101
- logger.debug('Response:');
102
- logger.debug(response);
100
+ logger.debug(`<-- HTTP Response:\n${this.formatAxiosResponse(response)}`);
103
101
  return response;
104
102
  }, (error) => {
105
- logger.error('Error: ');
106
- logger.error(error);
103
+ logger.debug(`<-- HTTP Error:\n${this.formatAxiosError(error)}`);
107
104
  return Promise.reject(error);
108
105
  });
109
106
  }
110
107
  }
108
+ /**
109
+ * Formats the specified Axios request for debug logging.
110
+ * @param request - the request to be logged
111
+ * @returns the string representation of the request
112
+ */
113
+ formatAxiosRequest(request) {
114
+ const { method, url, data, headers } = request;
115
+ const headersOutput = this.formatAxiosHeaders(headers);
116
+ const body = this.formatAxiosBody(data);
117
+ const output = `${(method || '??').toUpperCase()} ${url || '??'}\n${headersOutput}\n${body}`;
118
+ return redactSecrets(output);
119
+ }
120
+ /**
121
+ * Formats the specified Axios response for debug logging.
122
+ * @param response - the response to be logged
123
+ * @returns the string representation of the response
124
+ */
125
+ formatAxiosResponse(response) {
126
+ const { status, statusText, headers, data } = response;
127
+ const headersOutput = this.formatAxiosHeaders(headers);
128
+ const body = this.formatAxiosBody(data);
129
+ const statusMsg = statusText || `status_code_${status}`;
130
+ const output = `${status} ${statusMsg}\n${headersOutput}\n${body}`;
131
+ return redactSecrets(output);
132
+ }
133
+ /**
134
+ * Formats the specified Axios error for debug logging.
135
+ * @param error - the error to be logged
136
+ * @returns the string representation of the error
137
+ */
138
+ formatAxiosError(error) {
139
+ const { response } = error;
140
+ let output = `HTTP error message=${error.message || ''}, code=${error.code || ''}`;
141
+ if (response) {
142
+ output = this.formatAxiosResponse(response);
143
+ }
144
+ return output;
145
+ }
146
+ /**
147
+ * Formats 'headers' to be included in the debug output
148
+ * like this:
149
+ * Accept: application/json
150
+ * Content-Type: application/json
151
+ * My-Header: my-value
152
+ * ...
153
+ * @param headers - the headers associated with an Axios request or response
154
+ * @returns the formatted output to be included in the HTTP message traces
155
+ */
156
+ formatAxiosHeaders(headers) {
157
+ let output = '';
158
+ if (headers) {
159
+ const lines = [];
160
+ Object.keys(headers).forEach((key) => {
161
+ lines.push(`${key}: ${headers[key]}`);
162
+ });
163
+ output = lines.join('\n');
164
+ }
165
+ return output;
166
+ }
167
+ /**
168
+ * Formats 'body' (either a string or object/array) to be included in the debug output
169
+ *
170
+ * @param body - a string, object or array that contains the request or response body
171
+ * @returns the formatted output to be included in the HTTP message traces
172
+ */
173
+ formatAxiosBody(body) {
174
+ let output = '';
175
+ if (body) {
176
+ output = typeof body === 'string' ? body : JSON.stringify(body);
177
+ }
178
+ return output;
179
+ }
111
180
  setCompressRequestData(setting) {
112
181
  this.compressRequestData = setting;
113
182
  }
@@ -293,7 +362,8 @@ export class RequestWrapper {
293
362
  instance: axiosInstance,
294
363
  backoffType: 'exponential',
295
364
  checkRetryAfter: true,
296
- maxRetryDelay: 30 * 1000, // default to 30 sec max delay
365
+ maxRetryDelay: 30 * 1000,
366
+ shouldRetry: this.retryPolicy,
297
367
  };
298
368
  if (retryOptions) {
299
369
  if (typeof retryOptions.maxRetries === 'number') {
@@ -314,13 +384,42 @@ export class RequestWrapper {
314
384
  }
315
385
  this.raxConfig = RequestWrapper.getRaxConfig(this.axiosInstance, retryOptions);
316
386
  this.retryInterceptorId = rax.attach(this.axiosInstance);
387
+ logger.debug(`Enabled retries; maxRetries=${this.raxConfig.retry}, maxRetryInterval=${this.raxConfig.maxRetryDelay}`);
317
388
  }
318
389
  disableRetries() {
319
390
  if (typeof this.retryInterceptorId === 'number') {
320
391
  rax.detach(this.retryInterceptorId, this.axiosInstance);
321
392
  delete this.retryInterceptorId;
322
393
  delete this.raxConfig;
394
+ logger.debug('Disabled retries');
395
+ }
396
+ }
397
+ /**
398
+ * Returns true iff the previously-failed request contained in "error" should be retried.
399
+ * @param error - an AxiosError instance that contains a previously-failed request
400
+ * @returns true iff the request should be retried
401
+ */
402
+ static retryPolicy(error) {
403
+ if (logger.debug.enabled) {
404
+ const details = [];
405
+ if (error.response) {
406
+ const statusText = error.response.statusText || ``;
407
+ details.push(`status_code=${error.response.status} (${statusText})`);
408
+ }
409
+ if (error.config) {
410
+ if (error.config.method) {
411
+ details.push(`method=${error.config.method.toUpperCase()}`);
412
+ }
413
+ if (error.config.url) {
414
+ details.push(`url=${error.config.url}`);
415
+ }
416
+ }
417
+ logger.debug(`Considering retry attempt; ${details.join(', ')}`);
323
418
  }
419
+ // Delegate to the default function defined by retry-axios.
420
+ const shouldRetry = rax.shouldRetryRequest(error);
421
+ logger.debug(`Retry will ${shouldRetry ? '' : 'not '}be attempted`);
422
+ return shouldRetry;
324
423
  }
325
424
  gzipRequestBody(data, headers) {
326
425
  return __awaiter(this, void 0, void 0, function* () {
@@ -13,10 +13,10 @@ import { OutgoingHttpHeaders } from 'http';
13
13
  import { Stream } from 'stream';
14
14
 
15
15
  // @public
16
- export function atLeastOne(a: any, b: any): boolean;
16
+ export function atLeastOne(...args: any): boolean;
17
17
 
18
18
  // @public
19
- export function atMostOne(a: any, b: any): boolean;
19
+ export function atMostOne(...args: any): boolean;
20
20
 
21
21
  // @public
22
22
  export class Authenticator implements AuthenticatorInterface {
@@ -34,6 +34,8 @@ export class Authenticator implements AuthenticatorInterface {
34
34
  // (undocumented)
35
35
  static AUTHTYPE_IAM: string;
36
36
  // (undocumented)
37
+ static AUTHTYPE_IAM_ASSUME: string;
38
+ // (undocumented)
37
39
  static AUTHTYPE_MCSP: string;
38
40
  // (undocumented)
39
41
  static AUTHTYPE_NOAUTH: string;
@@ -130,6 +132,7 @@ export class ContainerAuthenticator extends IamRequestBasedAuthenticator {
130
132
  // Warning: (ae-forgotten-export) The symbol "Options_8" needs to be exported by the entry point index.d.ts
131
133
  constructor(options: Options_8);
132
134
  authenticationType(): string;
135
+ getRefreshToken(): string;
133
136
  setCrTokenFilename(crTokenFilename: string): void;
134
137
  setIamProfileId(iamProfileId: string): void;
135
138
  setIamProfileName(iamProfileName: string): void;
@@ -142,6 +145,7 @@ export class ContainerTokenManager extends IamRequestBasedTokenManager {
142
145
  // Warning: (ae-forgotten-export) The symbol "Options_7" needs to be exported by the entry point index.d.ts
143
146
  constructor(options: Options_7);
144
147
  protected getCrToken(): string;
148
+ getRefreshToken(): string;
145
149
  protected requestToken(): Promise<any>;
146
150
  setCrTokenFilename(crTokenFilename: string): void;
147
151
  setIamProfileId(iamProfileId: string): void;
@@ -224,11 +228,37 @@ export function getNewLogger(moduleName: string): SDKLogger;
224
228
  // @public
225
229
  export function getQueryParam(urlStr: string, param: string): string;
226
230
 
231
+ // Warning: (ae-forgotten-export) The symbol "IamRequestBasedAuthenticatorImmutable" needs to be exported by the entry point index.d.ts
232
+ //
233
+ // @public
234
+ export class IamAssumeAuthenticator extends IamRequestBasedAuthenticatorImmutable {
235
+ // Warning: (ae-forgotten-export) The symbol "Options_14" needs to be exported by the entry point index.d.ts
236
+ constructor(options: Options_14);
237
+ authenticationType(): string;
238
+ // (undocumented)
239
+ protected tokenManager: IamAssumeTokenManager;
240
+ }
241
+
242
+ // @public
243
+ export class IamAssumeTokenManager extends IamRequestBasedTokenManager {
244
+ // Warning: (ae-forgotten-export) The symbol "Options_13" needs to be exported by the entry point index.d.ts
245
+ constructor(options: Options_13);
246
+ protected requestToken(): Promise<any>;
247
+ // (undocumented)
248
+ protected requiredOptions: string[];
249
+ protected saveTokenInfo(tokenResponse: any): void;
250
+ setClientIdAndSecret(clientId: string, clientSecret: string): void;
251
+ setDisableSslVerification(value: boolean): void;
252
+ setHeaders(headers: OutgoingHttpHeaders): void;
253
+ setScope(scope: string): void;
254
+ }
255
+
227
256
  // @public
228
257
  export class IamAuthenticator extends IamRequestBasedAuthenticator {
229
258
  // Warning: (ae-forgotten-export) The symbol "Options_6" needs to be exported by the entry point index.d.ts
230
259
  constructor(options: Options_6);
231
260
  authenticationType(): string;
261
+ getRefreshToken(): string;
232
262
  // (undocumented)
233
263
  protected requiredOptions: string[];
234
264
  // (undocumented)
@@ -236,33 +266,29 @@ export class IamAuthenticator extends IamRequestBasedAuthenticator {
236
266
  }
237
267
 
238
268
  // @public
239
- export class IamRequestBasedAuthenticator extends TokenRequestBasedAuthenticator {
240
- // Warning: (ae-forgotten-export) The symbol "IamRequestOptions_2" needs to be exported by the entry point index.d.ts
241
- constructor(options: IamRequestOptions_2);
242
- // (undocumented)
243
- protected clientId: string;
244
- // (undocumented)
245
- protected clientSecret: string;
246
- getRefreshToken(): string;
247
- // (undocumented)
248
- protected scope: string;
269
+ export class IamRequestBasedAuthenticator extends IamRequestBasedAuthenticatorImmutable {
249
270
  setClientIdAndSecret(clientId: string, clientSecret: string): void;
271
+ setDisableSslVerification(value: boolean): void;
272
+ setHeaders(headers: OutgoingHttpHeaders): void;
250
273
  setScope(scope: string): void;
251
- // (undocumented)
252
- protected tokenManager: IamRequestBasedTokenManager;
253
274
  }
254
275
 
255
276
  // @public
256
277
  export class IamRequestBasedTokenManager extends JwtTokenManager {
257
278
  constructor(options: IamRequestOptions);
258
279
  // (undocumented)
280
+ protected clientId: string;
281
+ // (undocumented)
282
+ protected clientSecret: string;
283
+ // (undocumented)
259
284
  protected formData: any;
260
- getRefreshToken(): string;
261
285
  protected isTokenExpired(): boolean;
262
286
  // (undocumented)
263
287
  protected refreshToken: string;
264
288
  protected requestToken(): Promise<any>;
265
289
  protected saveTokenInfo(tokenResponse: any): void;
290
+ // (undocumented)
291
+ protected scope: string;
266
292
  setClientIdAndSecret(clientId: string, clientSecret: string): void;
267
293
  setScope(scope: string): void;
268
294
  }
@@ -281,6 +307,7 @@ export interface IamRequestOptions extends JwtTokenManagerOptions {
281
307
  export class IamTokenManager extends IamRequestBasedTokenManager {
282
308
  // Warning: (ae-forgotten-export) The symbol "Options_5" needs to be exported by the entry point index.d.ts
283
309
  constructor(options: Options_5);
310
+ getRefreshToken(): string;
284
311
  // (undocumented)
285
312
  protected requiredOptions: string[];
286
313
  }
@@ -343,7 +370,7 @@ export class NoAuthAuthenticator extends Authenticator {
343
370
  }
344
371
 
345
372
  // @public
346
- export function onlyOne(a: any, b: any): boolean;
373
+ export function onlyOne(...args: any): boolean;
347
374
 
348
375
  // @public
349
376
  export const qs: {
@@ -420,21 +447,12 @@ export type TokenManagerOptions = {
420
447
  [propName: string]: any;
421
448
  };
422
449
 
450
+ // Warning: (ae-forgotten-export) The symbol "TokenRequestBasedAuthenticatorImmutable" needs to be exported by the entry point index.d.ts
451
+ //
423
452
  // @public
424
- export class TokenRequestBasedAuthenticator extends Authenticator {
425
- // Warning: (ae-forgotten-export) The symbol "BaseOptions" needs to be exported by the entry point index.d.ts
426
- constructor(options: BaseOptions);
427
- authenticate(requestOptions: AuthenticateOptions): Promise<void>;
428
- // (undocumented)
429
- protected disableSslVerification: boolean;
430
- // (undocumented)
431
- protected headers: OutgoingHttpHeaders;
453
+ export class TokenRequestBasedAuthenticator extends TokenRequestBasedAuthenticatorImmutable {
432
454
  setDisableSslVerification(value: boolean): void;
433
455
  setHeaders(headers: OutgoingHttpHeaders): void;
434
- // (undocumented)
435
- protected tokenManager: JwtTokenManager;
436
- // (undocumented)
437
- protected url: string;
438
456
  }
439
457
 
440
458
  // @public