fix: stringify comment content and use cursor-based pagination

Docmost comment API requires `content` as a JSON string, not a JSON object.
Also, comments use cursor-based pagination (nextCursor/prevCursor) instead
of page-based pagination used by other endpoints.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Max Nikitin
2026-03-10 13:59:39 +03:00
parent a739d62318
commit 6cde1fddfc

View File

@@ -334,8 +334,22 @@ class DocmostClient {
// --- Comment Methods --- // --- Comment Methods ---
async listComments(pageId: string) { async listComments(pageId: string) {
const comments = await this.paginateAll("/comments", { pageId }); await this.ensureAuthenticated();
return comments.map((comment: any) => { let allComments: any[] = [];
let cursor: string | null = null;
do {
const payload: Record<string, any> = { pageId, limit: 100 };
if (cursor) payload.cursor = cursor;
const response = await this.client.post("/comments", payload);
const data = response.data.data || response.data;
const items = data.items || [];
allComments = allComments.concat(items);
cursor = data.meta?.nextCursor || null;
} while (cursor);
return allComments.map((comment: any) => {
const markdown = comment.content const markdown = comment.content
? convertProseMirrorToMarkdown(comment.content) ? convertProseMirrorToMarkdown(comment.content)
: ""; : "";
@@ -367,7 +381,7 @@ class DocmostClient {
const jsonContent = await markdownToTiptapJson(content); const jsonContent = await markdownToTiptapJson(content);
const payload: Record<string, any> = { const payload: Record<string, any> = {
pageId, pageId,
content: jsonContent, content: JSON.stringify(jsonContent),
type, type,
}; };
if (selection) payload.selection = selection; if (selection) payload.selection = selection;
@@ -389,7 +403,7 @@ class DocmostClient {
const jsonContent = await markdownToTiptapJson(content); const jsonContent = await markdownToTiptapJson(content);
const response = await this.client.post("/comments/update", { const response = await this.client.post("/comments/update", {
commentId, commentId,
content: jsonContent, content: JSON.stringify(jsonContent),
}); });
return { return {
success: true, success: true,