vtlab-generic-functions 1.0.31 → 1.0.33

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 (2) hide show
  1. package/package.json +1 -1
  2. package/sqs/index.js +32 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtlab-generic-functions",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "scripts": {
5
5
  "test": "jest"
6
6
  },
package/sqs/index.js CHANGED
@@ -161,7 +161,7 @@ const sendSQSMessageBatch = async (messages, queueUrl, isFIFOQueue = true) => {
161
161
  Entries: entries
162
162
  });
163
163
 
164
- const response = await sqsClient.send(command);
164
+ const response = await batchSQSClient.send(command);
165
165
  results.push(response);
166
166
  }
167
167
 
@@ -171,6 +171,36 @@ const sendSQSMessageBatch = async (messages, queueUrl, isFIFOQueue = true) => {
171
171
  }
172
172
  };
173
173
 
174
+ /**
175
+ * Saves multiple integration messages to an SQS queue in batch.
176
+ *
177
+ * @param {Array<Object>} documents - Array of integration message documents to be saved.
178
+ * @returns {Promise<Object>} - A promise that resolves to the response from SQS.
179
+ * @throws {Error} - Throws an error if saving the integration messages fails.
180
+ */
181
+ const saveIntegrationMessagesBatch = async (documents = []) => {
182
+ try {
183
+ if (!Array.isArray(documents)) {
184
+ throw new Error('Documents must be an array');
185
+ }
186
+
187
+ if (documents.length === 0) {
188
+ return [];
189
+ }
190
+
191
+ // Validate each document
192
+ const validatedMessages = documents.map(doc =>
193
+ validator.validate(doc, 'integrationMessages')
194
+ );
195
+
196
+ const queue = await config.get('microservices.sqs.integrationMessage');
197
+ return sendSQSMessageBatch(validatedMessages, queue, false);
198
+ } catch (error) {
199
+ throw error;
200
+ }
201
+ };
202
+
203
+
174
204
  module.exports = {
175
- saveJobEvent, saveIntegrationMessages, sendZplSqsMessage,sendSQSMessageBatch
205
+ saveJobEvent, saveIntegrationMessages, saveIntegrationMessagesBatch, sendZplSqsMessage,sendSQSMessageBatch
176
206
  };