mblabs-roccato-backend-commons 1.0.50 → 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.
- package/dist/interfaces/gcp.d.ts +56 -7
- package/dist/services/gcp/auth.d.ts +6 -0
- package/dist/services/gcp/auth.js +18 -0
- package/dist/services/gcp/calendar.d.ts +6 -0
- package/dist/services/gcp/calendar.js +30 -0
- package/dist/services/gcp/index.d.ts +4 -2
- package/dist/services/gcp/index.js +7 -3
- package/dist/services/gcp/storage.d.ts +8 -0
- package/dist/services/gcp/{cloudstorage.js → storage.js} +10 -7
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.js +4 -2
- package/package.json +2 -1
- package/src/interfaces/gcp.ts +63 -9
- package/src/services/gcp/auth.ts +31 -0
- package/src/services/gcp/calendar.ts +44 -0
- package/src/services/gcp/index.ts +6 -2
- package/src/services/gcp/sheets.ts +2 -2
- package/src/services/gcp/storage.ts +37 -0
- package/src/services/index.ts +6 -2
- package/yarn.lock +39 -0
- package/dist/services/gcp/cloudstorage.d.ts +0 -8
- package/src/services/gcp/cloudstorage.ts +0 -33
package/dist/interfaces/gcp.d.ts
CHANGED
|
@@ -1,8 +1,53 @@
|
|
|
1
1
|
import { sheets_v4 as Sheetsv4 } from 'googleapis';
|
|
2
2
|
export interface Credentials {
|
|
3
|
-
|
|
3
|
+
project?: string;
|
|
4
|
+
audience?: string;
|
|
5
|
+
clientId?: string;
|
|
6
|
+
clientSecret?: string;
|
|
7
|
+
redirectUri?: string;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
accessToken?: string;
|
|
10
|
+
refreshToken?: string;
|
|
4
11
|
}
|
|
5
|
-
export declare namespace
|
|
12
|
+
export declare namespace GoogleAuth {
|
|
13
|
+
namespace RefreshAccess {
|
|
14
|
+
interface Request {
|
|
15
|
+
data: {
|
|
16
|
+
accessToken: string;
|
|
17
|
+
refreshToken: string;
|
|
18
|
+
};
|
|
19
|
+
credentials: Credentials;
|
|
20
|
+
}
|
|
21
|
+
interface Response {
|
|
22
|
+
accessToken: string;
|
|
23
|
+
refreshToken: string;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
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
|
+
}
|
|
50
|
+
export declare namespace GoogleStorage {
|
|
6
51
|
namespace GetSignedUrl {
|
|
7
52
|
interface Request {
|
|
8
53
|
data: {
|
|
@@ -13,9 +58,7 @@ export declare namespace GoogleCloudStorage {
|
|
|
13
58
|
expirationSeconds?: number;
|
|
14
59
|
contentType?: string;
|
|
15
60
|
};
|
|
16
|
-
credentials:
|
|
17
|
-
projectId: string;
|
|
18
|
-
};
|
|
61
|
+
credentials: Credentials;
|
|
19
62
|
}
|
|
20
63
|
interface Response {
|
|
21
64
|
url: string;
|
|
@@ -56,6 +99,12 @@ export interface IGoogleSecretsService {
|
|
|
56
99
|
export interface IGoogleSheetsService {
|
|
57
100
|
readSheet(req: GoogleSheets.ReadSheet.Request): Promise<GoogleSheets.ReadSheet.Response>;
|
|
58
101
|
}
|
|
59
|
-
export interface
|
|
60
|
-
getSignedUrl(req:
|
|
102
|
+
export interface IGoogleStorageService {
|
|
103
|
+
getSignedUrl(req: GoogleStorage.GetSignedUrl.Request): Promise<GoogleStorage.GetSignedUrl.Response>;
|
|
104
|
+
}
|
|
105
|
+
export interface IGoogleAuthService {
|
|
106
|
+
refreshAccess(req: GoogleAuth.RefreshAccess.Request): Promise<GoogleAuth.RefreshAccess.Response>;
|
|
107
|
+
}
|
|
108
|
+
export interface IGoogleCalendarService {
|
|
109
|
+
getEvents(req: GoogleCalendar.GetEvents.Request): Promise<GoogleCalendar.GetEvents.Response>;
|
|
61
110
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GoogleAuth, IGoogleAuthService } from '../../interfaces';
|
|
2
|
+
declare class GoogleAuthService implements IGoogleAuthService {
|
|
3
|
+
refreshAccess({ credentials, data, }: GoogleAuth.RefreshAccess.Request): Promise<GoogleAuth.RefreshAccess.Response>;
|
|
4
|
+
}
|
|
5
|
+
declare const _default: GoogleAuthService;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
4
|
+
class GoogleAuthService {
|
|
5
|
+
async refreshAccess({ credentials, data, }) {
|
|
6
|
+
const client = new google_auth_library_1.OAuth2Client(credentials.clientId, credentials.clientSecret, credentials.redirectUri);
|
|
7
|
+
client.setCredentials({
|
|
8
|
+
access_token: data.accessToken,
|
|
9
|
+
refresh_token: data.refreshToken,
|
|
10
|
+
});
|
|
11
|
+
const response = await client.refreshAccessToken();
|
|
12
|
+
return {
|
|
13
|
+
accessToken: response.credentials?.access_token,
|
|
14
|
+
refreshToken: response.credentials?.refresh_token,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = new GoogleAuthService();
|
|
@@ -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,4 +1,6 @@
|
|
|
1
|
-
import
|
|
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';
|
|
6
|
+
export { GoogleAuthService, GoogleCalendarService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, };
|
|
@@ -3,10 +3,14 @@ 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.
|
|
7
|
-
const
|
|
8
|
-
exports.
|
|
6
|
+
exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleCalendarService = exports.GoogleAuthService = void 0;
|
|
7
|
+
const auth_1 = __importDefault(require("./auth"));
|
|
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"));
|
|
12
14
|
exports.GoogleSheetsService = sheets_1.default;
|
|
15
|
+
const storage_1 = __importDefault(require("./storage"));
|
|
16
|
+
exports.GoogleStorageService = storage_1.default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GoogleStorage, IGoogleStorageService } from '../../interfaces';
|
|
2
|
+
declare class GoogleStorageService implements IGoogleStorageService {
|
|
3
|
+
getSignedUrl({ credentials, data, }: GoogleStorage.GetSignedUrl.Request): Promise<{
|
|
4
|
+
url: string;
|
|
5
|
+
}>;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: GoogleStorageService;
|
|
8
|
+
export default _default;
|
|
@@ -5,17 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const storage_1 = require("@google-cloud/storage");
|
|
7
7
|
const file_1 = __importDefault(require("../file"));
|
|
8
|
-
class
|
|
8
|
+
class GoogleStorageService {
|
|
9
9
|
async getSignedUrl({ credentials, data, }) {
|
|
10
10
|
const storage = new storage_1.Storage({
|
|
11
|
-
credentials:
|
|
12
|
-
|
|
11
|
+
credentials: {
|
|
12
|
+
audience: credentials.audience,
|
|
13
|
+
project_id: credentials.project,
|
|
14
|
+
apiKey: credentials.apiKey,
|
|
15
|
+
},
|
|
13
16
|
});
|
|
14
17
|
const options = {
|
|
15
18
|
version: 'v4',
|
|
16
|
-
action: data
|
|
17
|
-
expires: data
|
|
18
|
-
contentType: data
|
|
19
|
+
action: data.isUpload ? 'write' : 'read',
|
|
20
|
+
expires: data.expirationSeconds ?? 180,
|
|
21
|
+
contentType: data.contentType ?? 'text/csv',
|
|
19
22
|
};
|
|
20
23
|
const [url] = await storage
|
|
21
24
|
.bucket(data.bucket)
|
|
@@ -26,4 +29,4 @@ class GoogleCloudStorageService {
|
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
|
-
exports.default = new
|
|
32
|
+
exports.default = new GoogleStorageService();
|
package/dist/services/index.d.ts
CHANGED
|
@@ -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 {
|
|
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, GoogleSecretsService, GoogleSheetsService,
|
|
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, };
|
package/dist/services/index.js
CHANGED
|
@@ -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.
|
|
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; } });
|
|
@@ -22,9 +22,11 @@ exports.FileService = file_1.default;
|
|
|
22
22
|
const firebase_1 = __importDefault(require("./firebase"));
|
|
23
23
|
exports.FirebaseService = firebase_1.default;
|
|
24
24
|
const gcp_1 = require("./gcp");
|
|
25
|
-
Object.defineProperty(exports, "
|
|
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; } });
|
|
29
|
+
Object.defineProperty(exports, "GoogleStorageService", { enumerable: true, get: function () { return gcp_1.GoogleStorageService; } });
|
|
28
30
|
const grafana_1 = __importDefault(require("./grafana"));
|
|
29
31
|
exports.GrafanaService = grafana_1.default;
|
|
30
32
|
const i18n_1 = __importDefault(require("./i18n"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mblabs-roccato-backend-commons",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.52",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"axios": "^1.8.4",
|
|
63
63
|
"class-transformer": "^0.5.1",
|
|
64
64
|
"firebase-admin": "^13.4.0",
|
|
65
|
+
"google-auth-library": "^10.3.0",
|
|
65
66
|
"googleapis": "^148.0.0",
|
|
66
67
|
"i18next": "^25.3.6",
|
|
67
68
|
"kafkajs": "^2.2.4",
|
package/src/interfaces/gcp.ts
CHANGED
|
@@ -1,10 +1,59 @@
|
|
|
1
1
|
import { sheets_v4 as Sheetsv4 } from 'googleapis';
|
|
2
2
|
|
|
3
3
|
export interface Credentials {
|
|
4
|
-
|
|
4
|
+
project?: string;
|
|
5
|
+
audience?: string;
|
|
6
|
+
clientId?: string;
|
|
7
|
+
clientSecret?: string;
|
|
8
|
+
redirectUri?: string;
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
accessToken?: string;
|
|
11
|
+
refreshToken?: string;
|
|
5
12
|
}
|
|
6
13
|
|
|
7
|
-
export namespace
|
|
14
|
+
export namespace GoogleAuth {
|
|
15
|
+
export namespace RefreshAccess {
|
|
16
|
+
export interface Request {
|
|
17
|
+
data: {
|
|
18
|
+
accessToken: string;
|
|
19
|
+
refreshToken: string;
|
|
20
|
+
};
|
|
21
|
+
credentials: Credentials;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface Response {
|
|
25
|
+
accessToken: string;
|
|
26
|
+
refreshToken: string;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
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
|
+
|
|
56
|
+
export namespace GoogleStorage {
|
|
8
57
|
export namespace GetSignedUrl {
|
|
9
58
|
export interface Request {
|
|
10
59
|
data: {
|
|
@@ -12,12 +61,10 @@ export namespace GoogleCloudStorage {
|
|
|
12
61
|
bucket: string;
|
|
13
62
|
folder?: string;
|
|
14
63
|
isUpload?: boolean;
|
|
15
|
-
expirationSeconds?: number
|
|
16
|
-
contentType?: string
|
|
17
|
-
};
|
|
18
|
-
credentials: {
|
|
19
|
-
projectId: string
|
|
64
|
+
expirationSeconds?: number;
|
|
65
|
+
contentType?: string;
|
|
20
66
|
};
|
|
67
|
+
credentials: Credentials;
|
|
21
68
|
}
|
|
22
69
|
|
|
23
70
|
export interface Response {
|
|
@@ -66,7 +113,14 @@ export interface IGoogleSheetsService {
|
|
|
66
113
|
readSheet(req: GoogleSheets.ReadSheet.Request): Promise<GoogleSheets.ReadSheet.Response>;
|
|
67
114
|
}
|
|
68
115
|
|
|
69
|
-
export interface
|
|
70
|
-
getSignedUrl(req:
|
|
116
|
+
export interface IGoogleStorageService {
|
|
117
|
+
getSignedUrl(req: GoogleStorage.GetSignedUrl.Request): Promise<GoogleStorage.GetSignedUrl.Response>;
|
|
71
118
|
}
|
|
72
119
|
|
|
120
|
+
export interface IGoogleAuthService {
|
|
121
|
+
refreshAccess(req: GoogleAuth.RefreshAccess.Request): Promise<GoogleAuth.RefreshAccess.Response>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface IGoogleCalendarService {
|
|
125
|
+
getEvents(req: GoogleCalendar.GetEvents.Request): Promise<GoogleCalendar.GetEvents.Response>;
|
|
126
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OAuth2Client } from 'google-auth-library';
|
|
2
|
+
|
|
3
|
+
import { GoogleAuth, IGoogleAuthService } from '../../interfaces';
|
|
4
|
+
|
|
5
|
+
class GoogleAuthService implements IGoogleAuthService {
|
|
6
|
+
async refreshAccess ({
|
|
7
|
+
credentials,
|
|
8
|
+
data,
|
|
9
|
+
}: GoogleAuth.RefreshAccess.Request): Promise<GoogleAuth.RefreshAccess.Response> {
|
|
10
|
+
|
|
11
|
+
const client = new OAuth2Client(
|
|
12
|
+
credentials.clientId,
|
|
13
|
+
credentials.clientSecret,
|
|
14
|
+
credentials.redirectUri
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
client.setCredentials({
|
|
18
|
+
access_token: data.accessToken,
|
|
19
|
+
refresh_token: data.refreshToken,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const response = await client.refreshAccessToken();
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
accessToken: response.credentials?.access_token,
|
|
26
|
+
refreshToken: response.credentials?.refresh_token,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default new GoogleAuthService();
|
|
@@ -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,9 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import GoogleAuthService from './auth';
|
|
2
|
+
import GoogleCalendarService from './calendar';
|
|
2
3
|
import GoogleSecretsService from './secrets';
|
|
3
4
|
import GoogleSheetsService from './sheets';
|
|
5
|
+
import GoogleStorageService from './storage';
|
|
4
6
|
|
|
5
7
|
export {
|
|
8
|
+
GoogleAuthService,
|
|
9
|
+
GoogleCalendarService,
|
|
6
10
|
GoogleSecretsService,
|
|
7
11
|
GoogleSheetsService,
|
|
8
|
-
|
|
12
|
+
GoogleStorageService,
|
|
9
13
|
};
|
|
@@ -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 =
|
|
10
|
+
const instance = GoogleSDK.sheets({
|
|
11
11
|
version: 'v4',
|
|
12
12
|
auth: credentials.apiKey,
|
|
13
13
|
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { GetSignedUrlConfig, Storage } from '@google-cloud/storage';
|
|
2
|
+
|
|
3
|
+
import { GoogleStorage, IGoogleStorageService } from '../../interfaces';
|
|
4
|
+
import FileService from '../file';
|
|
5
|
+
|
|
6
|
+
class GoogleStorageService implements IGoogleStorageService {
|
|
7
|
+
async getSignedUrl ({
|
|
8
|
+
credentials,
|
|
9
|
+
data,
|
|
10
|
+
}: GoogleStorage.GetSignedUrl.Request) {
|
|
11
|
+
const storage = new Storage({
|
|
12
|
+
credentials: {
|
|
13
|
+
audience: credentials.audience,
|
|
14
|
+
project_id: credentials.project,
|
|
15
|
+
apiKey: credentials.apiKey,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const options: GetSignedUrlConfig = {
|
|
20
|
+
version: 'v4',
|
|
21
|
+
action: data.isUpload ? 'write' : 'read',
|
|
22
|
+
expires: data.expirationSeconds ?? 180,
|
|
23
|
+
contentType: data.contentType ?? 'text/csv',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const [ url ] = await storage
|
|
27
|
+
.bucket(data.bucket)
|
|
28
|
+
.file(FileService.getBucketPath(data.filename, data.folder))
|
|
29
|
+
.getSignedUrl(options);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
url,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default new GoogleStorageService();
|
package/src/services/index.ts
CHANGED
|
@@ -15,9 +15,11 @@ import DateService from './date';
|
|
|
15
15
|
import FileService from './file';
|
|
16
16
|
import FirebaseService from './firebase';
|
|
17
17
|
import {
|
|
18
|
-
|
|
18
|
+
GoogleAuthService,
|
|
19
|
+
GoogleCalendarService,
|
|
19
20
|
GoogleSecretsService,
|
|
20
21
|
GoogleSheetsService,
|
|
22
|
+
GoogleStorageService,
|
|
21
23
|
} from './gcp';
|
|
22
24
|
import GrafanaService from './grafana';
|
|
23
25
|
import I18nService from './i18n';
|
|
@@ -41,9 +43,11 @@ export {
|
|
|
41
43
|
DateService,
|
|
42
44
|
FileService,
|
|
43
45
|
FirebaseService,
|
|
46
|
+
GoogleAuthService,
|
|
47
|
+
GoogleCalendarService,
|
|
44
48
|
GoogleSecretsService,
|
|
45
49
|
GoogleSheetsService,
|
|
46
|
-
|
|
50
|
+
GoogleStorageService,
|
|
47
51
|
GrafanaService,
|
|
48
52
|
I18nService,
|
|
49
53
|
KafkaService,
|
package/yarn.lock
CHANGED
|
@@ -4938,6 +4938,15 @@ gaxios@^6.0.0, gaxios@^6.0.2, gaxios@^6.0.3, gaxios@^6.1.1:
|
|
|
4938
4938
|
node-fetch "^2.6.9"
|
|
4939
4939
|
uuid "^9.0.1"
|
|
4940
4940
|
|
|
4941
|
+
gaxios@^7.0.0:
|
|
4942
|
+
version "7.1.2"
|
|
4943
|
+
resolved "https://registry.yarnpkg.com/gaxios/-/gaxios-7.1.2.tgz#4954bc5628e3cd108e5252cb597b03a5f16c21ac"
|
|
4944
|
+
integrity sha512-/Szrn8nr+2TsQT1Gp8iIe/BEytJmbyfrbFh419DfGQSkEgNEhbPi7JRJuughjkTzPWgU9gBQf5AVu3DbHt0OXA==
|
|
4945
|
+
dependencies:
|
|
4946
|
+
extend "^3.0.2"
|
|
4947
|
+
https-proxy-agent "^7.0.1"
|
|
4948
|
+
node-fetch "^3.3.2"
|
|
4949
|
+
|
|
4941
4950
|
gaxios@^7.0.0-rc.1, gaxios@^7.0.0-rc.4:
|
|
4942
4951
|
version "7.0.0-rc.6"
|
|
4943
4952
|
resolved "https://registry.npmjs.org/gaxios/-/gaxios-7.0.0-rc.6.tgz#4648afddc60b05eb9cb901534ba9493f1a390df0"
|
|
@@ -4956,6 +4965,15 @@ gcp-metadata@^6.1.0:
|
|
|
4956
4965
|
google-logging-utils "^0.0.2"
|
|
4957
4966
|
json-bigint "^1.0.0"
|
|
4958
4967
|
|
|
4968
|
+
gcp-metadata@^7.0.0:
|
|
4969
|
+
version "7.0.1"
|
|
4970
|
+
resolved "https://registry.yarnpkg.com/gcp-metadata/-/gcp-metadata-7.0.1.tgz#43bb9cd482cf0590629b871ab9133af45b78382d"
|
|
4971
|
+
integrity sha512-UcO3kefx6dCcZkgcTGgVOTFb7b1LlQ02hY1omMjjrrBzkajRMCFgYOjs7J71WqnuG1k2b+9ppGL7FsOfhZMQKQ==
|
|
4972
|
+
dependencies:
|
|
4973
|
+
gaxios "^7.0.0"
|
|
4974
|
+
google-logging-utils "^1.0.0"
|
|
4975
|
+
json-bigint "^1.0.0"
|
|
4976
|
+
|
|
4959
4977
|
gcp-metadata@^7.0.0-rc.1:
|
|
4960
4978
|
version "7.0.0-rc.1"
|
|
4961
4979
|
resolved "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-7.0.0-rc.1.tgz#ddce444cf1ca780e8df0db15d4e5907ca8388cd5"
|
|
@@ -5071,6 +5089,19 @@ google-auth-library@^10.0.0-rc.1:
|
|
|
5071
5089
|
gtoken "^8.0.0-rc.1"
|
|
5072
5090
|
jws "^4.0.0"
|
|
5073
5091
|
|
|
5092
|
+
google-auth-library@^10.3.0:
|
|
5093
|
+
version "10.3.0"
|
|
5094
|
+
resolved "https://registry.yarnpkg.com/google-auth-library/-/google-auth-library-10.3.0.tgz#d44d005d546bf6b8956529caf0f9e70a07960c04"
|
|
5095
|
+
integrity sha512-ylSE3RlCRZfZB56PFJSfUCuiuPq83Fx8hqu1KPWGK8FVdSaxlp/qkeMMX/DT/18xkwXIHvXEXkZsljRwfrdEfQ==
|
|
5096
|
+
dependencies:
|
|
5097
|
+
base64-js "^1.3.0"
|
|
5098
|
+
ecdsa-sig-formatter "^1.0.11"
|
|
5099
|
+
gaxios "^7.0.0"
|
|
5100
|
+
gcp-metadata "^7.0.0"
|
|
5101
|
+
google-logging-utils "^1.0.0"
|
|
5102
|
+
gtoken "^8.0.0"
|
|
5103
|
+
jws "^4.0.0"
|
|
5104
|
+
|
|
5074
5105
|
google-auth-library@^9.0.0, google-auth-library@^9.14.2, google-auth-library@^9.3.0, google-auth-library@^9.6.3, google-auth-library@^9.7.0:
|
|
5075
5106
|
version "9.15.1"
|
|
5076
5107
|
resolved "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.15.1.tgz#0c5d84ed1890b2375f1cd74f03ac7b806b392928"
|
|
@@ -5167,6 +5198,14 @@ gtoken@^7.0.0:
|
|
|
5167
5198
|
gaxios "^6.0.0"
|
|
5168
5199
|
jws "^4.0.0"
|
|
5169
5200
|
|
|
5201
|
+
gtoken@^8.0.0:
|
|
5202
|
+
version "8.0.0"
|
|
5203
|
+
resolved "https://registry.yarnpkg.com/gtoken/-/gtoken-8.0.0.tgz#d67a0e346dd441bfb54ad14040ddc3b632886575"
|
|
5204
|
+
integrity sha512-+CqsMbHPiSTdtSO14O51eMNlrp9N79gmeqmXeouJOhfucAedHw9noVe/n5uJk3tbKE6a+6ZCQg3RPhVhHByAIw==
|
|
5205
|
+
dependencies:
|
|
5206
|
+
gaxios "^7.0.0"
|
|
5207
|
+
jws "^4.0.0"
|
|
5208
|
+
|
|
5170
5209
|
gtoken@^8.0.0-rc.1:
|
|
5171
5210
|
version "8.0.0-rc.1"
|
|
5172
5211
|
resolved "https://registry.npmjs.org/gtoken/-/gtoken-8.0.0-rc.1.tgz#3877f1069f02ae99548f5d285d6c1834b692e22a"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { GoogleCloudStorage, IGoogleCloudStorageService } from '../../interfaces';
|
|
2
|
-
declare class GoogleCloudStorageService implements IGoogleCloudStorageService {
|
|
3
|
-
getSignedUrl({ credentials, data, }: GoogleCloudStorage.GetSignedUrl.Request): Promise<{
|
|
4
|
-
url: string;
|
|
5
|
-
}>;
|
|
6
|
-
}
|
|
7
|
-
declare const _default: GoogleCloudStorageService;
|
|
8
|
-
export default _default;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { GetSignedUrlConfig, Storage } from '@google-cloud/storage';
|
|
2
|
-
|
|
3
|
-
import { GoogleCloudStorage, IGoogleCloudStorageService } from '../../interfaces';
|
|
4
|
-
import FileService from '../file';
|
|
5
|
-
|
|
6
|
-
class GoogleCloudStorageService implements IGoogleCloudStorageService {
|
|
7
|
-
async getSignedUrl ({
|
|
8
|
-
credentials, data,
|
|
9
|
-
}: GoogleCloudStorage.GetSignedUrl.Request) {
|
|
10
|
-
const storage = new Storage({
|
|
11
|
-
credentials: credentials as any,
|
|
12
|
-
projectId: credentials.projectId,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const options: GetSignedUrlConfig = {
|
|
16
|
-
version: 'v4',
|
|
17
|
-
action: data?.isUpload ? 'write' : 'read',
|
|
18
|
-
expires: data?.expirationSeconds ?? 180,
|
|
19
|
-
contentType: data?.contentType ?? 'text/csv',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const [ url ] = await storage
|
|
23
|
-
.bucket(data.bucket)
|
|
24
|
-
.file(FileService.getBucketPath(data.filename, data.folder))
|
|
25
|
-
.getSignedUrl(options);
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
url,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default new GoogleCloudStorageService();
|