@pepperi-addons/system-addon-utils 1.1.0 → 1.1.1
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/dist/index.d.ts +3 -3
- package/dist/index.js +21 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
export declare function callElasticSearchLambda(endpoint: string, method: string, body?:
|
1
|
+
export declare function callElasticSearchLambda(endpoint: string, method: string, body?: any, contentType?: string): Promise<{
|
2
2
|
success: true;
|
3
|
-
resultObject:
|
3
|
+
resultObject: any;
|
4
4
|
} | {
|
5
5
|
success: false;
|
6
|
-
errorMessage:
|
6
|
+
errorMessage: string;
|
7
7
|
}>;
|
package/dist/index.js
CHANGED
@@ -11,35 +11,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.callElasticSearchLambda = callElasticSearchLambda;
|
13
13
|
const client_lambda_1 = require("@aws-sdk/client-lambda");
|
14
|
+
// Ensure payloadRaw is always a string: if it's already a string, use it; if it's a Uint8Array (binary), decode it as UTF-8.
|
15
|
+
const payloadToString = (payload) => payload
|
16
|
+
? (typeof payload === 'string'
|
17
|
+
? payload
|
18
|
+
: new TextDecoder('utf-8').decode(payload))
|
19
|
+
: '';
|
20
|
+
const errorToString = (error) => typeof error === 'string'
|
21
|
+
? error
|
22
|
+
: (error instanceof Error && error.message
|
23
|
+
? error.message
|
24
|
+
: JSON.stringify(error));
|
14
25
|
function callElasticSearchLambda(endpoint, method, body, contentType) {
|
15
26
|
return __awaiter(this, void 0, void 0, function* () {
|
16
27
|
const lambdaClient = new client_lambda_1.LambdaClient({});
|
17
|
-
const invokeCommandInput =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
23
|
-
: {
|
24
|
-
FunctionName: 'ElasticSearchLambda',
|
25
|
-
InvocationType: 'RequestResponse',
|
26
|
-
Payload: JSON.stringify({ endpoint, method })
|
27
|
-
};
|
28
|
+
const invokeCommandInput = {
|
29
|
+
FunctionName: 'ElasticSearchLambda',
|
30
|
+
InvocationType: 'RequestResponse',
|
31
|
+
Payload: JSON.stringify(body ? { endpoint, method, body, contentType: contentType !== null && contentType !== void 0 ? contentType : "application/json" } : { endpoint, method })
|
32
|
+
};
|
28
33
|
try {
|
29
34
|
const response = yield lambdaClient.send(new client_lambda_1.InvokeCommand(invokeCommandInput));
|
30
|
-
const
|
31
|
-
const payloadString = payloadRaw
|
32
|
-
? (typeof payloadRaw === 'string' ? payloadRaw : new TextDecoder('utf-8').decode(payloadRaw))
|
33
|
-
: '';
|
35
|
+
const payloadString = payloadToString(response.Payload);
|
34
36
|
console.log("lambda invoke response:", payloadString);
|
35
|
-
if (response.StatusCode === 200 && payloadString)
|
37
|
+
if (response.StatusCode === 200 && payloadString)
|
36
38
|
return { success: true, resultObject: JSON.parse(payloadString) };
|
37
|
-
|
38
|
-
return { success: false, errorMessage:
|
39
|
+
const parsed = payloadString ? JSON.parse(payloadString) : 'Unknown error';
|
40
|
+
return { success: false, errorMessage: typeof parsed === 'string' ? parsed : JSON.stringify(parsed) };
|
39
41
|
}
|
40
42
|
catch (error) {
|
41
43
|
console.error("Lambda invocation failed:", error);
|
42
|
-
return { success: false, errorMessage: error };
|
44
|
+
return { success: false, errorMessage: errorToString(error) };
|
43
45
|
}
|
44
46
|
});
|
45
47
|
}
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;AAiBA,0DAwBC;AAzCD,0DAA8G;AAE9G,6HAA6H;AAC7H,MAAM,eAAe,GAAG,CAAC,OAAY,EAAU,EAAE,CAC7C,OAAO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