@posiwise/common-services 0.1.76 → 0.1.78

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,22 +1,22 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, Inject, isDevMode, inject, NgModule, ViewEncapsulation } from '@angular/core';
3
- import * as i1 from '@angular/router';
3
+ import * as i3 from '@angular/router';
4
4
  import { NavigationEnd } from '@angular/router';
5
- import * as i1$1 from '@posiwise/app-config-service';
5
+ import * as i1 from '@posiwise/app-config-service';
6
6
  import { AppConfigService } from '@posiwise/app-config-service';
7
7
  import { DOCUMENT, CommonModule } from '@angular/common';
8
- import * as i1$3 from '@angular/common/http';
8
+ import * as i1$2 from '@angular/common/http';
9
9
  import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
10
- import { throwError, of, tap, BehaviorSubject, timer } from 'rxjs';
10
+ import { throwError, of, BehaviorSubject, tap, timer } from 'rxjs';
11
11
  import { catchError, switchMap, map, mergeMap, tap as tap$1, distinctUntilChanged } from 'rxjs/operators';
12
12
  import { HelperService } from '@posiwise/helper-service';
13
- import * as i1$2 from 'ngx-toastr';
13
+ import * as i1$1 from 'ngx-toastr';
14
14
  import { getUser, UserActionTypes, SetUser, appReducers } from '@posiwise/app-store';
15
- import * as i1$4 from '@ngrx/effects';
15
+ import * as i1$3 from '@ngrx/effects';
16
16
  import { Actions, createEffect, ofType, EffectsModule } from '@ngrx/effects';
17
17
  import * as i2 from '@ngrx/store';
18
18
  import { StoreModule } from '@ngrx/store';
19
- import { INTEGRATIONS_API_PREFIX, MAIN_API_PREFIX, USER_PATH, USER_IMPERSONATED_TOKEN, USER_IMPERSONATED_PHONEGAP_TOKEN, TOKEN_KEY, TOKEN_HEADER_KEY, NEWSLETTER_CONFIRMATION_PATH, NEWSLETTER_UNSUBSCRIBE_PATH, CAPTCHA_VALIDATION_PATH, SOCIAL_LOGIN_PATH, PERMISSION_NAMES, ADMIN_SUB_MENU_WHITELIST, AB_TEST_ACTIONS, GEO_PATH, PROJECT_PATH, PRODUCT_PATH, CONTACT_US_PATH, INCIDENTS_PATH, INCIDENTS_PATH_ADMIN, NEWSLETTERS_PATH, NEWSLETTER_SUBSCRIPTION_PATH, ADMIN_FAQS_PATH, FAQS_PATH, ORGANIZATIONS_PATH, GLOBAL_SUBSCRIPTION_CONFIGS_PATH, GLOBAL_CONFIGS_PATH, USER_LOGIN_NOTIFICATION, FEEDBACK_QUESTIONS_PATH, USER_FEEDBACKS_PATH, CUSTOMER_SUPPORT_PATH, ADMIN_TAG_PATH, ADMIN_TAG_CATEGORIES_PATH, ADMIN_PATH, QUALIFICATIONS_PATH, SOCKET_TYPE, BRAIN_API_PREFIX } from '@posiwise/common-utilities';
19
+ import { INTEGRATIONS_API_PREFIX, MAIN_API_PREFIX, USER_PATH, TOKEN_HEADER_KEY, NEWSLETTER_CONFIRMATION_PATH, NEWSLETTER_UNSUBSCRIBE_PATH, CAPTCHA_VALIDATION_PATH, SOCIAL_LOGIN_PATH, TOKEN_KEY, PERMISSION_NAMES, ADMIN_SUB_MENU_WHITELIST, AB_TEST_ACTIONS, GEO_PATH, PROJECT_PATH, PRODUCT_PATH, CONTACT_US_PATH, INCIDENTS_PATH, INCIDENTS_PATH_ADMIN, NEWSLETTERS_PATH, NEWSLETTER_SUBSCRIPTION_PATH, ADMIN_FAQS_PATH, FAQS_PATH, ORGANIZATIONS_PATH, GLOBAL_SUBSCRIPTION_CONFIGS_PATH, GLOBAL_CONFIGS_PATH, USER_LOGIN_NOTIFICATION, FEEDBACK_QUESTIONS_PATH, USER_FEEDBACKS_PATH, CUSTOMER_SUPPORT_PATH, ADMIN_TAG_PATH, ADMIN_TAG_CATEGORIES_PATH, ADMIN_PATH, QUALIFICATIONS_PATH, SOCKET_TYPE, BRAIN_API_PREFIX } from '@posiwise/common-utilities';
20
20
  import swal from 'sweetalert2';
21
21
  import cloneDeep from 'lodash/cloneDeep';
22
22
  import pickBy from 'lodash/pickBy';
@@ -212,12 +212,12 @@ class GoogleAnalyticsService {
212
212
  this.subscription.unsubscribe();
213
213
  }
214
214
  }
215
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: GoogleAnalyticsService, deps: [{ token: i1.Router }, { token: ScriptLoaderService }, { token: i1$1.AppConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
215
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: GoogleAnalyticsService, deps: [{ token: i3.Router }, { token: ScriptLoaderService }, { token: i1.AppConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
216
216
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: GoogleAnalyticsService }); }
217
217
  }
218
218
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: GoogleAnalyticsService, decorators: [{
219
219
  type: Injectable
220
- }], ctorParameters: () => [{ type: i1.Router }, { type: ScriptLoaderService }, { type: i1$1.AppConfigService }] });
220
+ }], ctorParameters: () => [{ type: i3.Router }, { type: ScriptLoaderService }, { type: i1.AppConfigService }] });
221
221
 
222
222
  class CustomToastService {
223
223
  constructor(toastr) {
@@ -289,7 +289,7 @@ class CustomToastService {
289
289
  this.error(message);
290
290
  }
291
291
  }
292
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: CustomToastService, deps: [{ token: i1$2.ToastrService }], target: i0.ɵɵFactoryTarget.Injectable }); }
292
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: CustomToastService, deps: [{ token: i1$1.ToastrService }], target: i0.ɵɵFactoryTarget.Injectable }); }
293
293
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: CustomToastService, providedIn: 'root' }); }
294
294
  }
295
295
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: CustomToastService, decorators: [{
@@ -297,7 +297,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
297
297
  args: [{
298
298
  providedIn: 'root'
299
299
  }]
300
- }], ctorParameters: () => [{ type: i1$2.ToastrService }] });
300
+ }], ctorParameters: () => [{ type: i1$1.ToastrService }] });
301
301
 
302
302
  /* eslint-disable @typescript-eslint/no-explicit-any */
303
303
  class BaseHttpService {
@@ -383,12 +383,12 @@ class BaseHttpService {
383
383
  this.toast.showToast(error);
384
384
  }
385
385
  }
386
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: BaseHttpService, deps: [{ token: i1$3.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
386
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: BaseHttpService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
387
387
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: BaseHttpService }); }
388
388
  }
389
389
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: BaseHttpService, decorators: [{
390
390
  type: Injectable
391
- }], ctorParameters: () => [{ type: i1$3.HttpClient }, { type: i0.Injector }] });
391
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
392
392
 
393
393
  class IntegrationsApiHttpService extends BaseHttpService {
394
394
  constructor(http, injector) {
@@ -401,7 +401,7 @@ class IntegrationsApiHttpService extends BaseHttpService {
401
401
  : config?.['links']?.integrations_api;
402
402
  });
403
403
  }
404
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: IntegrationsApiHttpService, deps: [{ token: i1$3.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
404
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: IntegrationsApiHttpService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
405
405
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: IntegrationsApiHttpService, providedIn: 'root' }); }
406
406
  }
407
407
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: IntegrationsApiHttpService, decorators: [{
@@ -409,7 +409,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
409
409
  args: [{
410
410
  providedIn: 'root'
411
411
  }]
412
- }], ctorParameters: () => [{ type: i1$3.HttpClient }, { type: i0.Injector }] });
412
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
413
413
 
414
414
  class LocalStorage {
415
415
  getItem$(key) {
@@ -449,7 +449,7 @@ class MainApiHttpService extends BaseHttpService {
449
449
  this.baseUrl = isDevMode() ? MAIN_API_PREFIX : config?.['links']?.main_api;
450
450
  });
451
451
  }
452
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: MainApiHttpService, deps: [{ token: i1$3.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
452
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: MainApiHttpService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
453
453
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: MainApiHttpService, providedIn: 'root' }); }
454
454
  }
455
455
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: MainApiHttpService, decorators: [{
@@ -457,7 +457,267 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
457
457
  args: [{
458
458
  providedIn: 'root'
459
459
  }]
460
- }], ctorParameters: () => [{ type: i1$3.HttpClient }, { type: i0.Injector }] });
460
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
461
+
462
+ /**
463
+ * Secure Token Storage Service
464
+ *
465
+ * This service provides secure token storage using memory + secure cookies.
466
+ * NO localStorage usage - tokens are stored only in memory and secure cookies.
467
+ *
468
+ * Security Features:
469
+ * - Memory storage (primary) - not persistent across refreshes
470
+ * - Secure cookies (backup) - with SameSite=Strict protection
471
+ * - No localStorage - prevents XSS token theft
472
+ * - Secure flag for HTTPS
473
+ * - CSRF protection via SameSite cookies
474
+ */
475
+ class SecureTokenStorageService {
476
+ constructor(document) {
477
+ this.document = document;
478
+ this.TOKEN_COOKIE_NAME = 'auth_token';
479
+ this.IMPERSONATED_TOKEN_COOKIE_NAME = 'user_impersonated_token';
480
+ this.PHONEGAP_TOKEN_COOKIE_NAME = 'user_impersonated_phonegap_token';
481
+ // In-memory fallback for development or when cookies are not available
482
+ this.memoryStorage = new Map();
483
+ this.tokenSubject = new BehaviorSubject(null);
484
+ this.impersonatedTokenSubject = new BehaviorSubject(null);
485
+ this.phonegapTokenSubject = new BehaviorSubject(null);
486
+ this.initializeTokens();
487
+ }
488
+ /**
489
+ * Store authentication token securely
490
+ */
491
+ storeToken(token) {
492
+ try {
493
+ // Store ONLY in memory and secure cookie - NO localStorage
494
+ this.memoryStorage.set(this.TOKEN_COOKIE_NAME, token);
495
+ this.setSecureCookie(this.TOKEN_COOKIE_NAME, token);
496
+ this.tokenSubject.next(token);
497
+ return of(true);
498
+ }
499
+ catch (error) {
500
+ console.warn('Failed to store token, using memory fallback:', error);
501
+ this.memoryStorage.set(this.TOKEN_COOKIE_NAME, token);
502
+ this.tokenSubject.next(token);
503
+ return of(true);
504
+ }
505
+ }
506
+ /**
507
+ * Store impersonated user token
508
+ */
509
+ storeImpersonatedToken(token) {
510
+ try {
511
+ // Store ONLY in memory and secure cookie - NO localStorage
512
+ this.memoryStorage.set(this.IMPERSONATED_TOKEN_COOKIE_NAME, token);
513
+ this.setSecureCookie(this.IMPERSONATED_TOKEN_COOKIE_NAME, token);
514
+ this.impersonatedTokenSubject.next(token);
515
+ return of(true);
516
+ }
517
+ catch (error) {
518
+ console.warn('Failed to store impersonated token, using memory fallback:', error);
519
+ this.memoryStorage.set(this.IMPERSONATED_TOKEN_COOKIE_NAME, token);
520
+ this.impersonatedTokenSubject.next(token);
521
+ return of(true);
522
+ }
523
+ }
524
+ /**
525
+ * Store phonegap impersonated token
526
+ */
527
+ storePhonegapToken(token) {
528
+ try {
529
+ // Store ONLY in memory and secure cookie - NO localStorage
530
+ this.memoryStorage.set(this.PHONEGAP_TOKEN_COOKIE_NAME, token);
531
+ this.setSecureCookie(this.PHONEGAP_TOKEN_COOKIE_NAME, token);
532
+ this.phonegapTokenSubject.next(token);
533
+ return of(true);
534
+ }
535
+ catch (error) {
536
+ console.warn('Failed to store phonegap token, using memory fallback:', error);
537
+ this.memoryStorage.set(this.PHONEGAP_TOKEN_COOKIE_NAME, token);
538
+ this.phonegapTokenSubject.next(token);
539
+ return of(true);
540
+ }
541
+ }
542
+ /**
543
+ * Get authentication token
544
+ */
545
+ getToken() {
546
+ // Try memory storage first (primary storage)
547
+ const memoryToken = this.memoryStorage.get(this.TOKEN_COOKIE_NAME);
548
+ if (memoryToken) {
549
+ return memoryToken;
550
+ }
551
+ // Try cookie as backup
552
+ const cookieToken = this.getCookieValue(this.TOKEN_COOKIE_NAME);
553
+ if (cookieToken) {
554
+ // Restore to memory storage
555
+ this.memoryStorage.set(this.TOKEN_COOKIE_NAME, cookieToken);
556
+ return cookieToken;
557
+ }
558
+ return null;
559
+ }
560
+ /**
561
+ * Get impersonated token
562
+ */
563
+ getImpersonatedToken() {
564
+ const memoryToken = this.memoryStorage.get(this.IMPERSONATED_TOKEN_COOKIE_NAME);
565
+ if (memoryToken) {
566
+ return memoryToken;
567
+ }
568
+ const cookieToken = this.getCookieValue(this.IMPERSONATED_TOKEN_COOKIE_NAME);
569
+ if (cookieToken) {
570
+ this.memoryStorage.set(this.IMPERSONATED_TOKEN_COOKIE_NAME, cookieToken);
571
+ return cookieToken;
572
+ }
573
+ return null;
574
+ }
575
+ /**
576
+ * Get phonegap token
577
+ */
578
+ getPhonegapToken() {
579
+ const memoryToken = this.memoryStorage.get(this.PHONEGAP_TOKEN_COOKIE_NAME);
580
+ if (memoryToken) {
581
+ return memoryToken;
582
+ }
583
+ const cookieToken = this.getCookieValue(this.PHONEGAP_TOKEN_COOKIE_NAME);
584
+ if (cookieToken) {
585
+ this.memoryStorage.set(this.PHONEGAP_TOKEN_COOKIE_NAME, cookieToken);
586
+ return cookieToken;
587
+ }
588
+ return null;
589
+ }
590
+ /**
591
+ * Get token as Observable
592
+ */
593
+ getToken$() {
594
+ return this.tokenSubject.asObservable();
595
+ }
596
+ /**
597
+ * Get impersonated token as Observable
598
+ */
599
+ getImpersonatedToken$() {
600
+ return this.impersonatedTokenSubject.asObservable();
601
+ }
602
+ /**
603
+ * Get phonegap token as Observable
604
+ */
605
+ getPhonegapToken$() {
606
+ return this.phonegapTokenSubject.asObservable();
607
+ }
608
+ /**
609
+ * Remove all tokens
610
+ */
611
+ clearTokens() {
612
+ try {
613
+ // Clear cookies
614
+ this.deleteCookie(this.TOKEN_COOKIE_NAME);
615
+ this.deleteCookie(this.IMPERSONATED_TOKEN_COOKIE_NAME);
616
+ this.deleteCookie(this.PHONEGAP_TOKEN_COOKIE_NAME);
617
+ }
618
+ catch (error) {
619
+ console.warn('Failed to clear cookies:', error);
620
+ }
621
+ // Clear memory storage
622
+ this.memoryStorage.delete(this.TOKEN_COOKIE_NAME);
623
+ this.memoryStorage.delete(this.IMPERSONATED_TOKEN_COOKIE_NAME);
624
+ this.memoryStorage.delete(this.PHONEGAP_TOKEN_COOKIE_NAME);
625
+ // Update subjects
626
+ this.tokenSubject.next(null);
627
+ this.impersonatedTokenSubject.next(null);
628
+ this.phonegapTokenSubject.next(null);
629
+ return of(true);
630
+ }
631
+ /**
632
+ * Remove specific token
633
+ */
634
+ removeToken() {
635
+ try {
636
+ this.deleteCookie(this.TOKEN_COOKIE_NAME);
637
+ }
638
+ catch (error) {
639
+ console.warn('Failed to remove token:', error);
640
+ }
641
+ this.memoryStorage.delete(this.TOKEN_COOKIE_NAME);
642
+ this.tokenSubject.next(null);
643
+ return of(true);
644
+ }
645
+ /**
646
+ * Remove impersonated tokens
647
+ */
648
+ removeImpersonatedTokens() {
649
+ try {
650
+ this.deleteCookie(this.IMPERSONATED_TOKEN_COOKIE_NAME);
651
+ this.deleteCookie(this.PHONEGAP_TOKEN_COOKIE_NAME);
652
+ }
653
+ catch (error) {
654
+ console.warn('Failed to remove impersonated tokens:', error);
655
+ }
656
+ this.memoryStorage.delete(this.IMPERSONATED_TOKEN_COOKIE_NAME);
657
+ this.memoryStorage.delete(this.PHONEGAP_TOKEN_COOKIE_NAME);
658
+ this.impersonatedTokenSubject.next(null);
659
+ this.phonegapTokenSubject.next(null);
660
+ return of(true);
661
+ }
662
+ /**
663
+ * Set secure cookie
664
+ * Note: HttpOnly cannot be set from client-side JavaScript
665
+ * For maximum security, backend should set httpOnly cookies
666
+ */
667
+ setSecureCookie(name, value) {
668
+ const isSecure = this.document.location.protocol === 'https:';
669
+ // Set cookie with maximum security possible from client-side
670
+ const cookieString = `${name}=${value}; Path=/; ${isSecure ? 'Secure; ' : ''}SameSite=Strict; Max-Age=86400`;
671
+ this.document.cookie = cookieString;
672
+ // Log warning about security limitations
673
+ console.warn('⚠️ SECURITY WARNING: Cookie is not httpOnly. For maximum security, backend should set httpOnly cookies.');
674
+ }
675
+ /**
676
+ * Get cookie value
677
+ */
678
+ getCookieValue(name) {
679
+ const value = `; ${this.document.cookie}`;
680
+ const parts = value.split(`; ${name}=`);
681
+ if (parts.length === 2) {
682
+ return parts.pop()?.split(';').shift() || null;
683
+ }
684
+ return null;
685
+ }
686
+ /**
687
+ * Delete cookie
688
+ */
689
+ deleteCookie(name) {
690
+ this.document.cookie = `${name}=; Path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
691
+ }
692
+ /**
693
+ * Initialize tokens from storage on service startup
694
+ */
695
+ initializeTokens() {
696
+ const token = this.getToken();
697
+ const impersonatedToken = this.getImpersonatedToken();
698
+ const phonegapToken = this.getPhonegapToken();
699
+ if (token) {
700
+ this.tokenSubject.next(token);
701
+ }
702
+ if (impersonatedToken) {
703
+ this.impersonatedTokenSubject.next(impersonatedToken);
704
+ }
705
+ if (phonegapToken) {
706
+ this.phonegapTokenSubject.next(phonegapToken);
707
+ }
708
+ }
709
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: SecureTokenStorageService, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
710
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: SecureTokenStorageService, providedIn: 'root' }); }
711
+ }
712
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: SecureTokenStorageService, decorators: [{
713
+ type: Injectable,
714
+ args: [{
715
+ providedIn: 'root'
716
+ }]
717
+ }], ctorParameters: () => [{ type: Document, decorators: [{
718
+ type: Inject,
719
+ args: [DOCUMENT]
720
+ }] }] });
461
721
 
462
722
  class UserService {
463
723
  constructor(api, store, router) {
@@ -549,7 +809,7 @@ class UserService {
549
809
  postTipsDisregarded(data) {
550
810
  return this.api.post('/users/user_tips', data);
551
811
  }
552
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: UserService, deps: [{ token: MainApiHttpService }, { token: i2.Store }, { token: i1.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
812
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: UserService, deps: [{ token: MainApiHttpService }, { token: i2.Store }, { token: i3.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
553
813
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: UserService, providedIn: 'root' }); }
554
814
  }
555
815
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: UserService, decorators: [{
@@ -557,11 +817,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
557
817
  args: [{
558
818
  providedIn: 'root'
559
819
  }]
560
- }], ctorParameters: () => [{ type: MainApiHttpService }, { type: i2.Store }, { type: i1.Router }] });
820
+ }], ctorParameters: () => [{ type: MainApiHttpService }, { type: i2.Store }, { type: i3.Router }] });
561
821
 
562
822
  class AuthService {
563
- constructor(localStorage, router, http, userService, toastr, appConfigService, integrationsApi, document) {
823
+ constructor(localStorage, secureTokenStorage, router, http, userService, toastr, appConfigService, integrationsApi, document) {
564
824
  this.localStorage = localStorage;
825
+ this.secureTokenStorage = secureTokenStorage;
565
826
  this.router = router;
566
827
  this.http = http;
567
828
  this.userService = userService;
@@ -578,20 +839,20 @@ class AuthService {
578
839
  this.setHeaderKey();
579
840
  }
580
841
  getToken() {
581
- if (this.localStorage.getItem(USER_IMPERSONATED_TOKEN)) {
842
+ if (this.secureTokenStorage.getImpersonatedToken()) {
582
843
  this.isUserPersonated = true;
583
- return this.localStorage.getItem(USER_IMPERSONATED_TOKEN);
844
+ return this.secureTokenStorage.getImpersonatedToken();
584
845
  }
585
- if (this.localStorage.getItem(USER_IMPERSONATED_PHONEGAP_TOKEN)) {
846
+ if (this.secureTokenStorage.getPhonegapToken()) {
586
847
  this.isUserPersonated = true;
587
- return this.localStorage.getItem(USER_IMPERSONATED_PHONEGAP_TOKEN);
848
+ return this.secureTokenStorage.getPhonegapToken();
588
849
  }
589
850
  this.isUserPersonated = false;
590
- return this.localStorage.getItem(TOKEN_KEY);
851
+ return this.secureTokenStorage.getToken();
591
852
  }
592
853
  getImpersonatedToken() {
593
- return (this.localStorage.getItem(USER_IMPERSONATED_TOKEN) ||
594
- this.localStorage.getItem(USER_IMPERSONATED_PHONEGAP_TOKEN));
854
+ return (this.secureTokenStorage.getImpersonatedToken() ||
855
+ this.secureTokenStorage.getPhonegapToken());
595
856
  }
596
857
  setHeaderKey() {
597
858
  // Mobile: app
@@ -680,7 +941,7 @@ class AuthService {
680
941
  return this.http.post('session', formData);
681
942
  }
682
943
  storeToken(token) {
683
- return this.localStorage.setItem$(TOKEN_KEY, token);
944
+ return this.secureTokenStorage.storeToken(token);
684
945
  }
685
946
  storePlatform(plat) {
686
947
  return this.localStorage.setItem$('platform', plat);
@@ -694,10 +955,18 @@ class AuthService {
694
955
  phonegap: true
695
956
  };
696
957
  }
958
+ // Clear all tokens securely
959
+ this.secureTokenStorage.clearTokens().subscribe();
697
960
  return this.http.delete('session', options);
698
961
  }
962
+ /**
963
+ * Clear all authentication tokens
964
+ */
965
+ clearTokens() {
966
+ return this.secureTokenStorage.clearTokens();
967
+ }
699
968
  getToken$() {
700
- return this.localStorage.getItem$(TOKEN_KEY);
969
+ return this.secureTokenStorage.getToken$();
701
970
  }
702
971
  getNewsletterSubscription(token) {
703
972
  return this.http.get(`${NEWSLETTER_CONFIRMATION_PATH}?token=${token}`);
@@ -778,10 +1047,10 @@ class AuthService {
778
1047
  }
779
1048
  return this.http.post('/session/impersonate_user', data).pipe(map(x => {
780
1049
  if (x?.auth_token) {
781
- this.localStorage.setItem$(USER_IMPERSONATED_TOKEN, x.auth_token);
1050
+ this.secureTokenStorage.storeImpersonatedToken(x.auth_token);
782
1051
  }
783
1052
  if (x?.phonegap_token) {
784
- this.localStorage.setItem$(USER_IMPERSONATED_PHONEGAP_TOKEN, x.phonegap_token);
1053
+ this.secureTokenStorage.storePhonegapToken(x.phonegap_token);
785
1054
  }
786
1055
  return x;
787
1056
  }));
@@ -832,12 +1101,12 @@ class AuthService {
832
1101
  }
833
1102
  });
834
1103
  }
835
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AuthService, deps: [{ token: LocalStorage }, { token: i1.Router }, { token: MainApiHttpService }, { token: UserService }, { token: CustomToastService }, { token: i1$1.AppConfigService }, { token: IntegrationsApiHttpService }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
1104
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AuthService, deps: [{ token: LocalStorage }, { token: SecureTokenStorageService }, { token: i3.Router }, { token: MainApiHttpService }, { token: UserService }, { token: CustomToastService }, { token: i1.AppConfigService }, { token: IntegrationsApiHttpService }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
836
1105
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AuthService }); }
837
1106
  }
838
1107
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AuthService, decorators: [{
839
1108
  type: Injectable
840
- }], ctorParameters: () => [{ type: LocalStorage }, { type: i1.Router }, { type: MainApiHttpService }, { type: UserService }, { type: CustomToastService }, { type: i1$1.AppConfigService }, { type: IntegrationsApiHttpService }, { type: Document, decorators: [{
1109
+ }], ctorParameters: () => [{ type: LocalStorage }, { type: SecureTokenStorageService }, { type: i3.Router }, { type: MainApiHttpService }, { type: UserService }, { type: CustomToastService }, { type: i1.AppConfigService }, { type: IntegrationsApiHttpService }, { type: Document, decorators: [{
841
1110
  type: Inject,
842
1111
  args: [DOCUMENT]
843
1112
  }] }] });
@@ -864,7 +1133,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
864
1133
 
865
1134
  class CommonServicesModule {
866
1135
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: CommonServicesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
867
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.11", ngImport: i0, type: CommonServicesModule, imports: [CommonModule, i1$4.EffectsRootModule, i2.StoreRootModule] }); }
1136
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.11", ngImport: i0, type: CommonServicesModule, imports: [CommonModule, i1$3.EffectsRootModule, i2.StoreRootModule] }); }
868
1137
  static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: CommonServicesModule, providers: [AuthService], imports: [CommonModule, EffectsModule.forRoot([UserEffects]), StoreModule.forRoot(appReducers)] }); }
869
1138
  }
870
1139
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: CommonServicesModule, decorators: [{
@@ -1229,7 +1498,7 @@ class AbTestService {
1229
1498
  console.log(typeof service);
1230
1499
  return service ? this.injector.get(service) : this.injector.get(MainApiHttpService); // fallback to Core Microservice
1231
1500
  }
1232
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AbTestService, deps: [{ token: i0.Injector }, { token: i1$3.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
1501
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AbTestService, deps: [{ token: i0.Injector }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
1233
1502
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AbTestService, providedIn: 'root' }); }
1234
1503
  }
1235
1504
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AbTestService, decorators: [{
@@ -1237,7 +1506,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
1237
1506
  args: [{
1238
1507
  providedIn: 'root'
1239
1508
  }]
1240
- }], ctorParameters: () => [{ type: i0.Injector }, { type: i1$3.HttpClient }] });
1509
+ }], ctorParameters: () => [{ type: i0.Injector }, { type: i1$2.HttpClient }] });
1241
1510
 
1242
1511
  class GeoService {
1243
1512
  constructor(api, cookieService) {
@@ -1654,7 +1923,7 @@ class AhoyService {
1654
1923
  this.toast.showToast(error);
1655
1924
  }
1656
1925
  }
1657
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AhoyService, deps: [{ token: i1$3.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
1926
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AhoyService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
1658
1927
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AhoyService, providedIn: 'root' }); }
1659
1928
  }
1660
1929
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: AhoyService, decorators: [{
@@ -1662,7 +1931,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
1662
1931
  args: [{
1663
1932
  providedIn: 'root'
1664
1933
  }]
1665
- }], ctorParameters: () => [{ type: i1$3.HttpClient }, { type: i0.Injector }] });
1934
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
1666
1935
 
1667
1936
  class CommonService {
1668
1937
  constructor(api) {
@@ -2260,7 +2529,7 @@ class WebsocketService {
2260
2529
  this.webSocket$ = this.webSocketSubject.asObservable().pipe(distinctUntilChanged());
2261
2530
  });
2262
2531
  }
2263
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: WebsocketService, deps: [{ token: i1$1.AppConfigService }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable }); }
2532
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: WebsocketService, deps: [{ token: i1.AppConfigService }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable }); }
2264
2533
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: WebsocketService, providedIn: 'root' }); }
2265
2534
  }
2266
2535
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: WebsocketService, decorators: [{
@@ -2268,7 +2537,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
2268
2537
  args: [{
2269
2538
  providedIn: 'root'
2270
2539
  }]
2271
- }], ctorParameters: () => [{ type: i1$1.AppConfigService }, { type: AuthService }] });
2540
+ }], ctorParameters: () => [{ type: i1.AppConfigService }, { type: AuthService }] });
2272
2541
 
2273
2542
  class NotificationService {
2274
2543
  constructor(api, toastrService, socketService) {
@@ -2495,7 +2764,7 @@ class SentryErrorHandler {
2495
2764
  });
2496
2765
  }
2497
2766
  // Check if it's a non-error exception
2498
- const isNonErrorException = event?.exception?.values?.[0]?.value?.startsWith('Non-Error exception captured') ||
2767
+ const isNonErrorException = event?.exception?.values?.[0]?.value?.startsWith('Non-Error exception captured') ??
2499
2768
  hint?.originalException?.message?.startsWith('Non-Error exception captured');
2500
2769
  if (isNonErrorException) {
2501
2770
  // We want to ignore those kinds of errors
@@ -2752,7 +3021,7 @@ class SentryErrorHandler {
2752
3021
  console.error(error, e);
2753
3022
  }
2754
3023
  }
2755
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: SentryErrorHandler, deps: [{ token: i1$1.AppConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3024
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: SentryErrorHandler, deps: [{ token: i1.AppConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
2756
3025
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: SentryErrorHandler, providedIn: 'root' }); }
2757
3026
  }
2758
3027
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: SentryErrorHandler, decorators: [{
@@ -2760,7 +3029,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
2760
3029
  args: [{
2761
3030
  providedIn: 'root'
2762
3031
  }]
2763
- }], ctorParameters: () => [{ type: i1$1.AppConfigService }] });
3032
+ }], ctorParameters: () => [{ type: i1.AppConfigService }] });
2764
3033
 
2765
3034
  class LogoCacheService {
2766
3035
  constructor() {
@@ -2876,7 +3145,7 @@ class BrainApiHttpService extends BaseHttpService {
2876
3145
  this.baseUrl = isDevMode() ? BRAIN_API_PREFIX : config?.['links']['brain_api'] ?? '';
2877
3146
  });
2878
3147
  }
2879
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: BrainApiHttpService, deps: [{ token: i1$3.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
3148
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: BrainApiHttpService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
2880
3149
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: BrainApiHttpService, providedIn: 'root' }); }
2881
3150
  }
2882
3151
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: BrainApiHttpService, decorators: [{
@@ -2884,7 +3153,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
2884
3153
  args: [{
2885
3154
  providedIn: 'root'
2886
3155
  }]
2887
- }], ctorParameters: () => [{ type: i1$3.HttpClient }, { type: i0.Injector }] });
3156
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
2888
3157
 
2889
3158
  class BrainApiService {
2890
3159
  constructor(api) {
@@ -2903,39 +3172,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
2903
3172
  }]
2904
3173
  }], ctorParameters: () => [{ type: BrainApiHttpService }] });
2905
3174
 
2906
- class JQueryService {
2907
- constructor() {
2908
- this.loadPromise = null;
2909
- }
2910
- ensure() {
2911
- if (!this.loadPromise) {
2912
- this.loadPromise = import('jquery')
2913
- .then((mod) => {
2914
- const $ = (mod.default ?? mod);
2915
- // Only assign if not already set
2916
- if (!window.$) {
2917
- window.$ = $;
2918
- }
2919
- if (!window.jQuery) {
2920
- window.jQuery = $;
2921
- }
2922
- return $;
2923
- })
2924
- .catch(err => {
2925
- console.error('Failed to load jQuery:', err);
2926
- throw err;
2927
- });
2928
- }
2929
- return this.loadPromise;
2930
- }
2931
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: JQueryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
2932
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: JQueryService, providedIn: 'root' }); }
2933
- }
2934
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: JQueryService, decorators: [{
2935
- type: Injectable,
2936
- args: [{ providedIn: 'root' }]
2937
- }] });
2938
-
2939
3175
  /*
2940
3176
  * Public API Surface of pw-services
2941
3177
  */
@@ -2944,5 +3180,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
2944
3180
  * Generated bundle index. Do not edit.
2945
3181
  */
2946
3182
 
2947
- export { AbTestService, AhoyService, AuthService, BaseHttpService, BrainApiHttpService, BrainApiService, CommonService, CommonServicesModule, CustomPreloadingStrategy, CustomToastService, DashboardService, DataService, FormHelperService, GeoService, GoogleAnalyticsService, GroupService, HopscotchService, IntegrationsApiHttpService, JQueryService, LinkService, LocalStorage, LogoCacheService, MailBoxService, MainApiHttpService, NgbDateCustomParserFormatter, NotificationService, NumberPickerService, PermissionService, PrimeNgHelper, ProductService, ProfileService, QualificationService, ScriptLoaderService, SentryErrorHandler, SubscriptionService, TagService, TipsService, UserEffects, UserService, ValidationService, WebsocketService, WindowService };
3183
+ export { AbTestService, AhoyService, AuthService, BaseHttpService, BrainApiHttpService, BrainApiService, CommonService, CommonServicesModule, CustomPreloadingStrategy, CustomToastService, DashboardService, DataService, FormHelperService, GeoService, GoogleAnalyticsService, GroupService, HopscotchService, IntegrationsApiHttpService, LinkService, LocalStorage, LogoCacheService, MailBoxService, MainApiHttpService, NgbDateCustomParserFormatter, NotificationService, NumberPickerService, PermissionService, PrimeNgHelper, ProductService, ProfileService, QualificationService, ScriptLoaderService, SecureTokenStorageService, SentryErrorHandler, SubscriptionService, TagService, TipsService, UserEffects, UserService, ValidationService, WebsocketService, WindowService };
2948
3184
  //# sourceMappingURL=posiwise-common-services.mjs.map