@iblai/web-utils 1.9.0 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -774,6 +774,11 @@ const LOCAL_STORAGE_KEYS = {
774
774
  EDX_TOKEN_KEY: "edx_jwt_token",
775
775
  DM_TOKEN_KEY: "dm_token",
776
776
  DM_TOKEN_EXPIRES: "dm_token_expires",
777
+ DM_TOKEN_EXPIRY: "dm_token_expires",
778
+ AXD_TOKEN_KEY: "axd_token",
779
+ DEFAULT_TENANT: "tenant",
780
+ MODEL_DOWNLOAD_STATE: "model_download_state",
781
+ MODEL_DOWNLOAD_PROMPT_DISMISSED: "model_download_prompt_dismissed",
777
782
  };
778
783
  const TOOLS = {
779
784
  WEB_SEARCH: "web-search",
@@ -8982,6 +8987,29 @@ async function syncAuthToCookies(storageService) {
8982
8987
  console.error("[syncAuthToCookies] Error syncing to cookies:", error);
8983
8988
  }
8984
8989
  }
8990
+ function hasNonExpiredAuthToken() {
8991
+ const token = window.localStorage.getItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
8992
+ if (!token) {
8993
+ console.log('################### [hasNonExpiredAuthToken] axd token is not defined', token);
8994
+ return false;
8995
+ }
8996
+ const tokenExpiry = window.localStorage.getItem(LOCAL_STORAGE_KEYS.TOKEN_EXPIRY);
8997
+ if (!tokenExpiry) {
8998
+ console.log('################### [hasNonExpiredAuthToken] axd token expiry is not defined', tokenExpiry);
8999
+ return true;
9000
+ }
9001
+ const expiryDate = new Date(tokenExpiry);
9002
+ if (isNaN(expiryDate.getTime())) {
9003
+ console.log('################### [hasNonExpiredAuthToken] axd token expiry date', expiryDate);
9004
+ return false;
9005
+ }
9006
+ const currentDate = new Date();
9007
+ if (expiryDate <= currentDate) {
9008
+ console.log('################### [hasNonExpiredAuthToken] axd token expiry date is less than current date ', expiryDate, currentDate);
9009
+ return false;
9010
+ }
9011
+ return true;
9012
+ }
8985
9013
  /**
8986
9014
  * Clear current tenant cookie only (web only)
8987
9015
  * Should be called before tenant switching
@@ -9182,7 +9210,7 @@ async function validateJwtToken(storageService) {
9182
9210
  return false;
9183
9211
  }
9184
9212
  }
9185
- function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure, redirectToAuthSpa, hasNonExpiredAuthToken, username, pathname, storageService, skipAuthCheck, token, enableStorageSync = true, }) {
9213
+ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure, redirectToAuthSpa, username, pathname, storageService, skipAuthCheck, token, enableStorageSync = true, }) {
9186
9214
  const [isAuthenticating, setIsAuthenticating] = React.useState(true);
9187
9215
  const [userIsAccessingPublicRoute, setUserIsAccessingPublicRoute] = React.useState(false);
9188
9216
  const [initialSyncComplete, setInitialSyncComplete] = React.useState(false);
@@ -9518,13 +9546,12 @@ async function determineAuthRequired(middleware, pathname) {
9518
9546
  * 4. Handles redirects to auth SPA when needed
9519
9547
  * 5. Manages public route access state
9520
9548
  */
9521
- function AuthProvider({ children, fallback, middleware = new Map(), onAuthSuccess, onAuthFailure, redirectToAuthSpa, hasNonExpiredAuthToken, username, pathname, storageService, token, enableStorageSync = true, skip = false, }) {
9549
+ function AuthProvider({ children, fallback, middleware = new Map(), onAuthSuccess, onAuthFailure, redirectToAuthSpa, username, pathname, storageService, token, enableStorageSync = true, skip = false, }) {
9522
9550
  const { isAuthenticating, userIsAccessingPublicRoute, setUserIsAccessingPublicRoute, } = useAuthProvider({
9523
9551
  middleware,
9524
9552
  onAuthSuccess,
9525
9553
  onAuthFailure,
9526
9554
  redirectToAuthSpa,
9527
- hasNonExpiredAuthToken,
9528
9555
  username,
9529
9556
  pathname,
9530
9557
  storageService,
@@ -18277,6 +18304,7 @@ exports.getTimeAgo = getTimeAgo;
18277
18304
  exports.getUserEmail = getUserEmail;
18278
18305
  exports.getUserName = getUserName;
18279
18306
  exports.handleLogout = handleLogout;
18307
+ exports.hasNonExpiredAuthToken = hasNonExpiredAuthToken;
18280
18308
  exports.hostChatReducer = hostChatReducer;
18281
18309
  exports.hostChatSlice = hostChatSlice;
18282
18310
  exports.initServiceWorker = initServiceWorker;