@resolveio/server-lib 22.2.1 → 22.2.2
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/collections/customer-notification.collection.d.ts +3 -0
- package/collections/customer-notification.collection.js +130 -0
- package/collections/customer-notification.collection.js.map +1 -0
- package/managers/local-log.manager.js +1 -2
- package/managers/local-log.manager.js.map +1 -1
- package/managers/method.manager.js +3 -2
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +18 -36
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +4 -8
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +2 -0
- package/managers/subscription.manager.js.map +1 -1
- package/methods/customer-notifications.d.ts +2 -0
- package/methods/customer-notifications.js +456 -0
- package/methods/customer-notifications.js.map +1 -0
- package/methods/logs.js +2 -4
- package/methods/logs.js.map +1 -1
- package/methods.ts +12 -0
- package/models/customer-notification.model.d.ts +26 -0
- package/models/customer-notification.model.js +4 -0
- package/models/customer-notification.model.js.map +1 -0
- package/package.json +1 -1
- package/public_api.d.ts +2 -0
- package/public_api.js +2 -0
- package/public_api.js.map +1 -1
- package/publications/customer-notifications.d.ts +2 -0
- package/publications/customer-notifications.js +161 -0
- package/publications/customer-notifications.js.map +1 -0
- package/publications.ts +6 -0
- package/resolveio-server-app.d.ts +4 -0
- package/resolveio-server-app.js +38 -0
- package/resolveio-server-app.js.map +1 -1
- package/server-app.js +2 -4
- package/server-app.js.map +1 -1
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.loadCustomerNotificationMethods = loadCustomerNotificationMethods;
|
|
51
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
52
|
+
var customer_notification_collection_1 = require("../collections/customer-notification.collection");
|
|
53
|
+
var user_collection_1 = require("../collections/user.collection");
|
|
54
|
+
var common_1 = require("../util/common");
|
|
55
|
+
var DEFAULT_LIST_LIMIT = 100;
|
|
56
|
+
var MAX_LIST_LIMIT = 500;
|
|
57
|
+
var DEDUPE_WINDOW_MS = 30 * 60 * 1000;
|
|
58
|
+
var MAX_TARGET_USERS = 5000;
|
|
59
|
+
function normalizeString(value, maxLength) {
|
|
60
|
+
if (maxLength === void 0) { maxLength = 500; }
|
|
61
|
+
var normalized = String(value || '').trim();
|
|
62
|
+
if (!normalized) {
|
|
63
|
+
return '';
|
|
64
|
+
}
|
|
65
|
+
if (normalized.length <= maxLength) {
|
|
66
|
+
return normalized;
|
|
67
|
+
}
|
|
68
|
+
return normalized.slice(0, maxLength);
|
|
69
|
+
}
|
|
70
|
+
function normalizeNotificationCategory(value) {
|
|
71
|
+
var normalized = normalizeString(value, 40).toLowerCase();
|
|
72
|
+
if (!normalized) {
|
|
73
|
+
return 'system';
|
|
74
|
+
}
|
|
75
|
+
if (['autofix', 'slow-query', 'system', 'manual'].includes(normalized)) {
|
|
76
|
+
return normalized;
|
|
77
|
+
}
|
|
78
|
+
return 'system';
|
|
79
|
+
}
|
|
80
|
+
function normalizeNotificationSeverity(value) {
|
|
81
|
+
var normalized = normalizeString(value, 20).toLowerCase();
|
|
82
|
+
if (!normalized) {
|
|
83
|
+
return 'info';
|
|
84
|
+
}
|
|
85
|
+
if (['info', 'success', 'warning', 'error'].includes(normalized)) {
|
|
86
|
+
return normalized;
|
|
87
|
+
}
|
|
88
|
+
return 'info';
|
|
89
|
+
}
|
|
90
|
+
function normalizeListLimit(value) {
|
|
91
|
+
var parsed = Number(value);
|
|
92
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
93
|
+
return DEFAULT_LIST_LIMIT;
|
|
94
|
+
}
|
|
95
|
+
return Math.min(Math.floor(parsed), MAX_LIST_LIMIT);
|
|
96
|
+
}
|
|
97
|
+
function isSystemMethodUser(methodUser) {
|
|
98
|
+
return !methodUser || methodUser === 'Internal System';
|
|
99
|
+
}
|
|
100
|
+
function resolveMethodUser(methodUser) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
var idUser;
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
if (isSystemMethodUser(methodUser)) {
|
|
107
|
+
return [2 /*return*/, null];
|
|
108
|
+
}
|
|
109
|
+
if (typeof methodUser === 'object' && (methodUser === null || methodUser === void 0 ? void 0 : methodUser._id) && (methodUser === null || methodUser === void 0 ? void 0 : methodUser.roles)) {
|
|
110
|
+
return [2 /*return*/, methodUser];
|
|
111
|
+
}
|
|
112
|
+
idUser = normalizeString(typeof methodUser === 'string'
|
|
113
|
+
? methodUser
|
|
114
|
+
: ((methodUser === null || methodUser === void 0 ? void 0 : methodUser._id) || (methodUser === null || methodUser === void 0 ? void 0 : methodUser.id_user) || ''), 80);
|
|
115
|
+
if (!idUser) {
|
|
116
|
+
return [2 /*return*/, null];
|
|
117
|
+
}
|
|
118
|
+
return [4 /*yield*/, user_collection_1.Users.findById(idUser)];
|
|
119
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function isSuperAdmin(user) {
|
|
125
|
+
var _a;
|
|
126
|
+
return !!((_a = user === null || user === void 0 ? void 0 : user.roles) === null || _a === void 0 ? void 0 : _a.super_admin);
|
|
127
|
+
}
|
|
128
|
+
function uniqueUserIds(input) {
|
|
129
|
+
var e_1, _a;
|
|
130
|
+
var unique = new Set();
|
|
131
|
+
try {
|
|
132
|
+
for (var _b = __values((Array.isArray(input) ? input : [])), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
133
|
+
var entry = _c.value;
|
|
134
|
+
var id = normalizeString(entry, 80);
|
|
135
|
+
if (id) {
|
|
136
|
+
unique.add(id);
|
|
137
|
+
}
|
|
138
|
+
if (unique.size >= MAX_TARGET_USERS) {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
144
|
+
finally {
|
|
145
|
+
try {
|
|
146
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
147
|
+
}
|
|
148
|
+
finally { if (e_1) throw e_1.error; }
|
|
149
|
+
}
|
|
150
|
+
return Array.from(unique);
|
|
151
|
+
}
|
|
152
|
+
function resolveTargetUsers(payload) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
154
|
+
var targetType, users_1, idClient, users;
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
switch (_a.label) {
|
|
157
|
+
case 0:
|
|
158
|
+
targetType = normalizeString((payload === null || payload === void 0 ? void 0 : payload.target_type) || 'client', 20).toLowerCase() || 'client';
|
|
159
|
+
if (targetType === 'users') {
|
|
160
|
+
return [2 /*return*/, uniqueUserIds((payload === null || payload === void 0 ? void 0 : payload.id_users) || [])];
|
|
161
|
+
}
|
|
162
|
+
if (!(targetType === 'all_active')) return [3 /*break*/, 2];
|
|
163
|
+
return [4 /*yield*/, user_collection_1.Users.find({
|
|
164
|
+
active: true,
|
|
165
|
+
username: {
|
|
166
|
+
$exists: true
|
|
167
|
+
}
|
|
168
|
+
}, {
|
|
169
|
+
projection: {
|
|
170
|
+
_id: 1
|
|
171
|
+
},
|
|
172
|
+
limit: MAX_TARGET_USERS
|
|
173
|
+
})];
|
|
174
|
+
case 1:
|
|
175
|
+
users_1 = _a.sent();
|
|
176
|
+
return [2 /*return*/, uniqueUserIds(users_1.map(function (user) { return user === null || user === void 0 ? void 0 : user._id; }))];
|
|
177
|
+
case 2:
|
|
178
|
+
idClient = normalizeString(payload === null || payload === void 0 ? void 0 : payload.id_client, 80);
|
|
179
|
+
if (!idClient) {
|
|
180
|
+
return [2 /*return*/, []];
|
|
181
|
+
}
|
|
182
|
+
return [4 /*yield*/, user_collection_1.Users.find({
|
|
183
|
+
active: true,
|
|
184
|
+
username: {
|
|
185
|
+
$exists: true
|
|
186
|
+
},
|
|
187
|
+
$or: [
|
|
188
|
+
{ 'other.id_client': idClient },
|
|
189
|
+
{ 'other.idClient': idClient },
|
|
190
|
+
{ id_client: idClient }
|
|
191
|
+
]
|
|
192
|
+
}, {
|
|
193
|
+
projection: {
|
|
194
|
+
_id: 1
|
|
195
|
+
},
|
|
196
|
+
limit: MAX_TARGET_USERS
|
|
197
|
+
})];
|
|
198
|
+
case 3:
|
|
199
|
+
users = _a.sent();
|
|
200
|
+
return [2 /*return*/, uniqueUserIds(users.map(function (user) { return user === null || user === void 0 ? void 0 : user._id; }))];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function loadCustomerNotificationMethods(methodManager) {
|
|
206
|
+
methodManager.methods({
|
|
207
|
+
createCustomerNotification: {
|
|
208
|
+
check: new simpl_schema_1.default({
|
|
209
|
+
payload: {
|
|
210
|
+
type: Object,
|
|
211
|
+
blackbox: true
|
|
212
|
+
}
|
|
213
|
+
}),
|
|
214
|
+
function: function (payload) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
+
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
|
+
return __generator(this, function (_a) {
|
|
218
|
+
switch (_a.label) {
|
|
219
|
+
case 0: return [4 /*yield*/, resolveMethodUser(this.user)];
|
|
220
|
+
case 1:
|
|
221
|
+
methodUser = _a.sent();
|
|
222
|
+
systemUser = isSystemMethodUser(this.user);
|
|
223
|
+
if (!systemUser && !isSuperAdmin(methodUser)) {
|
|
224
|
+
throw new Error('Only super admins can create notifications.');
|
|
225
|
+
}
|
|
226
|
+
title = normalizeString(payload === null || payload === void 0 ? void 0 : payload.title, 160);
|
|
227
|
+
message = normalizeString(payload === null || payload === void 0 ? void 0 : payload.message, 1500);
|
|
228
|
+
if (!title || !message) {
|
|
229
|
+
throw new Error('Notification title and message are required.');
|
|
230
|
+
}
|
|
231
|
+
idClient = normalizeString(payload === null || payload === void 0 ? void 0 : payload.id_client, 80);
|
|
232
|
+
clientName = normalizeString(payload === null || payload === void 0 ? void 0 : payload.client_name, 200);
|
|
233
|
+
category = normalizeNotificationCategory(payload === null || payload === void 0 ? void 0 : payload.category);
|
|
234
|
+
severity = normalizeNotificationSeverity(payload === null || payload === void 0 ? void 0 : payload.severity);
|
|
235
|
+
details = normalizeString(payload === null || payload === void 0 ? void 0 : payload.details, 6000);
|
|
236
|
+
source = normalizeString(payload === null || payload === void 0 ? void 0 : payload.source, 120);
|
|
237
|
+
sourceId = normalizeString(payload === null || payload === void 0 ? void 0 : payload.source_id, 120);
|
|
238
|
+
actionLabel = normalizeString(payload === null || payload === void 0 ? void 0 : payload.action_label, 80);
|
|
239
|
+
actionRoute = normalizeString(payload === null || payload === void 0 ? void 0 : payload.action_route, 500);
|
|
240
|
+
dedupeKey = normalizeString(payload === null || payload === void 0 ? void 0 : payload.dedupe_key, 160);
|
|
241
|
+
expiresAt = (payload === null || payload === void 0 ? void 0 : payload.expires_at) instanceof Date && !Number.isNaN(payload.expires_at.getTime())
|
|
242
|
+
? payload.expires_at
|
|
243
|
+
: undefined;
|
|
244
|
+
metadata = (payload === null || payload === void 0 ? void 0 : payload.metadata) && typeof payload.metadata === 'object'
|
|
245
|
+
? payload.metadata
|
|
246
|
+
: undefined;
|
|
247
|
+
return [4 /*yield*/, resolveTargetUsers(payload)];
|
|
248
|
+
case 2:
|
|
249
|
+
targetUsers = _a.sent();
|
|
250
|
+
if (!targetUsers.length) {
|
|
251
|
+
return [2 /*return*/, {
|
|
252
|
+
created: 0,
|
|
253
|
+
reason: 'no_target_users'
|
|
254
|
+
}];
|
|
255
|
+
}
|
|
256
|
+
now = new Date();
|
|
257
|
+
createById = systemUser ? 'Internal System' : normalizeString(methodUser === null || methodUser === void 0 ? void 0 : methodUser._id, 80);
|
|
258
|
+
createByName = systemUser
|
|
259
|
+
? 'Internal System'
|
|
260
|
+
: normalizeString((methodUser === null || methodUser === void 0 ? void 0 : methodUser.fullname) || (methodUser === null || methodUser === void 0 ? void 0 : methodUser.username), 200);
|
|
261
|
+
skippedByDedupe = new Set();
|
|
262
|
+
if (!dedupeKey) return [3 /*break*/, 4];
|
|
263
|
+
cutoff = new Date(now.getTime() - DEDUPE_WINDOW_MS);
|
|
264
|
+
return [4 /*yield*/, customer_notification_collection_1.CustomerNotifications.find({
|
|
265
|
+
id_user: {
|
|
266
|
+
$in: targetUsers
|
|
267
|
+
},
|
|
268
|
+
dedupe_key: dedupeKey,
|
|
269
|
+
createdAt: {
|
|
270
|
+
$gte: cutoff
|
|
271
|
+
}
|
|
272
|
+
}, {
|
|
273
|
+
projection: {
|
|
274
|
+
id_user: 1
|
|
275
|
+
},
|
|
276
|
+
limit: MAX_TARGET_USERS
|
|
277
|
+
})];
|
|
278
|
+
case 3:
|
|
279
|
+
existing = _a.sent();
|
|
280
|
+
skippedByDedupe = new Set(existing.map(function (entry) { return normalizeString(entry === null || entry === void 0 ? void 0 : entry.id_user, 80); }).filter(Boolean));
|
|
281
|
+
_a.label = 4;
|
|
282
|
+
case 4:
|
|
283
|
+
docs = targetUsers
|
|
284
|
+
.filter(function (idUser) { return !skippedByDedupe.has(idUser); })
|
|
285
|
+
.map(function (idUser) { return ({
|
|
286
|
+
_id: (0, common_1.objectIdHexString)(),
|
|
287
|
+
__v: 0,
|
|
288
|
+
id_user: idUser,
|
|
289
|
+
id_client: idClient || undefined,
|
|
290
|
+
client_name: clientName || undefined,
|
|
291
|
+
title: title,
|
|
292
|
+
message: message,
|
|
293
|
+
details: details || undefined,
|
|
294
|
+
category: category,
|
|
295
|
+
severity: severity,
|
|
296
|
+
status: 'unread',
|
|
297
|
+
read_at: undefined,
|
|
298
|
+
read_by: '',
|
|
299
|
+
source: source || undefined,
|
|
300
|
+
source_id: sourceId || undefined,
|
|
301
|
+
action_label: actionLabel || undefined,
|
|
302
|
+
action_route: actionRoute || undefined,
|
|
303
|
+
dedupe_key: dedupeKey || undefined,
|
|
304
|
+
metadata: metadata,
|
|
305
|
+
expires_at: expiresAt,
|
|
306
|
+
created_by: createById || undefined,
|
|
307
|
+
created_by_name: createByName || undefined,
|
|
308
|
+
createdAt: now,
|
|
309
|
+
updatedAt: now
|
|
310
|
+
}); });
|
|
311
|
+
if (!docs.length) {
|
|
312
|
+
return [2 /*return*/, {
|
|
313
|
+
created: 0,
|
|
314
|
+
reason: 'dedupe_suppressed'
|
|
315
|
+
}];
|
|
316
|
+
}
|
|
317
|
+
return [4 /*yield*/, customer_notification_collection_1.CustomerNotifications.insertMany(docs)];
|
|
318
|
+
case 5:
|
|
319
|
+
_a.sent();
|
|
320
|
+
return [2 /*return*/, {
|
|
321
|
+
created: docs.length,
|
|
322
|
+
targeted: targetUsers.length
|
|
323
|
+
}];
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
markUserNotificationRead: {
|
|
330
|
+
check: new simpl_schema_1.default({
|
|
331
|
+
id_notification: {
|
|
332
|
+
type: String
|
|
333
|
+
}
|
|
334
|
+
}),
|
|
335
|
+
function: function (id_notification) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
337
|
+
var methodUser, idUser;
|
|
338
|
+
return __generator(this, function (_a) {
|
|
339
|
+
switch (_a.label) {
|
|
340
|
+
case 0: return [4 /*yield*/, resolveMethodUser(this.user)];
|
|
341
|
+
case 1:
|
|
342
|
+
methodUser = _a.sent();
|
|
343
|
+
idUser = normalizeString(methodUser === null || methodUser === void 0 ? void 0 : methodUser._id, 80);
|
|
344
|
+
if (!idUser) {
|
|
345
|
+
throw new Error('You must be logged in to mark notifications as read.');
|
|
346
|
+
}
|
|
347
|
+
return [4 /*yield*/, customer_notification_collection_1.CustomerNotifications.updateOne({
|
|
348
|
+
_id: id_notification,
|
|
349
|
+
id_user: idUser
|
|
350
|
+
}, {
|
|
351
|
+
$set: {
|
|
352
|
+
status: 'read',
|
|
353
|
+
read_at: new Date(),
|
|
354
|
+
read_by: idUser
|
|
355
|
+
}
|
|
356
|
+
})];
|
|
357
|
+
case 2:
|
|
358
|
+
_a.sent();
|
|
359
|
+
return [2 /*return*/, true];
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
markAllUserNotificationsRead: {
|
|
366
|
+
check: new simpl_schema_1.default({
|
|
367
|
+
id_client: {
|
|
368
|
+
type: String,
|
|
369
|
+
optional: true
|
|
370
|
+
}
|
|
371
|
+
}),
|
|
372
|
+
function: function (id_client) {
|
|
373
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
374
|
+
var methodUser, idUser, idClient, query;
|
|
375
|
+
return __generator(this, function (_a) {
|
|
376
|
+
switch (_a.label) {
|
|
377
|
+
case 0: return [4 /*yield*/, resolveMethodUser(this.user)];
|
|
378
|
+
case 1:
|
|
379
|
+
methodUser = _a.sent();
|
|
380
|
+
idUser = normalizeString(methodUser === null || methodUser === void 0 ? void 0 : methodUser._id, 80);
|
|
381
|
+
if (!idUser) {
|
|
382
|
+
throw new Error('You must be logged in to mark notifications as read.');
|
|
383
|
+
}
|
|
384
|
+
idClient = normalizeString(id_client, 80);
|
|
385
|
+
query = {
|
|
386
|
+
id_user: idUser,
|
|
387
|
+
status: 'unread'
|
|
388
|
+
};
|
|
389
|
+
if (idClient) {
|
|
390
|
+
query.id_client = idClient;
|
|
391
|
+
}
|
|
392
|
+
return [4 /*yield*/, customer_notification_collection_1.CustomerNotifications.updateMany(query, {
|
|
393
|
+
$set: {
|
|
394
|
+
status: 'read',
|
|
395
|
+
read_at: new Date(),
|
|
396
|
+
read_by: idUser
|
|
397
|
+
}
|
|
398
|
+
})];
|
|
399
|
+
case 2:
|
|
400
|
+
_a.sent();
|
|
401
|
+
return [2 /*return*/, true];
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
listCustomerNotifications: {
|
|
408
|
+
check: new simpl_schema_1.default({
|
|
409
|
+
payload: {
|
|
410
|
+
type: Object,
|
|
411
|
+
optional: true,
|
|
412
|
+
blackbox: true
|
|
413
|
+
}
|
|
414
|
+
}),
|
|
415
|
+
function: function (payload) {
|
|
416
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
417
|
+
var methodUser, systemUser, query, idUser, idClient, status, limit;
|
|
418
|
+
return __generator(this, function (_a) {
|
|
419
|
+
switch (_a.label) {
|
|
420
|
+
case 0: return [4 /*yield*/, resolveMethodUser(this.user)];
|
|
421
|
+
case 1:
|
|
422
|
+
methodUser = _a.sent();
|
|
423
|
+
systemUser = isSystemMethodUser(this.user);
|
|
424
|
+
if (!systemUser && !isSuperAdmin(methodUser)) {
|
|
425
|
+
throw new Error('Only super admins can list all notifications.');
|
|
426
|
+
}
|
|
427
|
+
query = {};
|
|
428
|
+
idUser = normalizeString(payload === null || payload === void 0 ? void 0 : payload.id_user, 80);
|
|
429
|
+
idClient = normalizeString(payload === null || payload === void 0 ? void 0 : payload.id_client, 80);
|
|
430
|
+
status = normalizeString(payload === null || payload === void 0 ? void 0 : payload.status, 20).toLowerCase();
|
|
431
|
+
if (idUser) {
|
|
432
|
+
query.id_user = idUser;
|
|
433
|
+
}
|
|
434
|
+
if (idClient) {
|
|
435
|
+
query.id_client = idClient;
|
|
436
|
+
}
|
|
437
|
+
if (status === 'unread' || status === 'read') {
|
|
438
|
+
query.status = status;
|
|
439
|
+
}
|
|
440
|
+
limit = normalizeListLimit(payload === null || payload === void 0 ? void 0 : payload.limit);
|
|
441
|
+
return [4 /*yield*/, customer_notification_collection_1.CustomerNotifications.find(query, {
|
|
442
|
+
sort: {
|
|
443
|
+
createdAt: -1
|
|
444
|
+
},
|
|
445
|
+
limit: limit
|
|
446
|
+
})];
|
|
447
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
//# sourceMappingURL=customer-notifications.js.map
|
|
@@ -0,0 +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,CA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C;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\t\tlimit\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n}\n"]}
|
package/methods/logs.js
CHANGED
|
@@ -83,8 +83,7 @@ function loadLogMethods(methodManager) {
|
|
|
83
83
|
})];
|
|
84
84
|
case 1:
|
|
85
85
|
_d.sent();
|
|
86
|
-
if (!
|
|
87
|
-
&& resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200')) return [3 /*break*/, 2];
|
|
86
|
+
if (!resolveio_server_app_1.ResolveIOServer.shouldWriteLogsOffline()) return [3 /*break*/, 2];
|
|
88
87
|
resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({
|
|
89
88
|
type: 'log',
|
|
90
89
|
data: {
|
|
@@ -136,8 +135,7 @@ function loadLogMethods(methodManager) {
|
|
|
136
135
|
return __generator(this, function (_a) {
|
|
137
136
|
switch (_a.label) {
|
|
138
137
|
case 0:
|
|
139
|
-
if (!
|
|
140
|
-
&& resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200')) return [3 /*break*/, 1];
|
|
138
|
+
if (!resolveio_server_app_1.ResolveIOServer.shouldWriteLogsOffline()) return [3 /*break*/, 1];
|
|
141
139
|
resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({
|
|
142
140
|
type: 'log-subscription',
|
|
143
141
|
data: {
|
package/methods/logs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/methods/logs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,wCAkYC;AA3YD,8FAAkF;AAClF,0FAA8E;AAC9E,gEAAqD;AAErD,gEAA0D;AAC1D,yCAAmD;AACnD,yDAAuD;AACvD,yDAA0D;AAE1D,SAAgB,cAAc,CAAC,aAA4B;IACzD,aAAa,CAAC,OAAO,CAAC;QACrB,cAAc,EAAE;YACf,QAAQ,EAAE,UAAe,OAAO,EAAE,IAAI;;;;;;;gCAC/B,oBAAoB,GAAG,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI;oCAC5D,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,aAAa,KAAK,QAAQ,IAAI,IAAI,CAAC,aAAa,CAAC;2CAC5D,CAAC,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;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,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,uBAAuB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAAC,EAAE,IAAI,CAAC,EAAA;;gCAxB/H,eAAe,GAAG,SAwB6G;gCAEhH,qBAAM,8CAAgB,CAAC,SAAS,CAAC;wCACnD;4CACC,MAAM,EAAE;gDACP,IAAI,EAAE;oDACL;wDACC,SAAS,EAAE,EAAC,IAAI,EAAE,UAAU,EAAC;qDAC7B;oDACD;wDACC,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC;qDAC3B;iDACD;6CACD;yCACD;wCACD;4CACC,MAAM,EAAE;gDACP,GAAG,EAAE,OAAO;gDACZ,KAAK,EAAE;oDACN,IAAI,EAAE,CAAC;iDACP;6CACD;yCACD;wCACD;4CACC,KAAK,EAAE,SAAS;yCAChB;qCACD,EAAE,EAAC,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,uBAAuB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAAC,EAAE,IAAI,CAAC,EAAA;;gCAxB/H,YAAY,GAAG,SAwBgH;gCAEnI,sBAAO;wCACN,OAAO,EAAE,SAAS;wCAClB,aAAa,EAAE,aAAa;wCAC5B,eAAe,EAAE,eAAe;wCAChC,YAAY,EAAE,YAAY;qCAC1B,EAAC;;;;aACF;YACD,cAAc,EAAE,IAAI;SACpB;KACD,CAAC,CAAC;AACJ,CAAC","file":"logs.js","sourcesContent":["import { LogMethodLatencies } from '../collections/log-method-latency.collection';\nimport { LogSubscriptions } from '../collections/log-subscription.collection';\nimport { Logs } from '../collections/log.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\nimport { ErrorReporter } from '../util/error-reporter';\nimport { getCorrelationId } from '../util/error-tracking';\n\nexport function loadLogMethods(methodManager: MethodManager) {\n\t\tmethodManager.methods({\n\t\t\tinsertErrorLog: {\n\t\t\t\tfunction: async function(message, data) {\n\t\t\t\t\tconst payloadCorrelationId = typeof data === 'object' && data\n\t\t\t\t\t\t? (typeof data.correlationId === 'string' && data.correlationId)\n\t\t\t\t\t\t\t|| (typeof data.error === 'object' && data.error && typeof data.error.correlationId === 'string' && data.error.correlationId)\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tconst correlationId = getCorrelationId() || payloadCorrelationId || objectIdHexString();\n\t\t\t\t\tconst payload = {\n\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\tid_user: this.id_user,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\tdata,\n\t\t\t\t\tcorrelationId\n\t\t\t\t};\n\n\t\t\t\tawait ErrorReporter.report({\n\t\t\t\t\tsourceApp: 'method-logs',\n\t\t\t\t\tmessage: 'Error Detected - ' + ResolveIOServer.getClientName(),\n\t\t\t\t\tenvironment: this.serverConfig?.ROOT_URL || ResolveIOServer.getServerConfig()?.ROOT_URL,\n\t\t\t\t\tclientSlug: ResolveIOServer.getClientName(),\n\t\t\t\t\tclientName: ResolveIOServer.getServerConfig()?.CLIENT_NAME,\n\t\t\t\t\tseverity: 'error',\n\t\t\t\t\tcontext: payload,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tcontext: 'insertErrorLog',\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t},\n\t\t\t\t\tcorrelationId\n\t\t\t\t});\n\n\t\t\t\tif (\n\t\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t\t\t) {\n\t\t\t\t\tResolveIOServer.getLocalLogManager().writeLog({\n\t\t\t\t\t\ttype: 'log',\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\tpayload: JSON.stringify([payload], null, 2),\n\t\t\t\t\t\t\tmethod: '',\n\t\t\t\t\t\t\tid_user: this.id_user || '',\n\t\t\t\t\t\t\tuser: this.user || '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: '',\n\t\t\t\t\t\t\tinstance_index: process.env.NODE_APP_INSTANCE || '0',\n\t\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tawait Logs.insertOne({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\tpayload: JSON.stringify([payload], null, 2),\n\t\t\t\t\t\tmethod: '',\n\t\t\t\t\t\tid_user: this.id_user || '',\n\t\t\t\t\t\tuser: this.user || '',\n\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\troute: '',\n\t\t\t\t\t\tclient: 'ResolveIO',\n\t\t\t\t\t\tinstance: 'backend.resolveio.com',\n\t\t\t\t\t\tinstance_index: process.env.NODE_APP_INSTANCE || '0',\n\t\t\t\t\t\tcorrelationId\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\tskipValidation: true\n\t\t},\n\t\tinsertSubscriptionLog: {\n\t\t\tfunction: async function(type, subscription, collection_name, subData) {\n\t\t\t\tif (\n\t\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t\t\t) {\n\t\t\t\t\tResolveIOServer.getLocalLogManager().writeLog({\n\t\t\t\t\t\ttype: 'log-subscription',\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\ttype: type,\n\t\t\t\t\t\t\tsubscription: subscription,\n\t\t\t\t\t\t\tcollection_name: collection_name,\n\t\t\t\t\t\t\tsubData: subData,\n\t\t\t\t\t\t\tinstance_index: process.env.NODE_APP_INSTANCE || '0'\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tawait LogSubscriptions.create({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\ttype: type,\n\t\t\t\t\t\tsubscription: subscription,\n\t\t\t\t\t\tcollection_name: collection_name,\n\t\t\t\t\t\tsubData: subData,\n\t\t\t\t\t\tclient: 'ResolveIO',\n\t\t\t\t\t\tinstance: 'backend.resolveio.com'\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\tskipValidation: true\n\t\t},\n\t\tsuperadminAPM: {\n\t\t\tfunction: async function(date_start: Date, date_end: Date, graphInterval) {\n\t\t\t\tlet latencies = await LogMethodLatencies.aggregate([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t_id: '$method',\n\t\t\t\t\t\t\tmethod: {$first: '$method'},\n\t\t\t\t\t\t\tcount: {$sum: 1},\n\t\t\t\t\t\t\tlatency_min: {$min: '$latency_ms'},\n\t\t\t\t\t\t\tlatency_avg: {$avg: '$latency_ms'},\n\t\t\t\t\t\t\tlatency_max: {$max: '$latency_ms'}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\tlet subscriptions = await LogSubscriptions.aggregate([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t_id: '$subscription',\n\t\t\t\t\t\t\tsubscription: {$first: '$subscription'},\n\t\t\t\t\t\t\tcount: {$sum: 1}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\tlet groupId = {};\n\t\t\t\tlet groupSort = {};\n\n\t\t\t\tif (graphInterval === 'seconds') {\n\t\t\t\t\tgroupId = {\n\t\t\t\t\t\tsecond: {\n\t\t\t\t\t\t\t$second: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tminute: {\n\t\t\t\t\t\t\t$minute: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t'_id.hour': 1,\n\t\t\t\t\t\t'_id.minute': 1,\n\t\t\t\t\t\t'_id.second': 1\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (graphInterval === 'minutes') {\n\t\t\t\t\tgroupId = {\n\t\t\t\t\t\tminute: {\n\t\t\t\t\t\t\t$minute: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t'_id.hour': 1,\n\t\t\t\t\t\t'_id.minute': 1\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (graphInterval === 'hours') {\n\t\t\t\t\tgroupId = {\n\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t'_id.hour': 1\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tgroupId = {\n\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t'_id.day': 1\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tlet methodGraphData = await LogMethodLatencies.aggregate([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t_id: groupId,\n\t\t\t\t\t\t\tcount: {\n\t\t\t\t\t\t\t\t$sum: 1\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$sort: groupSort\n\t\t\t\t\t}\n\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\tlet subGraphData = await LogSubscriptions.aggregate([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t_id: groupId,\n\t\t\t\t\t\t\tcount: {\n\t\t\t\t\t\t\t\t$sum: 1\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$sort: groupSort\n\t\t\t\t\t}\n\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\treturn {\n\t\t\t\t\tmethods: latencies,\n\t\t\t\t\tsubscriptions: subscriptions,\n\t\t\t\t\tmethodGraphData: methodGraphData,\n\t\t\t\t\tsubGraphData: subGraphData\n\t\t\t\t};\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t}\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/methods/logs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,wCAgYC;AAzYD,8FAAkF;AAClF,0FAA8E;AAC9E,gEAAqD;AAErD,gEAA0D;AAC1D,yCAAmD;AACnD,yDAAuD;AACvD,yDAA0D;AAE1D,SAAgB,cAAc,CAAC,aAA4B;IACzD,aAAa,CAAC,OAAO,CAAC;QACrB,cAAc,EAAE;YACf,QAAQ,EAAE,UAAe,OAAO,EAAE,IAAI;;;;;;;gCAC/B,oBAAoB,GAAG,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI;oCAC5D,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,aAAa,KAAK,QAAQ,IAAI,IAAI,CAAC,aAAa,CAAC;2CAC5D,CAAC,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;oCAC9H,CAAC,CAAC,SAAS,CAAC;gCACP,aAAa,GAAG,IAAA,iCAAgB,GAAE,IAAI,oBAAoB,IAAI,IAAA,0BAAiB,GAAE,CAAC;gCAClF,OAAO,GAAG;oCACf,IAAI,EAAE,IAAI,CAAC,IAAI;oCACf,OAA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ACC,MAAM,EAAE;gDACP,GAAG,EAAE,OAAO;gDACZ,KAAK,EAAE;oDACN,IAAI,EAAE,CAAC;iDACP;6CACD;yCACD;wCACD;4CACC,KAAK,EAAE,SAAS;yCAChB;qCACD,EAAE,EAAC,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,uBAAuB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAAC,EAAE,IAAI,CAAC,EAAA;;gCAxB/H,YAAY,GAAG,SAwBgH;gCAEnI,sBAAO;wCACN,OAAO,EAAE,SAAS;wCAClB,aAAa,EAAE,aAAa;wCAC5B,eAAe,EAAE,eAAe;wCAChC,YAAY,EAAE,YAAY;qCAC1B,EAAC;;;;aACF;YACD,cAAc,EAAE,IAAI;SACpB;KACD,CAAC,CAAC;AACJ,CAAC","file":"logs.js","sourcesContent":["import { LogMethodLatencies } from '../collections/log-method-latency.collection';\nimport { LogSubscriptions } from '../collections/log-subscription.collection';\nimport { Logs } from '../collections/log.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\nimport { ErrorReporter } from '../util/error-reporter';\nimport { getCorrelationId } from '../util/error-tracking';\n\nexport function loadLogMethods(methodManager: MethodManager) {\n\t\tmethodManager.methods({\n\t\t\tinsertErrorLog: {\n\t\t\t\tfunction: async function(message, data) {\n\t\t\t\t\tconst payloadCorrelationId = typeof data === 'object' && data\n\t\t\t\t\t\t? (typeof data.correlationId === 'string' && data.correlationId)\n\t\t\t\t\t\t\t|| (typeof data.error === 'object' && data.error && typeof data.error.correlationId === 'string' && data.error.correlationId)\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tconst correlationId = getCorrelationId() || payloadCorrelationId || objectIdHexString();\n\t\t\t\t\tconst payload = {\n\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\tid_user: this.id_user,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\tdata,\n\t\t\t\t\tcorrelationId\n\t\t\t\t};\n\n\t\t\t\tawait ErrorReporter.report({\n\t\t\t\t\tsourceApp: 'method-logs',\n\t\t\t\t\tmessage: 'Error Detected - ' + ResolveIOServer.getClientName(),\n\t\t\t\t\tenvironment: this.serverConfig?.ROOT_URL || ResolveIOServer.getServerConfig()?.ROOT_URL,\n\t\t\t\t\tclientSlug: ResolveIOServer.getClientName(),\n\t\t\t\t\tclientName: ResolveIOServer.getServerConfig()?.CLIENT_NAME,\n\t\t\t\t\tseverity: 'error',\n\t\t\t\t\tcontext: payload,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tcontext: 'insertErrorLog',\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t},\n\t\t\t\t\tcorrelationId\n\t\t\t\t});\n\n\t\t\t\tif (\n\t\t\t\t\tResolveIOServer.shouldWriteLogsOffline()\n\t\t\t\t) {\n\t\t\t\t\tResolveIOServer.getLocalLogManager().writeLog({\n\t\t\t\t\t\ttype: 'log',\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\tpayload: JSON.stringify([payload], null, 2),\n\t\t\t\t\t\t\tmethod: '',\n\t\t\t\t\t\t\tid_user: this.id_user || '',\n\t\t\t\t\t\t\tuser: this.user || '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: '',\n\t\t\t\t\t\t\tinstance_index: process.env.NODE_APP_INSTANCE || '0',\n\t\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tawait Logs.insertOne({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\ttype: 'error',\n\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\tpayload: JSON.stringify([payload], null, 2),\n\t\t\t\t\t\tmethod: '',\n\t\t\t\t\t\tid_user: this.id_user || '',\n\t\t\t\t\t\tuser: this.user || '',\n\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\troute: '',\n\t\t\t\t\t\tclient: 'ResolveIO',\n\t\t\t\t\t\tinstance: 'backend.resolveio.com',\n\t\t\t\t\t\tinstance_index: process.env.NODE_APP_INSTANCE || '0',\n\t\t\t\t\t\tcorrelationId\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\tskipValidation: true\n\t\t},\n\t\tinsertSubscriptionLog: {\n\t\t\tfunction: async function(type, subscription, collection_name, subData) {\n\t\t\t\tif (\n\t\t\t\t\tResolveIOServer.shouldWriteLogsOffline()\n\t\t\t\t) {\n\t\t\t\t\tResolveIOServer.getLocalLogManager().writeLog({\n\t\t\t\t\t\ttype: 'log-subscription',\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\ttype: type,\n\t\t\t\t\t\t\tsubscription: subscription,\n\t\t\t\t\t\t\tcollection_name: collection_name,\n\t\t\t\t\t\t\tsubData: subData,\n\t\t\t\t\t\t\tinstance_index: process.env.NODE_APP_INSTANCE || '0'\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tawait LogSubscriptions.create({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\ttype: type,\n\t\t\t\t\t\tsubscription: subscription,\n\t\t\t\t\t\tcollection_name: collection_name,\n\t\t\t\t\t\tsubData: subData,\n\t\t\t\t\t\tclient: 'ResolveIO',\n\t\t\t\t\t\tinstance: 'backend.resolveio.com'\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\tskipValidation: true\n\t\t},\n\t\tsuperadminAPM: {\n\t\t\tfunction: async function(date_start: Date, date_end: Date, graphInterval) {\n\t\t\t\tlet latencies = await LogMethodLatencies.aggregate([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t_id: '$method',\n\t\t\t\t\t\t\tmethod: {$first: '$method'},\n\t\t\t\t\t\t\tcount: {$sum: 1},\n\t\t\t\t\t\t\tlatency_min: {$min: '$latency_ms'},\n\t\t\t\t\t\t\tlatency_avg: {$avg: '$latency_ms'},\n\t\t\t\t\t\t\tlatency_max: {$max: '$latency_ms'}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\tlet subscriptions = await LogSubscriptions.aggregate([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t_id: '$subscription',\n\t\t\t\t\t\t\tsubscription: {$first: '$subscription'},\n\t\t\t\t\t\t\tcount: {$sum: 1}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\tlet groupId = {};\n\t\t\t\tlet groupSort = {};\n\n\t\t\t\tif (graphInterval === 'seconds') {\n\t\t\t\t\tgroupId = {\n\t\t\t\t\t\tsecond: {\n\t\t\t\t\t\t\t$second: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tminute: {\n\t\t\t\t\t\t\t$minute: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t'_id.hour': 1,\n\t\t\t\t\t\t'_id.minute': 1,\n\t\t\t\t\t\t'_id.second': 1\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (graphInterval === 'minutes') {\n\t\t\t\t\tgroupId = {\n\t\t\t\t\t\tminute: {\n\t\t\t\t\t\t\t$minute: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t'_id.hour': 1,\n\t\t\t\t\t\t'_id.minute': 1\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (graphInterval === 'hours') {\n\t\t\t\t\tgroupId = {\n\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t'_id.hour': 1\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tgroupId = {\n\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t},\n\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t} \n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t'_id.day': 1\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tlet methodGraphData = await LogMethodLatencies.aggregate([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t_id: groupId,\n\t\t\t\t\t\t\tcount: {\n\t\t\t\t\t\t\t\t$sum: 1\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$sort: groupSort\n\t\t\t\t\t}\n\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\tlet subGraphData = await LogSubscriptions.aggregate([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t_id: groupId,\n\t\t\t\t\t\t\tcount: {\n\t\t\t\t\t\t\t\t$sum: 1\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$sort: groupSort\n\t\t\t\t\t}\n\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\treturn {\n\t\t\t\t\tmethods: latencies,\n\t\t\t\t\tsubscriptions: subscriptions,\n\t\t\t\t\tmethodGraphData: methodGraphData,\n\t\t\t\t\tsubGraphData: subGraphData\n\t\t\t\t};\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t}\n\t});\n}\n"]}
|