@adobe/spacecat-shared-utils 1.21.1 → 1.22.0

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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [@adobe/spacecat-shared-utils-v1.22.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.21.1...@adobe/spacecat-shared-utils-v1.22.0) (2024-10-31)
2
+
3
+
4
+ ### Features
5
+
6
+ * support FIFO queues with the SQS sendMessage helper ([#417](https://github.com/adobe/spacecat-shared/issues/417)) ([f9df606](https://github.com/adobe/spacecat-shared/commit/f9df606d62b9e23c89b9944f7042b4804cef0599))
7
+
1
8
  # [@adobe/spacecat-shared-utils-v1.21.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.21.0...@adobe/spacecat-shared-utils-v1.21.1) (2024-10-26)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.21.1",
3
+ "version": "1.22.0",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "engines": {
package/src/sqs.js CHANGED
@@ -12,6 +12,7 @@
12
12
 
13
13
  import { SendMessageCommand, SQSClient } from '@aws-sdk/client-sqs';
14
14
  import AWSXray from 'aws-xray-sdk';
15
+ import { hasText } from './functions.js';
15
16
 
16
17
  /**
17
18
  * @class SQS utility to send messages to SQS
@@ -24,16 +25,30 @@ class SQS {
24
25
  this.log = log;
25
26
  }
26
27
 
27
- async sendMessage(queueUrl, message) {
28
+ /**
29
+ * Send a message to an SQS queue. For FIFO queues, messageGroupId is required.
30
+ * @param {string} queueUrl - The URL of the SQS queue.
31
+ * @param {object} message - The message body to send.
32
+ * @param {string} messageGroupId - (Optional) The message group ID for FIFO queues.
33
+ * @return {Promise<void>}
34
+ */
35
+ async sendMessage(queueUrl, message, messageGroupId = undefined) {
28
36
  const body = {
29
37
  ...message,
30
38
  timestamp: new Date().toISOString(),
31
39
  };
32
40
 
33
- const msgCommand = new SendMessageCommand({
41
+ const params = {
34
42
  MessageBody: JSON.stringify(body),
35
43
  QueueUrl: queueUrl,
36
- });
44
+ };
45
+
46
+ if (hasText(messageGroupId)) {
47
+ // MessageGroupId is required for FIFO queues
48
+ params.MessageGroupId = messageGroupId;
49
+ }
50
+
51
+ const msgCommand = new SendMessageCommand(params);
37
52
 
38
53
  try {
39
54
  const data = await this.sqsClient.send(msgCommand);