ligbox-ops-platform/projects/cloudflare-agents/onboard/src/vm112-client.ts
Ligbox Spec Hub c1881f58e6 chore: sync Console SSO, DNS viewer, specs e infra docs pendentes
Inclui console handoff Desk↔Console (Spec 019), melhorias DNS Viewer (037),
OpenPanel/Nextcloud/VM116 deploy notes, contracts stack e sidebar actualizado.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-25 20:10:17 +00:00

37 lines
1.1 KiB
TypeScript

/**
* VM112 onboarding API client — Fase B/C
*/
export type Vm112Config = { baseUrl: string; sessionId: string };
export async function vm112Post(
cfg: Vm112Config,
path: string,
body: Record<string, unknown>,
): Promise<Record<string, unknown>> {
const res = await fetch(`${cfg.baseUrl}${path}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Onboarding-Session": cfg.sessionId,
},
body: JSON.stringify(body),
});
const data = (await res.json().catch(() => ({}))) as Record<string, unknown>;
if (!res.ok) {
const msg = (data.detail as string) || (data.message as string) || res.statusText;
throw new Error(typeof msg === "string" ? msg : JSON.stringify(msg));
}
return data;
}
export async function vm112Get(
cfg: Vm112Config,
path: string,
): Promise<Record<string, unknown>> {
const res = await fetch(`${cfg.baseUrl}${path}`, {
headers: { "X-Onboarding-Session": cfg.sessionId },
});
const data = (await res.json().catch(() => ({}))) as Record<string, unknown>;
if (!res.ok) throw new Error(res.statusText);
return data;
}