/** * Unwrap the unified response envelope: * {"ok": true, "data": ...} -> returns { success: true, ...data } * {"ok": false, "error": ...} -> returns { success: false, error: message } * Also supports legacy format for backward compat. */ export function unwrap(json) { if (typeof json.ok === 'boolean') { if (json.ok) { const d = json.data || {}; return { success: true, ...(Array.isArray(d) ? { items: d } : d) }; } return { success: false, error: json.error?.message || 'Unknown error' }; } return json; }