import { claimLocateRequest } from '@/lib/db'; import { corsJson, corsPreflight } from '../../cors'; /** The extension takes the oldest pending request. Claiming marks it in-flight so * the next poll doesn't run the same click a second time. */ export async function POST() { const row = claimLocateRequest(); if (!row) return corsJson({ request: null }); return corsJson({ request: { id: row.id, selector: row.selector, index: row.match_index, urlPattern: row.url_pattern, openUrl: row.open_url, navigateUrl: row.navigate_url, options: (() => { try { return JSON.parse(row.options); } catch { return {}; } })(), }, }); } export async function OPTIONS() { return corsPreflight(); }