pangea-server 3.3.141 → 3.3.143
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/gemini.helpers.d.ts +4 -1
- package/dist/helpers/gemini.helpers.js +22 -15
- package/dist/helpers/google-calendar.helpers.d.ts +85 -0
- package/dist/helpers/google-calendar.helpers.js +107 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/pass.helpers.js +3 -3
- package/dist/validator/validators.helpers.d.ts +1 -0
- package/package.json +2 -1
|
@@ -3,5 +3,8 @@ type File = {
|
|
|
3
3
|
mimetype: string;
|
|
4
4
|
};
|
|
5
5
|
type Part = string | File;
|
|
6
|
-
export declare
|
|
6
|
+
export declare abstract class Gemini {
|
|
7
|
+
static GenerateText(content: string | Part[]): Promise<string | undefined>;
|
|
8
|
+
private static __GetAi;
|
|
9
|
+
}
|
|
7
10
|
export {};
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Gemini = void 0;
|
|
4
4
|
// helpers
|
|
5
5
|
const helpers_1 = require("../helpers");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const MODEL = 'gemini-2.5-flash-lite';
|
|
7
|
+
class Gemini {
|
|
8
|
+
static async GenerateText(content) {
|
|
9
|
+
const ai = await this.__GetAi();
|
|
10
|
+
const contents = typeof content === 'string'
|
|
11
|
+
? content
|
|
12
|
+
: await Promise.all(content.map(async (part) => {
|
|
13
|
+
if (typeof part === 'string')
|
|
14
|
+
return { text: part };
|
|
15
|
+
const blob = new Blob([new Uint8Array(part.buffer)], { type: part.mimetype });
|
|
16
|
+
const uploadedFile = await ai.files.upload({ file: blob });
|
|
17
|
+
return { fileData: { fileUri: uploadedFile.uri, mimeType: part.mimetype } };
|
|
18
|
+
}));
|
|
19
|
+
const response = await ai.models.generateContent({ model: MODEL, contents });
|
|
20
|
+
return response.text;
|
|
21
|
+
}
|
|
22
|
+
static async __GetAi() {
|
|
23
|
+
const { GoogleGenAI } = await import('@google/genai');
|
|
24
|
+
return new GoogleGenAI({ apiKey: (0, helpers_1.getEnvStr)('GEMINI_API_KEY') });
|
|
25
|
+
}
|
|
20
26
|
}
|
|
27
|
+
exports.Gemini = Gemini;
|
|
@@ -0,0 +1,85 @@
|
|
|
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 = {
|
|
17
|
+
title?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
location?: string;
|
|
20
|
+
start?: Date;
|
|
21
|
+
end?: Date;
|
|
22
|
+
attendees?: string[];
|
|
23
|
+
};
|
|
24
|
+
export declare class GoogleCalendar {
|
|
25
|
+
private __calendar;
|
|
26
|
+
constructor({ accesstoken, refreshtoken }: {
|
|
27
|
+
accesstoken: string;
|
|
28
|
+
refreshtoken: string;
|
|
29
|
+
});
|
|
30
|
+
static GetAuthUrl(redirectTo: string): Promise<string>;
|
|
31
|
+
static GetTokens(code: string, redirectTo: string): Promise<{
|
|
32
|
+
accesstoken: string;
|
|
33
|
+
refreshtoken: string;
|
|
34
|
+
}>;
|
|
35
|
+
getEvent(eventId: string): Promise<{
|
|
36
|
+
id: string;
|
|
37
|
+
summary: string | null | undefined;
|
|
38
|
+
description: string | null | undefined;
|
|
39
|
+
location: string | null | undefined;
|
|
40
|
+
start: Date | undefined;
|
|
41
|
+
end: Date | undefined;
|
|
42
|
+
attendees: string[];
|
|
43
|
+
hangoutLink: string | null | undefined;
|
|
44
|
+
htmlLink: string | null | undefined;
|
|
45
|
+
status: string | null | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
getEvents(options?: GetEventsOptions): Promise<{
|
|
48
|
+
id: string;
|
|
49
|
+
summary: string | null | undefined;
|
|
50
|
+
description: string | null | undefined;
|
|
51
|
+
location: string | null | undefined;
|
|
52
|
+
start: Date | undefined;
|
|
53
|
+
end: Date | undefined;
|
|
54
|
+
attendees: string[];
|
|
55
|
+
hangoutLink: string | null | undefined;
|
|
56
|
+
htmlLink: string | null | undefined;
|
|
57
|
+
status: string | null | undefined;
|
|
58
|
+
}[]>;
|
|
59
|
+
createEvent(options: CreateEventOptions): Promise<{
|
|
60
|
+
id: string;
|
|
61
|
+
summary: string | null | undefined;
|
|
62
|
+
description: string | null | undefined;
|
|
63
|
+
location: string | null | undefined;
|
|
64
|
+
start: Date | undefined;
|
|
65
|
+
end: Date | undefined;
|
|
66
|
+
attendees: string[];
|
|
67
|
+
hangoutLink: string | null | undefined;
|
|
68
|
+
htmlLink: string | null | undefined;
|
|
69
|
+
status: string | null | undefined;
|
|
70
|
+
}>;
|
|
71
|
+
updateEvent(eventId: string, options: UpdateEventOptions): Promise<{
|
|
72
|
+
id: string;
|
|
73
|
+
summary: string | null | undefined;
|
|
74
|
+
description: string | null | undefined;
|
|
75
|
+
location: string | null | undefined;
|
|
76
|
+
start: Date | undefined;
|
|
77
|
+
end: Date | undefined;
|
|
78
|
+
attendees: string[];
|
|
79
|
+
hangoutLink: string | null | undefined;
|
|
80
|
+
htmlLink: string | null | undefined;
|
|
81
|
+
status: string | null | undefined;
|
|
82
|
+
}>;
|
|
83
|
+
deleteEvent(eventId: string): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GoogleCalendar = 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 GoogleCalendar {
|
|
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 async 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.GoogleCalendar = GoogleCalendar;
|
|
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,6 +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
9
|
export * from './html-sanitize.helpers';
|
|
9
10
|
export * from './job.helpers';
|
|
10
11
|
export * from './mailer.helpers';
|
package/dist/helpers/index.js
CHANGED
|
@@ -21,6 +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
25
|
__exportStar(require("./html-sanitize.helpers"), exports);
|
|
25
26
|
__exportStar(require("./job.helpers"), exports);
|
|
26
27
|
__exportStar(require("./mailer.helpers"), exports);
|
|
@@ -10,16 +10,16 @@ const env_helpers_1 = require("./env.helpers");
|
|
|
10
10
|
const COST = 12;
|
|
11
11
|
class Pass {
|
|
12
12
|
static Hash(password) {
|
|
13
|
-
return bcrypt_1.default.hash(
|
|
13
|
+
return bcrypt_1.default.hash(sign(password), COST);
|
|
14
14
|
}
|
|
15
15
|
static async Compare(password, hash) {
|
|
16
|
-
if (await bcrypt_1.default.compare(
|
|
16
|
+
if (await bcrypt_1.default.compare(sign(password), hash))
|
|
17
17
|
return true;
|
|
18
18
|
return bcrypt_1.default.compare(password, hash);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.Pass = Pass;
|
|
22
22
|
// internal functions
|
|
23
|
-
function
|
|
23
|
+
function sign(password) {
|
|
24
24
|
return crypto_1.default.createHmac('sha256', (0, env_helpers_1.getEnvStr)('PASSWORD_SECRET')).update(password).digest('hex');
|
|
25
25
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pangea-server",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.143",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"express": "4.21.2",
|
|
46
46
|
"express-async-errors": "3.1.1",
|
|
47
47
|
"express-rate-limit": "^8.1.0",
|
|
48
|
+
"googleapis": "^172.0.0",
|
|
48
49
|
"helmet": "8.1.0",
|
|
49
50
|
"http-status-codes": "2.3.0",
|
|
50
51
|
"jsdom": "26.0.0",
|