ngx-dsxlibrary 1.21.22 → 1.21.24
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/README.md
CHANGED
|
@@ -16,4 +16,5 @@ Se actualizo el servicio authorize se agrego getTokenValues y se agrego a primeN
|
|
|
16
16
|
Se actualizo primeNg se agrego PanelMenuModule y se dio acceso al servicio de error 1.21.9
|
|
17
17
|
Se actualizo primeNg se agrego DrawerModule 1.21.10
|
|
18
18
|
Se actualiza url de json loader 1.21.12
|
|
19
|
+
Se actualizo el interceptor http-authorize para manejar correctamente el refresh de token (401), detener peticiones cuando el TokenRefresh es inválido y mostrar mensajes de error más claros al usuario 1.21.24
|
|
19
20
|
```
|
|
@@ -6,7 +6,7 @@ import { TagModule } from 'primeng/tag';
|
|
|
6
6
|
import { CountUpDirective } from 'ngx-countup';
|
|
7
7
|
import { map, catchError, of, shareReplay, throwError, BehaviorSubject, EMPTY, switchMap, filter, take, finalize } from 'rxjs';
|
|
8
8
|
import * as i1$1 from '@angular/common/http';
|
|
9
|
-
import { HttpClient, HttpHeaders, HttpParams, HttpStatusCode } from '@angular/common/http';
|
|
9
|
+
import { HttpClient, HttpHeaders, HttpParams, HttpStatusCode, HttpErrorResponse } from '@angular/common/http';
|
|
10
10
|
import * as i2 from '@angular/platform-browser';
|
|
11
11
|
import { LottieComponent } from 'ngx-lottie';
|
|
12
12
|
import * as i4 from '@angular/forms';
|
|
@@ -1700,7 +1700,8 @@ class ErrorHandlerService {
|
|
|
1700
1700
|
'Solicitud incorrecta (400). Verifica los datos ingresados o validaciones existentes.';
|
|
1701
1701
|
break;
|
|
1702
1702
|
case HttpStatusCode.Unauthorized:
|
|
1703
|
-
userMessage =
|
|
1703
|
+
userMessage =
|
|
1704
|
+
'<b>Acceso no autorizado</b> (401). Por favor inicia sesión.';
|
|
1704
1705
|
break;
|
|
1705
1706
|
case HttpStatusCode.Forbidden:
|
|
1706
1707
|
userMessage = 'No tienes permisos para realizar esta acción (403).';
|
|
@@ -1725,7 +1726,7 @@ class ErrorHandlerService {
|
|
|
1725
1726
|
err.status +
|
|
1726
1727
|
' <i>Message:</i> ' +
|
|
1727
1728
|
userMessage +
|
|
1728
|
-
|
|
1729
|
+
`<strong class="alertMessageDsx"> (${error.error})</strong>`);
|
|
1729
1730
|
// Imprimir el mensaje técnico
|
|
1730
1731
|
if (isDevMode()) {
|
|
1731
1732
|
console.error(err);
|
|
@@ -1796,16 +1797,32 @@ const httpAuthorizeInterceptor = (req, next) => {
|
|
|
1796
1797
|
// Si no se está refrescando el token, inicia el proceso de refresh
|
|
1797
1798
|
if (!isRefreshing) {
|
|
1798
1799
|
isRefreshing = true;
|
|
1799
|
-
|
|
1800
|
+
// Reiniciar el subject en cada ciclo de refresh para evitar estados cerrados por error
|
|
1801
|
+
refreshTokenSubject = new BehaviorSubject(null);
|
|
1800
1802
|
// Solicita el refresh del token
|
|
1801
1803
|
return _securityService.tokenRefresh(refreshToken).pipe(switchMap((response) => {
|
|
1804
|
+
// Si el servicio de refresh indica fallo o no retorna datos, mostrar error y cortar flujo
|
|
1805
|
+
if (!response.isSuccess || !response.data) {
|
|
1806
|
+
//console.log('Refresh token fallido:', response);
|
|
1807
|
+
isRefreshing = false;
|
|
1808
|
+
const refreshError = new HttpErrorResponse({
|
|
1809
|
+
status: HttpStatusCode.Unauthorized,
|
|
1810
|
+
statusText: 'Token de refresco inválido',
|
|
1811
|
+
error: response.message,
|
|
1812
|
+
url: req.url,
|
|
1813
|
+
});
|
|
1814
|
+
// Notificar a las peticiones en espera que el refresh falló
|
|
1815
|
+
refreshTokenSubject.error(refreshError);
|
|
1816
|
+
// Enviamos el error al manejador centralizado para mostrar el mensaje al usuario
|
|
1817
|
+
return _handleErrorService.handleErrorResponse(refreshError);
|
|
1818
|
+
}
|
|
1819
|
+
// Refresh exitoso: actualizar tokens y repetir la petición original
|
|
1802
1820
|
isRefreshing = false;
|
|
1803
1821
|
_authorizeService.tokenReload(response.data); // Actualiza el token en el servicio
|
|
1804
|
-
refreshTokenSubject.next(response.data
|
|
1805
|
-
// Repite la petición original con el nuevo token
|
|
1822
|
+
refreshTokenSubject.next(response.data.token); // Emite el nuevo token
|
|
1806
1823
|
return next(req.clone({
|
|
1807
1824
|
setHeaders: {
|
|
1808
|
-
Authorization: `Bearer ${response.data
|
|
1825
|
+
Authorization: `Bearer ${response.data.token}`,
|
|
1809
1826
|
},
|
|
1810
1827
|
}));
|
|
1811
1828
|
}), catchError((err) => {
|
|
@@ -2672,66 +2689,28 @@ function dateRangeValidator(control) {
|
|
|
2672
2689
|
}
|
|
2673
2690
|
/**
|
|
2674
2691
|
* Valida que una fecha única esté dentro de un rango mínimo y máximo.
|
|
2675
|
-
*
|
|
2676
|
-
*
|
|
2677
|
-
*
|
|
2678
|
-
* @param minDate Fecha mínima permitida (tipo Date, debe ser creada correctamente en local).
|
|
2679
|
-
* @param maxDate Fecha máxima permitida (tipo Date, debe ser creada correctamente en local).
|
|
2680
|
-
* @returns Una función validadora para Angular Reactive Forms.
|
|
2681
|
-
*
|
|
2682
|
-
* Ejemplo de uso:
|
|
2683
|
-
* myControl = new FormControl('', [dateMinMaxValidator(new Date(2025, 2, 1), new Date(2025, 2, 15))]);
|
|
2684
|
-
*
|
|
2685
|
-
* Notas de depuración:
|
|
2686
|
-
* - Si recibes fechas string, se convierten a local usando parseLocalDate.
|
|
2687
|
-
* - Si recibes objetos Date, se usan directamente.
|
|
2688
|
-
* - Si la fecha está fuera del rango, se retorna un error con detalles.
|
|
2689
|
-
* - Si la fecha es inválida o vacía, no retorna error (null).
|
|
2692
|
+
* Las fechas deben utilizar la función de convertirFechaISOString para asegurar el formato correcto y que funcione con el componente primeNg.
|
|
2693
|
+
* @param minDate Fecha mínima permitida.
|
|
2694
|
+
* @param maxDate Fecha máxima permitida.
|
|
2690
2695
|
*/
|
|
2691
2696
|
function dateMinMaxValidator(minDate, maxDate) {
|
|
2692
|
-
/**
|
|
2693
|
-
* Convierte un string 'YYYY-MM-DD' a un objeto Date en la zona horaria local.
|
|
2694
|
-
* Esto evita desfases por zona horaria al crear fechas desde strings.
|
|
2695
|
-
* @param dateString Fecha en formato 'YYYY-MM-DD'.
|
|
2696
|
-
* @returns Date en local.
|
|
2697
|
-
*/
|
|
2698
|
-
function parseLocalDate(dateString) {
|
|
2699
|
-
const [year, month, day] = dateString.split('-').map(Number);
|
|
2700
|
-
// El mes es 0-indexado en JavaScript
|
|
2701
|
-
return new Date(year, month - 1, day);
|
|
2702
|
-
}
|
|
2703
2697
|
return (control) => {
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
//
|
|
2709
|
-
if (
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
if (!isNaN(currentDate.getTime())) {
|
|
2718
|
-
// Depuración: descomentar para ver valores en consola
|
|
2719
|
-
// console.log('Fecha actual:', currentDate, 'Min:', minDate, 'Max:', maxDate);
|
|
2720
|
-
// Validar si la fecha está fuera del rango permitido
|
|
2721
|
-
if (currentDate < minDate || currentDate > maxDate) {
|
|
2722
|
-
return {
|
|
2723
|
-
dateNotRange: {
|
|
2724
|
-
message: `La fecha debe estar entre ${minDate.toLocaleDateString()} y ${maxDate.toLocaleDateString()}`,
|
|
2725
|
-
minDate: minDate.toISOString(),
|
|
2726
|
-
maxDate: maxDate.toISOString(),
|
|
2727
|
-
actualDate: currentDate.toISOString(), // Para depuración
|
|
2728
|
-
},
|
|
2729
|
-
};
|
|
2730
|
-
}
|
|
2731
|
-
return null; // Fecha válida y dentro del rango
|
|
2698
|
+
const date = control.value;
|
|
2699
|
+
// Verificar si el valor es una fecha válida
|
|
2700
|
+
if (date && !isNaN(new Date(date).getTime())) {
|
|
2701
|
+
const currentDate = new Date(date);
|
|
2702
|
+
// Validar si la fecha está fuera del rango permitido
|
|
2703
|
+
if (currentDate < minDate || currentDate > maxDate) {
|
|
2704
|
+
return {
|
|
2705
|
+
dateNotRange: {
|
|
2706
|
+
message: `La fecha debe estar entre ${minDate.toLocaleDateString()} y ${maxDate.toLocaleDateString()}`,
|
|
2707
|
+
minDate: minDate.toISOString(),
|
|
2708
|
+
maxDate: maxDate.toISOString(),
|
|
2709
|
+
},
|
|
2710
|
+
};
|
|
2732
2711
|
}
|
|
2712
|
+
return null; // Fecha válida y dentro del rango
|
|
2733
2713
|
}
|
|
2734
|
-
// Si no hay valor o la fecha es inválida, no retorna error
|
|
2735
2714
|
return null;
|
|
2736
2715
|
};
|
|
2737
2716
|
}
|