@resolveio/server-lib 5.0.7 → 5.0.9-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 +39 -32
- package/fixtures/init.js +1 -1
- package/managers/subscription.manager.js +55 -29
- package/package.json +1 -1
|
@@ -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,
|
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;
|
|
@@ -297,13 +297,6 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
if (!!sub.clients.length) return [3 /*break*/, 2];
|
|
300
|
-
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); }), 1);
|
|
301
|
-
active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
302
|
-
$and: [
|
|
303
|
-
{ publication: publication },
|
|
304
|
-
{ subData: JSON.stringify(subscriptionData) }
|
|
305
|
-
]
|
|
306
|
-
}).exec();
|
|
307
300
|
return [3 /*break*/, 4];
|
|
308
301
|
case 2: return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.findOne({
|
|
309
302
|
$and: [
|
|
@@ -329,7 +322,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
329
322
|
// Unsubscribe from publication
|
|
330
323
|
SubscriptionManager.prototype.unsubscribeAll = function (ws) {
|
|
331
324
|
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
-
var that, loggedInUser, userSubs,
|
|
325
|
+
var that, loggedInUser, userSubs, i, sub, j, activeSubs;
|
|
333
326
|
return __generator(this, function (_a) {
|
|
334
327
|
switch (_a.label) {
|
|
335
328
|
case 0:
|
|
@@ -341,19 +334,16 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
341
334
|
logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id }).exec();
|
|
342
335
|
}
|
|
343
336
|
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']; }); });
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
for (
|
|
337
|
+
for (i = userSubs.length - 1; i >= 0; i--) {
|
|
338
|
+
sub = userSubs[i];
|
|
339
|
+
for (j = sub.clients.length - 1; j >= 0; j--) {
|
|
347
340
|
if (sub.clients[j].id_socket === ws['id_socket']) {
|
|
348
341
|
sub.clients.splice(j, 1);
|
|
349
342
|
}
|
|
350
343
|
}
|
|
351
344
|
if (!sub.clients.length) {
|
|
352
|
-
that._subscriptions.splice(that._subscriptions.findIndex(
|
|
345
|
+
// that._subscriptions.splice(that._subscriptions.findIndex(a => a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)), 1);
|
|
353
346
|
}
|
|
354
|
-
};
|
|
355
|
-
for (i = userSubs.length - 1; i >= 0; i--) {
|
|
356
|
-
_loop_2(i);
|
|
357
347
|
}
|
|
358
348
|
return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.find({ 'clients.id_socket': ws['id_socket'] })];
|
|
359
349
|
case 2:
|
|
@@ -365,7 +355,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
365
355
|
}
|
|
366
356
|
}
|
|
367
357
|
if (!sub.clients.length) {
|
|
368
|
-
|
|
358
|
+
// ActiveSubscriptions.deleteOne({_id: sub._id}).exec();
|
|
369
359
|
}
|
|
370
360
|
else {
|
|
371
361
|
for (var j = sub.clients.length - 1; j >= 0; j--) {
|
|
@@ -511,7 +501,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
511
501
|
var _this = this;
|
|
512
502
|
var that = this;
|
|
513
503
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
514
|
-
var uniqueOplog_1, uniquePubs, needIds_1,
|
|
504
|
+
var uniqueOplog_1, uniquePubs, needIds_1, _loop_2, i, _loop_3, i, i, oplog, _loop_4, j, state_1;
|
|
515
505
|
var _this = this;
|
|
516
506
|
return __generator(this, function (_a) {
|
|
517
507
|
switch (_a.label) {
|
|
@@ -521,13 +511,13 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
521
511
|
this._oplogQueue = [];
|
|
522
512
|
uniquePubs = [];
|
|
523
513
|
needIds_1 = {};
|
|
524
|
-
|
|
514
|
+
_loop_2 = function (i) {
|
|
525
515
|
if (!that._subscriptions.some(function (a) { return a.collections.includes(uniqueOplog_1[i].collection); })) {
|
|
526
516
|
uniqueOplog_1.splice(i, 1);
|
|
527
517
|
}
|
|
528
518
|
};
|
|
529
519
|
for (i = uniqueOplog_1.length - 1; i >= 0; i--) {
|
|
530
|
-
|
|
520
|
+
_loop_2(i);
|
|
531
521
|
}
|
|
532
522
|
uniqueOplog_1.forEach(function (oplog) {
|
|
533
523
|
var schemaErrors = null;
|
|
@@ -548,7 +538,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
548
538
|
}
|
|
549
539
|
}
|
|
550
540
|
});
|
|
551
|
-
|
|
541
|
+
_loop_3 = function (i) {
|
|
552
542
|
var collection, docs;
|
|
553
543
|
return __generator(this, function (_a) {
|
|
554
544
|
switch (_a.label) {
|
|
@@ -573,7 +563,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
573
563
|
_a.label = 1;
|
|
574
564
|
case 1:
|
|
575
565
|
if (!(i < Object.keys(needIds_1).length)) return [3 /*break*/, 4];
|
|
576
|
-
return [5 /*yield**/,
|
|
566
|
+
return [5 /*yield**/, _loop_3(i)];
|
|
577
567
|
case 2:
|
|
578
568
|
_a.sent();
|
|
579
569
|
_a.label = 3;
|
|
@@ -586,7 +576,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
586
576
|
case 5:
|
|
587
577
|
if (!(i >= 0)) return [3 /*break*/, 10];
|
|
588
578
|
oplog = uniqueOplog_1[i];
|
|
589
|
-
|
|
579
|
+
_loop_4 = function (j) {
|
|
590
580
|
var _a, sub, _b;
|
|
591
581
|
return __generator(this, function (_c) {
|
|
592
582
|
switch (_c.label) {
|
|
@@ -653,7 +643,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
653
643
|
_a.label = 6;
|
|
654
644
|
case 6:
|
|
655
645
|
if (!(j < that._subscriptions.length)) return [3 /*break*/, 9];
|
|
656
|
-
return [5 /*yield**/,
|
|
646
|
+
return [5 /*yield**/, _loop_4(j)];
|
|
657
647
|
case 7:
|
|
658
648
|
state_1 = _a.sent();
|
|
659
649
|
if (state_1 === "break")
|
|
@@ -702,12 +692,12 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
702
692
|
// Check to see if any pubs need to refetch due to Mongo operation
|
|
703
693
|
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type) {
|
|
704
694
|
return __awaiter(this, void 0, void 0, function () {
|
|
705
|
-
var that,
|
|
695
|
+
var that, _loop_5, this_1, i;
|
|
706
696
|
return __generator(this, function (_a) {
|
|
707
697
|
switch (_a.label) {
|
|
708
698
|
case 0:
|
|
709
699
|
that = this;
|
|
710
|
-
|
|
700
|
+
_loop_5 = function (i) {
|
|
711
701
|
var _a, _b, sub, _c, _d;
|
|
712
702
|
return __generator(this, function (_e) {
|
|
713
703
|
switch (_e.label) {
|
|
@@ -716,6 +706,15 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
716
706
|
if (!sub.preSubscriptionData) return [3 /*break*/, 2];
|
|
717
707
|
if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
|
|
718
708
|
if (this_1._subCache.some(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })) {
|
|
709
|
+
if (!sub.clients.length) {
|
|
710
|
+
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
711
|
+
active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
712
|
+
$and: [
|
|
713
|
+
{ publication: sub.publication },
|
|
714
|
+
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
715
|
+
]
|
|
716
|
+
}).exec();
|
|
717
|
+
}
|
|
719
718
|
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
720
719
|
}
|
|
721
720
|
that.sendPubData(sub, type, collection);
|
|
@@ -732,6 +731,15 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
732
731
|
_d.preSubscriptionData = _e.sent();
|
|
733
732
|
if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
|
|
734
733
|
if (this_1._subCache.some(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })) {
|
|
734
|
+
if (!sub.clients.length) {
|
|
735
|
+
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
736
|
+
active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
737
|
+
$and: [
|
|
738
|
+
{ publication: sub.publication },
|
|
739
|
+
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
740
|
+
]
|
|
741
|
+
}).exec();
|
|
742
|
+
}
|
|
735
743
|
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
736
744
|
}
|
|
737
745
|
that.sendPubData(sub, type, collection);
|
|
@@ -763,6 +771,15 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
763
771
|
if (that._publications[sub.publication].fetchFunction) {
|
|
764
772
|
if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
|
|
765
773
|
if (this_1._subCache.some(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })) {
|
|
774
|
+
if (!sub.clients.length) {
|
|
775
|
+
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
776
|
+
active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
777
|
+
$and: [
|
|
778
|
+
{ publication: sub.publication },
|
|
779
|
+
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
780
|
+
]
|
|
781
|
+
}).exec();
|
|
782
|
+
}
|
|
766
783
|
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
767
784
|
}
|
|
768
785
|
that.sendPubData(sub, type, collection);
|
|
@@ -771,6 +788,15 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
771
788
|
}
|
|
772
789
|
else {
|
|
773
790
|
if (this_1._subCache.some(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })) {
|
|
791
|
+
if (!sub.clients.length) {
|
|
792
|
+
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
793
|
+
active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
794
|
+
$and: [
|
|
795
|
+
{ publication: sub.publication },
|
|
796
|
+
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
797
|
+
]
|
|
798
|
+
}).exec();
|
|
799
|
+
}
|
|
774
800
|
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
775
801
|
}
|
|
776
802
|
that.sendPubData(sub, type, collection);
|
|
@@ -782,16 +808,16 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
782
808
|
});
|
|
783
809
|
};
|
|
784
810
|
this_1 = this;
|
|
785
|
-
i =
|
|
811
|
+
i = that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).length - 1;
|
|
786
812
|
_a.label = 1;
|
|
787
813
|
case 1:
|
|
788
|
-
if (!(i
|
|
789
|
-
return [5 /*yield**/,
|
|
814
|
+
if (!(i >= 0)) return [3 /*break*/, 4];
|
|
815
|
+
return [5 /*yield**/, _loop_5(i)];
|
|
790
816
|
case 2:
|
|
791
817
|
_a.sent();
|
|
792
818
|
_a.label = 3;
|
|
793
819
|
case 3:
|
|
794
|
-
i
|
|
820
|
+
i--;
|
|
795
821
|
return [3 /*break*/, 1];
|
|
796
822
|
case 4: return [2 /*return*/];
|
|
797
823
|
}
|