/** * api/events.js — Client des endpoints Hub /events (vue staff RSVP). * Miroir de services/targo-hub/lib/events.js. Passe par le proxy /ops/hub * (jeton HUB_SERVICE_TOKEN injecté) → routes /events gatées (PII). * * listEvents() → { events:[{id,name,date_iso,active}] } * listRsvps(eventId) → { event:{...,public_url}, responses:[], count, headcount, matched, unmatched } * deleteRsvp(eventId, key) → { ok } * sendInvite(eventId, body) → envoi d'invitations (GATÉ — non branché pour l'instant) */ import { HUB_URL } from 'src/config/hub' async function hubFetch (path, { method = 'GET', body } = {}) { const opts = { method, headers: { 'Content-Type': 'application/json' } } if (body) opts.body = JSON.stringify(body) const res = await fetch(`${HUB_URL}${path}`, opts) const text = await res.text() let data try { data = text ? JSON.parse(text) : {} } catch { throw new Error(`Réponse invalide de ${path}`) } if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`) return data } export async function listEvents () { return hubFetch('/events') } export async function listRsvps (eventId) { return hubFetch(`/events/${encodeURIComponent(eventId)}/rsvps`) } export async function deleteRsvp (eventId, key) { return hubFetch(`/events/${encodeURIComponent(eventId)}/rsvps/${encodeURIComponent(key)}`, { method: 'DELETE' }) } export async function sendInvite (eventId, body) { return hubFetch(`/events/${encodeURIComponent(eventId)}/send`, { method: 'POST', body }) } export async function previewAudience (eventId, body) { return hubFetch(`/events/${encodeURIComponent(eventId)}/audience`, { method: 'POST', body }) } export async function listTemplates () { return hubFetch('/campaigns/templates') }