UNPKG

l7note

Version:

Access your notion notes quick

52 lines (44 loc) 1.16 kB
import { Client } from '@notionhq/client'; import { SearchResponse } from '@notionhq/client/build/src/api-endpoints'; import chalk from 'chalk'; import { exit } from 'process'; import { globalConfig } from '../setup'; class NotionDatabase { id: string; title: string; properties: any; constructor(id: string, title: string, properties: any) { this.id = id; this.title = title; this.properties = properties; } } const getDatabaseList = async (): Promise<NotionDatabase[]> => { try { const notion = new Client({ auth: globalConfig.token, }); const data = await notion.search({ filter: { property: 'object', value: 'database', }, sort: { direction: 'descending', timestamp: 'last_edited_time', }, }); const results = data.results.map((database: any) => { return new NotionDatabase( database.id, database.title[0] ? database.title[0].plain_text : '', database.properties ); }); return results; } catch (err) { console.log(chalk.red('There was en error fetching your database list')); exit(1); } }; export { getDatabaseList };