@xuda.io/notification_module 1.1.101 → 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 -91
  2. package/package.json +1 -1
package/index_ms.mjs CHANGED
@@ -3,128 +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
-
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';
8
+ global.queueName = 'notification_module';
9
+ const _ms_broker = await import(path.join(process.env.XUDA_HOME, 'common', 'ms_broker.mjs'));
87
10
 
88
11
  export const get_new_notification_count = async function (...args) {
89
- return await send_to_queue("get_new_notification_count", ...args);
12
+ return await _ms_broker.send_to_queue('get_new_notification_count', ...args);
90
13
  };
91
14
 
92
15
  export const set_notification_read = async function (...args) {
93
- return await send_to_queue("set_notification_read", ...args);
16
+ return await _ms_broker.send_to_queue('set_notification_read', ...args);
94
17
  };
95
18
 
96
19
  export const update_notification_status = async function (...args) {
97
- return await send_to_queue("update_notification_status", ...args);
20
+ return await _ms_broker.send_to_queue('update_notification_status', ...args);
98
21
  };
99
22
 
100
23
  export const submit_notification = async function (...args) {
101
- return await send_to_queue("submit_notification", ...args);
24
+ return await _ms_broker.send_to_queue('submit_notification', ...args);
102
25
  };
103
26
 
104
27
  export const get_notifications = async function (...args) {
105
- return await send_to_queue("get_notifications", ...args);
28
+ return await _ms_broker.send_to_queue('get_notifications', ...args);
106
29
  };
107
30
 
108
31
  export const submit_superuser_notification = async function (...args) {
109
- return await send_to_queue("submit_superuser_notification", ...args);
32
+ return await _ms_broker.send_to_queue('submit_superuser_notification', ...args);
110
33
  };
111
34
 
112
35
  export const submit_app_notification = async function (...args) {
113
- return await send_to_queue("submit_app_notification", ...args);
36
+ return await _ms_broker.send_to_queue('submit_app_notification', ...args);
114
37
  };
115
38
 
116
39
  export const update_system_notification = async function (...args) {
117
- return await send_to_queue("update_system_notification", ...args);
40
+ return await _ms_broker.send_to_queue('update_system_notification', ...args);
118
41
  };
119
42
 
120
43
  export const submit_topic_app_notification = async function (...args) {
121
- return await send_to_queue("submit_topic_app_notification", ...args);
44
+ return await _ms_broker.send_to_queue('submit_topic_app_notification', ...args);
122
45
  };
123
46
 
124
47
  export const get_system_notifications = async function (...args) {
125
- return await send_to_queue("get_system_notifications", ...args);
48
+ return await _ms_broker.send_to_queue('get_system_notifications', ...args);
126
49
  };
127
50
 
128
51
  export const notifications_validation_fx = async function (...args) {
129
- return await send_to_queue("notifications_validation_fx", ...args);
52
+ return await _ms_broker.send_to_queue('notifications_validation_fx', ...args);
130
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/notification_module",
3
- "version": "1.1.101",
3
+ "version": "1.1.103",
4
4
  "description": "Xuda Notification Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {