// Append-only one-line-per-delivery log of webhook activity. Lives at // /data/webhook.log so it's persistent across container restarts and // readable from `gs logs`. Best-effort writes — if the disk is full or // the file is locked, we don't crash the webhook handler. import { appendFileSync } from 'node:fs'; const LOG_PATH = process.env.GS_WEBHOOK_LOG ?? '/data/webhook.log'; export interface WebhookLogEntry { siteSlug: string; action: 'sync' | 'delete' | 'ignore' | 'rejected'; postId?: string; slug?: string; status: 'ok' | 'failed' | 'ignored' | 'rejected'; atUri?: string; error?: string; reason?: string; } export function logWebhookDelivery(entry: WebhookLogEntry): void { const line = JSON.stringify({ ts: new Date().toISOString(), ...entry }) + '\n'; try { appendFileSync(LOG_PATH, line); } catch { // Best-effort; don't take the webhook down if logging fails. } }