pangea-server 3.3.156 → 3.3.158

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.
@@ -0,0 +1,78 @@
1
+ type GetEventsOptions = {
2
+ maxResults?: number;
3
+ timeMin?: Date;
4
+ timeMax?: Date;
5
+ query?: string;
6
+ };
7
+ type CreateEventOptions = {
8
+ title: string;
9
+ description?: string;
10
+ location?: string;
11
+ start: Date;
12
+ end: Date;
13
+ attendees?: string[];
14
+ meet?: boolean;
15
+ };
16
+ type UpdateEventOptions = Partial<Omit<CreateEventOptions, 'meet'>>;
17
+ export declare class Google {
18
+ private __calendar;
19
+ constructor({ accessToken, refreshToken }: {
20
+ accessToken: string;
21
+ refreshToken: string;
22
+ });
23
+ static GetAuthUrl(redirectTo: string): string;
24
+ static GetTokens(code: string, redirectTo: string): Promise<{
25
+ accessToken: string;
26
+ refreshToken: string;
27
+ }>;
28
+ getEvent(eventId: string): Promise<{
29
+ id: string;
30
+ summary: string | null | undefined;
31
+ description: string | null | undefined;
32
+ location: string | null | undefined;
33
+ start: Date | undefined;
34
+ end: Date | undefined;
35
+ attendees: string[];
36
+ hangoutLink: string | null | undefined;
37
+ htmlLink: string | null | undefined;
38
+ status: string | null | undefined;
39
+ }>;
40
+ getEvents(options?: GetEventsOptions): Promise<{
41
+ id: string;
42
+ summary: string | null | undefined;
43
+ description: string | null | undefined;
44
+ location: string | null | undefined;
45
+ start: Date | undefined;
46
+ end: Date | undefined;
47
+ attendees: string[];
48
+ hangoutLink: string | null | undefined;
49
+ htmlLink: string | null | undefined;
50
+ status: string | null | undefined;
51
+ }[]>;
52
+ createEvent(options: CreateEventOptions): Promise<{
53
+ id: string;
54
+ summary: string | null | undefined;
55
+ description: string | null | undefined;
56
+ location: string | null | undefined;
57
+ start: Date | undefined;
58
+ end: Date | undefined;
59
+ attendees: string[];
60
+ hangoutLink: string | null | undefined;
61
+ htmlLink: string | null | undefined;
62
+ status: string | null | undefined;
63
+ }>;
64
+ updateEvent(eventId: string, options: UpdateEventOptions): Promise<{
65
+ id: string;
66
+ summary: string | null | undefined;
67
+ description: string | null | undefined;
68
+ location: string | null | undefined;
69
+ start: Date | undefined;
70
+ end: Date | undefined;
71
+ attendees: string[];
72
+ hangoutLink: string | null | undefined;
73
+ htmlLink: string | null | undefined;
74
+ status: string | null | undefined;
75
+ }>;
76
+ deleteEvent(eventId: string): Promise<void>;
77
+ }
78
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Google = void 0;
4
+ const googleapis_1 = require("googleapis");
5
+ // helpers
6
+ const helpers_1 = require("../helpers");
7
+ const scopes = ['https://www.googleapis.com/auth/calendar.events'];
8
+ class Google {
9
+ constructor({ accessToken, refreshToken }) {
10
+ const auth = getOAuth2();
11
+ auth.setCredentials({ access_token: accessToken, refresh_token: refreshToken });
12
+ this.__calendar = googleapis_1.google.calendar({ version: 'v3', auth });
13
+ }
14
+ // class methods
15
+ static GetAuthUrl(redirectTo) {
16
+ const auth = getOAuth2();
17
+ return auth.generateAuthUrl({ access_type: 'offline', prompt: 'consent', scope: scopes, redirect_uri: redirectTo });
18
+ }
19
+ static async GetTokens(code, redirectTo) {
20
+ const auth = getOAuth2();
21
+ const { tokens } = await auth.getToken({ code, redirect_uri: redirectTo });
22
+ return { accessToken: tokens.access_token, refreshToken: tokens.refresh_token };
23
+ }
24
+ // methods
25
+ async getEvent(eventId) {
26
+ const response = await this.__calendar.events.get({ calendarId: 'primary', eventId });
27
+ return convertEvent(response.data);
28
+ }
29
+ async getEvents(options = {}) {
30
+ const response = await this.__calendar.events.list({
31
+ calendarId: 'primary',
32
+ maxResults: options.maxResults || 10,
33
+ timeMin: options.timeMin?.toISOString(),
34
+ timeMax: options.timeMax?.toISOString(),
35
+ q: options.query,
36
+ singleEvents: true,
37
+ orderBy: 'startTime',
38
+ });
39
+ return (response.data.items || []).map(convertEvent);
40
+ }
41
+ async createEvent(options) {
42
+ try {
43
+ const response = await this.__calendar.events.insert({
44
+ calendarId: 'primary',
45
+ requestBody: {
46
+ summary: options.title,
47
+ description: options.description,
48
+ location: options.location,
49
+ start: { dateTime: options.start.toISOString() },
50
+ end: { dateTime: options.end.toISOString() },
51
+ attendees: options.attendees?.map((email) => ({ email })),
52
+ conferenceData: options.meet
53
+ ? {
54
+ createRequest: {
55
+ requestId: `meet-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,
56
+ conferenceSolutionKey: { type: 'hangoutsMeet' },
57
+ },
58
+ }
59
+ : undefined,
60
+ },
61
+ conferenceDataVersion: options.meet ? 1 : undefined,
62
+ });
63
+ return convertEvent(response.data);
64
+ }
65
+ catch (err) {
66
+ (0, helpers_1.printDanger)('google', err);
67
+ throw err;
68
+ }
69
+ }
70
+ async updateEvent(eventId, options) {
71
+ try {
72
+ const { title, description, location, start, end, attendees } = options;
73
+ const requestBody = {};
74
+ if (title !== undefined)
75
+ requestBody.summary = title;
76
+ if (description !== undefined)
77
+ requestBody.description = description;
78
+ if (location !== undefined)
79
+ requestBody.location = location;
80
+ if (start !== undefined)
81
+ requestBody.start = { dateTime: start.toISOString() };
82
+ if (end !== undefined)
83
+ requestBody.end = { dateTime: end.toISOString() };
84
+ if (attendees !== undefined)
85
+ requestBody.attendees = attendees.map((email) => ({ email }));
86
+ const response = await this.__calendar.events.patch({ calendarId: 'primary', eventId, requestBody });
87
+ return convertEvent(response.data);
88
+ }
89
+ catch (err) {
90
+ (0, helpers_1.printDanger)('google', err);
91
+ throw err;
92
+ }
93
+ }
94
+ async deleteEvent(eventId) {
95
+ try {
96
+ await this.__calendar.events.delete({ calendarId: 'primary', eventId });
97
+ }
98
+ catch (err) {
99
+ (0, helpers_1.printDanger)('google', err);
100
+ throw err;
101
+ }
102
+ }
103
+ }
104
+ exports.Google = Google;
105
+ // internal functions
106
+ function getOAuth2() {
107
+ return new googleapis_1.google.auth.OAuth2({
108
+ clientId: (0, helpers_1.getEnvStr)('GOOGLE_CLIENT_ID'),
109
+ clientSecret: (0, helpers_1.getEnvStr)('GOOGLE_CLIENT_SECRET'),
110
+ });
111
+ }
112
+ function convertEvent(event) {
113
+ return {
114
+ id: event.id,
115
+ summary: event.summary,
116
+ description: event.description,
117
+ location: event.location,
118
+ start: event.start ? new Date(event.start.dateTime || event.start.date || '') : undefined,
119
+ end: event.end ? new Date(event.end.dateTime || event.end.date || '') : undefined,
120
+ attendees: event.attendees?.map((attendee) => attendee.email).filter(Boolean) || [],
121
+ hangoutLink: event.hangoutLink || event.conferenceData?.entryPoints?.find((ep) => ep.entryPointType === 'video')?.uri,
122
+ htmlLink: event.htmlLink,
123
+ status: event.status,
124
+ };
125
+ }
@@ -5,7 +5,7 @@ export * from './env.helpers';
5
5
  export * from './error.helpers';
6
6
  export * from './file-storage.helpers';
7
7
  export * from './gemini.helpers';
8
- export * from './google-calendar.helpers';
8
+ export * from './google.helpers';
9
9
  export * from './html-sanitize.helpers';
10
10
  export * from './job.helpers';
11
11
  export * from './mailer.helpers';
@@ -21,7 +21,7 @@ __exportStar(require("./env.helpers"), exports);
21
21
  __exportStar(require("./error.helpers"), exports);
22
22
  __exportStar(require("./file-storage.helpers"), exports);
23
23
  __exportStar(require("./gemini.helpers"), exports);
24
- __exportStar(require("./google-calendar.helpers"), exports);
24
+ __exportStar(require("./google.helpers"), exports);
25
25
  __exportStar(require("./html-sanitize.helpers"), exports);
26
26
  __exportStar(require("./job.helpers"), exports);
27
27
  __exportStar(require("./mailer.helpers"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.156",
4
+ "version": "3.3.158",
5
5
  "engines": {
6
6
  "node": "22.14.0"
7
7
  },