Adds createScopedClient() — an openapi-fetch client bound to a specific Instance (rather than the active one in localStorage) — and the useScoped* TanStack Query hooks (workspaces, peers, peer representation, peer card) with per-instance query-key isolation so caches never collide across instances. Foundation for multi-instance features (seed kits, desktop auto-discover) that read from non-active instances. Co-authored-by: Ben Sheridan-Edwards <BenSheridanEdwards@users.noreply.github.com>
19 lines
825 B
TypeScript
19 lines
825 B
TypeScript
import createClient from "openapi-fetch";
|
|
import type { Instance } from "@/lib/config";
|
|
import { httpFetch } from "@/lib/http";
|
|
import type { paths } from "./schema.d.ts";
|
|
|
|
export type ScopedClient = ReturnType<typeof createClient<paths>>;
|
|
|
|
/**
|
|
* Create an openapi-fetch client bound to a specific instance. Use for views
|
|
* that need to query non-active instances (e.g. side-by-side comparison).
|
|
* For single-instance access, prefer `client.current` which tracks the active
|
|
* instance via localStorage.
|
|
*/
|
|
export function createScopedClient(instance: Instance): ScopedClient {
|
|
const headers: Record<string, string> = { "Content-Type": "application/json" };
|
|
if (instance.token) headers.Authorization = `Bearer ${instance.token}`;
|
|
return createClient<paths>({ baseUrl: instance.baseUrl, headers, fetch: httpFetch });
|
|
}
|