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

94 lines
2.7 KiB
TypeScript

"use client";
// Client-side fetch helpers for the onboarding console pages. Attaches the active
// org id (persisted by the console layout) as the x-org-id header so withOrg scopes
// API calls to the org shown in the switcher, and unwraps the standard
// { success, data, error, meta } envelope into a small FetchResult shape.
import type { ApiResponse } from "@/lib/api/response";
import type {
Checklist,
OnboardingState,
SeededSample,
StepId,
} from "./types";
const ORG_STORAGE_KEY = "pt_active_org";
function orgHeaders(json = false): Record<string, string> {
const headers: Record<string, string> = {};
if (json) headers["Content-Type"] = "application/json";
if (typeof window !== "undefined") {
const orgId = window.localStorage.getItem(ORG_STORAGE_KEY);
if (orgId) headers["x-org-id"] = orgId;
}
return headers;
}
export interface FetchResult<T> {
data: T | null;
error: string | null;
}
async function unwrap<T>(res: Response): Promise<FetchResult<T>> {
const body = (await res.json().catch(() => null)) as ApiResponse<T> | null;
if (!body) {
return { data: null, error: "Unexpected response from server." };
}
if (!res.ok || !body.success) {
return { data: null, error: body.error ?? "Request failed." };
}
return { data: body.data ?? null, error: null };
}
export async function fetchState(): Promise<FetchResult<OnboardingState>> {
try {
const res = await fetch("/api/onboarding/state", {
headers: orgHeaders(),
cache: "no-store",
});
return unwrap<OnboardingState>(res);
} catch {
return { data: null, error: "Network error loading your progress." };
}
}
export async function fetchChecklist(): Promise<FetchResult<Checklist>> {
try {
const res = await fetch("/api/onboarding/checklist", {
headers: orgHeaders(),
cache: "no-store",
});
return unwrap<Checklist>(res);
} catch {
return { data: null, error: "Network error loading your checklist." };
}
}
export async function completeStep(
step: StepId
): Promise<FetchResult<OnboardingState>> {
try {
const res = await fetch("/api/onboarding/complete-step", {
method: "POST",
headers: orgHeaders(true),
body: JSON.stringify({ step }),
});
return unwrap<OnboardingState>(res);
} catch {
return { data: null, error: "Network error saving your progress." };
}
}
export async function seedSample(): Promise<FetchResult<SeededSample>> {
try {
const res = await fetch("/api/onboarding/seed-sample", {
method: "POST",
headers: orgHeaders(true),
});
return unwrap<SeededSample>(res);
} catch {
return { data: null, error: "Network error loading sample data." };
}
}