npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

notion-client

v7.1.5

Published

Robust TypeScript client for the unofficial Notion API.

Downloads

173,865

Readme

notion-client

Robust TypeScript client for the unofficial Notion API.

NPM Build Status Prettier Code Formatting

Install

npm install notion-client

This package is compatible with server-side V8 contexts such as Node.js, Deno, and Cloudflare Workers.

Usage

import { NotionAPI } from 'notion-client'

// you can optionally pass an authToken to access private notion resources
const api = new NotionAPI()

// fetch a 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 collectionData = await api.getCollectionData(
  collectionId,
  collectionViewId
)

Fetch a database's content

You can pass a database ID to the getPage method. The response is an object which contains several important properties:

  • block
  • collection
  • collection_view

The value of the block property maps the id of each block object present in the database to its corresponding properties like type, parent id, created time, last edited by, and more.

{
  block: {
    'cc368b47-772a-4a1a-a36e-1f52c507d20d': { role: 'reader', value: [Object] },
    '97dbe6d5-aea3-4e03-b571-91810cf975d4': { role: 'reader', value: [Object] },
    '08d5ba1e-03d2-4d4a-add7-a414f297ff8a': { role: 'reader', value: [Object] },
    '7aad4627-c4af-4314-960e-1465e76cc6bd': { role: 'reader', value: [Object] },
    '7be73360-19b9-4b77-a518-70acd610d492': { role: 'reader', value: [Object] },
    'af961803-cd0c-470e-bd27-1d025baa2f95': { role: 'reader', value: [Object] },
    // ...
  }
}

The map of blocks is arranged as followed:

  • The first id is of the collection view
  • The second is of the parent page that contains the database in question
  • The next ids are of all the children pages inside the database
  • After that comes all the children blocks of each page.

Please note that a block object can take many types: header, text, list, media, and almost any block supported by Notion. It can also be a page or a collection view.

Example of a block object of type text:

{
  role: 'reader',
  value: {
    id: '0377e1a4-dc3d-4daf-99dd-f54f986d932e',
    version: 1,
    type: 'text',
    properties: { title: [Array] },
    format: { copied_from_pointer: [Object] },
    created_time: 1655961814278,
    last_edited_time: 1655961814278,
    parent_id: '08d5ba1e-03d2-4d4a-add7-a414f297ff8a',
    parent_table: 'block',
    alive: true,
    copied_from: '526d2008-0d0b-46f8-9de1-7411a85bff7b',
    created_by_table: 'notion_user',
    created_by_id: '55b29a2b-a8fe-4a11-9f9d-ada341bd922b',
    last_edited_by_table: 'notion_user',
    last_edited_by_id: '55b29a2b-a8fe-4a11-9f9d-ada341bd922b',
    space_id: '6b70425f-211e-4318-80c6-5d093df8f7eb'
  }
}

Example of a block object of type page:

{
  role: 'reader',
  value: {
    id: 'af961803-cd0c-470e-bd27-1d025baa2f95',
    version: 31,
    type: 'page',
    properties: { '==~K': [Array], 'BN]P': [Array], title: [Array] },
    content: [
      '8cbf7053-da37-4d69-8cde-89343baf3623',
      '0fc1712e-852c-4307-b72b-094dadaa86ba'
    ],
    created_time: 1655962200000,
    last_edited_time: 1655979420000,
    parent_id: '175482e5-870d-4da8-980c-ead469427316',
    parent_table: 'collection',
    alive: true,
    created_by_table: 'notion_user',
    created_by_id: '55b29a2b-a8fe-4a11-9f9d-ada341bd922b',
    last_edited_by_table: 'notion_user',
    last_edited_by_id: '55b29a2b-a8fe-4a11-9f9d-ada341bd922b',
    space_id: '6b70425f-211e-4318-80c6-5d093df8f7eb'
  }
}

Example of a block object of type collection_view:

{
  role: 'reader',
  value: {
    id: 'cc368b47-772a-4a1a-a36e-1f52c507d20d',
    version: 5,
    type: 'collection_view',
    view_ids: [
      '028f6968-2a6c-46da-bf43-cb44e6d91765',
      '77f32047-52dd-422e-93fa-813438087e57'
    ],
    collection_id: '175482e5-870d-4da8-980c-ead469427316',
    format: { collection_pointer: [Object], copied_from_pointer: [Object] },
    created_time: 1655961814276,
    last_edited_time: 1656075900000,
    parent_id: '97dbe6d5-aea3-4e03-b571-91810cf975d4',
    parent_table: 'block',
    alive: true,
    copied_from: '3e3073e9-7aee-481c-b831-765e112ec7b5',
    created_by_table: 'notion_user',
    created_by_id: '55b29a2b-a8fe-4a11-9f9d-ada341bd922b',
    last_edited_by_table: 'notion_user',
    last_edited_by_id: '55b29a2b-a8fe-4a11-9f9d-ada341bd922b',
    space_id: '6b70425f-211e-4318-80c6-5d093df8f7eb'
  }
}

Docs

See the full docs.

License

MIT © Travis Fischer

Support my OSS work by following me on twitter