@resolveio/server-lib 1.0.0-rc28 → 1.0.0-rc3

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.
Files changed (159) hide show
  1. package/collections/active-subscription.collection.js +1 -68
  2. package/collections/app-status.collection.js +1 -43
  3. package/collections/app-version.collection.js +1 -56
  4. package/collections/counter.collection.js +1 -73
  5. package/collections/cron-job-history.collection.js +1 -86
  6. package/collections/cron-job.collection.js +1 -89
  7. package/collections/file.collection.js +1 -73
  8. package/collections/flag.collection.js +1 -47
  9. package/collections/log.collection.js +1 -64
  10. package/collections/logged-in-users.collection.js +1 -70
  11. package/collections/method-call.collection.js +1 -44
  12. package/collections/method-response.collection.js +1 -48
  13. package/collections/queue-flag.collection.js +1 -41
  14. package/collections/queue-method.collection.js +1 -116
  15. package/collections/queue-response.collection.js +1 -78
  16. package/collections/support-ticket.collection.js +1 -146
  17. package/collections/user.collection.js +1 -108
  18. package/cron/cron.js +1 -160
  19. package/fixtures/cron-jobs.js +1 -72
  20. package/fixtures/init.js +1 -73
  21. package/http/auth.js +1 -472
  22. package/http/health.js +1 -8
  23. package/index.js +1 -125
  24. package/managers/cron.manager.js +1 -193
  25. package/managers/method.manager.js +1 -544
  26. package/managers/queue-method.manager.js +1 -239
  27. package/managers/subscription.manager.js +1 -700
  28. package/managers/support.manager.js +1 -208
  29. package/methods/accounts.js +1 -253
  30. package/methods/aws.js +1 -345
  31. package/methods/cloudconvert.js +1 -37
  32. package/methods/collections.js +1 -738
  33. package/methods/counters.js +1 -404
  34. package/methods/cron-jobs.js +1 -63
  35. package/methods/flags.js +1 -6
  36. package/methods/logs.js +1 -29
  37. package/methods/pdf.js +1 -303
  38. package/models/active-subscription.model.js +1 -2
  39. package/models/app-status.model.js +1 -2
  40. package/models/app-version.model.js +1 -2
  41. package/models/collection-document.model.js +1 -2
  42. package/models/counter.model.js +1 -2
  43. package/models/cron-job-history.model.js +1 -2
  44. package/models/cron-job.model.js +1 -2
  45. package/models/dialog.model.js +1 -2
  46. package/models/file.model.js +1 -2
  47. package/models/flag.model.js +1 -2
  48. package/models/log.model.js +1 -2
  49. package/models/logged-in-users.model.js +1 -2
  50. package/models/method-call.model.js +1 -2
  51. package/models/method-response.model.js +1 -2
  52. package/models/method.model.js +1 -2
  53. package/models/pagination.model.js +1 -20
  54. package/models/permission.model.js +1 -2
  55. package/models/queue-method.model.js +1 -2
  56. package/models/queue-response.model.js +1 -2
  57. package/models/select-data-label.model.js +1 -2
  58. package/models/server-response.model.js +1 -2
  59. package/models/subscription.model.js +1 -2
  60. package/models/support-method.model.js +1 -2
  61. package/models/support-ticket.model.js +1 -2
  62. package/models/user.model.js +1 -2
  63. package/package.json +2 -5
  64. package/publications/app-status.js +1 -14
  65. package/publications/app-version.js +1 -14
  66. package/publications/cron-jobs.js +1 -14
  67. package/publications/files.js +1 -71
  68. package/publications/flags.js +1 -23
  69. package/publications/logs.js +1 -26
  70. package/publications/method-calls.js +1 -14
  71. package/publications/method-responses.js +1 -14
  72. package/publications/super-admin.js +1 -21
  73. package/publications/support-tickets.js +1 -118
  74. package/server-app.js +1 -641
  75. package/support-methods/aws.js +1 -276
  76. package/support-methods/collections.js +1 -471
  77. package/support-methods/counters.js +1 -189
  78. package/support-methods/support.js +1 -19
  79. package/util/common.js +1 -334
  80. package/collections/active-subscription.collection.d.ts +0 -8
  81. package/collections/app-status.collection.d.ts +0 -8
  82. package/collections/app-version.collection.d.ts +0 -8
  83. package/collections/counter.collection.d.ts +0 -10
  84. package/collections/cron-job-history.collection.d.ts +0 -8
  85. package/collections/cron-job.collection.d.ts +0 -8
  86. package/collections/file.collection.d.ts +0 -10
  87. package/collections/flag.collection.d.ts +0 -8
  88. package/collections/log.collection.d.ts +0 -8
  89. package/collections/logged-in-users.collection.d.ts +0 -8
  90. package/collections/method-call.collection.d.ts +0 -7
  91. package/collections/method-response.collection.d.ts +0 -7
  92. package/collections/queue-flag.collection.d.ts +0 -8
  93. package/collections/queue-method.collection.d.ts +0 -8
  94. package/collections/queue-response.collection.d.ts +0 -8
  95. package/collections/support-ticket.collection.d.ts +0 -8
  96. package/collections/user.collection.d.ts +0 -9
  97. package/cron/cron.d.ts +0 -6
  98. package/fixtures/cron-jobs.d.ts +0 -2
  99. package/fixtures/init.d.ts +0 -2
  100. package/http/auth.d.ts +0 -3
  101. package/http/health.d.ts +0 -2
  102. package/index.d.ts +0 -17
  103. package/managers/cron.manager.d.ts +0 -17
  104. package/managers/method.manager.d.ts +0 -28
  105. package/managers/queue-method.manager.d.ts +0 -14
  106. package/managers/subscription.manager.d.ts +0 -27
  107. package/managers/support.manager.d.ts +0 -18
  108. package/methods/accounts.d.ts +0 -3
  109. package/methods/aws.d.ts +0 -3
  110. package/methods/cloudconvert.d.ts +0 -3
  111. package/methods/collections.d.ts +0 -3
  112. package/methods/counters.d.ts +0 -3
  113. package/methods/cron-jobs.d.ts +0 -3
  114. package/methods/flags.d.ts +0 -3
  115. package/methods/logs.d.ts +0 -3
  116. package/methods/pdf.d.ts +0 -3
  117. package/models/active-subscription.model.d.ts +0 -14
  118. package/models/app-status.model.d.ts +0 -5
  119. package/models/app-version.model.d.ts +0 -5
  120. package/models/collection-document.model.d.ts +0 -7
  121. package/models/counter.model.d.ts +0 -6
  122. package/models/cron-job-history.model.d.ts +0 -13
  123. package/models/cron-job.model.d.ts +0 -14
  124. package/models/dialog.model.d.ts +0 -24
  125. package/models/file.model.d.ts +0 -10
  126. package/models/flag.model.d.ts +0 -6
  127. package/models/log.model.d.ts +0 -12
  128. package/models/logged-in-users.model.d.ts +0 -10
  129. package/models/method-call.model.d.ts +0 -8
  130. package/models/method-response.model.d.ts +0 -9
  131. package/models/method.model.d.ts +0 -11
  132. package/models/notification.model.d.ts +0 -5
  133. package/models/notification.model.js +0 -2
  134. package/models/pagination.model.d.ts +0 -12
  135. package/models/permission.model.d.ts +0 -13
  136. package/models/queue-method.model.d.ts +0 -10
  137. package/models/queue-response.model.d.ts +0 -11
  138. package/models/select-data-label.model.d.ts +0 -10
  139. package/models/server-response.model.d.ts +0 -6
  140. package/models/subscription.model.d.ts +0 -31
  141. package/models/support-method.model.d.ts +0 -10
  142. package/models/support-ticket.model.d.ts +0 -40
  143. package/models/user.model.d.ts +0 -15
  144. package/publications/app-status.d.ts +0 -3
  145. package/publications/app-version.d.ts +0 -3
  146. package/publications/cron-jobs.d.ts +0 -3
  147. package/publications/files.d.ts +0 -3
  148. package/publications/flags.d.ts +0 -3
  149. package/publications/logs.d.ts +0 -3
  150. package/publications/method-calls.d.ts +0 -3
  151. package/publications/method-responses.d.ts +0 -3
  152. package/publications/super-admin.d.ts +0 -3
  153. package/publications/support-tickets.d.ts +0 -2
  154. package/server-app.d.ts +0 -34
  155. package/support-methods/aws.d.ts +0 -3
  156. package/support-methods/collections.d.ts +0 -3
  157. package/support-methods/counters.d.ts +0 -3
  158. package/support-methods/support.d.ts +0 -3
  159. package/util/common.d.ts +0 -15
package/server-app.js CHANGED
@@ -1,641 +1 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- 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;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- var http_1 = require("http");
39
- var express = require("express");
40
- var mongoose = require("mongoose");
41
- var bodyParser = require("body-parser");
42
- var passport = require("passport");
43
- var passportlocal = require("passport-local");
44
- var WebSocket = require("ws");
45
- var jwt = require("jsonwebtoken");
46
- var uuid = require("uuid/v4");
47
- var auth_1 = require("./http/auth");
48
- var common_1 = require("./util/common");
49
- var health_1 = require("./http/health");
50
- var method_call_collection_1 = require("./collections/method-call.collection");
51
- var mongoose_1 = require("mongoose");
52
- var method_response_collection_1 = require("./collections/method-response.collection");
53
- var log_collection_1 = require("./collections/log.collection");
54
- var moment = require("moment");
55
- var user_collection_1 = require("./collections/user.collection");
56
- var cron_manager_1 = require("./managers/cron.manager");
57
- var method_manager_1 = require("./managers/method.manager");
58
- var subscription_manager_1 = require("./managers/subscription.manager");
59
- var support_manager_1 = require("./managers/support.manager");
60
- var queue_method_manager_1 = require("./managers/queue-method.manager");
61
- var ResolveIOMainServer = /** @class */ (function () {
62
- function ResolveIOMainServer(mainServer, serverConfig, clientDir) {
63
- this._resolveioServer = mainServer;
64
- this._serverConfig = serverConfig;
65
- this._clientDir = clientDir;
66
- // process.on('unhandledException').
67
- // Start express app
68
- this._app = express();
69
- // Use body parser for http call (login)
70
- this._app.use(bodyParser.json({ limit: '5mb' }));
71
- this._app.use(bodyParser.urlencoded({ limit: '5mb', extended: true }));
72
- // Set port
73
- this._port = process.env.PORT || serverConfig['PORT'];
74
- // Create http server and websock server
75
- this.createServer();
76
- // Set CORS
77
- this._app.use(function (req, res, next) {
78
- // Website you wish to allow to connect
79
- // res.setHeader('Access-Control-Allow-Origin', serverConfig['ROOT_URL']);
80
- res.setHeader('Access-Control-Allow-Origin', '*');
81
- // Request methods you wish to allow
82
- // res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
83
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
84
- // Request headers you wish to allow
85
- res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
86
- // Set to true if you need the website to include cookies in the requests sent
87
- // to the API (e.g. in case you use sessions)
88
- res.setHeader('Access-Control-Allow-Credentials', 'false');
89
- // Pass to next layer of middleware
90
- next();
91
- });
92
- // Set up http login route
93
- auth_1.setupAuthRoutes(this, this._app, serverConfig);
94
- health_1.setupHealthRoutes(this._app, serverConfig);
95
- }
96
- ResolveIOMainServer.prototype.getWS = function (id_ws) {
97
- var res = null;
98
- this._wss.clients.forEach(function (ws) {
99
- if (ws['id_socket'] === id_ws) {
100
- res = ws;
101
- }
102
- });
103
- return res;
104
- };
105
- ResolveIOMainServer.prototype.getWSList = function () {
106
- var res = [];
107
- this._wss.clients.forEach(function (ws) {
108
- res.push(ws['id_socket']);
109
- });
110
- return res;
111
- };
112
- ResolveIOMainServer.prototype.getCronManager = function () {
113
- return this._cronManager;
114
- };
115
- ResolveIOMainServer.prototype.getMethodManager = function () {
116
- return this._methodManager;
117
- };
118
- ResolveIOMainServer.prototype.getSubscriptionManager = function () {
119
- return this._subscriptionManager;
120
- };
121
- ResolveIOMainServer.prototype.getQueueManager = function () {
122
- return this._queueManager;
123
- };
124
- ResolveIOMainServer.prototype.getSupportManager = function () {
125
- return this._supportManager;
126
- };
127
- ResolveIOMainServer.prototype.createServer = function () {
128
- var _this = this;
129
- // Start express server
130
- this._server = http_1.createServer(this._app);
131
- // Start websocket server
132
- // Verify client with token before opening socket
133
- this._wss = new WebSocket.Server({
134
- server: this._server,
135
- verifyClient: function (info, cb) { return __awaiter(_this, void 0, void 0, function () {
136
- var infoData, token;
137
- var _this = this;
138
- return __generator(this, function (_a) {
139
- infoData = info.req.headers['sec-websocket-protocol'].split(/,/);
140
- 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']) {
141
- cb(false, 401, 'Unauthorized');
142
- }
143
- else {
144
- if (infoData[1]) { //app version
145
- token = infoData[0];
146
- if (!token) {
147
- cb(false, 401, 'Unauthorized');
148
- }
149
- else {
150
- jwt.verify(token, this._serverConfig['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
151
- var user, err_1;
152
- return __generator(this, function (_a) {
153
- switch (_a.label) {
154
- case 0:
155
- if (!err) return [3 /*break*/, 1];
156
- cb(false, 401, 'Unauthorized');
157
- return [3 /*break*/, 5];
158
- case 1:
159
- info.req['id_user'] = decoded['id_user'];
160
- _a.label = 2;
161
- case 2:
162
- _a.trys.push([2, 4, , 5]);
163
- return [4 /*yield*/, user_collection_1.Users.findById(decoded['id_user']).exec()];
164
- case 3:
165
- user = _a.sent();
166
- if (user) {
167
- info.req['user'] = user.fullname;
168
- cb(true);
169
- }
170
- else {
171
- cb(false);
172
- }
173
- return [3 /*break*/, 5];
174
- case 4:
175
- err_1 = _a.sent();
176
- cb(false);
177
- return [3 /*break*/, 5];
178
- case 5: return [2 /*return*/];
179
- }
180
- });
181
- }); });
182
- }
183
- }
184
- else {
185
- cb(false, 401, 'Invalid Version');
186
- }
187
- }
188
- return [2 /*return*/];
189
- });
190
- }); }
191
- });
192
- // Start Mongoose (MongoDB Connection)
193
- this.setUpMongoose();
194
- };
195
- ResolveIOMainServer.prototype.setUpMongoose = function () {
196
- this.setUpPassport();
197
- // Enable lean by default
198
- var __setOptions = mongoose_1.Query.prototype.setOptions;
199
- mongoose_1.Query.prototype.setOptions = function (options) {
200
- if (this._mongooseOptions.lean == null && this.mongooseCollection.collectionName !== 'users') {
201
- this._mongooseOptions.lean = true;
202
- }
203
- __setOptions.apply(this, arguments);
204
- return this;
205
- };
206
- // Start Managers
207
- this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this._wss, this._serverConfig);
208
- this._methodManager = new method_manager_1.MethodManager(this, this._serverConfig, this._clientDir);
209
- this._supportManager = new support_manager_1.SupportManager(this, this._serverConfig);
210
- this._cronManager = new cron_manager_1.CronManager(this);
211
- this._queueManager = new queue_method_manager_1.QueueMethodManager(this);
212
- this.listen();
213
- mongoose.set('useFindAndModify', false);
214
- // mongoose.set('useCreateIndexes', true);
215
- };
216
- ResolveIOMainServer.prototype.setUpPassport = function () {
217
- // Set up login passort
218
- this._app.use(passport.initialize());
219
- // Start user authentication
220
- passport.use(new passportlocal.Strategy(user_collection_1.Users.authenticate()));
221
- passport.serializeUser(user_collection_1.Users.serializeUser());
222
- passport.deserializeUser(user_collection_1.Users.deserializeUser());
223
- };
224
- // Listen to port for http/websocket
225
- ResolveIOMainServer.prototype.listen = function () {
226
- var _this = this;
227
- this._server.listen(this._port, function () {
228
- console.log('Running server on port %s', _this._port);
229
- });
230
- // On websocket connection (already verified)
231
- this._wss.on('connection', function (ws, req) {
232
- // Get user from token
233
- ws['id_user'] = req.id_user;
234
- ws['user'] = req.user;
235
- ws['id_socket'] = uuid();
236
- ws['retryCnt'] = 0;
237
- // Use for keeping connection alive (ping/pong)
238
- ws['isAlive'] = true;
239
- ws.on('pong', function () {
240
- ws['isAlive'] = true;
241
- ws['pongTime'] = new Date();
242
- ws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();
243
- _this._subscriptionManager.loggedInLatency(ws);
244
- });
245
- ws['versionTimer'] = setTimeout(function () {
246
- _this.unsubscribeWS(ws);
247
- ws.terminate();
248
- }, 10000);
249
- // On data received (message)
250
- ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
251
- var _a, _b, _c, _d, _e, data, messageId, type, method, serverRes, methodCall, subType, pub, supportMethod, serverRes;
252
- var _this = this;
253
- return __generator(this, function (_f) {
254
- switch (_f.label) {
255
- case 0:
256
- data = JSON.parse(message, common_1.dateReviver);
257
- // console.log(data);
258
- if (data[0] === 'ping') {
259
- if (ws && ws.readyState === ws.OPEN) {
260
- ws.send('pong', function (error) {
261
- if (error) {
262
- console.log('Error on WS: ', error);
263
- _this.unsubscribeWS(ws);
264
- }
265
- });
266
- }
267
- return [2 /*return*/];
268
- }
269
- messageId = data.shift();
270
- type = data.shift();
271
- method = '';
272
- if (!(type === 'method')) return [3 /*break*/, 8];
273
- method = data.shift();
274
- if (method === 'setWSAppVersion') {
275
- clearTimeout(ws['versionTimer']);
276
- }
277
- if (method === 'disconnectWSCommand') {
278
- setTimeout(function () {
279
- _this.unsubscribeWS(ws);
280
- ws.terminate();
281
- }, 5000);
282
- }
283
- if (method !== 'countQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion') {
284
- if (common_1.getBinarySize(JSON.stringify(data)) < 200000) {
285
- log_collection_1.Logs.create({
286
- _id: mongoose_1.Types.ObjectId().toHexString(),
287
- date: new Date(),
288
- type: 'client-request',
289
- title: 'Client Request - Method',
290
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
291
- payload: data,
292
- method: method,
293
- user: ws['user'],
294
- messageId: messageId
295
- });
296
- }
297
- else {
298
- log_collection_1.Logs.create({
299
- _id: mongoose_1.Types.ObjectId().toHexString(),
300
- date: new Date(),
301
- type: 'client-request',
302
- title: 'Client Request - Method',
303
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
304
- payload: 'Too Big',
305
- method: method,
306
- user: ws['user'],
307
- messageId: messageId
308
- });
309
- }
310
- }
311
- serverRes = {
312
- messageId: messageId,
313
- hasError: false,
314
- data: 'ACK'
315
- };
316
- if (ws && ws.readyState === ws.OPEN) {
317
- ws.send(JSON.stringify(serverRes), function (error) {
318
- if (error) {
319
- console.log('Error on WS: ', error);
320
- _this.unsubscribeWS(ws);
321
- }
322
- });
323
- }
324
- if (!this._methodManager._methods[method]) return [3 /*break*/, 6];
325
- if (!this._methodManager._methods[method].skipQueue) return [3 /*break*/, 1];
326
- (_a = this._methodManager).callMethod.apply(_a, [ws, messageId, method].concat(data));
327
- return [3 /*break*/, 5];
328
- case 1: return [4 /*yield*/, method_call_collection_1.MethodCalls.findOne({ $and: [
329
- { id_user: ws['id_user'] },
330
- { message_id: messageId },
331
- { method: method },
332
- { data: JSON.stringify(data) }
333
- ] }).exec()];
334
- case 2:
335
- methodCall = _f.sent();
336
- if (!!methodCall) return [3 /*break*/, 4];
337
- return [4 /*yield*/, method_call_collection_1.MethodCalls.create({
338
- _id: mongoose_1.Types.ObjectId().toHexString(),
339
- __v: 0,
340
- id_user: ws['id_user'],
341
- message_id: messageId,
342
- method: method,
343
- data: JSON.stringify(data)
344
- })];
345
- case 3:
346
- _f.sent();
347
- if (this._methodManager._methods[method]) {
348
- if (this._methodManager._methods[method].skipQueue) {
349
- (_b = this._methodManager).callMethod.apply(_b, [ws, messageId, method].concat(data));
350
- }
351
- else {
352
- this._queueManager.addMethodToQueue(ws['id_socket'], ws['id_user'], ws['user'], messageId, method, data);
353
- }
354
- }
355
- else {
356
- console.log('Could not find method: ' + method);
357
- }
358
- return [3 /*break*/, 5];
359
- case 4:
360
- method_response_collection_1.MethodResponses.findOne({ $and: [
361
- { id_user: ws['id_user'] },
362
- { message_id: messageId },
363
- { method: method },
364
- { data: JSON.stringify(data) }
365
- ] }).exec(function (err, res) {
366
- if (res) {
367
- if (ws && ws.readyState === ws.OPEN) {
368
- ws.send(JSON.stringify(res.response), function (error) {
369
- if (error) {
370
- console.log('Error on WS: ', error);
371
- _this.unsubscribeWS(ws);
372
- }
373
- });
374
- }
375
- }
376
- });
377
- _f.label = 5;
378
- case 5: return [3 /*break*/, 7];
379
- case 6:
380
- console.log('Could not find method: ' + method);
381
- _f.label = 7;
382
- case 7: return [3 /*break*/, 9];
383
- case 8:
384
- if (type === 'methodRetry') {
385
- method = data.shift();
386
- if (method !== 'countQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion') {
387
- if (common_1.getBinarySize(JSON.stringify(data)) < 200000) {
388
- log_collection_1.Logs.create({
389
- _id: mongoose_1.Types.ObjectId().toHexString(),
390
- date: new Date(),
391
- type: 'client-request',
392
- title: 'Client Request - Method Retry',
393
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
394
- payload: data,
395
- method: method,
396
- user: ws['user'],
397
- messageId: messageId
398
- });
399
- }
400
- else {
401
- log_collection_1.Logs.create({
402
- _id: mongoose_1.Types.ObjectId().toHexString(),
403
- date: new Date(),
404
- type: 'client-request',
405
- title: 'Client Request - Method Retry',
406
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
407
- payload: 'Too Big',
408
- method: method,
409
- user: ws['user'],
410
- messageId: messageId
411
- });
412
- }
413
- }
414
- method_call_collection_1.MethodCalls.findOne({ $and: [
415
- { id_user: ws['id_user'] },
416
- { message_id: messageId },
417
- { method: method },
418
- { data: JSON.stringify(data) }
419
- ] }).exec(function (err, res) {
420
- if (res) {
421
- var serverRes = {
422
- messageId: messageId,
423
- hasError: false,
424
- data: 'ACK'
425
- };
426
- if (ws && ws.readyState === ws.OPEN) {
427
- ws.send(JSON.stringify(serverRes), function (error) {
428
- if (error) {
429
- console.log('Error on WS: ', error);
430
- _this.unsubscribeWS(ws);
431
- }
432
- });
433
- }
434
- }
435
- else {
436
- var serverRes = {
437
- messageId: messageId,
438
- hasError: false,
439
- data: 'NACK'
440
- };
441
- if (ws && ws.readyState === ws.OPEN) {
442
- ws.send(JSON.stringify(serverRes), function (error) {
443
- if (error) {
444
- console.log('Error on WS: ', error);
445
- _this.unsubscribeWS(ws);
446
- }
447
- });
448
- }
449
- }
450
- });
451
- }
452
- else if (type === 'methodResponse') {
453
- method = data.shift();
454
- if (method !== 'countQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion') {
455
- if (common_1.getBinarySize(JSON.stringify(data)) < 200000) {
456
- log_collection_1.Logs.create({
457
- _id: mongoose_1.Types.ObjectId().toHexString(),
458
- date: new Date(),
459
- type: 'client-request',
460
- title: 'Client Request - Method Response',
461
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
462
- payload: data,
463
- method: method,
464
- user: ws['user'],
465
- messageId: messageId
466
- });
467
- }
468
- else {
469
- log_collection_1.Logs.create({
470
- _id: mongoose_1.Types.ObjectId().toHexString(),
471
- date: new Date(),
472
- type: 'client-request',
473
- title: 'Client Request - Method Response',
474
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
475
- payload: 'Too Big',
476
- method: method,
477
- user: ws['user'],
478
- messageId: messageId
479
- });
480
- }
481
- }
482
- method_response_collection_1.MethodResponses.findOne({ $and: [
483
- { id_user: ws['id_user'] },
484
- { message_id: messageId },
485
- { method: method },
486
- { data: JSON.stringify(data) }
487
- ] }).exec(function (err, res) {
488
- if (res) {
489
- if (ws && ws.readyState === ws.OPEN) {
490
- ws.send(JSON.stringify(res.response), function (error) {
491
- if (error) {
492
- console.log('Error on WS: ', error);
493
- _this.unsubscribeWS(ws);
494
- }
495
- });
496
- }
497
- }
498
- });
499
- }
500
- // Subscription call
501
- else if (type === 'subscription') {
502
- subType = data.shift();
503
- pub = data.shift();
504
- // Subscribe
505
- if (subType === 'sub') {
506
- (_c = this._subscriptionManager).subscribe.apply(_c, [ws, messageId, pub].concat(data));
507
- }
508
- // Unsubscribe
509
- else {
510
- (_d = this._subscriptionManager).unsubscribe.apply(_d, [ws, messageId, pub].concat(data));
511
- }
512
- }
513
- else if (type === 'support') {
514
- supportMethod = data.shift();
515
- // if (supportMethod !== 'countQuery' && supportMethod !== 'countCollectionWithQuery' && supportMethod !== 'find' && supportMethod !== 'findOne' && supportMethod !== 'findWithOptions' && method !== 'setWSAppVersion' && method !== 'uploadFileAndSave') {
516
- if (common_1.getBinarySize(JSON.stringify(data)) < 200000) {
517
- log_collection_1.Logs.create({
518
- _id: mongoose_1.Types.ObjectId().toHexString(),
519
- date: new Date(),
520
- type: 'client-request',
521
- title: 'Client Request - Support',
522
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Support Method: ' + supportMethod,
523
- payload: data,
524
- method: supportMethod,
525
- user: ws['user'],
526
- messageId: messageId
527
- });
528
- }
529
- else {
530
- log_collection_1.Logs.create({
531
- _id: mongoose_1.Types.ObjectId().toHexString(),
532
- date: new Date(),
533
- type: 'client-request',
534
- title: 'Client Request - Support',
535
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Support Method: ' + supportMethod,
536
- payload: 'Too Big',
537
- method: supportMethod,
538
- user: ws['user'],
539
- messageId: messageId
540
- });
541
- }
542
- serverRes = {
543
- messageId: messageId,
544
- hasError: false,
545
- data: 'ACK'
546
- };
547
- if (ws && ws.readyState === ws.OPEN) {
548
- ws.send(JSON.stringify(serverRes), function (error) {
549
- if (error) {
550
- console.log('Error on WS: ', error);
551
- _this.unsubscribeWS(ws);
552
- }
553
- });
554
- }
555
- if (this._supportManager._supportMethods[supportMethod]) {
556
- (_e = this._supportManager).callSupportMethod.apply(_e, [ws, messageId, supportMethod].concat(data));
557
- }
558
- else {
559
- console.log('Could not find support method: ' + supportMethod);
560
- }
561
- }
562
- _f.label = 9;
563
- case 9: return [2 /*return*/];
564
- }
565
- });
566
- }); });
567
- ws.on('close', function () {
568
- _this.unsubscribeWS(ws);
569
- });
570
- });
571
- // Keep alive timer to ping/pong
572
- setInterval(function () {
573
- _this._wss.clients.forEach(function (ws) {
574
- if (ws['isAlive'] === false) {
575
- ws['retryCnt']++;
576
- if (ws['retryCnt'] >= 12) {
577
- _this.unsubscribeWS(ws);
578
- ws.terminate();
579
- }
580
- else {
581
- ws['pingTime'] = new Date();
582
- ws.ping(function () { });
583
- }
584
- }
585
- else {
586
- ws['retryCnt'] = 0;
587
- ws['isAlive'] = false;
588
- ws['pingTime'] = new Date();
589
- ws.ping(function () { });
590
- }
591
- });
592
- }, 5000);
593
- };
594
- ResolveIOMainServer.prototype.unsubscribeWS = function (ws) {
595
- this._subscriptionManager.unsubscribeAll(ws);
596
- };
597
- return ResolveIOMainServer;
598
- }());
599
- exports.default = ResolveIOMainServer;
600
- // export * from './collections/active-subscription.collection';
601
- // export * from './collections/app-status.collection';
602
- // export * from './collections/app-version.collection';
603
- // export * from './collections/counter.collection';
604
- // export * from './collections/cron-job-history.collection';
605
- // export * from './collections/cron-job.collection';
606
- // export * from './collections/file.collection';
607
- // export * from './collections/flag.collection';
608
- // export * from './collections/log.collection';
609
- // export * from './collections/logged-in-users.collection';
610
- // export * from './collections/method-call.collection';
611
- // export * from './collections/method-response.collection';
612
- // export * from './collections/queue-flag.collection';
613
- // export * from './collections/queue-method.collection';
614
- // export * from './collections/queue-response.collection';
615
- // export * from './collections/support-ticket.collection';
616
- // export * from './collections/user.collection';
617
- // export * from './managers/cron.manager';
618
- // export * from './managers/method.manager';
619
- // export * from './managers/queue-method.manager';
620
- // export * from './managers/subscription.manager';
621
- // export * from './managers/support.manager';
622
- // export * from './models/active-subscription.model';
623
- // export * from './models/app-status.model';
624
- // export * from './models/app-version.model';
625
- // export * from './models/collection-document.model';
626
- // export * from './models/counter.model';
627
- // // export * from './models/cron-job-history.model';
628
- // export * from './models/cron-job.model';
629
- // export * from './models/dialog.model';
630
- // export * from './models/file.model';
631
- // export * from './models/flag.model';
632
- // export * from './models/log.model';
633
- // export * from './models/method.model';
634
- // export * from './models/pagination.model';
635
- // export * from './models/permission.model';
636
- // export * from './models/select-data-label.model';
637
- // export * from './models/server-response.model';
638
- // export * from './models/support-method.model';
639
- // export * from './models/support-ticket.model';
640
- // export * from './models/user.model';
641
- // export * from './util/common';
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(n,i,a,u){return new(a||(a=Promise))(function(e,t){function o(e){try{r(u.next(e))}catch(e){t(e)}}function s(e){try{r(u.throw(e))}catch(e){t(e)}}function r(t){t.done?e(t.value):new a(function(e){e(t.value)}).then(o,s)}r((u=u.apply(n,i||[])).next())})},__generator=this&&this.__generator||function(o,s){var r,n,i,e,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&t[0]?n.return:t[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,t[1])).done)return i;switch(n=0,i&&(t=[2&t[0],i.value]),t[0]){case 0:case 1:i=t;break;case 4:return a.label++,{value:t[1],done:!1};case 5:a.label++,n=t[1],t=[0];continue;case 7:t=a.ops.pop(),a.trys.pop();continue;default:if(!(i=0<(i=a.trys).length&&i[i.length-1])&&(6===t[0]||2===t[0])){a=0;continue}if(3===t[0]&&(!i||t[1]>i[0]&&t[1]<i[3])){a.label=t[1];break}if(6===t[0]&&a.label<i[1]){a.label=i[1],i=t;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(t);break}i[2]&&a.ops.pop(),a.trys.pop();continue}t=s.call(o,a)}catch(e){t=[6,e],n=0}finally{r=i=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}};Object.defineProperty(exports,"__esModule",{value:!0});var http_1=require("http"),express=require("express"),mongoose=require("mongoose"),bodyParser=require("body-parser"),passport=require("passport"),passportlocal=require("passport-local"),WebSocket=require("ws"),jwt=require("jsonwebtoken"),uuid=require("uuid/v4"),auth_1=require("./http/auth"),common_1=require("./util/common"),health_1=require("./http/health"),method_call_collection_1=require("./collections/method-call.collection"),mongoose_1=require("mongoose"),method_response_collection_1=require("./collections/method-response.collection"),log_collection_1=require("./collections/log.collection"),moment=require("moment"),user_collection_1=require("./collections/user.collection"),cron_manager_1=require("./managers/cron.manager"),method_manager_1=require("./managers/method.manager"),subscription_manager_1=require("./managers/subscription.manager"),support_manager_1=require("./managers/support.manager"),queue_method_manager_1=require("./managers/queue-method.manager"),ResolveIOMainServer=function(){function e(e,t){this._resolveioServer=e,this._serverConfig=t,this._app=express(),this._app.use(bodyParser.json({limit:"5mb"})),this._app.use(bodyParser.urlencoded({limit:"5mb",extended:!0})),this._port=process.env.PORT||t.PORT,this.createServer(),this._app.use(function(e,t,o){t.setHeader("Access-Control-Allow-Origin","*"),t.setHeader("Access-Control-Allow-Methods","GET, POST"),t.setHeader("Access-Control-Allow-Headers","X-Requested-With,content-type"),t.setHeader("Access-Control-Allow-Credentials","false"),o()}),auth_1.setupAuthRoutes(this,this._app,t),health_1.setupHealthRoutes(this._app,t)}return e.prototype.getWS=function(t){var o=null;return this._wss.clients.forEach(function(e){e.id_socket===t&&(o=e)}),o},e.prototype.getWSList=function(){var t=[];return this._wss.clients.forEach(function(e){t.push(e.id_socket)}),t},e.prototype.getCronManager=function(){return this._cronManager},e.prototype.getMethodManager=function(){return this._methodManager},e.prototype.getSubscriptionManager=function(){return this._subscriptionManager},e.prototype.getQueueManager=function(){return this._queueManager},e.prototype.getSupportManager=function(){return this._supportManager},e.prototype.createServer=function(){var e=this;this._server=http_1.createServer(this._app),this._wss=new WebSocket.Server({server:this._server,verifyClient:function(n,i){return __awaiter(e,void 0,void 0,function(){var t,o,r=this;return __generator(this,function(e){return t=n.req.headers["sec-websocket-protocol"].split(/,/),n.origin!==this._serverConfig.ROOT_URL&&n.origin!==this._serverConfig.SEC_ROOT_URL&&n.origin!==this._serverConfig.RESOLVEIO_URL&&n.origin!==this._serverConfig.RESOLVEIO_SECONDARY_URL?i(!1,401,"Unauthorized"):t[1]?(o=t[0])?jwt.verify(o,this._serverConfig.JWT_SECRET,function(o,s){return __awaiter(r,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return o?(i(!1,401,"Unauthorized"),[3,5]):[3,1];case 1:n.req.id_user=s.id_user,e.label=2;case 2:return e.trys.push([2,4,,5]),[4,user_collection_1.Users.findById(s.id_user).exec()];case 3:return(t=e.sent())?(n.req.user=t.fullname,i(!0)):i(!1),[3,5];case 4:return e.sent(),i(!1),[3,5];case 5:return[2]}})})}):i(!1,401,"Unauthorized"):i(!1,401,"Invalid Version"),[2]})})}}),this.setUpMongoose()},e.prototype.setUpMongoose=function(){this.setUpPassport();var t=mongoose_1.Query.prototype.setOptions;mongoose_1.Query.prototype.setOptions=function(e){return null==this._mongooseOptions.lean&&"users"!==this.mongooseCollection.collectionName&&(this._mongooseOptions.lean=!0),t.apply(this,arguments),this},this._subscriptionManager=new subscription_manager_1.SubscriptionManager(this,this._wss,this._serverConfig),this._methodManager=new method_manager_1.MethodManager(this,this._serverConfig),this._supportManager=new support_manager_1.SupportManager(this,this._serverConfig),this._cronManager=new cron_manager_1.CronManager(this),this._queueManager=new queue_method_manager_1.QueueMethodManager(this),this.listen(),mongoose.set("useFindAndModify",!1)},e.prototype.setUpPassport=function(){this._app.use(passport.initialize()),passport.use(new passportlocal.Strategy(user_collection_1.Users.authenticate())),passport.serializeUser(user_collection_1.Users.serializeUser()),passport.deserializeUser(user_collection_1.Users.deserializeUser())},e.prototype.listen=function(){var t=this;this._server.listen(this._port,function(){console.log("Running server on port %s",t._port)}),this._wss.on("connection",function(m,e){m.id_user=e.id_user,m.user=e.user,m.id_socket=uuid(),m.retryCnt=0,m.isAlive=!0,m.on("pong",function(){m.isAlive=!0,m.pongTime=new Date,m.latency=moment.duration(moment(m.pongTime).diff(m.pingTime)).asMilliseconds(),t._subscriptionManager.loggedInLatency(m)}),m.versionTimer=setTimeout(function(){t.unsubscribeWS(m),m.terminate()},1e4),m.on("message",function(h){return __awaiter(t,void 0,void 0,function(){var t,o,s,r,n,i,a,u,c,l,d,p,_,g=this;return __generator(this,function(e){switch(e.label){case 0:return"ping"===(i=JSON.parse(h,common_1.dateReviver))[0]?(m&&m.readyState===m.OPEN&&m.send("pong",function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))}),[2]):(a=i.shift(),u=i.shift(),c="","method"!==u?[3,8]:("setWSAppVersion"===(c=i.shift())&&clearTimeout(m.versionTimer),"disconnectWSCommand"===c&&setTimeout(function(){g.unsubscribeWS(m),m.terminate()},5e3),"countQuery"!==c&&"countCollectionWithQuery"!==c&&"find"!==c&&"findOne"!==c&&"findWithOptions"!==c&&"setWSAppVersion"!==c&&(common_1.getBinarySize(JSON.stringify(i))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:i,method:c,user:m.user,messageId:a}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:"Too Big",method:c,user:m.user,messageId:a})),_={messageId:a,hasError:!1,data:"ACK"},m&&m.readyState===m.OPEN&&m.send(JSON.stringify(_),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))}),this._methodManager._methods[c]?this._methodManager._methods[c].skipQueue?((t=this._methodManager).callMethod.apply(t,[m,a,c].concat(i)),[3,5]):[3,1]:[3,6]));case 1:return[4,method_call_collection_1.MethodCalls.findOne({$and:[{id_user:m.id_user},{message_id:a},{method:c},{data:JSON.stringify(i)}]}).exec()];case 2:return e.sent()?[3,4]:[4,method_call_collection_1.MethodCalls.create({_id:mongoose_1.Types.ObjectId().toHexString(),__v:0,id_user:m.id_user,message_id:a,method:c,data:JSON.stringify(i)})];case 3:return e.sent(),this._methodManager._methods[c]?this._methodManager._methods[c].skipQueue?(o=this._methodManager).callMethod.apply(o,[m,a,c].concat(i)):this._queueManager.addMethodToQueue(m.id_socket,m.id_user,m.user,a,c,i):console.log("Could not find method: "+c),[3,5];case 4:method_response_collection_1.MethodResponses.findOne({$and:[{id_user:m.id_user},{message_id:a},{method:c},{data:JSON.stringify(i)}]}).exec(function(e,t){t&&m&&m.readyState===m.OPEN&&m.send(JSON.stringify(t.response),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))})}),e.label=5;case 5:return[3,7];case 6:console.log("Could not find method: "+c),e.label=7;case 7:return[3,9];case 8:"methodRetry"===u?("countQuery"!==(c=i.shift())&&"countCollectionWithQuery"!==c&&"find"!==c&&"findOne"!==c&&"findWithOptions"!==c&&"setWSAppVersion"!==c&&(common_1.getBinarySize(JSON.stringify(i))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method Retry",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:i,method:c,user:m.user,messageId:a}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method Retry",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:"Too Big",method:c,user:m.user,messageId:a})),method_call_collection_1.MethodCalls.findOne({$and:[{id_user:m.id_user},{message_id:a},{method:c},{data:JSON.stringify(i)}]}).exec(function(e,t){if(t){var o={messageId:a,hasError:!1,data:"ACK"};m&&m.readyState===m.OPEN&&m.send(JSON.stringify(o),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))})}else{o={messageId:a,hasError:!1,data:"NACK"};m&&m.readyState===m.OPEN&&m.send(JSON.stringify(o),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))})}})):"methodResponse"===u?("countQuery"!==(c=i.shift())&&"countCollectionWithQuery"!==c&&"find"!==c&&"findOne"!==c&&"findWithOptions"!==c&&"setWSAppVersion"!==c&&(common_1.getBinarySize(JSON.stringify(i))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method Response",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:i,method:c,user:m.user,messageId:a}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method Response",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:"Too Big",method:c,user:m.user,messageId:a})),method_response_collection_1.MethodResponses.findOne({$and:[{id_user:m.id_user},{message_id:a},{method:c},{data:JSON.stringify(i)}]}).exec(function(e,t){t&&m&&m.readyState===m.OPEN&&m.send(JSON.stringify(t.response),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))})})):"subscription"===u?(l=i.shift(),d=i.shift(),"sub"===l?(s=this._subscriptionManager).subscribe.apply(s,[m,a,d].concat(i)):(r=this._subscriptionManager).unsubscribe.apply(r,[m,a,d].concat(i))):"support"===u&&(p=i.shift(),common_1.getBinarySize(JSON.stringify(i))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Support",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Support Method: "+p,payload:i,method:p,user:m.user,messageId:a}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Support",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Support Method: "+p,payload:"Too Big",method:p,user:m.user,messageId:a}),_={messageId:a,hasError:!1,data:"ACK"},m&&m.readyState===m.OPEN&&m.send(JSON.stringify(_),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))}),this._supportManager._supportMethods[p]?(n=this._supportManager).callSupportMethod.apply(n,[m,a,p].concat(i)):console.log("Could not find support method: "+p)),e.label=9;case 9:return[2]}})})}),m.on("close",function(){t.unsubscribeWS(m)})}),setInterval(function(){t._wss.clients.forEach(function(e){!1===e.isAlive?(e.retryCnt++,12<=e.retryCnt?(t.unsubscribeWS(e),e.terminate()):(e.pingTime=new Date,e.ping(function(){}))):(e.retryCnt=0,e.isAlive=!1,e.pingTime=new Date,e.ping(function(){}))})},5e3)},e.prototype.unsubscribeWS=function(e){this._subscriptionManager.unsubscribeAll(e)},e}();exports.ResolveIOMainServer=ResolveIOMainServer;