@ikonintegration/ikapi 3.1.32 → 3.1.34
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikonintegration/ikapi",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.34",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "main.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@aws-sdk/credential-provider-node": "3.190.0",
|
|
18
18
|
"@aws-sdk/node-http-handler": "3.190.0",
|
|
19
19
|
"@aws-sdk/util-dynamodb": "3.190.0",
|
|
20
|
+
"@aws-sdk/util-endpoints": "3.190.0",
|
|
20
21
|
"@ikonintegration/mod-resources-tracker-client": "0.0.18",
|
|
21
22
|
"abind": "^1.0.5",
|
|
22
23
|
"bluebird": "^3.7.2",
|
|
@@ -59,7 +59,7 @@ export default class IKTransaction {
|
|
|
59
59
|
if (this._resp && this._resp instanceof IKResponse) {
|
|
60
60
|
await this._resp.build(this._context, this, this._syncReturn);
|
|
61
61
|
executionFailed = !!(this._resp.getBody() && this._resp.getBody().rollback);
|
|
62
|
-
} else {
|
|
62
|
+
} else if (!this._syncReturn) { //sync return can return other than ikresponse
|
|
63
63
|
this._resp = this._getErrorResponse(IKGlobals.ErrorResponseInvalidServerResponse, IKGlobals.ErrorCode_APIError)
|
|
64
64
|
await this._resp.build(this._context, this, this._syncReturn);
|
|
65
65
|
this.logger.error("Invalid response object from main request code.");
|
package/src/IKEventProcessor.js
CHANGED
|
@@ -3,11 +3,11 @@ import IKResponse, { IKBadRequestResponse, IKSuccessResponse } from './API/IKRes
|
|
|
3
3
|
import IKGlobals from './IKGlobals';
|
|
4
4
|
//
|
|
5
5
|
export default class IKEventProcessor {
|
|
6
|
-
constructor(event, context, config,
|
|
6
|
+
constructor(event, context, config, respondWithFailures) {
|
|
7
7
|
this.event = event;
|
|
8
8
|
this.context = context;
|
|
9
9
|
this.apiConfig = config;
|
|
10
|
-
this.
|
|
10
|
+
this._respondWithFailures = respondWithFailures;
|
|
11
11
|
}
|
|
12
12
|
async processEvent(execution, doNotDecodeMessage) {
|
|
13
13
|
const resp = await this._processRawEvent(execution, doNotDecodeMessage);
|
|
@@ -20,17 +20,21 @@ export default class IKEventProcessor {
|
|
|
20
20
|
return await (new IKTransaction(this.event, this.context, this.apiConfig, true /*batch processing*/)).execute(async (transaction) => {
|
|
21
21
|
//Map records with decoded message when required
|
|
22
22
|
const decodedRecords = this.event.Records.map((eventRecord) => (doNotDecodeMessage ? eventRecord.body : JSON.parse(eventRecord.body)));
|
|
23
|
-
|
|
24
|
-
if (this._syncReturn) return await execution(transaction, decodedRecords);
|
|
23
|
+
|
|
25
24
|
//for each available event
|
|
25
|
+
const failureIDs = [];
|
|
26
26
|
for (let eventRecord of decodedRecords) {
|
|
27
27
|
//Call execution
|
|
28
28
|
let resp = await execution(transaction, eventRecord);
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
//check for failure
|
|
30
|
+
if (!(resp.getCode() >= 200 && resp.getCode() < 300)) {
|
|
31
|
+
//response with failures or fail hard at first
|
|
32
|
+
if (this._respondWithFailures) failureIDs.push(eventRecord.messageId);
|
|
33
|
+
else return resp;
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
|
-
//not errored and loop ended - succeeded
|
|
36
|
+
//not errored and loop ended - succeeded (might have failures)
|
|
37
|
+
if (this._respondWithFailures) return { batchItemFailures: failureIDs.map((id) => ({ itemIdentifier: id })) };
|
|
34
38
|
return IKSuccessResponse();
|
|
35
39
|
});
|
|
36
40
|
} else return IKBadRequestResponse(IKGlobals.ErrorResponseNoRecords, IKGlobals.ErrorCode_NoRecords); //no event to be processed?
|