/** * Netlify scheduled function — daily reconciliation of Helcim payments. * * Calls the protected Nitro route `/api/internal/reconcile-payments` with the * shared-secret header. Heavy lifting (Mongo queries, Helcim API calls, retry * logic) lives in the Nitro handler so it can use auto-imported utils. * * Required env (set in Netlify dashboard): * - URL (set automatically by Netlify) * - RECONCILE_TOKEN (must match NUXT_RECONCILE_TOKEN in Nitro runtime config) * * Schedule: @daily (00:00 UTC). Also pinned in netlify.toml. */ export default async () => { const url = `${process.env.URL}/api/internal/reconcile-payments` const token = process.env.RECONCILE_TOKEN if (!token) { const msg = '[reconcile] RECONCILE_TOKEN not configured; aborting' console.error(msg) return new Response(msg, { status: 500 }) } const res = await fetch(url, { method: 'POST', headers: { 'X-Reconcile-Token': token } }) const body = await res.text() if (!res.ok) { console.error('[reconcile] route failed', res.status, body) return new Response(body, { status: res.status }) } console.log('[reconcile] ok', body) return new Response(body, { status: 200 }) } export const config = { schedule: '@daily' }