Skip to content

Commit f712907

Browse files
author
Anatoli Kurtsevich
authored
Modified AccessToken.createdOn to be in seconds instead of milliseconds (#97)
* modified AccessToken.createdOn to be in seconds instead of milliseconds * updated CHANGELOG * updated changelog and version in package.json
1 parent 78ac26c commit f712907

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## v0.7.1-alpha
4+
- Storing `AccessToken.createdOn` in seconds to be consistent with other RAI SDKs.
5+
6+
## v0.7.0
7+
38
## [v0.7.0](https://github.com/relationalai/rai-sdk-javascript/tree/v0.7.0) (2022-XX-XX)
49

510
[Full Changelog](https://github.com/relationalai/rai-sdk-javascript/compare/v0.6.3...v0.7.0)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@relationalai/rai-sdk-javascript",
33
"description": "RelationalAI SDK for JavaScript",
4-
"version": "0.7.0",
4+
"version": "0.7.1-alpha",
55
"author": {
66
"name": "RelationalAI",
77
"url": "https://relational.ai"

src/credentials.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class AccessToken {
4141
) {}
4242

4343
get isExpired() {
44-
// experiesIn stored in seconds
45-
const delta = (Date.now() - this.createdOn) / 1000;
44+
// createdOn and experiesIn stored in seconds
45+
const delta = Date.now() / 1000 - this.createdOn;
4646

4747
// anticipate access token expiration by 60 seconds
4848
return delta + 60 >= this.experiesIn;
@@ -126,7 +126,7 @@ export class ClientCredentials extends Credentials {
126126
const token: AccessTokenCache = {
127127
access_token: data.access_token,
128128
expires_in: data.expires_in,
129-
created_on: Date.now(),
129+
created_on: Date.now() / 1000,
130130
};
131131

132132
this.accessToken = new AccessToken(

0 commit comments

Comments
 (0)