@senior-gestao-empresarial/angular-components 5.1.1 → 6.0.0

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.
@@ -6552,14 +6552,23 @@ var NpsService = /** @class */ (function () {
6552
6552
 
6553
6553
  var WebsocketService = /** @class */ (function () {
6554
6554
  function WebsocketService() {
6555
+ /** @private */
6555
6556
  this.focused = true;
6557
+ /** @private */
6556
6558
  this.wasConnected = false;
6559
+ /** @private */
6557
6560
  this.connected = false;
6561
+ /** @private */
6558
6562
  this.isConnecting = false;
6563
+ /** @private */
6559
6564
  this.primitiveManagers = new Map();
6565
+ /** @private */
6560
6566
  this.connect$ = new Subject();
6567
+ /** @private */
6561
6568
  this.disconnect$ = new Subject();
6569
+ /** @private */
6562
6570
  this.reconnect$ = new Subject();
6571
+ /** @private */
6563
6572
  this.error$ = new Subject();
6564
6573
  window.onfocus = this.onFocus;
6565
6574
  window.onblur = this.onBlur;
@@ -6601,18 +6610,19 @@ var WebsocketService = /** @class */ (function () {
6601
6610
  return this.error$.asObservable();
6602
6611
  };
6603
6612
  /**
6604
- * Observable responsável por emitir uma notificação quando um evento é publicado.
6605
6613
  * @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
6606
- * @param domain Dominio da primitiva.
6607
- * @param service Service da primitiva.
6608
- * @param primitive Primitiva que será "observada" pelo client.
6609
- * @param identifierPath Caminho até a propriedade considerada o identificador do registro.
6610
- * @return Um `observable` que emite notificações toda vez que o respectivo evento é publicado no sistema.
6614
+ * @param {Object} options Objeto de configuração do evento.
6615
+ * @param {string} options.domain Domínio da primitiva.
6616
+ * @param {string} options.service Serviço da primitiva.
6617
+ * @param {string} options.primitive Primitiva que será "observada".
6618
+ * @return Um Observable<T> que emite notificações toda vez que o respectivo evento é publicado.
6611
6619
  */
6612
- WebsocketService.prototype.onEvent = function (domain, service, primitive, identifierPath) {
6620
+ WebsocketService.prototype.onEvent = function (options) {
6613
6621
  var _this = this;
6614
- if (this.primitiveManagers.has(primitive)) {
6615
- return this.primitiveManagers.get(primitive).subject.asObservable();
6622
+ var domain = options.domain, service = options.service, primitive = options.primitive;
6623
+ var key = this.getPrimitiveManagerKey(domain, service, primitive);
6624
+ if (this.primitiveManagers.has(key)) {
6625
+ return this.primitiveManagers.get(key).subject.asObservable();
6616
6626
  }
6617
6627
  var primitiveManager = {
6618
6628
  domain: domain,
@@ -6620,13 +6630,11 @@ var WebsocketService = /** @class */ (function () {
6620
6630
  primitive: primitive,
6621
6631
  stompSubscriptions: [],
6622
6632
  subject: new Subject(),
6623
- identifierPath: identifierPath,
6624
- publishedEvents: [],
6625
6633
  };
6626
- this.primitiveManagers.set(primitive, primitiveManager);
6634
+ this.primitiveManagers.set(key, primitiveManager);
6627
6635
  if (this.isConnected()) {
6628
6636
  this.createStompSubscriptions(primitiveManager);
6629
- return primitiveManager.subject.pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6637
+ return primitiveManager.subject.pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
6630
6638
  }
6631
6639
  else {
6632
6640
  if (!this.isConnecting) {
@@ -6635,53 +6643,10 @@ var WebsocketService = /** @class */ (function () {
6635
6643
  this.connect$.pipe(first()).subscribe(function () {
6636
6644
  _this.createStompSubscriptions(primitiveManager);
6637
6645
  });
6638
- return primitiveManager.subject.pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6639
- }
6640
- };
6641
- /**
6642
- * Retorna todos os eventos ouvidos pela primitiva com os respectivos identificadores.
6643
- * @typeParam `<T>` Tipo do evento retornado pela primitiva.
6644
- * @param primitive Primitiva que será "observada" pelo client.
6645
- * @param identifiers Array com os identificadores interessados.
6646
- * @return Array contendo o último evento recebido de cada identificador fornecido.
6647
- */
6648
- WebsocketService.prototype.getPublishedEvents = function (primitive, identifiers) {
6649
- var e_1, _a;
6650
- var _this = this;
6651
- var publishedEvents = [];
6652
- var primitiveManager = this.primitiveManagers.get(primitive);
6653
- var _loop_1 = function (identifier) {
6654
- var event_1 = primitiveManager.publishedEvents.find(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6655
- if (event_1) {
6656
- publishedEvents.push(event_1);
6657
- }
6658
- };
6659
- try {
6660
- for (var identifiers_1 = __values(identifiers), identifiers_1_1 = identifiers_1.next(); !identifiers_1_1.done; identifiers_1_1 = identifiers_1.next()) {
6661
- var identifier = identifiers_1_1.value;
6662
- _loop_1(identifier);
6663
- }
6664
- }
6665
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
6666
- finally {
6667
- try {
6668
- if (identifiers_1_1 && !identifiers_1_1.done && (_a = identifiers_1.return)) _a.call(identifiers_1);
6669
- }
6670
- finally { if (e_1) throw e_1.error; }
6671
- }
6672
- return publishedEvents;
6673
- };
6674
- WebsocketService.prototype.addPublishedEvent = function (primitiveManager, event) {
6675
- var _this = this;
6676
- var identifier = this.getIdentifierFromEvent(primitiveManager.identifierPath, event);
6677
- var eventIndex = primitiveManager.publishedEvents.findIndex(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6678
- if (eventIndex !== -1) {
6679
- primitiveManager.publishedEvents[eventIndex] = __assign(__assign({}, primitiveManager.publishedEvents[eventIndex]), event);
6680
- }
6681
- else {
6682
- primitiveManager.publishedEvents.push(event);
6646
+ return primitiveManager.subject.pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
6683
6647
  }
6684
6648
  };
6649
+ /** @private */
6685
6650
  WebsocketService.prototype.createStompSubscriptions = function (primitiveManager) {
6686
6651
  var withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6687
6652
  var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
@@ -6689,25 +6654,7 @@ var WebsocketService = /** @class */ (function () {
6689
6654
  var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6690
6655
  primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
6691
6656
  };
6692
- WebsocketService.prototype.getIdentifierFromEvent = function (identifierPath, event) {
6693
- var e_2, _a;
6694
- var properties = identifierPath.split(".");
6695
- var identifier = event;
6696
- try {
6697
- for (var properties_1 = __values(properties), properties_1_1 = properties_1.next(); !properties_1_1.done; properties_1_1 = properties_1.next()) {
6698
- var property = properties_1_1.value;
6699
- identifier = identifier[property];
6700
- }
6701
- }
6702
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
6703
- finally {
6704
- try {
6705
- if (properties_1_1 && !properties_1_1.done && (_a = properties_1.return)) _a.call(properties_1);
6706
- }
6707
- finally { if (e_2) throw e_2.error; }
6708
- }
6709
- return identifier;
6710
- };
6657
+ /** @private */
6711
6658
  WebsocketService.prototype.connect = function () {
6712
6659
  var _this = this;
6713
6660
  this.createStompClient();
@@ -6730,14 +6677,16 @@ var WebsocketService = /** @class */ (function () {
6730
6677
  _this.reconnect();
6731
6678
  });
6732
6679
  };
6680
+ /** @private */
6733
6681
  WebsocketService.prototype.onFocus = function () {
6734
6682
  this.focused = true;
6735
6683
  };
6684
+ /** @private */
6736
6685
  WebsocketService.prototype.onBlur = function () {
6737
6686
  this.focused = false;
6738
6687
  };
6739
6688
  WebsocketService.prototype.disconnect = function () {
6740
- var e_3, _a, e_4, _b, e_5, _c;
6689
+ var e_1, _a, e_2, _b, e_3, _c;
6741
6690
  var observersCount = this.getObserversCount();
6742
6691
  if (observersCount > 0)
6743
6692
  return;
@@ -6745,26 +6694,26 @@ var WebsocketService = /** @class */ (function () {
6745
6694
  for (var _d = __values(this.primitiveManagers.values()), _e = _d.next(); !_e.done; _e = _d.next()) {
6746
6695
  var primitiveManager = _e.value;
6747
6696
  try {
6748
- for (var _f = (e_4 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
6697
+ for (var _f = (e_2 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
6749
6698
  var stompSubscription = _g.value;
6750
6699
  stompSubscription.unsubscribe();
6751
6700
  }
6752
6701
  }
6753
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
6702
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
6754
6703
  finally {
6755
6704
  try {
6756
6705
  if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
6757
6706
  }
6758
- finally { if (e_4) throw e_4.error; }
6707
+ finally { if (e_2) throw e_2.error; }
6759
6708
  }
6760
6709
  }
6761
6710
  }
6762
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
6711
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
6763
6712
  finally {
6764
6713
  try {
6765
6714
  if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
6766
6715
  }
6767
- finally { if (e_3) throw e_3.error; }
6716
+ finally { if (e_1) throw e_1.error; }
6768
6717
  }
6769
6718
  try {
6770
6719
  for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
@@ -6772,12 +6721,12 @@ var WebsocketService = /** @class */ (function () {
6772
6721
  primitiveManager.subject.complete();
6773
6722
  }
6774
6723
  }
6775
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
6724
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
6776
6725
  finally {
6777
6726
  try {
6778
6727
  if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
6779
6728
  }
6780
- finally { if (e_5) throw e_5.error; }
6729
+ finally { if (e_3) throw e_3.error; }
6781
6730
  }
6782
6731
  this.primitiveManagers.clear();
6783
6732
  this._stompClient.disconnect();
@@ -6787,35 +6736,40 @@ var WebsocketService = /** @class */ (function () {
6787
6736
  this.wasConnected = false;
6788
6737
  this.disconnect$.next();
6789
6738
  };
6739
+ /** @private */
6790
6740
  WebsocketService.prototype.isConnected = function () {
6791
6741
  return this.connected;
6792
6742
  };
6743
+ /** @private */
6793
6744
  WebsocketService.prototype.setConnected = function (connected) {
6794
6745
  this.connected = connected;
6795
6746
  };
6747
+ /** @private */
6796
6748
  WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
6797
6749
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6798
6750
  var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
6799
6751
  return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
6800
6752
  };
6753
+ /** @private */
6801
6754
  WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
6802
6755
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6803
6756
  return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
6804
6757
  };
6758
+ /** @private */
6805
6759
  WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
6806
- var _this = this;
6807
6760
  return this._stompClient.subscribe(destination, function (message) {
6808
6761
  var event = JSON.parse(message.body || "{}");
6809
- _this.addPublishedEvent(primitiveManager, event);
6810
6762
  primitiveManager.subject.next(event);
6811
6763
  });
6812
6764
  };
6765
+ /** @private */
6813
6766
  WebsocketService.prototype.createStompClient = function () {
6814
6767
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
6815
6768
  this._stompClient = Stomp.over(ws);
6816
6769
  // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
6817
6770
  this._stompClient.debug = function () { }; // Para remover os logs.
6818
6771
  };
6772
+ /** @private */
6819
6773
  WebsocketService.prototype.reconnect = function () {
6820
6774
  var _this = this;
6821
6775
  if (this.connected)
@@ -6831,37 +6785,39 @@ var WebsocketService = /** @class */ (function () {
6831
6785
  }
6832
6786
  }, WebsocketService_1.RECONNECT_TIMER);
6833
6787
  };
6788
+ /** @private */
6834
6789
  WebsocketService.prototype.reconnectPrimitives = function () {
6835
- var e_6, _a, e_7, _b;
6790
+ var e_4, _a, e_5, _b;
6836
6791
  try {
6837
6792
  for (var _c = __values(this.primitiveManagers.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
6838
6793
  var primitiveManager = _d.value;
6839
6794
  try {
6840
- for (var _e = (e_7 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
6795
+ for (var _e = (e_5 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
6841
6796
  var stompSubscription = _f.value;
6842
6797
  stompSubscription.unsubscribe();
6843
6798
  }
6844
6799
  }
6845
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
6800
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
6846
6801
  finally {
6847
6802
  try {
6848
6803
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
6849
6804
  }
6850
- finally { if (e_7) throw e_7.error; }
6805
+ finally { if (e_5) throw e_5.error; }
6851
6806
  }
6852
6807
  this.createStompSubscriptions(primitiveManager);
6853
6808
  }
6854
6809
  }
6855
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
6810
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
6856
6811
  finally {
6857
6812
  try {
6858
6813
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
6859
6814
  }
6860
- finally { if (e_6) throw e_6.error; }
6815
+ finally { if (e_4) throw e_4.error; }
6861
6816
  }
6862
6817
  };
6818
+ /** @private */
6863
6819
  WebsocketService.prototype.getObserversCount = function () {
6864
- var e_8, _a;
6820
+ var e_6, _a;
6865
6821
  var observersCount = 0;
6866
6822
  try {
6867
6823
  for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -6869,21 +6825,19 @@ var WebsocketService = /** @class */ (function () {
6869
6825
  observersCount += primitiveManager.subject.observers.length;
6870
6826
  }
6871
6827
  }
6872
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
6828
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
6873
6829
  finally {
6874
6830
  try {
6875
6831
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6876
6832
  }
6877
- finally { if (e_8) throw e_8.error; }
6833
+ finally { if (e_6) throw e_6.error; }
6878
6834
  }
6879
6835
  return observersCount;
6880
6836
  };
6881
- WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitive) {
6882
- var e_9, _a;
6883
- var primitiveManager = this.primitiveManagers.get(primitive);
6884
- if (!primitiveManager)
6885
- return;
6886
- // @IMPORTANT: Replace .observers.length with .observed in rxjs 7.0+
6837
+ /** @private */
6838
+ WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitiveManager) {
6839
+ var e_7, _a;
6840
+ // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
6887
6841
  var hasObservers = !(primitiveManager.subject.observers.length === 1);
6888
6842
  if (hasObservers)
6889
6843
  return;
@@ -6893,22 +6847,33 @@ var WebsocketService = /** @class */ (function () {
6893
6847
  stompSubscription.unsubscribe();
6894
6848
  }
6895
6849
  }
6896
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
6850
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
6897
6851
  finally {
6898
6852
  try {
6899
6853
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6900
6854
  }
6901
- finally { if (e_9) throw e_9.error; }
6855
+ finally { if (e_7) throw e_7.error; }
6902
6856
  }
6903
- this.primitiveManagers.delete(primitive);
6857
+ var key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6858
+ this.primitiveManagers.delete(key);
6904
6859
  this.disconnect();
6905
6860
  };
6861
+ /** @private */
6862
+ WebsocketService.prototype.getPrimitiveManagerKey = function (domain, service, primitive) {
6863
+ return domain + "/" + service + "/" + primitive;
6864
+ };
6906
6865
  var WebsocketService_1;
6866
+ /** @private */
6907
6867
  WebsocketService.RECONNECT_TIMER = 3000;
6868
+ /** @private */
6908
6869
  WebsocketService.CONNECTION_TIMEOUT = 15000;
6870
+ /** @private */
6909
6871
  WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
6872
+ /** @private */
6910
6873
  WebsocketService.TOKEN_COOKIE = "com.senior.token";
6874
+ /** @private */
6911
6875
  WebsocketService.TOKEN = JSON.parse(get(WebsocketService_1.TOKEN_COOKIE) || "{}");
6876
+ /** @private */
6912
6877
  WebsocketService.WEBSOCKET_URL = get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
6913
6878
  WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
6914
6879
  WebsocketService = WebsocketService_1 = __decorate([