@resolveio/server-lib 20.12.20 → 20.12.21
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/methods/accounts.js +201 -0
- package/methods/accounts.js.map +1 -1
- package/methods.ts +3 -0
- package/package.json +1 -1
package/methods/accounts.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
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
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -44,6 +55,7 @@ var user_collection_1 = require("../collections/user.collection");
|
|
|
44
55
|
var resolveio_server_app_1 = require("../resolveio-server-app");
|
|
45
56
|
var common_1 = require("../util/common");
|
|
46
57
|
var error_reporter_1 = require("../util/error-reporter");
|
|
58
|
+
var common_2 = require("../util/common");
|
|
47
59
|
function loadAccountMethods(methodManager) {
|
|
48
60
|
methodManager.methods({
|
|
49
61
|
incorrectUser: {
|
|
@@ -318,8 +330,197 @@ function loadAccountMethods(methodManager) {
|
|
|
318
330
|
});
|
|
319
331
|
});
|
|
320
332
|
}
|
|
333
|
+
},
|
|
334
|
+
saveUserStickySelects: {
|
|
335
|
+
check: new simpl_schema_1.default({
|
|
336
|
+
stickySelects: {
|
|
337
|
+
type: Array
|
|
338
|
+
},
|
|
339
|
+
'stickySelects.$': {
|
|
340
|
+
type: Object,
|
|
341
|
+
blackbox: true
|
|
342
|
+
},
|
|
343
|
+
id_user: {
|
|
344
|
+
type: String,
|
|
345
|
+
optional: true
|
|
346
|
+
}
|
|
347
|
+
}),
|
|
348
|
+
function: function (stickySelects, id_user) {
|
|
349
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
350
|
+
var targetUserId, user, mergedStickySelects, nextUser;
|
|
351
|
+
var _a;
|
|
352
|
+
return __generator(this, function (_b) {
|
|
353
|
+
switch (_b.label) {
|
|
354
|
+
case 0:
|
|
355
|
+
targetUserId = id_user || this.id_user;
|
|
356
|
+
if (!targetUserId) {
|
|
357
|
+
throw new Error('Error in Save User Sticky Selects: Invalid User');
|
|
358
|
+
}
|
|
359
|
+
return [4 /*yield*/, user_collection_1.Users.findOne({ _id: targetUserId })];
|
|
360
|
+
case 1:
|
|
361
|
+
user = _b.sent();
|
|
362
|
+
if (!user) {
|
|
363
|
+
throw new Error('Error in Save User Sticky Selects: Invalid User');
|
|
364
|
+
}
|
|
365
|
+
mergedStickySelects = mergeStickySelects((_a = user.other) === null || _a === void 0 ? void 0 : _a.stickySelects, stickySelects);
|
|
366
|
+
nextUser = (0, common_2.deepCopy)(user);
|
|
367
|
+
nextUser.other = __assign(__assign({}, (nextUser.other || {})), { stickySelects: mergedStickySelects });
|
|
368
|
+
return [4 /*yield*/, user_collection_1.Users.replaceOne({ _id: nextUser._id }, nextUser, {}, false, false, user)];
|
|
369
|
+
case 2:
|
|
370
|
+
_b.sent();
|
|
371
|
+
return [2 /*return*/, {
|
|
372
|
+
stickySelects: mergedStickySelects,
|
|
373
|
+
__v: nextUser.__v
|
|
374
|
+
}];
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
}
|
|
321
379
|
}
|
|
322
380
|
});
|
|
323
381
|
}
|
|
382
|
+
function mergeStickySelects(existingList, incomingList) {
|
|
383
|
+
var _a;
|
|
384
|
+
var existingMap = new Map();
|
|
385
|
+
if (Array.isArray(existingList)) {
|
|
386
|
+
existingList.forEach(function (entry) {
|
|
387
|
+
var normalized = normalizeStickyPreference(entry);
|
|
388
|
+
if (normalized && normalized.key) {
|
|
389
|
+
existingMap.set(normalized.key, normalized);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
var _loop_1 = function (i) {
|
|
394
|
+
var normalized = normalizeStickyPreference(incomingList[i]);
|
|
395
|
+
if (!normalized || !normalized.key) {
|
|
396
|
+
return "continue";
|
|
397
|
+
}
|
|
398
|
+
var prev = existingMap.get(normalized.key);
|
|
399
|
+
var mergedOptions = trimOptions(normalized.options && normalized.options.length
|
|
400
|
+
? mergeOptions((prev === null || prev === void 0 ? void 0 : prev.options) || [], normalized.options)
|
|
401
|
+
: ((prev === null || prev === void 0 ? void 0 : prev.options) || []));
|
|
402
|
+
var defaultValue = normalized.defaultValue !== undefined ? normalized.defaultValue : (prev ? prev.defaultValue : null);
|
|
403
|
+
if (defaultValue === undefined) {
|
|
404
|
+
defaultValue = null;
|
|
405
|
+
}
|
|
406
|
+
var defaultLabel = cleanStickyLabel(normalized.defaultLabel);
|
|
407
|
+
if (!defaultLabel && (prev === null || prev === void 0 ? void 0 : prev.defaultLabel)) {
|
|
408
|
+
defaultLabel = cleanStickyLabel(prev.defaultLabel);
|
|
409
|
+
}
|
|
410
|
+
if (defaultValue !== null && !defaultLabel) {
|
|
411
|
+
var optionLabel = ((_a = mergedOptions.find(function (opt) { return valuesMatch(opt.value, defaultValue, !!normalized.multiple); })) === null || _a === void 0 ? void 0 : _a.label) || '';
|
|
412
|
+
defaultLabel = cleanStickyLabel(optionLabel);
|
|
413
|
+
}
|
|
414
|
+
existingMap.set(normalized.key, {
|
|
415
|
+
key: normalized.key,
|
|
416
|
+
defaultValue: defaultValue,
|
|
417
|
+
defaultLabel: defaultLabel,
|
|
418
|
+
multiple: normalized.multiple !== undefined ? normalized.multiple : !!(prev === null || prev === void 0 ? void 0 : prev.multiple),
|
|
419
|
+
options: mergedOptions,
|
|
420
|
+
updatedAt: new Date().toISOString()
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
for (var i = 0; i < incomingList.length; i++) {
|
|
424
|
+
_loop_1(i);
|
|
425
|
+
}
|
|
426
|
+
return Array.from(existingMap.values());
|
|
427
|
+
}
|
|
428
|
+
function mergeOptions(existing, incoming) {
|
|
429
|
+
var map = new Map();
|
|
430
|
+
normalizeStickyOptions(existing).forEach(function (opt) {
|
|
431
|
+
var key = buildOptionKey(opt.value);
|
|
432
|
+
map.set(key, opt);
|
|
433
|
+
});
|
|
434
|
+
normalizeStickyOptions(incoming).forEach(function (opt) {
|
|
435
|
+
var key = buildOptionKey(opt.value);
|
|
436
|
+
map.set(key, opt);
|
|
437
|
+
});
|
|
438
|
+
return Array.from(map.values());
|
|
439
|
+
}
|
|
440
|
+
function trimOptions(options) {
|
|
441
|
+
if (!Array.isArray(options)) {
|
|
442
|
+
return [];
|
|
443
|
+
}
|
|
444
|
+
if (options.length <= STICKY_MAX_OPTIONS) {
|
|
445
|
+
return options;
|
|
446
|
+
}
|
|
447
|
+
return options.slice(0, STICKY_MAX_OPTIONS);
|
|
448
|
+
}
|
|
449
|
+
function normalizeStickyPreference(entry) {
|
|
450
|
+
if (!entry || !entry.key) {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
var normalized = {
|
|
454
|
+
key: "".concat(entry.key),
|
|
455
|
+
defaultValue: entry.defaultValue !== undefined ? entry.defaultValue : null,
|
|
456
|
+
defaultLabel: cleanStickyLabel(entry.defaultLabel),
|
|
457
|
+
multiple: !!entry.multiple,
|
|
458
|
+
options: normalizeStickyOptions(entry.options),
|
|
459
|
+
updatedAt: entry.updatedAt
|
|
460
|
+
};
|
|
461
|
+
return normalized;
|
|
462
|
+
}
|
|
463
|
+
function normalizeStickyOptions(options) {
|
|
464
|
+
if (Array.isArray(options)) {
|
|
465
|
+
return options
|
|
466
|
+
.map(function (opt) { return normalizeStickyOption(opt); })
|
|
467
|
+
.filter(function (opt) { return !!opt; });
|
|
468
|
+
}
|
|
469
|
+
if (options && typeof options === 'object') {
|
|
470
|
+
return Object.keys(options)
|
|
471
|
+
.sort()
|
|
472
|
+
.map(function (key) { return normalizeStickyOption(options[key]); })
|
|
473
|
+
.filter(function (opt) { return !!opt; });
|
|
474
|
+
}
|
|
475
|
+
return [];
|
|
476
|
+
}
|
|
477
|
+
function normalizeStickyOption(option) {
|
|
478
|
+
if (!option || option.value === undefined) {
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
return {
|
|
482
|
+
value: option.value,
|
|
483
|
+
label: cleanStickyLabel(option.label)
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function cleanStickyLabel(label) {
|
|
487
|
+
if (!label) {
|
|
488
|
+
return '';
|
|
489
|
+
}
|
|
490
|
+
var trimmed = "".concat(label).trim();
|
|
491
|
+
if (!trimmed || trimmed.toLowerCase() === 'loading...') {
|
|
492
|
+
return '';
|
|
493
|
+
}
|
|
494
|
+
return trimmed;
|
|
495
|
+
}
|
|
496
|
+
function buildOptionKey(value) {
|
|
497
|
+
if (value === null) {
|
|
498
|
+
return 'null';
|
|
499
|
+
}
|
|
500
|
+
if (value === undefined) {
|
|
501
|
+
return 'undefined';
|
|
502
|
+
}
|
|
503
|
+
if (typeof value === 'object') {
|
|
504
|
+
try {
|
|
505
|
+
return JSON.stringify(value);
|
|
506
|
+
}
|
|
507
|
+
catch (_a) {
|
|
508
|
+
return "".concat(value);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return "".concat(value);
|
|
512
|
+
}
|
|
513
|
+
function valuesMatch(a, b, multiple) {
|
|
514
|
+
if (multiple) {
|
|
515
|
+
var arrA = Array.isArray(a) ? a : [];
|
|
516
|
+
var arrB_1 = Array.isArray(b) ? b : [];
|
|
517
|
+
if (arrA.length !== arrB_1.length) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
return arrA.every(function (item) { return arrB_1.some(function (candidate) { return buildOptionKey(candidate) === buildOptionKey(item); }); });
|
|
521
|
+
}
|
|
522
|
+
return buildOptionKey(a) === buildOptionKey(b);
|
|
523
|
+
}
|
|
524
|
+
var STICKY_MAX_OPTIONS = 200;
|
|
324
525
|
|
|
325
526
|
//# sourceMappingURL=accounts.js.map
|
package/methods/accounts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/methods/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,gDAsOC;AAhPD,uCAAyC;AACzC,kCAAoC;AACpC,6CAAwC;AACxC,kEAAuD;AAGvD,gEAA0D;AAC1D,yCAAmD;AACnD,yDAAuD;AAEvD,SAAgB,kBAAkB,CAAC,aAA4B;IAC9D,aAAa,CAAC,OAAO,CAAC;QACrB,aAAa,EAAE;YACd,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,QAAQ,EAAE;oBACT,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;gBACD,QAAQ,EAAE;oBACT,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;gBACD,WAAW,EAAE;oBACZ,IAAI,EAAE,KAAK;iBACX;gBACD,eAAe,EAAE;oBAChB,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;aACD,CAAC;YACF,QAAQ,EAAE,UAAe,QAAQ,EAAE,QAAQ,EAAE,WAAW;;;;;;;qCACnD,sCAAe,CAAC,aAAa,EAAE,EAA/B,wBAA+B;gCAC9B,EAAE,GAAG,sCAAe,CAAC,aAAa,EAAE,CAAC,mBAAmB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gCAClF,aAAa,GAAG,IAAA,0BAAiB,GAAE,CAAC;gCAC1C,qBAAM,8BAAa,CAAC,MAAM,CAAC;wCAC1B,SAAS,EAAE,iBAAiB;wCAC5B,OAAO,EAAE,iCAAiC,GAAG,IA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AE;oBACT,IAAI,EAAE,MAAM;iBACZ;aACD,CAAC;YACF,QAAQ,EAAE,UAAe,MAAc,EAAE,QAAgB;;;;;oCAC7C,qBAAM,uBAAK,CAAC,OAAO,CAAC,EAAC,GAAG,EAAE,MAAM,EAAC,CAAC,EAAA;;gCAAzC,IAAI,GAAG,SAAkC;qCAEzC,CAAA,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAA,EAA/B,wBAA+B;gCAClC,qBAAM,uBAAK,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAA;;gCAAvC,SAAuC,CAAC;gCAExC,sBAAO,IAAI,EAAC;oCAGZ,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;;;;aAE7D;SACD;KACD,CAAC,CAAC;AACJ,CAAC","file":"accounts.js","sourcesContent":["import * as handlebars from 'handlebars';\nimport * as jwt from 'jsonwebtoken';\nimport SimpleSchema from 'simpl-schema';\nimport { Users } from '../collections/user.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { UserModel } from '../models/user.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\nimport { ErrorReporter } from '../util/error-reporter';\n\nexport function loadAccountMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tincorrectUser: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\told_user: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tnew_user: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tclient_subs: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'client_subs.$': {\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(old_user, new_user, client_subs) {\n\t\t\t\tif (ResolveIOServer.getMainServer()) {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(this.id_ws);\n\t\t\t\t\tconst correlationId = objectIdHexString();\n\t\t\t\t\tawait ErrorReporter.report({\n\t\t\t\t\t\tsourceApp: 'method-accounts',\n\t\t\t\t\t\tmessage: 'SERVER - WRONG USER Detected - ' + this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\t\tenvironment: this.serverConfig?.ROOT_URL,\n\t\t\t\t\t\tclientSlug: ResolveIOServer.getClientName(),\n\t\t\t\t\t\tclientName: this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tws,\n\t\t\t\t\t\t\tuserMethod: this.user,\n\t\t\t\t\t\t\tid_user: this.id_user,\n\t\t\t\t\t\t\tactiveSubs: ResolveIOServer.getMainServer().getSubscriptionManager().getActiveSubscriptions(),\n\t\t\t\t\t\t\told_user,\n\t\t\t\t\t\t\tnew_user,\n\t\t\t\t\t\t\tclient_subs\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tcontext: 'incorrectUser',\n\t\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn Promise.resolve(null);\n\t\t\t}\n\t\t},\n\t\treloadWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: async function(id_ws) {\n\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(id_ws);\n\n\t\t\t\tif (ws) {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Error('Error in Reload WS: No WS');\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\treconnectWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: async function(id_ws) {\n\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(id_ws);\n\n\t\t\t\tif (ws) {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Error('Error in Reconnect WS: No WS');\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdisconnectWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: async function(id_ws) {\n\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(id_ws);\n\n\t\t\t\tif (ws) {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Error('Error in Disconnect WS: No WS');\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tcreateUserAndEmailEnrollment: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tnewUser: {\n\t\t\t\t\ttype: Users['simplschema']\n\t\t\t\t},\n\t\t\t\tsendEnrollmentEmail: {\n\t\t\t\t\ttype: Boolean,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(newUser: UserModel, sendEnrollmentEmail = true) {\n\t\t\t\tif (newUser.username.toLocaleLowerCase() === 'admin') {\n\t\t\t\t\tthrow new Error('Error in Create User And Email Enrollment: Username can not be admin');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet otherUser = await Users.findOne({\n\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t{username: newUser.username.toLocaleLowerCase()},\n\t\t\t\t\t\t\t{email: newUser.email.toLocaleLowerCase()}\n\t\t\t\t\t\t]\n\t\t\t\t\t});\n\n\t\t\t\t\tif (otherUser) {\n\t\t\t\t\t\tthrow new Error('Error in Create User And Email Enrollment: Username/Email is already used');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tnewUser._id = objectIdHexString();\n\n\t\t\t\tnewUser.services = {\n\t\t\t\t\tenrollment: jwt.sign({id_user: newUser._id}, this.serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\texpiresIn : 3 * 24 * 60 * 60 * 1000 // 3 days\n\t\t\t\t\t})\n\t\t\t\t};\n\n\t\t\t\tnewUser.is_customer = false;\n\t\t\t\tawait Users.insertOne(newUser);\n\n\t\t\t\tif (sendEnrollmentEmail) {\n\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\tfullname: newUser.fullname,\n\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\turl: (this.serverConfig['ROOT_URL'] + '/enroll-account?' + encodeURIComponent(this.serverConfig['SERVER_URL']) + '&' + newUser.services['enrollment'])\n\t\t\t\t\t};\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet html = this.readFile('email-templates/enrollment.html');\n\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait this.sendEmail(newUser.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Enrollment Email', '', template(emailData), null, null, '');\n\n\t\t\t\t\t\treturn newUser;\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\terr.message = `Error in Create User And Email Enrollment: email-templates/enrollment.html - ${err.message}`;\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treturn newUser;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tresetUserPassword: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(userId: string) {\n\t\t\t\tlet user = await Users.findOne({_id: userId});\n\t\n\t\t\t\tif (user) {\n\t\t\t\t\tif (!user.services) {\n\t\t\t\t\t\tuser.services = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tuser.services['forgot_password'] = jwt.sign({id_user: userId}, this.serverConfig['JWT_SECRET']);\n\n\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\tuserToChangePassword: user.fullname,\n\t\t\t\t\t\tuserWhoResetPassword: this.user,\n\t\t\t\t\t\turl: (this.serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(this.serverConfig['SERVER_URL']) + '&' + user.services['forgot_password'])\n\t\t\t\t\t};\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {services: user.services, attempts: 0}});\n\t\t\t\t\t\tlet html = this.readFile('email-templates/forgot-password.html');\n\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t});\n\t\n\t\t\t\t\t\tawait this.sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData), null, null, '');\n\t\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\terr.message = `Error in Reset User Password: email-templates/forgot-password.html - ${err.message}`;\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthrow new Error('Error in Reset User Password: Invalid User');\n\t\t\t}\n\t\t},\n\t\tsetUserPassword: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(userId: string, password: string) {\n\t\t\t\tlet user = await Users.findOne({_id: userId});\n\t\n\t\t\t\tif (user && !user.roles.super_admin) {\n\t\t\t\t\tawait Users.setPassword(user, password);\n\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Error('Error in Set User Password: Invalid User');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/methods/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,gDA2QC;AApSD,uCAAyC;AACzC,kCAAoC;AACpC,6CAAwC;AACxC,kEAAuD;AAGvD,gEAA0D;AAC1D,yCAAmD;AACnD,yDAAuD;AACvD,yCAA0C;AAgB1C,SAAgB,kBAAkB,CAAC,aAA4B;IAC9D,aAAa,CAAC,OAAO,CAAC;QACrB,aAAa,EAAE;YACd,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,QAAQ,EAAE;oBACT,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;gBACD,QAAQ,EAAE;oBACT,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;gBACD,WAAW,EAAE;oBACZ,IAAI,EAAE,KAAK;iBACX;gBACD,eAAe,EAAE;oBAChB,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;aACD,CAAC;YACF,QAAQ,EAAE,UAAe,QAAQ,EAAE,QAAQ,EAAE,WAAW;;;;;;;qCACnD,sCAAe,CAAC,aAAa,EAAE,EAA/B,wBAA+B;gCAC9B,EAAE,GAAG,sCAAe,CAAC,aAAa,EAAE,CAAC,mBAAmB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gCAClF,aAAa,GAAG,IAAA,0BAAiB,GAAE,CAAC;gCAC1C,qBAAM,8BAAa,CAAC,MAAM,CAAC;wCAC1B,SAAS,EAAE,iBAAiB;wCAC5B,OAAO,EAAE,iCAAiC,GAAG,IAAI,CAA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W,CAAC,CAAM,EAAE,CAAM,EAAE,QAAiB;IACrD,IAAI,QAAQ,EAAE,CAAC;QACd,IAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,IAAM,MAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEvC,IAAI,IAAI,CAAC,MAAM,KAAK,MAAI,CAAC,MAAM,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,UAAA,IAAI,IAAI,OAAA,MAAI,CAAC,IAAI,CAAC,UAAA,SAAS,IAAI,OAAA,cAAc,CAAC,SAAS,CAAC,KAAK,cAAc,CAAC,IAAI,CAAC,EAAlD,CAAkD,CAAC,EAA1E,CAA0E,CAAC,CAAC;IACvG,CAAC;IAED,OAAO,cAAc,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AACD,IAAM,kBAAkB,GAAG,GAAG,CAAC","file":"accounts.js","sourcesContent":["import * as handlebars from 'handlebars';\nimport * as jwt from 'jsonwebtoken';\nimport SimpleSchema from 'simpl-schema';\nimport { Users } from '../collections/user.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { UserModel } from '../models/user.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\nimport { ErrorReporter } from '../util/error-reporter';\nimport { deepCopy } from '../util/common';\n\ninterface StickySelectOption {\n\tvalue: any;\n\tlabel?: string;\n}\n\ninterface StickySelectPreference {\n\tkey: string;\n\tdefaultValue: any;\n\tdefaultLabel?: string;\n\tmultiple?: boolean;\n\toptions?: StickySelectOption[];\n\tupdatedAt?: string;\n}\n\nexport function loadAccountMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tincorrectUser: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\told_user: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tnew_user: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tclient_subs: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'client_subs.$': {\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(old_user, new_user, client_subs) {\n\t\t\t\tif (ResolveIOServer.getMainServer()) {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(this.id_ws);\n\t\t\t\t\tconst correlationId = objectIdHexString();\n\t\t\t\t\tawait ErrorReporter.report({\n\t\t\t\t\t\tsourceApp: 'method-accounts',\n\t\t\t\t\t\tmessage: 'SERVER - WRONG USER Detected - ' + this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\t\tenvironment: this.serverConfig?.ROOT_URL,\n\t\t\t\t\t\tclientSlug: ResolveIOServer.getClientName(),\n\t\t\t\t\t\tclientName: this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tws,\n\t\t\t\t\t\t\tuserMethod: this.user,\n\t\t\t\t\t\t\tid_user: this.id_user,\n\t\t\t\t\t\t\tactiveSubs: ResolveIOServer.getMainServer().getSubscriptionManager().getActiveSubscriptions(),\n\t\t\t\t\t\t\told_user,\n\t\t\t\t\t\t\tnew_user,\n\t\t\t\t\t\t\tclient_subs\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tcontext: 'incorrectUser',\n\t\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn Promise.resolve(null);\n\t\t\t}\n\t\t},\n\t\treloadWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: async function(id_ws) {\n\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(id_ws);\n\n\t\t\t\tif (ws) {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Error('Error in Reload WS: No WS');\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\treconnectWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: async function(id_ws) {\n\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(id_ws);\n\n\t\t\t\tif (ws) {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Error('Error in Reconnect WS: No WS');\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdisconnectWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: async function(id_ws) {\n\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(id_ws);\n\n\t\t\t\tif (ws) {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Error('Error in Disconnect WS: No WS');\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tcreateUserAndEmailEnrollment: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tnewUser: {\n\t\t\t\t\ttype: Users['simplschema']\n\t\t\t\t},\n\t\t\t\tsendEnrollmentEmail: {\n\t\t\t\t\ttype: Boolean,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(newUser: UserModel, sendEnrollmentEmail = true) {\n\t\t\t\tif (newUser.username.toLocaleLowerCase() === 'admin') {\n\t\t\t\t\tthrow new Error('Error in Create User And Email Enrollment: Username can not be admin');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet otherUser = await Users.findOne({\n\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t{username: newUser.username.toLocaleLowerCase()},\n\t\t\t\t\t\t\t{email: newUser.email.toLocaleLowerCase()}\n\t\t\t\t\t\t]\n\t\t\t\t\t});\n\n\t\t\t\t\tif (otherUser) {\n\t\t\t\t\t\tthrow new Error('Error in Create User And Email Enrollment: Username/Email is already used');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tnewUser._id = objectIdHexString();\n\n\t\t\t\tnewUser.services = {\n\t\t\t\t\tenrollment: jwt.sign({id_user: newUser._id}, this.serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\texpiresIn : 3 * 24 * 60 * 60 * 1000 // 3 days\n\t\t\t\t\t})\n\t\t\t\t};\n\n\t\t\t\tnewUser.is_customer = false;\n\t\t\t\tawait Users.insertOne(newUser);\n\n\t\t\t\tif (sendEnrollmentEmail) {\n\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\tfullname: newUser.fullname,\n\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\turl: (this.serverConfig['ROOT_URL'] + '/enroll-account?' + encodeURIComponent(this.serverConfig['SERVER_URL']) + '&' + newUser.services['enrollment'])\n\t\t\t\t\t};\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet html = this.readFile('email-templates/enrollment.html');\n\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait this.sendEmail(newUser.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Enrollment Email', '', template(emailData), null, null, '');\n\n\t\t\t\t\t\treturn newUser;\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\terr.message = `Error in Create User And Email Enrollment: email-templates/enrollment.html - ${err.message}`;\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treturn newUser;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tresetUserPassword: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(userId: string) {\n\t\t\t\tlet user = await Users.findOne({_id: userId});\n\t\n\t\t\t\tif (user) {\n\t\t\t\t\tif (!user.services) {\n\t\t\t\t\t\tuser.services = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tuser.services['forgot_password'] = jwt.sign({id_user: userId}, this.serverConfig['JWT_SECRET']);\n\n\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\tuserToChangePassword: user.fullname,\n\t\t\t\t\t\tuserWhoResetPassword: this.user,\n\t\t\t\t\t\turl: (this.serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(this.serverConfig['SERVER_URL']) + '&' + user.services['forgot_password'])\n\t\t\t\t\t};\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {services: user.services, attempts: 0}});\n\t\t\t\t\t\tlet html = this.readFile('email-templates/forgot-password.html');\n\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t});\n\t\n\t\t\t\t\t\tawait this.sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData), null, null, '');\n\t\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\terr.message = `Error in Reset User Password: email-templates/forgot-password.html - ${err.message}`;\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthrow new Error('Error in Reset User Password: Invalid User');\n\t\t\t}\n\t\t},\n\t\tsetUserPassword: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(userId: string, password: string) {\n\t\t\t\tlet user = await Users.findOne({_id: userId});\n\t\n\t\t\t\tif (user && !user.roles.super_admin) {\n\t\t\t\t\tawait Users.setPassword(user, password);\n\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Error('Error in Set User Password: Invalid User');\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tsaveUserStickySelects: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tstickySelects: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'stickySelects.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tid_user: {\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(stickySelects: StickySelectPreference[], id_user?: string) {\n\t\t\t\tconst targetUserId = id_user || this.id_user;\n\t\t\t\tif (!targetUserId) {\n\t\t\t\t\tthrow new Error('Error in Save User Sticky Selects: Invalid User');\n\t\t\t\t}\n\n\t\t\t\tconst user = await Users.findOne({_id: targetUserId});\n\t\t\t\tif (!user) {\n\t\t\t\t\tthrow new Error('Error in Save User Sticky Selects: Invalid User');\n\t\t\t\t}\n\n\t\t\t\tconst mergedStickySelects = mergeStickySelects(user.other?.stickySelects, stickySelects);\n\t\t\t\tconst nextUser: UserModel = deepCopy(user);\n\t\t\t\tnextUser.other = {...(nextUser.other || {}), stickySelects: mergedStickySelects};\n\n\t\t\t\tawait Users.replaceOne({_id: nextUser._id}, nextUser, {}, false, false, user);\n\n\t\t\t\treturn {\n\t\t\t\t\tstickySelects: mergedStickySelects,\n\t\t\t\t\t__v: nextUser.__v\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction mergeStickySelects(existingList: any, incomingList: StickySelectPreference[]): StickySelectPreference[] {\n\tconst existingMap = new Map<string, StickySelectPreference>();\n\n\tif (Array.isArray(existingList)) {\n\t\texistingList.forEach(entry => {\n\t\t\tconst normalized = normalizeStickyPreference(entry);\n\t\t\tif (normalized && normalized.key) {\n\t\t\t\texistingMap.set(normalized.key, normalized);\n\t\t\t}\n\t\t});\n\t}\n\n\tfor (let i = 0; i < incomingList.length; i++) {\n\t\tconst normalized = normalizeStickyPreference(incomingList[i]);\n\t\tif (!normalized || !normalized.key) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst prev = existingMap.get(normalized.key);\n\t\tconst mergedOptions = trimOptions(normalized.options && normalized.options.length\n\t\t\t? mergeOptions(prev?.options || [], normalized.options)\n\t\t\t: (prev?.options || []));\n\n\t\tlet defaultValue = normalized.defaultValue !== undefined ? normalized.defaultValue : (prev ? prev.defaultValue : null);\n\t\tif (defaultValue === undefined) {\n\t\t\tdefaultValue = null;\n\t\t}\n\n\t\tlet defaultLabel = cleanStickyLabel(normalized.defaultLabel);\n\t\tif (!defaultLabel && prev?.defaultLabel) {\n\t\t\tdefaultLabel = cleanStickyLabel(prev.defaultLabel);\n\t\t}\n\n\t\tif (defaultValue !== null && !defaultLabel) {\n\t\t\tconst optionLabel = mergedOptions.find(opt => valuesMatch(opt.value, defaultValue, !!normalized.multiple))?.label || '';\n\t\t\tdefaultLabel = cleanStickyLabel(optionLabel);\n\t\t}\n\n\t\texistingMap.set(normalized.key, {\n\t\t\tkey: normalized.key,\n\t\t\tdefaultValue,\n\t\t\tdefaultLabel,\n\t\t\tmultiple: normalized.multiple !== undefined ? normalized.multiple : !!prev?.multiple,\n\t\t\toptions: mergedOptions,\n\t\t\tupdatedAt: new Date().toISOString()\n\t\t});\n\t}\n\n\treturn Array.from(existingMap.values());\n}\n\nfunction mergeOptions(existing: StickySelectOption[], incoming: StickySelectOption[]): StickySelectOption[] {\n\tconst map = new Map<string, StickySelectOption>();\n\n\tnormalizeStickyOptions(existing).forEach(opt => {\n\t\tconst key = buildOptionKey(opt.value);\n\t\tmap.set(key, opt);\n\t});\n\n\tnormalizeStickyOptions(incoming).forEach(opt => {\n\t\tconst key = buildOptionKey(opt.value);\n\t\tmap.set(key, opt);\n\t});\n\n\treturn Array.from(map.values());\n}\n\nfunction trimOptions(options: StickySelectOption[]): StickySelectOption[] {\n\tif (!Array.isArray(options)) {\n\t\treturn [];\n\t}\n\n\tif (options.length <= STICKY_MAX_OPTIONS) {\n\t\treturn options;\n\t}\n\n\treturn options.slice(0, STICKY_MAX_OPTIONS);\n}\n\nfunction normalizeStickyPreference(entry: any): StickySelectPreference | null {\n\tif (!entry || !entry.key) {\n\t\treturn null;\n\t}\n\n\tconst normalized: StickySelectPreference = {\n\t\tkey: `${entry.key}`,\n\t\tdefaultValue: entry.defaultValue !== undefined ? entry.defaultValue : null,\n\t\tdefaultLabel: cleanStickyLabel(entry.defaultLabel),\n\t\tmultiple: !!entry.multiple,\n\t\toptions: normalizeStickyOptions(entry.options),\n\t\tupdatedAt: entry.updatedAt\n\t};\n\n\treturn normalized;\n}\n\nfunction normalizeStickyOptions(options: any): StickySelectOption[] {\n\tif (Array.isArray(options)) {\n\t\treturn options\n\t\t\t.map(opt => normalizeStickyOption(opt))\n\t\t\t.filter(opt => !!opt) as StickySelectOption[];\n\t}\n\n\tif (options && typeof options === 'object') {\n\t\treturn Object.keys(options)\n\t\t\t.sort()\n\t\t\t.map(key => normalizeStickyOption(options[key]))\n\t\t\t.filter(opt => !!opt) as StickySelectOption[];\n\t}\n\n\treturn [];\n}\n\nfunction normalizeStickyOption(option: any): StickySelectOption | null {\n\tif (!option || option.value === undefined) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\tvalue: option.value,\n\t\tlabel: cleanStickyLabel(option.label)\n\t};\n}\n\nfunction cleanStickyLabel(label: string | undefined): string {\n\tif (!label) {\n\t\treturn '';\n\t}\n\n\tconst trimmed = `${label}`.trim();\n\tif (!trimmed || trimmed.toLowerCase() === 'loading...') {\n\t\treturn '';\n\t}\n\n\treturn trimmed;\n}\n\nfunction buildOptionKey(value: any): string {\n\tif (value === null) {\n\t\treturn 'null';\n\t}\n\n\tif (value === undefined) {\n\t\treturn 'undefined';\n\t}\n\n\tif (typeof value === 'object') {\n\t\ttry {\n\t\t\treturn JSON.stringify(value);\n\t\t}\n\t\tcatch {\n\t\t\treturn `${value}`;\n\t\t}\n\t}\n\n\treturn `${value}`;\n}\n\nfunction valuesMatch(a: any, b: any, multiple: boolean): boolean {\n\tif (multiple) {\n\t\tconst arrA = Array.isArray(a) ? a : [];\n\t\tconst arrB = Array.isArray(b) ? b : [];\n\n\t\tif (arrA.length !== arrB.length) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn arrA.every(item => arrB.some(candidate => buildOptionKey(candidate) === buildOptionKey(item)));\n\t}\n\n\treturn buildOptionKey(a) === buildOptionKey(b);\n}\nconst STICKY_MAX_OPTIONS = 200;\n"]}
|
package/methods.ts
CHANGED
|
@@ -135,6 +135,9 @@ export function SERVER_METHODS(resolveioServer) {
|
|
|
135
135
|
resetUserPassword: (userId: string, cb?: Function): Promise<any> => {
|
|
136
136
|
return resolveioServer.call('resetUserPassword', userId, cb);
|
|
137
137
|
},
|
|
138
|
+
saveUserStickySelects: (stickySelects: StickySelectPreference[], id_user?: string, cb?: Function): Promise<any> => {
|
|
139
|
+
return resolveioServer.call('saveUserStickySelects', stickySelects, id_user, cb);
|
|
140
|
+
},
|
|
138
141
|
setUserPassword: (userId: string, password: string, cb?: Function): Promise<any> => {
|
|
139
142
|
return resolveioServer.call('setUserPassword', userId, password, cb);
|
|
140
143
|
},
|