@8ms/helpers 1.36.1 → 1.37.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.
- package/api/index.d.ts +1 -0
- package/api/index.js +1 -0
- package/aws/ec2/initClient.d.ts +11 -0
- package/aws/ec2/initClient.js +23 -0
- package/aws/ec2/startInstances.d.ts +11 -0
- package/aws/ec2/startInstances.js +18 -0
- package/aws/ec2/stopInstances.d.ts +12 -0
- package/aws/ec2/stopInstances.js +19 -0
- package/initClients.d.ts +3 -2
- package/initClients.js +55 -49
- package/package.json +20 -19
package/api/index.d.ts
CHANGED
package/api/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.unexpectedError = exports.State = void 0;
|
|
4
4
|
var State;
|
|
5
5
|
(function (State) {
|
|
6
|
+
State["CANCELLED"] = "CANCELLED";
|
|
6
7
|
State["ERROR"] = "ERROR";
|
|
7
8
|
State["IDLE"] = "IDLE";
|
|
8
9
|
State["PENDING"] = "PENDING";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Config } from "../getConfig";
|
|
2
|
+
type InitClient = {
|
|
3
|
+
config: Config;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Shorthand function to get the EC2 Client.
|
|
7
|
+
* Library: @aws-sdk/client-ec2
|
|
8
|
+
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ec2/
|
|
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.awsEc2Client = null;
|
|
9
|
+
/**
|
|
10
|
+
* Shorthand function to get the EC2 Client.
|
|
11
|
+
* Library: @aws-sdk/client-ec2
|
|
12
|
+
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ec2/
|
|
13
|
+
*/
|
|
14
|
+
const initClient = (props) => {
|
|
15
|
+
if (!global.awsEc2Client) {
|
|
16
|
+
const { EC2Client } = require("@aws-sdk/client-ec2");
|
|
17
|
+
const formattedConfig = (0, getConfig_1.default)({
|
|
18
|
+
config: props.config
|
|
19
|
+
});
|
|
20
|
+
global.awsEc2Client = new EC2Client(formattedConfig);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.initClient = initClient;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type StartInstances = {
|
|
2
|
+
additionalInfo?: string;
|
|
3
|
+
instanceIds: string[];
|
|
4
|
+
dryRun?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Start one or more Ec2 Instances.
|
|
8
|
+
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ec2/command/StartInstancesCommand/
|
|
9
|
+
*/
|
|
10
|
+
export declare const startInstances: (props: StartInstances) => Promise<any>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startInstances = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Start one or more Ec2 Instances.
|
|
6
|
+
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ec2/command/StartInstancesCommand/
|
|
7
|
+
*/
|
|
8
|
+
const startInstances = async (props) => {
|
|
9
|
+
const { StartInstancesCommand } = require("@aws-sdk/client-ec2");
|
|
10
|
+
const command = new StartInstancesCommand({
|
|
11
|
+
InstanceIds: props.instanceIds,
|
|
12
|
+
AdditionalInfo: props?.additionalInfo,
|
|
13
|
+
DryRun: props?.dryRun,
|
|
14
|
+
});
|
|
15
|
+
const response = await global.awsEc2Client.send(command);
|
|
16
|
+
return response;
|
|
17
|
+
};
|
|
18
|
+
exports.startInstances = startInstances;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type StopInstances = {
|
|
2
|
+
dryRun?: boolean;
|
|
3
|
+
instanceIds: string[];
|
|
4
|
+
hibernate?: boolean;
|
|
5
|
+
force?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Stop one or more Ec2 Instances.
|
|
9
|
+
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ec2/command/StopInstancesCommand/
|
|
10
|
+
*/
|
|
11
|
+
export declare const stopInstances: (props: StopInstances) => Promise<any>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stopInstances = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Stop one or more Ec2 Instances.
|
|
6
|
+
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ec2/command/StopInstancesCommand/
|
|
7
|
+
*/
|
|
8
|
+
const stopInstances = async (props) => {
|
|
9
|
+
const { StopInstancesCommand } = require("@aws-sdk/client-ec2");
|
|
10
|
+
const command = new StopInstancesCommand({
|
|
11
|
+
InstanceIds: props.instanceIds,
|
|
12
|
+
Hibernate: props?.hibernate,
|
|
13
|
+
DryRun: props?.dryRun,
|
|
14
|
+
Force: props?.force,
|
|
15
|
+
});
|
|
16
|
+
const response = await global.awsEc2Client.send(command);
|
|
17
|
+
return response;
|
|
18
|
+
};
|
|
19
|
+
exports.stopInstances = stopInstances;
|
package/initClients.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config as AwsConfig } from
|
|
1
|
+
import { Config as AwsConfig } from "./aws/getConfig";
|
|
2
2
|
type InitClients = {
|
|
3
3
|
athenaExpress?: {
|
|
4
4
|
database: string;
|
|
@@ -6,6 +6,7 @@ type InitClients = {
|
|
|
6
6
|
s3Key: string;
|
|
7
7
|
};
|
|
8
8
|
awsConfig?: AwsConfig;
|
|
9
|
+
awsEc2?: boolean;
|
|
9
10
|
awsGlue?: boolean;
|
|
10
11
|
awsLambda?: boolean;
|
|
11
12
|
awsS3?: boolean;
|
|
@@ -37,5 +38,5 @@ type InitClients = {
|
|
|
37
38
|
/**
|
|
38
39
|
* Function to simplify initialising the clients.
|
|
39
40
|
*/
|
|
40
|
-
declare const initClients: (
|
|
41
|
+
declare const initClients: (props: InitClients) => Promise<void>;
|
|
41
42
|
export default initClients;
|
package/initClients.js
CHANGED
|
@@ -4,113 +4,119 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const initClient_1 = __importDefault(require("./aws/athenaExpress/initClient"));
|
|
7
|
-
const initClient_2 =
|
|
8
|
-
const initClient_3 = __importDefault(require("./aws/
|
|
9
|
-
const initClient_4 = __importDefault(require("./aws/
|
|
10
|
-
const initClient_5 = __importDefault(require("./aws/
|
|
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"));
|
|
11
12
|
const getParameter_1 = __importDefault(require("./aws/ssm/getParameter"));
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
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"));
|
|
20
21
|
/**
|
|
21
22
|
* Function to simplify initialising the clients.
|
|
22
23
|
*/
|
|
23
|
-
const initClients = async (
|
|
24
|
-
if (athenaExpress) {
|
|
24
|
+
const initClients = async (props) => {
|
|
25
|
+
if (props.athenaExpress) {
|
|
25
26
|
(0, initClient_1.default)({
|
|
26
|
-
config: awsConfig,
|
|
27
|
-
database: athenaExpress.database,
|
|
28
|
-
s3Bucket: athenaExpress.s3Bucket,
|
|
29
|
-
s3Key: athenaExpress.s3Key,
|
|
27
|
+
config: props.awsConfig,
|
|
28
|
+
database: props.athenaExpress.database,
|
|
29
|
+
s3Bucket: props.athenaExpress.s3Bucket,
|
|
30
|
+
s3Key: props.athenaExpress.s3Key,
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
|
-
if (
|
|
33
|
-
(0, initClient_2.
|
|
34
|
-
config: awsConfig,
|
|
33
|
+
if (props.awsEc2) {
|
|
34
|
+
(0, initClient_2.initClient)({
|
|
35
|
+
config: props.awsConfig,
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
|
-
if (
|
|
38
|
+
if (props.awsGlue) {
|
|
38
39
|
(0, initClient_3.default)({
|
|
39
|
-
config: awsConfig,
|
|
40
|
+
config: props.awsConfig,
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
|
-
if (
|
|
43
|
+
if (props.awsLambda) {
|
|
43
44
|
(0, initClient_4.default)({
|
|
44
|
-
config: awsConfig,
|
|
45
|
+
config: props.awsConfig,
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
|
-
if (
|
|
48
|
+
if (props.awsS3) {
|
|
48
49
|
(0, initClient_5.default)({
|
|
49
|
-
config: awsConfig,
|
|
50
|
+
config: props.awsConfig,
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
|
-
if (
|
|
53
|
+
if (props.awsSes) {
|
|
53
54
|
(0, initClient_6.default)({
|
|
54
|
-
config: awsConfig,
|
|
55
|
+
config: props.awsConfig,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (props.awsSsm || props.lumarApi || props.lumarGraphql || props.googleAds || props.googleConfig) {
|
|
59
|
+
(0, initClient_7.default)({
|
|
60
|
+
config: props.awsConfig,
|
|
55
61
|
});
|
|
56
62
|
}
|
|
57
63
|
// Lumar (API) authentication using SSM Parameter
|
|
58
|
-
if (lumarApi) {
|
|
64
|
+
if (props.lumarApi) {
|
|
59
65
|
const lumarApiParameter = await (0, getParameter_1.default)({
|
|
60
|
-
name: lumarApi.parameterName,
|
|
66
|
+
name: props.lumarApi.parameterName,
|
|
61
67
|
});
|
|
62
|
-
await (0,
|
|
68
|
+
await (0, initClient_8.default)({
|
|
63
69
|
auth: lumarApiParameter
|
|
64
70
|
});
|
|
65
71
|
}
|
|
66
72
|
// Lumar (GraphQL) authentication using SSM Parameter
|
|
67
|
-
if (lumarGraphql) {
|
|
73
|
+
if (props.lumarGraphql) {
|
|
68
74
|
const lumarGraphqlParameter = await (0, getParameter_1.default)({
|
|
69
|
-
name: lumarGraphql.parameterName,
|
|
75
|
+
name: props.lumarGraphql.parameterName,
|
|
70
76
|
});
|
|
71
|
-
await (0,
|
|
77
|
+
await (0, initClient_9.default)({
|
|
72
78
|
auth: lumarGraphqlParameter
|
|
73
79
|
});
|
|
74
80
|
}
|
|
75
81
|
// Google authentication using SSM
|
|
76
|
-
if (googleConfig) {
|
|
82
|
+
if (props.googleConfig) {
|
|
77
83
|
// Google Parameter
|
|
78
84
|
const googleParameter = await (0, getParameter_1.default)({
|
|
79
|
-
name: googleConfig.parameterName,
|
|
85
|
+
name: props.googleConfig.parameterName,
|
|
80
86
|
});
|
|
81
87
|
// BigQuery
|
|
82
|
-
if (googleBigQuery && googleConfig.projectId) {
|
|
83
|
-
(0,
|
|
88
|
+
if (props.googleBigQuery && props.googleConfig.projectId) {
|
|
89
|
+
(0, initClient_10.default)({
|
|
84
90
|
parameter: googleParameter,
|
|
85
|
-
projectId: googleConfig.projectId,
|
|
91
|
+
projectId: props.googleConfig.projectId,
|
|
86
92
|
});
|
|
87
93
|
}
|
|
88
94
|
// Google Sheets
|
|
89
|
-
if (googleSheets) {
|
|
90
|
-
(0,
|
|
95
|
+
if (props.googleSheets) {
|
|
96
|
+
(0, initClient_11.default)({
|
|
91
97
|
parameter: googleParameter,
|
|
92
98
|
});
|
|
93
99
|
}
|
|
94
100
|
// Google Storage
|
|
95
|
-
if (googleStorage && googleConfig.projectId) {
|
|
96
|
-
(0,
|
|
101
|
+
if (props.googleStorage && props.googleConfig.projectId) {
|
|
102
|
+
(0, initClient_12.default)({
|
|
97
103
|
parameter: googleParameter,
|
|
98
|
-
projectId: googleConfig.projectId,
|
|
104
|
+
projectId: props.googleConfig.projectId,
|
|
99
105
|
});
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
// Google Ads authentication using SSM Parameter
|
|
103
|
-
if (googleAds) {
|
|
109
|
+
if (props.googleAds) {
|
|
104
110
|
const googleAdsParameter = await (0, getParameter_1.default)({
|
|
105
|
-
name: googleAds.parameterName,
|
|
111
|
+
name: props.googleAds.parameterName,
|
|
106
112
|
});
|
|
107
|
-
await (0,
|
|
113
|
+
await (0, initClient_13.default)({
|
|
108
114
|
parameter: googleAdsParameter,
|
|
109
115
|
});
|
|
110
116
|
}
|
|
111
117
|
// Initialise Prisma
|
|
112
118
|
if (prisma) {
|
|
113
|
-
(0,
|
|
119
|
+
(0, initClient_14.default)({
|
|
114
120
|
debug: prisma ? false : prisma?.debug ?? false,
|
|
115
121
|
planetScale: prisma ? false : prisma?.planetScale ?? false,
|
|
116
122
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@8ms/helpers",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.37.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"jest": "jest --watch"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@date-fns/tz": "1.
|
|
16
|
+
"@date-fns/tz": "1.2.0",
|
|
17
17
|
"@date-fns/utc": "2.1.0",
|
|
18
18
|
"axios": "1.7.7",
|
|
19
19
|
"crypto-js": "4.2.0",
|
|
@@ -22,31 +22,32 @@
|
|
|
22
22
|
"zod": "3.23.8"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@aws-sdk/client-
|
|
26
|
-
"@aws-sdk/client-
|
|
27
|
-
"@aws-sdk/client-
|
|
28
|
-
"@aws-sdk/client-
|
|
29
|
-
"@aws-sdk/
|
|
30
|
-
"@aws-sdk/
|
|
31
|
-
"@
|
|
32
|
-
"@babel/preset-
|
|
33
|
-
"@babel/preset-
|
|
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",
|
|
32
|
+
"@babel/preset-env": "7.26.0",
|
|
33
|
+
"@babel/preset-flow": "7.25.9",
|
|
34
|
+
"@babel/preset-typescript": "7.26.0",
|
|
34
35
|
"@google-cloud/bigquery": "7.9.1",
|
|
35
|
-
"@google-cloud/storage": "7.
|
|
36
|
+
"@google-cloud/storage": "7.14.0",
|
|
36
37
|
"@planetscale/database": "1.19.0",
|
|
37
|
-
"@prisma/adapter-planetscale": "5.
|
|
38
|
-
"@prisma/client": "5.
|
|
39
|
-
"@types/jest": "29.5.
|
|
40
|
-
"@types/lodash": "4.17.
|
|
38
|
+
"@prisma/adapter-planetscale": "5.21.1",
|
|
39
|
+
"@prisma/client": "5.21.1",
|
|
40
|
+
"@types/jest": "29.5.14",
|
|
41
|
+
"@types/lodash": "4.17.13",
|
|
41
42
|
"@types/node": "20.14.12",
|
|
42
43
|
"babel-jest": "29.7.0",
|
|
43
44
|
"jest": "29.7.0",
|
|
44
45
|
"node-fetch": "3.3.2",
|
|
45
|
-
"stream-chain": "3.3.
|
|
46
|
-
"stream-json": "1.
|
|
46
|
+
"stream-chain": "3.3.2",
|
|
47
|
+
"stream-json": "1.9.0",
|
|
47
48
|
"timezone-mock": "1.3.6",
|
|
48
49
|
"ts-node": "10.9.2",
|
|
49
50
|
"tslib": "2.7.0",
|
|
50
|
-
"typescript": "5.6.
|
|
51
|
+
"typescript": "5.6.3"
|
|
51
52
|
}
|
|
52
53
|
}
|