@smartbit4all/ng-client 2.0.10 → 2.0.12

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.
@@ -1,5 +1,5 @@
1
1
  import { Inject, Injectable } from '@angular/core';
2
- import { SmartAuthService } from './smart-authentication.service';
2
+ import { SmartAuthService, } from './smart-authentication.service';
3
3
  import { SmartComponentApiClient } from './smart-component-api-client';
4
4
  import * as i0 from "@angular/core";
5
5
  export class SmartService extends SmartComponentApiClient {
@@ -12,6 +12,9 @@ export class SmartService extends SmartComponentApiClient {
12
12
  ngOnDestroy() {
13
13
  this._ngOnDestroy();
14
14
  }
15
+ ngAfterViewInit() {
16
+ this._ngAfterViewInit();
17
+ }
15
18
  }
16
19
  SmartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: SmartService, deps: [{ token: i0.Injector }, { token: SmartAuthService }, { token: 'pageName' }], target: i0.ɵɵFactoryTarget.Injectable });
17
20
  SmartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: SmartService, providedIn: 'root' });
@@ -27,4 +30,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImpor
27
30
  type: Inject,
28
31
  args: ['pageName']
29
32
  }] }]; } });
30
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnQuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3Byb2plY3RzL3NtYXJ0LW5nLWNsaWVudC9zcmMvbGliL3NtYXJ0LWNsaWVudC9zbWFydC5zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxNQUFNLEVBQUUsVUFBVSxFQUErQixNQUFNLGVBQWUsQ0FBQztBQUNoRixPQUF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XG4gIHByb3ZpZGVkSW46ICdyb290JyxcclxufSlcclxuZXhwb3J0IGFic3RyYWN0IGNsYXNzIFNtYXJ0U2VydmljZTxUPlxyXG4gIGV4dGVuZHMgU21hcnRDb21wb25lbnRBcGlDbGllbnQ8VD5cclxuICBpbXBsZW1lbnRzIE9uSW5pdCwgT25EZXN0cm95LCBBZnRlclZpZXdJbml0XHJcbntcclxuICBjb25zdHJ1Y3RvcihcclxuICAgIGluamVjdDogSW5qZWN0b3IsXHJcbiAgICBASW5qZWN0KFNtYXJ0QXV0aFNlcnZpY2UpIGF1dGg6IFNtYXJ0QXV0aGVudGljYXRpb25TZXJ2aWNlSW50ZXJmYWNlLFxyXG4gICAgQEluamVjdCgncGFnZU5hbWUnKSBwYWdlTmFtZTogc3RyaW5nXHJcbiAgKSB7XHJcbiAgICBzdXBlcihpbmplY3QsIGF1dGgsIHBhZ2VOYW1lKTtcclxuICB9XHJcbiAgbmdPbkluaXQoKTogdm9pZCB7XHJcbiAgICB0aGlzLl9uZ09uSW5pdCgpO1xyXG4gIH1cclxuICBuZ09uRGVzdHJveSgpOiB2b2lkIHtcclxuICAgIHRoaXMuX25nT25EZXN0cm95KCk7XHJcbiAgfVxyXG5cclxuICBuZ0FmdGVyVmlld0luaXQoKTogdm9pZCB7XHJcbiAgICB0aGlzLl9uZ0FmdGVyVmlld0luaXQoKTtcclxuICB9XHJcbn1cclxuIl19
@@ -1,10 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, Injectable, Optional, Inject, PLATFORM_ID, NgModule, SkipSelf, Component, Pipe, CUSTOM_ELEMENTS_SCHEMA, ViewChild, Input, ViewChildren } from '@angular/core';
2
+ import { InjectionToken, Injectable, Optional, Inject, PLATFORM_ID, NgModule, SkipSelf, Component, Pipe, CUSTOM_ELEMENTS_SCHEMA, ViewChild, Input, ViewChildren, ChangeDetectorRef } 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.sessionInfoData = sessionInfo;
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
- let sessionInfo = yield this.apiService
841
- .refreshSession({
842
- refreshToken,
843
- })
844
- .toPromise()
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
- return this.sessionInfoData;
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
@@ -3233,52 +3237,68 @@ class SmartErrorCatchingInterceptor {
3233
3237
  this.session = session;
3234
3238
  this.sessionErrorCodes = [
3235
3239
  {
3236
- code: "session.expired",
3240
+ code: 'session.expired',
3237
3241
  behaviour: SessionErrorBehaviour.REFRESH,
3238
3242
  },
3239
3243
  {
3240
- code: "session.refreshtoken.invalid",
3244
+ code: 'session.refreshtoken.invalid',
3241
3245
  behaviour: SessionErrorBehaviour.RESTART,
3242
3246
  },
3243
3247
  {
3244
- code: "session.badrequest.missingtoken",
3248
+ code: 'session.badrequest.missingtoken',
3245
3249
  behaviour: SessionErrorBehaviour.RESTART,
3246
3250
  },
3247
3251
  {
3248
- code: "session.security.nocontext",
3252
+ code: 'session.security.nocontext',
3249
3253
  behaviour: SessionErrorBehaviour.RESTART,
3250
3254
  },
3251
3255
  {
3252
- code: "session.invalidsessionuri",
3256
+ code: 'session.invalidsessionuri',
3253
3257
  behaviour: SessionErrorBehaviour.RESTART,
3254
3258
  },
3255
3259
  {
3256
- code: "session.notinitialized",
3260
+ code: 'session.notinitialized',
3257
3261
  behaviour: SessionErrorBehaviour.RESTART,
3258
3262
  },
3259
3263
  {
3260
- code: "session.viewcontext.missing",
3264
+ code: 'session.viewcontext.missing',
3261
3265
  behaviour: SessionErrorBehaviour.RESTART,
3262
3266
  },
3263
3267
  ];
3264
3268
  }
3265
3269
  intercept(request, next) {
3266
- return next.handle(request).pipe(catchError$1((error) => {
3267
- if (error.status === 400 && error.error.code) {
3268
- let sessionError = this.sessionErrorCodes.find((sessionError) => sessionError.code === error.error.code);
3269
- if (sessionError) {
3270
- return this.resolveError(sessionError).pipe(switchMap(() => {
3271
- this.session.headerParams.map((headerParam) => {
3272
- request = request.clone({
3273
- headers: request.headers.set(headerParam.headerName, headerParam.value),
3274
- });
3275
- });
3276
- return next.handle(request);
3277
- }));
3278
- }
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
+ }));
3279
3293
  }
3280
- return throwError(error);
3281
- }));
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);
3282
3302
  }
3283
3303
  resolveError(sessionError) {
3284
3304
  if (sessionError.behaviour === SessionErrorBehaviour.RESTART) {
@@ -3286,6 +3306,14 @@ class SmartErrorCatchingInterceptor {
3286
3306
  }
3287
3307
  return from(this.session.refreshSession());
3288
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
+ }
3289
3317
  }
3290
3318
  SmartErrorCatchingInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: SmartErrorCatchingInterceptor, deps: [{ token: SmartSessionService }], target: i0.ɵɵFactoryTarget.Injectable });
3291
3319
  SmartErrorCatchingInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: SmartErrorCatchingInterceptor });
@@ -5970,8 +5998,13 @@ let SmartComponentApiClient = class SmartComponentApiClient {
5970
5998
  this._destroy$.next();
5971
5999
  this._destroy$.complete();
5972
6000
  }
6001
+ _ngAfterViewInit() {
6002
+ this.changeDetector = this.inject.get(ChangeDetectorRef);
6003
+ }
5973
6004
  initComponentByModel() {
6005
+ var _a;
5974
6006
  this.initData();
6007
+ (_a = this.changeDetector) === null || _a === void 0 ? void 0 : _a.detectChanges();
5975
6008
  this.initActions();
5976
6009
  // TODO: layout, valueSet, widgets
5977
6010
  }
@@ -6255,6 +6288,9 @@ class SmartComponent extends SmartComponentApiClient {
6255
6288
  ngOnDestroy() {
6256
6289
  this._ngOnDestroy();
6257
6290
  }
6291
+ ngAfterViewInit() {
6292
+ this._ngAfterViewInit();
6293
+ }
6258
6294
  }
6259
6295
  SmartComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: SmartComponent, deps: [{ token: i0.Injector }, { token: SmartAuthService }, { token: 'pageName' }], target: i0.ɵɵFactoryTarget.Component });
6260
6296
  SmartComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: SmartComponent, selector: "ng-component", usesInheritance: true, ngImport: i0, template: '', isInline: true });
@@ -6283,6 +6319,9 @@ class SmartService extends SmartComponentApiClient {
6283
6319
  ngOnDestroy() {
6284
6320
  this._ngOnDestroy();
6285
6321
  }
6322
+ ngAfterViewInit() {
6323
+ this._ngAfterViewInit();
6324
+ }
6286
6325
  }
6287
6326
  SmartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: SmartService, deps: [{ token: i0.Injector }, { token: SmartAuthService }, { token: 'pageName' }], target: i0.ɵɵFactoryTarget.Injectable });
6288
6327
  SmartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: SmartService, providedIn: 'root' });