@go-mailer/vertebra 1.0.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/index.js ADDED
@@ -0,0 +1,2 @@
1
+ const Broker = require('./lib/queue/rabbit')
2
+ module.exports.default = Broker
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ actions: {
3
+ created: 'campaign_created',
4
+ updated: 'campaign_updated',
5
+ deleted: 'campaign_deleted'
6
+ },
7
+ status : {
8
+ draft: 'draft',
9
+ paused: 'paused',
10
+ cancelled: 'cancelled',
11
+ processed: 'processed'
12
+ },
13
+ providers : {
14
+ all: 'all',
15
+ gmail: 'gmail',
16
+ yahoo: 'yahoo',
17
+ others: 'others'
18
+ }
19
+ }
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ actions: {
3
+ created: 'wallet_created',
4
+ updated: 'wallet_updated',
5
+ deleted: 'wallet_deleted'
6
+ },
7
+ }
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ actions: {
3
+ created: 'payment_created',
4
+ updated: 'payment_updated',
5
+ verified: 'payment_verified',
6
+ deleted: 'payment_deleted'
7
+ },
8
+ status: {
9
+ pending: 'pending',
10
+ successful: 'successful'
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ queue: {
3
+ AUDIT: 'audit_event',
4
+ SEND_EMAIL: "emails_to_be_sent",
5
+ NOTIFICATION: "new_notification",
6
+ EMPTY_WALLET: "insufficient_wallet_balance",
7
+ CAMPAIGN_PROCESSED: "campaign_processed",
8
+ TRANSACTIONAL_SENT: "transactional_sent",
9
+ NEW_TENANT: "new_account_created",
10
+ WALLET_TOPUP: "wallet_topup",
11
+ },
12
+ };
@@ -0,0 +1,4 @@
1
+ module.exports.class = {
2
+ campaign: 'mailing',
3
+ transactional: 'transactional'
4
+ }
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ actions: {
3
+ created: 'wallet_created',
4
+ updated: 'wallet_updated',
5
+ deleted: 'wallet_deleted'
6
+ },
7
+ }
@@ -0,0 +1,37 @@
1
+ const rabbit = require('amqplib')
2
+
3
+ const Broker = async ({
4
+ host = 'localhost',
5
+ user = 'guest',
6
+ passwd = 'guest',
7
+ port = 5672
8
+ }) => {
9
+ const url = `amqp://${user}:${passwd}@${host}:${port}`
10
+ const conn = await rabbit.connect(url)
11
+ const channel = await conn.createChannel()
12
+
13
+ const acknowledge = (message = null) => {
14
+ if (message) channel.ack(message)
15
+ else channel.ackAll()
16
+ }
17
+
18
+ const recover = async () => {
19
+ await channel.recover()
20
+ }
21
+
22
+ const publish = async (queue_name, message = {}) => {
23
+ channel.assertQueue(queue_name, {
24
+ persistent: true
25
+ })
26
+ channel.sendToQueue(queue_name, Buffer.from(message))
27
+ }
28
+
29
+ const subscribe = async (queue_name, handler = console.log) => {
30
+ channel.assertQueue(queue_name, {})
31
+ channel.consume(queue_name, handler)
32
+ }
33
+
34
+ return { acknowledge, publish, recover, subscribe }
35
+ }
36
+
37
+ module.exports = Broker
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@go-mailer/vertebra",
3
+ "version": "1.0.0",
4
+ "description": "Go-Mailer vertebra",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git@noguntuberu:go-mailer-ltd/vertebra.git"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "ISC",
16
+ "dependencies": {
17
+ "amqplib": "^0.10.3",
18
+ "dotenv": "^16.0.2"
19
+ },
20
+ "directories": {
21
+ "lib": "lib",
22
+ "test": "test"
23
+ },
24
+ "devDependencies": {}
25
+ }
package/test/index.js ADDED
@@ -0,0 +1,6 @@
1
+ const Broker = require('../lib/queue/rabbit')
2
+
3
+ Broker({}).then((channel) => {
4
+ channel.publish('test_event', 'This is a test event')
5
+ channel.subscribe('test_event')
6
+ })