@xuda.io/notification_module 1.1.97 → 1.1.98

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.
Files changed (3) hide show
  1. package/index.mjs +3 -2
  2. package/index_ms.mjs +126 -0
  3. package/package.json +1 -1
package/index.mjs CHANGED
@@ -13,6 +13,7 @@ global._conf = (
13
13
  const _common = await import(path.join(process.env.XUDA_HOME, 'common', 'xuda_node_common.mjs'));
14
14
  const module_path = path.join(process.env.XUDA_HOME, 'cpi') + (!_conf.is_debug ? '/node_modules/@xuda.io' : '');
15
15
  const db_module = await import(`${module_path}/db_module/index.mjs`);
16
+ const email_ms = await import(`${module_path}/email_module/index_ms.mjs`);
16
17
 
17
18
  //////////////////// FCM /////////////////////
18
19
  const serviceAccount = _conf.firebase_serviceAccount;
@@ -149,8 +150,8 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
149
150
  send_result[uid] = false;
150
151
  return;
151
152
  }
152
- const email_module = await import(`${module_path}/email_module/index.mjs`);
153
- email_module.send_email({
153
+
154
+ email_ms.send_email({
154
155
  email: obj.email,
155
156
  subject,
156
157
  body,
package/index_ms.mjs ADDED
@@ -0,0 +1,126 @@
1
+ // =====================================================
2
+ // Queue wrapper – generated from index.mjs
3
+ // Queue target : notification_module
4
+ // =====================================================
5
+
6
+ import amqplib from 'amqplib';
7
+ import { randomUUID } from 'crypto';
8
+
9
+ let queue={}
10
+
11
+ // --- AMQP Connection & Channel ---
12
+ const conn = await amqplib.connect('amqp://localhost');
13
+ const channel = await conn.createChannel();
14
+ await channel.assertQueue(`_notification_module-${global.module_in}_ch`, { durable: false });
15
+
16
+ channel.consume(`_notification_module-${global.module_in}_ch`, async (msg) => {
17
+ try{
18
+
19
+
20
+ if (msg === null) {
21
+ console.log('Consumer cancelled by server');
22
+ return;
23
+ }
24
+
25
+ const content = JSON.parse(msg.content.toString());
26
+
27
+ queue[content.queue_id].resolve(content.ret)
28
+
29
+ channel.ack(msg);
30
+ } catch (err) {
31
+ channel.ack(msg); // Acknowledge to prevent requeue loops on error
32
+ console.error(module_in, content.method, err.message, err);
33
+ // debugger;
34
+ }
35
+ });
36
+
37
+
38
+ const send_to_queue =async function(ms_method, ...args) {
39
+
40
+ const queue_id = randomUUID();
41
+ return new Promise((resolve,reject)=>{
42
+
43
+ queue[queue_id] = { resolve, reject };
44
+
45
+ // Set timeout to prevent hanging
46
+ const timeout = setTimeout(() => {
47
+ delete queue[queue_id];
48
+ reject(new Error(`Queue timeout for ${ms_method}`));
49
+ }, 30000); // 30 second timeout
50
+
51
+ // Wrap resolve to clean up
52
+ queue[queue_id].resolve = (value) => {
53
+ clearTimeout(timeout);
54
+ delete queue[queue_id];
55
+ resolve(value);
56
+ };
57
+
58
+ // Wrap reject to clean up
59
+ queue[queue_id].reject = (error) => {
60
+ clearTimeout(timeout);
61
+ delete queue[queue_id];
62
+ reject(error);
63
+ };
64
+
65
+ global[`_${global.module_in}_ch`].sendToQueue(
66
+ 'notification_module',
67
+ Buffer.from(
68
+ JSON.stringify({
69
+ ms_method,
70
+ data: args,
71
+ cb:`_notification_module-${global.module_in}_ch`,
72
+ queue_id
73
+ })
74
+ )
75
+ );
76
+
77
+ })
78
+
79
+ };
80
+
81
+ // You must define this somewhere before using these wrappers:
82
+ const module_name = 'notification_module';
83
+
84
+ export const get_new_notification_count = async function (...args) {
85
+ return await send_to_queue("get_new_notification_count", ...args);
86
+ };
87
+
88
+ export const set_notification_read = async function (...args) {
89
+ return await send_to_queue("set_notification_read", ...args);
90
+ };
91
+
92
+ export const update_notification_status = async function (...args) {
93
+ return await send_to_queue("update_notification_status", ...args);
94
+ };
95
+
96
+ export const submit_notification = async function (...args) {
97
+ return await send_to_queue("submit_notification", ...args);
98
+ };
99
+
100
+ export const get_notifications = async function (...args) {
101
+ return await send_to_queue("get_notifications", ...args);
102
+ };
103
+
104
+ export const submit_superuser_notification = async function (...args) {
105
+ return await send_to_queue("submit_superuser_notification", ...args);
106
+ };
107
+
108
+ export const submit_app_notification = async function (...args) {
109
+ return await send_to_queue("submit_app_notification", ...args);
110
+ };
111
+
112
+ export const update_system_notification = async function (...args) {
113
+ return await send_to_queue("update_system_notification", ...args);
114
+ };
115
+
116
+ export const submit_topic_app_notification = async function (...args) {
117
+ return await send_to_queue("submit_topic_app_notification", ...args);
118
+ };
119
+
120
+ export const get_system_notifications = async function (...args) {
121
+ return await send_to_queue("get_system_notifications", ...args);
122
+ };
123
+
124
+ export const notifications_validation_fx = async function (...args) {
125
+ return await send_to_queue("notifications_validation_fx", ...args);
126
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/notification_module",
3
- "version": "1.1.97",
3
+ "version": "1.1.98",
4
4
  "description": "Xuda Notification Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {