UNPKG

@vtexlab/planner-message-bus

Version:

A Message Bus that uses AWS SNS, AWS SQS, and AWS EventBridge

46 lines (45 loc) 2.17 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.subscribeSnsTopicToQueue = exports.tagTopic = exports.createSnsTopic = void 0; const constants_1 = require("../utils/constants"); const client_sns_1 = require("@aws-sdk/client-sns"); const client = new client_sns_1.SNSClient(); function createSnsTopic(topicName) { return __awaiter(this, void 0, void 0, function* () { var _a; const commandOutput = yield client.send(new client_sns_1.CreateTopicCommand({ Name: topicName })); return (_a = commandOutput.TopicArn) !== null && _a !== void 0 ? _a : (0, constants_1.TOPIC_ARN_TEMPLATE)(topicName); }); } exports.createSnsTopic = createSnsTopic; function tagTopic(topicArn, tags) { return __awaiter(this, void 0, void 0, function* () { yield client.send(new client_sns_1.TagResourceCommand({ ResourceArn: topicArn, Tags: tags })); }); } exports.tagTopic = tagTopic; function subscribeSnsTopicToQueue(topicName, queueName) { return __awaiter(this, void 0, void 0, function* () { const commandOutput = yield client.send(new client_sns_1.SubscribeCommand({ TopicArn: (0, constants_1.TOPIC_ARN_TEMPLATE)(topicName), Endpoint: (0, constants_1.QUEUE_ARN_TEMPLATE)(queueName), Protocol: 'sqs' })); return commandOutput.SubscriptionArn; }); } exports.subscribeSnsTopicToQueue = subscribeSnsTopicToQueue;