// lib/api.ts — shared types and fetch helpers export type Repo = { name: string; node: string; path: string } export async function listRepos(): Promise { const r = await fetch('/api/repos', { credentials: 'include' }) if (!r.ok) throw new Error('failed to list repos') return r.json() } export async function listBranches(repo: string): Promise { const r = await fetch(`/api/repos/branches?repo=${encodeURIComponent(repo)}`, { credentials: 'include' }) if (!r.ok) throw new Error('failed to list branches') return r.json() } export type DeployResponse = { id: string } export async function startDeploy(payload: { repository: string branch: string username: string password: string }): Promise { const r = await fetch('/api/deployments', { method: 'POST', headers: { 'content-type': 'application/json' }, credentials: 'include', body: JSON.stringify(payload), }) if (!r.ok) { const text = await r.text() throw new Error(text || 'deploy failed') } return r.json() }