@8ms/helpers 1.1.82 → 1.1.85
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/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;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
const format_1 = __importDefault(require("./format"));
|
|
7
|
+
const getToday_1 = __importDefault(require("./getToday"));
|
|
8
|
+
/**
|
|
9
|
+
* Shorthand to get the current date.
|
|
10
|
+
*/
|
|
11
|
+
const getTodayYmd = () => {
|
|
12
|
+
const today = (0, getToday_1.default)({ setMidnight: false });
|
|
13
|
+
const todayYmd = (0, format_1.default)({
|
|
14
|
+
input: today,
|
|
15
|
+
dateFormat: 'yyyy-MM-dd',
|
|
16
|
+
setMidnight: false,
|
|
17
|
+
});
|
|
18
|
+
return todayYmd;
|
|
19
|
+
};
|
|
20
|
+
exports.default = getTodayYmd;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
const format_1 = __importDefault(require("./format"));
|
|
7
|
+
const getToday_1 = __importDefault(require("./getToday"));
|
|
8
|
+
/**
|
|
9
|
+
* Shorthand to get the current timestamp.
|
|
10
|
+
*/
|
|
11
|
+
const getTodayYmdhis = () => {
|
|
12
|
+
const today = (0, getToday_1.default)({ setMidnight: false });
|
|
13
|
+
const todayYmdhis = (0, format_1.default)({
|
|
14
|
+
input: today,
|
|
15
|
+
dateFormat: 'yyyy-MM-dd HH:mm:ss',
|
|
16
|
+
setMidnight: false,
|
|
17
|
+
});
|
|
18
|
+
return todayYmdhis;
|
|
19
|
+
};
|
|
20
|
+
exports.default = getTodayYmdhis;
|