@resolveio/server-lib 6.3.10 → 6.4.0-newrole
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/report-builder-library.collection.d.ts +7 -0
- package/collections/report-builder-library.collection.js +93 -0
- package/collections/report-builder-library.collection.js.map +1 -0
- package/collections/user-group.collection.d.ts +7 -0
- package/collections/user-group.collection.js +101 -0
- package/collections/user-group.collection.js.map +1 -0
- package/collections/user.collection.js +39 -32
- package/collections/user.collection.js.map +1 -1
- package/managers/method.manager.d.ts +1 -1
- package/managers/method.manager.js +18 -14
- package/managers/method.manager.js.map +1 -1
- package/managers/subscription.manager.js +4 -0
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js.map +1 -1
- package/methods/cron-jobs.js.map +1 -1
- package/models/report-builder-library.model.d.ts +17 -0
- package/models/report-builder-library.model.js +4 -0
- package/models/report-builder-library.model.js.map +1 -0
- package/models/user-group.model.d.ts +19 -0
- package/models/user-group.model.js +4 -0
- package/models/user-group.model.js.map +1 -0
- package/models/user.model.d.ts +25 -14
- package/models/user.model.js.map +1 -1
- package/package.json +1 -1
- package/publications/report-builder-libraries.d.ts +2 -0
- package/publications/report-builder-libraries.js +95 -0
- package/publications/report-builder-libraries.js.map +1 -0
- package/publications/user-groups.d.ts +1 -0
- package/publications/user-groups.js +16 -0
- package/publications/user-groups.js.map +1 -0
- package/server-app.js +48 -18
- package/server-app.js.map +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CollectionDocument } from './collection-document.model';
|
|
2
|
+
export interface ReportBuilderLibraryModel extends CollectionDocument {
|
|
3
|
+
name: string;
|
|
4
|
+
id_user_create: string;
|
|
5
|
+
user_create: string;
|
|
6
|
+
date: Date;
|
|
7
|
+
reports: ReportBuilderLibraryReportModel[];
|
|
8
|
+
user_groups: ReportBuilderLibraryUserGroupModel[];
|
|
9
|
+
}
|
|
10
|
+
export interface ReportBuilderLibraryReportModel {
|
|
11
|
+
id_report: string;
|
|
12
|
+
report: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ReportBuilderLibraryUserGroupModel {
|
|
15
|
+
id_user_group: string;
|
|
16
|
+
user_group: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/report-builder-library.model.ts"],"names":[],"mappings":"","file":"report-builder-library.model.js","sourcesContent":["import { CollectionDocument } from './collection-document.model';\n\nexport interface ReportBuilderLibraryModel extends CollectionDocument {\n\tname: string;\n\tid_user_create: string;\n\tuser_create: string;\n\tdate: Date;\n\treports: ReportBuilderLibraryReportModel[];\n\tuser_groups: ReportBuilderLibraryUserGroupModel[];\n}\n\nexport interface ReportBuilderLibraryReportModel {\n\tid_report: string;\n\treport: string;\n}\n\nexport interface ReportBuilderLibraryUserGroupModel {\n\tid_user_group: string;\n\tuser_group: string;\n}"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CollectionDocument } from './collection-document.model';
|
|
2
|
+
export interface UserGroupModel extends CollectionDocument {
|
|
3
|
+
name: string;
|
|
4
|
+
permissions: UserGroupPermissionModel[];
|
|
5
|
+
notifications: UserGroupNotificationModel[];
|
|
6
|
+
}
|
|
7
|
+
export interface UserGroupNotificationModel {
|
|
8
|
+
name: string;
|
|
9
|
+
selected: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface UserGroupPermissionModel {
|
|
12
|
+
name: string;
|
|
13
|
+
selected: boolean;
|
|
14
|
+
views: UserGroupViewModel[];
|
|
15
|
+
}
|
|
16
|
+
export interface UserGroupViewModel {
|
|
17
|
+
link: string;
|
|
18
|
+
selected: boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/user-group.model.ts"],"names":[],"mappings":"","file":"user-group.model.js","sourcesContent":["import { CollectionDocument } from './collection-document.model';\n\nexport interface UserGroupModel extends CollectionDocument {\n\tname: string;\n\tpermissions: UserGroupPermissionModel[];\n\tnotifications: UserGroupNotificationModel[];\n}\n\nexport interface UserGroupNotificationModel {\n\tname: string;\n\tselected: boolean;\n}\n\nexport interface UserGroupPermissionModel {\n\tname: string;\n\tselected: boolean;\n\tviews: UserGroupViewModel[];\n}\n\nexport interface UserGroupViewModel {\n\tlink: string;\n\tselected: boolean;\n}"]}
|
package/models/user.model.d.ts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { CollectionDocument } from './collection-document.model';
|
|
2
2
|
export interface UserModel extends CollectionDocument {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
roles: UserRoleModel;
|
|
4
|
+
attempts?: number;
|
|
5
|
+
last?: Date;
|
|
6
|
+
services?: any;
|
|
5
7
|
fullname: string;
|
|
6
|
-
roles: string[];
|
|
7
|
-
readonly?: boolean;
|
|
8
8
|
username?: string;
|
|
9
9
|
email?: string;
|
|
10
10
|
active?: boolean;
|
|
11
|
-
services?: any;
|
|
12
|
-
phonenumber?: string;
|
|
13
|
-
other?: UserObject;
|
|
14
11
|
id_customer?: string;
|
|
15
12
|
customer?: string;
|
|
16
13
|
customer_type?: string;
|
|
17
|
-
customers?:
|
|
14
|
+
customers?: UserCustomerModel[];
|
|
15
|
+
phonenumber?: string;
|
|
16
|
+
other?: UserObject;
|
|
17
|
+
assets?: UserAssetModel[];
|
|
18
|
+
id_function?: string;
|
|
19
|
+
readonly?: boolean;
|
|
18
20
|
departments?: UserDepartmentModel[];
|
|
19
21
|
}
|
|
20
22
|
export interface UserObject {
|
|
21
23
|
[key: string]: any;
|
|
22
24
|
}
|
|
23
|
-
export interface UserDepartmentModel {
|
|
24
|
-
id_department: string;
|
|
25
|
-
department: string;
|
|
26
|
-
}
|
|
27
25
|
export interface UserRoleModel {
|
|
28
26
|
super_admin: boolean;
|
|
29
27
|
approvals: UserRoleApprovalModel[];
|
|
@@ -41,7 +39,20 @@ export interface UserRoleGroupModel {
|
|
|
41
39
|
views: string[];
|
|
42
40
|
yard?: string;
|
|
43
41
|
}
|
|
44
|
-
export interface
|
|
45
|
-
|
|
42
|
+
export interface UserAssetModel {
|
|
43
|
+
type: any;
|
|
44
|
+
id_asset: string;
|
|
45
|
+
asset_number: string;
|
|
46
|
+
ownership: string;
|
|
47
|
+
ownership_driver: string;
|
|
48
|
+
date_start: Date;
|
|
49
|
+
date_end?: Date;
|
|
50
|
+
}
|
|
51
|
+
export interface UserCustomerModel {
|
|
46
52
|
customer: string;
|
|
53
|
+
id_customer: string;
|
|
54
|
+
}
|
|
55
|
+
export interface UserDepartmentModel {
|
|
56
|
+
id_department: string;
|
|
57
|
+
department: string;
|
|
47
58
|
}
|
package/models/user.model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/user.model.ts"],"names":[],"mappings":"","file":"user.model.js","sourcesContent":["import { CollectionDocument } from './collection-document.model';\n\nexport interface UserModel extends CollectionDocument {\n\
|
|
1
|
+
{"version":3,"sources":["../../src/models/user.model.ts"],"names":[],"mappings":"","file":"user.model.js","sourcesContent":["import { CollectionDocument } from './collection-document.model';\n\nexport interface UserModel extends CollectionDocument {\n\troles: UserRoleModel;\n\tattempts?: number;\n\tlast?: Date;\n\tservices?: any;\n\tfullname: string;\n\tusername?: string;\n\temail?: string;\n\tactive?: boolean;\n\tid_customer?: string;\n\tcustomer?: string;\n\tcustomer_type?: string;\n\tcustomers?: UserCustomerModel[];\n\tphonenumber?: string;\n\tother?: UserObject;\n\tassets?: UserAssetModel[];\n\tid_function?: string;\n\treadonly?: boolean;\n\tdepartments?: UserDepartmentModel[];\n}\n\nexport interface UserObject {\n [key: string]: any;\n}\n\nexport interface UserRoleModel {\n\tsuper_admin: boolean;\n\tapprovals: UserRoleApprovalModel[];\n\tgroups: UserRoleGroupModel[];\n\tnotifications: string[];\n\tmiscs: string[];\n}\n\nexport interface UserRoleApprovalModel {\n\taccounting_code: string;\n\ttype: string;\n\tname: string;\n}\n\nexport interface UserRoleGroupModel {\n\tname: string;\n\tviews: string[];\n\tyard?: string;\n}\n\nexport interface UserAssetModel {\n\ttype: any;\n\tid_asset: string;\n\tasset_number: string;\n\townership: string;\n\townership_driver: string;\n\tdate_start: Date;\n\tdate_end?: Date;\n}\n\nexport interface UserCustomerModel {\n\tcustomer: string;\n\tid_customer: string;\n}\n\nexport interface UserDepartmentModel {\n\tid_department: string;\n\tdepartment: string;\n}"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,95 @@
|
|
|
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;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "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 (_) 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
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
40
|
+
var report_builder_library_collection_1 = require("../collections/report-builder-library.collection");
|
|
41
|
+
var user_collection_1 = require("../collections/user.collection");
|
|
42
|
+
var user_group_collection_1 = require("../collections/user-group.collection");
|
|
43
|
+
function loadReportBuilderLibraryPublications(subscriptionManager) {
|
|
44
|
+
var _this = this;
|
|
45
|
+
subscriptionManager.publications({
|
|
46
|
+
reportbuilderlibraries: {
|
|
47
|
+
function: function () {
|
|
48
|
+
return report_builder_library_collection_1.ReportBuilderLibraries.find().sort({ name: 1 }).exec();
|
|
49
|
+
},
|
|
50
|
+
collections: ['report-builder-libraries']
|
|
51
|
+
},
|
|
52
|
+
reportbuilderlibrariesWithIdUser: {
|
|
53
|
+
check: new simpl_schema_1.default({
|
|
54
|
+
id_user: {
|
|
55
|
+
type: String
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
function: function (id_user) {
|
|
59
|
+
return report_builder_library_collection_1.ReportBuilderLibraries.find({ id_user_create: id_user }).sort({ name: 1 }).exec();
|
|
60
|
+
},
|
|
61
|
+
collections: ['report-builder-libraries'],
|
|
62
|
+
fetchFunction: function (document, id_user) {
|
|
63
|
+
return (document['id_user'] === id_user);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
reportbuilderlibrariesForUser: {
|
|
67
|
+
check: new simpl_schema_1.default({
|
|
68
|
+
id_user: {
|
|
69
|
+
type: String
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
function: function (id_user) { return __awaiter(_this, void 0, void 0, function () {
|
|
73
|
+
var user, userGroups;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0: return [4 /*yield*/, user_collection_1.Users.findById(id_user)];
|
|
77
|
+
case 1:
|
|
78
|
+
user = _a.sent();
|
|
79
|
+
return [4 /*yield*/, user_group_collection_1.UserGroups.find({ name: { $in: user.roles.groups.map(function (a) { return a.name; }) } })];
|
|
80
|
+
case 2:
|
|
81
|
+
userGroups = _a.sent();
|
|
82
|
+
return [2 /*return*/, report_builder_library_collection_1.ReportBuilderLibraries.find({ 'user_groups.id_user_group': { $in: userGroups.map(function (a) { return a._id; }) } }).sort({ name: 1 }).exec()];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}); },
|
|
86
|
+
collections: ['report-builder-libraries'],
|
|
87
|
+
fetchFunction: function (document, id_user) {
|
|
88
|
+
return (document['id_user'] === id_user);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
exports.loadReportBuilderLibraryPublications = loadReportBuilderLibraryPublications;
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=report-builder-libraries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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,EAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,EAAN,CAAM,CAAC,EAAC,EAAC,CAAC,EAAA;;4BAArF,UAAU,GAAG,SAAwE;4BAEzF,sBAAO,0DAAsB,CAAC,IAAI,CAAC,EAAC,2BAA2B,EAAE,EAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,GAAG,EAAL,CAAK,CAAC,EAAC,EAAC,CAAC,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,CAAC,EAAC,CAAC,CAAC,IAAI,EAAE,EAAC;;;iBAC5H;YACD,WAAW,EAAE,CAAC,0BAA0B,CAAC;YACzC,aAAa,EAAE,UAAC,QAAkB,EAAE,OAAe;gBAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,OAAO,CAAC,CAAC;YAC1C,CAAC;SACD;KACD,CAAC,CAAC;AACJ,CAAC;AAxCD,oFAwCC","file":"report-builder-libraries.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { Document } from 'mongoose';\nimport { SubscriptionManager } from '../managers/subscription.manager';\nimport { ReportBuilderLibraries } from '../collections/report-builder-library.collection';\nimport { Users } from '../collections/user.collection';\nimport { UserGroups } from '../collections/user-group.collection';\n\nexport function loadReportBuilderLibraryPublications(subscriptionManager: SubscriptionManager) {\n\tsubscriptionManager.publications({\n\t\treportbuilderlibraries: {\n\t\t\tfunction: () => {\n\t\t\t\treturn ReportBuilderLibraries.find().sort({name: 1}).exec();\n\t\t\t},\n\t\t\tcollections: ['report-builder-libraries']\n\t\t},\n\t\treportbuilderlibrariesWithIdUser: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_user: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: (id_user: string) => {\n\t\t\t\treturn ReportBuilderLibraries.find({id_user_create: id_user}).sort({name: 1}).exec();\n\t\t\t},\n\t\t\tcollections: ['report-builder-libraries'],\n\t\t\tfetchFunction: (document: Document, id_user: string) => {\n\t\t\t\treturn (document['id_user'] === id_user);\n\t\t\t}\n\t\t},\n\t\treportbuilderlibrariesForUser: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_user: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async (id_user: string) => {\n\t\t\t\tlet user = await Users.findById(id_user);\n\t\t\t\tlet userGroups = await UserGroups.find({name: {$in: user.roles.groups.map(a => a.name)}});\n\n\t\t\t\treturn ReportBuilderLibraries.find({'user_groups.id_user_group': {$in: userGroups.map(a => a._id)}}).sort({name: 1}).exec();\n\t\t\t},\n\t\t\tcollections: ['report-builder-libraries'],\n\t\t\tfetchFunction: (document: Document, id_user: string) => {\n\t\t\t\treturn (document['id_user'] === id_user);\n\t\t\t}\n\t\t},\n\t});\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadUserGroupPublications(subscriptionManager: any): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var user_group_collection_1 = require("../collections/user-group.collection");
|
|
4
|
+
function loadUserGroupPublications(subscriptionManager) {
|
|
5
|
+
subscriptionManager.publications({
|
|
6
|
+
usergroups: {
|
|
7
|
+
function: function () {
|
|
8
|
+
return user_group_collection_1.UserGroups.find({}).sort({ name: 1 }).exec();
|
|
9
|
+
},
|
|
10
|
+
collections: ['user-groups']
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.loadUserGroupPublications = loadUserGroupPublications;
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=user-groups.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/publications/user-groups.ts"],"names":[],"mappings":";;AAAA,8EAAkE;AAElE,SAAgB,yBAAyB,CAAC,mBAAmB;IAC5D,mBAAmB,CAAC,YAAY,CAAC;QAChC,UAAU,EAAE;YACX,QAAQ,EAAE;gBACT,OAAO,kCAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,CAAC,EAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACnD,CAAC;YACD,WAAW,EAAE,CAAC,aAAa,CAAC;SAC5B;KACD,CAAC,CAAC;AACJ,CAAC;AATD,8DASC","file":"user-groups.js","sourcesContent":["import { UserGroups } from '../collections/user-group.collection';\n\nexport function loadUserGroupPublications(subscriptionManager) {\n\tsubscriptionManager.publications({\n\t\tusergroups: {\n\t\t\tfunction: () => {\n\t\t\t\treturn UserGroups.find({}).sort({name: 1}).exec();\n\t\t\t},\n\t\t\tcollections: ['user-groups']\n\t\t}\n\t});\n}"]}
|
package/server-app.js
CHANGED
|
@@ -78,24 +78,54 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
78
78
|
this._msgQueueRunning = false;
|
|
79
79
|
this.sesMail = false;
|
|
80
80
|
this.LOGGER = 'ERROR'; //ERROR / DEBUG
|
|
81
|
-
process.on('unhandledRejection', function (error, rej) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
81
|
+
process.on('unhandledRejection', function (error, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
84
|
+
case 0:
|
|
85
|
+
console.error('Unhandled Rejection at Promise', [error, rej]);
|
|
86
|
+
if (!(error['name'] === 'MissingSchemaError')) return [3 /*break*/, 2];
|
|
87
|
+
return [4 /*yield*/, this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2))];
|
|
88
|
+
case 1:
|
|
89
|
+
_a.sent();
|
|
90
|
+
process.exit(1);
|
|
91
|
+
_a.label = 2;
|
|
92
|
+
case 2:
|
|
93
|
+
this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));
|
|
94
|
+
return [2 /*return*/];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}); });
|
|
98
|
+
process.on('uncaughtException', function (error) { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
console.error(error, 'Uncaught Exception thrown');
|
|
103
|
+
return [4 /*yield*/, this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Exception - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2))];
|
|
104
|
+
case 1:
|
|
105
|
+
_a.sent();
|
|
106
|
+
process.exit(1);
|
|
107
|
+
return [2 /*return*/];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}); });
|
|
111
|
+
SegfaultHandler.registerHandler('crash.log', function (signal, address, stack) { return __awaiter(_this, void 0, void 0, function () {
|
|
112
|
+
return __generator(this, function (_a) {
|
|
113
|
+
switch (_a.label) {
|
|
114
|
+
case 0:
|
|
115
|
+
// Do what you want with the signal, address, or stack (array)
|
|
116
|
+
// This callback will execute before the signal is forwarded on.
|
|
117
|
+
console.log('Segment Fault Detected');
|
|
118
|
+
console.log('Signal', JSON.stringify(signal, null, 2));
|
|
119
|
+
console.log('Address', JSON.stringify(address, null, 2));
|
|
120
|
+
console.log('Stack', JSON.stringify(stack, null, 2));
|
|
121
|
+
return [4 /*yield*/, this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([signal, address, stack], null, 2))];
|
|
122
|
+
case 1:
|
|
123
|
+
_a.sent();
|
|
124
|
+
process.exit(1);
|
|
125
|
+
return [2 /*return*/];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}); });
|
|
99
129
|
//SegfaultHandler.causeSegfault(); // simulates a buggy native module that dereferences NULL
|
|
100
130
|
if (this.LOGGER === 'DEBUG') {
|
|
101
131
|
console.log('Starting ResolveIO Server');
|
package/server-app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/server-app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA4C;AAC5C,iCAAmC;AACnC,mCAAqC;AACrC,wCAA0C;AAC1C,kDAAoD;AACpD,mCAAqC;AACrC,8CAAgD;AAChD,8BAAgC;AAChC,kCAAoC;AACpC,8BAAgC;AAChC,kDAAoD;AAEpD,oCAA8C;AAC9C,wCAA2D;AAC3D,wCAAkD;AAGlD,+EAAmE;AAEnE,qCAAwC;AACxC,uFAA2E;AAC3E,+DAAoD;AAEpD,+BAAiC;AACjC,iEAAsD;AACtD,wDAAsD;AACtD,4DAA0D;AAC1D,wEAAsE;AACtE,8DAA4D;AAC5D,wEAAqE;AAErE,wCAAyC;AACzC,6FAAiF;AACjF,oCAA8C;AAE9C;IAqBC,6BAAY,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO;QAAxD,iBAgGC;QA9GO,cAAS,GAAG,EAAE,CAAC;QACf,qBAAgB,GAAG,KAAK,CAAC;QAC1B,YAAO,GAAG,KAAK,CAAC;QAEf,WAAM,GAAG,OAAO,CAAC,CAAC,eAAe;QAWxC,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,UAAC,KAAK,EAAE,GAAG;YAC3C,OAAO,CAAC,KAAK,CA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CAAC,CAAC;IAC9C,CAAC;IAEM,oCAAM,GAAb;QACC,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IACF,0BAAC;AAAD,CA9uBA,AA8uBC,IAAA","file":"server-app.js","sourcesContent":["import { createServer, Server } from 'http';\nimport * as express from 'express';\nimport * as mongoose from 'mongoose';\nimport * as bodyParser from 'body-parser';\nimport * as xmlParser from 'express-xml-bodyparser';\nimport * as passport from 'passport';\nimport * as passportlocal from 'passport-local';\nimport * as WebSocket from 'ws';\nimport * as jwt from 'jsonwebtoken';\nimport * as uuid from 'uuid/v4';\nimport * as SegfaultHandler from 'segfault-handler';\n\nimport { setupAuthRoutes } from './http/auth';\nimport { dateReviver, getBinarySize } from './util/common';\nimport { setupHealthRoutes } from './http/health';\n\nimport { ServerResponseModel } from './models/server-response.model';\nimport { MethodCalls } from './collections/method-call.collection';\n\nimport { Types, Query } from 'mongoose';\nimport { MethodResponses } from './collections/method-response.collection';\nimport { Logs } from './collections/log.collection';\n\nimport * as moment from 'moment';\nimport { Users } from './collections/user.collection';\nimport { CronManager } from './managers/cron.manager';\nimport { MethodManager } from './managers/method.manager';\nimport { SubscriptionManager } from './managers/subscription.manager';\nimport { SupportManager } from './managers/support.manager';\nimport { QueueMethodManager } from './managers/queue-method.manager';\nimport { ResolveIOServer } from '.';\nimport { deepCopy } from './util/common';\nimport { LogMethodLatencies } from './collections/log-method-latency.collection';\nimport { setupHomeRoutes } from './http/home';\n\nexport default class ResolveIOMainServer {\n\tprivate _app: express.Application;\n\tprivate _server: Server;\n\tprivate _port: string | number;\n\tprivate _wss;\n\tprivate _serverConfig;\n\tprivate _clientDir;\n\tprivate _msgQueue = [];\n\tprivate _msgQueueRunning = false;\n\tpublic sesMail = false;\n\n\tprivate LOGGER = 'ERROR'; //ERROR / DEBUG\n\t\n\tprivate _resolveioServer: ResolveIOServer;\n\n\tprivate _subscriptionManager: SubscriptionManager;\n\tprivate _methodManager: MethodManager;\n\tprivate _queueManager: QueueMethodManager;\n\tprivate _cronManager: CronManager;\n\tprivate _supportManager: SupportManager;\n\n\tconstructor(mainServer, serverConfig, clientDir, sesMail) {\n\t\tprocess.on('unhandledRejection', (error, rej) => {\n\t\t\tconsole.error('Unhandled Rejection at Promise', error);\n\n\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error, rej], null, 2));\n\t\t});\n\n\t\tprocess.on('uncaughtException', err => {\n\t\t\tconsole.error(err, 'Uncaught Exception thrown');\n\n\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Exception - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([err], null, 2));\n\n\t\t\tprocess.exit(1);\n\t\t});\n\n\t\tSegfaultHandler.registerHandler('crash.log', (signal, address, stack) => {\n\t\t\t// Do what you want with the signal, address, or stack (array)\n\t\t\t// This callback will execute before the signal is forwarded on.\n\n\t\t\tconsole.log('Segment Fault Detected');\n\t\t\tconsole.log('Signal', JSON.stringify(signal, null, 2));\n\t\t\tconsole.log('Address', JSON.stringify(address, null, 2));\n\t\t\tconsole.log('Stack', JSON.stringify(stack, null, 2));\n\n\t\t\tprocess.exit(1);\n\t\t});\n\n\t\t//SegfaultHandler.causeSegfault(); // simulates a buggy native module that dereferences NULL\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Starting ResolveIO Server');\n\t\t}\n\t\tthis._resolveioServer = mainServer;\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._clientDir = clientDir;\n\t\tthis.sesMail = sesMail;\n\n\t\t// Start express app\n\t\tthis._app = express();\n\n\t\t// Use body parser for http call (login)\n\t\tthis._app.use(bodyParser.json({limit: '50mb'}));\n\t\tthis._app.use(bodyParser.urlencoded({limit: '50mb', extended: true, parameterLimit: 1000000 }));\n\t\tthis._app.use(xmlParser());\n\t\t\n\t\t// Set port\n\t\tthis._port = process.env.PORT || serverConfig['PORT'];\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup ports');\n\t\t}\n\n\t\t// Create http server and websock server\n\t\tthis.createServer();\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Create server');\n\t\t}\n\t\t\n\t\t// Set CORS\n\t\tthis._app.use(function (req, res, next) {\n\n\t\t\t// Website you wish to allow to connect\n\t\t\t// res.setHeader('Access-Control-Allow-Origin', serverConfig['ROOT_URL']);\n\t\t\tres.setHeader('Access-Control-Allow-Origin', '*');\n\t\t\n\t\t\t// Request methods you wish to allow\n\t\t\t// res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');\n\t\t\tres.setHeader('Access-Control-Allow-Methods', 'GET, POST');\n\t\t\n\t\t\t// Request headers you wish to allow\n\t\t\tres.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');\n\t\t\n\t\t\t// Set to true if you need the website to include cookies in the requests sent\n\t\t\t// to the API (e.g. in case you use sessions)\n\t\t\tres.setHeader('Access-Control-Allow-Credentials', 'false');\n\t\t\n\t\t\t// Pass to next layer of middleware\n\t\t\tnext();\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup cors');\n\t\t}\n\n\t\t// Set up http login route\n\t\tsetupAuthRoutes(this, this._app, serverConfig);\n\t\tsetupHealthRoutes(this._app, serverConfig);\n\n\t\tif (serverConfig['CLIENT_NAME'] === 'ResolveIO') {\n\t\t\tsetupHomeRoutes(this, this._app, serverConfig);\n\t\t}\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup express routes');\n\t\t}\n\t}\n\n\tpublic getWS(id_ws: string) {\n\t\tlet res = null;\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tif (ws['id_socket'] === id_ws) {\n\t\t\t\tres = ws;\n\t\t\t}\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getWSList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_socket']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getWSUserList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_user']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getHTTPServer() {\n\t\treturn this._server;\n\t}\n\n\tpublic getCronManager() {\n\t\treturn this._cronManager;\n\t}\n\n\tpublic getMethodManager() {\n\t\treturn this._methodManager;\n\t}\n\n\tpublic getSubscriptionManager() {\n\t\treturn this._subscriptionManager;\n\t}\n\n\tpublic getQueueManager() {\n\t\treturn this._queueManager;\n\t}\n\n\tpublic getSupportManager() {\n\t\treturn this._supportManager;\n\t}\n\n\tprivate createServer(): void {\n\t\t// Start express server\n\t\tthis._server = createServer(this._app);\n\n\t\t// Start websocket server\n\t\t// Verify client with token before opening socket\n\t\tthis._wss = new WebSocket.Server({ \n\t\t\tserver: this._server,\n\t\t\tverifyClient: async (info, cb) => {\n\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\tconsole.log('Verify Client', info, cb);\n\t\t\t\t}\n\n\t\t\t\tlet infoData = (<string>info.req.headers['sec-websocket-protocol']).split(/,/);\n\n\t\t\t\tif (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (infoData[1]) { //app version\n\t\t\t\t\t\tlet token = infoData[0];\n\t\t\t\t\t\tif (!token) {\n\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tjwt.verify(token, this._serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tinfo.req['id_user'] = decoded['id_user'];\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tlet user = await Users.findById(decoded['id_user']).exec();\n\t\t\t\t\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user'] = user.fullname;\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user_readonly'] = user.readonly || false;\n\t\t\t\t\t\t\t\t\t\t\tcb(true);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tcb(false, 401, 'Invalid Version');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Start Mongoose (MongoDB Connection)\n\t\tthis.setUpMongoose();\n\t}\n\n\tprivate setUpMongoose() {\n\t\tthis.setUpPassport();\n\n\t\t// Enable lean by default\n\t\tlet __setOptions = Query.prototype.setOptions;\n\t\tQuery.prototype.setOptions = function(options) {\n\t\t\tif (this._mongooseOptions.lean == null && this.mongooseCollection.collectionName !== 'users') {\n\t\t\t\tthis._mongooseOptions.lean = true;\n\t\t\t}\n\n\t\t\t__setOptions.apply(this, arguments);\n\n\t\t\treturn this;\n\t\t};\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Start Managers');\n\t\t}\n\n\t\t// Start Managers\n\t\tthis._subscriptionManager = new SubscriptionManager(this, this._wss, this._serverConfig);\n\t\tthis._methodManager = new MethodManager(this, this._serverConfig, this._clientDir);\n\t\tthis._supportManager = new SupportManager(this, this._serverConfig, this._clientDir);\n\t\tthis._cronManager = new CronManager(this);\n\t\tthis._queueManager = new QueueMethodManager(this);\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('End Managers');\n\t\t}\n\n\t\tthis.listen();\n\n\t\tmongoose.set('useFindAndModify', false);\n\t\t// mongoose.set('useCreateIndexes', true);\n\t}\n\n\tprivate setUpPassport(): void {\n\t\t// Set up login passort\n\t\tthis._app.use(passport.initialize());\n\n\t\t// Start user authentication\n\t\tpassport.use(new passportlocal.Strategy(Users.authenticate()));\n\t\tpassport.serializeUser(Users.serializeUser());\n\t\tpassport.deserializeUser(Users.deserializeUser());\n\t}\n\n\n\t// Listen to port for websocket\n\tprivate listen(): void {\n\t\tthis._server.listen(this._port, () => {\n\t\t\tconsole.log('Running server on port %s', this._port);\n\t\t});\n\n\t\t// On websocket connection (already verified)\n\t\tthis._wss.on('connection', (ws, req) => {\n\n\t\t\t// Get user from token\n\t\t\tws['id_user'] = req.id_user;\n\t\t\tws['user'] = req.user;\n\t\t\tws['user_readonly'] = req.user_readonly;\n\t\t\tws['id_socket'] = uuid();\n\t\t\tws['retryCnt'] = 0;\n\n\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\tconsole.log('Connection from: ' + req.user);\n\t\t\t}\n\t\t\t\n\t\t\t// Use for keeping connection alive (ping/pong)\n\t\t\tws['isAlive'] = true;\n\t\t\tws.on('pong', () => {\n\t\t\t\tws['isAlive'] = true;\n\t\t\t\tws['pongTime'] = new Date();\n\t\t\t\tws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();\n\t\t\t\tthis._subscriptionManager.loggedInLatency(ws);\n\t\t\t});\n\n\t\t\tws['versionTimer'] = setTimeout(() => {\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t}, 10000);\n\n\t\t\t// On data received (message)\n\t\t\tws.on('message', async (message: string) => {\n\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\tconsole.log('Message from: ' + ws['user'], message);\n\t\t\t\t}\n\n\t\t\t\tlet parseErrorFound = false;\n\n\t\t\t\tlet socketData = null;\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tsocketData = JSON.parse(message, dateReviver);\n\t\t\t\t}\n\t\t\t\tcatch(e) {\n\t\t\t\t\tconsole.log('Error - JSON.parse', message);\n\t\t\t\t\t\n\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - JSON Parse Error - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([message, e]));\n\n\t\t\t\t\tparseErrorFound = true;\n\t\t\t\t}\n\n\t\t\t\tif (!parseErrorFound) {\n\t\t\t\t\tlet data = deepCopy(socketData);\n\n\t\t\t\t\tif (data[0] === 'ping') {\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send('pong', (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageRoute = data.shift();\n\t\t\t\t\tlet messageDate = data.shift();\n\t\t\t\t\tlet messageId = data.shift();\n\t\t\t\t\tlet type = data.shift();\n\n\t\t\t\t\tif (type === 'subscription') {\n\t\t\t\t\t\tlet subType = data.shift();\n\t\t\t\t\t\tlet pub = data.shift();\n\t\t\n\t\t\t\t\t\t// Subscribe\n\t\t\t\t\t\tif (subType === 'sub') {\n\t\t\t\t\t\t\tthis._subscriptionManager.subscribe(messageDate, ws, messageId, pub, ...data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Unsubscribe\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._subscriptionManager.unsubscribe(messageDate, ws, messageId, pub, ...data);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._msgQueue.splice(0, 0, {\n\t\t\t\t\t\t\tws: ws,\n\t\t\t\t\t\t\tdata: socketData\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('close', () => {\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t});\n\n\t\t\tws.on('error', error => {\n\t\t\t\tconsole.log(error);\n\t\t\t\t\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t});\n\t\t});\n\n\t\t// Keep alive timer to ping/pong\n\t\tsetInterval(() => {\n\t\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\t\tif (ws['isAlive'] === false) {\n\t\t\t\t\tws['retryCnt']++;\n\n\t\t\t\t\tif (ws['retryCnt'] >= 60) {\n\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tws['retryCnt'] = 0;\n\t\t\t\t\tws['isAlive'] = false;\n\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\tws.ping(() => {});\n\t\t\t\t}\n\t\t\t});\n\t\t}, 5000);\n\n\t\tsetInterval(async () => {\n\t\t\t// console.log(data);\n\n\t\t\tif (!this._msgQueueRunning) {\n\t\t\t\tthis._msgQueueRunning = true;\n\t\t\t\t\n\t\t\t\tfor (let i = this._msgQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\tlet msg = this._msgQueue.pop();\n\t\t\t\t\tlet data = msg.data;\n\t\t\t\t\tlet ws = msg.ws;\n\t\t\n\t\t\t\t\tlet messageRoute = data.shift();\n\t\t\t\t\tlet messageDate = data.shift();\n\t\t\t\t\tlet messageId = data.shift();\n\t\t\t\t\tlet type = data.shift();\n\t\t\n\t\t\t\t\t// Method call\n\t\t\t\t\tif (type === 'method') {\n\t\t\t\t\t\tlet method = data.shift();\n\t\t\n\t\t\t\t\t\tif (method === 'setWSAppVersion') {\n\t\t\t\t\t\t\tclearTimeout(ws['versionTimer']);\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (method === 'disconnectWSCommand') {\n\t\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t}, 5000);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (ws['user_readonly']) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet methodLatency = await LogMethodLatencies.create({\n\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t});\n\t\t\n\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion' && method !== 'getDrivers') {\n\t\t\t\t\t\t\tif (getBinarySize(JSON.stringify(data)) < 200000) {\n\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\t\ttitle: 'Client Request - Method',\n\t\t\t\t\t\t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method + ', Route: ' + messageRoute,\n\t\t\t\t\t\t\t\t\tpayload: JSON.stringify(data, null, 2),\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\t\troute: messageRoute,\n\t\t\t\t\t\t\t\t\tdata_0: data[0] ? JSON.stringify(data[0]) : null,\n\t\t\t\t\t\t\t\t\tdata_1: data[1] ? JSON.stringify(data[1]) : null,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\t\ttitle: 'Client Request - Method',\n\t\t\t\t\t\t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method + ', Route: ' + messageRoute,\n\t\t\t\t\t\t\t\t\tpayload: 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\t\troute: messageRoute,\n\t\t\t\t\t\t\t\t\tdata_0: null,\n\t\t\t\t\t\t\t\t\tdata_1: null\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\n\t\t\t\t\t\t\tlet query: any = {$and: [\n\t\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t\t]};\n\t\t\n\t\t\t\t\t\t\tif (method !== 'updateDocumentOffline' && method !== 'updateDocumentPropsOffline') {\n\t\t\t\t\t\t\t\tquery.$and.push({method: method});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tif (method === 'updateDocumentOffline') {\n\t\t\t\t\t\t\t\t\tquery.$and.push({\n\t\t\t\t\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t\t\t\t\t{method: 'updateDocument'}\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if (method === 'updateDocumentPropsOffline') {\n\t\t\t\t\t\t\t\t\tquery.$and.push({\n\t\t\t\t\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t\t\t\t\t{method: 'updateDocumentProps'}\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\t\tlet methodCall = await MethodCalls.findOne(query).exec();\n\t\t\n\t\t\t\t\t\t\tif (!methodCall) {\n\t\t\t\t\t\t\t\tawait MethodCalls.create({\n\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\t\t\t\tmessage_id: messageId,\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tdate: messageDate\n\t\t\t\t\t\t\t\t});\n\t\t\t\n\t\t\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\t\t\tif (this._methodManager._methods[method].skipQueue) {\n\t\t\t\t\t\t\t\t\t\tthis._methodManager.callMethod(methodLatency._id, ws, messageDate, messageId, method, ...data);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\tthis._queueManager.addMethodToQueue(methodLatency._id, ws['id_socket'], ws['id_user'], ws['user'], messageDate, messageId, method, data);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tconsole.log('Could not find method: ' + method);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tMethodResponses.findOne({$and: [\n\t\t\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t\t\t]}).exec((err, res) => {\n\t\t\t\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\t\t\tws.send(JSON.stringify(res.response), (error) => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('Could not find method: ' + method);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// else if (type === 'methodRetry') {\n\t\t\t\t\t// \tmethod = data.shift();\n\t\t\n\t\t\t\t\t// \tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion' && method !== 'getDrivers') {\n\t\t\t\t\t// \t\tif (getBinarySize(JSON.stringify(data)) < 200000) {\n\t\t\t\t\t// \t\t\tLogs.create({\n\t\t\t\t\t// \t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t// \t\t\t\tdate: new Date(),\n\t\t\t\t\t// \t\t\t\ttype: 'client-request',\n\t\t\t\t\t// \t\t\t\ttitle: 'Client Request - Method Retry',\n\t\t\t\t\t// \t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,\n\t\t\t\t\t// \t\t\t\tpayload: JSON.stringify(data, null, 2),\n\t\t\t\t\t// \t\t\t\tmethod: method,\n\t\t\t\t\t// \t\t\t\tuser: ws['user'],\n\t\t\t\t\t// \t\t\t\tmessageId: messageId\n\t\t\t\t\t// \t\t\t});\n\t\t\t\t\t// \t\t}\n\t\t\t\t\t// \t\telse {\n\t\t\t\t\t// \t\t\tLogs.create({\n\t\t\t\t\t// \t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t// \t\t\t\tdate: new Date(),\n\t\t\t\t\t// \t\t\t\ttype: 'client-request',\n\t\t\t\t\t// \t\t\t\ttitle: 'Client Request - Method Retry',\n\t\t\t\t\t// \t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,\n\t\t\t\t\t// \t\t\t\tpayload: 'Too Big',\n\t\t\t\t\t// \t\t\t\tmethod: method,\n\t\t\t\t\t// \t\t\t\tuser: ws['user'],\n\t\t\t\t\t// \t\t\t\tmessageId: messageId\n\t\t\t\t\t// \t\t\t});\n\t\t\t\t\t// \t\t}\n\t\t\t\t\t// \t}\n\t\t\n\t\t\t\t\t// \tMethodCalls.findOne({$and: [\n\t\t\t\t\t// \t\t{id_user: ws['id_user']}, \n\t\t\t\t\t// \t\t{message_id: messageId},\n\t\t\t\t\t// \t\t{method: method},\n\t\t\t\t\t// \t\t{date: messageDate}\n\t\t\t\t\t// \t]}).exec((err, res) => {\n\t\t\t\t\t// \t\tif (res) {\n\t\t\t\t\t// \t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t// \t\t\t\tmessageId: messageId,\n\t\t\t\t\t// \t\t\t\thasError: false,\n\t\t\t\t\t// \t\t\t\tdata: 'ACK'\n\t\t\t\t\t// \t\t\t};\n\t\t\t\t\n\t\t\t\t\t// \t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t// \t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t// \t\t\t\t\tif (error) {\n\t\t\t\t\t// \t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t// \t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t// \t\t\t\t\t}\n\t\t\t\t\t// \t\t\t\t});\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t}\n\t\t\t\t\t// \t\telse {\n\t\t\t\t\t// \t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t// \t\t\t\tmessageId: messageId,\n\t\t\t\t\t// \t\t\t\thasError: false,\n\t\t\t\t\t// \t\t\t\tdata: 'NACK'\n\t\t\t\t\t// \t\t\t};\n\t\t\t\t\n\t\t\t\t\t// \t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t// \t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t// \t\t\t\t\tif (error) {\n\t\t\t\t\t// \t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t// \t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t// \t\t\t\t\t}\n\t\t\t\t\t// \t\t\t\t});\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t}\n\t\t\t\t\t// \t});\n\t\t\t\t\t// }\n\t\t\t\t\telse if (type === 'methodResponse') {\n\t\t\t\t\t\tlet method = data.shift();\n\t\t\n\t\t\t\t\t\tMethodResponses.findOne({$and: [\n\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t]}).exec((err, res) => {\n\t\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\tws.send(JSON.stringify(res.response), (error) => {\n\t\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse if (type === 'support') {\n\t\t\t\t\t\tlet supportMethod = data.shift();\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (getBinarySize(JSON.stringify(data)) < 200000) {\n\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\ttitle: 'Client Request - Support',\n\t\t\t\t\t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Support Method: ' + supportMethod + ', Route: ' + messageRoute,\n\t\t\t\t\t\t\t\tpayload: JSON.stringify(data, null, 2),\n\t\t\t\t\t\t\t\tmethod: supportMethod,\n\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\troute: messageRoute,\n\t\t\t\t\t\t\t\tdata_0: data[0] ? JSON.stringify(data[0]) : null,\n\t\t\t\t\t\t\t\tdata_1: data[1] ? JSON.stringify(data[1]) : null,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\ttitle: 'Client Request - Support',\n\t\t\t\t\t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Support Method: ' + supportMethod + ', Route: ' + messageRoute,\n\t\t\t\t\t\t\t\tpayload: 'Too Big',\n\t\t\t\t\t\t\t\tmethod: supportMethod,\n\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\troute: messageRoute,\n\t\t\t\t\t\t\t\tdata_0: null,\n\t\t\t\t\t\t\t\tdata_1: null\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (this._supportManager._supportMethods[supportMethod]) {\n\t\t\n\t\t\t\t\t\t\tthis._supportManager.callSupportMethod(ws, messageId, supportMethod, ...data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('Could not find support method: ' + supportMethod);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis._msgQueueRunning = false;\n\t\t\t}\n\t\t}, 25);\n\t}\n\n\tpublic unsubscribeWS(ws: WebSocket) {\n\t\tthis._subscriptionManager.unsubscribeAll(ws);\n\t}\n\n\tpublic getApp() {\n\t\treturn this._app;\n\t}\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/server-app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA4C;AAC5C,iCAAmC;AACnC,mCAAqC;AACrC,wCAA0C;AAC1C,kDAAoD;AACpD,mCAAqC;AACrC,8CAAgD;AAChD,8BAAgC;AAChC,kCAAoC;AACpC,8BAAgC;AAChC,kDAAoD;AAEpD,oCAA8C;AAC9C,wCAA2D;AAC3D,wCAAkD;AAGlD,+EAAmE;AAEnE,qCAAwC;AACxC,uFAA2E;AAC3E,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AAK,CAAC;;;;;aAE/B,EAAE,EAAE,CAAC,CAAC;IACR,CAAC;IAEM,2CAAa,GAApB,UAAqB,EAAa;QACjC,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;IAEM,oCAAM,GAAb;QACC,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IACF,0BAAC;AAAD,CAtvBA,AAsvBC,IAAA","file":"server-app.js","sourcesContent":["import { createServer, Server } from 'http';\nimport * as express from 'express';\nimport * as mongoose from 'mongoose';\nimport * as bodyParser from 'body-parser';\nimport * as xmlParser from 'express-xml-bodyparser';\nimport * as passport from 'passport';\nimport * as passportlocal from 'passport-local';\nimport * as WebSocket from 'ws';\nimport * as jwt from 'jsonwebtoken';\nimport * as uuid from 'uuid/v4';\nimport * as SegfaultHandler from 'segfault-handler';\n\nimport { setupAuthRoutes } from './http/auth';\nimport { dateReviver, getBinarySize } from './util/common';\nimport { setupHealthRoutes } from './http/health';\n\nimport { ServerResponseModel } from './models/server-response.model';\nimport { MethodCalls } from './collections/method-call.collection';\n\nimport { Types, Query } from 'mongoose';\nimport { MethodResponses } from './collections/method-response.collection';\nimport { Logs } from './collections/log.collection';\n\nimport * as moment from 'moment';\nimport { Users } from './collections/user.collection';\nimport { CronManager } from './managers/cron.manager';\nimport { MethodManager } from './managers/method.manager';\nimport { SubscriptionManager } from './managers/subscription.manager';\nimport { SupportManager } from './managers/support.manager';\nimport { QueueMethodManager } from './managers/queue-method.manager';\nimport { ResolveIOServer } from '.';\nimport { deepCopy } from './util/common';\nimport { LogMethodLatencies } from './collections/log-method-latency.collection';\nimport { setupHomeRoutes } from './http/home';\n\nexport default class ResolveIOMainServer {\n\tprivate _app: express.Application;\n\tprivate _server: Server;\n\tprivate _port: string | number;\n\tprivate _wss;\n\tprivate _serverConfig;\n\tprivate _clientDir;\n\tprivate _msgQueue = [];\n\tprivate _msgQueueRunning = false;\n\tpublic sesMail = false;\n\n\tprivate LOGGER = 'ERROR'; //ERROR / DEBUG\n\t\n\tprivate _resolveioServer: ResolveIOServer;\n\n\tprivate _subscriptionManager: SubscriptionManager;\n\tprivate _methodManager: MethodManager;\n\tprivate _queueManager: QueueMethodManager;\n\tprivate _cronManager: CronManager;\n\tprivate _supportManager: SupportManager;\n\n\tconstructor(mainServer, serverConfig, clientDir, sesMail) {\n\t\tprocess.on('unhandledRejection', async (error, rej) => {\n\t\t\tconsole.error('Unhandled Rejection at Promise', [error, rej]);\n\n\t\t\tif (error['name'] === 'MissingSchemaError') {\n\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t});\n\n\t\tprocess.on('uncaughtException', async error => {\n\t\t\tconsole.error(error, 'Uncaught Exception thrown');\n\n\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Exception - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\n\t\t\tprocess.exit(1);\n\t\t});\n\n\t\tSegfaultHandler.registerHandler('crash.log', async (signal, address, stack) => {\n\t\t\t// Do what you want with the signal, address, or stack (array)\n\t\t\t// This callback will execute before the signal is forwarded on.\n\n\t\t\tconsole.log('Segment Fault Detected');\n\t\t\tconsole.log('Signal', JSON.stringify(signal, null, 2));\n\t\t\tconsole.log('Address', JSON.stringify(address, null, 2));\n\t\t\tconsole.log('Stack', JSON.stringify(stack, null, 2));\n\n\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([signal, address, stack], null, 2));\n\n\t\t\tprocess.exit(1);\n\t\t});\n\n\t\t//SegfaultHandler.causeSegfault(); // simulates a buggy native module that dereferences NULL\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Starting ResolveIO Server');\n\t\t}\n\t\tthis._resolveioServer = mainServer;\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._clientDir = clientDir;\n\t\tthis.sesMail = sesMail;\n\n\t\t// Start express app\n\t\tthis._app = express();\n\n\t\t// Use body parser for http call (login)\n\t\tthis._app.use(bodyParser.json({limit: '50mb'}));\n\t\tthis._app.use(bodyParser.urlencoded({limit: '50mb', extended: true, parameterLimit: 1000000 }));\n\t\tthis._app.use(xmlParser());\n\t\t\n\t\t// Set port\n\t\tthis._port = process.env.PORT || serverConfig['PORT'];\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup ports');\n\t\t}\n\n\t\t// Create http server and websock server\n\t\tthis.createServer();\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Create server');\n\t\t}\n\t\t\n\t\t// Set CORS\n\t\tthis._app.use(function (req, res, next) {\n\n\t\t\t// Website you wish to allow to connect\n\t\t\t// res.setHeader('Access-Control-Allow-Origin', serverConfig['ROOT_URL']);\n\t\t\tres.setHeader('Access-Control-Allow-Origin', '*');\n\t\t\n\t\t\t// Request methods you wish to allow\n\t\t\t// res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');\n\t\t\tres.setHeader('Access-Control-Allow-Methods', 'GET, POST');\n\t\t\n\t\t\t// Request headers you wish to allow\n\t\t\tres.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');\n\t\t\n\t\t\t// Set to true if you need the website to include cookies in the requests sent\n\t\t\t// to the API (e.g. in case you use sessions)\n\t\t\tres.setHeader('Access-Control-Allow-Credentials', 'false');\n\t\t\n\t\t\t// Pass to next layer of middleware\n\t\t\tnext();\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup cors');\n\t\t}\n\n\t\t// Set up http login route\n\t\tsetupAuthRoutes(this, this._app, serverConfig);\n\t\tsetupHealthRoutes(this._app, serverConfig);\n\n\t\tif (serverConfig['CLIENT_NAME'] === 'ResolveIO') {\n\t\t\tsetupHomeRoutes(this, this._app, serverConfig);\n\t\t}\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup express routes');\n\t\t}\n\t}\n\n\tpublic getWS(id_ws: string) {\n\t\tlet res = null;\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tif (ws['id_socket'] === id_ws) {\n\t\t\t\tres = ws;\n\t\t\t}\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getWSList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_socket']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getWSUserList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_user']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getHTTPServer() {\n\t\treturn this._server;\n\t}\n\n\tpublic getCronManager() {\n\t\treturn this._cronManager;\n\t}\n\n\tpublic getMethodManager() {\n\t\treturn this._methodManager;\n\t}\n\n\tpublic getSubscriptionManager() {\n\t\treturn this._subscriptionManager;\n\t}\n\n\tpublic getQueueManager() {\n\t\treturn this._queueManager;\n\t}\n\n\tpublic getSupportManager() {\n\t\treturn this._supportManager;\n\t}\n\n\tprivate createServer(): void {\n\t\t// Start express server\n\t\tthis._server = createServer(this._app);\n\n\t\t// Start websocket server\n\t\t// Verify client with token before opening socket\n\t\tthis._wss = new WebSocket.Server({ \n\t\t\tserver: this._server,\n\t\t\tverifyClient: async (info, cb) => {\n\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\tconsole.log('Verify Client', info, cb);\n\t\t\t\t}\n\n\t\t\t\tlet infoData = (<string>info.req.headers['sec-websocket-protocol']).split(/,/);\n\n\t\t\t\tif (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (infoData[1]) { //app version\n\t\t\t\t\t\tlet token = infoData[0];\n\t\t\t\t\t\tif (!token) {\n\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tjwt.verify(token, this._serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tinfo.req['id_user'] = decoded['id_user'];\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tlet user = await Users.findById(decoded['id_user']).exec();\n\t\t\t\t\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user'] = user.fullname;\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user_readonly'] = user.readonly || false;\n\t\t\t\t\t\t\t\t\t\t\tcb(true);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tcb(false, 401, 'Invalid Version');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Start Mongoose (MongoDB Connection)\n\t\tthis.setUpMongoose();\n\t}\n\n\tprivate setUpMongoose() {\n\t\tthis.setUpPassport();\n\n\t\t// Enable lean by default\n\t\tlet __setOptions = Query.prototype.setOptions;\n\t\tQuery.prototype.setOptions = function(options) {\n\t\t\tif (this._mongooseOptions.lean == null && this.mongooseCollection.collectionName !== 'users') {\n\t\t\t\tthis._mongooseOptions.lean = true;\n\t\t\t}\n\n\t\t\t__setOptions.apply(this, arguments);\n\n\t\t\treturn this;\n\t\t};\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Start Managers');\n\t\t}\n\n\t\t// Start Managers\n\t\tthis._subscriptionManager = new SubscriptionManager(this, this._wss, this._serverConfig);\n\t\tthis._methodManager = new MethodManager(this, this._serverConfig, this._clientDir);\n\t\tthis._supportManager = new SupportManager(this, this._serverConfig, this._clientDir);\n\t\tthis._cronManager = new CronManager(this);\n\t\tthis._queueManager = new QueueMethodManager(this);\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('End Managers');\n\t\t}\n\n\t\tthis.listen();\n\n\t\tmongoose.set('useFindAndModify', false);\n\t\t// mongoose.set('useCreateIndexes', true);\n\t}\n\n\tprivate setUpPassport(): void {\n\t\t// Set up login passort\n\t\tthis._app.use(passport.initialize());\n\n\t\t// Start user authentication\n\t\tpassport.use(new passportlocal.Strategy(Users.authenticate()));\n\t\tpassport.serializeUser(Users.serializeUser());\n\t\tpassport.deserializeUser(Users.deserializeUser());\n\t}\n\n\n\t// Listen to port for websocket\n\tprivate listen(): void {\n\t\tthis._server.listen(this._port, () => {\n\t\t\tconsole.log('Running server on port %s', this._port);\n\t\t});\n\n\t\t// On websocket connection (already verified)\n\t\tthis._wss.on('connection', (ws, req) => {\n\n\t\t\t// Get user from token\n\t\t\tws['id_user'] = req.id_user;\n\t\t\tws['user'] = req.user;\n\t\t\tws['user_readonly'] = req.user_readonly;\n\t\t\tws['id_socket'] = uuid();\n\t\t\tws['retryCnt'] = 0;\n\n\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\tconsole.log('Connection from: ' + req.user);\n\t\t\t}\n\t\t\t\n\t\t\t// Use for keeping connection alive (ping/pong)\n\t\t\tws['isAlive'] = true;\n\t\t\tws.on('pong', () => {\n\t\t\t\tws['isAlive'] = true;\n\t\t\t\tws['pongTime'] = new Date();\n\t\t\t\tws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();\n\t\t\t\tthis._subscriptionManager.loggedInLatency(ws);\n\t\t\t});\n\n\t\t\tws['versionTimer'] = setTimeout(() => {\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t}, 10000);\n\n\t\t\t// On data received (message)\n\t\t\tws.on('message', async (message: string) => {\n\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\tconsole.log('Message from: ' + ws['user'], message);\n\t\t\t\t}\n\n\t\t\t\tlet parseErrorFound = false;\n\n\t\t\t\tlet socketData = null;\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tsocketData = JSON.parse(message, dateReviver);\n\t\t\t\t}\n\t\t\t\tcatch(e) {\n\t\t\t\t\tconsole.log('Error - JSON.parse', message);\n\t\t\t\t\t\n\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - JSON Parse Error - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([message, e]));\n\n\t\t\t\t\tparseErrorFound = true;\n\t\t\t\t}\n\n\t\t\t\tif (!parseErrorFound) {\n\t\t\t\t\tlet data = deepCopy(socketData);\n\n\t\t\t\t\tif (data[0] === 'ping') {\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send('pong', (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageRoute = data.shift();\n\t\t\t\t\tlet messageDate = data.shift();\n\t\t\t\t\tlet messageId = data.shift();\n\t\t\t\t\tlet type = data.shift();\n\n\t\t\t\t\tif (type === 'subscription') {\n\t\t\t\t\t\tlet subType = data.shift();\n\t\t\t\t\t\tlet pub = data.shift();\n\t\t\n\t\t\t\t\t\t// Subscribe\n\t\t\t\t\t\tif (subType === 'sub') {\n\t\t\t\t\t\t\tthis._subscriptionManager.subscribe(messageDate, ws, messageId, pub, ...data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Unsubscribe\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._subscriptionManager.unsubscribe(messageDate, ws, messageId, pub, ...data);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._msgQueue.splice(0, 0, {\n\t\t\t\t\t\t\tws: ws,\n\t\t\t\t\t\t\tdata: socketData\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('close', () => {\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t});\n\n\t\t\tws.on('error', error => {\n\t\t\t\tconsole.log(error);\n\t\t\t\t\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t});\n\t\t});\n\n\t\t// Keep alive timer to ping/pong\n\t\tsetInterval(() => {\n\t\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\t\tif (ws['isAlive'] === false) {\n\t\t\t\t\tws['retryCnt']++;\n\n\t\t\t\t\tif (ws['retryCnt'] >= 60) {\n\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tws['retryCnt'] = 0;\n\t\t\t\t\tws['isAlive'] = false;\n\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\tws.ping(() => {});\n\t\t\t\t}\n\t\t\t});\n\t\t}, 5000);\n\n\t\tsetInterval(async () => {\n\t\t\t// console.log(data);\n\n\t\t\tif (!this._msgQueueRunning) {\n\t\t\t\tthis._msgQueueRunning = true;\n\t\t\t\t\n\t\t\t\tfor (let i = this._msgQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\tlet msg = this._msgQueue.pop();\n\t\t\t\t\tlet data = msg.data;\n\t\t\t\t\tlet ws = msg.ws;\n\t\t\n\t\t\t\t\tlet messageRoute = data.shift();\n\t\t\t\t\tlet messageDate = data.shift();\n\t\t\t\t\tlet messageId = data.shift();\n\t\t\t\t\tlet type = data.shift();\n\t\t\n\t\t\t\t\t// Method call\n\t\t\t\t\tif (type === 'method') {\n\t\t\t\t\t\tlet method = data.shift();\n\t\t\n\t\t\t\t\t\tif (method === 'setWSAppVersion') {\n\t\t\t\t\t\t\tclearTimeout(ws['versionTimer']);\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (method === 'disconnectWSCommand') {\n\t\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t}, 5000);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (ws['user_readonly']) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet methodLatency = await LogMethodLatencies.create({\n\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t});\n\t\t\n\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion' && method !== 'getDrivers') {\n\t\t\t\t\t\t\tif (getBinarySize(JSON.stringify(data)) < 200000) {\n\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\t\ttitle: 'Client Request - Method',\n\t\t\t\t\t\t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method + ', Route: ' + messageRoute,\n\t\t\t\t\t\t\t\t\tpayload: JSON.stringify(data, null, 2),\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\t\troute: messageRoute,\n\t\t\t\t\t\t\t\t\tdata_0: data[0] ? JSON.stringify(data[0]) : null,\n\t\t\t\t\t\t\t\t\tdata_1: data[1] ? JSON.stringify(data[1]) : null,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\t\ttitle: 'Client Request - Method',\n\t\t\t\t\t\t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method + ', Route: ' + messageRoute,\n\t\t\t\t\t\t\t\t\tpayload: 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\t\troute: messageRoute,\n\t\t\t\t\t\t\t\t\tdata_0: null,\n\t\t\t\t\t\t\t\t\tdata_1: null\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\n\t\t\t\t\t\t\tlet query: any = {$and: [\n\t\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t\t]};\n\t\t\n\t\t\t\t\t\t\tif (method !== 'updateDocumentOffline' && method !== 'updateDocumentPropsOffline') {\n\t\t\t\t\t\t\t\tquery.$and.push({method: method});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tif (method === 'updateDocumentOffline') {\n\t\t\t\t\t\t\t\t\tquery.$and.push({\n\t\t\t\t\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t\t\t\t\t{method: 'updateDocument'}\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if (method === 'updateDocumentPropsOffline') {\n\t\t\t\t\t\t\t\t\tquery.$and.push({\n\t\t\t\t\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t\t\t\t\t{method: 'updateDocumentProps'}\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\t\tlet methodCall = await MethodCalls.findOne(query).exec();\n\t\t\n\t\t\t\t\t\t\tif (!methodCall) {\n\t\t\t\t\t\t\t\tawait MethodCalls.create({\n\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\t\t\t\tmessage_id: messageId,\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tdate: messageDate\n\t\t\t\t\t\t\t\t});\n\t\t\t\n\t\t\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\t\t\tif (this._methodManager._methods[method].skipQueue) {\n\t\t\t\t\t\t\t\t\t\tthis._methodManager.callMethod(methodLatency._id, ws, messageDate, messageId, method, ...data);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\tthis._queueManager.addMethodToQueue(methodLatency._id, ws['id_socket'], ws['id_user'], ws['user'], messageDate, messageId, method, data);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tconsole.log('Could not find method: ' + method);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tMethodResponses.findOne({$and: [\n\t\t\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t\t\t]}).exec((err, res) => {\n\t\t\t\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\t\t\tws.send(JSON.stringify(res.response), (error) => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('Could not find method: ' + method);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// else if (type === 'methodRetry') {\n\t\t\t\t\t// \tmethod = data.shift();\n\t\t\n\t\t\t\t\t// \tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion' && method !== 'getDrivers') {\n\t\t\t\t\t// \t\tif (getBinarySize(JSON.stringify(data)) < 200000) {\n\t\t\t\t\t// \t\t\tLogs.create({\n\t\t\t\t\t// \t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t// \t\t\t\tdate: new Date(),\n\t\t\t\t\t// \t\t\t\ttype: 'client-request',\n\t\t\t\t\t// \t\t\t\ttitle: 'Client Request - Method Retry',\n\t\t\t\t\t// \t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,\n\t\t\t\t\t// \t\t\t\tpayload: JSON.stringify(data, null, 2),\n\t\t\t\t\t// \t\t\t\tmethod: method,\n\t\t\t\t\t// \t\t\t\tuser: ws['user'],\n\t\t\t\t\t// \t\t\t\tmessageId: messageId\n\t\t\t\t\t// \t\t\t});\n\t\t\t\t\t// \t\t}\n\t\t\t\t\t// \t\telse {\n\t\t\t\t\t// \t\t\tLogs.create({\n\t\t\t\t\t// \t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t// \t\t\t\tdate: new Date(),\n\t\t\t\t\t// \t\t\t\ttype: 'client-request',\n\t\t\t\t\t// \t\t\t\ttitle: 'Client Request - Method Retry',\n\t\t\t\t\t// \t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,\n\t\t\t\t\t// \t\t\t\tpayload: 'Too Big',\n\t\t\t\t\t// \t\t\t\tmethod: method,\n\t\t\t\t\t// \t\t\t\tuser: ws['user'],\n\t\t\t\t\t// \t\t\t\tmessageId: messageId\n\t\t\t\t\t// \t\t\t});\n\t\t\t\t\t// \t\t}\n\t\t\t\t\t// \t}\n\t\t\n\t\t\t\t\t// \tMethodCalls.findOne({$and: [\n\t\t\t\t\t// \t\t{id_user: ws['id_user']}, \n\t\t\t\t\t// \t\t{message_id: messageId},\n\t\t\t\t\t// \t\t{method: method},\n\t\t\t\t\t// \t\t{date: messageDate}\n\t\t\t\t\t// \t]}).exec((err, res) => {\n\t\t\t\t\t// \t\tif (res) {\n\t\t\t\t\t// \t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t// \t\t\t\tmessageId: messageId,\n\t\t\t\t\t// \t\t\t\thasError: false,\n\t\t\t\t\t// \t\t\t\tdata: 'ACK'\n\t\t\t\t\t// \t\t\t};\n\t\t\t\t\n\t\t\t\t\t// \t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t// \t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t// \t\t\t\t\tif (error) {\n\t\t\t\t\t// \t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t// \t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t// \t\t\t\t\t}\n\t\t\t\t\t// \t\t\t\t});\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t}\n\t\t\t\t\t// \t\telse {\n\t\t\t\t\t// \t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t// \t\t\t\tmessageId: messageId,\n\t\t\t\t\t// \t\t\t\thasError: false,\n\t\t\t\t\t// \t\t\t\tdata: 'NACK'\n\t\t\t\t\t// \t\t\t};\n\t\t\t\t\n\t\t\t\t\t// \t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t// \t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t// \t\t\t\t\tif (error) {\n\t\t\t\t\t// \t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t// \t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t// \t\t\t\t\t}\n\t\t\t\t\t// \t\t\t\t});\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t}\n\t\t\t\t\t// \t});\n\t\t\t\t\t// }\n\t\t\t\t\telse if (type === 'methodResponse') {\n\t\t\t\t\t\tlet method = data.shift();\n\t\t\n\t\t\t\t\t\tMethodResponses.findOne({$and: [\n\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t]}).exec((err, res) => {\n\t\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\tws.send(JSON.stringify(res.response), (error) => {\n\t\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse if (type === 'support') {\n\t\t\t\t\t\tlet supportMethod = data.shift();\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (getBinarySize(JSON.stringify(data)) < 200000) {\n\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\ttitle: 'Client Request - Support',\n\t\t\t\t\t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Support Method: ' + supportMethod + ', Route: ' + messageRoute,\n\t\t\t\t\t\t\t\tpayload: JSON.stringify(data, null, 2),\n\t\t\t\t\t\t\t\tmethod: supportMethod,\n\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\troute: messageRoute,\n\t\t\t\t\t\t\t\tdata_0: data[0] ? JSON.stringify(data[0]) : null,\n\t\t\t\t\t\t\t\tdata_1: data[1] ? JSON.stringify(data[1]) : null,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\ttitle: 'Client Request - Support',\n\t\t\t\t\t\t\t\tmessage: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Support Method: ' + supportMethod + ', Route: ' + messageRoute,\n\t\t\t\t\t\t\t\tpayload: 'Too Big',\n\t\t\t\t\t\t\t\tmethod: supportMethod,\n\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\troute: messageRoute,\n\t\t\t\t\t\t\t\tdata_0: null,\n\t\t\t\t\t\t\t\tdata_1: null\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (this._supportManager._supportMethods[supportMethod]) {\n\t\t\n\t\t\t\t\t\t\tthis._supportManager.callSupportMethod(ws, messageId, supportMethod, ...data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('Could not find support method: ' + supportMethod);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis._msgQueueRunning = false;\n\t\t\t}\n\t\t}, 25);\n\t}\n\n\tpublic unsubscribeWS(ws: WebSocket) {\n\t\tthis._subscriptionManager.unsubscribeAll(ws);\n\t}\n\n\tpublic getApp() {\n\t\treturn this._app;\n\t}\n}"]}
|