From 6cde1fddfc99e217fe8eb412359d22d983786a41 Mon Sep 17 00:00:00 2001 From: Max Nikitin Date: Tue, 10 Mar 2026 13:59:39 +0300 Subject: [PATCH] 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 --- src/index.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8198433..83ec704 100644 --- a/src/index.ts +++ b/src/index.ts @@ -334,8 +334,22 @@ class DocmostClient { // --- Comment Methods --- async listComments(pageId: string) { - const comments = await this.paginateAll("/comments", { pageId }); - return comments.map((comment: any) => { + await this.ensureAuthenticated(); + let allComments: any[] = []; + let cursor: string | null = null; + + do { + const payload: Record = { 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 ? convertProseMirrorToMarkdown(comment.content) : ""; @@ -367,7 +381,7 @@ class DocmostClient { const jsonContent = await markdownToTiptapJson(content); const payload: Record = { pageId, - content: jsonContent, + content: JSON.stringify(jsonContent), type, }; if (selection) payload.selection = selection; @@ -389,7 +403,7 @@ class DocmostClient { const jsonContent = await markdownToTiptapJson(content); const response = await this.client.post("/comments/update", { commentId, - content: jsonContent, + content: JSON.stringify(jsonContent), }); return { success: true,