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 } 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';
|
|
@@ -10149,83 +10149,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
|
|
|
10149
10149
|
}]
|
|
10150
10150
|
}] });
|
|
10151
10151
|
|
|
10152
|
-
const NAME_TOKEN = 'token';
|
|
10153
|
-
const NAME_REFRESH_TOKEN = 'refreshToken';
|
|
10154
|
-
class JwtService extends JwtHelperService {
|
|
10155
|
-
getToken() {
|
|
10156
|
-
return localStorage[NAME_TOKEN];
|
|
10157
|
-
}
|
|
10158
|
-
getRefreshToken() {
|
|
10159
|
-
return localStorage[NAME_REFRESH_TOKEN];
|
|
10160
|
-
}
|
|
10161
|
-
saveTokens(tokens) {
|
|
10162
|
-
localStorage[NAME_TOKEN] = tokens.token;
|
|
10163
|
-
localStorage[NAME_REFRESH_TOKEN] = tokens.refreshToken;
|
|
10164
|
-
}
|
|
10165
|
-
destroyTokens() {
|
|
10166
|
-
localStorage.removeItem(NAME_TOKEN);
|
|
10167
|
-
localStorage.removeItem(NAME_REFRESH_TOKEN);
|
|
10168
|
-
}
|
|
10169
|
-
getUser() {
|
|
10170
|
-
const token = this.decodeToken();
|
|
10171
|
-
if (!token) {
|
|
10172
|
-
return null;
|
|
10173
|
-
}
|
|
10174
|
-
return plainToClass(User, { id: token.id, roles: token.roles, email: token.username, status: token.status });
|
|
10175
|
-
}
|
|
10176
|
-
isMe(userId) {
|
|
10177
|
-
return this.getUser().id === userId;
|
|
10178
|
-
}
|
|
10179
|
-
}
|
|
10180
|
-
JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
10181
|
-
JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, providedIn: 'root' });
|
|
10182
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, decorators: [{
|
|
10183
|
-
type: Injectable,
|
|
10184
|
-
args: [{
|
|
10185
|
-
providedIn: 'root'
|
|
10186
|
-
}]
|
|
10187
|
-
}] });
|
|
10188
|
-
|
|
10189
|
-
class AuthService {
|
|
10190
|
-
constructor(http, jwtService, environment) {
|
|
10191
|
-
this.http = http;
|
|
10192
|
-
this.jwtService = jwtService;
|
|
10193
|
-
this.environment = environment;
|
|
10194
|
-
this.isLoggedInSubject = new BehaviorSubject(!this.jwtService.isTokenExpired());
|
|
10195
|
-
}
|
|
10196
|
-
setAuth(response) {
|
|
10197
|
-
this.jwtService.saveTokens(response);
|
|
10198
|
-
this.isLoggedInSubject.next(true);
|
|
10199
|
-
}
|
|
10200
|
-
login(username, password) {
|
|
10201
|
-
return this.http.post(`${this.environment.apiV2}/login`, { username, password }).pipe(map((response) => {
|
|
10202
|
-
this.setAuth(response);
|
|
10203
|
-
return response;
|
|
10204
|
-
}));
|
|
10205
|
-
}
|
|
10206
|
-
refresh(refreshToken) {
|
|
10207
|
-
return this.http.post(`${this.environment.apiV2}/token/refresh`, { refreshToken }).pipe(map((response) => {
|
|
10208
|
-
this.setAuth(response);
|
|
10209
|
-
return response;
|
|
10210
|
-
}));
|
|
10211
|
-
}
|
|
10212
|
-
logoutFront(url = '/login') {
|
|
10213
|
-
localStorage.clear();
|
|
10214
|
-
location.replace(url);
|
|
10215
|
-
}
|
|
10216
|
-
}
|
|
10217
|
-
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 });
|
|
10218
|
-
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
10219
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, decorators: [{
|
|
10220
|
-
type: Injectable,
|
|
10221
|
-
args: [{
|
|
10222
|
-
providedIn: 'root'
|
|
10223
|
-
}]
|
|
10224
|
-
}], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: JwtService }, { type: undefined, decorators: [{
|
|
10225
|
-
type: Inject,
|
|
10226
|
-
args: ['environment']
|
|
10227
|
-
}] }]; } });
|
|
10228
|
-
|
|
10229
10152
|
/**
|
|
10230
10153
|
* @TODO Alex (TT-1777): replace old logic with the new when all services ready
|
|
10231
10154
|
* @TODO Alex (TT-1777): rename old logic and keep it for custom events
|
|
@@ -10263,6 +10186,43 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
|
|
|
10263
10186
|
}]
|
|
10264
10187
|
}] });
|
|
10265
10188
|
|
|
10189
|
+
const NAME_TOKEN = 'token';
|
|
10190
|
+
const NAME_REFRESH_TOKEN = 'refreshToken';
|
|
10191
|
+
class JwtService extends JwtHelperService {
|
|
10192
|
+
getToken() {
|
|
10193
|
+
return localStorage[NAME_TOKEN];
|
|
10194
|
+
}
|
|
10195
|
+
getRefreshToken() {
|
|
10196
|
+
return localStorage[NAME_REFRESH_TOKEN];
|
|
10197
|
+
}
|
|
10198
|
+
saveTokens(tokens) {
|
|
10199
|
+
localStorage[NAME_TOKEN] = tokens.token;
|
|
10200
|
+
localStorage[NAME_REFRESH_TOKEN] = tokens.refreshToken;
|
|
10201
|
+
}
|
|
10202
|
+
destroyTokens() {
|
|
10203
|
+
localStorage.removeItem(NAME_TOKEN);
|
|
10204
|
+
localStorage.removeItem(NAME_REFRESH_TOKEN);
|
|
10205
|
+
}
|
|
10206
|
+
getUser() {
|
|
10207
|
+
const token = this.decodeToken();
|
|
10208
|
+
if (!token) {
|
|
10209
|
+
return null;
|
|
10210
|
+
}
|
|
10211
|
+
return plainToClass(User, { id: token.id, roles: token.roles, email: token.username, status: token.status });
|
|
10212
|
+
}
|
|
10213
|
+
isMe(userId) {
|
|
10214
|
+
return this.getUser().id === userId;
|
|
10215
|
+
}
|
|
10216
|
+
}
|
|
10217
|
+
JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
10218
|
+
JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, providedIn: 'root' });
|
|
10219
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: JwtService, decorators: [{
|
|
10220
|
+
type: Injectable,
|
|
10221
|
+
args: [{
|
|
10222
|
+
providedIn: 'root'
|
|
10223
|
+
}]
|
|
10224
|
+
}] });
|
|
10225
|
+
|
|
10266
10226
|
/**
|
|
10267
10227
|
* server sent events service
|
|
10268
10228
|
* https://symfony.com/doc/current/mercure.html
|
|
@@ -10318,7 +10278,6 @@ let RestService$1 = class RestService extends DataService {
|
|
|
10318
10278
|
this.http = http;
|
|
10319
10279
|
this.eventDispatcherService = eventDispatcherService;
|
|
10320
10280
|
this.environment = environment;
|
|
10321
|
-
this.jwtService = inject(JwtService);
|
|
10322
10281
|
/**
|
|
10323
10282
|
* Subject for service cache
|
|
10324
10283
|
*/
|
|
@@ -10330,6 +10289,9 @@ let RestService$1 = class RestService extends DataService {
|
|
|
10330
10289
|
*/
|
|
10331
10290
|
this.disabledMethods = [];
|
|
10332
10291
|
this.roles = [];
|
|
10292
|
+
this.eventDispatcherService.on2(User.getEventName('get')).subscribe((data) => {
|
|
10293
|
+
this.user = data[0];
|
|
10294
|
+
});
|
|
10333
10295
|
// @TODO Alex remove, bad idea to call empty method overrided in child (because it will be called with parent context)
|
|
10334
10296
|
this.listenEvents();
|
|
10335
10297
|
}
|
|
@@ -10358,13 +10320,14 @@ let RestService$1 = class RestService extends DataService {
|
|
|
10358
10320
|
this.setCache([]);
|
|
10359
10321
|
return this.http.get(path)
|
|
10360
10322
|
.pipe(map((response) => this.isApiPlatform ? response['hydra:member'] : toArray(response)), map((response) => {
|
|
10361
|
-
this.
|
|
10323
|
+
const result = response.map((item) => this.createModelInstance(item));
|
|
10324
|
+
this.handleResponse(result, 'get');
|
|
10362
10325
|
return this.cache;
|
|
10363
10326
|
}));
|
|
10364
10327
|
}
|
|
10365
10328
|
get(path = this.apiUrl) {
|
|
10366
10329
|
if (!this.cache) {
|
|
10367
|
-
this.
|
|
10330
|
+
(!this.user || this.user.hasRoles(this.roles)) ? this.fetch(path).pipe(first$1()).subscribe() : this.setCache([], true);
|
|
10368
10331
|
}
|
|
10369
10332
|
return this.cacheSubject.asObservable();
|
|
10370
10333
|
}
|
|
@@ -10459,24 +10422,24 @@ let RestService$1 = class RestService extends DataService {
|
|
|
10459
10422
|
* Update cache with passed items. Add/Update detects automatically, Delete via optional flag
|
|
10460
10423
|
*/
|
|
10461
10424
|
updateCache(items, method) {
|
|
10425
|
+
let cache;
|
|
10462
10426
|
switch (method) {
|
|
10463
10427
|
case 'post':
|
|
10464
|
-
|
|
10428
|
+
cache = this.cache.push(...items);
|
|
10465
10429
|
break;
|
|
10466
10430
|
case 'put':
|
|
10467
10431
|
// @TODO Alex old instance
|
|
10468
10432
|
items.forEach((item) => {
|
|
10469
|
-
|
|
10433
|
+
cache = this.cache.replaceBy('id', item.id, item);
|
|
10470
10434
|
});
|
|
10471
10435
|
break;
|
|
10472
10436
|
case 'delete':
|
|
10473
|
-
|
|
10437
|
+
cache = this.cache.removeBy('id', items.map((item) => item.id));
|
|
10474
10438
|
break;
|
|
10475
10439
|
case 'get':
|
|
10476
|
-
|
|
10440
|
+
cache = this.createCollectionInstance(this.collectionClass, items);
|
|
10477
10441
|
}
|
|
10478
|
-
|
|
10479
|
-
this.cacheSubject.next(this.cache);
|
|
10442
|
+
this.setCache(cache.toArray(), true);
|
|
10480
10443
|
}
|
|
10481
10444
|
/**
|
|
10482
10445
|
* Generate and dispatch rest event
|
|
@@ -11649,6 +11612,46 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
|
|
|
11649
11612
|
args: ['environment']
|
|
11650
11613
|
}] }]; } });
|
|
11651
11614
|
|
|
11615
|
+
class AuthService {
|
|
11616
|
+
constructor(http, jwtService, environment) {
|
|
11617
|
+
this.http = http;
|
|
11618
|
+
this.jwtService = jwtService;
|
|
11619
|
+
this.environment = environment;
|
|
11620
|
+
this.isLoggedInSubject = new BehaviorSubject(!this.jwtService.isTokenExpired());
|
|
11621
|
+
}
|
|
11622
|
+
setAuth(response) {
|
|
11623
|
+
this.jwtService.saveTokens(response);
|
|
11624
|
+
this.isLoggedInSubject.next(true);
|
|
11625
|
+
}
|
|
11626
|
+
login(username, password) {
|
|
11627
|
+
return this.http.post(`${this.environment.apiV2}/login`, { username, password }).pipe(map((response) => {
|
|
11628
|
+
this.setAuth(response);
|
|
11629
|
+
return response;
|
|
11630
|
+
}));
|
|
11631
|
+
}
|
|
11632
|
+
refresh(refreshToken) {
|
|
11633
|
+
return this.http.post(`${this.environment.apiV2}/token/refresh`, { refreshToken }).pipe(map((response) => {
|
|
11634
|
+
this.setAuth(response);
|
|
11635
|
+
return response;
|
|
11636
|
+
}));
|
|
11637
|
+
}
|
|
11638
|
+
logoutFront(url = '/login') {
|
|
11639
|
+
localStorage.clear();
|
|
11640
|
+
location.replace(url);
|
|
11641
|
+
}
|
|
11642
|
+
}
|
|
11643
|
+
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 });
|
|
11644
|
+
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
11645
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: AuthService, decorators: [{
|
|
11646
|
+
type: Injectable,
|
|
11647
|
+
args: [{
|
|
11648
|
+
providedIn: 'root'
|
|
11649
|
+
}]
|
|
11650
|
+
}], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: JwtService }, { type: undefined, decorators: [{
|
|
11651
|
+
type: Inject,
|
|
11652
|
+
args: ['environment']
|
|
11653
|
+
}] }]; } });
|
|
11654
|
+
|
|
11652
11655
|
/**
|
|
11653
11656
|
* Google instance
|
|
11654
11657
|
* https://developers.google.com/identity/oauth2/web/guides/overview
|
|
@@ -11784,10 +11787,12 @@ class RestService {
|
|
|
11784
11787
|
this.eventDispatcherService = eventDispatcherService;
|
|
11785
11788
|
this.environment = environment;
|
|
11786
11789
|
this.toastService = toastService;
|
|
11787
|
-
this.jwtService = inject(JwtService);
|
|
11788
11790
|
// subject for service cache
|
|
11789
11791
|
this.cacheSubject = new ReplaySubject(1);
|
|
11790
11792
|
this.roles = [];
|
|
11793
|
+
this.eventDispatcherService.on2(User.getEventName('get')).subscribe((data) => {
|
|
11794
|
+
this.user = data[0];
|
|
11795
|
+
});
|
|
11791
11796
|
this.listenEvents();
|
|
11792
11797
|
}
|
|
11793
11798
|
/**
|
|
@@ -11808,7 +11813,7 @@ class RestService {
|
|
|
11808
11813
|
*/
|
|
11809
11814
|
get() {
|
|
11810
11815
|
if (!this.cache) {
|
|
11811
|
-
this.
|
|
11816
|
+
(!this.user || this.user.hasRoles(this.roles)) ? this.fetch().pipe(first$1()).subscribe() : this.setCache([], true);
|
|
11812
11817
|
}
|
|
11813
11818
|
return this.cacheSubject.asObservable();
|
|
11814
11819
|
}
|
|
@@ -15228,7 +15233,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImpor
|
|
|
15228
15233
|
|
|
15229
15234
|
class UserService extends RestService$1 {
|
|
15230
15235
|
constructor(http, eventDispatcherService, environment) {
|
|
15231
|
-
console.log('userService');
|
|
15232
15236
|
super(http, eventDispatcherService, environment);
|
|
15233
15237
|
this.http = http;
|
|
15234
15238
|
this.eventDispatcherService = eventDispatcherService;
|