import { apiFetch } from './api'; import type { EntityResponse, InventoryTreeNode, ListResponse, NodeContext, Relation } from '../types/inventory'; async function handleResponse(response: Response): Promise { if (!response.ok) throw new Error(`API error: ${response.status}`); return response.json() as Promise; } async function fetchJson(path: string): Promise { const response = await apiFetch(path, { cache: 'no-store' }); return handleResponse(response); } export async function fetchInventoryTree(): Promise { const data = await fetchJson>('/inventory/tree'); return data.items; } export async function fetchNodeContext(id: string): Promise { const data = await fetchJson>(`/inventory/nodes/${id}/context`); return data.item; } export async function fetchNodeRelations(id: string): Promise { const data = await fetchJson>(`/inventory/nodes/${id}/relations`); return data.items; }