-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (48 loc) · 1.06 KB
/
index.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
48
49
50
51
52
53
const fetch = require("node-fetch");
const crypto = require("crypto");
require("dotenv").config();
const token = process.env.TODOIST_API_KEY;
const themes = {
dark: 11,
light: 0,
};
const todoistAPI = async ({ data = {} }) => {
try {
let res = await fetch(`https://api.todoist.com/sync/v8/sync`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
token,
...data,
}),
});
return await res.json();
} catch (error) {
console.error(error.message);
}
};
const theme = process.argv[2];
const availableThemes = Object.keys(themes);
if (!availableThemes.includes(theme)) {
console.error(`Pass argument with one of: ${availableThemes.join(", ")}`);
return 1;
}
todoistAPI({
data: {
commands: [
{
type: "user_update",
uuid: crypto.randomBytes(20).toString("hex"),
args: { theme: themes[theme] },
},
],
},
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});