ngx-vector-components 6.57.0 → 6.57.1

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [6.57.1] (25/11/2026)
4
+
5
+ ### Fix
6
+
7
+ - `HttpInterceptorProvider`: when the token refresh fails (or there is no refresh token stored), the requests that were waiting in the refresh queue now receive the error too, instead of waiting forever with the screen stuck. The queue subject is replaced before being errored, so the next 401 starts with a clean queue (`http-interceptor.ts`)
8
+ - `HttpInterceptorProvider`: the global spinner now turns off after a 401, whether the refresh succeeds or fails; previously the request stayed in the active list and the spinner never went off (`http-interceptor.ts`)
9
+ - `HttpInterceptorProvider`: each request now releases only its own spinner slot, once. Previously the slot was looked up by the response URL and removed by the request URL; when they differed, `splice(-1, 1)` removed another request's slot and the spinner could turn off too early (`http-interceptor.ts`)
10
+ - Added `http-interceptor.spec.ts` covering the 401 path: queued requests fail with the refresh, and the spinner turns off on refresh success and failure
11
+
3
12
  ## [6.57.0] (23/11/2026)
4
13
 
5
14
  ### Feat
@@ -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, debounceTime, catchError, filter, take } from 'rxjs/operators';
66
+ import { switchMap, map, tap, debounceTime, catchError, 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';
@@ -7699,17 +7699,33 @@ class HttpInterceptorProvider {
7699
7699
  request = this.addClientHeaders(request);
7700
7700
  }
7701
7701
  const noSpinnerHeader = request.headers.get('no-spinner');
7702
- if (!noSpinnerHeader && !request.url.startsWith('/assets/')) {
7702
+ const tracksSpinner = !noSpinnerHeader && !request.url.startsWith('/assets/');
7703
+ const spinnerKey = this.getUrlWithoutParams(request.url);
7704
+ if (tracksSpinner) {
7703
7705
  this.loadingService.loading$.next(true);
7704
- this.activeRequests.push(this.getUrlWithoutParams(request.url));
7705
- }
7706
+ this.activeRequests.push(spinnerKey);
7707
+ }
7708
+ // Cada requisicao solta a sua vaga uma vez so. Depois do refresh o retry passa de novo
7709
+ // pelo `tap`, e sem esta trava a segunda soltura tiraria a vaga de outra requisicao com
7710
+ // a mesma URL -- o que e comum aqui, porque a mesma chamada sai repetida.
7711
+ let released = !tracksSpinner;
7712
+ const release = () => {
7713
+ if (released) {
7714
+ return;
7715
+ }
7716
+ released = true;
7717
+ this.releaseRequest(spinnerKey);
7718
+ };
7706
7719
  return next.handle(request).pipe(catchError((response) => {
7707
7720
  if (response.error?.messages?.length) {
7708
7721
  this.errorMessageService.genericModalErrorMessage$.next(response.error.messages[response.error.messages.length - 1]);
7709
7722
  }
7710
7723
  if (!this.isRefreshTokenRequest(request.url)) {
7711
7724
  if (response.status === 401) {
7712
- return this.handle401Error(request, next);
7725
+ // A volta acontecia aqui, antes da limpeza la embaixo: a requisicao ficava para
7726
+ // sempre no activeRequests e o spinner nunca apagava. O `finalize` solta a vaga
7727
+ // tanto se o retry der certo quanto se a renovacao falhar.
7728
+ return this.handle401Error(request, next).pipe(finalize(release));
7713
7729
  }
7714
7730
  if (response.status === 403) {
7715
7731
  this.errorMessageService.genericModalErrorMessage$.next('Usuário sem privilégios para realizar essa ação');
@@ -7722,21 +7738,11 @@ class HttpInterceptorProvider {
7722
7738
  }
7723
7739
  }
7724
7740
  }
7725
- if (this.activeRequests.includes(this.getUrlWithoutParams(response.url))) {
7726
- this.activeRequests.splice(this.activeRequests.findIndex((item) => item === this.getUrlWithoutParams(request.url)), 1);
7727
- if (!this.activeRequests.length) {
7728
- this.loadingService.loading$.next(false);
7729
- }
7730
- }
7741
+ release();
7731
7742
  return throwError(() => response);
7732
7743
  }), tap((response) => {
7733
7744
  if (response instanceof HttpResponse) {
7734
- if (this.activeRequests.includes(this.getUrlWithoutParams(response.url))) {
7735
- this.activeRequests.splice(this.activeRequests.findIndex((item) => item === this.getUrlWithoutParams(request.url)), 1);
7736
- if (!this.activeRequests.length) {
7737
- this.loadingService.loading$.next(false);
7738
- }
7739
- }
7745
+ release();
7740
7746
  if (Object(response.body).hasOwnProperty('statusCode') &&
7741
7747
  response.body.statusCode === 400 &&
7742
7748
  response.body.messages?.length) {
@@ -7745,6 +7751,41 @@ class HttpInterceptorProvider {
7745
7751
  }
7746
7752
  }));
7747
7753
  }
7754
+ /**
7755
+ * Tira uma vaga da URL do contador do spinner e apaga o spinner na ultima.
7756
+ *
7757
+ * A busca da vaga usa a MESMA chave que entrou na fila. Antes o `includes` olhava a URL
7758
+ * da resposta e o `findIndex` a da requisicao: quando as duas diferiam, o `findIndex`
7759
+ * devolvia -1 e o `splice(-1, 1)` apagava a ultima vaga da lista, que era de outra
7760
+ * requisicao.
7761
+ */
7762
+ releaseRequest(key) {
7763
+ const index = this.activeRequests.indexOf(key);
7764
+ if (index === -1) {
7765
+ return;
7766
+ }
7767
+ this.activeRequests.splice(index, 1);
7768
+ if (!this.activeRequests.length) {
7769
+ this.loadingService.loading$.next(false);
7770
+ }
7771
+ }
7772
+ /**
7773
+ * Derruba quem ficou esperando o refresh terminar.
7774
+ *
7775
+ * Quando o refresh falhava, so quem disparou a renovacao recebia o erro. As requisicoes
7776
+ * que entraram na fila do `refreshTokenSubject` esperavam um token que nunca chegava:
7777
+ * sem `next`, sem `error` e sem `complete`, a inscricao ficava pendurada para sempre e
7778
+ * com ela a tela.
7779
+ *
7780
+ * O subject e trocado antes de receber o erro porque um BehaviorSubject que errou fica
7781
+ * morto: qualquer inscricao nova erra na hora. Assim a fila atual cai e o proximo 401
7782
+ * comeca com uma fila limpa.
7783
+ */
7784
+ failQueuedRequests(error) {
7785
+ const queue = this.refreshTokenSubject;
7786
+ this.refreshTokenSubject = new BehaviorSubject(null);
7787
+ queue.error(error);
7788
+ }
7748
7789
  isRefreshTokenRequest(url) {
7749
7790
  return url.includes('connect/token');
7750
7791
  }
@@ -7842,24 +7883,25 @@ class HttpInterceptorProvider {
7842
7883
  this.isRefreshing = true;
7843
7884
  this.refreshTokenSubject.next(null);
7844
7885
  const refreshToken = this.storageService.getRefreshToken();
7845
- if (refreshToken) {
7846
- return this.authService.getTokenByRefreshToken(refreshToken).pipe(switchMap((token) => {
7847
- this.isRefreshing = false;
7848
- this.refreshTokenSubject.next(this.storageService.getToken());
7849
- return next.handle(this.addTokenIfPresent(request));
7850
- }), catchError((err) => {
7851
- this.isRefreshing = false;
7852
- this.authService.logout();
7853
- return throwError(() => err);
7854
- }));
7855
- }
7856
- else {
7886
+ if (!refreshToken) {
7857
7887
  this.isRefreshing = false;
7888
+ const missingRefreshToken = new Error('Sessao expirada: nao ha refresh token guardado');
7889
+ this.failQueuedRequests(missingRefreshToken);
7858
7890
  this.authService.logout();
7859
- return throwError(() => new Error());
7891
+ return throwError(() => missingRefreshToken);
7860
7892
  }
7893
+ return this.authService.getTokenByRefreshToken(refreshToken).pipe(switchMap(() => {
7894
+ this.isRefreshing = false;
7895
+ this.refreshTokenSubject.next(this.storageService.getToken());
7896
+ return next.handle(this.addTokenIfPresent(request));
7897
+ }), catchError((err) => {
7898
+ this.isRefreshing = false;
7899
+ this.failQueuedRequests(err);
7900
+ this.authService.logout();
7901
+ return throwError(() => err);
7902
+ }));
7861
7903
  }
7862
- return this.refreshTokenSubject.pipe(filter((token) => token !== null), take(1), switchMap((token) => next.handle(this.addTokenIfPresent(request))));
7904
+ return this.refreshTokenSubject.pipe(filter((token) => token !== null), take(1), switchMap(() => next.handle(this.addTokenIfPresent(request))));
7863
7905
  }
7864
7906
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HttpInterceptorProvider, deps: [{ token: StorageService }, { token: ErrorMessageService }, { token: LoadingService }, { token: AuthService }, { token: i2$2.MessageService }, { token: ENVIRONMENT }, { token: APP_NAME, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
7865
7907
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HttpInterceptorProvider }); }