SurfSense/surfsense_web/tests/helpers/api/documents.ts
Anish Sarkar a8c1fb660d feat(rename): complete searchSpace to workspace transition across frontend and backend
- Introduced a comprehensive specification for renaming `searchSpace` to `workspace` in `surfsense_web` and `surfsense_desktop`, ensuring all TypeScript identifiers, React props, and local data structures are updated.
- Implemented migration shims for persisted local state to prevent data loss during the transition.
- Updated observability metrics and IPC channels to reflect the new naming convention.
- Removed legacy `active-search-space` module and replaced it with `active-workspace` to maintain consistency.
- Ensured no behavioral changes or data loss for users during the renaming process.
2026-07-06 15:12:40 +05:30

65 lines
1.8 KiB
TypeScript

import type { APIRequestContext } from "@playwright/test";
import { authHeaders, BACKEND_URL } from "./auth";
export type DocumentRow = {
id: number;
title: string;
content: string;
document_type: string;
status: { state?: string } | string;
};
type Paginated<T> = {
items?: T[];
total?: number;
};
export async function listDocuments(
request: APIRequestContext,
token: string,
workspaceId: number,
limit = 100
): Promise<DocumentRow[]> {
const response = await request.get(
`${BACKEND_URL}/api/v1/documents?workspace_id=${workspaceId}&limit=${limit}`,
{ headers: authHeaders(token) }
);
if (!response.ok()) {
throw new Error(`listDocuments failed (${response.status()}): ${await response.text()}`);
}
const body = (await response.json()) as Paginated<DocumentRow> | DocumentRow[];
return Array.isArray(body) ? body : (body.items ?? []);
}
export function isDocumentReady(doc: DocumentRow): boolean {
const state = typeof doc.status === "string" ? doc.status : doc.status?.state;
return state === "ready" || state === "READY";
}
export type EditorContent = {
document_id: number;
title: string;
document_type: string;
source_markdown: string;
content_size_bytes: number;
chunk_count: number;
viewer_mode?: "plate" | "monaco";
editor_plate_max_bytes?: number;
};
// Same endpoint the UI hits when a user opens a document in the dashboard.
export async function getEditorContent(
request: APIRequestContext,
token: string,
workspaceId: number,
documentId: number
): Promise<EditorContent> {
const response = await request.get(
`${BACKEND_URL}/api/v1/workspaces/${workspaceId}/documents/${documentId}/editor-content`,
{ headers: authHeaders(token) }
);
if (!response.ok()) {
throw new Error(`getEditorContent failed (${response.status()}): ${await response.text()}`);
}
return (await response.json()) as EditorContent;
}