taxtank-core 0.31.50 → 0.31.52

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.
@@ -1884,7 +1884,7 @@ class Collection {
1884
1884
  return this.items.reduce((prev, current) => (get(prev, path) > get(current, path) ? prev : current));
1885
1885
  }
1886
1886
  reduce(callback, init = 0) {
1887
- return round(this.items.reduce(callback, init), 2);
1887
+ return this.items.reduce(callback, init);
1888
1888
  }
1889
1889
  slice(from, to) {
1890
1890
  this.items.slice(from, to);
@@ -10481,6 +10481,12 @@ class MixpanelService {
10481
10481
  }
10482
10482
  mixpanel.track(event, properties);
10483
10483
  }
10484
+ trackPageView() {
10485
+ if (!this.environment.enableMixpanel) {
10486
+ return;
10487
+ }
10488
+ mixpanel['track_pageview']();
10489
+ }
10484
10490
  }
10485
10491
  MixpanelService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: MixpanelService, deps: [{ token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
10486
10492
  MixpanelService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: MixpanelService, providedIn: 'root' });
@@ -10534,6 +10540,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
10534
10540
  const NAME_TOKEN = 'token';
10535
10541
  const NAME_REFRESH_TOKEN = 'refreshToken';
10536
10542
  class JwtService extends JwtHelperService {
10543
+ constructor() {
10544
+ super(...arguments);
10545
+ this.mpService = inject(MixpanelService);
10546
+ }
10537
10547
  getToken() {
10538
10548
  return localStorage[NAME_TOKEN];
10539
10549
  }
@@ -10543,6 +10553,7 @@ class JwtService extends JwtHelperService {
10543
10553
  saveTokens(tokens) {
10544
10554
  localStorage[NAME_TOKEN] = tokens.token;
10545
10555
  localStorage[NAME_REFRESH_TOKEN] = tokens.refreshToken;
10556
+ this.mpService.identify(this.getUser().id);
10546
10557
  }
10547
10558
  destroyTokens() {
10548
10559
  localStorage.removeItem(NAME_TOKEN);
@@ -10659,6 +10670,10 @@ let RestService$1 = class RestService extends DataService {
10659
10670
  */
10660
10671
  fetch(path = this.apiUrl) {
10661
10672
  this.handleAccessError('get');
10673
+ if (!this.hasRoles()) {
10674
+ this.setCache([], true);
10675
+ return this.cacheSubject.asObservable();
10676
+ }
10662
10677
  // Set cache as empty collection to avoid multiple requests before cache filled
10663
10678
  this.setCache([]);
10664
10679
  return this.http.get(path)
@@ -10846,6 +10861,15 @@ let RestService$1 = class RestService extends DataService {
10846
10861
  });
10847
10862
  });
10848
10863
  }
10864
+ /**
10865
+ * check if user has subscription role to access api
10866
+ */
10867
+ hasRoles() {
10868
+ if (!this.roles.length) {
10869
+ return true;
10870
+ }
10871
+ return !!intersection(JSON.parse(localStorage.getItem('roles')), this.roles).length;
10872
+ }
10849
10873
  /**
10850
10874
  * // @TODO Alex remove
10851
10875
  * Method that call all listeners. Empty by default. Should be redefined by child services if required
@@ -11879,6 +11903,53 @@ var DocumentMessagesEnum;
11879
11903
  DocumentMessagesEnum["DELETED"] = "Document deleted!";
11880
11904
  })(DocumentMessagesEnum || (DocumentMessagesEnum = {}));
11881
11905
 
11906
+ class AuthService {
11907
+ constructor(http, jwtService, mpService, environment) {
11908
+ this.http = http;
11909
+ this.jwtService = jwtService;
11910
+ this.mpService = mpService;
11911
+ this.environment = environment;
11912
+ this.isLoggedInSubject = new BehaviorSubject(!this.jwtService.isTokenExpired());
11913
+ }
11914
+ setAuth(response) {
11915
+ this.jwtService.saveTokens(response);
11916
+ this.isLoggedInSubject.next(true);
11917
+ }
11918
+ login(username, password) {
11919
+ return this.http.post(`${this.environment.apiV2}/login`, { username, password }).pipe(map((response) => {
11920
+ this.setAuth(response);
11921
+ this.mpService.track('login');
11922
+ return response;
11923
+ }), catchError((error) => {
11924
+ this.mpService.track('loginError', { username });
11925
+ return throwError(error);
11926
+ }));
11927
+ }
11928
+ refresh(refreshToken) {
11929
+ return this.http.post(`${this.environment.apiV2}/token/refresh`, { refreshToken }).pipe(map((response) => {
11930
+ this.setAuth(response);
11931
+ return response;
11932
+ }));
11933
+ }
11934
+ logoutFront(url = '/login') {
11935
+ localStorage.clear();
11936
+ this.mpService.track('logout');
11937
+ this.mpService.reset();
11938
+ location.replace(url);
11939
+ }
11940
+ }
11941
+ AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, deps: [{ token: i1.HttpClient }, { token: JwtService }, { token: MixpanelService }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
11942
+ AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, providedIn: 'root' });
11943
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, decorators: [{
11944
+ type: Injectable,
11945
+ args: [{
11946
+ providedIn: 'root'
11947
+ }]
11948
+ }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: JwtService }, { type: MixpanelService }, { type: undefined, decorators: [{
11949
+ type: Inject,
11950
+ args: ['environment']
11951
+ }] }]; } });
11952
+
11882
11953
  const ERROR_EMAIL_PERMISSION = 'Access to email denied. Please provide access to email in facebook.';
11883
11954
  class FacebookService {
11884
11955
  /**
@@ -11912,7 +11983,6 @@ class FacebookService {
11912
11983
  setAuth(response) {
11913
11984
  this.jwtService.saveTokens(response);
11914
11985
  this.isLoggedInSubject.next(true);
11915
- this.mpService.identify(this.jwtService.getUser().id);
11916
11986
  this.mpService.track('loginFB');
11917
11987
  }
11918
11988
  /**
@@ -11962,54 +12032,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
11962
12032
  args: ['environment']
11963
12033
  }] }]; } });
11964
12034
 
11965
- class AuthService {
11966
- constructor(http, jwtService, mpService, environment) {
11967
- this.http = http;
11968
- this.jwtService = jwtService;
11969
- this.mpService = mpService;
11970
- this.environment = environment;
11971
- this.isLoggedInSubject = new BehaviorSubject(!this.jwtService.isTokenExpired());
11972
- }
11973
- setAuth(response) {
11974
- this.jwtService.saveTokens(response);
11975
- this.isLoggedInSubject.next(true);
11976
- }
11977
- login(username, password) {
11978
- return this.http.post(`${this.environment.apiV2}/login`, { username, password }).pipe(map((response) => {
11979
- this.setAuth(response);
11980
- this.mpService.identify(this.jwtService.getUser().id);
11981
- this.mpService.track('login');
11982
- return response;
11983
- }), catchError((error) => {
11984
- this.mpService.track('loginError', { username });
11985
- return throwError(error);
11986
- }));
11987
- }
11988
- refresh(refreshToken) {
11989
- return this.http.post(`${this.environment.apiV2}/token/refresh`, { refreshToken }).pipe(map((response) => {
11990
- this.setAuth(response);
11991
- return response;
11992
- }));
11993
- }
11994
- logoutFront(url = '/login') {
11995
- localStorage.clear();
11996
- this.mpService.track('logout');
11997
- this.mpService.reset();
11998
- location.replace(url);
11999
- }
12000
- }
12001
- AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, deps: [{ token: i1.HttpClient }, { token: JwtService }, { token: MixpanelService }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
12002
- AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, providedIn: 'root' });
12003
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, decorators: [{
12004
- type: Injectable,
12005
- args: [{
12006
- providedIn: 'root'
12007
- }]
12008
- }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: JwtService }, { type: MixpanelService }, { type: undefined, decorators: [{
12009
- type: Inject,
12010
- args: ['environment']
12011
- }] }]; } });
12012
-
12013
12035
  /**
12014
12036
  * Google instance
12015
12037
  * https://developers.google.com/identity/oauth2/web/guides/overview
@@ -12054,7 +12076,6 @@ class GoogleService {
12054
12076
  .subscribe((response) => {
12055
12077
  this.jwtService.saveTokens(response);
12056
12078
  this.isLoggedInSubject.next(true);
12057
- this.mpService.identify(this.jwtService.getUser().id);
12058
12079
  this.mpService.track('loginGoogle');
12059
12080
  this.router.navigate([redirectUrl]);
12060
12081
  }, (error) => {
@@ -15526,14 +15547,19 @@ class UserService extends RestService$1 {
15526
15547
  }
15527
15548
  fetch() {
15528
15549
  return super.fetch(`${this.apiUrl}/current`).pipe(map((users) => {
15550
+ // @TODO vik use separated service to handle global user storage
15529
15551
  localStorage.setItem('userId', this.getCacheFirst().id.toString());
15530
15552
  localStorage.setItem('financialYear', this.getCacheFirst().financialYear.toString());
15531
- this.mpService.identify(this.getCacheFirst().id);
15553
+ localStorage.setItem('roles', JSON.stringify(this.getCacheFirst().roles));
15532
15554
  return users;
15533
15555
  }));
15534
15556
  }
15535
15557
  register(data) {
15536
- return this.http.post(`${this.apiUrl}/registration`, data);
15558
+ return this.http.post(`${this.apiUrl}/registration`, data)
15559
+ .pipe(map((user) => {
15560
+ this.mpService.identify(user['id']);
15561
+ return user;
15562
+ }));
15537
15563
  }
15538
15564
  changePassword(currentPassword, newPassword) {
15539
15565
  return this.http.put(`${this.apiUrl}/password/change`, { currentPassword, newPassword })