UNPKG

l7note

Version:

Access your notion notes quick

85 lines (84 loc) 3.64 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.configureSettings = void 0; const chalk_1 = __importDefault(require("chalk")); const process_1 = require("process"); const prompts_1 = __importDefault(require("prompts")); const createDatabase_js_1 = require("./noteActions/createDatabase.js"); const getDatabaseList_js_1 = require("./noteActions/getDatabaseList.js"); const setup_js_1 = require("./setup.js"); const setupQuestions = [ { type: 'text', name: 'token', message: 'Enter your integration secret token:', validate: input => /secret_.*/.test(input) ? true : 'This input was not the right token', }, { type: 'select', name: 'select', message: 'Where is the database:', choices: [ { title: 'Use a existing database', value: 0 }, { title: 'Create a new database on a page', value: 1 }, ], }, ]; const pageIdQuestions = [ { type: 'text', name: 'pageId', message: 'Enter your Page Id', validate: input => /.{32}/.test(input) ? true : 'This input was not a real Id', }, ]; const configureSettings = () => __awaiter(void 0, void 0, void 0, function* () { const res = yield (0, prompts_1.default)(setupQuestions); if (!res.token) { (0, process_1.exit)(1); } setup_js_1.globalConfig.token = res.token; if (res.select == 0) { // const dbList = yield (0, getDatabaseList_js_1.getDatabaseList)(); const dbChoiseList = dbList.map(db => { return { title: db.title, value: db.id }; }); const dataBaseSelectQuestions = [ { type: 'select', name: 'databaseId', choices: dbChoiseList, message: 'Select the default database:', validate: input => /.{32}/.test(input) ? true : 'This input was not a real Id', }, ]; const dbSelectResponse = yield (0, prompts_1.default)(dataBaseSelectQuestions); const index = dbList.findIndex(index => index.id == dbSelectResponse.databaseId); if ('Done' in dbList[index].properties) { setup_js_1.globalConfig.dbId = dbSelectResponse.databaseId; } else { console.log(chalk_1.default.red('Selected database has the wrong properties ')); (0, process_1.exit)(1); } } else { const pageResponse = yield (0, prompts_1.default)(pageIdQuestions); setup_js_1.globalConfig.dbId = yield (0, createDatabase_js_1.createDataBase)(pageResponse.pageId); } (0, setup_js_1.saveConfig)(); }); exports.configureSettings = configureSettings;