plenna_utilities 1.12.0 → 1.13.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/dist/src/google/index.d.ts +53 -1
- package/dist/src/google/index.js +69 -1
- package/package.json +2 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { docs_v1 } from '@googleapis/docs';
|
|
2
|
+
import { calendar_v3 } from '@googleapis/calendar';
|
|
2
3
|
import { GoogleAuth, type JWTInput } from 'google-auth-library';
|
|
3
4
|
import { type JSONClient } from 'google-auth-library/build/src/auth/googleauth';
|
|
4
5
|
import { type IPlennaGoogleBase } from './requestBuilder';
|
|
@@ -14,6 +15,50 @@ interface deleteDocumentResponse {
|
|
|
14
15
|
success: boolean;
|
|
15
16
|
documentId?: string;
|
|
16
17
|
}
|
|
18
|
+
interface createCalendarEventResponse {
|
|
19
|
+
success: boolean;
|
|
20
|
+
event?: calendar_v3.Schema$Event;
|
|
21
|
+
}
|
|
22
|
+
interface deleteCalendarEventResponse {
|
|
23
|
+
success: boolean;
|
|
24
|
+
eventId?: string;
|
|
25
|
+
}
|
|
26
|
+
interface updateCalendarEventResponse {
|
|
27
|
+
success: boolean;
|
|
28
|
+
event?: calendar_v3.Schema$Event;
|
|
29
|
+
}
|
|
30
|
+
export interface IRescheduleEvent {
|
|
31
|
+
start: {
|
|
32
|
+
dateTime?: string;
|
|
33
|
+
date?: string;
|
|
34
|
+
timeZone?: string;
|
|
35
|
+
};
|
|
36
|
+
end: {
|
|
37
|
+
dateTime?: string;
|
|
38
|
+
date?: string;
|
|
39
|
+
timeZone?: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface ICalendarEventInsertParameters {
|
|
43
|
+
calendarId: string;
|
|
44
|
+
conferenceDataVersion: number;
|
|
45
|
+
maxAttendees: number;
|
|
46
|
+
sendNotifications: boolean;
|
|
47
|
+
sendUpdates: 'all' | 'externalOnly' | 'none';
|
|
48
|
+
supportsAttachments: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface ICalendarEventPatchParameters {
|
|
51
|
+
calendarId: string;
|
|
52
|
+
eventId: string;
|
|
53
|
+
alwaysIncludeEmail?: boolean;
|
|
54
|
+
conferenceDataVersion?: number;
|
|
55
|
+
maxAttendees?: number;
|
|
56
|
+
sendNotifications?: boolean;
|
|
57
|
+
sendUpdates?: 'all' | 'externalOnly' | 'none';
|
|
58
|
+
supportsAttachments?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface ICalendarEvent extends calendar_v3.Schema$Event {
|
|
61
|
+
}
|
|
17
62
|
export interface ISchemaRequest extends docs_v1.Schema$Request {
|
|
18
63
|
}
|
|
19
64
|
export interface IInsertText extends docs_v1.Schema$InsertTextRequest {
|
|
@@ -24,8 +69,12 @@ export interface ICredentials extends JWTInput {
|
|
|
24
69
|
}
|
|
25
70
|
export declare class PlennaGoogleService {
|
|
26
71
|
private readonly credentials;
|
|
27
|
-
|
|
72
|
+
private readonly opts?;
|
|
73
|
+
constructor(credentials: ICredentials, opts?: {
|
|
74
|
+
subject?: string;
|
|
75
|
+
});
|
|
28
76
|
authorization(): GoogleAuth<JSONClient>;
|
|
77
|
+
calendarAuthorization(): GoogleAuth<JSONClient>;
|
|
29
78
|
getDocument(documentId: string): Promise<docs_v1.Schema$Document | undefined>;
|
|
30
79
|
cloneDocument(documentId: string, folderId: string): Promise<cloneDocumentResponse>;
|
|
31
80
|
buildPayload(template?: Array<Partial<IPlennaGoogleBase>>): ISchemaRequest[];
|
|
@@ -34,5 +83,8 @@ export declare class PlennaGoogleService {
|
|
|
34
83
|
exportDocumentAsUrl(fileId: string): Promise<string | undefined>;
|
|
35
84
|
exportDocumentAsFile(fileId: string): Promise<ArrayBuffer | undefined>;
|
|
36
85
|
deleteDocument(fileId: string): Promise<deleteDocumentResponse>;
|
|
86
|
+
createCalendarEvent(parameterOptions: ICalendarEventInsertParameters, event: ICalendarEvent): Promise<createCalendarEventResponse>;
|
|
87
|
+
deleteCalendarEvent(eventId: string, calendarId?: string): Promise<deleteCalendarEventResponse>;
|
|
88
|
+
updateCalendarEvent(parameterOptions: ICalendarEventPatchParameters, updates: Partial<ICalendarEvent>): Promise<updateCalendarEventResponse>;
|
|
37
89
|
}
|
|
38
90
|
export {};
|
package/dist/src/google/index.js
CHANGED
|
@@ -3,11 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PlennaGoogleService = void 0;
|
|
4
4
|
const docs_1 = require("@googleapis/docs");
|
|
5
5
|
const drive_1 = require("@googleapis/drive");
|
|
6
|
+
const calendar_1 = require("@googleapis/calendar");
|
|
6
7
|
const google_auth_library_1 = require("google-auth-library");
|
|
7
8
|
const requestBuilder_1 = require("./requestBuilder");
|
|
8
9
|
class PlennaGoogleService {
|
|
9
10
|
credentials;
|
|
10
|
-
|
|
11
|
+
opts;
|
|
12
|
+
constructor(credentials, opts) {
|
|
13
|
+
this.opts = opts ?? null;
|
|
11
14
|
this.credentials = credentials;
|
|
12
15
|
}
|
|
13
16
|
authorization() {
|
|
@@ -19,6 +22,17 @@ class PlennaGoogleService {
|
|
|
19
22
|
]
|
|
20
23
|
});
|
|
21
24
|
}
|
|
25
|
+
calendarAuthorization() {
|
|
26
|
+
return new google_auth_library_1.GoogleAuth({
|
|
27
|
+
credentials: this.credentials,
|
|
28
|
+
scopes: [
|
|
29
|
+
'https://www.googleapis.com/auth/calendar'
|
|
30
|
+
],
|
|
31
|
+
clientOptions: {
|
|
32
|
+
subject: this.opts?.subject ?? ''
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
22
36
|
async getDocument(documentId) {
|
|
23
37
|
const authClient = this.authorization();
|
|
24
38
|
const client = new docs_1.docs_v1.Docs({ auth: authClient });
|
|
@@ -114,5 +128,59 @@ class PlennaGoogleService {
|
|
|
114
128
|
return { success: false };
|
|
115
129
|
}
|
|
116
130
|
}
|
|
131
|
+
async createCalendarEvent(parameterOptions, event) {
|
|
132
|
+
const authClient = this.calendarAuthorization();
|
|
133
|
+
const calendar = new calendar_1.calendar_v3.Calendar({ auth: authClient });
|
|
134
|
+
try {
|
|
135
|
+
const response = await calendar.events.insert({
|
|
136
|
+
...parameterOptions,
|
|
137
|
+
requestBody: event
|
|
138
|
+
}, { headers: await authClient.getRequestHeaders() });
|
|
139
|
+
return {
|
|
140
|
+
success: true,
|
|
141
|
+
event: response.data
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.log(error);
|
|
146
|
+
return { success: false };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async deleteCalendarEvent(eventId, calendarId = 'primary') {
|
|
150
|
+
const authClient = this.calendarAuthorization();
|
|
151
|
+
const calendar = new calendar_1.calendar_v3.Calendar({ auth: authClient });
|
|
152
|
+
try {
|
|
153
|
+
await calendar.events.delete({
|
|
154
|
+
calendarId,
|
|
155
|
+
eventId
|
|
156
|
+
}, { headers: await authClient.getRequestHeaders() });
|
|
157
|
+
return {
|
|
158
|
+
success: true,
|
|
159
|
+
eventId
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
console.log(error);
|
|
164
|
+
return { success: false };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async updateCalendarEvent(parameterOptions, updates) {
|
|
168
|
+
const authClient = this.authorization();
|
|
169
|
+
const calendar = new calendar_1.calendar_v3.Calendar({ auth: authClient });
|
|
170
|
+
try {
|
|
171
|
+
const response = await calendar.events.patch({
|
|
172
|
+
...parameterOptions,
|
|
173
|
+
requestBody: updates
|
|
174
|
+
}, { headers: await authClient.getRequestHeaders() });
|
|
175
|
+
return {
|
|
176
|
+
success: true,
|
|
177
|
+
event: response.data
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
console.log(error);
|
|
182
|
+
return { success: false };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
117
185
|
}
|
|
118
186
|
exports.PlennaGoogleService = PlennaGoogleService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plenna_utilities",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "plenna's utils for backend projects",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"@aws-sdk/client-bedrock-runtime": "^3.600.0",
|
|
40
40
|
"@aws-sdk/client-s3": "^3.600.0",
|
|
41
41
|
"@aws-sdk/s3-request-presigner": "^3.600.0",
|
|
42
|
+
"@googleapis/calendar": "^14.2.0",
|
|
42
43
|
"@googleapis/docs": "^3.0.2",
|
|
43
44
|
"@googleapis/drive": "^8.10.0",
|
|
44
45
|
"@googleapis/sheets": "^8.0.0",
|