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