@resolveio/server-lib 5.2.25 → 5.2.26-newrole
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.
|
@@ -56,6 +56,7 @@ var DefaultSchema = new mongoose_1.Schema(schema, {
|
|
|
56
56
|
versionKey: false,
|
|
57
57
|
timestamps: true
|
|
58
58
|
});
|
|
59
|
+
DefaultSchema.index({ id_ws: 1 });
|
|
59
60
|
exports.LoggedInUsers = index_1.ResolveIOServer.getMainDB().model('logged-in-users', DefaultSchema);
|
|
60
61
|
var vSchema = __assign({}, schema);
|
|
61
62
|
vSchema._id = {
|
|
@@ -22,13 +22,6 @@ var schema = {
|
|
|
22
22
|
type: Date,
|
|
23
23
|
optional: true
|
|
24
24
|
},
|
|
25
|
-
readonly: {
|
|
26
|
-
type: Boolean,
|
|
27
|
-
optional: true
|
|
28
|
-
},
|
|
29
|
-
active: {
|
|
30
|
-
type: Boolean
|
|
31
|
-
},
|
|
32
25
|
attempts: {
|
|
33
26
|
type: Number,
|
|
34
27
|
optional: true
|
|
@@ -65,53 +58,67 @@ var schema = {
|
|
|
65
58
|
type: String
|
|
66
59
|
},
|
|
67
60
|
roles: {
|
|
61
|
+
type: Object
|
|
62
|
+
},
|
|
63
|
+
'roles.super_admin': {
|
|
64
|
+
type: Boolean
|
|
65
|
+
},
|
|
66
|
+
'roles.approvals': {
|
|
68
67
|
type: Array
|
|
69
68
|
},
|
|
70
|
-
'roles.$': {
|
|
69
|
+
'roles.approvals.$': {
|
|
70
|
+
type: Object
|
|
71
|
+
},
|
|
72
|
+
'roles.approvals.$.name': {
|
|
71
73
|
type: String
|
|
72
74
|
},
|
|
73
|
-
|
|
74
|
-
type: String
|
|
75
|
-
optional: true
|
|
75
|
+
'roles.approvals.$.type': {
|
|
76
|
+
type: String
|
|
76
77
|
},
|
|
77
|
-
|
|
78
|
-
type:
|
|
79
|
-
blackbox: true,
|
|
80
|
-
optional: true
|
|
78
|
+
'roles.approvals.$.accounting_code': {
|
|
79
|
+
type: String
|
|
81
80
|
},
|
|
82
|
-
|
|
83
|
-
type: Array
|
|
84
|
-
optional: true
|
|
81
|
+
'roles.groups': {
|
|
82
|
+
type: Array
|
|
85
83
|
},
|
|
86
|
-
'
|
|
84
|
+
'roles.groups.$': {
|
|
87
85
|
type: Object
|
|
88
86
|
},
|
|
89
|
-
'
|
|
87
|
+
'roles.groups.$.name': {
|
|
90
88
|
type: String
|
|
91
89
|
},
|
|
92
|
-
'
|
|
93
|
-
type:
|
|
90
|
+
'roles.groups.$.views': {
|
|
91
|
+
type: Array
|
|
94
92
|
},
|
|
95
|
-
'
|
|
93
|
+
'roles.groups.$.views.$': {
|
|
96
94
|
type: String
|
|
97
95
|
},
|
|
98
|
-
'
|
|
99
|
-
type: String
|
|
96
|
+
'roles.groups.$.yard': {
|
|
97
|
+
type: String,
|
|
98
|
+
optional: true
|
|
99
|
+
},
|
|
100
|
+
'roles.notifications': {
|
|
101
|
+
type: Array
|
|
100
102
|
},
|
|
101
|
-
'
|
|
103
|
+
'roles.notifications.$': {
|
|
102
104
|
type: String
|
|
103
105
|
},
|
|
104
|
-
'
|
|
105
|
-
type:
|
|
106
|
+
'roles.miscs': {
|
|
107
|
+
type: Array
|
|
106
108
|
},
|
|
107
|
-
'
|
|
108
|
-
type:
|
|
109
|
-
optional: true
|
|
109
|
+
'roles.miscs.$': {
|
|
110
|
+
type: String
|
|
110
111
|
},
|
|
111
|
-
|
|
112
|
+
active: Boolean,
|
|
113
|
+
phonenumber: {
|
|
112
114
|
type: String,
|
|
113
115
|
optional: true
|
|
114
116
|
},
|
|
117
|
+
other: {
|
|
118
|
+
type: Object,
|
|
119
|
+
optional: true,
|
|
120
|
+
blackbox: true
|
|
121
|
+
},
|
|
115
122
|
customers: {
|
|
116
123
|
type: Array,
|
|
117
124
|
optional: true,
|
|
@@ -62,6 +62,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
62
62
|
var _this = this;
|
|
63
63
|
this._publications = {};
|
|
64
64
|
this._subscriptions = [];
|
|
65
|
+
this._loggedInUsers = [];
|
|
65
66
|
this._oplogQueue = [];
|
|
66
67
|
this._subCache = [];
|
|
67
68
|
this._cacheId = 0;
|
|
@@ -124,6 +125,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
}, 25);
|
|
128
|
+
logged_in_users_collection_1.LoggedInUsers.find().then(function (loggedInUsers) {
|
|
129
|
+
_this._loggedInUsers = loggedInUsers;
|
|
130
|
+
});
|
|
131
|
+
setInterval(function () {
|
|
132
|
+
for (var i = 0; i < _this._loggedInUsers.length; i++) {
|
|
133
|
+
var loggedInUser = _this._loggedInUsers[i];
|
|
134
|
+
if (!loggedInUser.updatedAt || moment().diff(moment(loggedInUser.updatedAt), 'minutes', true) > 1) {
|
|
135
|
+
_this.unsubscribeAll(_this._mainServer.getWS(loggedInUser.id_ws));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}, 60000);
|
|
127
139
|
}
|
|
128
140
|
// Add all files to publications private object
|
|
129
141
|
SubscriptionManager.prototype.publications = function (method) {
|
|
@@ -149,7 +161,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
149
161
|
subscriptionData[_i - 4] = arguments[_i];
|
|
150
162
|
}
|
|
151
163
|
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
-
var _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub, begDate, endDate, billUser;
|
|
164
|
+
var _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub, newLoggedInUser, begDate, endDate, billUser;
|
|
153
165
|
return __generator(this, function (_c) {
|
|
154
166
|
switch (_c.label) {
|
|
155
167
|
case 0:
|
|
@@ -237,14 +249,16 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
237
249
|
_c.label = 4;
|
|
238
250
|
case 4:
|
|
239
251
|
if (!(publication === 'appversion')) return [3 /*break*/, 6];
|
|
240
|
-
|
|
252
|
+
newLoggedInUser = {
|
|
241
253
|
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
242
254
|
__v: 0,
|
|
243
255
|
date: new Date(),
|
|
244
256
|
id_user: ws['id_user'],
|
|
245
257
|
user: ws['user'],
|
|
246
258
|
id_ws: ws['id_socket']
|
|
247
|
-
}
|
|
259
|
+
};
|
|
260
|
+
this._loggedInUsers.push(newLoggedInUser);
|
|
261
|
+
logged_in_users_collection_1.LoggedInUsers.create(newLoggedInUser);
|
|
248
262
|
if (!(ws['user'] !== 'Admin' && index_1.ResolveIOServer.getSupportDB())) return [3 /*break*/, 6];
|
|
249
263
|
begDate = moment().startOf('month');
|
|
250
264
|
endDate = moment().endOf('month');
|
|
@@ -340,6 +354,9 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
340
354
|
case 1:
|
|
341
355
|
loggedInUser = _a.sent();
|
|
342
356
|
if (loggedInUser) {
|
|
357
|
+
if (this._loggedInUsers.map(function (a) { return a._id; }).indexOf(loggedInUser._id) >= 0) {
|
|
358
|
+
this._loggedInUsers.splice(this._loggedInUsers.map(function (a) { return a._id; }).indexOf(loggedInUser._id), 1);
|
|
359
|
+
}
|
|
343
360
|
logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id }).exec();
|
|
344
361
|
}
|
|
345
362
|
userSubs = that._subscriptions.filter(function (a) { return a.clients.some(function (b) { return b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']; }); });
|
|
@@ -375,6 +392,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
375
392
|
active_subscription_collection_1.ActiveSubscriptions.updateOne({ _id: sub._id }, { $set: { clients: sub.clients } }).exec();
|
|
376
393
|
}
|
|
377
394
|
});
|
|
395
|
+
ws.terminate();
|
|
378
396
|
return [2 /*return*/];
|
|
379
397
|
}
|
|
380
398
|
});
|
package/package.json
CHANGED
package/server-app.js
CHANGED
|
@@ -281,7 +281,6 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
281
281
|
});
|
|
282
282
|
ws['versionTimer'] = setTimeout(function () {
|
|
283
283
|
_this.unsubscribeWS(ws);
|
|
284
|
-
ws.terminate();
|
|
285
284
|
}, 10000);
|
|
286
285
|
// On data received (message)
|
|
287
286
|
ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -345,23 +344,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
345
344
|
ws.on('error', function (error) {
|
|
346
345
|
console.log(error);
|
|
347
346
|
_this.unsubscribeWS(ws);
|
|
348
|
-
ws.terminate();
|
|
349
347
|
});
|
|
350
348
|
});
|
|
351
|
-
// Seems to cause issues
|
|
352
|
-
// process.stdout.on('error', (err) => {
|
|
353
|
-
// if (err.code === "EPIPE") {
|
|
354
|
-
// console.log('EPIPE error found => ignoring');
|
|
355
|
-
// this._wss.clients.forEach((ws: WebSocket) => {
|
|
356
|
-
// if (ws['isAlive'] === false) {
|
|
357
|
-
// if (ws['retryCnt'] >= 60) {
|
|
358
|
-
// this.unsubscribeWS(ws);
|
|
359
|
-
// ws.terminate();
|
|
360
|
-
// }
|
|
361
|
-
// }
|
|
362
|
-
// });
|
|
363
|
-
// }
|
|
364
|
-
// });
|
|
365
349
|
process.on('unhandledRejection', function (reason, p) {
|
|
366
350
|
console.error(reason, 'Unhandled Rejection at Promise', p);
|
|
367
351
|
_this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + _this._serverConfig['CLIENT_NAME'], JSON.stringify([reason, p]));
|
|
@@ -378,7 +362,6 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
378
362
|
ws['retryCnt']++;
|
|
379
363
|
if (ws['retryCnt'] >= 60) {
|
|
380
364
|
_this.unsubscribeWS(ws);
|
|
381
|
-
ws.terminate();
|
|
382
365
|
}
|
|
383
366
|
else {
|
|
384
367
|
ws['pingTime'] = new Date();
|
|
@@ -421,7 +404,6 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
421
404
|
if (method === 'disconnectWSCommand') {
|
|
422
405
|
setTimeout(function () {
|
|
423
406
|
_this.unsubscribeWS(ws);
|
|
424
|
-
ws.terminate();
|
|
425
407
|
}, 5000);
|
|
426
408
|
}
|
|
427
409
|
if (ws['user_readonly']) {
|