message-brokers 1.11.0-beta.0 → 1.11.0-beta.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/README.md CHANGED
@@ -193,6 +193,33 @@ messageBrokers.publishPastDataReminderRequest(reminder_request);
193
193
  messageBrokers.publishPastDataReminderMessage(reminder_message);
194
194
  ```
195
195
 
196
+ ## RabbitMQ Utils Usage
197
+
198
+ The queue / exchange / routing key naming logic (`RABBITMQ_ISOLATED_NAMESPACE` and `RABBITMQ_DEPLOYMENT_ENV`) can be imported on its own, so other apps build the same names without duplicating it.
199
+
200
+ ```javascript
201
+ // ES5 Syntax
202
+ const {
203
+ applyExchangeName,
204
+ applyQueueName,
205
+ applyRoutingKey,
206
+ } = require("message-brokers/rabbitmq-utils");
207
+ // ES6 Syntax
208
+ import { applyExchangeName, applyQueueName, applyRoutingKey } from "message-brokers/rabbitmq-utils";
209
+
210
+ const exchange = "hv.exchange";
211
+ const queue = "billing.events";
212
+ const routingKey = "billing";
213
+
214
+ const newExchangeName = applyExchangeName(exchange); // hv.exchange.stage
215
+ const newQueueName = applyQueueName(queue); // billing.events.prod-2.stage
216
+ const newRoutingKey = applyRoutingKey(queue, routingKey); // billing-prod-2-stage
217
+ ```
218
+
219
+ The example output assumes `RABBITMQ_ISOLATED_NAMESPACE=prod-2` and `RABBITMQ_DEPLOYMENT_ENV=stage`; the namespace is only added for the isolated queues / routing keys.
220
+
221
+ The package's `exports` allow only `message-brokers`, `message-brokers/rabbitmq-utils`, `message-brokers/lib/*` and `message-brokers/package.json` to be imported.
222
+
196
223
  ## Publish options
197
224
 
198
225
  Every publish method takes an optional last argument `options` (since 1.11.0). Everything is off by default: a call without options behaves as before, except that the message now gets a `message_id`.
@@ -1,4 +1,7 @@
1
- require("dotenv").config();
1
+ // quiet: dotenv 17+ otherwise logs "injected env (n) from .env" in every app that loads the package
2
+ require("dotenv").config({
3
+ quiet: true
4
+ });
2
5
  const package_loader = require("./package-loader");
3
6
  const AmqpController = require("./controllers/amqp.controller");
4
7
  const mbConfigs = require("./configs/mb.configs");
@@ -0,0 +1,35 @@
1
+ /**
2
+ * RabbitMQ naming helpers, importable on their own:
3
+ * const { applyQueueName } = require("message-brokers/rabbitmq-utils");
4
+ *
5
+ * Names are built from RABBITMQ_ISOLATED_NAMESPACE (only for the isolated queues / routing keys
6
+ * listed in the package's mb.configs) and RABBITMQ_DEPLOYMENT_ENV (for every name).
7
+ */
8
+
9
+ /**
10
+ * Whether the queue starts with one of the isolated queue prefixes.
11
+ */
12
+ export function isIsolatedQueue(queueName: string): boolean;
13
+
14
+ /**
15
+ * Queue name with ".<RABBITMQ_ISOLATED_NAMESPACE>" (isolated queues only) and
16
+ * ".<RABBITMQ_DEPLOYMENT_ENV>" appended when they are set.
17
+ */
18
+ export function applyQueueName(queueName: string): string;
19
+
20
+ /**
21
+ * Routing key with "-<RABBITMQ_ISOLATED_NAMESPACE>" (when the queue is isolated) and
22
+ * "-<RABBITMQ_DEPLOYMENT_ENV>" appended when they are set.
23
+ */
24
+ export function applyRoutingKey(queueName: string, routingKey: string): string;
25
+
26
+ /**
27
+ * Exchange name with ".<RABBITMQ_DEPLOYMENT_ENV>" appended when it is set (exchanges are never isolated).
28
+ */
29
+ export function applyExchangeName(exchangeName: string): string;
30
+
31
+ /**
32
+ * Routing key used when publishing: "-<RABBITMQ_ISOLATED_NAMESPACE>" (when the routing key starts
33
+ * with one of the isolated routing key prefixes) and "-<RABBITMQ_DEPLOYMENT_ENV>" appended when they are set.
34
+ */
35
+ export function applyRoutingKeyIsolationForPublish(routingKey: string): string;
package/package.json CHANGED
@@ -1,19 +1,38 @@
1
1
  {
2
2
  "name": "message-brokers",
3
- "version": "1.11.0-beta.0",
3
+ "version": "1.11.0-beta.2",
4
4
  "description": "This package contains functions to publish the messages into the message brokers like rabbitmq.",
5
5
  "main": "lib/message-brokers.js",
6
6
  "types": "lib/types/message-brokers.d.ts",
7
+ "typesVersions": {
8
+ "*": {
9
+ "rabbitmq-utils": [
10
+ "lib/types/rabbitmq-utils.d.ts"
11
+ ]
12
+ }
13
+ },
7
14
  "files": [
8
15
  "lib",
9
16
  "LICENSE",
10
17
  "README.md",
11
18
  "package.json"
12
19
  ],
20
+ "exports": {
21
+ ".": {
22
+ "types": "./lib/types/message-brokers.d.ts",
23
+ "default": "./lib/message-brokers.js"
24
+ },
25
+ "./rabbitmq-utils": {
26
+ "types": "./lib/types/rabbitmq-utils.d.ts",
27
+ "default": "./lib/utils/rabbitmq.utils.js"
28
+ },
29
+ "./lib/*": "./lib/*",
30
+ "./package.json": "./package.json"
31
+ },
13
32
  "scripts": {
14
33
  "install_deps": "NODE_ENV='development' yarn",
15
- "build": "babel ./src -d ./lib && mkdir -p ./lib/types && cp ./src/types/message-brokers.d.ts ./lib/types/",
16
- "watch": "mkdir -p ./lib/types && cp ./src/types/message-brokers.d.ts ./lib/types/ && babel ./src -d ./lib --watch",
34
+ "build": "babel ./src -d ./lib && mkdir -p ./lib/types && cp ./src/types/*.d.ts ./lib/types/",
35
+ "watch": "mkdir -p ./lib/types && cp ./src/types/*.d.ts ./lib/types/ && babel ./src -d ./lib --watch",
17
36
  "prepublishOnly": "npm run build"
18
37
  },
19
38
  "repository": {
@@ -23,15 +42,15 @@
23
42
  "author": "Akif Mohammed <akiif.dev@gmail.com> (https://akiif.dev)",
24
43
  "license": "UNLICENSED",
25
44
  "dependencies": {
26
- "amqplib": "^0.10.8",
45
+ "amqplib": "^2.2.1",
27
46
  "chalk": "^5.4.1",
28
- "dotenv": "^16.5.0",
47
+ "dotenv": "^18.0.9",
29
48
  "redis": "^5.0.1"
30
49
  },
31
50
  "devDependencies": {
32
- "@babel/cli": "^7.27.2",
33
- "@babel/core": "^7.27.1",
34
- "@babel/preset-env": "^7.27.2"
51
+ "@babel/cli": "^8.1.0",
52
+ "@babel/core": "^8.1.0",
53
+ "@babel/preset-env": "^8.0.7"
35
54
  },
36
55
  "keywords": [
37
56
  "amqp",