@xuda.io/notification_module 1.1.102 → 1.1.103

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 (2) hide show
  1. package/index_ms.mjs +14 -84
  2. package/package.json +1 -1
package/index_ms.mjs CHANGED
@@ -3,121 +3,51 @@
3
3
  // Queue target : notification_module
4
4
  // =====================================================
5
5
 
6
- import amqplib from 'amqplib';
7
- import { randomUUID } from 'crypto';
6
+ import path from 'node:path';
8
7
 
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
- 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
- }
75
- });
76
- };
77
-
78
- // You must define this somewhere before using these wrappers:
79
- const module_name = 'notification_module';
8
+ global.queueName = 'notification_module';
9
+ const _ms_broker = await import(path.join(process.env.XUDA_HOME, 'common', 'ms_broker.mjs'));
80
10
 
81
11
  export const get_new_notification_count = async function (...args) {
82
- return await send_to_queue('get_new_notification_count', ...args);
12
+ return await _ms_broker.send_to_queue('get_new_notification_count', ...args);
83
13
  };
84
14
 
85
15
  export const set_notification_read = async function (...args) {
86
- return await send_to_queue('set_notification_read', ...args);
16
+ return await _ms_broker.send_to_queue('set_notification_read', ...args);
87
17
  };
88
18
 
89
19
  export const update_notification_status = async function (...args) {
90
- return await send_to_queue('update_notification_status', ...args);
20
+ return await _ms_broker.send_to_queue('update_notification_status', ...args);
91
21
  };
92
22
 
93
23
  export const submit_notification = async function (...args) {
94
- return await send_to_queue('submit_notification', ...args);
24
+ return await _ms_broker.send_to_queue('submit_notification', ...args);
95
25
  };
96
26
 
97
27
  export const get_notifications = async function (...args) {
98
- return await send_to_queue('get_notifications', ...args);
28
+ return await _ms_broker.send_to_queue('get_notifications', ...args);
99
29
  };
100
30
 
101
31
  export const submit_superuser_notification = async function (...args) {
102
- return await send_to_queue('submit_superuser_notification', ...args);
32
+ return await _ms_broker.send_to_queue('submit_superuser_notification', ...args);
103
33
  };
104
34
 
105
35
  export const submit_app_notification = async function (...args) {
106
- return await send_to_queue('submit_app_notification', ...args);
36
+ return await _ms_broker.send_to_queue('submit_app_notification', ...args);
107
37
  };
108
38
 
109
39
  export const update_system_notification = async function (...args) {
110
- return await send_to_queue('update_system_notification', ...args);
40
+ return await _ms_broker.send_to_queue('update_system_notification', ...args);
111
41
  };
112
42
 
113
43
  export const submit_topic_app_notification = async function (...args) {
114
- return await send_to_queue('submit_topic_app_notification', ...args);
44
+ return await _ms_broker.send_to_queue('submit_topic_app_notification', ...args);
115
45
  };
116
46
 
117
47
  export const get_system_notifications = async function (...args) {
118
- return await send_to_queue('get_system_notifications', ...args);
48
+ return await _ms_broker.send_to_queue('get_system_notifications', ...args);
119
49
  };
120
50
 
121
51
  export const notifications_validation_fx = async function (...args) {
122
- return await send_to_queue('notifications_validation_fx', ...args);
52
+ return await _ms_broker.send_to_queue('notifications_validation_fx', ...args);
123
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/notification_module",
3
- "version": "1.1.102",
3
+ "version": "1.1.103",
4
4
  "description": "Xuda Notification Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {