@resolveio/server-lib 20.0.26 → 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 -616
- 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
|
@@ -1,594 +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
|
-
exports.MethodManager = exports.AWS = void 0;
|
|
49
|
-
var collections_1 = require("../methods/collections");
|
|
50
|
-
var logs_1 = require("../methods/logs");
|
|
51
|
-
var counters_1 = require("../methods/counters");
|
|
52
|
-
var pdf_1 = require("../methods/pdf");
|
|
53
|
-
var aws_1 = require("../methods/aws");
|
|
54
|
-
var path = require("path");
|
|
55
|
-
var fs = require("fs");
|
|
56
|
-
var nodemailer = require("nodemailer");
|
|
57
|
-
var sesTransport = require("nodemailer-ses-transport");
|
|
58
|
-
var accounts_1 = require("../methods/accounts");
|
|
59
|
-
var init_1 = require("../fixtures/init");
|
|
60
|
-
var cron_jobs_1 = require("../fixtures/cron-jobs");
|
|
61
|
-
var cron_jobs_2 = require("../methods/cron-jobs");
|
|
62
|
-
var flags_1 = require("../methods/flags");
|
|
63
|
-
var method_response_collection_1 = require("../collections/method-response.collection");
|
|
64
|
-
var common_1 = require("../util/common");
|
|
65
|
-
var log_collection_1 = require("../collections/log.collection");
|
|
66
|
-
var log_method_latency_collection_1 = require("../collections/log-method-latency.collection");
|
|
67
|
-
var moment = require("moment-timezone");
|
|
68
|
-
var report_builder_1 = require("../methods/report-builder");
|
|
69
|
-
var support_1 = require("../methods/support");
|
|
70
|
-
var monitor_1 = require("../methods/monitor");
|
|
71
|
-
var email_history_collection_1 = require("../collections/email-history.collection");
|
|
72
|
-
var mongo_manager_1 = require("./mongo.manager");
|
|
73
|
-
var client_s3_1 = require("@aws-sdk/client-s3");
|
|
74
|
-
var AWS = /** @class */ (function () {
|
|
75
|
-
function AWS(serverConfig) {
|
|
76
|
-
this._serverConfig = null;
|
|
77
|
-
this._s3 = null;
|
|
78
|
-
this._s3USEast1 = null;
|
|
79
|
-
this._serverConfig = serverConfig;
|
|
80
|
-
}
|
|
81
|
-
AWS.prototype.s3 = function () {
|
|
82
|
-
if (this._s3) {
|
|
83
|
-
return this._s3;
|
|
84
|
-
}
|
|
85
|
-
this._s3 = new client_s3_1.S3({
|
|
86
|
-
credentials: {
|
|
87
|
-
accessKeyId: process.env.AWS_ACCESS_KEY,
|
|
88
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
|
|
89
|
-
},
|
|
90
|
-
region: process.env.AWS_REGION,
|
|
91
|
-
apiVersion: '2006-03-01'
|
|
92
|
-
});
|
|
93
|
-
return this._s3;
|
|
94
|
-
};
|
|
95
|
-
AWS.prototype.s3USEast1 = function () {
|
|
96
|
-
if (process.env.AWS_REGION === 'us-east-1') {
|
|
97
|
-
return this.s3();
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
if (this._s3USEast1) {
|
|
101
|
-
return this._s3USEast1;
|
|
102
|
-
}
|
|
103
|
-
this._s3USEast1 = new client_s3_1.S3({
|
|
104
|
-
credentials: {
|
|
105
|
-
accessKeyId: process.env.AWS_ACCESS_KEY,
|
|
106
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
|
|
107
|
-
},
|
|
108
|
-
region: 'us-east-1',
|
|
109
|
-
apiVersion: '2006-03-01'
|
|
110
|
-
});
|
|
111
|
-
return this._s3USEast1;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
return AWS;
|
|
115
|
-
}());
|
|
116
|
-
exports.AWS = AWS;
|
|
117
|
-
var MethodManager = /** @class */ (function () {
|
|
118
|
-
function MethodManager(mainServer, serverConfig, clientDir, monitorManagerFunction) {
|
|
119
|
-
var _this = this;
|
|
120
|
-
this._methods = {};
|
|
121
|
-
this._sendQueue = [];
|
|
122
|
-
this._runningQueue = false;
|
|
123
|
-
this._debugCallMethodInternalHits = 0;
|
|
124
|
-
this._debugCallMethodHits = 0;
|
|
125
|
-
this._debugCallMethodCronJobHits = 0;
|
|
126
|
-
this._debugSendQueueHits = 0;
|
|
127
|
-
this._mainServer = mainServer;
|
|
128
|
-
this.serverConfig = serverConfig;
|
|
129
|
-
this.clientDir = clientDir;
|
|
130
|
-
this._monitorManagerFunction = monitorManagerFunction;
|
|
131
|
-
// Fixtures
|
|
132
|
-
(0, init_1.loadServerInit)();
|
|
133
|
-
(0, cron_jobs_1.loadServerCronJobs)();
|
|
134
|
-
// Methods
|
|
135
|
-
(0, accounts_1.loadAccountMethods)(this);
|
|
136
|
-
(0, aws_1.loadAWSMethods)(this);
|
|
137
|
-
(0, collections_1.loadCollectionMethods)(this);
|
|
138
|
-
(0, counters_1.loadCounterMethods)(this);
|
|
139
|
-
(0, logs_1.loadLogMethods)(this);
|
|
140
|
-
(0, pdf_1.loadPDFMethods)(this);
|
|
141
|
-
(0, cron_jobs_2.loadCronJobMethods)(this);
|
|
142
|
-
(0, flags_1.loadFlagMethods)(this);
|
|
143
|
-
(0, report_builder_1.loadReportBuilderMethods)(this);
|
|
144
|
-
(0, support_1.loadSupportMethods)(this);
|
|
145
|
-
(0, monitor_1.loadMonitorMethods)(this);
|
|
146
|
-
this._aws = new AWS(serverConfig);
|
|
147
|
-
if (mainServer.sesMail) {
|
|
148
|
-
this._mailer = nodemailer.createTransport(sesTransport({
|
|
149
|
-
accessKeyId: process.env.AWS_ACCESS_KEY,
|
|
150
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
151
|
-
region: process.env.AWS_SES_REGION
|
|
152
|
-
}));
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
this._mailer = nodemailer.createTransport({
|
|
156
|
-
host: this.serverConfig['MAIL_HOST'],
|
|
157
|
-
port: this.serverConfig['MAIL_PORT'],
|
|
158
|
-
secure: false,
|
|
159
|
-
auth: {
|
|
160
|
-
user: this.serverConfig['MAIL_USERNAME'],
|
|
161
|
-
pass: this.serverConfig['MAIL_PASSWORD']
|
|
162
|
-
},
|
|
163
|
-
tls: {
|
|
164
|
-
ciphers: 'SSLv3'
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
setInterval(function () {
|
|
169
|
-
if (_this._mainServer.getSubscriptionManager().getEnableDebug()) {
|
|
170
|
-
console.log(new Date(), 'Method Manager', 'Send Queue Length', _this._sendQueue.length);
|
|
171
|
-
console.log(new Date(), 'Method Manager', 'Send Queue Hits', _this._debugSendQueueHits);
|
|
172
|
-
console.log(new Date(), 'Method Manager', 'Call Method Internal Hits', _this._debugCallMethodInternalHits);
|
|
173
|
-
console.log(new Date(), 'Method Manager', 'Call Method Hits', _this._debugCallMethodHits);
|
|
174
|
-
console.log(new Date(), 'Method Manager', 'Call Method Cron Hits', _this._debugCallMethodCronJobHits);
|
|
175
|
-
}
|
|
176
|
-
_this._debugCallMethodInternalHits = 0;
|
|
177
|
-
_this._debugCallMethodHits = 0;
|
|
178
|
-
_this._debugCallMethodCronJobHits = 0;
|
|
179
|
-
_this._debugSendQueueHits = 0;
|
|
180
|
-
_this._debugSendQueueHits = 0;
|
|
181
|
-
}, 60000);
|
|
182
|
-
setInterval(function () {
|
|
183
|
-
if (!_this._runningQueue) {
|
|
184
|
-
if (_this._sendQueue.length) {
|
|
185
|
-
_this._runningQueue = true;
|
|
186
|
-
var _loop_1 = function (i) {
|
|
187
|
-
_this._debugSendQueueHits += 1;
|
|
188
|
-
var ws = _this._mainServer.getWS(_this._sendQueue[i].id_ws);
|
|
189
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
190
|
-
if (ws.bufferedAmount < 20480) {
|
|
191
|
-
var sendItem = _this._sendQueue.pop();
|
|
192
|
-
ws.send(JSON.stringify(sendItem.data), function (error) {
|
|
193
|
-
if (error) {
|
|
194
|
-
_this._mainServer.unsubscribeWS(ws);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
if (sendItem.method !== 'reportBuilderGetResults' && sendItem.method !== 'reportBuilderGetDistinctValue' && sendItem.method !== 'reportBuilderBuildTree' && sendItem.method !== 'generatePDF' && sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'countQuery' && sendItem.method !== 'countWithQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'uploadFileAndSave' && sendItem.method !== 'getDrivers' && sendItem.method !== 'processAirdropDistribution') {
|
|
198
|
-
log_collection_1.Logs.insertOne({
|
|
199
|
-
_id: (0, mongo_manager_1.objectIdHexString)(),
|
|
200
|
-
type: 'client-response',
|
|
201
|
-
collection: '',
|
|
202
|
-
id_document: '',
|
|
203
|
-
payload: (0, common_1.getBinarySize)(JSON.stringify([sendItem.methodData, sendItem.data])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.data], null, 2) : 'Too Big',
|
|
204
|
-
method: sendItem.method,
|
|
205
|
-
id_user: ws['id_user'] || '',
|
|
206
|
-
user: ws['user'] || '',
|
|
207
|
-
messageId: sendItem.data.messageId,
|
|
208
|
-
route: ''
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
method_response_collection_1.MethodResponses.create({
|
|
212
|
-
_id: (0, mongo_manager_1.objectIdHexString)(),
|
|
213
|
-
__v: 0,
|
|
214
|
-
id_user: ws['id_user'] || '',
|
|
215
|
-
message_id: sendItem.data.messageId,
|
|
216
|
-
response: (0, common_1.getBinarySize)(JSON.stringify(sendItem.data)) < 200000 ? sendItem.data : { error: 'Too Big' },
|
|
217
|
-
method: sendItem.method,
|
|
218
|
-
date: sendItem.date
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
_this._sendQueue.splice(i, 1);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
for (var i = _this._sendQueue.length - 1; i >= 0; i--) {
|
|
227
|
-
_loop_1(i);
|
|
228
|
-
}
|
|
229
|
-
_this._runningQueue = false;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}, 25);
|
|
233
|
-
}
|
|
234
|
-
MethodManager.prototype.getMainServer = function () {
|
|
235
|
-
return this._mainServer;
|
|
236
|
-
};
|
|
237
|
-
// Add methods to private methods object
|
|
238
|
-
MethodManager.prototype.methods = function (method) {
|
|
239
|
-
this._methods = Object.assign(this._methods, method);
|
|
240
|
-
};
|
|
241
|
-
MethodManager.prototype.callMethodCron = function (method) {
|
|
242
|
-
var _a;
|
|
243
|
-
var _this = this;
|
|
244
|
-
var methodData = [];
|
|
245
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
246
|
-
methodData[_i - 1] = arguments[_i];
|
|
247
|
-
}
|
|
248
|
-
this._debugCallMethodCronJobHits += 1;
|
|
249
|
-
if (!this._methods[method]) {
|
|
250
|
-
console.log('No Method: ' + method);
|
|
251
|
-
this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'No Method: ' + method);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
if ((methodData.length > 1 || methodData[0]) && !this._methods[method].skipValidation) {
|
|
255
|
-
if (!this._methods[method].check) {
|
|
256
|
-
console.error(new Date(), 'No Check Function For Method ' + method);
|
|
257
|
-
this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
else if (!this._methods[method].check._schema) {
|
|
261
|
-
console.error(new Date(), 'No Check Schema For Method ' + method);
|
|
262
|
-
this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
var valObj = {};
|
|
267
|
-
var valKeys = Object.keys(this._methods[method].check._schema);
|
|
268
|
-
var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
269
|
-
for (var i = 0; i < methodData.length; i++) {
|
|
270
|
-
valObj[rootKeys[i]] = methodData[i];
|
|
271
|
-
}
|
|
272
|
-
try {
|
|
273
|
-
this._methods[method].check.validate(valObj);
|
|
274
|
-
}
|
|
275
|
-
catch (errors) {
|
|
276
|
-
if (errors) {
|
|
277
|
-
console.error(new Date(), 'Error in Method Check (' + method + ')', errors);
|
|
278
|
-
this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Match Error On Method ' + method + '\n\nData Being Checked\n' + JSON.stringify(valObj, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
var monitor = this._monitorManagerFunction.startMonitorFunction('Cron Method', method, '', '', methodData);
|
|
285
|
-
var promise = (_a = this._methods[method].function).call.apply(_a, __spreadArray([Object.assign({}, this, MethodManager.prototype, { id_user: '', user: '', id_ws: '' })], methodData, false)).then(function (res) {
|
|
286
|
-
_this._monitorManagerFunction.finishMonitorFunction(monitor);
|
|
287
|
-
return res;
|
|
288
|
-
}, function (methodErrs) {
|
|
289
|
-
_this._monitorManagerFunction.finishMonitorFunction(monitor);
|
|
290
|
-
_this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During Method ' + method + ' - (callMethodCron)\n\nData \n' + JSON.stringify(methodData, null, 2) + '\n\nErrors\n' + JSON.stringify(methodErrs, null, 2));
|
|
291
|
-
return methodErrs;
|
|
292
|
-
});
|
|
293
|
-
return promise;
|
|
294
|
-
};
|
|
295
|
-
// Call/run method (Emit on Socket)
|
|
296
|
-
MethodManager.prototype.callMethod = function (id_methodLatency, ws, messageDate, messageId, method) {
|
|
297
|
-
var _a;
|
|
298
|
-
var _this = this;
|
|
299
|
-
var methodData = [];
|
|
300
|
-
for (var _i = 5; _i < arguments.length; _i++) {
|
|
301
|
-
methodData[_i - 5] = arguments[_i];
|
|
302
|
-
}
|
|
303
|
-
this._debugCallMethodHits += 1;
|
|
304
|
-
if (!this._methods[method]) {
|
|
305
|
-
console.log('No Method: ' + method);
|
|
306
|
-
this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'No Method: ' + method);
|
|
307
|
-
var serverRes = {
|
|
308
|
-
messageId: messageId,
|
|
309
|
-
hasError: true,
|
|
310
|
-
data: 'Internal Error'
|
|
311
|
-
};
|
|
312
|
-
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
313
|
-
if (id_methodLatency) {
|
|
314
|
-
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
315
|
-
}
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
if ((methodData.length > 1 || methodData[0]) && !this._methods[method].skipValidation) {
|
|
319
|
-
if (!this._methods[method].check) {
|
|
320
|
-
console.error(new Date(), 'No Check Function For Method ' + method);
|
|
321
|
-
this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
322
|
-
var serverRes = {
|
|
323
|
-
messageId: messageId,
|
|
324
|
-
hasError: true,
|
|
325
|
-
data: 'Internal Error'
|
|
326
|
-
};
|
|
327
|
-
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
328
|
-
if (id_methodLatency) {
|
|
329
|
-
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
330
|
-
}
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
else if (!this._methods[method].check._schema) {
|
|
334
|
-
console.error(new Date(), 'No Check Schema For Method ' + method);
|
|
335
|
-
this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
336
|
-
var serverRes = {
|
|
337
|
-
messageId: messageId,
|
|
338
|
-
hasError: true,
|
|
339
|
-
data: 'Internal Error'
|
|
340
|
-
};
|
|
341
|
-
if (id_methodLatency) {
|
|
342
|
-
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
343
|
-
}
|
|
344
|
-
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
var valObj = {};
|
|
349
|
-
var valKeys = Object.keys(this._methods[method].check._schema);
|
|
350
|
-
var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
351
|
-
for (var i = 0; i < methodData.length; i++) {
|
|
352
|
-
valObj[rootKeys[i]] = methodData[i];
|
|
353
|
-
}
|
|
354
|
-
try {
|
|
355
|
-
this._methods[method].check.validate(valObj);
|
|
356
|
-
}
|
|
357
|
-
catch (errors) {
|
|
358
|
-
if (errors) {
|
|
359
|
-
console.error(new Date(), 'Error in Method Check (' + method + ')', errors);
|
|
360
|
-
if (method !== 'processAirdropDistribution') {
|
|
361
|
-
this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Match Error On Method ' + method + '\n\nData Being Checked\n' + JSON.stringify(valObj, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
362
|
-
}
|
|
363
|
-
var serverRes = {
|
|
364
|
-
messageId: messageId,
|
|
365
|
-
hasError: true,
|
|
366
|
-
data: 'Internal Error'
|
|
367
|
-
};
|
|
368
|
-
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
369
|
-
if (id_methodLatency) {
|
|
370
|
-
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
371
|
-
}
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
var monitor = this._monitorManagerFunction.startMonitorFunction('Method', method, ws['user'] || '', ws['id_socket'] || '', methodData);
|
|
378
|
-
(_a = this._methods[method].function).call.apply(_a, __spreadArray([Object.assign({}, this, MethodManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })], methodData, false)).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
379
|
-
var serverRes, latency;
|
|
380
|
-
return __generator(this, function (_a) {
|
|
381
|
-
switch (_a.label) {
|
|
382
|
-
case 0:
|
|
383
|
-
this._monitorManagerFunction.finishMonitorFunction(monitor);
|
|
384
|
-
serverRes = {
|
|
385
|
-
messageId: messageId,
|
|
386
|
-
hasError: false,
|
|
387
|
-
data: res
|
|
388
|
-
};
|
|
389
|
-
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
390
|
-
if (!id_methodLatency) return [3 /*break*/, 2];
|
|
391
|
-
return [4 /*yield*/, log_method_latency_collection_1.LogMethodLatencies.findById(id_methodLatency)];
|
|
392
|
-
case 1:
|
|
393
|
-
latency = _a.sent();
|
|
394
|
-
if (latency) {
|
|
395
|
-
log_method_latency_collection_1.LogMethodLatencies.updateOne({ _id: id_methodLatency }, { $set: { date_end: new Date(), latency_ms: moment().diff(moment(latency.date_start), 'milliseconds', true) } });
|
|
396
|
-
}
|
|
397
|
-
_a.label = 2;
|
|
398
|
-
case 2: return [2 /*return*/];
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
}); }, function (err) {
|
|
402
|
-
_this._monitorManagerFunction.finishMonitorFunction(monitor);
|
|
403
|
-
var serverRes = {
|
|
404
|
-
messageId: messageId,
|
|
405
|
-
hasError: true,
|
|
406
|
-
data: err
|
|
407
|
-
};
|
|
408
|
-
_this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
409
|
-
if (id_methodLatency) {
|
|
410
|
-
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
411
|
-
}
|
|
412
|
-
if (method !== 'processAirdropDistribution') {
|
|
413
|
-
_this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During Method ' + method + ' - (callMethod)\n\nData \n' + JSON.stringify(methodData, null, 2) + '\n\nErrors\n' + JSON.stringify(err, null, 2));
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
};
|
|
417
|
-
// Call/run method internal (No Emit on Socket)
|
|
418
|
-
MethodManager.prototype.callMethodInternal = function (method) {
|
|
419
|
-
var _a;
|
|
420
|
-
var _this = this;
|
|
421
|
-
var methodData = [];
|
|
422
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
423
|
-
methodData[_i - 1] = arguments[_i];
|
|
424
|
-
}
|
|
425
|
-
this._debugCallMethodInternalHits += 1;
|
|
426
|
-
if (!this._methods[method]) {
|
|
427
|
-
console.log('No Method: ' + method);
|
|
428
|
-
return null;
|
|
429
|
-
}
|
|
430
|
-
if ((methodData.length > 1 || (methodData[0] && typeof (methodData[0]) !== 'function')) && !this._methods[method].skipValidation) {
|
|
431
|
-
if (!this._methods[method].check) {
|
|
432
|
-
console.error(new Date(), 'No Check Function For Method ' + method);
|
|
433
|
-
return null;
|
|
434
|
-
}
|
|
435
|
-
else if (!this._methods[method].check._schema) {
|
|
436
|
-
console.error(new Date(), 'No Check Schema For Method ' + method);
|
|
437
|
-
return null;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
if (method !== 'insertSubscriptionLog' && method !== 'getDataURIfromURL' && method !== 'processAirdropDistribution') {
|
|
441
|
-
log_collection_1.Logs.insertOne({
|
|
442
|
-
_id: (0, mongo_manager_1.objectIdHexString)(),
|
|
443
|
-
type: 'callMethodInternal',
|
|
444
|
-
collection: '',
|
|
445
|
-
id_document: '',
|
|
446
|
-
payload: (0, common_1.getBinarySize)(JSON.stringify([methodData])) < 200000 ? JSON.stringify([methodData], null, 2) : 'Too Big',
|
|
447
|
-
method: method,
|
|
448
|
-
id_user: this['id_user'] || '',
|
|
449
|
-
user: this['user'] || '',
|
|
450
|
-
messageId: 0,
|
|
451
|
-
route: ''
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
var functionMethodData = typeof (methodData[methodData.length - 1]) === 'function' ? methodData.slice(0, -1) : methodData;
|
|
455
|
-
var monitor = this._monitorManagerFunction.startMonitorFunction('Internal Method', method, this['user'] || '', '', functionMethodData);
|
|
456
|
-
var promise = (_a = this._methods[method].function).call.apply(_a, __spreadArray([Object.assign({}, this, MethodManager.prototype)], functionMethodData, false)).then(function (res) {
|
|
457
|
-
_this._monitorManagerFunction.finishMonitorFunction(monitor);
|
|
458
|
-
return res;
|
|
459
|
-
}, function (methodErrs) {
|
|
460
|
-
_this._monitorManagerFunction.finishMonitorFunction(monitor);
|
|
461
|
-
_this.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During Method ' + method + ' - (callMethodInternal)\n\nData \n' + JSON.stringify(methodData, null, 2) + '\n\nErrors\n' + JSON.stringify(methodErrs, null, 2));
|
|
462
|
-
return methodErrs;
|
|
463
|
-
});
|
|
464
|
-
if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
|
|
465
|
-
promise.then(function (res) { return methodData[methodData.length - 1](null, res); }, function (err) { return methodData[methodData.length - 1](err, null); });
|
|
466
|
-
}
|
|
467
|
-
return promise;
|
|
468
|
-
};
|
|
469
|
-
MethodManager.prototype.sendWS = function (ws, messageDate, method, methodData, data) {
|
|
470
|
-
this._sendQueue.splice(0, 0, {
|
|
471
|
-
id_ws: ws['id_socket'],
|
|
472
|
-
method: method,
|
|
473
|
-
methodData: methodData,
|
|
474
|
-
data: data,
|
|
475
|
-
date: messageDate
|
|
476
|
-
});
|
|
477
|
-
};
|
|
478
|
-
MethodManager.prototype.sendEmail = function (sendTo, subject, text, html, attachments, send_from, reply_to) {
|
|
479
|
-
var _this = this;
|
|
480
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
481
|
-
var _this = this;
|
|
482
|
-
return __generator(this, function (_a) {
|
|
483
|
-
if ((this.serverConfig['ROOT_URL'].match(new RegExp(/https\:\/\/dev\./)) || this.serverConfig['ROOT_URL'].match(new RegExp(/https\:\/\/www\.dev\./)) || this.serverConfig['ROOT_URL'] === 'http://localhost:4200') && !sendTo.match(new RegExp(/\@resolveio\.com/))) {
|
|
484
|
-
sendTo = 'dev@resolveio.com';
|
|
485
|
-
}
|
|
486
|
-
if (sendTo) {
|
|
487
|
-
if (this.serverConfig['ROOT_URL'] !== 'http://localhost:4200') {
|
|
488
|
-
this._mailer.sendMail({
|
|
489
|
-
replyTo: reply_to !== null && reply_to !== undefined ? reply_to : (this.serverConfig['MAIL_REPLY_TO'] || undefined),
|
|
490
|
-
from: send_from ? send_from : this.serverConfig.MAIL_FROM,
|
|
491
|
-
to: sendTo,
|
|
492
|
-
subject: (this.serverConfig['ROOT_URL'].match(new RegExp(/https\:\/\/dev\./)) || this.serverConfig['ROOT_URL'].match(new RegExp(/https\:\/\/www\.dev\./)) ? '(DEV SERVER) - ' : '') + subject,
|
|
493
|
-
text: text,
|
|
494
|
-
html: html,
|
|
495
|
-
attachments: attachments
|
|
496
|
-
}, function (err, info) {
|
|
497
|
-
if (err) {
|
|
498
|
-
console.log(err);
|
|
499
|
-
email_history_collection_1.EmailHistories.create({
|
|
500
|
-
_id: (0, mongo_manager_1.objectIdHexString)(),
|
|
501
|
-
__v: 0,
|
|
502
|
-
date: new Date(),
|
|
503
|
-
id_user: _this['id_user'] || '',
|
|
504
|
-
user: _this['user'] || '',
|
|
505
|
-
email: sendTo,
|
|
506
|
-
success: false,
|
|
507
|
-
verified: false
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
email_history_collection_1.EmailHistories.create({
|
|
512
|
-
_id: (0, mongo_manager_1.objectIdHexString)(),
|
|
513
|
-
__v: 0,
|
|
514
|
-
date: new Date(),
|
|
515
|
-
id_user: _this['id_user'] || '',
|
|
516
|
-
user: _this['user'] || '',
|
|
517
|
-
email: sendTo,
|
|
518
|
-
success: true,
|
|
519
|
-
verified: false
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
console.log('Send email', sendTo, subject, text, html, attachments, send_from);
|
|
526
|
-
}
|
|
527
|
-
resolve(true);
|
|
528
|
-
}
|
|
529
|
-
return [2 /*return*/];
|
|
530
|
-
});
|
|
531
|
-
}); });
|
|
532
|
-
};
|
|
533
|
-
MethodManager.prototype.getAWS = function () {
|
|
534
|
-
return this._aws;
|
|
535
|
-
};
|
|
536
|
-
MethodManager.prototype.readFile = function (fileName) {
|
|
537
|
-
var _this = this;
|
|
538
|
-
return new Promise(function (resolve, reject) {
|
|
539
|
-
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
540
|
-
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'utf-8', function (err, res) {
|
|
541
|
-
if (err) {
|
|
542
|
-
reject(err);
|
|
543
|
-
}
|
|
544
|
-
else {
|
|
545
|
-
resolve(res);
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
551
|
-
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'utf-8', function (err, res) {
|
|
552
|
-
if (err) {
|
|
553
|
-
reject(err);
|
|
554
|
-
}
|
|
555
|
-
else {
|
|
556
|
-
resolve(res);
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
});
|
|
562
|
-
};
|
|
563
|
-
MethodManager.prototype.readImage = function (fileName) {
|
|
564
|
-
var _this = this;
|
|
565
|
-
return new Promise(function (resolve, reject) {
|
|
566
|
-
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
567
|
-
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'base64', function (err, res) {
|
|
568
|
-
if (err) {
|
|
569
|
-
reject(err);
|
|
570
|
-
}
|
|
571
|
-
else {
|
|
572
|
-
resolve(res);
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
578
|
-
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'base64', function (err, res) {
|
|
579
|
-
if (err) {
|
|
580
|
-
reject(err);
|
|
581
|
-
}
|
|
582
|
-
else {
|
|
583
|
-
resolve(res);
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
};
|
|
590
|
-
return MethodManager;
|
|
591
|
-
}());
|
|
592
|
-
exports.MethodManager = MethodManager;
|
|
593
|
-
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,s,a,l){return new(a=a||Promise)(function(o,t){function n(e){try{i(l.next(e))}catch(e){t(e)}}function r(e){try{i(l.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?o(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(n,r)}i((l=l.apply(e,s||[])).next())})},__generator=this&&this.__generator||function(n,r){var i,s,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},c={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(c[Symbol.iterator]=function(){return this}),c;function e(o){return function(e){var t=[o,e];if(i)throw new TypeError("Generator is already executing.");for(;l=c&&t[c=0]?0:l;)try{if(i=1,s&&(a=2&t[0]?s.return:t[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,t[1])).done)return a;switch(s=0,(t=a?[2&t[0],a.value]:t)[0]){case 0:case 1:a=t;break;case 4:return l.label++,{value:t[1],done:!1};case 5:l.label++,s=t[1],t=[0];continue;case 7:t=l.ops.pop(),l.trys.pop();continue;default:if(!(a=0<(a=l.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){l=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3]))l.label=t[1];else if(6===t[0]&&l.label<a[1])l.label=a[1],a=t;else{if(!(a&&l.label<a[2])){a[2]&&l.ops.pop(),l.trys.pop();continue}l.label=a[2],l.ops.push(t)}}t=r.call(n,l)}catch(e){t=[6,e],s=0}finally{i=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,o){if(o||2===arguments.length)for(var n,r=0,i=t.length;r<i;r++)!n&&r in t||((n=n||Array.prototype.slice.call(t,0,r))[r]=t[r]);return e.concat(n||Array.prototype.slice.call(t))},collections_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.MethodManager=exports.AWS=void 0,require("../methods/collections")),logs_1=require("../methods/logs"),counters_1=require("../methods/counters"),pdf_1=require("../methods/pdf"),aws_1=require("../methods/aws"),path=require("path"),fs=require("fs"),nodemailer=require("nodemailer"),sesTransport=require("nodemailer-ses-transport"),accounts_1=require("../methods/accounts"),init_1=require("../fixtures/init"),cron_jobs_1=require("../fixtures/cron-jobs"),cron_jobs_2=require("../methods/cron-jobs"),flags_1=require("../methods/flags"),method_response_collection_1=require("../collections/method-response.collection"),common_1=require("../util/common"),log_collection_1=require("../collections/log.collection"),log_method_latency_collection_1=require("../collections/log-method-latency.collection"),moment=require("moment-timezone"),report_builder_1=require("../methods/report-builder"),support_1=require("../methods/support"),monitor_1=require("../methods/monitor"),email_history_collection_1=require("../collections/email-history.collection"),mongo_manager_1=require("./mongo.manager"),client_s3_1=require("@aws-sdk/client-s3"),AWS=function(){function e(e){this._serverConfig=null,this._s3=null,this._s3USEast1=null,this._serverConfig=e}return e.prototype.s3=function(){return this._s3||(this._s3=new client_s3_1.S3({credentials:{accessKeyId:process.env.AWS_ACCESS_KEY,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY},region:process.env.AWS_REGION,apiVersion:"2006-03-01"})),this._s3},e.prototype.s3USEast1=function(){return"us-east-1"===process.env.AWS_REGION?this.s3():(this._s3USEast1||(this._s3USEast1=new client_s3_1.S3({credentials:{accessKeyId:process.env.AWS_ACCESS_KEY,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY},region:"us-east-1",apiVersion:"2006-03-01"})),this._s3USEast1)},e}(),MethodManager=(exports.AWS=AWS,function(){function g(e,t,o,n){var r=this;this._methods={},this._sendQueue=[],this._runningQueue=!1,this._debugCallMethodInternalHits=0,this._debugCallMethodHits=0,this._debugCallMethodCronJobHits=0,this._debugSendQueueHits=0,this._mainServer=e,this.serverConfig=t,this.clientDir=o,this._monitorManagerFunction=n,(0,init_1.loadServerInit)(),(0,cron_jobs_1.loadServerCronJobs)(),(0,accounts_1.loadAccountMethods)(this),(0,aws_1.loadAWSMethods)(this),(0,collections_1.loadCollectionMethods)(this),(0,counters_1.loadCounterMethods)(this),(0,logs_1.loadLogMethods)(this),(0,pdf_1.loadPDFMethods)(this),(0,cron_jobs_2.loadCronJobMethods)(this),(0,flags_1.loadFlagMethods)(this),(0,report_builder_1.loadReportBuilderMethods)(this),(0,support_1.loadSupportMethods)(this),(0,monitor_1.loadMonitorMethods)(this),this._aws=new AWS(t),e.sesMail?this._mailer=nodemailer.createTransport(sesTransport({accessKeyId:process.env.AWS_ACCESS_KEY,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY,region:process.env.AWS_SES_REGION})):this._mailer=nodemailer.createTransport({host:this.serverConfig.MAIL_HOST,port:this.serverConfig.MAIL_PORT,secure:!1,auth:{user:this.serverConfig.MAIL_USERNAME,pass:this.serverConfig.MAIL_PASSWORD},tls:{ciphers:"SSLv3"}}),setInterval(function(){r._mainServer.getSubscriptionManager().getEnableDebug()&&(console.log(new Date,"Method Manager","Send Queue Length",r._sendQueue.length),console.log(new Date,"Method Manager","Send Queue Hits",r._debugSendQueueHits),console.log(new Date,"Method Manager","Call Method Internal Hits",r._debugCallMethodInternalHits),console.log(new Date,"Method Manager","Call Method Hits",r._debugCallMethodHits),console.log(new Date,"Method Manager","Call Method Cron Hits",r._debugCallMethodCronJobHits)),r._debugCallMethodInternalHits=0,r._debugCallMethodHits=0,r._debugCallMethodCronJobHits=0,r._debugSendQueueHits=0,r._debugSendQueueHits=0},6e4),setInterval(function(){if(!r._runningQueue&&r._sendQueue.length){r._runningQueue=!0;for(var e=r._sendQueue.length-1;0<=e;e--)!function(e){r._debugSendQueueHits+=1;var t,o=r._mainServer.getWS(r._sendQueue[e].id_ws);o&&o.readyState===o.OPEN?o.bufferedAmount<20480&&(t=r._sendQueue.pop(),o.send(JSON.stringify(t.data),function(e){e&&r._mainServer.unsubscribeWS(o)}),"reportBuilderGetResults"!==t.method&&"reportBuilderGetDistinctValue"!==t.method&&"reportBuilderBuildTree"!==t.method&&"generatePDF"!==t.method&&"getWOOfflineData"!==t.method&&"countQuery"!==t.method&&"countWithQuery"!==t.method&&"countCollectionWithQuery"!==t.method&&"find"!==t.method&&"findOne"!==t.method&&"findWithOptions"!==t.method&&"uploadFileAndSave"!==t.method&&"getDrivers"!==t.method&&"processAirdropDistribution"!==t.method&&log_collection_1.Logs.insertOne({_id:(0,mongo_manager_1.objectIdHexString)(),type:"client-response",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify([t.methodData,t.data]))<2e5?JSON.stringify([t.methodData,t.data],null,2):"Too Big",method:t.method,id_user:o.id_user||"",user:o.user||"",messageId:t.data.messageId,route:""}),method_response_collection_1.MethodResponses.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,id_user:o.id_user||"",message_id:t.data.messageId,response:(0,common_1.getBinarySize)(JSON.stringify(t.data))<2e5?t.data:{error:"Too Big"},method:t.method,date:t.date})):r._sendQueue.splice(e,1)}(e);r._runningQueue=!1}},25)}return g.prototype.getMainServer=function(){return this._mainServer},g.prototype.methods=function(e){this._methods=Object.assign(this._methods,e)},g.prototype.callMethodCron=function(t){for(var e,o=this,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(this._debugCallMethodCronJobHits+=1,this._methods[t]){if((1<n.length||n[0])&&!this._methods[t].skipValidation){if(!this._methods[t].check)return console.error(new Date,"No Check Function For Method "+t),void this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+this.serverConfig.CLIENT_NAME,"No Check Function For Method "+t);if(!this._methods[t].check._schema)return console.error(new Date,"No Check Schema For Method "+t),void this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+this.serverConfig.CLIENT_NAME,"No Check Function For Method "+t);for(var i={},s=Object.keys(this._methods[t].check._schema).filter(function(e){return!e.includes(".")}),a=0;a<n.length;a++)i[s[a]]=n[a];try{this._methods[t].check.validate(i)}catch(e){if(e)return console.error(new Date,"Error in Method Check ("+t+")",e),void this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+this.serverConfig.CLIENT_NAME,"Match Error On Method "+t+"\n\nData Being Checked\n"+JSON.stringify(i,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2))}}var l=this._monitorManagerFunction.startMonitorFunction("Cron Method",t,"","",n);return(e=this._methods[t].function).call.apply(e,__spreadArray([Object.assign({},this,g.prototype,{id_user:"",user:"",id_ws:""})],n,!1)).then(function(e){return o._monitorManagerFunction.finishMonitorFunction(l),e},function(e){return o._monitorManagerFunction.finishMonitorFunction(l),o.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+o.serverConfig.CLIENT_NAME,"Error Detected During Method "+t+" - (callMethodCron)\n\nData \n"+JSON.stringify(n,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),e})}console.log("No Method: "+t),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+this.serverConfig.CLIENT_NAME,"No Method: "+t)},g.prototype.callMethod=function(n,r,i,s,a){for(var e,t=this,l=[],o=5;o<arguments.length;o++)l[o-5]=arguments[o];if(this._debugCallMethodHits+=1,this._methods[a]){if((1<l.length||l[0])&&!this._methods[a].skipValidation){if(!this._methods[a].check)return console.error(new Date,"No Check Function For Method "+a),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+this.serverConfig.CLIENT_NAME,"No Check Function For Method "+a),this.sendWS(r,i,a,l,c={messageId:s,hasError:!0,data:"Internal Error"}),void(n&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:n}));if(!this._methods[a].check._schema)return console.error(new Date,"No Check Schema For Method "+a),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+this.serverConfig.CLIENT_NAME,"No Check Function For Method "+a),c={messageId:s,hasError:!0,data:"Internal Error"},n&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:n}),void this.sendWS(r,i,a,l,c);for(var c,d={},h=Object.keys(this._methods[a].check._schema).filter(function(e){return!e.includes(".")}),u=0;u<l.length;u++)d[h[u]]=l[u];try{this._methods[a].check.validate(d)}catch(e){if(e)return console.error(new Date,"Error in Method Check ("+a+")",e),"processAirdropDistribution"!==a&&this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+this.serverConfig.CLIENT_NAME,"Match Error On Method "+a+"\n\nData Being Checked\n"+JSON.stringify(d,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),this.sendWS(r,i,a,l,c={messageId:s,hasError:!0,data:"Internal Error"}),void(n&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:n}))}}var _=this._monitorManagerFunction.startMonitorFunction("Method",a,r.user||"",r.id_socket||"",l);(e=this._methods[a].function).call.apply(e,__spreadArray([Object.assign({},this,g.prototype,{id_user:r.id_user,user:r.user,id_ws:r.id_socket})],l,!1)).then(function(o){return __awaiter(t,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return(this._monitorManagerFunction.finishMonitorFunction(_),t={messageId:s,hasError:!1,data:o},this.sendWS(r,i,a,l,t),n)?[4,log_method_latency_collection_1.LogMethodLatencies.findById(n)]:[3,2];case 1:(t=e.sent())&&log_method_latency_collection_1.LogMethodLatencies.updateOne({_id:n},{$set:{date_end:new Date,latency_ms:moment().diff(moment(t.date_start),"milliseconds",!0)}}),e.label=2;case 2:return[2]}})})},function(e){t._monitorManagerFunction.finishMonitorFunction(_),t.sendWS(r,i,a,l,{messageId:s,hasError:!0,data:e}),n&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:n}),"processAirdropDistribution"!==a&&t.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+t.serverConfig.CLIENT_NAME,"Error Detected During Method "+a+" - (callMethod)\n\nData \n"+JSON.stringify(l,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2))})}else console.log("No Method: "+a),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+this.serverConfig.CLIENT_NAME,"No Method: "+a),this.sendWS(r,i,a,l,c={messageId:s,hasError:!0,data:"Internal Error"}),n&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:n})},g.prototype.callMethodInternal=function(t){for(var o=this,n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];if(this._debugCallMethodInternalHits+=1,!this._methods[t])return console.log("No Method: "+t),null;if((1<n.length||n[0]&&"function"!=typeof n[0])&&!this._methods[t].skipValidation){if(!this._methods[t].check)return console.error(new Date,"No Check Function For Method "+t),null;if(!this._methods[t].check._schema)return console.error(new Date,"No Check Schema For Method "+t),null}"insertSubscriptionLog"!==t&&"getDataURIfromURL"!==t&&"processAirdropDistribution"!==t&&log_collection_1.Logs.insertOne({_id:(0,mongo_manager_1.objectIdHexString)(),type:"callMethodInternal",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify([n]))<2e5?JSON.stringify([n],null,2):"Too Big",method:t,id_user:this.id_user||"",user:this.user||"",messageId:0,route:""});var r="function"==typeof n[n.length-1]?n.slice(0,-1):n,i=this._monitorManagerFunction.startMonitorFunction("Internal Method",t,this.user||"","",r),s=(s=this._methods[t].function).call.apply(s,__spreadArray([Object.assign({},this,g.prototype)],r,!1)).then(function(e){return o._monitorManagerFunction.finishMonitorFunction(i),e},function(e){return o._monitorManagerFunction.finishMonitorFunction(i),o.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+o.serverConfig.CLIENT_NAME,"Error Detected During Method "+t+" - (callMethodInternal)\n\nData \n"+JSON.stringify(n,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),e});return n[n.length-1]&&"function"==typeof n[n.length-1]&&s.then(function(e){return n[n.length-1](null,e)},function(e){return n[n.length-1](e,null)}),s},g.prototype.sendWS=function(e,t,o,n,r){this._sendQueue.splice(0,0,{id_ws:e.id_socket,method:o,methodData:n,data:r,date:t})},g.prototype.sendEmail=function(n,r,i,s,a,l,c){var o=this;return new Promise(function(t,e){return __awaiter(o,void 0,void 0,function(){var o=this;return __generator(this,function(e){return(n=!this.serverConfig.ROOT_URL.match(new RegExp(/https\:\/\/dev\./))&&!this.serverConfig.ROOT_URL.match(new RegExp(/https\:\/\/www\.dev\./))&&"http://localhost:4200"!==this.serverConfig.ROOT_URL||n.match(new RegExp(/\@resolveio\.com/))?n:"dev@resolveio.com")&&("http://localhost:4200"!==this.serverConfig.ROOT_URL?this._mailer.sendMail({replyTo:null!=c?c:this.serverConfig.MAIL_REPLY_TO||void 0,from:l||this.serverConfig.MAIL_FROM,to:n,subject:(this.serverConfig.ROOT_URL.match(new RegExp(/https\:\/\/dev\./))||this.serverConfig.ROOT_URL.match(new RegExp(/https\:\/\/www\.dev\./))?"(DEV SERVER) - ":"")+r,text:i,html:s,attachments:a},function(e,t){e?(console.log(e),email_history_collection_1.EmailHistories.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,date:new Date,id_user:o.id_user||"",user:o.user||"",email:n,success:!1,verified:!1})):email_history_collection_1.EmailHistories.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,date:new Date,id_user:o.id_user||"",user:o.user||"",email:n,success:!0,verified:!1})}):console.log("Send email",n,r,i,s,a,l),t(!0)),[2]})})})},g.prototype.getAWS=function(){return this._aws},g.prototype.readFile=function(e){var t=this;return new Promise(function(o,n){fs.existsSync(path.join(__dirname,"../private/"+e))?fs.readFile(path.join(__dirname,"../private/"+e),"utf-8",function(e,t){e?n(e):o(t)}):fs.existsSync(path.join(t.clientDir,"./private/"+e))&&fs.readFile(path.join(t.clientDir,"./private/"+e),"utf-8",function(e,t){e?n(e):o(t)})})},g.prototype.readImage=function(e){var t=this;return new Promise(function(o,n){fs.existsSync(path.join(__dirname,"../private/"+e))?fs.readFile(path.join(__dirname,"../private/"+e),"base64",function(e,t){e?n(e):o(t)}):fs.existsSync(path.join(t.clientDir,"./private/"+e))&&fs.readFile(path.join(t.clientDir,"./private/"+e),"base64",function(e,t){e?n(e):o(t)})})},g}());exports.MethodManager=MethodManager;
|
|
594
2
|
//# sourceMappingURL=method.manager.js.map
|