feat: add comment support (list, get, create, update, delete) #3
22
src/index.ts
22
src/index.ts
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user