@resolveio/server-lib 22.2.4 → 22.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/collections/app-setting.collection.d.ts +3 -0
  2. package/collections/app-setting.collection.js +103 -0
  3. package/collections/app-setting.collection.js.map +1 -0
  4. package/managers/customer-notification-content.manager.d.ts +55 -0
  5. package/managers/customer-notification-content.manager.js +158 -0
  6. package/managers/customer-notification-content.manager.js.map +1 -0
  7. package/managers/diagnostic-manager-bootstrap.d.ts +9 -0
  8. package/managers/diagnostic-manager-bootstrap.js +260 -0
  9. package/managers/diagnostic-manager-bootstrap.js.map +1 -0
  10. package/managers/error-auto-fix.manager.d.ts +143 -0
  11. package/managers/error-auto-fix.manager.js +2934 -0
  12. package/managers/error-auto-fix.manager.js.map +1 -0
  13. package/managers/method.manager.js +2 -0
  14. package/managers/method.manager.js.map +1 -1
  15. package/managers/slow-query-verifier.manager.d.ts +114 -0
  16. package/managers/slow-query-verifier.manager.js +3358 -0
  17. package/managers/slow-query-verifier.manager.js.map +1 -0
  18. package/managers/slow-query.manager.d.ts +28 -0
  19. package/managers/slow-query.manager.js +468 -0
  20. package/managers/slow-query.manager.js.map +1 -0
  21. package/managers/subscription.manager.js +2 -0
  22. package/managers/subscription.manager.js.map +1 -1
  23. package/methods/app-settings.d.ts +2 -0
  24. package/methods/app-settings.js +169 -0
  25. package/methods/app-settings.js.map +1 -0
  26. package/methods/customer-notifications.js +77 -9
  27. package/methods/customer-notifications.js.map +1 -1
  28. package/methods.ts +3 -0
  29. package/models/app-setting.model.d.ts +16 -0
  30. package/models/app-setting.model.js +4 -0
  31. package/models/app-setting.model.js.map +1 -0
  32. package/package.json +3 -1
  33. package/public_api.d.ts +9 -0
  34. package/public_api.js +9 -0
  35. package/public_api.js.map +1 -1
  36. package/publications/app-settings.d.ts +2 -0
  37. package/publications/app-settings.js +28 -0
  38. package/publications/app-settings.js.map +1 -0
  39. package/publications.ts +6 -0
  40. package/types/error-report.d.ts +25 -0
  41. package/types/error-report.js +4 -0
  42. package/types/error-report.js.map +1 -0
  43. package/types/slow-query-report.d.ts +27 -0
  44. package/types/slow-query-report.js +6 -0
  45. package/types/slow-query-report.js.map +1 -0
@@ -0,0 +1,2 @@
1
+ import { MethodManager } from '../managers/method.manager';
2
+ export declare function loadAppSettingsMethods(methodManager: MethodManager): void;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ 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);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.loadAppSettingsMethods = loadAppSettingsMethods;
51
+ var simpl_schema_1 = require("simpl-schema");
52
+ var app_setting_collection_1 = require("../collections/app-setting.collection");
53
+ var common_1 = require("../util/common");
54
+ function loadAppSettingsMethods(methodManager) {
55
+ methodManager.methods({
56
+ appSettingsUpsert: {
57
+ check: new simpl_schema_1.default({
58
+ settings: {
59
+ type: Object,
60
+ blackbox: true
61
+ }
62
+ }),
63
+ function: function (settings) {
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var update, idSetting, existing, now, newIdSetting, insertDoc;
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0:
69
+ update = {
70
+ updatedAt: new Date()
71
+ };
72
+ if (settings.company_name !== undefined) {
73
+ update.company_name = normalizeOptionalString(settings.company_name);
74
+ }
75
+ if (settings.timezone !== undefined) {
76
+ update.timezone = normalizeOptionalString(settings.timezone);
77
+ }
78
+ if (settings.currency !== undefined) {
79
+ update.currency = normalizeOptionalString(settings.currency);
80
+ }
81
+ if (settings.invoice_prefix !== undefined) {
82
+ update.invoice_prefix = normalizeOptionalString(settings.invoice_prefix);
83
+ }
84
+ if (settings.support_email !== undefined) {
85
+ update.support_email = normalizeOptionalString(settings.support_email);
86
+ }
87
+ if (settings.support_phone !== undefined) {
88
+ update.support_phone = normalizeOptionalString(settings.support_phone);
89
+ }
90
+ if (settings.support_address !== undefined) {
91
+ update.support_address = normalizeOptionalString(settings.support_address);
92
+ }
93
+ if (settings.notes !== undefined) {
94
+ update.notes = normalizeOptionalString(settings.notes);
95
+ }
96
+ if (settings.enable_ai !== undefined) {
97
+ update.enable_ai = !!settings.enable_ai;
98
+ }
99
+ if (settings.enable_auto_fix !== undefined) {
100
+ update.enable_auto_fix = !!settings.enable_auto_fix;
101
+ }
102
+ if (settings.enable_slow_query_optimizer !== undefined) {
103
+ update.enable_slow_query_optimizer = !!settings.enable_slow_query_optimizer;
104
+ }
105
+ if (settings.custom_settings !== undefined) {
106
+ update.custom_settings = normalizeCustomSettings(settings.custom_settings);
107
+ }
108
+ if (settings.is_active !== undefined) {
109
+ update.is_active = settings.is_active;
110
+ }
111
+ idSetting = normalizeOptionalString(settings.id_app_setting);
112
+ if (!idSetting) return [3 /*break*/, 2];
113
+ return [4 /*yield*/, app_setting_collection_1.AppSettings.updateOne({ _id: idSetting }, { $set: update })];
114
+ case 1:
115
+ _a.sent();
116
+ return [2 /*return*/, { id_app_setting: idSetting }];
117
+ case 2: return [4 /*yield*/, app_setting_collection_1.AppSettings.findOne({}, { sort: { createdAt: -1 } })];
118
+ case 3:
119
+ existing = _a.sent();
120
+ if (!(existing && existing._id)) return [3 /*break*/, 5];
121
+ return [4 /*yield*/, app_setting_collection_1.AppSettings.updateOne({ _id: existing._id }, { $set: update })];
122
+ case 4:
123
+ _a.sent();
124
+ return [2 /*return*/, { id_app_setting: existing._id }];
125
+ case 5:
126
+ now = new Date();
127
+ newIdSetting = (0, common_1.objectIdHexString)();
128
+ insertDoc = {
129
+ _id: newIdSetting,
130
+ __v: 0,
131
+ company_name: update.company_name || 'New Company',
132
+ timezone: update.timezone,
133
+ currency: update.currency,
134
+ invoice_prefix: update.invoice_prefix,
135
+ support_email: update.support_email,
136
+ support_phone: update.support_phone,
137
+ support_address: update.support_address,
138
+ notes: update.notes,
139
+ enable_ai: update.enable_ai !== undefined ? update.enable_ai : false,
140
+ enable_auto_fix: update.enable_auto_fix !== undefined ? update.enable_auto_fix : true,
141
+ enable_slow_query_optimizer: update.enable_slow_query_optimizer !== undefined ? update.enable_slow_query_optimizer : true,
142
+ custom_settings: update.custom_settings,
143
+ is_active: update.is_active !== undefined ? update.is_active : true,
144
+ createdAt: now,
145
+ updatedAt: now
146
+ };
147
+ return [4 /*yield*/, app_setting_collection_1.AppSettings.insertOne(insertDoc)];
148
+ case 6:
149
+ _a.sent();
150
+ return [2 /*return*/, { id_app_setting: newIdSetting }];
151
+ }
152
+ });
153
+ });
154
+ }
155
+ }
156
+ });
157
+ }
158
+ function normalizeOptionalString(value) {
159
+ var raw = typeof value === 'string' ? value.trim() : '';
160
+ return raw || undefined;
161
+ }
162
+ function normalizeCustomSettings(value) {
163
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
164
+ return {};
165
+ }
166
+ return __assign({}, value);
167
+ }
168
+
169
+ //# sourceMappingURL=app-settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/methods/app-settings.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,wDA6FC;AAnGD,6CAAwC;AACxC,gFAAoE;AAGpE,yCAAmD;AAEnD,SAAgB,sBAAsB,CAAC,aAA4B;IAClE,aAAa,CAAC,OAAO,CAAC;QACrB,iBAAiB,EAAE;YAClB,KAAK,EAAE,IAAI,s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,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;oCACnE,SAAS,EAAE,GAAG;oCACd,SAAS,EAAE,GAAG;iCACd,CAAC;gCAEF,qBAAM,oCAAW,CAAC,SAAS,CAAC,SAA4B,CAAC,EAAA;;gCAAzD,SAAyD,CAAC;gCAC1D,sBAAO,EAAE,cAAc,EAAE,YAAY,EAAE,EAAC;;;;aACxC;SACD;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAU;IAC1C,IAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1D,OAAO,GAAG,IAAI,SAAS,CAAC;AACzB,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAU;IAC1C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjE,OAAO,EAAE,CAAC;IACX,CAAC;IACD,oBACI,KAAK,EACP;AACH,CAAC","file":"app-settings.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { AppSettings } from '../collections/app-setting.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { AppSettingModel } from '../models/app-setting.model';\nimport { objectIdHexString } from '../util/common';\n\nexport function loadAppSettingsMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tappSettingsUpsert: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tsettings: {\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(settings: any) {\n\t\t\t\tconst update: Partial<AppSettingModel> & { updatedAt: Date } = {\n\t\t\t\t\tupdatedAt: new Date()\n\t\t\t\t};\n\n\t\t\t\tif (settings.company_name !== undefined) {\n\t\t\t\t\tupdate.company_name = normalizeOptionalString(settings.company_name);\n\t\t\t\t}\n\t\t\t\tif (settings.timezone !== undefined) {\n\t\t\t\t\tupdate.timezone = normalizeOptionalString(settings.timezone);\n\t\t\t\t}\n\t\t\t\tif (settings.currency !== undefined) {\n\t\t\t\t\tupdate.currency = normalizeOptionalString(settings.currency);\n\t\t\t\t}\n\t\t\t\tif (settings.invoice_prefix !== undefined) {\n\t\t\t\t\tupdate.invoice_prefix = normalizeOptionalString(settings.invoice_prefix);\n\t\t\t\t}\n\t\t\t\tif (settings.support_email !== undefined) {\n\t\t\t\t\tupdate.support_email = normalizeOptionalString(settings.support_email);\n\t\t\t\t}\n\t\t\t\tif (settings.support_phone !== undefined) {\n\t\t\t\t\tupdate.support_phone = normalizeOptionalString(settings.support_phone);\n\t\t\t\t}\n\t\t\t\tif (settings.support_address !== undefined) {\n\t\t\t\t\tupdate.support_address = normalizeOptionalString(settings.support_address);\n\t\t\t\t}\n\t\t\t\tif (settings.notes !== undefined) {\n\t\t\t\t\tupdate.notes = normalizeOptionalString(settings.notes);\n\t\t\t\t}\n\t\t\t\tif (settings.enable_ai !== undefined) {\n\t\t\t\t\tupdate.enable_ai = !!settings.enable_ai;\n\t\t\t\t}\n\t\t\t\tif (settings.enable_auto_fix !== undefined) {\n\t\t\t\t\tupdate.enable_auto_fix = !!settings.enable_auto_fix;\n\t\t\t\t}\n\t\t\t\tif (settings.enable_slow_query_optimizer !== undefined) {\n\t\t\t\t\tupdate.enable_slow_query_optimizer = !!settings.enable_slow_query_optimizer;\n\t\t\t\t}\n\t\t\t\tif (settings.custom_settings !== undefined) {\n\t\t\t\t\tupdate.custom_settings = normalizeCustomSettings(settings.custom_settings);\n\t\t\t\t}\n\t\t\t\tif (settings.is_active !== undefined) {\n\t\t\t\t\tupdate.is_active = settings.is_active;\n\t\t\t\t}\n\n\t\t\t\tconst idSetting = normalizeOptionalString(settings.id_app_setting);\n\t\t\t\tif (idSetting) {\n\t\t\t\t\tawait AppSettings.updateOne({ _id: idSetting }, { $set: update });\n\t\t\t\t\treturn { id_app_setting: idSetting };\n\t\t\t\t}\n\n\t\t\t\tconst existing = await AppSettings.findOne({}, { sort: { createdAt: -1 } });\n\t\t\t\tif (existing && existing._id) {\n\t\t\t\t\tawait AppSettings.updateOne({ _id: existing._id }, { $set: update });\n\t\t\t\t\treturn { id_app_setting: existing._id };\n\t\t\t\t}\n\n\t\t\t\tconst now = new Date();\n\t\t\t\tconst newIdSetting = objectIdHexString();\n\t\t\t\tconst insertDoc: Partial<AppSettingModel> = {\n\t\t\t\t\t_id: newIdSetting,\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tcompany_name: update.company_name || 'New Company',\n\t\t\t\t\ttimezone: update.timezone,\n\t\t\t\t\tcurrency: update.currency,\n\t\t\t\t\tinvoice_prefix: update.invoice_prefix,\n\t\t\t\t\tsupport_email: update.support_email,\n\t\t\t\t\tsupport_phone: update.support_phone,\n\t\t\t\t\tsupport_address: update.support_address,\n\t\t\t\t\tnotes: update.notes,\n\t\t\t\t\tenable_ai: update.enable_ai !== undefined ? update.enable_ai : false,\n\t\t\t\t\tenable_auto_fix: update.enable_auto_fix !== undefined ? update.enable_auto_fix : true,\n\t\t\t\t\tenable_slow_query_optimizer: update.enable_slow_query_optimizer !== undefined ? update.enable_slow_query_optimizer : true,\n\t\t\t\t\tcustom_settings: update.custom_settings,\n\t\t\t\t\tis_active: update.is_active !== undefined ? update.is_active : true,\n\t\t\t\t\tcreatedAt: now,\n\t\t\t\t\tupdatedAt: now\n\t\t\t\t};\n\n\t\t\t\tawait AppSettings.insertOne(insertDoc as AppSettingModel);\n\t\t\t\treturn { id_app_setting: newIdSetting };\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction normalizeOptionalString(value: any): string | undefined {\n\tconst raw = typeof value === 'string' ? value.trim() : '';\n\treturn raw || undefined;\n}\n\nfunction normalizeCustomSettings(value: any): Record<string, any> {\n\tif (!value || typeof value !== 'object' || Array.isArray(value)) {\n\t\treturn {};\n\t}\n\treturn {\n\t\t...value\n\t};\n}\n"]}
@@ -153,9 +153,68 @@ function uniqueUserIds(input) {
153
153
  }
154
154
  return Array.from(unique);
155
155
  }
156
+ function buildClientMembershipCriteria(idClient) {
157
+ return {
158
+ $or: [
159
+ { 'other.id_client': idClient },
160
+ { 'other.idClient': idClient },
161
+ { id_client: idClient }
162
+ ]
163
+ };
164
+ }
165
+ function buildInternalUserCriteria() {
166
+ return {
167
+ $and: [
168
+ {
169
+ is_customer: {
170
+ $ne: true
171
+ }
172
+ },
173
+ {
174
+ $nor: [
175
+ {
176
+ 'other.id_customer': {
177
+ $exists: true,
178
+ $nin: ['', null]
179
+ }
180
+ },
181
+ {
182
+ id_customer: {
183
+ $exists: true,
184
+ $nin: ['', null]
185
+ }
186
+ }
187
+ ]
188
+ }
189
+ ]
190
+ };
191
+ }
192
+ function buildAdminUserCriteria() {
193
+ return {
194
+ $or: [
195
+ {
196
+ 'roles.super_admin': true
197
+ },
198
+ {
199
+ 'roles.groups.name': {
200
+ $regex: 'admin',
201
+ $options: 'i'
202
+ }
203
+ },
204
+ {
205
+ 'roles.groups.views': {
206
+ $regex: '^/manage'
207
+ }
208
+ },
209
+ {
210
+ 'roles.groups.views': '/manage'
211
+ }
212
+ ]
213
+ };
214
+ }
156
215
  function resolveTargetUsers(payload) {
157
216
  return __awaiter(this, void 0, void 0, function () {
158
- var targetType, users_1, idClient, users;
217
+ var targetType, users_1, idClient, andClauses, users;
159
218
  return __generator(this, function (_a) {
160
219
  switch (_a.label) {
161
220
  case 0:
@@ -183,16 +242,25 @@ function resolveTargetUsers(payload) {
183
242
  if (!idClient) {
184
243
  return [2 /*return*/, []];
185
244
  }
186
- return [4 /*yield*/, user_collection_1.Users.find({
187
- active: true,
245
+ andClauses = [
246
+ {
247
+ active: true
248
+ },
249
+ {
188
250
  username: {
189
251
  $exists: true
190
- },
191
- $or: [
192
- { 'other.id_client': idClient },
193
- { 'other.idClient': idClient },
194
- { id_client: idClient }
195
- ]
252
+ }
253
+ },
254
+ buildClientMembershipCriteria(idClient)
255
+ ];
256
+ if (targetType === 'client_internal' || targetType === 'client_admins') {
257
+ andClauses.push(buildInternalUserCriteria());
258
+ }
259
+ if (targetType === 'client_admins') {
260
+ andClauses.push(buildAdminUserCriteria());
261
+ }
262
+ return [4 /*yield*/, user_collection_1.Users.find({
263
+ $and: andClauses
196
264
  }, {
197
265
  projection: {
198
266
  _id: 1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/methods/customer-notifications.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6KA,0EAyNC;AAtYD,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,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AgD;gCAC7D,UAAU,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gCACjD,IAAI,CAAC,UAAU,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;oCAC9C,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;gCAClE,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"]}
1
+ {"version":3,"sources":["../../src/methods/customer-notifications.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuPA,0EAyNC;AAhdD,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,CAA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K,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' | 'client_admins' | 'client_internal';\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\nfunction buildClientMembershipCriteria(idClient: string): Record<string, any> {\n\treturn {\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}\n\nfunction buildInternalUserCriteria(): Record<string, any> {\n\treturn {\n\t\t$and: [\n\t\t\t{\n\t\t\t\tis_customer: {\n\t\t\t\t\t$ne: true\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\t$nor: [\n\t\t\t\t\t{\n\t\t\t\t\t\t'other.id_customer': {\n\t\t\t\t\t\t\t$exists: true,\n\t\t\t\t\t\t\t$nin: ['', null]\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\tid_customer: {\n\t\t\t\t\t\t\t$exists: true,\n\t\t\t\t\t\t\t$nin: ['', null]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n}\n\nfunction buildAdminUserCriteria(): Record<string, any> {\n\treturn {\n\t\t$or: [\n\t\t\t{\n\t\t\t\t'roles.super_admin': true\n\t\t\t},\n\t\t\t{\n\t\t\t\t'roles.groups.name': {\n\t\t\t\t\t$regex: 'admin',\n\t\t\t\t\t$options: 'i'\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\t'roles.groups.views': {\n\t\t\t\t\t$regex: '^/manage'\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\t'roles.groups.views': '/manage'\n\t\t\t}\n\t\t]\n\t};\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 andClauses: Record<string, any>[] = [\n\t\t{\n\t\t\tactive: true\n\t\t},\n\t\t{\n\t\t\tusername: {\n\t\t\t\t$exists: true\n\t\t\t}\n\t\t},\n\t\tbuildClientMembershipCriteria(idClient)\n\t];\n\n\tif (targetType === 'client_internal' || targetType === 'client_admins') {\n\t\tandClauses.push(buildInternalUserCriteria());\n\t}\n\n\tif (targetType === 'client_admins') {\n\t\tandClauses.push(buildAdminUserCriteria());\n\t}\n\n\tconst users = await Users.find({\n\t\t$and: andClauses\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"]}
package/methods.ts CHANGED
@@ -48,6 +48,9 @@ export function SERVER_METHODS(resolveioServer) {
48
48
  aiTerminalUploadFile: (id_conversation: string, file_name: string, content_base64: string, size: number, content_type?: string, cb?: Function): Promise<any> => {
49
49
  return resolveioServer.call('aiTerminalUploadFile', id_conversation, file_name, content_base64, size, content_type, cb);
50
50
  },
51
+ appSettingsUpsert: (settings: any, cb?: Function): Promise<any> => {
52
+ return resolveioServer.call('appSettingsUpsert', settings, cb);
53
+ },
51
54
  collectionListAll: (cb?: Function): Promise<any> => {
52
55
  return resolveioServer.call('collectionListAll', cb);
53
56
  },
@@ -0,0 +1,16 @@
1
+ import { CollectionDocument } from './collection-document.model';
2
+ export interface AppSettingModel extends CollectionDocument {
3
+ company_name?: string;
4
+ timezone?: string;
5
+ currency?: string;
6
+ invoice_prefix?: string;
7
+ support_email?: string;
8
+ support_phone?: string;
9
+ support_address?: string;
10
+ notes?: string;
11
+ enable_ai?: boolean;
12
+ enable_auto_fix?: boolean;
13
+ enable_slow_query_optimizer?: boolean;
14
+ custom_settings?: Record<string, any>;
15
+ is_active?: boolean;
16
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=app-setting.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/models/app-setting.model.ts"],"names":[],"mappings":"","file":"app-setting.model.js","sourcesContent":["import { CollectionDocument } from './collection-document.model';\n\nexport interface AppSettingModel extends CollectionDocument {\n\tcompany_name?: string;\n\ttimezone?: string;\n\tcurrency?: string;\n\tinvoice_prefix?: string;\n\tsupport_email?: string;\n\tsupport_phone?: string;\n\tsupport_address?: string;\n\tnotes?: string;\n\tenable_ai?: boolean;\n\tenable_auto_fix?: boolean;\n\tenable_slow_query_optimizer?: boolean;\n\tcustom_settings?: Record<string, any>;\n\tis_active?: boolean;\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "22.2.4",
3
+ "version": "22.2.7",
4
4
  "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/public_api.d.ts",
5
7
  "scripts": {
6
8
  "package": "./build_package.sh",
7
9
  "library": "node_modules/gulp/bin/gulp.js watch:dist",
package/public_api.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './collections/app-status.collection';
2
+ export * from './collections/app-setting.collection';
2
3
  export * from './collections/ai-terminal-issue-report.collection';
3
4
  export * from './collections/ai-terminal-conversation.collection';
4
5
  export * from './collections/ai-terminal-message.collection';
@@ -28,7 +29,13 @@ export * from './collections/user-group.collection';
28
29
  export * from './collections/user-guide.collection';
29
30
  export * from './collections/user.collection';
30
31
  export * from './managers/mongo.manager';
32
+ export * from './managers/error-auto-fix.manager';
33
+ export * from './managers/slow-query-verifier.manager';
34
+ export * from './managers/slow-query.manager';
35
+ export * from './managers/customer-notification-content.manager';
36
+ export * from './managers/diagnostic-manager-bootstrap';
31
37
  export * from './models/app-status.model';
38
+ export * from './models/app-setting.model';
32
39
  export * from './models/ai-terminal-issue-report.model';
33
40
  export * from './models/ai-terminal-conversation.model';
34
41
  export * from './models/ai-terminal-message.model';
@@ -68,6 +75,8 @@ export * from './models/support-ticket.model';
68
75
  export * from './models/user-group.model';
69
76
  export * from './models/user-guide.model';
70
77
  export * from './models/user.model';
78
+ export * from './types/error-report';
79
+ export * from './types/slow-query-report';
71
80
  export * from './managers/openai-usage-ledger.manager';
72
81
  export * from './managers/communication-metric.manager';
73
82
  export * from './resolveio-server-app';
package/public_api.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./collections/app-status.collection"), exports);
18
+ __exportStar(require("./collections/app-setting.collection"), exports);
18
19
  __exportStar(require("./collections/ai-terminal-issue-report.collection"), exports);
19
20
  __exportStar(require("./collections/ai-terminal-conversation.collection"), exports);
20
21
  __exportStar(require("./collections/ai-terminal-message.collection"), exports);
@@ -44,7 +45,13 @@ __exportStar(require("./collections/user-group.collection"), exports);
44
45
  __exportStar(require("./collections/user-guide.collection"), exports);
45
46
  __exportStar(require("./collections/user.collection"), exports);
46
47
  __exportStar(require("./managers/mongo.manager"), exports);
48
+ __exportStar(require("./managers/error-auto-fix.manager"), exports);
49
+ __exportStar(require("./managers/slow-query-verifier.manager"), exports);
50
+ __exportStar(require("./managers/slow-query.manager"), exports);
51
+ __exportStar(require("./managers/customer-notification-content.manager"), exports);
52
+ __exportStar(require("./managers/diagnostic-manager-bootstrap"), exports);
47
53
  __exportStar(require("./models/app-status.model"), exports);
54
+ __exportStar(require("./models/app-setting.model"), exports);
48
55
  __exportStar(require("./models/ai-terminal-issue-report.model"), exports);
49
56
  __exportStar(require("./models/ai-terminal-conversation.model"), exports);
50
57
  __exportStar(require("./models/ai-terminal-message.model"), exports);
@@ -84,6 +91,8 @@ __exportStar(require("./models/support-ticket.model"), exports);
84
91
  __exportStar(require("./models/user-group.model"), exports);
85
92
  __exportStar(require("./models/user-guide.model"), exports);
86
93
  __exportStar(require("./models/user.model"), exports);
94
+ __exportStar(require("./types/error-report"), exports);
95
+ __exportStar(require("./types/slow-query-report"), exports);
87
96
  __exportStar(require("./managers/openai-usage-ledger.manager"), exports);
88
97
  __exportStar(require("./managers/communication-metric.manager"), exports);
89
98
  __exportStar(require("./resolveio-server-app"), exports);
package/public_api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/public_api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,oFAAkE;AAClE,oFAAkE;AAClE,+EAA6D;AAC7D,mEAAiD;AACjD,iFAA+D;AAC/D,gFAA8D;AAC9D,4EAA0D;AAC1D,oEAAkD;AAClD,yEAAuD;AACvD,0EAAwD;AACxD,gEAA8C;AAC9C,uEAAqD;AACrD,gEAA8C;AAC9C,8EAA4D;AAC5D,4EAA0D;AAC1D,+DAA6C;AAC7C,2EAAyD;AACzD,uEAAqD;AACrD,4EAA0D;AAC1D,0EAAwD;AACxD,yEAAuD;AACvD,wEAAsD;AACtD,+EAA6D;AAC7D,kFAAgE;AAChE,iFAA+D;AAC/D,sEAAoD;AACpD,sEAAoD;AACpD,gEAA8C;AAC9C,2DAAyC;AACzC,4DAA0C;AAC1C,0EAAwD;AACxD,0EAAwD;AACxD,qEAAmD;AACnD,yEAAuD;AACvD,qEAAmD;AACnD,sEAAoD;AACpD,yDAAuC;AACvC,uEAAqD;AACrD,kEAAgD;AAChD,0DAAwC;AACxC,wDAAsC;AACtC,+DAA6C;AAC7C,gEAA8C;AAC9C,sDAAoC;AACpC,6DAA2C;AAC3C,sDAAoC;AACpC,oEAAkD;AAClD,kEAAgD;AAChD,qDAAmC;AACnC,iEAA+C;AAC/C,iEAA+C;AAC/C,wDAAsC;AACtC,6DAA2C;AAC3C,gEAA8C;AAC9C,+DAA6C;AAC7C,8DAA4C;AAC5C,qEAAmD;AACnD,4DAA0C;AAC1C,4DAA0C;AAC1C,wEAAsD;AACtD,uEAAqD;AACrD,gEAA8C;AAC9C,mEAAiD;AACjD,gEAA8C;AAC9C,8DAA4C;AAC5C,gEAA8C;AAC9C,4DAA0C;AAC1C,4DAA0C;AAC1C,sDAAoC;AACpC,yEAAuD;AACvD,0EAAwD;AACxD,yDAAuC;AACvC,2DAAyC;AACzC,0DAAwC;AACxC,gDAA8B;AAC9B,mDAAiC","file":"public_api.js","sourcesContent":["export * from './collections/app-status.collection';\nexport * from './collections/ai-terminal-issue-report.collection';\nexport * from './collections/ai-terminal-conversation.collection';\nexport * from './collections/ai-terminal-message.collection';\nexport * from './collections/counter.collection';\nexport * from './collections/customer-notification.collection';\nexport * from './collections/communication-metric.collection';\nexport * from './collections/cron-job-history.collection';\nexport * from './collections/cron-job.collection';\nexport * from './collections/email-history.collection';\nexport * from './collections/email-verified.collection';\nexport * from './collections/file.collection';\nexport * from './collections/flag-update.collection';\nexport * from './collections/flag.collection';\nexport * from './collections/log-method-latency.collection';\nexport * from './collections/log-subscription.collection';\nexport * from './collections/log.collection';\nexport * from './collections/logged-in-users.collection';\nexport * from './collections/monitor-cpu.collection';\nexport * from './collections/monitor-function.collection';\nexport * from './collections/monitor-memory.collection';\nexport * from './collections/monitor-mongo.collection';\nexport * from './collections/notification.collection';\nexport * from './collections/openai-usage-ledger.collection';\nexport * from './collections/report-builder-library.collection';\nexport * from './collections/report-builder-report.collection';\nexport * from './collections/user-group.collection';\nexport * from './collections/user-guide.collection';\nexport * from './collections/user.collection';\nexport * from './managers/mongo.manager';\nexport * from './models/app-status.model';\nexport * from './models/ai-terminal-issue-report.model';\nexport * from './models/ai-terminal-conversation.model';\nexport * from './models/ai-terminal-message.model';\nexport * from './models/billing-logged-in-users.model';\nexport * from './models/collection-document.model';\nexport * from './models/communication-metric.model';\nexport * from './models/counter.model';\nexport * from './models/customer-notification.model';\nexport * from './models/cron-job-history.model';\nexport * from './models/cron-job.model';\nexport * from './models/dialog.model';\nexport * from './models/email-history.model';\nexport * from './models/email-verified.model';\nexport * from './models/file.model';\nexport * from './models/flag-update.model';\nexport * from './models/flag.model';\nexport * from './models/log-method-latency.model';\nexport * from './models/log-subscription.model';\nexport * from './models/log.model';\nexport * from './models/logged-in-users.model';\nexport * from './models/method-response.model';\nexport * from './models/method.model';\nexport * from './models/monitor-cpu.model';\nexport * from './models/monitor-memory.model';\nexport * from './models/monitor-mongo.model';\nexport * from './models/notification.model';\nexport * from './models/openai-usage-ledger.model';\nexport * from './models/pagination.model';\nexport * from './models/permission.model';\nexport * from './models/report-builder-library.model';\nexport * from './models/report-builder-report.model';\nexport * from './models/report-builder.model';\nexport * from './models/select-data-label.model';\nexport * from './models/server-message.model';\nexport * from './models/subscription.model';\nexport * from './models/support-ticket.model';\nexport * from './models/user-group.model';\nexport * from './models/user-guide.model';\nexport * from './models/user.model';\nexport * from './managers/openai-usage-ledger.manager';\nexport * from './managers/communication-metric.manager';\nexport * from './resolveio-server-app';\nexport * from './services/openai-client';\nexport * from './services/codex-client';\nexport * from './util/common';\nexport * from './util/tokenizer';\n"]}
1
+ {"version":3,"sources":["../../src/public_api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,uEAAqD;AACrD,oFAAkE;AAClE,oFAAk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public_api.js","sourcesContent":["export * from './collections/app-status.collection';\nexport * from './collections/app-setting.collection';\nexport * from './collections/ai-terminal-issue-report.collection';\nexport * from './collections/ai-terminal-conversation.collection';\nexport * from './collections/ai-terminal-message.collection';\nexport * from './collections/counter.collection';\nexport * from './collections/customer-notification.collection';\nexport * from './collections/communication-metric.collection';\nexport * from './collections/cron-job-history.collection';\nexport * from './collections/cron-job.collection';\nexport * from './collections/email-history.collection';\nexport * from './collections/email-verified.collection';\nexport * from './collections/file.collection';\nexport * from './collections/flag-update.collection';\nexport * from './collections/flag.collection';\nexport * from './collections/log-method-latency.collection';\nexport * from './collections/log-subscription.collection';\nexport * from './collections/log.collection';\nexport * from './collections/logged-in-users.collection';\nexport * from './collections/monitor-cpu.collection';\nexport * from './collections/monitor-function.collection';\nexport * from './collections/monitor-memory.collection';\nexport * from './collections/monitor-mongo.collection';\nexport * from './collections/notification.collection';\nexport * from './collections/openai-usage-ledger.collection';\nexport * from './collections/report-builder-library.collection';\nexport * from './collections/report-builder-report.collection';\nexport * from './collections/user-group.collection';\nexport * from './collections/user-guide.collection';\nexport * from './collections/user.collection';\nexport * from './managers/mongo.manager';\nexport * from './managers/error-auto-fix.manager';\nexport * from './managers/slow-query-verifier.manager';\nexport * from './managers/slow-query.manager';\nexport * from './managers/customer-notification-content.manager';\nexport * from './managers/diagnostic-manager-bootstrap';\nexport * from './models/app-status.model';\nexport * from './models/app-setting.model';\nexport * from './models/ai-terminal-issue-report.model';\nexport * from './models/ai-terminal-conversation.model';\nexport * from './models/ai-terminal-message.model';\nexport * from './models/billing-logged-in-users.model';\nexport * from './models/collection-document.model';\nexport * from './models/communication-metric.model';\nexport * from './models/counter.model';\nexport * from './models/customer-notification.model';\nexport * from './models/cron-job-history.model';\nexport * from './models/cron-job.model';\nexport * from './models/dialog.model';\nexport * from './models/email-history.model';\nexport * from './models/email-verified.model';\nexport * from './models/file.model';\nexport * from './models/flag-update.model';\nexport * from './models/flag.model';\nexport * from './models/log-method-latency.model';\nexport * from './models/log-subscription.model';\nexport * from './models/log.model';\nexport * from './models/logged-in-users.model';\nexport * from './models/method-response.model';\nexport * from './models/method.model';\nexport * from './models/monitor-cpu.model';\nexport * from './models/monitor-memory.model';\nexport * from './models/monitor-mongo.model';\nexport * from './models/notification.model';\nexport * from './models/openai-usage-ledger.model';\nexport * from './models/pagination.model';\nexport * from './models/permission.model';\nexport * from './models/report-builder-library.model';\nexport * from './models/report-builder-report.model';\nexport * from './models/report-builder.model';\nexport * from './models/select-data-label.model';\nexport * from './models/server-message.model';\nexport * from './models/subscription.model';\nexport * from './models/support-ticket.model';\nexport * from './models/user-group.model';\nexport * from './models/user-guide.model';\nexport * from './models/user.model';\nexport * from './types/error-report';\nexport * from './types/slow-query-report';\nexport * from './managers/openai-usage-ledger.manager';\nexport * from './managers/communication-metric.manager';\nexport * from './resolveio-server-app';\nexport * from './services/openai-client';\nexport * from './services/codex-client';\nexport * from './util/common';\nexport * from './util/tokenizer';\n"]}
@@ -0,0 +1,2 @@
1
+ import { SubscriptionManager } from '../managers/subscription.manager';
2
+ export declare function loadAppSettingsPublications(subscriptionManager: SubscriptionManager): void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadAppSettingsPublications = loadAppSettingsPublications;
4
+ var simpl_schema_1 = require("simpl-schema");
5
+ var app_setting_collection_1 = require("../collections/app-setting.collection");
6
+ function loadAppSettingsPublications(subscriptionManager) {
7
+ subscriptionManager.publications({
8
+ appSettings: {
9
+ function: function () {
10
+ return app_setting_collection_1.AppSettings.find({}, { sort: { company_name: 1 } });
11
+ },
12
+ collections: ['app-settings']
13
+ },
14
+ appSettingById: {
15
+ check: new simpl_schema_1.default({
16
+ id_app_setting: {
17
+ type: String
18
+ }
19
+ }),
20
+ function: function (id_app_setting) {
21
+ return app_setting_collection_1.AppSettings.findById(id_app_setting);
22
+ },
23
+ collections: ['app-settings']
24
+ }
25
+ });
26
+ }
27
+
28
+ //# sourceMappingURL=app-settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/publications/app-settings.ts"],"names":[],"mappings":";;AAIA,kEAoBC;AAxBD,6CAAwC;AACxC,gFAAoE;AAGpE,SAAgB,2BAA2B,CAAC,mBAAwC;IACnF,mBAAmB,CAAC,YAAY,CAAC;QAChC,WAAW,EAAE;YACZ,QAAQ,EAAE;gBACT,OAAO,oCAAW,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5D,CAAC;YACD,WAAW,EAAE,CAAC,cAAc,CAAC;SAC7B;QACD,cAAc,EAAE;YACf,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,cAAc,EAAE;oBACf,IAAI,EAAE,MAAM;iBACZ;aACD,CAAC;YACF,QAAQ,EAAE,UAAS,cAAsB;gBACxC,OAAO,oCAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;YAC7C,CAAC;YACD,WAAW,EAAE,CAAC,cAAc,CAAC;SAC7B;KACD,CAAC,CAAC;AACJ,CAAC","file":"app-settings.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { AppSettings } from '../collections/app-setting.collection';\nimport { SubscriptionManager } from '../managers/subscription.manager';\n\nexport function loadAppSettingsPublications(subscriptionManager: SubscriptionManager) {\n\tsubscriptionManager.publications({\n\t\tappSettings: {\n\t\t\tfunction: function() {\n\t\t\t\treturn AppSettings.find({}, { sort: { company_name: 1 } });\n\t\t\t},\n\t\t\tcollections: ['app-settings']\n\t\t},\n\t\tappSettingById: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_app_setting: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(id_app_setting: string) {\n\t\t\t\treturn AppSettings.findById(id_app_setting);\n\t\t\t},\n\t\t\tcollections: ['app-settings']\n\t\t}\n\t});\n}\n"]}
package/publications.ts CHANGED
@@ -8,6 +8,12 @@ export function SERVER_PUBLICATIONS(resolveioServer) {
8
8
  aiTerminalMessages: (id_conversation: string, limit?: number) => {
9
9
  return <Observable<any>> resolveioServer.subscribe('aiTerminalMessages', id_conversation, limit);
10
10
  },
11
+ appSettingById: (id_app_setting: string) => {
12
+ return <Observable<any>> resolveioServer.subscribe('appSettingById', id_app_setting);
13
+ },
14
+ appSettings: () => {
15
+ return <Observable<any>> resolveioServer.subscribe('appSettings');
16
+ },
11
17
  appstatus: () => {
12
18
  return <Observable<any>> resolveioServer.subscribe('appstatus');
13
19
  },