// Thin fetch wrappers for all backend endpoints async function request(method, path, body) { const opts = { method, headers: { 'Content-Type': 'application/json' }, }; if (body !== undefined) opts.body = JSON.stringify(body); const resp = await fetch(path, opts); const data = await resp.json().catch(() => ({})); if (!resp.ok) { const msg = data.detail || data.error || `HTTP ${resp.status}`; throw Object.assign(new Error(msg), { status: resp.status, data }); } return data; } const GET = path => request('GET', path); const POST = (path, body) => request('POST', path, body); const PUT = (path, body) => request('PUT', path, body); export const api = { // ── Auth ────────────────────────────────────────────────────────────────── auth: { status() { return GET('/api/auth/status'); }, connectAdobe() { return GET('/api/auth/adobe/connect'); }, adobeUrl() { return GET('/api/auth/adobe/url'); }, exchangeAdobe(redirectUrl) { return POST('/api/auth/adobe/exchange', { redirect_url: redirectUrl }); }, connectDocusign() { return GET('/api/auth/docusign/connect'); }, disconnect(platform) { return GET(`/api/auth/${platform}/disconnect`); }, }, // ── Templates ───────────────────────────────────────────────────────────── templates: { status() { return GET('/api/templates/status'); }, adobe() { return GET('/api/templates/adobe'); }, docusign() { return GET('/api/templates/docusign'); }, }, // ── Migration ───────────────────────────────────────────────────────────── migrate: { run(body) { return POST('/api/migrate', body); }, batch(body) { return POST('/api/migrate/batch', body); }, batchStatus(jobId) { return GET(`/api/migrate/batch/${jobId}`); }, history() { return GET('/api/migrate/history'); }, }, // ── Verification ────────────────────────────────────────────────────────── verify: { send(templateId, recipientName, recipientEmail) { return POST('/api/verify/send', { template_id: templateId, recipient_name: recipientName, recipient_email: recipientEmail, }); }, status(envelopeId) { return GET(`/api/verify/status/${envelopeId}`); }, void(envelopeId, reason = 'Test envelope — voided after verification') { return POST(`/api/verify/void/${envelopeId}`, { reason }); }, }, };