pangea-server 3.3.142 → 3.3.144

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,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
+ }
@@ -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';
@@ -12,3 +13,4 @@ export * from './multer.helpers';
12
13
  export * from './pass.helpers';
13
14
  export * from './print.helpers';
14
15
  export * from './random.helpers';
16
+ export * from './whatsapp.helpers';
@@ -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);
@@ -28,3 +29,4 @@ __exportStar(require("./multer.helpers"), exports);
28
29
  __exportStar(require("./pass.helpers"), exports);
29
30
  __exportStar(require("./print.helpers"), exports);
30
31
  __exportStar(require("./random.helpers"), exports);
32
+ __exportStar(require("./whatsapp.helpers"), exports);
@@ -0,0 +1,9 @@
1
+ export declare class Whatsapp {
2
+ private __accessToken;
3
+ private __phoneNumberId;
4
+ constructor(config: {
5
+ accessToken: string;
6
+ phoneNumberId: string;
7
+ });
8
+ sendText(to: string, text: string): Promise<import("@whatsapp-cloudapi/types/cloudapi", { with: { "resolution-mode": "import" } }).CloudAPIResponse>;
9
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Whatsapp = void 0;
7
+ const client_1 = __importDefault(require("@whatsapp-cloudapi/client"));
8
+ class Whatsapp {
9
+ constructor(config) {
10
+ this.__accessToken = config.accessToken;
11
+ this.__phoneNumberId = config.phoneNumberId;
12
+ }
13
+ async sendText(to, text) {
14
+ return client_1.default.sendTextMessage({ accessToken: this.__accessToken, from: this.__phoneNumberId, to, text });
15
+ }
16
+ }
17
+ exports.Whatsapp = Whatsapp;
@@ -14,7 +14,6 @@ const validate_request_1 = require("../validator/validate-request");
14
14
  function callController(controller, validate, appVersion, authConfig) {
15
15
  const { authMap, authCtor, initAuthCtor, accessToken } = authConfig;
16
16
  return async function (req, res) {
17
- const reqId = (0, helpers_1.getRandomString)(6);
18
17
  const headers = req.headers;
19
18
  if ((0, helpers_1.getEnvStr)('ENVIRONMENT') !== 'development' && appVersion !== headers['x-app-version']) {
20
19
  helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'APP_VERSION_MISMATCH' });
@@ -21,6 +21,7 @@ export declare namespace Val {
21
21
  type Id = Val.Int & Val.GreaterEqual<1>;
22
22
  type IdOptional = Val.Id | 0;
23
23
  type Ids = Val.Id[];
24
+ type MaxItems<T extends number> = tags.MaxItems<T>;
24
25
  interface IdParams {
25
26
  id: Val.Id;
26
27
  }
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.142",
4
+ "version": "3.3.144",
5
+ "engines": {
6
+ "node": "22.14.0"
7
+ },
5
8
  "files": [
6
9
  "dist"
7
10
  ],
@@ -34,6 +37,7 @@
34
37
  "dependencies": {
35
38
  "@afipsdk/afip.js": "1.2.3",
36
39
  "@google/genai": "1.34.0",
40
+ "@whatsapp-cloudapi/client": "4.2.0",
37
41
  "aws-sdk": "2.1692.0",
38
42
  "bcrypt": "5.1.1",
39
43
  "compression": "1.7.5",
@@ -45,6 +49,7 @@
45
49
  "express": "4.21.2",
46
50
  "express-async-errors": "3.1.1",
47
51
  "express-rate-limit": "^8.1.0",
52
+ "googleapis": "^172.0.0",
48
53
  "helmet": "8.1.0",
49
54
  "http-status-codes": "2.3.0",
50
55
  "jsdom": "26.0.0",