@senior-gestao-empresarial/angular-components 6.11.5-f1ae0f56-eaa0-41bd-bf14-efca8153a452 → 6.12.0-bea9aaec-b4b5-4e5b-b8eb-155b7aa8d5aa

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 (37) hide show
  1. package/bundles/senior-gestao-empresarial-angular-components.umd.js +414 -251
  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/websocket/models/primitive-manager.d.ts +19 -0
  9. package/components/websocket/protocols/on-event-options.d.ts +8 -0
  10. package/components/websocket/protocols/primitive-event.d.ts +10 -0
  11. package/components/websocket/user-information.service.d.ts +7 -0
  12. package/components/websocket/websocket.service.d.ts +78 -74
  13. package/esm2015/components/permissions/index.js +2 -1
  14. package/esm2015/components/permissions/verify-module-permissions-service.js +26 -0
  15. package/esm2015/components/permissions/verify-module-permissions.js +51 -0
  16. package/esm2015/components/websocket/models/primitive-manager.js +39 -0
  17. package/esm2015/components/websocket/protocols/on-event-options.js +1 -0
  18. package/esm2015/components/websocket/protocols/primitive-event.js +1 -0
  19. package/esm2015/components/websocket/user-information.service.js +34 -0
  20. package/esm2015/components/websocket/websocket.service.js +233 -191
  21. package/esm2015/senior-gestao-empresarial-angular-components.js +4 -2
  22. package/esm5/components/permissions/index.js +2 -1
  23. package/esm5/components/permissions/verify-module-permissions-service.js +28 -0
  24. package/esm5/components/permissions/verify-module-permissions.js +53 -0
  25. package/esm5/components/websocket/models/primitive-manager.js +58 -0
  26. package/esm5/components/websocket/protocols/on-event-options.js +1 -0
  27. package/esm5/components/websocket/protocols/primitive-event.js +1 -0
  28. package/esm5/components/websocket/user-information.service.js +38 -0
  29. package/esm5/components/websocket/websocket.service.js +259 -252
  30. package/esm5/senior-gestao-empresarial-angular-components.js +4 -2
  31. package/fesm2015/senior-gestao-empresarial-angular-components.js +360 -190
  32. package/fesm2015/senior-gestao-empresarial-angular-components.js.map +1 -1
  33. package/fesm5/senior-gestao-empresarial-angular-components.js +411 -251
  34. package/fesm5/senior-gestao-empresarial-angular-components.js.map +1 -1
  35. package/package.json +3 -3
  36. package/senior-gestao-empresarial-angular-components.d.ts +3 -1
  37. package/senior-gestao-empresarial-angular-components.metadata.json +1 -1
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/breadcrumb'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('moment'), require('@seniorsistemas/angular-components'), require('@angular/common/http'), require('primeng/api'), require('@ngx-translate/core'), require('@seniorsistemas/platform-components'), require('@seniorsistemas/senior-platform-data'), require('@angular/forms'), require('@stomp/stompjs'), require('js-cookie'), require('sockjs-client')) :
3
- typeof define === 'function' && define.amd ? define('@senior-gestao-empresarial/angular-components', ['exports', '@angular/core', '@angular/common', 'primeng/breadcrumb', '@angular/router', 'rxjs', 'rxjs/operators', 'moment', '@seniorsistemas/angular-components', '@angular/common/http', 'primeng/api', '@ngx-translate/core', '@seniorsistemas/platform-components', '@seniorsistemas/senior-platform-data', '@angular/forms', '@stomp/stompjs', 'js-cookie', 'sockjs-client'], factory) :
4
- (global = global || self, factory((global['senior-gestao-empresarial'] = global['senior-gestao-empresarial'] || {}, global['senior-gestao-empresarial']['angular-components'] = {}), global.ng.core, global.ng.common, global.breadcrumb, global.ng.router, global.rxjs, global.rxjs.operators, global.moment_, global.angularComponents, global.ng.common.http, global.api, global.core$1, global.platformComponents, global.seniorPlatformData, global.ng.forms, global.stompjs, global.jsCookie, global.SockJS));
5
- }(this, (function (exports, core, common, breadcrumb, router, rxjs, operators, moment_, angularComponents, http, api, core$1, platformComponents, seniorPlatformData, forms, stompjs, jsCookie, SockJS) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/breadcrumb'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('moment'), require('@seniorsistemas/angular-components'), require('@angular/common/http'), require('primeng/api'), require('@ngx-translate/core'), require('@seniorsistemas/platform-components'), require('@seniorsistemas/senior-platform-data'), require('@angular/forms'), require('@stomp/stompjs'), require('sockjs-client'), require('js-cookie')) :
3
+ typeof define === 'function' && define.amd ? define('@senior-gestao-empresarial/angular-components', ['exports', '@angular/core', '@angular/common', 'primeng/breadcrumb', '@angular/router', 'rxjs', 'rxjs/operators', 'moment', '@seniorsistemas/angular-components', '@angular/common/http', 'primeng/api', '@ngx-translate/core', '@seniorsistemas/platform-components', '@seniorsistemas/senior-platform-data', '@angular/forms', '@stomp/stompjs', 'sockjs-client', 'js-cookie'], factory) :
4
+ (global = global || self, factory((global['senior-gestao-empresarial'] = global['senior-gestao-empresarial'] || {}, global['senior-gestao-empresarial']['angular-components'] = {}), global.ng.core, global.ng.common, global.breadcrumb, global.ng.router, global.rxjs, global.rxjs.operators, global.moment_, global.angularComponents, global.ng.common.http, global.api, global.core$1, global.platformComponents, global.seniorPlatformData, global.ng.forms, global.stompjs, global.SockJS, global.jsCookie));
5
+ }(this, (function (exports, core, common, breadcrumb, router, rxjs, operators, moment_, angularComponents, http, api, core$1, platformComponents, seniorPlatformData, forms, stompjs, SockJS, jsCookie) { 'use strict';
6
6
 
7
7
  /*! *****************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -7412,320 +7412,413 @@
7412
7412
  return NpsService;
7413
7413
  }());
7414
7414
 
7415
+ var UserInformationService = /** @class */ (function () {
7416
+ function UserInformationService() {
7417
+ }
7418
+ UserInformationService_1 = UserInformationService;
7419
+ UserInformationService.prototype.getAuthToken = function () {
7420
+ var cookieValue = jsCookie.get(UserInformationService_1.TOKEN_COOKIE_KEY) || '{}';
7421
+ var authToken = JSON.parse(cookieValue);
7422
+ return authToken.access_token;
7423
+ };
7424
+ UserInformationService.prototype.getTenantDomain = function () {
7425
+ var cookieValue = jsCookie.get(UserInformationService_1.TOKEN_COOKIE_KEY) || '{}';
7426
+ var authToken = JSON.parse(cookieValue);
7427
+ return authToken.username.split('@')[1];
7428
+ };
7429
+ UserInformationService.prototype.getWebSocketUrl = function () {
7430
+ var baseUrl = jsCookie.get(UserInformationService_1.BASE_URL_COOKIE_KEY);
7431
+ if (!baseUrl.endsWith('/')) {
7432
+ baseUrl += '/';
7433
+ }
7434
+ return baseUrl + 'websocket';
7435
+ };
7436
+ var UserInformationService_1;
7437
+ UserInformationService.BASE_URL_COOKIE_KEY = 'com.senior.base.url';
7438
+ UserInformationService.TOKEN_COOKIE_KEY = 'com.senior.token';
7439
+ UserInformationService.ɵprov = core.ɵɵdefineInjectable({ factory: function UserInformationService_Factory() { return new UserInformationService(); }, token: UserInformationService, providedIn: "root" });
7440
+ UserInformationService = UserInformationService_1 = __decorate([
7441
+ core.Injectable({
7442
+ providedIn: 'root'
7443
+ })
7444
+ ], UserInformationService);
7445
+ return UserInformationService;
7446
+ }());
7447
+
7448
+ var PrimitiveManager = /** @class */ (function () {
7449
+ function PrimitiveManager(domain, service, primitive) {
7450
+ this.domain = domain;
7451
+ this.service = service;
7452
+ this.primitive = primitive;
7453
+ this.stompSubscriptions = [];
7454
+ this.event$ = new rxjs.Subject();
7455
+ this.subscribed$ = new rxjs.BehaviorSubject(false);
7456
+ }
7457
+ PrimitiveManager.prototype.unsubscribe = function () {
7458
+ var e_1, _a;
7459
+ this.event$.complete();
7460
+ try {
7461
+ for (var _b = __values(this.stompSubscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
7462
+ var stompSubscription = _c.value;
7463
+ stompSubscription.unsubscribe();
7464
+ }
7465
+ }
7466
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
7467
+ finally {
7468
+ try {
7469
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7470
+ }
7471
+ finally { if (e_1) throw e_1.error; }
7472
+ }
7473
+ this.subscribed$.complete();
7474
+ };
7475
+ PrimitiveManager.prototype.fireEvent = function (event) {
7476
+ this.event$.next(event);
7477
+ };
7478
+ PrimitiveManager.prototype.subscribe = function () {
7479
+ var _a;
7480
+ var subscriptions = [];
7481
+ for (var _i = 0; _i < arguments.length; _i++) {
7482
+ subscriptions[_i] = arguments[_i];
7483
+ }
7484
+ (_a = this.stompSubscriptions).push.apply(_a, __spread(subscriptions));
7485
+ this.subscribed$.next(true);
7486
+ };
7487
+ PrimitiveManager.prototype.getEventObservable = function () {
7488
+ return this.event$.asObservable();
7489
+ };
7490
+ PrimitiveManager.prototype.getSubscriptionObservable = function () {
7491
+ return this.subscribed$.asObservable();
7492
+ };
7493
+ PrimitiveManager.prototype.hasObservers = function () {
7494
+ // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7495
+ return this.event$.observers.length > 1;
7496
+ };
7497
+ PrimitiveManager.prototype.getObserversCount = function () {
7498
+ return this.event$.observers.length;
7499
+ };
7500
+ return PrimitiveManager;
7501
+ }());
7502
+
7503
+ var RECONNECT_INTERVAL_MILLISECONDS = 3000;
7504
+ var CONNECTION_TIMEOUT_MILLISECONDS = 5000;
7415
7505
  var WebsocketService = /** @class */ (function () {
7416
- function WebsocketService() {
7417
- /** @private */
7418
- this.wasConnected = false;
7419
- /** @private */
7420
- this.isConnected = false;
7421
- /** @private */
7422
- this.isConnecting = false;
7423
- /** @private */
7424
- this.primitiveManagers = new Map();
7425
- /** @private */
7506
+ function WebsocketService(userInformationService) {
7507
+ this.userInformationService = userInformationService;
7426
7508
  this.connected$ = new rxjs.BehaviorSubject(false);
7427
- /** @private */
7428
- this.disconnect$ = new rxjs.Subject();
7429
- /** @private */
7430
- this.reconnect$ = new rxjs.Subject();
7431
- /** @private */
7509
+ this.disconnected$ = new rxjs.Subject();
7510
+ this.reconnected$ = new rxjs.Subject();
7432
7511
  this.error$ = new rxjs.Subject();
7433
7512
  this.subscribed$ = new rxjs.Subject();
7513
+ this.primitiveManagers = new Map();
7514
+ this.debugEnable = false;
7515
+ this.lostConnection = false;
7434
7516
  }
7435
- WebsocketService_1 = WebsocketService;
7436
7517
  /**
7437
- * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7438
- * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7518
+ * Enables stompjs debug logs and additional info
7439
7519
  */
7440
- WebsocketService.prototype.onConnect = function () {
7441
- return this.connected$.asObservable().pipe(operators.filter(Boolean), operators.map(function () { return undefined; }), operators.take(1));
7520
+ WebsocketService.prototype.enableDebugLogs = function () {
7521
+ this.debugEnable = true;
7442
7522
  };
7443
7523
  /**
7444
- * Observable responsável por emitir uma notificação quando a conexão é desconectada.
7445
- * @return Um `Observable<void>` que emite uma notificação quando a conexão é desconectada.
7524
+ * Manually starts the connection
7446
7525
  */
7447
- WebsocketService.prototype.onDisconnect = function () {
7448
- return this.disconnect$.asObservable();
7526
+ WebsocketService.prototype.connect = function () {
7527
+ var _this = this;
7528
+ if (this.isConnected() || this.isConnecting()) {
7529
+ return;
7530
+ }
7531
+ this.lostConnection = false;
7532
+ var stompConfig = {
7533
+ webSocketFactory: function () {
7534
+ return new SockJS(_this.getSubscriptionUrl(), null, {
7535
+ timeout: CONNECTION_TIMEOUT_MILLISECONDS
7536
+ });
7537
+ },
7538
+ connectionTimeout: CONNECTION_TIMEOUT_MILLISECONDS,
7539
+ reconnectDelay: RECONNECT_INTERVAL_MILLISECONDS,
7540
+ debug: this.debug.bind(this),
7541
+ onConnect: this.handleOnConnected.bind(this),
7542
+ onDisconnect: this.handleOnDisconnect.bind(this),
7543
+ onWebSocketClose: this.handleOnWebSocketClose.bind(this),
7544
+ onStompError: this.handleOnStompError.bind(this),
7545
+ onWebSocketError: this.handleOnWebSocketError.bind(this)
7546
+ };
7547
+ this.debug('Connecting the Webscoket');
7548
+ this.stompClient = new stompjs.Client(stompConfig);
7549
+ this.stompClient.activate();
7449
7550
  };
7450
7551
  /**
7451
- * Observable responsável por emitir uma notificação quando a conexão é reconectada.
7452
- * @return Um `Observable<void>` que emite uma notificação quando a conexão é reconectada.
7552
+ * Manually disconnect the websocket. The reconnect loop will be stopped.
7453
7553
  */
7454
- WebsocketService.prototype.onReconnect = function () {
7455
- return this.reconnect$.asObservable();
7554
+ WebsocketService.prototype.disconnect = function () {
7555
+ return __awaiter(this, void 0, void 0, function () {
7556
+ var _a, _b, primitiveManager;
7557
+ var e_1, _c;
7558
+ return __generator(this, function (_d) {
7559
+ switch (_d.label) {
7560
+ case 0:
7561
+ try {
7562
+ for (_a = __values(this.primitiveManagers.values()), _b = _a.next(); !_b.done; _b = _a.next()) {
7563
+ primitiveManager = _b.value;
7564
+ primitiveManager.unsubscribe();
7565
+ }
7566
+ }
7567
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
7568
+ finally {
7569
+ try {
7570
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
7571
+ }
7572
+ finally { if (e_1) throw e_1.error; }
7573
+ }
7574
+ this.primitiveManagers.clear();
7575
+ if (!this.stompClient) return [3 /*break*/, 2];
7576
+ return [4 /*yield*/, this.stompClient.deactivate()];
7577
+ case 1:
7578
+ _d.sent();
7579
+ this.stompClient = null;
7580
+ _d.label = 2;
7581
+ case 2:
7582
+ this.connected$.next(false);
7583
+ return [2 /*return*/];
7584
+ }
7585
+ });
7586
+ });
7456
7587
  };
7457
7588
  /**
7458
- * Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
7459
- * @return Um `Observable<void>` que emite uma notificação após o subscribe do evento pela primeira vez.
7589
+ * Check if the websocket is connected
7590
+ * @return `boolean` representing if the websocket is connected
7460
7591
  */
7461
- WebsocketService.prototype.onSubscribe = function (_a) {
7462
- var _this = this;
7463
- var domain = _a.domain, service = _a.service, primitive = _a.primitive;
7464
- var key = this.getPrimitiveManagerKey(domain, service, primitive);
7465
- return this.onConnect().pipe(operators.switchMap(function () {
7466
- if (_this.primitiveManagers.has(key))
7467
- return _this.primitiveManagers
7468
- .get(key)
7469
- .subscribed$.asObservable()
7470
- .pipe(operators.map(function () { return undefined; }), operators.take(1));
7471
- return _this.subscribed$.asObservable().pipe(operators.filter(function (primitiveManager) {
7472
- return _this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key;
7473
- }), operators.map(function () { return undefined; }), operators.take(1));
7474
- }));
7592
+ WebsocketService.prototype.isConnected = function () {
7593
+ if (!this.stompClient) {
7594
+ return false;
7595
+ }
7596
+ return this.stompClient.connected;
7597
+ };
7598
+ /**
7599
+ * Check if the websocket is tring to connect
7600
+ * @return `boolean` representing if the websocket status
7601
+ */
7602
+ WebsocketService.prototype.isConnecting = function () {
7603
+ if (!this.stompClient) {
7604
+ return false;
7605
+ }
7606
+ return !this.stompClient.connected && this.stompClient.active;
7607
+ };
7608
+ /**
7609
+ * Event responsable to emit an event when the connection is established.
7610
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7611
+ * @return `Observable<boolean>`
7612
+ */
7613
+ WebsocketService.prototype.onConnect = function () {
7614
+ return this.connected$.asObservable()
7615
+ .pipe(operators.filter(function (p) { return p === true; }));
7475
7616
  };
7476
7617
  /**
7477
- * Observable responsável por emitir uma notificação quando ocorre algum erro.
7478
- * @return Um `Observable<FrameImpl>` que emite uma notificação quando ocorre algum erro.
7618
+ * Event responsable to emit an event when the connection is closed.
7619
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7620
+ * @return `Observable<void>`
7621
+ */
7622
+ WebsocketService.prototype.onDisconnect = function () {
7623
+ return this.disconnected$.asObservable();
7624
+ };
7625
+ /**
7626
+ * Event responsable to emit an event when the connection is reestablished.
7627
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7628
+ * @return `Observable<void>`
7629
+ */
7630
+ WebsocketService.prototype.onReconnect = function () {
7631
+ return this.reconnected$.asObservable();
7632
+ };
7633
+ /**
7634
+ * Event responsable to emit an event when an error ocurred.
7635
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7636
+ * @return `Observable<FrameImpl>`
7479
7637
  */
7480
7638
  WebsocketService.prototype.onError = function () {
7481
7639
  return this.error$.asObservable();
7482
7640
  };
7483
7641
  /**
7484
- * @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
7485
- * @param {Object} options Objeto de configuração do evento.
7486
- * @param {string} options.domain Domínio da primitiva.
7487
- * @param {string} options.service Serviço da primitiva.
7488
- * @param {string} options.primitive Primitiva que será "observada".
7489
- * @return Um Observable<T> que emite notificações toda vez que o respectivo evento é publicado.
7642
+ * Event responsible to emit an event when a primitive is called.
7643
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7644
+ * @typeParam `<T>` Object type that will be used in the observable for the `data` property.
7645
+ * @param {OnEventOptions} options Configurations for the event.
7646
+ * @return `Observable<PrimitiveEvent<T>>` Observable that emits an event when the service calls the primitive.
7490
7647
  */
7491
7648
  WebsocketService.prototype.onEvent = function (options) {
7492
7649
  var _this = this;
7493
- this.connect();
7494
7650
  var domain = options.domain, service = options.service, primitive = options.primitive;
7495
- var key = this.getPrimitiveManagerKey(domain, service, primitive);
7651
+ var key = this.buildPrimitiveManagerKey(domain, service, primitive);
7496
7652
  if (this.primitiveManagers.has(key)) {
7497
- return this.primitiveManagers.get(key).event$.asObservable();
7653
+ return this.primitiveManagers.get(key).getEventObservable();
7498
7654
  }
7499
- var primitiveManager = {
7500
- domain: domain,
7501
- service: service,
7502
- primitive: primitive,
7503
- stompSubscriptions: [],
7504
- event$: new rxjs.Subject(),
7505
- subscribed$: new rxjs.BehaviorSubject(false)
7506
- };
7655
+ var primitiveManager = new PrimitiveManager(domain, service, primitive);
7507
7656
  this.primitiveManagers.set(key, primitiveManager);
7657
+ this.connect();
7508
7658
  this.onConnect()
7509
7659
  .pipe(operators.take(1))
7510
7660
  .subscribe(function () {
7511
7661
  _this.createStompSubscriptions(primitiveManager);
7512
7662
  });
7513
- return primitiveManager.event$
7514
- .asObservable()
7515
- .pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7516
- };
7517
- /** @private */
7518
- WebsocketService.prototype.createStompSubscriptions = function (primitiveManager) {
7519
- var withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7520
- var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
7521
- var withoutTokenUrl = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7522
- var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
7523
- primitiveManager.stompSubscriptions = [
7524
- stompSubscriptionWithToken,
7525
- stompSubscriptionWithoutToken
7526
- ];
7527
- primitiveManager.subscribed$.next(true);
7528
- this.subscribed$.next(primitiveManager);
7663
+ return primitiveManager
7664
+ .getEventObservable()
7665
+ .pipe(operators.finalize(function () { return _this.unsubscribePrimitiveOnFinalize(primitiveManager); }));
7529
7666
  };
7530
- /** @private */
7531
- WebsocketService.prototype.connect = function () {
7667
+ /**
7668
+ * Event responsible to emit an event when a subscription is created for the primitive.
7669
+ * Do not forget to unsubscribe the observable when you don't need it anymore.
7670
+ * @param {OnEventOptions} options Configurations for the event.
7671
+ * Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
7672
+ * @return `Observable<boolean>` Observable that emits an event when the service calls the primitive.
7673
+ */
7674
+ WebsocketService.prototype.onSubscribe = function (options) {
7532
7675
  var _this = this;
7533
- if (this.isConnected || this.isConnecting)
7534
- return;
7535
- this.createStompClient();
7536
- this.isConnecting = true;
7537
- this._stompClient.connect({}, function () {
7538
- _this.isConnecting = false;
7539
- _this.isConnected = true;
7540
- if (_this.wasConnected) {
7541
- _this.reconnectPrimitives();
7542
- _this.connected$.next(true);
7543
- _this.reconnect$.next();
7676
+ var domain = options.domain, service = options.service, primitive = options.primitive;
7677
+ var key = this.buildPrimitiveManagerKey(domain, service, primitive);
7678
+ this.connect();
7679
+ return this.onConnect().pipe(operators.take(1), operators.switchMap(function () {
7680
+ if (_this.primitiveManagers.has(key)) {
7681
+ return _this.primitiveManagers
7682
+ .get(key)
7683
+ .getSubscriptionObservable()
7684
+ .pipe(operators.take(1));
7544
7685
  }
7545
- else {
7546
- _this.wasConnected = true;
7547
- _this.connected$.next(true);
7548
- }
7549
- }, function (error) {
7550
- _this.isConnected = false;
7551
- _this.connected$.next(false);
7552
- _this.error$.next(error);
7553
- rxjs.race(_this.disconnect$.pipe(operators.take(1), operators.map(function () { return ({ wasDisconnected: true }); })), rxjs.timer(WebsocketService_1.RECONNECT_INTERVAL).pipe(operators.take(1), operators.switchMap(function () {
7554
- return rxjs.iif(function () { return document.hidden; }, rxjs.fromEvent(document, 'visibilitychange').pipe(operators.first()), rxjs.of(void 0));
7555
- }), operators.map(function () { return ({ wasDisconnected: false }); })))
7556
- .pipe(operators.take(1))
7557
- .subscribe({
7558
- next: function (_a) {
7559
- var wasDisconnected = _a.wasDisconnected;
7560
- if (!wasDisconnected &&
7561
- !(_this.isConnected || _this.isConnecting)) {
7562
- _this.connect();
7563
- }
7564
- }
7565
- });
7566
- });
7686
+ return _this.subscribed$.asObservable().pipe(operators.filter(function (primitiveManager) {
7687
+ return _this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key;
7688
+ }), operators.map(function () { return true; }), operators.take(1));
7689
+ }));
7567
7690
  };
7568
- WebsocketService.prototype.disconnect = function () {
7569
- var e_1, _a, e_2, _b, e_3, _c;
7570
- if (!this.isConnected || this.getObserversCount() > 0) {
7691
+ WebsocketService.prototype.debug = function (message) {
7692
+ var optionalParams = [];
7693
+ for (var _i = 1; _i < arguments.length; _i++) {
7694
+ optionalParams[_i - 1] = arguments[_i];
7695
+ }
7696
+ if (!this.debugEnable) {
7571
7697
  return;
7572
7698
  }
7573
- try {
7574
- for (var _d = __values(this.primitiveManagers.values()), _e = _d.next(); !_e.done; _e = _d.next()) {
7575
- var primitiveManager = _e.value;
7576
- try {
7577
- for (var _f = (e_2 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
7578
- var stompSubscription = _g.value;
7579
- stompSubscription.unsubscribe();
7580
- }
7581
- }
7582
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
7583
- finally {
7584
- try {
7585
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
7586
- }
7587
- finally { if (e_2) throw e_2.error; }
7588
- }
7589
- }
7699
+ console.log.apply(console, __spread(['WS debug: ' + message], optionalParams));
7700
+ };
7701
+ WebsocketService.prototype.info = function (message) {
7702
+ console.info('WS info: ' + message);
7703
+ };
7704
+ WebsocketService.prototype.handleOnConnected = function (data) {
7705
+ this.debug('Webscoket connected', data);
7706
+ this.connected$.next(true);
7707
+ if (this.lostConnection) {
7708
+ this.info('Webscoket reconnected, recriating subscriptions');
7709
+ this.handleReconnection();
7590
7710
  }
7591
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
7592
- finally {
7593
- try {
7594
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
7595
- }
7596
- finally { if (e_1) throw e_1.error; }
7711
+ };
7712
+ WebsocketService.prototype.handleOnDisconnect = function (data) {
7713
+ this.debug('Webscoket disconnected', data);
7714
+ this.disconnected$.next();
7715
+ };
7716
+ WebsocketService.prototype.handleOnWebSocketClose = function (data) {
7717
+ if (data.wasClean) {
7718
+ return;
7597
7719
  }
7598
- try {
7599
- for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
7600
- var primitiveManager = _j.value;
7601
- primitiveManager.event$.complete();
7602
- }
7720
+ this.lostConnection = true;
7721
+ };
7722
+ WebsocketService.prototype.handleOnStompError = function (data) {
7723
+ debugger;
7724
+ this.handleError('StompError', data);
7725
+ if (this.isAuthenticationError(data)) {
7726
+ this.info('Authentication error, recriating subscriptions');
7727
+ this.handleReconnection();
7603
7728
  }
7604
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
7605
- finally {
7606
- try {
7607
- if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
7608
- }
7609
- finally { if (e_3) throw e_3.error; }
7729
+ };
7730
+ WebsocketService.prototype.isAuthenticationError = function (data) {
7731
+ var _a;
7732
+ var errorMessage = (_a = data === null || data === void 0 ? void 0 : data.headers) === null || _a === void 0 ? void 0 : _a.message;
7733
+ if (!errorMessage) {
7734
+ return false;
7610
7735
  }
7611
- this.primitiveManagers.clear();
7612
- this._stompClient.disconnect();
7613
- this._stompClient.deactivate();
7614
- this.isConnected = false;
7615
- this.isConnecting = false;
7616
- this.wasConnected = false;
7617
- this.connected$.next(false);
7618
- this.disconnect$.next();
7736
+ return errorMessage.toLowerCase().indexOf('forbiddenexception') !== -1;
7619
7737
  };
7620
- /** @private */
7621
- WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
7622
- var tenant = WebsocketService_1.TOKEN
7623
- ? WebsocketService_1.TOKEN.username.split('@')[1]
7624
- : null;
7625
- var token = WebsocketService_1.TOKEN
7626
- ? WebsocketService_1.TOKEN.access_token
7627
- : null;
7628
- return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
7738
+ WebsocketService.prototype.handleOnWebSocketError = function (data) {
7739
+ this.handleError('WebSocketError', data);
7629
7740
  };
7630
- /** @private */
7631
- WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
7632
- var tenant = WebsocketService_1.TOKEN
7633
- ? WebsocketService_1.TOKEN.username.split('@')[1]
7634
- : null;
7635
- return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
7741
+ WebsocketService.prototype.handleError = function (origin, data) {
7742
+ console.error(origin, data);
7743
+ this.error$.next(data);
7636
7744
  };
7637
- /** @private */
7638
- WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
7639
- return this._stompClient.subscribe(destination, function (message) {
7640
- var event = JSON.parse(message.body || '{}');
7641
- primitiveManager.event$.next(event);
7642
- });
7745
+ WebsocketService.prototype.handleReconnection = function () {
7746
+ this.lostConnection = false;
7747
+ this.reconnectPrimitives();
7748
+ this.reconnected$.next();
7643
7749
  };
7644
- /** @private */
7645
- WebsocketService.prototype.createStompClient = function () {
7646
- var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
7647
- this._stompClient = stompjs.Stomp.over(ws);
7648
- this._stompClient.debug = function () { return null; };
7649
- };
7650
- /** @private */
7651
7750
  WebsocketService.prototype.reconnectPrimitives = function () {
7652
- var e_4, _a;
7751
+ var e_2, _a;
7653
7752
  try {
7654
7753
  for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
7655
7754
  var primitiveManager = _c.value;
7656
7755
  this.createStompSubscriptions(primitiveManager);
7657
7756
  }
7658
7757
  }
7659
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
7758
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
7660
7759
  finally {
7661
7760
  try {
7662
7761
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7663
7762
  }
7664
- finally { if (e_4) throw e_4.error; }
7763
+ finally { if (e_2) throw e_2.error; }
7665
7764
  }
7666
7765
  };
7667
- /** @private */
7668
- WebsocketService.prototype.getObserversCount = function () {
7669
- var e_5, _a;
7670
- var observersCount = 0;
7671
- try {
7672
- for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
7673
- var primitiveManager = _c.value;
7674
- observersCount += primitiveManager.event$.observers.length;
7675
- }
7676
- }
7677
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
7678
- finally {
7679
- try {
7680
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7681
- }
7682
- finally { if (e_5) throw e_5.error; }
7683
- }
7684
- return observersCount;
7766
+ WebsocketService.prototype.buildSubscriptionUrlWithToken = function (domain, service, primitive) {
7767
+ var authToken = this.userInformationService.getAuthToken();
7768
+ var tenant = this.userInformationService.getTenantDomain();
7769
+ return "/topic/" + tenant + "/" + authToken + "/" + domain + "/" + service + "/" + primitive;
7685
7770
  };
7686
- /** @private */
7687
- WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitiveManager) {
7688
- var e_6, _a;
7689
- // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7690
- var hasObservers = !(primitiveManager.event$.observers.length === 1);
7691
- if (hasObservers)
7771
+ WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
7772
+ var tenant = this.userInformationService.getTenantDomain();
7773
+ return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
7774
+ };
7775
+ WebsocketService.prototype.buildPrimitiveManagerKey = function (domain, service, primitive) {
7776
+ return domain + "/" + service + "/" + primitive;
7777
+ };
7778
+ WebsocketService.prototype.unsubscribePrimitiveOnFinalize = function (primitiveManager) {
7779
+ if (primitiveManager.hasObservers()) {
7692
7780
  return;
7693
- primitiveManager.event$.complete();
7694
- try {
7695
- for (var _b = __values(primitiveManager.stompSubscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
7696
- var stompSubscription = _c.value;
7697
- stompSubscription.unsubscribe();
7698
- }
7699
7781
  }
7700
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
7701
- finally {
7702
- try {
7703
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7704
- }
7705
- finally { if (e_6) throw e_6.error; }
7706
- }
7707
- primitiveManager.subscribed$.complete();
7708
- var key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7782
+ primitiveManager.unsubscribe();
7783
+ var key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7709
7784
  this.primitiveManagers.delete(key);
7710
- this.disconnect();
7785
+ this.disconnectIfNoMoreObservables();
7711
7786
  };
7712
- /** @private */
7713
- WebsocketService.prototype.getPrimitiveManagerKey = function (domain, service, primitive) {
7714
- return domain + "/" + service + "/" + primitive;
7787
+ WebsocketService.prototype.disconnectIfNoMoreObservables = function () {
7788
+ if (this.getObserversCount() === 0) {
7789
+ this.debug('Manually disconnecting because there are no more observers');
7790
+ this.disconnect();
7791
+ }
7792
+ };
7793
+ WebsocketService.prototype.getObserversCount = function () {
7794
+ var observersCount = 0;
7795
+ this.primitiveManagers.forEach(function (primitiveManager) {
7796
+ observersCount += primitiveManager.getObserversCount();
7797
+ });
7798
+ return observersCount;
7715
7799
  };
7716
- var WebsocketService_1;
7717
- WebsocketService.RECONNECT_INTERVAL = 3000;
7718
- WebsocketService.CONNECTION_TIMEOUT = 15000;
7719
- /** @private */
7720
- WebsocketService.BASE_URL_COOKIE = 'com.senior.base.url';
7721
- /** @private */
7722
- WebsocketService.TOKEN_COOKIE = 'com.senior.token';
7723
- /** @private */
7724
- WebsocketService.TOKEN = JSON.parse(jsCookie.get(WebsocketService_1.TOKEN_COOKIE) || '{}');
7725
- /** @private */
7726
- WebsocketService.WEBSOCKET_URL = jsCookie.get(WebsocketService_1.BASE_URL_COOKIE) + '/websocket/';
7727
- WebsocketService.ɵprov = core.ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
7728
- WebsocketService = WebsocketService_1 = __decorate([
7800
+ WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
7801
+ return this.stompClient.subscribe(destination, function (message) {
7802
+ var event = JSON.parse(message.body || '{}');
7803
+ primitiveManager.fireEvent(event);
7804
+ });
7805
+ };
7806
+ WebsocketService.prototype.createStompSubscriptions = function (primitiveManager) {
7807
+ var subscriptionUrlWithToken = this.buildSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7808
+ var subscriptionUrlWithoutToken = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7809
+ var stompSubscriptionWithToken = this.createStompSubscription(subscriptionUrlWithToken, primitiveManager);
7810
+ var stompSubscriptionWithoutToken = this.createStompSubscription(subscriptionUrlWithoutToken, primitiveManager);
7811
+ primitiveManager.subscribe(stompSubscriptionWithToken, stompSubscriptionWithoutToken);
7812
+ this.subscribed$.next(primitiveManager);
7813
+ };
7814
+ WebsocketService.prototype.getSubscriptionUrl = function () {
7815
+ return this.userInformationService.getWebSocketUrl() + "/subscription";
7816
+ };
7817
+ WebsocketService.ctorParameters = function () { return [
7818
+ { type: UserInformationService }
7819
+ ]; };
7820
+ WebsocketService.ɵprov = core.ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(core.ɵɵinject(UserInformationService)); }, token: WebsocketService, providedIn: "root" });
7821
+ WebsocketService = __decorate([
7729
7822
  core.Injectable({
7730
7823
  providedIn: 'root'
7731
7824
  })
@@ -7801,6 +7894,73 @@
7801
7894
  return VerifyModulePermission;
7802
7895
  }());
7803
7896
 
7897
+ var VerifyModulePermissionsService = /** @class */ (function () {
7898
+ function VerifyModulePermissionsService(http) {
7899
+ this.http = http;
7900
+ }
7901
+ VerifyModulePermissionsService_1 = VerifyModulePermissionsService;
7902
+ VerifyModulePermissionsService.prototype.consultaModulos = function (request) {
7903
+ return this.http.post(VerifyModulePermissionsService_1.QUERY_MODULES_URL, request);
7904
+ };
7905
+ var VerifyModulePermissionsService_1;
7906
+ VerifyModulePermissionsService.QUERY_MODULES_URL = "erpx_fnd/empresa/queries/consultaModulos";
7907
+ VerifyModulePermissionsService.ctorParameters = function () { return [
7908
+ { type: http.HttpClient }
7909
+ ]; };
7910
+ VerifyModulePermissionsService.ɵprov = core.ɵɵdefineInjectable({ factory: function VerifyModulePermissionsService_Factory() { return new VerifyModulePermissionsService(core.ɵɵinject(http.HttpClient)); }, token: VerifyModulePermissionsService, providedIn: "any" });
7911
+ VerifyModulePermissionsService = VerifyModulePermissionsService_1 = __decorate([
7912
+ core.Injectable({
7913
+ providedIn: "any"
7914
+ })
7915
+ ], VerifyModulePermissionsService);
7916
+ return VerifyModulePermissionsService;
7917
+ }());
7918
+
7919
+ var VerifyModulePermissions = /** @class */ (function () {
7920
+ function VerifyModulePermissions(verifyModulePermissionsService) {
7921
+ this.verifyModulePermissionsService = verifyModulePermissionsService;
7922
+ }
7923
+ VerifyModulePermissions_1 = VerifyModulePermissions;
7924
+ /**
7925
+ * Method to verify if user has permission on a specific module
7926
+ * @param modules Modules to verify the permission
7927
+ * @param requestPermission Indicative if must be call the primitive
7928
+ * @returns An boolean Observable
7929
+ */
7930
+ VerifyModulePermissions.prototype.hasPermissions = function (modules, requestPermission) {
7931
+ var moduleSubject = VerifyModulePermissions_1.subjectsPerModuleMap.get(modules);
7932
+ if (!moduleSubject || requestPermission) {
7933
+ var newModuleSubject_1 = new rxjs.ReplaySubject(1);
7934
+ VerifyModulePermissions_1.subjectsPerModuleMap.set(modules, newModuleSubject_1);
7935
+ this.verifyModulePermissionsService
7936
+ .consultaModulos({ modulo: modules, somenteAtivo: true })
7937
+ .pipe(operators.take(1))
7938
+ .subscribe(function (response) {
7939
+ var hasPermissions = (response === null || response === void 0 ? void 0 : response.modulos) || [];
7940
+ newModuleSubject_1.next(hasPermissions);
7941
+ }, function (err) {
7942
+ VerifyModulePermissions_1.subjectsPerModuleMap.delete(modules);
7943
+ newModuleSubject_1.error(err);
7944
+ newModuleSubject_1.unsubscribe();
7945
+ });
7946
+ return newModuleSubject_1.asObservable();
7947
+ }
7948
+ return moduleSubject.asObservable();
7949
+ };
7950
+ var VerifyModulePermissions_1;
7951
+ VerifyModulePermissions.ctorParameters = function () { return [
7952
+ { type: VerifyModulePermissionsService }
7953
+ ]; };
7954
+ VerifyModulePermissions.subjectsPerModuleMap = new Map();
7955
+ VerifyModulePermissions.ɵprov = core.ɵɵdefineInjectable({ factory: function VerifyModulePermissions_Factory() { return new VerifyModulePermissions(core.ɵɵinject(VerifyModulePermissionsService)); }, token: VerifyModulePermissions, providedIn: "root" });
7956
+ VerifyModulePermissions = VerifyModulePermissions_1 = __decorate([
7957
+ core.Injectable({
7958
+ providedIn: "root"
7959
+ })
7960
+ ], VerifyModulePermissions);
7961
+ return VerifyModulePermissions;
7962
+ }());
7963
+
7804
7964
 
7805
7965
  (function (ModulesEnum) {
7806
7966
  ModulesEnum["CONTROLADORIA"] = "CONTROLADORIA";
@@ -7937,12 +8097,15 @@
7937
8097
  exports.UnidadeMedidaLookup = UnidadeMedidaLookup;
7938
8098
  exports.UtilsModule = UtilsModule;
7939
8099
  exports.VerifyModulePermission = VerifyModulePermission;
8100
+ exports.VerifyModulePermissions = VerifyModulePermissions;
7940
8101
  exports.WebsocketService = WebsocketService;
7941
8102
  exports.naturezaReceitaPisCofins = naturezaReceitaPisCofins;
7942
8103
  exports.ɵ0 = ɵ0;
7943
8104
  exports.ɵa = ErpLookupsService;
7944
8105
  exports.ɵd = StorageService;
7945
- exports.ɵe = VerifyModulePermissionService;
8106
+ exports.ɵe = UserInformationService;
8107
+ exports.ɵf = VerifyModulePermissionService;
8108
+ exports.ɵg = VerifyModulePermissionsService;
7946
8109
 
7947
8110
  Object.defineProperty(exports, '__esModule', { value: true });
7948
8111