@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.
Files changed (3) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +1 -1
  3. 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.26.2",
3
+ "version": "1.26.4",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "engines": {
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
- import { hasText } from './functions.js';
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
- // currently not publishing batch messages
99
- const records = context.invocation?.event?.Records;
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 new Response('', {
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
  };