@resolveio/server-lib 20.0.27 → 20.0.28
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 -47
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +1 -50
- package/collections/app-status.collection.js.map +1 -1
- package/collections/counter.collection.js +1 -53
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +1 -88
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +1 -84
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +1 -65
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +1 -60
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +1 -72
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +1 -55
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +1 -63
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +1 -67
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log-ts.collection.js +1 -77
- package/collections/log-ts.collection.js.map +1 -1
- package/collections/log.collection.js +1 -76
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +1 -64
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-response.collection.js +1 -65
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +1 -62
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +1 -74
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +1 -68
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +1 -55
- package/collections/notification.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +1 -108
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +1 -86
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +1 -148
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +1 -93
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +1 -56
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +1 -265
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +1 -101
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +1 -87
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +1 -58
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +1 -763
- package/http/auth.js.map +1 -1
- package/http/health.js +1 -11
- package/http/health.js.map +1 -1
- package/http/home.js +1 -65
- package/http/home.js.map +1 -1
- package/index.js +1 -126
- package/index.js.map +1 -1
- package/managers/cron.manager.js +1 -322
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +1 -593
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +1 -2259
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +1 -350
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +1 -1110
- package/managers/subscription.manager.js.map +1 -1
- package/managers/subscription.performance.js +1 -102
- package/managers/subscription.performance.js.map +1 -1
- package/methods/accounts.js +1 -291
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +1 -634
- package/methods/aws.js.map +1 -1
- package/methods/collections.js +1 -499
- 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 -1337
- 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 -564
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +1 -731
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +1 -859
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +1 -245
- 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/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-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-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 +6 -4
- package/public_api.js +1 -74
- package/public_api.js.map +1 -1
- package/publications/app-status.js +1 -16
- package/publications/app-status.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 -164
- package/publications/logs.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 -770
- package/server-app.js.map +1 -1
- package/util/common.js +1 -546
- 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,771 +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 (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
var http_1 = require("http");
|
|
49
|
-
var express = require("express");
|
|
50
|
-
var bodyParser = require("body-parser");
|
|
51
|
-
var xmlParser = require("express-xml-bodyparser");
|
|
52
|
-
var WebSocket = require("ws");
|
|
53
|
-
var jwt = require("jsonwebtoken");
|
|
54
|
-
// import * as SegfaultHandler from 'segfault-handler';
|
|
55
|
-
var moment = require("moment-timezone");
|
|
56
|
-
var common_1 = require("./util/common");
|
|
57
|
-
var mongo_manager_1 = require("./managers/mongo.manager");
|
|
58
|
-
var cron_manager_1 = require("./managers/cron.manager");
|
|
59
|
-
var method_manager_1 = require("./managers/method.manager");
|
|
60
|
-
var subscription_manager_1 = require("./managers/subscription.manager");
|
|
61
|
-
var monitor_manager_1 = require("./managers/monitor.manager");
|
|
62
|
-
var method_response_collection_1 = require("./collections/method-response.collection");
|
|
63
|
-
var log_collection_1 = require("./collections/log.collection");
|
|
64
|
-
var log_method_latency_collection_1 = require("./collections/log-method-latency.collection");
|
|
65
|
-
var user_collection_1 = require("./collections/user.collection");
|
|
66
|
-
var home_1 = require("./http/home");
|
|
67
|
-
var auth_1 = require("./http/auth");
|
|
68
|
-
var health_1 = require("./http/health");
|
|
69
|
-
var index_1 = require("./index");
|
|
70
|
-
var mongodb_1 = require("mongodb");
|
|
71
|
-
var ResolveIOMainServer = /** @class */ (function () {
|
|
72
|
-
function ResolveIOMainServer(mainServer, serverConfig, clientRoutes, clientDir, sesMail, standardProgram, publicProgram) {
|
|
73
|
-
if (publicProgram === void 0) { publicProgram = false; }
|
|
74
|
-
var _this = this;
|
|
75
|
-
this._offlineUpdates = [];
|
|
76
|
-
this._msgQueue = [];
|
|
77
|
-
this._msgQueueRunning = false;
|
|
78
|
-
this.sesMail = false;
|
|
79
|
-
this.standardProgram = false;
|
|
80
|
-
this.publicProgram = false;
|
|
81
|
-
this._rebootFlag = false;
|
|
82
|
-
this.LOGGER = 'ERROR'; //ERROR / DEBUG
|
|
83
|
-
this._clientRoutes = [];
|
|
84
|
-
this._lastErrorMsg = null;
|
|
85
|
-
this._debugMsgRecv = 0;
|
|
86
|
-
this._debugMsgQueue = 0;
|
|
87
|
-
this._safeShutdown = false;
|
|
88
|
-
this._serverConfig = serverConfig;
|
|
89
|
-
this._clientRoutes = clientRoutes;
|
|
90
|
-
this._clientDir = clientDir;
|
|
91
|
-
this.sesMail = sesMail;
|
|
92
|
-
this.standardProgram = standardProgram;
|
|
93
|
-
this.publicProgram = publicProgram;
|
|
94
|
-
this._serverStartTime = new Date();
|
|
95
|
-
this._lastErrorMsg = null;
|
|
96
|
-
this._monitorManager = new monitor_manager_1.MonitorManager(mainServer, serverConfig);
|
|
97
|
-
this._monitorManagerFunction = new monitor_manager_1.MonitorManagerFunction();
|
|
98
|
-
setInterval(function () {
|
|
99
|
-
if (_this._subscriptionManager.getEnableDebug()) {
|
|
100
|
-
console.log(new Date(), 'Server App', 'Msg Queue Length', _this._msgQueue.length);
|
|
101
|
-
console.log(new Date(), 'Server App', 'Msg Recv Hits', _this._debugMsgRecv);
|
|
102
|
-
console.log(new Date(), 'Server App', 'Msg Queue Hits', _this._debugMsgQueue);
|
|
103
|
-
}
|
|
104
|
-
_this._debugMsgQueue = 0;
|
|
105
|
-
_this._debugMsgRecv = 0;
|
|
106
|
-
}, 60000);
|
|
107
|
-
process.on('unhandledRejection', function (error, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
108
|
-
var diffTimeSec;
|
|
109
|
-
var _this = this;
|
|
110
|
-
return __generator(this, function (_a) {
|
|
111
|
-
switch (_a.label) {
|
|
112
|
-
case 0:
|
|
113
|
-
// Condition to filter out the MongoError with code 48 (NamespaceExists)
|
|
114
|
-
if (error && error['name'] === 'MongoError' && error['code'] === 48) {
|
|
115
|
-
return [2 /*return*/]; // Simply return without doing anything further
|
|
116
|
-
}
|
|
117
|
-
console.error(new Date(), 'Unhandled Rejection at Promise', [error, rej]);
|
|
118
|
-
diffTimeSec = moment().diff(this._serverStartTime, 'seconds');
|
|
119
|
-
if (!(error && (error['name'] === 'MongoNetworkTimeoutError' || error instanceof mongodb_1.MongoNetworkTimeoutError))) return [3 /*break*/, 3];
|
|
120
|
-
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 2];
|
|
121
|
-
this._lastErrorMsg = new Date();
|
|
122
|
-
setTimeout(function () {
|
|
123
|
-
_this._lastErrorMsg = null;
|
|
124
|
-
}, 60000);
|
|
125
|
-
// Sending email notification (using your existing method)
|
|
126
|
-
return [4 /*yield*/, this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - MongoNetworkTimeoutError - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify({
|
|
127
|
-
name: error['name'],
|
|
128
|
-
message: error['message'],
|
|
129
|
-
stack: error['stack']
|
|
130
|
-
}, null, 2))];
|
|
131
|
-
case 1:
|
|
132
|
-
// Sending email notification (using your existing method)
|
|
133
|
-
_a.sent();
|
|
134
|
-
// Exiting the process
|
|
135
|
-
process.exit(1);
|
|
136
|
-
_a.label = 2;
|
|
137
|
-
case 2: return [3 /*break*/, 10];
|
|
138
|
-
case 3:
|
|
139
|
-
if (!(error && error['name'] === 'MongoError' && error['message'] === 'not master')) return [3 /*break*/, 6];
|
|
140
|
-
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 5];
|
|
141
|
-
this._lastErrorMsg = new Date();
|
|
142
|
-
setTimeout(function () {
|
|
143
|
-
_this._lastErrorMsg = null;
|
|
144
|
-
}, 60000);
|
|
145
|
-
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))];
|
|
146
|
-
case 4:
|
|
147
|
-
_a.sent();
|
|
148
|
-
_a.label = 5;
|
|
149
|
-
case 5:
|
|
150
|
-
process.exit(1);
|
|
151
|
-
return [3 /*break*/, 10];
|
|
152
|
-
case 6:
|
|
153
|
-
if (!(error && error['name'] === 'MongoError' && error['message'] === 'not master and slaveOk=false')) return [3 /*break*/, 9];
|
|
154
|
-
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 8];
|
|
155
|
-
this._lastErrorMsg = new Date();
|
|
156
|
-
setTimeout(function () {
|
|
157
|
-
_this._lastErrorMsg = null;
|
|
158
|
-
}, 60000);
|
|
159
|
-
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))];
|
|
160
|
-
case 7:
|
|
161
|
-
_a.sent();
|
|
162
|
-
_a.label = 8;
|
|
163
|
-
case 8:
|
|
164
|
-
process.exit(1);
|
|
165
|
-
return [3 /*break*/, 10];
|
|
166
|
-
case 9:
|
|
167
|
-
if (error) {
|
|
168
|
-
if (error['name'] !== 'StatusError' && error['message'] !== '') {
|
|
169
|
-
if (diffTimeSec > 60 && !this._lastErrorMsg) {
|
|
170
|
-
this._lastErrorMsg = new Date();
|
|
171
|
-
setTimeout(function () {
|
|
172
|
-
_this._lastErrorMsg = null;
|
|
173
|
-
}, 60000);
|
|
174
|
-
this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
_a.label = 10;
|
|
179
|
-
case 10: return [2 /*return*/];
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}); });
|
|
183
|
-
process.on('uncaughtException', function (error) { return __awaiter(_this, void 0, void 0, function () {
|
|
184
|
-
var diffTimeSec;
|
|
185
|
-
var _this = this;
|
|
186
|
-
return __generator(this, function (_a) {
|
|
187
|
-
switch (_a.label) {
|
|
188
|
-
case 0:
|
|
189
|
-
console.error(error, 'Uncaught Exception thrown');
|
|
190
|
-
diffTimeSec = moment().diff(this._serverStartTime, 'seconds');
|
|
191
|
-
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 2];
|
|
192
|
-
this._lastErrorMsg = new Date();
|
|
193
|
-
setTimeout(function () {
|
|
194
|
-
_this._lastErrorMsg = null;
|
|
195
|
-
}, 60000);
|
|
196
|
-
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))];
|
|
197
|
-
case 1:
|
|
198
|
-
_a.sent();
|
|
199
|
-
_a.label = 2;
|
|
200
|
-
case 2: return [2 /*return*/];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}); });
|
|
204
|
-
//PM2 wants to reboot/restart
|
|
205
|
-
process.on('SIGINT', function () {
|
|
206
|
-
_this._rebootFlag = true;
|
|
207
|
-
_this._serverHTTP.close();
|
|
208
|
-
_this.safeShutdown();
|
|
209
|
-
});
|
|
210
|
-
process.on('SIGTERM', function () {
|
|
211
|
-
_this._rebootFlag = true;
|
|
212
|
-
_this._serverHTTP.close();
|
|
213
|
-
_this.safeShutdown();
|
|
214
|
-
});
|
|
215
|
-
process.on('SIGQUIT', function () {
|
|
216
|
-
_this._rebootFlag = true;
|
|
217
|
-
_this._serverHTTP.close();
|
|
218
|
-
_this.safeShutdown();
|
|
219
|
-
});
|
|
220
|
-
if (this.LOGGER === 'DEBUG') {
|
|
221
|
-
console.log('Starting ResolveIO Server');
|
|
222
|
-
}
|
|
223
|
-
// Start express app
|
|
224
|
-
this._app = express();
|
|
225
|
-
// Use body parser for http call (login)
|
|
226
|
-
this._app.use(bodyParser.json({ limit: '50mb', reviver: common_1.dateReviver }));
|
|
227
|
-
this._app.use(bodyParser.urlencoded({ limit: '50mb', extended: true, parameterLimit: 1000000 }));
|
|
228
|
-
this._app.use(xmlParser());
|
|
229
|
-
// Set port
|
|
230
|
-
this._portHTTP = process.env.PORT_HTTP || serverConfig['PORT_HTTP'] || 8080;
|
|
231
|
-
this._portWSS = process.env.PORT_WSS || serverConfig['PORT_WSS'] || 8081;
|
|
232
|
-
if (this.LOGGER === 'DEBUG') {
|
|
233
|
-
console.log('Setup ports');
|
|
234
|
-
}
|
|
235
|
-
// Create http server and websock server
|
|
236
|
-
this.createServer();
|
|
237
|
-
if (this.LOGGER === 'DEBUG') {
|
|
238
|
-
console.log('Create server');
|
|
239
|
-
}
|
|
240
|
-
// Set CORS
|
|
241
|
-
this._app.use(function (req, res, next) {
|
|
242
|
-
// Website you wish to allow to connect
|
|
243
|
-
// res.setHeader('Access-Control-Allow-Origin', serverConfig['ROOT_URL']);
|
|
244
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
245
|
-
// Request methods you wish to allow
|
|
246
|
-
// res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
|
247
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
|
|
248
|
-
// Request headers you wish to allow
|
|
249
|
-
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
|
|
250
|
-
// Set to true if you need the website to include cookies in the requests sent
|
|
251
|
-
// to the API (e.g. in case you use sessions)
|
|
252
|
-
res.setHeader('Access-Control-Allow-Credentials', 'false');
|
|
253
|
-
// Pass to next layer of middleware
|
|
254
|
-
next();
|
|
255
|
-
});
|
|
256
|
-
if (this.LOGGER === 'DEBUG') {
|
|
257
|
-
console.log('Setup cors');
|
|
258
|
-
}
|
|
259
|
-
// Set up http login route
|
|
260
|
-
(0, auth_1.setupAuthRoutes)(this, this._app, serverConfig);
|
|
261
|
-
(0, health_1.setupHealthRoutes)(this._app, serverConfig);
|
|
262
|
-
if (serverConfig['CLIENT_NAME'] === 'ResolveIO' || this.standardProgram) {
|
|
263
|
-
(0, home_1.setupHomeRoutes)(this, this._app, serverConfig);
|
|
264
|
-
}
|
|
265
|
-
if (this.LOGGER === 'DEBUG') {
|
|
266
|
-
console.log('Setup express routes');
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
ResolveIOMainServer.prototype.safeShutdown = function () {
|
|
270
|
-
var _this = this;
|
|
271
|
-
if (!this._safeShutdown) {
|
|
272
|
-
console.log(new Date(), 'Safe Shutdown Command Received');
|
|
273
|
-
}
|
|
274
|
-
if (!this._monitorManagerFunction.getActiveMonitorFunctions().length &&
|
|
275
|
-
// (!this._monitorManagerFunction.getLastCompletedMonitorFunction() ||
|
|
276
|
-
// Date.now() >= this._monitorManagerFunction.getLastCompletedMonitorFunction().endTime.getTime() + 1500) &&
|
|
277
|
-
!this._msgQueue.length &&
|
|
278
|
-
!this._msgQueueRunning &&
|
|
279
|
-
!this._offlineUpdates.length) {
|
|
280
|
-
index_1.ResolveIOServer.getMongoConnection().close(false).then(function () {
|
|
281
|
-
console.log(new Date(), 'Safe Exit Complete, Process Exit');
|
|
282
|
-
process.exit(0);
|
|
283
|
-
}, function () { process.exit(1); });
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
if (!this._safeShutdown) {
|
|
287
|
-
this._safeShutdown = true;
|
|
288
|
-
setTimeout(function () {
|
|
289
|
-
_this._safeShutdown = false;
|
|
290
|
-
}, 1000);
|
|
291
|
-
console.log(new Date(), 'Safe Exit In Progress', this._monitorManagerFunction.getActiveMonitorFunctions().length,
|
|
292
|
-
// this._monitorManagerFunction.getLastCompletedMonitorFunction() ? this._monitorManagerFunction.getLastCompletedMonitorFunction().endTime : '',
|
|
293
|
-
this._msgQueue.length, this._msgQueueRunning, this._offlineUpdates.length);
|
|
294
|
-
}
|
|
295
|
-
setImmediate(function () {
|
|
296
|
-
_this.safeShutdown();
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
ResolveIOMainServer.prototype.getWS = function (id_ws) {
|
|
301
|
-
return Array.from(this._serverWSS.clients).filter(function (a) { return a['id_socket'] === id_ws; })[0];
|
|
302
|
-
};
|
|
303
|
-
ResolveIOMainServer.prototype.getWSList = function () {
|
|
304
|
-
var res = [];
|
|
305
|
-
this._serverWSS.clients.forEach(function (ws) {
|
|
306
|
-
res.push(ws['id_socket']);
|
|
307
|
-
});
|
|
308
|
-
return res;
|
|
309
|
-
};
|
|
310
|
-
ResolveIOMainServer.prototype.getWSUserList = function () {
|
|
311
|
-
var res = [];
|
|
312
|
-
this._serverWSS.clients.forEach(function (ws) {
|
|
313
|
-
res.push(ws['id_user']);
|
|
314
|
-
});
|
|
315
|
-
return res;
|
|
316
|
-
};
|
|
317
|
-
ResolveIOMainServer.prototype.getHTTPServer = function () {
|
|
318
|
-
return this._serverHTTP;
|
|
319
|
-
};
|
|
320
|
-
ResolveIOMainServer.prototype.getCronManager = function () {
|
|
321
|
-
return this._cronManager;
|
|
322
|
-
};
|
|
323
|
-
ResolveIOMainServer.prototype.getMethodManager = function () {
|
|
324
|
-
return this._methodManager;
|
|
325
|
-
};
|
|
326
|
-
ResolveIOMainServer.prototype.getSubscriptionManager = function () {
|
|
327
|
-
return this._subscriptionManager;
|
|
328
|
-
};
|
|
329
|
-
ResolveIOMainServer.prototype.getMonitorManager = function () {
|
|
330
|
-
return this._monitorManager;
|
|
331
|
-
};
|
|
332
|
-
ResolveIOMainServer.prototype.getRebootFlag = function () {
|
|
333
|
-
return this._rebootFlag;
|
|
334
|
-
};
|
|
335
|
-
ResolveIOMainServer.prototype.createServer = function () {
|
|
336
|
-
var _this = this;
|
|
337
|
-
// Start express server
|
|
338
|
-
this._serverHTTP = (0, http_1.createServer)(this._app);
|
|
339
|
-
this._serverHTTP.keepAliveTimeout = 65000;
|
|
340
|
-
this._serverHTTP.headersTimeout = 66000; // This should be bigger than `keepAliveTimeout + your server's expected response time`
|
|
341
|
-
// Start websocket server
|
|
342
|
-
// Verify client with token before opening socket
|
|
343
|
-
this._serverWSS = new WebSocket.Server({
|
|
344
|
-
port: this._portWSS,
|
|
345
|
-
verifyClient: this.publicProgram ? null : function (info, cb) { return __awaiter(_this, void 0, void 0, function () {
|
|
346
|
-
var infoData, token;
|
|
347
|
-
var _this = this;
|
|
348
|
-
return __generator(this, function (_a) {
|
|
349
|
-
if (this._rebootFlag) {
|
|
350
|
-
cb(false, 409, 'Unable To Process');
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
if (this.LOGGER === 'DEBUG') {
|
|
354
|
-
console.log('Verify Client', info, cb);
|
|
355
|
-
}
|
|
356
|
-
infoData = info.req.headers['sec-websocket-protocol'].split(/,/);
|
|
357
|
-
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']) {
|
|
358
|
-
cb(false, 401, 'Unauthorized');
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
token = infoData[0];
|
|
362
|
-
if (!token) {
|
|
363
|
-
cb(false, 401, 'Unauthorized');
|
|
364
|
-
}
|
|
365
|
-
else {
|
|
366
|
-
jwt.verify(token, this._serverConfig['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
|
|
367
|
-
var user, err_1;
|
|
368
|
-
return __generator(this, function (_a) {
|
|
369
|
-
switch (_a.label) {
|
|
370
|
-
case 0:
|
|
371
|
-
if (!err) return [3 /*break*/, 1];
|
|
372
|
-
cb(false, 401, 'Unauthorized');
|
|
373
|
-
return [3 /*break*/, 5];
|
|
374
|
-
case 1:
|
|
375
|
-
info.req['id_user'] = decoded['id_user'];
|
|
376
|
-
_a.label = 2;
|
|
377
|
-
case 2:
|
|
378
|
-
_a.trys.push([2, 4, , 5]);
|
|
379
|
-
return [4 /*yield*/, user_collection_1.Users.findById(decoded['id_user'])];
|
|
380
|
-
case 3:
|
|
381
|
-
user = _a.sent();
|
|
382
|
-
if (user) {
|
|
383
|
-
info.req['user'] = user.fullname;
|
|
384
|
-
info.req['user_readonly'] = user.readonly || false;
|
|
385
|
-
info.req['doc_user'] = user;
|
|
386
|
-
cb(true);
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
cb(false);
|
|
390
|
-
}
|
|
391
|
-
return [3 /*break*/, 5];
|
|
392
|
-
case 4:
|
|
393
|
-
err_1 = _a.sent();
|
|
394
|
-
cb(false);
|
|
395
|
-
return [3 /*break*/, 5];
|
|
396
|
-
case 5: return [2 /*return*/];
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
}); });
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return [2 /*return*/];
|
|
404
|
-
});
|
|
405
|
-
}); }
|
|
406
|
-
});
|
|
407
|
-
// Start MongoDB Connection
|
|
408
|
-
this.setUpMongo();
|
|
409
|
-
};
|
|
410
|
-
ResolveIOMainServer.prototype.setUpMongo = function () {
|
|
411
|
-
if (this.LOGGER === 'DEBUG') {
|
|
412
|
-
console.log('Start Managers');
|
|
413
|
-
}
|
|
414
|
-
// Start Managers
|
|
415
|
-
this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this._serverWSS, this._serverConfig, this._monitorManagerFunction);
|
|
416
|
-
this._methodManager = new method_manager_1.MethodManager(this, this._serverConfig, this._clientDir, this._monitorManagerFunction);
|
|
417
|
-
this._cronManager = new cron_manager_1.CronManager(this);
|
|
418
|
-
if (this.LOGGER === 'DEBUG') {
|
|
419
|
-
console.log('End Managers');
|
|
420
|
-
}
|
|
421
|
-
this.listen();
|
|
422
|
-
};
|
|
423
|
-
// Listen to port for websocket
|
|
424
|
-
ResolveIOMainServer.prototype.listen = function () {
|
|
425
|
-
var _this = this;
|
|
426
|
-
this._serverHTTP.listen(this._portHTTP, function () {
|
|
427
|
-
console.log('Running server on port %s', _this._portHTTP);
|
|
428
|
-
});
|
|
429
|
-
this._serverWSS.on('listening', function () {
|
|
430
|
-
console.log('Running server on port %s', _this._portWSS);
|
|
431
|
-
});
|
|
432
|
-
// On websocket connection (already verified)
|
|
433
|
-
this._serverWSS.on('connection', function (ws, req) {
|
|
434
|
-
if (!_this.publicProgram) {
|
|
435
|
-
// Get user from token
|
|
436
|
-
ws['id_user'] = req['id_user'];
|
|
437
|
-
ws['user'] = req['user'];
|
|
438
|
-
ws['user_readonly'] = req['user_readonly'];
|
|
439
|
-
ws['doc_user'] = req['doc_user'];
|
|
440
|
-
if (ws['user'] !== 'Admin' && _this._serverConfig['CLIENT_NAME'] !== 'ResolveIO') {
|
|
441
|
-
_this.getMethodManager().callMethodInternal.call(_this.getMethodManager(), 'supportCreateBillingUser', {
|
|
442
|
-
id_user: ws['id_user'],
|
|
443
|
-
user: ws['user'],
|
|
444
|
-
date: new Date(),
|
|
445
|
-
client: index_1.ResolveIOServer.getClientName()
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
ws['id_socket'] = (0, mongo_manager_1.objectIdHexString)();
|
|
450
|
-
ws['retryCnt'] = 0;
|
|
451
|
-
_this._subscriptionManager.createLoggedInUser(ws['id_socket']).then(function () {
|
|
452
|
-
setTimeout(function () {
|
|
453
|
-
ws['pingTime'] = new Date();
|
|
454
|
-
ws.ping(function () { });
|
|
455
|
-
}, 5000);
|
|
456
|
-
});
|
|
457
|
-
if (_this.LOGGER === 'DEBUG') {
|
|
458
|
-
console.log('Connection from: ' + req['user']);
|
|
459
|
-
}
|
|
460
|
-
// Use for keeping connection alive (ping/pong)
|
|
461
|
-
ws['isAlive'] = true;
|
|
462
|
-
ws.on('pong', function () {
|
|
463
|
-
ws['isAlive'] = true;
|
|
464
|
-
ws['pongTime'] = new Date();
|
|
465
|
-
ws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();
|
|
466
|
-
_this._subscriptionManager.loggedInLatency(ws);
|
|
467
|
-
})
|
|
468
|
-
.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
469
|
-
var parseErrorFound, socketData, messageRoute_1, messageDate, messageId, type, subType, pub, serverRes, offlineUpdates, i, update, data, serverResMethod, updateRoute, updateDate, updateMessageId, updateType, method, methodLatencyId, err_2;
|
|
470
|
-
var _a;
|
|
471
|
-
var _this = this;
|
|
472
|
-
return __generator(this, function (_b) {
|
|
473
|
-
switch (_b.label) {
|
|
474
|
-
case 0:
|
|
475
|
-
if (this.LOGGER === 'DEBUG') {
|
|
476
|
-
console.log('Message from: ' + ws['user'], message);
|
|
477
|
-
}
|
|
478
|
-
this._debugMsgRecv += 1;
|
|
479
|
-
parseErrorFound = false;
|
|
480
|
-
socketData = [];
|
|
481
|
-
try {
|
|
482
|
-
socketData = JSON.parse(message, common_1.dateReviver);
|
|
483
|
-
}
|
|
484
|
-
catch (e) {
|
|
485
|
-
console.log('Error - JSON.parse', message);
|
|
486
|
-
this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - JSON Parse Error - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([message, e]));
|
|
487
|
-
parseErrorFound = true;
|
|
488
|
-
}
|
|
489
|
-
if (!!parseErrorFound) return [3 /*break*/, 11];
|
|
490
|
-
if (socketData[0] === 'ping') {
|
|
491
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
492
|
-
ws.send('pong', function (error) {
|
|
493
|
-
if (error) {
|
|
494
|
-
if (_this._subscriptionManager.getEnableDebug()) {
|
|
495
|
-
console.log(new Date(), 'Server App', 'Error WS Pong');
|
|
496
|
-
}
|
|
497
|
-
_this.unsubscribeWS(ws);
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
return [2 /*return*/];
|
|
502
|
-
}
|
|
503
|
-
messageRoute_1 = socketData[0];
|
|
504
|
-
if (!this.publicProgram && 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) || b.includes(messageRoute_1); }); }) && !ws['doc_user'].roles.super_admin) {
|
|
505
|
-
return [2 /*return*/];
|
|
506
|
-
}
|
|
507
|
-
messageDate = socketData[1];
|
|
508
|
-
messageId = socketData[2];
|
|
509
|
-
type = socketData[3];
|
|
510
|
-
if (!(type === 'subscription')) return [3 /*break*/, 1];
|
|
511
|
-
subType = socketData[4];
|
|
512
|
-
pub = socketData[5];
|
|
513
|
-
// Subscribe
|
|
514
|
-
if (subType === 'sub') {
|
|
515
|
-
this._subscriptionManager.subscribe(messageRoute_1, messageDate, ws, messageId, pub, socketData.slice(6));
|
|
516
|
-
}
|
|
517
|
-
// Unsubscribe
|
|
518
|
-
else {
|
|
519
|
-
this._subscriptionManager.unsubscribe(messageRoute_1, messageDate, ws, messageId, pub, socketData.slice(6));
|
|
520
|
-
}
|
|
521
|
-
return [3 /*break*/, 11];
|
|
522
|
-
case 1:
|
|
523
|
-
if (!(!this.publicProgram && type === 'offline')) return [3 /*break*/, 10];
|
|
524
|
-
serverRes = {
|
|
525
|
-
messageId: messageId,
|
|
526
|
-
hasError: false,
|
|
527
|
-
data: 'ACK'
|
|
528
|
-
};
|
|
529
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
530
|
-
ws.send(JSON.stringify(serverRes), function (error) {
|
|
531
|
-
if (error) {
|
|
532
|
-
if (_this._subscriptionManager.getEnableDebug()) {
|
|
533
|
-
console.log(new Date(), 'Server App', 'Error WS Offline Ack Main');
|
|
534
|
-
}
|
|
535
|
-
_this.unsubscribeWS(ws);
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
this._offlineUpdates.push(ws);
|
|
540
|
-
offlineUpdates = socketData[4];
|
|
541
|
-
i = 0;
|
|
542
|
-
_b.label = 2;
|
|
543
|
-
case 2:
|
|
544
|
-
if (!(i < offlineUpdates.length)) return [3 /*break*/, 9];
|
|
545
|
-
update = offlineUpdates[i];
|
|
546
|
-
data = update.data;
|
|
547
|
-
serverResMethod = {
|
|
548
|
-
messageId: update.data[2],
|
|
549
|
-
hasError: false,
|
|
550
|
-
data: 'ACK'
|
|
551
|
-
};
|
|
552
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
553
|
-
ws.send(JSON.stringify(serverResMethod), function (error) {
|
|
554
|
-
if (error) {
|
|
555
|
-
if (_this._subscriptionManager.getEnableDebug()) {
|
|
556
|
-
console.log(new Date(), 'Server App', 'Error WS Offline Ack Each');
|
|
557
|
-
}
|
|
558
|
-
_this.unsubscribeWS(ws);
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
updateRoute = data.shift();
|
|
563
|
-
updateDate = data.shift();
|
|
564
|
-
updateMessageId = data.shift();
|
|
565
|
-
updateType = data.shift();
|
|
566
|
-
method = data.shift();
|
|
567
|
-
methodLatencyId = (0, mongo_manager_1.objectIdHexString)();
|
|
568
|
-
log_method_latency_collection_1.LogMethodLatencies.create({
|
|
569
|
-
_id: methodLatencyId,
|
|
570
|
-
__v: 0,
|
|
571
|
-
date_start: new Date(),
|
|
572
|
-
date_end: null,
|
|
573
|
-
latency_ms: 0,
|
|
574
|
-
method: method
|
|
575
|
-
});
|
|
576
|
-
if (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers' && method !== 'processAirdropDistribution') {
|
|
577
|
-
log_collection_1.Logs.insertOne({
|
|
578
|
-
_id: (0, mongo_manager_1.objectIdHexString)(),
|
|
579
|
-
type: 'client-request',
|
|
580
|
-
collection: '',
|
|
581
|
-
id_document: '',
|
|
582
|
-
payload: (0, common_1.getBinarySize)(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',
|
|
583
|
-
method: method,
|
|
584
|
-
id_user: ws['id_user'] || '',
|
|
585
|
-
user: ws['user'] || '',
|
|
586
|
-
messageId: messageId,
|
|
587
|
-
route: messageRoute_1
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
if (!this._methodManager._methods[method]) return [3 /*break*/, 7];
|
|
591
|
-
_b.label = 3;
|
|
592
|
-
case 3:
|
|
593
|
-
_b.trys.push([3, 5, , 6]);
|
|
594
|
-
return [4 /*yield*/, (_a = this._methodManager.callMethodInternal).call.apply(_a, __spreadArray([Object.assign({}, this._methodManager, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] }), method], data, false))];
|
|
595
|
-
case 4:
|
|
596
|
-
_b.sent();
|
|
597
|
-
return [3 /*break*/, 6];
|
|
598
|
-
case 5:
|
|
599
|
-
err_2 = _b.sent();
|
|
600
|
-
console.log(new Date(), 'Offline Error', JSON.stringify(err_2, null, 2));
|
|
601
|
-
return [3 /*break*/, 6];
|
|
602
|
-
case 6:
|
|
603
|
-
if (method === 'updateDocumentOffline' || method === 'updateDocumentPropsOffline') {
|
|
604
|
-
index_1.ResolveIOServer.getMongoManager().invalidateQueryCache(data[0]);
|
|
605
|
-
}
|
|
606
|
-
return [3 /*break*/, 8];
|
|
607
|
-
case 7:
|
|
608
|
-
console.log('Offline - Could not find method: ' + method);
|
|
609
|
-
_b.label = 8;
|
|
610
|
-
case 8:
|
|
611
|
-
i++;
|
|
612
|
-
return [3 /*break*/, 2];
|
|
613
|
-
case 9:
|
|
614
|
-
this._offlineUpdates.splice(this._offlineUpdates.map(function (a) { return a['id_socket']; }).indexOf(ws['id_socket']), 1);
|
|
615
|
-
return [3 /*break*/, 11];
|
|
616
|
-
case 10:
|
|
617
|
-
this._msgQueue.splice(0, 0, {
|
|
618
|
-
ws: ws,
|
|
619
|
-
data: socketData
|
|
620
|
-
});
|
|
621
|
-
_b.label = 11;
|
|
622
|
-
case 11: return [2 /*return*/];
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
}); })
|
|
626
|
-
.on('end', function () {
|
|
627
|
-
_this.unsubscribeWS(ws);
|
|
628
|
-
if (_this._subscriptionManager.getEnableDebug()) {
|
|
629
|
-
console.log(new Date(), 'Server App', 'WS End');
|
|
630
|
-
}
|
|
631
|
-
})
|
|
632
|
-
.on('close', function () {
|
|
633
|
-
_this.unsubscribeWS(ws);
|
|
634
|
-
if (_this._subscriptionManager.getEnableDebug()) {
|
|
635
|
-
console.log(new Date(), 'Server App', 'WS Close');
|
|
636
|
-
}
|
|
637
|
-
})
|
|
638
|
-
.on('error', function (error) {
|
|
639
|
-
_this.unsubscribeWS(ws);
|
|
640
|
-
if (_this._subscriptionManager.getEnableDebug()) {
|
|
641
|
-
console.log(new Date(), ws['user'], ws['id_socket'], 'WS Error');
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
});
|
|
645
|
-
// Keep alive timer to ping/pong
|
|
646
|
-
setInterval(function () {
|
|
647
|
-
_this._serverWSS.clients.forEach(function (ws) {
|
|
648
|
-
if (ws['pingTime'] && Date.now() - ws['pingTime'].getTime() >= 20000) {
|
|
649
|
-
if (ws['isAlive'] === false) {
|
|
650
|
-
ws['retryCnt']++;
|
|
651
|
-
if (ws['retryCnt'] >= 3) {
|
|
652
|
-
_this.unsubscribeWS(ws);
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
ws['pingTime'] = new Date();
|
|
656
|
-
ws.ping(function () { });
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
else {
|
|
660
|
-
ws['retryCnt'] = 0;
|
|
661
|
-
ws['isAlive'] = false;
|
|
662
|
-
ws['pingTime'] = new Date();
|
|
663
|
-
ws.ping(function () { });
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
}, 20000);
|
|
668
|
-
setInterval(function () {
|
|
669
|
-
var _a;
|
|
670
|
-
if (!_this._msgQueueRunning) {
|
|
671
|
-
if (_this._msgQueue.length) {
|
|
672
|
-
_this._msgQueueRunning = true;
|
|
673
|
-
_this._debugMsgQueue += 1;
|
|
674
|
-
var msg = _this._msgQueue.pop();
|
|
675
|
-
var data = msg.data;
|
|
676
|
-
var ws_1 = msg.ws;
|
|
677
|
-
var messageRoute = data.shift();
|
|
678
|
-
var messageDate = data.shift();
|
|
679
|
-
var messageId = data.shift();
|
|
680
|
-
var type = data.shift();
|
|
681
|
-
// Method call
|
|
682
|
-
if (type === 'method') {
|
|
683
|
-
var method = data.shift();
|
|
684
|
-
if (ws_1['user_readonly']) {
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
var methodLatencyId = (0, mongo_manager_1.objectIdHexString)();
|
|
688
|
-
log_method_latency_collection_1.LogMethodLatencies.create({
|
|
689
|
-
_id: methodLatencyId,
|
|
690
|
-
__v: 0,
|
|
691
|
-
date_start: new Date(),
|
|
692
|
-
date_end: null,
|
|
693
|
-
latency_ms: 0,
|
|
694
|
-
method: method
|
|
695
|
-
});
|
|
696
|
-
if (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers' && method !== 'processAirdropDistribution') {
|
|
697
|
-
log_collection_1.Logs.insertOne({
|
|
698
|
-
_id: (0, mongo_manager_1.objectIdHexString)(),
|
|
699
|
-
type: 'client-request',
|
|
700
|
-
collection: '',
|
|
701
|
-
id_document: '',
|
|
702
|
-
payload: (0, common_1.getBinarySize)(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',
|
|
703
|
-
method: method,
|
|
704
|
-
id_user: ws_1['id_user'] || '',
|
|
705
|
-
user: ws_1['user'] || '',
|
|
706
|
-
messageId: messageId,
|
|
707
|
-
route: messageRoute
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
var serverRes = {
|
|
711
|
-
messageId: messageId,
|
|
712
|
-
hasError: false,
|
|
713
|
-
data: 'ACK'
|
|
714
|
-
};
|
|
715
|
-
if (ws_1 && ws_1.readyState === ws_1.OPEN) {
|
|
716
|
-
ws_1.send(JSON.stringify(serverRes), function (error) {
|
|
717
|
-
if (error) {
|
|
718
|
-
_this.unsubscribeWS(ws_1);
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
if (_this._methodManager._methods[method]) {
|
|
723
|
-
(_a = _this._methodManager).callMethod.apply(_a, __spreadArray([methodLatencyId, ws_1, messageDate, messageId, method], data, false));
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
console.log('Could not find method: ' + method);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
else if (type === 'methodResponse') {
|
|
730
|
-
var method = data.shift();
|
|
731
|
-
method_response_collection_1.MethodResponses.findOne({ $and: [
|
|
732
|
-
{ id_user: ws_1['id_user'] },
|
|
733
|
-
{ message_id: messageId },
|
|
734
|
-
{ method: method },
|
|
735
|
-
{ date: messageDate }
|
|
736
|
-
] }).then(function (res) {
|
|
737
|
-
if (res) {
|
|
738
|
-
if (ws_1 && ws_1.readyState === ws_1.OPEN) {
|
|
739
|
-
ws_1.send(JSON.stringify(res.response), function (error) {
|
|
740
|
-
if (error) {
|
|
741
|
-
_this.unsubscribeWS(ws_1);
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
}, function (err) { });
|
|
747
|
-
}
|
|
748
|
-
_this._msgQueueRunning = false;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
}, 25);
|
|
752
|
-
};
|
|
753
|
-
ResolveIOMainServer.prototype.unsubscribeWS = function (ws) {
|
|
754
|
-
if (this._subscriptionManager.getEnableDebug()) {
|
|
755
|
-
console.log(new Date(), 'Server App', 'Unsub WS', ws['user'], ws['id_socket']);
|
|
756
|
-
}
|
|
757
|
-
this._subscriptionManager.unsubscribeAll(ws);
|
|
758
|
-
ws.removeAllListeners();
|
|
759
|
-
ws = null;
|
|
760
|
-
};
|
|
761
|
-
ResolveIOMainServer.prototype.getApp = function () {
|
|
762
|
-
return this._app;
|
|
763
|
-
};
|
|
764
|
-
ResolveIOMainServer.prototype.getServerConfig = function () {
|
|
765
|
-
return this._serverConfig;
|
|
766
|
-
};
|
|
767
|
-
return ResolveIOMainServer;
|
|
768
|
-
}());
|
|
769
|
-
exports.default = ResolveIOMainServer;
|
|
770
|
-
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,i,a,u){return new(a=a||Promise)(function(r,t){function n(e){try{s(u.next(e))}catch(e){t(e)}}function o(e){try{s(u.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?r(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(n,o)}s((u=u.apply(e,i||[])).next())})},__generator=this&&this.__generator||function(n,o){var s,i,a,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},l={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function e(r){return function(e){var t=[r,e];if(s)throw new TypeError("Generator is already executing.");for(;u=l&&t[l=0]?0:u;)try{if(s=1,i&&(a=2&t[0]?i.return:t[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,t[1])).done)return a;switch(i=0,(t=a?[2&t[0],a.value]:t)[0]){case 0:case 1:a=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,i=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(a=0<(a=u.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3]))u.label=t[1];else if(6===t[0]&&u.label<a[1])u.label=a[1],a=t;else{if(!(a&&u.label<a[2])){a[2]&&u.ops.pop(),u.trys.pop();continue}u.label=a[2],u.ops.push(t)}}t=o.call(n,u)}catch(e){t=[6,e],i=0}finally{s=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},__spreadArray=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,o=0,s=t.length;o<s;o++)!n&&o in t||((n=n||Array.prototype.slice.call(t,0,o))[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))},http_1=(Object.defineProperty(exports,"__esModule",{value:!0}),require("http")),express=require("express"),bodyParser=require("body-parser"),xmlParser=require("express-xml-bodyparser"),WebSocket=require("ws"),jwt=require("jsonwebtoken"),moment=require("moment-timezone"),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_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"),index_1=require("./index"),mongodb_1=require("mongodb"),ResolveIOMainServer=function(){function e(e,t,r,n,o,s,i){void 0===i&&(i=!1);var a=this;this._offlineUpdates=[],this._msgQueue=[],this._msgQueueRunning=!1,this.sesMail=!1,this.standardProgram=!1,this.publicProgram=!1,this._rebootFlag=!1,this.LOGGER="ERROR",this._clientRoutes=[],this._lastErrorMsg=null,this._debugMsgRecv=0,this._debugMsgQueue=0,this._safeShutdown=!1,this._serverConfig=t,this._clientRoutes=r,this._clientDir=n,this.sesMail=o,this.standardProgram=s,this.publicProgram=i,this._serverStartTime=new Date,this._lastErrorMsg=null,this._monitorManager=new monitor_manager_1.MonitorManager(e,t),this._monitorManagerFunction=new monitor_manager_1.MonitorManagerFunction,setInterval(function(){a._subscriptionManager.getEnableDebug()&&(console.log(new Date,"Server App","Msg Queue Length",a._msgQueue.length),console.log(new Date,"Server App","Msg Recv Hits",a._debugMsgRecv),console.log(new Date,"Server App","Msg Queue Hits",a._debugMsgQueue)),a._debugMsgQueue=0,a._debugMsgRecv=0},6e4),process.on("unhandledRejection",function(n,o){return __awaiter(a,void 0,void 0,function(){var t,r=this;return __generator(this,function(e){switch(e.label){case 0:return n&&"MongoError"===n.name&&48===n.code?[2]:(console.error(new Date,"Unhandled Rejection at Promise",[n,o]),t=moment().diff(this._serverStartTime,"seconds"),n&&("MongoNetworkTimeoutError"===n.name||n instanceof mongodb_1.MongoNetworkTimeoutError)?60<t&&!this._lastErrorMsg?(this._lastErrorMsg=new Date,setTimeout(function(){r._lastErrorMsg=null},6e4),[4,this._methodManager.sendEmail("dev@resolveio.com","SERVER - MongoNetworkTimeoutError - Quitting NodeJS - "+this._serverConfig.CLIENT_NAME,JSON.stringify({name:n.name,message:n.message,stack:n.stack},null,2))]):[3,2]:[3,3]);case 1:e.sent(),process.exit(1),e.label=2;case 2:return[3,10];case 3:return n&&"MongoError"===n.name&&"not master"===n.message?60<t&&!this._lastErrorMsg?(this._lastErrorMsg=new Date,setTimeout(function(){r._lastErrorMsg=null},6e4),[4,this._methodManager.sendEmail("dev@resolveio.com","SERVER - Unhandled Rejection - Quitting NodeJS - "+this._serverConfig.CLIENT_NAME,JSON.stringify([n.name,n.message,n.stack],null,2))]):[3,5]:[3,6];case 4:e.sent(),e.label=5;case 5:return process.exit(1),[3,10];case 6:return n&&"MongoError"===n.name&&"not master and slaveOk=false"===n.message?60<t&&!this._lastErrorMsg?(this._lastErrorMsg=new Date,setTimeout(function(){r._lastErrorMsg=null},6e4),[4,this._methodManager.sendEmail("dev@resolveio.com","SERVER - Unhandled Rejection - Quitting NodeJS - "+this._serverConfig.CLIENT_NAME,JSON.stringify([n.name,n.message,n.stack],null,2))]):[3,8]:[3,9];case 7:e.sent(),e.label=8;case 8:return process.exit(1),[3,10];case 9:n&&"StatusError"!==n.name&&""!==n.message&&60<t&&!this._lastErrorMsg&&(this._lastErrorMsg=new Date,setTimeout(function(){r._lastErrorMsg=null},6e4),this._methodManager.sendEmail("dev@resolveio.com","SERVER - Unhandled Rejection - "+this._serverConfig.CLIENT_NAME,JSON.stringify([n.name,n.message,n.stack],null,2))),e.label=10;case 10:return[2]}})})}),process.on("uncaughtException",function(r){return __awaiter(a,void 0,void 0,function(){var t=this;return __generator(this,function(e){switch(e.label){case 0:return(console.error(r,"Uncaught Exception thrown"),60<moment().diff(this._serverStartTime,"seconds")&&!this._lastErrorMsg)?(this._lastErrorMsg=new Date,setTimeout(function(){t._lastErrorMsg=null},6e4),[4,this._methodManager.sendEmail("dev@resolveio.com","SERVER - Unhandled Exception - "+this._serverConfig.CLIENT_NAME,JSON.stringify([r.name,r.message,r.stack],null,2))]):[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}})})}),process.on("SIGINT",function(){a._rebootFlag=!0,a._serverHTTP.close(),a.safeShutdown()}),process.on("SIGTERM",function(){a._rebootFlag=!0,a._serverHTTP.close(),a.safeShutdown()}),process.on("SIGQUIT",function(){a._rebootFlag=!0,a._serverHTTP.close(),a.safeShutdown()}),"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._portHTTP=process.env.PORT_HTTP||t.PORT_HTTP||8080,this._portWSS=process.env.PORT_WSS||t.PORT_WSS||8081,"DEBUG"===this.LOGGER&&console.log("Setup ports"),this.createServer(),"DEBUG"===this.LOGGER&&console.log("Create server"),this._app.use(function(e,t,r){t.setHeader("Access-Control-Allow-Origin","*"),t.setHeader("Access-Control-Allow-Methods","GET, POST"),t.setHeader("Access-Control-Allow-Headers","X-Requested-With,content-type"),t.setHeader("Access-Control-Allow-Credentials","false"),r()}),"DEBUG"===this.LOGGER&&console.log("Setup cors"),(0,auth_1.setupAuthRoutes)(this,this._app,t),(0,health_1.setupHealthRoutes)(this._app,t),"ResolveIO"!==t.CLIENT_NAME&&!this.standardProgram||(0,home_1.setupHomeRoutes)(this,this._app,t),"DEBUG"===this.LOGGER&&console.log("Setup express routes")}return e.prototype.safeShutdown=function(){var e=this;this._safeShutdown||console.log(new Date,"Safe Shutdown Command Received"),this._monitorManagerFunction.getActiveMonitorFunctions().length||this._msgQueue.length||this._msgQueueRunning||this._offlineUpdates.length?(this._safeShutdown||(this._safeShutdown=!0,setTimeout(function(){e._safeShutdown=!1},1e3),console.log(new Date,"Safe Exit In Progress",this._monitorManagerFunction.getActiveMonitorFunctions().length,this._msgQueue.length,this._msgQueueRunning,this._offlineUpdates.length)),setImmediate(function(){e.safeShutdown()})):index_1.ResolveIOServer.getMongoConnection().close(!1).then(function(){console.log(new Date,"Safe Exit Complete, Process Exit"),process.exit(0)},function(){process.exit(1)})},e.prototype.getWS=function(t){return Array.from(this._serverWSS.clients).filter(function(e){return e.id_socket===t})[0]},e.prototype.getWSList=function(){var t=[];return this._serverWSS.clients.forEach(function(e){t.push(e.id_socket)}),t},e.prototype.getWSUserList=function(){var t=[];return this._serverWSS.clients.forEach(function(e){t.push(e.id_user)}),t},e.prototype.getHTTPServer=function(){return this._serverHTTP},e.prototype.getCronManager=function(){return this._cronManager},e.prototype.getMethodManager=function(){return this._methodManager},e.prototype.getSubscriptionManager=function(){return this._subscriptionManager},e.prototype.getMonitorManager=function(){return this._monitorManager},e.prototype.getRebootFlag=function(){return this._rebootFlag},e.prototype.createServer=function(){var e=this;this._serverHTTP=(0,http_1.createServer)(this._app),this._serverHTTP.keepAliveTimeout=65e3,this._serverHTTP.headersTimeout=66e3,this._serverWSS=new WebSocket.Server({port:this._portWSS,verifyClient:this.publicProgram?null:function(s,i){return __awaiter(e,void 0,void 0,function(){var t,o=this;return __generator(this,function(e){return this._rebootFlag?i(!1,409,"Unable To Process"):("DEBUG"===this.LOGGER&&console.log("Verify Client",s,i),t=s.req.headers["sec-websocket-protocol"].split(/,/),(s.origin===this._serverConfig.ROOT_URL||s.origin===this._serverConfig.SEC_ROOT_URL||s.origin===this._serverConfig.RESOLVEIO_URL||s.origin===this._serverConfig.RESOLVEIO_SECONDARY_URL)&&(t=t[0])?jwt.verify(t,this._serverConfig.JWT_SECRET,function(r,n){return __awaiter(o,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return r?(i(!1,401,"Unauthorized"),[3,5]):[3,1];case 1:s.req.id_user=n.id_user,e.label=2;case 2:return e.trys.push([2,4,,5]),[4,user_collection_1.Users.findById(n.id_user)];case 3:return(t=e.sent())?(s.req.user=t.fullname,s.req.user_readonly=t.readonly||!1,s.req.doc_user=t,i(!0)):i(!1),[3,5];case 4:return e.sent(),i(!1),[3,5];case 5:return[2]}})})}):i(!1,401,"Unauthorized")),[2]})})}}),this.setUpMongo()},e.prototype.setUpMongo=function(){"DEBUG"===this.LOGGER&&console.log("Start Managers"),this._subscriptionManager=new subscription_manager_1.SubscriptionManager(this,this._serverWSS,this._serverConfig,this._monitorManagerFunction),this._methodManager=new method_manager_1.MethodManager(this,this._serverConfig,this._clientDir,this._monitorManagerFunction),this._cronManager=new cron_manager_1.CronManager(this),"DEBUG"===this.LOGGER&&console.log("End Managers"),this.listen()},e.prototype.listen=function(){var u=this;this._serverHTTP.listen(this._portHTTP,function(){console.log("Running server on port %s",u._portHTTP)}),this._serverWSS.on("listening",function(){console.log("Running server on port %s",u._portWSS)}),this._serverWSS.on("connection",function(f,e){u.publicProgram||(f.id_user=e.id_user,f.user=e.user,f.user_readonly=e.user_readonly,f.doc_user=e.doc_user,"Admin"!==f.user&&"ResolveIO"!==u._serverConfig.CLIENT_NAME&&u.getMethodManager().callMethodInternal.call(u.getMethodManager(),"supportCreateBillingUser",{id_user:f.id_user,user:f.user,date:new Date,client:index_1.ResolveIOServer.getClientName()})),f.id_socket=(0,mongo_manager_1.objectIdHexString)(),f.retryCnt=0,u._subscriptionManager.createLoggedInUser(f.id_socket).then(function(){setTimeout(function(){f.pingTime=new Date,f.ping(function(){})},5e3)}),"DEBUG"===u.LOGGER&&console.log("Connection from: "+e.user),f.isAlive=!0,f.on("pong",function(){f.isAlive=!0,f.pongTime=new Date,f.latency=moment.duration(moment(f.pongTime).diff(f.pingTime)).asMilliseconds(),u._subscriptionManager.loggedInLatency(f)}).on("message",function(p){return __awaiter(u,void 0,void 0,function(){var t,r,n,o,s,i,a,u,l,c,g,_,h,d=this;return __generator(this,function(e){switch(e.label){case 0:"DEBUG"===this.LOGGER&&console.log("Message from: "+f.user,p),this._debugMsgRecv+=1,u=!1,t=[];try{t=JSON.parse(p,common_1.dateReviver)}catch(e){console.log("Error - JSON.parse",p),this._methodManager.sendEmail("dev@resolveio.com","SERVER - JSON Parse Error - "+this._serverConfig.CLIENT_NAME,JSON.stringify([p,e])),u=!0}if(!u){if("ping"===t[0])return f&&f.readyState===f.OPEN&&f.send("pong",function(e){e&&(d._subscriptionManager.getEnableDebug()&&console.log(new Date,"Server App","Error WS Pong"),d.unsubscribeWS(f))}),[2];if(r=t[0],!this.publicProgram&&this._clientRoutes.some(function(e){return r.includes(e)})&&!f.doc_user.roles.groups.some(function(e){return e.views.some(function(e){return r.includes(e)||e.includes(r)})})&&!f.doc_user.roles.super_admin)return[2];if(u=t[1],n=t[2],"subscription"!==(o=t[3]))return[3,1];s=t[4],c=t[5],"sub"===s?this._subscriptionManager.subscribe(r,u,f,n,c,t.slice(6)):this._subscriptionManager.unsubscribe(r,u,f,n,c,t.slice(6))}return[3,11];case 1:if(this.publicProgram||"offline"!==o)return[3,10];s={messageId:n,hasError:!1,data:"ACK"},f&&f.readyState===f.OPEN&&f.send(JSON.stringify(s),function(e){e&&(d._subscriptionManager.getEnableDebug()&&console.log(new Date,"Server App","Error WS Offline Ack Main"),d.unsubscribeWS(f))}),this._offlineUpdates.push(f),i=t[4],a=0,e.label=2;case 2:if(!(a<i.length))return[3,9];if(u=i[a],l=u.data,c={messageId:u.data[2],hasError:!1,data:"ACK"},f&&f.readyState===f.OPEN&&f.send(JSON.stringify(c),function(e){e&&(d._subscriptionManager.getEnableDebug()&&console.log(new Date,"Server App","Error WS Offline Ack Each"),d.unsubscribeWS(f))}),l.shift(),l.shift(),l.shift(),l.shift(),g=l.shift(),h=(0,mongo_manager_1.objectIdHexString)(),log_method_latency_collection_1.LogMethodLatencies.create({_id:h,__v:0,date_start:new Date,date_end:null,latency_ms:0,method:g}),"reportBuilderGetResults"!==g&&"reportBuilderGetDistinctValue"!==g&&"reportBuilderBuildTree"!==g&&"generatePDF"!==g&&"getWOOfflineData"!==g&&"countQuery"!==g&&"countWithQuery"!==g&&"countCollectionWithQuery"!==g&&"find"!==g&&"findOne"!==g&&"findWithOptions"!==g&&"getDrivers"!==g&&"processAirdropDistribution"!==g&&log_collection_1.Logs.insertOne({_id:(0,mongo_manager_1.objectIdHexString)(),type:"client-request",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify(l))<2e5?JSON.stringify(l,null,2):"Too Big",method:g,id_user:f.id_user||"",user:f.user||"",messageId:n,route:r}),!this._methodManager._methods[g])return[3,7];e.label=3;case 3:return e.trys.push([3,5,,6]),[4,(h=this._methodManager.callMethodInternal).call.apply(h,__spreadArray([Object.assign({},this._methodManager,{id_user:f.id_user,user:f.user,id_ws:f.id_socket}),g],l,!1))];case 4:return e.sent(),[3,6];case 5:return _=e.sent(),console.log(new Date,"Offline Error",JSON.stringify(_,null,2)),[3,6];case 6:return"updateDocumentOffline"!==g&&"updateDocumentPropsOffline"!==g||index_1.ResolveIOServer.getMongoManager().invalidateQueryCache(l[0]),[3,8];case 7:console.log("Offline - Could not find method: "+g),e.label=8;case 8:return a++,[3,2];case 9:return this._offlineUpdates.splice(this._offlineUpdates.map(function(e){return e.id_socket}).indexOf(f.id_socket),1),[3,11];case 10:this._msgQueue.splice(0,0,{ws:f,data:t}),e.label=11;case 11:return[2]}})})}).on("end",function(){u.unsubscribeWS(f),u._subscriptionManager.getEnableDebug()&&console.log(new Date,"Server App","WS End")}).on("close",function(){u.unsubscribeWS(f),u._subscriptionManager.getEnableDebug()&&console.log(new Date,"Server App","WS Close")}).on("error",function(e){u.unsubscribeWS(f),u._subscriptionManager.getEnableDebug()&&console.log(new Date,f.user,f.id_socket,"WS Error")})}),setInterval(function(){u._serverWSS.clients.forEach(function(e){e.pingTime&&2e4<=Date.now()-e.pingTime.getTime()&&(!1===e.isAlive?(e.retryCnt++,3<=e.retryCnt?u.unsubscribeWS(e):(e.pingTime=new Date,e.ping(function(){}))):(e.retryCnt=0,e.isAlive=!1,e.pingTime=new Date,e.ping(function(){})))})},2e4),setInterval(function(){if(!u._msgQueueRunning&&u._msgQueue.length){u._msgQueueRunning=!0,u._debugMsgQueue+=1;var e=u._msgQueue.pop(),t=e.data,r=e.ws,e=t.shift(),n=t.shift(),o=t.shift(),s=t.shift();if("method"===s){var i=t.shift();if(r.user_readonly)return;var a=(0,mongo_manager_1.objectIdHexString)(),e=(log_method_latency_collection_1.LogMethodLatencies.create({_id:a,__v:0,date_start:new Date,date_end:null,latency_ms:0,method:i}),"reportBuilderGetResults"!==i&&"reportBuilderGetDistinctValue"!==i&&"reportBuilderBuildTree"!==i&&"generatePDF"!==i&&"getWOOfflineData"!==i&&"countQuery"!==i&&"countWithQuery"!==i&&"countCollectionWithQuery"!==i&&"find"!==i&&"findOne"!==i&&"findWithOptions"!==i&&"getDrivers"!==i&&"processAirdropDistribution"!==i&&log_collection_1.Logs.insertOne({_id:(0,mongo_manager_1.objectIdHexString)(),type:"client-request",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify(t))<2e5?JSON.stringify(t,null,2):"Too Big",method:i,id_user:r.id_user||"",user:r.user||"",messageId:o,route:e}),{messageId:o,hasError:!1,data:"ACK"});r&&r.readyState===r.OPEN&&r.send(JSON.stringify(e),function(e){e&&u.unsubscribeWS(r)}),u._methodManager._methods[i]?(e=u._methodManager).callMethod.apply(e,__spreadArray([a,r,n,o,i],t,!1)):console.log("Could not find method: "+i)}else"methodResponse"===s&&(i=t.shift(),method_response_collection_1.MethodResponses.findOne({$and:[{id_user:r.id_user},{message_id:o},{method:i},{date:n}]}).then(function(e){e&&r&&r.readyState===r.OPEN&&r.send(JSON.stringify(e.response),function(e){e&&u.unsubscribeWS(r)})},function(e){}));u._msgQueueRunning=!1}},25)},e.prototype.unsubscribeWS=function(e){this._subscriptionManager.getEnableDebug()&&console.log(new Date,"Server App","Unsub WS",e.user,e.id_socket),this._subscriptionManager.unsubscribeAll(e),e.removeAllListeners()},e.prototype.getApp=function(){return this._app},e.prototype.getServerConfig=function(){return this._serverConfig},e}();exports.default=ResolveIOMainServer;
|
|
771
2
|
//# sourceMappingURL=server-app.js.map
|