@open-rlb/ng-app 3.0.19 → 3.0.21

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.
@@ -1,7 +1,7 @@
1
1
  import * as i1$3 from '@angular/common/http';
2
2
  import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
3
3
  import * as i0 from '@angular/core';
4
- import { InjectionToken, Injectable, Inject, Optional, EventEmitter, importProvidersFrom, makeStateKey, makeEnvironmentProviders, Pipe, Input, Component, PLATFORM_ID, NgModule, Directive, inject, APP_INITIALIZER, isDevMode } from '@angular/core';
4
+ import { InjectionToken, Injectable, Inject, Optional, EventEmitter, importProvidersFrom, makeStateKey, makeEnvironmentProviders, Pipe, Input, Component, PLATFORM_ID, NgModule, Directive, inject, provideAppInitializer, isDevMode } from '@angular/core';
5
5
  import * as i2 from '@angular/router';
6
6
  import { NavigationEnd, RoutesRecognized, RouterModule, Router, provideRouter } from '@angular/router';
7
7
  import * as i1$4 from '@angular/service-worker';
@@ -15,7 +15,7 @@ import { RLB_TRANSLATION_SERVICE, RlbBootstrapModule, ModalDirective, ToastDirec
15
15
  import * as i1$5 from 'angular-auth-oidc-client';
16
16
  import { AbstractLoggerService, AuthModule, provideAuth, AuthInterceptor, AbstractSecurityStorage } from 'angular-auth-oidc-client';
17
17
  import * as i1 from 'ngx-cookie-service-ssr';
18
- import { filter, switchMap, of, map, BehaviorSubject, share, lastValueFrom, from, zip, EMPTY, catchError, Observable, tap, shareReplay, distinctUntilChanged, take } from 'rxjs';
18
+ import { filter, switchMap, map, BehaviorSubject, of, share, lastValueFrom, from, zip, EMPTY, catchError, Observable, tap, shareReplay, distinctUntilChanged, take } from 'rxjs';
19
19
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
20
20
  import * as i1$2 from '@ngx-translate/core';
21
21
  import { TranslateModule } from '@ngx-translate/core';
@@ -485,44 +485,72 @@ class AppsService {
485
485
  resolveRouteAndApps() {
486
486
  const route = this.findDeepestChild(this.activatedRoute);
487
487
  const fullPath = this.getFullPath(route);
488
- this.logger.info('Full path for route resolution:', fullPath);
489
- if (!fullPath) {
490
- this.logger.warn('No valid path found, treating as default route:', route);
491
- return of(null);
492
- }
488
+ this.logger.info(`Full path for route resolution: '${fullPath}'`);
489
+ // if (!fullPath) {
490
+ // this.logger.warn('No valid path found, treating as default route:', route);
491
+ // return of(null);
492
+ // }
493
493
  const appRoutes = this.apps?.map(app => ({
494
494
  type: app.type,
495
495
  routes: app.routes || [],
496
496
  viewMode: app.viewMode,
497
497
  enabled: app.enabled,
498
+ core: app.core
498
499
  }));
499
500
  let appRoutesMatched = [];
500
- if (!this.isDefaultRoute(fullPath)) {
501
+ if (fullPath && !this.isDefaultRoute(fullPath)) {
501
502
  appRoutesMatched = appRoutes?.filter(app => app.routes?.some(r => r.includes(fullPath))) ?? [];
502
503
  }
503
504
  this.logger.info('Route fullPath:', fullPath, 'Matched appRoute:', appRoutesMatched);
504
- return this.store.select(state => state[appContextFeatureKey].apps).pipe(map(apps => appRoutesMatched.length
505
- ? { route, appsConfig: appRoutesMatched, apps }
506
- : null));
505
+ return this.store.select(state => state[appContextFeatureKey].apps).pipe(map(apps => {
506
+ // handle root route case
507
+ if (appRoutesMatched.length > 0 || fullPath === '') {
508
+ return { route, appsConfig: appRoutesMatched, apps };
509
+ }
510
+ return null;
511
+ }));
507
512
  }
508
513
  handleResolvedApps(data) {
509
514
  const route = this.findDeepestChild(this.activatedRoute);
510
515
  const storedId = this.getStoredAppId();
516
+ // Check if it is a root route
517
+ const currentPath = route.snapshot.url.map(s => s.path).join('/');
518
+ const isRoot = currentPath === '';
511
519
  if (data?.apps?.some(app => !app.id)) {
512
- this.logger.error('Some apps are not finalized. Please finalize apps before using AppsService.');
520
+ this.logger.error('Some apps are not finalized...');
513
521
  return;
514
522
  }
515
523
  if (!data || !data.apps || data.apps.length === 0) {
516
- this.logger.warn(`No unique app found for route: ${route.routeConfig?.path ? route.routeConfig?.path : "'/'"} - show core`);
517
- // const globalDefaultApp = this.apps[0];
524
+ this.logger.warn(`No apps found (or data is null). Path: '${currentPath}'`);
518
525
  this.selectApp(undefined);
519
526
  return;
520
527
  }
521
- const matchedApps = data.apps
522
- // domain filter in case apps have similar routes path
523
- .filter(app => !app.domains || app.domains?.some((domain) => domain.includes(this.currentDomain)))
528
+ // domain filter
529
+ const domainApps = data.apps.filter(app => !app.domains || app.domains?.some((domain) => domain.includes(this.currentDomain)));
530
+ if (domainApps.length === 0) {
531
+ this.logger.warn(`No apps allowed for domain: ${this.currentDomain}`);
532
+ this.selectApp(undefined);
533
+ return;
534
+ }
535
+ // Auto-redirect logic
536
+ // if there is a root route and only 1 app matched -> auto redirect on app home page
537
+ if (isRoot && domainApps.length === 1) {
538
+ const singleApp = domainApps[0];
539
+ const targetUrl = singleApp.core?.url;
540
+ if (targetUrl && targetUrl !== '/' && targetUrl !== '') {
541
+ this.logger.info(`[AutoRedirect] Single app detected at root. Redirecting to: ${targetUrl}`);
542
+ this.router.navigate([targetUrl], {
543
+ queryParams: route.snapshot.queryParams,
544
+ replaceUrl: true
545
+ });
546
+ // break flow, to prevent selectApp
547
+ return;
548
+ }
549
+ }
550
+ const matchedApps = domainApps
524
551
  .filter(app => app.routes?.some(r => r.includes(route.routeConfig?.path)) ||
525
- app.core?.url === '/' + route.routeConfig?.path);
552
+ app.core?.url === '/' + route.routeConfig?.path ||
553
+ (isRoot && app.core?.url));
526
554
  let appToSelect;
527
555
  if (matchedApps.length === 1) {
528
556
  appToSelect = matchedApps[0];
@@ -533,11 +561,11 @@ class AppsService {
533
561
  this.logger.info('Multiple apps matched route, selected:', appToSelect);
534
562
  }
535
563
  else {
536
- appToSelect = data.apps[0];
537
- this.logger.info('No app matched route. Falling back to default app:', appToSelect);
564
+ appToSelect = domainApps[0];
565
+ this.logger.info('No specific route match. Falling back to domain default:', appToSelect);
538
566
  }
539
567
  const qp = new URLSearchParams(route.snapshot.queryParams).toString();
540
- const url = route.snapshot.url.map(segment => segment.path).join('/') + (qp ? `?${qp}` : '');
568
+ const url = currentPath + (qp ? `?${qp}` : '');
541
569
  const viewMode = this.isSettingsRoute(route) ? 'settings' : 'app';
542
570
  this.selectApp(appToSelect, viewMode, url);
543
571
  }
@@ -2890,10 +2918,7 @@ class AuthEffects {
2890
2918
  return this.actions$.pipe(ofType(AuthActions.setCurrentProvider), map$1(({ currentProvider }) => AuthActionsInternal.setCurrentProvider({ currentProvider })));
2891
2919
  });
2892
2920
  this.logger = this.loggerService.for(this.constructor.name);
2893
- this.logger.log(`Initialized AuthEffects, auth config: ${authConfig}`);
2894
- // if (authConfig) {
2895
- // auth.checkAuthMultiple().subscribe();
2896
- // }
2921
+ this.logger.log(`Initialized AuthEffects}`);
2897
2922
  }
2898
2923
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AuthEffects, deps: [{ token: i1$8.Actions }, { token: AuthenticationService }, { token: AppLoggerService }, { token: RLB_CFG_AUTH, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
2899
2924
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AuthEffects }); }
@@ -3004,10 +3029,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
3004
3029
  }]
3005
3030
  }] });
3006
3031
 
3007
- function authInitializer(authService) {
3008
- return () => authService.checkAuthMultiple();
3009
- }
3010
-
3011
3032
  const verifyDeactivate = (component, currentRoute, currentState, nextState) => {
3012
3033
  return component.verifyDeactivate();
3013
3034
  };
@@ -3031,6 +3052,13 @@ function provideRlbConfig(env) {
3031
3052
  enabled: !isDevMode(),
3032
3053
  registrationStrategy: 'registerWhenStable:15000',
3033
3054
  }),
3055
+ provideAppInitializer(() => {
3056
+ inject(AppsService);
3057
+ }),
3058
+ provideAppInitializer(() => {
3059
+ const authService = inject(AuthenticationService);
3060
+ return authService.checkAuthMultiple();
3061
+ }),
3034
3062
  { provide: RLB_CFG, useValue: env },
3035
3063
  { provide: RLB_CFG_ENV, useValue: env.environment },
3036
3064
  { provide: RLB_CFG_CMS, useValue: env.cms },
@@ -3053,12 +3081,6 @@ function provideRlbConfig(env) {
3053
3081
  },
3054
3082
  multi: true,
3055
3083
  },
3056
- {
3057
- provide: APP_INITIALIZER,
3058
- useFactory: authInitializer,
3059
- deps: [AuthenticationService],
3060
- multi: true
3061
- },
3062
3084
  ];
3063
3085
  }
3064
3086
  function provideApp(app) {