@adobe/spacecat-shared-utils 1.26.2 → 1.26.4
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/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/sqs.js +25 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-utils-v1.26.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.26.3...@adobe/spacecat-shared-utils-v1.26.4) (2025-01-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* missing Response import ([#543](https://github.com/adobe/spacecat-shared/issues/543)) ([6e82332](https://github.com/adobe/spacecat-shared/commit/6e82332fcadb504def553268ff36228d864bcfef))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-utils-v1.26.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.26.2...@adobe/spacecat-shared-utils-v1.26.3) (2025-01-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* improve sqs event adapter error handling ([#541](https://github.com/adobe/spacecat-shared/issues/541)) ([2e9fca8](https://github.com/adobe/spacecat-shared/commit/2e9fca89e327b9b680b20a6105088f0e844eb54a))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-utils-v1.26.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.26.1...@adobe/spacecat-shared-utils-v1.26.2) (2025-01-12)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/sqs.js
CHANGED
|
@@ -10,9 +10,18 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { Response } from '@adobe/fetch';
|
|
13
14
|
import { SendMessageCommand, SQSClient } from '@aws-sdk/client-sqs';
|
|
14
15
|
import AWSXray from 'aws-xray-sdk';
|
|
15
|
-
|
|
16
|
+
|
|
17
|
+
import { hasText, isNonEmptyArray } from './functions.js';
|
|
18
|
+
|
|
19
|
+
function badRequest(message) {
|
|
20
|
+
return new Response('', {
|
|
21
|
+
status: 400,
|
|
22
|
+
headers: { 'x-error': message },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
16
25
|
|
|
17
26
|
/**
|
|
18
27
|
* @class SQS utility to send messages to SQS
|
|
@@ -94,24 +103,24 @@ export function sqsEventAdapter(fn) {
|
|
|
94
103
|
const { log } = context;
|
|
95
104
|
let message;
|
|
96
105
|
|
|
106
|
+
// currently not processing batch messages
|
|
107
|
+
const records = context.invocation?.event?.Records;
|
|
108
|
+
|
|
109
|
+
if (!isNonEmptyArray(records)) {
|
|
110
|
+
log.warn('Function was not invoked properly, event does not contain any records');
|
|
111
|
+
return badRequest('Event does not contain any records');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const record = records[0];
|
|
115
|
+
|
|
116
|
+
log.info(`Received ${records.length} records. ID of the first message in the batch: ${record.messageId}`);
|
|
117
|
+
|
|
97
118
|
try {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (!Array.isArray(records) || records.length === 0) {
|
|
101
|
-
throw new Error('No records found');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
log.info(`Received ${records.length} records. ID of the first message in the batch: ${records[0]?.messageId}`);
|
|
105
|
-
message = JSON.parse(records[0]?.body);
|
|
106
|
-
log.info(`Received message with id: ${records[0]?.messageId}`);
|
|
119
|
+
message = JSON.parse(record.body);
|
|
120
|
+
log.info(`Received message with id: ${record.messageId}`);
|
|
107
121
|
} catch (e) {
|
|
108
122
|
log.warn('Function was not invoked properly, message body is not a valid JSON', e);
|
|
109
|
-
return
|
|
110
|
-
status: 400,
|
|
111
|
-
headers: {
|
|
112
|
-
'x-error': 'Event does not contain a valid message body',
|
|
113
|
-
},
|
|
114
|
-
});
|
|
123
|
+
return badRequest('Event does not contain a valid message body');
|
|
115
124
|
}
|
|
116
125
|
return fn(message, context);
|
|
117
126
|
};
|