mblabs-roccato-backend-commons 1.0.62 → 1.0.64

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.
@@ -36,7 +36,8 @@ export declare namespace AmazonCloudwatch {
36
36
  value: string;
37
37
  }[];
38
38
  value: number;
39
- unit: 'Time' | 'Count' | 'Percent' | 'Bytes' | 'None';
39
+ unit: 'time' | 'count' | 'percent' | 'bytes' | 'none';
40
+ timestamp?: Date;
40
41
  };
41
42
  };
42
43
  credentials: Credentials;
@@ -59,11 +59,11 @@ export declare namespace GoogleMonitor {
59
59
  metric: {
60
60
  title: string;
61
61
  value: number;
62
- typeof: 'Boolean' | 'String' | 'Int' | 'Double' | 'Decimal';
63
- measure: 'Gauge' | 'Delta' | 'Cumulative';
64
- labels: {
62
+ typeof: 'boolean' | 'string' | 'int' | 'double' | 'decimal';
63
+ measure: 'gauge' | 'delta' | 'cumulative';
64
+ labels?: {
65
65
  key: string;
66
- typeof: 'Boolean' | 'String' | 'Int';
66
+ typeof: 'boolean' | 'string' | 'int';
67
67
  description: string;
68
68
  }[];
69
69
  };
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const client_cloudwatch_1 = require("@aws-sdk/client-cloudwatch");
4
7
  const client_cloudwatch_logs_1 = require("@aws-sdk/client-cloudwatch-logs");
8
+ const date_1 = __importDefault(require("../date"));
5
9
  class AmazonCloudwatchService {
6
10
  async createMetric({ credentials, data }) {
7
11
  const client = new client_cloudwatch_1.CloudWatch({
@@ -12,26 +16,25 @@ class AmazonCloudwatchService {
12
16
  region: credentials.region,
13
17
  });
14
18
  const UnitMap = {
15
- Time: 'Milliseconds',
16
- Count: 'Count',
17
- Percent: 'Percent',
18
- Bytes: 'Bytes',
19
- None: 'None',
19
+ time: 'Milliseconds',
20
+ count: 'Count',
21
+ percent: 'Percent',
22
+ bytes: 'Bytes',
23
+ none: 'None',
20
24
  };
21
- await client.putMetricData({
25
+ const payload = {
22
26
  Namespace: data.namespace,
23
27
  MetricData: [
24
28
  {
25
29
  MetricName: data.metric.title,
26
- Dimensions: data.metric.dimensions.map(dimension => ({
27
- Name: dimension.name,
28
- Value: dimension.value,
29
- })),
30
+ Dimensions: data.metric.dimensions?.map(dimension => ({ Name: dimension.name, Value: dimension.value })) ?? [],
30
31
  Value: data.metric.value,
31
32
  Unit: UnitMap[data.metric.unit] || 'None',
33
+ Timestamp: data.metric.timestamp ?? date_1.default.getCurrentDate(),
32
34
  },
33
35
  ],
34
- });
36
+ };
37
+ await client.send(new client_cloudwatch_1.PutMetricDataCommand(payload));
35
38
  }
36
39
  async createLogEvent({ credentials, data }) {
37
40
  const client = new client_cloudwatch_logs_1.CloudWatchLogs({
@@ -8,21 +8,21 @@ class GoogleMonitorService {
8
8
  projectId: credentials.project,
9
9
  });
10
10
  const MetricKindMap = {
11
- Gauge: 'GAUGE',
12
- Delta: 'DELTA',
13
- Cumulative: 'CUMULATIVE',
11
+ gauge: 'GAUGE',
12
+ delta: 'DELTA',
13
+ cumulative: 'CUMULATIVE',
14
14
  };
15
15
  const ValueTypeMap = {
16
- Boolean: 'BOOL',
17
- String: 'STRING',
18
- Int: 'INT64',
19
- Double: 'DOUBLE',
20
- Decimal: 'MONEY',
16
+ boolean: 'BOOL',
17
+ string: 'STRING',
18
+ int: 'INT64',
19
+ double: 'DOUBLE',
20
+ decimal: 'MONEY',
21
21
  };
22
22
  const LabelValueTypeMap = {
23
- Boolean: 'BOOL',
24
- String: 'STRING',
25
- Int: 'INT64',
23
+ boolean: 'BOOL',
24
+ string: 'STRING',
25
+ int: 'INT64',
26
26
  };
27
27
  await client.createMetricDescriptor({
28
28
  name: client.projectPath(credentials.project),
@@ -32,11 +32,11 @@ class GoogleMonitorService {
32
32
  metricKind: MetricKindMap[data.metric.measure] || 'METRIC_KIND_UNSPECIFIED',
33
33
  valueType: ValueTypeMap[data.metric.typeof] || 'VALUE_TYPE_UNSPECIFIED',
34
34
  unit: data.metric.value.toString(),
35
- labels: data.metric.labels.map((label) => ({
35
+ labels: data.metric.labels?.map((label) => ({
36
36
  key: label.key,
37
37
  valueType: LabelValueTypeMap[label.typeof],
38
38
  description: label.description,
39
- })),
39
+ })) ?? [],
40
40
  },
41
41
  });
42
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mblabs-roccato-backend-commons",
3
- "version": "1.0.62",
3
+ "version": "1.0.64",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -40,7 +40,8 @@ export namespace AmazonCloudwatch {
40
40
  value: string
41
41
  }[];
42
42
  value: number;
43
- unit: 'Time' | 'Count' | 'Percent' | 'Bytes' | 'None';
43
+ unit: 'time' | 'count' | 'percent' | 'bytes' | 'none';
44
+ timestamp?: Date;
44
45
  };
45
46
  };
46
47
  credentials: Credentials;
@@ -65,11 +65,11 @@ export namespace GoogleMonitor {
65
65
  metric: {
66
66
  title: string;
67
67
  value: number;
68
- typeof: 'Boolean' | 'String' | 'Int' | 'Double' | 'Decimal',
69
- measure: 'Gauge' | 'Delta' | 'Cumulative',
70
- labels: {
68
+ typeof: 'boolean' | 'string' | 'int' | 'double' | 'decimal',
69
+ measure: 'gauge' | 'delta' | 'cumulative',
70
+ labels?: {
71
71
  key: string;
72
- typeof: 'Boolean' | 'String' | 'Int';
72
+ typeof: 'boolean' | 'string' | 'int';
73
73
  description: string;
74
74
  }[];
75
75
  };
@@ -1,7 +1,8 @@
1
- import { CloudWatch } from '@aws-sdk/client-cloudwatch';
1
+ import { CloudWatch, PutMetricDataCommand } from '@aws-sdk/client-cloudwatch';
2
2
  import { CloudWatchLogs, StandardUnit } from '@aws-sdk/client-cloudwatch-logs';
3
3
 
4
4
  import { AmazonCloudwatch, IAmazonCloudwatchService } from '../../interfaces';
5
+ import DateService from '../date';
5
6
 
6
7
  class AmazonCloudwatchService implements IAmazonCloudwatchService {
7
8
  async createMetric ({ credentials, data }: AmazonCloudwatch.CreateMetric.Request): Promise<void> {
@@ -13,28 +14,30 @@ class AmazonCloudwatchService implements IAmazonCloudwatchService {
13
14
  region: credentials.region,
14
15
  });
15
16
 
16
- const UnitMap: Record<'Time' | 'Count' | 'Percent' | 'Bytes' | 'None', StandardUnit> = {
17
- Time: 'Milliseconds',
18
- Count: 'Count',
19
- Percent: 'Percent',
20
- Bytes: 'Bytes',
21
- None: 'None',
17
+ const UnitMap: Record<'time' | 'count' | 'percent' | 'bytes' | 'none', StandardUnit> = {
18
+ time: 'Milliseconds',
19
+ count: 'Count',
20
+ percent: 'Percent',
21
+ bytes: 'Bytes',
22
+ none: 'None',
22
23
  };
23
24
 
24
- await client.putMetricData({
25
+ const payload = {
25
26
  Namespace: data.namespace,
26
27
  MetricData: [
27
28
  {
28
29
  MetricName: data.metric.title,
29
- Dimensions: data.metric.dimensions.map(dimension => ({
30
- Name: dimension.name,
31
- Value: dimension.value,
32
- })),
30
+ Dimensions: data.metric.dimensions?.map(
31
+ dimension => ({ Name: dimension.name, Value: dimension.value })
32
+ ) ?? [],
33
33
  Value: data.metric.value,
34
34
  Unit: UnitMap[data.metric.unit] || 'None',
35
+ Timestamp: data.metric.timestamp ?? DateService.getCurrentDate(),
35
36
  },
36
37
  ],
37
- });
38
+ };
39
+
40
+ await client.send(new PutMetricDataCommand(payload));
38
41
  }
39
42
 
40
43
  public async createLogEvent ({ credentials, data }: AmazonCloudwatch.CreateLogEvent.Request): Promise<void> {
@@ -12,27 +12,27 @@ class GoogleMonitorService implements IGoogleMonitorService {
12
12
  projectId: credentials.project,
13
13
  });
14
14
 
15
- const MetricKindMap: Record<'Gauge' | 'Delta' | 'Cumulative', 'GAUGE' | 'DELTA' | 'CUMULATIVE'> = {
16
- Gauge: 'GAUGE',
17
- Delta: 'DELTA',
18
- Cumulative: 'CUMULATIVE',
15
+ const MetricKindMap: Record<'gauge' | 'delta' | 'cumulative', 'GAUGE' | 'DELTA' | 'CUMULATIVE'> = {
16
+ gauge: 'GAUGE',
17
+ delta: 'DELTA',
18
+ cumulative: 'CUMULATIVE',
19
19
  };
20
20
 
21
21
  const ValueTypeMap: Record<
22
- 'Boolean' | 'String' | 'Int' | 'Double' | 'Decimal',
22
+ 'boolean' | 'string' | 'int' | 'double' | 'decimal',
23
23
  'BOOL' | 'INT64' | 'DOUBLE' | 'STRING' | 'DISTRIBUTION' | 'MONEY'
24
24
  > = {
25
- Boolean: 'BOOL',
26
- String: 'STRING',
27
- Int: 'INT64',
28
- Double: 'DOUBLE',
29
- Decimal: 'MONEY',
25
+ boolean: 'BOOL',
26
+ string: 'STRING',
27
+ int: 'INT64',
28
+ double: 'DOUBLE',
29
+ decimal: 'MONEY',
30
30
  };
31
31
 
32
- const LabelValueTypeMap: Record<'Boolean' | 'String' | 'Int', 'BOOL' | 'INT64' | 'STRING'> = {
33
- Boolean: 'BOOL',
34
- String: 'STRING',
35
- Int: 'INT64',
32
+ const LabelValueTypeMap: Record<'boolean' | 'string' | 'int', 'BOOL' | 'INT64' | 'STRING'> = {
33
+ boolean: 'BOOL',
34
+ string: 'STRING',
35
+ int: 'INT64',
36
36
  };
37
37
 
38
38
  await client.createMetricDescriptor({
@@ -43,11 +43,13 @@ class GoogleMonitorService implements IGoogleMonitorService {
43
43
  metricKind: MetricKindMap[data.metric.measure] || 'METRIC_KIND_UNSPECIFIED',
44
44
  valueType: ValueTypeMap[data.metric.typeof] || 'VALUE_TYPE_UNSPECIFIED',
45
45
  unit: data.metric.value.toString(),
46
- labels: data.metric.labels.map((label) => ({
47
- key: label.key,
48
- valueType: LabelValueTypeMap[label.typeof],
49
- description: label.description,
50
- })),
46
+ labels: data.metric.labels?.map(
47
+ (label) => ({
48
+ key: label.key,
49
+ valueType: LabelValueTypeMap[label.typeof],
50
+ description: label.description,
51
+ })
52
+ ) ?? [],
51
53
  },
52
54
  });
53
55
  }