mblabs-roccato-backend-commons 1.0.54 → 1.0.55

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 {
@@ -137,6 +159,9 @@ export declare namespace AzureStorageBlob {
137
159
  }
138
160
  }
139
161
  }
162
+ export interface IAzureAuthService {
163
+ refreshAccess(req: AzureAuth.RefreshAccess.Request): Promise<AzureAuth.RefreshAccess.Response>;
164
+ }
140
165
  export interface IAzureApplicationInsightsService {
141
166
  trackTrace(req: AzureApplicationInsights.TrackTrace.Request): Promise<void>;
142
167
  trackEvent(req: AzureApplicationInsights.TrackEvent.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();
@@ -1,5 +1,6 @@
1
1
  import AzureApplicationInsightsService from './application-insights';
2
+ import AzureAuthService from './auth';
2
3
  import AzureCommunicationService from './communication';
3
4
  import AzureKeyVaultService from './keyvault';
4
5
  import AzureStorageBlobService from './storage-blob';
5
- export { AzureApplicationInsightsService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, };
6
+ export { AzureAuthService, AzureApplicationInsightsService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, };
@@ -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.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureApplicationInsightsService = void 0;
6
+ exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = 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;
9
11
  const communication_1 = __importDefault(require("./communication"));
10
12
  exports.AzureCommunicationService = communication_1.default;
11
13
  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,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, 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, 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.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,7 @@ 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; } });
15
16
  Object.defineProperty(exports, "AzureCommunicationService", { enumerable: true, get: function () { return azure_1.AzureCommunicationService; } });
16
17
  Object.defineProperty(exports, "AzureKeyVaultService", { enumerable: true, get: function () { return azure_1.AzureKeyVaultService; } });
17
18
  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.55",
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",
@@ -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 {
@@ -150,6 +174,10 @@ export namespace AzureStorageBlob {
150
174
  }
151
175
  }
152
176
 
177
+ export interface IAzureAuthService {
178
+ refreshAccess(req: AzureAuth.RefreshAccess.Request): Promise<AzureAuth.RefreshAccess.Response>;
179
+ }
180
+
153
181
  export interface IAzureApplicationInsightsService {
154
182
  trackTrace(req: AzureApplicationInsights.TrackTrace.Request): Promise<void>;
155
183
  trackEvent(req: AzureApplicationInsights.TrackEvent.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();
@@ -1,11 +1,13 @@
1
1
  import AzureApplicationInsightsService from './application-insights';
2
+ import AzureAuthService from './auth';
2
3
  import AzureCommunicationService from './communication';
3
4
  import AzureKeyVaultService from './keyvault';
4
5
  import AzureStorageBlobService from './storage-blob';
5
6
 
6
7
  export {
8
+ AzureAuthService,
7
9
  AzureApplicationInsightsService,
8
10
  AzureCommunicationService,
9
11
  AzureKeyVaultService,
10
12
  AzureStorageBlobService,
11
- };
13
+ };
@@ -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 {
@@ -7,6 +7,7 @@ import {
7
7
  } from './aws';
8
8
  import {
9
9
  AzureApplicationInsightsService,
10
+ AzureAuthService,
10
11
  AzureCommunicationService,
11
12
  AzureKeyVaultService,
12
13
  AzureStorageBlobService,
@@ -37,6 +38,7 @@ export {
37
38
  AmazonSecretManagerService,
38
39
  AmazonSQSService,
39
40
  AzureApplicationInsightsService,
41
+ AzureAuthService,
40
42
  AzureCommunicationService,
41
43
  AzureKeyVaultService,
42
44
  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"