@8ms/helpers 1.1.81 → 1.1.84
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/aws/lambda/initClient.js +2 -2
- package/aws/lambda/invoke.d.ts +3 -2
- package/aws/lambda/invoke.js +17 -10
- package/google/keywordPlanner/request.d.ts +1 -1
- package/google/keywordPlanner/response.d.ts +0 -1
- package/initClients.d.ts +1 -1
- package/initClients.js +25 -19
- package/package.json +1 -1
package/aws/lambda/initClient.js
CHANGED
|
@@ -11,9 +11,9 @@ global.awsLambdaClient = null;
|
|
|
11
11
|
*/
|
|
12
12
|
const initClient = ({ config }) => {
|
|
13
13
|
if (!global.awsLambdaClient) {
|
|
14
|
-
const {
|
|
14
|
+
const { LambdaClient } = require('@aws-sdk/client-lambda');
|
|
15
15
|
const formattedConfig = (0, getConfig_1.default)({ config });
|
|
16
|
-
global.awsLambdaClient = new
|
|
16
|
+
global.awsLambdaClient = new LambdaClient(formattedConfig);
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
exports.default = initClient;
|
package/aws/lambda/invoke.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
declare type Invoke = {
|
|
2
|
+
awaitResponse?: boolean;
|
|
2
3
|
functionName: string;
|
|
4
|
+
isJson?: boolean;
|
|
3
5
|
payload?: object;
|
|
4
|
-
response?: boolean;
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
7
8
|
* Invoke a AWS Lambda function by passing in the Function name and optional Payload data.
|
|
8
9
|
* Runs asynchronously, doesn't wait for function to fully end.
|
|
9
10
|
* Library: @aws-sdk/client-lambda
|
|
10
11
|
*/
|
|
11
|
-
declare const invoke: ({ functionName,
|
|
12
|
+
declare const invoke: ({ awaitResponse, functionName, isJson, payload }: Invoke) => Promise<any>;
|
|
12
13
|
export default invoke;
|
package/aws/lambda/invoke.js
CHANGED
|
@@ -9,10 +9,11 @@ const isResponse200_1 = __importDefault(require("../isResponse200"));
|
|
|
9
9
|
* Runs asynchronously, doesn't wait for function to fully end.
|
|
10
10
|
* Library: @aws-sdk/client-lambda
|
|
11
11
|
*/
|
|
12
|
-
const invoke = async ({ functionName,
|
|
12
|
+
const invoke = async ({ awaitResponse, functionName, isJson, payload }) => {
|
|
13
|
+
let response = false;
|
|
13
14
|
const params = {
|
|
14
15
|
FunctionName: functionName,
|
|
15
|
-
InvocationType: true ===
|
|
16
|
+
InvocationType: true === awaitResponse ? 'RequestResponse' : 'Event',
|
|
16
17
|
};
|
|
17
18
|
// Payload is defined add to parameters
|
|
18
19
|
if (undefined !== payload) {
|
|
@@ -26,17 +27,23 @@ const invoke = async ({ functionName, payload, response }) => {
|
|
|
26
27
|
// Success
|
|
27
28
|
if ((0, isResponse200_1.default)({ apiResponse })) {
|
|
28
29
|
// Return the data
|
|
29
|
-
if (
|
|
30
|
+
if (awaitResponse && undefined !== apiResponse.Payload) {
|
|
30
31
|
const asciiDecoder = new TextDecoder('ascii');
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
32
|
+
response = asciiDecoder.decode(apiResponse.Payload);
|
|
33
|
+
// Decode string as JSON object
|
|
34
|
+
if (true === isJson) {
|
|
35
|
+
response = JSON.parse(response);
|
|
36
|
+
// If it's still a string, double decode it
|
|
37
|
+
if ('string' === typeof response) {
|
|
38
|
+
response = JSON.parse(response);
|
|
39
|
+
}
|
|
35
40
|
}
|
|
36
|
-
return decodedJson;
|
|
37
41
|
}
|
|
38
|
-
|
|
42
|
+
// Success but not waiting for response
|
|
43
|
+
else {
|
|
44
|
+
response = true;
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
|
-
return
|
|
47
|
+
return response;
|
|
41
48
|
};
|
|
42
49
|
exports.default = invoke;
|
package/initClients.d.ts
CHANGED
|
@@ -33,5 +33,5 @@ declare type InitClients = {
|
|
|
33
33
|
/**
|
|
34
34
|
* Function to simplify initialising the clients.
|
|
35
35
|
*/
|
|
36
|
-
declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, awsSsm, deepCrawl, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }: InitClients) => Promise<void>;
|
|
36
|
+
declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepCrawl, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }: InitClients) => Promise<void>;
|
|
37
37
|
export default initClients;
|
package/initClients.js
CHANGED
|
@@ -5,20 +5,21 @@ 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 = __importDefault(require("./aws/glue/initClient"));
|
|
8
|
-
const initClient_3 = __importDefault(require("./aws/
|
|
9
|
-
const initClient_4 = __importDefault(require("./aws/
|
|
8
|
+
const initClient_3 = __importDefault(require("./aws/lambda/initClient"));
|
|
9
|
+
const initClient_4 = __importDefault(require("./aws/s3/initClient"));
|
|
10
|
+
const initClient_5 = __importDefault(require("./aws/ses/initClient"));
|
|
10
11
|
const getParameter_1 = __importDefault(require("./aws/ssm/getParameter"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
12
|
+
const initClient_6 = __importDefault(require("./aws/ssm/initClient"));
|
|
13
|
+
const initClient_7 = __importDefault(require("./deepCrawl/initClient"));
|
|
14
|
+
const initClient_8 = __importDefault(require("./google/bigQuery/initClient"));
|
|
15
|
+
const initClient_9 = __importDefault(require("./google/sheets/initClient"));
|
|
16
|
+
const initClient_10 = __importDefault(require("./google/storage/initClient"));
|
|
17
|
+
const initClient_11 = __importDefault(require("./googleAds/initClient"));
|
|
18
|
+
const initClient_12 = __importDefault(require("./prisma/initClient"));
|
|
18
19
|
/**
|
|
19
20
|
* Function to simplify initialising the clients.
|
|
20
21
|
*/
|
|
21
|
-
const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, awsSsm, deepCrawl, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }) => {
|
|
22
|
+
const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepCrawl, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }) => {
|
|
22
23
|
if (athenaExpress) {
|
|
23
24
|
(0, initClient_1.default)({
|
|
24
25
|
config: awsConfig,
|
|
@@ -32,27 +33,32 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, a
|
|
|
32
33
|
config: awsConfig,
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
|
-
if (
|
|
36
|
+
if (awsLambda) {
|
|
36
37
|
(0, initClient_3.default)({
|
|
37
38
|
config: awsConfig,
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
|
-
if (
|
|
41
|
+
if (awsS3) {
|
|
41
42
|
(0, initClient_4.default)({
|
|
42
43
|
config: awsConfig,
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
|
-
if (
|
|
46
|
+
if (awsSes) {
|
|
46
47
|
(0, initClient_5.default)({
|
|
47
48
|
config: awsConfig,
|
|
48
49
|
});
|
|
49
50
|
}
|
|
51
|
+
if (awsSsm || deepCrawl || googleAds || googleConfig) {
|
|
52
|
+
(0, initClient_6.default)({
|
|
53
|
+
config: awsConfig,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
50
56
|
// Deepcrawl authentication using SSM Parameter
|
|
51
57
|
if (deepCrawl) {
|
|
52
58
|
const deepcrawlParameter = await (0, getParameter_1.default)({
|
|
53
59
|
name: deepCrawl.parameterName,
|
|
54
60
|
});
|
|
55
|
-
await (0,
|
|
61
|
+
await (0, initClient_7.default)({ auth: deepcrawlParameter });
|
|
56
62
|
}
|
|
57
63
|
// Google authentication using SSM
|
|
58
64
|
if (googleConfig) {
|
|
@@ -62,20 +68,20 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, a
|
|
|
62
68
|
});
|
|
63
69
|
// BigQuery
|
|
64
70
|
if (googleBigQuery && googleConfig.projectId) {
|
|
65
|
-
(0,
|
|
71
|
+
(0, initClient_8.default)({
|
|
66
72
|
parameter: googleParameter,
|
|
67
73
|
projectId: googleConfig.projectId,
|
|
68
74
|
});
|
|
69
75
|
}
|
|
70
76
|
// Google Sheets
|
|
71
77
|
if (googleSheets) {
|
|
72
|
-
(0,
|
|
78
|
+
(0, initClient_9.default)({
|
|
73
79
|
parameter: googleParameter,
|
|
74
80
|
});
|
|
75
81
|
}
|
|
76
82
|
// Google Storage
|
|
77
83
|
if (googleStorage && googleConfig.projectId) {
|
|
78
|
-
(0,
|
|
84
|
+
(0, initClient_10.default)({
|
|
79
85
|
parameter: googleParameter,
|
|
80
86
|
projectId: googleConfig.projectId,
|
|
81
87
|
});
|
|
@@ -86,13 +92,13 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, a
|
|
|
86
92
|
const googleAdsParameter = await (0, getParameter_1.default)({
|
|
87
93
|
name: googleAds.parameterName,
|
|
88
94
|
});
|
|
89
|
-
await (0,
|
|
95
|
+
await (0, initClient_11.default)({
|
|
90
96
|
parameter: googleAdsParameter,
|
|
91
97
|
});
|
|
92
98
|
}
|
|
93
99
|
// Initialise Prisma
|
|
94
100
|
if (prisma) {
|
|
95
|
-
(0,
|
|
101
|
+
(0, initClient_12.default)({
|
|
96
102
|
debug: prisma ? false : prisma.debug || false,
|
|
97
103
|
});
|
|
98
104
|
}
|