monkey-front-core 0.0.304 → 0.0.305

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.
@@ -19,10 +19,10 @@ import { NG_VALUE_ACCESSOR } from '@angular/forms';
19
19
  import { TemplatePortal } from '@angular/cdk/portal';
20
20
  import * as i1$4 from '@angular/cdk/overlay';
21
21
  import { OverlayModule } from '@angular/cdk/overlay';
22
+ import { __awaiter, __decorate } from 'tslib';
22
23
  import * as i2$3 from '@ngrx/store';
23
24
  import { createAction, props, INIT, UPDATE, createReducer, on, createFeatureSelector, createSelector, StoreModule } from '@ngrx/store';
24
25
  import { createEntityAdapter } from '@ngrx/entity';
25
- import { __awaiter, __decorate } from 'tslib';
26
26
  import { datadogRum } from '@datadog/browser-rum';
27
27
  import * as i1$5 from '@angular/service-worker';
28
28
  import { ServiceWorkerModule } from '@angular/service-worker';
@@ -2558,7 +2558,7 @@ const selectState = createFeatureSelector(featureKey);
2558
2558
  const selectAll = createSelector(selectState, selectAll$1);
2559
2559
  const select = (props) => {
2560
2560
  return createSelector(selectAll, (entities) => {
2561
- return entities.filter((_) => {
2561
+ return entities.find((_) => {
2562
2562
  return _.username === props.username;
2563
2563
  });
2564
2564
  });
@@ -2589,6 +2589,28 @@ var index = /*#__PURE__*/Object.freeze({
2589
2589
  selectors: index$1
2590
2590
  });
2591
2591
 
2592
+ class Link {
2593
+ constructor(data) {
2594
+ this.href = data === null || data === void 0 ? void 0 : data.href;
2595
+ this.type = data === null || data === void 0 ? void 0 : data.type;
2596
+ this.templated = data === null || data === void 0 ? void 0 : data.templated;
2597
+ }
2598
+ }
2599
+ class MonkeyEcxModel {
2600
+ getAction(type, replaceOptions) {
2601
+ const { _links } = this;
2602
+ if (!_links)
2603
+ return null;
2604
+ let link = _links[type.toLowerCase()];
2605
+ link = new Link(link);
2606
+ if (link && replaceOptions && (link === null || link === void 0 ? void 0 : link.templated)) {
2607
+ const { from, to } = replaceOptions;
2608
+ link = new Link(Object.assign(Object.assign({}, link), { href: `${link.href}`.replace(from, to) }));
2609
+ }
2610
+ return link;
2611
+ }
2612
+ }
2613
+
2592
2614
  class MonkeyEcxRequestPagedHandling {
2593
2615
  constructor(url, pagedParams, links, samePage = false) {
2594
2616
  this.samePage = false;
@@ -2630,28 +2652,6 @@ class MonkeyEcxRequestPagedHandling {
2630
2652
  }
2631
2653
  }
2632
2654
 
2633
- class Link {
2634
- constructor(data) {
2635
- this.href = data === null || data === void 0 ? void 0 : data.href;
2636
- this.type = data === null || data === void 0 ? void 0 : data.type;
2637
- this.templated = data === null || data === void 0 ? void 0 : data.templated;
2638
- }
2639
- }
2640
- class MonkeyEcxModel {
2641
- getAction(type, replaceOptions) {
2642
- const { _links } = this;
2643
- if (!_links)
2644
- return null;
2645
- let link = _links[type.toLowerCase()];
2646
- link = new Link(link);
2647
- if (link && replaceOptions && (link === null || link === void 0 ? void 0 : link.templated)) {
2648
- const { from, to } = replaceOptions;
2649
- link = new Link(Object.assign(Object.assign({}, link), { href: `${link.href}`.replace(from, to) }));
2650
- }
2651
- return link;
2652
- }
2653
- }
2654
-
2655
2655
  class LinksModel extends MonkeyEcxModel {
2656
2656
  constructor(data) {
2657
2657
  super();
@@ -2683,7 +2683,7 @@ class MonkeyEcxCommonsService {
2683
2683
  this.__onZipCodeDataChanged$ = new BehaviorSubject(null);
2684
2684
  this.__oni18nDataChanged$ = new BehaviorSubject(null);
2685
2685
  this.__onDoSearch$ = new BehaviorSubject({});
2686
- this.__tokenCredentials = null;
2686
+ this.__tokenCredentials = undefined;
2687
2687
  this.__schedule = null;
2688
2688
  this.__callbackPagination = () => {
2689
2689
  // eslint-disable-next-line no-console
@@ -2694,25 +2694,27 @@ class MonkeyEcxCommonsService {
2694
2694
  }
2695
2695
  handleInit() {
2696
2696
  var _a, _b, _c;
2697
- if (this.tokenStorage) {
2698
- this.__tokenCredentials = this.tokenStorage.getToken();
2699
- }
2700
- if ((_a = this.otherArgs) === null || _a === void 0 ? void 0 : _a.router) {
2701
- const { clearOnChangeRoute } = ((_c = (_b = this.otherArgs) === null || _b === void 0 ? void 0 : _b.schedule) === null || _c === void 0 ? void 0 : _c.options) || {
2702
- clearOnChangeRoute: false
2703
- };
2704
- this.otherArgs.router.events
2705
- .pipe(filter((event) => {
2706
- return event instanceof NavigationStart;
2707
- }), take(1))
2708
- .subscribe(() => {
2709
- var _a, _b, _c;
2710
- if (this.__schedule && clearOnChangeRoute) {
2711
- (_c = (_b = (_a = this.otherArgs) === null || _a === void 0 ? void 0 : _a.schedule) === null || _b === void 0 ? void 0 : _b.service) === null || _c === void 0 ? void 0 : _c.removeSchedule(this.__schedule);
2712
- this.__schedule = null;
2713
- }
2714
- });
2715
- }
2697
+ return __awaiter(this, void 0, void 0, function* () {
2698
+ if (this.tokenStorage) {
2699
+ this.__tokenCredentials = yield this.tokenStorage.getToken();
2700
+ }
2701
+ if ((_a = this.otherArgs) === null || _a === void 0 ? void 0 : _a.router) {
2702
+ const { clearOnChangeRoute } = ((_c = (_b = this.otherArgs) === null || _b === void 0 ? void 0 : _b.schedule) === null || _c === void 0 ? void 0 : _c.options) || {
2703
+ clearOnChangeRoute: false
2704
+ };
2705
+ this.otherArgs.router.events
2706
+ .pipe(filter((event) => {
2707
+ return event instanceof NavigationStart;
2708
+ }), take(1))
2709
+ .subscribe(() => {
2710
+ var _a, _b, _c;
2711
+ if (this.__schedule && clearOnChangeRoute) {
2712
+ (_c = (_b = (_a = this.otherArgs) === null || _a === void 0 ? void 0 : _a.schedule) === null || _b === void 0 ? void 0 : _b.service) === null || _c === void 0 ? void 0 : _c.removeSchedule(this.__schedule);
2713
+ this.__schedule = null;
2714
+ }
2715
+ });
2716
+ }
2717
+ });
2716
2718
  }
2717
2719
  navigateToPendencyPage(arg, router) {
2718
2720
  const { companyType } = this.__tokenCredentials || {
@@ -2875,77 +2877,82 @@ class MonkeyEcxCommonsService {
2875
2877
  }
2876
2878
  resolve(route, state, otherArgs) {
2877
2879
  var _a, _b, _c;
2878
- if (JSON.stringify(route === null || route === void 0 ? void 0 : route.queryParams) === '{}') {
2879
- this.__data = null;
2880
- this.__page = null;
2881
- }
2882
- this.__requestPaged = null;
2883
- this.flagValidator = true;
2884
- if (this.tokenStorage) {
2885
- this.__tokenCredentials = this.tokenStorage.getToken();
2886
- }
2887
- const pend = this.allowedSecurityAccessByPendency(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.pendency);
2888
- const allowedByProgram = this.allowedSecurityAccessByFeature(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.featureByProgram);
2889
- if (this.allowedSecurityAccess(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.security) &&
2890
- this.allowedSecurityAccessByCountry(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.countrySecurity) &&
2891
- !pend.hasPendencies &&
2892
- allowedByProgram) {
2893
- if (this.__schedule) {
2894
- (_c = (_b = (_a = this.otherArgs) === null || _a === void 0 ? void 0 : _a.schedule) === null || _b === void 0 ? void 0 : _b.service) === null || _c === void 0 ? void 0 : _c.removeSchedule(this.__schedule);
2895
- this.__schedule = null;
2896
- }
2897
- const { __requestPaged } = this;
2898
- if (!__requestPaged) {
2899
- this.setPage({
2900
- page: {
2901
- number: 0,
2902
- size: 10
2903
- }
2904
- });
2905
- }
2906
- if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.translateOptions) {
2907
- const { service, keys } = otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.translateOptions;
2908
- this.geti18n(service, keys || '');
2909
- }
2910
- if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackPagination) {
2911
- this.__callbackPagination = otherArgs.callbackPagination;
2880
+ return __awaiter(this, void 0, void 0, function* () {
2881
+ if (JSON.stringify(route === null || route === void 0 ? void 0 : route.queryParams) === '{}') {
2882
+ this.__data = null;
2883
+ this.__page = null;
2912
2884
  }
2913
- if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.paginationOptions) {
2914
- this.__paginationOptions = otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.paginationOptions;
2915
- this.handlePaginationOptions();
2885
+ this.__requestPaged = null;
2886
+ this.flagValidator = true;
2887
+ if (this.tokenStorage) {
2888
+ console.log('resolve commmons');
2889
+ this.__tokenCredentials = yield this.tokenStorage.getToken();
2890
+ console.log('this.__tokenCredentials');
2891
+ console.log(this.__tokenCredentials);
2916
2892
  }
2917
- if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.feature) {
2918
- const { flag, service } = otherArgs.feature;
2919
- service.onFlags
2920
- .pipe(takeWhile(() => {
2921
- return this.flagValidator;
2922
- }))
2923
- .subscribe((val) => {
2924
- if (val) {
2925
- const hasFlag = service.getFlag(flag);
2926
- if (MonkeyEcxUtils.persistNullEmptyUndefined(hasFlag)) {
2927
- if (!hasFlag) {
2928
- this.navigateToErrorPage(404, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2929
- return;
2893
+ const pend = this.allowedSecurityAccessByPendency(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.pendency);
2894
+ const allowedByProgram = this.allowedSecurityAccessByFeature(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.featureByProgram);
2895
+ if (this.allowedSecurityAccess(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.security) &&
2896
+ this.allowedSecurityAccessByCountry(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.countrySecurity) &&
2897
+ !pend.hasPendencies &&
2898
+ allowedByProgram) {
2899
+ if (this.__schedule) {
2900
+ (_c = (_b = (_a = this.otherArgs) === null || _a === void 0 ? void 0 : _a.schedule) === null || _b === void 0 ? void 0 : _b.service) === null || _c === void 0 ? void 0 : _c.removeSchedule(this.__schedule);
2901
+ this.__schedule = null;
2902
+ }
2903
+ const { __requestPaged } = this;
2904
+ if (!__requestPaged) {
2905
+ this.setPage({
2906
+ page: {
2907
+ number: 0,
2908
+ size: 10
2909
+ }
2910
+ });
2911
+ }
2912
+ if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.translateOptions) {
2913
+ const { service, keys } = otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.translateOptions;
2914
+ this.geti18n(service, keys || '');
2915
+ }
2916
+ if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackPagination) {
2917
+ this.__callbackPagination = otherArgs.callbackPagination;
2918
+ }
2919
+ if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.paginationOptions) {
2920
+ this.__paginationOptions = otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.paginationOptions;
2921
+ this.handlePaginationOptions();
2922
+ }
2923
+ if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.feature) {
2924
+ const { flag, service } = otherArgs.feature;
2925
+ service.onFlags
2926
+ .pipe(takeWhile(() => {
2927
+ return this.flagValidator;
2928
+ }))
2929
+ .subscribe((val) => {
2930
+ if (val) {
2931
+ const hasFlag = service.getFlag(flag);
2932
+ if (MonkeyEcxUtils.persistNullEmptyUndefined(hasFlag)) {
2933
+ if (!hasFlag) {
2934
+ this.navigateToErrorPage(404, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2935
+ return;
2936
+ }
2930
2937
  }
2938
+ otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackMain();
2931
2939
  }
2932
- otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackMain();
2933
- }
2934
- });
2940
+ });
2941
+ }
2942
+ else {
2943
+ otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackMain();
2944
+ }
2945
+ }
2946
+ else if (!allowedByProgram) {
2947
+ this.navigateToErrorPage(404, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2948
+ }
2949
+ else if (pend.hasPendencies) {
2950
+ this.navigateToPendencyPage(pend, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2935
2951
  }
2936
2952
  else {
2937
- otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackMain();
2953
+ this.navigateToErrorPage(403, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2938
2954
  }
2939
- }
2940
- else if (!allowedByProgram) {
2941
- this.navigateToErrorPage(404, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2942
- }
2943
- else if (pend.hasPendencies) {
2944
- this.navigateToPendencyPage(pend, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2945
- }
2946
- else {
2947
- this.navigateToErrorPage(403, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2948
- }
2955
+ });
2949
2956
  }
2950
2957
  getHTTPHeaderApplicationPDF() {
2951
2958
  return {
@@ -3645,15 +3652,27 @@ class MonkeyEcxTokenStorageService {
3645
3652
  }
3646
3653
  getAllTokens() {
3647
3654
  var _a;
3648
- const { token, config } = this;
3649
- const handledToken = Object.assign({}, token);
3650
- Object.entries(token || {}).forEach(([key, value]) => {
3651
- handledToken[key] = localStorage.getItem(key);
3655
+ return __awaiter(this, void 0, void 0, function* () {
3656
+ const { store, monkeyecxConfigService } = this;
3657
+ const username = localStorage.getItem('username');
3658
+ let data = {
3659
+ username: username || '',
3660
+ program: ''
3661
+ };
3662
+ if (username) {
3663
+ data = yield store.select(select({ username })).pipe(take(1)).toPromise();
3664
+ data === null || data === void 0 ? true : delete data.me;
3665
+ }
3666
+ const config = yield monkeyecxConfigService.config()
3667
+ .pipe(first((val) => {
3668
+ return !!val && JSON.stringify(val) !== '{}';
3669
+ }))
3670
+ .toPromise();
3671
+ if (data && !(data === null || data === void 0 ? void 0 : data.program) && (config === null || config === void 0 ? void 0 : config.program)) {
3672
+ data.program = (_a = config === null || config === void 0 ? void 0 : config.program) === null || _a === void 0 ? void 0 : _a.token;
3673
+ }
3674
+ return data;
3652
3675
  });
3653
- if (!(handledToken === null || handledToken === void 0 ? void 0 : handledToken.program) && (config === null || config === void 0 ? void 0 : config.program)) {
3654
- handledToken.program = (_a = config === null || config === void 0 ? void 0 : config.program) === null || _a === void 0 ? void 0 : _a.token;
3655
- }
3656
- return handledToken;
3657
3676
  }
3658
3677
  setAllMe(me) {
3659
3678
  const { me$, store } = this;
@@ -3678,8 +3697,18 @@ class MonkeyEcxTokenStorageService {
3678
3697
  me$.next(previousMe);
3679
3698
  }
3680
3699
  getAllMe() {
3681
- const me = localStorage.getItem('me');
3682
- return JSON.parse(me || '{}');
3700
+ return __awaiter(this, void 0, void 0, function* () {
3701
+ const { store } = this;
3702
+ const username = localStorage.getItem('username');
3703
+ let data = {
3704
+ username: username || '',
3705
+ program: ''
3706
+ };
3707
+ if (username) {
3708
+ data = yield store.select(select({ username })).pipe(take(1)).toPromise();
3709
+ }
3710
+ return data === null || data === void 0 ? void 0 : data.me;
3711
+ });
3683
3712
  }
3684
3713
  tokenHasChanged() {
3685
3714
  return this.token$.asObservable();
@@ -3758,7 +3787,7 @@ class MonkeyEcxSecurityDirective {
3758
3787
  this.cdr = cdr;
3759
3788
  this.roles = [];
3760
3789
  this.byExclusion = false;
3761
- this.tokenCredentials = null;
3790
+ this.tokenCredentials = undefined;
3762
3791
  // not to do
3763
3792
  }
3764
3793
  getRole() {
@@ -3791,15 +3820,19 @@ class MonkeyEcxSecurityDirective {
3791
3820
  this.elementRef.nativeElement.style.display = display;
3792
3821
  this.cdr.detectChanges();
3793
3822
  }
3823
+ handleData() {
3824
+ return __awaiter(this, void 0, void 0, function* () {
3825
+ this.tokenCredentials = yield this.tokenStorageService.getToken();
3826
+ this.handleAccess();
3827
+ });
3828
+ }
3794
3829
  ngOnInit() {
3795
3830
  this.elementRef.nativeElement.style.display = 'none';
3796
3831
  this.cdr.detectChanges();
3797
3832
  this.tokenStorageService.tokenHasChanged().subscribe(() => {
3798
- this.tokenCredentials = this.tokenStorageService.getToken();
3799
- this.handleAccess();
3833
+ this.handleData();
3800
3834
  });
3801
- this.tokenCredentials = this.tokenStorageService.getToken();
3802
- this.handleAccess();
3835
+ this.handleData();
3803
3836
  }
3804
3837
  }
3805
3838
  MonkeyEcxSecurityDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxSecurityDirective, deps: [{ token: i0.ElementRef }, { token: MonkeyEcxTokenStorageService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
@@ -3807,7 +3840,7 @@ MonkeyEcxSecurityDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0
3807
3840
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxSecurityDirective, decorators: [{
3808
3841
  type: Directive,
3809
3842
  args: [{
3810
- selector: '[monkeyecxSecurity]',
3843
+ selector: '[monkeyecxSecurity]'
3811
3844
  }]
3812
3845
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MonkeyEcxTokenStorageService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { roles: [{
3813
3846
  type: Input,
@@ -4305,31 +4338,33 @@ class MonkeyEcxHttpErrorHandlingService extends MonkeyEcxCommonsService {
4305
4338
  }
4306
4339
  }
4307
4340
  handleError(error, mkc) {
4308
- const { router, tokenStorage } = this;
4309
- const { status } = error;
4310
- const { companyType } = (tokenStorage === null || tokenStorage === void 0 ? void 0 : tokenStorage.getToken()) || { companyType: '' };
4311
- const routes = {
4312
- 403: 'forbidden',
4313
- 500: 'service-problems',
4314
- 503: 'service-problems'
4315
- };
4316
- let route = '/app';
4317
- if (companyType) {
4318
- route = `${route}/${companyType}/pages`;
4319
- }
4320
- else {
4321
- route = `${route}/pages`;
4322
- }
4323
- const found = routes[status];
4324
- let timeout = 0;
4325
- if (found && !this.isHttpCodeIgnoreRedirect(mkc, error === null || error === void 0 ? void 0 : error.status)) {
4326
- route = `${route}/${found}`.toLowerCase();
4327
- timeout = 800;
4328
- router.navigate([route]);
4329
- }
4330
- setTimeout(() => {
4331
- this.handleMessage(error, mkc);
4332
- }, timeout);
4341
+ return __awaiter(this, void 0, void 0, function* () {
4342
+ const { router, tokenStorage } = this;
4343
+ const { status } = error;
4344
+ const { companyType } = (yield (tokenStorage === null || tokenStorage === void 0 ? void 0 : tokenStorage.getToken())) || { companyType: '' };
4345
+ const routes = {
4346
+ 403: 'forbidden',
4347
+ 500: 'service-problems',
4348
+ 503: 'service-problems'
4349
+ };
4350
+ let route = '/app';
4351
+ if (companyType) {
4352
+ route = `${route}/${companyType}/pages`;
4353
+ }
4354
+ else {
4355
+ route = `${route}/pages`;
4356
+ }
4357
+ const found = routes[status];
4358
+ let timeout = 0;
4359
+ if (found && !this.isHttpCodeIgnoreRedirect(mkc, error === null || error === void 0 ? void 0 : error.status)) {
4360
+ route = `${route}/${found}`.toLowerCase();
4361
+ timeout = 800;
4362
+ router.navigate([route]);
4363
+ }
4364
+ setTimeout(() => {
4365
+ this.handleMessage(error, mkc);
4366
+ }, timeout);
4367
+ });
4333
4368
  }
4334
4369
  handleErrorRefreshToken(error, mkc) {
4335
4370
  if (error.status === 401 || error.status === 400) {