@resolveio/server-lib 9.0.34 → 9.0.35
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/client-server-app.js +48 -7
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +11 -8
- package/collections/app-status.collection.js.map +1 -1
- package/collections/app-version.collection.js +11 -8
- package/collections/app-version.collection.js.map +1 -1
- package/collections/counter.collection.js +11 -8
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +12 -9
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +11 -8
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +11 -8
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +12 -9
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +11 -8
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +11 -8
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +14 -11
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +16 -13
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +19 -16
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +12 -9
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-call.collection.js +13 -10
- package/collections/method-call.collection.js.map +1 -1
- package/collections/method-response.collection.js +13 -10
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +16 -13
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-https-inbound.collection.js +16 -13
- package/collections/monitor-https-inbound.collection.js.map +1 -1
- package/collections/monitor-https-outbound.collection.js +18 -15
- package/collections/monitor-https-outbound.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +15 -12
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +15 -12
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +11 -8
- package/collections/notification.collection.js.map +1 -1
- package/collections/queue-flag.collection.js +12 -9
- package/collections/queue-flag.collection.js.map +1 -1
- package/collections/queue-method.collection.js +12 -9
- package/collections/queue-method.collection.js.map +1 -1
- package/collections/queue-response.collection.js +12 -9
- package/collections/queue-response.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +13 -10
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +14 -11
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +14 -11
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +14 -11
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +11 -8
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +15 -12
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +25 -25
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +80 -30
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +59 -9
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +460 -344
- package/http/auth.js.map +1 -1
- package/http/health.js +5 -1
- package/http/health.js.map +1 -1
- package/http/home.js +11 -7
- package/http/home.js.map +1 -1
- package/index.js +98 -36
- package/index.js.map +1 -1
- package/managers/cron.manager.js +157 -78
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +302 -314
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +1001 -739
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +254 -171
- package/managers/monitor.manager.js.map +1 -1
- package/managers/queue-method.manager.js +166 -69
- package/managers/queue-method.manager.js.map +1 -1
- package/managers/subscription.manager.js +714 -515
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +183 -111
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +262 -156
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +180 -100
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +110 -103
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +79 -29
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +884 -819
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +5 -1
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +313 -258
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +348 -289
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +340 -341
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +657 -565
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +185 -67
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +2 -1
- package/models/app-version.model.js +2 -1
- package/models/billing-logged-in-users.model.js +2 -1
- package/models/collection-document.model.js +2 -1
- package/models/counter.model.js +2 -1
- package/models/cron-job-history.model.js +2 -1
- package/models/cron-job.model.js +2 -1
- package/models/dialog.model.js +2 -1
- package/models/email-history.model.js +2 -1
- package/models/email-verified.model.js +2 -1
- package/models/file.model.js +2 -1
- package/models/flag.model.js +2 -1
- package/models/log-method-latency.model.js +2 -1
- package/models/log-subscription.model.js +2 -1
- package/models/log.model.js +2 -1
- package/models/logged-in-users.model.js +2 -1
- package/models/method-call.model.js +2 -1
- package/models/method-response.model.js +2 -1
- package/models/method.model.js +2 -1
- package/models/monitor-cpu.model.js +2 -1
- package/models/monitor-https-inbound.model.js +2 -1
- package/models/monitor-https-outbound.model.js +2 -1
- package/models/monitor-memory.model.js +2 -1
- package/models/monitor-mongo.model.js +2 -1
- package/models/notification.model.js +2 -1
- package/models/pagination.model.js +5 -2
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +2 -1
- package/models/queue-method.model.js +2 -1
- package/models/queue-response.model.js +2 -1
- package/models/report-builder-dashboard-builder.model.js +2 -1
- package/models/report-builder-library.model.js +2 -1
- package/models/report-builder-report.model.js +2 -1
- package/models/report-builder.model.js +2 -1
- package/models/select-data-label.model.js +2 -1
- package/models/server-response.model.js +2 -1
- package/models/subscription.model.js +2 -1
- package/models/support-ticket.model.js +2 -1
- package/models/user-group.model.js +2 -1
- package/models/user-guide.model.js +2 -1
- package/models/user.model.js +2 -1
- package/package.json +1 -1
- package/public_api.js +82 -70
- package/public_api.js.map +1 -1
- package/publications/app-status.js +8 -4
- package/publications/app-status.js.map +1 -1
- package/publications/app-version.js +8 -4
- package/publications/app-version.js.map +1 -1
- package/publications/cron-jobs.js +13 -9
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +15 -11
- package/publications/files.js.map +1 -1
- package/publications/flags.js +11 -7
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +35 -31
- package/publications/logs.js.map +1 -1
- package/publications/method-calls.js +8 -4
- package/publications/method-calls.js.map +1 -1
- package/publications/method-responses.js +8 -4
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +8 -4
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +12 -8
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +66 -16
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +21 -17
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +7 -3
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +8 -4
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +8 -4
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +534 -393
- package/server-app.js.map +1 -1
- package/util/common.js +92 -55
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +134 -76
- package/util/schema-report-builder.js.map +1 -1
package/server-app.js
CHANGED
|
@@ -1,31 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
39
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
40
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
41
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
42
|
+
r[k] = a[j];
|
|
43
|
+
return r;
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
var http_1 = require("http");
|
|
47
|
+
var express = require("express");
|
|
48
|
+
var bodyParser = require("body-parser");
|
|
49
|
+
var xmlParser = require("express-xml-bodyparser");
|
|
50
|
+
var passport = require("passport");
|
|
51
|
+
var passportlocal = require("passport-local");
|
|
52
|
+
var WebSocket = require("ws");
|
|
53
|
+
var jwt = require("jsonwebtoken");
|
|
54
|
+
var uuid = require("uuid/v4");
|
|
55
|
+
var SegfaultHandler = require("segfault-handler");
|
|
56
|
+
var moment = require("moment");
|
|
57
|
+
var common_1 = require("./util/common");
|
|
58
|
+
var mongo_manager_1 = require("./managers/mongo.manager");
|
|
59
|
+
var cron_manager_1 = require("./managers/cron.manager");
|
|
60
|
+
var method_manager_1 = require("./managers/method.manager");
|
|
61
|
+
var subscription_manager_1 = require("./managers/subscription.manager");
|
|
62
|
+
var queue_method_manager_1 = require("./managers/queue-method.manager");
|
|
63
|
+
var monitor_manager_1 = require("./managers/monitor.manager");
|
|
64
|
+
var method_call_collection_1 = require("./collections/method-call.collection");
|
|
65
|
+
var method_response_collection_1 = require("./collections/method-response.collection");
|
|
66
|
+
var log_collection_1 = require("./collections/log.collection");
|
|
67
|
+
var log_method_latency_collection_1 = require("./collections/log-method-latency.collection");
|
|
68
|
+
var user_collection_1 = require("./collections/user.collection");
|
|
69
|
+
var home_1 = require("./http/home");
|
|
70
|
+
var auth_1 = require("./http/auth");
|
|
71
|
+
var health_1 = require("./http/health");
|
|
72
|
+
var ResolveIOMainServer = /** @class */ (function () {
|
|
73
|
+
function ResolveIOMainServer(mainServer, monitorAgent, serverConfig, clientRoutes, clientDir, sesMail, standardProgram) {
|
|
74
|
+
var _this = this;
|
|
29
75
|
this._msgQueue = [];
|
|
30
76
|
this._msgQueueRunning = false;
|
|
31
77
|
this.sesMail = false;
|
|
@@ -41,68 +87,105 @@ export default class ResolveIOMainServer {
|
|
|
41
87
|
this._serverStartTime = new Date();
|
|
42
88
|
this._lastErrorMsg = null;
|
|
43
89
|
if (serverConfig['ROOT_URL'] !== 'http://localhost:4200') {
|
|
44
|
-
this._monitorManager = new MonitorManager(mainServer, monitorAgent, serverConfig);
|
|
90
|
+
this._monitorManager = new monitor_manager_1.MonitorManager(mainServer, monitorAgent, serverConfig);
|
|
45
91
|
}
|
|
46
|
-
process.on('unhandledRejection',
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
92
|
+
process.on('unhandledRejection', function (error, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
93
|
+
var diffTimeSec;
|
|
94
|
+
var _this = this;
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0:
|
|
98
|
+
diffTimeSec = moment().diff(this._serverStartTime, 'seconds');
|
|
99
|
+
if (!(error && error['name'] === 'MongoError' && error['message'] === 'not master')) return [3 /*break*/, 3];
|
|
100
|
+
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 2];
|
|
101
|
+
this._lastErrorMsg = new Date();
|
|
102
|
+
setTimeout(function () {
|
|
103
|
+
_this._lastErrorMsg = null;
|
|
104
|
+
}, 60000);
|
|
105
|
+
return [4 /*yield*/, this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2))];
|
|
106
|
+
case 1:
|
|
107
|
+
_a.sent();
|
|
108
|
+
_a.label = 2;
|
|
109
|
+
case 2:
|
|
110
|
+
process.exit(1);
|
|
111
|
+
return [3 /*break*/, 7];
|
|
112
|
+
case 3:
|
|
113
|
+
if (!(error && error['name'] === 'MongoError' && error['message'] === 'not master and slaveOk=false')) return [3 /*break*/, 6];
|
|
114
|
+
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 5];
|
|
115
|
+
this._lastErrorMsg = new Date();
|
|
116
|
+
setTimeout(function () {
|
|
117
|
+
_this._lastErrorMsg = null;
|
|
118
|
+
}, 60000);
|
|
119
|
+
return [4 /*yield*/, this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2))];
|
|
120
|
+
case 4:
|
|
121
|
+
_a.sent();
|
|
122
|
+
_a.label = 5;
|
|
123
|
+
case 5:
|
|
124
|
+
process.exit(1);
|
|
125
|
+
return [3 /*break*/, 7];
|
|
126
|
+
case 6:
|
|
127
|
+
if (error) {
|
|
128
|
+
if (error['name'] !== 'StatusError' && error['message'] !== '') {
|
|
129
|
+
if (diffTimeSec > 60 && !this._lastErrorMsg) {
|
|
130
|
+
this._lastErrorMsg = new Date();
|
|
131
|
+
setTimeout(function () {
|
|
132
|
+
_this._lastErrorMsg = null;
|
|
133
|
+
}, 60000);
|
|
134
|
+
this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
_a.label = 7;
|
|
139
|
+
case 7: return [2 /*return*/];
|
|
66
140
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
141
|
+
});
|
|
142
|
+
}); });
|
|
143
|
+
process.on('uncaughtException', function (error) { return __awaiter(_this, void 0, void 0, function () {
|
|
144
|
+
var diffTimeSec;
|
|
145
|
+
var _this = this;
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
switch (_a.label) {
|
|
148
|
+
case 0:
|
|
149
|
+
console.error(error, 'Uncaught Exception thrown');
|
|
150
|
+
diffTimeSec = moment().diff(this._serverStartTime, 'seconds');
|
|
151
|
+
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 2];
|
|
72
152
|
this._lastErrorMsg = new Date();
|
|
73
|
-
setTimeout(()
|
|
74
|
-
|
|
153
|
+
setTimeout(function () {
|
|
154
|
+
_this._lastErrorMsg = null;
|
|
75
155
|
}, 60000);
|
|
76
|
-
this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled
|
|
77
|
-
|
|
156
|
+
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))];
|
|
157
|
+
case 1:
|
|
158
|
+
_a.sent();
|
|
159
|
+
_a.label = 2;
|
|
160
|
+
case 2:
|
|
161
|
+
process.exit(1);
|
|
162
|
+
return [2 /*return*/];
|
|
78
163
|
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
process.exit(1);
|
|
105
|
-
});
|
|
164
|
+
});
|
|
165
|
+
}); });
|
|
166
|
+
SegfaultHandler.registerHandler('crash.log', function (signal, address, stack) { return __awaiter(_this, void 0, void 0, function () {
|
|
167
|
+
var diffTimeSec;
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
switch (_a.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
// Do what you want with the signal, address, or stack (array)
|
|
172
|
+
// This callback will execute before the signal is forwarded on.
|
|
173
|
+
console.log('Segment Fault Detected');
|
|
174
|
+
console.log('Signal', JSON.stringify(signal, null, 2));
|
|
175
|
+
console.log('Address', JSON.stringify(address, null, 2));
|
|
176
|
+
console.log('Stack', JSON.stringify(stack, null, 2));
|
|
177
|
+
diffTimeSec = moment().diff(this._serverStartTime, 'seconds');
|
|
178
|
+
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 2];
|
|
179
|
+
return [4 /*yield*/, this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Segfault - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([signal, address, stack], null, 2))];
|
|
180
|
+
case 1:
|
|
181
|
+
_a.sent();
|
|
182
|
+
_a.label = 2;
|
|
183
|
+
case 2:
|
|
184
|
+
process.exit(1);
|
|
185
|
+
return [2 /*return*/];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}); });
|
|
106
189
|
//SegfaultHandler.causeSegfault(); // simulates a buggy native module that dereferences NULL
|
|
107
190
|
if (this.LOGGER === 'DEBUG') {
|
|
108
191
|
console.log('Starting ResolveIO Server');
|
|
@@ -110,7 +193,7 @@ export default class ResolveIOMainServer {
|
|
|
110
193
|
// Start express app
|
|
111
194
|
this._app = express();
|
|
112
195
|
// Use body parser for http call (login)
|
|
113
|
-
this._app.use(bodyParser.json({ limit: '50mb', reviver: dateReviver }));
|
|
196
|
+
this._app.use(bodyParser.json({ limit: '50mb', reviver: common_1.dateReviver }));
|
|
114
197
|
this._app.use(bodyParser.urlencoded({ limit: '50mb', extended: true, parameterLimit: 1000000 }));
|
|
115
198
|
this._app.use(xmlParser());
|
|
116
199
|
// Set port
|
|
@@ -143,151 +226,170 @@ export default class ResolveIOMainServer {
|
|
|
143
226
|
console.log('Setup cors');
|
|
144
227
|
}
|
|
145
228
|
// Set up http login route
|
|
146
|
-
setupAuthRoutes(this, this._app, serverConfig);
|
|
147
|
-
setupHealthRoutes(this._app, serverConfig);
|
|
229
|
+
auth_1.setupAuthRoutes(this, this._app, serverConfig);
|
|
230
|
+
health_1.setupHealthRoutes(this._app, serverConfig);
|
|
148
231
|
if (serverConfig['CLIENT_NAME'] === 'ResolveIO' || this.standardProgram) {
|
|
149
|
-
setupHomeRoutes(this, this._app, serverConfig);
|
|
232
|
+
home_1.setupHomeRoutes(this, this._app, serverConfig);
|
|
150
233
|
}
|
|
151
234
|
if (this.LOGGER === 'DEBUG') {
|
|
152
235
|
console.log('Setup express routes');
|
|
153
236
|
}
|
|
154
237
|
}
|
|
155
|
-
getWS(id_ws) {
|
|
156
|
-
|
|
157
|
-
this._wss.clients.forEach((ws)
|
|
238
|
+
ResolveIOMainServer.prototype.getWS = function (id_ws) {
|
|
239
|
+
var res = null;
|
|
240
|
+
this._wss.clients.forEach(function (ws) {
|
|
158
241
|
if (ws['id_socket'] === id_ws) {
|
|
159
242
|
res = ws;
|
|
160
243
|
}
|
|
161
244
|
});
|
|
162
245
|
return res;
|
|
163
|
-
}
|
|
164
|
-
getWSList() {
|
|
165
|
-
|
|
166
|
-
this._wss.clients.forEach((ws)
|
|
246
|
+
};
|
|
247
|
+
ResolveIOMainServer.prototype.getWSList = function () {
|
|
248
|
+
var res = [];
|
|
249
|
+
this._wss.clients.forEach(function (ws) {
|
|
167
250
|
res.push(ws['id_socket']);
|
|
168
251
|
});
|
|
169
252
|
return res;
|
|
170
|
-
}
|
|
171
|
-
getWSUserList() {
|
|
172
|
-
|
|
173
|
-
this._wss.clients.forEach((ws)
|
|
253
|
+
};
|
|
254
|
+
ResolveIOMainServer.prototype.getWSUserList = function () {
|
|
255
|
+
var res = [];
|
|
256
|
+
this._wss.clients.forEach(function (ws) {
|
|
174
257
|
res.push(ws['id_user']);
|
|
175
258
|
});
|
|
176
259
|
return res;
|
|
177
|
-
}
|
|
178
|
-
getHTTPServer() {
|
|
260
|
+
};
|
|
261
|
+
ResolveIOMainServer.prototype.getHTTPServer = function () {
|
|
179
262
|
return this._server;
|
|
180
|
-
}
|
|
181
|
-
getCronManager() {
|
|
263
|
+
};
|
|
264
|
+
ResolveIOMainServer.prototype.getCronManager = function () {
|
|
182
265
|
return this._cronManager;
|
|
183
|
-
}
|
|
184
|
-
getMethodManager() {
|
|
266
|
+
};
|
|
267
|
+
ResolveIOMainServer.prototype.getMethodManager = function () {
|
|
185
268
|
return this._methodManager;
|
|
186
|
-
}
|
|
187
|
-
getSubscriptionManager() {
|
|
269
|
+
};
|
|
270
|
+
ResolveIOMainServer.prototype.getSubscriptionManager = function () {
|
|
188
271
|
return this._subscriptionManager;
|
|
189
|
-
}
|
|
190
|
-
getQueueManager() {
|
|
272
|
+
};
|
|
273
|
+
ResolveIOMainServer.prototype.getQueueManager = function () {
|
|
191
274
|
return this._queueManager;
|
|
192
|
-
}
|
|
193
|
-
getMonitorManager() {
|
|
275
|
+
};
|
|
276
|
+
ResolveIOMainServer.prototype.getMonitorManager = function () {
|
|
194
277
|
return this._monitorManager;
|
|
195
|
-
}
|
|
196
|
-
createServer() {
|
|
278
|
+
};
|
|
279
|
+
ResolveIOMainServer.prototype.createServer = function () {
|
|
280
|
+
var _this = this;
|
|
197
281
|
// Start express server
|
|
198
|
-
this._server = createServer(this._app);
|
|
282
|
+
this._server = http_1.createServer(this._app);
|
|
199
283
|
this._server.keepAliveTimeout = 65000;
|
|
200
284
|
this._server.headersTimeout = 66000; // This should be bigger than `keepAliveTimeout + your server's expected response time`
|
|
201
285
|
// Start websocket server
|
|
202
286
|
// Verify client with token before opening socket
|
|
203
287
|
this._wss = new WebSocket.Server({
|
|
204
288
|
server: this._server,
|
|
205
|
-
verifyClient:
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
289
|
+
verifyClient: function (info, cb) { return __awaiter(_this, void 0, void 0, function () {
|
|
290
|
+
var infoData, token;
|
|
291
|
+
var _this = this;
|
|
292
|
+
return __generator(this, function (_a) {
|
|
293
|
+
if (this.LOGGER === 'DEBUG') {
|
|
294
|
+
console.log('Verify Client', info, cb);
|
|
295
|
+
}
|
|
296
|
+
infoData = info.req.headers['sec-websocket-protocol'].split(/,/);
|
|
297
|
+
if (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']) {
|
|
298
|
+
cb(false, 401, 'Unauthorized');
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
if (infoData[1]) { //app version
|
|
302
|
+
token = infoData[0];
|
|
303
|
+
if (!token) {
|
|
304
|
+
cb(false, 401, 'Unauthorized');
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
jwt.verify(token, this._serverConfig['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
|
|
308
|
+
var user, err_1;
|
|
309
|
+
return __generator(this, function (_a) {
|
|
310
|
+
switch (_a.label) {
|
|
311
|
+
case 0:
|
|
312
|
+
if (!err) return [3 /*break*/, 1];
|
|
313
|
+
cb(false, 401, 'Unauthorized');
|
|
314
|
+
return [3 /*break*/, 5];
|
|
315
|
+
case 1:
|
|
316
|
+
info.req['id_user'] = decoded['id_user'];
|
|
317
|
+
_a.label = 2;
|
|
318
|
+
case 2:
|
|
319
|
+
_a.trys.push([2, 4, , 5]);
|
|
320
|
+
return [4 /*yield*/, user_collection_1.Users.findById(decoded['id_user'])];
|
|
321
|
+
case 3:
|
|
322
|
+
user = _a.sent();
|
|
323
|
+
if (user) {
|
|
324
|
+
info.req['user'] = user.fullname;
|
|
325
|
+
info.req['user_readonly'] = user.readonly || false;
|
|
326
|
+
info.req['doc_user'] = user;
|
|
327
|
+
cb(true);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
cb(false);
|
|
331
|
+
}
|
|
332
|
+
return [3 /*break*/, 5];
|
|
333
|
+
case 4:
|
|
334
|
+
err_1 = _a.sent();
|
|
335
|
+
cb(false);
|
|
336
|
+
return [3 /*break*/, 5];
|
|
337
|
+
case 5: return [2 /*return*/];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}); });
|
|
341
|
+
}
|
|
218
342
|
}
|
|
219
343
|
else {
|
|
220
|
-
|
|
221
|
-
if (err) {
|
|
222
|
-
cb(false, 401, 'Unauthorized');
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
info.req['id_user'] = decoded['id_user'];
|
|
226
|
-
try {
|
|
227
|
-
let user = await Users.findById(decoded['id_user']);
|
|
228
|
-
if (user) {
|
|
229
|
-
info.req['user'] = user.fullname;
|
|
230
|
-
info.req['user_readonly'] = user.readonly || false;
|
|
231
|
-
info.req['doc_user'] = user;
|
|
232
|
-
cb(true);
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
cb(false);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
catch (err) {
|
|
239
|
-
cb(false);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
});
|
|
344
|
+
cb(false, 401, 'Invalid Version');
|
|
243
345
|
}
|
|
244
346
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
}
|
|
347
|
+
return [2 /*return*/];
|
|
348
|
+
});
|
|
349
|
+
}); }
|
|
250
350
|
});
|
|
251
351
|
// Start MongoDB Connection
|
|
252
352
|
this.setUpMongo();
|
|
253
|
-
}
|
|
254
|
-
setUpMongo() {
|
|
353
|
+
};
|
|
354
|
+
ResolveIOMainServer.prototype.setUpMongo = function () {
|
|
255
355
|
this.setUpPassport();
|
|
256
356
|
if (this.LOGGER === 'DEBUG') {
|
|
257
357
|
console.log('Start Managers');
|
|
258
358
|
}
|
|
259
359
|
// Start Managers
|
|
260
|
-
this._subscriptionManager = new SubscriptionManager(this, this._wss, this._serverConfig);
|
|
261
|
-
this._methodManager = new MethodManager(this, this._serverConfig, this._clientDir);
|
|
262
|
-
this._cronManager = new CronManager(this);
|
|
263
|
-
this._queueManager = new QueueMethodManager(this);
|
|
360
|
+
this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this._wss, this._serverConfig);
|
|
361
|
+
this._methodManager = new method_manager_1.MethodManager(this, this._serverConfig, this._clientDir);
|
|
362
|
+
this._cronManager = new cron_manager_1.CronManager(this);
|
|
363
|
+
this._queueManager = new queue_method_manager_1.QueueMethodManager(this);
|
|
264
364
|
if (this.LOGGER === 'DEBUG') {
|
|
265
365
|
console.log('End Managers');
|
|
266
366
|
}
|
|
267
367
|
this.listen();
|
|
268
|
-
}
|
|
269
|
-
setUpPassport() {
|
|
270
|
-
|
|
368
|
+
};
|
|
369
|
+
ResolveIOMainServer.prototype.setUpPassport = function () {
|
|
370
|
+
var _this = this;
|
|
371
|
+
if (user_collection_1.Users) {
|
|
271
372
|
// Set up login passort
|
|
272
373
|
this._app.use(passport.initialize());
|
|
273
374
|
// Start user authentication
|
|
274
|
-
passport.use(new passportlocal.Strategy(Users.authenticateStrategy()));
|
|
275
|
-
passport.serializeUser(Users.serializeUser());
|
|
276
|
-
passport.deserializeUser(Users.deserializeUser());
|
|
375
|
+
passport.use(new passportlocal.Strategy(user_collection_1.Users.authenticateStrategy()));
|
|
376
|
+
passport.serializeUser(user_collection_1.Users.serializeUser());
|
|
377
|
+
passport.deserializeUser(user_collection_1.Users.deserializeUser());
|
|
277
378
|
}
|
|
278
379
|
else {
|
|
279
|
-
setTimeout(()
|
|
280
|
-
|
|
380
|
+
setTimeout(function () {
|
|
381
|
+
_this.setUpPassport();
|
|
281
382
|
}, 1);
|
|
282
383
|
}
|
|
283
|
-
}
|
|
384
|
+
};
|
|
284
385
|
// Listen to port for websocket
|
|
285
|
-
listen() {
|
|
286
|
-
|
|
287
|
-
|
|
386
|
+
ResolveIOMainServer.prototype.listen = function () {
|
|
387
|
+
var _this = this;
|
|
388
|
+
this._server.listen(this._port, function () {
|
|
389
|
+
console.log('Running server on port %s', _this._port);
|
|
288
390
|
});
|
|
289
391
|
// On websocket connection (already verified)
|
|
290
|
-
this._wss.on('connection', (ws, req)
|
|
392
|
+
this._wss.on('connection', function (ws, req) {
|
|
291
393
|
// Get user from token
|
|
292
394
|
ws['id_user'] = req.id_user;
|
|
293
395
|
ws['user'] = req.user;
|
|
@@ -295,270 +397,309 @@ export default class ResolveIOMainServer {
|
|
|
295
397
|
ws['doc_user'] = req.doc_user;
|
|
296
398
|
ws['id_socket'] = uuid();
|
|
297
399
|
ws['retryCnt'] = 0;
|
|
298
|
-
if (
|
|
400
|
+
if (_this.LOGGER === 'DEBUG') {
|
|
299
401
|
console.log('Connection from: ' + req.user);
|
|
300
402
|
}
|
|
301
403
|
// Use for keeping connection alive (ping/pong)
|
|
302
404
|
ws['isAlive'] = true;
|
|
303
|
-
ws.on('pong', ()
|
|
405
|
+
ws.on('pong', function () {
|
|
304
406
|
ws['isAlive'] = true;
|
|
305
407
|
ws['pongTime'] = new Date();
|
|
306
408
|
ws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();
|
|
307
|
-
|
|
409
|
+
_this._subscriptionManager.loggedInLatency(ws);
|
|
308
410
|
});
|
|
309
|
-
ws['versionTimer'] = setTimeout(()
|
|
310
|
-
|
|
411
|
+
ws['versionTimer'] = setTimeout(function () {
|
|
412
|
+
_this.unsubscribeWS(ws);
|
|
311
413
|
}, 10000);
|
|
312
414
|
// On data received (message)
|
|
313
|
-
ws.on('message',
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
socketData = JSON.parse(message, dateReviver);
|
|
321
|
-
}
|
|
322
|
-
catch (e) {
|
|
323
|
-
console.log('Error - JSON.parse', message);
|
|
324
|
-
this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - JSON Parse Error - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([message, e]));
|
|
325
|
-
parseErrorFound = true;
|
|
326
|
-
}
|
|
327
|
-
if (!parseErrorFound) {
|
|
328
|
-
let data = deepCopy(socketData);
|
|
329
|
-
if (data[0] === 'ping') {
|
|
330
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
331
|
-
ws.send('pong', (error) => {
|
|
332
|
-
if (error) {
|
|
333
|
-
console.log('Error on WS: ', error);
|
|
334
|
-
this.unsubscribeWS(ws);
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
return;
|
|
415
|
+
ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
416
|
+
var parseErrorFound, socketData, data, messageRoute_1, messageDate, messageId, type, subType, pub;
|
|
417
|
+
var _a, _b;
|
|
418
|
+
var _this = this;
|
|
419
|
+
return __generator(this, function (_c) {
|
|
420
|
+
if (this.LOGGER === 'DEBUG') {
|
|
421
|
+
console.log('Message from: ' + ws['user'], message);
|
|
339
422
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
423
|
+
parseErrorFound = false;
|
|
424
|
+
socketData = null;
|
|
425
|
+
try {
|
|
426
|
+
socketData = JSON.parse(message, common_1.dateReviver);
|
|
343
427
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (
|
|
352
|
-
|
|
428
|
+
catch (e) {
|
|
429
|
+
console.log('Error - JSON.parse', message);
|
|
430
|
+
this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - JSON Parse Error - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([message, e]));
|
|
431
|
+
parseErrorFound = true;
|
|
432
|
+
}
|
|
433
|
+
if (!parseErrorFound) {
|
|
434
|
+
data = common_1.deepCopy(socketData);
|
|
435
|
+
if (data[0] === 'ping') {
|
|
436
|
+
if (ws && ws.readyState === ws.OPEN) {
|
|
437
|
+
ws.send('pong', function (error) {
|
|
438
|
+
if (error) {
|
|
439
|
+
console.log('Error on WS: ', error);
|
|
440
|
+
_this.unsubscribeWS(ws);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
return [2 /*return*/];
|
|
445
|
+
}
|
|
446
|
+
messageRoute_1 = data.shift();
|
|
447
|
+
if (this._clientRoutes.some(function (a) { return messageRoute_1.includes(a); }) && !ws['doc_user'].roles.groups.some(function (a) { return a.views.some(function (b) { return messageRoute_1.includes(b); }); }) && !ws['doc_user'].roles.super_admin) {
|
|
448
|
+
return [2 /*return*/];
|
|
449
|
+
}
|
|
450
|
+
messageDate = data.shift();
|
|
451
|
+
messageId = data.shift();
|
|
452
|
+
type = data.shift();
|
|
453
|
+
if (type === 'subscription') {
|
|
454
|
+
subType = data.shift();
|
|
455
|
+
pub = data.shift();
|
|
456
|
+
// Subscribe
|
|
457
|
+
if (subType === 'sub') {
|
|
458
|
+
(_a = this._subscriptionManager).subscribe.apply(_a, __spreadArrays([messageDate, ws, messageId, pub], data));
|
|
459
|
+
}
|
|
460
|
+
// Unsubscribe
|
|
461
|
+
else {
|
|
462
|
+
(_b = this._subscriptionManager).unsubscribe.apply(_b, __spreadArrays([messageDate, ws, messageId, pub], data));
|
|
463
|
+
}
|
|
353
464
|
}
|
|
354
|
-
// Unsubscribe
|
|
355
465
|
else {
|
|
356
|
-
this.
|
|
466
|
+
this._msgQueue.splice(0, 0, {
|
|
467
|
+
ws: ws,
|
|
468
|
+
data: socketData
|
|
469
|
+
});
|
|
357
470
|
}
|
|
358
471
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
}
|
|
472
|
+
return [2 /*return*/];
|
|
473
|
+
});
|
|
474
|
+
}); });
|
|
475
|
+
ws.on('close', function () {
|
|
476
|
+
_this.unsubscribeWS(ws);
|
|
366
477
|
});
|
|
367
|
-
ws.on('
|
|
368
|
-
this.unsubscribeWS(ws);
|
|
369
|
-
});
|
|
370
|
-
ws.on('error', error => {
|
|
478
|
+
ws.on('error', function (error) {
|
|
371
479
|
console.log(error);
|
|
372
|
-
|
|
480
|
+
_this.unsubscribeWS(ws);
|
|
373
481
|
});
|
|
374
482
|
});
|
|
375
483
|
// Keep alive timer to ping/pong
|
|
376
|
-
setInterval(()
|
|
377
|
-
|
|
484
|
+
setInterval(function () {
|
|
485
|
+
_this._wss.clients.forEach(function (ws) {
|
|
378
486
|
if (ws['isAlive'] === false) {
|
|
379
487
|
ws['retryCnt']++;
|
|
380
488
|
if (ws['retryCnt'] >= 60) {
|
|
381
|
-
|
|
489
|
+
_this.unsubscribeWS(ws);
|
|
382
490
|
}
|
|
383
491
|
else {
|
|
384
492
|
ws['pingTime'] = new Date();
|
|
385
|
-
ws.ping(()
|
|
493
|
+
ws.ping(function () { });
|
|
386
494
|
}
|
|
387
495
|
}
|
|
388
496
|
else {
|
|
389
497
|
ws['retryCnt'] = 0;
|
|
390
498
|
ws['isAlive'] = false;
|
|
391
499
|
ws['pingTime'] = new Date();
|
|
392
|
-
ws.ping(()
|
|
500
|
+
ws.ping(function () { });
|
|
393
501
|
}
|
|
394
502
|
});
|
|
395
503
|
}, 5000);
|
|
396
|
-
setInterval(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
if (this._methodManager._methods[method]) {
|
|
459
|
-
let query = { $and: [
|
|
460
|
-
{ id_user: ws['id_user'] },
|
|
461
|
-
{ message_id: messageId },
|
|
462
|
-
{ date: messageDate }
|
|
463
|
-
] };
|
|
464
|
-
if (method !== 'updateDocumentOffline' && method !== 'updateDocumentPropsOffline') {
|
|
465
|
-
query.$and.push({ method: method });
|
|
466
|
-
}
|
|
467
|
-
else {
|
|
468
|
-
if (method === 'updateDocumentOffline') {
|
|
469
|
-
query.$and.push({
|
|
470
|
-
$or: [
|
|
471
|
-
{ method: method },
|
|
472
|
-
{ method: 'updateDocument' }
|
|
473
|
-
]
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
else if (method === 'updateDocumentPropsOffline') {
|
|
477
|
-
query.$and.push({
|
|
478
|
-
$or: [
|
|
479
|
-
{ method: method },
|
|
480
|
-
{ method: 'updateDocumentProps' }
|
|
481
|
-
]
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
let methodCall = await MethodCalls.findOne(query);
|
|
486
|
-
if (!methodCall) {
|
|
487
|
-
MethodCalls.create({
|
|
488
|
-
_id: objectIdHexString(),
|
|
489
|
-
__v: 0,
|
|
490
|
-
id_user: ws['id_user'],
|
|
491
|
-
message_id: messageId.toString(),
|
|
492
|
-
method: method,
|
|
493
|
-
date: messageDate
|
|
494
|
-
});
|
|
495
|
-
if (this._methodManager._methods[method]) {
|
|
496
|
-
if (this._methodManager._methods[method].skipQueue) {
|
|
497
|
-
this._methodManager.callMethod(methodLatencyId, ws, messageDate, messageId, method, ...data);
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
this._queueManager.addMethodToQueue(methodLatencyId, ws['id_socket'], ws['id_user'], ws['user'], messageDate, messageId, method, data);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
else {
|
|
504
|
-
console.log('Could not find method: ' + method);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
MethodResponses.findOne({ $and: [
|
|
509
|
-
{ id_user: ws['id_user'] },
|
|
510
|
-
{ message_id: messageId.toString() },
|
|
511
|
-
{ method: method },
|
|
512
|
-
{ date: messageDate }
|
|
513
|
-
] }).then(res => {
|
|
514
|
-
if (res) {
|
|
504
|
+
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
505
|
+
var _loop_1, this_1, i;
|
|
506
|
+
var _this = this;
|
|
507
|
+
return __generator(this, function (_a) {
|
|
508
|
+
switch (_a.label) {
|
|
509
|
+
case 0:
|
|
510
|
+
if (!!this._msgQueueRunning) return [3 /*break*/, 5];
|
|
511
|
+
this._msgQueueRunning = true;
|
|
512
|
+
_loop_1 = function (i) {
|
|
513
|
+
var msg, data, ws, messageRoute, messageDate, messageId, type, method, methodLatencyId, serverRes, query, methodCall, method;
|
|
514
|
+
var _a;
|
|
515
|
+
return __generator(this, function (_b) {
|
|
516
|
+
switch (_b.label) {
|
|
517
|
+
case 0:
|
|
518
|
+
msg = this_1._msgQueue.pop();
|
|
519
|
+
data = msg.data;
|
|
520
|
+
ws = msg.ws;
|
|
521
|
+
messageRoute = data.shift();
|
|
522
|
+
messageDate = data.shift();
|
|
523
|
+
messageId = data.shift();
|
|
524
|
+
type = data.shift();
|
|
525
|
+
if (!(type === 'method')) return [3 /*break*/, 4];
|
|
526
|
+
method = data.shift();
|
|
527
|
+
if (method === 'setWSAppVersion') {
|
|
528
|
+
clearTimeout(ws['versionTimer']);
|
|
529
|
+
}
|
|
530
|
+
if (method === 'disconnectWSCommand') {
|
|
531
|
+
setTimeout(function () {
|
|
532
|
+
_this.unsubscribeWS(ws);
|
|
533
|
+
}, 1000);
|
|
534
|
+
}
|
|
535
|
+
if (ws['user_readonly']) {
|
|
536
|
+
return [2 /*return*/, "continue"];
|
|
537
|
+
}
|
|
538
|
+
methodLatencyId = mongo_manager_1.objectIdHexString();
|
|
539
|
+
log_method_latency_collection_1.LogMethodLatencies.create({
|
|
540
|
+
_id: methodLatencyId,
|
|
541
|
+
__v: 0,
|
|
542
|
+
date_start: new Date(),
|
|
543
|
+
date_end: null,
|
|
544
|
+
latency_ms: 0,
|
|
545
|
+
method: method
|
|
546
|
+
});
|
|
547
|
+
if (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') {
|
|
548
|
+
log_collection_1.Logs.create({
|
|
549
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
550
|
+
type: 'client-request',
|
|
551
|
+
collection: '',
|
|
552
|
+
id_document: '',
|
|
553
|
+
payload: common_1.getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',
|
|
554
|
+
method: method,
|
|
555
|
+
id_user: ws['id_user'],
|
|
556
|
+
user: ws['user'],
|
|
557
|
+
messageId: messageId.toString(),
|
|
558
|
+
route: messageRoute
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
serverRes = {
|
|
562
|
+
messageId: messageId,
|
|
563
|
+
hasError: false,
|
|
564
|
+
data: 'ACK'
|
|
565
|
+
};
|
|
515
566
|
if (ws && ws.readyState === ws.OPEN) {
|
|
516
|
-
ws.send(JSON.stringify(
|
|
567
|
+
ws.send(JSON.stringify(serverRes), function (error) {
|
|
517
568
|
if (error) {
|
|
518
569
|
console.log('Error on WS: ', error);
|
|
519
|
-
|
|
570
|
+
_this.unsubscribeWS(ws);
|
|
520
571
|
}
|
|
521
572
|
});
|
|
522
573
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
else if (type === 'methodResponse') {
|
|
532
|
-
let method = data.shift();
|
|
533
|
-
MethodResponses.findOne({ $and: [
|
|
534
|
-
{ id_user: ws['id_user'] },
|
|
535
|
-
{ message_id: messageId.toString() },
|
|
536
|
-
{ method: method },
|
|
537
|
-
{ date: messageDate }
|
|
538
|
-
] }).then(res => {
|
|
539
|
-
if (res) {
|
|
540
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
541
|
-
ws.send(JSON.stringify(res.response), (error) => {
|
|
542
|
-
if (error) {
|
|
543
|
-
console.log('Error on WS: ', error);
|
|
544
|
-
this.unsubscribeWS(ws);
|
|
574
|
+
if (!this_1._methodManager._methods[method]) return [3 /*break*/, 2];
|
|
575
|
+
query = { $and: [
|
|
576
|
+
{ id_user: ws['id_user'] },
|
|
577
|
+
{ message_id: messageId },
|
|
578
|
+
{ date: messageDate }
|
|
579
|
+
] };
|
|
580
|
+
if (method !== 'updateDocumentOffline' && method !== 'updateDocumentPropsOffline') {
|
|
581
|
+
query.$and.push({ method: method });
|
|
545
582
|
}
|
|
546
|
-
|
|
583
|
+
else {
|
|
584
|
+
if (method === 'updateDocumentOffline') {
|
|
585
|
+
query.$and.push({
|
|
586
|
+
$or: [
|
|
587
|
+
{ method: method },
|
|
588
|
+
{ method: 'updateDocument' }
|
|
589
|
+
]
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
else if (method === 'updateDocumentPropsOffline') {
|
|
593
|
+
query.$and.push({
|
|
594
|
+
$or: [
|
|
595
|
+
{ method: method },
|
|
596
|
+
{ method: 'updateDocumentProps' }
|
|
597
|
+
]
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return [4 /*yield*/, method_call_collection_1.MethodCalls.findOne(query)];
|
|
602
|
+
case 1:
|
|
603
|
+
methodCall = _b.sent();
|
|
604
|
+
if (!methodCall) {
|
|
605
|
+
method_call_collection_1.MethodCalls.create({
|
|
606
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
607
|
+
__v: 0,
|
|
608
|
+
id_user: ws['id_user'],
|
|
609
|
+
message_id: messageId.toString(),
|
|
610
|
+
method: method,
|
|
611
|
+
date: messageDate
|
|
612
|
+
});
|
|
613
|
+
if (this_1._methodManager._methods[method]) {
|
|
614
|
+
if (this_1._methodManager._methods[method].skipQueue) {
|
|
615
|
+
(_a = this_1._methodManager).callMethod.apply(_a, __spreadArrays([methodLatencyId, ws, messageDate, messageId, method], data));
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
this_1._queueManager.addMethodToQueue(methodLatencyId, ws['id_socket'], ws['id_user'], ws['user'], messageDate, messageId, method, data);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
console.log('Could not find method: ' + method);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
method_response_collection_1.MethodResponses.findOne({ $and: [
|
|
627
|
+
{ id_user: ws['id_user'] },
|
|
628
|
+
{ message_id: messageId.toString() },
|
|
629
|
+
{ method: method },
|
|
630
|
+
{ date: messageDate }
|
|
631
|
+
] }).then(function (res) {
|
|
632
|
+
if (res) {
|
|
633
|
+
if (ws && ws.readyState === ws.OPEN) {
|
|
634
|
+
ws.send(JSON.stringify(res.response), function (error) {
|
|
635
|
+
if (error) {
|
|
636
|
+
console.log('Error on WS: ', error);
|
|
637
|
+
_this.unsubscribeWS(ws);
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}, function (err) { });
|
|
643
|
+
}
|
|
644
|
+
return [3 /*break*/, 3];
|
|
645
|
+
case 2:
|
|
646
|
+
console.log('Could not find method: ' + method);
|
|
647
|
+
_b.label = 3;
|
|
648
|
+
case 3: return [3 /*break*/, 5];
|
|
649
|
+
case 4:
|
|
650
|
+
if (type === 'methodResponse') {
|
|
651
|
+
method = data.shift();
|
|
652
|
+
method_response_collection_1.MethodResponses.findOne({ $and: [
|
|
653
|
+
{ id_user: ws['id_user'] },
|
|
654
|
+
{ message_id: messageId.toString() },
|
|
655
|
+
{ method: method },
|
|
656
|
+
{ date: messageDate }
|
|
657
|
+
] }).then(function (res) {
|
|
658
|
+
if (res) {
|
|
659
|
+
if (ws && ws.readyState === ws.OPEN) {
|
|
660
|
+
ws.send(JSON.stringify(res.response), function (error) {
|
|
661
|
+
if (error) {
|
|
662
|
+
console.log('Error on WS: ', error);
|
|
663
|
+
_this.unsubscribeWS(ws);
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}, function (err) { });
|
|
669
|
+
}
|
|
670
|
+
_b.label = 5;
|
|
671
|
+
case 5: return [2 /*return*/];
|
|
547
672
|
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
673
|
+
});
|
|
674
|
+
};
|
|
675
|
+
this_1 = this;
|
|
676
|
+
i = this._msgQueue.length - 1;
|
|
677
|
+
_a.label = 1;
|
|
678
|
+
case 1:
|
|
679
|
+
if (!(i >= 0)) return [3 /*break*/, 4];
|
|
680
|
+
return [5 /*yield**/, _loop_1(i)];
|
|
681
|
+
case 2:
|
|
682
|
+
_a.sent();
|
|
683
|
+
_a.label = 3;
|
|
684
|
+
case 3:
|
|
685
|
+
i--;
|
|
686
|
+
return [3 /*break*/, 1];
|
|
687
|
+
case 4:
|
|
688
|
+
this._msgQueueRunning = false;
|
|
689
|
+
_a.label = 5;
|
|
690
|
+
case 5: return [2 /*return*/];
|
|
551
691
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
unsubscribeWS(ws) {
|
|
692
|
+
});
|
|
693
|
+
}); }, 10);
|
|
694
|
+
};
|
|
695
|
+
ResolveIOMainServer.prototype.unsubscribeWS = function (ws) {
|
|
557
696
|
this._subscriptionManager.unsubscribeAll(ws);
|
|
558
|
-
}
|
|
559
|
-
getApp() {
|
|
697
|
+
};
|
|
698
|
+
ResolveIOMainServer.prototype.getApp = function () {
|
|
560
699
|
return this._app;
|
|
561
|
-
}
|
|
562
|
-
|
|
700
|
+
};
|
|
701
|
+
return ResolveIOMainServer;
|
|
702
|
+
}());
|
|
703
|
+
exports.default = ResolveIOMainServer;
|
|
563
704
|
|
|
564
705
|
//# sourceMappingURL=server-app.js.map
|