caelum0x 695a365ae4 feat: PaperTrail — enterprise evidence-verification platform
Multi-tenant platform (182 pages, 228 API routes, ~30 modules) built on a
deterministic verification core: clinical-trial claims checked against
ClinicalTrials.gov registered results and raw event counts (ARR/NNT/RR+CI
recomputed in code, oracle-tested), code-enforced exact-span grounding, and
multi-source cross-verification. Auth/RBAC/multi-tenancy, document processing
at scale (unpdf + Docling), agentic workflows, Claude Science connector,
compliance/audit, billing, public API, and more.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 07:21:22 +03:00

42 lines
1.3 KiB
TypeScript

import type { NextRequest } from "next/server";
import { withOrg, type Ctx } from "@/lib/api/handler";
import { created, fail } from "@/lib/api/response";
import { getPool } from "@/lib/db";
import { writeAudit } from "@/lib/audit";
import { requireRole } from "@/lib/authz/rbac";
import { runSync } from "@/lib/connectors/service";
import { idSchema, failFromError } from "../../_lib";
export const runtime = "nodejs";
// POST /api/connectors/[id]/sync — run a sync now. Records a completed sync row
// (with item count + status) and an inbound event. Editor+.
export const POST = withOrg(async (_req: NextRequest, ctx: Ctx, params) => {
try {
requireRole(ctx, "editor");
const parsed = idSchema.safeParse(params?.id);
if (!parsed.success) {
return fail("Invalid connector id.", 400);
}
const sync = await runSync(ctx.org.id, parsed.data);
if (!sync) {
return fail("Connector not found.", 404);
}
await writeAudit(getPool(), {
orgId: ctx.org.id,
userId: ctx.user.id,
action: "connector.sync",
entityType: "connector",
entityId: parsed.data,
metadata: { status: sync.status, items: sync.items },
});
return created(sync);
} catch (err: unknown) {
return failFromError(err, "Couldn't run the sync. Please try again.");
}
});