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:
22
src/index.ts
22
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<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
|
||||
? convertProseMirrorToMarkdown(comment.content)
|
||||
: "";
|
||||
@@ -367,7 +381,7 @@ class DocmostClient {
|
||||
const jsonContent = await markdownToTiptapJson(content);
|
||||
const payload: Record<string, any> = {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user