-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlist-calendars.ts
More file actions
46 lines (39 loc) · 1.43 KB
/
list-calendars.ts
File metadata and controls
46 lines (39 loc) · 1.43 KB
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
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function listCalendars() {
const conn = await connectToSuperhuman(9333, true);
if (!conn) return;
const result = await conn.Runtime.evaluate({
expression: `
(async () => {
try {
const ga = window.GoogleAccount;
const di = ga?.di;
if (!di) return { error: "DI not found" };
const isMicrosoft = di.get?.('isMicrosoft');
const accountEmail = ga?.emailAddress;
if (isMicrosoft) {
const msgraph = di.get?.('msgraph');
const calendars = await msgraph.getCalendars(accountEmail);
return { provider: 'microsoft', calendars };
} else {
const gcal = di.get?.('gcal');
try {
const url = 'https://www.googleapis.com/calendar/v3/users/me/calendarList';
const list = await gcal._getAsync(url, {}, { calendarAccountEmail: accountEmail, endpoint: 'gcal.calendarList.list', allowCachedResponses: true });
return { provider: 'google', list };
} catch (e) {
return { provider: 'google', err: e.message };
}
}
} catch (e) {
return { error: e.message };
}
})()
`,
returnByValue: true,
awaitPromise: true
});
console.log(JSON.stringify(result.result.value, null, 2));
await disconnect(conn);
}
listCalendars();