@tachikomas/notion-kit
v0.0.3
Published
Mintnoii notion-kit
Downloads
16
Readme
Notion-Kit
Notion-Kit is a TypeScript library that simplifies interactions with the Notion API. It provides a convenient way to query databases, retrieve pages, and handle various types of Notion blocks.
Installation
npm install @tachikomas/notion-kit
Usage
Initializing Notion Kit
To get started, initialize the Notion Kit by providing your Notion token:
import { NotionKit } from '@tachikomas/notion-kit';
const {notion} = new NotionKit({
token: 'your-notion-token',
});
Querying Databases
To query a database, use the queryDatabase
method:
const database = await notion.queryDatabase({
database_id: 'your-database-id',
filter: {
property: 'Status',
status: {
equals: 'Blog',
}
}
});
Retrieving Pages
To retrieve a page, use the retrievePage
method:
const page = await notion.retrievePage ({
page_id: 'your-page-id',
});
Retrieve Block Children
To retrieve a block's children, use the retrieveBlockChildren
method:
const blocks = await listBlocks(page_id, start_cursor)
// or custom your own getAllBlocks
export const getAllBlocks = async (page_id: string, start_cursor?: string | null) => {
const blocks = await listBlocks(page_id, start_cursor)
const { results, has_more, next_cursor } = blocks
const data = results as IBlockObjectResp[]
if (has_more) {
const more_blocks = await getAllBlocks(page_id, next_cursor)
data.push(...more_blocks)
}
return data as IBlockObjectResp[]
}
Formatting Content Blocks
Use the formatContent method to format different types of content blocks:
const blockObject = {
// specify
};
const formattedContent = formatContent(blockObject);
License
This library is licensed under the MIT
License. See the LICENSE file for details.