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