@senior-gestao-empresarial/angular-components 6.11.5 → 6.12.0-67d9099d-c888-4b61-a14e-4c7c373707d6

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.
Files changed (49) hide show
  1. package/bundles/senior-gestao-empresarial-angular-components.umd.js +513 -255
  2. package/bundles/senior-gestao-empresarial-angular-components.umd.js.map +1 -1
  3. package/bundles/senior-gestao-empresarial-angular-components.umd.min.js +2 -2
  4. package/bundles/senior-gestao-empresarial-angular-components.umd.min.js.map +1 -1
  5. package/components/permissions/index.d.ts +1 -0
  6. package/components/permissions/verify-module-permissions-service.d.ts +18 -0
  7. package/components/permissions/verify-module-permissions.d.ts +16 -0
  8. package/components/utils/async-lock.d.ts +6 -0
  9. package/components/websocket/index.d.ts +2 -0
  10. package/components/websocket/models/index.d.ts +1 -0
  11. package/components/websocket/models/primitive-manager.d.ts +19 -0
  12. package/components/websocket/protocols/index.d.ts +2 -0
  13. package/components/websocket/protocols/on-event-options.d.ts +8 -0
  14. package/components/websocket/protocols/primitive-event.d.ts +10 -0
  15. package/components/websocket/user-information.service.d.ts +7 -0
  16. package/components/websocket/websocket.service.d.ts +78 -74
  17. package/esm2015/components/permissions/index.js +2 -1
  18. package/esm2015/components/permissions/verify-module-permissions-service.js +26 -0
  19. package/esm2015/components/permissions/verify-module-permissions.js +51 -0
  20. package/esm2015/components/utils/async-lock.js +34 -0
  21. package/esm2015/components/websocket/index.js +2 -1
  22. package/esm2015/components/websocket/models/index.js +2 -0
  23. package/esm2015/components/websocket/models/primitive-manager.js +39 -0
  24. package/esm2015/components/websocket/protocols/index.js +1 -0
  25. package/esm2015/components/websocket/protocols/on-event-options.js +1 -0
  26. package/esm2015/components/websocket/protocols/primitive-event.js +1 -0
  27. package/esm2015/components/websocket/user-information.service.js +34 -0
  28. package/esm2015/components/websocket/websocket.service.js +259 -195
  29. package/esm2015/senior-gestao-empresarial-angular-components.js +4 -2
  30. package/esm5/components/permissions/index.js +2 -1
  31. package/esm5/components/permissions/verify-module-permissions-service.js +28 -0
  32. package/esm5/components/permissions/verify-module-permissions.js +53 -0
  33. package/esm5/components/utils/async-lock.js +43 -0
  34. package/esm5/components/websocket/index.js +2 -1
  35. package/esm5/components/websocket/models/index.js +2 -0
  36. package/esm5/components/websocket/models/primitive-manager.js +58 -0
  37. package/esm5/components/websocket/protocols/index.js +1 -0
  38. package/esm5/components/websocket/protocols/on-event-options.js +1 -0
  39. package/esm5/components/websocket/protocols/primitive-event.js +1 -0
  40. package/esm5/components/websocket/user-information.service.js +38 -0
  41. package/esm5/components/websocket/websocket.service.js +317 -256
  42. package/esm5/senior-gestao-empresarial-angular-components.js +4 -2
  43. package/fesm2015/senior-gestao-empresarial-angular-components.js +417 -193
  44. package/fesm2015/senior-gestao-empresarial-angular-components.js.map +1 -1
  45. package/fesm5/senior-gestao-empresarial-angular-components.js +509 -255
  46. package/fesm5/senior-gestao-empresarial-angular-components.js.map +1 -1
  47. package/package.json +3 -3
  48. package/senior-gestao-empresarial-angular-components.d.ts +3 -1
  49. package/senior-gestao-empresarial-angular-components.metadata.json +1 -1
@@ -3,8 +3,8 @@ import { Input, Component, NgModule, Injectable, Inject, ɵɵdefineInjectable,
3
3
  import { CommonModule } from '@angular/common';
4
4
  import { BreadcrumbModule as BreadcrumbModule$1 } from 'primeng/breadcrumb';
5
5
  import { NavigationEnd, PRIMARY_OUTLET, ActivatedRoute, Router, RouterModule } from '@angular/router';
6
- import { Subject, throwError, interval, of, BehaviorSubject, race, timer, iif, fromEvent, ReplaySubject } from 'rxjs';
7
- import { takeUntil, filter, catchError, map, takeWhile, switchMap, take, finalize, first } from 'rxjs/operators';
6
+ import { Subject, throwError, interval, of, BehaviorSubject, ReplaySubject } from 'rxjs';
7
+ import { takeUntil, filter, catchError, map, takeWhile, switchMap, take, finalize } from 'rxjs/operators';
8
8
  import * as moment_ from 'moment';
9
9
  import { FormField, FieldType } from '@seniorsistemas/angular-components';
10
10
  import { HttpParams, HttpClient } from '@angular/common/http';
@@ -13,9 +13,9 @@ import { TranslateService } from '@ngx-translate/core';
13
13
  import { HttpInterceptorModule } from '@seniorsistemas/platform-components';
14
14
  import { user } from '@seniorsistemas/senior-platform-data';
15
15
  import { FormControl, FormGroup } from '@angular/forms';
16
- import { Stomp } from '@stomp/stompjs';
17
- import { get } from 'js-cookie';
16
+ import { Client } from '@stomp/stompjs';
18
17
  import * as SockJS from 'sockjs-client';
18
+ import { get } from 'js-cookie';
19
19
 
20
20
  let BreadcrumbComponent = class BreadcrumbComponent {
21
21
  constructor(activatedRoute, router) {
@@ -6768,247 +6768,408 @@ NpsService = __decorate([
6768
6768
  })
6769
6769
  ], NpsService);
6770
6770
 
6771
- var WebsocketService_1;
6772
- let WebsocketService = WebsocketService_1 = class WebsocketService {
6771
+ class AsyncLock {
6773
6772
  constructor() {
6774
- /** @private */
6775
- this.wasConnected = false;
6776
- /** @private */
6777
- this.isConnected = false;
6778
- /** @private */
6779
- this.isConnecting = false;
6780
- /** @private */
6781
- this.primitiveManagers = new Map();
6782
- /** @private */
6773
+ this.queue = [];
6774
+ this.acquired = false;
6775
+ }
6776
+ acquire() {
6777
+ return __awaiter(this, void 0, void 0, function* () {
6778
+ if (!this.acquired) {
6779
+ this.acquired = true;
6780
+ return Promise.resolve();
6781
+ }
6782
+ else {
6783
+ return new Promise((resolve, _) => {
6784
+ this.queue.push(resolve);
6785
+ });
6786
+ }
6787
+ });
6788
+ }
6789
+ release() {
6790
+ return __awaiter(this, void 0, void 0, function* () {
6791
+ if (this.queue.length === 0 && this.acquired) {
6792
+ this.acquired = false;
6793
+ return Promise.resolve();
6794
+ }
6795
+ const continuation = this.queue.shift();
6796
+ return new Promise((res) => {
6797
+ continuation();
6798
+ res();
6799
+ });
6800
+ });
6801
+ }
6802
+ }
6803
+
6804
+ var UserInformationService_1;
6805
+ let UserInformationService = UserInformationService_1 = class UserInformationService {
6806
+ getAuthToken() {
6807
+ const cookieValue = get(UserInformationService_1.TOKEN_COOKIE_KEY) || '{}';
6808
+ const authToken = JSON.parse(cookieValue);
6809
+ return authToken.access_token;
6810
+ }
6811
+ getTenantDomain() {
6812
+ const cookieValue = get(UserInformationService_1.TOKEN_COOKIE_KEY) || '{}';
6813
+ const authToken = JSON.parse(cookieValue);
6814
+ return authToken.username.split('@')[1];
6815
+ }
6816
+ getWebSocketUrl() {
6817
+ let baseUrl = get(UserInformationService_1.BASE_URL_COOKIE_KEY);
6818
+ if (baseUrl && !baseUrl.endsWith('/')) {
6819
+ baseUrl += '/';
6820
+ }
6821
+ return baseUrl + 'websocket';
6822
+ }
6823
+ };
6824
+ UserInformationService.BASE_URL_COOKIE_KEY = 'com.senior.base.url';
6825
+ UserInformationService.TOKEN_COOKIE_KEY = 'com.senior.token';
6826
+ UserInformationService.ɵprov = ɵɵdefineInjectable({ factory: function UserInformationService_Factory() { return new UserInformationService(); }, token: UserInformationService, providedIn: "root" });
6827
+ UserInformationService = UserInformationService_1 = __decorate([
6828
+ Injectable({
6829
+ providedIn: 'root'
6830
+ })
6831
+ ], UserInformationService);
6832
+
6833
+ class PrimitiveManager {
6834
+ constructor(domain, service, primitive) {
6835
+ this.domain = domain;
6836
+ this.service = service;
6837
+ this.primitive = primitive;
6838
+ this.stompSubscriptions = [];
6839
+ this.event$ = new Subject();
6840
+ this.subscribed$ = new BehaviorSubject(false);
6841
+ }
6842
+ unsubscribe() {
6843
+ this.event$.complete();
6844
+ for (const stompSubscription of this.stompSubscriptions) {
6845
+ stompSubscription.unsubscribe();
6846
+ }
6847
+ this.subscribed$.complete();
6848
+ }
6849
+ fireEvent(event) {
6850
+ this.event$.next(event);
6851
+ }
6852
+ subscribe(...subscriptions) {
6853
+ this.stompSubscriptions.push(...subscriptions);
6854
+ this.subscribed$.next(true);
6855
+ }
6856
+ getEventObservable() {
6857
+ return this.event$.asObservable();
6858
+ }
6859
+ getSubscriptionObservable() {
6860
+ return this.subscribed$.asObservable();
6861
+ }
6862
+ hasObservers() {
6863
+ // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
6864
+ return this.event$.observers.length !== 1;
6865
+ }
6866
+ getObserversCount() {
6867
+ return this.event$.observers.length;
6868
+ }
6869
+ }
6870
+
6871
+ const RECONNECT_INTERVAL_MILLISECONDS = 3000;
6872
+ const CONNECTION_TIMEOUT_MILLISECONDS = 5000;
6873
+ let WebsocketService = class WebsocketService {
6874
+ constructor(userInformationService) {
6875
+ this.userInformationService = userInformationService;
6783
6876
  this.connected$ = new BehaviorSubject(false);
6784
- /** @private */
6785
- this.disconnect$ = new Subject();
6786
- /** @private */
6787
- this.reconnect$ = new Subject();
6788
- /** @private */
6877
+ this.disconnected$ = new Subject();
6878
+ this.reconnected$ = new Subject();
6789
6879
  this.error$ = new Subject();
6790
6880
  this.subscribed$ = new Subject();
6881
+ this.primitiveManagers = new Map();
6882
+ this.connectionLock = new AsyncLock();
6883
+ this.debugEnable = false;
6884
+ this.lostConnection = false;
6791
6885
  }
6792
6886
  /**
6793
- * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida pela primeira vez.
6794
- * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida pela primeira vez.
6887
+ * Enables stompjs debug logs and additional info
6795
6888
  */
6796
- onConnect() {
6797
- return this.connected$.asObservable().pipe(filter(Boolean), map(() => undefined), take(1));
6889
+ enableDebugLogs() {
6890
+ this.debugEnable = true;
6798
6891
  }
6799
6892
  /**
6800
- * Observable responsável por emitir uma notificação quando a conexão é desconectada.
6801
- * @return Um `Observable<void>` que emite uma notificação quando a conexão é desconectada.
6893
+ * Manually starts the connection
6802
6894
  */
6803
- onDisconnect() {
6804
- return this.disconnect$.asObservable();
6895
+ connect() {
6896
+ return __awaiter(this, void 0, void 0, function* () {
6897
+ yield this.connectionLock.acquire();
6898
+ try {
6899
+ if (this.isConnected() || this.isConnecting()) {
6900
+ return;
6901
+ }
6902
+ this.lostConnection = false;
6903
+ const stompConfig = {
6904
+ webSocketFactory: () => {
6905
+ return new SockJS(this.getSubscriptionUrl(), null, {
6906
+ timeout: CONNECTION_TIMEOUT_MILLISECONDS
6907
+ });
6908
+ },
6909
+ connectionTimeout: CONNECTION_TIMEOUT_MILLISECONDS,
6910
+ reconnectDelay: RECONNECT_INTERVAL_MILLISECONDS,
6911
+ debug: this.debug.bind(this),
6912
+ onConnect: this.handleOnConnected.bind(this),
6913
+ onDisconnect: this.handleOnDisconnect.bind(this),
6914
+ onWebSocketClose: this.handleOnWebSocketClose.bind(this),
6915
+ onStompError: this.handleOnStompError.bind(this),
6916
+ onWebSocketError: this.handleOnWebSocketError.bind(this)
6917
+ };
6918
+ this.debug('Connecting the Webscoket');
6919
+ this.stompClient = new Client(stompConfig);
6920
+ this.stompClient.activate();
6921
+ }
6922
+ finally {
6923
+ yield this.connectionLock.release();
6924
+ }
6925
+ });
6805
6926
  }
6806
6927
  /**
6807
- * Observable responsável por emitir uma notificação quando a conexão é reconectada.
6808
- * @return Um `Observable<void>` que emite uma notificação quando a conexão é reconectada.
6928
+ * Manually disconnect the websocket. The reconnect loop will be stopped.
6809
6929
  */
6810
- onReconnect() {
6811
- return this.reconnect$.asObservable();
6930
+ disconnect() {
6931
+ return __awaiter(this, void 0, void 0, function* () {
6932
+ if (!this.isConnected()) {
6933
+ return;
6934
+ }
6935
+ yield this.connectionLock.acquire();
6936
+ try {
6937
+ for (const primitiveManager of this.primitiveManagers.values()) {
6938
+ primitiveManager.unsubscribe();
6939
+ }
6940
+ this.primitiveManagers.clear();
6941
+ this.connected$.next(false);
6942
+ if (this.stompClient) {
6943
+ yield this.stompClient.deactivate();
6944
+ }
6945
+ }
6946
+ finally {
6947
+ yield this.connectionLock.release();
6948
+ }
6949
+ });
6812
6950
  }
6813
6951
  /**
6814
- * Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
6815
- * @return Um `Observable<void>` que emite uma notificação após o subscribe do evento pela primeira vez.
6952
+ * Check if the websocket is connected
6953
+ * @return `boolean` representing if the websocket is connected
6816
6954
  */
6817
- onSubscribe({ domain, service, primitive }) {
6818
- const key = this.getPrimitiveManagerKey(domain, service, primitive);
6819
- return this.onConnect().pipe(switchMap(() => {
6820
- if (this.primitiveManagers.has(key))
6821
- return this.primitiveManagers
6822
- .get(key)
6823
- .subscribed$.asObservable()
6824
- .pipe(map(() => undefined), take(1));
6825
- return this.subscribed$.asObservable().pipe(filter((primitiveManager) => this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key), map(() => undefined), take(1));
6826
- }));
6955
+ isConnected() {
6956
+ if (!this.stompClient) {
6957
+ return false;
6958
+ }
6959
+ return this.stompClient.connected;
6960
+ }
6961
+ /**
6962
+ * Check if the websocket is tring to connect
6963
+ * @return `boolean` representing if the websocket status
6964
+ */
6965
+ isConnecting() {
6966
+ if (!this.stompClient) {
6967
+ return false;
6968
+ }
6969
+ return !this.stompClient.connected && this.stompClient.active;
6970
+ }
6971
+ /**
6972
+ * Event responsable to emit an event when the connection is established.
6973
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
6974
+ * @return `Observable<boolean>`
6975
+ */
6976
+ onConnect() {
6977
+ return this.connected$.asObservable()
6978
+ .pipe(filter(p => p === true));
6979
+ }
6980
+ /**
6981
+ * Event responsable to emit an event when the connection is closed.
6982
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
6983
+ * @return `Observable<void>`
6984
+ */
6985
+ onDisconnect() {
6986
+ return this.disconnected$.asObservable();
6987
+ }
6988
+ /**
6989
+ * Event responsable to emit an event when the connection is reestablished.
6990
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
6991
+ * @return `Observable<void>`
6992
+ */
6993
+ onReconnect() {
6994
+ return this.reconnected$.asObservable();
6827
6995
  }
6828
6996
  /**
6829
- * Observable responsável por emitir uma notificação quando ocorre algum erro.
6830
- * @return Um `Observable<FrameImpl>` que emite uma notificação quando ocorre algum erro.
6997
+ * Event responsable to emit an event when an error ocurred.
6998
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
6999
+ * @return `Observable<FrameImpl>`
6831
7000
  */
6832
7001
  onError() {
6833
7002
  return this.error$.asObservable();
6834
7003
  }
6835
7004
  /**
6836
- * @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
6837
- * @param {Object} options Objeto de configuração do evento.
6838
- * @param {string} options.domain Domínio da primitiva.
6839
- * @param {string} options.service Serviço da primitiva.
6840
- * @param {string} options.primitive Primitiva que será "observada".
6841
- * @return Um Observable<T> que emite notificações toda vez que o respectivo evento é publicado.
7005
+ * Event responsible to emit an event when a primitive is called.
7006
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7007
+ * @typeParam `<T>` Object type that will be used in the observable for the `data` property.
7008
+ * @param {OnEventOptions} options Configurations for the event.
7009
+ * @return `Observable<PrimitiveEvent<T>>` Observable that emits an event when the service calls the primitive.
6842
7010
  */
6843
7011
  onEvent(options) {
6844
- this.connect();
6845
7012
  const { domain, service, primitive } = options;
6846
- const key = this.getPrimitiveManagerKey(domain, service, primitive);
7013
+ const key = this.buildPrimitiveManagerKey(domain, service, primitive);
6847
7014
  if (this.primitiveManagers.has(key)) {
6848
- return this.primitiveManagers.get(key).event$.asObservable();
7015
+ return this.primitiveManagers.get(key).getEventObservable();
6849
7016
  }
6850
- const primitiveManager = {
6851
- domain: domain,
6852
- service: service,
6853
- primitive: primitive,
6854
- stompSubscriptions: [],
6855
- event$: new Subject(),
6856
- subscribed$: new BehaviorSubject(false)
6857
- };
7017
+ const primitiveManager = new PrimitiveManager(domain, service, primitive);
6858
7018
  this.primitiveManagers.set(key, primitiveManager);
6859
- this.onConnect()
6860
- .pipe(take(1))
6861
- .subscribe(() => {
6862
- this.createStompSubscriptions(primitiveManager);
7019
+ this.connect().then(() => {
7020
+ this.onConnect()
7021
+ .pipe(take(1))
7022
+ .subscribe(() => {
7023
+ this.createStompSubscriptions(primitiveManager);
7024
+ });
6863
7025
  });
6864
- return primitiveManager.event$
6865
- .asObservable()
6866
- .pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitiveManager)));
7026
+ return primitiveManager
7027
+ .getEventObservable()
7028
+ .pipe(finalize(() => this.unsubscribePrimitiveOnFinalize(primitiveManager)));
6867
7029
  }
6868
- /** @private */
6869
- createStompSubscriptions(primitiveManager) {
6870
- const withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6871
- const stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
6872
- const withoutTokenUrl = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6873
- const stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6874
- primitiveManager.stompSubscriptions = [
6875
- stompSubscriptionWithToken,
6876
- stompSubscriptionWithoutToken
6877
- ];
6878
- primitiveManager.subscribed$.next(true);
6879
- this.subscribed$.next(primitiveManager);
7030
+ /**
7031
+ * Event responsible to emit an event when a subscription is created for the primitive.
7032
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7033
+ * @param {OnEventOptions} options Configurations for the event.
7034
+ * Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
7035
+ * @return `Observable<boolean>` Observable that emits an event when the service calls the primitive.
7036
+ */
7037
+ onSubscribe(options) {
7038
+ const { domain, service, primitive } = options;
7039
+ const key = this.buildPrimitiveManagerKey(domain, service, primitive);
7040
+ return this.onConnect().pipe(take(1), switchMap(() => {
7041
+ if (this.primitiveManagers.has(key)) {
7042
+ return this.primitiveManagers
7043
+ .get(key)
7044
+ .getSubscriptionObservable()
7045
+ .pipe(take(1));
7046
+ }
7047
+ return this.subscribed$.asObservable().pipe(filter((primitiveManager) => {
7048
+ return this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key;
7049
+ }), map(() => true), take(1));
7050
+ }));
6880
7051
  }
6881
- /** @private */
6882
- connect() {
6883
- if (this.isConnected || this.isConnecting)
7052
+ debug(message, ...optionalParams) {
7053
+ if (!this.debugEnable) {
6884
7054
  return;
6885
- this.createStompClient();
6886
- this.isConnecting = true;
6887
- this._stompClient.connect({}, () => {
6888
- this.isConnecting = false;
6889
- this.isConnected = true;
6890
- if (this.wasConnected) {
6891
- this.reconnectPrimitives();
6892
- this.connected$.next(true);
6893
- this.reconnect$.next();
6894
- }
6895
- else {
6896
- this.wasConnected = true;
6897
- this.connected$.next(true);
6898
- }
6899
- }, (error) => {
6900
- this.isConnected = false;
6901
- this.connected$.next(false);
6902
- this.error$.next(error);
6903
- race(this.disconnect$.pipe(take(1), map(() => ({ wasDisconnected: true }))), timer(WebsocketService_1.RECONNECT_INTERVAL).pipe(take(1), switchMap(() => iif(() => document.hidden, fromEvent(document, 'visibilitychange').pipe(first()), of(void 0))), map(() => ({ wasDisconnected: false }))))
6904
- .pipe(take(1))
6905
- .subscribe({
6906
- next: ({ wasDisconnected }) => {
6907
- if (!wasDisconnected &&
6908
- !(this.isConnected || this.isConnecting)) {
6909
- this.connect();
6910
- }
6911
- }
6912
- });
6913
- });
7055
+ }
7056
+ console.log('WS debug: ' + message, ...optionalParams);
6914
7057
  }
6915
- disconnect() {
6916
- if (!this.isConnected || this.getObserversCount() > 0) {
7058
+ info(message) {
7059
+ console.info('WS info: ' + message);
7060
+ }
7061
+ handleOnConnected() {
7062
+ this.info('Webscoket connected');
7063
+ this.connected$.next(true);
7064
+ if (this.lostConnection) {
7065
+ this.info('Webscoket reconnected, recriating subscriptions');
7066
+ this.handleReconnection();
7067
+ }
7068
+ }
7069
+ handleOnDisconnect() {
7070
+ this.info('Webscoket disconnected');
7071
+ this.connected$.next(false);
7072
+ this.disconnected$.next();
7073
+ }
7074
+ handleOnWebSocketClose(data) {
7075
+ if (data.wasClean) {
6917
7076
  return;
6918
7077
  }
6919
- for (const primitiveManager of this.primitiveManagers.values()) {
6920
- for (const stompSubscription of primitiveManager.stompSubscriptions) {
6921
- stompSubscription.unsubscribe();
6922
- }
7078
+ this.lostConnection = true;
7079
+ }
7080
+ handleOnStompError(data) {
7081
+ this.handleError('StompError', data);
7082
+ if (this.isAuthenticationError(data)) {
7083
+ this.info('Authentication error, recriating subscriptions');
7084
+ this.handleReconnection();
6923
7085
  }
6924
- for (const primitiveManager of this.primitiveManagers.values()) {
6925
- primitiveManager.event$.complete();
7086
+ }
7087
+ isAuthenticationError(data) {
7088
+ var _a;
7089
+ const errorMessage = (_a = data === null || data === void 0 ? void 0 : data.headers) === null || _a === void 0 ? void 0 : _a.message;
7090
+ if (!errorMessage) {
7091
+ return false;
6926
7092
  }
6927
- this.primitiveManagers.clear();
6928
- this._stompClient.disconnect();
6929
- this._stompClient.deactivate();
6930
- this.isConnected = false;
6931
- this.isConnecting = false;
6932
- this.wasConnected = false;
6933
- this.connected$.next(false);
6934
- this.disconnect$.next();
6935
- }
6936
- /** @private */
6937
- getSubscriptionUrlWithToken(domain, service, primitive) {
6938
- const tenant = WebsocketService_1.TOKEN
6939
- ? WebsocketService_1.TOKEN.username.split('@')[1]
6940
- : null;
6941
- const token = WebsocketService_1.TOKEN
6942
- ? WebsocketService_1.TOKEN.access_token
6943
- : null;
6944
- return `/topic/${tenant}/${token}/${domain}/${service}/${primitive}`;
6945
- }
6946
- /** @private */
6947
- getSubscriptionUrlWithoutToken(domain, service, primitive) {
6948
- const tenant = WebsocketService_1.TOKEN
6949
- ? WebsocketService_1.TOKEN.username.split('@')[1]
6950
- : null;
6951
- return `/topic/${tenant}/${domain}/${service}/${primitive}`;
7093
+ return errorMessage.toLowerCase().indexOf('forbiddenexception') !== -1;
6952
7094
  }
6953
- /** @private */
6954
- createStompSubscription(destination, primitiveManager) {
6955
- return this._stompClient.subscribe(destination, (message) => {
6956
- const event = JSON.parse(message.body || '{}');
6957
- primitiveManager.event$.next(event);
6958
- });
7095
+ handleOnWebSocketError(data) {
7096
+ this.handleError('WebSocketError', data);
6959
7097
  }
6960
- /** @private */
6961
- createStompClient() {
6962
- const ws = new SockJS(`${WebsocketService_1.WEBSOCKET_URL}subscription`, null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
6963
- this._stompClient = Stomp.over(ws);
6964
- this._stompClient.debug = () => null;
7098
+ handleError(origin, data) {
7099
+ console.error(origin, data);
7100
+ this.error$.next(data);
7101
+ }
7102
+ handleReconnection() {
7103
+ this.lostConnection = false;
7104
+ this.reconnectPrimitives();
7105
+ this.reconnected$.next();
6965
7106
  }
6966
- /** @private */
6967
7107
  reconnectPrimitives() {
6968
7108
  for (const primitiveManager of this.primitiveManagers.values()) {
6969
7109
  this.createStompSubscriptions(primitiveManager);
6970
7110
  }
6971
7111
  }
6972
- /** @private */
7112
+ buildSubscriptionUrlWithToken(domain, service, primitive) {
7113
+ const authToken = this.userInformationService.getAuthToken();
7114
+ const tenant = this.userInformationService.getTenantDomain();
7115
+ return `/topic/${tenant}/${authToken}/${domain}/${service}/${primitive}`;
7116
+ }
7117
+ getSubscriptionUrlWithoutToken(domain, service, primitive) {
7118
+ const tenant = this.userInformationService.getTenantDomain();
7119
+ return `/topic/${tenant}/${domain}/${service}/${primitive}`;
7120
+ }
7121
+ buildPrimitiveManagerKey(domain, service, primitive) {
7122
+ return `${domain}/${service}/${primitive}`;
7123
+ }
7124
+ unsubscribePrimitiveOnFinalize(primitiveManager) {
7125
+ return __awaiter(this, void 0, void 0, function* () {
7126
+ if (primitiveManager.hasObservers()) {
7127
+ return;
7128
+ }
7129
+ primitiveManager.unsubscribe();
7130
+ const key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7131
+ this.primitiveManagers.delete(key);
7132
+ yield this.disconnectIfNoMoreObservables();
7133
+ });
7134
+ }
7135
+ disconnectIfNoMoreObservables() {
7136
+ return __awaiter(this, void 0, void 0, function* () {
7137
+ if (this.getObserversCount() === 0) {
7138
+ this.debug('Manually disconnecting because there are no more observers');
7139
+ yield this.disconnect();
7140
+ }
7141
+ });
7142
+ }
6973
7143
  getObserversCount() {
6974
7144
  let observersCount = 0;
6975
- for (const primitiveManager of this.primitiveManagers.values()) {
6976
- observersCount += primitiveManager.event$.observers.length;
6977
- }
7145
+ this.primitiveManagers.forEach(primitiveManager => {
7146
+ observersCount += primitiveManager.getObserversCount();
7147
+ });
6978
7148
  return observersCount;
6979
7149
  }
6980
- /** @private */
6981
- disconnectPrimitiveOnFinalize(primitiveManager) {
6982
- // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
6983
- const hasObservers = !(primitiveManager.event$.observers.length === 1);
6984
- if (hasObservers)
6985
- return;
6986
- primitiveManager.event$.complete();
6987
- for (const stompSubscription of primitiveManager.stompSubscriptions) {
6988
- stompSubscription.unsubscribe();
6989
- }
6990
- primitiveManager.subscribed$.complete();
6991
- const key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6992
- this.primitiveManagers.delete(key);
6993
- this.disconnect();
7150
+ createStompSubscription(destination, primitiveManager) {
7151
+ return this.stompClient.subscribe(destination, (message) => {
7152
+ const event = JSON.parse(message.body || '{}');
7153
+ primitiveManager.fireEvent(event);
7154
+ });
6994
7155
  }
6995
- /** @private */
6996
- getPrimitiveManagerKey(domain, service, primitive) {
6997
- return `${domain}/${service}/${primitive}`;
7156
+ createStompSubscriptions(primitiveManager) {
7157
+ const subscriptionUrlWithToken = this.buildSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7158
+ const subscriptionUrlWithoutToken = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7159
+ const stompSubscriptionWithToken = this.createStompSubscription(subscriptionUrlWithToken, primitiveManager);
7160
+ const stompSubscriptionWithoutToken = this.createStompSubscription(subscriptionUrlWithoutToken, primitiveManager);
7161
+ primitiveManager.subscribe(stompSubscriptionWithToken, stompSubscriptionWithoutToken);
7162
+ this.subscribed$.next(primitiveManager);
7163
+ }
7164
+ getSubscriptionUrl() {
7165
+ return `${this.userInformationService.getWebSocketUrl()}/subscription`;
6998
7166
  }
6999
7167
  };
7000
- WebsocketService.RECONNECT_INTERVAL = 3000;
7001
- WebsocketService.CONNECTION_TIMEOUT = 15000;
7002
- /** @private */
7003
- WebsocketService.BASE_URL_COOKIE = 'com.senior.base.url';
7004
- /** @private */
7005
- WebsocketService.TOKEN_COOKIE = 'com.senior.token';
7006
- /** @private */
7007
- WebsocketService.TOKEN = JSON.parse(get(WebsocketService_1.TOKEN_COOKIE) || '{}');
7008
- /** @private */
7009
- WebsocketService.WEBSOCKET_URL = get(WebsocketService_1.BASE_URL_COOKIE) + '/websocket/';
7010
- WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
7011
- WebsocketService = WebsocketService_1 = __decorate([
7168
+ WebsocketService.ctorParameters = () => [
7169
+ { type: UserInformationService }
7170
+ ];
7171
+ WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(ɵɵinject(UserInformationService)); }, token: WebsocketService, providedIn: "root" });
7172
+ WebsocketService = __decorate([
7012
7173
  Injectable({
7013
7174
  providedIn: 'root'
7014
7175
  })
@@ -7078,6 +7239,69 @@ VerifyModulePermission = VerifyModulePermission_1 = __decorate([
7078
7239
  })
7079
7240
  ], VerifyModulePermission);
7080
7241
 
7242
+ var VerifyModulePermissionsService_1;
7243
+ let VerifyModulePermissionsService = VerifyModulePermissionsService_1 = class VerifyModulePermissionsService {
7244
+ constructor(http) {
7245
+ this.http = http;
7246
+ }
7247
+ consultaModulos(request) {
7248
+ return this.http.post(VerifyModulePermissionsService_1.QUERY_MODULES_URL, request);
7249
+ }
7250
+ };
7251
+ VerifyModulePermissionsService.QUERY_MODULES_URL = "erpx_fnd/empresa/queries/consultaModulos";
7252
+ VerifyModulePermissionsService.ctorParameters = () => [
7253
+ { type: HttpClient }
7254
+ ];
7255
+ VerifyModulePermissionsService.ɵprov = ɵɵdefineInjectable({ factory: function VerifyModulePermissionsService_Factory() { return new VerifyModulePermissionsService(ɵɵinject(HttpClient)); }, token: VerifyModulePermissionsService, providedIn: "any" });
7256
+ VerifyModulePermissionsService = VerifyModulePermissionsService_1 = __decorate([
7257
+ Injectable({
7258
+ providedIn: "any"
7259
+ })
7260
+ ], VerifyModulePermissionsService);
7261
+
7262
+ var VerifyModulePermissions_1;
7263
+ let VerifyModulePermissions = VerifyModulePermissions_1 = class VerifyModulePermissions {
7264
+ constructor(verifyModulePermissionsService) {
7265
+ this.verifyModulePermissionsService = verifyModulePermissionsService;
7266
+ }
7267
+ /**
7268
+ * Method to verify if user has permission on a specific module
7269
+ * @param modules Modules to verify the permission
7270
+ * @param requestPermission Indicative if must be call the primitive
7271
+ * @returns An boolean Observable
7272
+ */
7273
+ hasPermissions(modules, requestPermission) {
7274
+ const moduleSubject = VerifyModulePermissions_1.subjectsPerModuleMap.get(modules);
7275
+ if (!moduleSubject || requestPermission) {
7276
+ const newModuleSubject = new ReplaySubject(1);
7277
+ VerifyModulePermissions_1.subjectsPerModuleMap.set(modules, newModuleSubject);
7278
+ this.verifyModulePermissionsService
7279
+ .consultaModulos({ modulo: modules, somenteAtivo: true })
7280
+ .pipe(take(1))
7281
+ .subscribe(response => {
7282
+ const hasPermissions = (response === null || response === void 0 ? void 0 : response.modulos) || [];
7283
+ newModuleSubject.next(hasPermissions);
7284
+ }, (err) => {
7285
+ VerifyModulePermissions_1.subjectsPerModuleMap.delete(modules);
7286
+ newModuleSubject.error(err);
7287
+ newModuleSubject.unsubscribe();
7288
+ });
7289
+ return newModuleSubject.asObservable();
7290
+ }
7291
+ return moduleSubject.asObservable();
7292
+ }
7293
+ };
7294
+ VerifyModulePermissions.ctorParameters = () => [
7295
+ { type: VerifyModulePermissionsService }
7296
+ ];
7297
+ VerifyModulePermissions.subjectsPerModuleMap = new Map();
7298
+ VerifyModulePermissions.ɵprov = ɵɵdefineInjectable({ factory: function VerifyModulePermissions_Factory() { return new VerifyModulePermissions(ɵɵinject(VerifyModulePermissionsService)); }, token: VerifyModulePermissions, providedIn: "root" });
7299
+ VerifyModulePermissions = VerifyModulePermissions_1 = __decorate([
7300
+ Injectable({
7301
+ providedIn: "root"
7302
+ })
7303
+ ], VerifyModulePermissions);
7304
+
7081
7305
  var ModulesEnum;
7082
7306
  (function (ModulesEnum) {
7083
7307
  ModulesEnum["CONTROLADORIA"] = "CONTROLADORIA";
@@ -7096,5 +7320,5 @@ var ModulesEnum;
7096
7320
  * Generated bundle index. Do not edit.
7097
7321
  */
7098
7322
 
7099
- export { AgreementLookup, BankLookup, BeneficioFiscalLookup, BreadcrumbComponent, BreadcrumbModule, Breakpoints, ContaInternaFilialLookup, CountryLookup, CplTriNotaSaidaE001EndLookup, CplTriNotaSaidaE001PesLookup, CplTriNotaSaidaE001TnsLookup, CplTriNotaSaidaE007UfsLookup, CplTriNotaSaidaE008RaiLookup, CplTriNotaSaidaE015MedLookup, CplTriNotaSaidaE020SnfLookup, CplTriNotaSaidaE024MsgLookup, CplTriNotaSaidaE028CpgLookup, CplTriNotaSaidaE032EdcLookup, CplTriNotaSaidaE051DisLookup, CplTriNotaSaidaE066FpgLookup, CplTriNotaSaidaE070EmpLookup, CplTriNotaSaidaE070FilLookup, CplTriNotaSaidaE075DerLookup, CplTriNotaSaidaE080SerLookup, CplTriNotaSaidaNaturezaReceitaPisCofinsLookup, CplTriNotaSaidaNcmLookup, CplTriNotaSaidaNfEntradaLookup, CplTriNotaSaidaNfSaidaLookup, CurrencyLookup, DocumentoLookup, E001EndLookup, E001PesLookup, E001TnsLookup, E001TnsSupEstLookup, E002TptLookup, E007UfsLookup, E008CepLookup, E008RaiLookup, E012FamLookup, E015MedLookup, E020SnfLookup, E021MotLookup, E023CrpLookup, E024MsgLookup, E027EqiLookup, E027StrLookup, E028CpgLookup, E030AgeLookup, E030BanLookup, E031MoeLookup, E032EdcLookup, E035OcrLookup, E036InsLookup, E039PorLookup, E043MpcLookup, E043PcmLookup, E044CcuFinRatDepLookup, E044CcuLookup, E045PlaLookup, E046HpdLookup, E047NtgLookup, E048FctLookup, E048SfcLookup, E051DisLookup, E066FpgLookup, E067FinLookup, E069GreLookup, E070EmpLookup, E070EntLookup, E070FilLookup, E073PesLookup, E073VeiLookup, E075DerLookup, E080SerLookup, E081TabLookup, E082TprLookup, E085PesLookup, E089DocLookup, E090HrpComGerLookup, E090PesLookup, E091PlfFinRatLookup, E095PesLookup, E099UsuComGerLookup, E099UsuSupCprLookup, E140InsLookup, E140NfsLookup, E200LotLookup, E200SerLookup, E205DepLookup, E210DxpE075DerLookup, E210DxpLookup, E301TcrLookup, E403FprLookup, E420IcpLookup, E420IpcLookup, E420OcpLookup, E501TcpLookup, E600CcoLookup, E640LotLookup, EntityPersonProductLookup, EnumLogicalOperator, EquipmentLookup, ErpLookups, ErpLookupsModule, ErpPolling, ExportUtils, FiltersStorageService, FormUtilsService, HTTP_STATUS_CODE, LigacaoItemFornecedorLookup, LookupValidationUtils, ModulesEnum, NcmLookup, NotaFiscalEntradaLookup, NpsService, ParametersLookup, ProdutoServicoLookup, QuantidadeDisponivelDemandaLookup, RequisicaoLookup, SegmentoLookup, TypeTaxesLookup, UnidadeMedidaLookup, UtilsModule, VerifyModulePermission, WebsocketService, naturezaReceitaPisCofins, ɵ0, ErpLookupsService as ɵa, EnumAnaSin as ɵb, EnumNatCtb as ɵc, StorageService as ɵd, VerifyModulePermissionService as ɵe };
7323
+ export { AgreementLookup, BankLookup, BeneficioFiscalLookup, BreadcrumbComponent, BreadcrumbModule, Breakpoints, ContaInternaFilialLookup, CountryLookup, CplTriNotaSaidaE001EndLookup, CplTriNotaSaidaE001PesLookup, CplTriNotaSaidaE001TnsLookup, CplTriNotaSaidaE007UfsLookup, CplTriNotaSaidaE008RaiLookup, CplTriNotaSaidaE015MedLookup, CplTriNotaSaidaE020SnfLookup, CplTriNotaSaidaE024MsgLookup, CplTriNotaSaidaE028CpgLookup, CplTriNotaSaidaE032EdcLookup, CplTriNotaSaidaE051DisLookup, CplTriNotaSaidaE066FpgLookup, CplTriNotaSaidaE070EmpLookup, CplTriNotaSaidaE070FilLookup, CplTriNotaSaidaE075DerLookup, CplTriNotaSaidaE080SerLookup, CplTriNotaSaidaNaturezaReceitaPisCofinsLookup, CplTriNotaSaidaNcmLookup, CplTriNotaSaidaNfEntradaLookup, CplTriNotaSaidaNfSaidaLookup, CurrencyLookup, DocumentoLookup, E001EndLookup, E001PesLookup, E001TnsLookup, E001TnsSupEstLookup, E002TptLookup, E007UfsLookup, E008CepLookup, E008RaiLookup, E012FamLookup, E015MedLookup, E020SnfLookup, E021MotLookup, E023CrpLookup, E024MsgLookup, E027EqiLookup, E027StrLookup, E028CpgLookup, E030AgeLookup, E030BanLookup, E031MoeLookup, E032EdcLookup, E035OcrLookup, E036InsLookup, E039PorLookup, E043MpcLookup, E043PcmLookup, E044CcuFinRatDepLookup, E044CcuLookup, E045PlaLookup, E046HpdLookup, E047NtgLookup, E048FctLookup, E048SfcLookup, E051DisLookup, E066FpgLookup, E067FinLookup, E069GreLookup, E070EmpLookup, E070EntLookup, E070FilLookup, E073PesLookup, E073VeiLookup, E075DerLookup, E080SerLookup, E081TabLookup, E082TprLookup, E085PesLookup, E089DocLookup, E090HrpComGerLookup, E090PesLookup, E091PlfFinRatLookup, E095PesLookup, E099UsuComGerLookup, E099UsuSupCprLookup, E140InsLookup, E140NfsLookup, E200LotLookup, E200SerLookup, E205DepLookup, E210DxpE075DerLookup, E210DxpLookup, E301TcrLookup, E403FprLookup, E420IcpLookup, E420IpcLookup, E420OcpLookup, E501TcpLookup, E600CcoLookup, E640LotLookup, EntityPersonProductLookup, EnumLogicalOperator, EquipmentLookup, ErpLookups, ErpLookupsModule, ErpPolling, ExportUtils, FiltersStorageService, FormUtilsService, HTTP_STATUS_CODE, LigacaoItemFornecedorLookup, LookupValidationUtils, ModulesEnum, NcmLookup, NotaFiscalEntradaLookup, NpsService, ParametersLookup, PrimitiveManager, ProdutoServicoLookup, QuantidadeDisponivelDemandaLookup, RequisicaoLookup, SegmentoLookup, TypeTaxesLookup, UnidadeMedidaLookup, UtilsModule, VerifyModulePermission, VerifyModulePermissions, WebsocketService, naturezaReceitaPisCofins, ɵ0, ErpLookupsService as ɵa, EnumAnaSin as ɵb, EnumNatCtb as ɵc, StorageService as ɵd, UserInformationService as ɵe, VerifyModulePermissionService as ɵf, VerifyModulePermissionsService as ɵg };
7100
7324
  //# sourceMappingURL=senior-gestao-empresarial-angular-components.js.map