AcadeDoc/apps/client/src/features/acadenice/graph/services/graph-client.ts
Corentin 9dd283ced6 refactor(acadedoc): rename API routes /api/acadenice -> /api/v1 — R5.1
Replace all @Controller('acadenice/...') decorators with 'v1/...' on 16 NestJS controllers. Update all client services, hooks, tests, extension-clipper, and doc comments to match. DB table names (acadenice_*) and folder structure untouched.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-08 14:52:49 +02:00

73 lines
1.9 KiB
TypeScript

/**
* HTTP client for the graph endpoint (R3.5.1 backend).
*
* Uses the shared Docmost `api` axios instance (same base "/api" and cookie auth)
* rather than the bridge client — the graph endpoint lives on the Docmost server.
*/
import api from "@/lib/api-client";
export interface GraphNode {
id: string;
label: string | null;
/** URL slug for /p/:slug navigation — null when the page has no slug yet */
slug: string | null;
type: "page";
spaceId: string;
spaceName: string | null;
icon: string | null;
isOrphan: boolean;
metrics: {
inDegree: number;
outDegree: number;
};
}
export interface GraphEdge {
id: string;
source: string;
target: string;
type: "wikilink" | "mention" | "database_embed" | "parent_child";
weight: number;
}
export interface GraphMeta {
totalNodes: number;
totalEdges: number;
workspaceId: string;
rootPageId?: string;
depth?: number;
truncated: boolean;
}
export interface GraphResponse {
nodes: GraphNode[];
edges: GraphEdge[];
meta: GraphMeta;
}
export interface GraphQueryParams {
spaceId?: string;
pageId?: string;
depth?: number;
types?: Array<"wikilink" | "mention" | "database_embed">;
includeOrphans?: boolean;
}
export async function fetchGraph(
params: GraphQueryParams,
): Promise<GraphResponse> {
const query: Record<string, string> = {};
if (params.spaceId) query.spaceId = params.spaceId;
if (params.pageId) query.pageId = params.pageId;
if (params.depth !== undefined) query.depth = String(params.depth);
if (params.types && params.types.length > 0)
query.types = params.types.join(",");
if (params.includeOrphans !== undefined)
query.includeOrphans = String(params.includeOrphans);
const qs = new URLSearchParams(query).toString();
const url = qs ? `/v1/graph?${qs}` : "/v1/graph";
return api.get(url) as unknown as Promise<GraphResponse>;
}