@resolveio/server-lib 3.2.10 → 3.2.11
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/package.json +26 -26
- package/collections/active-subscription.collection.d.ts +0 -7
- package/collections/active-subscription.collection.js +0 -68
- package/collections/app-status.collection.d.ts +0 -7
- package/collections/app-status.collection.js +0 -43
- package/collections/app-version.collection.d.ts +0 -7
- package/collections/app-version.collection.js +0 -56
- package/collections/billing-logged-in-users.collection.d.ts +0 -7
- package/collections/billing-logged-in-users.collection.js +0 -73
- package/collections/counter.collection.d.ts +0 -9
- package/collections/counter.collection.js +0 -73
- package/collections/cron-job-history.collection.d.ts +0 -7
- package/collections/cron-job-history.collection.js +0 -86
- package/collections/cron-job.collection.d.ts +0 -7
- package/collections/cron-job.collection.js +0 -89
- package/collections/file.collection.d.ts +0 -9
- package/collections/file.collection.js +0 -73
- package/collections/flag.collection.d.ts +0 -7
- package/collections/flag.collection.js +0 -47
- package/collections/log.collection.d.ts +0 -7
- package/collections/log.collection.js +0 -65
- package/collections/logged-in-users.collection.d.ts +0 -7
- package/collections/logged-in-users.collection.js +0 -70
- package/collections/method-call.collection.d.ts +0 -6
- package/collections/method-call.collection.js +0 -44
- package/collections/method-response.collection.d.ts +0 -6
- package/collections/method-response.collection.js +0 -48
- package/collections/notification.collection.d.ts +0 -7
- package/collections/notification.collection.js +0 -43
- package/collections/queue-flag.collection.d.ts +0 -7
- package/collections/queue-flag.collection.js +0 -41
- package/collections/queue-method.collection.d.ts +0 -7
- package/collections/queue-method.collection.js +0 -119
- package/collections/queue-response.collection.d.ts +0 -7
- package/collections/queue-response.collection.js +0 -74
- package/collections/support-ticket.collection.d.ts +0 -7
- package/collections/support-ticket.collection.js +0 -200
- package/collections/user.collection.d.ts +0 -9
- package/collections/user.collection.js +0 -153
- package/cron/cron.d.ts +0 -5
- package/cron/cron.js +0 -160
- package/fixtures/cron-jobs.d.ts +0 -1
- package/fixtures/cron-jobs.js +0 -90
- package/fixtures/init.d.ts +0 -1
- package/fixtures/init.js +0 -67
- package/http/auth.d.ts +0 -2
- package/http/auth.js +0 -468
- package/http/health.d.ts +0 -1
- package/http/health.js +0 -8
- package/index.d.ts +0 -16
- package/index.js +0 -125
- package/managers/cron.manager.d.ts +0 -16
- package/managers/cron.manager.js +0 -202
- package/managers/database.manager.d.ts +0 -6
- package/managers/database.manager.js +0 -12
- package/managers/method.manager.d.ts +0 -28
- package/managers/method.manager.js +0 -584
- package/managers/queue-method.manager.d.ts +0 -13
- package/managers/queue-method.manager.js +0 -240
- package/managers/subscription.manager.d.ts +0 -28
- package/managers/subscription.manager.js +0 -803
- package/managers/support.manager.d.ts +0 -22
- package/managers/support.manager.js +0 -320
- package/methods/accounts.d.ts +0 -2
- package/methods/accounts.js +0 -253
- package/methods/aws.d.ts +0 -2
- package/methods/aws.js +0 -387
- package/methods/cloudconvert.d.ts +0 -2
- package/methods/cloudconvert.js +0 -37
- package/methods/collections.d.ts +0 -2
- package/methods/collections.js +0 -750
- package/methods/counters.d.ts +0 -2
- package/methods/counters.js +0 -107
- package/methods/cron-jobs.d.ts +0 -2
- package/methods/cron-jobs.js +0 -132
- package/methods/flags.d.ts +0 -2
- package/methods/flags.js +0 -6
- package/methods/logs.d.ts +0 -2
- package/methods/logs.js +0 -29
- package/methods/pdf.d.ts +0 -2
- package/methods/pdf.js +0 -303
- package/models/active-subscription.model.d.ts +0 -13
- package/models/active-subscription.model.js +0 -2
- package/models/app-status.model.d.ts +0 -4
- package/models/app-status.model.js +0 -2
- package/models/app-version.model.d.ts +0 -4
- package/models/app-version.model.js +0 -2
- package/models/billing-logged-in-users.model.d.ts +0 -7
- package/models/billing-logged-in-users.model.js +0 -2
- package/models/collection-document.model.d.ts +0 -6
- package/models/collection-document.model.js +0 -2
- package/models/counter.model.d.ts +0 -5
- package/models/counter.model.js +0 -2
- package/models/cron-job-history.model.d.ts +0 -12
- package/models/cron-job-history.model.js +0 -2
- package/models/cron-job.model.d.ts +0 -13
- package/models/cron-job.model.js +0 -2
- package/models/dialog.model.d.ts +0 -23
- package/models/dialog.model.js +0 -2
- package/models/file.model.d.ts +0 -9
- package/models/file.model.js +0 -2
- package/models/flag.model.d.ts +0 -5
- package/models/flag.model.js +0 -2
- package/models/log.model.d.ts +0 -11
- package/models/log.model.js +0 -2
- package/models/logged-in-users.model.d.ts +0 -9
- package/models/logged-in-users.model.js +0 -2
- package/models/method-call.model.d.ts +0 -7
- package/models/method-call.model.js +0 -2
- package/models/method-response.model.d.ts +0 -8
- package/models/method-response.model.js +0 -2
- package/models/method.model.d.ts +0 -10
- package/models/method.model.js +0 -2
- package/models/notification.model.d.ts +0 -4
- package/models/notification.model.js +0 -2
- package/models/pagination.model.d.ts +0 -11
- package/models/pagination.model.js +0 -20
- package/models/permission.model.d.ts +0 -12
- package/models/permission.model.js +0 -2
- package/models/queue-method.model.d.ts +0 -10
- package/models/queue-method.model.js +0 -2
- package/models/queue-response.model.d.ts +0 -10
- package/models/queue-response.model.js +0 -2
- package/models/select-data-label.model.d.ts +0 -9
- package/models/select-data-label.model.js +0 -2
- package/models/server-response.model.d.ts +0 -5
- package/models/server-response.model.js +0 -2
- package/models/subscription.model.d.ts +0 -30
- package/models/subscription.model.js +0 -2
- package/models/support-method.model.d.ts +0 -9
- package/models/support-method.model.js +0 -2
- package/models/support-ticket.model.d.ts +0 -61
- package/models/support-ticket.model.js +0 -2
- package/models/user.model.d.ts +0 -14
- package/models/user.model.js +0 -2
- package/private/email-templates/enrollment.html +0 -12
- package/private/email-templates/forgot-password.html +0 -12
- package/private/email-templates/support-ticket-deleted.html +0 -40
- package/private/email-templates/support-ticket-modified.html +0 -71
- package/private/email-templates/support-ticket.html +0 -71
- package/private/images/ResolveIO.png +0 -0
- package/publications/app-status.d.ts +0 -2
- package/publications/app-status.js +0 -14
- package/publications/app-version.d.ts +0 -2
- package/publications/app-version.js +0 -14
- package/publications/billing-logged-in-users.d.ts +0 -1
- package/publications/billing-logged-in-users.js +0 -63
- package/publications/cron-jobs.d.ts +0 -2
- package/publications/cron-jobs.js +0 -14
- package/publications/files.d.ts +0 -2
- package/publications/files.js +0 -71
- package/publications/flags.d.ts +0 -2
- package/publications/flags.js +0 -23
- package/publications/logs.d.ts +0 -2
- package/publications/logs.js +0 -26
- package/publications/method-calls.d.ts +0 -2
- package/publications/method-calls.js +0 -14
- package/publications/method-responses.d.ts +0 -2
- package/publications/method-responses.js +0 -14
- package/publications/notifications.d.ts +0 -2
- package/publications/notifications.js +0 -14
- package/publications/super-admin.d.ts +0 -2
- package/publications/super-admin.js +0 -21
- package/publications/support-tickets.d.ts +0 -1
- package/publications/support-tickets.js +0 -200
- package/server-app.d.ts +0 -35
- package/server-app.js +0 -636
- package/support-methods/aws.d.ts +0 -2
- package/support-methods/aws.js +0 -276
- package/support-methods/collections.d.ts +0 -2
- package/support-methods/collections.js +0 -471
- package/support-methods/counters.d.ts +0 -2
- package/support-methods/counters.js +0 -189
- package/support-methods/support.d.ts +0 -2
- package/support-methods/support.js +0 -236
- package/util/common.d.ts +0 -14
- package/util/common.js +0 -341
|
@@ -1,584 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var collections_1 = require("../methods/collections");
|
|
4
|
-
var logs_1 = require("../methods/logs");
|
|
5
|
-
var counters_1 = require("../methods/counters");
|
|
6
|
-
var pdf_1 = require("../methods/pdf");
|
|
7
|
-
var aws_1 = require("../methods/aws");
|
|
8
|
-
var cloudconvert_1 = require("../methods/cloudconvert");
|
|
9
|
-
var path = require("path");
|
|
10
|
-
var fs = require("fs");
|
|
11
|
-
var nodemailer = require("nodemailer");
|
|
12
|
-
var aws = require("aws-sdk");
|
|
13
|
-
var accounts_1 = require("../methods/accounts");
|
|
14
|
-
var init_1 = require("../fixtures/init");
|
|
15
|
-
var cron_jobs_1 = require("../fixtures/cron-jobs");
|
|
16
|
-
var cron_jobs_2 = require("../methods/cron-jobs");
|
|
17
|
-
var flags_1 = require("../methods/flags");
|
|
18
|
-
var method_response_collection_1 = require("../collections/method-response.collection");
|
|
19
|
-
var mongoose_1 = require("mongoose");
|
|
20
|
-
var common_1 = require("../util/common");
|
|
21
|
-
var log_collection_1 = require("../collections/log.collection");
|
|
22
|
-
var support_manager_1 = require("./support.manager");
|
|
23
|
-
var MethodManager = /** @class */ (function () {
|
|
24
|
-
function MethodManager(mainServer, serverConfig, clientDir) {
|
|
25
|
-
var _this = this;
|
|
26
|
-
this._methods = {};
|
|
27
|
-
this._sendQueue = [];
|
|
28
|
-
this._runningQueue = false;
|
|
29
|
-
this._mainServer = mainServer;
|
|
30
|
-
this.serverConfig = serverConfig;
|
|
31
|
-
this.clientDir = clientDir;
|
|
32
|
-
// Fixtures
|
|
33
|
-
init_1.loadServerInit();
|
|
34
|
-
cron_jobs_1.loadServerCronJobs();
|
|
35
|
-
// Methods
|
|
36
|
-
accounts_1.loadAccountMethods(this);
|
|
37
|
-
aws_1.loadAWSMethods(this);
|
|
38
|
-
cloudconvert_1.loadCloudConvertMethods(this);
|
|
39
|
-
collections_1.loadCollectionMethods(this);
|
|
40
|
-
counters_1.loadCounterMethods(this);
|
|
41
|
-
logs_1.loadLogMethods(this);
|
|
42
|
-
pdf_1.loadPDFMethods(this);
|
|
43
|
-
cron_jobs_2.loadCronJobMethods(this);
|
|
44
|
-
flags_1.loadFlagMethods(this);
|
|
45
|
-
this._mailer = nodemailer.createTransport({
|
|
46
|
-
SES: new aws.SES({
|
|
47
|
-
apiVersion: '2010-12-01',
|
|
48
|
-
accessKeyId: serverConfig.AWSACCESSKEYID,
|
|
49
|
-
secretAccessKey: serverConfig.AWSSECRETACCESSKEY,
|
|
50
|
-
region: serverConfig.AWSSES_REGION
|
|
51
|
-
})
|
|
52
|
-
});
|
|
53
|
-
// this._imap = new imap({
|
|
54
|
-
// user: this.serverConfig['ORDERS_EMAIL'],
|
|
55
|
-
// password: this.serverConfig['ORDERS_PASSWORD'],
|
|
56
|
-
// host: this.serverConfig['ORDERS_HOST'],
|
|
57
|
-
// port: this.serverConfig['ORDERS_PORT'],
|
|
58
|
-
// tls: this.serverConfig['ORDERS_TLS']
|
|
59
|
-
// });
|
|
60
|
-
// let that = this;
|
|
61
|
-
// let chemicalNames = await Chemicals.find({}).select('description').exec();
|
|
62
|
-
// let jobNames = await Jobs.find({status: 'Active'}).select('well').exec();
|
|
63
|
-
// console.log(jobNames.map(a => a.well));
|
|
64
|
-
// this._imap.once('ready', () => {
|
|
65
|
-
// this._imap.openBox('INBOX', true, function(err, box) {
|
|
66
|
-
// if (err) {
|
|
67
|
-
// throw err;
|
|
68
|
-
// }
|
|
69
|
-
// that._imap.search([ 'NEW' ], function(err, results) {
|
|
70
|
-
// console.log(err, results);
|
|
71
|
-
// if (err || !results.length) {
|
|
72
|
-
// return that._imap.end();
|
|
73
|
-
// }
|
|
74
|
-
// let f = that._imap.fetch(results[0], { bodies: ['HEADER.FIELDS (FROM)', 'TEXT'] });
|
|
75
|
-
// f.on('message', function(msg, seqno) {
|
|
76
|
-
// // console.log('Message #%d', seqno);
|
|
77
|
-
// let prefix = '(#' + seqno + ') ';
|
|
78
|
-
// msg.on('body', function(stream, info) {
|
|
79
|
-
// let buffer = '', count = 0;
|
|
80
|
-
// stream.on('data', function(chunk) {
|
|
81
|
-
// count += chunk.length;
|
|
82
|
-
// buffer += chunk.toString('utf8');
|
|
83
|
-
// });
|
|
84
|
-
// stream.once('end', function() {
|
|
85
|
-
// if (info.which === 'TEXT') {
|
|
86
|
-
// // console.log(buffer);
|
|
87
|
-
// // console.log(typeof(buffer));
|
|
88
|
-
// let lines = buffer.split('\r\n');
|
|
89
|
-
// // console.log(lines);
|
|
90
|
-
// // let i = 0;
|
|
91
|
-
// // lines.forEach(line => {
|
|
92
|
-
// // let date: Date;
|
|
93
|
-
// // let dateString;
|
|
94
|
-
// // if (line.includes('From')) {
|
|
95
|
-
// // console.log(line);
|
|
96
|
-
// // }
|
|
97
|
-
// // if (!line.includes('class=3D') && !line.includes('style=3D')) {
|
|
98
|
-
// // if (line.includes('Well') || line.includes('Well Name') || line.includes('Job') || line.includes('Pad')) {
|
|
99
|
-
// // let best = stringSimilarity.findBestMatch(line, jobNames.map(a => a.well)).bestMatch;
|
|
100
|
-
// // if (best && best.rating > 0.5) {
|
|
101
|
-
// // console.log('Well', line);
|
|
102
|
-
// // }
|
|
103
|
-
// // }
|
|
104
|
-
// // if (line.includes('Product') || line.includes('Chemical')) {
|
|
105
|
-
// // let best = stringSimilarity.findBestMatch(line, chemicalNames.map(a => a.description)).bestMatch;
|
|
106
|
-
// // if (best && best.rating > 0.5) {
|
|
107
|
-
// // console.log('Chemical', line);
|
|
108
|
-
// // }
|
|
109
|
-
// // }
|
|
110
|
-
// // if (line.includes('Quantity') || line.includes('Qty') || line.includes('Amount')) {
|
|
111
|
-
// // console.log('Qty', line);
|
|
112
|
-
// // }
|
|
113
|
-
// // if (line.includes('Date')) {
|
|
114
|
-
// // console.log('Date', line);
|
|
115
|
-
// // console.log(moment(Date.parse(line)));
|
|
116
|
-
// // date = moment(Date.parse(line)).toDate();
|
|
117
|
-
// // dateString = line;
|
|
118
|
-
// // }
|
|
119
|
-
// // if (line.includes('Time')) {
|
|
120
|
-
// // console.log('Time', line);
|
|
121
|
-
// // console.log(moment(Date.parse(line)));
|
|
122
|
-
// // console.log(moment(date.setTime(Date.parse(line))));
|
|
123
|
-
// // }
|
|
124
|
-
// // }
|
|
125
|
-
// // });
|
|
126
|
-
// }
|
|
127
|
-
// });
|
|
128
|
-
// });
|
|
129
|
-
// msg.once('attributes', function(attrs) {
|
|
130
|
-
// console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));
|
|
131
|
-
// });
|
|
132
|
-
// msg.once('end', function() {
|
|
133
|
-
// console.log(prefix + 'Finished');
|
|
134
|
-
// });
|
|
135
|
-
// });
|
|
136
|
-
// f.once('error', function(error) {
|
|
137
|
-
// console.log('Fetch error: ' + error);
|
|
138
|
-
// });
|
|
139
|
-
// f.once('end', function() {
|
|
140
|
-
// console.log('Done fetching all messages!');
|
|
141
|
-
// that._imap.end();
|
|
142
|
-
// });
|
|
143
|
-
// });
|
|
144
|
-
// });
|
|
145
|
-
// });
|
|
146
|
-
// this._imap.connect();
|
|
147
|
-
this._aws = new aws.S3({
|
|
148
|
-
accessKeyId: serverConfig.AWSACCESSKEYID,
|
|
149
|
-
secretAccessKey: serverConfig.AWSSECRETACCESSKEY,
|
|
150
|
-
region: serverConfig.AWSREGION
|
|
151
|
-
});
|
|
152
|
-
setInterval(function () {
|
|
153
|
-
if (!_this._runningQueue) {
|
|
154
|
-
if (_this._sendQueue.length) {
|
|
155
|
-
_this._runningQueue = true;
|
|
156
|
-
var _loop_1 = function (i) {
|
|
157
|
-
var ws = _this._mainServer.getWS(_this._sendQueue[i].id_ws);
|
|
158
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
159
|
-
if (ws.bufferedAmount < 20480) {
|
|
160
|
-
var sendItem = _this._sendQueue.pop();
|
|
161
|
-
ws.send(JSON.stringify(sendItem.data), function (error) {
|
|
162
|
-
if (error) {
|
|
163
|
-
console.log('Error on WS: ', error);
|
|
164
|
-
_this._mainServer.unsubscribeWS(ws);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
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 !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave' && sendItem.method !== 'getDrivers') {
|
|
168
|
-
if (common_1.getBinarySize(JSON.stringify(sendItem.methodData)) < 200000 && common_1.getBinarySize(JSON.stringify(sendItem.data)) < 200000) {
|
|
169
|
-
log_collection_1.Logs.create({
|
|
170
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
171
|
-
date: new Date(),
|
|
172
|
-
type: 'client-response',
|
|
173
|
-
title: 'Client Response',
|
|
174
|
-
message: 'User: ' + ws['user'] + ', MessageId: ' + sendItem.data.messageId + ', Method: ' + sendItem.method,
|
|
175
|
-
payload: JSON.stringify([sendItem.methodData, sendItem.data]),
|
|
176
|
-
method: sendItem.method,
|
|
177
|
-
user: ws['user'],
|
|
178
|
-
messageId: sendItem.data.messageId
|
|
179
|
-
});
|
|
180
|
-
method_response_collection_1.MethodResponses.create({
|
|
181
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
182
|
-
__v: 0,
|
|
183
|
-
id_user: ws['id_user'],
|
|
184
|
-
message_id: sendItem.data.messageId,
|
|
185
|
-
response: sendItem.data,
|
|
186
|
-
method: sendItem.method,
|
|
187
|
-
date: sendItem.date
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
log_collection_1.Logs.create({
|
|
192
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
193
|
-
date: new Date(),
|
|
194
|
-
type: 'client-response',
|
|
195
|
-
title: 'Client Response',
|
|
196
|
-
message: 'User: ' + ws['user'] + ', MessageId: ' + sendItem.data.messageId + ', Method: ' + sendItem.method,
|
|
197
|
-
payload: 'Too Big',
|
|
198
|
-
method: sendItem.method,
|
|
199
|
-
user: ws['user'],
|
|
200
|
-
messageId: sendItem.data.messageId
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
_this._sendQueue.splice(i, 1);
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
for (var i = _this._sendQueue.length - 1; i >= 0; i--) {
|
|
211
|
-
_loop_1(i);
|
|
212
|
-
}
|
|
213
|
-
_this._runningQueue = false;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}, 25);
|
|
217
|
-
}
|
|
218
|
-
MethodManager.prototype.getMainServer = function () {
|
|
219
|
-
return this._mainServer;
|
|
220
|
-
};
|
|
221
|
-
// Add methods to private methods object
|
|
222
|
-
MethodManager.prototype.methods = function (method) {
|
|
223
|
-
this._methods = Object.assign(this._methods, method);
|
|
224
|
-
};
|
|
225
|
-
MethodManager.prototype.callMethodCron = function (method) {
|
|
226
|
-
var methodData = [];
|
|
227
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
228
|
-
methodData[_i - 1] = arguments[_i];
|
|
229
|
-
}
|
|
230
|
-
var _a;
|
|
231
|
-
var that = this;
|
|
232
|
-
if (!that._methods[method]) {
|
|
233
|
-
console.log('No Method: ' + method);
|
|
234
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Method: ' + method);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
if ((methodData.length > 1 || methodData[0]) && !that._methods[method].skipValidation) {
|
|
238
|
-
if (!that._methods[method].check) {
|
|
239
|
-
console.error('No Check Function For Method ' + method);
|
|
240
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
else if (!that._methods[method].check._schema) {
|
|
244
|
-
console.error('No Check Schema For Method ' + method);
|
|
245
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
var valObj = {};
|
|
250
|
-
var valKeys = Object.keys(that._methods[method].check._schema);
|
|
251
|
-
var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
252
|
-
for (var i = 0; i < methodData.length; i++) {
|
|
253
|
-
valObj[rootKeys[i]] = methodData[i];
|
|
254
|
-
}
|
|
255
|
-
try {
|
|
256
|
-
that._methods[method].check.validate(valObj);
|
|
257
|
-
}
|
|
258
|
-
catch (errors) {
|
|
259
|
-
if (errors) {
|
|
260
|
-
console.error('Error in Method Check (' + method + ')', errors);
|
|
261
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.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));
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
(_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: '', user: '', id_ws: '' })].concat(methodData));
|
|
268
|
-
};
|
|
269
|
-
MethodManager.prototype.callMethodQueue = function (update) {
|
|
270
|
-
var _this = this;
|
|
271
|
-
// console.log('Call Method Queue', update);
|
|
272
|
-
return new Promise(function (resolve, reject) {
|
|
273
|
-
var _a;
|
|
274
|
-
var updateCopy = common_1.deepCopy(update);
|
|
275
|
-
var that = _this;
|
|
276
|
-
if (!that._methods[update.method]) {
|
|
277
|
-
console.log('No Method: ' + update.method);
|
|
278
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Method: ' + update.method);
|
|
279
|
-
var serverRes = {
|
|
280
|
-
messageId: update.messageId,
|
|
281
|
-
hasError: true,
|
|
282
|
-
data: 'Internal Error'
|
|
283
|
-
};
|
|
284
|
-
_this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
|
|
285
|
-
return resolve('No Method: ' + update.method);
|
|
286
|
-
}
|
|
287
|
-
if ((update.method_data.length > 1 || update.method_data[0]) && !that._methods[update.method].skipValidation) {
|
|
288
|
-
if (!that._methods[update.method].check) {
|
|
289
|
-
console.error('No Check Function For Method ' + update.method);
|
|
290
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + update.method);
|
|
291
|
-
var serverRes = {
|
|
292
|
-
messageId: update.messageId,
|
|
293
|
-
hasError: true,
|
|
294
|
-
data: 'Internal Error'
|
|
295
|
-
};
|
|
296
|
-
_this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
|
|
297
|
-
return resolve('No Check Function For Method ' + update.method);
|
|
298
|
-
}
|
|
299
|
-
else if (!that._methods[update.method].check._schema) {
|
|
300
|
-
console.error('No Check Schema For Method ' + update.method);
|
|
301
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + update.method);
|
|
302
|
-
var serverRes = {
|
|
303
|
-
messageId: update.messageId,
|
|
304
|
-
hasError: true,
|
|
305
|
-
data: 'Internal Error'
|
|
306
|
-
};
|
|
307
|
-
_this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
|
|
308
|
-
return resolve('No Check Schema For Method ' + update.method);
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
var valObj = {};
|
|
312
|
-
var valKeys = Object.keys(that._methods[update.method].check._schema);
|
|
313
|
-
var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
314
|
-
for (var i = 0; i < update.method_data.length; i++) {
|
|
315
|
-
valObj[rootKeys[i]] = update.method_data[i];
|
|
316
|
-
}
|
|
317
|
-
try {
|
|
318
|
-
that._methods[update.method].check.validate(valObj);
|
|
319
|
-
}
|
|
320
|
-
catch (errors) {
|
|
321
|
-
if (errors) {
|
|
322
|
-
console.error('Error in Method Check (' + update.method + ')', errors);
|
|
323
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Match Error On Method ' + update.method + '\n\nData Being Checked\n' + JSON.stringify(valObj, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
324
|
-
var serverRes = {
|
|
325
|
-
messageId: update.messageId,
|
|
326
|
-
hasError: true,
|
|
327
|
-
data: 'Internal Error'
|
|
328
|
-
};
|
|
329
|
-
_this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
|
|
330
|
-
return resolve('Error in Method Check (' + update.method + ')');
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
var timeout = setTimeout(function () {
|
|
336
|
-
console.error('Timeout on method', update);
|
|
337
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'Timeout on method: ', [update]);
|
|
338
|
-
resolve('Timeout');
|
|
339
|
-
}, 5000);
|
|
340
|
-
// console.log('Run Method', update.method);
|
|
341
|
-
(_a = that._methods[update.method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: update.id_user, user: update.user, id_ws: update.id_ws })].concat(update.method_data)).then(function (res) {
|
|
342
|
-
var serverRes = {
|
|
343
|
-
messageId: update.messageId,
|
|
344
|
-
hasError: false,
|
|
345
|
-
data: res
|
|
346
|
-
};
|
|
347
|
-
_this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
|
|
348
|
-
clearTimeout(timeout);
|
|
349
|
-
resolve(serverRes);
|
|
350
|
-
}, function (err) {
|
|
351
|
-
var serverRes = {
|
|
352
|
-
messageId: update.messageId,
|
|
353
|
-
hasError: true,
|
|
354
|
-
data: err
|
|
355
|
-
};
|
|
356
|
-
_this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
|
|
357
|
-
clearTimeout(timeout);
|
|
358
|
-
resolve(serverRes);
|
|
359
|
-
});
|
|
360
|
-
});
|
|
361
|
-
};
|
|
362
|
-
// Call/run method (Emit on Socket)
|
|
363
|
-
MethodManager.prototype.callMethod = function (ws, messageDate, messageId, method) {
|
|
364
|
-
var _this = this;
|
|
365
|
-
var methodData = [];
|
|
366
|
-
for (var _i = 4; _i < arguments.length; _i++) {
|
|
367
|
-
methodData[_i - 4] = arguments[_i];
|
|
368
|
-
}
|
|
369
|
-
var _a;
|
|
370
|
-
var that = this;
|
|
371
|
-
if (!that._methods[method]) {
|
|
372
|
-
console.log('No Method: ' + method);
|
|
373
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Method: ' + method);
|
|
374
|
-
var serverRes = {
|
|
375
|
-
messageId: messageId,
|
|
376
|
-
hasError: true,
|
|
377
|
-
data: 'Internal Error'
|
|
378
|
-
};
|
|
379
|
-
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
if ((methodData.length > 1 || methodData[0]) && !that._methods[method].skipValidation) {
|
|
383
|
-
if (!that._methods[method].check) {
|
|
384
|
-
console.error('No Check Function For Method ' + method);
|
|
385
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
386
|
-
var serverRes = {
|
|
387
|
-
messageId: messageId,
|
|
388
|
-
hasError: true,
|
|
389
|
-
data: 'Internal Error'
|
|
390
|
-
};
|
|
391
|
-
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
else if (!that._methods[method].check._schema) {
|
|
395
|
-
console.error('No Check Schema For Method ' + method);
|
|
396
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
397
|
-
var serverRes = {
|
|
398
|
-
messageId: messageId,
|
|
399
|
-
hasError: true,
|
|
400
|
-
data: 'Internal Error'
|
|
401
|
-
};
|
|
402
|
-
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
var valObj = {};
|
|
407
|
-
var valKeys = Object.keys(that._methods[method].check._schema);
|
|
408
|
-
var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
409
|
-
for (var i = 0; i < methodData.length; i++) {
|
|
410
|
-
valObj[rootKeys[i]] = methodData[i];
|
|
411
|
-
}
|
|
412
|
-
try {
|
|
413
|
-
that._methods[method].check.validate(valObj);
|
|
414
|
-
}
|
|
415
|
-
catch (errors) {
|
|
416
|
-
if (errors) {
|
|
417
|
-
console.error('Error in Method Check (' + method + ')', errors);
|
|
418
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.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));
|
|
419
|
-
var serverRes = {
|
|
420
|
-
messageId: messageId,
|
|
421
|
-
hasError: true,
|
|
422
|
-
data: 'Internal Error'
|
|
423
|
-
};
|
|
424
|
-
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
(_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
|
|
431
|
-
var serverRes = {
|
|
432
|
-
messageId: messageId,
|
|
433
|
-
hasError: false,
|
|
434
|
-
data: res
|
|
435
|
-
};
|
|
436
|
-
_this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
437
|
-
}, function (err) {
|
|
438
|
-
var serverRes = {
|
|
439
|
-
messageId: messageId,
|
|
440
|
-
hasError: true,
|
|
441
|
-
data: err
|
|
442
|
-
};
|
|
443
|
-
_this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
444
|
-
});
|
|
445
|
-
};
|
|
446
|
-
// Call/run method internal (No Emit on Socket)
|
|
447
|
-
MethodManager.prototype.callMethodInternal = function (method) {
|
|
448
|
-
var methodData = [];
|
|
449
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
450
|
-
methodData[_i - 1] = arguments[_i];
|
|
451
|
-
}
|
|
452
|
-
var _a;
|
|
453
|
-
var that = this;
|
|
454
|
-
if (!that._methods[method]) {
|
|
455
|
-
console.log('No Method: ' + method);
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
if ((methodData.length > 1 || (methodData[0] && typeof (methodData[0]) !== 'function')) && !that._methods[method].skipValidation) {
|
|
459
|
-
if (!that._methods[method].check) {
|
|
460
|
-
console.error('No Check Function For Method ' + method);
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
else if (!that._methods[method].check._schema) {
|
|
464
|
-
console.error('No Check Schema For Method ' + method);
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
var promise = (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype)].concat(methodData));
|
|
469
|
-
if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
|
|
470
|
-
promise.then(function (res) { return methodData[methodData.length - 1](null, res); }, function (err) { return methodData[methodData.length - 1](err, null); });
|
|
471
|
-
}
|
|
472
|
-
return promise;
|
|
473
|
-
};
|
|
474
|
-
MethodManager.prototype.callSupportMethodInternal = function (supportMethod) {
|
|
475
|
-
var methodData = [];
|
|
476
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
477
|
-
methodData[_i - 1] = arguments[_i];
|
|
478
|
-
}
|
|
479
|
-
var _a;
|
|
480
|
-
var that = this;
|
|
481
|
-
if (!that.getMainServer().getSupportManager()._supportMethods[supportMethod]) {
|
|
482
|
-
console.log('No Support Method: ' + supportMethod);
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
if ((methodData.length > 1 || (methodData[0] && typeof (methodData[0]) !== 'function')) && !that.getMainServer().getSupportManager()._supportMethods[supportMethod].skipValidation) {
|
|
486
|
-
if (!that.getMainServer().getSupportManager()._supportMethods[supportMethod].check) {
|
|
487
|
-
console.error('No Check Function For Method ' + supportMethod);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
else if (!that.getMainServer().getSupportManager()._supportMethods[supportMethod].check._schema) {
|
|
491
|
-
console.error('No Check Schema For Method ' + supportMethod);
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
var promise = (_a = that.getMainServer().getSupportManager()._supportMethods[supportMethod].function).call.apply(_a, [Object.assign({}, that, support_manager_1.SupportManager.prototype)].concat(methodData));
|
|
496
|
-
if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
|
|
497
|
-
promise.then(function (res) { return methodData[methodData.length - 1](null, res); }, function (err) { return methodData[methodData.length - 1](err, null); });
|
|
498
|
-
}
|
|
499
|
-
return promise;
|
|
500
|
-
};
|
|
501
|
-
MethodManager.prototype.sendWS = function (ws, messageDate, method, methodData, data) {
|
|
502
|
-
this._sendQueue.splice(0, 0, {
|
|
503
|
-
id_ws: ws['id_socket'],
|
|
504
|
-
method: method,
|
|
505
|
-
methodData: methodData,
|
|
506
|
-
data: data,
|
|
507
|
-
date: messageDate
|
|
508
|
-
});
|
|
509
|
-
};
|
|
510
|
-
MethodManager.prototype.sendEmail = function (sendTo, subject, text, html, attachments, send_from) {
|
|
511
|
-
this._mailer.sendMail({
|
|
512
|
-
replyTo: undefined,
|
|
513
|
-
from: send_from ? send_from : this.serverConfig.MAIL_FROM,
|
|
514
|
-
to: sendTo,
|
|
515
|
-
subject: subject,
|
|
516
|
-
text: text,
|
|
517
|
-
html: html,
|
|
518
|
-
attachments: attachments
|
|
519
|
-
}, function (err, info) {
|
|
520
|
-
if (err) {
|
|
521
|
-
console.log(err);
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
};
|
|
525
|
-
MethodManager.prototype.getAWS = function () {
|
|
526
|
-
return this._aws;
|
|
527
|
-
};
|
|
528
|
-
MethodManager.prototype.readFile = function (fileName) {
|
|
529
|
-
var _this = this;
|
|
530
|
-
return new Promise(function (resolve, reject) {
|
|
531
|
-
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
532
|
-
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'utf-8', function (err, res) {
|
|
533
|
-
if (err) {
|
|
534
|
-
reject(err);
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
resolve(res);
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
else {
|
|
542
|
-
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
543
|
-
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'utf-8', function (err, res) {
|
|
544
|
-
if (err) {
|
|
545
|
-
reject(err);
|
|
546
|
-
}
|
|
547
|
-
else {
|
|
548
|
-
resolve(res);
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
};
|
|
555
|
-
MethodManager.prototype.readImage = function (fileName) {
|
|
556
|
-
var _this = this;
|
|
557
|
-
return new Promise(function (resolve, reject) {
|
|
558
|
-
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
559
|
-
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'base64', function (err, res) {
|
|
560
|
-
if (err) {
|
|
561
|
-
reject(err);
|
|
562
|
-
}
|
|
563
|
-
else {
|
|
564
|
-
resolve(res);
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
else {
|
|
569
|
-
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
570
|
-
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'base64', function (err, res) {
|
|
571
|
-
if (err) {
|
|
572
|
-
reject(err);
|
|
573
|
-
}
|
|
574
|
-
else {
|
|
575
|
-
resolve(res);
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
};
|
|
582
|
-
return MethodManager;
|
|
583
|
-
}());
|
|
584
|
-
exports.MethodManager = MethodManager;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { QueueMethodModel } from '../models/queue-method.model';
|
|
2
|
-
import { ServerResponseModel } from '../models/server-response.model';
|
|
3
|
-
export declare class QueueMethodManager {
|
|
4
|
-
private _mainServer;
|
|
5
|
-
private _sendQueue;
|
|
6
|
-
private _runningQueue;
|
|
7
|
-
private _runningMethodResponse;
|
|
8
|
-
constructor(mainServer: any);
|
|
9
|
-
addMethodToQueue(id_ws: string, id_user: string, user: string, messageDate: Date, messageId: string, method: string, data: any[]): void;
|
|
10
|
-
runMethodQueue(count?: number): Promise<void>;
|
|
11
|
-
addMethodResponse(update: QueueMethodModel, response: ServerResponseModel): void;
|
|
12
|
-
runMethodResponse(): Promise<void>;
|
|
13
|
-
}
|