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.
@@ -2552,7 +2552,7 @@ const selectState = createFeatureSelector(featureKey);
2552
2552
  const selectAll = createSelector(selectState, selectAll$1);
2553
2553
  const select = (props) => {
2554
2554
  return createSelector(selectAll, (entities) => {
2555
- return entities.filter((_) => {
2555
+ return entities.find((_) => {
2556
2556
  return _.username === props.username;
2557
2557
  });
2558
2558
  });
@@ -2583,6 +2583,31 @@ var index = /*#__PURE__*/Object.freeze({
2583
2583
  selectors: index$1
2584
2584
  });
2585
2585
 
2586
+ class Link {
2587
+ constructor(data) {
2588
+ this.href = data?.href;
2589
+ this.type = data?.type;
2590
+ this.templated = data?.templated;
2591
+ }
2592
+ }
2593
+ class MonkeyEcxModel {
2594
+ getAction(type, replaceOptions) {
2595
+ const { _links } = this;
2596
+ if (!_links)
2597
+ return null;
2598
+ let link = _links[type.toLowerCase()];
2599
+ link = new Link(link);
2600
+ if (link && replaceOptions && link?.templated) {
2601
+ const { from, to } = replaceOptions;
2602
+ link = new Link({
2603
+ ...link,
2604
+ href: `${link.href}`.replace(from, to),
2605
+ });
2606
+ }
2607
+ return link;
2608
+ }
2609
+ }
2610
+
2586
2611
  class MonkeyEcxRequestPagedHandling {
2587
2612
  constructor(url, pagedParams, links, samePage = false) {
2588
2613
  this.samePage = false;
@@ -2624,31 +2649,6 @@ class MonkeyEcxRequestPagedHandling {
2624
2649
  }
2625
2650
  }
2626
2651
 
2627
- class Link {
2628
- constructor(data) {
2629
- this.href = data?.href;
2630
- this.type = data?.type;
2631
- this.templated = data?.templated;
2632
- }
2633
- }
2634
- class MonkeyEcxModel {
2635
- getAction(type, replaceOptions) {
2636
- const { _links } = this;
2637
- if (!_links)
2638
- return null;
2639
- let link = _links[type.toLowerCase()];
2640
- link = new Link(link);
2641
- if (link && replaceOptions && link?.templated) {
2642
- const { from, to } = replaceOptions;
2643
- link = new Link({
2644
- ...link,
2645
- href: `${link.href}`.replace(from, to),
2646
- });
2647
- }
2648
- return link;
2649
- }
2650
- }
2651
-
2652
2652
  class LinksModel extends MonkeyEcxModel {
2653
2653
  constructor(data) {
2654
2654
  super();
@@ -2680,7 +2680,7 @@ class MonkeyEcxCommonsService {
2680
2680
  this.__onZipCodeDataChanged$ = new BehaviorSubject(null);
2681
2681
  this.__oni18nDataChanged$ = new BehaviorSubject(null);
2682
2682
  this.__onDoSearch$ = new BehaviorSubject({});
2683
- this.__tokenCredentials = null;
2683
+ this.__tokenCredentials = undefined;
2684
2684
  this.__schedule = null;
2685
2685
  this.__callbackPagination = () => {
2686
2686
  // eslint-disable-next-line no-console
@@ -2689,9 +2689,9 @@ class MonkeyEcxCommonsService {
2689
2689
  this.__isAbleToDoPagination = {};
2690
2690
  this.handleInit();
2691
2691
  }
2692
- handleInit() {
2692
+ async handleInit() {
2693
2693
  if (this.tokenStorage) {
2694
- this.__tokenCredentials = this.tokenStorage.getToken();
2694
+ this.__tokenCredentials = await this.tokenStorage.getToken();
2695
2695
  }
2696
2696
  if (this.otherArgs?.router) {
2697
2697
  const { clearOnChangeRoute } = this.otherArgs?.schedule?.options || {
@@ -2874,7 +2874,7 @@ class MonkeyEcxCommonsService {
2874
2874
  this.__handledError = null;
2875
2875
  this.flagValidator = false;
2876
2876
  }
2877
- resolve(route, state, otherArgs) {
2877
+ async resolve(route, state, otherArgs) {
2878
2878
  if (JSON.stringify(route?.queryParams) === '{}') {
2879
2879
  this.__data = null;
2880
2880
  this.__page = null;
@@ -2882,7 +2882,10 @@ class MonkeyEcxCommonsService {
2882
2882
  this.__requestPaged = null;
2883
2883
  this.flagValidator = true;
2884
2884
  if (this.tokenStorage) {
2885
- this.__tokenCredentials = this.tokenStorage.getToken();
2885
+ console.log('resolve commmons');
2886
+ this.__tokenCredentials = await this.tokenStorage.getToken();
2887
+ console.log('this.__tokenCredentials');
2888
+ console.log(this.__tokenCredentials);
2886
2889
  }
2887
2890
  const pend = this.allowedSecurityAccessByPendency(otherArgs?.pendency);
2888
2891
  const allowedByProgram = this.allowedSecurityAccessByFeature(otherArgs?.featureByProgram);
@@ -3652,18 +3655,26 @@ class MonkeyEcxTokenStorageService {
3652
3655
  }
3653
3656
  token$.next(token);
3654
3657
  }
3655
- getAllTokens() {
3656
- const { token, config } = this;
3657
- const handledToken = {
3658
- ...token
3658
+ async getAllTokens() {
3659
+ const { store, monkeyecxConfigService } = this;
3660
+ const username = localStorage.getItem('username');
3661
+ let data = {
3662
+ username: username || '',
3663
+ program: ''
3659
3664
  };
3660
- Object.entries(token || {}).forEach(([key, value]) => {
3661
- handledToken[key] = localStorage.getItem(key);
3662
- });
3663
- if (!handledToken?.program && config?.program) {
3664
- handledToken.program = config?.program?.token;
3665
+ if (username) {
3666
+ data = await store.select(select({ username })).pipe(take(1)).toPromise();
3667
+ delete data?.me;
3668
+ }
3669
+ const config = await monkeyecxConfigService.config()
3670
+ .pipe(first((val) => {
3671
+ return !!val && JSON.stringify(val) !== '{}';
3672
+ }))
3673
+ .toPromise();
3674
+ if (data && !data?.program && config?.program) {
3675
+ data.program = config?.program?.token;
3665
3676
  }
3666
- return handledToken;
3677
+ return data;
3667
3678
  }
3668
3679
  setAllMe(me) {
3669
3680
  const { me$, store } = this;
@@ -3690,9 +3701,17 @@ class MonkeyEcxTokenStorageService {
3690
3701
  localStorage.setItem('me', JSON.stringify(previousMe));
3691
3702
  me$.next(previousMe);
3692
3703
  }
3693
- getAllMe() {
3694
- const me = localStorage.getItem('me');
3695
- return JSON.parse(me || '{}');
3704
+ async getAllMe() {
3705
+ const { store } = this;
3706
+ const username = localStorage.getItem('username');
3707
+ let data = {
3708
+ username: username || '',
3709
+ program: ''
3710
+ };
3711
+ if (username) {
3712
+ data = await store.select(select({ username })).pipe(take(1)).toPromise();
3713
+ }
3714
+ return data?.me;
3696
3715
  }
3697
3716
  tokenHasChanged() {
3698
3717
  return this.token$.asObservable();
@@ -3776,7 +3795,7 @@ class MonkeyEcxSecurityDirective {
3776
3795
  this.cdr = cdr;
3777
3796
  this.roles = [];
3778
3797
  this.byExclusion = false;
3779
- this.tokenCredentials = null;
3798
+ this.tokenCredentials = undefined;
3780
3799
  // not to do
3781
3800
  }
3782
3801
  getRole() {
@@ -3809,15 +3828,17 @@ class MonkeyEcxSecurityDirective {
3809
3828
  this.elementRef.nativeElement.style.display = display;
3810
3829
  this.cdr.detectChanges();
3811
3830
  }
3831
+ async handleData() {
3832
+ this.tokenCredentials = await this.tokenStorageService.getToken();
3833
+ this.handleAccess();
3834
+ }
3812
3835
  ngOnInit() {
3813
3836
  this.elementRef.nativeElement.style.display = 'none';
3814
3837
  this.cdr.detectChanges();
3815
3838
  this.tokenStorageService.tokenHasChanged().subscribe(() => {
3816
- this.tokenCredentials = this.tokenStorageService.getToken();
3817
- this.handleAccess();
3839
+ this.handleData();
3818
3840
  });
3819
- this.tokenCredentials = this.tokenStorageService.getToken();
3820
- this.handleAccess();
3841
+ this.handleData();
3821
3842
  }
3822
3843
  }
3823
3844
  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 });
@@ -3825,7 +3846,7 @@ MonkeyEcxSecurityDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0
3825
3846
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxSecurityDirective, decorators: [{
3826
3847
  type: Directive,
3827
3848
  args: [{
3828
- selector: '[monkeyecxSecurity]',
3849
+ selector: '[monkeyecxSecurity]'
3829
3850
  }]
3830
3851
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MonkeyEcxTokenStorageService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { roles: [{
3831
3852
  type: Input,
@@ -4315,10 +4336,10 @@ class MonkeyEcxHttpErrorHandlingService extends MonkeyEcxCommonsService {
4315
4336
  this.showMessage(customMessage, error, mkc);
4316
4337
  }
4317
4338
  }
4318
- handleError(error, mkc) {
4339
+ async handleError(error, mkc) {
4319
4340
  const { router, tokenStorage } = this;
4320
4341
  const { status } = error;
4321
- const { companyType } = tokenStorage?.getToken() || { companyType: '' };
4342
+ const { companyType } = await tokenStorage?.getToken() || { companyType: '' };
4322
4343
  const routes = {
4323
4344
  403: 'forbidden',
4324
4345
  500: 'service-problems',