ac-sqs 3.3.0 → 3.3.2

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,20 @@
1
+
2
+ ## [3.3.2](https://github.com/admiralcloud/ac-sqs/compare/v3.3.1..v3.3.2) (2025-09-26 20:15:26)
3
+
4
+
5
+ ### Bug Fix
6
+
7
+ * **App:** Several minor improvement for createQueues | MP | [ef2abc7c6bc2f08e1328cb1c94be479362836323](https://github.com/admiralcloud/ac-sqs/commit/ef2abc7c6bc2f08e1328cb1c94be479362836323)
8
+ Several minor improvement for createQueues
9
+
10
+ ## [3.3.1](https://github.com/admiralcloud/ac-sqs/compare/v3.3.0..v3.3.1) (2025-09-26 17:45:21)
11
+
12
+
13
+ ### Bug Fix
14
+
15
+ * **App:** Fixed createSQSlists function | MP | [246023f5eb622a33b7a261d45d68080bcfa29be6](https://github.com/admiralcloud/ac-sqs/commit/246023f5eb622a33b7a261d45d68080bcfa29be6)
16
+ Improved with logging and improved function names
17
+ Related issues:
1
18
 
2
19
  # [3.3.0](https://github.com/admiralcloud/ac-sqs/compare/v3.2.2..v3.3.0) (2025-09-26 17:27:53)
3
20
 
package/README.md CHANGED
@@ -112,7 +112,7 @@ An array of metadata to get. By default only "ApproximateNumberOfMessages" is re
112
112
 
113
113
  https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_GetQueueAttributes.html
114
114
 
115
- ## createQueue
115
+ ## createQueues
116
116
  Call with all lists and let the function check if the queues exist. If not, the missing queue is created.
117
117
 
118
118
  # Test
package/index.js CHANGED
@@ -2,7 +2,7 @@ const _ = require('lodash')
2
2
  const { v4: uuidV4 } = require('uuid')
3
3
  const { setTimeout: sleep } = require('timers/promises')
4
4
 
5
- const { SQSClient, SendMessageCommand, SendMessageBatchCommand, ReceiveMessageCommand, DeleteMessageBatchCommand, GetQueueAttributesCommand, ChangeMessageVisibilityBatchCommand } = require('@aws-sdk/client-sqs')
5
+ const { SQSClient, SendMessageCommand, SendMessageBatchCommand, ReceiveMessageCommand, DeleteMessageBatchCommand, GetQueueAttributesCommand, ChangeMessageVisibilityBatchCommand, GetQueueUrlCommand, CreateQueueCommand } = require('@aws-sdk/client-sqs')
6
6
  const { S3Client, GetObjectCommand, PutObjectCommand, DeleteObjectsCommand } = require("@aws-sdk/client-s3")
7
7
 
8
8
  class ACSQS {
@@ -146,9 +146,10 @@ class ACSQS {
146
146
  ReceiptHandle: messageData.receiptHandle,
147
147
  VisibilityTimeout: visibilityTimeout
148
148
  }))
149
+ const { queueUrl } = this.getQueueUrl(config)
149
150
 
150
151
  return {
151
- QueueUrl: await this.getQueueUrl(config),
152
+ QueueUrl: queueUrl,
152
153
  Entries: entries
153
154
  }
154
155
  }
@@ -318,14 +319,18 @@ class ACSQS {
318
319
  return response
319
320
  }
320
321
 
321
- async getQueueUrl({ name, fifo, localPrefix, suffix }) {
322
- let queueUrl = `https://sqs.${this.region}.amazonaws.com/${this.account}/`
323
- if (localPrefix) queueUrl += `local_${localPrefix}_`
324
- if (process.env['NODE_ENV'] === 'test') queueUrl += 'test_'
325
- queueUrl += name
326
- if (suffix) queueUrl += suffix
327
- if (fifo) queueUrl += '.fifo'
328
- return queueUrl
322
+ getQueueUrl({ name, fifo, localPrefix, suffix }) {
323
+ // Build queue name using array filtering for cleaner concatenation
324
+ const queueName = [
325
+ localPrefix && `local_${localPrefix}_`,
326
+ process.env['NODE_ENV'] === 'test' && 'test_',
327
+ name,
328
+ suffix,
329
+ fifo && '.fifo'
330
+ ].filter(Boolean).join('')
331
+
332
+ const queueUrl = `https://sqs.${this.region}.amazonaws.com/${this.account}/${queueName}`
333
+ return { queueName, queueUrl }
329
334
  }
330
335
 
331
336
  async getQueueAttributes({ name, attributes = ['ApproximateNumberOfMessages'], throwError }) {
@@ -334,8 +339,9 @@ class ACSQS {
334
339
  this.logger.error('ACSQS | getQueueAttributes | configurationMissing | %s', name)
335
340
  throw new Error('configurationForListMissing')
336
341
  }
342
+ const { queueUrl } = this.getQueueUrl(config)
337
343
  let sqsParams = {
338
- QueueUrl: await this.getQueueUrl(config),
344
+ QueueUrl: queueUrl,
339
345
  AttributeNames: attributes
340
346
  }
341
347
  if (config.debug) this.logger.debug('ACSQS | getQueueAttributes | Payload %j', sqsParams)
@@ -349,7 +355,7 @@ class ACSQS {
349
355
  }
350
356
  }
351
357
 
352
- async createQueue({ lists }) {
358
+ async createQueues({ lists, debug }) {
353
359
  for (const list of lists) {
354
360
  const config = _.find(this.availableLists, { name: list.name })
355
361
  if (!config) {
@@ -357,14 +363,34 @@ class ACSQS {
357
363
  throw new Error('configurationForListMissing')
358
364
  }
359
365
 
360
- const queueUrl = await this.getQueueUrl(config)
361
- const command = new CreateQueueCommand({ QueueName: queueUrl })
366
+ const { queueName } = this.getQueueUrl(config)
367
+ if (debug) this.logger.info('ACSQS | createQueues | %s | %s', list.name, queueName)
368
+ const input = {
369
+ QueueName: queueName
370
+ }
371
+ const checkCommand = new GetQueueUrlCommand(input)
362
372
  try {
363
- await this.sqs.send(command)
373
+ await this.sqs.send(checkCommand)
374
+ continue
364
375
  }
365
- catch(e) {
366
- this.logger.error('AWS | createQueue | %s | %s', list.name, e?.message)
367
- if (this.throwError) throw e
376
+ catch {
377
+ if (!_.isEmpty(_.get(config, 'attributes'))) {
378
+ input.Attributes = config.attributes
379
+ }
380
+ if (config?.fifo) input.Attributes = { ...input.Attributes, FifoQueue: 'true' }
381
+ if (config?.visibilityTimeout) input.Attributes = { ...input.Attributes, VisibilityTimeout: config.visibilityTimeout }
382
+ if (config?.delay) input.Attributes = { ...input.Attributes, DelaySeconds: config.delay }
383
+
384
+
385
+ const command = new CreateQueueCommand(input)
386
+ try {
387
+ await this.sqs.send(command)
388
+ if (debug) this.logger.info('ACSQS | createQueues | Created | %s | %s', list.name, queueName)
389
+ }
390
+ catch(e) {
391
+ this.logger.error('AWS | createQueue | %s | %s', list.name, e?.message)
392
+ if (this.throwError) throw e
393
+ }
368
394
  }
369
395
  }
370
396
  }
@@ -390,8 +416,9 @@ class ACSQS {
390
416
  message = `s3:${key}`
391
417
  }
392
418
 
419
+ const { queueUrl } = this.getQueueUrl(config)
393
420
  const sqsParams = {
394
- QueueUrl: await this.getQueueUrl(config),
421
+ QueueUrl: queueUrl,
395
422
  MessageBody: message
396
423
  }
397
424
  if (messageGroupId) _.set(sqsParams, 'MessageGroupId', messageGroupId)
@@ -448,8 +475,9 @@ class ACSQS {
448
475
  return item
449
476
  })
450
477
 
478
+ const { queueUrl } = this.getQueueUrl(config)
451
479
  const sqsParams = {
452
- QueueUrl: await this.getQueueUrl(config),
480
+ QueueUrl: queueUrl,
453
481
  Entries: entries
454
482
  }
455
483
  if (debug || config.debug) this.logger.error('ACSQS | sendSQSMessageBatch | Payload %j', sqsParams)
@@ -473,8 +501,9 @@ class ACSQS {
473
501
  }
474
502
  const visibilityTimeout = _.get(config, 'visibilityTimeout') // if set, will activate visibilityTimeout management
475
503
 
504
+ const { queueUrl } = this.getQueueUrl(config)
476
505
  const sqsParams = {
477
- QueueUrl: await this.getQueueUrl(config),
506
+ QueueUrl: queueUrl,
478
507
  MaxNumberOfMessages: _.get(config, 'batchSize', 10),
479
508
  VisibilityTimeout: _.get(config, 'visibilityTimeout', 30),
480
509
  WaitTimeSeconds: _.get(config, 'waitTime', 20)
@@ -539,8 +568,9 @@ class ACSQS {
539
568
  this.removeVisibilityTracking(messageId)
540
569
  }
541
570
 
542
- let sqsParams = {
543
- QueueUrl: await this.getQueueUrl(config),
571
+ const { queueUrl } = this.getQueueUrl(config)
572
+ const sqsParams = {
573
+ QueueUrl: queueUrl,
544
574
  Entries: entries
545
575
  }
546
576
  if (debug || config.debug) this.logger.debug('ACSQS | deleteSQSMessages | Payload %j', sqsParams)
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Mark Poepping (https://www.admiralcloud.com)",
4
4
  "license": "MIT",
5
5
  "repository": "admiralcloud/ac-sqs",
6
- "version": "3.3.0",
6
+ "version": "3.3.2",
7
7
  "dependencies": {
8
8
  "@aws-sdk/client-s3": "^3.896.0",
9
9
  "@aws-sdk/client-sqs": "^3.896.0",