feat(api): Vercel-native platform API + Postgres schema

Route Handlers (Vercel Functions): /api/health, /api/estimates (single-source estimate math, ore), /api/catalog, /api/sources (legal sourcing map). sql/001_init.sql = full docs/03 data model (entities + bridge_provenance + platform tables, pgvector). Ready to wire Vercel Postgres.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
2026-06-24 17:56:30 +02:00
co-authored by Claude Opus 4.8
parent f3b796a241
commit 15c65a584c
5 changed files with 224 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
import { NextResponse } from "next/server";
// GET /api/catalog (docs/04) — ready-made datasets. Static seed until DB is provisioned.
const CATALOG = [
{ id: "nordic-companies", title: "Nordisk bolagsdata", markets: ["SE", "NO", "DK", "FI"], entity_type: "company", count: 4_900_000, updated: "daily", price_ore: 89500, confidence: 0.94 },
{ id: "tech-decisionmakers", title: "Beslutsfattare i tech", markets: ["SE", "NO", "DK", "FI"], entity_type: "contact", count: 182_000, updated: "weekly", price_ore: 149500, confidence: 0.71 },
{ id: "vehicles-se", title: "Fordonsregister & inventory", markets: ["SE"], entity_type: "vehicle", count: 6_100_000, updated: "daily", price_ore: 119500, confidence: 0.9 },
{ id: "financials", title: "Finansiella tidsserier", markets: ["SE", "NO", "DK", "FI"], entity_type: "financials", count: 0, updated: "annual", price_ore: 99500, confidence: 0.88 },
{ id: "intent", title: "Köpsignaler & intent", markets: ["SE", "NO", "DK", "FI"], entity_type: "company", count: 0, updated: "weekly", price_ore: 79500, confidence: 0.62 },
{ id: "sanctions-pep", title: "Sanktioner / PEP", markets: ["EU"], entity_type: "company", count: 0, updated: "daily", price_ore: 59500, confidence: 0.95 },
];
export async function GET() {
return NextResponse.json(CATALOG);
}
+41
View File
@@ -0,0 +1,41 @@
import { NextRequest, NextResponse } from "next/server";
import { computeEstimate, type EntityType, type Frequency } from "@/lib/data";
// POST /api/estimates (docs/04) — price/time/confidence for a configured job.
// Single source of truth for the estimate math; the configurator calls this.
export async function POST(req: NextRequest) {
let body: Record<string, unknown>;
try {
body = await req.json();
} catch {
return NextResponse.json({ error: { code: "bad_json", message: "Invalid JSON body" } }, { status: 400 });
}
const markets = Array.isArray(body.markets) ? (body.markets as string[]) : [];
const entity_type = (body.entity_type as EntityType) || "Bolag";
const fields = Array.isArray(body.fields) ? (body.fields as string[]) : [];
const enrichment = Array.isArray(body.enrichment) ? (body.enrichment as string[]) : [];
const volume = Number(body.volume) || 1000;
const frequency = (body.frequency as Frequency) || "Engångs";
const confidence_target = Number(body.confidence_target) || 92;
const est = computeEstimate({
markets,
type: entity_type,
fieldIds: fields,
enrichmentIds: enrichment,
volume,
frequency,
confidence: confidence_target,
});
// amounts in öre (docs/03 convention)
return NextResponse.json({
total_ore: est.price * 100,
deposit_ore: est.deposit * 100,
balance_ore: est.remainder * 100,
est_days: est.timelineDays,
est_confidence: est.estConfidence / 100,
recurring: est.recurring,
});
}
+12
View File
@@ -0,0 +1,12 @@
import { NextResponse } from "next/server";
// GET /api/health — platform liveness (docs/04). DB/queue wired when provisioned.
export async function GET() {
return NextResponse.json({
ok: true,
service: "0pt-web",
db: Boolean(process.env.DATABASE_URL) ? "configured" : "not_configured",
queue: Boolean(process.env.REDIS_URL) ? "configured" : "not_configured",
ts: new Date().toISOString(),
});
}
+19
View File
@@ -0,0 +1,19 @@
import { NextResponse } from "next/server";
// GET /api/sources (docs/04) — the transparency moat. Legal sourcing only (CLAUDE.md §1).
// access: api | bulk | authorized_web | licensed. VERIFY current terms before relying.
const SOURCES = [
{ source_id: "gleif", name: "GLEIF (LEI)", market: "global", access: "api", licence: "open (CC0) — verify", cadence: "daily", confidence: 0.98 },
{ source_id: "brreg", name: "Brønnøysundregistrene", market: "NO", access: "api", licence: "NLOD open — verify", cadence: "daily", confidence: 0.97 },
{ source_id: "companies_house", name: "Companies House", market: "GB", access: "api", licence: "free (key) — verify", cadence: "daily", confidence: 0.97 },
{ source_id: "cvr", name: "CVR / Virk", market: "DK", access: "api", licence: "terms apply — verify", cadence: "daily", confidence: 0.95 },
{ source_id: "prh", name: "PRH avoindata", market: "FI", access: "api", licence: "CC-BY — verify", cadence: "daily", confidence: 0.93 },
{ source_id: "bolagsverket", name: "Bolagsverket", market: "SE", access: "licensed", licence: "restricted bulk — partner route", cadence: "daily", confidence: 0.92 },
{ source_id: "rdw", name: "RDW (vehicles)", market: "NL", access: "api", licence: "open — verify", cadence: "daily", confidence: 0.9 },
{ source_id: "traficom", name: "Traficom (vehicles)", market: "FI", access: "bulk", licence: "CC-BY — verify", cadence: "quarterly", confidence: 0.88 },
{ source_id: "opensanctions", name: "OpenSanctions", market: "global", access: "bulk", licence: "open — verify commercial terms", cadence: "daily", confidence: 0.95 },
];
export async function GET() {
return NextResponse.json(SOURCES);
}