const BASE_URL = process.env.UPPZY_BASE_URL || "https://api.uppzy.com/api/v1";
const API_KEY = process.env.UPPZY_API_KEY;
export async function uppzy(path, { method = "GET", body } = {}) {
const response = await fetch(`${BASE_URL}${path}`, {
method,
headers: {
"X-API-Key": API_KEY,
"Content-Type": "application/json",
},
body: body ? JSON.stringify(body) : undefined,
});
const text = await response.text();
const data = text ? JSON.parse(text) : null;
if (!response.ok) {
const error = new Error(`Uppzy API returned HTTP ${response.status}`);
error.status = response.status;
error.details = data;
throw error;
}
return data;
}