caelum0x 9ed86fa715 feat(apps): roadmap batch — agent-console, creator-dashboard, marketplace, admin, dashboard
- agent-console: Agents (ERC-8004 identity/reputation) + Jobs (ERC-8183 lifecycle timeline) pages via Local ports; 'Agent economy' nav group.
- creator-dashboard: per-source detail + per-payout royalty-split breakdown pages (stable slug/settlementId routing).
- marketplace: listing/service detail page + tag/search filtering.
- admin: settlements console.
- dashboard: Profile card (EditProfile) wired to PATCH /v1/auth/account.
- 1308 tests / 213 suites, typecheck + all app builds green.
2026-06-21 02:04:43 +03:00

63 lines
2.1 KiB
TypeScript

import { headers } from "next/headers";
import type {
AdminDeliveryRun,
AdminEntitlement,
AdminOrganization,
AdminPayment,
AdminRiskProfile,
AdminSettlement,
AdminWebhookEvent,
} from "./types";
import type { PlatformOverview } from "./service";
/**
* Server-side API client. Pages (server components) call these to read through
* the app's own /api/v1 route handlers, keeping a single data path and a real
* HTTP boundary between the UI and the service layer.
*/
/** Standard API envelope used by every route handler. */
export interface ApiEnvelope<T> {
readonly ok: boolean;
readonly data: T | null;
readonly error: string | null;
}
function baseUrl(): string {
const explicit = process.env.NEXT_PUBLIC_ADMIN_URL ?? process.env.ADMIN_BASE_URL;
if (explicit) return explicit.replace(/\/$/, "");
const h = headers();
const host = h.get("x-forwarded-host") ?? h.get("host") ?? "localhost:3002";
const proto = h.get("x-forwarded-proto") ?? (host.startsWith("localhost") ? "http" : "https");
return `${proto}://${host}`;
}
async function getJson<T>(path: string): Promise<T> {
const res = await fetch(`${baseUrl()}${path}`, {
cache: "no-store",
headers: { accept: "application/json" },
});
const body = (await res.json()) as ApiEnvelope<T>;
if (!res.ok || !body.ok || body.data === null) {
throw new Error(body.error ?? `Request to ${path} failed (${res.status})`);
}
return body.data;
}
export const api = {
overview: () => getJson<PlatformOverview>("/api/v1/overview"),
organizations: () => getJson<AdminOrganization[]>("/api/v1/organizations"),
organization: (id: string) =>
getJson<{
organization: AdminOrganization;
payments: AdminPayment[];
entitlements: AdminEntitlement[];
deliveryRuns: AdminDeliveryRun[];
}>(`/api/v1/organizations/${encodeURIComponent(id)}`),
riskProfiles: () => getJson<AdminRiskProfile[]>("/api/v1/risk"),
settlements: () => getJson<AdminSettlement[]>("/api/v1/settlements"),
failedDeliveries: () =>
getJson<AdminDeliveryRun[]>("/api/v1/delivery-runs?status=failed"),
webhookEvents: () => getJson<AdminWebhookEvent[]>("/api/v1/webhooks"),
};