@bnsights/bbsf-utilities 1.0.65 → 1.0.67

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.
Files changed (25) hide show
  1. package/README.md +31 -2
  2. package/esm2022/lib/bbsf-utilities.module.mjs +39 -12
  3. package/esm2022/lib/shared/authentication/auth.service.mjs +46 -22
  4. package/esm2022/lib/shared/services/appearance-configuration.service.mjs +4 -4
  5. package/esm2022/lib/shared/services/configuration.service.mjs +15 -9
  6. package/esm2022/lib/shared/services/control-validation.service.mjs +4 -4
  7. package/esm2022/lib/shared/services/environment.service.mjs +8 -4
  8. package/esm2022/lib/shared/services/language.service.mjs +4 -4
  9. package/esm2022/lib/shared/services/master-layout.service.mjs +5 -5
  10. package/esm2022/lib/shared/services/preload.service.mjs +4 -4
  11. package/esm2022/lib/shared/services/request-handler.service.mjs +10 -13
  12. package/esm2022/lib/shared/services/speech-recognition.service.mjs +4 -4
  13. package/esm2022/lib/shared/services/styles-bundle.service.mjs +4 -4
  14. package/esm2022/lib/shared/services/translate.service.mjs +4 -4
  15. package/esm2022/lib/shared/services/utility.service.mjs +4 -4
  16. package/esm2022/lib/shared/services/word-document.service.mjs +4 -4
  17. package/fesm2022/bnsights-bbsf-utilities.mjs +443 -386
  18. package/fesm2022/bnsights-bbsf-utilities.mjs.map +1 -1
  19. package/lib/bbsf-utilities.module.d.ts +2 -2
  20. package/lib/shared/authentication/auth.service.d.ts +5 -1
  21. package/lib/shared/services/configuration.service.d.ts +5 -3
  22. package/lib/shared/services/environment.service.d.ts +1 -0
  23. package/lib/shared/services/request-handler.service.d.ts +3 -2
  24. package/package.json +16 -16
  25. package/bnsights-bbsf-utilities-1.0.65.tgz +0 -0
@@ -1,19 +1,21 @@
1
- import { CommonModule, DOCUMENT } from '@angular/common';
2
- import * as i1$1 from '@angular/common/http';
3
- import { HttpClientModule, HttpHeaders, HttpParams, HttpErrorResponse } from '@angular/common/http';
1
+ import { DOCUMENT, CommonModule } from '@angular/common';
4
2
  import * as i0 from '@angular/core';
5
- import { NgModule, Injectable, inject, Inject } from '@angular/core';
6
- import * as i3 from '@angular/router';
7
- import { RouterModule, Router } from '@angular/router';
8
- import * as i1 from 'ng-block-ui';
9
- import { BlockUIModule, BlockUI } from 'ng-block-ui';
10
- import { provideToastr, ToastrService } from 'ngx-toastr';
11
- import { __decorate } from 'tslib';
12
- import { BehaviorSubject, Subject, throwError, Observable, lastValueFrom } from 'rxjs';
13
- import { JwtHelperService } from '@auth0/angular-jwt';
14
- import * as i4 from 'ngx-cookie-service';
15
- import * as i4$1 from '@ngx-translate/core';
3
+ import { Injectable, Inject, inject, NgModule } from '@angular/core';
4
+ import * as i1$1 from '@angular/router';
5
+ import { RouterModule } from '@angular/router';
6
+ import * as i4 from '@ngx-translate/core';
16
7
  import { TranslateService } from '@ngx-translate/core';
8
+ import * as i1$2 from 'ng-block-ui';
9
+ import { BlockUI, BlockUIModule } from 'ng-block-ui';
10
+ import * as i2 from 'ngx-toastr';
11
+ import { ToastrService, ToastrModule } from 'ngx-toastr';
12
+ import * as i4$1 from 'ngx-cookie-service';
13
+ import { CookieService } from 'ngx-cookie-service';
14
+ import * as i1 from '@angular/common/http';
15
+ import { HttpParams, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
16
+ import { Subject, throwError, Observable, lastValueFrom, BehaviorSubject } from 'rxjs';
17
+ import { JwtHelperService } from '@auth0/angular-jwt';
18
+ import { __decorate } from 'tslib';
17
19
  import { plainToClass } from 'class-transformer';
18
20
  import { takeUntil, tap, map } from 'rxjs/operators';
19
21
  import JSZip from 'jszip';
@@ -31,33 +33,16 @@ import imageToBase64 from 'image-to-base64';
31
33
  import mimeTypes from 'mime-types';
32
34
  import sizeOf from 'image-size';
33
35
 
34
- class BBSFUtilitiesModule {
35
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
36
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, imports: [CommonModule,
37
- RouterModule, i1.BlockUIModule, HttpClientModule] }); }
38
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, providers: [
39
- provideToastr(),
40
- ], imports: [CommonModule,
41
- RouterModule,
42
- BlockUIModule.forRoot(),
43
- HttpClientModule] }); }
36
+ class User {
44
37
  }
45
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, decorators: [{
46
- type: NgModule,
47
- args: [{
48
- declarations: [],
49
- imports: [
50
- CommonModule,
51
- RouterModule,
52
- BlockUIModule.forRoot(),
53
- HttpClientModule
54
- ],
55
- exports: [],
56
- providers: [
57
- provideToastr(),
58
- ]
59
- }]
60
- }] });
38
+
39
+ var AuthenticationModes;
40
+ (function (AuthenticationModes) {
41
+ AuthenticationModes["Forms"] = "Forms";
42
+ AuthenticationModes["UAEPass"] = "UAEPass";
43
+ AuthenticationModes["WindowsAD"] = "WindowsAD";
44
+ AuthenticationModes["AzureAD"] = "AzureAD";
45
+ })(AuthenticationModes || (AuthenticationModes = {}));
61
46
 
62
47
  class AppearanceConfigurationService {
63
48
  constructor(configService) {
@@ -81,263 +66,34 @@ class AppearanceConfigurationService {
81
66
  getLogo() {
82
67
  return this.configService.getConfigurationValue('AnonymousLayout_Logo');
83
68
  }
84
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AppearanceConfigurationService, deps: [{ token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable }); }
85
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AppearanceConfigurationService, providedIn: 'root' }); }
69
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AppearanceConfigurationService, deps: [{ token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable }); }
70
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AppearanceConfigurationService, providedIn: 'root' }); }
86
71
  }
87
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AppearanceConfigurationService, decorators: [{
72
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AppearanceConfigurationService, decorators: [{
88
73
  type: Injectable,
89
74
  args: [{
90
75
  providedIn: 'root'
91
76
  }]
92
77
  }], ctorParameters: () => [{ type: ConfigurationService }] });
93
78
 
94
- class User {
95
- }
96
-
97
- var AuthenticationModes;
98
- (function (AuthenticationModes) {
99
- AuthenticationModes["Forms"] = "Forms";
100
- AuthenticationModes["UAEPass"] = "UAEPass";
101
- AuthenticationModes["WindowsAD"] = "WindowsAD";
102
- AuthenticationModes["AzureAD"] = "AzureAD";
103
- })(AuthenticationModes || (AuthenticationModes = {}));
104
-
105
- const TOKEN_KEY = 'access_token';
106
- class AuthService {
107
- static { this.user = null; }
108
- static { this.UserClaims = null; }
109
- //refresh
110
- static { this.timers = []; }
111
- static { this.seconds = 0; }
112
- constructor(injector, http, environmentService, translateService, router, cookieService, utilityService) {
113
- this.injector = injector;
114
- this.http = http;
115
- this.environmentService = environmentService;
116
- this.translateService = translateService;
117
- this.router = router;
118
- this.cookieService = cookieService;
119
- this.utilityService = utilityService;
120
- this.redirectUrl = '';
121
- this.jwtHelper = new JwtHelperService();
122
- this.isAuthenticatedSubject = new BehaviorSubject(this.hasToken());
123
- this.isAuthenticate$ = this.isAuthenticatedSubject.asObservable();
124
- this.user = this.getUserManager();
125
- }
126
- hasToken() {
127
- const token = this.cookieService.get(TOKEN_KEY);
128
- return token && !this.jwtHelper.isTokenExpired(token);
129
- }
130
- getUserManager() {
131
- const token = this.cookieService.get(TOKEN_KEY);
132
- if (token) {
133
- if (!this.jwtHelper.isTokenExpired(token))
134
- this.handleAccessTokenWithoutLanguage(token);
135
- else
136
- this.cookieService.delete(TOKEN_KEY, '/');
137
- }
138
- else {
139
- AuthService.timers.map(t => clearInterval(t));
140
- AuthService.timers = [];
141
- AuthService.user = null;
142
- this.user = null;
143
- }
144
- return AuthService.user;
145
- }
146
- getUser() {
147
- this.user = AuthService.user;
148
- }
149
- storUser(User) {
150
- AuthService.user = this.user = this.user;
151
- }
152
- getCurrentUser() {
153
- return AuthService.user;
154
- }
155
- isAuthenticated() {
156
- return AuthService.user != null && !this.jwtHelper.isTokenExpired(AuthService.user.access_token);
157
- }
158
- isUserInRole(allowedPermission) {
159
- let selectedPermissionSetID = Number.parseInt(AuthService.user.profile['selectedpermissionsetid']);
160
- return allowedPermission.includes(selectedPermissionSetID);
161
- }
162
- authorizationHeaderValue() {
163
- return AuthService.user
164
- ? `${AuthService.user.token_type} ${AuthService.user.access_token}`
165
- : '';
166
- }
167
- name() {
168
- return AuthService.user != null ? AuthService.user.profile.given_name : '';
169
- }
170
- setUrl(url) {
171
- localStorage.setItem('redirectUrl', url);
172
- }
173
- getUrl() {
174
- return localStorage.getItem('redirectUrl') ?? "/";
175
- }
176
- signOut() {
177
- let isAuthenticated = this.isAuthenticated();
178
- this.cookieService.delete(TOKEN_KEY, '/');
179
- AuthService.timers.map(t => clearInterval(t));
180
- AuthService.timers = [];
181
- AuthService.user = null;
182
- this.user = null;
183
- localStorage.removeItem("redirectUrl");
184
- if (isAuthenticated) {
185
- this.logout().subscribe(res => {
186
- if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
187
- this.logoutFromUAEPass();
188
- else
189
- this.router.navigate(['/Admin/account/login']);
190
- });
191
- }
192
- else {
193
- if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
194
- this.logoutFromUAEPass();
195
- else
196
- this.router.navigate(['/Admin/account/login']);
197
- }
198
- }
199
- logout() {
200
- const httpOptions = {
201
- headers: new HttpHeaders({
202
- 'Content-Type': 'application/json',
203
- }),
204
- };
205
- let ApiUrl = '/Account/';
206
- return this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'Logout', httpOptions);
207
- }
208
- clearUserSessionClaims() {
209
- const httpOptions = {
210
- headers: new HttpHeaders({
211
- 'Content-Type': 'application/json',
212
- }),
213
- };
214
- let ApiUrl = '/api/Home/';
215
- return this.http.get(this.environmentService.getBaseUrl() + ApiUrl + 'ClearCurrentUserSession', httpOptions);
216
- }
217
- async handleAccessToken(response) {
218
- this.cookieService.delete(TOKEN_KEY, '/');
219
- const token = response;
220
- AuthService.user = null;
221
- AuthService.user = new User();
222
- AuthService.user.token_type = "Bearer";
223
- AuthService.user.access_token = token;
224
- AuthService.user.profile = this.jwtHelper.decodeToken(token);
225
- AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
226
- this.user = AuthService.user;
227
- localStorage.setItem("language", AuthService.user.profile.locale);
228
- this.cookieService.set(TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
229
- this.isAuthenticatedSubject.next(true);
230
- this.setTokenSeconds();
231
- AuthService.timers.push(this.checkRefreshToken());
232
- await this.updateLanguage();
233
- }
234
- handleAccessTokenWithoutLanguage(response) {
235
- this.cookieService.delete(TOKEN_KEY, '/');
236
- const token = response;
237
- AuthService.user = null;
238
- AuthService.user = new User();
239
- AuthService.user.token_type = "Bearer";
240
- AuthService.user.access_token = token;
241
- AuthService.user.profile = this.jwtHelper.decodeToken(token);
242
- AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
243
- this.setTokenSeconds();
244
- this.user = AuthService.user;
245
- localStorage.setItem("language", AuthService.user.profile.locale);
246
- this.cookieService.set(TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
247
- this.isAuthenticatedSubject.next(true);
248
- AuthService.timers.push(this.checkRefreshToken());
249
- }
250
- async updateLanguage() {
251
- if (!localStorage.getItem('language') || localStorage.getItem('language') == this.user.profile.locale)
252
- localStorage.setItem('language', this.user.profile.locale);
253
- if (this.translateService.currentLang != localStorage.getItem('language')) {
254
- this.translateService.resetLang(this.translateService.currentLang);
255
- await this.translateService.reloadLang(localStorage.getItem('language')).subscribe();
256
- }
257
- }
258
- checkRefreshToken() {
259
- let date = new Date();
260
- return setInterval(() => {
261
- if (Math.floor(AuthService.seconds) < 120 && this.isAuthenticated()) {
262
- AuthService.timers.map(t => clearInterval(t));
263
- AuthService.timers = [];
264
- const token = this.cookieService.get(TOKEN_KEY);
265
- if (token) {
266
- this.refresh();
267
- }
268
- }
269
- AuthService.seconds--;
270
- }, 1000);
271
- }
272
- setTokenSeconds() {
273
- let date = new Date();
274
- AuthService.seconds = (AuthService.user.expires_at - date) / 1000;
275
- }
276
- refresh() {
277
- this.cookieService.delete(TOKEN_KEY, '/');
278
- const httpOptions = {
279
- headers: new HttpHeaders({
280
- 'Content-Type': 'application/json',
281
- 'Authorization': this.authorizationHeaderValue(),
282
- }),
283
- };
284
- let ApiUrl = '/api/Home/';
285
- this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'RefreshAccessToken', httpOptions).subscribe((res) => {
286
- this.handleAccessTokenWithoutLanguage(res.val);
287
- });
288
- }
289
- loginWithUAEPass() {
290
- const authEndpoint = `${this.environmentService.getUAEPassBaseUrl()}${this.environmentService.getUAEPassAuthorizationEndPoint()}`;
291
- const queryParams = {
292
- response_type: 'code',
293
- client_id: `${this.environmentService.getUAEPassClientID()}`,
294
- redirect_uri: `${this.environmentService.getBaseUrl()}${this.environmentService.getUAEPassRedirectUrl()}`,
295
- scope: 'urn:uae:digitalid:profile:general urn:uae:digitalid:profile:general:profileType urn:uae:digitalid:profile:general:unifiedId',
296
- state: this.translateService.currentLang,
297
- acr_values: 'urn:safelayer:tws:policies:authentication:level:low',
298
- ui_locales: this.translateService.currentLang,
299
- };
300
- const queryParamsString = Object.entries(queryParams)
301
- .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
302
- .join('&');
303
- const loginUrl = `${authEndpoint}?${queryParamsString}`;
304
- window.location.href = loginUrl;
305
- return;
306
- }
307
- logoutFromUAEPass() {
308
- const logoutEndpoint = `${this.environmentService.getUAEPassBaseUrl()}${this.environmentService.getUAEPassLogoutEndPoint()}`;
309
- const queryParams = {
310
- redirect_uri: `${this.environmentService.getBaseUrl()}`,
311
- };
312
- const queryParamsString = Object.entries(queryParams)
313
- .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
314
- .join('&');
315
- const logoutUrl = `${logoutEndpoint}?${queryParamsString}`;
316
- window.location.href = logoutUrl;
317
- return;
318
- }
319
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AuthService, deps: [{ token: i0.Injector }, { token: i1$1.HttpClient }, { token: EnvironmentService }, { token: BBSFTranslateService }, { token: i3.Router }, { token: i4.CookieService }, { token: UtilityService }], target: i0.ɵɵFactoryTarget.Injectable }); }
320
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AuthService, providedIn: 'root' }); }
321
- }
322
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AuthService, decorators: [{
323
- type: Injectable,
324
- args: [{
325
- providedIn: 'root',
326
- }]
327
- }], ctorParameters: () => [{ type: i0.Injector }, { type: i1$1.HttpClient }, { type: EnvironmentService }, { type: BBSFTranslateService }, { type: i3.Router }, { type: i4.CookieService }, { type: UtilityService }] });
328
-
329
79
  class ConfigurationService {
330
80
  static { this.JsonData = []; }
331
- constructor(httpClient, authService) {
81
+ constructor(httpClient, injector) {
332
82
  this.httpClient = httpClient;
333
- this.authService = authService;
83
+ this.injector = injector;
334
84
  this.httpClient.get("./assets/config/configurations.json")
335
85
  .subscribe(data => {
336
86
  ConfigurationService.JsonData = data;
337
87
  });
338
- this.currentUserProfile = this.authService.getCurrentUser()?.profile;
88
+ }
89
+ get authService() {
90
+ if (!this._authService) {
91
+ this._authService = this.injector.get(AuthService);
92
+ }
93
+ return this._authService;
339
94
  }
340
95
  getConfigurationValue(key) {
96
+ this.currentUserProfile = this.authService.getCurrentUser()?.profile;
341
97
  var selectedKey = ConfigurationService.JsonData[key];
342
98
  if (selectedKey && typeof selectedKey === 'object') {
343
99
  if (selectedKey.OrganizationConfigurations) {
@@ -354,15 +110,15 @@ class ConfigurationService {
354
110
  return selectedKey;
355
111
  }
356
112
  }
357
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ConfigurationService, deps: [{ token: i1$1.HttpClient }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable }); }
358
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ConfigurationService, providedIn: 'root' }); }
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 }); }
114
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ConfigurationService, providedIn: 'root' }); }
359
115
  }
360
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ConfigurationService, decorators: [{
116
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ConfigurationService, decorators: [{
361
117
  type: Injectable,
362
118
  args: [{
363
119
  providedIn: 'root'
364
120
  }]
365
- }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: AuthService }] });
121
+ }], ctorParameters: () => [{ type: i1.HttpClient }, { type: i0.Injector }] });
366
122
 
367
123
  class AreaModel {
368
124
  }
@@ -546,13 +302,13 @@ class ControlValidationService {
546
302
  let control = form.get(controlName);
547
303
  return control;
548
304
  }
549
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ControlValidationService, deps: [{ token: UtilityService }], target: i0.ɵɵFactoryTarget.Injectable }); }
550
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ControlValidationService, providedIn: 'root' }); }
305
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ControlValidationService, deps: [{ token: UtilityService }], target: i0.ɵɵFactoryTarget.Injectable }); }
306
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ControlValidationService, providedIn: 'root' }); }
551
307
  }
552
308
  __decorate([
553
309
  BlockUI()
554
310
  ], ControlValidationService.prototype, "blockUI", void 0);
555
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ControlValidationService, decorators: [{
311
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ControlValidationService, decorators: [{
556
312
  type: Injectable,
557
313
  args: [{
558
314
  providedIn: 'root'
@@ -637,10 +393,14 @@ class EnvironmentService {
637
393
  let mode = environment["BBSF_AllowMultiTenancy"];
638
394
  return mode.toLocaleLowerCase() == 'true';
639
395
  }
640
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: EnvironmentService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
641
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: EnvironmentService, providedIn: 'root' }); }
396
+ getCookieName() {
397
+ let cookieName = environment["BBSF_CookieName"];
398
+ return cookieName;
399
+ }
400
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: EnvironmentService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
401
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: EnvironmentService, providedIn: 'root' }); }
642
402
  }
643
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: EnvironmentService, decorators: [{
403
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: EnvironmentService, decorators: [{
644
404
  type: Injectable,
645
405
  args: [{
646
406
  providedIn: 'root'
@@ -702,31 +462,31 @@ class MasterLayoutService {
702
462
  }
703
463
  updateRole(permissionSetID) {
704
464
  let params = new HttpParams();
705
- params = params.append('UserId', this.authService.user.profile.id);
465
+ params = params.append('UserId', AuthService.user.profile.id);
706
466
  params = params.append('RoleID', permissionSetID);
707
467
  return this.http.post(this.apiUrl + 'SwitchRole', null, null, params);
708
468
  }
709
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: MasterLayoutService, deps: [{ token: i3.Router }, { token: RequestHandlerService }, { token: AuthService }, { token: StylesBundleService }, { token: i4$1.TranslateService }, { token: EnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
710
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: MasterLayoutService, providedIn: 'root' }); }
469
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MasterLayoutService, deps: [{ token: i1$1.Router }, { token: RequestHandlerService }, { token: AuthService }, { token: StylesBundleService }, { token: i4.TranslateService }, { token: EnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
470
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MasterLayoutService, providedIn: 'root' }); }
711
471
  }
712
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: MasterLayoutService, decorators: [{
472
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MasterLayoutService, decorators: [{
713
473
  type: Injectable,
714
474
  args: [{
715
475
  providedIn: 'root',
716
476
  }]
717
- }], ctorParameters: () => [{ type: i3.Router }, { type: RequestHandlerService }, { type: AuthService }, { type: StylesBundleService }, { type: i4$1.TranslateService }, { type: EnvironmentService }] });
477
+ }], ctorParameters: () => [{ type: i1$1.Router }, { type: RequestHandlerService }, { type: AuthService }, { type: StylesBundleService }, { type: i4.TranslateService }, { type: EnvironmentService }] });
718
478
 
719
479
  class RequestHandlerService {
720
- constructor(http, authService, environmentService, utilityService, bbsfTranslateService) {
480
+ constructor(http, authService, environmentService, utilityService, bbsfTranslateService, router) {
721
481
  this.http = http;
722
482
  this.authService = authService;
723
483
  this.environmentService = environmentService;
724
484
  this.utilityService = utilityService;
725
485
  this.bbsfTranslateService = bbsfTranslateService;
486
+ this.router = router;
726
487
  this.requestOptions = new RequestOptionsModel();
727
488
  this.currentLanguage = "";
728
489
  this.onDestroy$ = new Subject();
729
- this.router = inject(Router);
730
490
  //using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
731
491
  this.bbsfTranslateService.onLangChange.subscribe((event) => {
732
492
  if (this.currentLanguage != event.lang) {
@@ -964,15 +724,12 @@ class RequestHandlerService {
964
724
  'Image-Upload': 'true',
965
725
  });
966
726
  }
967
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: RequestHandlerService, deps: [{ token: i1$1.HttpClient }, { token: AuthService }, { token: EnvironmentService }, { token: UtilityService }, { token: BBSFTranslateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
968
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: RequestHandlerService, providedIn: 'root' }); }
727
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RequestHandlerService, deps: [{ token: i1.HttpClient }, { token: AuthService }, { token: EnvironmentService }, { token: UtilityService }, { token: BBSFTranslateService }, { token: i1$1.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
728
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RequestHandlerService }); }
969
729
  }
970
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: RequestHandlerService, decorators: [{
971
- type: Injectable,
972
- args: [{
973
- providedIn: 'root',
974
- }]
975
- }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: AuthService }, { type: EnvironmentService }, { type: UtilityService }, { type: BBSFTranslateService }] });
730
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RequestHandlerService, decorators: [{
731
+ type: Injectable
732
+ }], ctorParameters: () => [{ type: i1.HttpClient }, { type: AuthService }, { type: EnvironmentService }, { type: UtilityService }, { type: BBSFTranslateService }, { type: i1$1.Router }] });
976
733
 
977
734
  class StylesBundleService {
978
735
  constructor(document, translateService) {
@@ -1012,10 +769,10 @@ class StylesBundleService {
1012
769
  style.href = `${styleName}`;
1013
770
  head.appendChild(style);
1014
771
  }
1015
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: StylesBundleService, deps: [{ token: DOCUMENT }, { token: BBSFTranslateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1016
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: StylesBundleService, providedIn: 'root' }); }
772
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: StylesBundleService, deps: [{ token: DOCUMENT }, { token: BBSFTranslateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
773
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: StylesBundleService, providedIn: 'root' }); }
1017
774
  }
1018
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: StylesBundleService, decorators: [{
775
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: StylesBundleService, decorators: [{
1019
776
  type: Injectable,
1020
777
  args: [{
1021
778
  providedIn: 'root'
@@ -1026,10 +783,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImpor
1026
783
  }] }, { type: BBSFTranslateService }] });
1027
784
 
1028
785
  class BBSFTranslateService extends TranslateService {
1029
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFTranslateService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
1030
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFTranslateService, providedIn: 'root' }); }
786
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: BBSFTranslateService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
787
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: BBSFTranslateService, providedIn: 'root' }); }
1031
788
  }
1032
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFTranslateService, decorators: [{
789
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: BBSFTranslateService, decorators: [{
1033
790
  type: Injectable,
1034
791
  args: [{
1035
792
  providedIn: 'root'
@@ -1041,6 +798,87 @@ const TranslationResolverService = () => {
1041
798
  return translateService.getTranslation(translateService.currentLang);
1042
799
  };
1043
800
 
801
+ class UtilityService {
802
+ constructor(translator, environmentService, injector) {
803
+ this.translator = translator;
804
+ this.environmentService = environmentService;
805
+ this.injector = injector;
806
+ this.isCreatedBefore = false;
807
+ }
808
+ getResourceValue(Key) {
809
+ let ResourceValue = this.translator.instant(Key);
810
+ return ResourceValue;
811
+ }
812
+ getCurrentLanguage() {
813
+ let currentLanguage = this.environmentService.getDefaultLanguage();
814
+ let lang = localStorage.getItem('language');
815
+ if (lang)
816
+ currentLanguage = lang;
817
+ else
818
+ localStorage.setItem('language', currentLanguage);
819
+ return currentLanguage;
820
+ }
821
+ isCurrentLanguageEnglish() {
822
+ return this.getCurrentLanguage() == "en";
823
+ }
824
+ isCurrentLanguageArabic() {
825
+ return this.getCurrentLanguage() == "ar";
826
+ }
827
+ notifySuccessMessage(Message, title, time, showHeader = true) {
828
+ let MessageTemplate = this.getResourceValue("SuccessMessage");
829
+ let titleTemplate;
830
+ if (Message) {
831
+ MessageTemplate = Message;
832
+ }
833
+ if (title) {
834
+ titleTemplate = title;
835
+ }
836
+ let toaster = this.injector.get(ToastrService);
837
+ showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
838
+ }
839
+ notifyErrorMessage(Message, title, time, showHeader = true) {
840
+ let MessageTemplate = this.getResourceValue("ErrorMessage");
841
+ let titleTemplate = this.getResourceValue("Error");
842
+ if (Message) {
843
+ MessageTemplate = Message;
844
+ }
845
+ if (title) {
846
+ titleTemplate = title;
847
+ }
848
+ const toaster = this.injector.get(ToastrService);
849
+ showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
850
+ }
851
+ notifyWarningMessage(Message, title, time, showHeader = true) {
852
+ let MessageTemplate = this.getResourceValue("WarningMessage");
853
+ let titleTemplate = this.getResourceValue("Warning");
854
+ if (Message) {
855
+ MessageTemplate = Message;
856
+ }
857
+ if (title) {
858
+ titleTemplate = title;
859
+ }
860
+ const toaster = this.injector.get(ToastrService);
861
+ showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
862
+ }
863
+ startBlockUI() {
864
+ this.blockUI.start();
865
+ }
866
+ stopBlockUI() {
867
+ this.blockUI.stop();
868
+ }
869
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: UtilityService, deps: [{ token: BBSFTranslateService }, { token: EnvironmentService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
870
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: UtilityService, providedIn: 'root' }); }
871
+ }
872
+ __decorate([
873
+ BlockUI()
874
+ ], UtilityService.prototype, "blockUI", void 0);
875
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: UtilityService, decorators: [{
876
+ type: Injectable,
877
+ args: [{
878
+ providedIn: 'root'
879
+ }]
880
+ }], ctorParameters: () => [{ type: BBSFTranslateService }, { type: EnvironmentService }, { type: i0.Injector }], propDecorators: { blockUI: [] } });
881
+
1044
882
  const contentTypesXML = `
1045
883
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1046
884
 
@@ -4585,10 +4423,10 @@ class WordDocumentService {
4585
4423
  var fileBuffer = await generateContainer(model.body, model.header, documentOptions, model.footer);
4586
4424
  return fileBuffer;
4587
4425
  }
4588
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: WordDocumentService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
4589
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: WordDocumentService, providedIn: 'root' }); }
4426
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: WordDocumentService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
4427
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: WordDocumentService, providedIn: 'root' }); }
4590
4428
  }
4591
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: WordDocumentService, decorators: [{
4429
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: WordDocumentService, decorators: [{
4592
4430
  type: Injectable,
4593
4431
  args: [{
4594
4432
  providedIn: 'root',
@@ -4603,10 +4441,10 @@ class LanguageService {
4603
4441
  getLanguages() {
4604
4442
  return this.http.get(this.apiUrl + 'GetAll', null, null);
4605
4443
  }
4606
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: LanguageService, deps: [{ token: RequestHandlerService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4607
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: LanguageService, providedIn: 'root' }); }
4444
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LanguageService, deps: [{ token: RequestHandlerService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4445
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LanguageService, providedIn: 'root' }); }
4608
4446
  }
4609
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: LanguageService, decorators: [{
4447
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LanguageService, decorators: [{
4610
4448
  type: Injectable,
4611
4449
  args: [{
4612
4450
  providedIn: 'root',
@@ -4675,10 +4513,10 @@ class SpeechRecognitionService {
4675
4513
  this.recognition.stop();
4676
4514
  }
4677
4515
  }
4678
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: SpeechRecognitionService, deps: [{ token: i0.NgZone }, { token: UtilityService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4679
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: SpeechRecognitionService, providedIn: 'root' }); }
4516
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SpeechRecognitionService, deps: [{ token: i0.NgZone }, { token: UtilityService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4517
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SpeechRecognitionService, providedIn: 'root' }); }
4680
4518
  }
4681
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: SpeechRecognitionService, decorators: [{
4519
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SpeechRecognitionService, decorators: [{
4682
4520
  type: Injectable,
4683
4521
  args: [{
4684
4522
  providedIn: 'root'
@@ -4726,96 +4564,315 @@ class FileLoaderService {
4726
4564
  console.error('Error preloading translations:', error);
4727
4565
  }
4728
4566
  }
4729
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: FileLoaderService, deps: [{ token: BBSFTranslateService }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
4730
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: FileLoaderService, providedIn: 'root' }); }
4567
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: FileLoaderService, deps: [{ token: BBSFTranslateService }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
4568
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: FileLoaderService, providedIn: 'root' }); }
4731
4569
  }
4732
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: FileLoaderService, decorators: [{
4570
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: FileLoaderService, decorators: [{
4733
4571
  type: Injectable,
4734
4572
  args: [{
4735
4573
  providedIn: 'root',
4736
4574
  }]
4737
- }], ctorParameters: () => [{ type: BBSFTranslateService }, { type: i1$1.HttpClient }] });
4575
+ }], ctorParameters: () => [{ type: BBSFTranslateService }, { type: i1.HttpClient }] });
4738
4576
 
4739
- class UtilityService {
4740
- constructor(translator, environmentService, injector) {
4741
- this.translator = translator;
4742
- this.environmentService = environmentService;
4577
+ class AuthService {
4578
+ static { this.user = null; }
4579
+ get user() {
4580
+ if (!this._user) {
4581
+ this._user = this.getUserManager();
4582
+ }
4583
+ return this._user;
4584
+ }
4585
+ static { this.UserClaims = null; }
4586
+ //refresh
4587
+ static { this.timers = []; }
4588
+ static { this.seconds = 0; }
4589
+ constructor(injector, http, environmentService, translateService, router, cookieService, utilityService) {
4743
4590
  this.injector = injector;
4744
- this.isCreatedBefore = false;
4591
+ this.http = http;
4592
+ this.environmentService = environmentService;
4593
+ this.translateService = translateService;
4594
+ this.router = router;
4595
+ this.cookieService = cookieService;
4596
+ this.utilityService = utilityService;
4597
+ this.redirectUrl = '';
4598
+ this.jwtHelper = new JwtHelperService();
4599
+ this.isAuthenticatedSubject = new BehaviorSubject(this.hasToken());
4600
+ this.isAuthenticate$ = this.isAuthenticatedSubject.asObservable();
4745
4601
  }
4746
- getResourceValue(Key) {
4747
- let ResourceValue = this.translator.instant(Key);
4748
- return ResourceValue;
4602
+ get TOKEN_KEY() {
4603
+ if (!this._TOKEN_KEY) {
4604
+ this._TOKEN_KEY = this.environmentService.getCookieName();
4605
+ }
4606
+ return this._TOKEN_KEY;
4749
4607
  }
4750
- getCurrentLanguage() {
4751
- let currentLanguage = this.environmentService.getDefaultLanguage();
4752
- let lang = localStorage.getItem('language');
4753
- if (lang)
4754
- currentLanguage = lang;
4755
- else
4756
- localStorage.setItem('language', currentLanguage);
4757
- return currentLanguage;
4608
+ hasToken() {
4609
+ const token = this.cookieService.get(this.TOKEN_KEY);
4610
+ return token && !this.jwtHelper.isTokenExpired(token);
4758
4611
  }
4759
- isCurrentLanguageEnglish() {
4760
- return this.getCurrentLanguage() == "en";
4612
+ getUserManager() {
4613
+ const token = this.cookieService.get(this.TOKEN_KEY);
4614
+ if (token) {
4615
+ if (!this.jwtHelper.isTokenExpired(token))
4616
+ this.handleAccessTokenWithoutLanguage(token);
4617
+ else
4618
+ this.cookieService.delete(this.TOKEN_KEY, '/');
4619
+ }
4620
+ else {
4621
+ AuthService.timers.map(t => clearInterval(t));
4622
+ AuthService.timers = [];
4623
+ AuthService.user = null;
4624
+ this._user = null;
4625
+ }
4626
+ return AuthService.user;
4761
4627
  }
4762
- isCurrentLanguageArabic() {
4763
- return this.getCurrentLanguage() == "ar";
4628
+ getUser() {
4629
+ this._user = AuthService.user;
4764
4630
  }
4765
- notifySuccessMessage(Message, title, time, showHeader = true) {
4766
- let MessageTemplate = this.getResourceValue("SuccessMessage");
4767
- let titleTemplate;
4768
- if (Message) {
4769
- MessageTemplate = Message;
4770
- }
4771
- if (title) {
4772
- titleTemplate = title;
4631
+ storUser(User) {
4632
+ AuthService.user = this._user = this.user;
4633
+ }
4634
+ getCurrentUser() {
4635
+ return AuthService.user;
4636
+ }
4637
+ isAuthenticated() {
4638
+ AuthService.user = this.user;
4639
+ return AuthService.user != null && !this.jwtHelper.isTokenExpired(AuthService.user.access_token);
4640
+ }
4641
+ isUserInRole(allowedPermission) {
4642
+ let selectedPermissionSetID = Number.parseInt(AuthService.user.profile['selectedpermissionsetid']);
4643
+ return allowedPermission.includes(selectedPermissionSetID);
4644
+ }
4645
+ isUserPermissionSetsInRoles(allowedPermission) {
4646
+ const permissionSetSIDString = AuthService.user.profile['permissionSetSID'];
4647
+ if (!permissionSetSIDString) {
4648
+ return false;
4773
4649
  }
4774
- let toaster = this.injector.get(ToastrService);
4775
- showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
4650
+ // Split comma-separated string and convert to numbers
4651
+ const userPermissionSets = permissionSetSIDString
4652
+ .split(',')
4653
+ .map(id => Number.parseInt(id.trim()))
4654
+ .filter(id => !isNaN(id)); // Filter out invalid numbers
4655
+ // Check if any user permission set is in the allowed permissions
4656
+ return userPermissionSets.some(permissionSetID => allowedPermission.includes(permissionSetID));
4776
4657
  }
4777
- notifyErrorMessage(Message, title, time, showHeader = true) {
4778
- let MessageTemplate = this.getResourceValue("ErrorMessage");
4779
- let titleTemplate = this.getResourceValue("Error");
4780
- if (Message) {
4781
- MessageTemplate = Message;
4658
+ authorizationHeaderValue() {
4659
+ return AuthService.user
4660
+ ? `${AuthService.user.token_type} ${AuthService.user.access_token}`
4661
+ : '';
4662
+ }
4663
+ name() {
4664
+ return AuthService.user != null ? AuthService.user.profile.given_name : '';
4665
+ }
4666
+ setUrl(url) {
4667
+ localStorage.setItem('redirectUrl', url);
4668
+ }
4669
+ getUrl() {
4670
+ return localStorage.getItem('redirectUrl') ?? "/";
4671
+ }
4672
+ signOut() {
4673
+ let isAuthenticated = this.isAuthenticated();
4674
+ this.cookieService.delete(this.TOKEN_KEY, '/');
4675
+ AuthService.timers.map(t => clearInterval(t));
4676
+ AuthService.timers = [];
4677
+ AuthService.user = null;
4678
+ this._user = null;
4679
+ localStorage.removeItem("redirectUrl");
4680
+ if (isAuthenticated) {
4681
+ this.logout().subscribe(res => {
4682
+ if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
4683
+ this.logoutFromUAEPass();
4684
+ else
4685
+ this.router.navigate(['/Admin/account/login']);
4686
+ });
4782
4687
  }
4783
- if (title) {
4784
- titleTemplate = title;
4688
+ else {
4689
+ if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
4690
+ this.logoutFromUAEPass();
4691
+ else
4692
+ this.router.navigate(['/Admin/account/login']);
4785
4693
  }
4786
- const toaster = this.injector.get(ToastrService);
4787
- showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
4788
4694
  }
4789
- notifyWarningMessage(Message, title, time, showHeader = true) {
4790
- let MessageTemplate = this.getResourceValue("WarningMessage");
4791
- let titleTemplate = this.getResourceValue("Warning");
4792
- if (Message) {
4793
- MessageTemplate = Message;
4794
- }
4795
- if (title) {
4796
- titleTemplate = title;
4695
+ logout() {
4696
+ const httpOptions = {
4697
+ headers: new HttpHeaders({
4698
+ 'Content-Type': 'application/json',
4699
+ }),
4700
+ };
4701
+ let ApiUrl = '/Account/';
4702
+ return this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'Logout', httpOptions);
4703
+ }
4704
+ clearUserSessionClaims() {
4705
+ const httpOptions = {
4706
+ headers: new HttpHeaders({
4707
+ 'Content-Type': 'application/json',
4708
+ }),
4709
+ };
4710
+ let ApiUrl = '/api/Home/';
4711
+ return this.http.get(this.environmentService.getBaseUrl() + ApiUrl + 'ClearCurrentUserSession', httpOptions);
4712
+ }
4713
+ async handleAccessToken(response) {
4714
+ this.cookieService.delete(this.TOKEN_KEY, '/');
4715
+ const token = response;
4716
+ AuthService.user = null;
4717
+ AuthService.user = new User();
4718
+ AuthService.user.token_type = "Bearer";
4719
+ AuthService.user.access_token = token;
4720
+ AuthService.user.profile = this.jwtHelper.decodeToken(token);
4721
+ AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
4722
+ this._user = AuthService.user;
4723
+ localStorage.setItem("language", AuthService.user.profile.locale);
4724
+ this.cookieService.set(this.TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
4725
+ this.isAuthenticatedSubject.next(true);
4726
+ this.setTokenSeconds();
4727
+ AuthService.timers.push(this.checkRefreshToken());
4728
+ await this.updateLanguage();
4729
+ }
4730
+ handleAccessTokenWithoutLanguage(response) {
4731
+ this.cookieService.delete(this.TOKEN_KEY, '/');
4732
+ const token = response;
4733
+ AuthService.user = null;
4734
+ AuthService.user = new User();
4735
+ AuthService.user.token_type = "Bearer";
4736
+ AuthService.user.access_token = token;
4737
+ AuthService.user.profile = this.jwtHelper.decodeToken(token);
4738
+ AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
4739
+ this.setTokenSeconds();
4740
+ this._user = AuthService.user;
4741
+ localStorage.setItem("language", AuthService.user.profile.locale);
4742
+ this.cookieService.set(this.TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
4743
+ this.isAuthenticatedSubject.next(true);
4744
+ AuthService.timers.push(this.checkRefreshToken());
4745
+ }
4746
+ async updateLanguage() {
4747
+ if (!localStorage.getItem('language') || localStorage.getItem('language') == this.user.profile.locale)
4748
+ localStorage.setItem('language', this.user.profile.locale);
4749
+ if (this.translateService.currentLang != localStorage.getItem('language')) {
4750
+ this.translateService.resetLang(this.translateService.currentLang);
4751
+ await this.translateService.reloadLang(localStorage.getItem('language')).subscribe();
4797
4752
  }
4798
- const toaster = this.injector.get(ToastrService);
4799
- showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
4800
4753
  }
4801
- startBlockUI() {
4802
- this.blockUI.start();
4754
+ checkRefreshToken() {
4755
+ let date = new Date();
4756
+ return setInterval(() => {
4757
+ if (Math.floor(AuthService.seconds) < 120 && this.isAuthenticated()) {
4758
+ AuthService.timers.map(t => clearInterval(t));
4759
+ AuthService.timers = [];
4760
+ const token = this.cookieService.get(this.TOKEN_KEY);
4761
+ if (token) {
4762
+ this.refresh();
4763
+ }
4764
+ }
4765
+ AuthService.seconds--;
4766
+ }, 1000);
4803
4767
  }
4804
- stopBlockUI() {
4805
- this.blockUI.stop();
4768
+ setTokenSeconds() {
4769
+ let date = new Date();
4770
+ AuthService.seconds = (AuthService.user.expires_at - date) / 1000;
4806
4771
  }
4807
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: UtilityService, deps: [{ token: BBSFTranslateService }, { token: EnvironmentService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
4808
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: UtilityService, providedIn: 'root' }); }
4772
+ refresh() {
4773
+ this.cookieService.delete(this.TOKEN_KEY, '/');
4774
+ const httpOptions = {
4775
+ headers: new HttpHeaders({
4776
+ 'Content-Type': 'application/json',
4777
+ 'Authorization': this.authorizationHeaderValue(),
4778
+ }),
4779
+ };
4780
+ let ApiUrl = '/api/Home/';
4781
+ this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'RefreshAccessToken', httpOptions).subscribe((res) => {
4782
+ this.handleAccessTokenWithoutLanguage(res.val);
4783
+ });
4784
+ }
4785
+ loginWithUAEPass() {
4786
+ const authEndpoint = `${this.environmentService.getUAEPassBaseUrl()}${this.environmentService.getUAEPassAuthorizationEndPoint()}`;
4787
+ const queryParams = {
4788
+ response_type: 'code',
4789
+ client_id: `${this.environmentService.getUAEPassClientID()}`,
4790
+ redirect_uri: `${this.environmentService.getBaseUrl()}${this.environmentService.getUAEPassRedirectUrl()}`,
4791
+ scope: 'urn:uae:digitalid:profile:general urn:uae:digitalid:profile:general:profileType urn:uae:digitalid:profile:general:unifiedId',
4792
+ state: this.translateService.currentLang,
4793
+ acr_values: 'urn:safelayer:tws:policies:authentication:level:low',
4794
+ ui_locales: this.translateService.currentLang,
4795
+ };
4796
+ const queryParamsString = Object.entries(queryParams)
4797
+ .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
4798
+ .join('&');
4799
+ const loginUrl = `${authEndpoint}?${queryParamsString}`;
4800
+ window.location.href = loginUrl;
4801
+ return;
4802
+ }
4803
+ logoutFromUAEPass() {
4804
+ const logoutEndpoint = `${this.environmentService.getUAEPassBaseUrl()}${this.environmentService.getUAEPassLogoutEndPoint()}`;
4805
+ const queryParams = {
4806
+ redirect_uri: `${this.environmentService.getBaseUrl()}`,
4807
+ };
4808
+ const queryParamsString = Object.entries(queryParams)
4809
+ .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
4810
+ .join('&');
4811
+ const logoutUrl = `${logoutEndpoint}?${queryParamsString}`;
4812
+ window.location.href = logoutUrl;
4813
+ return;
4814
+ }
4815
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AuthService, deps: [{ token: i0.Injector }, { token: i1.HttpClient }, { token: EnvironmentService }, { token: BBSFTranslateService }, { token: i1$1.Router }, { token: i4$1.CookieService }, { token: UtilityService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4816
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AuthService, providedIn: 'root' }); }
4809
4817
  }
4810
- __decorate([
4811
- BlockUI()
4812
- ], UtilityService.prototype, "blockUI", void 0);
4813
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: UtilityService, decorators: [{
4818
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AuthService, decorators: [{
4814
4819
  type: Injectable,
4815
4820
  args: [{
4816
- providedIn: 'root'
4821
+ providedIn: 'root',
4817
4822
  }]
4818
- }], ctorParameters: () => [{ type: BBSFTranslateService }, { type: EnvironmentService }, { type: i0.Injector }], propDecorators: { blockUI: [] } });
4823
+ }], ctorParameters: () => [{ type: i0.Injector }, { type: i1.HttpClient }, { type: EnvironmentService }, { type: BBSFTranslateService }, { type: i1$1.Router }, { type: i4$1.CookieService }, { type: UtilityService }] });
4824
+
4825
+ class BBSFUtilitiesModule {
4826
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: BBSFUtilitiesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
4827
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: BBSFUtilitiesModule, imports: [CommonModule,
4828
+ RouterModule, i1$2.BlockUIModule, i2.ToastrModule] }); }
4829
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: BBSFUtilitiesModule, providers: [
4830
+ UtilityService,
4831
+ EnvironmentService,
4832
+ AuthService,
4833
+ RequestHandlerService,
4834
+ StylesBundleService,
4835
+ TranslateService,
4836
+ BBSFTranslateService,
4837
+ ControlValidationService,
4838
+ MasterLayoutService,
4839
+ ConfigurationService,
4840
+ CookieService,
4841
+ LanguageService,
4842
+ SpeechRecognitionService
4843
+ ], imports: [CommonModule,
4844
+ RouterModule,
4845
+ BlockUIModule.forRoot(),
4846
+ ToastrModule.forRoot()] }); }
4847
+ }
4848
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: BBSFUtilitiesModule, decorators: [{
4849
+ type: NgModule,
4850
+ args: [{
4851
+ declarations: [],
4852
+ imports: [
4853
+ CommonModule,
4854
+ RouterModule,
4855
+ BlockUIModule.forRoot(),
4856
+ ToastrModule.forRoot(),
4857
+ ],
4858
+ exports: [],
4859
+ providers: [
4860
+ UtilityService,
4861
+ EnvironmentService,
4862
+ AuthService,
4863
+ RequestHandlerService,
4864
+ StylesBundleService,
4865
+ TranslateService,
4866
+ BBSFTranslateService,
4867
+ ControlValidationService,
4868
+ MasterLayoutService,
4869
+ ConfigurationService,
4870
+ CookieService,
4871
+ LanguageService,
4872
+ SpeechRecognitionService
4873
+ ]
4874
+ }]
4875
+ }] });
4819
4876
 
4820
4877
  /*
4821
4878
  * Public API Surface of @bnsights/bbsf-utilities