Skip to content

Commit

Permalink
Modified AccessToken.createdOn to be in seconds instead of millisecon…
Browse files Browse the repository at this point in the history
…ds (#97)

* modified AccessToken.createdOn to be in seconds instead of milliseconds

* updated CHANGELOG

* updated changelog and version in package.json
  • Loading branch information
antikus authored Aug 25, 2023
1 parent 78ac26c commit f712907
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## v0.7.1-alpha
- Storing `AccessToken.createdOn` in seconds to be consistent with other RAI SDKs.

## v0.7.0

## [v0.7.0](https://github.com/relationalai/rai-sdk-javascript/tree/v0.7.0) (2022-XX-XX)

[Full Changelog](https://github.com/relationalai/rai-sdk-javascript/compare/v0.6.3...v0.7.0)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@relationalai/rai-sdk-javascript",
"description": "RelationalAI SDK for JavaScript",
"version": "0.7.0",
"version": "0.7.1-alpha",
"author": {
"name": "RelationalAI",
"url": "https://relational.ai"
Expand Down
6 changes: 3 additions & 3 deletions src/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class AccessToken {
) {}

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

// anticipate access token expiration by 60 seconds
return delta + 60 >= this.experiesIn;
Expand Down Expand Up @@ -126,7 +126,7 @@ export class ClientCredentials extends Credentials {
const token: AccessTokenCache = {
access_token: data.access_token,
expires_in: data.expires_in,
created_on: Date.now(),
created_on: Date.now() / 1000,
};

this.accessToken = new AccessToken(
Expand Down

0 comments on commit f712907

Please sign in to comment.