UNPKG

@message-queue-toolkit/sqs

Version:
65 lines 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deleteSqs = deleteSqs; exports.updateQueueAttributes = updateQueueAttributes; exports.updateQueueTags = updateQueueTags; exports.initSqs = initSqs; const client_sqs_1 = require("@aws-sdk/client-sqs"); const core_1 = require("@message-queue-toolkit/core"); const sqsUtils_1 = require("./sqsUtils"); async function deleteSqs(sqsClient, deletionConfig, creationConfig) { if (!deletionConfig.deleteIfExists) { return; } if ((0, core_1.isProduction)() && !deletionConfig.forceDeleteInProduction) { throw new Error('You are running autodeletion in production. This can and probably will cause a loss of data. If you are absolutely sure you want to do this, please set deletionConfig.forceDeleteInProduction to true'); } if (!creationConfig.queue.QueueName) { throw new Error('QueueName must be set for automatic deletion'); } await (0, sqsUtils_1.deleteQueue)(sqsClient, creationConfig.queue.QueueName, deletionConfig.waitForConfirmation !== false); } async function updateQueueAttributes(sqsClient, queueUrl, attributes = {}) { const command = new client_sqs_1.SetQueueAttributesCommand({ QueueUrl: queueUrl, Attributes: attributes, }); await sqsClient.send(command); } async function updateQueueTags(sqsClient, queueUrl, tags = {}) { const command = new client_sqs_1.TagQueueCommand({ QueueUrl: queueUrl, Tags: tags, }); await sqsClient.send(command); } async function initSqs(sqsClient, locatorConfig, creationConfig) { // reuse existing queue only if (locatorConfig?.queueUrl) { const checkResult = await (0, sqsUtils_1.getQueueAttributes)(sqsClient, locatorConfig.queueUrl, ['QueueArn']); if (checkResult.error === 'not_found') { throw new Error(`Queue with queueUrl ${locatorConfig.queueUrl} does not exist.`); } const queueArn = checkResult.result?.attributes?.QueueArn; if (!queueArn) { throw new Error('Queue ARN was not set'); } const queueUrl = locatorConfig.queueUrl; const splitUrl = queueUrl.split('/'); const queueName = splitUrl[splitUrl.length - 1]; return { queueArn, queueUrl, queueName }; } // create new queue if does not exist if (!creationConfig?.queue.QueueName) { throw new Error('queueConfig.QueueName is mandatory when locator is not provided'); } // create new queue const { queueUrl, queueArn } = await (0, sqsUtils_1.assertQueue)(sqsClient, creationConfig.queue, { topicArnsWithPublishPermissionsPrefix: creationConfig.topicArnsWithPublishPermissionsPrefix, updateAttributesIfExists: creationConfig.updateAttributesIfExists, forceTagUpdate: creationConfig.forceTagUpdate, }); const queueName = creationConfig.queue.QueueName; return { queueUrl, queueArn, queueName }; } //# sourceMappingURL=sqsInitter.js.map