UNPKG

l7note

Version:

Access your notion notes quick

53 lines (52 loc) 2.21 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDatabaseList = void 0; const client_1 = require("@notionhq/client"); const chalk_1 = __importDefault(require("chalk")); const process_1 = require("process"); const setup_1 = require("../setup"); class NotionDatabase { constructor(id, title, properties) { this.id = id; this.title = title; this.properties = properties; } } const getDatabaseList = () => __awaiter(void 0, void 0, void 0, function* () { try { const notion = new client_1.Client({ auth: setup_1.globalConfig.token, }); const data = yield notion.search({ filter: { property: 'object', value: 'database', }, sort: { direction: 'descending', timestamp: 'last_edited_time', }, }); const results = data.results.map((database) => { return new NotionDatabase(database.id, database.title[0] ? database.title[0].plain_text : '', database.properties); }); return results; } catch (err) { console.log(chalk_1.default.red('There was en error fetching your database list')); (0, process_1.exit)(1); } }); exports.getDatabaseList = getDatabaseList;