Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { getPool } from "@/lib/db";
|
|
import { withOrg, parsePagination, type Ctx } from "@/lib/api/handler";
|
|
import { ok, fail } from "@/lib/api/response";
|
|
import { requireRole } from "@/lib/authz/rbac";
|
|
import {
|
|
countEvidenceEvents,
|
|
listEvidenceEvents,
|
|
} from "@/lib/events/evidenceEvents";
|
|
import {
|
|
isEvidenceEventType,
|
|
type EvidenceEventLogEntry,
|
|
} from "@/lib/events/evidenceEvents.schemas";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
// GET /api/events/evidence — paginated, org-scoped log of emitted evidence
|
|
// lifecycle events (evidence.verified, dossier.built, dossier.published,
|
|
// signal.detected). Optional ?type= filter, validated against the known event
|
|
// catalogue. This is the source-side audit view of what fired, distinct from the
|
|
// per-endpoint delivery history under /api/webhooks. Admin+ only — the event log
|
|
// is governance/audit data, aligned with the webhook subsystem's admin gate.
|
|
export const GET = withOrg(async (req: NextRequest, ctx: Ctx) => {
|
|
try {
|
|
requireRole(ctx, "admin");
|
|
const pool = getPool();
|
|
const { limit, offset, page } = parsePagination(req);
|
|
|
|
const rawType = new URL(req.url).searchParams.get("type");
|
|
if (rawType !== null && !isEvidenceEventType(rawType)) {
|
|
return fail("Unknown evidence event type.", 400);
|
|
}
|
|
const eventType = rawType ?? undefined;
|
|
|
|
const [total, events] = await Promise.all([
|
|
countEvidenceEvents(pool, ctx.org.id, eventType),
|
|
listEvidenceEvents(pool, ctx.org.id, { limit, offset, eventType }),
|
|
]);
|
|
|
|
return ok<EvidenceEventLogEntry[]>(events, { total, page, limit });
|
|
} catch (err) {
|
|
if (err instanceof Error && "status" in err) {
|
|
return fail(err.message, (err as { status: number }).status);
|
|
}
|
|
return fail("Failed to load evidence events.", 500);
|
|
}
|
|
});
|