@8ms/helpers 1.37.0 → 1.38.0

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.
@@ -0,0 +1,9 @@
1
+ type GetClusters = {
2
+ maxResults?: number;
3
+ };
4
+ /**
5
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/command/ListClustersCommand/
6
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/ListClustersCommandInput/
7
+ */
8
+ export declare const getClusters: (props: GetClusters) => Promise<string[]>;
9
+ export {};
@@ -0,0 +1,32 @@
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
+ exports.getClusters = void 0;
7
+ const isResponse200_1 = __importDefault(require("../isResponse200"));
8
+ /**
9
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/command/ListClustersCommand/
10
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/ListClustersCommandInput/
11
+ */
12
+ const getClusters = async (props) => {
13
+ let response = [];
14
+ let apiResponse = null;
15
+ const { ListClustersCommand } = require("@aws-sdk/client-ecs");
16
+ while (null === apiResponse || apiResponse?.nextToken) {
17
+ const listClustersCommand = new ListClustersCommand({
18
+ maxResults: props?.maxResults,
19
+ nextToken: apiResponse?.nextToken,
20
+ });
21
+ apiResponse = await global.awsEcsClient.send(listClustersCommand);
22
+ // console.log("listClustersResponse", apiResponse);
23
+ if ((0, isResponse200_1.default)({ apiResponse })) {
24
+ response = [
25
+ ...response,
26
+ ...apiResponse.clusterArns,
27
+ ];
28
+ }
29
+ }
30
+ return response;
31
+ };
32
+ exports.getClusters = getClusters;
@@ -0,0 +1,13 @@
1
+ import { SortOrder, TaskDefinitionStatus } from "@aws-sdk/client-ecs";
2
+ type GetTaskDefinitions = {
3
+ familyPrefix?: string;
4
+ maxResults?: number;
5
+ sort?: SortOrder;
6
+ status?: TaskDefinitionStatus;
7
+ };
8
+ /**
9
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/command/ListTaskDefinitionsCommand/
10
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/ListTaskDefinitionsCommandInput/
11
+ */
12
+ export declare const getTaskDefinitions: (props: GetTaskDefinitions) => Promise<string[]>;
13
+ export {};
@@ -0,0 +1,35 @@
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
+ exports.getTaskDefinitions = void 0;
7
+ const isResponse200_1 = __importDefault(require("../isResponse200"));
8
+ /**
9
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/command/ListTaskDefinitionsCommand/
10
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/ListTaskDefinitionsCommandInput/
11
+ */
12
+ const getTaskDefinitions = async (props) => {
13
+ let response = [];
14
+ let apiResponse = null;
15
+ const { ListTaskDefinitionsCommand } = require("@aws-sdk/client-ecs");
16
+ while (null === apiResponse || apiResponse?.nextToken) {
17
+ const listTaskDefinitionsCommand = new ListTaskDefinitionsCommand({
18
+ maxResults: props?.maxResults,
19
+ familyPrefix: props?.familyPrefix,
20
+ sort: props?.sort,
21
+ status: props?.status,
22
+ nextToken: apiResponse?.nextToken,
23
+ });
24
+ apiResponse = await global.awsEcsClient.send(listTaskDefinitionsCommand);
25
+ // console.log("listTaskDefinitionsResponse", apiResponse);
26
+ if ((0, isResponse200_1.default)({ apiResponse })) {
27
+ response = [
28
+ ...response,
29
+ ...apiResponse.taskDefinitionArns,
30
+ ];
31
+ }
32
+ }
33
+ return response;
34
+ };
35
+ exports.getTaskDefinitions = getTaskDefinitions;
@@ -0,0 +1,16 @@
1
+ import { DesiredStatus } from "@aws-sdk/client-ecs";
2
+ type GetTasks = {
3
+ cluster?: string;
4
+ containerInstance?: string;
5
+ desiredStatus?: DesiredStatus;
6
+ family?: string;
7
+ maxResults?: number;
8
+ serviceName?: string;
9
+ startedBy?: string;
10
+ };
11
+ /**
12
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/command/ListTasksCommand/
13
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/ListTasksCommandInput/
14
+ */
15
+ export declare const getTasks: (props: GetTasks) => Promise<string[]>;
16
+ export {};
@@ -0,0 +1,38 @@
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
+ exports.getTasks = void 0;
7
+ const isResponse200_1 = __importDefault(require("../isResponse200"));
8
+ /**
9
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/command/ListTasksCommand/
10
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/ListTasksCommandInput/
11
+ */
12
+ const getTasks = async (props) => {
13
+ let response = [];
14
+ let apiResponse = null;
15
+ const { ListTasksCommand } = require("@aws-sdk/client-ecs");
16
+ while (null === apiResponse || apiResponse?.nextToken) {
17
+ const listTasksCommand = new ListTasksCommand({
18
+ cluster: props?.cluster,
19
+ containerInstance: props?.containerInstance,
20
+ desiredStatus: props?.desiredStatus,
21
+ family: props?.family,
22
+ maxResults: props?.maxResults,
23
+ nextToken: apiResponse?.nextToken,
24
+ serviceName: props?.serviceName,
25
+ startedBy: props?.startedBy,
26
+ });
27
+ apiResponse = await global.awsEcsClient.send(listTasksCommand);
28
+ // console.log("listClustersResponse", apiResponse);
29
+ if ((0, isResponse200_1.default)({ apiResponse })) {
30
+ response = [
31
+ ...response,
32
+ ...apiResponse.taskArns,
33
+ ];
34
+ }
35
+ }
36
+ return response;
37
+ };
38
+ exports.getTasks = getTasks;
@@ -0,0 +1,11 @@
1
+ import { Config } from "../getConfig";
2
+ type InitClient = {
3
+ config: Config;
4
+ };
5
+ /**
6
+ * Shorthand function to get the ECS Client.
7
+ * Library: @aws-sdk/client-ecs
8
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/
9
+ */
10
+ export declare const initClient: (props: InitClient) => void;
11
+ export {};
@@ -0,0 +1,23 @@
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
+ exports.initClient = void 0;
7
+ const getConfig_1 = __importDefault(require("../getConfig"));
8
+ global.awsEcsClient = null;
9
+ /**
10
+ * Shorthand function to get the ECS Client.
11
+ * Library: @aws-sdk/client-ecs
12
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/
13
+ */
14
+ const initClient = (props) => {
15
+ if (!global.awsEcsClient) {
16
+ const { ECSClient } = require("@aws-sdk/client-ecs");
17
+ const formattedConfig = (0, getConfig_1.default)({
18
+ config: props.config
19
+ });
20
+ global.awsEcsClient = new ECSClient(formattedConfig);
21
+ }
22
+ };
23
+ exports.initClient = initClient;
@@ -0,0 +1,16 @@
1
+ import { LaunchType, NetworkConfiguration, TaskOverride } from "@aws-sdk/client-ecs";
2
+ type RunTask = {
3
+ cluster?: string;
4
+ count?: number;
5
+ launchType?: LaunchType;
6
+ networkConfiguration?: NetworkConfiguration;
7
+ overrides?: TaskOverride;
8
+ taskDefinition?: string;
9
+ };
10
+ /**
11
+ * Initialise and run a task
12
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/command/RunTaskCommand/
13
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/RunTaskCommandInput/
14
+ */
15
+ export declare const runTask: (props: RunTask) => Promise<boolean>;
16
+ export {};
@@ -0,0 +1,30 @@
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
+ exports.runTask = void 0;
7
+ const isResponse200_1 = __importDefault(require("../isResponse200"));
8
+ /**
9
+ * Initialise and run a task
10
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/command/RunTaskCommand/
11
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/RunTaskCommandInput/
12
+ */
13
+ const runTask = async (props) => {
14
+ let response = false;
15
+ const { RunTaskCommand } = require("@aws-sdk/client-ecs");
16
+ const runtTaskCommand = new RunTaskCommand({
17
+ cluster: props?.cluster,
18
+ launchType: props?.launchType,
19
+ networkConfiguration: props?.networkConfiguration,
20
+ overrides: props?.overrides,
21
+ taskDefinition: props?.taskDefinition,
22
+ });
23
+ const apiResponse = await global.awsEcsClient.send(runtTaskCommand);
24
+ // console.log("runTaskCommandResponse", apiResponse);
25
+ if ((0, isResponse200_1.default)({ apiResponse })) {
26
+ response = apiResponse;
27
+ }
28
+ return response;
29
+ };
30
+ exports.runTask = runTask;
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
package/initClients.d.ts CHANGED
@@ -7,6 +7,7 @@ type InitClients = {
7
7
  };
8
8
  awsConfig?: AwsConfig;
9
9
  awsEc2?: boolean;
10
+ awsEcs?: boolean;
10
11
  awsGlue?: boolean;
11
12
  awsLambda?: boolean;
12
13
  awsS3?: boolean;
package/initClients.js CHANGED
@@ -5,24 +5,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const initClient_1 = __importDefault(require("./aws/athenaExpress/initClient"));
7
7
  const initClient_2 = require("./aws/ec2/initClient");
8
- const initClient_3 = __importDefault(require("./aws/glue/initClient"));
9
- const initClient_4 = __importDefault(require("./aws/lambda/initClient"));
10
- const initClient_5 = __importDefault(require("./aws/s3/initClient"));
11
- const initClient_6 = __importDefault(require("./aws/ses/initClient"));
8
+ const initClient_3 = require("./aws/ecs/initClient");
9
+ const initClient_4 = __importDefault(require("./aws/glue/initClient"));
10
+ const initClient_5 = __importDefault(require("./aws/lambda/initClient"));
11
+ const initClient_6 = __importDefault(require("./aws/s3/initClient"));
12
+ const initClient_7 = __importDefault(require("./aws/ses/initClient"));
12
13
  const getParameter_1 = __importDefault(require("./aws/ssm/getParameter"));
13
- const initClient_7 = __importDefault(require("./aws/ssm/initClient"));
14
- const initClient_8 = __importDefault(require("./lumar/api/initClient"));
15
- const initClient_9 = __importDefault(require("./lumar/graphql/initClient"));
16
- const initClient_10 = __importDefault(require("./google/bigQuery/initClient"));
17
- const initClient_11 = __importDefault(require("./google/sheets/initClient"));
18
- const initClient_12 = __importDefault(require("./google/storage/initClient"));
19
- const initClient_13 = __importDefault(require("./googleAds/initClient"));
20
- const initClient_14 = __importDefault(require("./prisma/initClient"));
14
+ const initClient_8 = __importDefault(require("./aws/ssm/initClient"));
15
+ const initClient_9 = __importDefault(require("./lumar/api/initClient"));
16
+ const initClient_10 = __importDefault(require("./lumar/graphql/initClient"));
17
+ const initClient_11 = __importDefault(require("./google/bigQuery/initClient"));
18
+ const initClient_12 = __importDefault(require("./google/sheets/initClient"));
19
+ const initClient_13 = __importDefault(require("./google/storage/initClient"));
20
+ const initClient_14 = __importDefault(require("./googleAds/initClient"));
21
+ const initClient_15 = __importDefault(require("./prisma/initClient"));
21
22
  /**
22
23
  * Function to simplify initialising the clients.
23
24
  */
24
25
  const initClients = async (props) => {
25
- if (props.athenaExpress) {
26
+ if (props?.athenaExpress) {
26
27
  (0, initClient_1.default)({
27
28
  config: props.awsConfig,
28
29
  database: props.athenaExpress.database,
@@ -30,95 +31,100 @@ const initClients = async (props) => {
30
31
  s3Key: props.athenaExpress.s3Key,
31
32
  });
32
33
  }
33
- if (props.awsEc2) {
34
+ if (props?.awsEc2) {
34
35
  (0, initClient_2.initClient)({
35
36
  config: props.awsConfig,
36
37
  });
37
38
  }
38
- if (props.awsGlue) {
39
- (0, initClient_3.default)({
39
+ if (props?.awsEcs) {
40
+ (0, initClient_3.initClient)({
40
41
  config: props.awsConfig,
41
42
  });
42
43
  }
43
- if (props.awsLambda) {
44
+ if (props?.awsGlue) {
44
45
  (0, initClient_4.default)({
45
46
  config: props.awsConfig,
46
47
  });
47
48
  }
48
- if (props.awsS3) {
49
+ if (props?.awsLambda) {
49
50
  (0, initClient_5.default)({
50
51
  config: props.awsConfig,
51
52
  });
52
53
  }
53
- if (props.awsSes) {
54
+ if (props?.awsS3) {
54
55
  (0, initClient_6.default)({
55
56
  config: props.awsConfig,
56
57
  });
57
58
  }
58
- if (props.awsSsm || props.lumarApi || props.lumarGraphql || props.googleAds || props.googleConfig) {
59
+ if (props?.awsSes) {
59
60
  (0, initClient_7.default)({
60
61
  config: props.awsConfig,
61
62
  });
62
63
  }
64
+ if (props?.awsSsm || props?.lumarApi || props?.lumarGraphql || props?.googleAds || props?.googleConfig) {
65
+ (0, initClient_8.default)({
66
+ config: props.awsConfig,
67
+ });
68
+ }
63
69
  // Lumar (API) authentication using SSM Parameter
64
- if (props.lumarApi) {
70
+ if (props?.lumarApi) {
65
71
  const lumarApiParameter = await (0, getParameter_1.default)({
66
72
  name: props.lumarApi.parameterName,
67
73
  });
68
- await (0, initClient_8.default)({
74
+ await (0, initClient_9.default)({
69
75
  auth: lumarApiParameter
70
76
  });
71
77
  }
72
78
  // Lumar (GraphQL) authentication using SSM Parameter
73
- if (props.lumarGraphql) {
79
+ if (props?.lumarGraphql) {
74
80
  const lumarGraphqlParameter = await (0, getParameter_1.default)({
75
81
  name: props.lumarGraphql.parameterName,
76
82
  });
77
- await (0, initClient_9.default)({
83
+ await (0, initClient_10.default)({
78
84
  auth: lumarGraphqlParameter
79
85
  });
80
86
  }
81
87
  // Google authentication using SSM
82
- if (props.googleConfig) {
88
+ if (props?.googleConfig) {
83
89
  // Google Parameter
84
90
  const googleParameter = await (0, getParameter_1.default)({
85
91
  name: props.googleConfig.parameterName,
86
92
  });
87
93
  // BigQuery
88
- if (props.googleBigQuery && props.googleConfig.projectId) {
89
- (0, initClient_10.default)({
94
+ if (props?.googleBigQuery && props?.googleConfig?.projectId) {
95
+ (0, initClient_11.default)({
90
96
  parameter: googleParameter,
91
97
  projectId: props.googleConfig.projectId,
92
98
  });
93
99
  }
94
100
  // Google Sheets
95
- if (props.googleSheets) {
96
- (0, initClient_11.default)({
101
+ if (props?.googleSheets) {
102
+ (0, initClient_12.default)({
97
103
  parameter: googleParameter,
98
104
  });
99
105
  }
100
106
  // Google Storage
101
- if (props.googleStorage && props.googleConfig.projectId) {
102
- (0, initClient_12.default)({
107
+ if (props?.googleStorage && props?.googleConfig?.projectId) {
108
+ (0, initClient_13.default)({
103
109
  parameter: googleParameter,
104
110
  projectId: props.googleConfig.projectId,
105
111
  });
106
112
  }
107
113
  }
108
114
  // Google Ads authentication using SSM Parameter
109
- if (props.googleAds) {
115
+ if (props?.googleAds) {
110
116
  const googleAdsParameter = await (0, getParameter_1.default)({
111
117
  name: props.googleAds.parameterName,
112
118
  });
113
- await (0, initClient_13.default)({
119
+ await (0, initClient_14.default)({
114
120
  parameter: googleAdsParameter,
115
121
  });
116
122
  }
117
123
  // Initialise Prisma
118
- if (prisma) {
119
- (0, initClient_14.default)({
120
- debug: prisma ? false : prisma?.debug ?? false,
121
- planetScale: prisma ? false : prisma?.planetScale ?? false,
124
+ if (props?.prisma) {
125
+ (0, initClient_15.default)({
126
+ debug: props?.prisma?.debug ?? false,
127
+ planetScale: props?.prisma?.planetScale ?? false,
122
128
  });
123
129
  }
124
130
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.37.0",
4
+ "version": "1.38.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -15,28 +15,29 @@
15
15
  "dependencies": {
16
16
  "@date-fns/tz": "1.2.0",
17
17
  "@date-fns/utc": "2.1.0",
18
- "axios": "1.7.7",
18
+ "axios": "1.7.8",
19
19
  "crypto-js": "4.2.0",
20
20
  "date-fns": "4.1.0",
21
21
  "lodash": "4.17.21",
22
22
  "zod": "3.23.8"
23
23
  },
24
24
  "devDependencies": {
25
- "@aws-sdk/client-ec2": "3.683.0",
26
- "@aws-sdk/client-s3": "3.682.0",
27
- "@aws-sdk/client-ses": "3.682.0",
28
- "@aws-sdk/client-sqs": "3.682.0",
29
- "@aws-sdk/client-ssm": "3.682.0",
30
- "@aws-sdk/lib-storage": "3.685.0",
31
- "@aws-sdk/s3-request-presigner": "3.685.0",
25
+ "@aws-sdk/client-ec2": "3.701.0",
26
+ "@aws-sdk/client-ecs": "3.699.0",
27
+ "@aws-sdk/client-s3": "3.701.0",
28
+ "@aws-sdk/client-ses": "3.699.0",
29
+ "@aws-sdk/client-sqs": "3.699.0",
30
+ "@aws-sdk/client-ssm": "3.699.0",
31
+ "@aws-sdk/lib-storage": "3.701.0",
32
+ "@aws-sdk/s3-request-presigner": "3.701.0",
32
33
  "@babel/preset-env": "7.26.0",
33
34
  "@babel/preset-flow": "7.25.9",
34
35
  "@babel/preset-typescript": "7.26.0",
35
36
  "@google-cloud/bigquery": "7.9.1",
36
37
  "@google-cloud/storage": "7.14.0",
37
38
  "@planetscale/database": "1.19.0",
38
- "@prisma/adapter-planetscale": "5.21.1",
39
- "@prisma/client": "5.21.1",
39
+ "@prisma/adapter-planetscale": "5.22.0",
40
+ "@prisma/client": "5.22.0",
40
41
  "@types/jest": "29.5.14",
41
42
  "@types/lodash": "4.17.13",
42
43
  "@types/node": "20.14.12",
@@ -44,10 +45,10 @@
44
45
  "jest": "29.7.0",
45
46
  "node-fetch": "3.3.2",
46
47
  "stream-chain": "3.3.2",
47
- "stream-json": "1.9.0",
48
+ "stream-json": "1.9.1",
48
49
  "timezone-mock": "1.3.6",
49
50
  "ts-node": "10.9.2",
50
- "tslib": "2.7.0",
51
- "typescript": "5.6.3"
51
+ "tslib": "2.8.1",
52
+ "typescript": "5.7.2"
52
53
  }
53
54
  }
package/stream/sort.d.ts CHANGED
@@ -4,6 +4,7 @@ declare const Transform: any;
4
4
  * https://www.npmjs.com/package/fast-stream-sort
5
5
  */
6
6
  declare class SortStreamer extends Transform {
7
+ static [x: string]: any;
7
8
  constructor(options: any, comp: any);
8
9
  _transform(data: any, _: any, callback: any): void;
9
10
  _flush(): void;