@goofmint/growi-js
v1.1.5
Published
This is a SDK for [GROWI](https://growi.org/) written in node.js.
Downloads
31
Readme
Growi node.js SDK
This is a SDK for GROWI written in node.js.
Installation
$ npm install @goofmint/growi-jsUsage
Create a client
import { GROWI } from '@goofmint/growi-js';
const growi = new GROWI({apiToken: 'YOUR_API_TOKEN'});Initialize parameters are as follows:
| Parameter | Description |
| --------- | ----------- |
| apiToken | API token for GROWI. You can get it from the setting page of GROWI. |
| url | URL of GROWI. Default is http://localhost:3000. |
| path | Endpoint path of Growi API. Default is /. |
Get root page
const page = await growi.root();
page instanceof growi.Page; // trueGet children of a page
const pages = await page.children();
pages[0] instanceof growi.Page; // trueUpdate page contents
page.contents('New contents');
await page.save();Get contents of a page
const contents = await page.contents();Create a page
const newPage = await page.create({name: 'New page'});Remove a page
await page.remove();Tag
Get tags of a page
const tags = await page.tags();Add a tag to a page
await page.addTag('tag');Remove a tag from a page
await page.removeTag('tag');Comment
Get comments of a page
const comments = await page.comments();Add a comment to a page
const comment = page.comment();
comment.set('comment', 'New comment');
await comment.save();Update a comment
comment.set('comment', 'Updated comment');
await comment.save();Remove a comment
await comment.remove();Search
Search pages
const result = await growi.search({q: 'keyword'});
result.pages[0] instanceof growi.Page; // true
result.total // total number of pages
result.took // time taken for search
result.hitsCount // number of hitsSearch by tag
const result = await growi.searchByTag('tag');
result.pages[0] instanceof growi.Page; // true
result.total // total number of pages
result.took // time taken for search
result.hitsCount // number of hitsAttachment
Upload an attachment
const page = await growi.page({path: '/API Test'});
const fileName = 'logo.png';
const attachment = await page.upload(path.resolve("jest", fileName));
attachment // Attachment instanceGet attachments of a page
const page = await growi.page({path: '/API Test'});
const res = await Attachment.list(page);
res.attachments // array of Attachment instances
res.limit // 10
res.page // 1
res.totalDocs // 20Check uploadable file size
const bol = await Attachment.limit(1024 * 1024 * 10);
bol // trueFind attachment
const a = await Attachment.find(attachment.id!);
a // Attachment instanceUser
Get current user
const user = await growi.currentUser();Bookmark Folder
Get bookmark folders
const bookmarkFolders = await user.bookmarkFolders();Create a bookmark folder
const bookmarkFolder = new BookmarkFolder();
bookmarkFolder.name = 'my folder';
await bookmarkFolder.save();Update a bookmark folder
bookmarkFolder.name = 'my folder updated';
await bookmarkFolder.save();Remove a bookmark folder
await bookmarkFolder.remove();Create a bookmark folder in a folder
const bookmarkFolder = new BookmarkFolder();
bookmarkFolder.name = 'Parent';
await bookmarkFolder.save();
const bookmarkFolder2 = new BookmarkFolder();
bookmarkFolder2.name = 'Child';
bookmarkFolder2.parent = bookmarkFolder;
await bookmarkFolder2.save();Or
const bookmarkFolder = new BookmarkFolder();
bookmarkFolder.name = 'Parent';
const bookmarkFolder2 = new BookmarkFolder();
bookmarkFolder2.name = 'Child';
await bookmarkFolder.addFolder(bookmarkFolder2);Move a bookmark folder
const bookmarkFolder3 = new BookmarkFolder();
bookmarkFolder3.name = 'New parent';
bookmarkFolder3.parent = bookmarkFolder2;
await bookmarkFolder3.save();Fetch folder info
await bookmarkFolder.fetch();Bookmark
Get my bookmarks
const bookmarks = await user.bookmarks();Get bookmark info of a page
const page = await growi.root();
const info = await page.bookmarkInfo();
info.bookmarkCount // number of bookmarks
info.bookmarked // true if the page is bookmarked by the current user
info.users // array of users who bookmarked the pageBookmark a page
await user.bookmark(page); // unbookmarkUnbookmark a page
await user.bookmark(page, false); // unbookmarkCheck if a page is bookmarked
const bol = await user.isBookmarked(page);Add bookmark to a folder
const folder = new BookmarkFolder();
folder.name = 'my folder';
await folder.save();
await folder.addPage(page);License
MIT
