@xuda.io/notification_module 1.1.102 → 1.1.104
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 +18 -18
- package/index_ms.mjs +22 -83
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ global._conf = (
|
|
|
12
12
|
|
|
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
|
-
const
|
|
15
|
+
const db_ms = await import(`${module_path}/db_module/index_ms.mjs`);
|
|
16
16
|
const email_ms = await import(`${module_path}/email_module/index_ms.mjs`);
|
|
17
17
|
const ws_dashboard_ms = await import(`${module_path}/ws_dashboard_module/index_ms.mjs`);
|
|
18
18
|
|
|
@@ -26,7 +26,7 @@ const messaging = admin.messaging();
|
|
|
26
26
|
//////////////////////////////////////////////
|
|
27
27
|
|
|
28
28
|
export const get_new_notification_count = async (req) => {
|
|
29
|
-
return await
|
|
29
|
+
return await db_ms.get_couch_view('xuda_notification', 'new_notifications_count', {
|
|
30
30
|
key: [req.uid],
|
|
31
31
|
reduce: true,
|
|
32
32
|
group_level: 1,
|
|
@@ -34,7 +34,7 @@ export const get_new_notification_count = async (req) => {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export const set_notification_read = async (req, job_id, header) => {
|
|
37
|
-
const ret = await
|
|
37
|
+
const ret = await db_ms.get_couch_doc('xuda_notification', req.notification_id);
|
|
38
38
|
let notification_doc = ret.data;
|
|
39
39
|
|
|
40
40
|
if (notification_doc.system) {
|
|
@@ -44,12 +44,12 @@ export const set_notification_read = async (req, job_id, header) => {
|
|
|
44
44
|
notification_doc.read_date = Date.now();
|
|
45
45
|
notification_doc.read = true;
|
|
46
46
|
notification_doc.read_header = header;
|
|
47
|
-
return await
|
|
47
|
+
return await db_ms.save_couch_doc('xuda_notification', notification_doc);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
export const update_notification_status = async (req) => {
|
|
51
51
|
const { notification_id, stat, uid } = req;
|
|
52
|
-
const ret = await
|
|
52
|
+
const ret = await db_ms.get_couch_doc('xuda_notification', notification_id);
|
|
53
53
|
let notification_doc = ret.data;
|
|
54
54
|
notification_doc.stat_ts = Date.now();
|
|
55
55
|
notification_doc.stat = stat;
|
|
@@ -58,7 +58,7 @@ export const update_notification_status = async (req) => {
|
|
|
58
58
|
to: notification_doc.system ? uid : notification_doc.uid,
|
|
59
59
|
data: notification_doc,
|
|
60
60
|
});
|
|
61
|
-
return await
|
|
61
|
+
return await db_ms.save_couch_doc('xuda_notification', notification_doc);
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
export const submit_notification = async (req, _ch = global[`_notification_module_ch`]) => {
|
|
@@ -69,7 +69,7 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
69
69
|
let icon = 'https://dev.xuda.io/dist/images/xuda_ico.png';
|
|
70
70
|
if (app_id) {
|
|
71
71
|
const app_id_reference = await _common.get_project_app_id(app_id, true);
|
|
72
|
-
const app_ret = await
|
|
72
|
+
const app_ret = await db_ms.get_couch_doc('xuda_master', app_id_reference);
|
|
73
73
|
if (app_ret.code > -1) {
|
|
74
74
|
icon = app_ret.data.app_pic;
|
|
75
75
|
}
|
|
@@ -105,7 +105,7 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
105
105
|
for await (let delivery_method_item of delivery_method) {
|
|
106
106
|
let account_ret;
|
|
107
107
|
if (!system) {
|
|
108
|
-
account_ret = await
|
|
108
|
+
account_ret = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
109
109
|
if (account_ret.code < 0) {
|
|
110
110
|
throw new Error(`user ${uid} not found`);
|
|
111
111
|
}
|
|
@@ -162,7 +162,7 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
162
162
|
break;
|
|
163
163
|
case 'push':
|
|
164
164
|
try {
|
|
165
|
-
const ret = await
|
|
165
|
+
const ret = await db_ms.find_couch_query('xuda_sessions', {
|
|
166
166
|
selector: {
|
|
167
167
|
docType: 'gtp_session',
|
|
168
168
|
stat: { $lt: 3 },
|
|
@@ -232,7 +232,7 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
232
232
|
break;
|
|
233
233
|
}
|
|
234
234
|
obj.sent = send_result[uid];
|
|
235
|
-
const ret = await
|
|
235
|
+
const ret = await db_ms.save_couch_doc('xuda_notification', obj);
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
return { code: 1, data: obj };
|
|
@@ -355,7 +355,7 @@ export const get_notifications = async (req) => {
|
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
try {
|
|
358
|
-
let ret = await
|
|
358
|
+
let ret = await db_ms.find_couch_query('xuda_notification', opt);
|
|
359
359
|
let data = { docs: [] };
|
|
360
360
|
if (ret.docs) {
|
|
361
361
|
for await (let doc of ret.docs) {
|
|
@@ -390,7 +390,7 @@ export const submit_superuser_notification = async (req) => {
|
|
|
390
390
|
|
|
391
391
|
if (_.isEmpty(to_uid)) {
|
|
392
392
|
if (!system) {
|
|
393
|
-
const all_users = await
|
|
393
|
+
const all_users = await db_ms.find_couch_query('xuda_accounts', {
|
|
394
394
|
selector: {
|
|
395
395
|
docType: 'account',
|
|
396
396
|
stat: { $lt: 4 },
|
|
@@ -472,7 +472,7 @@ export const submit_app_notification = async (req) => {
|
|
|
472
472
|
|
|
473
473
|
export const update_system_notification = async (req) => {
|
|
474
474
|
const { display_type, subject, body, delivery_method, uid, type } = req;
|
|
475
|
-
const ret = await
|
|
475
|
+
const ret = await db_ms.get_couch_doc('xuda_notification', req._id);
|
|
476
476
|
let notification_doc = ret.data;
|
|
477
477
|
|
|
478
478
|
if (!notification_doc.system) {
|
|
@@ -500,7 +500,7 @@ export const update_system_notification = async (req) => {
|
|
|
500
500
|
data: notification_doc,
|
|
501
501
|
});
|
|
502
502
|
|
|
503
|
-
return await
|
|
503
|
+
return await db_ms.save_couch_doc('xuda_notification', notification_doc);
|
|
504
504
|
};
|
|
505
505
|
|
|
506
506
|
export const submit_topic_app_notification = async (req, _ch) => {
|
|
@@ -554,16 +554,16 @@ export const get_system_notifications = async (req) => {
|
|
|
554
554
|
};
|
|
555
555
|
|
|
556
556
|
export const notifications_validation_fx = async (notification_id) => {
|
|
557
|
-
let { code, data: doc } = await
|
|
557
|
+
let { code, data: doc } = await db_ms.get_couch_doc('xuda_notification', notification_id);
|
|
558
558
|
const delete_notification = async () => {
|
|
559
559
|
doc.stat = 4;
|
|
560
|
-
await
|
|
560
|
+
await db_ms.save_couch_doc('xuda_notification', doc);
|
|
561
561
|
};
|
|
562
562
|
const read_notification = async () => {
|
|
563
563
|
doc.read = true;
|
|
564
564
|
doc.read_ts = Date.now();
|
|
565
565
|
doc.read_note = 'read by notifications_validation_fx';
|
|
566
|
-
await
|
|
566
|
+
await db_ms.save_couch_doc('xuda_notification', doc);
|
|
567
567
|
};
|
|
568
568
|
|
|
569
569
|
if (code < 0) return false;
|
|
@@ -574,7 +574,7 @@ export const notifications_validation_fx = async (notification_id) => {
|
|
|
574
574
|
}
|
|
575
575
|
const fx = {
|
|
576
576
|
new_version_available: async () => {
|
|
577
|
-
const { code, data: app_doc } = await
|
|
577
|
+
const { code, data: app_doc } = await db_ms.get_app_obj(doc.app_id);
|
|
578
578
|
if (app_doc.app_build_id >= doc.params.build) {
|
|
579
579
|
await read_notification();
|
|
580
580
|
return false;
|
package/index_ms.mjs
CHANGED
|
@@ -3,121 +3,60 @@
|
|
|
3
3
|
// Queue target : notification_module
|
|
4
4
|
// =====================================================
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
channel.consume(`_notification_module-${global.module_in}_ch`, async (msg) => {
|
|
17
|
-
try {
|
|
18
|
-
if (msg === null) {
|
|
19
|
-
console.log('Consumer cancelled by server');
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const content = JSON.parse(msg.content.toString());
|
|
24
|
-
|
|
25
|
-
queue[content.queue_id].resolve(content.ret);
|
|
26
|
-
|
|
27
|
-
channel.ack(msg);
|
|
28
|
-
} catch (err) {
|
|
29
|
-
channel.ack(msg); // Acknowledge to prevent requeue loops on error
|
|
30
|
-
console.error(module_in, content.method, err.message, err);
|
|
31
|
-
// debugger;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const send_to_queue = async function (ms_method, ...args) {
|
|
36
|
-
const queue_id = randomUUID();
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
queue[queue_id] = { resolve, reject };
|
|
39
|
-
|
|
40
|
-
// Set timeout to prevent hanging
|
|
41
|
-
const timeout = setTimeout(() => {
|
|
42
|
-
delete queue[queue_id];
|
|
43
|
-
reject(new Error(`Queue timeout for ${ms_method}`));
|
|
44
|
-
}, 300000); // 300 second timeout
|
|
45
|
-
|
|
46
|
-
// Wrap resolve to clean up
|
|
47
|
-
queue[queue_id].resolve = (value) => {
|
|
48
|
-
clearTimeout(timeout);
|
|
49
|
-
delete queue[queue_id];
|
|
50
|
-
resolve(value);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// Wrap reject to clean up
|
|
54
|
-
queue[queue_id].reject = (error) => {
|
|
55
|
-
clearTimeout(timeout);
|
|
56
|
-
delete queue[queue_id];
|
|
57
|
-
reject(error);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
global[`_${global.module_in}_ch`].sendToQueue(
|
|
62
|
-
'notification_module',
|
|
63
|
-
Buffer.from(
|
|
64
|
-
JSON.stringify({
|
|
65
|
-
ms_method,
|
|
66
|
-
data: args,
|
|
67
|
-
cb: `_notification_module-${global.module_in}_ch`,
|
|
68
|
-
queue_id,
|
|
69
|
-
}),
|
|
70
|
-
),
|
|
71
|
-
);
|
|
72
|
-
} catch (err) {
|
|
73
|
-
debugger;
|
|
74
|
-
}
|
|
6
|
+
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
const { MessageBroker } = await import(path.join(process.env.XUDA_HOME, 'common', 'ms_broker.mjs'));
|
|
10
|
+
|
|
11
|
+
const broker = new MessageBroker();
|
|
12
|
+
|
|
13
|
+
await broker.init({
|
|
14
|
+
queueName: 'notification_module',
|
|
15
|
+
module_in: global.module_in
|
|
75
16
|
});
|
|
76
|
-
};
|
|
77
17
|
|
|
78
|
-
|
|
79
|
-
const module_name = 'notification_module';
|
|
18
|
+
|
|
80
19
|
|
|
81
20
|
export const get_new_notification_count = async function (...args) {
|
|
82
|
-
return await send_to_queue(
|
|
21
|
+
return await broker.send_to_queue("get_new_notification_count", ...args);
|
|
83
22
|
};
|
|
84
23
|
|
|
85
24
|
export const set_notification_read = async function (...args) {
|
|
86
|
-
return await send_to_queue(
|
|
25
|
+
return await broker.send_to_queue("set_notification_read", ...args);
|
|
87
26
|
};
|
|
88
27
|
|
|
89
28
|
export const update_notification_status = async function (...args) {
|
|
90
|
-
return await send_to_queue(
|
|
29
|
+
return await broker.send_to_queue("update_notification_status", ...args);
|
|
91
30
|
};
|
|
92
31
|
|
|
93
32
|
export const submit_notification = async function (...args) {
|
|
94
|
-
return await send_to_queue(
|
|
33
|
+
return await broker.send_to_queue("submit_notification", ...args);
|
|
95
34
|
};
|
|
96
35
|
|
|
97
36
|
export const get_notifications = async function (...args) {
|
|
98
|
-
return await send_to_queue(
|
|
37
|
+
return await broker.send_to_queue("get_notifications", ...args);
|
|
99
38
|
};
|
|
100
39
|
|
|
101
40
|
export const submit_superuser_notification = async function (...args) {
|
|
102
|
-
return await send_to_queue(
|
|
41
|
+
return await broker.send_to_queue("submit_superuser_notification", ...args);
|
|
103
42
|
};
|
|
104
43
|
|
|
105
44
|
export const submit_app_notification = async function (...args) {
|
|
106
|
-
return await send_to_queue(
|
|
45
|
+
return await broker.send_to_queue("submit_app_notification", ...args);
|
|
107
46
|
};
|
|
108
47
|
|
|
109
48
|
export const update_system_notification = async function (...args) {
|
|
110
|
-
return await send_to_queue(
|
|
49
|
+
return await broker.send_to_queue("update_system_notification", ...args);
|
|
111
50
|
};
|
|
112
51
|
|
|
113
52
|
export const submit_topic_app_notification = async function (...args) {
|
|
114
|
-
return await send_to_queue(
|
|
53
|
+
return await broker.send_to_queue("submit_topic_app_notification", ...args);
|
|
115
54
|
};
|
|
116
55
|
|
|
117
56
|
export const get_system_notifications = async function (...args) {
|
|
118
|
-
return await send_to_queue(
|
|
57
|
+
return await broker.send_to_queue("get_system_notifications", ...args);
|
|
119
58
|
};
|
|
120
59
|
|
|
121
60
|
export const notifications_validation_fx = async function (...args) {
|
|
122
|
-
return await send_to_queue(
|
|
61
|
+
return await broker.send_to_queue("notifications_validation_fx", ...args);
|
|
123
62
|
};
|