Skip to content

Commit

Permalink
Add comments to methods in CoreUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
sggerard committed Jul 15, 2024
1 parent 94b4aef commit 25c9013
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/src/integrations/core-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const SECONDS_TO_MILLISECONDS_MULTIPLIER = 1000;

class CoreUtil {

/**
* Sets the CORE API token and marks when the token will expire
*
*/
async getToken(){
console.log('Updating CORE Token...');
const apiAccess = await getCoreAccessToken(CORE_CLIENT_ID, CORE_CLIENT_SECRET, CORE_GRANT_TYPE);
Expand All @@ -18,10 +22,21 @@ class CoreUtil {
console.log('CORE Token updated.');
}

/**
* Gives a time for when the given duration will pass with a buffer
*
* @param {int} tokenDuration the number of seconds that the token is valid for.
* @returns {int} the epoch time when the token is expected to expire ( - the buffer ) = current time + token duration - buffer
*
*/
getExpiryTime(tokenDuration) {
return Date.now() + ( tokenDuration * SECONDS_TO_MILLISECONDS_MULTIPLIER ) - TIME_BUFFER;
}

/**
* Wrapper for integration-utils.getRecords with additional logic to check if the token is expired
*
*/
async getRecords(url, additionalOptions = {}) {
if (this.client_token == null || Date.now() >= this.apiAccessExpiry) {
await this.getToken();
Expand Down

0 comments on commit 25c9013

Please sign in to comment.