@bnsights/bbsf-utilities 1.0.66 → 1.0.68
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/README.md +20 -0
- package/esm2022/lib/shared/authentication/auth.service.mjs +20 -10
- package/esm2022/lib/shared/services/configuration.service.mjs +13 -7
- package/esm2022/lib/shared/services/environment.service.mjs +1 -4
- package/esm2022/lib/shared/services/master-layout.service.mjs +2 -2
- package/esm2022/lib/shared/services/request-handler.service.mjs +39 -45
- package/esm2022/lib/shared/services/utility.service.mjs +1 -1
- package/fesm2022/bnsights-bbsf-utilities.mjs +69 -62
- package/fesm2022/bnsights-bbsf-utilities.mjs.map +1 -1
- package/lib/shared/authentication/auth.service.d.ts +4 -2
- package/lib/shared/services/configuration.service.d.ts +5 -3
- package/lib/shared/services/request-handler.service.d.ts +1 -2
- package/package.json +1 -1
|
@@ -78,16 +78,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
|
|
|
78
78
|
|
|
79
79
|
class ConfigurationService {
|
|
80
80
|
static { this.JsonData = []; }
|
|
81
|
-
constructor(httpClient,
|
|
81
|
+
constructor(httpClient, injector) {
|
|
82
82
|
this.httpClient = httpClient;
|
|
83
|
-
this.
|
|
83
|
+
this.injector = injector;
|
|
84
84
|
this.httpClient.get("./assets/config/configurations.json")
|
|
85
85
|
.subscribe(data => {
|
|
86
86
|
ConfigurationService.JsonData = data;
|
|
87
87
|
});
|
|
88
|
-
|
|
88
|
+
}
|
|
89
|
+
get authService() {
|
|
90
|
+
if (!this._authService) {
|
|
91
|
+
this._authService = this.injector.get(AuthService);
|
|
92
|
+
}
|
|
93
|
+
return this._authService;
|
|
89
94
|
}
|
|
90
95
|
getConfigurationValue(key) {
|
|
96
|
+
this.currentUserProfile = this.authService.getCurrentUser()?.profile;
|
|
91
97
|
var selectedKey = ConfigurationService.JsonData[key];
|
|
92
98
|
if (selectedKey && typeof selectedKey === 'object') {
|
|
93
99
|
if (selectedKey.OrganizationConfigurations) {
|
|
@@ -104,7 +110,7 @@ class ConfigurationService {
|
|
|
104
110
|
return selectedKey;
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ConfigurationService, deps: [{ token: i1.HttpClient }, { token:
|
|
113
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ConfigurationService, deps: [{ token: i1.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
108
114
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ConfigurationService, providedIn: 'root' }); }
|
|
109
115
|
}
|
|
110
116
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ConfigurationService, decorators: [{
|
|
@@ -112,7 +118,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
|
|
|
112
118
|
args: [{
|
|
113
119
|
providedIn: 'root'
|
|
114
120
|
}]
|
|
115
|
-
}], ctorParameters: () => [{ type: i1.HttpClient }, { type:
|
|
121
|
+
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: i0.Injector }] });
|
|
116
122
|
|
|
117
123
|
class AreaModel {
|
|
118
124
|
}
|
|
@@ -389,9 +395,6 @@ class EnvironmentService {
|
|
|
389
395
|
}
|
|
390
396
|
getCookieName() {
|
|
391
397
|
let cookieName = environment["BBSF_CookieName"];
|
|
392
|
-
if (!cookieName || cookieName == '') {
|
|
393
|
-
cookieName = 'access_token';
|
|
394
|
-
}
|
|
395
398
|
return cookieName;
|
|
396
399
|
}
|
|
397
400
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: EnvironmentService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
@@ -459,7 +462,7 @@ class MasterLayoutService {
|
|
|
459
462
|
}
|
|
460
463
|
updateRole(permissionSetID) {
|
|
461
464
|
let params = new HttpParams();
|
|
462
|
-
params = params.append('UserId',
|
|
465
|
+
params = params.append('UserId', AuthService.user.profile.id);
|
|
463
466
|
params = params.append('RoleID', permissionSetID);
|
|
464
467
|
return this.http.post(this.apiUrl + 'SwitchRole', null, null, params);
|
|
465
468
|
}
|
|
@@ -481,7 +484,6 @@ class RequestHandlerService {
|
|
|
481
484
|
this.utilityService = utilityService;
|
|
482
485
|
this.bbsfTranslateService = bbsfTranslateService;
|
|
483
486
|
this.router = router;
|
|
484
|
-
this.requestOptions = new RequestOptionsModel();
|
|
485
487
|
this.currentLanguage = "";
|
|
486
488
|
this.onDestroy$ = new Subject();
|
|
487
489
|
//using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
|
|
@@ -500,23 +502,22 @@ class RequestHandlerService {
|
|
|
500
502
|
if (!this.isOnline()) {
|
|
501
503
|
const errorCode = 504; // Custom error code for internet disconnection
|
|
502
504
|
const errorMessage = 'Internet connection is disconnected.';
|
|
503
|
-
var error = new HttpErrorResponse({ error: { Message: errorMessage }, status:
|
|
505
|
+
var error = new HttpErrorResponse({ error: { Message: errorMessage }, status: errorCode });
|
|
504
506
|
this.handleError(error);
|
|
505
507
|
return;
|
|
506
508
|
}
|
|
507
|
-
|
|
508
|
-
this.requestOptions = requestOptions;
|
|
509
|
+
const currentRequestOptions = requestOptions || new RequestOptionsModel();
|
|
509
510
|
let headers = this.getHeaders();
|
|
510
|
-
if (!
|
|
511
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
511
512
|
this.utilityService.startBlockUI();
|
|
512
513
|
return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
513
|
-
if (!
|
|
514
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
514
515
|
this.utilityService.stopBlockUI();
|
|
515
516
|
}, error => {
|
|
516
|
-
if (!
|
|
517
|
+
if (!currentRequestOptions.disableErrorHandler)
|
|
517
518
|
this.handleError(error);
|
|
518
519
|
}), map((data) => {
|
|
519
|
-
if (
|
|
520
|
+
if (currentRequestOptions.castResponsetoClass)
|
|
520
521
|
return plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
521
522
|
else
|
|
522
523
|
return data;
|
|
@@ -530,19 +531,18 @@ class RequestHandlerService {
|
|
|
530
531
|
this.handleError(error);
|
|
531
532
|
return;
|
|
532
533
|
}
|
|
533
|
-
|
|
534
|
-
this.requestOptions = requestOptions;
|
|
534
|
+
const currentRequestOptions = requestOptions || new RequestOptionsModel();
|
|
535
535
|
let headers = this.getHeaders();
|
|
536
|
-
if (!
|
|
536
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
537
537
|
this.utilityService.startBlockUI();
|
|
538
|
-
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType:
|
|
539
|
-
if (!
|
|
538
|
+
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: currentRequestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
539
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
540
540
|
this.utilityService.stopBlockUI();
|
|
541
541
|
}, error => {
|
|
542
|
-
if (!
|
|
542
|
+
if (!currentRequestOptions.disableErrorHandler)
|
|
543
543
|
this.handleError(error);
|
|
544
544
|
}), map((data) => {
|
|
545
|
-
if (
|
|
545
|
+
if (currentRequestOptions.castResponsetoClass)
|
|
546
546
|
return plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
547
547
|
else
|
|
548
548
|
return data;
|
|
@@ -556,19 +556,18 @@ class RequestHandlerService {
|
|
|
556
556
|
this.handleError(error);
|
|
557
557
|
return;
|
|
558
558
|
}
|
|
559
|
-
|
|
560
|
-
this.requestOptions = requestOptions;
|
|
559
|
+
const currentRequestOptions = requestOptions || new RequestOptionsModel();
|
|
561
560
|
let headers = this.getHeaders();
|
|
562
|
-
if (!
|
|
561
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
563
562
|
this.utilityService.startBlockUI();
|
|
564
563
|
return this.http.delete(this.environmentService.getApiUrl() + Url + `/${deletedId}`, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
565
|
-
if (!
|
|
564
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
566
565
|
this.utilityService.stopBlockUI();
|
|
567
566
|
}, error => {
|
|
568
|
-
if (!
|
|
567
|
+
if (!currentRequestOptions.disableErrorHandler)
|
|
569
568
|
this.handleError(error);
|
|
570
569
|
}), map((data) => {
|
|
571
|
-
if (
|
|
570
|
+
if (currentRequestOptions.castResponsetoClass)
|
|
572
571
|
return plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
573
572
|
else
|
|
574
573
|
return data;
|
|
@@ -582,19 +581,18 @@ class RequestHandlerService {
|
|
|
582
581
|
this.handleError(error);
|
|
583
582
|
return;
|
|
584
583
|
}
|
|
585
|
-
|
|
586
|
-
this.requestOptions = requestOptions;
|
|
584
|
+
const currentRequestOptions = requestOptions || new RequestOptionsModel();
|
|
587
585
|
let headers = this.getHeaders();
|
|
588
|
-
if (!
|
|
586
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
589
587
|
this.utilityService.startBlockUI();
|
|
590
|
-
return this.http.put(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType:
|
|
591
|
-
if (!
|
|
588
|
+
return this.http.put(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: currentRequestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
589
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
592
590
|
this.utilityService.stopBlockUI();
|
|
593
591
|
}, error => {
|
|
594
|
-
if (!
|
|
592
|
+
if (!currentRequestOptions.disableErrorHandler)
|
|
595
593
|
this.handleError(error);
|
|
596
594
|
}), map((data) => {
|
|
597
|
-
if (
|
|
595
|
+
if (currentRequestOptions.castResponsetoClass)
|
|
598
596
|
return plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
599
597
|
else
|
|
600
598
|
return data;
|
|
@@ -608,8 +606,7 @@ class RequestHandlerService {
|
|
|
608
606
|
this.handleError(error);
|
|
609
607
|
return;
|
|
610
608
|
}
|
|
611
|
-
|
|
612
|
-
this.requestOptions = requestOptions;
|
|
609
|
+
const currentRequestOptions = requestOptions || new RequestOptionsModel();
|
|
613
610
|
let headers = new HttpHeaders({
|
|
614
611
|
'Content-Type': 'application/json',
|
|
615
612
|
'Authorization': this.authService.authorizationHeaderValue(),
|
|
@@ -617,16 +614,16 @@ class RequestHandlerService {
|
|
|
617
614
|
this.currentLanguage = localStorage.getItem('language');
|
|
618
615
|
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
619
616
|
headers = headers.set('ignore-cookies', 'true');
|
|
620
|
-
if (!
|
|
617
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
621
618
|
this.utilityService.startBlockUI();
|
|
622
|
-
return this.http.patch(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType:
|
|
623
|
-
if (!
|
|
619
|
+
return this.http.patch(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: currentRequestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
620
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
624
621
|
this.utilityService.stopBlockUI();
|
|
625
622
|
}, error => {
|
|
626
|
-
if (!
|
|
623
|
+
if (!currentRequestOptions.disableErrorHandler)
|
|
627
624
|
this.handleError(error);
|
|
628
625
|
}), map((data) => {
|
|
629
|
-
if (
|
|
626
|
+
if (currentRequestOptions.castResponsetoClass)
|
|
630
627
|
return plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
631
628
|
else
|
|
632
629
|
return data;
|
|
@@ -640,20 +637,19 @@ class RequestHandlerService {
|
|
|
640
637
|
this.handleError(error);
|
|
641
638
|
return;
|
|
642
639
|
}
|
|
643
|
-
|
|
644
|
-
this.requestOptions = requestOptions;
|
|
640
|
+
const currentRequestOptions = requestOptions || new RequestOptionsModel();
|
|
645
641
|
let headers = this.getHeaders();
|
|
646
|
-
if (!
|
|
642
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
647
643
|
this.utilityService.startBlockUI();
|
|
648
|
-
return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params, responseType:
|
|
649
|
-
if (!
|
|
644
|
+
return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params, responseType: currentRequestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
645
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
650
646
|
this.utilityService.stopBlockUI();
|
|
651
647
|
}, error => {
|
|
652
|
-
if (!
|
|
648
|
+
if (!currentRequestOptions.disableErrorHandler)
|
|
653
649
|
this.handleError(error);
|
|
654
650
|
}));
|
|
655
651
|
}
|
|
656
|
-
Upload(Url, model) {
|
|
652
|
+
Upload(Url, model, requestOptions) {
|
|
657
653
|
if (!this.isOnline()) {
|
|
658
654
|
const errorCode = 504; // Custom error code for internet disconnection
|
|
659
655
|
const errorMessage = 'Internet connection is disconnected.';
|
|
@@ -661,12 +657,13 @@ class RequestHandlerService {
|
|
|
661
657
|
this.handleError(error);
|
|
662
658
|
return;
|
|
663
659
|
}
|
|
660
|
+
const currentRequestOptions = requestOptions || new RequestOptionsModel();
|
|
664
661
|
let headers = this.getHeadersUpdated();
|
|
665
662
|
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, reportProgress: true, observe: 'events' }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
666
|
-
if (!
|
|
663
|
+
if (!currentRequestOptions.disableBlockUI)
|
|
667
664
|
this.utilityService.stopBlockUI();
|
|
668
665
|
}, error => {
|
|
669
|
-
if (!
|
|
666
|
+
if (!currentRequestOptions.disableErrorHandler)
|
|
670
667
|
this.handleError(error);
|
|
671
668
|
}));
|
|
672
669
|
}
|
|
@@ -4573,6 +4570,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
|
|
|
4573
4570
|
|
|
4574
4571
|
class AuthService {
|
|
4575
4572
|
static { this.user = null; }
|
|
4573
|
+
get user() {
|
|
4574
|
+
if (!this._user) {
|
|
4575
|
+
this._user = this.getUserManager();
|
|
4576
|
+
}
|
|
4577
|
+
return this._user;
|
|
4578
|
+
}
|
|
4576
4579
|
static { this.UserClaims = null; }
|
|
4577
4580
|
//refresh
|
|
4578
4581
|
static { this.timers = []; }
|
|
@@ -4589,9 +4592,12 @@ class AuthService {
|
|
|
4589
4592
|
this.jwtHelper = new JwtHelperService();
|
|
4590
4593
|
this.isAuthenticatedSubject = new BehaviorSubject(this.hasToken());
|
|
4591
4594
|
this.isAuthenticate$ = this.isAuthenticatedSubject.asObservable();
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
+
}
|
|
4596
|
+
get TOKEN_KEY() {
|
|
4597
|
+
if (!this._TOKEN_KEY) {
|
|
4598
|
+
this._TOKEN_KEY = this.environmentService.getCookieName();
|
|
4599
|
+
}
|
|
4600
|
+
return this._TOKEN_KEY;
|
|
4595
4601
|
}
|
|
4596
4602
|
hasToken() {
|
|
4597
4603
|
const token = this.cookieService.get(this.TOKEN_KEY);
|
|
@@ -4609,20 +4615,21 @@ class AuthService {
|
|
|
4609
4615
|
AuthService.timers.map(t => clearInterval(t));
|
|
4610
4616
|
AuthService.timers = [];
|
|
4611
4617
|
AuthService.user = null;
|
|
4612
|
-
this.
|
|
4618
|
+
this._user = null;
|
|
4613
4619
|
}
|
|
4614
4620
|
return AuthService.user;
|
|
4615
4621
|
}
|
|
4616
4622
|
getUser() {
|
|
4617
|
-
this.
|
|
4623
|
+
this._user = AuthService.user;
|
|
4618
4624
|
}
|
|
4619
4625
|
storUser(User) {
|
|
4620
|
-
AuthService.user = this.
|
|
4626
|
+
AuthService.user = this._user = this.user;
|
|
4621
4627
|
}
|
|
4622
4628
|
getCurrentUser() {
|
|
4623
4629
|
return AuthService.user;
|
|
4624
4630
|
}
|
|
4625
4631
|
isAuthenticated() {
|
|
4632
|
+
AuthService.user = this.user;
|
|
4626
4633
|
return AuthService.user != null && !this.jwtHelper.isTokenExpired(AuthService.user.access_token);
|
|
4627
4634
|
}
|
|
4628
4635
|
isUserInRole(allowedPermission) {
|
|
@@ -4662,7 +4669,7 @@ class AuthService {
|
|
|
4662
4669
|
AuthService.timers.map(t => clearInterval(t));
|
|
4663
4670
|
AuthService.timers = [];
|
|
4664
4671
|
AuthService.user = null;
|
|
4665
|
-
this.
|
|
4672
|
+
this._user = null;
|
|
4666
4673
|
localStorage.removeItem("redirectUrl");
|
|
4667
4674
|
if (isAuthenticated) {
|
|
4668
4675
|
this.logout().subscribe(res => {
|
|
@@ -4706,7 +4713,7 @@ class AuthService {
|
|
|
4706
4713
|
AuthService.user.access_token = token;
|
|
4707
4714
|
AuthService.user.profile = this.jwtHelper.decodeToken(token);
|
|
4708
4715
|
AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
|
|
4709
|
-
this.
|
|
4716
|
+
this._user = AuthService.user;
|
|
4710
4717
|
localStorage.setItem("language", AuthService.user.profile.locale);
|
|
4711
4718
|
this.cookieService.set(this.TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
|
|
4712
4719
|
this.isAuthenticatedSubject.next(true);
|
|
@@ -4724,7 +4731,7 @@ class AuthService {
|
|
|
4724
4731
|
AuthService.user.profile = this.jwtHelper.decodeToken(token);
|
|
4725
4732
|
AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
|
|
4726
4733
|
this.setTokenSeconds();
|
|
4727
|
-
this.
|
|
4734
|
+
this._user = AuthService.user;
|
|
4728
4735
|
localStorage.setItem("language", AuthService.user.profile.locale);
|
|
4729
4736
|
this.cookieService.set(this.TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
|
|
4730
4737
|
this.isAuthenticatedSubject.next(true);
|