@mindstone/mcp-server-google-workspace 0.1.5 → 0.3.0
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 +28 -9
- package/dist/modules/accounts/manager.js +20 -2
- package/dist/modules/accounts/token.d.ts +13 -0
- package/dist/modules/accounts/token.js +73 -58
- package/dist/modules/accounts/types.d.ts +1 -0
- package/dist/modules/calendar/service.js +9 -0
- package/dist/modules/chat/index.d.ts +12 -0
- package/dist/modules/chat/index.js +18 -0
- package/dist/modules/chat/scopes.d.ts +14 -0
- package/dist/modules/chat/scopes.js +32 -0
- package/dist/modules/chat/types.d.ts +88 -0
- package/dist/modules/chat/types.js +14 -0
- package/dist/modules/comments/service.js +26 -5
- package/dist/modules/contacts/scopes.d.ts +1 -0
- package/dist/modules/contacts/scopes.js +2 -2
- package/dist/modules/contacts/types.d.ts +34 -0
- package/dist/modules/docs/index.js +2 -1
- package/dist/modules/docs/service.js +36 -7
- package/dist/modules/drive/activity-service.d.ts +45 -0
- package/dist/modules/drive/activity-service.js +114 -0
- package/dist/modules/drive/index.d.ts +4 -0
- package/dist/modules/drive/index.js +12 -0
- package/dist/modules/drive/scopes.d.ts +1 -0
- package/dist/modules/drive/scopes.js +3 -0
- package/dist/modules/drive/service.d.ts +2 -1
- package/dist/modules/drive/service.js +29 -0
- package/dist/modules/drive/types.d.ts +8 -0
- package/dist/modules/forms/service.js +16 -3
- package/dist/modules/gmail/services/attachment.js +2 -1
- package/dist/modules/gmail/services/base.d.ts +5 -1
- package/dist/modules/gmail/services/base.js +10 -1
- package/dist/modules/gmail/services/draft.js +13 -7
- package/dist/modules/gmail/services/email.js +4 -3
- package/dist/modules/gmail/services/label.js +10 -9
- package/dist/modules/gmail/services/settings.d.ts +14 -1
- package/dist/modules/gmail/services/settings.js +96 -1
- package/dist/modules/gmail/types.d.ts +36 -0
- package/dist/modules/meet/index.d.ts +12 -0
- package/dist/modules/meet/index.js +18 -0
- package/dist/modules/meet/scopes.d.ts +9 -0
- package/dist/modules/meet/scopes.js +25 -0
- package/dist/modules/meet/types.d.ts +97 -0
- package/dist/modules/meet/types.js +14 -0
- package/dist/modules/sheets/service.js +49 -0
- package/dist/modules/slides/service.js +31 -6
- package/dist/modules/tasks/service.js +31 -6
- package/dist/resources/compose-email-template.d.ts +1 -1
- package/dist/resources/compose-email-template.js +388 -19
- package/dist/services/base/BaseGoogleService.d.ts +9 -1
- package/dist/services/base/BaseGoogleService.js +33 -1
- package/dist/services/chat/index.d.ts +34 -0
- package/dist/services/chat/index.js +120 -0
- package/dist/services/contacts/index.d.ts +19 -1
- package/dist/services/contacts/index.js +124 -0
- package/dist/services/meet/index.d.ts +35 -0
- package/dist/services/meet/index.js +116 -0
- package/dist/tools/calendar-handlers.js +28 -23
- package/dist/tools/chat-handlers.d.ts +14 -0
- package/dist/tools/chat-handlers.js +126 -0
- package/dist/tools/contacts-handlers.d.ts +31 -0
- package/dist/tools/contacts-handlers.js +96 -23
- package/dist/tools/definitions/account.js +8 -1
- package/dist/tools/definitions/chat.d.ts +3 -0
- package/dist/tools/definitions/chat.js +137 -0
- package/dist/tools/definitions/contacts.js +82 -0
- package/dist/tools/definitions/destructive-overrides.json +12 -0
- package/dist/tools/definitions/drive.js +132 -6
- package/dist/tools/definitions/gmail.js +94 -0
- package/dist/tools/definitions/index.d.ts +2 -0
- package/dist/tools/definitions/index.js +6 -0
- package/dist/tools/definitions/meet.d.ts +3 -0
- package/dist/tools/definitions/meet.js +149 -0
- package/dist/tools/definitions/open-world-overrides.json +12 -0
- package/dist/tools/drive-handlers.d.ts +27 -0
- package/dist/tools/drive-handlers.js +93 -2
- package/dist/tools/forms-handlers.js +5 -12
- package/dist/tools/gmail-handlers.d.ts +31 -1
- package/dist/tools/gmail-handlers.js +167 -35
- package/dist/tools/meet-handlers.d.ts +42 -0
- package/dist/tools/meet-handlers.js +144 -0
- package/dist/tools/server.js +67 -5
- package/dist/tools/tasks-handlers.js +7 -18
- package/dist/tools/type-guards.d.ts +3 -1
- package/dist/tools/type-guards.js +22 -2
- package/dist/tools/types.d.ts +13 -0
- package/dist/utils/apiError.d.ts +49 -0
- package/dist/utils/apiError.js +96 -0
- package/dist/utils/scope-hierarchy.js +10 -0
- package/dist/utils/service-initializer.js +9 -0
- package/dist/utils/untrusted-content.d.ts +37 -1
- package/dist/utils/untrusted-content.js +61 -6
- package/package.json +5 -1
- package/dist/services/calendar/index.d.ts +0 -27
- package/dist/services/calendar/index.js +0 -146
- package/dist/services/gmail/index.d.ts +0 -39
- package/dist/services/gmail/index.js +0 -337
|
@@ -52,4 +52,38 @@ export declare class ContactsError extends Error {
|
|
|
52
52
|
details?: string;
|
|
53
53
|
constructor(message: string, code: string, details?: string);
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Fields accepted when creating or updating a contact.
|
|
57
|
+
* All fields are optional at the type level; handlers enforce that at least
|
|
58
|
+
* one is provided (and that create has a name or email).
|
|
59
|
+
*/
|
|
60
|
+
export interface ContactWriteFields {
|
|
61
|
+
givenName?: string;
|
|
62
|
+
familyName?: string;
|
|
63
|
+
emailAddress?: string;
|
|
64
|
+
emailType?: string;
|
|
65
|
+
phoneNumber?: string;
|
|
66
|
+
phoneType?: string;
|
|
67
|
+
organization?: string;
|
|
68
|
+
jobTitle?: string;
|
|
69
|
+
notes?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface CreateContactParams extends ContactWriteFields {
|
|
72
|
+
email: string;
|
|
73
|
+
}
|
|
74
|
+
export interface UpdateContactParams extends ContactWriteFields {
|
|
75
|
+
email: string;
|
|
76
|
+
resourceName: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Compact summary of a written contact, returned to the caller.
|
|
80
|
+
*/
|
|
81
|
+
export interface ContactWriteResult {
|
|
82
|
+
resourceName: string;
|
|
83
|
+
etag?: string;
|
|
84
|
+
displayName?: string;
|
|
85
|
+
email?: string;
|
|
86
|
+
phone?: string;
|
|
87
|
+
organization?: string;
|
|
88
|
+
}
|
|
55
89
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { docsService } from '../../services/docs/index.js';
|
|
2
2
|
import { DocsService } from './service.js';
|
|
3
|
+
import { describeApiError } from '../../utils/apiError.js';
|
|
3
4
|
// Export types and service
|
|
4
5
|
export * from './types.js';
|
|
5
6
|
export * from './scopes.js';
|
|
@@ -17,7 +18,7 @@ export async function initializeDocsModule() {
|
|
|
17
18
|
export function handleDocsError(error) {
|
|
18
19
|
return {
|
|
19
20
|
success: false,
|
|
20
|
-
error: error
|
|
21
|
+
error: describeApiError(error),
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
3
|
import { DOCS_SCOPES } from './scopes.js';
|
|
4
|
+
import { describeApiError, isAuthHandoffError } from '../../utils/apiError.js';
|
|
4
5
|
const DEFAULT_MAX_CHARS = 50000;
|
|
5
6
|
const TRUNCATION_MARKER = '\n\n[TRUNCATED - document exceeds character limit]';
|
|
6
7
|
export class DocsService extends BaseGoogleService {
|
|
@@ -125,9 +126,13 @@ export class DocsService extends BaseGoogleService {
|
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
128
|
catch (error) {
|
|
129
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
130
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
131
|
+
if (isAuthHandoffError(error))
|
|
132
|
+
throw error;
|
|
128
133
|
return {
|
|
129
134
|
success: false,
|
|
130
|
-
error: error
|
|
135
|
+
error: describeApiError(error),
|
|
131
136
|
};
|
|
132
137
|
}
|
|
133
138
|
}
|
|
@@ -180,9 +185,13 @@ export class DocsService extends BaseGoogleService {
|
|
|
180
185
|
};
|
|
181
186
|
}
|
|
182
187
|
catch (error) {
|
|
188
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
189
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
190
|
+
if (isAuthHandoffError(error))
|
|
191
|
+
throw error;
|
|
183
192
|
return {
|
|
184
193
|
success: false,
|
|
185
|
-
error: error
|
|
194
|
+
error: describeApiError(error),
|
|
186
195
|
};
|
|
187
196
|
}
|
|
188
197
|
}
|
|
@@ -225,9 +234,13 @@ export class DocsService extends BaseGoogleService {
|
|
|
225
234
|
};
|
|
226
235
|
}
|
|
227
236
|
catch (error) {
|
|
237
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
238
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
239
|
+
if (isAuthHandoffError(error))
|
|
240
|
+
throw error;
|
|
228
241
|
return {
|
|
229
242
|
success: false,
|
|
230
|
-
error: error
|
|
243
|
+
error: describeApiError(error),
|
|
231
244
|
};
|
|
232
245
|
}
|
|
233
246
|
}
|
|
@@ -281,9 +294,13 @@ export class DocsService extends BaseGoogleService {
|
|
|
281
294
|
};
|
|
282
295
|
}
|
|
283
296
|
catch (error) {
|
|
297
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
298
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
299
|
+
if (isAuthHandoffError(error))
|
|
300
|
+
throw error;
|
|
284
301
|
return {
|
|
285
302
|
success: false,
|
|
286
|
-
error: error
|
|
303
|
+
error: describeApiError(error),
|
|
287
304
|
};
|
|
288
305
|
}
|
|
289
306
|
}
|
|
@@ -334,9 +351,13 @@ export class DocsService extends BaseGoogleService {
|
|
|
334
351
|
};
|
|
335
352
|
}
|
|
336
353
|
catch (error) {
|
|
354
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
355
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
356
|
+
if (isAuthHandoffError(error))
|
|
357
|
+
throw error;
|
|
337
358
|
return {
|
|
338
359
|
success: false,
|
|
339
|
-
error: error
|
|
360
|
+
error: describeApiError(error),
|
|
340
361
|
};
|
|
341
362
|
}
|
|
342
363
|
}
|
|
@@ -368,9 +389,13 @@ export class DocsService extends BaseGoogleService {
|
|
|
368
389
|
};
|
|
369
390
|
}
|
|
370
391
|
catch (error) {
|
|
392
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
393
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
394
|
+
if (isAuthHandoffError(error))
|
|
395
|
+
throw error;
|
|
371
396
|
return {
|
|
372
397
|
success: false,
|
|
373
|
-
error: error
|
|
398
|
+
error: describeApiError(error),
|
|
374
399
|
};
|
|
375
400
|
}
|
|
376
401
|
}
|
|
@@ -411,9 +436,13 @@ export class DocsService extends BaseGoogleService {
|
|
|
411
436
|
};
|
|
412
437
|
}
|
|
413
438
|
catch (error) {
|
|
439
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
440
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
441
|
+
if (isAuthHandoffError(error))
|
|
442
|
+
throw error;
|
|
414
443
|
return {
|
|
415
444
|
success: false,
|
|
416
|
-
error: error
|
|
445
|
+
error: describeApiError(error),
|
|
417
446
|
};
|
|
418
447
|
}
|
|
419
448
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { driveactivity_v2 } from 'googleapis';
|
|
2
|
+
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
|
+
export interface QueryDriveActivityOptions {
|
|
4
|
+
/** Drive item to inspect ("items/<id>" or a bare file/folder ID). */
|
|
5
|
+
itemName?: string;
|
|
6
|
+
/** Folder or shared drive whose subtree to inspect ("items/<id>" or bare ID). */
|
|
7
|
+
ancestorName?: string;
|
|
8
|
+
pageSize?: number;
|
|
9
|
+
pageToken?: string;
|
|
10
|
+
/** Drive Activity API filter string, passed through verbatim. */
|
|
11
|
+
filter?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DriveActivitySummary {
|
|
14
|
+
action: string;
|
|
15
|
+
timestamp?: string;
|
|
16
|
+
actors: string[];
|
|
17
|
+
targets: Array<{
|
|
18
|
+
title?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
mimeType?: string;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
export interface QueryDriveActivityResult {
|
|
24
|
+
activities: DriveActivitySummary[];
|
|
25
|
+
nextPageToken?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Normalizes a user-supplied item/ancestor reference to the API's resource
|
|
29
|
+
* form ("items/<id>"); accepts the resource form or a bare Drive ID.
|
|
30
|
+
*/
|
|
31
|
+
export declare function normalizeDriveItemName(value: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Service for the Drive Activity API v2 — answers "what changed in this
|
|
34
|
+
* file/folder/shared drive". Kept separate from DriveService because
|
|
35
|
+
* BaseGoogleService caches one client per email and the activity API is a
|
|
36
|
+
* different client (google.driveactivity v2).
|
|
37
|
+
*/
|
|
38
|
+
export declare class DriveActivityService extends BaseGoogleService<driveactivity_v2.Driveactivity> {
|
|
39
|
+
private initialized;
|
|
40
|
+
constructor();
|
|
41
|
+
initialize(): Promise<void>;
|
|
42
|
+
ensureInitialized(): Promise<void>;
|
|
43
|
+
queryActivity(email: string, options: QueryDriveActivityOptions): Promise<QueryDriveActivityResult>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=activity-service.d.ts.map
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { google } from 'googleapis';
|
|
2
|
+
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
|
+
import { DRIVE_SCOPES } from './scopes.js';
|
|
4
|
+
import { wrapUntrustedContent } from '../../utils/untrusted-content.js';
|
|
5
|
+
const KNOWN_ACTIONS = [
|
|
6
|
+
'create', 'edit', 'move', 'rename', 'delete', 'restore',
|
|
7
|
+
'permissionChange', 'comment', 'dlpChange', 'reference', 'settingsChange',
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes a user-supplied item/ancestor reference to the API's resource
|
|
11
|
+
* form ("items/<id>"); accepts the resource form or a bare Drive ID.
|
|
12
|
+
*/
|
|
13
|
+
export function normalizeDriveItemName(value) {
|
|
14
|
+
return value.startsWith('items/') ? value : `items/${value}`;
|
|
15
|
+
}
|
|
16
|
+
function summarizeAction(detail) {
|
|
17
|
+
if (!detail)
|
|
18
|
+
return 'unknown';
|
|
19
|
+
for (const action of KNOWN_ACTIONS) {
|
|
20
|
+
if (detail[action] !== undefined && detail[action] !== null)
|
|
21
|
+
return action;
|
|
22
|
+
}
|
|
23
|
+
return 'unknown';
|
|
24
|
+
}
|
|
25
|
+
function summarizeActor(actor) {
|
|
26
|
+
if (actor.user?.knownUser) {
|
|
27
|
+
return actor.user.knownUser.isCurrentUser
|
|
28
|
+
? 'you'
|
|
29
|
+
: actor.user.knownUser.personName || 'a known user';
|
|
30
|
+
}
|
|
31
|
+
if (actor.user?.deletedUser)
|
|
32
|
+
return 'a deleted user';
|
|
33
|
+
if (actor.anonymous)
|
|
34
|
+
return 'an anonymous user';
|
|
35
|
+
if (actor.system)
|
|
36
|
+
return 'Google Workspace (system)';
|
|
37
|
+
if (actor.administrator)
|
|
38
|
+
return 'an administrator';
|
|
39
|
+
return 'unknown actor';
|
|
40
|
+
}
|
|
41
|
+
function summarizeTarget(target) {
|
|
42
|
+
// Titles are authored in Drive (attacker-controlled) and get the envelope;
|
|
43
|
+
// resource names / MIME types are structural identifiers and stay raw so the
|
|
44
|
+
// caller can use them directly.
|
|
45
|
+
const wrapTitle = (title) => title ? wrapUntrustedContent(title, 'google-workspace:drive:activity') : undefined;
|
|
46
|
+
if (target.driveItem) {
|
|
47
|
+
return {
|
|
48
|
+
title: wrapTitle(target.driveItem.title),
|
|
49
|
+
name: target.driveItem.name || undefined,
|
|
50
|
+
mimeType: target.driveItem.mimeType || undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (target.drive) {
|
|
54
|
+
return { title: wrapTitle(target.drive.title), name: target.drive.name || undefined };
|
|
55
|
+
}
|
|
56
|
+
if (target.fileComment) {
|
|
57
|
+
return { title: wrapTitle(target.fileComment.parent?.title), name: target.fileComment.parent?.name || undefined };
|
|
58
|
+
}
|
|
59
|
+
if (target.teamDrive) {
|
|
60
|
+
return { title: wrapTitle(target.teamDrive.title), name: target.teamDrive.name || undefined };
|
|
61
|
+
}
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Service for the Drive Activity API v2 — answers "what changed in this
|
|
66
|
+
* file/folder/shared drive". Kept separate from DriveService because
|
|
67
|
+
* BaseGoogleService caches one client per email and the activity API is a
|
|
68
|
+
* different client (google.driveactivity v2).
|
|
69
|
+
*/
|
|
70
|
+
export class DriveActivityService extends BaseGoogleService {
|
|
71
|
+
initialized = false;
|
|
72
|
+
constructor() {
|
|
73
|
+
super({ serviceName: 'Google Drive Activity', version: 'v2' });
|
|
74
|
+
}
|
|
75
|
+
async initialize() {
|
|
76
|
+
try {
|
|
77
|
+
await super.initialize();
|
|
78
|
+
this.initialized = true;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw this.handleError(error, 'Failed to initialize Drive Activity service');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async ensureInitialized() {
|
|
85
|
+
if (!this.initialized) {
|
|
86
|
+
await this.initialize();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async queryActivity(email, options) {
|
|
90
|
+
await this.ensureInitialized();
|
|
91
|
+
await this.validateScopes(email, [DRIVE_SCOPES.ACTIVITY_READONLY]);
|
|
92
|
+
const client = await this.getAuthenticatedClient(email, (auth) => google.driveactivity({ version: 'v2', auth }));
|
|
93
|
+
const response = await client.activity.query({
|
|
94
|
+
requestBody: {
|
|
95
|
+
...(options.itemName && { itemName: options.itemName }),
|
|
96
|
+
...(options.ancestorName && { ancestorName: options.ancestorName }),
|
|
97
|
+
...(options.pageSize && { pageSize: options.pageSize }),
|
|
98
|
+
...(options.pageToken && { pageToken: options.pageToken }),
|
|
99
|
+
...(options.filter && { filter: options.filter }),
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const activities = (response.data.activities || []).map(activity => ({
|
|
103
|
+
action: summarizeAction(activity.primaryActionDetail),
|
|
104
|
+
timestamp: activity.timestamp ?? activity.timeRange?.endTime ?? undefined,
|
|
105
|
+
actors: (activity.actors || []).map(summarizeActor),
|
|
106
|
+
targets: (activity.targets || []).map(summarizeTarget),
|
|
107
|
+
}));
|
|
108
|
+
return {
|
|
109
|
+
activities,
|
|
110
|
+
nextPageToken: response.data.nextPageToken || undefined,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=activity-service.js.map
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { DriveService } from './service.js';
|
|
2
|
+
import { DriveActivityService } from './activity-service.js';
|
|
2
3
|
import { DriveOperationResult } from './types.js';
|
|
3
4
|
export * from './types.js';
|
|
4
5
|
export * from './scopes.js';
|
|
5
6
|
export { DriveService };
|
|
7
|
+
export { DriveActivityService } from './activity-service.js';
|
|
8
|
+
export type { QueryDriveActivityOptions, QueryDriveActivityResult, DriveActivitySummary } from './activity-service.js';
|
|
6
9
|
export declare function getDriveService(): Promise<DriveService>;
|
|
10
|
+
export declare function getDriveActivityService(): Promise<DriveActivityService>;
|
|
7
11
|
export declare function initializeDriveModule(): Promise<void>;
|
|
8
12
|
export declare function handleDriveError(error: unknown): DriveOperationResult;
|
|
9
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { driveService } from '../../services/drive/index.js';
|
|
2
2
|
import { DriveService } from './service.js';
|
|
3
|
+
import { DriveActivityService } from './activity-service.js';
|
|
3
4
|
// Export types and service
|
|
4
5
|
export * from './types.js';
|
|
5
6
|
export * from './scopes.js';
|
|
6
7
|
export { DriveService };
|
|
8
|
+
export { DriveActivityService } from './activity-service.js';
|
|
7
9
|
// Get singleton instance
|
|
8
10
|
let serviceInstance;
|
|
9
11
|
export async function getDriveService() {
|
|
@@ -13,6 +15,16 @@ export async function getDriveService() {
|
|
|
13
15
|
}
|
|
14
16
|
return serviceInstance;
|
|
15
17
|
}
|
|
18
|
+
// Drive Activity API client (separate service: BaseGoogleService caches one
|
|
19
|
+
// client per email, and the activity API is a different googleapis client).
|
|
20
|
+
let activityServiceInstance;
|
|
21
|
+
export async function getDriveActivityService() {
|
|
22
|
+
if (!activityServiceInstance) {
|
|
23
|
+
activityServiceInstance = new DriveActivityService();
|
|
24
|
+
await activityServiceInstance.ensureInitialized();
|
|
25
|
+
}
|
|
26
|
+
return activityServiceInstance;
|
|
27
|
+
}
|
|
16
28
|
// Initialize module
|
|
17
29
|
export async function initializeDriveModule() {
|
|
18
30
|
const service = await getDriveService();
|
|
@@ -3,6 +3,7 @@ export declare const DRIVE_SCOPES: {
|
|
|
3
3
|
readonly READONLY: "https://www.googleapis.com/auth/drive.readonly";
|
|
4
4
|
readonly FILE: "https://www.googleapis.com/auth/drive.file";
|
|
5
5
|
readonly APPDATA: "https://www.googleapis.com/auth/drive.appdata";
|
|
6
|
+
readonly ACTIVITY_READONLY: "https://www.googleapis.com/auth/drive.activity.readonly";
|
|
6
7
|
};
|
|
7
8
|
export type DriveScope = typeof DRIVE_SCOPES[keyof typeof DRIVE_SCOPES];
|
|
8
9
|
/**
|
|
@@ -10,6 +10,8 @@ export const DRIVE_SCOPES = {
|
|
|
10
10
|
FILE: 'https://www.googleapis.com/auth/drive.file',
|
|
11
11
|
// Access to app data folder
|
|
12
12
|
APPDATA: 'https://www.googleapis.com/auth/drive.appdata',
|
|
13
|
+
// Read-only access to Drive activity (what changed, when, by whom)
|
|
14
|
+
ACTIVITY_READONLY: 'https://www.googleapis.com/auth/drive.activity.readonly',
|
|
13
15
|
};
|
|
14
16
|
/**
|
|
15
17
|
* Register Drive OAuth scopes at startup.
|
|
@@ -26,6 +28,7 @@ export function registerDriveScopes() {
|
|
|
26
28
|
scopeRegistry.registerScope('drive', DRIVE_SCOPES.FILE);
|
|
27
29
|
// Register feature-specific scopes
|
|
28
30
|
scopeRegistry.registerScope('drive', DRIVE_SCOPES.APPDATA);
|
|
31
|
+
scopeRegistry.registerScope('drive', DRIVE_SCOPES.ACTIVITY_READONLY);
|
|
29
32
|
// Verify all scopes are registered
|
|
30
33
|
const registeredScopes = scopeRegistry.getAllScopes();
|
|
31
34
|
const requiredScopes = Object.values(DRIVE_SCOPES);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
|
-
import { DriveOperationResult, FileDownloadOptions, FileListOptions, FileSearchOptions, FileUploadOptions, PermissionOptions } from './types.js';
|
|
3
|
+
import { DriveOperationResult, FileDownloadOptions, FileListOptions, FileSearchOptions, FileUploadOptions, PermissionOptions, SharedDriveListOptions } from './types.js';
|
|
4
4
|
export declare class DriveService extends BaseGoogleService<ReturnType<typeof google.drive>> {
|
|
5
5
|
private initialized;
|
|
6
6
|
constructor();
|
|
@@ -17,6 +17,7 @@ export declare class DriveService extends BaseGoogleService<ReturnType<typeof go
|
|
|
17
17
|
*/
|
|
18
18
|
private checkInitialized;
|
|
19
19
|
listFiles(email: string, options?: FileListOptions): Promise<DriveOperationResult>;
|
|
20
|
+
listSharedDrives(email: string, options?: SharedDriveListOptions): Promise<DriveOperationResult>;
|
|
20
21
|
uploadFile(email: string, options: FileUploadOptions): Promise<DriveOperationResult>;
|
|
21
22
|
downloadFile(email: string, options: FileDownloadOptions): Promise<DriveOperationResult>;
|
|
22
23
|
createFolder(email: string, name: string, parentId?: string): Promise<DriveOperationResult>;
|
|
@@ -93,6 +93,9 @@ export class DriveService extends BaseGoogleService {
|
|
|
93
93
|
pageToken: options.pageToken,
|
|
94
94
|
orderBy: options.orderBy?.join(','),
|
|
95
95
|
fields: options.fields?.join(',') || 'files(id, name, mimeType, modifiedTime, size)',
|
|
96
|
+
// Google rejects driveId unless corpora is 'drive', so force the pairing.
|
|
97
|
+
driveId: options.driveId || undefined,
|
|
98
|
+
corpora: options.driveId ? 'drive' : options.corpora,
|
|
96
99
|
supportsAllDrives: true,
|
|
97
100
|
includeItemsFromAllDrives: true,
|
|
98
101
|
});
|
|
@@ -105,6 +108,26 @@ export class DriveService extends BaseGoogleService {
|
|
|
105
108
|
throw this.handleError(error, 'Failed to list Drive files');
|
|
106
109
|
}
|
|
107
110
|
}
|
|
111
|
+
async listSharedDrives(email, options = {}) {
|
|
112
|
+
try {
|
|
113
|
+
await this.ensureInitialized();
|
|
114
|
+
this.checkInitialized();
|
|
115
|
+
await this.validateScopes(email, [DRIVE_SCOPES.READONLY]);
|
|
116
|
+
const client = await this.getAuthenticatedClient(email, (auth) => google.drive({ version: 'v3', auth }));
|
|
117
|
+
const response = await client.drives.list({
|
|
118
|
+
pageSize: options.pageSize,
|
|
119
|
+
pageToken: options.pageToken,
|
|
120
|
+
fields: 'drives(id, name, createdTime), nextPageToken',
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
success: true,
|
|
124
|
+
data: response.data,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw this.handleError(error, 'Failed to list shared drives');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
108
131
|
async uploadFile(email, options) {
|
|
109
132
|
try {
|
|
110
133
|
await this.ensureInitialized();
|
|
@@ -265,6 +288,9 @@ export class DriveService extends BaseGoogleService {
|
|
|
265
288
|
pageToken: options.pageToken,
|
|
266
289
|
orderBy: options.orderBy?.join(','),
|
|
267
290
|
fields: options.fields?.join(',') || 'files(id, name, mimeType, modifiedTime, size)',
|
|
291
|
+
// Google rejects driveId unless corpora is 'drive', so force the pairing.
|
|
292
|
+
driveId: options.driveId || undefined,
|
|
293
|
+
corpora: options.driveId ? 'drive' : options.corpora,
|
|
268
294
|
supportsAllDrives: true,
|
|
269
295
|
includeItemsFromAllDrives: true,
|
|
270
296
|
});
|
|
@@ -417,6 +443,9 @@ export class DriveService extends BaseGoogleService {
|
|
|
417
443
|
throw this.handleError(error, 'Failed to untrash Drive file');
|
|
418
444
|
}
|
|
419
445
|
}
|
|
446
|
+
// The Drive Revisions API does not accept supportsAllDrives and does not
|
|
447
|
+
// surface revisions for shared-drive files, so revisions.* calls here and in
|
|
448
|
+
// downloadRevision intentionally omit the flag (see CHANGELOG 0.1.3).
|
|
420
449
|
async listRevisions(email, fileId) {
|
|
421
450
|
try {
|
|
422
451
|
await this.ensureInitialized();
|
|
@@ -4,6 +4,8 @@ export type DriveFileList = drive_v3.Schema$FileList;
|
|
|
4
4
|
export type DrivePermission = drive_v3.Schema$Permission;
|
|
5
5
|
export type DriveRevision = drive_v3.Schema$Revision;
|
|
6
6
|
export type DriveRevisionList = drive_v3.Schema$RevisionList;
|
|
7
|
+
export type SharedDrive = drive_v3.Schema$Drive;
|
|
8
|
+
export type SharedDriveList = drive_v3.Schema$DriveList;
|
|
7
9
|
export interface FileUploadOptions {
|
|
8
10
|
name: string;
|
|
9
11
|
mimeType?: string;
|
|
@@ -21,6 +23,12 @@ export interface FileListOptions {
|
|
|
21
23
|
pageToken?: string;
|
|
22
24
|
orderBy?: string[];
|
|
23
25
|
fields?: string[];
|
|
26
|
+
driveId?: string;
|
|
27
|
+
corpora?: 'user' | 'drive' | 'allDrives';
|
|
28
|
+
}
|
|
29
|
+
export interface SharedDriveListOptions {
|
|
30
|
+
pageSize?: number;
|
|
31
|
+
pageToken?: string;
|
|
24
32
|
}
|
|
25
33
|
export interface FileSearchOptions extends FileListOptions {
|
|
26
34
|
fullText?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
|
+
import { describeApiError, isAuthHandoffError } from '../../utils/apiError.js';
|
|
3
4
|
import { FORMS_SCOPES } from './scopes.js';
|
|
4
5
|
/**
|
|
5
6
|
* Service for interacting with Google Forms API.
|
|
@@ -147,9 +148,13 @@ export class FormsService extends BaseGoogleService {
|
|
|
147
148
|
};
|
|
148
149
|
}
|
|
149
150
|
catch (error) {
|
|
151
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
152
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
153
|
+
if (isAuthHandoffError(error))
|
|
154
|
+
throw error;
|
|
150
155
|
return {
|
|
151
156
|
success: false,
|
|
152
|
-
error: error
|
|
157
|
+
error: describeApiError(error)
|
|
153
158
|
};
|
|
154
159
|
}
|
|
155
160
|
}
|
|
@@ -213,9 +218,13 @@ export class FormsService extends BaseGoogleService {
|
|
|
213
218
|
};
|
|
214
219
|
}
|
|
215
220
|
catch (error) {
|
|
221
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
222
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
223
|
+
if (isAuthHandoffError(error))
|
|
224
|
+
throw error;
|
|
216
225
|
return {
|
|
217
226
|
success: false,
|
|
218
|
-
error: error
|
|
227
|
+
error: describeApiError(error)
|
|
219
228
|
};
|
|
220
229
|
}
|
|
221
230
|
}
|
|
@@ -274,9 +283,13 @@ export class FormsService extends BaseGoogleService {
|
|
|
274
283
|
};
|
|
275
284
|
}
|
|
276
285
|
catch (error) {
|
|
286
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
287
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
288
|
+
if (isAuthHandoffError(error))
|
|
289
|
+
throw error;
|
|
277
290
|
return {
|
|
278
291
|
success: false,
|
|
279
|
-
error: error
|
|
292
|
+
error: describeApiError(error)
|
|
280
293
|
};
|
|
281
294
|
}
|
|
282
295
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeApiError } from '../../../utils/apiError.js';
|
|
1
2
|
import { GmailError } from '../types.js';
|
|
2
3
|
import { AttachmentIndexService } from '../../attachments/index-service.js';
|
|
3
4
|
/**
|
|
@@ -112,7 +113,7 @@ export class GmailAttachmentService {
|
|
|
112
113
|
catch (error) {
|
|
113
114
|
if (error instanceof GmailError)
|
|
114
115
|
throw error;
|
|
115
|
-
throw new GmailError('Failed to get attachment', 'ATTACHMENT_ERROR', `Error: ${error
|
|
116
|
+
throw new GmailError('Failed to get attachment', 'ATTACHMENT_ERROR', `Error: ${describeApiError(error)}`);
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../../services/base/BaseGoogleService.js';
|
|
3
|
-
import { GetEmailsParams, SendEmailParams, SendEmailResponse, GetGmailSettingsParams, GetGmailSettingsResponse, GmailModuleConfig, GetEmailsResponse, DraftResponse, GetDraftsResponse, Label, GetLabelsResponse, GetLabelFiltersResponse, LabelFilter } from '../types.js';
|
|
3
|
+
import { GetEmailsParams, SendEmailParams, SendEmailResponse, GetGmailSettingsParams, GetGmailSettingsResponse, UpdateVacationResponderParams, VacationResponderState, SendAsAlias, GmailModuleConfig, GetEmailsResponse, DraftResponse, GetDraftsResponse, Label, GetLabelsResponse, GetLabelFiltersResponse, LabelFilter } from '../types.js';
|
|
4
4
|
import { ManageLabelParams, ManageLabelAssignmentParams, ManageLabelFilterParams } from './label.js';
|
|
5
5
|
import { ManageDraftParams } from './draft.js';
|
|
6
6
|
/**
|
|
@@ -69,6 +69,10 @@ export declare class GmailService extends BaseGoogleService<ReturnType<typeof go
|
|
|
69
69
|
sendEmail(params: SendEmailParams): Promise<SendEmailResponse>;
|
|
70
70
|
manageDraft(params: ManageDraftParams): Promise<DraftResponse | GetDraftsResponse | SendEmailResponse | void>;
|
|
71
71
|
getWorkspaceGmailSettings(params: GetGmailSettingsParams): Promise<GetGmailSettingsResponse>;
|
|
72
|
+
updateVacationResponder(params: UpdateVacationResponderParams): Promise<VacationResponderState>;
|
|
73
|
+
listSendAs(params: GetGmailSettingsParams): Promise<{
|
|
74
|
+
sendAs: SendAsAlias[];
|
|
75
|
+
}>;
|
|
72
76
|
manageLabel(params: ManageLabelParams): Promise<Label | GetLabelsResponse | void>;
|
|
73
77
|
manageLabelAssignment(params: ManageLabelAssignmentParams): Promise<void>;
|
|
74
78
|
manageLabelFilter(params: ManageLabelFilterParams): Promise<LabelFilter | GetLabelFiltersResponse | void>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../../services/base/BaseGoogleService.js';
|
|
3
|
+
import { describeApiError } from '../../../utils/apiError.js';
|
|
3
4
|
import { GmailError } from '../types.js';
|
|
4
5
|
import { EmailService } from './email.js';
|
|
5
6
|
import { SearchService } from './search.js';
|
|
@@ -42,7 +43,7 @@ export class GmailService extends BaseGoogleService {
|
|
|
42
43
|
this.initialized = true;
|
|
43
44
|
}
|
|
44
45
|
catch (error) {
|
|
45
|
-
throw new GmailError('Failed to initialize Gmail service', 'INIT_ERROR', error
|
|
46
|
+
throw new GmailError('Failed to initialize Gmail service', 'INIT_ERROR', describeApiError(error));
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
@@ -95,6 +96,14 @@ export class GmailService extends BaseGoogleService {
|
|
|
95
96
|
await this.getGmailClient(params.email);
|
|
96
97
|
return this.settingsService.getWorkspaceGmailSettings(params);
|
|
97
98
|
}
|
|
99
|
+
async updateVacationResponder(params) {
|
|
100
|
+
await this.getGmailClient(params.email);
|
|
101
|
+
return this.settingsService.updateVacationResponder(params);
|
|
102
|
+
}
|
|
103
|
+
async listSendAs(params) {
|
|
104
|
+
await this.getGmailClient(params.email);
|
|
105
|
+
return this.settingsService.listSendAs(params);
|
|
106
|
+
}
|
|
98
107
|
// Consolidated Label Management Methods
|
|
99
108
|
async manageLabel(params) {
|
|
100
109
|
await this.getGmailClient(params.email);
|