@open-rlb/ng-app 3.0.20 → 3.0.22

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.
@@ -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,83 @@ 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(
506
+ // waiting for all "finalizeApp" dispatches
507
+ filter(apps => {
508
+ if (!apps || apps.length === 0)
509
+ return true;
510
+ const allFinalized = !apps.some(app => !app.id);
511
+ if (!allFinalized) {
512
+ this.logger.info('Waiting for apps initialization (finalizeApp)...');
513
+ }
514
+ return allFinalized;
515
+ }),
516
+ // Return config in there are matched apps, or it's root route case
517
+ map(apps => {
518
+ if (appRoutesMatched.length > 0 || fullPath === '') {
519
+ return { route, appsConfig: appRoutesMatched, apps };
520
+ }
521
+ return null;
522
+ }));
507
523
  }
508
524
  handleResolvedApps(data) {
509
525
  const route = this.findDeepestChild(this.activatedRoute);
510
526
  const storedId = this.getStoredAppId();
527
+ // Check if it is a root route
528
+ const currentPath = route.snapshot.url.map(s => s.path).join('/');
529
+ const isRoot = currentPath === '';
511
530
  if (data?.apps?.some(app => !app.id)) {
512
- this.logger.error('Some apps are not finalized. Please finalize apps before using AppsService.');
531
+ this.logger.error('Some apps are not finalized...');
513
532
  return;
514
533
  }
515
534
  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];
535
+ this.logger.warn(`No apps found (or data is null). Path: '${currentPath}'`);
518
536
  this.selectApp(undefined);
519
537
  return;
520
538
  }
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)))
539
+ // domain filter
540
+ const domainApps = data.apps.filter(app => !app.domains || app.domains?.some((domain) => domain.includes(this.currentDomain)));
541
+ if (domainApps.length === 0) {
542
+ this.logger.warn(`No apps allowed for domain: ${this.currentDomain}`);
543
+ this.selectApp(undefined);
544
+ return;
545
+ }
546
+ // Auto-redirect logic
547
+ // if there is a root route and only 1 app matched -> auto redirect on app home page
548
+ if (isRoot && domainApps.length === 1) {
549
+ const singleApp = domainApps[0];
550
+ const targetUrl = singleApp.core?.url;
551
+ if (targetUrl && targetUrl !== '/' && targetUrl !== '') {
552
+ this.logger.info(`[AutoRedirect] Single app detected at root. Redirecting to: ${targetUrl}`);
553
+ this.router.navigate([targetUrl], {
554
+ queryParams: route.snapshot.queryParams,
555
+ replaceUrl: true
556
+ });
557
+ // break flow, to prevent selectApp
558
+ return;
559
+ }
560
+ }
561
+ const matchedApps = domainApps
524
562
  .filter(app => app.routes?.some(r => r.includes(route.routeConfig?.path)) ||
525
- app.core?.url === '/' + route.routeConfig?.path);
563
+ app.core?.url === '/' + route.routeConfig?.path ||
564
+ (isRoot && app.core?.url));
526
565
  let appToSelect;
527
566
  if (matchedApps.length === 1) {
528
567
  appToSelect = matchedApps[0];
@@ -533,11 +572,11 @@ class AppsService {
533
572
  this.logger.info('Multiple apps matched route, selected:', appToSelect);
534
573
  }
535
574
  else {
536
- appToSelect = data.apps[0];
537
- this.logger.info('No app matched route. Falling back to default app:', appToSelect);
575
+ appToSelect = domainApps[0];
576
+ this.logger.info('No specific route match. Falling back to domain default:', appToSelect);
538
577
  }
539
578
  const qp = new URLSearchParams(route.snapshot.queryParams).toString();
540
- const url = route.snapshot.url.map(segment => segment.path).join('/') + (qp ? `?${qp}` : '');
579
+ const url = currentPath + (qp ? `?${qp}` : '');
541
580
  const viewMode = this.isSettingsRoute(route) ? 'settings' : 'app';
542
581
  this.selectApp(appToSelect, viewMode, url);
543
582
  }
@@ -1339,23 +1378,11 @@ class AuthenticationService {
1339
1378
  }
1340
1379
  else {
1341
1380
  this.logger.info(`User authenticated, no redirectUrl found. Staying on current route.`);
1342
- // this.router.navigate([], {
1343
- // queryParams: {},
1344
- // replaceUrl: true,
1345
- // relativeTo: this.router.routerState.root
1346
- // });
1347
1381
  }
1348
1382
  }
1349
1383
  else {
1350
1384
  this.logger.warn(`No authenticatedConfig found for ${url}`);
1351
1385
  }
1352
- // if (data.some(o => o.isAuthenticated)) {
1353
- // const redirect = this.cookiesService.getCookie('loginRedirectUrl');
1354
- // if (redirect) {
1355
- // this.cookiesService.deleteCookie('loginRedirectUrl');
1356
- // this.router.navigate([redirect]);
1357
- // }
1358
- // }
1359
1386
  }));
1360
1387
  //}
1361
1388
  }
@@ -2890,10 +2917,7 @@ class AuthEffects {
2890
2917
  return this.actions$.pipe(ofType(AuthActions.setCurrentProvider), map$1(({ currentProvider }) => AuthActionsInternal.setCurrentProvider({ currentProvider })));
2891
2918
  });
2892
2919
  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
- // }
2920
+ this.logger.log(`Initialized AuthEffects}`);
2897
2921
  }
2898
2922
  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
2923
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AuthEffects }); }
@@ -3056,18 +3080,6 @@ function provideRlbConfig(env) {
3056
3080
  },
3057
3081
  multi: true,
3058
3082
  },
3059
- // {
3060
- // provide: APP_INITIALIZER,
3061
- // useFactory: authInitializer,
3062
- // deps: [AuthenticationService],
3063
- // multi: true
3064
- // },
3065
- // {
3066
- // provide: APP_INITIALIZER,
3067
- // useFactory: appsServiceInitializer,
3068
- // deps: [AppsService],
3069
- // multi: true
3070
- // },
3071
3083
  ];
3072
3084
  }
3073
3085
  function provideApp(app) {