ibm-cloud-sdk-core 4.2.3 → 4.2.4

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 (27) hide show
  1. package/.secrets.baseline +8 -8
  2. package/CHANGELOG.md +7 -0
  3. package/auth/token-managers/iam-request-based-token-manager.d.ts +11 -1
  4. package/auth/token-managers/iam-request-based-token-manager.js +19 -1
  5. package/auth/token-managers/jwt-token-manager.js +2 -2
  6. package/auth/token-managers/token-manager.d.ts +2 -2
  7. package/auth/token-managers/vpc-instance-token-manager.d.ts +11 -1
  8. package/auth/token-managers/vpc-instance-token-manager.js +19 -1
  9. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.istokenexpired.md +19 -0
  10. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.md +1 -0
  11. package/build/docs/ibm-cloud-sdk-core.tokenmanager.istokenexpired.md +17 -0
  12. package/build/docs/ibm-cloud-sdk-core.tokenmanager.md +1 -0
  13. package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.istokenexpired.md +19 -0
  14. package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.md +1 -0
  15. package/docs/ibm-cloud-sdk-core.api.json +94 -1
  16. package/es/auth/token-managers/iam-request-based-token-manager.d.ts +11 -1
  17. package/es/auth/token-managers/iam-request-based-token-manager.js +20 -2
  18. package/es/auth/token-managers/jwt-token-manager.js +2 -2
  19. package/es/auth/token-managers/token-manager.d.ts +2 -2
  20. package/es/auth/token-managers/vpc-instance-token-manager.d.ts +11 -1
  21. package/es/auth/token-managers/vpc-instance-token-manager.js +20 -2
  22. package/es/tsdoc-metadata.json +1 -1
  23. package/etc/ibm-cloud-sdk-core.api.md +3 -0
  24. package/ibm-cloud-sdk-core.d.ts +21 -1
  25. package/package.json +1 -1
  26. package/temp/ibm-cloud-sdk-core.api.json +94 -1
  27. package/temp/ibm-cloud-sdk-core.api.md +3 -0
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": "2024-01-04T12:07:27Z",
6
+ "generated_at": "2024-02-27T01:02:51Z",
7
7
  "plugins_used": [
8
8
  {
9
9
  "name": "AWSKeyDetector"
@@ -96,7 +96,7 @@
96
96
  "hashed_secret": "bc2f74c22f98f7b6ffbc2f67453dbfa99bce9a32",
97
97
  "is_secret": false,
98
98
  "is_verified": false,
99
- "line_number": 118,
99
+ "line_number": 132,
100
100
  "type": "Secret Keyword",
101
101
  "verified_result": null
102
102
  }
@@ -244,7 +244,7 @@
244
244
  "hashed_secret": "f84f793e0af9ade37c8b927bc5091e98f35bf821",
245
245
  "is_secret": false,
246
246
  "is_verified": false,
247
- "line_number": 84,
247
+ "line_number": 85,
248
248
  "type": "Secret Keyword",
249
249
  "verified_result": null
250
250
  },
@@ -252,7 +252,7 @@
252
252
  "hashed_secret": "45c43fe97e3a06ab078b0eeff6fbe622cc417a25",
253
253
  "is_secret": false,
254
254
  "is_verified": false,
255
- "line_number": 118,
255
+ "line_number": 119,
256
256
  "type": "Secret Keyword",
257
257
  "verified_result": null
258
258
  },
@@ -260,7 +260,7 @@
260
260
  "hashed_secret": "99833a8b234b57b886a9aef1dba187fdd7ceece8",
261
261
  "is_secret": false,
262
262
  "is_verified": false,
263
- "line_number": 120,
263
+ "line_number": 121,
264
264
  "type": "Secret Keyword",
265
265
  "verified_result": null
266
266
  }
@@ -334,7 +334,7 @@
334
334
  "hashed_secret": "45c43fe97e3a06ab078b0eeff6fbe622cc417a25",
335
335
  "is_secret": false,
336
336
  "is_verified": false,
337
- "line_number": 283,
337
+ "line_number": 284,
338
338
  "type": "Secret Keyword",
339
339
  "verified_result": null
340
340
  }
@@ -522,7 +522,7 @@
522
522
  "hashed_secret": "a7ef1be18bb8d37af79f3d87761a203378bf26a2",
523
523
  "is_secret": false,
524
524
  "is_verified": false,
525
- "line_number": 146,
525
+ "line_number": 151,
526
526
  "type": "Secret Keyword",
527
527
  "verified_result": null
528
528
  }
@@ -582,7 +582,7 @@
582
582
  }
583
583
  ]
584
584
  },
585
- "version": "0.13.1+ibm.61.dss",
585
+ "version": "0.13.1+ibm.62.dss",
586
586
  "word_list": {
587
587
  "file": null,
588
588
  "hash": null
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [4.2.4](https://github.com/IBM/node-sdk-core/compare/v4.2.3...v4.2.4) (2024-02-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * adjust IAM token expiration time ([#268](https://github.com/IBM/node-sdk-core/issues/268)) ([9b975e0](https://github.com/IBM/node-sdk-core/commit/9b975e0da75d46ea29095eebeda5d0b079f058c6))
7
+
1
8
  ## [4.2.3](https://github.com/IBM/node-sdk-core/compare/v4.2.2...v4.2.3) (2024-02-01)
2
9
 
3
10
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2023.
2
+ * (C) Copyright IBM Corp. 2019, 2024.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -89,4 +89,14 @@ export declare class IamRequestBasedTokenManager extends JwtTokenManager {
89
89
  * @returns Promise
90
90
  */
91
91
  protected requestToken(): Promise<any>;
92
+ /**
93
+ * Returns true iff the currently-cached IAM access token is expired.
94
+ * We'll consider an access token as expired when we reach its IAM server-reported
95
+ * expiration time minus our expiration window (10 secs).
96
+ * We do this to avoid using an access token that might expire in the middle of a long-running
97
+ * transaction within an IBM Cloud service.
98
+ *
99
+ * @returns true if the token has expired, false otherwise
100
+ */
101
+ protected isTokenExpired(): boolean;
92
102
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * (C) Copyright IBM Corp. 2019, 2023.
3
+ * (C) Copyright IBM Corp. 2019, 2024.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@ var jwt_token_manager_1 = require("./jwt-token-manager");
41
41
  var CLIENT_ID_SECRET_WARNING = 'Warning: Client ID and Secret must BOTH be given, or the header will not be included.';
42
42
  var DEFAULT_IAM_URL = 'https://iam.cloud.ibm.com';
43
43
  var OPERATION_PATH = '/identity/token';
44
+ var IAM_EXPIRATION_WINDOW = 10;
44
45
  /**
45
46
  * The IamRequestBasedTokenManager class contains code relevant to any token manager that
46
47
  * interacts with the IAM service to manage a token. It stores information relevant to all
@@ -168,6 +169,23 @@ var IamRequestBasedTokenManager = /** @class */ (function (_super) {
168
169
  };
169
170
  return this.requestWrapperInstance.sendRequest(parameters);
170
171
  };
172
+ /**
173
+ * Returns true iff the currently-cached IAM access token is expired.
174
+ * We'll consider an access token as expired when we reach its IAM server-reported
175
+ * expiration time minus our expiration window (10 secs).
176
+ * We do this to avoid using an access token that might expire in the middle of a long-running
177
+ * transaction within an IBM Cloud service.
178
+ *
179
+ * @returns true if the token has expired, false otherwise
180
+ */
181
+ IamRequestBasedTokenManager.prototype.isTokenExpired = function () {
182
+ var expireTime = this.expireTime;
183
+ if (!expireTime) {
184
+ return true;
185
+ }
186
+ var currentTime = (0, helpers_1.getCurrentTime)();
187
+ return currentTime >= expireTime - IAM_EXPIRATION_WINDOW;
188
+ };
171
189
  return IamRequestBasedTokenManager;
172
190
  }(jwt_token_manager_1.JwtTokenManager));
173
191
  exports.IamRequestBasedTokenManager = IamRequestBasedTokenManager;
@@ -32,7 +32,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
33
  exports.JwtTokenManager = void 0;
34
34
  /**
35
- * (C) Copyright IBM Corp. 2019, 2022.
35
+ * (C) Copyright IBM Corp. 2019, 2024.
36
36
  *
37
37
  * Licensed under the Apache License, Version 2.0 (the "License");
38
38
  * you may not use this file except in compliance with the License.
@@ -102,7 +102,7 @@ var JwtTokenManager = /** @class */ (function (_super) {
102
102
  }
103
103
  var decodedResponse = (0, jsonwebtoken_1.decode)(this.accessToken);
104
104
  if (!decodedResponse) {
105
- var err = 'Access token recieved is not a valid JWT';
105
+ var err = 'Access token received is not a valid JWT';
106
106
  logger_1.default.error(err);
107
107
  throw new Error(err);
108
108
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /**
3
- * (C) Copyright IBM Corp. 2020, 2023.
3
+ * (C) Copyright IBM Corp. 2020, 2024.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -106,7 +106,7 @@ export declare class TokenManager {
106
106
  /**
107
107
  * Checks if currently-stored token is expired
108
108
  */
109
- private isTokenExpired;
109
+ protected isTokenExpired(): boolean;
110
110
  /**
111
111
  * Checks if currently-stored token should be refreshed
112
112
  * i.e. past the window to request a new token
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2021, 2023.
2
+ * (C) Copyright IBM Corp. 2021, 2024.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -53,5 +53,15 @@ export declare class VpcInstanceTokenManager extends JwtTokenManager {
53
53
  setIamProfileId(iamProfileId: string): void;
54
54
  protected requestToken(): Promise<any>;
55
55
  private getInstanceIdentityToken;
56
+ /**
57
+ * Returns true iff the currently-cached IAM access token is expired.
58
+ * We'll consider an access token as expired when we reach its IAM server-reported
59
+ * expiration time minus our expiration window (10 secs).
60
+ * We do this to avoid using an access token that might expire in the middle of a long-running
61
+ * transaction within an IBM Cloud service.
62
+ *
63
+ * @returns true if the token has expired, false otherwise
64
+ */
65
+ protected isTokenExpired(): boolean;
56
66
  }
57
67
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * (C) Copyright IBM Corp. 2021, 2023.
3
+ * (C) Copyright IBM Corp. 2021, 2024.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -75,6 +75,7 @@ var helpers_1 = require("../utils/helpers");
75
75
  var jwt_token_manager_1 = require("./jwt-token-manager");
76
76
  var DEFAULT_IMS_ENDPOINT = 'http://169.254.169.254';
77
77
  var METADATA_SERVICE_VERSION = '2022-03-01';
78
+ var IAM_EXPIRATION_WINDOW = 10;
78
79
  /**
79
80
  * Token Manager for VPC Instance Authentication.
80
81
  */
@@ -207,6 +208,23 @@ var VpcInstanceTokenManager = /** @class */ (function (_super) {
207
208
  });
208
209
  });
209
210
  };
211
+ /**
212
+ * Returns true iff the currently-cached IAM access token is expired.
213
+ * We'll consider an access token as expired when we reach its IAM server-reported
214
+ * expiration time minus our expiration window (10 secs).
215
+ * We do this to avoid using an access token that might expire in the middle of a long-running
216
+ * transaction within an IBM Cloud service.
217
+ *
218
+ * @returns true if the token has expired, false otherwise
219
+ */
220
+ VpcInstanceTokenManager.prototype.isTokenExpired = function () {
221
+ var expireTime = this.expireTime;
222
+ if (!expireTime) {
223
+ return true;
224
+ }
225
+ var currentTime = (0, helpers_1.getCurrentTime)();
226
+ return currentTime >= expireTime - IAM_EXPIRATION_WINDOW;
227
+ };
210
228
  return VpcInstanceTokenManager;
211
229
  }(jwt_token_manager_1.JwtTokenManager));
212
230
  exports.VpcInstanceTokenManager = VpcInstanceTokenManager;
@@ -0,0 +1,19 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [IamRequestBasedTokenManager](./ibm-cloud-sdk-core.iamrequestbasedtokenmanager.md) &gt; [isTokenExpired](./ibm-cloud-sdk-core.iamrequestbasedtokenmanager.istokenexpired.md)
4
+
5
+ ## IamRequestBasedTokenManager.isTokenExpired() method
6
+
7
+ Returns true iff the currently-cached IAM access token is expired. We'll consider an access token as expired when we reach its IAM server-reported expiration time minus our expiration window (10 secs). We do this to avoid using an access token that might expire in the middle of a long-running transaction within an IBM Cloud service.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ protected isTokenExpired(): boolean;
13
+ ```
14
+ **Returns:**
15
+
16
+ boolean
17
+
18
+ true if the token has expired, false otherwise
19
+
@@ -31,6 +31,7 @@ export declare class IamRequestBasedTokenManager extends JwtTokenManager
31
31
  | Method | Modifiers | Description |
32
32
  | --- | --- | --- |
33
33
  | [getRefreshToken()](./ibm-cloud-sdk-core.iamrequestbasedtokenmanager.getrefreshtoken.md) | | Returns the most recently stored refresh token. |
34
+ | [isTokenExpired()](./ibm-cloud-sdk-core.iamrequestbasedtokenmanager.istokenexpired.md) | <code>protected</code> | Returns true iff the currently-cached IAM access token is expired. We'll consider an access token as expired when we reach its IAM server-reported expiration time minus our expiration window (10 secs). We do this to avoid using an access token that might expire in the middle of a long-running transaction within an IBM Cloud service. |
34
35
  | [requestToken()](./ibm-cloud-sdk-core.iamrequestbasedtokenmanager.requesttoken.md) | <code>protected</code> | Request an IAM access token using an API key. |
35
36
  | [saveTokenInfo(tokenResponse)](./ibm-cloud-sdk-core.iamrequestbasedtokenmanager.savetokeninfo.md) | <code>protected</code> | Extend this method from the parent class to extract the refresh token from the request and save it. |
36
37
  | [setClientIdAndSecret(clientId, clientSecret)](./ibm-cloud-sdk-core.iamrequestbasedtokenmanager.setclientidandsecret.md) | | Sets the IAM "clientId" and "clientSecret" values. These values are used to compute the Authorization header used when retrieving the IAM access token. If these values are not set, no Authorization header will be set on the request (it is not required). |
@@ -0,0 +1,17 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [TokenManager](./ibm-cloud-sdk-core.tokenmanager.md) &gt; [isTokenExpired](./ibm-cloud-sdk-core.tokenmanager.istokenexpired.md)
4
+
5
+ ## TokenManager.isTokenExpired() method
6
+
7
+ Checks if currently-stored token is expired
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ protected isTokenExpired(): boolean;
13
+ ```
14
+ **Returns:**
15
+
16
+ boolean
17
+
@@ -35,6 +35,7 @@ export declare class TokenManager
35
35
  | Method | Modifiers | Description |
36
36
  | --- | --- | --- |
37
37
  | [getToken()](./ibm-cloud-sdk-core.tokenmanager.gettoken.md) | | Retrieves a new token using "requestToken()" if there is not a currently stored token from a previous call, or the previous token has expired. |
38
+ | [isTokenExpired()](./ibm-cloud-sdk-core.tokenmanager.istokenexpired.md) | <code>protected</code> | Checks if currently-stored token is expired |
38
39
  | [pacedRequestToken()](./ibm-cloud-sdk-core.tokenmanager.pacedrequesttoken.md) | <code>protected</code> | <p>Paces requests to requestToken().</p><p>This method pseudo-serializes requests for an access\_token when the current token is undefined or expired. The first caller to this method records its <code>requestTime</code> and then issues the token request. Subsequent callers will check the <code>requestTime</code> to see if a request is active (has been issued within the past 60 seconds), and if so will queue their promise for the active requestor to resolve when that request completes.</p> |
39
40
  | [requestToken()](./ibm-cloud-sdk-core.tokenmanager.requesttoken.md) | <code>protected</code> | Request a token using an API endpoint. |
40
41
  | [saveTokenInfo(tokenResponse)](./ibm-cloud-sdk-core.tokenmanager.savetokeninfo.md) | <code>protected</code> | Parse and save token information from the response. Save the requested token into field <code>accessToken</code>. Calculate expiration and refresh time from the received info and store them in fields <code>expireTime</code> and <code>refreshTime</code>. |
@@ -0,0 +1,19 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [VpcInstanceTokenManager](./ibm-cloud-sdk-core.vpcinstancetokenmanager.md) &gt; [isTokenExpired](./ibm-cloud-sdk-core.vpcinstancetokenmanager.istokenexpired.md)
4
+
5
+ ## VpcInstanceTokenManager.isTokenExpired() method
6
+
7
+ Returns true iff the currently-cached IAM access token is expired. We'll consider an access token as expired when we reach its IAM server-reported expiration time minus our expiration window (10 secs). We do this to avoid using an access token that might expire in the middle of a long-running transaction within an IBM Cloud service.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ protected isTokenExpired(): boolean;
13
+ ```
14
+ **Returns:**
15
+
16
+ boolean
17
+
18
+ true if the token has expired, false otherwise
19
+
@@ -23,6 +23,7 @@ export declare class VpcInstanceTokenManager extends JwtTokenManager
23
23
 
24
24
  | Method | Modifiers | Description |
25
25
  | --- | --- | --- |
26
+ | [isTokenExpired()](./ibm-cloud-sdk-core.vpcinstancetokenmanager.istokenexpired.md) | <code>protected</code> | Returns true iff the currently-cached IAM access token is expired. We'll consider an access token as expired when we reach its IAM server-reported expiration time minus our expiration window (10 secs). We do this to avoid using an access token that might expire in the middle of a long-running transaction within an IBM Cloud service. |
26
27
  | [requestToken()](./ibm-cloud-sdk-core.vpcinstancetokenmanager.requesttoken.md) | <code>protected</code> | |
27
28
  | [setIamProfileCrn(iamProfileCrn)](./ibm-cloud-sdk-core.vpcinstancetokenmanager.setiamprofilecrn.md) | | Sets the CRN of the IAM trusted profile to use when fetching the access token from the IAM token server. |
28
29
  | [setIamProfileId(iamProfileId)](./ibm-cloud-sdk-core.vpcinstancetokenmanager.setiamprofileid.md) | | Sets the Id of the IAM trusted profile to use when fetching the access token from the IAM token server. |
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "metadata": {
3
3
  "toolPackage": "@microsoft/api-extractor",
4
- "toolVersion": "7.39.0",
4
+ "toolVersion": "7.41.0",
5
5
  "schemaVersion": 1011,
6
6
  "oldestForwardsCompatibleVersion": 1001,
7
7
  "tsdocConfig": {
@@ -4514,6 +4514,37 @@
4514
4514
  "isAbstract": false,
4515
4515
  "name": "getRefreshToken"
4516
4516
  },
4517
+ {
4518
+ "kind": "Method",
4519
+ "canonicalReference": "ibm-cloud-sdk-core!IamRequestBasedTokenManager#isTokenExpired:member(1)",
4520
+ "docComment": "/**\n * Returns true iff the currently-cached IAM access token is expired. We'll consider an access token as expired when we reach its IAM server-reported expiration time minus our expiration window (10 secs). We do this to avoid using an access token that might expire in the middle of a long-running transaction within an IBM Cloud service.\n *\n * @returns true if the token has expired, false otherwise\n */\n",
4521
+ "excerptTokens": [
4522
+ {
4523
+ "kind": "Content",
4524
+ "text": "protected isTokenExpired(): "
4525
+ },
4526
+ {
4527
+ "kind": "Content",
4528
+ "text": "boolean"
4529
+ },
4530
+ {
4531
+ "kind": "Content",
4532
+ "text": ";"
4533
+ }
4534
+ ],
4535
+ "isStatic": false,
4536
+ "returnTypeTokenRange": {
4537
+ "startIndex": 1,
4538
+ "endIndex": 2
4539
+ },
4540
+ "releaseTag": "Public",
4541
+ "isProtected": true,
4542
+ "overloadIndex": 1,
4543
+ "parameters": [],
4544
+ "isOptional": false,
4545
+ "isAbstract": false,
4546
+ "name": "isTokenExpired"
4547
+ },
4517
4548
  {
4518
4549
  "kind": "Property",
4519
4550
  "canonicalReference": "ibm-cloud-sdk-core!IamRequestBasedTokenManager#refreshToken:member",
@@ -6582,6 +6613,37 @@
6582
6613
  "isProtected": true,
6583
6614
  "isAbstract": false
6584
6615
  },
6616
+ {
6617
+ "kind": "Method",
6618
+ "canonicalReference": "ibm-cloud-sdk-core!TokenManager#isTokenExpired:member(1)",
6619
+ "docComment": "/**\n * Checks if currently-stored token is expired\n */\n",
6620
+ "excerptTokens": [
6621
+ {
6622
+ "kind": "Content",
6623
+ "text": "protected isTokenExpired(): "
6624
+ },
6625
+ {
6626
+ "kind": "Content",
6627
+ "text": "boolean"
6628
+ },
6629
+ {
6630
+ "kind": "Content",
6631
+ "text": ";"
6632
+ }
6633
+ ],
6634
+ "isStatic": false,
6635
+ "returnTypeTokenRange": {
6636
+ "startIndex": 1,
6637
+ "endIndex": 2
6638
+ },
6639
+ "releaseTag": "Public",
6640
+ "isProtected": true,
6641
+ "overloadIndex": 1,
6642
+ "parameters": [],
6643
+ "isOptional": false,
6644
+ "isAbstract": false,
6645
+ "name": "isTokenExpired"
6646
+ },
6585
6647
  {
6586
6648
  "kind": "Method",
6587
6649
  "canonicalReference": "ibm-cloud-sdk-core!TokenManager#pacedRequestToken:member(1)",
@@ -8373,6 +8435,37 @@
8373
8435
  }
8374
8436
  ]
8375
8437
  },
8438
+ {
8439
+ "kind": "Method",
8440
+ "canonicalReference": "ibm-cloud-sdk-core!VpcInstanceTokenManager#isTokenExpired:member(1)",
8441
+ "docComment": "/**\n * Returns true iff the currently-cached IAM access token is expired. We'll consider an access token as expired when we reach its IAM server-reported expiration time minus our expiration window (10 secs). We do this to avoid using an access token that might expire in the middle of a long-running transaction within an IBM Cloud service.\n *\n * @returns true if the token has expired, false otherwise\n */\n",
8442
+ "excerptTokens": [
8443
+ {
8444
+ "kind": "Content",
8445
+ "text": "protected isTokenExpired(): "
8446
+ },
8447
+ {
8448
+ "kind": "Content",
8449
+ "text": "boolean"
8450
+ },
8451
+ {
8452
+ "kind": "Content",
8453
+ "text": ";"
8454
+ }
8455
+ ],
8456
+ "isStatic": false,
8457
+ "returnTypeTokenRange": {
8458
+ "startIndex": 1,
8459
+ "endIndex": 2
8460
+ },
8461
+ "releaseTag": "Public",
8462
+ "isProtected": true,
8463
+ "overloadIndex": 1,
8464
+ "parameters": [],
8465
+ "isOptional": false,
8466
+ "isAbstract": false,
8467
+ "name": "isTokenExpired"
8468
+ },
8376
8469
  {
8377
8470
  "kind": "Method",
8378
8471
  "canonicalReference": "ibm-cloud-sdk-core!VpcInstanceTokenManager#requestToken:member(1)",
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2023.
2
+ * (C) Copyright IBM Corp. 2019, 2024.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -89,4 +89,14 @@ export declare class IamRequestBasedTokenManager extends JwtTokenManager {
89
89
  * @returns Promise
90
90
  */
91
91
  protected requestToken(): Promise<any>;
92
+ /**
93
+ * Returns true iff the currently-cached IAM access token is expired.
94
+ * We'll consider an access token as expired when we reach its IAM server-reported
95
+ * expiration time minus our expiration window (10 secs).
96
+ * We do this to avoid using an access token that might expire in the middle of a long-running
97
+ * transaction within an IBM Cloud service.
98
+ *
99
+ * @returns true if the token has expired, false otherwise
100
+ */
101
+ protected isTokenExpired(): boolean;
92
102
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2023.
2
+ * (C) Copyright IBM Corp. 2019, 2024.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -15,11 +15,12 @@
15
15
  */
16
16
  import extend from 'extend';
17
17
  import logger from '../../lib/logger';
18
- import { computeBasicAuthHeader, onlyOne, removeSuffix } from '../utils/helpers';
18
+ import { computeBasicAuthHeader, getCurrentTime, onlyOne, removeSuffix } from '../utils/helpers';
19
19
  import { JwtTokenManager } from './jwt-token-manager';
20
20
  const CLIENT_ID_SECRET_WARNING = 'Warning: Client ID and Secret must BOTH be given, or the header will not be included.';
21
21
  const DEFAULT_IAM_URL = 'https://iam.cloud.ibm.com';
22
22
  const OPERATION_PATH = '/identity/token';
23
+ const IAM_EXPIRATION_WINDOW = 10;
23
24
  /**
24
25
  * The IamRequestBasedTokenManager class contains code relevant to any token manager that
25
26
  * interacts with the IAM service to manage a token. It stores information relevant to all
@@ -144,4 +145,21 @@ export class IamRequestBasedTokenManager extends JwtTokenManager {
144
145
  };
145
146
  return this.requestWrapperInstance.sendRequest(parameters);
146
147
  }
148
+ /**
149
+ * Returns true iff the currently-cached IAM access token is expired.
150
+ * We'll consider an access token as expired when we reach its IAM server-reported
151
+ * expiration time minus our expiration window (10 secs).
152
+ * We do this to avoid using an access token that might expire in the middle of a long-running
153
+ * transaction within an IBM Cloud service.
154
+ *
155
+ * @returns true if the token has expired, false otherwise
156
+ */
157
+ isTokenExpired() {
158
+ const { expireTime } = this;
159
+ if (!expireTime) {
160
+ return true;
161
+ }
162
+ const currentTime = getCurrentTime();
163
+ return currentTime >= expireTime - IAM_EXPIRATION_WINDOW;
164
+ }
147
165
  }
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable class-methods-use-this */
2
2
  /**
3
- * (C) Copyright IBM Corp. 2019, 2022.
3
+ * (C) Copyright IBM Corp. 2019, 2024.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ export class JwtTokenManager extends TokenManager {
67
67
  }
68
68
  const decodedResponse = decode(this.accessToken);
69
69
  if (!decodedResponse) {
70
- const err = 'Access token recieved is not a valid JWT';
70
+ const err = 'Access token received is not a valid JWT';
71
71
  logger.error(err);
72
72
  throw new Error(err);
73
73
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /**
3
- * (C) Copyright IBM Corp. 2020, 2023.
3
+ * (C) Copyright IBM Corp. 2020, 2024.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -106,7 +106,7 @@ export declare class TokenManager {
106
106
  /**
107
107
  * Checks if currently-stored token is expired
108
108
  */
109
- private isTokenExpired;
109
+ protected isTokenExpired(): boolean;
110
110
  /**
111
111
  * Checks if currently-stored token should be refreshed
112
112
  * i.e. past the window to request a new token
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2021, 2023.
2
+ * (C) Copyright IBM Corp. 2021, 2024.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -53,5 +53,15 @@ export declare class VpcInstanceTokenManager extends JwtTokenManager {
53
53
  setIamProfileId(iamProfileId: string): void;
54
54
  protected requestToken(): Promise<any>;
55
55
  private getInstanceIdentityToken;
56
+ /**
57
+ * Returns true iff the currently-cached IAM access token is expired.
58
+ * We'll consider an access token as expired when we reach its IAM server-reported
59
+ * expiration time minus our expiration window (10 secs).
60
+ * We do this to avoid using an access token that might expire in the middle of a long-running
61
+ * transaction within an IBM Cloud service.
62
+ *
63
+ * @returns true if the token has expired, false otherwise
64
+ */
65
+ protected isTokenExpired(): boolean;
56
66
  }
57
67
  export {};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2021, 2023.
2
+ * (C) Copyright IBM Corp. 2021, 2024.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -23,10 +23,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
23
  });
24
24
  };
25
25
  import logger from '../../lib/logger';
26
- import { atMostOne } from '../utils/helpers';
26
+ import { atMostOne, getCurrentTime } from '../utils/helpers';
27
27
  import { JwtTokenManager } from './jwt-token-manager';
28
28
  const DEFAULT_IMS_ENDPOINT = 'http://169.254.169.254';
29
29
  const METADATA_SERVICE_VERSION = '2022-03-01';
30
+ const IAM_EXPIRATION_WINDOW = 10;
30
31
  /**
31
32
  * Token Manager for VPC Instance Authentication.
32
33
  */
@@ -141,4 +142,21 @@ export class VpcInstanceTokenManager extends JwtTokenManager {
141
142
  return token;
142
143
  });
143
144
  }
145
+ /**
146
+ * Returns true iff the currently-cached IAM access token is expired.
147
+ * We'll consider an access token as expired when we reach its IAM server-reported
148
+ * expiration time minus our expiration window (10 secs).
149
+ * We do this to avoid using an access token that might expire in the middle of a long-running
150
+ * transaction within an IBM Cloud service.
151
+ *
152
+ * @returns true if the token has expired, false otherwise
153
+ */
154
+ isTokenExpired() {
155
+ const { expireTime } = this;
156
+ if (!expireTime) {
157
+ return true;
158
+ }
159
+ const currentTime = getCurrentTime();
160
+ return currentTime >= expireTime - IAM_EXPIRATION_WINDOW;
161
+ }
144
162
  }
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.39.0"
8
+ "packageVersion": "7.41.0"
9
9
  }
10
10
  ]
11
11
  }
@@ -276,6 +276,7 @@ export class IamRequestBasedTokenManager extends JwtTokenManager {
276
276
  // (undocumented)
277
277
  protected formData: any;
278
278
  getRefreshToken(): string;
279
+ protected isTokenExpired(): boolean;
279
280
  // (undocumented)
280
281
  protected refreshToken: string;
281
282
  protected requestToken(): Promise<any>;
@@ -411,6 +412,7 @@ export class TokenManager {
411
412
  getToken(): Promise<any>;
412
413
  // (undocumented)
413
414
  protected headers: OutgoingHttpHeaders;
415
+ protected isTokenExpired(): boolean;
414
416
  protected pacedRequestToken(): Promise<any>;
415
417
  // (undocumented)
416
418
  protected refreshTime: number;
@@ -501,6 +503,7 @@ export class VpcInstanceAuthenticator extends TokenRequestBasedAuthenticator {
501
503
  export class VpcInstanceTokenManager extends JwtTokenManager {
502
504
  // Warning: (ae-forgotten-export) The symbol "Options_9" needs to be exported by the entry point index.d.ts
503
505
  constructor(options: Options_9);
506
+ protected isTokenExpired(): boolean;
504
507
  // (undocumented)
505
508
  protected requestToken(): Promise<any>;
506
509
  setIamProfileCrn(iamProfileCrn: string): void;
@@ -925,6 +925,16 @@ export declare class IamRequestBasedTokenManager extends JwtTokenManager {
925
925
  * @returns Promise
926
926
  */
927
927
  protected requestToken(): Promise<any>;
928
+ /**
929
+ * Returns true iff the currently-cached IAM access token is expired.
930
+ * We'll consider an access token as expired when we reach its IAM server-reported
931
+ * expiration time minus our expiration window (10 secs).
932
+ * We do this to avoid using an access token that might expire in the middle of a long-running
933
+ * transaction within an IBM Cloud service.
934
+ *
935
+ * @returns true if the token has expired, false otherwise
936
+ */
937
+ protected isTokenExpired(): boolean;
928
938
  }
929
939
 
930
940
  /** Configuration options for IAM token retrieval. */
@@ -1436,7 +1446,7 @@ export declare class TokenManager {
1436
1446
  /**
1437
1447
  * Checks if currently-stored token is expired
1438
1448
  */
1439
- private isTokenExpired;
1449
+ protected isTokenExpired(): boolean;
1440
1450
  /**
1441
1451
  * Checks if currently-stored token should be refreshed
1442
1452
  * i.e. past the window to request a new token
@@ -1658,6 +1668,16 @@ export declare class VpcInstanceTokenManager extends JwtTokenManager {
1658
1668
  setIamProfileId(iamProfileId: string): void;
1659
1669
  protected requestToken(): Promise<any>;
1660
1670
  private getInstanceIdentityToken;
1671
+ /**
1672
+ * Returns true iff the currently-cached IAM access token is expired.
1673
+ * We'll consider an access token as expired when we reach its IAM server-reported
1674
+ * expiration time minus our expiration window (10 secs).
1675
+ * We do this to avoid using an access token that might expire in the middle of a long-running
1676
+ * transaction within an IBM Cloud service.
1677
+ *
1678
+ * @returns true if the token has expired, false otherwise
1679
+ */
1680
+ protected isTokenExpired(): boolean;
1661
1681
  }
1662
1682
 
1663
1683
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ibm-cloud-sdk-core",
3
- "version": "4.2.3",
3
+ "version": "4.2.4",
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",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "metadata": {
3
3
  "toolPackage": "@microsoft/api-extractor",
4
- "toolVersion": "7.39.0",
4
+ "toolVersion": "7.41.0",
5
5
  "schemaVersion": 1011,
6
6
  "oldestForwardsCompatibleVersion": 1001,
7
7
  "tsdocConfig": {
@@ -4514,6 +4514,37 @@
4514
4514
  "isAbstract": false,
4515
4515
  "name": "getRefreshToken"
4516
4516
  },
4517
+ {
4518
+ "kind": "Method",
4519
+ "canonicalReference": "ibm-cloud-sdk-core!IamRequestBasedTokenManager#isTokenExpired:member(1)",
4520
+ "docComment": "/**\n * Returns true iff the currently-cached IAM access token is expired. We'll consider an access token as expired when we reach its IAM server-reported expiration time minus our expiration window (10 secs). We do this to avoid using an access token that might expire in the middle of a long-running transaction within an IBM Cloud service.\n *\n * @returns true if the token has expired, false otherwise\n */\n",
4521
+ "excerptTokens": [
4522
+ {
4523
+ "kind": "Content",
4524
+ "text": "protected isTokenExpired(): "
4525
+ },
4526
+ {
4527
+ "kind": "Content",
4528
+ "text": "boolean"
4529
+ },
4530
+ {
4531
+ "kind": "Content",
4532
+ "text": ";"
4533
+ }
4534
+ ],
4535
+ "isStatic": false,
4536
+ "returnTypeTokenRange": {
4537
+ "startIndex": 1,
4538
+ "endIndex": 2
4539
+ },
4540
+ "releaseTag": "Public",
4541
+ "isProtected": true,
4542
+ "overloadIndex": 1,
4543
+ "parameters": [],
4544
+ "isOptional": false,
4545
+ "isAbstract": false,
4546
+ "name": "isTokenExpired"
4547
+ },
4517
4548
  {
4518
4549
  "kind": "Property",
4519
4550
  "canonicalReference": "ibm-cloud-sdk-core!IamRequestBasedTokenManager#refreshToken:member",
@@ -6582,6 +6613,37 @@
6582
6613
  "isProtected": true,
6583
6614
  "isAbstract": false
6584
6615
  },
6616
+ {
6617
+ "kind": "Method",
6618
+ "canonicalReference": "ibm-cloud-sdk-core!TokenManager#isTokenExpired:member(1)",
6619
+ "docComment": "/**\n * Checks if currently-stored token is expired\n */\n",
6620
+ "excerptTokens": [
6621
+ {
6622
+ "kind": "Content",
6623
+ "text": "protected isTokenExpired(): "
6624
+ },
6625
+ {
6626
+ "kind": "Content",
6627
+ "text": "boolean"
6628
+ },
6629
+ {
6630
+ "kind": "Content",
6631
+ "text": ";"
6632
+ }
6633
+ ],
6634
+ "isStatic": false,
6635
+ "returnTypeTokenRange": {
6636
+ "startIndex": 1,
6637
+ "endIndex": 2
6638
+ },
6639
+ "releaseTag": "Public",
6640
+ "isProtected": true,
6641
+ "overloadIndex": 1,
6642
+ "parameters": [],
6643
+ "isOptional": false,
6644
+ "isAbstract": false,
6645
+ "name": "isTokenExpired"
6646
+ },
6585
6647
  {
6586
6648
  "kind": "Method",
6587
6649
  "canonicalReference": "ibm-cloud-sdk-core!TokenManager#pacedRequestToken:member(1)",
@@ -8373,6 +8435,37 @@
8373
8435
  }
8374
8436
  ]
8375
8437
  },
8438
+ {
8439
+ "kind": "Method",
8440
+ "canonicalReference": "ibm-cloud-sdk-core!VpcInstanceTokenManager#isTokenExpired:member(1)",
8441
+ "docComment": "/**\n * Returns true iff the currently-cached IAM access token is expired. We'll consider an access token as expired when we reach its IAM server-reported expiration time minus our expiration window (10 secs). We do this to avoid using an access token that might expire in the middle of a long-running transaction within an IBM Cloud service.\n *\n * @returns true if the token has expired, false otherwise\n */\n",
8442
+ "excerptTokens": [
8443
+ {
8444
+ "kind": "Content",
8445
+ "text": "protected isTokenExpired(): "
8446
+ },
8447
+ {
8448
+ "kind": "Content",
8449
+ "text": "boolean"
8450
+ },
8451
+ {
8452
+ "kind": "Content",
8453
+ "text": ";"
8454
+ }
8455
+ ],
8456
+ "isStatic": false,
8457
+ "returnTypeTokenRange": {
8458
+ "startIndex": 1,
8459
+ "endIndex": 2
8460
+ },
8461
+ "releaseTag": "Public",
8462
+ "isProtected": true,
8463
+ "overloadIndex": 1,
8464
+ "parameters": [],
8465
+ "isOptional": false,
8466
+ "isAbstract": false,
8467
+ "name": "isTokenExpired"
8468
+ },
8376
8469
  {
8377
8470
  "kind": "Method",
8378
8471
  "canonicalReference": "ibm-cloud-sdk-core!VpcInstanceTokenManager#requestToken:member(1)",
@@ -276,6 +276,7 @@ export class IamRequestBasedTokenManager extends JwtTokenManager {
276
276
  // (undocumented)
277
277
  protected formData: any;
278
278
  getRefreshToken(): string;
279
+ protected isTokenExpired(): boolean;
279
280
  // (undocumented)
280
281
  protected refreshToken: string;
281
282
  protected requestToken(): Promise<any>;
@@ -411,6 +412,7 @@ export class TokenManager {
411
412
  getToken(): Promise<any>;
412
413
  // (undocumented)
413
414
  protected headers: OutgoingHttpHeaders;
415
+ protected isTokenExpired(): boolean;
414
416
  protected pacedRequestToken(): Promise<any>;
415
417
  // (undocumented)
416
418
  protected refreshTime: number;
@@ -501,6 +503,7 @@ export class VpcInstanceAuthenticator extends TokenRequestBasedAuthenticator {
501
503
  export class VpcInstanceTokenManager extends JwtTokenManager {
502
504
  // Warning: (ae-forgotten-export) The symbol "Options_9" needs to be exported by the entry point index.d.ts
503
505
  constructor(options: Options_9);
506
+ protected isTokenExpired(): boolean;
504
507
  // (undocumented)
505
508
  protected requestToken(): Promise<any>;
506
509
  setIamProfileCrn(iamProfileCrn: string): void;