// ═══════════════════════════════════════════════════════════════════════════ // LandveX Finance — API Client // ═══════════════════════════════════════════════════════════════════════════ export class API { constructor(opts = {}) { this.baseUrl = opts.baseUrl || '/api/ledger'; this.tenant = opts.tenant || 'landvex'; this.getToken = opts.getToken || (() => localStorage.getItem('lv_token')); } async request(method, path, body = null) { const url = this.baseUrl + path; const headers = { 'Content-Type': 'application/json', 'x-tenant-id': this.tenant, }; const token = this.getToken(); if (token) headers['Authorization'] = `Bearer ${token}`; const opts = { method, headers }; if (body) opts.body = JSON.stringify(body); const res = await fetch(url, opts); if (!res.ok) { const err = new Error(`HTTP ${res.status}`); err.status = res.status; try { err.data = await res.json(); } catch {} throw err; } return res.json(); } get(path) { return this.request('GET', path); } post(path, body) { return this.request('POST', path, body); } put(path, body) { return this.request('PUT', path, body); } delete(path) { return this.request('DELETE', path); } }