@xuda.io/notification_module 1.1.101 → 1.1.102

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 +40 -47
  2. package/package.json +1 -1
package/index_ms.mjs CHANGED
@@ -6,17 +6,15 @@
6
6
  import amqplib from 'amqplib';
7
7
  import { randomUUID } from 'crypto';
8
8
 
9
- let queue={}
9
+ let queue = {};
10
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 });
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
15
 
16
- channel.consume(`_notification_module-${global.module_in}_ch`, async (msg) => {
17
- try{
18
-
19
-
16
+ channel.consume(`_notification_module-${global.module_in}_ch`, async (msg) => {
17
+ try {
20
18
  if (msg === null) {
21
19
  console.log('Consumer cancelled by server');
22
20
  return;
@@ -24,107 +22,102 @@ let queue={}
24
22
 
25
23
  const content = JSON.parse(msg.content.toString());
26
24
 
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
- });
25
+ queue[content.queue_id].resolve(content.ret);
36
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
+ });
37
34
 
38
- const send_to_queue =async function(ms_method, ...args) {
39
-
35
+ const send_to_queue = async function (ms_method, ...args) {
40
36
  const queue_id = randomUUID();
41
- return new Promise((resolve,reject)=>{
42
-
37
+ return new Promise((resolve, reject) => {
43
38
  queue[queue_id] = { resolve, reject };
44
-
39
+
45
40
  // Set timeout to prevent hanging
46
41
  const timeout = setTimeout(() => {
47
42
  delete queue[queue_id];
48
43
  reject(new Error(`Queue timeout for ${ms_method}`));
49
44
  }, 300000); // 300 second timeout
50
-
45
+
51
46
  // Wrap resolve to clean up
52
47
  queue[queue_id].resolve = (value) => {
53
48
  clearTimeout(timeout);
54
49
  delete queue[queue_id];
55
50
  resolve(value);
56
51
  };
57
-
52
+
58
53
  // Wrap reject to clean up
59
54
  queue[queue_id].reject = (error) => {
60
55
  clearTimeout(timeout);
61
56
  delete queue[queue_id];
62
57
  reject(error);
63
58
  };
64
-
65
- try{
59
+
60
+ try {
66
61
  global[`_${global.module_in}_ch`].sendToQueue(
67
62
  'notification_module',
68
63
  Buffer.from(
69
64
  JSON.stringify({
70
65
  ms_method,
71
66
  data: args,
72
- cb:`_notification_module-${global.module_in}_ch`,
73
- queue_id
74
- })
75
- )
67
+ cb: `_notification_module-${global.module_in}_ch`,
68
+ queue_id,
69
+ }),
70
+ ),
76
71
  );
77
-
78
- }catch(err){
79
- debugger
72
+ } catch (err) {
73
+ debugger;
80
74
  }
81
- })
82
-
75
+ });
83
76
  };
84
77
 
85
78
  // You must define this somewhere before using these wrappers:
86
79
  const module_name = 'notification_module';
87
80
 
88
81
  export const get_new_notification_count = async function (...args) {
89
- return await send_to_queue("get_new_notification_count", ...args);
82
+ return await send_to_queue('get_new_notification_count', ...args);
90
83
  };
91
84
 
92
85
  export const set_notification_read = async function (...args) {
93
- return await send_to_queue("set_notification_read", ...args);
86
+ return await send_to_queue('set_notification_read', ...args);
94
87
  };
95
88
 
96
89
  export const update_notification_status = async function (...args) {
97
- return await send_to_queue("update_notification_status", ...args);
90
+ return await send_to_queue('update_notification_status', ...args);
98
91
  };
99
92
 
100
93
  export const submit_notification = async function (...args) {
101
- return await send_to_queue("submit_notification", ...args);
94
+ return await send_to_queue('submit_notification', ...args);
102
95
  };
103
96
 
104
97
  export const get_notifications = async function (...args) {
105
- return await send_to_queue("get_notifications", ...args);
98
+ return await send_to_queue('get_notifications', ...args);
106
99
  };
107
100
 
108
101
  export const submit_superuser_notification = async function (...args) {
109
- return await send_to_queue("submit_superuser_notification", ...args);
102
+ return await send_to_queue('submit_superuser_notification', ...args);
110
103
  };
111
104
 
112
105
  export const submit_app_notification = async function (...args) {
113
- return await send_to_queue("submit_app_notification", ...args);
106
+ return await send_to_queue('submit_app_notification', ...args);
114
107
  };
115
108
 
116
109
  export const update_system_notification = async function (...args) {
117
- return await send_to_queue("update_system_notification", ...args);
110
+ return await send_to_queue('update_system_notification', ...args);
118
111
  };
119
112
 
120
113
  export const submit_topic_app_notification = async function (...args) {
121
- return await send_to_queue("submit_topic_app_notification", ...args);
114
+ return await send_to_queue('submit_topic_app_notification', ...args);
122
115
  };
123
116
 
124
117
  export const get_system_notifications = async function (...args) {
125
- return await send_to_queue("get_system_notifications", ...args);
118
+ return await send_to_queue('get_system_notifications', ...args);
126
119
  };
127
120
 
128
121
  export const notifications_validation_fx = async function (...args) {
129
- return await send_to_queue("notifications_validation_fx", ...args);
122
+ return await send_to_queue('notifications_validation_fx', ...args);
130
123
  };
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.102",
4
4
  "description": "Xuda Notification Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {