@8ms/helpers 2.3.38 → 2.3.40

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.
@@ -3,7 +3,7 @@ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
3
  import * as _aws_sdk_client_cloudwatch_logs0 from "@aws-sdk/client-cloudwatch-logs";
4
4
  import { CloudWatchLogsClient } from "@aws-sdk/client-cloudwatch-logs";
5
5
 
6
- //#region src/aws/cloudWatch/server/logEvent.d.ts
6
+ //#region src/aws/cloudWatchLog/server/logEvent.d.ts
7
7
  declare const logLevel: {
8
8
  readonly INFO: "info";
9
9
  readonly WARN: "warn";
@@ -19,8 +19,8 @@ type LogEvent = {
19
19
  data: object;
20
20
  };
21
21
  //#endregion
22
- //#region src/aws/cloudWatch/server/AwsCloudWatchNamespace.d.ts
23
- declare class AwsCloudWatchNamespace extends BaseNamespace {
22
+ //#region src/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.d.ts
23
+ declare class AwsCloudWatchLogNamespace extends BaseNamespace {
24
24
  client: CloudWatchLogsClient;
25
25
  config: AwsConfig;
26
26
  ensureInit: () => Promise<void>;
@@ -29,15 +29,23 @@ declare class AwsCloudWatchNamespace extends BaseNamespace {
29
29
  * This should typically be the name of the application + environment
30
30
  */
31
31
  createLogGroup: (logGroupName: string) => Promise<_aws_sdk_client_cloudwatch_logs0.CreateLogGroupCommandOutput>;
32
+ /**
33
+ * Checks whether a CloudWatch Log Group exists.
34
+ */
35
+ logGroupExists: (logGroupName: string) => Promise<boolean>;
32
36
  /**
33
37
  * Creates a stream within a CloudWatch Log Group.
34
38
  */
35
39
  createStream: (logGroupName: string, logStreamName: string) => Promise<_aws_sdk_client_cloudwatch_logs0.CreateLogStreamCommandOutput>;
40
+ /**
41
+ * Checks whether a CloudWatch Log Stream exists within a given Log Group.
42
+ */
43
+ logStreamExists: (logGroupName: string, logStreamName: string) => Promise<boolean>;
36
44
  createEvent: (logGroupName: string, logStreamName: string, logEvent: LogEvent) => Promise<_aws_sdk_client_cloudwatch_logs0.PutLogEventsCommandOutput>;
37
45
  createEvents: (logGroupName: string, logStreamName: string, logEvents: LogEvent[]) => Promise<_aws_sdk_client_cloudwatch_logs0.PutLogEventsCommandOutput>;
38
46
  }
39
47
  //#endregion
40
- //#region src/aws/cloudWatch/server/awsCloudWatch.d.ts
41
- declare const awsCloudWatchClient: (key?: string, config?: AwsConfig, vaultId?: string, itemId?: string) => Promise<AwsCloudWatchNamespace>;
48
+ //#region src/aws/cloudWatchLog/server/awsCloudWatchLog.d.ts
49
+ declare const awsCloudWatchLogClient: (key?: string, config?: AwsConfig, vaultId?: string, itemId?: string) => Promise<AwsCloudWatchLogNamespace>;
42
50
  //#endregion
43
- export { AwsCloudWatchNamespace, LogEvent, LogLevel, awsCloudWatchClient, logLevel };
51
+ export { AwsCloudWatchLogNamespace, LogEvent, LogLevel, awsCloudWatchLogClient, logLevel };
@@ -1,8 +1,8 @@
1
1
  import { BaseNamespace } from "../../../_class/index.mjs";
2
2
  import { t as getConfig } from "../../../server-Bwy4JI8Z.mjs";
3
3
 
4
- //#region src/aws/cloudWatch/server/AwsCloudWatchNamespace.ts
5
- var AwsCloudWatchNamespace = class extends BaseNamespace {
4
+ //#region src/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.ts
5
+ var AwsCloudWatchLogNamespace = class extends BaseNamespace {
6
6
  ensureInit = async () => {
7
7
  if (!this.client) try {
8
8
  const { CloudWatchLogsClient } = await import("@aws-sdk/client-cloudwatch-logs");
@@ -21,6 +21,19 @@ var AwsCloudWatchNamespace = class extends BaseNamespace {
21
21
  return await this.client.send(new CreateLogGroupCommand({ logGroupName }));
22
22
  };
23
23
  /**
24
+ * Checks whether a CloudWatch Log Group exists.
25
+ */
26
+ logGroupExists = async (logGroupName) => {
27
+ await this.ensureInit();
28
+ const { DescribeLogGroupsCommand } = await import("@aws-sdk/client-cloudwatch-logs");
29
+ const response = await this.client.send(new DescribeLogGroupsCommand({
30
+ logGroupNamePrefix: logGroupName,
31
+ limit: 1
32
+ }));
33
+ if (!response?.logGroups || 0 === response.logGroups.length) return false;
34
+ return true;
35
+ };
36
+ /**
24
37
  * Creates a stream within a CloudWatch Log Group.
25
38
  */
26
39
  createStream = async (logGroupName, logStreamName) => {
@@ -31,6 +44,20 @@ var AwsCloudWatchNamespace = class extends BaseNamespace {
31
44
  logStreamName
32
45
  }));
33
46
  };
47
+ /**
48
+ * Checks whether a CloudWatch Log Stream exists within a given Log Group.
49
+ */
50
+ logStreamExists = async (logGroupName, logStreamName) => {
51
+ await this.ensureInit();
52
+ const { DescribeLogStreamsCommand } = await import("@aws-sdk/client-cloudwatch-logs");
53
+ const response = await this.client.send(new DescribeLogStreamsCommand({
54
+ logGroupName,
55
+ logStreamNamePrefix: logStreamName,
56
+ limit: 1
57
+ }));
58
+ if (!response?.logStreams || 0 === response.logStreams.length) return false;
59
+ return true;
60
+ };
34
61
  createEvent = async (logGroupName, logStreamName, logEvent) => {
35
62
  return await this.createEvents(logGroupName, logStreamName, [logEvent]);
36
63
  };
@@ -49,17 +76,17 @@ var AwsCloudWatchNamespace = class extends BaseNamespace {
49
76
  };
50
77
 
51
78
  //#endregion
52
- //#region src/aws/cloudWatch/server/awsCloudWatch.ts
53
- const awsCloudWatchNamespaces = /* @__PURE__ */ new Map();
54
- const awsCloudWatchClient = async (key = "default", config, vaultId, itemId) => {
55
- if (awsCloudWatchNamespaces.has(key)) return awsCloudWatchNamespaces.get(key);
56
- const namespace = new AwsCloudWatchNamespace(key, await getConfig(key, config, vaultId, itemId));
57
- awsCloudWatchNamespaces.set(key, namespace);
79
+ //#region src/aws/cloudWatchLog/server/awsCloudWatchLog.ts
80
+ const awsCloudWatchLogNamespaces = /* @__PURE__ */ new Map();
81
+ const awsCloudWatchLogClient = async (key = "default", config, vaultId, itemId) => {
82
+ if (awsCloudWatchLogNamespaces.has(key)) return awsCloudWatchLogNamespaces.get(key);
83
+ const namespace = new AwsCloudWatchLogNamespace(key, await getConfig(key, config, vaultId, itemId));
84
+ awsCloudWatchLogNamespaces.set(key, namespace);
58
85
  return namespace;
59
86
  };
60
87
 
61
88
  //#endregion
62
- //#region src/aws/cloudWatch/server/logEvent.ts
89
+ //#region src/aws/cloudWatchLog/server/logEvent.ts
63
90
  const logLevel = {
64
91
  INFO: "info",
65
92
  WARN: "warn",
@@ -67,4 +94,4 @@ const logLevel = {
67
94
  };
68
95
 
69
96
  //#endregion
70
- export { AwsCloudWatchNamespace, awsCloudWatchClient, logLevel };
97
+ export { AwsCloudWatchLogNamespace, awsCloudWatchLogClient, logLevel };
@@ -0,0 +1,35 @@
1
+ import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
+ import { X as InputDate } from "../../../index-1fBbJGQz.mjs";
3
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
4
+ import * as _aws_sdk_client_cloudwatch0 from "@aws-sdk/client-cloudwatch";
5
+ import { CloudWatchClient, StandardUnit } from "@aws-sdk/client-cloudwatch";
6
+
7
+ //#region src/aws/cloudWatchMetric/server/logMetric.d.ts
8
+ type LogMetric = {
9
+ metricName: string;
10
+ value: number;
11
+ unit?: StandardUnit;
12
+ timestamp?: InputDate;
13
+ dimensions?: {
14
+ name: string;
15
+ value: string;
16
+ }[];
17
+ };
18
+ //#endregion
19
+ //#region src/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.d.ts
20
+ declare class AwsCloudWatchMetricNamespace extends BaseNamespace {
21
+ client: CloudWatchClient;
22
+ config: AwsConfig;
23
+ ensureInit: () => Promise<void>;
24
+ /**
25
+ * Publishes metric data to CloudWatch.
26
+ * The namespace is created automatically.
27
+ * Dimensions should contain additional info (but top level).
28
+ */
29
+ putMetricData: (namespace: string, metricData: LogMetric | LogMetric[]) => Promise<_aws_sdk_client_cloudwatch0.PutMetricDataCommandOutput>;
30
+ }
31
+ //#endregion
32
+ //#region src/aws/cloudWatchMetric/server/awsCloudWatchMetric.d.ts
33
+ declare const awsCloudWatchMetricClient: (key?: string, config?: AwsConfig, vaultId?: string, itemId?: string) => Promise<AwsCloudWatchMetricNamespace>;
34
+ //#endregion
35
+ export { AwsCloudWatchMetricNamespace, LogMetric, awsCloudWatchMetricClient };
@@ -0,0 +1,52 @@
1
+ import { getArray } from "../../../array/index.mjs";
2
+ import { BaseNamespace } from "../../../_class/index.mjs";
3
+ import { getLuxonDate } from "../../../date/index.mjs";
4
+ import { t as getConfig } from "../../../server-Bwy4JI8Z.mjs";
5
+
6
+ //#region src/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.ts
7
+ var AwsCloudWatchMetricNamespace = class extends BaseNamespace {
8
+ ensureInit = async () => {
9
+ if (!this.client) try {
10
+ const { CloudWatchClient } = await import("@aws-sdk/client-cloudwatch");
11
+ this.client = new CloudWatchClient(this.config);
12
+ } catch (e) {
13
+ throw new Error("AWS CloudWatch Client not installed");
14
+ }
15
+ };
16
+ /**
17
+ * Publishes metric data to CloudWatch.
18
+ * The namespace is created automatically.
19
+ * Dimensions should contain additional info (but top level).
20
+ */
21
+ putMetricData = async (namespace, metricData) => {
22
+ await this.ensureInit();
23
+ const { PutMetricDataCommand } = await import("@aws-sdk/client-cloudwatch");
24
+ const data = getArray(metricData);
25
+ return await this.client.send(new PutMetricDataCommand({
26
+ Namespace: namespace,
27
+ MetricData: data.map((metric) => ({
28
+ MetricName: metric.metricName,
29
+ Value: metric.value,
30
+ Unit: metric.unit,
31
+ Timestamp: getLuxonDate(metric.timestamp).toJSDate(),
32
+ Dimensions: metric.dimensions?.map((dimension) => ({
33
+ Name: dimension.name,
34
+ Value: dimension.value
35
+ }))
36
+ }))
37
+ }));
38
+ };
39
+ };
40
+
41
+ //#endregion
42
+ //#region src/aws/cloudWatchMetric/server/awsCloudWatchMetric.ts
43
+ const awsCloudWatchMetricNamespaces = /* @__PURE__ */ new Map();
44
+ const awsCloudWatchMetricClient = async (key = "default", config, vaultId, itemId) => {
45
+ if (awsCloudWatchMetricNamespaces.has(key)) return awsCloudWatchMetricNamespaces.get(key);
46
+ const namespace = new AwsCloudWatchMetricNamespace(key, await getConfig(key, config, vaultId, itemId));
47
+ awsCloudWatchMetricNamespaces.set(key, namespace);
48
+ return namespace;
49
+ };
50
+
51
+ //#endregion
52
+ export { AwsCloudWatchMetricNamespace, awsCloudWatchMetricClient };
@@ -1,5 +1,5 @@
1
- import { u as ApiResponseClass } from "../../../api-DGKJDAfb.mjs";
2
1
  import { BaseNamespace } from "../../../_class/index.mjs";
2
+ import { u as ApiResponseClass } from "../../../api-DGKJDAfb.mjs";
3
3
  import { n as isResponse200, t as getConfig } from "../../../server-Bwy4JI8Z.mjs";
4
4
 
5
5
  //#region src/aws/lambda/server/AwsLambdaNamespace.ts
@@ -1,5 +1,5 @@
1
1
  import { f as ApiResponseClass } from "../../../index-DW9yJLtI.mjs";
2
- import { t as Auth } from "../../../index-Cpfm8vFH.mjs";
2
+ import { t as Auth } from "../../../index-DInsoSQm.mjs";
3
3
 
4
4
  //#region src/brightData/serpApi/server/brightDataSerpApi.d.ts
5
5
  declare const brightDataSerpApiType: {
@@ -1,2 +1,2 @@
1
- import { n as getCustomerId, r as getZone, t as Auth } from "../../index-Cpfm8vFH.mjs";
1
+ import { n as getCustomerId, r as getZone, t as Auth } from "../../index-DInsoSQm.mjs";
2
2
  export { Auth, getCustomerId, getZone };
@@ -1,4 +1,4 @@
1
- import { t as Auth } from "../../../index-Cpfm8vFH.mjs";
1
+ import { t as Auth } from "../../../index-DInsoSQm.mjs";
2
2
 
3
3
  //#region src/brightData/webScraperIde/server/getBatch.d.ts
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as GoogleCloudConfig } from "../../../index-BqrbHL2-.mjs";
2
+ import { t as GoogleCloudConfig } from "../../../index-DDH4qfj3.mjs";
3
3
  import { BigQuery, DatasetResource, QueryOptions } from "@google-cloud/bigquery";
4
4
  import { GoogleAuthOptions } from "@google-cloud/common";
5
5
 
@@ -1,2 +1,2 @@
1
- import { n as getConfig, t as GoogleCloudConfig } from "../../index-BqrbHL2-.mjs";
1
+ import { n as getConfig, t as GoogleCloudConfig } from "../../index-DDH4qfj3.mjs";
2
2
  export { GoogleCloudConfig, getConfig };
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as GoogleCloudConfig } from "../../../index-BqrbHL2-.mjs";
2
+ import { t as GoogleCloudConfig } from "../../../index-DDH4qfj3.mjs";
3
3
  import * as _googleapis_sheets0 from "@googleapis/sheets";
4
4
  import { GoogleAuth } from "googleapis-common";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as GoogleCloudConfig } from "../../../index-BqrbHL2-.mjs";
2
+ import { t as GoogleCloudConfig } from "../../../index-DDH4qfj3.mjs";
3
3
  import * as _google_cloud_storage0 from "@google-cloud/storage";
4
4
  import { Storage } from "@google-cloud/storage";
5
5
  import { GoogleAuthOptions } from "@google-cloud/common";
@@ -1,5 +1,5 @@
1
- import "../../api-DGKJDAfb.mjs";
2
1
  import { BaseNamespace } from "../../_class/index.mjs";
2
+ import "../../api-DGKJDAfb.mjs";
3
3
  import { get } from "../../axios/index.mjs";
4
4
  import { onePasswordClient } from "../../onePassword/server/index.mjs";
5
5
 
@@ -1,5 +1,5 @@
1
- import "../../api-DGKJDAfb.mjs";
2
1
  import { BaseNamespace } from "../../_class/index.mjs";
2
+ import "../../api-DGKJDAfb.mjs";
3
3
  import { get } from "../../axios/index.mjs";
4
4
  import { onePasswordClient } from "../../onePassword/server/index.mjs";
5
5
 
@@ -1,5 +1,5 @@
1
- import "../../api-DGKJDAfb.mjs";
2
1
  import { BaseNamespace } from "../../_class/index.mjs";
2
+ import "../../api-DGKJDAfb.mjs";
3
3
  import { post } from "../../axios/index.mjs";
4
4
  import { onePasswordClient } from "../../onePassword/server/index.mjs";
5
5
 
@@ -1,5 +1,5 @@
1
- import "../../api-DGKJDAfb.mjs";
2
1
  import { BaseNamespace } from "../../_class/index.mjs";
2
+ import "../../api-DGKJDAfb.mjs";
3
3
  import { post } from "../../axios/index.mjs";
4
4
  import { onePasswordClient } from "../../onePassword/server/index.mjs";
5
5
  import { DateTime } from "luxon";
@@ -1,5 +1,5 @@
1
- import "../../api-DGKJDAfb.mjs";
2
1
  import { BaseNamespace } from "../../_class/index.mjs";
2
+ import "../../api-DGKJDAfb.mjs";
3
3
  import { post } from "../../axios/index.mjs";
4
4
  import { onePasswordClient } from "../../onePassword/server/index.mjs";
5
5
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.3.38",
4
+ "version": "2.3.40",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@1password/sdk": "<1.0.0",
25
+ "@aws-sdk/client-cloudwatch": "^3.0.0",
25
26
  "@aws-sdk/client-cloudwatch-logs": "^3.0.0",
26
27
  "@aws-sdk/client-ec2": "^3.0.0",
27
28
  "@aws-sdk/client-ecs": "^3.0.0",
@@ -57,6 +58,9 @@
57
58
  "@1password/sdk": {
58
59
  "optional": true
59
60
  },
61
+ "@aws-sdk/client-cloudwatch": {
62
+ "optional": true
63
+ },
60
64
  "@aws-sdk/client-cloudwatch-logs": {
61
65
  "optional": true
62
66
  },
@@ -147,6 +151,7 @@
147
151
  },
148
152
  "devDependencies": {
149
153
  "@1password/sdk": "^0.4.0",
154
+ "@aws-sdk/client-cloudwatch": "^3.992.0",
150
155
  "@aws-sdk/client-cloudwatch-logs": "^3.992.0",
151
156
  "@aws-sdk/client-ec2": "^3.992.0",
152
157
  "@aws-sdk/client-ecs": "^3.992.0",
@@ -203,7 +208,8 @@
203
208
  "./api": "./dist/api/index.mjs",
204
209
  "./array": "./dist/array/index.mjs",
205
210
  "./atInternet": "./dist/atInternet/index.mjs",
206
- "./aws/cloudWatch/server": "./dist/aws/cloudWatch/server/index.mjs",
211
+ "./aws/cloudWatchLog/server": "./dist/aws/cloudWatchLog/server/index.mjs",
212
+ "./aws/cloudWatchMetric/server": "./dist/aws/cloudWatchMetric/server/index.mjs",
207
213
  "./aws/ec2/server": "./dist/aws/ec2/server/index.mjs",
208
214
  "./aws/ecs/server": "./dist/aws/ecs/server/index.mjs",
209
215
  "./aws/glue/server": "./dist/aws/glue/server/index.mjs",