56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
/**
|
|
* 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<WebhookSubscription[]> {
|
|
return apiFetch<WebhookSubscription[]>('/api/webhooks');
|
|
}
|
|
|
|
export async function createSubscription(data: {
|
|
url: string;
|
|
events: string[];
|
|
description?: string;
|
|
}): Promise<WebhookSubscription> {
|
|
return apiFetch<WebhookSubscription>('/api/webhooks', {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
});
|
|
}
|
|
|
|
export async function deleteSubscription(id: string): Promise<void> {
|
|
await apiFetch<void>(`/api/webhooks/${id}`, { method: 'DELETE' });
|
|
}
|
|
|
|
export async function testWebhook(subscriptionId: string, eventType?: string): Promise<unknown> {
|
|
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');
|
|
}
|