Skip to content

Modified AccessToken.createdOn to be in seconds instead of milliseconds #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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