@smartbit4all/ng-client 2.0.9 → 2.0.11
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/dev-tool/smart-dev-tool-dialog/smart-dev-tool-dialog.component.mjs +2 -1
- package/esm2020/lib/session/dev-tool/smart-dev-tool-floating-button/smart-dev-tool-floating-button.component.mjs +2 -1
- package/esm2020/lib/session/smart-error-catching.interceptor.mjs +51 -27
- package/esm2020/lib/session/smart-session-handler.service.mjs +1 -1
- package/esm2020/lib/session/smart-session.service.mjs +31 -26
- package/esm2020/lib/view-context/smart-ui-action/ui-action-toolbar.component.mjs +2 -1
- package/fesm2015/smartbit4all-ng-client.mjs +80 -49
- package/fesm2015/smartbit4all-ng-client.mjs.map +1 -1
- package/fesm2020/smartbit4all-ng-client.mjs +80 -49
- package/fesm2020/smartbit4all-ng-client.mjs.map +1 -1
- package/lib/session/smart-error-catching.interceptor.d.ts +8 -4
- package/lib/session/smart-session-handler.service.d.ts +10 -0
- package/lib/session/smart-session.service.d.ts +2 -0
- package/package.json +1 -1
- package/smartbit4all-ng-client-2.0.11.tgz +0 -0
- package/smartbit4all-ng-client-2.0.9.tgz +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, Injectable, Optional, Inject, PLATFORM_ID, NgModule, SkipSelf, Component, Pipe, CUSTOM_ELEMENTS_SCHEMA, ViewChild, Input, ViewChildren } from '@angular/core';
|
|
3
3
|
import { __awaiter, __decorate, __param } from 'tslib';
|
|
4
|
-
import { Subject, takeUntil, map, catchError, throwError, from } from 'rxjs';
|
|
5
|
-
import { SmartSubject } from '@smartbit4all/subject';
|
|
6
4
|
import * as i1 from '@angular/common/http';
|
|
7
|
-
import { HttpHeaders, HttpContext, HttpParams, HttpEventType, HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
|
|
5
|
+
import { HttpHeaders, HttpContext, HttpErrorResponse, HttpParams, HttpEventType, HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
|
|
6
|
+
import { Subject, lastValueFrom, takeUntil, map, catchError, throwError, from } from 'rxjs';
|
|
7
|
+
import { SmartSubject } from '@smartbit4all/subject';
|
|
8
8
|
import * as i4 from '@angular/common';
|
|
9
9
|
import { isPlatformBrowser, DOCUMENT, DatePipe, CommonModule } from '@angular/common';
|
|
10
10
|
import * as i2 from '@angular/material/button';
|
|
@@ -711,7 +711,7 @@ class SmartSessionService {
|
|
|
711
711
|
handleSessionError(sessionError) {
|
|
712
712
|
return __awaiter(this, void 0, void 0, function* () {
|
|
713
713
|
if (this.sessionHandlerService) {
|
|
714
|
-
yield this.sessionHandlerService.handleSessionError(sessionError);
|
|
714
|
+
return yield this.sessionHandlerService.handleSessionError(sessionError);
|
|
715
715
|
}
|
|
716
716
|
throw new Error(`sessionHandlerService was not initialized. Error: ${sessionError.code}`);
|
|
717
717
|
});
|
|
@@ -810,11 +810,7 @@ class SmartSessionService {
|
|
|
810
810
|
return __awaiter(this, void 0, void 0, function* () {
|
|
811
811
|
let sessionInfo = yield this.apiService.startSession().toPromise();
|
|
812
812
|
if (sessionInfo) {
|
|
813
|
-
this.
|
|
814
|
-
this.token = sessionInfo.sid;
|
|
815
|
-
this.saveTokenToLocalStorage();
|
|
816
|
-
this.setAuthenticationStatus();
|
|
817
|
-
this.setUpTokenForSessionService();
|
|
813
|
+
this.updateSessionInfo(sessionInfo);
|
|
818
814
|
}
|
|
819
815
|
return this.sessionInfoData;
|
|
820
816
|
});
|
|
@@ -837,28 +833,36 @@ class SmartSessionService {
|
|
|
837
833
|
if (!refreshToken) {
|
|
838
834
|
return yield this.startSession();
|
|
839
835
|
}
|
|
840
|
-
|
|
841
|
-
.refreshSession({
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
846
|
-
if (error.error &&
|
|
847
|
-
error.error.code &&
|
|
848
|
-
error.error.code === 'session.refreshtoken.invalid') {
|
|
849
|
-
yield this.startSession();
|
|
836
|
+
try {
|
|
837
|
+
const sessionInfo = yield lastValueFrom(this.apiService.refreshSession({ refreshToken }));
|
|
838
|
+
if (sessionInfo) {
|
|
839
|
+
this.updateSessionInfo(sessionInfo);
|
|
840
|
+
return sessionInfo;
|
|
850
841
|
}
|
|
851
|
-
}));
|
|
852
|
-
if (sessionInfo) {
|
|
853
|
-
this.sessionInfoData = sessionInfo;
|
|
854
|
-
this.token = sessionInfo.sid;
|
|
855
|
-
this.saveTokenToLocalStorage();
|
|
856
|
-
this.setAuthenticationStatus();
|
|
857
|
-
this.setUpTokenForSessionService();
|
|
858
842
|
}
|
|
859
|
-
|
|
843
|
+
catch (error) {
|
|
844
|
+
if (this.isInvalidRefreshTokenError(error)) {
|
|
845
|
+
this.clearAndStartNewSession();
|
|
846
|
+
// still throw the error, so the error can be handled in the caller
|
|
847
|
+
}
|
|
848
|
+
throw error;
|
|
849
|
+
}
|
|
850
|
+
// no sessionInfo returned
|
|
851
|
+
throw new Error('Unable to refresh session');
|
|
860
852
|
});
|
|
861
853
|
}
|
|
854
|
+
updateSessionInfo(sessionInfo) {
|
|
855
|
+
this.sessionInfoData = sessionInfo;
|
|
856
|
+
this.token = sessionInfo.sid;
|
|
857
|
+
this.saveTokenToLocalStorage();
|
|
858
|
+
this.setAuthenticationStatus();
|
|
859
|
+
this.setUpTokenForSessionService();
|
|
860
|
+
}
|
|
861
|
+
isInvalidRefreshTokenError(error) {
|
|
862
|
+
return (error instanceof HttpErrorResponse &&
|
|
863
|
+
error.error &&
|
|
864
|
+
error.error.code === 'session.refreshtoken.invalid');
|
|
865
|
+
}
|
|
862
866
|
getAuthenticationProviders() {
|
|
863
867
|
return __awaiter(this, void 0, void 0, function* () {
|
|
864
868
|
let providers = yield this.apiService
|
|
@@ -2991,6 +2995,7 @@ class SmartDevToolDialogComponent {
|
|
|
2991
2995
|
}
|
|
2992
2996
|
ngOnDestroy() {
|
|
2993
2997
|
this._destroy$.next();
|
|
2998
|
+
this._destroy$.complete();
|
|
2994
2999
|
}
|
|
2995
3000
|
clear() {
|
|
2996
3001
|
this.service.clear();
|
|
@@ -3081,6 +3086,7 @@ class SmartDevToolFloatingButtonComponent {
|
|
|
3081
3086
|
}
|
|
3082
3087
|
ngOnDestroy() {
|
|
3083
3088
|
this._destroy$.next();
|
|
3089
|
+
this._destroy$.complete();
|
|
3084
3090
|
}
|
|
3085
3091
|
openDevToolDialog() {
|
|
3086
3092
|
this.service.openDialog();
|
|
@@ -3231,52 +3237,68 @@ class SmartErrorCatchingInterceptor {
|
|
|
3231
3237
|
this.session = session;
|
|
3232
3238
|
this.sessionErrorCodes = [
|
|
3233
3239
|
{
|
|
3234
|
-
code:
|
|
3240
|
+
code: 'session.expired',
|
|
3235
3241
|
behaviour: SessionErrorBehaviour.REFRESH,
|
|
3236
3242
|
},
|
|
3237
3243
|
{
|
|
3238
|
-
code:
|
|
3244
|
+
code: 'session.refreshtoken.invalid',
|
|
3239
3245
|
behaviour: SessionErrorBehaviour.RESTART,
|
|
3240
3246
|
},
|
|
3241
3247
|
{
|
|
3242
|
-
code:
|
|
3248
|
+
code: 'session.badrequest.missingtoken',
|
|
3243
3249
|
behaviour: SessionErrorBehaviour.RESTART,
|
|
3244
3250
|
},
|
|
3245
3251
|
{
|
|
3246
|
-
code:
|
|
3252
|
+
code: 'session.security.nocontext',
|
|
3247
3253
|
behaviour: SessionErrorBehaviour.RESTART,
|
|
3248
3254
|
},
|
|
3249
3255
|
{
|
|
3250
|
-
code:
|
|
3256
|
+
code: 'session.invalidsessionuri',
|
|
3251
3257
|
behaviour: SessionErrorBehaviour.RESTART,
|
|
3252
3258
|
},
|
|
3253
3259
|
{
|
|
3254
|
-
code:
|
|
3260
|
+
code: 'session.notinitialized',
|
|
3255
3261
|
behaviour: SessionErrorBehaviour.RESTART,
|
|
3256
3262
|
},
|
|
3257
3263
|
{
|
|
3258
|
-
code:
|
|
3264
|
+
code: 'session.viewcontext.missing',
|
|
3259
3265
|
behaviour: SessionErrorBehaviour.RESTART,
|
|
3260
3266
|
},
|
|
3261
3267
|
];
|
|
3262
3268
|
}
|
|
3263
3269
|
intercept(request, next) {
|
|
3264
|
-
return next
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
return next.handle(request);
|
|
3275
|
-
}
|
|
3276
|
-
|
|
3270
|
+
return next
|
|
3271
|
+
.handle(request)
|
|
3272
|
+
.pipe(catchError$1((error) => this.handleError(error, request, next)));
|
|
3273
|
+
}
|
|
3274
|
+
handleError(error, request, next) {
|
|
3275
|
+
if (this.isSessionError(error)) {
|
|
3276
|
+
const sessionError = this.getSessionError(error);
|
|
3277
|
+
if (sessionError) {
|
|
3278
|
+
return this.resolveError(sessionError).pipe(switchMap((resolved) => {
|
|
3279
|
+
if (resolved && sessionError.behaviour === SessionErrorBehaviour.REFRESH) {
|
|
3280
|
+
return next.handle(this.updateRequestHeaders(request));
|
|
3281
|
+
}
|
|
3282
|
+
return throwError(() => error);
|
|
3283
|
+
}), catchError$1((resolveError) => {
|
|
3284
|
+
// when the resolveError throws a restart error (in the refreshSession), rethrow the original error
|
|
3285
|
+
if (this.isSessionError(resolveError)) {
|
|
3286
|
+
const resolveSessionError = this.getSessionError(resolveError);
|
|
3287
|
+
if ((resolveSessionError === null || resolveSessionError === void 0 ? void 0 : resolveSessionError.behaviour) === SessionErrorBehaviour.RESTART) {
|
|
3288
|
+
return throwError(() => error);
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
return throwError(() => resolveError);
|
|
3292
|
+
}));
|
|
3277
3293
|
}
|
|
3278
|
-
|
|
3279
|
-
|
|
3294
|
+
}
|
|
3295
|
+
return throwError(() => error);
|
|
3296
|
+
}
|
|
3297
|
+
isSessionError(error) {
|
|
3298
|
+
return error.status === 400 && error.error.code != null;
|
|
3299
|
+
}
|
|
3300
|
+
getSessionError(error) {
|
|
3301
|
+
return this.sessionErrorCodes.find((sessionError) => sessionError.code === error.error.code);
|
|
3280
3302
|
}
|
|
3281
3303
|
resolveError(sessionError) {
|
|
3282
3304
|
if (sessionError.behaviour === SessionErrorBehaviour.RESTART) {
|
|
@@ -3284,6 +3306,14 @@ class SmartErrorCatchingInterceptor {
|
|
|
3284
3306
|
}
|
|
3285
3307
|
return from(this.session.refreshSession());
|
|
3286
3308
|
}
|
|
3309
|
+
updateRequestHeaders(request) {
|
|
3310
|
+
this.session.headerParams.forEach((headerParam) => {
|
|
3311
|
+
request = request.clone({
|
|
3312
|
+
headers: request.headers.set(headerParam.headerName, headerParam.value),
|
|
3313
|
+
});
|
|
3314
|
+
});
|
|
3315
|
+
return request;
|
|
3316
|
+
}
|
|
3287
3317
|
}
|
|
3288
3318
|
SmartErrorCatchingInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: SmartErrorCatchingInterceptor, deps: [{ token: SmartSessionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3289
3319
|
SmartErrorCatchingInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: SmartErrorCatchingInterceptor });
|
|
@@ -4257,6 +4287,7 @@ class UiActionToolbarComponent {
|
|
|
4257
4287
|
}
|
|
4258
4288
|
ngOnDestroy() {
|
|
4259
4289
|
this._destroy$.next();
|
|
4290
|
+
this._destroy$.complete();
|
|
4260
4291
|
}
|
|
4261
4292
|
subscribeToLanguageChange() {
|
|
4262
4293
|
var _a;
|