import { withErrors, ok } from "@/lib/api"; import { requireUser } from "@/lib/auth"; import { runOsa } from "@/lib/mac"; // GET /api/integrations/calendars — names of local Calendar.app calendars, // for the Settings picker. Returns [] if Calendar isn't reachable. export const GET = withErrors(async (req) => { await requireUser(req); try { const out = await runOsa(`tell application "Calendar" to get name of calendars`, 15_000); const calendars = out .trim() .split(",") .map((s) => s.trim()) .filter(Boolean); return ok({ calendars }); } catch (err) { return ok({ calendars: [], error: err instanceof Error ? err.message : "unavailable" }); } });