@adventurelabs/scout-core 1.4.34 → 1.4.35

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.
@@ -3,6 +3,7 @@ export interface UseScoutRefreshOptions {
3
3
  onRefreshComplete?: () => void;
4
4
  cacheFirst?: boolean;
5
5
  cacheTtlMs?: number;
6
+ onlineRefetchMinIntervalMs?: number;
6
7
  }
7
8
  /**
8
9
  * Hook for refreshing scout data with detailed timing measurements and cache-first loading
@@ -12,6 +13,7 @@ export interface UseScoutRefreshOptions {
12
13
  * @param options.onRefreshComplete - Callback function called when refresh completes
13
14
  * @param options.cacheFirst - Whether to load from cache first, then refresh (default: true)
14
15
  * @param options.cacheTtlMs - Cache time-to-live in milliseconds (default: 24 hours)
16
+ * @param options.onlineRefetchMinIntervalMs - Min ms since last refresh before refetch on "online" (default: 60s)
15
17
  *
16
18
  * @returns Object containing:
17
19
  * - handleRefresh: Function to manually trigger a refresh
@@ -15,6 +15,7 @@ import { createBrowserClient } from "@supabase/ssr";
15
15
  * @param options.onRefreshComplete - Callback function called when refresh completes
16
16
  * @param options.cacheFirst - Whether to load from cache first, then refresh (default: true)
17
17
  * @param options.cacheTtlMs - Cache time-to-live in milliseconds (default: 24 hours)
18
+ * @param options.onlineRefetchMinIntervalMs - Min ms since last refresh before refetch on "online" (default: 60s)
18
19
  *
19
20
  * @returns Object containing:
20
21
  * - handleRefresh: Function to manually trigger a refresh
@@ -32,10 +33,12 @@ import { createBrowserClient } from "@supabase/ssr";
32
33
  */
33
34
  export function useScoutRefresh(options = {}) {
34
35
  const { autoRefresh = true, onRefreshComplete, cacheFirst = true, cacheTtlMs = 24 * 60 * 60 * 1000, // 24 hours default (1 day)
36
+ onlineRefetchMinIntervalMs = 60 * 1000, // 1 minute
35
37
  } = options;
36
38
  const dispatch = useAppDispatch();
37
39
  const store = useStore();
38
40
  const refreshInProgressRef = useRef(false);
41
+ const lastQueryAtRef = useRef(0);
39
42
  // Create Supabase client directly to avoid circular dependency
40
43
  // Assumes Next.js environment variables (NEXT_PUBLIC_*)
41
44
  const supabase = useMemo(() => {
@@ -306,6 +309,7 @@ export function useScoutRefresh(options = {}) {
306
309
  }
307
310
  finally {
308
311
  refreshInProgressRef.current = false;
312
+ lastQueryAtRef.current = Date.now();
309
313
  }
310
314
  }, [
311
315
  dispatch,
@@ -321,6 +325,19 @@ export function useScoutRefresh(options = {}) {
321
325
  handleRefresh();
322
326
  }
323
327
  }, [autoRefresh, handleRefresh]);
328
+ // Full refetch when nav goes online, only if min interval since last query has passed
329
+ useEffect(() => {
330
+ if (typeof window === "undefined")
331
+ return;
332
+ const handleOnline = () => {
333
+ const now = Date.now();
334
+ if (now - lastQueryAtRef.current >= onlineRefetchMinIntervalMs) {
335
+ handleRefresh();
336
+ }
337
+ };
338
+ window.addEventListener("online", handleOnline);
339
+ return () => window.removeEventListener("online", handleOnline);
340
+ }, [handleRefresh, onlineRefetchMinIntervalMs]);
324
341
  // Utility function to clear cache
325
342
  const clearCache = useCallback(async () => {
326
343
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.4.34",
3
+ "version": "1.4.35",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",