Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rest-client-sdk

Package Overview
Dependencies
Maintainers
3
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-client-sdk - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

7

CHANGELOG.md
# Changelog
## Unreleased
## 3.1.0
### Changed
* Store a new key `expires_at` in the access token (which is accessible with `TokenStorage.getAccessTokenObject`) to have the timestamp after which the access token will be invalid, based on the `expires_in`
* Add `TokenStorage.getCurrentTokenExpiresIn` function to known how many seconds are remaining for the access token currently stored
## 3.0.0

@@ -6,0 +11,0 @@

@@ -1240,4 +1240,5 @@ import diff from 'deep-diff';

this._hasATokenBeenGenerated = true;
var callTimestamp = Date.now() / 1000;
return this._tokenGenerator.generateToken(parameters).then(function (responseData) {
return _this2._storeAccessToken(responseData).then(function () {
return _this2._storeAccessToken(responseData, callTimestamp).then(function () {
return responseData;

@@ -1253,4 +1254,5 @@ });

return this._asyncStorage.getItem(this.accessTokenKey).then(function (token) {
var callTimestamp = Date.now() / 1000;
return _this3._tokenGenerator.refreshToken(JSON.parse(token), parameters).then(function (responseData) {
return _this3._storeAccessToken(responseData).then(function () {
return _this3._storeAccessToken(responseData, callTimestamp).then(function () {
return responseData;

@@ -1261,6 +1263,34 @@ });

}
/**
* Return the number of second when the token will expire
* return value can be negative if the token is already expired
*/
}, {
key: 'getCurrentTokenExpiresIn',
value: function getCurrentTokenExpiresIn() {
return this.getAccessTokenObject().then(function (accessTokenObject) {
if (accessTokenObject === null || typeof accessTokenObject.expires_at === 'undefined') {
throw new Error('No token has been stored.');
}
var now = Date.now() / 1000;
return accessTokenObject.expires_at - now;
});
}
}, {
key: '_storeAccessToken',
value: function _storeAccessToken(responseData) {
return this._asyncStorage.setItem(this.accessTokenKey, JSON.stringify(responseData));
value: function _storeAccessToken(responseData, callTimestamp) {
var responseDataToStore = responseData;
if ((typeof responseData === 'undefined' ? 'undefined' : _typeof(responseData)) === 'object') {
responseDataToStore = Object.assign({}, responseData);
responseDataToStore.expires_at = null;
if (typeof responseData.expires_in !== 'undefined' && responseData.expires_in >= 0) {
responseDataToStore.expires_at = callTimestamp + responseData.expires_in;
}
}
return this._asyncStorage.setItem(this.accessTokenKey, JSON.stringify(responseDataToStore));
}

@@ -1267,0 +1297,0 @@ }]);

@@ -1246,4 +1246,5 @@ (function (global, factory) {

this._hasATokenBeenGenerated = true;
var callTimestamp = Date.now() / 1000;
return this._tokenGenerator.generateToken(parameters).then(function (responseData) {
return _this2._storeAccessToken(responseData).then(function () {
return _this2._storeAccessToken(responseData, callTimestamp).then(function () {
return responseData;

@@ -1259,4 +1260,5 @@ });

return this._asyncStorage.getItem(this.accessTokenKey).then(function (token) {
var callTimestamp = Date.now() / 1000;
return _this3._tokenGenerator.refreshToken(JSON.parse(token), parameters).then(function (responseData) {
return _this3._storeAccessToken(responseData).then(function () {
return _this3._storeAccessToken(responseData, callTimestamp).then(function () {
return responseData;

@@ -1267,6 +1269,34 @@ });

}
/**
* Return the number of second when the token will expire
* return value can be negative if the token is already expired
*/
}, {
key: 'getCurrentTokenExpiresIn',
value: function getCurrentTokenExpiresIn() {
return this.getAccessTokenObject().then(function (accessTokenObject) {
if (accessTokenObject === null || typeof accessTokenObject.expires_at === 'undefined') {
throw new Error('No token has been stored.');
}
var now = Date.now() / 1000;
return accessTokenObject.expires_at - now;
});
}
}, {
key: '_storeAccessToken',
value: function _storeAccessToken(responseData) {
return this._asyncStorage.setItem(this.accessTokenKey, JSON.stringify(responseData));
value: function _storeAccessToken(responseData, callTimestamp) {
var responseDataToStore = responseData;
if ((typeof responseData === 'undefined' ? 'undefined' : _typeof(responseData)) === 'object') {
responseDataToStore = Object.assign({}, responseData);
responseDataToStore.expires_at = null;
if (typeof responseData.expires_in !== 'undefined' && responseData.expires_in >= 0) {
responseDataToStore.expires_at = callTimestamp + responseData.expires_in;
}
}
return this._asyncStorage.setItem(this.accessTokenKey, JSON.stringify(responseDataToStore));
}

@@ -1273,0 +1303,0 @@ }]);

6

package.json
{
"name": "rest-client-sdk",
"version": "v3.0.0",
"version": "v3.1.0",
"description": "Rest Client SDK for API",

@@ -46,3 +46,3 @@ "main": "dist/index.js",

"rollup-plugin-commonjs": "^9.1.0",
"rollup-plugin-node-resolve": "^3.0.0"
"rollup-plugin-node-resolve": "^3.1.0"
},

@@ -76,4 +76,4 @@ "optionalDependencies": {

"jest": {
"setupFiles": ["./setupJest.js"]
"setupTestFrameworkScriptFile": "./setupJest.js"
}
}

@@ -55,6 +55,7 @@ class TokenStorage {

this._hasATokenBeenGenerated = true;
const callTimestamp = Date.now() / 1000;
return this._tokenGenerator
.generateToken(parameters)
.then(responseData =>
this._storeAccessToken(responseData).then(() => responseData)
this._storeAccessToken(responseData, callTimestamp).then(() => responseData)
);

@@ -66,15 +67,43 @@ }

.getItem(this.accessTokenKey)
.then(token =>
this._tokenGenerator
.then(token => {
const callTimestamp = Date.now() / 1000;
return this._tokenGenerator
.refreshToken(JSON.parse(token), parameters)
.then(responseData =>
this._storeAccessToken(responseData).then(() => responseData)
this._storeAccessToken(responseData, callTimestamp).then(() => responseData)
)
}
);
}
_storeAccessToken(responseData) {
/**
* Return the number of second when the token will expire
* return value can be negative if the token is already expired
*/
getCurrentTokenExpiresIn() {
return this.getAccessTokenObject()
.then(accessTokenObject => {
if (accessTokenObject === null || typeof accessTokenObject.expires_at === 'undefined') {
throw new Error('No token has been stored.');
}
const now = Date.now() / 1000;
return accessTokenObject.expires_at - now;
});
}
_storeAccessToken(responseData, callTimestamp) {
let responseDataToStore = responseData;
if (typeof responseData === 'object') {
responseDataToStore = Object.assign({}, responseData);
responseDataToStore.expires_at = null;
if (typeof responseData.expires_in !== 'undefined' && responseData.expires_in >= 0) {
responseDataToStore.expires_at = callTimestamp + responseData.expires_in;
}
}
return this._asyncStorage.setItem(
this.accessTokenKey,
JSON.stringify(responseData)
JSON.stringify(responseDataToStore)
);

@@ -81,0 +110,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc