@resolveio/server-lib 22.2.20 → 22.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/collections/customer-portal-password.collection.d.ts +3 -0
- package/collections/customer-portal-password.collection.js +75 -0
- package/collections/customer-portal-password.collection.js.map +1 -0
- package/managers/mongo.manager.js +11 -4
- package/managers/mongo.manager.js.map +1 -1
- package/managers/subscription.manager.d.ts +1 -0
- package/managers/subscription.manager.js +77 -34
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +85 -2
- package/methods/accounts.js.map +1 -1
- package/methods.ts +5 -2
- package/models/customer-portal-password.model.d.ts +11 -0
- package/models/customer-portal-password.model.js +4 -0
- package/models/customer-portal-password.model.js.map +1 -0
- package/package.json +1 -1
- package/public_api.d.ts +3 -0
- package/public_api.js +3 -0
- package/public_api.js.map +1 -1
- package/util/customer-portal-password.d.ts +13 -0
- package/util/customer-portal-password.js +209 -0
- package/util/customer-portal-password.js.map +1 -0
package/methods/accounts.js
CHANGED
|
@@ -54,6 +54,7 @@ var simpl_schema_1 = require("simpl-schema");
|
|
|
54
54
|
var user_collection_1 = require("../collections/user.collection");
|
|
55
55
|
var resolveio_server_app_1 = require("../resolveio-server-app");
|
|
56
56
|
var common_1 = require("../util/common");
|
|
57
|
+
var customer_portal_password_1 = require("../util/customer-portal-password");
|
|
57
58
|
var error_reporter_1 = require("../util/error-reporter");
|
|
58
59
|
function loadAccountMethods(methodManager) {
|
|
59
60
|
methodManager.methods({
|
|
@@ -319,12 +320,56 @@ function loadAccountMethods(methodManager) {
|
|
|
319
320
|
case 0: return [4 /*yield*/, user_collection_1.Users.findOne({ _id: userId })];
|
|
320
321
|
case 1:
|
|
321
322
|
user = _a.sent();
|
|
322
|
-
if (!(user && !user.roles.super_admin)) return [3 /*break*/,
|
|
323
|
+
if (!(user && !user.roles.super_admin)) return [3 /*break*/, 4];
|
|
323
324
|
return [4 /*yield*/, user_collection_1.Users.setPassword(user, password)];
|
|
324
325
|
case 2:
|
|
326
|
+
_a.sent();
|
|
327
|
+
return [4 /*yield*/, (0, customer_portal_password_1.saveCustomerPortalPassword)(user, password, {
|
|
328
|
+
updatedByUserId: this.id_user,
|
|
329
|
+
updatedByUser: this.user
|
|
330
|
+
})];
|
|
331
|
+
case 3:
|
|
325
332
|
_a.sent();
|
|
326
333
|
return [2 /*return*/, true];
|
|
327
|
-
case
|
|
334
|
+
case 4: throw new Error('Error in Set User Password: Invalid User');
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
getCustomerPortalUserPassword: {
|
|
341
|
+
check: new simpl_schema_1.default({
|
|
342
|
+
userId: {
|
|
343
|
+
type: String
|
|
344
|
+
}
|
|
345
|
+
}),
|
|
346
|
+
function: function (userId) {
|
|
347
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
348
|
+
var methodUser, targetUser, result;
|
|
349
|
+
return __generator(this, function (_a) {
|
|
350
|
+
switch (_a.label) {
|
|
351
|
+
case 0: return [4 /*yield*/, resolveMethodUser(this.id_user, this.user)];
|
|
352
|
+
case 1:
|
|
353
|
+
methodUser = _a.sent();
|
|
354
|
+
if (!canViewCustomerPortalPasswords(methodUser)) {
|
|
355
|
+
throw new Error('Error in Get Customer Portal User Password: Unauthorized');
|
|
356
|
+
}
|
|
357
|
+
return [4 /*yield*/, user_collection_1.Users.findOne({ _id: userId })];
|
|
358
|
+
case 2:
|
|
359
|
+
targetUser = _a.sent();
|
|
360
|
+
if (!targetUser) {
|
|
361
|
+
throw new Error('Error in Get Customer Portal User Password: Invalid User');
|
|
362
|
+
}
|
|
363
|
+
if (!(0, customer_portal_password_1.isCustomerPortalUser)(targetUser)) {
|
|
364
|
+
throw new Error('Error in Get Customer Portal User Password: User is not a customer portal user');
|
|
365
|
+
}
|
|
366
|
+
return [4 /*yield*/, (0, customer_portal_password_1.getDecryptedCustomerPortalPassword)(userId)];
|
|
367
|
+
case 3:
|
|
368
|
+
result = _a.sent();
|
|
369
|
+
return [2 /*return*/, {
|
|
370
|
+
password: result.password,
|
|
371
|
+
last_set_at: result.lastSetAt || null
|
|
372
|
+
}];
|
|
328
373
|
}
|
|
329
374
|
});
|
|
330
375
|
});
|
|
@@ -537,5 +582,43 @@ function valuesMatch(a, b, multiple) {
|
|
|
537
582
|
return buildOptionKey(a) === buildOptionKey(b);
|
|
538
583
|
}
|
|
539
584
|
var STICKY_MAX_OPTIONS = 200;
|
|
585
|
+
function resolveMethodUser(id_user, username) {
|
|
586
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
587
|
+
var userById, userByUsername;
|
|
588
|
+
return __generator(this, function (_a) {
|
|
589
|
+
switch (_a.label) {
|
|
590
|
+
case 0:
|
|
591
|
+
if (!id_user) return [3 /*break*/, 2];
|
|
592
|
+
return [4 /*yield*/, user_collection_1.Users.findById(id_user)];
|
|
593
|
+
case 1:
|
|
594
|
+
userById = _a.sent();
|
|
595
|
+
if (userById) {
|
|
596
|
+
return [2 /*return*/, userById];
|
|
597
|
+
}
|
|
598
|
+
_a.label = 2;
|
|
599
|
+
case 2:
|
|
600
|
+
if (!username) return [3 /*break*/, 4];
|
|
601
|
+
return [4 /*yield*/, user_collection_1.Users.findOne({ username: username })];
|
|
602
|
+
case 3:
|
|
603
|
+
userByUsername = _a.sent();
|
|
604
|
+
if (userByUsername) {
|
|
605
|
+
return [2 /*return*/, userByUsername];
|
|
606
|
+
}
|
|
607
|
+
_a.label = 4;
|
|
608
|
+
case 4: return [2 /*return*/, null];
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
function canViewCustomerPortalPasswords(user) {
|
|
614
|
+
if (!user || !user.roles) {
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
if (user.roles.super_admin) {
|
|
618
|
+
return true;
|
|
619
|
+
}
|
|
620
|
+
var groups = Array.isArray(user.roles.groups) ? user.roles.groups : [];
|
|
621
|
+
return groups.some(function (group) { return Array.isArray(group === null || group === void 0 ? void 0 : group.views) && group.views.includes('/admin/customer-user'); });
|
|
622
|
+
}
|
|
540
623
|
|
|
541
624
|
//# sourceMappingURL=accounts.js.map
|
package/methods/accounts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/methods/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,gDA2RC;AArSD,uCAAyC;AACzC,kCAAoC;AACpC,6CAAwC;AACxC,kEAAuD;AAGvD,gEAA0D;AAC1D,yCAA6D;AAC7D,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,IAAI,CAAC,YAAY,CAAC,a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ars';\nimport * as jwt from 'jsonwebtoken';\nimport SimpleSchema from 'simpl-schema';\nimport { Users } from '../collections/user.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { StickySelectOption, StickySelectPreference, UserModel } from '../models/user.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { deepCopy, 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\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: any[], 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\tlet attempts = 0;\n\t\t\t\tlet mergedStickySelects: StickySelectPreference[] = [];\n\t\t\t\tlet nextVersion = 0;\n\n\t\t\t\twhile (attempts < 5) {\n\t\t\t\t\tconst user = await Users.findOne({_id: targetUserId});\n\t\t\t\t\tif (!user) {\n\t\t\t\t\t\tthrow new Error('Error in Save User Sticky Selects: Invalid User');\n\t\t\t\t\t}\n\n\t\t\t\t\tmergedStickySelects = mergeStickySelects(user.other?.stickySelects, stickySelects);\n\t\t\t\t\tconst nextUser: UserModel = deepCopy(user);\n\t\t\t\t\tnextUser.other = {...(nextUser.other || {}), stickySelects: mergedStickySelects};\n\n\t\t\t\t\tconst res: any = await Users.replaceOne({_id: nextUser._id, __v: user.__v} as any, nextUser, {}, false, false, user);\n\t\t\t\t\tif (res && res.modifiedCount) {\n\t\t\t\t\t\tnextVersion = (user.__v || 0) + 1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tattempts += 1;\n\t\t\t\t}\n\n\t\t\t\tif (attempts >= 5) {\n\t\t\t\t\tthrow new Error('Error in Save User Sticky Selects: Could not acquire latest version');\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstickySelects: mergedStickySelects,\n\t\t\t\t\t__v: nextVersion\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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/methods/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,gDA2TC;AAtUD,uCAAyC;AACzC,kCAAoC;AACpC,6CAAwC;AACxC,kEAAuD;AAGvD,gEAA0D;AAC1D,yCAA6D;AAC7D,6EAAwI;AACxI,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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B,EAAE,QAAiB;;;;;;yBAC/D,OAAO,EAAP,wBAAO;oBACO,qBAAM,uBAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAA;;oBAAxC,QAAQ,GAAG,SAA6B;oBAC9C,IAAI,QAAQ,EAAE,CAAC;wBACd,sBAAO,QAAQ,EAAC;oBACjB,CAAC;;;yBAGE,QAAQ,EAAR,wBAAQ;oBACY,qBAAM,uBAAK,CAAC,OAAO,CAAC,EAAC,QAAQ,UAAA,EAAC,CAAC,EAAA;;oBAAhD,cAAc,GAAG,SAA+B;oBACtD,IAAI,cAAc,EAAE,CAAC;wBACpB,sBAAO,cAAc,EAAC;oBACvB,CAAC;;wBAGF,sBAAO,IAAI,EAAC;;;;CACZ;AAED,SAAS,8BAA8B,CAAC,IAAsB;IAC7D,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACzE,OAAO,MAAM,CAAC,IAAI,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,OAAO,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAA3E,CAA2E,CAAC,CAAC;AAC1G,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 { StickySelectOption, StickySelectPreference, UserModel } from '../models/user.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { deepCopy, objectIdHexString } from '../util/common';\nimport { getDecryptedCustomerPortalPassword, isCustomerPortalUser, saveCustomerPortalPassword } from '../util/customer-portal-password';\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\t\t\t\t\tawait saveCustomerPortalPassword(user, password, {\n\t\t\t\t\t\tupdatedByUserId: this.id_user,\n\t\t\t\t\t\tupdatedByUser: this.user\n\t\t\t\t\t});\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\tgetCustomerPortalUserPassword: {\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\tconst methodUser = await resolveMethodUser(this.id_user, this.user);\n\t\t\t\tif (!canViewCustomerPortalPasswords(methodUser)) {\n\t\t\t\t\tthrow new Error('Error in Get Customer Portal User Password: Unauthorized');\n\t\t\t\t}\n\n\t\t\t\tconst targetUser = await Users.findOne({_id: userId});\n\t\t\t\tif (!targetUser) {\n\t\t\t\t\tthrow new Error('Error in Get Customer Portal User Password: Invalid User');\n\t\t\t\t}\n\n\t\t\t\tif (!isCustomerPortalUser(targetUser)) {\n\t\t\t\t\tthrow new Error('Error in Get Customer Portal User Password: User is not a customer portal user');\n\t\t\t\t}\n\n\t\t\t\tconst result = await getDecryptedCustomerPortalPassword(userId);\n\t\t\t\treturn {\n\t\t\t\t\tpassword: result.password,\n\t\t\t\t\tlast_set_at: result.lastSetAt || null\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: any[], 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\tlet attempts = 0;\n\t\t\t\tlet mergedStickySelects: StickySelectPreference[] = [];\n\t\t\t\tlet nextVersion = 0;\n\n\t\t\t\twhile (attempts < 5) {\n\t\t\t\t\tconst user = await Users.findOne({_id: targetUserId});\n\t\t\t\t\tif (!user) {\n\t\t\t\t\t\tthrow new Error('Error in Save User Sticky Selects: Invalid User');\n\t\t\t\t\t}\n\n\t\t\t\t\tmergedStickySelects = mergeStickySelects(user.other?.stickySelects, stickySelects);\n\t\t\t\t\tconst nextUser: UserModel = deepCopy(user);\n\t\t\t\t\tnextUser.other = {...(nextUser.other || {}), stickySelects: mergedStickySelects};\n\n\t\t\t\t\tconst res: any = await Users.replaceOne({_id: nextUser._id, __v: user.__v} as any, nextUser, {}, false, false, user);\n\t\t\t\t\tif (res && res.modifiedCount) {\n\t\t\t\t\t\tnextVersion = (user.__v || 0) + 1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tattempts += 1;\n\t\t\t\t}\n\n\t\t\t\tif (attempts >= 5) {\n\t\t\t\t\tthrow new Error('Error in Save User Sticky Selects: Could not acquire latest version');\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstickySelects: mergedStickySelects,\n\t\t\t\t\t__v: nextVersion\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\nasync function resolveMethodUser(id_user?: string, username?: string): Promise<UserModel | null> {\n\tif (id_user) {\n\t\tconst userById = await Users.findById(id_user);\n\t\tif (userById) {\n\t\t\treturn userById;\n\t\t}\n\t}\n\n\tif (username) {\n\t\tconst userByUsername = await Users.findOne({username});\n\t\tif (userByUsername) {\n\t\t\treturn userByUsername;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction canViewCustomerPortalPasswords(user: UserModel | null): boolean {\n\tif (!user || !user.roles) {\n\t\treturn false;\n\t}\n\n\tif (user.roles.super_admin) {\n\t\treturn true;\n\t}\n\n\tconst groups = Array.isArray(user.roles.groups) ? user.roles.groups : [];\n\treturn groups.some(group => Array.isArray(group?.views) && group.views.includes('/admin/customer-user'));\n}\n"]}
|
package/methods.ts
CHANGED
|
@@ -108,6 +108,9 @@ export function SERVER_METHODS(resolveioServer) {
|
|
|
108
108
|
generatePDFNoPageNumber: (html, fileName, orientation = 'portrait', fontSize = '12px', upload = false, uploadFileOrder = -1, uploadFileType = '', cb?: Function): Promise<any> => {
|
|
109
109
|
return resolveioServer.call('generatePDFNoPageNumber', html, fileName, orientation, fontSize, upload, uploadFileOrder, uploadFileType, cb);
|
|
110
110
|
},
|
|
111
|
+
getCustomerPortalUserPassword: (userId: string, cb?: Function): Promise<any> => {
|
|
112
|
+
return resolveioServer.call('getCustomerPortalUserPassword', userId, cb);
|
|
113
|
+
},
|
|
111
114
|
getDataURIfromURL: (url: string, cb?: Function): Promise<any> => {
|
|
112
115
|
return resolveioServer.call('getDataURIfromURL', url, cb);
|
|
113
116
|
},
|
|
@@ -253,10 +256,10 @@ export function SERVER_METHODS(resolveioServer) {
|
|
|
253
256
|
return resolveioServer.call('superAdminDeploySlowQueryLog', logId, cb);
|
|
254
257
|
},
|
|
255
258
|
superAdminListAutoFixLogs: (payload: Record<string, any> = {}, cb?: Function): Promise<any> => {
|
|
256
|
-
return resolveioServer.call('superAdminListAutoFixLogs', payload,
|
|
259
|
+
return resolveioServer.call('superAdminListAutoFixLogs', payload, cb);
|
|
257
260
|
},
|
|
258
261
|
superAdminListSlowQueryLogs: (payload: Record<string, any> = {}, cb?: Function): Promise<any> => {
|
|
259
|
-
return resolveioServer.call('superAdminListSlowQueryLogs', payload,
|
|
262
|
+
return resolveioServer.call('superAdminListSlowQueryLogs', payload, cb);
|
|
260
263
|
},
|
|
261
264
|
superAdminRunAutoFixLog: (logId: string, cb?: Function): Promise<any> => {
|
|
262
265
|
return resolveioServer.call('superAdminRunAutoFixLog', logId, cb);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CollectionDocument } from './collection-document.model';
|
|
2
|
+
export interface CustomerPortalPasswordModel extends CollectionDocument {
|
|
3
|
+
id_user: string;
|
|
4
|
+
cipher_text: string;
|
|
5
|
+
iv: string;
|
|
6
|
+
auth_tag: string;
|
|
7
|
+
key_version: number;
|
|
8
|
+
last_set_at: Date;
|
|
9
|
+
updated_by_user_id?: string;
|
|
10
|
+
updated_by_user?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/customer-portal-password.model.ts"],"names":[],"mappings":"","file":"customer-portal-password.model.js","sourcesContent":["import { CollectionDocument } from './collection-document.model';\n\nexport interface CustomerPortalPasswordModel extends CollectionDocument {\n\tid_user: string;\n\tcipher_text: string;\n\tiv: string;\n\tauth_tag: string;\n\tkey_version: number;\n\tlast_set_at: Date;\n\tupdated_by_user_id?: string;\n\tupdated_by_user?: string;\n}\n"]}
|
package/package.json
CHANGED
package/public_api.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './collections/ai-terminal-issue-report.collection';
|
|
|
4
4
|
export * from './collections/ai-terminal-conversation.collection';
|
|
5
5
|
export * from './collections/ai-terminal-message.collection';
|
|
6
6
|
export * from './collections/counter.collection';
|
|
7
|
+
export * from './collections/customer-portal-password.collection';
|
|
7
8
|
export * from './collections/customer-notification.collection';
|
|
8
9
|
export * from './collections/communication-metric.collection';
|
|
9
10
|
export * from './collections/cron-job-history.collection';
|
|
@@ -43,6 +44,7 @@ export * from './models/billing-logged-in-users.model';
|
|
|
43
44
|
export * from './models/collection-document.model';
|
|
44
45
|
export * from './models/communication-metric.model';
|
|
45
46
|
export * from './models/counter.model';
|
|
47
|
+
export * from './models/customer-portal-password.model';
|
|
46
48
|
export * from './models/customer-notification.model';
|
|
47
49
|
export * from './models/cron-job-history.model';
|
|
48
50
|
export * from './models/cron-job.model';
|
|
@@ -83,4 +85,5 @@ export * from './resolveio-server-app';
|
|
|
83
85
|
export * from './services/openai-client';
|
|
84
86
|
export * from './services/codex-client';
|
|
85
87
|
export * from './util/common';
|
|
88
|
+
export * from './util/customer-portal-password';
|
|
86
89
|
export * from './util/tokenizer';
|
package/public_api.js
CHANGED
|
@@ -20,6 +20,7 @@ __exportStar(require("./collections/ai-terminal-issue-report.collection"), expor
|
|
|
20
20
|
__exportStar(require("./collections/ai-terminal-conversation.collection"), exports);
|
|
21
21
|
__exportStar(require("./collections/ai-terminal-message.collection"), exports);
|
|
22
22
|
__exportStar(require("./collections/counter.collection"), exports);
|
|
23
|
+
__exportStar(require("./collections/customer-portal-password.collection"), exports);
|
|
23
24
|
__exportStar(require("./collections/customer-notification.collection"), exports);
|
|
24
25
|
__exportStar(require("./collections/communication-metric.collection"), exports);
|
|
25
26
|
__exportStar(require("./collections/cron-job-history.collection"), exports);
|
|
@@ -59,6 +60,7 @@ __exportStar(require("./models/billing-logged-in-users.model"), exports);
|
|
|
59
60
|
__exportStar(require("./models/collection-document.model"), exports);
|
|
60
61
|
__exportStar(require("./models/communication-metric.model"), exports);
|
|
61
62
|
__exportStar(require("./models/counter.model"), exports);
|
|
63
|
+
__exportStar(require("./models/customer-portal-password.model"), exports);
|
|
62
64
|
__exportStar(require("./models/customer-notification.model"), exports);
|
|
63
65
|
__exportStar(require("./models/cron-job-history.model"), exports);
|
|
64
66
|
__exportStar(require("./models/cron-job.model"), exports);
|
|
@@ -99,6 +101,7 @@ __exportStar(require("./resolveio-server-app"), exports);
|
|
|
99
101
|
__exportStar(require("./services/openai-client"), exports);
|
|
100
102
|
__exportStar(require("./services/codex-client"), exports);
|
|
101
103
|
__exportStar(require("./util/common"), exports);
|
|
104
|
+
__exportStar(require("./util/customer-portal-password"), exports);
|
|
102
105
|
__exportStar(require("./util/tokenizer"), exports);
|
|
103
106
|
|
|
104
107
|
//# sourceMappingURL=public_api.js.map
|
package/public_api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/public_api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,uEAAqD;AACrD,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,oEAAkD;AAClD,yEAAuD;AACvD,gEAA8C;AAC9C,mFAAiE;AACjE,0EAAwD;AACxD,4DAA0C;AAC1C,6DAA2C;AAC3C,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,uDAAqC;AACrC,4DAA0C;AAC1C,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/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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/public_api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,uEAAqD;AACrD,oFAAkE;AAClE,oFAAkE;AAClE,+EAA6D;AAC7D,mEAAiD;AACjD,oFAAkE;AAClE,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,oEAAkD;AAClD,yEAAuD;AACvD,gEAA8C;AAC9C,mFAAiE;AACjE,0EAAwD;AACxD,4DAA0C;AAC1C,6DAA2C;AAC3C,0EAAwD;AACxD,0EAAwD;AACxD,qEAAmD;AACnD,yEAAuD;AACvD,qEAAmD;AACnD,sEAAoD;AACpD,yDAAuC;AACvC,0EAAwD;AACxD,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,uDAAqC;AACrC,4DAA0C;AAC1C,yEAAuD;AACvD,0EAAwD;AACxD,yDAAuC;AACvC,2DAAyC;AACzC,0DAAwC;AACxC,gDAA8B;AAC9B,kEAAgD;AAChD,mDAAiC","file":"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-portal-password.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-portal-password.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/customer-portal-password';\nexport * from './util/tokenizer';\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UserModel } from '../models/user.model';
|
|
2
|
+
interface PasswordRecordMeta {
|
|
3
|
+
updatedByUserId?: string;
|
|
4
|
+
updatedByUser?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function isCustomerPortalUser(user: UserModel | any): boolean;
|
|
7
|
+
export declare function saveCustomerPortalPassword(user: UserModel | any, password: string, meta?: PasswordRecordMeta): Promise<void>;
|
|
8
|
+
export declare function clearCustomerPortalPassword(userId: string): Promise<void>;
|
|
9
|
+
export declare function getDecryptedCustomerPortalPassword(userId: string): Promise<{
|
|
10
|
+
password: string;
|
|
11
|
+
lastSetAt?: Date;
|
|
12
|
+
}>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.isCustomerPortalUser = isCustomerPortalUser;
|
|
40
|
+
exports.saveCustomerPortalPassword = saveCustomerPortalPassword;
|
|
41
|
+
exports.clearCustomerPortalPassword = clearCustomerPortalPassword;
|
|
42
|
+
exports.getDecryptedCustomerPortalPassword = getDecryptedCustomerPortalPassword;
|
|
43
|
+
var customer_portal_password_collection_1 = require("../collections/customer-portal-password.collection");
|
|
44
|
+
var resolveio_server_app_1 = require("../resolveio-server-app");
|
|
45
|
+
var crypto = require('crypto');
|
|
46
|
+
var ALGORITHM = 'aes-256-gcm';
|
|
47
|
+
var ENCRYPTION_KEY_VERSION = 1;
|
|
48
|
+
var IV_LENGTH_BYTES = 12;
|
|
49
|
+
function isCustomerPortalUser(user) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (!user || typeof user !== 'object') {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
var other = user.other || {};
|
|
55
|
+
if (other.id_customer) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(other.customers) && other.customers.length > 0) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
var groups = Array.isArray((_a = user === null || user === void 0 ? void 0 : user.roles) === null || _a === void 0 ? void 0 : _a.groups) ? user.roles.groups : [];
|
|
62
|
+
if (groups.some(function (group) {
|
|
63
|
+
if (!group || typeof group.name !== 'string') {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
var normalized = group.name.trim().toLowerCase();
|
|
67
|
+
return normalized === 'customer portal' || normalized === 'customer-portal';
|
|
68
|
+
})) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
function saveCustomerPortalPassword(user, password, meta) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var payload, setData;
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
if (!(user === null || user === void 0 ? void 0 : user._id)) {
|
|
80
|
+
return [2 /*return*/];
|
|
81
|
+
}
|
|
82
|
+
if (!customer_portal_password_collection_1.CustomerPortalPasswords) {
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
if (!!isCustomerPortalUser(user)) return [3 /*break*/, 2];
|
|
86
|
+
return [4 /*yield*/, clearCustomerPortalPassword(user._id)];
|
|
87
|
+
case 1:
|
|
88
|
+
_a.sent();
|
|
89
|
+
return [2 /*return*/];
|
|
90
|
+
case 2:
|
|
91
|
+
if (!(!password || typeof password !== 'string')) return [3 /*break*/, 4];
|
|
92
|
+
return [4 /*yield*/, clearCustomerPortalPassword(user._id)];
|
|
93
|
+
case 3:
|
|
94
|
+
_a.sent();
|
|
95
|
+
return [2 /*return*/];
|
|
96
|
+
case 4:
|
|
97
|
+
payload = encryptPassword(password);
|
|
98
|
+
setData = {
|
|
99
|
+
id_user: user._id,
|
|
100
|
+
cipher_text: payload.cipherText,
|
|
101
|
+
iv: payload.iv,
|
|
102
|
+
auth_tag: payload.authTag,
|
|
103
|
+
key_version: payload.keyVersion,
|
|
104
|
+
last_set_at: new Date()
|
|
105
|
+
};
|
|
106
|
+
if (meta === null || meta === void 0 ? void 0 : meta.updatedByUserId) {
|
|
107
|
+
setData.updated_by_user_id = meta.updatedByUserId;
|
|
108
|
+
}
|
|
109
|
+
if (meta === null || meta === void 0 ? void 0 : meta.updatedByUser) {
|
|
110
|
+
setData.updated_by_user = meta.updatedByUser;
|
|
111
|
+
}
|
|
112
|
+
return [4 /*yield*/, customer_portal_password_collection_1.CustomerPortalPasswords.updateOne({ id_user: user._id }, {
|
|
113
|
+
$set: setData
|
|
114
|
+
}, { upsert: true })];
|
|
115
|
+
case 5:
|
|
116
|
+
_a.sent();
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function clearCustomerPortalPassword(userId) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
switch (_a.label) {
|
|
126
|
+
case 0:
|
|
127
|
+
if (!userId || !customer_portal_password_collection_1.CustomerPortalPasswords) {
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
return [4 /*yield*/, customer_portal_password_collection_1.CustomerPortalPasswords.deleteOne({ id_user: userId })];
|
|
131
|
+
case 1:
|
|
132
|
+
_a.sent();
|
|
133
|
+
return [2 /*return*/];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function getDecryptedCustomerPortalPassword(userId) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
var record, password;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
switch (_a.label) {
|
|
143
|
+
case 0:
|
|
144
|
+
if (!userId) {
|
|
145
|
+
throw new Error('Customer portal user id is required.');
|
|
146
|
+
}
|
|
147
|
+
if (!customer_portal_password_collection_1.CustomerPortalPasswords) {
|
|
148
|
+
throw new Error('Customer portal password store is not available.');
|
|
149
|
+
}
|
|
150
|
+
return [4 /*yield*/, customer_portal_password_collection_1.CustomerPortalPasswords.findOne({ id_user: userId })];
|
|
151
|
+
case 1:
|
|
152
|
+
record = _a.sent();
|
|
153
|
+
if (!record) {
|
|
154
|
+
throw new Error('No stored customer portal password is available for this user.');
|
|
155
|
+
}
|
|
156
|
+
password = decryptPassword({
|
|
157
|
+
cipherText: record.cipher_text,
|
|
158
|
+
iv: record.iv,
|
|
159
|
+
authTag: record.auth_tag,
|
|
160
|
+
keyVersion: record.key_version
|
|
161
|
+
});
|
|
162
|
+
return [2 /*return*/, {
|
|
163
|
+
password: password,
|
|
164
|
+
lastSetAt: record.last_set_at
|
|
165
|
+
}];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function encryptPassword(plainText) {
|
|
171
|
+
var key = resolveEncryptionKey();
|
|
172
|
+
var ivBuffer = crypto.randomBytes(IV_LENGTH_BYTES);
|
|
173
|
+
var cipher = crypto.createCipheriv(ALGORITHM, key, ivBuffer);
|
|
174
|
+
var encrypted = Buffer.concat([cipher.update(plainText, 'utf8'), cipher.final()]);
|
|
175
|
+
var authTag = cipher.getAuthTag();
|
|
176
|
+
return {
|
|
177
|
+
cipherText: encrypted.toString('base64'),
|
|
178
|
+
iv: ivBuffer.toString('base64'),
|
|
179
|
+
authTag: authTag.toString('base64'),
|
|
180
|
+
keyVersion: ENCRYPTION_KEY_VERSION
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function decryptPassword(payload) {
|
|
184
|
+
if (!payload || payload.keyVersion !== ENCRYPTION_KEY_VERSION) {
|
|
185
|
+
throw new Error('Unsupported customer portal password encryption version.');
|
|
186
|
+
}
|
|
187
|
+
var key = resolveEncryptionKey();
|
|
188
|
+
var decipher = crypto.createDecipheriv(ALGORITHM, key, Buffer.from(payload.iv, 'base64'));
|
|
189
|
+
decipher.setAuthTag(Buffer.from(payload.authTag, 'base64'));
|
|
190
|
+
var decrypted = Buffer.concat([
|
|
191
|
+
decipher.update(Buffer.from(payload.cipherText, 'base64')),
|
|
192
|
+
decipher.final()
|
|
193
|
+
]);
|
|
194
|
+
return decrypted.toString('utf8');
|
|
195
|
+
}
|
|
196
|
+
function resolveEncryptionKey() {
|
|
197
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : {};
|
|
198
|
+
var secret = String((config && config['CUSTOMER_PORTAL_PASSWORD_SECRET'])
|
|
199
|
+
|| process.env.CUSTOMER_PORTAL_PASSWORD_SECRET
|
|
200
|
+
|| (config && config['JWT_SECRET'])
|
|
201
|
+
|| process.env.JWT_SECRET
|
|
202
|
+
|| '').trim();
|
|
203
|
+
if (!secret) {
|
|
204
|
+
throw new Error('Missing CUSTOMER_PORTAL_PASSWORD_SECRET (or JWT_SECRET) for customer portal password encryption.');
|
|
205
|
+
}
|
|
206
|
+
return crypto.createHash('sha256').update(secret, 'utf8').digest();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//# sourceMappingURL=customer-portal-password.js.map
|