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

50 lines
1.3 KiB
TypeScript

"use client";
import type { ApiResponse } from "@/lib/api/response";
// Client-side fetch helper for the documents module. Injects the active org id
// (persisted by the console layout) into the x-org-id header so withOrg targets
// the right tenant, and unwraps the standard ApiResponse envelope.
const ORG_STORAGE_KEY = "pt_active_org";
function activeOrgHeader(): Record<string, string> {
if (typeof window === "undefined") return {};
const id = window.localStorage.getItem(ORG_STORAGE_KEY);
return id ? { "x-org-id": id } : {};
}
export interface ApiResult<T> {
ok: boolean;
status: number;
data: T | null;
error: string | null;
meta?: ApiResponse<T>["meta"];
}
export async function apiFetch<T>(
path: string,
init?: RequestInit
): Promise<ApiResult<T>> {
try {
const res = await fetch(path, {
...init,
headers: {
"Content-Type": "application/json",
...activeOrgHeader(),
...(init?.headers ?? {}),
},
});
const body = (await res.json().catch(() => null)) as ApiResponse<T> | null;
return {
ok: res.ok && Boolean(body?.success),
status: res.status,
data: body?.data ?? null,
error: body?.error ?? (res.ok ? null : "Request failed."),
meta: body?.meta,
};
} catch {
return { ok: false, status: 0, data: null, error: "Network error." };
}
}