@resolveio/server-lib 9.8.9 → 9.8.11

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.
@@ -379,131 +379,132 @@ var SubscriptionManager = /** @class */ (function () {
379
379
  };
380
380
  // Subscribe to publication
381
381
  SubscriptionManager.prototype.subscribe = function (messageDate, ws, messageId, publication) {
382
+ // let startDate = new Date();
382
383
  var subscriptionData = [];
383
384
  for (var _i = 4; _i < arguments.length; _i++) {
384
385
  subscriptionData[_i - 4] = arguments[_i];
385
386
  }
386
- return __awaiter(this, void 0, void 0, function () {
387
- var pub, valObj, valKeys, rootKeys, i, sub_1, newLoggedInUser;
388
- return __generator(this, function (_a) {
389
- pub = this._publications[publication];
390
- if (!pub) {
391
- console.error(new Date(), 'No Publication: ' + publication);
392
- return [2 /*return*/];
387
+ var pub = this._publications[publication];
388
+ if (!pub) {
389
+ console.error(new Date(), 'No Publication: ' + publication);
390
+ return;
391
+ }
392
+ else {
393
+ if (subscriptionData.length > 1 || subscriptionData[0]) {
394
+ if (!pub.check) {
395
+ console.error(new Date(), 'No Check Function For Pub ' + publication);
396
+ return;
397
+ }
398
+ else if (!pub.check._schema) {
399
+ console.error(new Date(), 'No Check Schema For Pub ' + publication);
400
+ return;
393
401
  }
394
402
  else {
395
- if (subscriptionData.length > 1 || subscriptionData[0]) {
396
- if (!pub.check) {
397
- console.error(new Date(), 'No Check Function For Pub ' + publication);
398
- return [2 /*return*/];
399
- }
400
- else if (!pub.check._schema) {
401
- console.error(new Date(), 'No Check Schema For Pub ' + publication);
402
- return [2 /*return*/];
403
- }
404
- else {
405
- valObj = {};
406
- valKeys = Object.keys(pub.check._schema);
407
- rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
408
- for (i = 0; i < subscriptionData.length; i++) {
409
- valObj[rootKeys[i]] = subscriptionData[i];
410
- }
411
- try {
412
- pub.check.validate(valObj);
413
- }
414
- catch (errors) {
415
- if (errors) {
416
- console.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);
417
- return [2 /*return*/];
418
- }
419
- }
420
- }
421
- }
422
- sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
423
- // If sub found (another user watching same data), add client to same sub
424
- if (sub_1) {
425
- if (!sub_1.clients.some(function (a) { return a.id_socket === ws['id_socket'] && a.messageId === messageId; })) {
426
- sub_1.clients.push({
427
- id_user: ws['id_user'],
428
- messageId: messageId,
429
- id_socket: ws['id_socket']
430
- });
431
- }
432
- }
433
- // If sub not found, create new sub
434
- else {
435
- this._subscriptions.push({
436
- publication: publication,
437
- subscriptionData: subscriptionData,
438
- collections: this.getPublicationCollections(publication),
439
- clients: [{
440
- id_user: ws['id_user'],
441
- messageId: messageId,
442
- id_socket: ws['id_socket']
443
- }],
444
- cacheId: 0
445
- });
446
- }
447
- if (!sub_1) {
448
- sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
449
- }
450
- if (!sub_1.cacheId && !this._mongoQueue.some(function (a) { return a.subscription.publication === sub_1.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(sub_1.subscriptionData); })) {
451
- this.addToQueue({
452
- _id: 0,
453
- type: 'newSub',
454
- collection: '',
455
- subscription: sub_1,
456
- running: false,
457
- run_again: false
458
- });
459
- // let endDate = new Date();
460
- // this.currentPerfomanceMonitor.push({
461
- // _id: this.idPerformance++,
462
- // function: 'subscribe',
463
- // publication: publication,
464
- // // subscriptionData: subscriptionData,
465
- // subscriptionData: [],
466
- // date_start: startDate,
467
- // date_end: endDate,
468
- // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
469
- // result: 'Add to Queue'
470
- // });
403
+ var valObj = {};
404
+ var valKeys = Object.keys(pub.check._schema);
405
+ var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
406
+ for (var i = 0; i < subscriptionData.length; i++) {
407
+ valObj[rootKeys[i]] = subscriptionData[i];
471
408
  }
472
- else if (sub_1.cacheId) {
473
- this.sendPubDataOnce(ws, messageId, sub_1, 'newSub', publication);
474
- // let endDate = new Date();
475
- // this.currentPerfomanceMonitor.push({
476
- // _id: this.idPerformance++,
477
- // function: 'subscribe',
478
- // publication: publication,
479
- // // subscriptionData: subscriptionData,
480
- // subscriptionData: [],
481
- // date_start: startDate,
482
- // date_end: endDate,
483
- // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
484
- // result: 'Send Pub Data Once'
485
- // });
409
+ try {
410
+ pub.check.validate(valObj);
486
411
  }
487
- }
488
- if (publication === 'appversion') {
489
- newLoggedInUser = this._loggedInUsers.filter(function (a) { return a.id_ws === ws['id_socket']; })[0];
490
- if (newLoggedInUser) {
491
- if (ws['user'] !== 'Admin' && this.serverConfig['CLIENT_NAME'] !== 'ResolveIO') {
492
- this._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'supportCreateBillingUser', {
493
- id_user: ws['id_user'],
494
- user: ws['user'],
495
- date: new Date(),
496
- client: index_1.ResolveIOServer.getClientName()
497
- });
412
+ catch (errors) {
413
+ if (errors) {
414
+ console.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);
415
+ return;
498
416
  }
499
417
  }
500
- else {
501
- this.unsubscribeAll(ws);
418
+ }
419
+ }
420
+ var sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
421
+ // If sub found (another user watching same data), add client to same sub
422
+ if (sub_1) {
423
+ if (!sub_1.clients.some(function (a) { return a.id_socket === ws['id_socket'] && a.messageId === messageId; })) {
424
+ sub_1.clients.push({
425
+ id_user: ws['id_user'],
426
+ messageId: messageId,
427
+ id_socket: ws['id_socket']
428
+ });
429
+ if (publication === 'userWithId' && subscriptionData[0] !== ws['id_user']) {
430
+ this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'SENDING INCORRECT USER FOR USERWITHID - 4!! Sub : ' + JSON.stringify(sub_1, null, 2) + ', Socket User: ' + ws['id_user'] + ', All Subs: ' + JSON.stringify(this._subscriptions, null, 2));
502
431
  }
503
432
  }
504
- return [2 /*return*/];
505
- });
506
- });
433
+ }
434
+ // If sub not found, create new sub
435
+ else {
436
+ this._subscriptions.push({
437
+ publication: publication,
438
+ subscriptionData: subscriptionData,
439
+ collections: this.getPublicationCollections(publication),
440
+ clients: [{
441
+ id_user: ws['id_user'],
442
+ messageId: messageId,
443
+ id_socket: ws['id_socket']
444
+ }],
445
+ cacheId: 0
446
+ });
447
+ if (publication === 'userWithId' && subscriptionData[0] !== ws['id_user']) {
448
+ this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'SENDING INCORRECT USER FOR USERWITHID - 5!! Sub : ' + JSON.stringify(this._subscriptions[this._subscriptions.length - 1], null, 2) + ', Socket User: ' + ws['id_user'] + ', All Subs: ' + JSON.stringify(this._subscriptions, null, 2));
449
+ }
450
+ }
451
+ if (!sub_1) {
452
+ sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
453
+ }
454
+ if (!sub_1.cacheId && !this._mongoQueue.some(function (a) { return a.subscription.publication === sub_1.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(sub_1.subscriptionData); })) {
455
+ this.addToQueue({
456
+ _id: 0,
457
+ type: 'newSub',
458
+ collection: '',
459
+ subscription: sub_1,
460
+ running: false,
461
+ run_again: false
462
+ });
463
+ // let endDate = new Date();
464
+ // this.currentPerfomanceMonitor.push({
465
+ // _id: this.idPerformance++,
466
+ // function: 'subscribe',
467
+ // publication: publication,
468
+ // // subscriptionData: subscriptionData,
469
+ // subscriptionData: [],
470
+ // date_start: startDate,
471
+ // date_end: endDate,
472
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
473
+ // result: 'Add to Queue'
474
+ // });
475
+ }
476
+ else if (sub_1.cacheId) {
477
+ this.sendPubDataOnce(ws, messageId, sub_1, 'newSub', publication);
478
+ // let endDate = new Date();
479
+ // this.currentPerfomanceMonitor.push({
480
+ // _id: this.idPerformance++,
481
+ // function: 'subscribe',
482
+ // publication: publication,
483
+ // // subscriptionData: subscriptionData,
484
+ // subscriptionData: [],
485
+ // date_start: startDate,
486
+ // date_end: endDate,
487
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
488
+ // result: 'Send Pub Data Once'
489
+ // });
490
+ }
491
+ }
492
+ if (publication === 'appversion') {
493
+ var newLoggedInUser = this._loggedInUsers.filter(function (a) { return a.id_ws === ws['id_socket']; })[0];
494
+ if (newLoggedInUser) {
495
+ if (ws['user'] !== 'Admin' && this.serverConfig['CLIENT_NAME'] !== 'ResolveIO') {
496
+ this._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'supportCreateBillingUser', {
497
+ id_user: ws['id_user'],
498
+ user: ws['user'],
499
+ date: new Date(),
500
+ client: index_1.ResolveIOServer.getClientName()
501
+ });
502
+ }
503
+ }
504
+ else {
505
+ this.unsubscribeAll(ws);
506
+ }
507
+ }
507
508
  };
508
509
  SubscriptionManager.prototype.createLoggedInUser = function (id_ws) {
509
510
  return __awaiter(this, void 0, void 0, function () {
@@ -542,33 +543,39 @@ var SubscriptionManager = /** @class */ (function () {
542
543
  };
543
544
  // Unsubscribe from publication
544
545
  SubscriptionManager.prototype.unsubscribe = function (messageDate, ws, messageId, publication) {
546
+ // let startDate = new Date();
547
+ // console.log('Before');
548
+ // console.dir(this._subscriptions.map(a => a.publication));
545
549
  var subscriptionData = [];
546
550
  for (var _i = 4; _i < arguments.length; _i++) {
547
551
  subscriptionData[_i - 4] = arguments[_i];
548
552
  }
549
- return __awaiter(this, void 0, void 0, function () {
550
- var sub, i;
551
- return __generator(this, function (_a) {
552
- // let startDate = new Date();
553
- // console.log('Before');
554
- // console.dir(this._subscriptions.map(a => a.publication));
555
- if (!this._publications[publication]) {
556
- console.log('No Publication: ' + publication);
557
- return [2 /*return*/];
558
- }
559
- else {
560
- sub = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
561
- if (sub) {
562
- for (i = sub.clients.length - 1; i >= 0; i--) {
563
- if (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {
564
- sub.clients.splice(i, 1);
565
- }
566
- }
553
+ if (!this._publications[publication]) {
554
+ console.log('No Publication: ' + publication);
555
+ return;
556
+ }
557
+ else {
558
+ var sub = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
559
+ if (sub) {
560
+ for (var i = sub.clients.length - 1; i >= 0; i--) {
561
+ if (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {
562
+ sub.clients.splice(i, 1);
567
563
  }
568
564
  }
569
- return [2 /*return*/];
570
- });
571
- });
565
+ }
566
+ }
567
+ // let endDate = new Date();
568
+ // this.currentPerfomanceMonitor.push({
569
+ // _id: this.idPerformance++,
570
+ // function: 'unsubscribe',
571
+ // publication: publication,
572
+ // // subscriptionData: subscriptionData,
573
+ // subscriptionData: [],
574
+ // date_start: startDate,
575
+ // date_end: endDate,
576
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
577
+ // result: 'Done'
578
+ // });
572
579
  };
573
580
  // Unsubscribe from publication
574
581
  SubscriptionManager.prototype.unsubscribeAll = function (ws) {
@@ -722,7 +729,7 @@ var SubscriptionManager = /** @class */ (function () {
722
729
  data: cacheData
723
730
  };
724
731
  if (subscription.publication === 'userWithId' && cacheData._id !== ws['id_user']) {
725
- this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'SENDING INCORRECT USER FOR USERWITHID - 2!! Cached Data: : ' + JSON.stringify(cacheData) + ', Socket User: ' + ws['id_user'] + ', Sub: ' + JSON.stringify(subscription, null, 2) + ', All Subs: ' + JSON.stringify(this._publications, null, 2));
732
+ this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'SENDING INCORRECT USER FOR USERWITHID - 2!! Cached Data: : ' + JSON.stringify(cacheData, null, 2) + ', Socket User: ' + ws['id_user'] + ', Sub: ' + JSON.stringify(subscription, null, 2) + ', All Subs: ' + JSON.stringify(this._subscriptions, null, 2));
726
733
  }
727
734
  this.sendWS(ws, serverRes);
728
735
  }
@@ -768,7 +775,7 @@ var SubscriptionManager = /** @class */ (function () {
768
775
  data: res
769
776
  };
770
777
  if (subscription.publication === 'userWithId' && res._id !== ws['id_user']) {
771
- _this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'SENDING INCORRECT USER FOR USERWITHID - 3!! Cached Data: : ' + JSON.stringify(res) + ', Socket User: ' + ws['id_user'] + ', Sub: ' + JSON.stringify(subscription, null, 2) + ', All Subs: ' + JSON.stringify(_this._publications, null, 2));
778
+ _this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'SENDING INCORRECT USER FOR USERWITHID - 3!! Cached Data: : ' + JSON.stringify(res, null, 2) + ', Socket User: ' + ws['id_user'] + ', Sub: ' + JSON.stringify(subscription, null, 2) + ', All Subs: ' + JSON.stringify(_this._subscriptions, null, 2));
772
779
  }
773
780
  // console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
774
781
  _this.sendWS(ws, serverRes);
@@ -853,7 +860,7 @@ var SubscriptionManager = /** @class */ (function () {
853
860
  data: res
854
861
  };
855
862
  if (subscription.publication === 'userWithId' && client.id_user !== ws['id_user']) {
856
- _this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'SENDING INCORRECT USER FOR USERWITHID!! Client User: ' + client.id_user + ', Socket User: ' + ws['id_user'] + ', Sub: ' + JSON.stringify(subscription, null, 2) + ', All Subs: ' + JSON.stringify(_this._publications, null, 2));
863
+ _this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'SENDING INCORRECT USER FOR USERWITHID!! Client User: ' + client.id_user + ', Socket User: ' + ws['id_user'] + ', Sub: ' + JSON.stringify(subscription, null, 2) + ', All Subs: ' + JSON.stringify(_this._subscriptions, null, 2));
857
864
  }
858
865
  _this.sendWS(ws, serverRes);
859
866
  }