/** * Webhook management API client — talks to ChronoMind backend. */ import { apiFetch } from './api-helpers'; // ── Types ── export interface WebhookSubscription { id: string; url: string; events: string[]; active: boolean; description?: string; createdAt: string; consecutiveFailures: number; } export interface EventType { type: string; category: string; action: string; } // ── API calls ── export async function listSubscriptions(): Promise { return apiFetch('/api/webhooks'); } export async function createSubscription(data: { url: string; events: string[]; description?: string; }): Promise { return apiFetch('/api/webhooks', { method: 'POST', body: JSON.stringify(data), }); } export async function deleteSubscription(id: string): Promise { await apiFetch(`/api/webhooks/${id}`, { method: 'DELETE' }); } export async function testWebhook(subscriptionId: string, eventType?: string): Promise { return apiFetch('/api/webhooks/test', { method: 'POST', body: JSON.stringify({ subscriptionId, eventType }), }); } export async function getEventTypes(): Promise<{ eventTypes: EventType[] }> { return apiFetch<{ eventTypes: EventType[] }>('/api/webhooks/event-types'); }