@dsivd/prestations-ng 18.2.4-beta.3 → 18.2.4-beta.4

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.
@@ -3,7 +3,7 @@ import { Optional, Inject, Injectable, EventEmitter, Input, HostBinding, Output,
3
3
  import * as i1$1 from '@angular/router';
4
4
  import { ActivatedRoute, NavigationStart, RouterModule, NavigationEnd, RouterLink } from '@angular/router';
5
5
  import { of, Subject, BehaviorSubject, combineLatest, throwError, switchMap as switchMap$1, forkJoin, tap as tap$1, concat, toArray, EMPTY, startWith, filter as filter$1, merge, withLatestFrom, debounceTime as debounceTime$1, map as map$1 } from 'rxjs';
6
- import { map, shareReplay, filter, tap, debounceTime, catchError, switchMap, first, throttleTime, mergeMap, share, finalize, distinctUntilChanged } from 'rxjs/operators';
6
+ import { map, shareReplay, filter, tap, debounceTime, catchError, switchMap, take, first, throttleTime, mergeMap, share, finalize, distinctUntilChanged } from 'rxjs/operators';
7
7
  import * as i1 from '@angular/common/http';
8
8
  import { HttpStatusCode, HttpClient, HttpHeaders, HttpResponseBase, HttpErrorResponse, HttpParams, HttpEventType, HttpResponse, HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
9
9
  import * as i3 from '@angular/forms';
@@ -1910,8 +1910,10 @@ const isRedirectionToLogin = (event) => {
1910
1910
  };
1911
1911
  class IamExpiredInterceptorService {
1912
1912
  constructor() {
1913
- this._isIamSessionExpired = new BehaviorSubject(false);
1914
1913
  this.http = inject(HttpClient);
1914
+ this.appInfoService = inject(ApplicationInfoService);
1915
+ this.sessionInfoService = inject(SessionInfo);
1916
+ this._isIamSessionExpired = new BehaviorSubject(false);
1915
1917
  }
1916
1918
  get isIamSessionExpired() {
1917
1919
  return this._isIamSessionExpired.asObservable();
@@ -1924,20 +1926,26 @@ class IamExpiredInterceptorService {
1924
1926
  if (req.headers.has('X-Skip-Interceptor')) {
1925
1927
  return next.handle(req);
1926
1928
  }
1927
- return (this.http
1928
- // before any request, refresh the IAM session by calling session info
1929
- .options('/sessioninfo/v2/me', {
1930
- headers: new HttpHeaders({ 'X-Skip-Interceptor': 'true' })
1931
- })
1932
- .pipe(switchMap(() => next.handle(req).pipe(map(event => {
1933
- if (event instanceof HttpResponseBase) {
1934
- if (hasIamExpiredHeader(event) ||
1935
- isRedirectionToLogin(event)) {
1936
- this.setIamSessionExpiredManually();
1929
+ const isDevEnv = this.appInfoService.data.pipe(map(appInfo => appInfo.environment.toUpperCase() === 'CO'));
1930
+ const isUserConnected = this.sessionInfoService.data.pipe(map(sessionInfo => !!sessionInfo?.context));
1931
+ return combineLatest([isDevEnv, isUserConnected]).pipe(take(1), switchMap(([isDev, isConnected]) => {
1932
+ const renewIamSession = this.http
1933
+ .options('/sessioninfo/v2/me', {
1934
+ headers: new HttpHeaders({
1935
+ 'X-Skip-Interceptor': 'true'
1936
+ })
1937
+ })
1938
+ .pipe(catchError(() => of(null)));
1939
+ return (!isDev && isConnected ? renewIamSession : of(null)).pipe(switchMap(() => next.handle(req).pipe(map(event => {
1940
+ if (event instanceof HttpResponseBase) {
1941
+ if (hasIamExpiredHeader(event) ||
1942
+ isRedirectionToLogin(event)) {
1943
+ this.setIamSessionExpiredManually();
1944
+ }
1937
1945
  }
1938
- }
1939
- return event;
1940
- }), catchError(this.handleError.bind(this))))));
1946
+ return event;
1947
+ }), catchError(this.handleError.bind(this)))));
1948
+ }));
1941
1949
  }
1942
1950
  handleError(err) {
1943
1951
  if (err instanceof HttpErrorResponse) {