bookstack-sdk
v1.0.1
Published
A lightweight Node.js SDK for the [BookStack API](https://demo.bookstackapp.com/api/docs).
Readme
bookstacksdk
A lightweight Node.js SDK for the BookStack API.
Installation
npm install bookstack-sdkRequirements
- Node.js 18+ (uses native
fetch)
Quick Start
import BookstackSDK from 'bookstack-sdk';
const sdk = new BookstackSDK({
apiHost: 'https://docs.your-domain.com',
apiKey: 'your_token_id',
apiSecret: 'your_token_secret'
});
const books = await sdk.book.list({ count: 5, sort: '-id' });
console.log(books);Configuration
You can pass credentials in the constructor or use environment variables.
Constructor options
apiHost: BookStack base URL (without trailing/api)apiKey: API token IDapiSecret: API token secret
Environment variables
BOOKSTACK_API_HOST=https://docs.your-domain.com
BOOKSTACK_API_KEY=your_token_id
BOOKSTACK_API_SECRET=your_token_secretAvailable Resources
sdk.booksdk.pagesdk.chaptersdk.shelfsdk.user
Each resource supports:
list(params?)create(data)read(id)update(id, data)delete(id)
Examples
Create a page
const page = await sdk.page.create({
book_id: 1,
name: 'My New Page',
markdown: '# Hello from SDK'
});Read a chapter
const chapter = await sdk.chapter.read(5);Update a shelf
const shelf = await sdk.shelf.update(3, {
name: 'Updated Shelf Name'
});Error Handling
The SDK throws an Error when the BookStack API returns a non-2xx response.
try {
await sdk.book.read(999999);
} catch (error) {
console.error(error.message);
}License
ISC
