@xuda.io/notification_module 1.1.126 → 1.1.127
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 +15 -12
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -273,17 +273,12 @@ export const get_notifications = async (req) => {
|
|
|
273
273
|
selector.sender_uid = req.uid;
|
|
274
274
|
} else {
|
|
275
275
|
if (req.system) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
uid: req.to_app_id,
|
|
285
|
-
},
|
|
286
|
-
];
|
|
276
|
+
// Drop empty/undefined uid clauses (e.g. an unauthenticated/public call where
|
|
277
|
+
// req.uid is undefined, or to_app_id is ''), which otherwise build a malformed
|
|
278
|
+
// Mango $or and make find_couch_query throw -> 400.
|
|
279
|
+
selector.$or = [{ uid: req.uid }, { uid: 'system' }, { uid: req.to_app_id }].filter(
|
|
280
|
+
(clause) => typeof clause.uid === 'string' && clause.uid.length > 0,
|
|
281
|
+
);
|
|
287
282
|
} else {
|
|
288
283
|
if (!req.to_app_id) {
|
|
289
284
|
selector.uid = req.uid;
|
|
@@ -589,9 +584,17 @@ export const get_system_notifications = async (req) => {
|
|
|
589
584
|
req.system = true;
|
|
590
585
|
req.to_app_id = '';
|
|
591
586
|
req.read = false;
|
|
592
|
-
|
|
587
|
+
// System notifications are non-critical app-init data fetched on every page load
|
|
588
|
+
// (including unauthenticated ones). A DB/query failure must never surface as a 400
|
|
589
|
+
// to the client (it stalls the loader) -> degrade to an empty list.
|
|
590
|
+
const ret = await get_notifications(req);
|
|
591
|
+
if (!ret || ret.code < 0) {
|
|
592
|
+
return { code: 1, data: { docs: [] } };
|
|
593
|
+
}
|
|
594
|
+
return ret;
|
|
593
595
|
};
|
|
594
596
|
|
|
597
|
+
|
|
595
598
|
export const notifications_validation_fx = async (notification_id) => {
|
|
596
599
|
let { code, data: doc } = await db_module.get_couch_doc('xuda_notification', notification_id);
|
|
597
600
|
const delete_notification = async () => {
|