monkey-front-core 0.0.303 → 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.
@@ -20,13 +20,13 @@ 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
22
  import { __awaiter, __decorate } from 'tslib';
23
+ import * as i2$3 from '@ngrx/store';
24
+ import { createAction, props, INIT, UPDATE, createReducer, on, createFeatureSelector, createSelector, StoreModule } from '@ngrx/store';
25
+ import { createEntityAdapter } from '@ngrx/entity';
23
26
  import { datadogRum } from '@datadog/browser-rum';
24
27
  import * as i1$5 from '@angular/service-worker';
25
28
  import { ServiceWorkerModule } from '@angular/service-worker';
26
29
  import { initialize } from 'launchdarkly-js-client-sdk';
27
- import * as i6 from '@ngrx/store';
28
- import { createAction, props, INIT, UPDATE, createReducer, on, createFeatureSelector, createSelector, StoreModule } from '@ngrx/store';
29
- import { createEntityAdapter } from '@ngrx/entity';
30
30
 
31
31
  class AlertsComponent {
32
32
  constructor(modalService) {
@@ -2453,6 +2453,164 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
2453
2453
  args: ['monkeyecxPopoverHeight']
2454
2454
  }] } });
2455
2455
 
2456
+ const clear = createAction('[MECX Core Storage] Clear All');
2457
+ const create = createAction('[MECX Core Storage] Create', props());
2458
+ const deleteOne = createAction('[MECX Core Storage] Delete One', props());
2459
+ const updateControl = createAction('[MECX Core Storage] Update Control', props());
2460
+ const updateOne = createAction('[MECX Core Storage] Update One', props());
2461
+
2462
+ var monkeyecxStorage_actions = /*#__PURE__*/Object.freeze({
2463
+ __proto__: null,
2464
+ clear: clear,
2465
+ create: create,
2466
+ deleteOne: deleteOne,
2467
+ updateControl: updateControl,
2468
+ updateOne: updateOne
2469
+ });
2470
+
2471
+ var index$3 = /*#__PURE__*/Object.freeze({
2472
+ __proto__: null,
2473
+ monkeyecxStorage: monkeyecxStorage_actions
2474
+ });
2475
+
2476
+ const seederReducer = (keys) => {
2477
+ return (reducer) => {
2478
+ return (state, action) => {
2479
+ const handledState = reducer(state, action);
2480
+ if (action.type === INIT || action.type === UPDATE) {
2481
+ const storageValue = localStorage.getItem('mecx-store');
2482
+ if (storageValue) {
2483
+ try {
2484
+ const handled = Object.assign(Object.assign({}, handledState), JSON.parse(atob(storageValue)));
2485
+ return handled;
2486
+ }
2487
+ catch (_a) {
2488
+ localStorage.removeItem('mecx-store');
2489
+ }
2490
+ }
2491
+ }
2492
+ let data = handledState;
2493
+ try {
2494
+ keys.forEach((key) => {
2495
+ data = Object.assign(Object.assign({}, data), { [key]: handledState[key] });
2496
+ });
2497
+ localStorage.setItem('mecx-store', btoa(JSON.stringify(data)));
2498
+ }
2499
+ catch (e) {
2500
+ localStorage.removeItem('mecx-store');
2501
+ }
2502
+ return data || handledState;
2503
+ };
2504
+ };
2505
+ };
2506
+
2507
+ var monkeyecxSeeder_reducer = /*#__PURE__*/Object.freeze({
2508
+ __proto__: null,
2509
+ seederReducer: seederReducer
2510
+ });
2511
+
2512
+ const featureKey = 'mecx-core-storage';
2513
+ const adapter = createEntityAdapter({
2514
+ selectId: (item) => {
2515
+ return item.username;
2516
+ }
2517
+ });
2518
+ const initialState = adapter.getInitialState({
2519
+ control: {
2520
+ isLoading: false
2521
+ },
2522
+ error: null
2523
+ });
2524
+ const reducer = createReducer(initialState, on(clear, (state) => {
2525
+ return adapter.removeAll(state);
2526
+ }), on(create, (state, action) => {
2527
+ return adapter.upsertMany(action.data, Object.assign({}, state));
2528
+ }), on(updateControl, (state, action) => {
2529
+ return Object.assign(Object.assign({}, state), { control: Object.assign(Object.assign({}, state.control), action.data) });
2530
+ }), on(updateOne, (state, action) => {
2531
+ const { username } = action.data;
2532
+ return adapter.upsertOne(Object.assign(Object.assign({}, action.data), { username }), Object.assign({}, state));
2533
+ }), on(deleteOne, (state, action) => {
2534
+ const { username } = action.data;
2535
+ return adapter.removeOne(username, state);
2536
+ }));
2537
+ const { selectAll: selectAll$1, selectEntities, selectIds, selectTotal } = adapter.getSelectors();
2538
+
2539
+ var monkeyecxStorage_reducer = /*#__PURE__*/Object.freeze({
2540
+ __proto__: null,
2541
+ featureKey: featureKey,
2542
+ adapter: adapter,
2543
+ initialState: initialState,
2544
+ reducer: reducer,
2545
+ selectAll: selectAll$1,
2546
+ selectEntities: selectEntities,
2547
+ selectIds: selectIds,
2548
+ selectTotal: selectTotal
2549
+ });
2550
+
2551
+ var index$2 = /*#__PURE__*/Object.freeze({
2552
+ __proto__: null,
2553
+ fromMonkeyecxSeeder: monkeyecxSeeder_reducer,
2554
+ fromMonkeyecxStorage: monkeyecxStorage_reducer
2555
+ });
2556
+
2557
+ const selectState = createFeatureSelector(featureKey);
2558
+ const selectAll = createSelector(selectState, selectAll$1);
2559
+ const select = (props) => {
2560
+ return createSelector(selectAll, (entities) => {
2561
+ return entities.find((_) => {
2562
+ return _.username === props.username;
2563
+ });
2564
+ });
2565
+ };
2566
+ const selectControl = () => {
2567
+ return createSelector(selectState, (state) => {
2568
+ return state.control;
2569
+ });
2570
+ };
2571
+
2572
+ var monkeyecxStorage_selector = /*#__PURE__*/Object.freeze({
2573
+ __proto__: null,
2574
+ selectState: selectState,
2575
+ selectAll: selectAll,
2576
+ select: select,
2577
+ selectControl: selectControl
2578
+ });
2579
+
2580
+ var index$1 = /*#__PURE__*/Object.freeze({
2581
+ __proto__: null,
2582
+ monkeyecxStorage: monkeyecxStorage_selector
2583
+ });
2584
+
2585
+ var index = /*#__PURE__*/Object.freeze({
2586
+ __proto__: null,
2587
+ actions: index$3,
2588
+ reducers: index$2,
2589
+ selectors: index$1
2590
+ });
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
+
2456
2614
  class MonkeyEcxRequestPagedHandling {
2457
2615
  constructor(url, pagedParams, links, samePage = false) {
2458
2616
  this.samePage = false;
@@ -2494,28 +2652,6 @@ class MonkeyEcxRequestPagedHandling {
2494
2652
  }
2495
2653
  }
2496
2654
 
2497
- class Link {
2498
- constructor(data) {
2499
- this.href = data === null || data === void 0 ? void 0 : data.href;
2500
- this.type = data === null || data === void 0 ? void 0 : data.type;
2501
- this.templated = data === null || data === void 0 ? void 0 : data.templated;
2502
- }
2503
- }
2504
- class MonkeyEcxModel {
2505
- getAction(type, replaceOptions) {
2506
- const { _links } = this;
2507
- if (!_links)
2508
- return null;
2509
- let link = _links[type.toLowerCase()];
2510
- link = new Link(link);
2511
- if (link && replaceOptions && (link === null || link === void 0 ? void 0 : link.templated)) {
2512
- const { from, to } = replaceOptions;
2513
- link = new Link(Object.assign(Object.assign({}, link), { href: `${link.href}`.replace(from, to) }));
2514
- }
2515
- return link;
2516
- }
2517
- }
2518
-
2519
2655
  class LinksModel extends MonkeyEcxModel {
2520
2656
  constructor(data) {
2521
2657
  super();
@@ -2547,7 +2683,7 @@ class MonkeyEcxCommonsService {
2547
2683
  this.__onZipCodeDataChanged$ = new BehaviorSubject(null);
2548
2684
  this.__oni18nDataChanged$ = new BehaviorSubject(null);
2549
2685
  this.__onDoSearch$ = new BehaviorSubject({});
2550
- this.__tokenCredentials = null;
2686
+ this.__tokenCredentials = undefined;
2551
2687
  this.__schedule = null;
2552
2688
  this.__callbackPagination = () => {
2553
2689
  // eslint-disable-next-line no-console
@@ -2558,25 +2694,27 @@ class MonkeyEcxCommonsService {
2558
2694
  }
2559
2695
  handleInit() {
2560
2696
  var _a, _b, _c;
2561
- if (this.tokenStorage) {
2562
- this.__tokenCredentials = this.tokenStorage.getToken();
2563
- }
2564
- if ((_a = this.otherArgs) === null || _a === void 0 ? void 0 : _a.router) {
2565
- const { clearOnChangeRoute } = ((_c = (_b = this.otherArgs) === null || _b === void 0 ? void 0 : _b.schedule) === null || _c === void 0 ? void 0 : _c.options) || {
2566
- clearOnChangeRoute: false
2567
- };
2568
- this.otherArgs.router.events
2569
- .pipe(filter((event) => {
2570
- return event instanceof NavigationStart;
2571
- }), take(1))
2572
- .subscribe(() => {
2573
- var _a, _b, _c;
2574
- if (this.__schedule && clearOnChangeRoute) {
2575
- (_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);
2576
- this.__schedule = null;
2577
- }
2578
- });
2579
- }
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
+ });
2580
2718
  }
2581
2719
  navigateToPendencyPage(arg, router) {
2582
2720
  const { companyType } = this.__tokenCredentials || {
@@ -2739,77 +2877,82 @@ class MonkeyEcxCommonsService {
2739
2877
  }
2740
2878
  resolve(route, state, otherArgs) {
2741
2879
  var _a, _b, _c;
2742
- if (JSON.stringify(route === null || route === void 0 ? void 0 : route.queryParams) === '{}') {
2743
- this.__data = null;
2744
- this.__page = null;
2745
- }
2746
- this.__requestPaged = null;
2747
- this.flagValidator = true;
2748
- if (this.tokenStorage) {
2749
- this.__tokenCredentials = this.tokenStorage.getToken();
2750
- }
2751
- const pend = this.allowedSecurityAccessByPendency(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.pendency);
2752
- const allowedByProgram = this.allowedSecurityAccessByFeature(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.featureByProgram);
2753
- if (this.allowedSecurityAccess(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.security) &&
2754
- this.allowedSecurityAccessByCountry(otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.countrySecurity) &&
2755
- !pend.hasPendencies &&
2756
- allowedByProgram) {
2757
- if (this.__schedule) {
2758
- (_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);
2759
- this.__schedule = null;
2760
- }
2761
- const { __requestPaged } = this;
2762
- if (!__requestPaged) {
2763
- this.setPage({
2764
- page: {
2765
- number: 0,
2766
- size: 10
2767
- }
2768
- });
2769
- }
2770
- if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.translateOptions) {
2771
- const { service, keys } = otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.translateOptions;
2772
- this.geti18n(service, keys || '');
2773
- }
2774
- if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackPagination) {
2775
- 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;
2776
2884
  }
2777
- if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.paginationOptions) {
2778
- this.__paginationOptions = otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.paginationOptions;
2779
- 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);
2780
2892
  }
2781
- if (otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.feature) {
2782
- const { flag, service } = otherArgs.feature;
2783
- service.onFlags
2784
- .pipe(takeWhile(() => {
2785
- return this.flagValidator;
2786
- }))
2787
- .subscribe((val) => {
2788
- if (val) {
2789
- const hasFlag = service.getFlag(flag);
2790
- if (MonkeyEcxUtils.persistNullEmptyUndefined(hasFlag)) {
2791
- if (!hasFlag) {
2792
- this.navigateToErrorPage(404, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2793
- 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
+ }
2794
2937
  }
2938
+ otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackMain();
2795
2939
  }
2796
- otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackMain();
2797
- }
2798
- });
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);
2799
2951
  }
2800
2952
  else {
2801
- otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.callbackMain();
2953
+ this.navigateToErrorPage(403, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2802
2954
  }
2803
- }
2804
- else if (!allowedByProgram) {
2805
- this.navigateToErrorPage(404, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2806
- }
2807
- else if (pend.hasPendencies) {
2808
- this.navigateToPendencyPage(pend, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2809
- }
2810
- else {
2811
- this.navigateToErrorPage(403, otherArgs === null || otherArgs === void 0 ? void 0 : otherArgs.router);
2812
- }
2955
+ });
2813
2956
  }
2814
2957
  getHTTPHeaderApplicationPDF() {
2815
2958
  return {
@@ -3462,8 +3605,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
3462
3605
  }], ctorParameters: function () { return [{ type: MonkeyEcxService }, { type: MonkeyEcxi18nConfigService }, { type: MonkeyEcxLogsConfigService }, { type: i1.MonkeyStyleGuideSettingsService }, { type: MonkeyEcxServiceWorkerConfigService }, { type: MonkeyEcxSecurityConsoleConfigService }, { type: MonkeyEcxMaintenanceConfigService }, { type: MonkeyEcxErrorConfigService }, { type: MonkeyEcxFeatureToggleService }, { type: MonkeyEcxGTMConfigService }, { type: MonkeyEcxAlertsConfigService }]; }, propDecorators: { init: [] } });
3463
3606
 
3464
3607
  class MonkeyEcxTokenStorageService {
3465
- constructor(monkeyecxConfigService) {
3608
+ constructor(monkeyecxConfigService, store) {
3466
3609
  this.monkeyecxConfigService = monkeyecxConfigService;
3610
+ this.store = store;
3467
3611
  this.config = null;
3468
3612
  this.token = {
3469
3613
  username: '',
@@ -3480,8 +3624,8 @@ class MonkeyEcxTokenStorageService {
3480
3624
  role: '',
3481
3625
  ownerGovernmentId: '',
3482
3626
  _clearIgnore: {
3483
- ignore: ['username', 'program', 'accessType'],
3484
- },
3627
+ ignore: ['username', 'program', 'accessType']
3628
+ }
3485
3629
  };
3486
3630
  this.token$ = new BehaviorSubject(null);
3487
3631
  this.me$ = new BehaviorSubject(null);
@@ -3490,40 +3634,81 @@ class MonkeyEcxTokenStorageService {
3490
3634
  });
3491
3635
  }
3492
3636
  setAllTokens(token) {
3493
- const { token$ } = this;
3637
+ const { token$, store } = this;
3494
3638
  Object.entries(token).forEach(([key, value]) => {
3495
3639
  if (MonkeyEcxUtils.persistNullEmptyUndefined(value)) {
3496
3640
  localStorage.setItem(key, value);
3497
3641
  }
3498
3642
  });
3643
+ const username = token.username || localStorage.getItem('username');
3644
+ if (username) {
3645
+ store.dispatch(create({
3646
+ data: [
3647
+ Object.assign({ username }, token)
3648
+ ]
3649
+ }));
3650
+ }
3499
3651
  token$.next(token);
3500
3652
  }
3501
3653
  getAllTokens() {
3502
3654
  var _a;
3503
- const { token, config } = this;
3504
- const handledToken = Object.assign({}, token);
3505
- Object.entries(token || {}).forEach(([key, value]) => {
3506
- 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;
3507
3675
  });
3508
- if (!(handledToken === null || handledToken === void 0 ? void 0 : handledToken.program) && (config === null || config === void 0 ? void 0 : config.program)) {
3509
- handledToken.program = (_a = config === null || config === void 0 ? void 0 : config.program) === null || _a === void 0 ? void 0 : _a.token;
3510
- }
3511
- return handledToken;
3512
3676
  }
3513
3677
  setAllMe(me) {
3514
- const { me$ } = this;
3678
+ const { me$, store } = this;
3515
3679
  let previousMe = JSON.parse((localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem('me')) || '{}');
3516
3680
  Object.entries(me).forEach(([key, value]) => {
3517
3681
  if (MonkeyEcxUtils.persistNullEmptyUndefined(value)) {
3518
3682
  previousMe = Object.assign(Object.assign({}, previousMe), { [key]: value });
3519
3683
  }
3520
3684
  });
3685
+ const username = me.username || localStorage.getItem('username');
3686
+ if (username) {
3687
+ store.dispatch(create({
3688
+ data: [
3689
+ {
3690
+ username,
3691
+ me
3692
+ }
3693
+ ]
3694
+ }));
3695
+ }
3521
3696
  localStorage.setItem('me', JSON.stringify(previousMe));
3522
3697
  me$.next(previousMe);
3523
3698
  }
3524
3699
  getAllMe() {
3525
- const me = localStorage.getItem('me');
3526
- 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
+ });
3527
3712
  }
3528
3713
  tokenHasChanged() {
3529
3714
  return this.token$.asObservable();
@@ -3544,7 +3729,7 @@ class MonkeyEcxTokenStorageService {
3544
3729
  this.setAllMe(me);
3545
3730
  }
3546
3731
  clear(force) {
3547
- const { token } = this;
3732
+ const { token, store } = this;
3548
3733
  try {
3549
3734
  Object.entries(token || {}).forEach(([key, value]) => {
3550
3735
  var _a;
@@ -3556,6 +3741,10 @@ class MonkeyEcxTokenStorageService {
3556
3741
  }
3557
3742
  });
3558
3743
  localStorage.removeItem('me');
3744
+ const username = localStorage.getItem('username');
3745
+ if (username) {
3746
+ store.dispatch(deleteOne({ data: { username } }));
3747
+ }
3559
3748
  }
3560
3749
  catch (error) {
3561
3750
  return of(false);
@@ -3566,19 +3755,30 @@ class MonkeyEcxTokenStorageService {
3566
3755
  * @param fields (the name of fields you want to clear. ie: ['companyId', 'role', ...])
3567
3756
  */
3568
3757
  clearCredentials(fields = ['companyId', 'governmentId', 'companyType', 'programAdmin', 'role']) {
3758
+ const { store } = this;
3759
+ let obj = null;
3569
3760
  fields === null || fields === void 0 ? void 0 : fields.forEach((key) => {
3761
+ obj = Object.assign(Object.assign({}, obj), { [key]: null });
3570
3762
  localStorage.removeItem(key);
3571
3763
  });
3764
+ const username = localStorage.getItem('username');
3765
+ if (username) {
3766
+ store.dispatch(create({
3767
+ data: [
3768
+ Object.assign({ username }, obj)
3769
+ ]
3770
+ }));
3771
+ }
3572
3772
  }
3573
3773
  }
3574
- MonkeyEcxTokenStorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxTokenStorageService, deps: [{ token: MonkeyEcxConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
3774
+ MonkeyEcxTokenStorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxTokenStorageService, deps: [{ token: MonkeyEcxConfigService }, { token: i2$3.Store }], target: i0.ɵɵFactoryTarget.Injectable });
3575
3775
  MonkeyEcxTokenStorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxTokenStorageService, providedIn: 'root' });
3576
3776
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxTokenStorageService, decorators: [{
3577
3777
  type: Injectable,
3578
3778
  args: [{
3579
- providedIn: 'root',
3779
+ providedIn: 'root'
3580
3780
  }]
3581
- }], ctorParameters: function () { return [{ type: MonkeyEcxConfigService }]; } });
3781
+ }], ctorParameters: function () { return [{ type: MonkeyEcxConfigService }, { type: i2$3.Store }]; } });
3582
3782
 
3583
3783
  class MonkeyEcxSecurityDirective {
3584
3784
  constructor(elementRef, tokenStorageService, cdr) {
@@ -3587,7 +3787,7 @@ class MonkeyEcxSecurityDirective {
3587
3787
  this.cdr = cdr;
3588
3788
  this.roles = [];
3589
3789
  this.byExclusion = false;
3590
- this.tokenCredentials = null;
3790
+ this.tokenCredentials = undefined;
3591
3791
  // not to do
3592
3792
  }
3593
3793
  getRole() {
@@ -3620,15 +3820,19 @@ class MonkeyEcxSecurityDirective {
3620
3820
  this.elementRef.nativeElement.style.display = display;
3621
3821
  this.cdr.detectChanges();
3622
3822
  }
3823
+ handleData() {
3824
+ return __awaiter(this, void 0, void 0, function* () {
3825
+ this.tokenCredentials = yield this.tokenStorageService.getToken();
3826
+ this.handleAccess();
3827
+ });
3828
+ }
3623
3829
  ngOnInit() {
3624
3830
  this.elementRef.nativeElement.style.display = 'none';
3625
3831
  this.cdr.detectChanges();
3626
3832
  this.tokenStorageService.tokenHasChanged().subscribe(() => {
3627
- this.tokenCredentials = this.tokenStorageService.getToken();
3628
- this.handleAccess();
3833
+ this.handleData();
3629
3834
  });
3630
- this.tokenCredentials = this.tokenStorageService.getToken();
3631
- this.handleAccess();
3835
+ this.handleData();
3632
3836
  }
3633
3837
  }
3634
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 });
@@ -3636,7 +3840,7 @@ MonkeyEcxSecurityDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0
3636
3840
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxSecurityDirective, decorators: [{
3637
3841
  type: Directive,
3638
3842
  args: [{
3639
- selector: '[monkeyecxSecurity]',
3843
+ selector: '[monkeyecxSecurity]'
3640
3844
  }]
3641
3845
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MonkeyEcxTokenStorageService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { roles: [{
3642
3846
  type: Input,
@@ -4134,31 +4338,33 @@ class MonkeyEcxHttpErrorHandlingService extends MonkeyEcxCommonsService {
4134
4338
  }
4135
4339
  }
4136
4340
  handleError(error, mkc) {
4137
- const { router, tokenStorage } = this;
4138
- const { status } = error;
4139
- const { companyType } = (tokenStorage === null || tokenStorage === void 0 ? void 0 : tokenStorage.getToken()) || { companyType: '' };
4140
- const routes = {
4141
- 403: 'forbidden',
4142
- 500: 'service-problems',
4143
- 503: 'service-problems'
4144
- };
4145
- let route = '/app';
4146
- if (companyType) {
4147
- route = `${route}/${companyType}/pages`;
4148
- }
4149
- else {
4150
- route = `${route}/pages`;
4151
- }
4152
- const found = routes[status];
4153
- let timeout = 0;
4154
- if (found && !this.isHttpCodeIgnoreRedirect(mkc, error === null || error === void 0 ? void 0 : error.status)) {
4155
- route = `${route}/${found}`.toLowerCase();
4156
- timeout = 800;
4157
- router.navigate([route]);
4158
- }
4159
- setTimeout(() => {
4160
- this.handleMessage(error, mkc);
4161
- }, 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
+ });
4162
4368
  }
4163
4369
  handleErrorRefreshToken(error, mkc) {
4164
4370
  if (error.status === 401 || error.status === 400) {
@@ -5319,147 +5525,11 @@ class MonkeyEcxSpecificationSearch {
5319
5525
  }
5320
5526
  }
5321
5527
 
5322
- const clear = createAction('[MECX Core Storage] Clear All');
5323
- const create = createAction('[MECX Core Storage] Create', props());
5324
- const updateControl = createAction('[MECX Core Storage] Update Control', props());
5325
- const updateOne = createAction('[MECX Core Storage] Update One', props());
5326
- const deleteOne = createAction('[MECX Core Storage] Delete One', props());
5327
-
5328
- var monkeyecxStorage_actions = /*#__PURE__*/Object.freeze({
5329
- __proto__: null,
5330
- clear: clear,
5331
- create: create,
5332
- updateControl: updateControl,
5333
- updateOne: updateOne,
5334
- deleteOne: deleteOne
5335
- });
5336
-
5337
- var index$3 = /*#__PURE__*/Object.freeze({
5338
- __proto__: null,
5339
- monkeyecxStorage: monkeyecxStorage_actions
5340
- });
5341
-
5342
- const seederReducer = (keys) => {
5343
- return (reducer) => {
5344
- return (state, action) => {
5345
- const handledState = reducer(state, action);
5346
- if (action.type === INIT || action.type === UPDATE) {
5347
- const storageValue = localStorage.getItem('state');
5348
- if (storageValue) {
5349
- try {
5350
- const handled = Object.assign(Object.assign({}, handledState), JSON.parse(atob(storageValue)));
5351
- return handled;
5352
- }
5353
- catch (_a) {
5354
- localStorage.removeItem('state');
5355
- }
5356
- }
5357
- }
5358
- let data = handledState;
5359
- try {
5360
- keys.forEach((key) => {
5361
- data = Object.assign(Object.assign({}, data), { [key]: handledState[key] });
5362
- });
5363
- localStorage.setItem('state', btoa(JSON.stringify(data)));
5364
- }
5365
- catch (e) {
5366
- localStorage.removeItem('state');
5367
- }
5368
- return data || handledState;
5369
- };
5370
- };
5371
- };
5372
-
5373
- var monkeyecxSeeder_reducer = /*#__PURE__*/Object.freeze({
5374
- __proto__: null,
5375
- seederReducer: seederReducer
5376
- });
5377
-
5378
- const featureKey = 'mecx-core-storage';
5379
- const adapter = createEntityAdapter({
5380
- selectId: (item) => {
5381
- return item.username;
5382
- }
5383
- });
5384
- const initialState = adapter.getInitialState({
5385
- control: {
5386
- isLoading: false
5387
- },
5388
- error: null
5389
- });
5390
- const reducer = createReducer(initialState, on(clear, (state) => {
5391
- return adapter.removeAll(state);
5392
- }), on(create, (state, action) => {
5393
- return adapter.upsertMany(action.data, Object.assign({}, state));
5394
- }), on(updateControl, (state, action) => {
5395
- return Object.assign(Object.assign({}, state), { control: Object.assign(Object.assign({}, state.control), action.data) });
5396
- }), on(updateOne, (state, action) => {
5397
- const { username } = action.data;
5398
- return adapter.upsertOne(Object.assign(Object.assign({}, action.data), { username }), Object.assign({}, state));
5399
- }), on(deleteOne, (state, action) => {
5400
- const { username } = action.data;
5401
- return adapter.removeOne(username, state);
5402
- }));
5403
- const { selectAll: selectAll$1, selectEntities, selectIds, selectTotal } = adapter.getSelectors();
5404
-
5405
- var monkeyecxStorage_reducer = /*#__PURE__*/Object.freeze({
5406
- __proto__: null,
5407
- featureKey: featureKey,
5408
- adapter: adapter,
5409
- initialState: initialState,
5410
- reducer: reducer,
5411
- selectAll: selectAll$1,
5412
- selectEntities: selectEntities,
5413
- selectIds: selectIds,
5414
- selectTotal: selectTotal
5415
- });
5416
-
5417
- var index$2 = /*#__PURE__*/Object.freeze({
5418
- __proto__: null,
5419
- fromMonkeyecxSeeder: monkeyecxSeeder_reducer,
5420
- fromMonkeyecxStorage: monkeyecxStorage_reducer
5421
- });
5422
-
5423
- const selectState = createFeatureSelector(featureKey);
5424
- const selectAll = createSelector(selectState, selectAll$1);
5425
- const select = (props) => {
5426
- return createSelector(selectAll, (entities) => {
5427
- return entities.filter((_) => {
5428
- return _.username === props.username;
5429
- });
5430
- });
5431
- };
5432
- const selectControl = () => {
5433
- return createSelector(selectState, (state) => {
5434
- return state.control;
5435
- });
5436
- };
5437
-
5438
- var monkeyecxStorage_selector = /*#__PURE__*/Object.freeze({
5439
- __proto__: null,
5440
- selectState: selectState,
5441
- selectAll: selectAll,
5442
- select: select,
5443
- selectControl: selectControl
5444
- });
5445
-
5446
- var index$1 = /*#__PURE__*/Object.freeze({
5447
- __proto__: null,
5448
- monkeyecxStorage: monkeyecxStorage_selector
5449
- });
5450
-
5451
- var index = /*#__PURE__*/Object.freeze({
5452
- __proto__: null,
5453
- actions: index$3,
5454
- reducers: index$2,
5455
- selectors: index$1
5456
- });
5457
-
5458
5528
  class MonkeyFrontCoreModule {
5459
5529
  }
5460
5530
  MonkeyFrontCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyFrontCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
5461
5531
  MonkeyFrontCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyFrontCoreModule, imports: [CommonModule,
5462
- HttpClientModule, i1$1.TranslateModule, MonkeyEcxConfigModule, MonkeyEcxHttpConfigInterceptorModule, MonkeyEcxErrorHandlingModule, MonkeyStyleGuideModule, i1$5.ServiceWorkerModule, ClosedToMaintenanceModule, i6.StoreFeatureModule, VersionChangedModule,
5532
+ HttpClientModule, i1$1.TranslateModule, MonkeyEcxConfigModule, MonkeyEcxHttpConfigInterceptorModule, MonkeyEcxErrorHandlingModule, MonkeyStyleGuideModule, i1$5.ServiceWorkerModule, ClosedToMaintenanceModule, i2$3.StoreFeatureModule, VersionChangedModule,
5463
5533
  AlertsModule,
5464
5534
  CurrencyConfigModule] });
5465
5535
  MonkeyFrontCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyFrontCoreModule, providers: [