@8ms/helpers 2.3.37 → 2.3.39

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 +1,51 @@
1
- export { };
1
+ import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
+ import * as _aws_sdk_client_cloudwatch_logs0 from "@aws-sdk/client-cloudwatch-logs";
4
+ import { CloudWatchLogsClient } from "@aws-sdk/client-cloudwatch-logs";
5
+
6
+ //#region src/aws/cloudWatch/server/logEvent.d.ts
7
+ declare const logLevel: {
8
+ readonly INFO: "info";
9
+ readonly WARN: "warn";
10
+ readonly ERROR: "error";
11
+ };
12
+ type LogLevel = typeof logLevel[keyof typeof logLevel];
13
+ type LogEvent = {
14
+ unixTimestamp: number;
15
+ level: LogLevel;
16
+ app: string;
17
+ environment: string;
18
+ stream: string;
19
+ data: object;
20
+ };
21
+ //#endregion
22
+ //#region src/aws/cloudWatch/server/AwsCloudWatchNamespace.d.ts
23
+ declare class AwsCloudWatchNamespace extends BaseNamespace {
24
+ client: CloudWatchLogsClient;
25
+ config: AwsConfig;
26
+ ensureInit: () => Promise<void>;
27
+ /**
28
+ * Create a CloudWatch Log Group.
29
+ * This should typically be the name of the application + environment
30
+ */
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>;
36
+ /**
37
+ * Creates a stream within a CloudWatch Log Group.
38
+ */
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>;
44
+ createEvent: (logGroupName: string, logStreamName: string, logEvent: LogEvent) => Promise<_aws_sdk_client_cloudwatch_logs0.PutLogEventsCommandOutput>;
45
+ createEvents: (logGroupName: string, logStreamName: string, logEvents: LogEvent[]) => Promise<_aws_sdk_client_cloudwatch_logs0.PutLogEventsCommandOutput>;
46
+ }
47
+ //#endregion
48
+ //#region src/aws/cloudWatch/server/awsCloudWatch.d.ts
49
+ declare const awsCloudWatchClient: (key?: string, config?: AwsConfig, vaultId?: string, itemId?: string) => Promise<AwsCloudWatchNamespace>;
50
+ //#endregion
51
+ export { AwsCloudWatchNamespace, LogEvent, LogLevel, awsCloudWatchClient, logLevel };
@@ -1 +1,97 @@
1
- export { };
1
+ import { BaseNamespace } from "../../../_class/index.mjs";
2
+ import { t as getConfig } from "../../../server-Bwy4JI8Z.mjs";
3
+
4
+ //#region src/aws/cloudWatch/server/AwsCloudWatchNamespace.ts
5
+ var AwsCloudWatchNamespace = class extends BaseNamespace {
6
+ ensureInit = async () => {
7
+ if (!this.client) try {
8
+ const { CloudWatchLogsClient } = await import("@aws-sdk/client-cloudwatch-logs");
9
+ this.client = new CloudWatchLogsClient(this.config);
10
+ } catch (e) {
11
+ throw new Error("AWS CloudWatch Logs Client not installed");
12
+ }
13
+ };
14
+ /**
15
+ * Create a CloudWatch Log Group.
16
+ * This should typically be the name of the application + environment
17
+ */
18
+ createLogGroup = async (logGroupName) => {
19
+ await this.ensureInit();
20
+ const { CreateLogGroupCommand } = await import("@aws-sdk/client-cloudwatch-logs");
21
+ return await this.client.send(new CreateLogGroupCommand({ logGroupName }));
22
+ };
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
+ /**
37
+ * Creates a stream within a CloudWatch Log Group.
38
+ */
39
+ createStream = async (logGroupName, logStreamName) => {
40
+ await this.ensureInit();
41
+ const { CreateLogStreamCommand } = await import("@aws-sdk/client-cloudwatch-logs");
42
+ return await this.client.send(new CreateLogStreamCommand({
43
+ logGroupName,
44
+ logStreamName
45
+ }));
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
+ };
61
+ createEvent = async (logGroupName, logStreamName, logEvent) => {
62
+ return await this.createEvents(logGroupName, logStreamName, [logEvent]);
63
+ };
64
+ createEvents = async (logGroupName, logStreamName, logEvents) => {
65
+ await this.ensureInit();
66
+ const { PutLogEventsCommand } = await import("@aws-sdk/client-cloudwatch-logs");
67
+ return await this.client.send(new PutLogEventsCommand({
68
+ logGroupName,
69
+ logStreamName,
70
+ logEvents: logEvents.map((event) => ({
71
+ timestamp: event.unixTimestamp ?? Date.now(),
72
+ message: typeof event === "string" ? event : JSON.stringify(event)
73
+ }))
74
+ }));
75
+ };
76
+ };
77
+
78
+ //#endregion
79
+ //#region src/aws/cloudWatch/server/awsCloudWatch.ts
80
+ const awsCloudWatchNamespaces = /* @__PURE__ */ new Map();
81
+ const awsCloudWatchClient = async (key = "default", config, vaultId, itemId) => {
82
+ if (awsCloudWatchNamespaces.has(key)) return awsCloudWatchNamespaces.get(key);
83
+ const namespace = new AwsCloudWatchNamespace(key, await getConfig(key, config, vaultId, itemId));
84
+ awsCloudWatchNamespaces.set(key, namespace);
85
+ return namespace;
86
+ };
87
+
88
+ //#endregion
89
+ //#region src/aws/cloudWatch/server/logEvent.ts
90
+ const logLevel = {
91
+ INFO: "info",
92
+ WARN: "warn",
93
+ ERROR: "error"
94
+ };
95
+
96
+ //#endregion
97
+ export { AwsCloudWatchNamespace, awsCloudWatchClient, logLevel };
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as AwsConfig } from "../../../index-CE8rcECG.mjs";
2
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
3
  import * as _aws_sdk_client_ec20 from "@aws-sdk/client-ec2";
4
4
  import { EC2Client } from "@aws-sdk/client-ec2";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as AwsConfig } from "../../../index-CE8rcECG.mjs";
2
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
3
  import { DesiredStatus, ECSClient, LaunchType, NetworkConfiguration, SortOrder, TaskDefinitionStatus, TaskOverride } from "@aws-sdk/client-ecs";
4
4
 
5
5
  //#region src/aws/ecs/server/AwsEcsNamespace.d.ts
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as AwsConfig } from "../../../index-CE8rcECG.mjs";
2
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
3
  import { GlueClient } from "@aws-sdk/client-glue";
4
4
 
5
5
  //#region src/aws/glue/server/AwsGlueNamespace.d.ts
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as AwsConfig } from "../../../index-CE8rcECG.mjs";
2
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
3
  import { LambdaClient } from "@aws-sdk/client-lambda";
4
4
 
5
5
  //#region src/aws/lambda/server/AwsLambdaNamespace.d.ts
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as AwsConfig } from "../../../index-CE8rcECG.mjs";
2
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
3
  import { z } from "zod/v4";
4
4
  import * as _aws_sdk_client_s30 from "@aws-sdk/client-s3";
5
5
  import { S3Client } from "@aws-sdk/client-s3";
@@ -4,7 +4,7 @@ import { getFolder, getStringFromStream } from "../../../string/index.mjs";
4
4
  import { n as isResponse200, t as getConfig } from "../../../server-Bwy4JI8Z.mjs";
5
5
  import { getBrotliCompressed, getBrotliDecompressed, getGzipCompressed, getGzipDecompressed } from "../../../util/server/index.mjs";
6
6
  import { z } from "zod/v4";
7
- import get from "axios";
7
+ import axios from "axios";
8
8
 
9
9
  //#region src/aws/s3/server/AwsS3Namespace.ts
10
10
  var AwsS3Namespace = class extends BaseNamespace {
@@ -293,7 +293,7 @@ var AwsS3Namespace = class extends BaseNamespace {
293
293
  */
294
294
  urlContents = async (bucket, key, url) => {
295
295
  await this.ensureInit();
296
- return get(url, {
296
+ return axios(url, {
297
297
  responseType: "arraybuffer",
298
298
  responseEncoding: "binary"
299
299
  }).then(async (response) => {
@@ -1,2 +1,2 @@
1
- import { n as getConfig, r as isResponse200, t as AwsConfig } from "../../index-CE8rcECG.mjs";
1
+ import { n as getConfig, r as isResponse200, t as AwsConfig } from "../../index-CqTOMR8f.mjs";
2
2
  export { AwsConfig, getConfig, isResponse200 };
@@ -1,5 +1,5 @@
1
1
  import { n as BaseClass, t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as AwsConfig } from "../../../index-CE8rcECG.mjs";
2
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
3
  import { SESClient, SendEmailCommandInput, SendRawEmailCommandInput } from "@aws-sdk/client-ses";
4
4
 
5
5
  //#region src/aws/ses/server/AwsSesNamespace.d.ts
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as AwsConfig } from "../../../index-CE8rcECG.mjs";
2
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
3
  import * as _aws_sdk_client_sqs0 from "@aws-sdk/client-sqs";
4
4
  import { SQSClient } from "@aws-sdk/client-sqs";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as AwsConfig } from "../../../index-CE8rcECG.mjs";
2
+ import { t as AwsConfig } from "../../../index-CqTOMR8f.mjs";
3
3
  import { SSMClient } from "@aws-sdk/client-ssm";
4
4
 
5
5
  //#region src/aws/ssm/server/AwsSsmNamespace.d.ts
@@ -1,5 +1,5 @@
1
1
  import { u as ApiResponseClass } from "../api-DGKJDAfb.mjs";
2
- import get$1 from "axios";
2
+ import axios from "axios";
3
3
 
4
4
  //#region src/axios/deleteRequest.ts
5
5
  /**
@@ -7,7 +7,7 @@ import get$1 from "axios";
7
7
  * Can't use the function name delete as it's reserved
8
8
  */
9
9
  const deleteRequest = async (url, config = {}) => {
10
- return await get$1.delete(url, config).then(async (response) => {
10
+ return await axios.delete(url, config).then(async (response) => {
11
11
  if (void 0 !== response.data.body && void 0 !== response.data.error && void 0 !== response.data.state) return new ApiResponseClass(response.data);
12
12
  else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(response.data);
13
13
  return new ApiResponseClass().setToError(response.data, response.statusText);
@@ -22,7 +22,7 @@ const deleteRequest = async (url, config = {}) => {
22
22
  * Make a GET request.
23
23
  */
24
24
  const get = async (url, config = {}) => {
25
- return await get$1.get(url, config).then(async (response) => {
25
+ return await axios.get(url, config).then(async (response) => {
26
26
  if (void 0 !== response.data.body && void 0 !== response.data.error && void 0 !== response.data.state) return new ApiResponseClass(response.data);
27
27
  else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(response.data);
28
28
  return new ApiResponseClass().setToError(response.data, response.statusText);
@@ -37,7 +37,7 @@ const get = async (url, config = {}) => {
37
37
  * Make a POST request.
38
38
  */
39
39
  const post = async (url, data = {}, config = {}) => {
40
- return await get$1.post(url, data, config).then(async (response) => {
40
+ return await axios.post(url, data, config).then(async (response) => {
41
41
  if (void 0 !== response.data.body && void 0 !== response.data.error && void 0 !== response.data.state) return new ApiResponseClass(response.data);
42
42
  else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(response.data);
43
43
  return new ApiResponseClass().setToError(response.data, response.statusText);
@@ -1,5 +1,5 @@
1
1
  import { createDirectory } from "../../file/server/index.mjs";
2
- import get from "axios";
2
+ import axios from "axios";
3
3
 
4
4
  //#region src/url/server/writeUrlContents.ts
5
5
  /**
@@ -11,7 +11,7 @@ const writeUrlContents = async (filePath, url) => {
11
11
  const fs = await import("fs-extra");
12
12
  await createDirectory(filePath);
13
13
  const writer = fs.createWriteStream(filePath);
14
- await get({
14
+ await axios({
15
15
  method: "get",
16
16
  url,
17
17
  responseType: "stream"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.3.37",
4
+ "version": "2.3.39",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"