@xuda.io/notification_module 1.1.97 → 1.1.99
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.mjs +8 -16
- package/index_ms.mjs +130 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -13,6 +13,8 @@ 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`);
|
|
17
|
+
const ws_dashboard_ms = await import(`${module_path}/ws_dashboard_module/index_ms.mjs`);
|
|
16
18
|
|
|
17
19
|
//////////////////// FCM /////////////////////
|
|
18
20
|
const serviceAccount = _conf.firebase_serviceAccount;
|
|
@@ -52,20 +54,10 @@ export const update_notification_status = async (req) => {
|
|
|
52
54
|
notification_doc.stat_ts = Date.now();
|
|
53
55
|
notification_doc.stat = stat;
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
method: 'notification',
|
|
60
|
-
|
|
61
|
-
data: {
|
|
62
|
-
to: notification_doc.system ? uid : notification_doc.uid,
|
|
63
|
-
data: notification_doc,
|
|
64
|
-
},
|
|
65
|
-
}),
|
|
66
|
-
),
|
|
67
|
-
);
|
|
68
|
-
|
|
57
|
+
ws_dashboard_ms.notification({
|
|
58
|
+
to: notification_doc.system ? uid : notification_doc.uid,
|
|
59
|
+
data: notification_doc,
|
|
60
|
+
});
|
|
69
61
|
return await db_module.save_couch_doc('xuda_notification', notification_doc);
|
|
70
62
|
};
|
|
71
63
|
|
|
@@ -149,8 +141,8 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
149
141
|
send_result[uid] = false;
|
|
150
142
|
return;
|
|
151
143
|
}
|
|
152
|
-
|
|
153
|
-
|
|
144
|
+
|
|
145
|
+
email_ms.send_email({
|
|
154
146
|
email: obj.email,
|
|
155
147
|
subject,
|
|
156
148
|
body,
|
package/index_ms.mjs
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
}, 300000); // 300 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
|
+
try{
|
|
66
|
+
global[`_${global.module_in}_ch`].sendToQueue(
|
|
67
|
+
'notification_module',
|
|
68
|
+
Buffer.from(
|
|
69
|
+
JSON.stringify({
|
|
70
|
+
ms_method,
|
|
71
|
+
data: args,
|
|
72
|
+
cb:`_notification_module-${global.module_in}_ch`,
|
|
73
|
+
queue_id
|
|
74
|
+
})
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
}catch(err){
|
|
79
|
+
debugger
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// You must define this somewhere before using these wrappers:
|
|
86
|
+
const module_name = 'notification_module';
|
|
87
|
+
|
|
88
|
+
export const get_new_notification_count = async function (...args) {
|
|
89
|
+
return await send_to_queue("get_new_notification_count", ...args);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const set_notification_read = async function (...args) {
|
|
93
|
+
return await send_to_queue("set_notification_read", ...args);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const update_notification_status = async function (...args) {
|
|
97
|
+
return await send_to_queue("update_notification_status", ...args);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const submit_notification = async function (...args) {
|
|
101
|
+
return await send_to_queue("submit_notification", ...args);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const get_notifications = async function (...args) {
|
|
105
|
+
return await send_to_queue("get_notifications", ...args);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const submit_superuser_notification = async function (...args) {
|
|
109
|
+
return await send_to_queue("submit_superuser_notification", ...args);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const submit_app_notification = async function (...args) {
|
|
113
|
+
return await send_to_queue("submit_app_notification", ...args);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const update_system_notification = async function (...args) {
|
|
117
|
+
return await send_to_queue("update_system_notification", ...args);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const submit_topic_app_notification = async function (...args) {
|
|
121
|
+
return await send_to_queue("submit_topic_app_notification", ...args);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const get_system_notifications = async function (...args) {
|
|
125
|
+
return await send_to_queue("get_system_notifications", ...args);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const notifications_validation_fx = async function (...args) {
|
|
129
|
+
return await send_to_queue("notifications_validation_fx", ...args);
|
|
130
|
+
};
|