@xuda.io/notification_module 1.1.103 → 1.1.105

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 (3) hide show
  1. package/index.mjs +17 -17
  2. package/index_ms.mjs +23 -14
  3. package/package.json +1 -1
package/index.mjs CHANGED
@@ -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 db_module.get_couch_view('xuda_notification', 'new_notifications_count', {
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 db_module.get_couch_doc('xuda_notification', req.notification_id);
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 db_module.save_couch_doc('xuda_notification', notification_doc);
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 db_module.get_couch_doc('xuda_notification', notification_id);
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 db_module.save_couch_doc('xuda_notification', notification_doc);
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 db_module.get_couch_doc('xuda_master', app_id_reference);
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 db_module.get_couch_doc('xuda_accounts', uid);
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 db_module.find_couch_query('xuda_sessions', {
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 db_module.save_couch_doc('xuda_notification', obj);
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 db_module.find_couch_query('xuda_notification', opt);
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 db_module.find_couch_query('xuda_accounts', {
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 db_module.get_couch_doc('xuda_notification', req._id);
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 db_module.save_couch_doc('xuda_notification', notification_doc);
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 db_module.get_couch_doc('xuda_notification', notification_id);
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 db_module.save_couch_doc('xuda_notification', doc);
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 db_module.save_couch_doc('xuda_notification', doc);
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 db_module.get_app_obj(doc.app_id);
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,51 +3,60 @@
3
3
  // Queue target : notification_module
4
4
  // =====================================================
5
5
 
6
- import path from 'node:path';
7
6
 
8
- global.queueName = 'notification_module';
9
- const _ms_broker = await import(path.join(process.env.XUDA_HOME, 'common', 'ms_broker.mjs'));
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
16
+ });
17
+
18
+
10
19
 
11
20
  export const get_new_notification_count = async function (...args) {
12
- return await _ms_broker.send_to_queue('get_new_notification_count', ...args);
21
+ return await broker.send_to_queue("get_new_notification_count", ...args);
13
22
  };
14
23
 
15
24
  export const set_notification_read = async function (...args) {
16
- return await _ms_broker.send_to_queue('set_notification_read', ...args);
25
+ return await broker.send_to_queue("set_notification_read", ...args);
17
26
  };
18
27
 
19
28
  export const update_notification_status = async function (...args) {
20
- return await _ms_broker.send_to_queue('update_notification_status', ...args);
29
+ return await broker.send_to_queue("update_notification_status", ...args);
21
30
  };
22
31
 
23
32
  export const submit_notification = async function (...args) {
24
- return await _ms_broker.send_to_queue('submit_notification', ...args);
33
+ return await broker.send_to_queue("submit_notification", ...args);
25
34
  };
26
35
 
27
36
  export const get_notifications = async function (...args) {
28
- return await _ms_broker.send_to_queue('get_notifications', ...args);
37
+ return await broker.send_to_queue("get_notifications", ...args);
29
38
  };
30
39
 
31
40
  export const submit_superuser_notification = async function (...args) {
32
- return await _ms_broker.send_to_queue('submit_superuser_notification', ...args);
41
+ return await broker.send_to_queue("submit_superuser_notification", ...args);
33
42
  };
34
43
 
35
44
  export const submit_app_notification = async function (...args) {
36
- return await _ms_broker.send_to_queue('submit_app_notification', ...args);
45
+ return await broker.send_to_queue("submit_app_notification", ...args);
37
46
  };
38
47
 
39
48
  export const update_system_notification = async function (...args) {
40
- return await _ms_broker.send_to_queue('update_system_notification', ...args);
49
+ return await broker.send_to_queue("update_system_notification", ...args);
41
50
  };
42
51
 
43
52
  export const submit_topic_app_notification = async function (...args) {
44
- return await _ms_broker.send_to_queue('submit_topic_app_notification', ...args);
53
+ return await broker.send_to_queue("submit_topic_app_notification", ...args);
45
54
  };
46
55
 
47
56
  export const get_system_notifications = async function (...args) {
48
- return await _ms_broker.send_to_queue('get_system_notifications', ...args);
57
+ return await broker.send_to_queue("get_system_notifications", ...args);
49
58
  };
50
59
 
51
60
  export const notifications_validation_fx = async function (...args) {
52
- return await _ms_broker.send_to_queue('notifications_validation_fx', ...args);
61
+ return await broker.send_to_queue("notifications_validation_fx", ...args);
53
62
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/notification_module",
3
- "version": "1.1.103",
3
+ "version": "1.1.105",
4
4
  "description": "Xuda Notification Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {