Files
mythic-oracle/public/js/api.js
T
claudecode 3a7340975f feat: Phase 3 campaign management
Campaign CRUD API with cascading delete across all campaign-scoped
tables, a systems endpoint to seed the create-campaign form, active
campaign state wired to the sidebar chaos factor, and a campaign
management view for creating/switching/deleting campaigns.
2026-06-30 23:22:34 -04:00

52 lines
1.2 KiB
JavaScript

// Mythic Oracle — shared fetch wrapper, all API calls
const BASE_URL = '/api';
async function request(path, options = {}) {
const response = await fetch(`${BASE_URL}${path}`, {
headers: { 'Content-Type': 'application/json' },
...options,
});
if (!response.ok) {
let message = `Request failed: ${response.status}`;
try {
const body = await response.json();
if (body.error) message = body.error;
} catch {
// no JSON body on the error response
}
throw new Error(message);
}
if (response.status === 204) {
return null;
}
return response.json();
}
export function getCampaigns() {
return request('/campaigns');
}
export function createCampaign(data) {
return request('/campaigns', { method: 'POST', body: JSON.stringify(data) });
}
export function getCampaign(id) {
return request(`/campaigns/${id}`);
}
export function updateCampaign(id, data) {
return request(`/campaigns/${id}`, { method: 'PATCH', body: JSON.stringify(data) });
}
export function deleteCampaign(id) {
return request(`/campaigns/${id}`, { method: 'DELETE' });
}
export function getSystems() {
return request('/systems');
}