@smartbit4all/ng-client 3.3.216 → 3.3.217
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.
- package/esm2020/lib/session/smart-error-catching.interceptor.mjs +11 -2
- package/esm2020/lib/session/smart-session.service.mjs +31 -26
- package/fesm2015/smartbit4all-ng-client.mjs +40 -27
- package/fesm2015/smartbit4all-ng-client.mjs.map +1 -1
- package/fesm2020/smartbit4all-ng-client.mjs +40 -27
- package/fesm2020/smartbit4all-ng-client.mjs.map +1 -1
- package/lib/session/smart-session.service.d.ts +2 -0
- package/package.json +1 -1
- package/smartbit4all-ng-client-3.3.217.tgz +0 -0
- package/smartbit4all-ng-client-3.3.216.tgz +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, Injectable, Optional, Inject, PLATFORM_ID, NgModule, SkipSelf, Component, RendererStyleFlags2, Input, Directive, HostBinding, HostListener, ViewChild, forwardRef, EventEmitter, Output, Pipe, ViewContainerRef, ViewEncapsulation, ChangeDetectionStrategy, ViewChildren, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, ChangeDetectorRef } from '@angular/core';
|
|
3
|
-
import { Subject, takeUntil, startWith, map, distinctUntilChanged, catchError, throwError, from, lastValueFrom } from 'rxjs';
|
|
4
3
|
import * as i1 from '@angular/common/http';
|
|
5
|
-
import { HttpHeaders, HttpContext, HttpParams, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
4
|
+
import { HttpHeaders, HttpContext, HttpErrorResponse, HttpParams, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
5
|
+
import { Subject, lastValueFrom, takeUntil, startWith, map, distinctUntilChanged, catchError, throwError, from } from 'rxjs';
|
|
6
6
|
import * as i3 from '@angular/common';
|
|
7
7
|
import { isPlatformBrowser, DOCUMENT, DatePipe, CommonModule } from '@angular/common';
|
|
8
8
|
import * as i2 from '@angular/material/button';
|
|
@@ -829,7 +829,7 @@ class SmartSessionService {
|
|
|
829
829
|
}
|
|
830
830
|
async handleSessionError(sessionError) {
|
|
831
831
|
if (this.sessionHandlerService) {
|
|
832
|
-
await this.sessionHandlerService.handleSessionError(sessionError);
|
|
832
|
+
return await this.sessionHandlerService.handleSessionError(sessionError);
|
|
833
833
|
}
|
|
834
834
|
throw new Error(`sessionHandlerService was not initialized. Error: ${sessionError.code}`);
|
|
835
835
|
}
|
|
@@ -924,11 +924,7 @@ class SmartSessionService {
|
|
|
924
924
|
async startSession() {
|
|
925
925
|
let sessionInfo = await this.apiService.startSession().toPromise();
|
|
926
926
|
if (sessionInfo) {
|
|
927
|
-
this.
|
|
928
|
-
this.token = sessionInfo.sid;
|
|
929
|
-
this.saveTokenToLocalStorage();
|
|
930
|
-
this.setAuthenticationStatus();
|
|
931
|
-
this.setUpTokenForSessionService();
|
|
927
|
+
this.updateSessionInfo(sessionInfo);
|
|
932
928
|
}
|
|
933
929
|
return this.sessionInfoData;
|
|
934
930
|
}
|
|
@@ -947,26 +943,34 @@ class SmartSessionService {
|
|
|
947
943
|
if (!refreshToken) {
|
|
948
944
|
return await this.startSession();
|
|
949
945
|
}
|
|
950
|
-
|
|
951
|
-
.refreshSession({
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
.catch(async (error) => {
|
|
956
|
-
if (error.error &&
|
|
957
|
-
error.error.code &&
|
|
958
|
-
error.error.code === 'session.refreshtoken.invalid') {
|
|
959
|
-
await this.startSession();
|
|
946
|
+
try {
|
|
947
|
+
const sessionInfo = await lastValueFrom(this.apiService.refreshSession({ refreshToken }));
|
|
948
|
+
if (sessionInfo) {
|
|
949
|
+
this.updateSessionInfo(sessionInfo);
|
|
950
|
+
return sessionInfo;
|
|
960
951
|
}
|
|
961
|
-
});
|
|
962
|
-
if (sessionInfo) {
|
|
963
|
-
this.sessionInfoData = sessionInfo;
|
|
964
|
-
this.token = sessionInfo.sid;
|
|
965
|
-
this.saveTokenToLocalStorage();
|
|
966
|
-
this.setAuthenticationStatus();
|
|
967
|
-
this.setUpTokenForSessionService();
|
|
968
952
|
}
|
|
969
|
-
|
|
953
|
+
catch (error) {
|
|
954
|
+
if (this.isInvalidRefreshTokenError(error)) {
|
|
955
|
+
this.clearAndStartNewSession();
|
|
956
|
+
// still throw the error, so the error can be handled in the caller
|
|
957
|
+
}
|
|
958
|
+
throw error;
|
|
959
|
+
}
|
|
960
|
+
// no sessionInfo returned
|
|
961
|
+
throw new Error('Unable to refresh session');
|
|
962
|
+
}
|
|
963
|
+
updateSessionInfo(sessionInfo) {
|
|
964
|
+
this.sessionInfoData = sessionInfo;
|
|
965
|
+
this.token = sessionInfo.sid;
|
|
966
|
+
this.saveTokenToLocalStorage();
|
|
967
|
+
this.setAuthenticationStatus();
|
|
968
|
+
this.setUpTokenForSessionService();
|
|
969
|
+
}
|
|
970
|
+
isInvalidRefreshTokenError(error) {
|
|
971
|
+
return (error instanceof HttpErrorResponse &&
|
|
972
|
+
error.error &&
|
|
973
|
+
error.error.code === 'session.refreshtoken.invalid');
|
|
970
974
|
}
|
|
971
975
|
async getAuthenticationProviders() {
|
|
972
976
|
let providers = await this.apiService
|
|
@@ -9103,10 +9107,19 @@ class SmartErrorCatchingInterceptor {
|
|
|
9103
9107
|
const sessionError = this.getSessionError(error);
|
|
9104
9108
|
if (sessionError) {
|
|
9105
9109
|
return this.resolveError(sessionError).pipe(switchMap((resolved) => {
|
|
9106
|
-
if (resolved && sessionError.behaviour
|
|
9110
|
+
if (resolved && sessionError.behaviour === SessionErrorBehaviour.REFRESH) {
|
|
9107
9111
|
return next.handle(this.updateRequestHeaders(request));
|
|
9108
9112
|
}
|
|
9109
9113
|
return throwError(() => error);
|
|
9114
|
+
}), catchError$1((resolveError) => {
|
|
9115
|
+
// when the resolveError throws a restart error (in the refreshSession), rethrow the original error
|
|
9116
|
+
if (this.isSessionError(resolveError)) {
|
|
9117
|
+
const resolveSessionError = this.getSessionError(resolveError);
|
|
9118
|
+
if (resolveSessionError?.behaviour === SessionErrorBehaviour.RESTART) {
|
|
9119
|
+
return throwError(() => error);
|
|
9120
|
+
}
|
|
9121
|
+
}
|
|
9122
|
+
return throwError(() => resolveError);
|
|
9110
9123
|
}));
|
|
9111
9124
|
}
|
|
9112
9125
|
}
|