mblabs-roccato-backend-commons 1.0.54 → 1.0.56

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.
@@ -1,8 +1,30 @@
1
1
  interface Credentials {
2
- accountName?: string;
3
- accountKey?: string;
2
+ tenant?: string;
3
+ account?: {
4
+ name?: string;
5
+ key?: string;
6
+ };
7
+ client?: {
8
+ id?: string;
9
+ secret?: string;
10
+ };
4
11
  connection?: string;
5
12
  }
13
+ export declare namespace AzureAuth {
14
+ namespace RefreshAccess {
15
+ interface Request {
16
+ data: {
17
+ refreshToken: string;
18
+ scopes?: string[];
19
+ };
20
+ credentials: Credentials;
21
+ }
22
+ interface Response {
23
+ accessToken: string;
24
+ refreshToken: string;
25
+ }
26
+ }
27
+ }
6
28
  export declare namespace AzureApplicationInsights {
7
29
  namespace TrackTrace {
8
30
  interface Request {
@@ -42,6 +64,34 @@ export declare namespace AzureApplicationInsights {
42
64
  }
43
65
  }
44
66
  }
67
+ export declare namespace AzureCalendar {
68
+ namespace GetEvents {
69
+ interface Request {
70
+ data: {
71
+ user: string;
72
+ accessToken: string;
73
+ startDate: Date;
74
+ endDate: Date;
75
+ };
76
+ credentials: Credentials;
77
+ }
78
+ interface Response {
79
+ events: {
80
+ title?: string;
81
+ description?: string;
82
+ type?: string;
83
+ status?: string;
84
+ createdAt?: string | Date;
85
+ startAt?: string | Date;
86
+ endAt?: string | Date;
87
+ organizer?: {
88
+ name?: string;
89
+ email?: string;
90
+ } | null;
91
+ }[];
92
+ }
93
+ }
94
+ }
45
95
  export declare namespace AzureCommunication {
46
96
  namespace SendMail {
47
97
  interface Request {
@@ -137,12 +187,18 @@ export declare namespace AzureStorageBlob {
137
187
  }
138
188
  }
139
189
  }
190
+ export interface IAzureAuthService {
191
+ refreshAccess(req: AzureAuth.RefreshAccess.Request): Promise<AzureAuth.RefreshAccess.Response>;
192
+ }
140
193
  export interface IAzureApplicationInsightsService {
141
194
  trackTrace(req: AzureApplicationInsights.TrackTrace.Request): Promise<void>;
142
195
  trackEvent(req: AzureApplicationInsights.TrackEvent.Request): Promise<void>;
143
196
  trackException(req: AzureApplicationInsights.TrackException.Request): Promise<void>;
144
197
  trackMetric(req: AzureApplicationInsights.TrackMetric.Request): Promise<void>;
145
198
  }
199
+ export interface IAzureCalendarService {
200
+ getEvents(req: AzureCalendar.GetEvents.Request): Promise<AzureCalendar.GetEvents.Response>;
201
+ }
146
202
  export interface IAzureCommunicationService {
147
203
  sendMail(req: AzureCommunication.SendMail.Request): Promise<void>;
148
204
  sendSMS(req: AzureCommunication.SendSMS.Request): Promise<void>;
@@ -0,0 +1,6 @@
1
+ import { AzureAuth, IAzureAuthService } from '../../interfaces/azure';
2
+ declare class AzureAuthService implements IAzureAuthService {
3
+ refreshAccess({ credentials, data, }: AzureAuth.RefreshAccess.Request): Promise<AzureAuth.RefreshAccess.Response>;
4
+ }
5
+ declare const _default: AzureAuthService;
6
+ export default _default;
@@ -0,0 +1,26 @@
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
+ const msal_node_1 = __importDefault(require("@azure/msal-node"));
7
+ class AzureAuthService {
8
+ async refreshAccess({ credentials, data, }) {
9
+ const client = new msal_node_1.default.ConfidentialClientApplication({
10
+ auth: {
11
+ clientId: credentials.client?.id,
12
+ authority: `https://login.microsoftonline.com/${credentials.tenant ?? 'common'}`,
13
+ clientSecret: credentials.client?.secret,
14
+ },
15
+ });
16
+ const { accessToken } = await client.acquireTokenByRefreshToken({
17
+ refreshToken: data.refreshToken,
18
+ scopes: data.scopes ?? [],
19
+ });
20
+ return {
21
+ accessToken,
22
+ refreshToken: data.refreshToken,
23
+ };
24
+ }
25
+ }
26
+ exports.default = new AzureAuthService();
@@ -0,0 +1,7 @@
1
+ import 'isomorphic-fetch';
2
+ import { AzureCalendar, IAzureCalendarService } from '../../interfaces';
3
+ declare class AzuerCalendarService implements IAzureCalendarService {
4
+ getEvents({ credentials, data, }: AzureCalendar.GetEvents.Request): Promise<AzureCalendar.GetEvents.Response>;
5
+ }
6
+ declare const _default: AzuerCalendarService;
7
+ export default _default;
@@ -0,0 +1,40 @@
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
+ require("isomorphic-fetch");
7
+ const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
8
+ const date_1 = __importDefault(require("../date"));
9
+ class AzuerCalendarService {
10
+ async getEvents({ credentials, data, }) {
11
+ const client = microsoft_graph_client_1.Client.init({
12
+ authProvider: (done) => { done(null, data.accessToken); },
13
+ });
14
+ const { value: items } = await client
15
+ .api(`/users/${data.user}/calendarview`)
16
+ .query({
17
+ 'startDateTime': date_1.default.toISO(data.startDate),
18
+ 'endDateTime': date_1.default.toISO(data.endDate),
19
+ '$select': 'subject,start,end,location,organizer,type,responseStatus',
20
+ '$orderby': 'start/dateTime',
21
+ })
22
+ .get();
23
+ return {
24
+ events: items.map((item) => ({
25
+ title: item.subject,
26
+ description: '',
27
+ type: item.type,
28
+ status: item.responseStatus?.response,
29
+ createdAt: item.createdDateTime,
30
+ startAt: item.start.dateTime,
31
+ endAt: item.end?.dateTime,
32
+ organizer: {
33
+ name: item.organizer?.emailAddress?.name,
34
+ email: item.organizer?.emailAddress?.address,
35
+ },
36
+ })),
37
+ };
38
+ }
39
+ }
40
+ exports.default = new AzuerCalendarService();
@@ -1,5 +1,7 @@
1
1
  import AzureApplicationInsightsService from './application-insights';
2
+ import AzureAuthService from './auth';
3
+ import AzureCalendarService from './calendar';
2
4
  import AzureCommunicationService from './communication';
3
5
  import AzureKeyVaultService from './keyvault';
4
6
  import AzureStorageBlobService from './storage-blob';
5
- export { AzureApplicationInsightsService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, };
7
+ export { AzureAuthService, AzureApplicationInsightsService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, };
@@ -3,9 +3,13 @@ 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.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureApplicationInsightsService = void 0;
6
+ exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureCalendarService = exports.AzureApplicationInsightsService = exports.AzureAuthService = void 0;
7
7
  const application_insights_1 = __importDefault(require("./application-insights"));
8
8
  exports.AzureApplicationInsightsService = application_insights_1.default;
9
+ const auth_1 = __importDefault(require("./auth"));
10
+ exports.AzureAuthService = auth_1.default;
11
+ const calendar_1 = __importDefault(require("./calendar"));
12
+ exports.AzureCalendarService = calendar_1.default;
9
13
  const communication_1 = __importDefault(require("./communication"));
10
14
  exports.AzureCommunicationService = communication_1.default;
11
15
  const keyvault_1 = __importDefault(require("./keyvault"));
@@ -8,7 +8,7 @@ const date_1 = __importDefault(require("../../services/date"));
8
8
  const file_1 = __importDefault(require("../../services/file"));
9
9
  class AzureStorageBlobService {
10
10
  async uploadBuffer({ credentials, data, }) {
11
- const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(credentials.accountName, credentials.accountKey);
11
+ const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(credentials.account?.name, credentials.account?.key);
12
12
  const client = new storage_blob_1.BlobServiceClient(data.storageUrl, sharedKeyCredential);
13
13
  await client
14
14
  .getContainerClient(data.storageContainer)
@@ -16,7 +16,7 @@ class AzureStorageBlobService {
16
16
  .uploadData(data.file);
17
17
  }
18
18
  async downloadBuffer({ credentials, data, }) {
19
- const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(credentials.accountName, credentials.accountKey);
19
+ const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(credentials.account?.name, credentials.account?.key);
20
20
  const client = new storage_blob_1.BlobServiceClient(data.storageUrl, sharedKeyCredential);
21
21
  const { readableStreamBody } = await client
22
22
  .getContainerClient(data.storageContainer)
@@ -28,7 +28,7 @@ class AzureStorageBlobService {
28
28
  };
29
29
  }
30
30
  async getPreSignedUrl({ credentials, data, }) {
31
- const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(credentials.accountName, credentials.accountKey);
31
+ const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(credentials.account?.name, credentials.account?.key);
32
32
  const payload = {
33
33
  containerName: data.storageContainer,
34
34
  blobName: data.filename,
@@ -41,7 +41,7 @@ class AzureStorageBlobService {
41
41
  expiresOn: data.options?.hoursToExpire &&
42
42
  date_1.default.addHours(date_1.default.getCurrentDate(), Number(data.options?.hoursToExpire)),
43
43
  };
44
- const url = `https://${credentials.accountName}.blob.core.windows.net/${data.storageContainer}/${data.filename}`;
44
+ const url = `https://${credentials.account?.name}.blob.core.windows.net/${data.storageContainer}/${data.filename}`;
45
45
  const token = (0, storage_blob_1.generateBlobSASQueryParameters)(payload, sharedKeyCredential).toString();
46
46
  return {
47
47
  url: `${url}?${token}`,
@@ -1,6 +1,7 @@
1
1
  declare class DateService {
2
- toDate(inp: Date | string, format?: string): Date;
3
- toFormat(inp: Date | string, format?: string): string;
2
+ toDate(inp: string | Date, format?: string): Date;
3
+ toFormat(inp: string | Date, format?: string): string;
4
+ toISO(inp: string | Date): string;
4
5
  convertTimestampToDate(inp: string | number): Date;
5
6
  getCurrent(): string;
6
7
  getCurrentDate(): Date;
@@ -11,7 +12,7 @@ declare class DateService {
11
12
  minusHours(start: Date, toRemove: number): Date;
12
13
  minusMinutes(start: Date, toRemove: number): Date;
13
14
  isValidDate(inp: string, format?: string): boolean;
14
- getStartAndEndOfDay(inp?: Date | string, useUTC?: boolean): {
15
+ getStartAndEndOfDay(inp?: string | Date, useUTC?: boolean): {
15
16
  startOfDay: Date;
16
17
  endOfDay: Date;
17
18
  };
@@ -24,7 +25,7 @@ declare class DateService {
24
25
  getCurrentTimestamp(): number;
25
26
  getMillisFromFormattedDate(date: string, format?: string): number;
26
27
  getMonthsInRange(startDate: Date, endDate: Date): string[];
27
- isSameDay(inp: Date | string, compare?: Date): boolean;
28
+ isSameDay(inp: string | Date, compare?: Date): boolean;
28
29
  isToday(date: Date): boolean;
29
30
  }
30
31
  declare const _default: DateService;
@@ -21,6 +21,12 @@ class DateService {
21
21
  }
22
22
  return luxon_1.DateTime.fromISO(inp).toFormat(format);
23
23
  }
24
+ toISO(inp) {
25
+ if (inp instanceof Date) {
26
+ return luxon_1.DateTime.fromJSDate(inp).toISO();
27
+ }
28
+ return luxon_1.DateTime.fromISO(inp).toISO();
29
+ }
24
30
  convertTimestampToDate(inp) {
25
31
  const timestamp = typeof inp === 'string' ? parseInt(inp, 10) : inp;
26
32
  return luxon_1.DateTime.fromMillis(timestamp).toJSDate();
@@ -12,21 +12,20 @@ class GoogleCalendarService {
12
12
  .calendar({ version: 'v3', auth: client })
13
13
  .events
14
14
  .list();
15
- const events = items.map(item => ({
16
- title: item.summary,
17
- description: item.description,
18
- type: item.eventType,
19
- status: item.status,
20
- createdAt: item.created,
21
- startAt: item.start?.dateTime,
22
- endAt: item.end?.dateTime,
23
- organizer: {
24
- name: item.organizer?.displayName,
25
- email: item.organizer?.email,
26
- },
27
- }));
28
15
  return {
29
- events,
16
+ events: items.map(item => ({
17
+ title: item.summary,
18
+ description: item.description,
19
+ type: item.eventType,
20
+ status: item.status,
21
+ createdAt: item.created,
22
+ startAt: item.start?.dateTime,
23
+ endAt: item.end?.dateTime,
24
+ organizer: {
25
+ name: item.organizer?.displayName,
26
+ email: item.organizer?.email,
27
+ },
28
+ })),
30
29
  };
31
30
  }
32
31
  }
@@ -1,5 +1,5 @@
1
1
  import { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService } from './aws';
2
- import { AzureApplicationInsightsService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService } from './azure';
2
+ import { AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService } from './azure';
3
3
  import DateService from './date';
4
4
  import FileService from './file';
5
5
  import FirebaseService from './firebase';
@@ -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, GoogleCalendarService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GrafanaService, I18nService, KafkaService, KeycloakService, NodeMailerService, RabbitMQService, RedisService, SendgridService, };
15
+ export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, 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.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;
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.AzureCalendarService = exports.AzureAuthService = 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; } });
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "AmazonSecretManagerService", { enumerable: true,
12
12
  Object.defineProperty(exports, "AmazonSQSService", { enumerable: true, get: function () { return aws_1.AmazonSQSService; } });
13
13
  const azure_1 = require("./azure");
14
14
  Object.defineProperty(exports, "AzureApplicationInsightsService", { enumerable: true, get: function () { return azure_1.AzureApplicationInsightsService; } });
15
+ Object.defineProperty(exports, "AzureAuthService", { enumerable: true, get: function () { return azure_1.AzureAuthService; } });
16
+ Object.defineProperty(exports, "AzureCalendarService", { enumerable: true, get: function () { return azure_1.AzureCalendarService; } });
15
17
  Object.defineProperty(exports, "AzureCommunicationService", { enumerable: true, get: function () { return azure_1.AzureCommunicationService; } });
16
18
  Object.defineProperty(exports, "AzureKeyVaultService", { enumerable: true, get: function () { return azure_1.AzureKeyVaultService; } });
17
19
  Object.defineProperty(exports, "AzureStorageBlobService", { enumerable: true, get: function () { return azure_1.AzureStorageBlobService; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mblabs-roccato-backend-commons",
3
- "version": "1.0.54",
3
+ "version": "1.0.56",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -51,6 +51,7 @@
51
51
  "@azure/communication-sms": "^1.2.0-beta.3",
52
52
  "@azure/identity": "^4.9.1",
53
53
  "@azure/keyvault-secrets": "^4.9.0",
54
+ "@azure/msal-node": "^3.8.0",
54
55
  "@azure/storage-blob": "^12.27.0",
55
56
  "@google-cloud/secret-manager": "^6.0.1",
56
57
  "@google-cloud/storage": "^7.16.0",
@@ -66,6 +67,7 @@
66
67
  "google-auth-library": "^10.3.0",
67
68
  "googleapis": "^148.0.0",
68
69
  "i18next": "^25.3.6",
70
+ "isomorphic-fetch": "^3.0.0",
69
71
  "kafkajs": "^2.2.4",
70
72
  "luxon": "^3.6.1",
71
73
  "nodemailer": "^7.0.3",
@@ -76,6 +78,7 @@
76
78
  "devDependencies": {
77
79
  "@commitlint/cli": "^19.8.0",
78
80
  "@commitlint/config-conventional": "^19.8.0",
81
+ "@microsoft/microsoft-graph-types": "^2.40.0",
79
82
  "@types/amqplib": "^0.10.7",
80
83
  "@types/express": "^5.0.1",
81
84
  "@types/luxon": "^3.6.2",
@@ -1,9 +1,33 @@
1
1
  interface Credentials {
2
- accountName?: string;
3
- accountKey?: string;
2
+ tenant?: string;
3
+ account?: {
4
+ name?: string;
5
+ key?: string;
6
+ };
7
+ client?: {
8
+ id?: string;
9
+ secret?: string;
10
+ };
4
11
  connection?: string;
5
12
  }
6
13
 
14
+ export namespace AzureAuth {
15
+ export namespace RefreshAccess {
16
+ export interface Request {
17
+ data: {
18
+ refreshToken: string;
19
+ scopes?: string[];
20
+ };
21
+ credentials: Credentials;
22
+ }
23
+
24
+ export interface Response {
25
+ accessToken: string;
26
+ refreshToken: string;
27
+ }
28
+ }
29
+ }
30
+
7
31
  export namespace AzureApplicationInsights {
8
32
  export namespace TrackTrace {
9
33
  export interface Request {
@@ -19,7 +43,9 @@ export namespace AzureApplicationInsights {
19
43
  export interface Request {
20
44
  data: {
21
45
  name: string;
22
- properties?: { [key: string]: string };
46
+ properties?: {
47
+ [key: string]: string;
48
+ };
23
49
  };
24
50
  credentials: Credentials;
25
51
  }
@@ -45,6 +71,36 @@ export namespace AzureApplicationInsights {
45
71
  }
46
72
  }
47
73
 
74
+ export namespace AzureCalendar {
75
+ export namespace GetEvents {
76
+ export interface Request {
77
+ data: {
78
+ user: string;
79
+ accessToken: string;
80
+ startDate: Date;
81
+ endDate: Date;
82
+ };
83
+ credentials: Credentials;
84
+ }
85
+
86
+ export interface Response {
87
+ events: {
88
+ title?: string;
89
+ description?: string;
90
+ type?: string;
91
+ status?: string;
92
+ createdAt?: string | Date;
93
+ startAt?: string | Date;
94
+ endAt?: string | Date;
95
+ organizer?: {
96
+ name?: string;
97
+ email?: string;
98
+ } | null;
99
+ }[];
100
+ }
101
+ }
102
+ }
103
+
48
104
  export namespace AzureCommunication {
49
105
  export namespace SendMail {
50
106
  export interface Request {
@@ -150,6 +206,10 @@ export namespace AzureStorageBlob {
150
206
  }
151
207
  }
152
208
 
209
+ export interface IAzureAuthService {
210
+ refreshAccess(req: AzureAuth.RefreshAccess.Request): Promise<AzureAuth.RefreshAccess.Response>;
211
+ }
212
+
153
213
  export interface IAzureApplicationInsightsService {
154
214
  trackTrace(req: AzureApplicationInsights.TrackTrace.Request): Promise<void>;
155
215
  trackEvent(req: AzureApplicationInsights.TrackEvent.Request): Promise<void>;
@@ -157,6 +217,10 @@ export interface IAzureApplicationInsightsService {
157
217
  trackMetric(req: AzureApplicationInsights.TrackMetric.Request): Promise<void>;
158
218
  }
159
219
 
220
+ export interface IAzureCalendarService {
221
+ getEvents(req: AzureCalendar.GetEvents.Request): Promise<AzureCalendar.GetEvents.Response>;
222
+ }
223
+
160
224
  export interface IAzureCommunicationService {
161
225
  sendMail(req: AzureCommunication.SendMail.Request): Promise<void>;
162
226
  sendSMS(req: AzureCommunication.SendSMS.Request): Promise<void>;
@@ -0,0 +1,30 @@
1
+ import MSAL from '@azure/msal-node';
2
+
3
+ import { AzureAuth, IAzureAuthService } from '../../interfaces/azure';
4
+
5
+ class AzureAuthService implements IAzureAuthService {
6
+ async refreshAccess ({
7
+ credentials,
8
+ data,
9
+ }: AzureAuth.RefreshAccess.Request): Promise<AzureAuth.RefreshAccess.Response> {
10
+ const client = new MSAL.ConfidentialClientApplication({
11
+ auth: {
12
+ clientId: credentials.client?.id!,
13
+ authority: `https://login.microsoftonline.com/${credentials.tenant ?? 'common'}`,
14
+ clientSecret: credentials.client?.secret!,
15
+ },
16
+ });
17
+
18
+ const { accessToken } = await client.acquireTokenByRefreshToken({
19
+ refreshToken: data.refreshToken,
20
+ scopes: data.scopes ?? [],
21
+ });
22
+
23
+ return {
24
+ accessToken,
25
+ refreshToken: data.refreshToken,
26
+ };
27
+ }
28
+ }
29
+
30
+ export default new AzureAuthService();
@@ -0,0 +1,46 @@
1
+ import 'isomorphic-fetch';
2
+
3
+ import { Client } from '@microsoft/microsoft-graph-client';
4
+ import { Event } from '@microsoft/microsoft-graph-types';
5
+
6
+ import { AzureCalendar, IAzureCalendarService } from '../../interfaces';
7
+ import DateService from '../date';
8
+
9
+ class AzuerCalendarService implements IAzureCalendarService {
10
+ async getEvents ({
11
+ credentials,
12
+ data,
13
+ }: AzureCalendar.GetEvents.Request): Promise<AzureCalendar.GetEvents.Response> {
14
+ const client = Client.init({
15
+ authProvider: (done) => { done(null, data.accessToken); },
16
+ });
17
+
18
+ const { value: items } = await client
19
+ .api(`/users/${data.user}/calendarview`)
20
+ .query({
21
+ 'startDateTime': DateService.toISO(data.startDate),
22
+ 'endDateTime': DateService.toISO(data.endDate),
23
+ '$select': 'subject,start,end,location,organizer,type,responseStatus',
24
+ '$orderby': 'start/dateTime',
25
+ })
26
+ .get();
27
+
28
+ return {
29
+ events: (items as Event[]).map((item) => ({
30
+ title: item.subject,
31
+ description: '',
32
+ type: item.type,
33
+ status: item.responseStatus?.response,
34
+ createdAt: item.createdDateTime,
35
+ startAt: item.start.dateTime,
36
+ endAt: item.end?.dateTime,
37
+ organizer: {
38
+ name: item.organizer?.emailAddress?.name,
39
+ email: item.organizer?.emailAddress?.address,
40
+ },
41
+ })),
42
+ };
43
+ }
44
+ }
45
+
46
+ export default new AzuerCalendarService();
@@ -1,11 +1,15 @@
1
1
  import AzureApplicationInsightsService from './application-insights';
2
+ import AzureAuthService from './auth';
3
+ import AzureCalendarService from './calendar';
2
4
  import AzureCommunicationService from './communication';
3
5
  import AzureKeyVaultService from './keyvault';
4
6
  import AzureStorageBlobService from './storage-blob';
5
7
 
6
8
  export {
9
+ AzureAuthService,
7
10
  AzureApplicationInsightsService,
11
+ AzureCalendarService,
8
12
  AzureCommunicationService,
9
13
  AzureKeyVaultService,
10
14
  AzureStorageBlobService,
11
- };
15
+ };
@@ -16,8 +16,8 @@ class AzureStorageBlobService implements IAzureStorageBlobService {
16
16
  data,
17
17
  }: AzureStorageBlob.UploadBuffer.Request): Promise<void> {
18
18
  const sharedKeyCredential = new StorageSharedKeyCredential(
19
- credentials.accountName!,
20
- credentials.accountKey!
19
+ credentials.account?.name!,
20
+ credentials.account?.key!
21
21
  );
22
22
 
23
23
  const client = new BlobServiceClient(data.storageUrl, sharedKeyCredential);
@@ -33,8 +33,8 @@ class AzureStorageBlobService implements IAzureStorageBlobService {
33
33
  data,
34
34
  }: AzureStorageBlob.DownloadBuffer.Request): Promise<AzureStorageBlob.DownloadBuffer.Response> {
35
35
  const sharedKeyCredential = new StorageSharedKeyCredential(
36
- credentials.accountName!,
37
- credentials.accountKey!
36
+ credentials.account?.name!,
37
+ credentials.account?.key!
38
38
  );
39
39
 
40
40
  const client = new BlobServiceClient(data.storageUrl, sharedKeyCredential);
@@ -56,8 +56,8 @@ class AzureStorageBlobService implements IAzureStorageBlobService {
56
56
  data,
57
57
  }: AzureStorageBlob.GetPreSignedUrl.Request): Promise<AzureStorageBlob.GetPreSignedUrl.Response> {
58
58
  const sharedKeyCredential = new StorageSharedKeyCredential(
59
- credentials.accountName!,
60
- credentials.accountKey!
59
+ credentials.account?.name!,
60
+ credentials.account?.key!
61
61
  );
62
62
 
63
63
  const payload: BlobSASSignatureValues = {
@@ -75,7 +75,7 @@ class AzureStorageBlobService implements IAzureStorageBlobService {
75
75
  DateService.addHours(DateService.getCurrentDate(), Number(data.options?.hoursToExpire)),
76
76
  };
77
77
 
78
- const url = `https://${credentials.accountName!}.blob.core.windows.net/${data.storageContainer}/${data.filename}`;
78
+ const url = `https://${credentials.account?.name!}.blob.core.windows.net/${data.storageContainer}/${data.filename}`;
79
79
  const token = generateBlobSASQueryParameters(payload, sharedKeyCredential).toString();
80
80
 
81
81
  return {
@@ -3,7 +3,7 @@ import { DateTime } from 'luxon';
3
3
  import { DATE } from '../constants';
4
4
 
5
5
  class DateService {
6
- public toDate (inp: Date | string, format = DATE.SYSTEM.COMMON_DATE): Date {
6
+ public toDate (inp: string | Date, format = DATE.SYSTEM.COMMON_DATE): Date {
7
7
  if (inp instanceof Date) {
8
8
  return inp;
9
9
  }
@@ -19,7 +19,7 @@ class DateService {
19
19
  return DateTime.local().toJSDate();
20
20
  }
21
21
 
22
- public toFormat (inp: Date | string, format = DATE.SYSTEM.COMMON_DATE): string {
22
+ public toFormat (inp: string | Date, format = DATE.SYSTEM.COMMON_DATE): string {
23
23
  if (inp instanceof Date) {
24
24
  return DateTime.fromJSDate(inp).toFormat(format);
25
25
  }
@@ -27,6 +27,14 @@ class DateService {
27
27
  return DateTime.fromISO(inp).toFormat(format);
28
28
  }
29
29
 
30
+ public toISO (inp: string | Date) {
31
+ if (inp instanceof Date) {
32
+ return DateTime.fromJSDate(inp).toISO();
33
+ }
34
+
35
+ return DateTime.fromISO(inp).toISO();
36
+ }
37
+
30
38
  public convertTimestampToDate (inp: string | number): Date {
31
39
  const timestamp = typeof inp === 'string' ? parseInt(inp, 10) : inp;
32
40
  return DateTime.fromMillis(timestamp).toJSDate();
@@ -69,7 +77,7 @@ class DateService {
69
77
  }
70
78
 
71
79
  public getStartAndEndOfDay (
72
- inp: Date | string = this.getCurrentDate(),
80
+ inp: string | Date = this.getCurrentDate(),
73
81
  useUTC = false
74
82
  ) {
75
83
  const date = inp instanceof Date
@@ -143,7 +151,7 @@ class DateService {
143
151
  return months;
144
152
  }
145
153
 
146
- public isSameDay (inp: Date | string, compare = this.getCurrentDate()): boolean {
154
+ public isSameDay (inp: string | Date, compare = this.getCurrentDate()): boolean {
147
155
  const startDate = DateTime.fromJSDate(this.toDate(inp)).startOf('day');
148
156
  const endDate = DateTime.fromJSDate(this.toDate(compare)).startOf('day');
149
157
 
@@ -23,22 +23,20 @@ class GoogleCalendarService implements IGoogleCalendarService {
23
23
  .events
24
24
  .list();
25
25
 
26
- const events = items.map(item => ({
27
- title: item.summary,
28
- description: item.description,
29
- type: item.eventType,
30
- status: item.status,
31
- createdAt: item.created,
32
- startAt: item.start?.dateTime,
33
- endAt: item.end?.dateTime,
34
- organizer: {
35
- name: item.organizer?.displayName,
36
- email: item.organizer?.email,
37
- },
38
- }));
39
-
40
26
  return {
41
- events,
27
+ events: items.map(item => ({
28
+ title: item.summary,
29
+ description: item.description,
30
+ type: item.eventType,
31
+ status: item.status,
32
+ createdAt: item.created,
33
+ startAt: item.start?.dateTime,
34
+ endAt: item.end?.dateTime,
35
+ organizer: {
36
+ name: item.organizer?.displayName,
37
+ email: item.organizer?.email,
38
+ },
39
+ })),
42
40
  };
43
41
  }
44
42
  }
@@ -7,6 +7,8 @@ import {
7
7
  } from './aws';
8
8
  import {
9
9
  AzureApplicationInsightsService,
10
+ AzureAuthService,
11
+ AzureCalendarService,
10
12
  AzureCommunicationService,
11
13
  AzureKeyVaultService,
12
14
  AzureStorageBlobService,
@@ -37,6 +39,8 @@ export {
37
39
  AmazonSecretManagerService,
38
40
  AmazonSQSService,
39
41
  AzureApplicationInsightsService,
42
+ AzureAuthService,
43
+ AzureCalendarService,
40
44
  AzureCommunicationService,
41
45
  AzureKeyVaultService,
42
46
  AzureStorageBlobService,
package/yarn.lock CHANGED
@@ -1404,6 +1404,11 @@
1404
1404
  dependencies:
1405
1405
  "@azure/msal-common" "15.7.0"
1406
1406
 
1407
+ "@azure/msal-common@15.13.0":
1408
+ version "15.13.0"
1409
+ resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-15.13.0.tgz#229008f8badbf5af6a446a0be1c436be2f4c8cd9"
1410
+ integrity sha512-8oF6nj02qX7eE/6+wFT5NluXRHc05AgdCC3fJnkjiJooq8u7BcLmxaYYSwc2AfEkWRMRi6Eyvvbeqk4U4412Ag==
1411
+
1407
1412
  "@azure/msal-common@15.7.0":
1408
1413
  version "15.7.0"
1409
1414
  resolved "https://registry.npmjs.org/@azure/msal-common/-/msal-common-15.7.0.tgz#03833058fc21e16f5dde0540ebe6233dfdd0dd2b"
@@ -1418,6 +1423,15 @@
1418
1423
  jsonwebtoken "^9.0.0"
1419
1424
  uuid "^8.3.0"
1420
1425
 
1426
+ "@azure/msal-node@^3.8.0":
1427
+ version "3.8.0"
1428
+ resolved "https://registry.yarnpkg.com/@azure/msal-node/-/msal-node-3.8.0.tgz#17634ebab1b4d6f6a3fac1a378c4929fdeeae79d"
1429
+ integrity sha512-23BXm82Mp5XnRhrcd4mrHa0xuUNRp96ivu3nRatrfdAqjoeWAGyD0eEAafxAOHAEWWmdlyFK4ELFcdziXyw2sA==
1430
+ dependencies:
1431
+ "@azure/msal-common" "15.13.0"
1432
+ jsonwebtoken "^9.0.0"
1433
+ uuid "^8.3.0"
1434
+
1421
1435
  "@azure/opentelemetry-instrumentation-azure-sdk@^1.0.0-beta.7":
1422
1436
  version "1.0.0-beta.8"
1423
1437
  resolved "https://registry.npmjs.org/@azure/opentelemetry-instrumentation-azure-sdk/-/opentelemetry-instrumentation-azure-sdk-1.0.0-beta.8.tgz#7abc6b056354414e6bacc366873c67f8cbe718aa"
@@ -2093,6 +2107,11 @@
2093
2107
  "@babel/runtime" "^7.12.5"
2094
2108
  tslib "^2.2.0"
2095
2109
 
2110
+ "@microsoft/microsoft-graph-types@^2.40.0":
2111
+ version "2.40.0"
2112
+ resolved "https://registry.yarnpkg.com/@microsoft/microsoft-graph-types/-/microsoft-graph-types-2.40.0.tgz#65f51600ab45ace97d7b1368c47f9e0f835fddca"
2113
+ integrity sha512-1fcPVrB/NkbNcGNfCy+Cgnvwxt6/sbIEEFgZHFBJ670zYLegENYJF8qMo7x3LqBjWX2/Eneq5BVVRCLTmlJN+g==
2114
+
2096
2115
  "@nodelib/fs.scandir@2.1.5":
2097
2116
  version "2.1.5"
2098
2117
  resolved "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
@@ -5643,6 +5662,14 @@ isexe@^2.0.0:
5643
5662
  resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
5644
5663
  integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==
5645
5664
 
5665
+ isomorphic-fetch@^3.0.0:
5666
+ version "3.0.0"
5667
+ resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz#0267b005049046d2421207215d45d6a262b8b8b4"
5668
+ integrity sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==
5669
+ dependencies:
5670
+ node-fetch "^2.6.1"
5671
+ whatwg-fetch "^3.4.1"
5672
+
5646
5673
  jackspeak@^3.1.2:
5647
5674
  version "3.4.3"
5648
5675
  resolved "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz#8833a9d89ab4acde6188942bd1c53b6390ed5a8a"
@@ -6096,7 +6123,7 @@ node-domexception@^1.0.0:
6096
6123
  resolved "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
6097
6124
  integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
6098
6125
 
6099
- node-fetch@^2.6.9, node-fetch@^2.7.0:
6126
+ node-fetch@^2.6.1, node-fetch@^2.6.9, node-fetch@^2.7.0:
6100
6127
  version "2.7.0"
6101
6128
  resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
6102
6129
  integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
@@ -7382,6 +7409,11 @@ websocket-extensions@>=0.1.1:
7382
7409
  resolved "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42"
7383
7410
  integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==
7384
7411
 
7412
+ whatwg-fetch@^3.4.1:
7413
+ version "3.6.20"
7414
+ resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz#580ce6d791facec91d37c72890995a0b48d31c70"
7415
+ integrity sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==
7416
+
7385
7417
  whatwg-url@^5.0.0:
7386
7418
  version "5.0.0"
7387
7419
  resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"