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