monkey-front-core 0.0.304 → 0.0.306

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 (28) hide show
  1. package/esm2020/lib/core/directives/monkeyecx-security-directive.mjs +9 -7
  2. package/esm2020/lib/core/interceptors/monkeyecx-http-config-error.interceptor.mjs +1 -1
  3. package/esm2020/lib/core/interceptors/monkeyecx-http-config-header.interceptor.mjs +9 -10
  4. package/esm2020/lib/core/services/auth/monkeyecx-auth-guard-company.service.mjs +4 -4
  5. package/esm2020/lib/core/services/auth/monkeyecx-auth-guard-login.service.mjs +4 -4
  6. package/esm2020/lib/core/services/auth/monkeyecx-auth-guard.service.mjs +3 -3
  7. package/esm2020/lib/core/services/auth/monkeyecx-authentication.service.mjs +10 -5
  8. package/esm2020/lib/core/services/commons/monkeyecx-commons.service.mjs +11 -8
  9. package/esm2020/lib/core/services/error/monkeyecx-http-error-handling.service.mjs +4 -4
  10. package/esm2020/lib/core/services/storage/monkeyecx-token-storage.service.mjs +32 -15
  11. package/esm2020/lib/store/selectors/monkeyecx-storage.selector.mjs +2 -2
  12. package/fesm2015/monkey-front-core.mjs +233 -188
  13. package/fesm2015/monkey-front-core.mjs.map +1 -1
  14. package/fesm2020/monkey-front-core.mjs +98 -73
  15. package/fesm2020/monkey-front-core.mjs.map +1 -1
  16. package/lib/core/directives/monkeyecx-security-directive.d.ts +1 -0
  17. package/lib/core/interceptors/monkeyecx-http-config-header.interceptor.d.ts +2 -2
  18. package/lib/core/services/auth/monkeyecx-auth-guard-company.service.d.ts +1 -2
  19. package/lib/core/services/auth/monkeyecx-auth-guard-login.service.d.ts +1 -2
  20. package/lib/core/services/auth/monkeyecx-auth-guard.service.d.ts +1 -2
  21. package/lib/core/services/auth/monkeyecx-authentication.service.d.ts +6 -4
  22. package/lib/core/services/commons/monkeyecx-commons.service.d.ts +6 -6
  23. package/lib/core/services/error/monkeyecx-http-error-handling.service.d.ts +4 -4
  24. package/lib/core/services/storage/monkeyecx-token-storage.service.d.ts +23 -3
  25. package/lib/store/selectors/monkeyecx-storage.selector.d.ts +1 -1
  26. package/monkey-front-core-0.0.306.tgz +0 -0
  27. package/package.json +1 -1
  28. package/monkey-front-core-0.0.304.tgz +0 -0
@@ -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,
@@ -3994,10 +4015,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
3994
4015
  }]
3995
4016
  }], ctorParameters: function () { return [{ type: i1.MonkeyStyleGuideSnackbarService }, { type: i1$1.TranslateService }]; } });
3996
4017
 
3997
- /* eslint-disable no-console */
3998
4018
  class MonkeyEcxAuthenticationService {
3999
4019
  constructor() {
4000
- this.hadAtLeastOneLogin = () => {
4020
+ this.hadAtLeastOneLogin = async () => {
4001
4021
  console.error('hadAtLeastOneLogin needs to be declared!');
4002
4022
  return null;
4003
4023
  };
@@ -4009,11 +4029,11 @@ class MonkeyEcxAuthenticationService {
4009
4029
  console.error('redirectLoginWelcomeBack needs to be declared!');
4010
4030
  return null;
4011
4031
  };
4012
- this.isAuthorized = () => {
4032
+ this.isAuthorized = async () => {
4013
4033
  console.error('isAuthorized needs to be declared!');
4014
4034
  return false;
4015
4035
  };
4016
- this.isCompanyAuthorized = () => {
4036
+ this.isCompanyAuthorized = async () => {
4017
4037
  console.error('isCompanyAuthorized needs to be declared!');
4018
4038
  return false;
4019
4039
  };
@@ -4029,6 +4049,10 @@ class MonkeyEcxAuthenticationService {
4029
4049
  console.error('getRequestWithHeadersOb needs to be declared!');
4030
4050
  return null;
4031
4051
  };
4052
+ this.getRequestWithHeadersAsync = async (request) => {
4053
+ console.error('getRequestWithHeadersAsync needs to be declared!');
4054
+ return null;
4055
+ };
4032
4056
  this.refreshShouldHappen = (response) => {
4033
4057
  console.error('refreshShouldHappen needs to be declared!');
4034
4058
  return false;
@@ -4049,6 +4073,8 @@ class MonkeyEcxAuthenticationService {
4049
4073
  this.isCompanyAuthorized = args?.isCompanyAuthorized || this.isCompanyAuthorized.bind(this);
4050
4074
  this.getRequestWithHeaders =
4051
4075
  args?.getRequestWithHeaders || this.getRequestWithHeaders.bind(this);
4076
+ this.getRequestWithHeadersAsync =
4077
+ args?.getRequestWithHeadersAsync || this.getRequestWithHeadersAsync.bind(this);
4052
4078
  this.getRequestWithHeadersOb = args?.getRequestWithHeadersOb.bind(this);
4053
4079
  this.refreshShouldHappen = args?.refreshShouldHappen || this.refreshShouldHappen.bind(this);
4054
4080
  this.refreshToken = args?.refreshToken || this.refreshToken.bind(this);
@@ -4066,10 +4092,10 @@ class MonkeyEcxAuthGuardCompany {
4066
4092
  this.monkeyecxAuthenticationService = monkeyecxAuthenticationService;
4067
4093
  // not to do
4068
4094
  }
4069
- canActivate() {
4095
+ async canActivate() {
4070
4096
  const { monkeyecxAuthenticationService } = this;
4071
- if (this.monkeyecxAuthenticationService.isAuthorized()) {
4072
- if (monkeyecxAuthenticationService.isCompanyAuthorized()) {
4097
+ if (await this.monkeyecxAuthenticationService.isAuthorized()) {
4098
+ if (await monkeyecxAuthenticationService.isCompanyAuthorized()) {
4073
4099
  return true;
4074
4100
  }
4075
4101
  this.monkeyecxAuthenticationService.redirectApp();
@@ -4091,12 +4117,12 @@ class MonkeyEcxAuthGuardLogin {
4091
4117
  this.monkeyecxAuthenticationService = monkeyecxAuthenticationService;
4092
4118
  // not to do
4093
4119
  }
4094
- canActivate() {
4095
- if (this.monkeyecxAuthenticationService.isAuthorized()) {
4120
+ async canActivate() {
4121
+ if (await this.monkeyecxAuthenticationService.isAuthorized()) {
4096
4122
  this.monkeyecxAuthenticationService.redirectApp();
4097
4123
  return false;
4098
4124
  }
4099
- if (this.monkeyecxAuthenticationService.hadAtLeastOneLogin()) {
4125
+ if (await this.monkeyecxAuthenticationService.hadAtLeastOneLogin()) {
4100
4126
  this.monkeyecxAuthenticationService.redirectLoginWelcomeBack();
4101
4127
  return false;
4102
4128
  }
@@ -4115,9 +4141,9 @@ class MonkeyEcxAuthGuard {
4115
4141
  this.monkeyecxAuthenticationService = monkeyecxAuthenticationService;
4116
4142
  // not to do
4117
4143
  }
4118
- canActivate() {
4144
+ async canActivate() {
4119
4145
  const { monkeyecxAuthenticationService } = this;
4120
- if (monkeyecxAuthenticationService.isAuthorized()) {
4146
+ if (await monkeyecxAuthenticationService.isAuthorized()) {
4121
4147
  return true;
4122
4148
  }
4123
4149
  monkeyecxAuthenticationService.redirectLoginWelcomeBack();
@@ -4315,10 +4341,10 @@ class MonkeyEcxHttpErrorHandlingService extends MonkeyEcxCommonsService {
4315
4341
  this.showMessage(customMessage, error, mkc);
4316
4342
  }
4317
4343
  }
4318
- handleError(error, mkc) {
4344
+ async handleError(error, mkc) {
4319
4345
  const { router, tokenStorage } = this;
4320
4346
  const { status } = error;
4321
- const { companyType } = tokenStorage?.getToken() || { companyType: '' };
4347
+ const { companyType } = await tokenStorage?.getToken() || { companyType: '' };
4322
4348
  const routes = {
4323
4349
  403: 'forbidden',
4324
4350
  500: 'service-problems',
@@ -5326,15 +5352,14 @@ class MonkeyEcxHttpConfigHeaderInterceptor {
5326
5352
  // not to do
5327
5353
  }
5328
5354
  }
5329
- const resp = await this.authService
5330
- .getRequestWithHeadersOb(request)
5331
- .pipe(take(1), map((event) => {
5332
- return event;
5333
- }), catchError((error) => {
5334
- this.errorHandlingService.handleError(error);
5335
- return throwError(error);
5336
- }))
5337
- .toPromise();
5355
+ let resp = null;
5356
+ try {
5357
+ resp = await this.authService.getRequestWithHeadersAsync(request);
5358
+ }
5359
+ catch (e) {
5360
+ this.errorHandlingService.handleError(e);
5361
+ return throwError(e);
5362
+ }
5338
5363
  return resp;
5339
5364
  }
5340
5365
  intercept(request, next) {