@dsivd/prestations-ng 18.2.4-beta.5 → 18.2.4-beta.6

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.
@@ -5,7 +5,7 @@ import { ActivatedRoute, NavigationStart, RouterModule, NavigationEnd, RouterLin
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
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
- import { HttpStatusCode, HttpClient, HttpHeaders, HttpResponseBase, HttpErrorResponse, HttpParams, HttpEventType, HttpResponse, HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
8
+ import { HttpStatusCode, HttpClient, HttpResponseBase, HttpHeaders, HttpErrorResponse, HttpParams, HttpEventType, HttpResponse, HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
9
9
  import * as i3 from '@angular/forms';
10
10
  import { NgModel, NgForm, FormsModule } from '@angular/forms';
11
11
  import * as i2 from '@angular/common';
@@ -1926,28 +1926,38 @@ class IamExpiredInterceptorService {
1926
1926
  if (req.headers.has('X-Skip-Interceptor') ||
1927
1927
  req.url.includes(APP_INFO_API_URL) ||
1928
1928
  req.url.includes(SESSION_INFO_API_URL)) {
1929
+ console.log('skipping interceptor for req : ', req);
1929
1930
  return next.handle(req);
1930
1931
  }
1931
- const isDevEnv = this.appInfoService.data.pipe(map(appInfo => appInfo.environment.toUpperCase() === 'CO'));
1932
- const isUserConnected = this.sessionInfoService.data.pipe(map(sessionInfo => !!sessionInfo?.context));
1933
- return combineLatest([isDevEnv, isUserConnected]).pipe(take(1), switchMap(([isDev, isConnected]) => {
1934
- const renewIamSession = this.http
1935
- .options('/sessioninfo/v2/me', {
1936
- headers: new HttpHeaders({
1937
- 'X-Skip-Interceptor': 'true'
1938
- })
1939
- })
1940
- .pipe(catchError(() => of(null)));
1941
- return (!isDev && isConnected ? renewIamSession : of(null)).pipe(switchMap(() => next.handle(req).pipe(map(event => {
1942
- if (event instanceof HttpResponseBase) {
1943
- if (hasIamExpiredHeader(event) ||
1944
- isRedirectionToLogin(event)) {
1945
- this.setIamSessionExpiredManually();
1946
- }
1947
- }
1948
- return event;
1949
- }), catchError(this.handleError.bind(this)))));
1932
+ const isDevEnv = this.appInfoService.data.pipe(map(appInfo => appInfo.environment.toUpperCase() === 'CO'), tap(result => {
1933
+ console.log('isDevEnv', result);
1934
+ }));
1935
+ const isUserConnected = this.sessionInfoService.data.pipe(map(sessionInfo => !!sessionInfo?.context), tap(result => {
1936
+ console.log('isUserConnected', result);
1950
1937
  }));
1938
+ return combineLatest([isDevEnv, isUserConnected]).pipe(take(1), switchMap(([isDev, isConnected]) => (!isDev && isConnected
1939
+ ? this.getRenewIamSession()
1940
+ : of(null)).pipe(switchMap(() => next.handle(req).pipe(map(event => {
1941
+ if (event instanceof HttpResponseBase) {
1942
+ if (hasIamExpiredHeader(event) ||
1943
+ isRedirectionToLogin(event)) {
1944
+ this.setIamSessionExpiredManually();
1945
+ }
1946
+ }
1947
+ return event;
1948
+ }), catchError(this.handleError.bind(this)))))));
1949
+ }
1950
+ getRenewIamSession() {
1951
+ // call session info through RP IAM (prestations.vd.ch)
1952
+ // this renews the session since it is a "securised" endpoint
1953
+ // use OPTIONS to avoid extra load on session info
1954
+ return this.http
1955
+ .options('/sessioninfo/v2/me', {
1956
+ headers: new HttpHeaders({
1957
+ 'X-Skip-Interceptor': 'true'
1958
+ })
1959
+ })
1960
+ .pipe(catchError(() => of(null)));
1951
1961
  }
1952
1962
  handleError(err) {
1953
1963
  if (err instanceof HttpErrorResponse) {