import { NextRequest, NextResponse } from "next/server"; import { engineFetch } from "@/lib/engine"; // GET /api/screen?q=Name — OpenSanctions screening (sanctions/PEP). VERIFY // commercial terms before production volume. Defers to engine when running. export async function GET(req: NextRequest) { const q = req.nextUrl.searchParams.get("q") ?? ""; if (!q) return NextResponse.json({ matches: [] }); const eng = await engineFetch(`/screen?q=${encodeURIComponent(q)}`); if (eng && eng.ok) return NextResponse.json(await eng.json()); try { const r = await fetch(`https://api.opensanctions.org/search/default?q=${encodeURIComponent(q)}&limit=5`, { headers: { "User-Agent": "0pt/0.1 (+https://0pt.app; SIAX)" }, cache: "no-store", }); if (!r.ok) return NextResponse.json({ matches: [], source: "opensanctions" }); const data = (await r.json()) as { results?: { caption?: string; score?: number; schema?: string }[] }; return NextResponse.json({ source: "opensanctions", matches: (data.results ?? []).map((x) => ({ name: x.caption ?? null, score: x.score ?? null, schema: x.schema ?? null })), }); } catch { return NextResponse.json({ matches: [], source: "opensanctions" }); } }