import { config } from 'dotenv'; import { resolve } from 'path'; config({ path: resolve(process.cwd(), '.env.local') }); import { generateMonthPreview } from '../src/lib/calendar-generate'; import type { RrssMonthPlan } from '../src/components/RrssMonthView'; async function main() { const url = process.env.NEXT_PUBLIC_SUPABASE_URL!; const key = process.env.SUPABASE_SERVICE_ROLE_KEY!; const h = { apikey: key, Authorization: `Bearer ${key}` }; const tid = '8bec977a-6032-4759-aa7f-b5042081f450'; const r = await fetch( `${url}/rest/v1/documents?tenant_id=eq.${tid}&type=eq.calendar&select=id,content&order=created_at.desc&limit=48`, { headers: h } ); const docs = (await r.json()) as { id: string; content: unknown }[]; const history: RrssMonthPlan[] = []; let novId: string | null = null; for (const d of docs) { const c = typeof d.content === 'string' ? JSON.parse(d.content) : d.content; const plan = c as RrssMonthPlan; if (plan?.month === '2026-11') novId = d.id; else if (plan?.month && Array.isArray(plan.pieces)) history.push(plan); } const result = await generateMonthPreview({ ym: '2026-11', slug: 'bps', label: 'Blue Parrot School', history, }); console.log('source', result.source); console.log('rationale\n', result.rationale); console.log('pieces', result.plan.pieces.length); for (const p of result.plan.pieces) { console.log(p.date, p.format.padEnd(8), '|', p.title); } if (!novId) { console.log('No Nov doc to patch'); return; } const patch = await fetch(`${url}/rest/v1/documents?id=eq.${novId}`, { method: 'PATCH', headers: { ...h, 'Content-Type': 'application/json', Prefer: 'return=minimal', }, body: JSON.stringify({ content: result.plan, title: 'RRSS Noviembre 2026', updated_at: new Date().toISOString(), }), }); console.log('patched', patch.status); } main().catch((e) => { console.error(e); process.exit(1); });