mblabs-roccato-backend-commons 1.0.51 → 1.0.52

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.
@@ -6,6 +6,8 @@ export interface Credentials {
6
6
  clientSecret?: string;
7
7
  redirectUri?: string;
8
8
  apiKey?: string;
9
+ accessToken?: string;
10
+ refreshToken?: string;
9
11
  }
10
12
  export declare namespace GoogleAuth {
11
13
  namespace RefreshAccess {
@@ -22,6 +24,29 @@ export declare namespace GoogleAuth {
22
24
  }
23
25
  }
24
26
  }
27
+ export declare namespace GoogleCalendar {
28
+ namespace GetEvents {
29
+ interface Request {
30
+ data: {
31
+ accessToken: string;
32
+ refreshToken: string;
33
+ };
34
+ credentials: Credentials;
35
+ }
36
+ interface Response {
37
+ events: {
38
+ title?: string;
39
+ status?: string;
40
+ startAt?: string | Date;
41
+ endAt?: string | Date;
42
+ organizer?: {
43
+ name?: string;
44
+ email?: string;
45
+ } | null;
46
+ }[];
47
+ }
48
+ }
49
+ }
25
50
  export declare namespace GoogleStorage {
26
51
  namespace GetSignedUrl {
27
52
  interface Request {
@@ -80,3 +105,6 @@ export interface IGoogleStorageService {
80
105
  export interface IGoogleAuthService {
81
106
  refreshAccess(req: GoogleAuth.RefreshAccess.Request): Promise<GoogleAuth.RefreshAccess.Response>;
82
107
  }
108
+ export interface IGoogleCalendarService {
109
+ getEvents(req: GoogleCalendar.GetEvents.Request): Promise<GoogleCalendar.GetEvents.Response>;
110
+ }
@@ -1,10 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GoogleStorage = void 0;
4
- var GoogleStorage;
5
- (function (GoogleStorage) {
6
- let GetSignedUrl;
7
- (function (GetSignedUrl) {
8
- ;
9
- })(GetSignedUrl = GoogleStorage.GetSignedUrl || (GoogleStorage.GetSignedUrl = {}));
10
- })(GoogleStorage || (exports.GoogleStorage = GoogleStorage = {}));
@@ -0,0 +1,6 @@
1
+ import { GoogleCalendar, IGoogleCalendarService } from '../../interfaces';
2
+ declare class GoogleCalendarService implements IGoogleCalendarService {
3
+ getEvents({ credentials, data, }: GoogleCalendar.GetEvents.Request): Promise<GoogleCalendar.GetEvents.Response>;
4
+ }
5
+ declare const _default: GoogleCalendarService;
6
+ export default _default;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const googleapis_1 = require("googleapis");
4
+ class GoogleCalendarService {
5
+ async getEvents({ credentials, data, }) {
6
+ const client = new googleapis_1.google.auth.OAuth2(credentials.clientId, credentials.clientSecret, credentials.redirectUri);
7
+ client.setCredentials({
8
+ access_token: credentials.accessToken,
9
+ refresh_token: data.refreshToken,
10
+ });
11
+ const { data: { items } } = await googleapis_1.google
12
+ .calendar({ version: 'v3', auth: client })
13
+ .events
14
+ .list();
15
+ const events = items.map(item => ({
16
+ title: item.summary,
17
+ status: item.status ?? '',
18
+ startAt: item.start?.dateTime ?? '',
19
+ endAt: item.end?.dateTime ?? '',
20
+ organizer: {
21
+ name: item.organizer?.displayName ?? '',
22
+ email: item.organizer?.email,
23
+ },
24
+ }));
25
+ return {
26
+ events,
27
+ };
28
+ }
29
+ }
30
+ exports.default = new GoogleCalendarService();
@@ -1,5 +1,6 @@
1
1
  import GoogleAuthService from './auth';
2
+ import GoogleCalendarService from './calendar';
2
3
  import GoogleSecretsService from './secrets';
3
4
  import GoogleSheetsService from './sheets';
4
5
  import GoogleStorageService from './storage';
5
- export { GoogleAuthService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, };
6
+ export { GoogleAuthService, GoogleCalendarService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, };
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleAuthService = void 0;
6
+ exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleCalendarService = exports.GoogleAuthService = void 0;
7
7
  const auth_1 = __importDefault(require("./auth"));
8
8
  exports.GoogleAuthService = auth_1.default;
9
+ const calendar_1 = __importDefault(require("./calendar"));
10
+ exports.GoogleCalendarService = calendar_1.default;
9
11
  const secrets_1 = __importDefault(require("./secrets"));
10
12
  exports.GoogleSecretsService = secrets_1.default;
11
13
  const sheets_1 = __importDefault(require("./sheets"));
@@ -3,7 +3,7 @@ import { AzureApplicationInsightsService, AzureCommunicationService, AzureKeyVau
3
3
  import DateService from './date';
4
4
  import FileService from './file';
5
5
  import FirebaseService from './firebase';
6
- import { GoogleAuthService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService } from './gcp';
6
+ import { GoogleAuthService, GoogleCalendarService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService } from './gcp';
7
7
  import GrafanaService from './grafana';
8
8
  import I18nService from './i18n';
9
9
  import KafkaService from './kafka';
@@ -12,4 +12,4 @@ import NodeMailerService from './nodemailer';
12
12
  import RabbitMQService from './rabbit';
13
13
  import RedisService from './redis';
14
14
  import SendgridService from './sendgrid';
15
- export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, DateService, FileService, FirebaseService, GoogleAuthService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GrafanaService, I18nService, KafkaService, KeycloakService, NodeMailerService, RabbitMQService, RedisService, SendgridService, };
15
+ export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, DateService, FileService, FirebaseService, GoogleAuthService, GoogleCalendarService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GrafanaService, I18nService, KafkaService, KeycloakService, NodeMailerService, RabbitMQService, RedisService, SendgridService, };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SendgridService = exports.RedisService = exports.RabbitMQService = exports.NodeMailerService = exports.KeycloakService = exports.KafkaService = exports.I18nService = exports.GrafanaService = exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleAuthService = exports.FirebaseService = exports.FileService = exports.DateService = exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureApplicationInsightsService = exports.AmazonSQSService = exports.AmazonSecretManagerService = exports.AmazonS3Service = exports.AmazonPinpointService = exports.AmazonCloudwatchService = void 0;
6
+ exports.SendgridService = exports.RedisService = exports.RabbitMQService = exports.NodeMailerService = exports.KeycloakService = exports.KafkaService = exports.I18nService = exports.GrafanaService = exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleCalendarService = exports.GoogleAuthService = exports.FirebaseService = exports.FileService = exports.DateService = exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureApplicationInsightsService = exports.AmazonSQSService = exports.AmazonSecretManagerService = exports.AmazonS3Service = exports.AmazonPinpointService = exports.AmazonCloudwatchService = void 0;
7
7
  const aws_1 = require("./aws");
8
8
  Object.defineProperty(exports, "AmazonCloudwatchService", { enumerable: true, get: function () { return aws_1.AmazonCloudwatchService; } });
9
9
  Object.defineProperty(exports, "AmazonPinpointService", { enumerable: true, get: function () { return aws_1.AmazonPinpointService; } });
@@ -23,6 +23,7 @@ const firebase_1 = __importDefault(require("./firebase"));
23
23
  exports.FirebaseService = firebase_1.default;
24
24
  const gcp_1 = require("./gcp");
25
25
  Object.defineProperty(exports, "GoogleAuthService", { enumerable: true, get: function () { return gcp_1.GoogleAuthService; } });
26
+ Object.defineProperty(exports, "GoogleCalendarService", { enumerable: true, get: function () { return gcp_1.GoogleCalendarService; } });
26
27
  Object.defineProperty(exports, "GoogleSecretsService", { enumerable: true, get: function () { return gcp_1.GoogleSecretsService; } });
27
28
  Object.defineProperty(exports, "GoogleSheetsService", { enumerable: true, get: function () { return gcp_1.GoogleSheetsService; } });
28
29
  Object.defineProperty(exports, "GoogleStorageService", { enumerable: true, get: function () { return gcp_1.GoogleStorageService; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mblabs-roccato-backend-commons",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -7,6 +7,8 @@ export interface Credentials {
7
7
  clientSecret?: string;
8
8
  redirectUri?: string;
9
9
  apiKey?: string;
10
+ accessToken?: string;
11
+ refreshToken?: string;
10
12
  }
11
13
 
12
14
  export namespace GoogleAuth {
@@ -26,6 +28,31 @@ export namespace GoogleAuth {
26
28
  }
27
29
  }
28
30
 
31
+ export namespace GoogleCalendar {
32
+ export namespace GetEvents {
33
+ export interface Request {
34
+ data: {
35
+ accessToken: string;
36
+ refreshToken: string;
37
+ };
38
+ credentials: Credentials;
39
+ }
40
+
41
+ export interface Response {
42
+ events: {
43
+ title?: string;
44
+ status?: string;
45
+ startAt?: string | Date;
46
+ endAt?: string | Date;
47
+ organizer?: {
48
+ name?: string;
49
+ email?: string;
50
+ } | null;
51
+ }[];
52
+ }
53
+ }
54
+ }
55
+
29
56
  export namespace GoogleStorage {
30
57
  export namespace GetSignedUrl {
31
58
  export interface Request {
@@ -34,11 +61,11 @@ export namespace GoogleStorage {
34
61
  bucket: string;
35
62
  folder?: string;
36
63
  isUpload?: boolean;
37
- expirationSeconds?: number
38
- contentType?: string
64
+ expirationSeconds?: number;
65
+ contentType?: string;
39
66
  };
40
- credentials: Credentials
41
- };
67
+ credentials: Credentials;
68
+ }
42
69
 
43
70
  export interface Response {
44
71
  url: string;
@@ -93,3 +120,7 @@ export interface IGoogleStorageService {
93
120
  export interface IGoogleAuthService {
94
121
  refreshAccess(req: GoogleAuth.RefreshAccess.Request): Promise<GoogleAuth.RefreshAccess.Response>;
95
122
  }
123
+
124
+ export interface IGoogleCalendarService {
125
+ getEvents(req: GoogleCalendar.GetEvents.Request): Promise<GoogleCalendar.GetEvents.Response>;
126
+ }
@@ -0,0 +1,44 @@
1
+ import { google as GoogleSDK } from 'googleapis';
2
+
3
+ import { GoogleCalendar, IGoogleCalendarService } from '../../interfaces';
4
+
5
+ class GoogleCalendarService implements IGoogleCalendarService {
6
+ async getEvents ({
7
+ credentials,
8
+ data,
9
+ }: GoogleCalendar.GetEvents.Request): Promise<GoogleCalendar.GetEvents.Response> {
10
+ const client = new GoogleSDK.auth.OAuth2(
11
+ credentials.clientId,
12
+ credentials.clientSecret,
13
+ credentials.redirectUri
14
+ );
15
+
16
+ client.setCredentials({
17
+ access_token: credentials.accessToken,
18
+ refresh_token: data.refreshToken,
19
+ });
20
+
21
+ const { data: { items } } = await GoogleSDK
22
+ .calendar({ version: 'v3', auth: client })
23
+ .events
24
+ .list();
25
+
26
+ const events = items.map(item => ({
27
+ title: item.summary,
28
+ status: item.status ?? '',
29
+ startAt: item.start?.dateTime ?? '',
30
+ endAt: item.end?.dateTime ?? '',
31
+ organizer: {
32
+ name: item.organizer?.displayName ?? '',
33
+ email: item.organizer?.email,
34
+ },
35
+ }));
36
+
37
+ return {
38
+ events,
39
+ };
40
+
41
+ }
42
+ }
43
+
44
+ export default new GoogleCalendarService();
@@ -1,10 +1,12 @@
1
1
  import GoogleAuthService from './auth';
2
+ import GoogleCalendarService from './calendar';
2
3
  import GoogleSecretsService from './secrets';
3
4
  import GoogleSheetsService from './sheets';
4
5
  import GoogleStorageService from './storage';
5
6
 
6
7
  export {
7
8
  GoogleAuthService,
9
+ GoogleCalendarService,
8
10
  GoogleSecretsService,
9
11
  GoogleSheetsService,
10
12
  GoogleStorageService,
@@ -1,4 +1,4 @@
1
- import { google } from 'googleapis';
1
+ import { google as GoogleSDK } from 'googleapis';
2
2
 
3
3
  import { GoogleSheets, IGoogleSheetsService } from '../../interfaces';
4
4
 
@@ -7,7 +7,7 @@ class GoogleSheetsService implements IGoogleSheetsService {
7
7
  credentials,
8
8
  data,
9
9
  }: GoogleSheets.ReadSheet.Request): Promise<GoogleSheets.ReadSheet.Response> {
10
- const instance = google.sheets({
10
+ const instance = GoogleSDK.sheets({
11
11
  version: 'v4',
12
12
  auth: credentials.apiKey,
13
13
  });
@@ -16,6 +16,7 @@ import FileService from './file';
16
16
  import FirebaseService from './firebase';
17
17
  import {
18
18
  GoogleAuthService,
19
+ GoogleCalendarService,
19
20
  GoogleSecretsService,
20
21
  GoogleSheetsService,
21
22
  GoogleStorageService,
@@ -43,6 +44,7 @@ export {
43
44
  FileService,
44
45
  FirebaseService,
45
46
  GoogleAuthService,
47
+ GoogleCalendarService,
46
48
  GoogleSecretsService,
47
49
  GoogleSheetsService,
48
50
  GoogleStorageService,