import type { Account } from './account.ts' import { granolaRequest } from './client.ts' export const WEBHOOK_EVENTS = ['note.generated', 'note.edited', 'note.access_granted'] as const export const WEBHOOK_SCOPES = ['personal', 'public', 'workspace'] as const export type WebhookEndpoint = { id: string url: string url_redacted?: boolean events: Array folder_ids?: Array scopes: Array created_by?: { name?: string | null; email?: string } | null enabled: boolean created_at: string } export async function listWebhookEndpoints(a: Account): Promise> { const res = await granolaRequest<{ webhook_endpoints?: Array }>(a, { path: '/v1/webhook-endpoints' }) return res.data?.webhook_endpoints ?? [] } /** Read-only lookup used by update/delete previews; null when the key cannot see the endpoint. */ export async function findWebhookEndpoint(a: Account, id: string): Promise { return (await listWebhookEndpoints(a)).find((w) => w.id === id) ?? null } export function checkEnumList(name: string, values: Array | undefined, allowed: ReadonlyArray): void { const bad = (values ?? []).filter((v) => !allowed.includes(v)) if (bad.length) throw new Error(`${name} contains unsupported value(s) ${bad.join(', ')}; allowed: ${allowed.join(', ')}.`) }