From 25c9013da46f7a315a6aaf4725d440ac575d587b Mon Sep 17 00:00:00 2001 From: sggerard Date: Mon, 15 Jul 2024 14:52:29 -0700 Subject: [PATCH] Add comments to methods in CoreUtil --- api/src/integrations/core-util.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/src/integrations/core-util.js b/api/src/integrations/core-util.js index d186d3eb2..4f2db1f56 100644 --- a/api/src/integrations/core-util.js +++ b/api/src/integrations/core-util.js @@ -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); @@ -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();