@iblai/web-utils 1.2.6 → 1.2.8

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.d.ts CHANGED
@@ -859,6 +859,7 @@ type ChatSliceState = {
859
859
  href: string;
860
860
  };
861
861
  pageContent: string;
862
+ metadata: Record<string, string> | null;
862
863
  };
863
864
  documentFilter: Record<string, unknown> | null;
864
865
  shouldStartNewChat: boolean;
@@ -910,6 +911,7 @@ declare const selectIframeContext: (state: {
910
911
  href: string;
911
912
  };
912
913
  pageContent: string;
914
+ metadata: Record<string, string> | null;
913
915
  };
914
916
  declare const selectDocumentFilter: (state: {
915
917
  chatSliceShared: ChatSliceState;
@@ -1527,7 +1529,7 @@ type Props$2 = {
1527
1529
  * 4. Handles redirects to auth SPA when needed
1528
1530
  * 5. Manages public route access state
1529
1531
  */
1530
- declare function AuthProvider({ children, fallback, middleware, onAuthSuccess, onAuthFailure, redirectToAuthSpa, hasNonExpiredAuthToken, username, pathname, skipAuthCheck, storageService, token, enableStorageSync, skip, }: Props$2): string | number | bigint | boolean | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
1532
+ declare function AuthProvider({ children, fallback, middleware, onAuthSuccess, onAuthFailure, redirectToAuthSpa, hasNonExpiredAuthToken, username, pathname, skipAuthCheck, storageService, token, enableStorageSync, skip, }: Props$2): string | number | bigint | boolean | react_jsx_runtime.JSX.Element | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | null | undefined;
1531
1533
 
1532
1534
  /**
1533
1535
  * Props for the MentorProvider component
@@ -1560,7 +1562,7 @@ type Props$1 = {
1560
1562
  * 3. Manages redirection based on mentor availability
1561
1563
  * 4. Integrates with tenant context for access control
1562
1564
  */
1563
- declare function MentorProvider({ children, fallback, onAuthSuccess, onAuthFailure, redirectToAuthSpa, redirectToMentor, onLoadMentorsPermissions, redirectToNoMentorsPage, redirectToCreateMentor, username, isAdmin, mainTenantKey, requestedMentorId, handleMentorNotFound, forceDetermineMentor, onComplete, skip, }: Props$1): string | number | bigint | boolean | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
1565
+ declare function MentorProvider({ children, fallback, onAuthSuccess, onAuthFailure, redirectToAuthSpa, redirectToMentor, onLoadMentorsPermissions, redirectToNoMentorsPage, redirectToCreateMentor, username, isAdmin, mainTenantKey, requestedMentorId, handleMentorNotFound, forceDetermineMentor, onComplete, skip, }: Props$1): string | number | bigint | boolean | react_jsx_runtime.JSX.Element | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | null | undefined;
1564
1566
 
1565
1567
  /**
1566
1568
  * Type definition for the tenant context
@@ -1623,7 +1625,7 @@ type Props = {
1623
1625
  * 4. Handles tenant-specific domain redirects
1624
1626
  * 5. Maintains tenant access state
1625
1627
  */
1626
- declare function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, currentTenant, requestedTenant, saveCurrentTenant, saveUserTenants, handleTenantSwitch, saveVisitingTenant, removeVisitingTenant, saveUserTokens, saveTenant, onAutoJoinUserToTenant, redirectToAuthSpa, username, isIframed, setUseMentorProvider, skip, onLoadPlatformPermissions, skipCustomDomainCheck, }: Props): string | number | bigint | boolean | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
1628
+ declare function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, currentTenant, requestedTenant, saveCurrentTenant, saveUserTenants, handleTenantSwitch, saveVisitingTenant, removeVisitingTenant, saveUserTokens, saveTenant, onAutoJoinUserToTenant, redirectToAuthSpa, username, isIframed, setUseMentorProvider, skip, onLoadPlatformPermissions, skipCustomDomainCheck, }: Props): string | number | bigint | boolean | react_jsx_runtime.JSX.Element | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | null | undefined;
1627
1629
 
1628
1630
  /**
1629
1631
  * Chat area size constants
package/dist/index.esm.js CHANGED
@@ -2822,12 +2822,22 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2822
2822
  return;
2823
2823
  }
2824
2824
  isRedirectingRef.current = true;
2825
- // Stop polling immediately to prevent stale callbacks
2826
- if (cookieCheckIntervalRef.current) {
2827
- clearInterval(cookieCheckIntervalRef.current);
2828
- cookieCheckIntervalRef.current = null;
2829
- }
2825
+ // NOTE: we intentionally do NOT clear the interval here.
2826
+ // The isRedirectingRef guard prevents redundant redirects while navigation
2827
+ // is in progress. Clearing the interval preemptively can permanently stop
2828
+ // cross-SPA sync if the consuming app suppresses the redirect (e.g. during
2829
+ // its own concurrent tenant switch), leaving the page with no active poller.
2830
2830
  redirectToAuthSpa(...args);
2831
+ // Safety recovery: if navigation was suppressed by the consuming app
2832
+ // (e.g. _suppressAuthRedirect was true), reset the guard after a short delay
2833
+ // so the interval can resume cross-SPA sync on its next tick.
2834
+ // If navigation did occur, the page will have unloaded before this fires.
2835
+ setTimeout(() => {
2836
+ if (isRedirectingRef.current) {
2837
+ console.log("[AuthProvider] safeRedirectToAuthSpa: navigation did not occur, resetting redirect guard");
2838
+ isRedirectingRef.current = false;
2839
+ }
2840
+ }, 3000);
2831
2841
  };
2832
2842
  /**
2833
2843
  * Sync cookies to localStorage on mount and periodically (web only)
@@ -2836,6 +2846,11 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2836
2846
  * Skipped if enableStorageSync is false
2837
2847
  */
2838
2848
  useEffect(() => {
2849
+ console.log("[AuthProvider] cookie-sync effect running", {
2850
+ pathname,
2851
+ enableStorageSync,
2852
+ hasStorageService: !!storageService,
2853
+ });
2839
2854
  if (!storageService || !isWeb$1() || !enableStorageSync) {
2840
2855
  // If no storage service, not web, or sync disabled, mark sync as complete immediately
2841
2856
  setInitialSyncComplete(true);
@@ -2845,16 +2860,22 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2845
2860
  isRedirectingRef.current = false;
2846
2861
  // Initial sync on mount
2847
2862
  async function initialSync() {
2863
+ console.log("[AuthProvider] initialSync starting");
2848
2864
  try {
2849
2865
  // Initialize last known logout timestamp
2850
2866
  lastLogoutTimestampRef.current = CookieUtils.get(COOKIE_KEYS.LOGOUT_TIMESTAMP);
2851
2867
  const { needsRefresh, userDataOutOfSync } = await syncCookiesToLocalStorage(storageService);
2868
+ console.log("[AuthProvider] initialSync result", {
2869
+ needsRefresh,
2870
+ userDataOutOfSync,
2871
+ });
2852
2872
  if (needsRefresh) {
2853
2873
  console.log("[auth-redirect] Cookie sync detected changes, refreshing page");
2854
2874
  // If user data is out of sync, trigger logout to force re-authentication
2855
2875
  safeRedirectToAuthSpa(undefined, undefined, userDataOutOfSync, false);
2856
2876
  }
2857
2877
  else {
2878
+ console.log("[AuthProvider] initialSync no changes, syncing auth to cookies");
2858
2879
  await syncAuthToCookies(storageService);
2859
2880
  }
2860
2881
  }
@@ -2867,8 +2888,10 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2867
2888
  // Poll for cookie changes every 2 seconds to detect cross-SPA updates
2868
2889
  cookieCheckIntervalRef.current = setInterval(async () => {
2869
2890
  // If a redirect is already in progress, skip entirely
2870
- if (isRedirectingRef.current)
2891
+ if (isRedirectingRef.current) {
2892
+ console.log("[AuthProvider] interval: redirect already in progress, skipping");
2871
2893
  return;
2894
+ }
2872
2895
  // Skip cookie sync checks if user is completing SSO at /sso-login
2873
2896
  const completingSso = /^\/sso-login/.test(pathname);
2874
2897
  if (completingSso) {
@@ -2889,6 +2912,11 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2889
2912
  return;
2890
2913
  }
2891
2914
  const { needsRefresh, userDataOutOfSync } = await syncCookiesToLocalStorage(storageService);
2915
+ console.log("[AuthProvider] interval poll result", {
2916
+ needsRefresh,
2917
+ userDataOutOfSync,
2918
+ pathname,
2919
+ });
2892
2920
  if (needsRefresh) {
2893
2921
  console.log("[auth-redirect] Cookie sync detected changes from another SPA, refreshing page");
2894
2922
  let cookieTenantKey;
@@ -2897,6 +2925,10 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2897
2925
  cookieTenantKey = cookieCurrentTenant.key;
2898
2926
  }
2899
2927
  catch (_a) { }
2928
+ console.log("[AuthProvider] interval redirecting to auth spa", {
2929
+ cookieTenantKey,
2930
+ userDataOutOfSync,
2931
+ });
2900
2932
  // If user data is out of sync, trigger logout to force re-authentication
2901
2933
  safeRedirectToAuthSpa(undefined, cookieTenantKey, userDataOutOfSync, false);
2902
2934
  }
@@ -2906,6 +2938,7 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2906
2938
  }, 2000);
2907
2939
  // Cleanup interval on unmount
2908
2940
  return () => {
2941
+ console.log("[AuthProvider] cookie-sync effect cleanup", { pathname });
2909
2942
  if (cookieCheckIntervalRef.current) {
2910
2943
  clearInterval(cookieCheckIntervalRef.current);
2911
2944
  }
@@ -5881,6 +5914,7 @@ const initialState$3 = {
5881
5914
  href: "",
5882
5915
  },
5883
5916
  pageContent: "",
5917
+ metadata: null,
5884
5918
  },
5885
5919
  documentFilter: null,
5886
5920
  token: null,
@@ -8024,6 +8058,7 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
8024
8058
  messageData = {
8025
8059
  ...messageData,
8026
8060
  page_content: iframeContext.pageContent,
8061
+ metadata: iframeContext.metadata,
8027
8062
  };
8028
8063
  }
8029
8064
  if (documentFilter) {