@resolveio/server-lib 2.0.4-newrole → 2.0.5

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.
@@ -21,6 +21,13 @@ 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
+ },
24
31
  attempts: {
25
32
  type: Number,
26
33
  optional: true
@@ -57,78 +64,60 @@ var schema = {
57
64
  type: String
58
65
  },
59
66
  roles: {
60
- type: Object
61
- },
62
- 'roles.super_admin': {
63
- type: Boolean
64
- },
65
- 'roles.approvals': {
66
67
  type: Array
67
68
  },
68
- 'roles.approvals.$': {
69
- type: Object
70
- },
71
- 'roles.approvals.$.name': {
69
+ 'roles.$': {
72
70
  type: String
73
71
  },
74
- 'roles.approvals.$.type': {
75
- type: String
72
+ phonenumber: {
73
+ type: String,
74
+ optional: true
76
75
  },
77
- 'roles.approvals.$.accounting_code': {
78
- type: String
76
+ other: {
77
+ type: Object,
78
+ blackbox: true,
79
+ optional: true
79
80
  },
80
- 'roles.groups': {
81
- type: Array
81
+ assets: {
82
+ type: Array,
83
+ optional: true
82
84
  },
83
- 'roles.groups.$': {
85
+ 'assets.$': {
84
86
  type: Object
85
87
  },
86
- 'roles.groups.$.name': {
88
+ 'assets.$.type': {
87
89
  type: String
88
90
  },
89
- 'roles.groups.$.views': {
90
- type: Array
91
- },
92
- 'roles.groups.$.views.$': {
91
+ 'assets.$.id_asset': {
93
92
  type: String
94
93
  },
95
- 'roles.groups.$.yard': {
96
- type: String,
97
- optional: true
98
- },
99
- 'roles.notifications': {
100
- type: Array
101
- },
102
- 'roles.notifications.$': {
94
+ 'assets.$.asset_number': {
103
95
  type: String
104
96
  },
105
- 'roles.miscs': {
106
- type: Array
97
+ 'assets.$.ownership': {
98
+ type: String
107
99
  },
108
- 'roles.miscs.$': {
100
+ 'assets.$.ownership_driver': {
109
101
  type: String
110
102
  },
111
- active: Boolean,
112
- id_customer: {
113
- type: String,
114
- optional: true
103
+ 'assets.$.date_start': {
104
+ type: Date
115
105
  },
116
- customer: {
117
- type: String,
106
+ 'assets.$.date_end': {
107
+ type: Date,
118
108
  optional: true
119
109
  },
120
- customer_type: {
110
+ id_function: {
121
111
  type: String,
122
112
  optional: true
123
113
  },
124
- phonenumber: {
114
+ customer: {
125
115
  type: String,
126
- optional: true
116
+ optional: true,
127
117
  },
128
- other: {
129
- type: Object,
118
+ id_customer: {
119
+ type: String,
130
120
  optional: true,
131
- blackbox: true
132
121
  }
133
122
  };
134
123
  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 mongoose_1 = require("mongoose");
41
40
  var active_subscription_collection_1 = require("../collections/active-subscription.collection");
41
+ var mongoose_1 = require("mongoose");
42
42
  function loadServerInit() {
43
43
  return __awaiter(this, void 0, void 0, function () {
44
44
  var appVersion;
@@ -5,6 +5,7 @@ export declare class SubscriptionManager {
5
5
  private _publications;
6
6
  private _subscriptions;
7
7
  private _wss;
8
+ private _oplogQueue;
8
9
  private _sendQueue;
9
10
  private _runningQueue;
10
11
  private serverConfig;
@@ -16,6 +17,7 @@ export declare class SubscriptionManager {
16
17
  unsubscribeAll(ws: WebSocket): Promise<void>;
17
18
  private getPublicationCollections;
18
19
  private tailOpLog;
20
+ private runOpLogQueue;
19
21
  private tailOpLogSupport;
20
22
  private resendPubsForDelete;
21
23
  private checkPubsForChanges;
@@ -51,11 +51,13 @@ var method_responses_1 = require("../publications/method-responses");
51
51
  var support_tickets_1 = require("../publications/support-tickets");
52
52
  var index_1 = require("../index");
53
53
  var notifications_1 = require("../publications/notifications");
54
+ var common_1 = require("../util/common");
54
55
  var SubscriptionManager = /** @class */ (function () {
55
56
  function SubscriptionManager(mainServer, wss, serverConfig) {
56
57
  var _this = this;
57
58
  this._publications = {};
58
59
  this._subscriptions = [];
60
+ this._oplogQueue = [];
59
61
  this._sendQueue = [];
60
62
  this._runningQueue = false;
61
63
  this._mainServer = mainServer;
@@ -74,6 +76,7 @@ var SubscriptionManager = /** @class */ (function () {
74
76
  support_tickets_1.loadSupportTicketPublications(this);
75
77
  notifications_1.loadNotificationPublications(this);
76
78
  this.tailOpLog();
79
+ this.runOpLogQueue();
77
80
  if (index_1.ResolveIOServer.getSupportDB()) {
78
81
  this.tailOpLogSupport();
79
82
  }
@@ -350,7 +353,11 @@ var SubscriptionManager = /** @class */ (function () {
350
353
  if (nsArray[2]) {
351
354
  collection += '.' + nsArray[2];
352
355
  }
353
- that.checkPubsForChanges(collection, doc.o);
356
+ _this._oplogQueue.push({
357
+ type: 'insert',
358
+ collection: collection,
359
+ doc: doc.o
360
+ });
354
361
  if (collection === 'cron-jobs') {
355
362
  _this._mainServer.getCronManager().checkCronJobsForUpdates();
356
363
  }
@@ -371,7 +378,11 @@ var SubscriptionManager = /** @class */ (function () {
371
378
  collection += '.' + nsArray[2];
372
379
  }
373
380
  doc.o['_id'] = doc.o2['_id'];
374
- that.checkPubsForChanges(collection, doc.o);
381
+ _this._oplogQueue.push({
382
+ type: 'update',
383
+ collection: collection,
384
+ doc: doc.o
385
+ });
375
386
  if (collection === 'cron-jobs') {
376
387
  _this._mainServer.getCronManager().checkCronJobsForUpdates();
377
388
  }
@@ -398,6 +409,34 @@ var SubscriptionManager = /** @class */ (function () {
398
409
  console.log('oplog stopped');
399
410
  });
400
411
  };
412
+ SubscriptionManager.prototype.runOpLogQueue = function () {
413
+ var _this = this;
414
+ setInterval(function () {
415
+ var oplogQueue = common_1.deepCopy(_this._oplogQueue);
416
+ var uniqueCollectionOplogQueue = oplogQueue.map(function (a) { return a.collection; }).filter(function (elem, index, self) {
417
+ return index === self.indexOf(elem);
418
+ });
419
+ uniqueCollectionOplogQueue.forEach(function (collection) {
420
+ var oplogQueueFiltered = oplogQueue.filter(function (a) { return a.collection === collection; });
421
+ if (oplogQueueFiltered.length === 1) {
422
+ _this.checkPubsForChanges(oplogQueueFiltered[0].collection, oplogQueueFiltered[0].doc);
423
+ _this._oplogQueue.splice(oplogQueue.map(collection).indexOf(collection), 1);
424
+ }
425
+ else {
426
+ oplogQueueFiltered.forEach(function (item) {
427
+ _this.checkPubsForChanges(item.collection, item.doc, true);
428
+ });
429
+ _this.checkPubsForChanges(oplogQueueFiltered[oplogQueueFiltered.length - 1].collection, oplogQueueFiltered[oplogQueueFiltered.length - 1].doc);
430
+ for (var i = _this._oplogQueue.length - 1; i >= 0; i--) {
431
+ var item = _this._oplogQueue[i];
432
+ if (item.collection === collection) {
433
+ _this._oplogQueue.splice(i, 1);
434
+ }
435
+ }
436
+ }
437
+ });
438
+ }, 1000);
439
+ };
401
440
  SubscriptionManager.prototype.tailOpLogSupport = function () {
402
441
  var that = this;
403
442
  var oplog = MongoOplog(that.serverConfig['RESOLVEIO_SUPPORT_OPLOG_URL']);
@@ -466,8 +505,9 @@ var SubscriptionManager = /** @class */ (function () {
466
505
  // Document: Inserted/Modified/Deleted Document
467
506
  // Collection: Collection Document Lives In
468
507
  // Check to see if any pubs need to refetch due to Mongo operation
469
- SubscriptionManager.prototype.checkPubsForChanges = function (collection, document) {
508
+ SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, fetchFunctionOnly) {
470
509
  var _this = this;
510
+ if (fetchFunctionOnly === void 0) { fetchFunctionOnly = false; }
471
511
  var that = this;
472
512
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
473
513
  var _a, schemaErrors, _b;
@@ -509,7 +549,7 @@ var SubscriptionManager = /** @class */ (function () {
509
549
  });
510
550
  }
511
551
  }
512
- else {
552
+ else if (!fetchFunctionOnly) {
513
553
  that._wss.clients.forEach(function (ws) {
514
554
  if (ws['id_socket'] === client.id_socket) {
515
555
  that.sendPubDataOnce(ws, client.messageId, sub);
@@ -524,7 +564,7 @@ var SubscriptionManager = /** @class */ (function () {
524
564
  that.sendPubData(sub);
525
565
  }
526
566
  }
527
- else {
567
+ else if (!fetchFunctionOnly) {
528
568
  that.sendPubData(sub);
529
569
  }
530
570
  }
@@ -1,31 +1,14 @@
1
1
  import { CollectionDocument } from './collection-document.model';
2
2
  export interface UserModel extends CollectionDocument {
3
+ attempts: number;
4
+ last: Date;
5
+ services?: any;
3
6
  fullname: string;
4
- roles: UserRoleModel;
5
7
  username?: string;
6
8
  email?: string;
9
+ roles?: string[];
7
10
  active?: boolean;
8
- services?: any;
9
- id_customer?: string;
10
- customer?: string;
11
- customer_type?: string;
11
+ readonly?: boolean;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "2.0.4-newrole",
3
+ "version": "2.0.5",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {