/// import { computed, Default, handler, NAME, pattern, Stream, UI, type VNode, Writable, } from "commontools"; // ===== Types ===== interface WebhookConfig { url: string; secret: string; } interface WebhookPatternInput { webhookConfig: Writable>; } interface WebhookPatternOutput { [NAME]: string; [UI]: VNode; webhookInbox: Stream; webhookConfig: WebhookConfig | null; lastEvent: unknown; } // ===== Handler ===== const onWebhookEvent = handler< unknown, { lastEvent: Writable } >((event, { lastEvent }) => { lastEvent.set(event); }); // ===== Pattern ===== const WebhookTest = pattern( ({ webhookConfig }) => { const lastEvent = Writable.of(null as unknown); const webhookInbox = onWebhookEvent({ lastEvent }); const inboxDisplay = computed(() => { const val = lastEvent.get(); if (val == null) return "No events received yet."; return JSON.stringify(val, null, 2); }); return { [NAME]: "Webhook Test Pattern", [UI]: ( Webhook Test Webhook Integration Click "Create Webhook" to register a new endpoint. The URL and secret will be stored in the config cell below. Last Received Event {inboxDisplay} ), webhookInbox, webhookConfig, lastEvent, }; }, ); export default WebhookTest;