@8ms/helpers 1.1.82 → 1.1.83
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 +3 -2
- package/aws/lambda/invoke.js +17 -10
- package/package.json +1 -1
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;
|