mblabs-roccato-backend-commons 1.0.59 → 1.0.60

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.
@@ -51,6 +51,27 @@ export declare namespace GoogleCalendar {
51
51
  }
52
52
  }
53
53
  }
54
+ export declare namespace GoogleMonitor {
55
+ namespace CreateMetric {
56
+ interface Request {
57
+ data: {
58
+ namespace: string;
59
+ metric: {
60
+ title: string;
61
+ value: number;
62
+ typeof: 'VALUE_TYPE_UNSPECIFIED' | 'BOOL' | 'INT64' | 'DOUBLE' | 'STRING' | 'DISTRIBUTION' | 'MONEY';
63
+ measure: 'METRIC_KIND_UNSPECIFIED' | 'GAUGE' | 'DELTA' | 'CUMULATIVE';
64
+ labels: {
65
+ key: string;
66
+ typeof: 'STRING' | 'BOOL' | 'INT64';
67
+ description: string;
68
+ }[];
69
+ };
70
+ };
71
+ credentials: Credentials;
72
+ }
73
+ }
74
+ }
54
75
  export declare namespace GoogleStorage {
55
76
  namespace GetSignedUrl {
56
77
  interface Request {
@@ -112,3 +133,6 @@ export interface IGoogleAuthService {
112
133
  export interface IGoogleCalendarService {
113
134
  getEvents(req: GoogleCalendar.GetEvents.Request): Promise<GoogleCalendar.GetEvents.Response>;
114
135
  }
136
+ export interface IGoogleMonitorService {
137
+ createMetric(req: GoogleMonitor.CreateMetric.Request): Promise<void>;
138
+ }
@@ -1,6 +1,7 @@
1
1
  import GoogleAuthService from './auth';
2
2
  import GoogleCalendarService from './calendar';
3
+ import GoogleMonitorService from './monitor';
3
4
  import GoogleSecretsService from './secrets';
4
5
  import GoogleSheetsService from './sheets';
5
6
  import GoogleStorageService from './storage';
6
- export { GoogleAuthService, GoogleCalendarService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, };
7
+ export { GoogleAuthService, GoogleCalendarService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GoogleMonitorService, };
@@ -3,11 +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.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleCalendarService = exports.GoogleAuthService = void 0;
6
+ exports.GoogleMonitorService = 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
9
  const calendar_1 = __importDefault(require("./calendar"));
10
10
  exports.GoogleCalendarService = calendar_1.default;
11
+ const monitor_1 = __importDefault(require("./monitor"));
12
+ exports.GoogleMonitorService = monitor_1.default;
11
13
  const secrets_1 = __importDefault(require("./secrets"));
12
14
  exports.GoogleSecretsService = secrets_1.default;
13
15
  const sheets_1 = __importDefault(require("./sheets"));
@@ -0,0 +1,6 @@
1
+ import { GoogleMonitor, IGoogleMonitorService } from '../../interfaces';
2
+ declare class GoogleMonitorService implements IGoogleMonitorService {
3
+ createMetric({ credentials, data, }: GoogleMonitor.CreateMetric.Request): Promise<void>;
4
+ }
5
+ declare const _default: GoogleMonitorService;
6
+ export default _default;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const monitoring_1 = require("@google-cloud/monitoring");
4
+ class GoogleMonitorService {
5
+ async createMetric({ credentials, data, }) {
6
+ const client = new monitoring_1.MetricServiceClient({
7
+ apiKey: credentials.apiKey,
8
+ projectId: credentials.project,
9
+ });
10
+ await client.createMetricDescriptor({
11
+ name: client.projectPath(credentials.project),
12
+ metricDescriptor: {
13
+ name: data.metric.title,
14
+ type: data.namespace,
15
+ metricKind: data.metric.measure,
16
+ valueType: data.metric.typeof,
17
+ unit: data.metric.value.toString(),
18
+ labels: data.metric.labels.map((label) => ({
19
+ key: label.key,
20
+ valueType: label.typeof,
21
+ description: label.description,
22
+ })),
23
+ },
24
+ });
25
+ }
26
+ }
27
+ exports.default = new GoogleMonitorService();
@@ -4,7 +4,10 @@ const secret_manager_1 = require("@google-cloud/secret-manager");
4
4
  const parser_1 = require("../../utils/parser");
5
5
  class GoogleSecretsService {
6
6
  async getSecret({ credentials, data, }) {
7
- const client = new secret_manager_1.SecretManagerServiceClient({ apiKey: credentials.apiKey });
7
+ const client = new secret_manager_1.SecretManagerServiceClient({
8
+ apiKey: credentials.apiKey,
9
+ projectId: credentials.project,
10
+ });
8
11
  const [version] = await client.accessSecretVersion({
9
12
  name: `projects/${data.project}/secrets/${data.secret}/versions/latest`,
10
13
  });
@@ -3,7 +3,7 @@ import { AzureApplicationInsightsService, AzureAuthService, AzureCalendarService
3
3
  import DateService from './date';
4
4
  import FileService from './file';
5
5
  import FirebaseService from './firebase';
6
- import { GoogleAuthService, GoogleCalendarService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService } from './gcp';
6
+ import { GoogleAuthService, GoogleCalendarService, GoogleMonitorService, 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, AzureAuthService, AzureCalendarService, 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, GoogleMonitorService, 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.AzureCalendarService = exports.AzureAuthService = 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.GoogleMonitorService = 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; } });
@@ -26,6 +26,7 @@ exports.FirebaseService = firebase_1.default;
26
26
  const gcp_1 = require("./gcp");
27
27
  Object.defineProperty(exports, "GoogleAuthService", { enumerable: true, get: function () { return gcp_1.GoogleAuthService; } });
28
28
  Object.defineProperty(exports, "GoogleCalendarService", { enumerable: true, get: function () { return gcp_1.GoogleCalendarService; } });
29
+ Object.defineProperty(exports, "GoogleMonitorService", { enumerable: true, get: function () { return gcp_1.GoogleMonitorService; } });
29
30
  Object.defineProperty(exports, "GoogleSecretsService", { enumerable: true, get: function () { return gcp_1.GoogleSecretsService; } });
30
31
  Object.defineProperty(exports, "GoogleSheetsService", { enumerable: true, get: function () { return gcp_1.GoogleSheetsService; } });
31
32
  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.59",
3
+ "version": "1.0.60",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -56,6 +56,7 @@
56
56
  "@azure/monitor-query-metrics": "^1.0.0",
57
57
  "@azure/msal-node": "^3.8.0",
58
58
  "@azure/storage-blob": "^12.27.0",
59
+ "@google-cloud/monitoring": "^5.3.0",
59
60
  "@google-cloud/secret-manager": "^6.0.1",
60
61
  "@google-cloud/storage": "^7.16.0",
61
62
  "@keycloak/keycloak-admin-client": "^26.3.1",
@@ -57,6 +57,28 @@ export namespace GoogleCalendar {
57
57
  }
58
58
  }
59
59
 
60
+ export namespace GoogleMonitor {
61
+ export namespace CreateMetric {
62
+ export interface Request {
63
+ data: {
64
+ namespace: string;
65
+ metric: {
66
+ title: string;
67
+ value: number;
68
+ typeof: 'VALUE_TYPE_UNSPECIFIED' | 'BOOL' | 'INT64' | 'DOUBLE' | 'STRING' | 'DISTRIBUTION' | 'MONEY',
69
+ measure: 'METRIC_KIND_UNSPECIFIED' | 'GAUGE' | 'DELTA' | 'CUMULATIVE',
70
+ labels: {
71
+ key: string;
72
+ typeof: 'STRING' | 'BOOL' | 'INT64';
73
+ description: string;
74
+ }[];
75
+ };
76
+ };
77
+ credentials: Credentials;
78
+ }
79
+ }
80
+ }
81
+
60
82
  export namespace GoogleStorage {
61
83
  export namespace GetSignedUrl {
62
84
  export interface Request {
@@ -128,3 +150,7 @@ export interface IGoogleAuthService {
128
150
  export interface IGoogleCalendarService {
129
151
  getEvents(req: GoogleCalendar.GetEvents.Request): Promise<GoogleCalendar.GetEvents.Response>;
130
152
  }
153
+
154
+ export interface IGoogleMonitorService {
155
+ createMetric(req: GoogleMonitor.CreateMetric.Request): Promise<void>;
156
+ }
@@ -1,5 +1,6 @@
1
1
  import GoogleAuthService from './auth';
2
2
  import GoogleCalendarService from './calendar';
3
+ import GoogleMonitorService from './monitor';
3
4
  import GoogleSecretsService from './secrets';
4
5
  import GoogleSheetsService from './sheets';
5
6
  import GoogleStorageService from './storage';
@@ -10,4 +11,5 @@ export {
10
11
  GoogleSecretsService,
11
12
  GoogleSheetsService,
12
13
  GoogleStorageService,
14
+ GoogleMonitorService,
13
15
  };
@@ -0,0 +1,33 @@
1
+ import { MetricServiceClient } from '@google-cloud/monitoring';
2
+
3
+ import { GoogleMonitor, IGoogleMonitorService } from '../../interfaces';
4
+
5
+ class GoogleMonitorService implements IGoogleMonitorService {
6
+ async createMetric ({
7
+ credentials,
8
+ data,
9
+ }: GoogleMonitor.CreateMetric.Request): Promise<void> {
10
+ const client = new MetricServiceClient({
11
+ apiKey: credentials.apiKey,
12
+ projectId: credentials.project,
13
+ });
14
+
15
+ await client.createMetricDescriptor({
16
+ name: client.projectPath(credentials.project),
17
+ metricDescriptor: {
18
+ name: data.metric.title,
19
+ type: data.namespace,
20
+ metricKind: data.metric.measure,
21
+ valueType: data.metric.typeof,
22
+ unit: data.metric.value.toString(),
23
+ labels: data.metric.labels.map((label) => ({
24
+ key: label.key,
25
+ valueType: label.typeof,
26
+ description: label.description,
27
+ })),
28
+ },
29
+ });
30
+ }
31
+ }
32
+
33
+ export default new GoogleMonitorService();
@@ -8,7 +8,10 @@ class GoogleSecretsService implements IGoogleSecretsService {
8
8
  credentials,
9
9
  data,
10
10
  }: GoogleSecrets.GetSecret.Request): Promise<GoogleSecrets.GetSecret.Response<T>> {
11
- const client = new SecretManagerServiceClient({ apiKey: credentials.apiKey });
11
+ const client = new SecretManagerServiceClient({
12
+ apiKey: credentials.apiKey,
13
+ projectId: credentials.project,
14
+ });
12
15
 
13
16
  const [ version ] = await client.accessSecretVersion({
14
17
  name: `projects/${data.project}/secrets/${data.secret}/versions/latest`,
@@ -19,6 +19,7 @@ import FirebaseService from './firebase';
19
19
  import {
20
20
  GoogleAuthService,
21
21
  GoogleCalendarService,
22
+ GoogleMonitorService,
22
23
  GoogleSecretsService,
23
24
  GoogleSheetsService,
24
25
  GoogleStorageService,
@@ -49,6 +50,7 @@ export {
49
50
  FirebaseService,
50
51
  GoogleAuthService,
51
52
  GoogleCalendarService,
53
+ GoogleMonitorService,
52
54
  GoogleSecretsService,
53
55
  GoogleSheetsService,
54
56
  GoogleStorageService,
package/yarn.lock CHANGED
@@ -2151,6 +2151,13 @@
2151
2151
  google-gax "^4.3.3"
2152
2152
  protobufjs "^7.2.6"
2153
2153
 
2154
+ "@google-cloud/monitoring@^5.3.0":
2155
+ version "5.3.0"
2156
+ resolved "https://registry.yarnpkg.com/@google-cloud/monitoring/-/monitoring-5.3.0.tgz#1b747efabddc746c72c62160b84a90ae63e905fe"
2157
+ integrity sha512-jAx0ASRcRqr+TZIgMTS3gFQR/FqkYzd4usCD0Y/QOkWt4vTT0SgYMaXn62gtuuEmY66VNBVROhpzOMeasgHuKw==
2158
+ dependencies:
2159
+ google-gax "^5.0.0"
2160
+
2154
2161
  "@google-cloud/paginator@^5.0.0":
2155
2162
  version "5.0.2"
2156
2163
  resolved "https://registry.npmjs.org/@google-cloud/paginator/-/paginator-5.0.2.tgz#86ad773266ce9f3b82955a8f75e22cd012ccc889"
@@ -2215,6 +2222,16 @@
2215
2222
  protobufjs "^7.2.5"
2216
2223
  yargs "^17.7.2"
2217
2224
 
2225
+ "@grpc/proto-loader@^0.8.0":
2226
+ version "0.8.0"
2227
+ resolved "https://registry.yarnpkg.com/@grpc/proto-loader/-/proto-loader-0.8.0.tgz#b6c324dd909c458a0e4aa9bfd3d69cf78a4b9bd8"
2228
+ integrity sha512-rc1hOQtjIWGxcxpb9aHAfLpIctjEnsDehj0DAiVfBlmT84uvR0uUtN2hEi/ecvWVjXUGf5qPF4qEgiLOx1YIMQ==
2229
+ dependencies:
2230
+ lodash.camelcase "^4.3.0"
2231
+ long "^5.0.0"
2232
+ protobufjs "^7.5.3"
2233
+ yargs "^17.7.2"
2234
+
2218
2235
  "@humanfs/core@^0.19.1":
2219
2236
  version "0.19.1"
2220
2237
  resolved "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz#17c55ca7d426733fe3c561906b8173c336b40a77"
@@ -5771,6 +5788,19 @@ google-auth-library@^10.0.0-rc.1:
5771
5788
  gtoken "^8.0.0-rc.1"
5772
5789
  jws "^4.0.0"
5773
5790
 
5791
+ google-auth-library@^10.1.0:
5792
+ version "10.4.0"
5793
+ resolved "https://registry.yarnpkg.com/google-auth-library/-/google-auth-library-10.4.0.tgz#2d5e36f3e0b0f33b1c5466a2f25617ff2c258c91"
5794
+ integrity sha512-CmIrSy1bqMQUsPmA9+hcSbAXL80cFhu40cGMUjCaLpNKVzzvi+0uAHq8GNZxkoGYIsTX4ZQ7e4aInAqWxgn4fg==
5795
+ dependencies:
5796
+ base64-js "^1.3.0"
5797
+ ecdsa-sig-formatter "^1.0.11"
5798
+ gaxios "^7.0.0"
5799
+ gcp-metadata "^7.0.0"
5800
+ google-logging-utils "^1.0.0"
5801
+ gtoken "^8.0.0"
5802
+ jws "^4.0.0"
5803
+
5774
5804
  google-auth-library@^10.3.0:
5775
5805
  version "10.3.0"
5776
5806
  resolved "https://registry.yarnpkg.com/google-auth-library/-/google-auth-library-10.3.0.tgz#d44d005d546bf6b8956529caf0f9e70a07960c04"
@@ -5814,6 +5844,22 @@ google-gax@^4.3.3:
5814
5844
  retry-request "^7.0.0"
5815
5845
  uuid "^9.0.1"
5816
5846
 
5847
+ google-gax@^5.0.0:
5848
+ version "5.0.4"
5849
+ resolved "https://registry.yarnpkg.com/google-gax/-/google-gax-5.0.4.tgz#0c93a60879f2332c545f4c5c1b6a2a0fbeb983b5"
5850
+ integrity sha512-HmQ6zIYBs2EikTk+kjeHmtHprNTEpsnVaKONw9cwZZwUNCkUb+D5RYrJpCxyjdvIDvJp3wLbVReolJLRZRms1g==
5851
+ dependencies:
5852
+ "@grpc/grpc-js" "^1.12.6"
5853
+ "@grpc/proto-loader" "^0.8.0"
5854
+ duplexify "^4.1.3"
5855
+ google-auth-library "^10.1.0"
5856
+ google-logging-utils "^1.1.1"
5857
+ node-fetch "^3.3.2"
5858
+ object-hash "^3.0.0"
5859
+ proto3-json-serializer "^3.0.0"
5860
+ protobufjs "^7.5.3"
5861
+ retry-request "^8.0.0"
5862
+
5817
5863
  google-gax@^5.0.1-rc.0:
5818
5864
  version "5.0.1-rc.1"
5819
5865
  resolved "https://registry.npmjs.org/google-gax/-/google-gax-5.0.1-rc.1.tgz#6c40a791b962c82b3b40fc10e2d6a40c3cb3a2dd"
@@ -7148,6 +7194,24 @@ protobufjs@^7.2.5, protobufjs@^7.2.6, protobufjs@^7.3.0, protobufjs@^7.3.2, prot
7148
7194
  "@types/node" ">=13.7.0"
7149
7195
  long "^5.0.0"
7150
7196
 
7197
+ protobufjs@^7.5.3:
7198
+ version "7.5.4"
7199
+ resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.5.4.tgz#885d31fe9c4b37f25d1bb600da30b1c5b37d286a"
7200
+ integrity sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg==
7201
+ dependencies:
7202
+ "@protobufjs/aspromise" "^1.1.2"
7203
+ "@protobufjs/base64" "^1.1.2"
7204
+ "@protobufjs/codegen" "^2.0.4"
7205
+ "@protobufjs/eventemitter" "^1.1.0"
7206
+ "@protobufjs/fetch" "^1.1.0"
7207
+ "@protobufjs/float" "^1.0.2"
7208
+ "@protobufjs/inquire" "^1.1.0"
7209
+ "@protobufjs/path" "^1.1.2"
7210
+ "@protobufjs/pool" "^1.1.0"
7211
+ "@protobufjs/utf8" "^1.1.0"
7212
+ "@types/node" ">=13.7.0"
7213
+ long "^5.0.0"
7214
+
7151
7215
  proxy-from-env@^1.1.0:
7152
7216
  version "1.1.0"
7153
7217
  resolved "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"