24 lines
950 B
JavaScript
24 lines
950 B
JavaScript
const apiBaseUrl = import.meta.env?.VITE_API_BASE_URL ?? '/api/v1';
|
|
|
|
async function request(path, options = {}) {
|
|
const response = await fetch(`${apiBaseUrl}${path}`, {
|
|
credentials: 'include',
|
|
...options,
|
|
headers: {
|
|
...(options.body ? { 'content-type': 'application/json' } : {}),
|
|
...options.headers,
|
|
},
|
|
});
|
|
const payload = await response.json().catch(() => null);
|
|
if (!response.ok) throw new Error(payload?.error?.message ?? 'Saved view request failed.');
|
|
return payload?.data;
|
|
}
|
|
|
|
export function listAdminSavedViews() { return request('/admin/saved-views'); }
|
|
export function createAdminSavedView(view, csrfToken) {
|
|
return request('/admin/saved-views', { method: 'POST', headers: { 'x-csrf-token': csrfToken }, body: JSON.stringify(view) });
|
|
}
|
|
export function deleteAdminSavedView(id, csrfToken) {
|
|
return request(`/admin/saved-views/${id}`, { method: 'DELETE', headers: { 'x-csrf-token': csrfToken } });
|
|
}
|