docta-package 1.2.11 → 1.2.12
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/build/config.d.ts +1 -0
- package/build/config.js +2 -1
- package/build/enums/exchanges.d.ts +3 -0
- package/build/enums/exchanges.js +7 -0
- package/build/enums/index.d.ts +3 -0
- package/build/enums/index.js +3 -0
- package/build/enums/queues.d.ts +3 -0
- package/build/enums/queues.js +7 -0
- package/build/enums/routing-keys.d.ts +4 -0
- package/build/enums/routing-keys.js +8 -0
- package/build/rabbitmq/events/patient-created.d.ts +6 -0
- package/build/rabbitmq/events/patient-created.js +2 -0
- package/build/rabbitmq/index.d.ts +2 -0
- package/build/rabbitmq/index.js +18 -0
- package/build/rabbitmq/publisher.d.ts +8 -0
- package/build/rabbitmq/publisher.js +99 -0
- package/package.json +3 -1
package/build/config.d.ts
CHANGED
package/build/config.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGeneralConfig = void 0;
|
|
4
4
|
const getGeneralConfig = () => {
|
|
5
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
6
6
|
return ({
|
|
7
7
|
accessTokenSecret: (_a = process.env.ACCESS_TOKEN_SECRET) !== null && _a !== void 0 ? _a : "",
|
|
8
8
|
refreshTokenSecret: (_b = process.env.REFRESH_TOKEN_SECRET) !== null && _b !== void 0 ? _b : "",
|
|
@@ -14,6 +14,7 @@ const getGeneralConfig = () => {
|
|
|
14
14
|
awsS3Region: (_h = process.env.AWS_S3_REGION) !== null && _h !== void 0 ? _h : "",
|
|
15
15
|
forgotPasswordTokenSecret: (_j = process.env.FORGOT_PASSWORD_TOKEN_SECRET) !== null && _j !== void 0 ? _j : "",
|
|
16
16
|
activationTokenSecret: (_k = process.env.ACTIVATION_TOKEN_SECRET) !== null && _k !== void 0 ? _k : "",
|
|
17
|
+
rabbitmqHost: (_l = process.env.RABBITMQ_HOST) !== null && _l !== void 0 ? _l : "",
|
|
17
18
|
});
|
|
18
19
|
};
|
|
19
20
|
exports.getGeneralConfig = getGeneralConfig;
|
package/build/enums/index.d.ts
CHANGED
package/build/enums/index.js
CHANGED
|
@@ -18,3 +18,6 @@ __exportStar(require("./language-levels"), exports);
|
|
|
18
18
|
__exportStar(require("./status-codes"), exports);
|
|
19
19
|
__exportStar(require("./user-role"), exports);
|
|
20
20
|
__exportStar(require("./gender"), exports);
|
|
21
|
+
__exportStar(require("./routing-keys"), exports);
|
|
22
|
+
__exportStar(require("./exchanges"), exports);
|
|
23
|
+
__exportStar(require("./queues"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RoutingKey = void 0;
|
|
4
|
+
var RoutingKey;
|
|
5
|
+
(function (RoutingKey) {
|
|
6
|
+
RoutingKey["PATIENT_CREATED"] = "patient.created";
|
|
7
|
+
RoutingKey["DOCTOR_CREATED"] = "doctor.created";
|
|
8
|
+
})(RoutingKey || (exports.RoutingKey = RoutingKey = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./publisher"), exports);
|
|
18
|
+
__exportStar(require("./events/patient-created"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RoutingKey } from "../enums";
|
|
2
|
+
interface PublishOptions<T> {
|
|
3
|
+
exchange: string;
|
|
4
|
+
routingKey: RoutingKey;
|
|
5
|
+
message: T;
|
|
6
|
+
}
|
|
7
|
+
export declare function publishToTopicExchange<T>({ exchange, routingKey, message, }: PublishOptions<T>): Promise<void>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.publishToTopicExchange = publishToTopicExchange;
|
|
16
|
+
const amqplib_1 = __importDefault(require("amqplib"));
|
|
17
|
+
const config_1 = require("../config");
|
|
18
|
+
function publishToTopicExchange(_a) {
|
|
19
|
+
return __awaiter(this, arguments, void 0, function* ({ exchange, routingKey, message, }) {
|
|
20
|
+
try {
|
|
21
|
+
// Connect to RabbitMQ server
|
|
22
|
+
const connection = yield amqplib_1.default.connect((0, config_1.getGeneralConfig)().rabbitmqHost); // Replace with your RabbitMQ URL
|
|
23
|
+
const channel = yield connection.createChannel();
|
|
24
|
+
// Assert the topic exchange exists
|
|
25
|
+
yield channel.assertExchange(exchange, "topic", { durable: true });
|
|
26
|
+
// Convert the object message to a Buffer
|
|
27
|
+
const messageBuffer = Buffer.from(JSON.stringify(message));
|
|
28
|
+
// Publish the message
|
|
29
|
+
const published = channel.publish(exchange, routingKey, messageBuffer);
|
|
30
|
+
console.log(published
|
|
31
|
+
? `Message sent to exchange "${exchange}" with routing key "${routingKey}"`
|
|
32
|
+
: "Message could not be published");
|
|
33
|
+
// Close channel and connection
|
|
34
|
+
yield channel.close();
|
|
35
|
+
yield connection.close();
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error("Error publishing message:", error);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// import amqp from "amqplib";
|
|
43
|
+
// interface ListenerOptions<T> {
|
|
44
|
+
// exchange: string;
|
|
45
|
+
// queue: string;
|
|
46
|
+
// routingKeys: string[];
|
|
47
|
+
// }
|
|
48
|
+
// export async function listenToQueue<T>({
|
|
49
|
+
// exchange,
|
|
50
|
+
// queue,
|
|
51
|
+
// routingKeys,
|
|
52
|
+
// }: ListenerOptions<T>) {
|
|
53
|
+
// try {
|
|
54
|
+
// const connection = await amqp.connect("amqp://localhost");
|
|
55
|
+
// const channel = await connection.createChannel();
|
|
56
|
+
// await channel.assertExchange(exchange, "topic", { durable: true });
|
|
57
|
+
// await channel.assertQueue(queue, { durable: true });
|
|
58
|
+
// // Bind queue to each routing key
|
|
59
|
+
// for (const key of routingKeys) {
|
|
60
|
+
// await channel.bindQueue(queue, exchange, key);
|
|
61
|
+
// console.log(`✅ Bound queue "${queue}" to routing key "${key}"`);
|
|
62
|
+
// }
|
|
63
|
+
// console.log(
|
|
64
|
+
// `🎧 Listening on "${queue}" for routing keys: [${routingKeys.join(", ")}]`
|
|
65
|
+
// );
|
|
66
|
+
// await channel.consume(
|
|
67
|
+
// queue,
|
|
68
|
+
// (msg) => {
|
|
69
|
+
// if (!msg) return;
|
|
70
|
+
// const routingKey = msg.fields.routingKey;
|
|
71
|
+
// const content = msg.content.toString();
|
|
72
|
+
// try {
|
|
73
|
+
// const data: T = JSON.parse(content);
|
|
74
|
+
// // Handle messages based on routing key
|
|
75
|
+
// switch (routingKey) {
|
|
76
|
+
// case "user.created":
|
|
77
|
+
// console.log("👤 User created:", data);
|
|
78
|
+
// break;
|
|
79
|
+
// case "user.updated":
|
|
80
|
+
// console.log("✏️ User updated:", data);
|
|
81
|
+
// break;
|
|
82
|
+
// case "user.deleted":
|
|
83
|
+
// console.log("🗑️ User deleted:", data);
|
|
84
|
+
// break;
|
|
85
|
+
// default:
|
|
86
|
+
// console.warn("⚠️ Unhandled routing key:", routingKey, data);
|
|
87
|
+
// }
|
|
88
|
+
// channel.ack(msg);
|
|
89
|
+
// } catch (err) {
|
|
90
|
+
// console.error("❌ Failed to process message:", err);
|
|
91
|
+
// channel.nack(msg, false, true);
|
|
92
|
+
// }
|
|
93
|
+
// },
|
|
94
|
+
// { noAck: false }
|
|
95
|
+
// );
|
|
96
|
+
// } catch (error) {
|
|
97
|
+
// console.error("Error setting up listener:", error);
|
|
98
|
+
// }
|
|
99
|
+
// }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docta-package",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
4
4
|
"description": "This package will contail all the required files to run the docta micro-service app",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@aws-sdk/client-s3": "^3.908.0",
|
|
31
31
|
"@aws-sdk/s3-request-presigner": "^3.908.0",
|
|
32
|
+
"@types/amqplib": "^0.10.7",
|
|
33
|
+
"amqplib": "^0.10.9",
|
|
32
34
|
"bcryptjs": "^3.0.2",
|
|
33
35
|
"class-transformer": "^0.5.1",
|
|
34
36
|
"class-validator": "^0.14.2",
|