yap-studios / notion-kit

TypeScript packages for Notion's unofficial API, data types, and related utilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Notion + TypeScript

Notion Kit

TypeScript packages for Notion's unofficial API, data types, and related utilities.

NPM Build Status Prettier Code Formatting

Features

  • πŸš€ Simple - It's all TypeScript. Easy peasy.
  • ⚑ Fast - Concurrent network IO for fetching all resources on a page.
  • πŸ’― Tests - Comes with a comprehensive test suite covering 98% of Notion functionality.
  • πŸ““ Docs - Auto-generated docs for all packages.
  • πŸ”₯ Solid - Used in production by Notion X (coming soon), Notion VIP, and Notion2Site.

Usage

import { NotionAPI } from 'notion-client'

const api = new NotionAPI()

// fetch a notion page's content, including all async blocks, collection queries, and signed urls
const page = await api.getPage('067dd719-a912-471e-a9a3-ac10710e7fdf')

// fetch the data for a specific collection instance
const collectionId = '2d8aec23-8281-4a94-9090-caaf823dd21a'
const collectionViewId = 'ab639a5a-853e-45e1-9ef7-133b486c0acf'
const colectionData = await api.getCollectionData(
  collectionId,
  collectionViewId
)

You can optionally pass an authToken to NotionAPI if you need to access private notion resources.

Packages

Package NPM Docs Environment Description
notion-client NPM docs Server-side* Robust TypeScript client for the unofficial Notion API.
notion-types NPM docs Universal TypeScript types for core Notion data structures.
notion-utils NPM docs Universal Useful utilities for working with Notion data.

* Notion's API should not be called from client-side browsers due to CORS restrictions. notion-client is compatible with Node.js, Deno, and Cloudflare Workers.

Supported Blocks

The majority of Notion blocks and collection views are fully supported.

Block Type Supported Block Type Notes
Page βœ… Yes page
Text βœ… Yes text Includes all known text formatting options
Bookmark βœ… Yes bookmark Embedded preview of external URL
Bulleted List βœ… Yes bulleted_list <ul>
Numbered List βœ… Yes numbered_list <ol>
Heading 1 βœ… Yes header <h1>
Heading 2 βœ… Yes sub_header <h2>
Heading 3 βœ… Yes sub_sub_header <h3>
Quote βœ… Yes quote
Callout βœ… Yes callout
Equation (block) βœ… Yes equation katex via react-katex
Equation (inline) βœ… Yes text katex via react-katex
Todos (checkboxes) βœ… Yes to_do
Table Of Contents βœ… Yes table_of_contents See notion-utils `get
Divider βœ… Yes divider Horizontal line
Column βœ… Yes column
Column List βœ… Yes column_list
Toggle βœ… Yes toggle <details>
Image βœ… Yes image <img>
Embed βœ… Yes embed Generic iframe embeds
Video βœ… Yes video iframe
Figma βœ… Yes figma iframe
Google Maps βœ… Yes maps iframe
Google Drive βœ… Yes drive Google Docs, Sheets, etc custom embed
Tweet βœ… Yes tweet Uses the twitter embedding SDK
PDF βœ… Yes pdf Uses S3 signed URLs and react-pdf
Audio βœ… Yes audio Uses S3 signed URLs and HTML5 audio element
File βœ… Yes file Uses S3 signed URLs (generic downloadable file)
Link βœ… Yes text External links
Page Link βœ… Yes page Link to a notion page in the same workspace
External Page Link βœ… Yes text Links to a notion page or collection view in another workspace
Code (block) βœ… Yes code Block code syntax highlighting via prismjs
Code (inline) βœ… Yes text Inline code formatting (no syntax highlighting)
Collections βœ… Yes Also known as databases
Collection View βœ… Yes collection_view Collections have a 1:N mapping to collection views
Collection View Table βœ… Yes collection_view type = "table" (default table view)
Collection View Gallery βœ… Yes collection_view type = "gallery" (grid view)
Collection View Board βœ… Yes collection_view type = "board" (kanban view)
Collection View List βœ… Yes collection_view type = "list" (vertical list view)
Collection View Calendar ❌ Missing collection_view type = "calendar" (embedded calendar view)
Collection View Page βœ… Yes collection_view_page Collection view as a standalone page

Please let us know if you find any issues or missing blocks.

All known blocks and most known configuration settings can be found in our test suite.

Related

  • Notion Test Suite - Comprehensive suite of Notion test pages
    • Includes all individual blocks
    • Includes all collection views
    • Covers most formatting options
    • More edge cases and feature coverage will be added over time
  • react-notion - React renderer for Notion data.
  • notion-api-worker - Notion API proxy exposed as a Cloudflare Worker.
    • This provided a solid starting point for notion-types and notion-client.
    • Currently doesn't handle collection data very robustly.
    • One of the main use cases for react-notion is server-side rendering via Next.js, in which case the CF worker is unnecessary.
  • notion-api-agent - Alternative Notion API client.

License

MIT Β© Travis Fischer

Support my OSS work by following me on twitter twitter

This project extends MIT-licensed work by Timo Lins, Tobias Lins, Sam Wight, and other contributors.

About

TypeScript packages for Notion's unofficial API, data types, and related utilities.

License:MIT License


Languages

Language:TypeScript 96.9%Language:JavaScript 3.1%