@resolveio/server-lib 22.2.2 → 22.2.3
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.
|
@@ -97,7 +97,7 @@ function normalizeListLimit(value) {
|
|
|
97
97
|
function isSystemMethodUser(methodUser) {
|
|
98
98
|
return !methodUser || methodUser === 'Internal System';
|
|
99
99
|
}
|
|
100
|
-
function resolveMethodUser(methodUser) {
|
|
100
|
+
function resolveMethodUser(methodUser, methodUserId) {
|
|
101
101
|
return __awaiter(this, void 0, void 0, function () {
|
|
102
102
|
var idUser;
|
|
103
103
|
return __generator(this, function (_a) {
|
|
@@ -109,9 +109,13 @@ function resolveMethodUser(methodUser) {
|
|
|
109
109
|
if (typeof methodUser === 'object' && (methodUser === null || methodUser === void 0 ? void 0 : methodUser._id) && (methodUser === null || methodUser === void 0 ? void 0 : methodUser.roles)) {
|
|
110
110
|
return [2 /*return*/, methodUser];
|
|
111
111
|
}
|
|
112
|
-
idUser = normalizeString(typeof
|
|
113
|
-
?
|
|
114
|
-
: ((
|
|
112
|
+
idUser = normalizeString(typeof methodUserId === 'string'
|
|
113
|
+
? methodUserId
|
|
114
|
+
: ((methodUserId === null || methodUserId === void 0 ? void 0 : methodUserId._id) ||
|
|
115
|
+
(methodUserId === null || methodUserId === void 0 ? void 0 : methodUserId.id_user) ||
|
|
116
|
+
(typeof methodUser === 'string'
|
|
117
|
+
? methodUser
|
|
118
|
+
: ((methodUser === null || methodUser === void 0 ? void 0 : methodUser._id) || (methodUser === null || methodUser === void 0 ? void 0 : methodUser.id_user) || ''))), 80);
|
|
115
119
|
if (!idUser) {
|
|
116
120
|
return [2 /*return*/, null];
|
|
117
121
|
}
|
|
@@ -216,7 +220,7 @@ function loadCustomerNotificationMethods(methodManager) {
|
|
|
216
220
|
var methodUser, systemUser, title, message, idClient, clientName, category, severity, details, source, sourceId, actionLabel, actionRoute, dedupeKey, expiresAt, metadata, targetUsers, now, createById, createByName, skippedByDedupe, cutoff, existing, docs;
|
|
217
221
|
return __generator(this, function (_a) {
|
|
218
222
|
switch (_a.label) {
|
|
219
|
-
case 0: return [4 /*yield*/, resolveMethodUser(this.user)];
|
|
223
|
+
case 0: return [4 /*yield*/, resolveMethodUser(this.user, this.id_user)];
|
|
220
224
|
case 1:
|
|
221
225
|
methodUser = _a.sent();
|
|
222
226
|
systemUser = isSystemMethodUser(this.user);
|
|
@@ -337,7 +341,7 @@ function loadCustomerNotificationMethods(methodManager) {
|
|
|
337
341
|
var methodUser, idUser;
|
|
338
342
|
return __generator(this, function (_a) {
|
|
339
343
|
switch (_a.label) {
|
|
340
|
-
case 0: return [4 /*yield*/, resolveMethodUser(this.user)];
|
|
344
|
+
case 0: return [4 /*yield*/, resolveMethodUser(this.user, this.id_user)];
|
|
341
345
|
case 1:
|
|
342
346
|
methodUser = _a.sent();
|
|
343
347
|
idUser = normalizeString(methodUser === null || methodUser === void 0 ? void 0 : methodUser._id, 80);
|
|
@@ -374,7 +378,7 @@ function loadCustomerNotificationMethods(methodManager) {
|
|
|
374
378
|
var methodUser, idUser, idClient, query;
|
|
375
379
|
return __generator(this, function (_a) {
|
|
376
380
|
switch (_a.label) {
|
|
377
|
-
case 0: return [4 /*yield*/, resolveMethodUser(this.user)];
|
|
381
|
+
case 0: return [4 /*yield*/, resolveMethodUser(this.user, this.id_user)];
|
|
378
382
|
case 1:
|
|
379
383
|
methodUser = _a.sent();
|
|
380
384
|
idUser = normalizeString(methodUser === null || methodUser === void 0 ? void 0 : methodUser._id, 80);
|
|
@@ -417,7 +421,7 @@ function loadCustomerNotificationMethods(methodManager) {
|
|
|
417
421
|
var methodUser, systemUser, query, idUser, idClient, status, limit;
|
|
418
422
|
return __generator(this, function (_a) {
|
|
419
423
|
switch (_a.label) {
|
|
420
|
-
case 0: return [4 /*yield*/, resolveMethodUser(this.user)];
|
|
424
|
+
case 0: return [4 /*yield*/, resolveMethodUser(this.user, this.id_user)];
|
|
421
425
|
case 1:
|
|
422
426
|
methodUser = _a.sent();
|
|
423
427
|
systemUser = isSystemMethodUser(this.user);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/methods/customer-notifications.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuKA,0EAyNC;AAhYD,6CAAwC;AACxC,oGAAwF;AACxF,kEAAuD;AAEvD,yCAAmD;AAEnD,IAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,IAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,IAAM,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACxC,IAAM,gBAAgB,GAAG,IAAI,CAAC;AA4B9B,SAAS,eAAe,CAAC,KAAU,EAAE,SAAe;IAAf,0BAAA,EAAA,eAAe;IACnD,IAAM,UAAU,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;IACX,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QACpC,OAAO,UAAU,CAAC;IACnB,CAAC;IACD,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,6BAA6B,CAAC,KAAc;IACpD,IAAM,UAAU,GAAG,eAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5D,IAAI,CAAC,UAAU,EAAE,CAAC;QACjB,OAAO,QAAQ,CAAC;IACjB,CAAC;IACD,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACxE,OAAO,UAAU,CAAC;IACnB,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,SAAS,6BAA6B,CAAC,K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MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;gCAClE,IAAI,MAAM,EAAE,CAAC;oCACZ,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;gCACxB,CAAC;gCACD,IAAI,QAAQ,EAAE,CAAC;oCACd,KAAK,CAAC,SAAS,GAAG,QAAQ,CAAC;gCAC5B,CAAC;gCACD,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;oCAC9C,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;gCACvB,CAAC;gCAEK,KAAK,GAAG,kBAAkB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC,CAAC;gCAC1C,qBAAM,wDAAqB,CAAC,IAAI,CAAC,KAAK,EAAE;wCAC9C,IAAI,EAAE;4CACL,SAAS,EAAE,CAAC,CAAC;yCACb;wCACD,KAAK,OAAA;qCACL,CAAC,EAAA;oCALF,sBAAO,SAKL,EAAC;;;;aACH;SACD;KACD,CAAC,CAAC;AACJ,CAAC","file":"customer-notifications.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { CustomerNotifications } from '../collections/customer-notification.collection';\nimport { Users } from '../collections/user.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { objectIdHexString } from '../util/common';\n\nconst DEFAULT_LIST_LIMIT = 100;\nconst MAX_LIST_LIMIT = 500;\nconst DEDUPE_WINDOW_MS = 30 * 60 * 1000;\nconst MAX_TARGET_USERS = 5000;\n\ntype CreateCustomerNotificationPayload = {\n\ttitle: string;\n\tmessage: string;\n\tdetails?: string;\n\tcategory?: string;\n\tseverity?: string;\n\ttarget_type?: 'client' | 'users' | 'all_active';\n\tid_client?: string;\n\tclient_name?: string;\n\tid_users?: string[];\n\tsource?: string;\n\tsource_id?: string;\n\taction_label?: string;\n\taction_route?: string;\n\tdedupe_key?: string;\n\texpires_at?: Date;\n\tmetadata?: Record<string, any>;\n};\n\ntype ListCustomerNotificationsPayload = {\n\tid_user?: string;\n\tid_client?: string;\n\tstatus?: 'unread' | 'read';\n\tlimit?: number;\n};\n\nfunction normalizeString(value: any, maxLength = 500): string {\n\tconst normalized = String(value || '').trim();\n\tif (!normalized) {\n\t\treturn '';\n\t}\n\tif (normalized.length <= maxLength) {\n\t\treturn normalized;\n\t}\n\treturn normalized.slice(0, maxLength);\n}\n\nfunction normalizeNotificationCategory(value?: string): string {\n\tconst normalized = normalizeString(value, 40).toLowerCase();\n\tif (!normalized) {\n\t\treturn 'system';\n\t}\n\tif (['autofix', 'slow-query', 'system', 'manual'].includes(normalized)) {\n\t\treturn normalized;\n\t}\n\treturn 'system';\n}\n\nfunction normalizeNotificationSeverity(value?: string): string {\n\tconst normalized = normalizeString(value, 20).toLowerCase();\n\tif (!normalized) {\n\t\treturn 'info';\n\t}\n\tif (['info', 'success', 'warning', 'error'].includes(normalized)) {\n\t\treturn normalized;\n\t}\n\treturn 'info';\n}\n\nfunction normalizeListLimit(value?: number): number {\n\tconst parsed = Number(value);\n\tif (!Number.isFinite(parsed) || parsed <= 0) {\n\t\treturn DEFAULT_LIST_LIMIT;\n\t}\n\treturn Math.min(Math.floor(parsed), MAX_LIST_LIMIT);\n}\n\nfunction isSystemMethodUser(methodUser: any): boolean {\n\treturn !methodUser || methodUser === 'Internal System';\n}\n\nasync function resolveMethodUser(methodUser: any): Promise<any | null> {\n\tif (isSystemMethodUser(methodUser)) {\n\t\treturn null;\n\t}\n\n\tif (typeof methodUser === 'object' && methodUser?._id && methodUser?.roles) {\n\t\treturn methodUser;\n\t}\n\n\tconst idUser = normalizeString(\n\t\ttypeof methodUser === 'string'\n\t\t\t? methodUser\n\t\t\t: (methodUser?._id || methodUser?.id_user || ''),\n\t\t80\n\t);\n\tif (!idUser) {\n\t\treturn null;\n\t}\n\treturn await Users.findById(idUser);\n}\n\nfunction isSuperAdmin(user: any): boolean {\n\treturn !!user?.roles?.super_admin;\n}\n\nfunction uniqueUserIds(input: string[]): string[] {\n\tconst unique = new Set<string>();\n\tfor (const entry of (Array.isArray(input) ? input : [])) {\n\t\tconst id = normalizeString(entry, 80);\n\t\tif (id) {\n\t\t\tunique.add(id);\n\t\t}\n\t\tif (unique.size >= MAX_TARGET_USERS) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn Array.from(unique);\n}\n\nasync function resolveTargetUsers(payload: CreateCustomerNotificationPayload): Promise<string[]> {\n\tconst targetType = normalizeString(payload?.target_type || 'client', 20).toLowerCase() || 'client';\n\tif (targetType === 'users') {\n\t\treturn uniqueUserIds(payload?.id_users || []);\n\t}\n\n\tif (targetType === 'all_active') {\n\t\tconst users = await Users.find({\n\t\t\tactive: true,\n\t\t\tusername: {\n\t\t\t\t$exists: true\n\t\t\t}\n\t\t}, {\n\t\t\tprojection: {\n\t\t\t\t_id: 1\n\t\t\t},\n\t\t\tlimit: MAX_TARGET_USERS\n\t\t});\n\t\treturn uniqueUserIds(users.map((user: any) => user?._id));\n\t}\n\n\tconst idClient = normalizeString(payload?.id_client, 80);\n\tif (!idClient) {\n\t\treturn [];\n\t}\n\n\tconst users = await Users.find({\n\t\tactive: true,\n\t\tusername: {\n\t\t\t$exists: true\n\t\t},\n\t\t$or: [\n\t\t\t{'other.id_client': idClient},\n\t\t\t{'other.idClient': idClient},\n\t\t\t{id_client: idClient}\n\t\t]\n\t}, {\n\t\tprojection: {\n\t\t\t_id: 1\n\t\t},\n\t\tlimit: MAX_TARGET_USERS\n\t});\n\n\treturn uniqueUserIds(users.map((user: any) => user?._id));\n}\n\nexport function loadCustomerNotificationMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tcreateCustomerNotification: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tpayload: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(payload: CreateCustomerNotificationPayload) {\n\t\t\t\tconst methodUser = await resolveMethodUser(this.user);\n\t\t\t\tconst systemUser = isSystemMethodUser(this.user);\n\t\t\t\tif (!systemUser && !isSuperAdmin(methodUser)) {\n\t\t\t\t\tthrow new Error('Only super admins can create notifications.');\n\t\t\t\t}\n\n\t\t\t\tconst title = normalizeString(payload?.title, 160);\n\t\t\t\tconst message = normalizeString(payload?.message, 1500);\n\t\t\t\tif (!title || !message) {\n\t\t\t\t\tthrow new Error('Notification title and message are required.');\n\t\t\t\t}\n\n\t\t\t\tconst idClient = normalizeString(payload?.id_client, 80);\n\t\t\t\tconst clientName = normalizeString(payload?.client_name, 200);\n\t\t\t\tconst category = normalizeNotificationCategory(payload?.category);\n\t\t\t\tconst severity = normalizeNotificationSeverity(payload?.severity);\n\t\t\t\tconst details = normalizeString(payload?.details, 6000);\n\t\t\t\tconst source = normalizeString(payload?.source, 120);\n\t\t\t\tconst sourceId = normalizeString(payload?.source_id, 120);\n\t\t\t\tconst actionLabel = normalizeString(payload?.action_label, 80);\n\t\t\t\tconst actionRoute = normalizeString(payload?.action_route, 500);\n\t\t\t\tconst dedupeKey = normalizeString(payload?.dedupe_key, 160);\n\t\t\t\tconst expiresAt = payload?.expires_at instanceof Date && !Number.isNaN(payload.expires_at.getTime())\n\t\t\t\t\t? payload.expires_at\n\t\t\t\t\t: undefined;\n\t\t\t\tconst metadata = payload?.metadata && typeof payload.metadata === 'object'\n\t\t\t\t\t? payload.metadata\n\t\t\t\t\t: undefined;\n\n\t\t\t\tconst targetUsers = await resolveTargetUsers(payload);\n\t\t\t\tif (!targetUsers.length) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcreated: 0,\n\t\t\t\t\t\treason: 'no_target_users'\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst now = new Date();\n\t\t\t\tconst createById = systemUser ? 'Internal System' : normalizeString(methodUser?._id, 80);\n\t\t\t\tconst createByName = systemUser\n\t\t\t\t\t? 'Internal System'\n\t\t\t\t\t: normalizeString(methodUser?.fullname || methodUser?.username, 200);\n\n\t\t\t\tlet skippedByDedupe = new Set<string>();\n\t\t\t\tif (dedupeKey) {\n\t\t\t\t\tconst cutoff = new Date(now.getTime() - DEDUPE_WINDOW_MS);\n\t\t\t\t\tconst existing = await CustomerNotifications.find({\n\t\t\t\t\t\tid_user: {\n\t\t\t\t\t\t\t$in: targetUsers\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdedupe_key: dedupeKey,\n\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t$gte: cutoff\n\t\t\t\t\t\t}\n\t\t\t\t\t}, {\n\t\t\t\t\t\tprojection: {\n\t\t\t\t\t\t\tid_user: 1\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlimit: MAX_TARGET_USERS\n\t\t\t\t\t});\n\t\t\t\t\tskippedByDedupe = new Set(existing.map(entry => normalizeString(entry?.id_user, 80)).filter(Boolean));\n\t\t\t\t}\n\n\t\t\t\tconst docs = targetUsers\n\t\t\t\t\t.filter(idUser => !skippedByDedupe.has(idUser))\n\t\t\t\t\t.map((idUser) => ({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\tid_user: idUser,\n\t\t\t\t\t\tid_client: idClient || undefined,\n\t\t\t\t\t\tclient_name: clientName || undefined,\n\t\t\t\t\t\ttitle,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tdetails: details || undefined,\n\t\t\t\t\t\tcategory,\n\t\t\t\t\t\tseverity,\n\t\t\t\t\t\tstatus: 'unread',\n\t\t\t\t\t\tread_at: undefined,\n\t\t\t\t\t\tread_by: '',\n\t\t\t\t\t\tsource: source || undefined,\n\t\t\t\t\t\tsource_id: sourceId || undefined,\n\t\t\t\t\t\taction_label: actionLabel || undefined,\n\t\t\t\t\t\taction_route: actionRoute || undefined,\n\t\t\t\t\t\tdedupe_key: dedupeKey || undefined,\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\texpires_at: expiresAt,\n\t\t\t\t\t\tcreated_by: createById || undefined,\n\t\t\t\t\t\tcreated_by_name: createByName || undefined,\n\t\t\t\t\t\tcreatedAt: now,\n\t\t\t\t\t\tupdatedAt: now\n\t\t\t\t\t}));\n\n\t\t\t\tif (!docs.length) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcreated: 0,\n\t\t\t\t\t\treason: 'dedupe_suppressed'\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tawait CustomerNotifications.insertMany(docs as any[]);\n\n\t\t\t\treturn {\n\t\t\t\t\tcreated: docs.length,\n\t\t\t\t\ttargeted: targetUsers.length\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\tmarkUserNotificationRead: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_notification: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(id_notification: string) {\n\t\t\t\tconst methodUser = await resolveMethodUser(this.user);\n\t\t\t\tconst idUser = normalizeString(methodUser?._id, 80);\n\t\t\t\tif (!idUser) {\n\t\t\t\t\tthrow new Error('You must be logged in to mark notifications as read.');\n\t\t\t\t}\n\n\t\t\t\tawait CustomerNotifications.updateOne({\n\t\t\t\t\t_id: id_notification,\n\t\t\t\t\tid_user: idUser\n\t\t\t\t}, {\n\t\t\t\t\t$set: {\n\t\t\t\t\t\tstatus: 'read',\n\t\t\t\t\t\tread_at: new Date(),\n\t\t\t\t\t\tread_by: idUser\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tmarkAllUserNotificationsRead: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_client: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(id_client?: string) {\n\t\t\t\tconst methodUser = await resolveMethodUser(this.user);\n\t\t\t\tconst idUser = normalizeString(methodUser?._id, 80);\n\t\t\t\tif (!idUser) {\n\t\t\t\t\tthrow new Error('You must be logged in to mark notifications as read.');\n\t\t\t\t}\n\n\t\t\t\tconst idClient = normalizeString(id_client, 80);\n\t\t\t\tconst query: Record<string, any> = {\n\t\t\t\t\tid_user: idUser,\n\t\t\t\t\tstatus: 'unread'\n\t\t\t\t};\n\t\t\t\tif (idClient) {\n\t\t\t\t\tquery.id_client = idClient;\n\t\t\t\t}\n\n\t\t\t\tawait CustomerNotifications.updateMany(query, {\n\t\t\t\t\t$set: {\n\t\t\t\t\t\tstatus: 'read',\n\t\t\t\t\t\tread_at: new Date(),\n\t\t\t\t\t\tread_by: idUser\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tlistCustomerNotifications: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tpayload: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\toptional: true,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(payload?: ListCustomerNotificationsPayload) {\n\t\t\t\tconst methodUser = await resolveMethodUser(this.user);\n\t\t\t\tconst systemUser = isSystemMethodUser(this.user);\n\t\t\t\tif (!systemUser && !isSuperAdmin(methodUser)) {\n\t\t\t\t\tthrow new Error('Only super admins can list all notifications.');\n\t\t\t\t}\n\n\t\t\t\tconst query: Record<string, any> = {};\n\t\t\t\tconst idUser = normalizeString(payload?.id_user, 80);\n\t\t\t\tconst idClient = normalizeString(payload?.id_client, 80);\n\t\t\t\tconst status = normalizeString(payload?.status, 20).toLowerCase();\n\t\t\t\tif (idUser) {\n\t\t\t\t\tquery.id_user = idUser;\n\t\t\t\t}\n\t\t\t\tif (idClient) {\n\t\t\t\t\tquery.id_client = idClient;\n\t\t\t\t}\n\t\t\t\tif (status === 'unread' || status === 'read') {\n\t\t\t\t\tquery.status = status;\n\t\t\t\t}\n\n\t\t\t\tconst limit = normalizeListLimit(payload?.limit);\n\t\t\t\treturn await CustomerNotifications.find(query, {\n\t\t\t\t\tsort: {\n\t\t\t\t\t\tcreatedAt: -1\n\t\t\t\t\t},\n\t\t\t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,CAAC;gCAEK,KAAK,GAAwB,EAAE,CAAC;gCAChC,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAE,EAAE,CAAC,CAAC;gCAC/C,QAAQ,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAE,EAAE,CAAC,CAAC;gCACnD,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;gCAClE,IAAI,MAAM,EAAE,CAAC;oCACZ,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;gCACxB,CAAC;gCACD,IAAI,QAAQ,EAAE,CAAC;oCACd,KAAK,CAAC,SAAS,GAAG,QAAQ,CAAC;gCAC5B,CAAC;gCACD,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;oCAC9C,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;gCACvB,CAAC;gCAEK,KAAK,GAAG,kBAAkB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC,CAAC;gCAC1C,qBAAM,wDAAqB,CAAC,IAAI,CAAC,KAAK,EAAE;wCAC9C,IAAI,EAAE;4CACL,SAAS,EAAE,CAAC,CAAC;yCACb;wCACD,KAAK,OAAA;qCACL,CAAC,EAAA;oCALF,sBAAO,SAKL,EAAC;;;;aACH;SACD;KACD,CAAC,CAAC;AACJ,CAAC","file":"customer-notifications.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { CustomerNotifications } from '../collections/customer-notification.collection';\nimport { Users } from '../collections/user.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { objectIdHexString } from '../util/common';\n\nconst DEFAULT_LIST_LIMIT = 100;\nconst MAX_LIST_LIMIT = 500;\nconst DEDUPE_WINDOW_MS = 30 * 60 * 1000;\nconst MAX_TARGET_USERS = 5000;\n\ntype CreateCustomerNotificationPayload = {\n\ttitle: string;\n\tmessage: string;\n\tdetails?: string;\n\tcategory?: string;\n\tseverity?: string;\n\ttarget_type?: 'client' | 'users' | 'all_active';\n\tid_client?: string;\n\tclient_name?: string;\n\tid_users?: string[];\n\tsource?: string;\n\tsource_id?: string;\n\taction_label?: string;\n\taction_route?: string;\n\tdedupe_key?: string;\n\texpires_at?: Date;\n\tmetadata?: Record<string, any>;\n};\n\ntype ListCustomerNotificationsPayload = {\n\tid_user?: string;\n\tid_client?: string;\n\tstatus?: 'unread' | 'read';\n\tlimit?: number;\n};\n\nfunction normalizeString(value: any, maxLength = 500): string {\n\tconst normalized = String(value || '').trim();\n\tif (!normalized) {\n\t\treturn '';\n\t}\n\tif (normalized.length <= maxLength) {\n\t\treturn normalized;\n\t}\n\treturn normalized.slice(0, maxLength);\n}\n\nfunction normalizeNotificationCategory(value?: string): string {\n\tconst normalized = normalizeString(value, 40).toLowerCase();\n\tif (!normalized) {\n\t\treturn 'system';\n\t}\n\tif (['autofix', 'slow-query', 'system', 'manual'].includes(normalized)) {\n\t\treturn normalized;\n\t}\n\treturn 'system';\n}\n\nfunction normalizeNotificationSeverity(value?: string): string {\n\tconst normalized = normalizeString(value, 20).toLowerCase();\n\tif (!normalized) {\n\t\treturn 'info';\n\t}\n\tif (['info', 'success', 'warning', 'error'].includes(normalized)) {\n\t\treturn normalized;\n\t}\n\treturn 'info';\n}\n\nfunction normalizeListLimit(value?: number): number {\n\tconst parsed = Number(value);\n\tif (!Number.isFinite(parsed) || parsed <= 0) {\n\t\treturn DEFAULT_LIST_LIMIT;\n\t}\n\treturn Math.min(Math.floor(parsed), MAX_LIST_LIMIT);\n}\n\nfunction isSystemMethodUser(methodUser: any): boolean {\n\treturn !methodUser || methodUser === 'Internal System';\n}\n\nasync function resolveMethodUser(methodUser: any, methodUserId?: any): Promise<any | null> {\n\tif (isSystemMethodUser(methodUser)) {\n\t\treturn null;\n\t}\n\n\tif (typeof methodUser === 'object' && methodUser?._id && methodUser?.roles) {\n\t\treturn methodUser;\n\t}\n\n\tconst idUser = normalizeString(\n\t\ttypeof methodUserId === 'string'\n\t\t\t? methodUserId\n\t\t\t: (\n\t\t\t\tmethodUserId?._id ||\n\t\t\t\tmethodUserId?.id_user ||\n\t\t\t\t(typeof methodUser === 'string'\n\t\t\t\t\t? methodUser\n\t\t\t\t\t: (methodUser?._id || methodUser?.id_user || ''))\n\t\t\t),\n\t\t80\n\t);\n\tif (!idUser) {\n\t\treturn null;\n\t}\n\treturn await Users.findById(idUser);\n}\n\nfunction isSuperAdmin(user: any): boolean {\n\treturn !!user?.roles?.super_admin;\n}\n\nfunction uniqueUserIds(input: string[]): string[] {\n\tconst unique = new Set<string>();\n\tfor (const entry of (Array.isArray(input) ? input : [])) {\n\t\tconst id = normalizeString(entry, 80);\n\t\tif (id) {\n\t\t\tunique.add(id);\n\t\t}\n\t\tif (unique.size >= MAX_TARGET_USERS) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn Array.from(unique);\n}\n\nasync function resolveTargetUsers(payload: CreateCustomerNotificationPayload): Promise<string[]> {\n\tconst targetType = normalizeString(payload?.target_type || 'client', 20).toLowerCase() || 'client';\n\tif (targetType === 'users') {\n\t\treturn uniqueUserIds(payload?.id_users || []);\n\t}\n\n\tif (targetType === 'all_active') {\n\t\tconst users = await Users.find({\n\t\t\tactive: true,\n\t\t\tusername: {\n\t\t\t\t$exists: true\n\t\t\t}\n\t\t}, {\n\t\t\tprojection: {\n\t\t\t\t_id: 1\n\t\t\t},\n\t\t\tlimit: MAX_TARGET_USERS\n\t\t});\n\t\treturn uniqueUserIds(users.map((user: any) => user?._id));\n\t}\n\n\tconst idClient = normalizeString(payload?.id_client, 80);\n\tif (!idClient) {\n\t\treturn [];\n\t}\n\n\tconst users = await Users.find({\n\t\tactive: true,\n\t\tusername: {\n\t\t\t$exists: true\n\t\t},\n\t\t$or: [\n\t\t\t{'other.id_client': idClient},\n\t\t\t{'other.idClient': idClient},\n\t\t\t{id_client: idClient}\n\t\t]\n\t}, {\n\t\tprojection: {\n\t\t\t_id: 1\n\t\t},\n\t\tlimit: MAX_TARGET_USERS\n\t});\n\n\treturn uniqueUserIds(users.map((user: any) => user?._id));\n}\n\nexport function loadCustomerNotificationMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tcreateCustomerNotification: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tpayload: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(payload: CreateCustomerNotificationPayload) {\n\t\t\t\tconst methodUser = await resolveMethodUser(this.user, this.id_user);\n\t\t\t\tconst systemUser = isSystemMethodUser(this.user);\n\t\t\t\tif (!systemUser && !isSuperAdmin(methodUser)) {\n\t\t\t\t\tthrow new Error('Only super admins can create notifications.');\n\t\t\t\t}\n\n\t\t\t\tconst title = normalizeString(payload?.title, 160);\n\t\t\t\tconst message = normalizeString(payload?.message, 1500);\n\t\t\t\tif (!title || !message) {\n\t\t\t\t\tthrow new Error('Notification title and message are required.');\n\t\t\t\t}\n\n\t\t\t\tconst idClient = normalizeString(payload?.id_client, 80);\n\t\t\t\tconst clientName = normalizeString(payload?.client_name, 200);\n\t\t\t\tconst category = normalizeNotificationCategory(payload?.category);\n\t\t\t\tconst severity = normalizeNotificationSeverity(payload?.severity);\n\t\t\t\tconst details = normalizeString(payload?.details, 6000);\n\t\t\t\tconst source = normalizeString(payload?.source, 120);\n\t\t\t\tconst sourceId = normalizeString(payload?.source_id, 120);\n\t\t\t\tconst actionLabel = normalizeString(payload?.action_label, 80);\n\t\t\t\tconst actionRoute = normalizeString(payload?.action_route, 500);\n\t\t\t\tconst dedupeKey = normalizeString(payload?.dedupe_key, 160);\n\t\t\t\tconst expiresAt = payload?.expires_at instanceof Date && !Number.isNaN(payload.expires_at.getTime())\n\t\t\t\t\t? payload.expires_at\n\t\t\t\t\t: undefined;\n\t\t\t\tconst metadata = payload?.metadata && typeof payload.metadata === 'object'\n\t\t\t\t\t? payload.metadata\n\t\t\t\t\t: undefined;\n\n\t\t\t\tconst targetUsers = await resolveTargetUsers(payload);\n\t\t\t\tif (!targetUsers.length) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcreated: 0,\n\t\t\t\t\t\treason: 'no_target_users'\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst now = new Date();\n\t\t\t\tconst createById = systemUser ? 'Internal System' : normalizeString(methodUser?._id, 80);\n\t\t\t\tconst createByName = systemUser\n\t\t\t\t\t? 'Internal System'\n\t\t\t\t\t: normalizeString(methodUser?.fullname || methodUser?.username, 200);\n\n\t\t\t\tlet skippedByDedupe = new Set<string>();\n\t\t\t\tif (dedupeKey) {\n\t\t\t\t\tconst cutoff = new Date(now.getTime() - DEDUPE_WINDOW_MS);\n\t\t\t\t\tconst existing = await CustomerNotifications.find({\n\t\t\t\t\t\tid_user: {\n\t\t\t\t\t\t\t$in: targetUsers\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdedupe_key: dedupeKey,\n\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t$gte: cutoff\n\t\t\t\t\t\t}\n\t\t\t\t\t}, {\n\t\t\t\t\t\tprojection: {\n\t\t\t\t\t\t\tid_user: 1\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlimit: MAX_TARGET_USERS\n\t\t\t\t\t});\n\t\t\t\t\tskippedByDedupe = new Set(existing.map(entry => normalizeString(entry?.id_user, 80)).filter(Boolean));\n\t\t\t\t}\n\n\t\t\t\tconst docs = targetUsers\n\t\t\t\t\t.filter(idUser => !skippedByDedupe.has(idUser))\n\t\t\t\t\t.map((idUser) => ({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\tid_user: idUser,\n\t\t\t\t\t\tid_client: idClient || undefined,\n\t\t\t\t\t\tclient_name: clientName || undefined,\n\t\t\t\t\t\ttitle,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tdetails: details || undefined,\n\t\t\t\t\t\tcategory,\n\t\t\t\t\t\tseverity,\n\t\t\t\t\t\tstatus: 'unread',\n\t\t\t\t\t\tread_at: undefined,\n\t\t\t\t\t\tread_by: '',\n\t\t\t\t\t\tsource: source || undefined,\n\t\t\t\t\t\tsource_id: sourceId || undefined,\n\t\t\t\t\t\taction_label: actionLabel || undefined,\n\t\t\t\t\t\taction_route: actionRoute || undefined,\n\t\t\t\t\t\tdedupe_key: dedupeKey || undefined,\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\texpires_at: expiresAt,\n\t\t\t\t\t\tcreated_by: createById || undefined,\n\t\t\t\t\t\tcreated_by_name: createByName || undefined,\n\t\t\t\t\t\tcreatedAt: now,\n\t\t\t\t\t\tupdatedAt: now\n\t\t\t\t\t}));\n\n\t\t\t\tif (!docs.length) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcreated: 0,\n\t\t\t\t\t\treason: 'dedupe_suppressed'\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tawait CustomerNotifications.insertMany(docs as any[]);\n\n\t\t\t\treturn {\n\t\t\t\t\tcreated: docs.length,\n\t\t\t\t\ttargeted: targetUsers.length\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\tmarkUserNotificationRead: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_notification: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(id_notification: string) {\n\t\t\t\tconst methodUser = await resolveMethodUser(this.user, this.id_user);\n\t\t\t\tconst idUser = normalizeString(methodUser?._id, 80);\n\t\t\t\tif (!idUser) {\n\t\t\t\t\tthrow new Error('You must be logged in to mark notifications as read.');\n\t\t\t\t}\n\n\t\t\t\tawait CustomerNotifications.updateOne({\n\t\t\t\t\t_id: id_notification,\n\t\t\t\t\tid_user: idUser\n\t\t\t\t}, {\n\t\t\t\t\t$set: {\n\t\t\t\t\t\tstatus: 'read',\n\t\t\t\t\t\tread_at: new Date(),\n\t\t\t\t\t\tread_by: idUser\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tmarkAllUserNotificationsRead: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_client: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(id_client?: string) {\n\t\t\t\tconst methodUser = await resolveMethodUser(this.user, this.id_user);\n\t\t\t\tconst idUser = normalizeString(methodUser?._id, 80);\n\t\t\t\tif (!idUser) {\n\t\t\t\t\tthrow new Error('You must be logged in to mark notifications as read.');\n\t\t\t\t}\n\n\t\t\t\tconst idClient = normalizeString(id_client, 80);\n\t\t\t\tconst query: Record<string, any> = {\n\t\t\t\t\tid_user: idUser,\n\t\t\t\t\tstatus: 'unread'\n\t\t\t\t};\n\t\t\t\tif (idClient) {\n\t\t\t\t\tquery.id_client = idClient;\n\t\t\t\t}\n\n\t\t\t\tawait CustomerNotifications.updateMany(query, {\n\t\t\t\t\t$set: {\n\t\t\t\t\t\tstatus: 'read',\n\t\t\t\t\t\tread_at: new Date(),\n\t\t\t\t\t\tread_by: idUser\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tlistCustomerNotifications: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tpayload: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\toptional: true,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(payload?: ListCustomerNotificationsPayload) {\n\t\t\t\tconst methodUser = await resolveMethodUser(this.user, this.id_user);\n\t\t\t\tconst systemUser = isSystemMethodUser(this.user);\n\t\t\t\tif (!systemUser && !isSuperAdmin(methodUser)) {\n\t\t\t\t\tthrow new Error('Only super admins can list all notifications.');\n\t\t\t\t}\n\n\t\t\t\tconst query: Record<string, any> = {};\n\t\t\t\tconst idUser = normalizeString(payload?.id_user, 80);\n\t\t\t\tconst idClient = normalizeString(payload?.id_client, 80);\n\t\t\t\tconst status = normalizeString(payload?.status, 20).toLowerCase();\n\t\t\t\tif (idUser) {\n\t\t\t\t\tquery.id_user = idUser;\n\t\t\t\t}\n\t\t\t\tif (idClient) {\n\t\t\t\t\tquery.id_client = idClient;\n\t\t\t\t}\n\t\t\t\tif (status === 'unread' || status === 'read') {\n\t\t\t\t\tquery.status = status;\n\t\t\t\t}\n\n\t\t\t\tconst limit = normalizeListLimit(payload?.limit);\n\t\t\t\treturn await CustomerNotifications.find(query, {\n\t\t\t\t\tsort: {\n\t\t\t\t\t\tcreatedAt: -1\n\t\t\t\t\t},\n\t\t\t\t\tlimit\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n}\n"]}
|