@adventurelabs/scout-core 1.4.10 → 1.4.12

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,8 +1,9 @@
1
1
  import { IWebResponseCompatible } from "../types/requests";
2
2
  import { IHealthMetric, IHealthMetricSummaryRow } from "../types/db";
3
3
  export declare function server_get_health_metrics(device_id: number, options: {
4
- lookbackMinutes: number;
4
+ lookbackSeconds: number;
5
5
  maxCount: number;
6
+ timestampAnchor?: string | null;
6
7
  source?: string | null;
7
8
  metricName?: string | null;
8
9
  }): Promise<IWebResponseCompatible<IHealthMetric[]>>;
@@ -3,12 +3,19 @@ import { newServerClient } from "../supabase/server";
3
3
  import { EnumWebResponse, IWebResponse, } from "../types/requests";
4
4
  export async function server_get_health_metrics(device_id, options) {
5
5
  const supabase = await newServerClient();
6
- const since = new Date(Date.now() - options.lookbackMinutes * 60 * 1000).toISOString();
6
+ const lookbackMs = options.lookbackSeconds * 1000;
7
+ const anchorMs = options.timestampAnchor != null && options.timestampAnchor !== ""
8
+ ? new Date(options.timestampAnchor).getTime()
9
+ : Date.now();
10
+ const startMs = anchorMs - lookbackMs;
11
+ const startISO = new Date(startMs).toISOString();
12
+ const endISO = new Date(anchorMs).toISOString();
7
13
  let query = supabase
8
14
  .from("health_metrics")
9
15
  .select("*")
10
16
  .eq("device_id", device_id)
11
- .gte("timestamp", since)
17
+ .gte("timestamp", startISO)
18
+ .lt("timestamp", endISO)
12
19
  .order("timestamp", { ascending: false })
13
20
  .limit(options.maxCount);
14
21
  if (options.source != null && options.source !== "") {
@@ -1,3 +1,4 @@
1
+ import { type UseScoutRefreshOptions } from "../hooks/useScoutRefresh";
1
2
  import { ReactNode } from "react";
2
3
  import { SupabaseClient } from "@supabase/supabase-js";
3
4
  import { Database } from "../types/supabase";
@@ -1802,8 +1803,8 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
1802
1803
  PostgrestVersion: "13.0.5";
1803
1804
  }>;
1804
1805
  export declare function useConnectionStatus(): ConnectionStatus;
1805
- export interface ScoutRefreshProviderProps {
1806
+ export interface ScoutRefreshProviderProps extends UseScoutRefreshOptions {
1806
1807
  children: ReactNode;
1807
1808
  }
1808
- export declare function ScoutRefreshProvider({ children }: ScoutRefreshProviderProps): import("react/jsx-runtime").JSX.Element;
1809
+ export declare function ScoutRefreshProvider({ children, ...refreshOptions }: ScoutRefreshProviderProps): import("react/jsx-runtime").JSX.Element;
1809
1810
  export {};
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useScoutRefresh } from "../hooks/useScoutRefresh";
3
+ import { useScoutRefresh, } from "../hooks/useScoutRefresh";
4
4
  import { createContext, useContext, useMemo, useRef } from "react";
5
5
  import { createBrowserClient } from "@supabase/ssr";
6
6
  // Create context for the Supabase client
@@ -22,7 +22,7 @@ export function useConnectionStatus() {
22
22
  }
23
23
  return connectionStatus;
24
24
  }
25
- export function ScoutRefreshProvider({ children }) {
25
+ export function ScoutRefreshProvider({ children, ...refreshOptions }) {
26
26
  // Use refs to store the URL and key to prevent unnecessary recreations
27
27
  // Assumes Next.js environment variables (NEXT_PUBLIC_*)
28
28
  const urlRef = useRef(process.env.NEXT_PUBLIC_SUPABASE_URL || "");
@@ -32,7 +32,7 @@ export function ScoutRefreshProvider({ children }) {
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();
35
+ useScoutRefresh(refreshOptions);
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.10",
3
+ "version": "1.4.12",
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",