• Stars
    star
    124
  • Rank 286,386 (Top 6 %)
  • Language
    TypeScript
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

API wrapper for Notion's database [WIP]

⚠️ Notion API 变动、不建议使用此项目。等官方 API 开放

⚠️ DO NOT use this

Notabase (WIP)

API Wrapper For Notion's Database

Getting Started

Installing

yarn add notabase

Use

You can use notabse in browser, browser extension, and node. But there is a difference when initializing the notabase instance.

Node

Env Token Read Write Note
node public data you can only read public data without token
node private data you can read and modify private data with token
import Notabase from 'notabase'

// node env
// just Read public data
let nb = new Notabase()
// CRUD support
let nb = new Notabase({
  token: "token_v2 from cookies"
})

Browser

If you want to use Notabase in your web pages, you need to handle CORS. You can solve this problem with a cloudflare worker.Generate a cloudflare-worker using the code from src/cf-worker.js

In the browser environment, we don't use token directly, instead we use authcode to handle identity checks. You need to set an authcode that only you know in your cf-worker , and then we use it when initializing the notabase instance.

Env authCode Read Write Note
browser public data just read public data without authCode
browser private data you can read and modify private data with authCode
import Notabase from 'notabase'

// browser env
// without authCode Read public data
// with authCode CRUD support
let nb = new Notabase({
  proxy: {
    url: "cloudflare worker url",
    authCode: "nobody knows it but you"
  }
})

Browser Extension

import Notabase from 'notabase'

// browser extension env
// CRUD support without setting anything
let nb = new Notabase()

withCredentials

Fetch Data

Method Note
fetch fetch data from one table, but you can't query relation data
fetchAll fetch data from multiple tables, you can query relation data if relation table has been fetched
// fetch one table
let songs = await nb.fetch("https://www.notion.so/2628769120ad41d998ec068d6e2eb410?v=e8e69ac68a8d483792c54541e4d8ba72")


// fetch all tables about music
// get my music data
let db = await nb.fetchAll({
  songs: "https://www.notion.so/2628769120ad41d998ec068d6e2eb410?v=e8e69ac68a8d483792c54541e4d8ba72",
  albums: "https://www.notion.so/15f1759f38a34fedaa79262812b707f0?v=b385656739214101b2b8a159092a52e8",
  artists: "https://www.notion.so/31b8544ffb034964b1aa56bfa78497c1?v=1d9cbfcd279d4534964acdd374c9824e"
})

Query

Data in Notion table will be mapped to JavaScript Array

// get all songs
let allSongs = db.songs.rows
 
// get song by index
let song = allSongs[0]

// get one song's title (base props)
console.log(`${song.tile}`)

// get artist's name of the song (related props)
console.log(`${song.artist[0].Name}`) // a song maybe has two or more artists

// search song by title in song's table
let aSong = allSongs.find(song=> song.title === "Bad Guy")
// search all song by artist's name in song's table
let songByArtistName = allSongs.filter(song=> song.artist[0].name === "someone")
// search all song by artist's name in artist's table
songByArtistName = db.artists.rows.filter(a=> a.name === "someone").songs

Write

let aSong = allSongs.find(song=> song.title === "Bad Guy")
aSong.title = "new title"

Create

// create then modify
let newRow = collection.addRow()
// if tag1 is not exists, it will be auto created. 
newRow.Tags = ["tag1"]


// create with value
collection.addRow({title:"",Tags:["tag1"]}) 

Delete

// delete row 
aSong.delete()

Update Table Schema

// change
collection.schema.Tags.options.push({
  id:nb.genId(),
  value: "new tag",
  color: "pink"
})

// commit
collection.updateSchema()

Todos

collection

  • collection.addRow({title:"",Tags:["tag1"]}) // add new row
  • updateSchema // update schema

row

  • row.delete() // delete a row

all

  • Rewrite in TypeScript

More Repositories

1

eidos

Offline alternative to Notion. Eidos is an extensible framework for managing your personal data throughout your lifetime in one place.
TypeScript
1,443
star
2

NotionPlus

Programming in Notion.so
TypeScript
181
star
3

gine-blog

Blog = Gatsby + React + Material-UI + Notion + Netlify
JavaScript
179
star
4

gatsby-source-notion-database

Load data from Notion's database [WIP]
JavaScript
91
star
5

gsbg

生成由随机彩色图形组成的简易背景图 a react app that generate simple background images
JavaScript
63
star
6

gatsby-starter-gine-blog

Blog powered by Notion.so
JavaScript
53
star
7

phos

Solution for personal music/podcast management based on Notion.so
JavaScript
53
star
8

gatsby-starter-notion

Starter kit to build site with Gatsby.js & Notion.so
JavaScript
29
star
9

InfoCard

Infocard 是一款 Chrome 扩展( Web App),在你每次打开新标签页时随机展示知识卡片, 利用零碎的时间学习知识。
JavaScript
16
star
10

stable-diffusion-webapi

API Client for the stable-diffusion-webui
8
star
11

awesome-notion

good tools for notion.so
Python
7
star
12

notion-bill

基于 notion 的账单结算工具
Python
4
star
13

weather

天气预报,纯前端 Ajax,各种api调用。
JavaScript
2
star
14

eidos-extension-system

TypeScript
2
star
15

eidos-api-agent-node

API agent implemented in Node for Eidos.
TypeScript
2
star
16

altair

制作任意 gif 为表情模板
JavaScript
2
star
17

Alice

JavaScript
2
star
18

some-site

JavaScript
2
star
19

gine-starter-kit

构建离线优先、移动优先 PWA 的开发工具包
TypeScript
1
star
20

blog

cache for notion post html
1
star
21

mdxtree

Rust
1
star
22

eidos-script-template

TypeScript
1
star
23

eidos-script-publish

TypeScript
1
star
24

gine

yet another blog powered by Notion & Next.js [WIP]
TypeScript
1
star
25

awesome-eidos

A curated list of awesome Eidos related things.
1
star