ngx-vector-components 6.58.1 → 6.59.0
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/CHANGELOG.md +10 -0
- package/fesm2022/ngx-vector-components.mjs +99 -14
- package/fesm2022/ngx-vector-components.mjs.map +1 -1
- package/lib/guards/crud-list-has-items.guard.d.ts +7 -0
- package/lib/guards/has-permission.guard.d.ts +7 -1
- package/lib/guards/token-is-present.guard.d.ts +12 -1
- package/lib/services/profile.service.d.ts +16 -0
- package/lib/services/storage.service.d.ts +17 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [6.59.0] (26/11/2026)
|
|
4
|
+
|
|
5
|
+
### Fix
|
|
6
|
+
|
|
7
|
+
- Corrects duplicating a tab, reloading the page or opening a screen from its URL left the top bar and the menu on screen but no content. Three guards were reading state that only exists in memory:
|
|
8
|
+
- `ProfileService.ensureProfileLoaded()`: fetches the profile when it is missing, and resolves synchronously when it is already loaded, so navigation gains no latency. It was only loaded through `getTokenByGuid`, so a start without a token in the URL never fetched permissions again (`profile.service.ts`)
|
|
9
|
+
- `hasPermissionGuard`: waits for the profile before deciding. A missing profile is not a denied permission (`has-permission.guard.ts`)
|
|
10
|
+
- `crudListHasItemsGuard`: a route carrying a URL parameter goes through, since the screen loads from that id and does not depend on `dataset$`, which starts empty on every load (`crud-list-has-items.guard.ts`)
|
|
11
|
+
- `StorageService`: `refreshToken` and `username` moved from sessionStorage to localStorage, next to the token they renew. Firefox and Safari do not copy the session when a tab is duplicated, so the new tab had no way to renew the token and the first 401 logged the user out. Values left in the old place are migrated on read (`storage.service.ts`)
|
|
12
|
+
|
|
3
13
|
## [6.58.1] (26/11/2026)
|
|
4
14
|
|
|
5
15
|
### Fix
|
|
@@ -63,7 +63,7 @@ import { Tabs, TabsModule as TabsModule$1 } from 'primeng/tabs';
|
|
|
63
63
|
import { DateTime } from 'luxon';
|
|
64
64
|
import * as i1$5 from '@angular/common/http';
|
|
65
65
|
import { HttpHeaders, HttpClient, HttpResponse } from '@angular/common/http';
|
|
66
|
-
import { switchMap, map, tap,
|
|
66
|
+
import { switchMap, map, tap, catchError, shareReplay, debounceTime, finalize, filter, take } from 'rxjs/operators';
|
|
67
67
|
import * as i1$7 from '@angular/platform-browser';
|
|
68
68
|
import * as i1$8 from 'primeng/drawer';
|
|
69
69
|
import { DrawerModule as DrawerModule$1 } from 'primeng/drawer';
|
|
@@ -2408,23 +2408,52 @@ class StorageService {
|
|
|
2408
2408
|
removeToken() {
|
|
2409
2409
|
localStorage.removeItem('token');
|
|
2410
2410
|
}
|
|
2411
|
+
/**
|
|
2412
|
+
* No localStorage, ao lado do {@link getToken}: os dois formam o par de
|
|
2413
|
+
* renovacao e precisam sobreviver juntos. No sessionStorage, uma aba
|
|
2414
|
+
* duplicada no Firefox ou no Safari — que nao copiam a sessao — subia com o
|
|
2415
|
+
* token de acesso mas sem como renova-lo, e o primeiro 401 caia no logout.
|
|
2416
|
+
*
|
|
2417
|
+
* O {@link getUsername} acompanha porque `getTokenByRefreshToken` o envia no
|
|
2418
|
+
* corpo da renovacao.
|
|
2419
|
+
*/
|
|
2411
2420
|
getRefreshToken() {
|
|
2412
|
-
return
|
|
2421
|
+
return this.readMigratingFromSession('refreshToken');
|
|
2413
2422
|
}
|
|
2414
2423
|
setRefreshToken(refreshToken) {
|
|
2415
|
-
|
|
2424
|
+
localStorage.setItem('refreshToken', refreshToken);
|
|
2416
2425
|
}
|
|
2417
2426
|
removeRefreshToken() {
|
|
2418
|
-
|
|
2427
|
+
localStorage.removeItem('refreshToken');
|
|
2419
2428
|
}
|
|
2420
2429
|
getUsername() {
|
|
2421
|
-
return
|
|
2430
|
+
return this.readMigratingFromSession('username');
|
|
2422
2431
|
}
|
|
2423
2432
|
setUsername(username) {
|
|
2424
|
-
|
|
2433
|
+
localStorage.setItem('username', username);
|
|
2425
2434
|
}
|
|
2426
2435
|
removeUsername() {
|
|
2427
|
-
|
|
2436
|
+
localStorage.removeItem('username');
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Le do localStorage e, se a chave ainda estiver no sessionStorage de uma
|
|
2440
|
+
* sessao anterior a mudanca de lugar, move antes de devolver — sem isso, todo
|
|
2441
|
+
* usuario logado no deploy cairia na primeira renovacao de token.
|
|
2442
|
+
*
|
|
2443
|
+
* Pode sair quando nao houver mais sessoes dessa epoca em circulacao.
|
|
2444
|
+
*/
|
|
2445
|
+
readMigratingFromSession(key) {
|
|
2446
|
+
const stored = localStorage.getItem(key);
|
|
2447
|
+
if (stored) {
|
|
2448
|
+
return stored;
|
|
2449
|
+
}
|
|
2450
|
+
const legacy = sessionStorage.getItem(key);
|
|
2451
|
+
if (!legacy) {
|
|
2452
|
+
return '';
|
|
2453
|
+
}
|
|
2454
|
+
localStorage.setItem(key, legacy);
|
|
2455
|
+
sessionStorage.removeItem(key);
|
|
2456
|
+
return legacy;
|
|
2428
2457
|
}
|
|
2429
2458
|
getUserId() {
|
|
2430
2459
|
const userId = sessionStorage.getItem('userId');
|
|
@@ -2920,6 +2949,32 @@ class ProfileService {
|
|
|
2920
2949
|
this.moduleProfile$.next(allModules);
|
|
2921
2950
|
}));
|
|
2922
2951
|
}
|
|
2952
|
+
/**
|
|
2953
|
+
* Garante o perfil disponível antes de alguém decidir com base nele.
|
|
2954
|
+
*
|
|
2955
|
+
* Com ele em mãos devolve de forma síncrona, sem requisição — o caminho da
|
|
2956
|
+
* maioria das navegações. Sem ele, busca uma vez: o `getTokenByGuid` era o
|
|
2957
|
+
* único lugar que carregava o perfil, então uma aplicação que subia sem token
|
|
2958
|
+
* na URL não tinha como buscá-lo de novo.
|
|
2959
|
+
*
|
|
2960
|
+
* O `shareReplay` faz navegações simultâneas dividirem a mesma requisição.
|
|
2961
|
+
* Erro devolve indefinido, e quem chamou decide negando; o cache é descartado
|
|
2962
|
+
* nesse caso, senão uma falha passageira ficaria gravada e nenhuma navegação
|
|
2963
|
+
* seguinte tentaria de novo.
|
|
2964
|
+
*/
|
|
2965
|
+
ensureProfileLoaded() {
|
|
2966
|
+
if (this.moduleProfile$.value) {
|
|
2967
|
+
return of(this.moduleProfile$.value);
|
|
2968
|
+
}
|
|
2969
|
+
if (!this.storageService.getToken()) {
|
|
2970
|
+
return of(undefined);
|
|
2971
|
+
}
|
|
2972
|
+
this.profileRequest$ ??= this.getUserProfile().pipe(map(() => this.moduleProfile$.value), catchError(() => {
|
|
2973
|
+
this.profileRequest$ = undefined;
|
|
2974
|
+
return of(undefined);
|
|
2975
|
+
}), shareReplay(1));
|
|
2976
|
+
return this.profileRequest$;
|
|
2977
|
+
}
|
|
2923
2978
|
userHasPermission(action) {
|
|
2924
2979
|
if (!action) {
|
|
2925
2980
|
return true;
|
|
@@ -7604,7 +7659,17 @@ function provideVectorPrimeNG() {
|
|
|
7604
7659
|
});
|
|
7605
7660
|
}
|
|
7606
7661
|
|
|
7662
|
+
/**
|
|
7663
|
+
* Deixa a rota abrir quando a lista do CRUD já foi carregada em memória.
|
|
7664
|
+
*
|
|
7665
|
+
* Rota com parâmetro passa direto: a tela se carrega pelo id da URL e não
|
|
7666
|
+
* depende do `dataset$`, que nasce vazio a cada carga. Sem essa saída, abrir um
|
|
7667
|
+
* detalhe por link, favorito ou aba duplicada voltava para a listagem.
|
|
7668
|
+
*/
|
|
7607
7669
|
const crudListHasItemsGuard = (routeSnapshot) => {
|
|
7670
|
+
if (Object.keys(routeSnapshot.params).length) {
|
|
7671
|
+
return true;
|
|
7672
|
+
}
|
|
7608
7673
|
const serviceType = routeSnapshot.data['service'];
|
|
7609
7674
|
if (!serviceType) {
|
|
7610
7675
|
console.error('You forgot to add the service declaration to route "data" property.');
|
|
@@ -7649,15 +7714,21 @@ const getTokenByGuidGuard = (route) => {
|
|
|
7649
7714
|
return false;
|
|
7650
7715
|
};
|
|
7651
7716
|
|
|
7717
|
+
/**
|
|
7718
|
+
* Libera a rota conforme as permissões do perfil.
|
|
7719
|
+
*
|
|
7720
|
+
* Espera o perfil antes de decidir: ausente não é o mesmo que negado. Com ele
|
|
7721
|
+
* já carregado, `ensureProfileLoaded` responde de forma síncrona.
|
|
7722
|
+
*/
|
|
7652
7723
|
const hasPermissionGuard = (routeSnapshot) => {
|
|
7653
7724
|
const profileService = inject(ProfileService);
|
|
7654
7725
|
const router = inject(Router);
|
|
7655
7726
|
const appName = inject(APP_NAME);
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7727
|
+
return profileService
|
|
7728
|
+
.ensureProfileLoaded()
|
|
7729
|
+
.pipe(map(() => profileService.userHasPermission(routeSnapshot.data['permission'])
|
|
7730
|
+
? true
|
|
7731
|
+
: router.createUrlTree([appName.toLowerCase()])));
|
|
7661
7732
|
};
|
|
7662
7733
|
|
|
7663
7734
|
const roleGuard = (routeSnapshot) => {
|
|
@@ -7670,15 +7741,29 @@ const roleGuard = (routeSnapshot) => {
|
|
|
7670
7741
|
return router.createUrlTree(['']);
|
|
7671
7742
|
};
|
|
7672
7743
|
|
|
7744
|
+
/**
|
|
7745
|
+
* Exige token para a rota e garante o perfil carregado antes de ativá-la.
|
|
7746
|
+
*
|
|
7747
|
+
* O perfil entra aqui, e não só nos guards de permissão, porque
|
|
7748
|
+
* `getUserProfile()` grava o `userInfo` que dezenas de componentes leem ao
|
|
7749
|
+
* montar. Numa aba duplicada no Firefox ou no Safari, que não copiam o
|
|
7750
|
+
* sessionStorage, eles estouravam com o dado vazio.
|
|
7751
|
+
*
|
|
7752
|
+
* Cobre as rotas raiz, logo vale para todas as telas abaixo. Com o perfil em
|
|
7753
|
+
* mãos a resposta é síncrona.
|
|
7754
|
+
*/
|
|
7673
7755
|
const tokenIsPresentGuard = (routeSnapshot) => {
|
|
7674
7756
|
const storageService = inject(StorageService);
|
|
7675
7757
|
const authService = inject(AuthService);
|
|
7758
|
+
const profileService = inject(ProfileService);
|
|
7759
|
+
// Este caminho ja carrega o perfil: `getTokenByGuid` encadeia `getUserProfile`.
|
|
7676
7760
|
if (routeSnapshot.queryParams['tokenGuid']) {
|
|
7677
7761
|
return firstValueFrom(authService.getTokenByGuid(routeSnapshot.queryParams['tokenGuid'])).then((response) => !!response.accessToken);
|
|
7678
7762
|
}
|
|
7679
|
-
|
|
7680
|
-
return
|
|
7763
|
+
if (!storageService.getToken()) {
|
|
7764
|
+
return false;
|
|
7681
7765
|
}
|
|
7766
|
+
return profileService.ensureProfileLoaded().pipe(map(() => true));
|
|
7682
7767
|
};
|
|
7683
7768
|
|
|
7684
7769
|
class HttpInterceptorProvider {
|