Comparing version 5.1.0 to 5.2.0
@@ -27,2 +27,3 @@ /** | ||
additionalClaims?: {}; | ||
eagerRefreshThresholdMillis?: number; | ||
} | ||
@@ -47,2 +48,3 @@ export interface GetTokenOptions { | ||
additionalClaims?: {}; | ||
eagerRefreshThresholdMillis?: number; | ||
private inFlightRequest?; | ||
@@ -62,2 +64,8 @@ /** | ||
/** | ||
* Returns whether the token will expire within eagerRefreshThresholdMillis | ||
* | ||
* @return true if the token will be expired within eagerRefreshThresholdMillis, false otherwise. | ||
*/ | ||
isTokenExpiring(): boolean; | ||
/** | ||
* Returns a cached token or retrieves a new one from Google. | ||
@@ -64,0 +72,0 @@ * |
@@ -65,2 +65,18 @@ "use strict"; | ||
} | ||
/** | ||
* Returns whether the token will expire within eagerRefreshThresholdMillis | ||
* | ||
* @return true if the token will be expired within eagerRefreshThresholdMillis, false otherwise. | ||
*/ | ||
isTokenExpiring() { | ||
var _a; | ||
const now = new Date().getTime(); | ||
const eagerRefreshThresholdMillis = (_a = this.eagerRefreshThresholdMillis) !== null && _a !== void 0 ? _a : 0; | ||
if (this.rawToken && this.expiresAt) { | ||
return this.expiresAt <= now + eagerRefreshThresholdMillis; | ||
} | ||
else { | ||
return true; | ||
} | ||
} | ||
getToken(callback, opts = {}) { | ||
@@ -134,3 +150,3 @@ if (typeof callback === 'object') { | ||
async getTokenAsyncInner(opts) { | ||
if (this.hasExpired() === false && opts.forceRefresh === false) { | ||
if (this.isTokenExpiring() === false && opts.forceRefresh === false) { | ||
return Promise.resolve(this.rawToken); | ||
@@ -195,2 +211,3 @@ } | ||
} | ||
this.eagerRefreshThresholdMillis = options.eagerRefreshThresholdMillis; | ||
} | ||
@@ -197,0 +214,0 @@ /** |
@@ -7,2 +7,9 @@ # Changelog | ||
## [5.2.0](https://www.github.com/googleapis/node-gtoken/compare/v5.1.0...v5.2.0) (2021-01-14) | ||
### Features | ||
* request new tokens before they expire ([#349](https://www.github.com/googleapis/node-gtoken/issues/349)) ([e84d9a3](https://www.github.com/googleapis/node-gtoken/commit/e84d9a31517c1449141708a0a2cddd9d0129fa95)) | ||
## [5.1.0](https://www.github.com/googleapis/node-gtoken/compare/v5.0.5...v5.1.0) (2020-11-14) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "gtoken", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Node.js Google Authentication Service Account Tokens", | ||
@@ -5,0 +5,0 @@ "main": "./build/src/index.js", |
@@ -32,3 +32,4 @@ <img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/> | ||
email: 'my_service_account_email@developer.gserviceaccount.com', | ||
scope: ['https://scope1', 'https://scope2'] // or space-delimited string of scopes | ||
scope: ['https://scope1', 'https://scope2'], // or space-delimited string of scopes | ||
eagerRefreshThresholdMillis: 5 * 60 * 1000 | ||
}); | ||
@@ -73,3 +74,4 @@ | ||
keyFile: 'path/to/key.json', | ||
scope: ['https://scope1', 'https://scope2'] // or space-delimited string of scopes | ||
scope: ['https://scope1', 'https://scope2'], // or space-delimited string of scopes | ||
eagerRefreshThresholdMillis: 5 * 60 * 1000 | ||
}); | ||
@@ -94,3 +96,4 @@ | ||
scope: ['https://scope1', 'https://scope2'], // or space-delimited string of scopes | ||
key: key | ||
key: key, | ||
eagerRefreshThresholdMillis: 5 * 60 * 1000 | ||
}); | ||
@@ -108,2 +111,4 @@ ``` | ||
- `options.key`: The raw RSA private key value, in place of using `options.keyFile`. | ||
- `options.additionalClaims`: Additional claims to include in the JWT when requesting a token. | ||
- `options.eagerRefreshThresholdMillis`: How long must a token be valid for in order to return it from the cache. Defaults to 0. | ||
@@ -110,0 +115,0 @@ ### .getToken(callback) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35555
362
188