@tenonhq/dovetail-google-calendar 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/dist/client.d.ts +65 -0
- package/dist/client.js +271 -0
- package/dist/formatter.d.ts +13 -0
- package/dist/formatter.js +191 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +23 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.js +5 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @tenonhq/dovetail-google-calendar
|
|
2
|
+
|
|
3
|
+
Google Calendar API client for Dovetail. Provides event management and LLM-optimized agenda formatting for the CTO morning digest (`context/calendar.md`).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i -D @tenonhq/dovetail-google-calendar @tenonhq/dovetail-google-auth
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
Calendar auth is handled by [`@tenonhq/dovetail-google-auth`](../google-auth). Follow the setup in that package's README to obtain `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, and `GOOGLE_REFRESH_TOKEN`. The OAuth consent screen must enable the **Google Calendar API** with the `calendar` scope.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# .env
|
|
17
|
+
GOOGLE_CLIENT_ID=...
|
|
18
|
+
GOOGLE_CLIENT_SECRET=...
|
|
19
|
+
GOOGLE_REFRESH_TOKEN=...
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createGoogleAuth, configFromEnv } from "@tenonhq/dovetail-google-auth";
|
|
26
|
+
import {
|
|
27
|
+
createCalendarClient,
|
|
28
|
+
getTodayEvents,
|
|
29
|
+
getUpcomingEvents,
|
|
30
|
+
createEvent,
|
|
31
|
+
formatDailyAgenda,
|
|
32
|
+
} from "@tenonhq/dovetail-google-calendar";
|
|
33
|
+
|
|
34
|
+
var { auth } = createGoogleAuth({ config: configFromEnv() });
|
|
35
|
+
var client = createCalendarClient({ auth: auth });
|
|
36
|
+
|
|
37
|
+
var today = await getTodayEvents({ client: client });
|
|
38
|
+
var week = await getUpcomingEvents({ client: client, days: 7 });
|
|
39
|
+
|
|
40
|
+
var agenda = formatDailyAgenda({ events: today });
|
|
41
|
+
|
|
42
|
+
await createEvent({
|
|
43
|
+
client: client,
|
|
44
|
+
summary: "Strategy review",
|
|
45
|
+
start: "2026-04-20T09:00:00-04:00",
|
|
46
|
+
end: "2026-04-20T10:00:00-04:00",
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API Surface
|
|
51
|
+
|
|
52
|
+
- **Client:** `createCalendarClient`
|
|
53
|
+
- **Read:** `getTodayEvents`, `getUpcomingEvents`, `getEvent`, `searchEvents`
|
|
54
|
+
- **Write:** `createEvent`, `updateEvent`, `deleteEvent`
|
|
55
|
+
- **Formatting:** `formatDailyAgenda`, `formatEvent`
|
|
56
|
+
|
|
57
|
+
See `src/types.ts` for the full type surface.
|
|
58
|
+
|
|
59
|
+
## Related
|
|
60
|
+
|
|
61
|
+
- [`@tenonhq/dovetail-google-auth`](../google-auth) — shared OAuth2 layer
|
|
62
|
+
- [`@tenonhq/dovetail-gmail`](../gmail) — sibling Google integration
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { OAuth2Client } from "google-auth-library";
|
|
2
|
+
import { CalendarEvent, CalendarSearchResult, CalendarClient, GetTodayEventsParams, GetUpcomingEventsParams, GetEventParams, SearchEventsParams, CreateEventParams, UpdateEventParams, DeleteEventParams } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* @description Creates a Google Calendar API client from an authenticated OAuth2 client.
|
|
5
|
+
* @param params - Object with the OAuth2Client auth instance.
|
|
6
|
+
* @returns The Google Calendar API client.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createCalendarClient(params: {
|
|
9
|
+
auth: OAuth2Client;
|
|
10
|
+
}): CalendarClient;
|
|
11
|
+
/**
|
|
12
|
+
* @description Fetches today's calendar events.
|
|
13
|
+
* @param params - Object with client and optional calendarId and timeZone.
|
|
14
|
+
* @returns Array of calendar events for today.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getTodayEvents(params: {
|
|
17
|
+
client: CalendarClient;
|
|
18
|
+
} & GetTodayEventsParams): Promise<CalendarEvent[]>;
|
|
19
|
+
/**
|
|
20
|
+
* @description Fetches upcoming events for a configurable time range.
|
|
21
|
+
* @param params - Object with client, optional days (default 7), maxResults, calendarId, timeZone.
|
|
22
|
+
* @returns Search result with events and total count.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getUpcomingEvents(params: {
|
|
25
|
+
client: CalendarClient;
|
|
26
|
+
} & GetUpcomingEventsParams): Promise<CalendarSearchResult>;
|
|
27
|
+
/**
|
|
28
|
+
* @description Fetches a single calendar event by ID.
|
|
29
|
+
* @param params - Object with client, eventId, and optional calendarId.
|
|
30
|
+
* @returns The calendar event.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getEvent(params: {
|
|
33
|
+
client: CalendarClient;
|
|
34
|
+
} & GetEventParams): Promise<CalendarEvent>;
|
|
35
|
+
/**
|
|
36
|
+
* @description Searches calendar events by title or description.
|
|
37
|
+
* @param params - Object with client, query string, optional time range and calendarId.
|
|
38
|
+
* @returns Search result with matching events.
|
|
39
|
+
*/
|
|
40
|
+
export declare function searchEvents(params: {
|
|
41
|
+
client: CalendarClient;
|
|
42
|
+
} & SearchEventsParams): Promise<CalendarSearchResult>;
|
|
43
|
+
/**
|
|
44
|
+
* @description Creates a new calendar event.
|
|
45
|
+
* @param params - Object with client, summary, start, end, and optional fields.
|
|
46
|
+
* @returns The created event.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createEvent(params: {
|
|
49
|
+
client: CalendarClient;
|
|
50
|
+
} & CreateEventParams): Promise<CalendarEvent>;
|
|
51
|
+
/**
|
|
52
|
+
* @description Updates an existing calendar event (partial update).
|
|
53
|
+
* @param params - Object with client, eventId, and fields to update.
|
|
54
|
+
* @returns The updated event.
|
|
55
|
+
*/
|
|
56
|
+
export declare function updateEvent(params: {
|
|
57
|
+
client: CalendarClient;
|
|
58
|
+
} & UpdateEventParams): Promise<CalendarEvent>;
|
|
59
|
+
/**
|
|
60
|
+
* @description Deletes a calendar event.
|
|
61
|
+
* @param params - Object with client, eventId, and optional calendarId.
|
|
62
|
+
*/
|
|
63
|
+
export declare function deleteEvent(params: {
|
|
64
|
+
client: CalendarClient;
|
|
65
|
+
} & DeleteEventParams): Promise<void>;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCalendarClient = createCalendarClient;
|
|
4
|
+
exports.getTodayEvents = getTodayEvents;
|
|
5
|
+
exports.getUpcomingEvents = getUpcomingEvents;
|
|
6
|
+
exports.getEvent = getEvent;
|
|
7
|
+
exports.searchEvents = searchEvents;
|
|
8
|
+
exports.createEvent = createEvent;
|
|
9
|
+
exports.updateEvent = updateEvent;
|
|
10
|
+
exports.deleteEvent = deleteEvent;
|
|
11
|
+
const calendar_1 = require("@googleapis/calendar");
|
|
12
|
+
const dovetail_google_auth_1 = require("@tenonhq/dovetail-google-auth");
|
|
13
|
+
var DEFAULT_CALENDAR_ID = "primary";
|
|
14
|
+
// --- Client Factory ---
|
|
15
|
+
/**
|
|
16
|
+
* @description Creates a Google Calendar API client from an authenticated OAuth2 client.
|
|
17
|
+
* @param params - Object with the OAuth2Client auth instance.
|
|
18
|
+
* @returns The Google Calendar API client.
|
|
19
|
+
*/
|
|
20
|
+
function createCalendarClient(params) {
|
|
21
|
+
return (0, calendar_1.calendar)({ version: "v3", auth: params.auth });
|
|
22
|
+
}
|
|
23
|
+
// --- Read Operations ---
|
|
24
|
+
/**
|
|
25
|
+
* @description Fetches today's calendar events.
|
|
26
|
+
* @param params - Object with client and optional calendarId and timeZone.
|
|
27
|
+
* @returns Array of calendar events for today.
|
|
28
|
+
*/
|
|
29
|
+
async function getTodayEvents(params) {
|
|
30
|
+
try {
|
|
31
|
+
var now = new Date();
|
|
32
|
+
var startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
33
|
+
var endOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
|
|
34
|
+
var response = await params.client.events.list({
|
|
35
|
+
calendarId: params.calendarId || DEFAULT_CALENDAR_ID,
|
|
36
|
+
timeMin: startOfDay.toISOString(),
|
|
37
|
+
timeMax: endOfDay.toISOString(),
|
|
38
|
+
singleEvents: true,
|
|
39
|
+
orderBy: "startTime",
|
|
40
|
+
timeZone: params.timeZone,
|
|
41
|
+
});
|
|
42
|
+
var items = response.data.items || [];
|
|
43
|
+
var events = [];
|
|
44
|
+
for (var i = 0; i < items.length; i++) {
|
|
45
|
+
events.push(parseEvent(items[i]));
|
|
46
|
+
}
|
|
47
|
+
return events;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return (0, dovetail_google_auth_1.handleAuthError)(error, "fetching today's events");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @description Fetches upcoming events for a configurable time range.
|
|
55
|
+
* @param params - Object with client, optional days (default 7), maxResults, calendarId, timeZone.
|
|
56
|
+
* @returns Search result with events and total count.
|
|
57
|
+
*/
|
|
58
|
+
async function getUpcomingEvents(params) {
|
|
59
|
+
try {
|
|
60
|
+
var days = params.days !== undefined ? params.days : 7;
|
|
61
|
+
var now = new Date();
|
|
62
|
+
var end = new Date(now.getTime() + days * 24 * 60 * 60 * 1000);
|
|
63
|
+
var response = await params.client.events.list({
|
|
64
|
+
calendarId: params.calendarId || DEFAULT_CALENDAR_ID,
|
|
65
|
+
timeMin: now.toISOString(),
|
|
66
|
+
timeMax: end.toISOString(),
|
|
67
|
+
singleEvents: true,
|
|
68
|
+
orderBy: "startTime",
|
|
69
|
+
maxResults: params.maxResults || 50,
|
|
70
|
+
timeZone: params.timeZone,
|
|
71
|
+
});
|
|
72
|
+
var items = response.data.items || [];
|
|
73
|
+
var events = [];
|
|
74
|
+
for (var i = 0; i < items.length; i++) {
|
|
75
|
+
events.push(parseEvent(items[i]));
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
events: events,
|
|
79
|
+
total: events.length,
|
|
80
|
+
nextPageToken: response.data.nextPageToken || undefined,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
return (0, dovetail_google_auth_1.handleAuthError)(error, "fetching upcoming events");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @description Fetches a single calendar event by ID.
|
|
89
|
+
* @param params - Object with client, eventId, and optional calendarId.
|
|
90
|
+
* @returns The calendar event.
|
|
91
|
+
*/
|
|
92
|
+
async function getEvent(params) {
|
|
93
|
+
try {
|
|
94
|
+
var response = await params.client.events.get({
|
|
95
|
+
calendarId: params.calendarId || DEFAULT_CALENDAR_ID,
|
|
96
|
+
eventId: params.eventId,
|
|
97
|
+
});
|
|
98
|
+
return parseEvent(response.data);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return (0, dovetail_google_auth_1.handleAuthError)(error, "fetching event '" + params.eventId + "'");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @description Searches calendar events by title or description.
|
|
106
|
+
* @param params - Object with client, query string, optional time range and calendarId.
|
|
107
|
+
* @returns Search result with matching events.
|
|
108
|
+
*/
|
|
109
|
+
async function searchEvents(params) {
|
|
110
|
+
try {
|
|
111
|
+
var listParams = {
|
|
112
|
+
calendarId: params.calendarId || DEFAULT_CALENDAR_ID,
|
|
113
|
+
q: params.query,
|
|
114
|
+
singleEvents: true,
|
|
115
|
+
orderBy: "startTime",
|
|
116
|
+
maxResults: params.maxResults || 25,
|
|
117
|
+
};
|
|
118
|
+
if (params.timeMin) {
|
|
119
|
+
listParams.timeMin = params.timeMin;
|
|
120
|
+
}
|
|
121
|
+
if (params.timeMax) {
|
|
122
|
+
listParams.timeMax = params.timeMax;
|
|
123
|
+
}
|
|
124
|
+
var response = await params.client.events.list(listParams);
|
|
125
|
+
var items = response.data.items || [];
|
|
126
|
+
var events = [];
|
|
127
|
+
for (var i = 0; i < items.length; i++) {
|
|
128
|
+
events.push(parseEvent(items[i]));
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
events: events,
|
|
132
|
+
total: events.length,
|
|
133
|
+
nextPageToken: response.data.nextPageToken || undefined,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
return (0, dovetail_google_auth_1.handleAuthError)(error, "searching events for '" + params.query + "'");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// --- Write Operations ---
|
|
141
|
+
/**
|
|
142
|
+
* @description Creates a new calendar event.
|
|
143
|
+
* @param params - Object with client, summary, start, end, and optional fields.
|
|
144
|
+
* @returns The created event.
|
|
145
|
+
*/
|
|
146
|
+
async function createEvent(params) {
|
|
147
|
+
try {
|
|
148
|
+
var body = {
|
|
149
|
+
summary: params.summary,
|
|
150
|
+
start: params.start,
|
|
151
|
+
end: params.end,
|
|
152
|
+
};
|
|
153
|
+
if (params.description !== undefined) {
|
|
154
|
+
body.description = params.description;
|
|
155
|
+
}
|
|
156
|
+
if (params.location !== undefined) {
|
|
157
|
+
body.location = params.location;
|
|
158
|
+
}
|
|
159
|
+
if (params.attendees !== undefined) {
|
|
160
|
+
body.attendees = params.attendees.map(function (a) {
|
|
161
|
+
return { email: a.email, displayName: a.displayName };
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
var response = await params.client.events.insert({
|
|
165
|
+
calendarId: params.calendarId || DEFAULT_CALENDAR_ID,
|
|
166
|
+
requestBody: body,
|
|
167
|
+
});
|
|
168
|
+
return parseEvent(response.data);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
return (0, dovetail_google_auth_1.handleAuthError)(error, "creating event '" + params.summary + "'");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* @description Updates an existing calendar event (partial update).
|
|
176
|
+
* @param params - Object with client, eventId, and fields to update.
|
|
177
|
+
* @returns The updated event.
|
|
178
|
+
*/
|
|
179
|
+
async function updateEvent(params) {
|
|
180
|
+
try {
|
|
181
|
+
var body = {};
|
|
182
|
+
if (params.summary !== undefined) {
|
|
183
|
+
body.summary = params.summary;
|
|
184
|
+
}
|
|
185
|
+
if (params.start !== undefined) {
|
|
186
|
+
body.start = params.start;
|
|
187
|
+
}
|
|
188
|
+
if (params.end !== undefined) {
|
|
189
|
+
body.end = params.end;
|
|
190
|
+
}
|
|
191
|
+
if (params.description !== undefined) {
|
|
192
|
+
body.description = params.description;
|
|
193
|
+
}
|
|
194
|
+
if (params.location !== undefined) {
|
|
195
|
+
body.location = params.location;
|
|
196
|
+
}
|
|
197
|
+
var response = await params.client.events.patch({
|
|
198
|
+
calendarId: params.calendarId || DEFAULT_CALENDAR_ID,
|
|
199
|
+
eventId: params.eventId,
|
|
200
|
+
requestBody: body,
|
|
201
|
+
});
|
|
202
|
+
return parseEvent(response.data);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
return (0, dovetail_google_auth_1.handleAuthError)(error, "updating event '" + params.eventId + "'");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* @description Deletes a calendar event.
|
|
210
|
+
* @param params - Object with client, eventId, and optional calendarId.
|
|
211
|
+
*/
|
|
212
|
+
async function deleteEvent(params) {
|
|
213
|
+
try {
|
|
214
|
+
await params.client.events.delete({
|
|
215
|
+
calendarId: params.calendarId || DEFAULT_CALENDAR_ID,
|
|
216
|
+
eventId: params.eventId,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
return (0, dovetail_google_auth_1.handleAuthError)(error, "deleting event '" + params.eventId + "'");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// --- Internal Helpers ---
|
|
224
|
+
function parseEvent(event) {
|
|
225
|
+
var start = event.start || {};
|
|
226
|
+
var end = event.end || {};
|
|
227
|
+
var isAllDay = !start.dateTime && !!start.date;
|
|
228
|
+
var attendees = [];
|
|
229
|
+
if (event.attendees && Array.isArray(event.attendees)) {
|
|
230
|
+
for (var i = 0; i < event.attendees.length; i++) {
|
|
231
|
+
var a = event.attendees[i];
|
|
232
|
+
attendees.push({
|
|
233
|
+
email: a.email || "",
|
|
234
|
+
displayName: a.displayName || "",
|
|
235
|
+
responseStatus: a.responseStatus || "needsAction",
|
|
236
|
+
self: a.self === true,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
var organizer = { email: "", displayName: "", self: false };
|
|
241
|
+
if (event.organizer) {
|
|
242
|
+
organizer = {
|
|
243
|
+
email: event.organizer.email || "",
|
|
244
|
+
displayName: event.organizer.displayName || "",
|
|
245
|
+
self: event.organizer.self === true,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
id: event.id || "",
|
|
250
|
+
summary: event.summary || "(No title)",
|
|
251
|
+
description: event.description || "",
|
|
252
|
+
location: event.location || "",
|
|
253
|
+
start: {
|
|
254
|
+
dateTime: start.dateTime || undefined,
|
|
255
|
+
date: start.date || undefined,
|
|
256
|
+
timeZone: start.timeZone || undefined,
|
|
257
|
+
},
|
|
258
|
+
end: {
|
|
259
|
+
dateTime: end.dateTime || undefined,
|
|
260
|
+
date: end.date || undefined,
|
|
261
|
+
timeZone: end.timeZone || undefined,
|
|
262
|
+
},
|
|
263
|
+
attendees: attendees,
|
|
264
|
+
organizer: organizer,
|
|
265
|
+
status: event.status || "confirmed",
|
|
266
|
+
htmlLink: event.htmlLink || "",
|
|
267
|
+
isAllDay: isAllDay,
|
|
268
|
+
created: event.created || "",
|
|
269
|
+
updated: event.updated || "",
|
|
270
|
+
};
|
|
271
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FormatDailyAgendaParams, FormatEventParams } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @description Formats calendar events as a markdown daily agenda, optimized for LLM consumption.
|
|
4
|
+
* @param params - Object with events array and date.
|
|
5
|
+
* @returns Markdown-formatted string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatDailyAgenda(params: FormatDailyAgendaParams): string;
|
|
8
|
+
/**
|
|
9
|
+
* @description Formats a single calendar event as a detailed markdown view.
|
|
10
|
+
* @param params - Object with the event.
|
|
11
|
+
* @returns Markdown-formatted string.
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatEvent(params: FormatEventParams): string;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatDailyAgenda = formatDailyAgenda;
|
|
4
|
+
exports.formatEvent = formatEvent;
|
|
5
|
+
/**
|
|
6
|
+
* @description Formats calendar events as a markdown daily agenda, optimized for LLM consumption.
|
|
7
|
+
* @param params - Object with events array and date.
|
|
8
|
+
* @returns Markdown-formatted string.
|
|
9
|
+
*/
|
|
10
|
+
function formatDailyAgenda(params) {
|
|
11
|
+
var events = params.events;
|
|
12
|
+
var date = params.date;
|
|
13
|
+
var lines = [];
|
|
14
|
+
lines.push("## Calendar — " + formatDateHeader(date));
|
|
15
|
+
lines.push("");
|
|
16
|
+
if (events.length === 0) {
|
|
17
|
+
lines.push("_No events scheduled._");
|
|
18
|
+
lines.push("");
|
|
19
|
+
return lines.join("\n");
|
|
20
|
+
}
|
|
21
|
+
// Separate all-day events from timed events
|
|
22
|
+
var allDay = [];
|
|
23
|
+
var timed = [];
|
|
24
|
+
for (var i = 0; i < events.length; i++) {
|
|
25
|
+
if (events[i].isAllDay) {
|
|
26
|
+
allDay.push(events[i]);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
timed.push(events[i]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// All-day events
|
|
33
|
+
if (allDay.length > 0) {
|
|
34
|
+
lines.push("**All-day:**");
|
|
35
|
+
for (var a = 0; a < allDay.length; a++) {
|
|
36
|
+
var adEvent = allDay[a];
|
|
37
|
+
var adLine = "- " + adEvent.summary;
|
|
38
|
+
if (adEvent.location) {
|
|
39
|
+
adLine = adLine + " (" + adEvent.location + ")";
|
|
40
|
+
}
|
|
41
|
+
lines.push(adLine);
|
|
42
|
+
}
|
|
43
|
+
lines.push("");
|
|
44
|
+
}
|
|
45
|
+
// Timed events as table
|
|
46
|
+
if (timed.length > 0) {
|
|
47
|
+
lines.push("| Time | Event | Location |");
|
|
48
|
+
lines.push("|---|---|---|");
|
|
49
|
+
for (var t = 0; t < timed.length; t++) {
|
|
50
|
+
var event = timed[t];
|
|
51
|
+
var timeStr = formatTimeRange(event);
|
|
52
|
+
var location = event.location ? escapeCell(event.location) : "-";
|
|
53
|
+
lines.push("| " + timeStr +
|
|
54
|
+
" | " + escapeCell(event.summary) +
|
|
55
|
+
" | " + location + " |");
|
|
56
|
+
}
|
|
57
|
+
lines.push("");
|
|
58
|
+
}
|
|
59
|
+
// Summary line
|
|
60
|
+
var nextEvent = findNextEvent(timed);
|
|
61
|
+
if (nextEvent) {
|
|
62
|
+
lines.push("> " + events.length + " events today. Next: **" +
|
|
63
|
+
nextEvent.summary + "** at " + formatTime(nextEvent.start.dateTime || "") + ".");
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
lines.push("> " + events.length + " events today.");
|
|
67
|
+
}
|
|
68
|
+
lines.push("");
|
|
69
|
+
return lines.join("\n");
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @description Formats a single calendar event as a detailed markdown view.
|
|
73
|
+
* @param params - Object with the event.
|
|
74
|
+
* @returns Markdown-formatted string.
|
|
75
|
+
*/
|
|
76
|
+
function formatEvent(params) {
|
|
77
|
+
var event = params.event;
|
|
78
|
+
var lines = [];
|
|
79
|
+
lines.push("## Event: " + event.summary);
|
|
80
|
+
lines.push("");
|
|
81
|
+
if (event.isAllDay) {
|
|
82
|
+
var startDate = event.start.date || "Unknown";
|
|
83
|
+
var endDate = event.end.date || startDate;
|
|
84
|
+
lines.push("- **When:** " + startDate + " (all day)");
|
|
85
|
+
if (endDate !== startDate) {
|
|
86
|
+
lines.push("- **Until:** " + endDate);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
lines.push("- **When:** " + formatTimeRange(event));
|
|
91
|
+
}
|
|
92
|
+
if (event.location) {
|
|
93
|
+
lines.push("- **Location:** " + event.location);
|
|
94
|
+
}
|
|
95
|
+
lines.push("- **Status:** " + capitalize(event.status));
|
|
96
|
+
if (event.organizer && event.organizer.email) {
|
|
97
|
+
var orgLabel = event.organizer.displayName || event.organizer.email;
|
|
98
|
+
lines.push("- **Organizer:** " + orgLabel);
|
|
99
|
+
}
|
|
100
|
+
if (event.attendees.length > 0) {
|
|
101
|
+
lines.push("- **Attendees:**");
|
|
102
|
+
for (var i = 0; i < event.attendees.length; i++) {
|
|
103
|
+
var attendee = event.attendees[i];
|
|
104
|
+
var name = attendee.displayName || attendee.email;
|
|
105
|
+
var status = attendee.responseStatus;
|
|
106
|
+
var statusIcon = status === "accepted" ? "+" : status === "declined" ? "x" : "?";
|
|
107
|
+
lines.push(" - [" + statusIcon + "] " + name);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (event.htmlLink) {
|
|
111
|
+
lines.push("- **Link:** " + event.htmlLink);
|
|
112
|
+
}
|
|
113
|
+
if (event.description && event.description.trim() !== "") {
|
|
114
|
+
lines.push("");
|
|
115
|
+
lines.push("### Description");
|
|
116
|
+
lines.push("");
|
|
117
|
+
lines.push(event.description);
|
|
118
|
+
}
|
|
119
|
+
return lines.join("\n");
|
|
120
|
+
}
|
|
121
|
+
// --- Helpers ---
|
|
122
|
+
function formatDateHeader(date) {
|
|
123
|
+
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
124
|
+
var months = [
|
|
125
|
+
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
126
|
+
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
|
127
|
+
];
|
|
128
|
+
return (days[date.getDay()] + ", " +
|
|
129
|
+
months[date.getMonth()] + " " +
|
|
130
|
+
date.getDate() + ", " +
|
|
131
|
+
date.getFullYear());
|
|
132
|
+
}
|
|
133
|
+
function formatTimeRange(event) {
|
|
134
|
+
var startStr = formatTime(event.start.dateTime || "");
|
|
135
|
+
var endStr = formatTime(event.end.dateTime || "");
|
|
136
|
+
if (startStr && endStr) {
|
|
137
|
+
return startStr + " - " + endStr;
|
|
138
|
+
}
|
|
139
|
+
if (startStr) {
|
|
140
|
+
return startStr;
|
|
141
|
+
}
|
|
142
|
+
return "All day";
|
|
143
|
+
}
|
|
144
|
+
function formatTime(dateTimeStr) {
|
|
145
|
+
if (!dateTimeStr) {
|
|
146
|
+
return "";
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
var date = new Date(dateTimeStr);
|
|
150
|
+
if (isNaN(date.getTime())) {
|
|
151
|
+
return dateTimeStr;
|
|
152
|
+
}
|
|
153
|
+
var hours = date.getHours();
|
|
154
|
+
var ampm = hours >= 12 ? "PM" : "AM";
|
|
155
|
+
var displayHours = hours % 12;
|
|
156
|
+
if (displayHours === 0) {
|
|
157
|
+
displayHours = 12;
|
|
158
|
+
}
|
|
159
|
+
var minutes = date.getMinutes();
|
|
160
|
+
var minStr = minutes < 10 ? "0" + minutes : String(minutes);
|
|
161
|
+
return displayHours + ":" + minStr + " " + ampm;
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
return dateTimeStr;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function findNextEvent(events) {
|
|
168
|
+
var now = new Date();
|
|
169
|
+
for (var i = 0; i < events.length; i++) {
|
|
170
|
+
var startStr = events[i].start.dateTime;
|
|
171
|
+
if (startStr) {
|
|
172
|
+
var start = new Date(startStr);
|
|
173
|
+
if (start.getTime() > now.getTime()) {
|
|
174
|
+
return events[i];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
function escapeCell(str) {
|
|
181
|
+
if (!str) {
|
|
182
|
+
return "";
|
|
183
|
+
}
|
|
184
|
+
return str.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/\n/g, " ");
|
|
185
|
+
}
|
|
186
|
+
function capitalize(str) {
|
|
187
|
+
if (!str || str.length === 0) {
|
|
188
|
+
return str;
|
|
189
|
+
}
|
|
190
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
191
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tenonhq/dovetail-google-calendar
|
|
3
|
+
*
|
|
4
|
+
* Google Calendar API client for Dovetail.
|
|
5
|
+
* Provides event management, agenda queries, and LLM-optimized formatting.
|
|
6
|
+
*/
|
|
7
|
+
export { createCalendarClient, getTodayEvents, getUpcomingEvents, getEvent, searchEvents, createEvent, updateEvent, deleteEvent, } from "./client";
|
|
8
|
+
export { formatDailyAgenda, formatEvent, } from "./formatter";
|
|
9
|
+
export type { CalendarEvent, EventDateTime, EventAttendee, EventOrganizer, CalendarSearchResult, CalendarClient, GetTodayEventsParams, GetUpcomingEventsParams, GetEventParams, SearchEventsParams, CreateEventParams, UpdateEventParams, DeleteEventParams, FormatDailyAgendaParams, FormatEventParams, } from "./types";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @tenonhq/dovetail-google-calendar
|
|
4
|
+
*
|
|
5
|
+
* Google Calendar API client for Dovetail.
|
|
6
|
+
* Provides event management, agenda queries, and LLM-optimized formatting.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.formatEvent = exports.formatDailyAgenda = exports.deleteEvent = exports.updateEvent = exports.createEvent = exports.searchEvents = exports.getEvent = exports.getUpcomingEvents = exports.getTodayEvents = exports.createCalendarClient = void 0;
|
|
10
|
+
// Client and API functions
|
|
11
|
+
var client_1 = require("./client");
|
|
12
|
+
Object.defineProperty(exports, "createCalendarClient", { enumerable: true, get: function () { return client_1.createCalendarClient; } });
|
|
13
|
+
Object.defineProperty(exports, "getTodayEvents", { enumerable: true, get: function () { return client_1.getTodayEvents; } });
|
|
14
|
+
Object.defineProperty(exports, "getUpcomingEvents", { enumerable: true, get: function () { return client_1.getUpcomingEvents; } });
|
|
15
|
+
Object.defineProperty(exports, "getEvent", { enumerable: true, get: function () { return client_1.getEvent; } });
|
|
16
|
+
Object.defineProperty(exports, "searchEvents", { enumerable: true, get: function () { return client_1.searchEvents; } });
|
|
17
|
+
Object.defineProperty(exports, "createEvent", { enumerable: true, get: function () { return client_1.createEvent; } });
|
|
18
|
+
Object.defineProperty(exports, "updateEvent", { enumerable: true, get: function () { return client_1.updateEvent; } });
|
|
19
|
+
Object.defineProperty(exports, "deleteEvent", { enumerable: true, get: function () { return client_1.deleteEvent; } });
|
|
20
|
+
// Formatting utilities
|
|
21
|
+
var formatter_1 = require("./formatter");
|
|
22
|
+
Object.defineProperty(exports, "formatDailyAgenda", { enumerable: true, get: function () { return formatter_1.formatDailyAgenda; } });
|
|
23
|
+
Object.defineProperty(exports, "formatEvent", { enumerable: true, get: function () { return formatter_1.formatEvent; } });
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Calendar API type definitions for Dovetail integration.
|
|
3
|
+
*/
|
|
4
|
+
import { calendar_v3 } from "@googleapis/calendar";
|
|
5
|
+
export interface CalendarEvent {
|
|
6
|
+
id: string;
|
|
7
|
+
summary: string;
|
|
8
|
+
description: string;
|
|
9
|
+
location: string;
|
|
10
|
+
start: EventDateTime;
|
|
11
|
+
end: EventDateTime;
|
|
12
|
+
attendees: EventAttendee[];
|
|
13
|
+
organizer: EventOrganizer;
|
|
14
|
+
status: string;
|
|
15
|
+
htmlLink: string;
|
|
16
|
+
isAllDay: boolean;
|
|
17
|
+
created: string;
|
|
18
|
+
updated: string;
|
|
19
|
+
}
|
|
20
|
+
export interface EventDateTime {
|
|
21
|
+
dateTime?: string;
|
|
22
|
+
date?: string;
|
|
23
|
+
timeZone?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface EventAttendee {
|
|
26
|
+
email: string;
|
|
27
|
+
displayName: string;
|
|
28
|
+
responseStatus: string;
|
|
29
|
+
self: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface EventOrganizer {
|
|
32
|
+
email: string;
|
|
33
|
+
displayName: string;
|
|
34
|
+
self: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface CalendarSearchResult {
|
|
37
|
+
events: CalendarEvent[];
|
|
38
|
+
total: number;
|
|
39
|
+
nextPageToken?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface GetTodayEventsParams {
|
|
42
|
+
calendarId?: string;
|
|
43
|
+
timeZone?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface GetUpcomingEventsParams {
|
|
46
|
+
calendarId?: string;
|
|
47
|
+
days?: number;
|
|
48
|
+
maxResults?: number;
|
|
49
|
+
timeZone?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface GetEventParams {
|
|
52
|
+
eventId: string;
|
|
53
|
+
calendarId?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface SearchEventsParams {
|
|
56
|
+
query: string;
|
|
57
|
+
timeMin?: string;
|
|
58
|
+
timeMax?: string;
|
|
59
|
+
calendarId?: string;
|
|
60
|
+
maxResults?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface CreateEventParams {
|
|
63
|
+
summary: string;
|
|
64
|
+
start: EventDateTime;
|
|
65
|
+
end: EventDateTime;
|
|
66
|
+
description?: string;
|
|
67
|
+
location?: string;
|
|
68
|
+
attendees?: EventAttendee[];
|
|
69
|
+
calendarId?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface UpdateEventParams {
|
|
72
|
+
eventId: string;
|
|
73
|
+
summary?: string;
|
|
74
|
+
start?: EventDateTime;
|
|
75
|
+
end?: EventDateTime;
|
|
76
|
+
description?: string;
|
|
77
|
+
location?: string;
|
|
78
|
+
calendarId?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface DeleteEventParams {
|
|
81
|
+
eventId: string;
|
|
82
|
+
calendarId?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface FormatDailyAgendaParams {
|
|
85
|
+
events: CalendarEvent[];
|
|
86
|
+
date: Date;
|
|
87
|
+
}
|
|
88
|
+
export interface FormatEventParams {
|
|
89
|
+
event: CalendarEvent;
|
|
90
|
+
}
|
|
91
|
+
export type CalendarClient = calendar_v3.Calendar;
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tenonhq/dovetail-google-calendar",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "Google Calendar API client for Dovetail — event management and agenda formatting",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"prepack": "tsc",
|
|
9
|
+
"version:bump": "node ./../../Scripts/bump-version.js ./package.json",
|
|
10
|
+
"postpublish": "npm run version:bump"
|
|
11
|
+
},
|
|
12
|
+
"author": "Multiple",
|
|
13
|
+
"license": "GPL-3.0",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@googleapis/calendar": "^9.0.0"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@tenonhq/dovetail-google-auth": "^0.0.9"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@tenonhq/dovetail-google-auth": "^0.0.9",
|
|
22
|
+
"@types/jest": "^29.5.5",
|
|
23
|
+
"@types/node": ">=20.8.4",
|
|
24
|
+
"jest": "^29.7.0",
|
|
25
|
+
"ts-jest": "^29.1.1",
|
|
26
|
+
"typescript": "^5.2.2"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/tenonhq/dovetail.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/tenonhq/dovetail/issues"
|
|
40
|
+
}
|
|
41
|
+
}
|