Spaces:
Sleeping
Sleeping
Deploy Store Intelligence API + dashboard with multi-store config, camera visuals audit, event pipeline exits, and WebSocket isolation fix
78d4e18 Download dashboard/src/api/client.ts from SandeepChakka/store-intelligence: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/spaces/SandeepChakka/store-intelligence/resolve/main/dashboard/src/api/client.ts
- Command line
-
hf download hf://spaces/SandeepChakka/store-intelligence/dashboard/src/api/client.ts
-
curl -L -o client.ts https://huggingface.co/spaces/SandeepChakka/store-intelligence/resolve/main/dashboard/src/api/client.ts
1.82 kB
| import { apiUrl, getSelectedStoreId } from '../config'; | |
| import { | |
| normalizeAnomalies, | |
| normalizeFunnel, | |
| normalizeHeatmap, | |
| normalizeMetrics, | |
| } from './normalize'; | |
| import type { | |
| HealthResponse, | |
| StoreAnomalies, | |
| StoreFunnel, | |
| StoreHeatmap, | |
| StoreMetrics, | |
| } from '../types/api'; | |
| async function fetchJson<T>(path: string, init?: RequestInit): Promise<T> { | |
| const res = await fetch(apiUrl(path), { | |
| ...init, | |
| headers: { | |
| Accept: 'application/json', | |
| ...init?.headers, | |
| }, | |
| }); | |
| if (!res.ok) { | |
| const body = await res.text().catch(() => ''); | |
| throw new Error( | |
| `API ${res.status} ${res.statusText}${body ? `: ${body.slice(0, 200)}` : ''}`, | |
| ); | |
| } | |
| return res.json() as Promise<T>; | |
| } | |
| export async function getStoreMetrics(storeId = getSelectedStoreId()): Promise<StoreMetrics> { | |
| const raw = await fetchJson<Record<string, unknown>>( | |
| `/stores/${encodeURIComponent(storeId)}/metrics`, | |
| ); | |
| return normalizeMetrics(raw); | |
| } | |
| export async function getStoreFunnel(storeId = getSelectedStoreId()): Promise<StoreFunnel> { | |
| const raw = await fetchJson<Record<string, unknown>>( | |
| `/stores/${encodeURIComponent(storeId)}/funnel`, | |
| ); | |
| return normalizeFunnel(raw); | |
| } | |
| export async function getStoreHeatmap(storeId = getSelectedStoreId()): Promise<StoreHeatmap> { | |
| const raw = await fetchJson<Record<string, unknown>>( | |
| `/stores/${encodeURIComponent(storeId)}/heatmap`, | |
| ); | |
| return normalizeHeatmap(raw); | |
| } | |
| export async function getStoreAnomalies(storeId = getSelectedStoreId()): Promise<StoreAnomalies> { | |
| const raw = await fetchJson<Record<string, unknown>>( | |
| `/stores/${encodeURIComponent(storeId)}/anomalies`, | |
| ); | |
| return normalizeAnomalies(raw); | |
| } | |
| export function getHealth(): Promise<HealthResponse> { | |
| return fetchJson<HealthResponse>('/health'); | |
| } | |