@resolveio/server-lib 3.0.1 → 3.0.2-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.
- package/collections/user.collection.js +45 -34
- package/fixtures/init.js +1 -1
- package/models/user.model.d.ts +22 -5
- package/package.json +1 -1
- package/server-app.js +50 -45
|
@@ -21,13 +21,6 @@ var schema = {
|
|
|
21
21
|
type: Date,
|
|
22
22
|
optional: true
|
|
23
23
|
},
|
|
24
|
-
readonly: {
|
|
25
|
-
type: Boolean,
|
|
26
|
-
optional: true
|
|
27
|
-
},
|
|
28
|
-
active: {
|
|
29
|
-
type: Boolean
|
|
30
|
-
},
|
|
31
24
|
attempts: {
|
|
32
25
|
type: Number,
|
|
33
26
|
optional: true
|
|
@@ -64,60 +57,78 @@ var schema = {
|
|
|
64
57
|
type: String
|
|
65
58
|
},
|
|
66
59
|
roles: {
|
|
60
|
+
type: Object
|
|
61
|
+
},
|
|
62
|
+
'roles.super_admin': {
|
|
63
|
+
type: Boolean
|
|
64
|
+
},
|
|
65
|
+
'roles.approvals': {
|
|
67
66
|
type: Array
|
|
68
67
|
},
|
|
69
|
-
'roles.$': {
|
|
68
|
+
'roles.approvals.$': {
|
|
69
|
+
type: Object
|
|
70
|
+
},
|
|
71
|
+
'roles.approvals.$.name': {
|
|
70
72
|
type: String
|
|
71
73
|
},
|
|
72
|
-
|
|
73
|
-
type: String
|
|
74
|
-
optional: true
|
|
74
|
+
'roles.approvals.$.type': {
|
|
75
|
+
type: String
|
|
75
76
|
},
|
|
76
|
-
|
|
77
|
-
type:
|
|
78
|
-
blackbox: true,
|
|
79
|
-
optional: true
|
|
77
|
+
'roles.approvals.$.accounting_code': {
|
|
78
|
+
type: String
|
|
80
79
|
},
|
|
81
|
-
|
|
82
|
-
type: Array
|
|
83
|
-
optional: true
|
|
80
|
+
'roles.groups': {
|
|
81
|
+
type: Array
|
|
84
82
|
},
|
|
85
|
-
'
|
|
83
|
+
'roles.groups.$': {
|
|
86
84
|
type: Object
|
|
87
85
|
},
|
|
88
|
-
'
|
|
86
|
+
'roles.groups.$.name': {
|
|
89
87
|
type: String
|
|
90
88
|
},
|
|
91
|
-
'
|
|
92
|
-
type:
|
|
89
|
+
'roles.groups.$.views': {
|
|
90
|
+
type: Array
|
|
93
91
|
},
|
|
94
|
-
'
|
|
92
|
+
'roles.groups.$.views.$': {
|
|
95
93
|
type: String
|
|
96
94
|
},
|
|
97
|
-
'
|
|
98
|
-
type: String
|
|
95
|
+
'roles.groups.$.yard': {
|
|
96
|
+
type: String,
|
|
97
|
+
optional: true
|
|
99
98
|
},
|
|
100
|
-
'
|
|
99
|
+
'roles.notifications': {
|
|
100
|
+
type: Array
|
|
101
|
+
},
|
|
102
|
+
'roles.notifications.$': {
|
|
101
103
|
type: String
|
|
102
104
|
},
|
|
103
|
-
'
|
|
104
|
-
type:
|
|
105
|
+
'roles.miscs': {
|
|
106
|
+
type: Array
|
|
105
107
|
},
|
|
106
|
-
'
|
|
107
|
-
type:
|
|
108
|
-
optional: true
|
|
108
|
+
'roles.miscs.$': {
|
|
109
|
+
type: String
|
|
109
110
|
},
|
|
110
|
-
|
|
111
|
+
active: Boolean,
|
|
112
|
+
id_customer: {
|
|
111
113
|
type: String,
|
|
112
114
|
optional: true
|
|
113
115
|
},
|
|
114
116
|
customer: {
|
|
115
117
|
type: String,
|
|
116
|
-
optional: true
|
|
118
|
+
optional: true
|
|
117
119
|
},
|
|
118
|
-
|
|
120
|
+
customer_type: {
|
|
121
|
+
type: String,
|
|
122
|
+
optional: true
|
|
123
|
+
},
|
|
124
|
+
phonenumber: {
|
|
119
125
|
type: String,
|
|
126
|
+
optional: true
|
|
127
|
+
},
|
|
128
|
+
other: {
|
|
129
|
+
type: Object,
|
|
120
130
|
optional: true,
|
|
131
|
+
blackbox: true
|
|
121
132
|
}
|
|
122
133
|
};
|
|
123
134
|
var DefaultSchema = new mongoose_1.Schema(schema, {
|
package/fixtures/init.js
CHANGED
|
@@ -37,8 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
var app_version_collection_1 = require("../collections/app-version.collection");
|
|
39
39
|
var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
|
|
40
|
-
var active_subscription_collection_1 = require("../collections/active-subscription.collection");
|
|
41
40
|
var mongoose_1 = require("mongoose");
|
|
41
|
+
var active_subscription_collection_1 = require("../collections/active-subscription.collection");
|
|
42
42
|
function loadServerInit() {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function () {
|
|
44
44
|
var appVersion;
|
package/models/user.model.d.ts
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import { CollectionDocument } from './collection-document.model';
|
|
2
2
|
export interface UserModel extends CollectionDocument {
|
|
3
|
-
attempts: number;
|
|
4
|
-
last: Date;
|
|
5
|
-
services?: any;
|
|
6
3
|
fullname: string;
|
|
4
|
+
roles: UserRoleModel;
|
|
7
5
|
username?: string;
|
|
8
6
|
email?: string;
|
|
9
|
-
roles?: string[];
|
|
10
7
|
active?: boolean;
|
|
11
|
-
|
|
8
|
+
services?: any;
|
|
9
|
+
id_customer?: string;
|
|
10
|
+
customer?: string;
|
|
11
|
+
customer_type?: string;
|
|
12
12
|
phonenumber?: string;
|
|
13
13
|
other?: object;
|
|
14
14
|
}
|
|
15
|
+
export interface UserRoleModel {
|
|
16
|
+
super_admin: boolean;
|
|
17
|
+
approvals: UserRoleApprovalModel[];
|
|
18
|
+
groups: UserRoleGroupModel[];
|
|
19
|
+
notifications: string[];
|
|
20
|
+
miscs: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface UserRoleApprovalModel {
|
|
23
|
+
accounting_code: string;
|
|
24
|
+
type: string;
|
|
25
|
+
name: string;
|
|
26
|
+
}
|
|
27
|
+
export interface UserRoleGroupModel {
|
|
28
|
+
name: string;
|
|
29
|
+
views: string[];
|
|
30
|
+
yard?: string;
|
|
31
|
+
}
|
package/package.json
CHANGED
package/server-app.js
CHANGED
|
@@ -58,6 +58,7 @@ var method_manager_1 = require("./managers/method.manager");
|
|
|
58
58
|
var subscription_manager_1 = require("./managers/subscription.manager");
|
|
59
59
|
var support_manager_1 = require("./managers/support.manager");
|
|
60
60
|
var queue_method_manager_1 = require("./managers/queue-method.manager");
|
|
61
|
+
var common_2 = require("./util/common");
|
|
61
62
|
var ResolveIOMainServer = /** @class */ (function () {
|
|
62
63
|
function ResolveIOMainServer(mainServer, serverConfig, clientDir) {
|
|
63
64
|
this._msgQueue = [];
|
|
@@ -250,13 +251,43 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
250
251
|
}, 10000);
|
|
251
252
|
// On data received (message)
|
|
252
253
|
ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
253
|
-
var data;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
254
|
+
var _a, _b, socketData, data, messageDate, messageId, type, subType, pub;
|
|
255
|
+
var _this = this;
|
|
256
|
+
return __generator(this, function (_c) {
|
|
257
|
+
socketData = JSON.parse(message, common_1.dateReviver);
|
|
258
|
+
data = common_2.deepCopy(socketData);
|
|
259
|
+
if (data[0] === 'ping') {
|
|
260
|
+
if (ws && ws.readyState === ws.OPEN) {
|
|
261
|
+
ws.send('pong', function (error) {
|
|
262
|
+
if (error) {
|
|
263
|
+
console.log('Error on WS: ', error);
|
|
264
|
+
_this.unsubscribeWS(ws);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return [2 /*return*/];
|
|
269
|
+
}
|
|
270
|
+
messageDate = data.shift();
|
|
271
|
+
messageId = data.shift();
|
|
272
|
+
type = data.shift();
|
|
273
|
+
if (type === 'subscription') {
|
|
274
|
+
subType = data.shift();
|
|
275
|
+
pub = data.shift();
|
|
276
|
+
// Subscribe
|
|
277
|
+
if (subType === 'sub') {
|
|
278
|
+
(_a = this._subscriptionManager).subscribe.apply(_a, [ws, messageId, pub].concat(data));
|
|
279
|
+
}
|
|
280
|
+
// Unsubscribe
|
|
281
|
+
else {
|
|
282
|
+
(_b = this._subscriptionManager).unsubscribe.apply(_b, [ws, messageId, pub].concat(data));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
this._msgQueue.splice(0, 0, {
|
|
287
|
+
ws: ws,
|
|
288
|
+
data: socketData
|
|
289
|
+
});
|
|
290
|
+
}
|
|
260
291
|
return [2 /*return*/];
|
|
261
292
|
});
|
|
262
293
|
}); });
|
|
@@ -287,32 +318,21 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
287
318
|
});
|
|
288
319
|
}, 5000);
|
|
289
320
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
290
|
-
var _loop_1, this_1, i
|
|
321
|
+
var _loop_1, this_1, i;
|
|
291
322
|
var _this = this;
|
|
292
323
|
return __generator(this, function (_a) {
|
|
293
324
|
switch (_a.label) {
|
|
294
325
|
case 0:
|
|
295
326
|
if (!!this._msgQueueRunning) return [3 /*break*/, 5];
|
|
327
|
+
this._msgQueueRunning = true;
|
|
296
328
|
_loop_1 = function (i) {
|
|
297
|
-
var _a, _b,
|
|
298
|
-
return __generator(this, function (
|
|
299
|
-
switch (
|
|
329
|
+
var _a, _b, msg, data, ws, messageDate, messageId, type, method, serverRes, query, methodCall, supportMethod, serverRes;
|
|
330
|
+
return __generator(this, function (_c) {
|
|
331
|
+
switch (_c.label) {
|
|
300
332
|
case 0:
|
|
301
|
-
this_1._msgQueueRunning = true;
|
|
302
333
|
msg = this_1._msgQueue.pop();
|
|
303
334
|
data = msg.data;
|
|
304
335
|
ws = msg.ws;
|
|
305
|
-
if (data[0] === 'ping') {
|
|
306
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
307
|
-
ws.send('pong', function (error) {
|
|
308
|
-
if (error) {
|
|
309
|
-
console.log('Error on WS: ', error);
|
|
310
|
-
_this.unsubscribeWS(ws);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
return [2 /*return*/, { value: void 0 }];
|
|
315
|
-
}
|
|
316
336
|
messageDate = data.shift();
|
|
317
337
|
messageId = data.shift();
|
|
318
338
|
type = data.shift();
|
|
@@ -412,7 +432,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
412
432
|
}
|
|
413
433
|
return [4 /*yield*/, method_call_collection_1.MethodCalls.findOne(query).exec()];
|
|
414
434
|
case 1:
|
|
415
|
-
methodCall =
|
|
435
|
+
methodCall = _c.sent();
|
|
416
436
|
if (!!methodCall) return [3 /*break*/, 3];
|
|
417
437
|
return [4 /*yield*/, method_call_collection_1.MethodCalls.create({
|
|
418
438
|
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
@@ -424,7 +444,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
424
444
|
date: messageDate
|
|
425
445
|
})];
|
|
426
446
|
case 2:
|
|
427
|
-
|
|
447
|
+
_c.sent();
|
|
428
448
|
if (this_1._methodManager._methods[method]) {
|
|
429
449
|
if (this_1._methodManager._methods[method].skipQueue) {
|
|
430
450
|
(_a = this_1._methodManager).callMethod.apply(_a, [ws, messageId, method].concat(data));
|
|
@@ -455,11 +475,11 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
455
475
|
}
|
|
456
476
|
}
|
|
457
477
|
});
|
|
458
|
-
|
|
478
|
+
_c.label = 4;
|
|
459
479
|
case 4: return [3 /*break*/, 6];
|
|
460
480
|
case 5:
|
|
461
481
|
console.log('Could not find method: ' + method);
|
|
462
|
-
|
|
482
|
+
_c.label = 6;
|
|
463
483
|
case 6: return [3 /*break*/, 8];
|
|
464
484
|
case 7:
|
|
465
485
|
if (type === 'methodRetry') {
|
|
@@ -604,19 +624,6 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
604
624
|
}
|
|
605
625
|
});
|
|
606
626
|
}
|
|
607
|
-
// Subscription call
|
|
608
|
-
else if (type === 'subscription') {
|
|
609
|
-
subType = data.shift();
|
|
610
|
-
pub = data.shift();
|
|
611
|
-
// Subscribe
|
|
612
|
-
if (subType === 'sub') {
|
|
613
|
-
(_b = this_1._subscriptionManager).subscribe.apply(_b, [ws, messageId, pub].concat(data));
|
|
614
|
-
}
|
|
615
|
-
// Unsubscribe
|
|
616
|
-
else {
|
|
617
|
-
(_c = this_1._subscriptionManager).unsubscribe.apply(_c, [ws, messageId, pub].concat(data));
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
627
|
else if (type === 'support') {
|
|
621
628
|
supportMethod = data.shift();
|
|
622
629
|
// if (supportMethod !== 'countQuery' && supportMethod !== 'countCollectionWithQuery' && supportMethod !== 'find' && supportMethod !== 'findOne' && supportMethod !== 'findWithOptions' && method !== 'setWSAppVersion' && method !== 'uploadFileAndSave') {
|
|
@@ -660,13 +667,13 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
660
667
|
});
|
|
661
668
|
}
|
|
662
669
|
if (this_1._supportManager._supportMethods[supportMethod]) {
|
|
663
|
-
(
|
|
670
|
+
(_b = this_1._supportManager).callSupportMethod.apply(_b, [ws, messageId, supportMethod].concat(data));
|
|
664
671
|
}
|
|
665
672
|
else {
|
|
666
673
|
console.log('Could not find support method: ' + supportMethod);
|
|
667
674
|
}
|
|
668
675
|
}
|
|
669
|
-
|
|
676
|
+
_c.label = 8;
|
|
670
677
|
case 8: return [2 /*return*/];
|
|
671
678
|
}
|
|
672
679
|
});
|
|
@@ -678,9 +685,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
678
685
|
if (!(i >= 0)) return [3 /*break*/, 4];
|
|
679
686
|
return [5 /*yield**/, _loop_1(i)];
|
|
680
687
|
case 2:
|
|
681
|
-
|
|
682
|
-
if (typeof state_1 === "object")
|
|
683
|
-
return [2 /*return*/, state_1.value];
|
|
688
|
+
_a.sent();
|
|
684
689
|
_a.label = 3;
|
|
685
690
|
case 3:
|
|
686
691
|
i--;
|