@senior-gestao-empresarial/angular-components 6.11.5-f1ae0f56-eaa0-41bd-bf14-efca8153a452 → 6.12.0-29fe646c-2d98-4822-8690-597195a76ad7

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 +514 -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 +260 -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 +318 -256
  42. package/esm5/senior-gestao-empresarial-angular-components.js +4 -2
  43. package/fesm2015/senior-gestao-empresarial-angular-components.js +418 -193
  44. package/fesm2015/senior-gestao-empresarial-angular-components.js.map +1 -1
  45. package/fesm5/senior-gestao-empresarial-angular-components.js +510 -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,409 @@ 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.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
+ this.stompClient.forceDisconnect();
6944
+ yield this.stompClient.deactivate();
6945
+ }
6946
+ }
6947
+ finally {
6948
+ yield this.connectionLock.release();
6949
+ }
6950
+ });
6812
6951
  }
6813
6952
  /**
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.
6953
+ * Check if the websocket is connected
6954
+ * @return `boolean` representing if the websocket is connected
6816
6955
  */
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
- }));
6956
+ isConnected() {
6957
+ if (!this.stompClient) {
6958
+ return false;
6959
+ }
6960
+ return this.stompClient.connected;
6961
+ }
6962
+ /**
6963
+ * Check if the websocket is tring to connect
6964
+ * @return `boolean` representing if the websocket status
6965
+ */
6966
+ isConnecting() {
6967
+ if (!this.stompClient) {
6968
+ return false;
6969
+ }
6970
+ return !this.stompClient.connected && this.stompClient.active;
6971
+ }
6972
+ /**
6973
+ * Event responsable to emit an event when the connection is established.
6974
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
6975
+ * @return `Observable<boolean>`
6976
+ */
6977
+ onConnect() {
6978
+ return this.connected$.asObservable()
6979
+ .pipe(filter(p => p === true));
6980
+ }
6981
+ /**
6982
+ * Event responsable to emit an event when the connection is closed.
6983
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
6984
+ * @return `Observable<void>`
6985
+ */
6986
+ onDisconnect() {
6987
+ return this.disconnected$.asObservable();
6988
+ }
6989
+ /**
6990
+ * Event responsable to emit an event when the connection is reestablished.
6991
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
6992
+ * @return `Observable<void>`
6993
+ */
6994
+ onReconnect() {
6995
+ return this.reconnected$.asObservable();
6827
6996
  }
6828
6997
  /**
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.
6998
+ * Event responsable to emit an event when an error ocurred.
6999
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7000
+ * @return `Observable<FrameImpl>`
6831
7001
  */
6832
7002
  onError() {
6833
7003
  return this.error$.asObservable();
6834
7004
  }
6835
7005
  /**
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.
7006
+ * Event responsible to emit an event when a primitive is called.
7007
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7008
+ * @typeParam `<T>` Object type that will be used in the observable for the `data` property.
7009
+ * @param {OnEventOptions} options Configurations for the event.
7010
+ * @return `Observable<PrimitiveEvent<T>>` Observable that emits an event when the service calls the primitive.
6842
7011
  */
6843
7012
  onEvent(options) {
6844
- this.connect();
6845
7013
  const { domain, service, primitive } = options;
6846
- const key = this.getPrimitiveManagerKey(domain, service, primitive);
7014
+ const key = this.buildPrimitiveManagerKey(domain, service, primitive);
6847
7015
  if (this.primitiveManagers.has(key)) {
6848
- return this.primitiveManagers.get(key).event$.asObservable();
7016
+ return this.primitiveManagers.get(key).getEventObservable();
6849
7017
  }
6850
- const primitiveManager = {
6851
- domain: domain,
6852
- service: service,
6853
- primitive: primitive,
6854
- stompSubscriptions: [],
6855
- event$: new Subject(),
6856
- subscribed$: new BehaviorSubject(false)
6857
- };
7018
+ const primitiveManager = new PrimitiveManager(domain, service, primitive);
6858
7019
  this.primitiveManagers.set(key, primitiveManager);
6859
- this.onConnect()
6860
- .pipe(take(1))
6861
- .subscribe(() => {
6862
- this.createStompSubscriptions(primitiveManager);
7020
+ this.connect().then(() => {
7021
+ this.onConnect()
7022
+ .pipe(take(1))
7023
+ .subscribe(() => {
7024
+ this.createStompSubscriptions(primitiveManager);
7025
+ });
6863
7026
  });
6864
- return primitiveManager.event$
6865
- .asObservable()
6866
- .pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitiveManager)));
7027
+ return primitiveManager
7028
+ .getEventObservable()
7029
+ .pipe(finalize(() => this.unsubscribePrimitiveOnFinalize(primitiveManager)));
6867
7030
  }
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);
7031
+ /**
7032
+ * Event responsible to emit an event when a subscription is created for the primitive.
7033
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7034
+ * @param {OnEventOptions} options Configurations for the event.
7035
+ * Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
7036
+ * @return `Observable<boolean>` Observable that emits an event when the service calls the primitive.
7037
+ */
7038
+ onSubscribe(options) {
7039
+ const { domain, service, primitive } = options;
7040
+ const key = this.buildPrimitiveManagerKey(domain, service, primitive);
7041
+ return this.onConnect().pipe(take(1), switchMap(() => {
7042
+ if (this.primitiveManagers.has(key)) {
7043
+ return this.primitiveManagers
7044
+ .get(key)
7045
+ .getSubscriptionObservable()
7046
+ .pipe(take(1));
7047
+ }
7048
+ return this.subscribed$.asObservable().pipe(filter((primitiveManager) => {
7049
+ return this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key;
7050
+ }), map(() => true), take(1));
7051
+ }));
6880
7052
  }
6881
- /** @private */
6882
- connect() {
6883
- if (this.isConnected || this.isConnecting)
7053
+ debug(message, ...optionalParams) {
7054
+ if (!this.debugEnable) {
6884
7055
  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
- });
7056
+ }
7057
+ console.log('WS debug: ' + message, ...optionalParams);
6914
7058
  }
6915
- disconnect() {
6916
- if (!this.isConnected || this.getObserversCount() > 0) {
7059
+ info(message) {
7060
+ console.info('WS info: ' + message);
7061
+ }
7062
+ handleOnConnected() {
7063
+ this.info('Webscoket connected');
7064
+ this.connected$.next(true);
7065
+ if (this.lostConnection) {
7066
+ this.info('Webscoket reconnected, recriating subscriptions');
7067
+ this.handleReconnection();
7068
+ }
7069
+ }
7070
+ handleOnDisconnect() {
7071
+ this.info('Webscoket disconnected');
7072
+ this.connected$.next(false);
7073
+ this.disconnected$.next();
7074
+ }
7075
+ handleOnWebSocketClose(data) {
7076
+ if (data.wasClean) {
6917
7077
  return;
6918
7078
  }
6919
- for (const primitiveManager of this.primitiveManagers.values()) {
6920
- for (const stompSubscription of primitiveManager.stompSubscriptions) {
6921
- stompSubscription.unsubscribe();
6922
- }
7079
+ this.lostConnection = true;
7080
+ }
7081
+ handleOnStompError(data) {
7082
+ this.handleError('StompError', data);
7083
+ if (this.isAuthenticationError(data)) {
7084
+ this.info('Authentication error, recriating subscriptions');
7085
+ this.handleReconnection();
6923
7086
  }
6924
- for (const primitiveManager of this.primitiveManagers.values()) {
6925
- primitiveManager.event$.complete();
7087
+ }
7088
+ isAuthenticationError(data) {
7089
+ var _a;
7090
+ const errorMessage = (_a = data === null || data === void 0 ? void 0 : data.headers) === null || _a === void 0 ? void 0 : _a.message;
7091
+ if (!errorMessage) {
7092
+ return false;
6926
7093
  }
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}`;
7094
+ return errorMessage.toLowerCase().indexOf('forbiddenexception') !== -1;
6952
7095
  }
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
- });
7096
+ handleOnWebSocketError(data) {
7097
+ this.handleError('WebSocketError', data);
6959
7098
  }
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;
7099
+ handleError(origin, data) {
7100
+ console.error(origin, data);
7101
+ this.error$.next(data);
7102
+ }
7103
+ handleReconnection() {
7104
+ this.lostConnection = false;
7105
+ this.reconnectPrimitives();
7106
+ this.reconnected$.next();
6965
7107
  }
6966
- /** @private */
6967
7108
  reconnectPrimitives() {
6968
7109
  for (const primitiveManager of this.primitiveManagers.values()) {
6969
7110
  this.createStompSubscriptions(primitiveManager);
6970
7111
  }
6971
7112
  }
6972
- /** @private */
7113
+ buildSubscriptionUrlWithToken(domain, service, primitive) {
7114
+ const authToken = this.userInformationService.getAuthToken();
7115
+ const tenant = this.userInformationService.getTenantDomain();
7116
+ return `/topic/${tenant}/${authToken}/${domain}/${service}/${primitive}`;
7117
+ }
7118
+ getSubscriptionUrlWithoutToken(domain, service, primitive) {
7119
+ const tenant = this.userInformationService.getTenantDomain();
7120
+ return `/topic/${tenant}/${domain}/${service}/${primitive}`;
7121
+ }
7122
+ buildPrimitiveManagerKey(domain, service, primitive) {
7123
+ return `${domain}/${service}/${primitive}`;
7124
+ }
7125
+ unsubscribePrimitiveOnFinalize(primitiveManager) {
7126
+ return __awaiter(this, void 0, void 0, function* () {
7127
+ if (primitiveManager.hasObservers()) {
7128
+ return;
7129
+ }
7130
+ primitiveManager.unsubscribe();
7131
+ const key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7132
+ this.primitiveManagers.delete(key);
7133
+ yield this.disconnectIfNoMoreObservables();
7134
+ });
7135
+ }
7136
+ disconnectIfNoMoreObservables() {
7137
+ return __awaiter(this, void 0, void 0, function* () {
7138
+ if (this.getObserversCount() === 0) {
7139
+ this.debug('Manually disconnecting because there are no more observers');
7140
+ yield this.disconnect();
7141
+ }
7142
+ });
7143
+ }
6973
7144
  getObserversCount() {
6974
7145
  let observersCount = 0;
6975
- for (const primitiveManager of this.primitiveManagers.values()) {
6976
- observersCount += primitiveManager.event$.observers.length;
6977
- }
7146
+ this.primitiveManagers.forEach(primitiveManager => {
7147
+ observersCount += primitiveManager.getObserversCount();
7148
+ });
6978
7149
  return observersCount;
6979
7150
  }
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();
7151
+ createStompSubscription(destination, primitiveManager) {
7152
+ return this.stompClient.subscribe(destination, (message) => {
7153
+ const event = JSON.parse(message.body || '{}');
7154
+ primitiveManager.fireEvent(event);
7155
+ });
6994
7156
  }
6995
- /** @private */
6996
- getPrimitiveManagerKey(domain, service, primitive) {
6997
- return `${domain}/${service}/${primitive}`;
7157
+ createStompSubscriptions(primitiveManager) {
7158
+ const subscriptionUrlWithToken = this.buildSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7159
+ const subscriptionUrlWithoutToken = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7160
+ const stompSubscriptionWithToken = this.createStompSubscription(subscriptionUrlWithToken, primitiveManager);
7161
+ const stompSubscriptionWithoutToken = this.createStompSubscription(subscriptionUrlWithoutToken, primitiveManager);
7162
+ primitiveManager.subscribe(stompSubscriptionWithToken, stompSubscriptionWithoutToken);
7163
+ this.subscribed$.next(primitiveManager);
7164
+ }
7165
+ getSubscriptionUrl() {
7166
+ return `${this.userInformationService.getWebSocketUrl()}/subscription`;
6998
7167
  }
6999
7168
  };
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([
7169
+ WebsocketService.ctorParameters = () => [
7170
+ { type: UserInformationService }
7171
+ ];
7172
+ WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(ɵɵinject(UserInformationService)); }, token: WebsocketService, providedIn: "root" });
7173
+ WebsocketService = __decorate([
7012
7174
  Injectable({
7013
7175
  providedIn: 'root'
7014
7176
  })
@@ -7078,6 +7240,69 @@ VerifyModulePermission = VerifyModulePermission_1 = __decorate([
7078
7240
  })
7079
7241
  ], VerifyModulePermission);
7080
7242
 
7243
+ var VerifyModulePermissionsService_1;
7244
+ let VerifyModulePermissionsService = VerifyModulePermissionsService_1 = class VerifyModulePermissionsService {
7245
+ constructor(http) {
7246
+ this.http = http;
7247
+ }
7248
+ consultaModulos(request) {
7249
+ return this.http.post(VerifyModulePermissionsService_1.QUERY_MODULES_URL, request);
7250
+ }
7251
+ };
7252
+ VerifyModulePermissionsService.QUERY_MODULES_URL = "erpx_fnd/empresa/queries/consultaModulos";
7253
+ VerifyModulePermissionsService.ctorParameters = () => [
7254
+ { type: HttpClient }
7255
+ ];
7256
+ VerifyModulePermissionsService.ɵprov = ɵɵdefineInjectable({ factory: function VerifyModulePermissionsService_Factory() { return new VerifyModulePermissionsService(ɵɵinject(HttpClient)); }, token: VerifyModulePermissionsService, providedIn: "any" });
7257
+ VerifyModulePermissionsService = VerifyModulePermissionsService_1 = __decorate([
7258
+ Injectable({
7259
+ providedIn: "any"
7260
+ })
7261
+ ], VerifyModulePermissionsService);
7262
+
7263
+ var VerifyModulePermissions_1;
7264
+ let VerifyModulePermissions = VerifyModulePermissions_1 = class VerifyModulePermissions {
7265
+ constructor(verifyModulePermissionsService) {
7266
+ this.verifyModulePermissionsService = verifyModulePermissionsService;
7267
+ }
7268
+ /**
7269
+ * Method to verify if user has permission on a specific module
7270
+ * @param modules Modules to verify the permission
7271
+ * @param requestPermission Indicative if must be call the primitive
7272
+ * @returns An boolean Observable
7273
+ */
7274
+ hasPermissions(modules, requestPermission) {
7275
+ const moduleSubject = VerifyModulePermissions_1.subjectsPerModuleMap.get(modules);
7276
+ if (!moduleSubject || requestPermission) {
7277
+ const newModuleSubject = new ReplaySubject(1);
7278
+ VerifyModulePermissions_1.subjectsPerModuleMap.set(modules, newModuleSubject);
7279
+ this.verifyModulePermissionsService
7280
+ .consultaModulos({ modulo: modules, somenteAtivo: true })
7281
+ .pipe(take(1))
7282
+ .subscribe(response => {
7283
+ const hasPermissions = (response === null || response === void 0 ? void 0 : response.modulos) || [];
7284
+ newModuleSubject.next(hasPermissions);
7285
+ }, (err) => {
7286
+ VerifyModulePermissions_1.subjectsPerModuleMap.delete(modules);
7287
+ newModuleSubject.error(err);
7288
+ newModuleSubject.unsubscribe();
7289
+ });
7290
+ return newModuleSubject.asObservable();
7291
+ }
7292
+ return moduleSubject.asObservable();
7293
+ }
7294
+ };
7295
+ VerifyModulePermissions.ctorParameters = () => [
7296
+ { type: VerifyModulePermissionsService }
7297
+ ];
7298
+ VerifyModulePermissions.subjectsPerModuleMap = new Map();
7299
+ VerifyModulePermissions.ɵprov = ɵɵdefineInjectable({ factory: function VerifyModulePermissions_Factory() { return new VerifyModulePermissions(ɵɵinject(VerifyModulePermissionsService)); }, token: VerifyModulePermissions, providedIn: "root" });
7300
+ VerifyModulePermissions = VerifyModulePermissions_1 = __decorate([
7301
+ Injectable({
7302
+ providedIn: "root"
7303
+ })
7304
+ ], VerifyModulePermissions);
7305
+
7081
7306
  var ModulesEnum;
7082
7307
  (function (ModulesEnum) {
7083
7308
  ModulesEnum["CONTROLADORIA"] = "CONTROLADORIA";
@@ -7096,5 +7321,5 @@ var ModulesEnum;
7096
7321
  * Generated bundle index. Do not edit.
7097
7322
  */
7098
7323
 
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 };
7324
+ 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
7325
  //# sourceMappingURL=senior-gestao-empresarial-angular-components.js.map