taxtank-core 0.31.12 → 0.31.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/services/http/rest/rest-old.service.mjs +7 -5
- package/esm2020/lib/services/http/rest/rest.service.mjs +15 -13
- package/esm2020/lib/services/http/user/user.service.mjs +1 -2
- package/fesm2015/taxtank-core.mjs +98 -94
- package/fesm2015/taxtank-core.mjs.map +1 -1
- package/fesm2020/taxtank-core.mjs +96 -92
- package/fesm2020/taxtank-core.mjs.map +1 -1
- package/lib/services/http/rest/rest-old.service.d.ts +1 -1
- package/lib/services/http/rest/rest.service.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, Inject,
|
|
2
|
+
import { Injectable, Inject, EventEmitter, NgModule } from '@angular/core';
|
|
3
3
|
import * as i1$1 from '@angular/common';
|
|
4
4
|
import { CommonModule, DatePipe } from '@angular/common';
|
|
5
5
|
import * as i1 from '@angular/common/http';
|
|
6
6
|
import { HttpParams, HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
7
7
|
import { map, mergeMap, filter, first as first$1, catchError, skip, take, switchMap, finalize, debounceTime, distinctUntilChanged } from 'rxjs/operators';
|
|
8
|
-
import { ReplaySubject,
|
|
8
|
+
import { ReplaySubject, Subject, Observable, throwError, combineLatest, BehaviorSubject, forkJoin, of, from, merge as merge$1 } from 'rxjs';
|
|
9
9
|
import { plainToClass, Type, Transform, Exclude, Expose, classToPlain } from 'class-transformer';
|
|
10
10
|
import get from 'lodash/get';
|
|
11
11
|
import { __decorate, __awaiter } from 'tslib';
|
|
@@ -27,8 +27,8 @@ import compact from 'lodash/compact';
|
|
|
27
27
|
import concat from 'lodash/concat';
|
|
28
28
|
import cloneDeep$1 from 'lodash/cloneDeep';
|
|
29
29
|
import clone from 'lodash/clone';
|
|
30
|
-
import { JwtHelperService } from '@auth0/angular-jwt';
|
|
31
30
|
import { EventSourcePolyfill } from 'event-source-polyfill/src/eventsource.min.js';
|
|
31
|
+
import { JwtHelperService } from '@auth0/angular-jwt';
|
|
32
32
|
import * as i4 from '@angular/router';
|
|
33
33
|
import { NavigationEnd } from '@angular/router';
|
|
34
34
|
import _ from 'lodash';
|
|
@@ -10210,85 +10210,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
|
|
|
10210
10210
|
}]
|
|
10211
10211
|
}] });
|
|
10212
10212
|
|
|
10213
|
-
const NAME_TOKEN = 'token';
|
|
10214
|
-
const NAME_REFRESH_TOKEN = 'refreshToken';
|
|
10215
|
-
class JwtService extends JwtHelperService {
|
|
10216
|
-
getToken() {
|
|
10217
|
-
return localStorage[NAME_TOKEN];
|
|
10218
|
-
}
|
|
10219
|
-
getRefreshToken() {
|
|
10220
|
-
return localStorage[NAME_REFRESH_TOKEN];
|
|
10221
|
-
}
|
|
10222
|
-
saveTokens(tokens) {
|
|
10223
|
-
localStorage[NAME_TOKEN] = tokens.token;
|
|
10224
|
-
localStorage[NAME_REFRESH_TOKEN] = tokens.refreshToken;
|
|
10225
|
-
}
|
|
10226
|
-
destroyTokens() {
|
|
10227
|
-
localStorage.removeItem(NAME_TOKEN);
|
|
10228
|
-
localStorage.removeItem(NAME_REFRESH_TOKEN);
|
|
10229
|
-
}
|
|
10230
|
-
getUser() {
|
|
10231
|
-
const token = this.decodeToken();
|
|
10232
|
-
if (!token) {
|
|
10233
|
-
return null;
|
|
10234
|
-
}
|
|
10235
|
-
return plainToClass(User, { id: token.id, roles: token.roles, email: token.username, status: token.status });
|
|
10236
|
-
}
|
|
10237
|
-
isMe(userId) {
|
|
10238
|
-
return this.getUser().id === userId;
|
|
10239
|
-
}
|
|
10240
|
-
}
|
|
10241
|
-
JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
10242
|
-
JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, providedIn: 'root' });
|
|
10243
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, decorators: [{
|
|
10244
|
-
type: Injectable,
|
|
10245
|
-
args: [{
|
|
10246
|
-
providedIn: 'root'
|
|
10247
|
-
}]
|
|
10248
|
-
}] });
|
|
10249
|
-
|
|
10250
|
-
class AuthService {
|
|
10251
|
-
constructor(http, jwtService, environment) {
|
|
10252
|
-
this.http = http;
|
|
10253
|
-
this.jwtService = jwtService;
|
|
10254
|
-
this.environment = environment;
|
|
10255
|
-
this.isLoggedInSubject = new BehaviorSubject(!this.jwtService.isTokenExpired());
|
|
10256
|
-
}
|
|
10257
|
-
setAuth(response) {
|
|
10258
|
-
this.jwtService.saveTokens(response);
|
|
10259
|
-
this.isLoggedInSubject.next(true);
|
|
10260
|
-
}
|
|
10261
|
-
login(username, password) {
|
|
10262
|
-
return this.http.post(`${this.environment.apiV2}/login`, { username, password }).pipe(map((response) => {
|
|
10263
|
-
this.setAuth(response);
|
|
10264
|
-
return response;
|
|
10265
|
-
}));
|
|
10266
|
-
}
|
|
10267
|
-
refresh(refreshToken) {
|
|
10268
|
-
return this.http.post(`${this.environment.apiV2}/token/refresh`, { refreshToken }).pipe(map((response) => {
|
|
10269
|
-
this.setAuth(response);
|
|
10270
|
-
return response;
|
|
10271
|
-
}));
|
|
10272
|
-
}
|
|
10273
|
-
logoutFront(url = '/login') {
|
|
10274
|
-
localStorage.clear();
|
|
10275
|
-
location.replace(url);
|
|
10276
|
-
}
|
|
10277
|
-
}
|
|
10278
|
-
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, deps: [{ token: i1.HttpClient }, { token: JwtService }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
10279
|
-
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
10280
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, decorators: [{
|
|
10281
|
-
type: Injectable,
|
|
10282
|
-
args: [{
|
|
10283
|
-
providedIn: 'root'
|
|
10284
|
-
}]
|
|
10285
|
-
}], ctorParameters: function () {
|
|
10286
|
-
return [{ type: i1.HttpClient }, { type: JwtService }, { type: undefined, decorators: [{
|
|
10287
|
-
type: Inject,
|
|
10288
|
-
args: ['environment']
|
|
10289
|
-
}] }];
|
|
10290
|
-
} });
|
|
10291
|
-
|
|
10292
10213
|
/**
|
|
10293
10214
|
* @TODO Alex (TT-1777): replace old logic with the new when all services ready
|
|
10294
10215
|
* @TODO Alex (TT-1777): rename old logic and keep it for custom events
|
|
@@ -10326,6 +10247,43 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
|
|
|
10326
10247
|
}]
|
|
10327
10248
|
}] });
|
|
10328
10249
|
|
|
10250
|
+
const NAME_TOKEN = 'token';
|
|
10251
|
+
const NAME_REFRESH_TOKEN = 'refreshToken';
|
|
10252
|
+
class JwtService extends JwtHelperService {
|
|
10253
|
+
getToken() {
|
|
10254
|
+
return localStorage[NAME_TOKEN];
|
|
10255
|
+
}
|
|
10256
|
+
getRefreshToken() {
|
|
10257
|
+
return localStorage[NAME_REFRESH_TOKEN];
|
|
10258
|
+
}
|
|
10259
|
+
saveTokens(tokens) {
|
|
10260
|
+
localStorage[NAME_TOKEN] = tokens.token;
|
|
10261
|
+
localStorage[NAME_REFRESH_TOKEN] = tokens.refreshToken;
|
|
10262
|
+
}
|
|
10263
|
+
destroyTokens() {
|
|
10264
|
+
localStorage.removeItem(NAME_TOKEN);
|
|
10265
|
+
localStorage.removeItem(NAME_REFRESH_TOKEN);
|
|
10266
|
+
}
|
|
10267
|
+
getUser() {
|
|
10268
|
+
const token = this.decodeToken();
|
|
10269
|
+
if (!token) {
|
|
10270
|
+
return null;
|
|
10271
|
+
}
|
|
10272
|
+
return plainToClass(User, { id: token.id, roles: token.roles, email: token.username, status: token.status });
|
|
10273
|
+
}
|
|
10274
|
+
isMe(userId) {
|
|
10275
|
+
return this.getUser().id === userId;
|
|
10276
|
+
}
|
|
10277
|
+
}
|
|
10278
|
+
JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
10279
|
+
JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, providedIn: 'root' });
|
|
10280
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, decorators: [{
|
|
10281
|
+
type: Injectable,
|
|
10282
|
+
args: [{
|
|
10283
|
+
providedIn: 'root'
|
|
10284
|
+
}]
|
|
10285
|
+
}] });
|
|
10286
|
+
|
|
10329
10287
|
/**
|
|
10330
10288
|
* server sent events service
|
|
10331
10289
|
* https://symfony.com/doc/current/mercure.html
|
|
@@ -10383,7 +10341,6 @@ let RestService$1 = class RestService extends DataService {
|
|
|
10383
10341
|
this.http = http;
|
|
10384
10342
|
this.eventDispatcherService = eventDispatcherService;
|
|
10385
10343
|
this.environment = environment;
|
|
10386
|
-
this.jwtService = inject(JwtService);
|
|
10387
10344
|
/**
|
|
10388
10345
|
* Subject for service cache
|
|
10389
10346
|
*/
|
|
@@ -10395,6 +10352,9 @@ let RestService$1 = class RestService extends DataService {
|
|
|
10395
10352
|
*/
|
|
10396
10353
|
this.disabledMethods = [];
|
|
10397
10354
|
this.roles = [];
|
|
10355
|
+
this.eventDispatcherService.on2(User.getEventName('get')).subscribe((data) => {
|
|
10356
|
+
this.user = data[0];
|
|
10357
|
+
});
|
|
10398
10358
|
// @TODO Alex remove, bad idea to call empty method overrided in child (because it will be called with parent context)
|
|
10399
10359
|
this.listenEvents();
|
|
10400
10360
|
}
|
|
@@ -10423,13 +10383,14 @@ let RestService$1 = class RestService extends DataService {
|
|
|
10423
10383
|
this.setCache([]);
|
|
10424
10384
|
return this.http.get(path)
|
|
10425
10385
|
.pipe(map((response) => this.isApiPlatform ? response['hydra:member'] : toArray(response)), map((response) => {
|
|
10426
|
-
this.
|
|
10386
|
+
const result = response.map((item) => this.createModelInstance(item));
|
|
10387
|
+
this.handleResponse(result, 'get');
|
|
10427
10388
|
return this.cache;
|
|
10428
10389
|
}));
|
|
10429
10390
|
}
|
|
10430
10391
|
get(path = this.apiUrl) {
|
|
10431
10392
|
if (!this.cache) {
|
|
10432
|
-
this.
|
|
10393
|
+
(!this.user || this.user.hasRoles(this.roles)) ? this.fetch(path).pipe(first$1()).subscribe() : this.setCache([], true);
|
|
10433
10394
|
}
|
|
10434
10395
|
return this.cacheSubject.asObservable();
|
|
10435
10396
|
}
|
|
@@ -10524,24 +10485,24 @@ let RestService$1 = class RestService extends DataService {
|
|
|
10524
10485
|
* Update cache with passed items. Add/Update detects automatically, Delete via optional flag
|
|
10525
10486
|
*/
|
|
10526
10487
|
updateCache(items, method) {
|
|
10488
|
+
let cache;
|
|
10527
10489
|
switch (method) {
|
|
10528
10490
|
case 'post':
|
|
10529
|
-
|
|
10491
|
+
cache = this.cache.push(...items);
|
|
10530
10492
|
break;
|
|
10531
10493
|
case 'put':
|
|
10532
10494
|
// @TODO Alex old instance
|
|
10533
10495
|
items.forEach((item) => {
|
|
10534
|
-
|
|
10496
|
+
cache = this.cache.replaceBy('id', item.id, item);
|
|
10535
10497
|
});
|
|
10536
10498
|
break;
|
|
10537
10499
|
case 'delete':
|
|
10538
|
-
|
|
10500
|
+
cache = this.cache.removeBy('id', items.map((item) => item.id));
|
|
10539
10501
|
break;
|
|
10540
10502
|
case 'get':
|
|
10541
|
-
|
|
10503
|
+
cache = this.createCollectionInstance(this.collectionClass, items);
|
|
10542
10504
|
}
|
|
10543
|
-
|
|
10544
|
-
this.cacheSubject.next(this.cache);
|
|
10505
|
+
this.setCache(cache.toArray(), true);
|
|
10545
10506
|
}
|
|
10546
10507
|
/**
|
|
10547
10508
|
* Generate and dispatch rest event
|
|
@@ -11735,6 +11696,48 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
|
|
|
11735
11696
|
}] }];
|
|
11736
11697
|
} });
|
|
11737
11698
|
|
|
11699
|
+
class AuthService {
|
|
11700
|
+
constructor(http, jwtService, environment) {
|
|
11701
|
+
this.http = http;
|
|
11702
|
+
this.jwtService = jwtService;
|
|
11703
|
+
this.environment = environment;
|
|
11704
|
+
this.isLoggedInSubject = new BehaviorSubject(!this.jwtService.isTokenExpired());
|
|
11705
|
+
}
|
|
11706
|
+
setAuth(response) {
|
|
11707
|
+
this.jwtService.saveTokens(response);
|
|
11708
|
+
this.isLoggedInSubject.next(true);
|
|
11709
|
+
}
|
|
11710
|
+
login(username, password) {
|
|
11711
|
+
return this.http.post(`${this.environment.apiV2}/login`, { username, password }).pipe(map((response) => {
|
|
11712
|
+
this.setAuth(response);
|
|
11713
|
+
return response;
|
|
11714
|
+
}));
|
|
11715
|
+
}
|
|
11716
|
+
refresh(refreshToken) {
|
|
11717
|
+
return this.http.post(`${this.environment.apiV2}/token/refresh`, { refreshToken }).pipe(map((response) => {
|
|
11718
|
+
this.setAuth(response);
|
|
11719
|
+
return response;
|
|
11720
|
+
}));
|
|
11721
|
+
}
|
|
11722
|
+
logoutFront(url = '/login') {
|
|
11723
|
+
localStorage.clear();
|
|
11724
|
+
location.replace(url);
|
|
11725
|
+
}
|
|
11726
|
+
}
|
|
11727
|
+
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, deps: [{ token: i1.HttpClient }, { token: JwtService }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
11728
|
+
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
11729
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, decorators: [{
|
|
11730
|
+
type: Injectable,
|
|
11731
|
+
args: [{
|
|
11732
|
+
providedIn: 'root'
|
|
11733
|
+
}]
|
|
11734
|
+
}], ctorParameters: function () {
|
|
11735
|
+
return [{ type: i1.HttpClient }, { type: JwtService }, { type: undefined, decorators: [{
|
|
11736
|
+
type: Inject,
|
|
11737
|
+
args: ['environment']
|
|
11738
|
+
}] }];
|
|
11739
|
+
} });
|
|
11740
|
+
|
|
11738
11741
|
/**
|
|
11739
11742
|
* Google instance
|
|
11740
11743
|
* https://developers.google.com/identity/oauth2/web/guides/overview
|
|
@@ -11872,10 +11875,12 @@ class RestService {
|
|
|
11872
11875
|
this.eventDispatcherService = eventDispatcherService;
|
|
11873
11876
|
this.environment = environment;
|
|
11874
11877
|
this.toastService = toastService;
|
|
11875
|
-
this.jwtService = inject(JwtService);
|
|
11876
11878
|
// subject for service cache
|
|
11877
11879
|
this.cacheSubject = new ReplaySubject(1);
|
|
11878
11880
|
this.roles = [];
|
|
11881
|
+
this.eventDispatcherService.on2(User.getEventName('get')).subscribe((data) => {
|
|
11882
|
+
this.user = data[0];
|
|
11883
|
+
});
|
|
11879
11884
|
this.listenEvents();
|
|
11880
11885
|
}
|
|
11881
11886
|
/**
|
|
@@ -11896,7 +11901,7 @@ class RestService {
|
|
|
11896
11901
|
*/
|
|
11897
11902
|
get() {
|
|
11898
11903
|
if (!this.cache) {
|
|
11899
|
-
this.
|
|
11904
|
+
(!this.user || this.user.hasRoles(this.roles)) ? this.fetch().pipe(first$1()).subscribe() : this.setCache([], true);
|
|
11900
11905
|
}
|
|
11901
11906
|
return this.cacheSubject.asObservable();
|
|
11902
11907
|
}
|
|
@@ -15346,7 +15351,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
|
|
|
15346
15351
|
|
|
15347
15352
|
class UserService extends RestService$1 {
|
|
15348
15353
|
constructor(http, eventDispatcherService, environment) {
|
|
15349
|
-
console.log('userService');
|
|
15350
15354
|
super(http, eventDispatcherService, environment);
|
|
15351
15355
|
this.http = http;
|
|
15352
15356
|
this.eventDispatcherService = eventDispatcherService;
|