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>
29 lines
896 B
TypeScript
29 lines
896 B
TypeScript
import { fail } from "@/lib/api/response";
|
|
import { z } from "zod";
|
|
|
|
// Shared helpers for the connectors API routes: map an RBAC error to its status
|
|
// and validate a route [id] param. Kept in a leaf file so route modules stay thin
|
|
// and consistent.
|
|
|
|
export const idSchema = z.string().uuid();
|
|
|
|
export function rbacStatus(err: unknown): number | null {
|
|
if (
|
|
err instanceof Error &&
|
|
typeof (err as unknown as { status?: unknown }).status === "number"
|
|
) {
|
|
return (err as unknown as { status: number }).status;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Maps a caught error to a NextResponse: RBAC errors keep their status, anything
|
|
// else becomes a 500 with the given user-facing message.
|
|
export function failFromError(err: unknown, fallback: string) {
|
|
const status = rbacStatus(err);
|
|
if (status !== null) {
|
|
return fail((err as Error).message, status);
|
|
}
|
|
return fail(fallback, 500);
|
|
}
|