@adventurelabs/scout-core 1.4.54 → 1.4.55

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.
@@ -1,4 +1,7 @@
1
+ import { SupabaseClient } from "@supabase/supabase-js";
2
+ import { Database } from "../types/supabase";
1
3
  export interface UseScoutRefreshOptions {
4
+ supabase?: SupabaseClient<Database>;
2
5
  autoRefresh?: boolean;
3
6
  onRefreshComplete?: () => void;
4
7
  cacheFirst?: boolean;
@@ -14,6 +17,7 @@ export interface UseScoutRefreshOptions {
14
17
  * @param options.cacheFirst - Whether to load from cache first, then refresh (default: true)
15
18
  * @param options.cacheTtlMs - Cache time-to-live in milliseconds (default: 24 hours)
16
19
  * @param options.onlineRefetchMinIntervalMs - Min ms since last refresh before refetch on "online" (default: 15s)
20
+ * @param options.supabase - Optional shared browser client; when omitted, the hook creates its own via `createBrowserClient`
17
21
  *
18
22
  * @returns Object containing:
19
23
  * - handleRefresh: Function to manually trigger a refresh
@@ -16,6 +16,7 @@ import { createBrowserClient } from "@supabase/ssr";
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
18
  * @param options.onlineRefetchMinIntervalMs - Min ms since last refresh before refetch on "online" (default: 15s)
19
+ * @param options.supabase - Optional shared browser client; when omitted, the hook creates its own via `createBrowserClient`
19
20
  *
20
21
  * @returns Object containing:
21
22
  * - handleRefresh: Function to manually trigger a refresh
@@ -32,18 +33,19 @@ import { createBrowserClient } from "@supabase/ssr";
32
33
  * ```
33
34
  */
34
35
  export function useScoutRefresh(options = {}) {
35
- const { autoRefresh = true, onRefreshComplete, cacheFirst = true, cacheTtlMs = 24 * 60 * 60 * 1000, // 24 hours default (1 day)
36
+ const { supabase: supabaseOption, autoRefresh = true, onRefreshComplete, cacheFirst = true, cacheTtlMs = 24 * 60 * 60 * 1000, // 24 hours default (1 day)
36
37
  onlineRefetchMinIntervalMs = 15 * 1000, // 15 seconds
37
38
  } = options;
38
39
  const dispatch = useAppDispatch();
39
40
  const store = useStore();
40
41
  const refreshInProgressRef = useRef(false);
41
42
  const lastQueryAtRef = useRef(0);
42
- // Create Supabase client directly to avoid circular dependency
43
- // Assumes Next.js environment variables (NEXT_PUBLIC_*)
44
43
  const supabase = useMemo(() => {
44
+ if (supabaseOption) {
45
+ return supabaseOption;
46
+ }
45
47
  return createBrowserClient(process.env.NEXT_PUBLIC_SUPABASE_URL || "", process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || "");
46
- }, []);
48
+ }, [supabaseOption]);
47
49
  // Refs to store timing measurements
48
50
  const timingRefs = useRef({
49
51
  startTime: 0,
@@ -32,7 +32,7 @@ export function ScoutRefreshProvider({ children, ...refreshOptions }) {
32
32
  console.log("[ScoutRefreshProvider] Creating Supabase client");
33
33
  return createBrowserClient(urlRef.current, anonKeyRef.current);
34
34
  }, []); // Empty dependency array ensures this only runs once
35
- useScoutRefresh(refreshOptions);
35
+ useScoutRefresh({ ...refreshOptions, supabase: supabaseClient });
36
36
  // // Log connection status changes for debugging
37
37
  // if (connectionStatus.lastError) {
38
38
  // console.warn(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.4.54",
3
+ "version": "1.4.55",
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",