-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
47 lines (38 loc) · 1.16 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require("dotenv").config();
const credentials = {
email: process.env.NEUROSITY_EMAIL || "",
password: process.env.NEUROSITY_PASSWORD || "",
};
const { Notion } = require("@neurosity/notion");
const spinner = require("ora")().start();
const checkCredentials = () => {
const isMissing = (env) => {
return env === "" || env === 0;
};
if (isMissing(credentials.email) || isMissing(credentials.password)) {
spinner.stop("Please verify email and password are in .env file, quitting...");
process.exit(0);
}
};
const connect = async () => {
checkCredentials();
spinner.start(`${credentials.email} attempting to authenticate`);
const notion = new Notion();
await notion
.login({
email: credentials.email,
password: credentials.password,
})
.catch((error) => {
spinner.fail(`Connection to Notion headset failed!`);
throw new Error(error);
});
const { deviceNickname } = await notion.getSelectedDevice();
spinner.succeed(`Connected to Notion headset: ${deviceNickname}`);
return notion;
};
const wait = (time) => new Promise((res) => setTimeout(res, time * 1000));
module.exports = {
connect,
wait,
};