@jvsoft/utils 0.0.13-alpha.0 → 0.0.13-alpha.2
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/classes/data-model.d.ts +25 -0
- package/fesm2022/jvsoft-utils-src-functions.mjs +1109 -0
- package/fesm2022/jvsoft-utils-src-functions.mjs.map +1 -0
- package/fesm2022/jvsoft-utils-src-interfaces.mjs +6 -0
- package/fesm2022/jvsoft-utils-src-interfaces.mjs.map +1 -0
- package/fesm2022/jvsoft-utils-src-pipes.mjs +290 -0
- package/fesm2022/jvsoft-utils-src-pipes.mjs.map +1 -0
- package/fesm2022/jvsoft-utils.mjs +1526 -0
- package/fesm2022/jvsoft-utils.mjs.map +1 -0
- package/functions/base64.d.ts +2 -0
- package/functions/browser.d.ts +1 -0
- package/functions/crypto-js.d.ts +2 -0
- package/functions/date.d.ts +3 -0
- package/functions/email.d.ts +2 -0
- package/functions/file.d.ts +10 -0
- package/functions/forms.d.ts +10 -0
- package/functions/http-client.d.ts +2 -0
- package/functions/index.d.ts +1 -0
- package/functions/local-storage.d.ts +29 -0
- package/functions/mat-form-controls/autocomplete.d.ts +21 -0
- package/functions/mat-form-controls/index.d.ts +2 -0
- package/functions/number.d.ts +1 -0
- package/functions/object-transformation.d.ts +2 -0
- package/functions/objects-arrays.d.ts +37 -0
- package/functions/public-api.d.ts +16 -0
- package/functions/string.d.ts +1 -0
- package/functions/sweetalert.d.ts +5 -0
- package/functions/utiles.d.ts +1 -0
- package/index.d.ts +5 -0
- package/{src/interfaces/datos.ts → interfaces/datos.d.ts} +1 -2
- package/interfaces/index.d.ts +1 -0
- package/interfaces/public-api.d.ts +1 -0
- package/package.json +27 -7
- package/pipes/data-en-lista.pipe.d.ts +8 -0
- package/pipes/date-diff-string.pipe.d.ts +17 -0
- package/pipes/filtro.pipe.d.ts +18 -0
- package/pipes/form-control-is-required.pipe.d.ts +9 -0
- package/pipes/index.d.ts +1 -0
- package/pipes/json-parse.pipe.d.ts +7 -0
- package/pipes/no-sanitize.pipe.d.ts +10 -0
- package/pipes/public-api.d.ts +8 -0
- package/pipes/tipo-valor-funcion.pipe.d.ts +9 -0
- package/pipes/zero-fill.pipe.d.ts +8 -0
- package/public-api.d.ts +4 -0
- package/src/functions/base64.d.ts +2 -0
- package/src/functions/browser.d.ts +1 -0
- package/src/functions/crypto-js.d.ts +2 -0
- package/src/functions/date.d.ts +3 -0
- package/src/functions/email.d.ts +2 -0
- package/src/functions/file.d.ts +10 -0
- package/src/functions/forms.d.ts +10 -0
- package/src/functions/http-client.d.ts +2 -0
- package/src/functions/index.d.ts +5 -0
- package/src/functions/local-storage.d.ts +29 -0
- package/src/functions/mat-form-controls/autocomplete.d.ts +21 -0
- package/src/functions/mat-form-controls/index.d.ts +2 -0
- package/src/functions/number.d.ts +1 -0
- package/src/functions/object-transformation.d.ts +2 -0
- package/src/functions/objects-arrays.d.ts +37 -0
- package/src/functions/public-api.d.ts +16 -0
- package/src/functions/string.d.ts +1 -0
- package/src/functions/sweetalert.d.ts +5 -0
- package/src/functions/utiles.d.ts +1 -0
- package/src/interfaces/datos.d.ts +4 -0
- package/src/interfaces/index.d.ts +5 -0
- package/src/interfaces/public-api.d.ts +1 -0
- package/src/pipes/data-en-lista.pipe.d.ts +8 -0
- package/src/pipes/date-diff-string.pipe.d.ts +17 -0
- package/src/pipes/filtro.pipe.d.ts +18 -0
- package/src/pipes/form-control-is-required.pipe.d.ts +9 -0
- package/src/pipes/index.d.ts +5 -0
- package/src/pipes/json-parse.pipe.d.ts +7 -0
- package/src/pipes/no-sanitize.pipe.d.ts +10 -0
- package/src/pipes/public-api.d.ts +8 -0
- package/src/pipes/tipo-valor-funcion.pipe.d.ts +9 -0
- package/src/pipes/zero-fill.pipe.d.ts +8 -0
- package/CHANGELOG.md +0 -19
- package/ng-package.json +0 -7
- package/src/classes/data-model.ts +0 -150
- package/src/functions/base64.ts +0 -8
- package/src/functions/browser.ts +0 -20
- package/src/functions/crypto-js.ts +0 -29
- package/src/functions/date.ts +0 -23
- package/src/functions/email.ts +0 -17
- package/src/functions/file.ts +0 -138
- package/src/functions/forms.ts +0 -145
- package/src/functions/http-client.ts +0 -110
- package/src/functions/index.ts +0 -1
- package/src/functions/local-storage.ts +0 -102
- package/src/functions/mat-form-controls/autocomplete.ts +0 -275
- package/src/functions/mat-form-controls/index.ts +0 -6
- package/src/functions/ng-package.json +0 -5
- package/src/functions/number.ts +0 -3
- package/src/functions/object-transformation.ts +0 -37
- package/src/functions/objects-arrays.ts +0 -243
- package/src/functions/public-api.ts +0 -19
- package/src/functions/string.ts +0 -9
- package/src/functions/sweetalert.ts +0 -95
- package/src/functions/utiles.ts +0 -20
- package/src/interfaces/index.ts +0 -1
- package/src/interfaces/ng-package.json +0 -5
- package/src/interfaces/otros.ts +0 -0
- package/src/interfaces/public-api.ts +0 -3
- package/src/interfaces/routes.ts +0 -42
- package/src/pipes/data-en-lista.pipe.ts +0 -40
- package/src/pipes/date-diff-string.pipe.ts +0 -117
- package/src/pipes/filtro.pipe.ts +0 -64
- package/src/pipes/form-control-is-required.pipe.ts +0 -17
- package/src/pipes/index.ts +0 -1
- package/src/pipes/json-parse.pipe.ts +0 -18
- package/src/pipes/ng-package.json +0 -5
- package/src/pipes/no-sanitize.pipe.ts +0 -12
- package/src/pipes/public-api.ts +0 -10
- package/src/pipes/tipo-valor-funcion.pipe.ts +0 -23
- package/src/pipes/zero-fill.pipe.ts +0 -19
- package/src/public-api.ts +0 -12
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -15
package/src/functions/email.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function maskEmail(email: string): string {
|
|
2
|
-
const [user, domain] = email.split("@");
|
|
3
|
-
|
|
4
|
-
if (user.length <= 2) {
|
|
5
|
-
return `${user[0]}***@${domain}`; // 🔹 Si el usuario es muy corto, no se oculta nada
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (user.length <= 4) {
|
|
9
|
-
return `${user[0]}***${user.slice(-1)}@${domain}`; // 🔹 Muestra 1 al inicio y 1 al final
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return `${user.slice(0, 2)}***${user.slice(-2)}@${domain}`; // 🔹 Muestra 2 al inicio y 2 al final
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function isEmail(email: string): boolean {
|
|
16
|
-
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
17
|
-
}
|
package/src/functions/file.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import {saveAs} from 'file-saver';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const mimeTypes: { [key: string]: string } = {
|
|
5
|
-
// Imágenes
|
|
6
|
-
'jpg': 'image/jpeg',
|
|
7
|
-
'jpeg': 'image/jpeg',
|
|
8
|
-
'png': 'image/png',
|
|
9
|
-
'gif': 'image/gif',
|
|
10
|
-
'webp': 'image/webp',
|
|
11
|
-
'svg': 'image/svg+xml',
|
|
12
|
-
'ico': 'image/x-icon',
|
|
13
|
-
'bmp': 'image/bmp',
|
|
14
|
-
|
|
15
|
-
// Documentos
|
|
16
|
-
'pdf': 'application/pdf',
|
|
17
|
-
'doc': 'application/msword',
|
|
18
|
-
'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
19
|
-
'xls': 'application/vnd.ms-excel',
|
|
20
|
-
'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
21
|
-
'ppt': 'application/vnd.ms-powerpoint',
|
|
22
|
-
'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
23
|
-
'txt': 'text/plain',
|
|
24
|
-
'csv': 'text/csv',
|
|
25
|
-
'json': 'application/json',
|
|
26
|
-
'xml': 'application/xml',
|
|
27
|
-
'html': 'text/html',
|
|
28
|
-
|
|
29
|
-
// Audio
|
|
30
|
-
'mp3': 'audio/mpeg',
|
|
31
|
-
'wav': 'audio/wav',
|
|
32
|
-
'ogg': 'audio/ogg',
|
|
33
|
-
'm4a': 'audio/mp4',
|
|
34
|
-
|
|
35
|
-
// Video
|
|
36
|
-
'mp4': 'video/mp4',
|
|
37
|
-
'avi': 'video/x-msvideo',
|
|
38
|
-
'mov': 'video/quicktime',
|
|
39
|
-
'wmv': 'video/x-ms-wmv',
|
|
40
|
-
'flv': 'video/x-flv',
|
|
41
|
-
'webm': 'video/webm',
|
|
42
|
-
'mkv': 'video/x-matroska',
|
|
43
|
-
|
|
44
|
-
// Archivos comprimidos
|
|
45
|
-
'zip': 'application/zip',
|
|
46
|
-
'rar': 'application/vnd.rar',
|
|
47
|
-
'7z': 'application/x-7z-compressed',
|
|
48
|
-
'tar': 'application/x-tar',
|
|
49
|
-
'gz': 'application/gzip',
|
|
50
|
-
'bz2': 'application/x-bzip2',
|
|
51
|
-
|
|
52
|
-
// Otros formatos
|
|
53
|
-
'js': 'application/javascript',
|
|
54
|
-
'css': 'text/css',
|
|
55
|
-
'ts': 'application/typescript',
|
|
56
|
-
'md': 'text/markdown',
|
|
57
|
-
'exe': 'application/octet-stream',
|
|
58
|
-
'eot': 'application/vnd.ms-fontobject',
|
|
59
|
-
'woff': 'font/woff',
|
|
60
|
-
'woff2': 'font/woff2',
|
|
61
|
-
'ttf': 'font/ttf',
|
|
62
|
-
'otf': 'font/otf',
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export function obtenerMimeType(nombreArchivo: string): string | null {
|
|
66
|
-
const extension = nombreArchivo.split('.').pop()?.toLowerCase();
|
|
67
|
-
return extension ? mimeTypes[extension] || 'application/octet-stream' : null;
|
|
68
|
-
}
|
|
69
|
-
export function sanitizarNombreArchivo(nombre: string, reemplazo: string = '_'): string {
|
|
70
|
-
// 1. Quitar caracteres no válidos para nombres de archivo
|
|
71
|
-
const nombreSanitizado = nombre.replace(/[\/\\:*?"<>|]/g, reemplazo);
|
|
72
|
-
|
|
73
|
-
// 2. Reemplazar espacios múltiples o al inicio/final
|
|
74
|
-
const nombreLimpio = nombreSanitizado.trim().replace(/\s+/g, reemplazo);
|
|
75
|
-
|
|
76
|
-
// 3. Asegurar longitud máxima (opcional, aquí 255 caracteres)
|
|
77
|
-
return nombreLimpio.substring(0, 255);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function getDataArchivoFromPath(value: string, conTimeStamp = false): {
|
|
81
|
-
nombre: string, extension?: string, d?: any, fechaSubida: any
|
|
82
|
-
} {
|
|
83
|
-
const partesPath = value.split('/');
|
|
84
|
-
const nombreCompleto = partesPath[partesPath.length - 1];
|
|
85
|
-
let timeStamp = 1;
|
|
86
|
-
let nombreSinTimeStamp = nombreCompleto;
|
|
87
|
-
const partesNombre: any [] = nombreCompleto.split('-');
|
|
88
|
-
if (partesNombre.length > 1) {
|
|
89
|
-
timeStamp = partesNombre[0] * 1;
|
|
90
|
-
partesNombre.shift();
|
|
91
|
-
nombreSinTimeStamp = partesNombre.join('-');
|
|
92
|
-
}
|
|
93
|
-
if (conTimeStamp) {
|
|
94
|
-
return {
|
|
95
|
-
nombre: nombreCompleto,
|
|
96
|
-
extension: nombreCompleto.split('.').pop(),
|
|
97
|
-
d: timeStamp,
|
|
98
|
-
fechaSubida: timeStamp ? new Date(timeStamp * 1000):'',
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
nombre: nombreSinTimeStamp,
|
|
103
|
-
extension: nombreSinTimeStamp.split('.').pop(),
|
|
104
|
-
d: timeStamp,
|
|
105
|
-
fechaSubida: timeStamp ? new Date(timeStamp * 1000):'',
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function convertirBytes(valor: number, unidadSalida: string | null = null, incluirUnidad: boolean = true): string | number | null {
|
|
110
|
-
const unidades: string[] = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
111
|
-
const indiceEntrada: number = unidadSalida ? unidades.indexOf(unidadSalida):0;
|
|
112
|
-
|
|
113
|
-
if (indiceEntrada === -1) {
|
|
114
|
-
// Unidad de entrada no válida
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
let indiceActual: number = indiceEntrada;
|
|
119
|
-
let resultado: number = valor;
|
|
120
|
-
|
|
121
|
-
let cont = 0;
|
|
122
|
-
|
|
123
|
-
while (cont < 6 && (indiceActual < unidades.length - 1) && (resultado >= 1024)) {
|
|
124
|
-
resultado /= 1024;
|
|
125
|
-
indiceActual++;
|
|
126
|
-
}
|
|
127
|
-
if (incluirUnidad) {
|
|
128
|
-
return `${resultado.toFixed(2)} ${unidades[indiceActual]}`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return resultado;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
export function downLoadFileStream(data: any, type: string, nombreArchivo?: string) {
|
|
136
|
-
const blob = new Blob([data], {type});
|
|
137
|
-
saveAs(blob, nombreArchivo);
|
|
138
|
-
}
|
package/src/functions/forms.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators} from '@angular/forms';
|
|
2
|
-
import {ReactiveFormConfig} from '@rxweb/reactive-form-validators';
|
|
3
|
-
|
|
4
|
-
export function establecerQuitarRequired(formulario: FormGroup, establecer: any[] = [], quitar: any[] = [], camposDisabled: string[] | 'todos' = []) {
|
|
5
|
-
establecer.forEach((control: string) => {
|
|
6
|
-
if (!formulario.get(control)?.hasValidator(Validators.required)) {
|
|
7
|
-
formulario.get(control)?.addValidators([Validators.required]);
|
|
8
|
-
formulario.get(control)?.enable();
|
|
9
|
-
formulario.get(control)?.updateValueAndValidity();
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
const deshabilitar = (strControl: string) => {
|
|
13
|
-
if (camposDisabled == 'todos') {
|
|
14
|
-
formulario.get(strControl)?.disable();
|
|
15
|
-
console.log(strControl);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
if (camposDisabled.includes(strControl)) {
|
|
19
|
-
formulario.get(strControl)?.disable();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
quitar.forEach(control => {
|
|
24
|
-
if (formulario.get(control)?.hasValidator(Validators.required)) {
|
|
25
|
-
formulario.get(control)?.removeValidators([Validators.required]);
|
|
26
|
-
formulario.get(control)?.updateValueAndValidity();
|
|
27
|
-
}
|
|
28
|
-
deshabilitar(control);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function getFormValidationErrors(form: FormGroup) {
|
|
33
|
-
const result: { control: string; error: string; value: any; }[] = [];
|
|
34
|
-
Object.keys(form.controls).forEach(key => {
|
|
35
|
-
const formProperty = form.get(key);
|
|
36
|
-
if (formProperty instanceof FormGroup) {
|
|
37
|
-
result.push(...getFormValidationErrors(formProperty));
|
|
38
|
-
}
|
|
39
|
-
const controlErrors: ValidationErrors | null | undefined = formProperty?.errors;
|
|
40
|
-
if (controlErrors) {
|
|
41
|
-
Object.keys(controlErrors).forEach(keyError => {
|
|
42
|
-
result.push({
|
|
43
|
-
control: key,
|
|
44
|
-
error: keyError,
|
|
45
|
-
value: controlErrors[keyError]
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function mensajesErrorFormControl(control: AbstractControl | null): string {
|
|
55
|
-
if (!control || !control.errors || !control.touched) return '';
|
|
56
|
-
|
|
57
|
-
ReactiveFormConfig.set({
|
|
58
|
-
// RxwebValidators
|
|
59
|
-
validationMessage: {
|
|
60
|
-
required: 'Es requerido',
|
|
61
|
-
numeric: 'Debe ser numérico valido',
|
|
62
|
-
// minLength: 'minimum length is {{1}}',
|
|
63
|
-
// maxLength: 'allowed max length is {{1}}',
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const errorMessages: Record<string, string> = {
|
|
68
|
-
required: 'Es requerido',
|
|
69
|
-
numeric: 'Debe ser numérico válido',
|
|
70
|
-
min: `Valor mínimo permitido: ${control.errors['min']?.min}`,
|
|
71
|
-
minValue: 'Debe ser positivo',
|
|
72
|
-
minlength: `Mínimo ${control.errors['minlength']?.requiredLength} caracteres.`,
|
|
73
|
-
maxlength: `Caracteres ${control.errors['maxlength']?.actualLength}/${control.errors['maxlength']?.requiredLength}`,
|
|
74
|
-
email: 'No se cumple con el formato de Correo Electrónico',
|
|
75
|
-
isNumeric: 'Debe seleccionar una opción',
|
|
76
|
-
hasNumber: 'Se requiere al menos un número',
|
|
77
|
-
hasCapitalCase: 'Se requiere al menos una mayúscula',
|
|
78
|
-
hasSmallCase: 'Se requiere al menos una minúscula',
|
|
79
|
-
hasSpecialCharacters: 'Se requiere al menos un carácter especial',
|
|
80
|
-
NoPassswordMatch: 'La contraseña no coincide',
|
|
81
|
-
itemSelected: 'Debe seleccionar una opción de la lista',
|
|
82
|
-
inputMask: 'El formato ingresado no es válido',
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// Devuelve el primer mensaje de error encontrado
|
|
86
|
-
for (const errorKey of Object.keys(control.errors)) {
|
|
87
|
-
if (errorMessages[errorKey]) {
|
|
88
|
-
return errorMessages[errorKey];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Si el error tiene un mensaje personalizado, usarlo
|
|
93
|
-
return control.errors[Object.keys(control.errors)[0]]?.message || '';
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function toFormData<T extends Record<string, any>>(formValue: T): FormData {
|
|
97
|
-
const formData = new FormData();
|
|
98
|
-
|
|
99
|
-
Object.keys(formValue).forEach((key) => {
|
|
100
|
-
const value = formValue[key];
|
|
101
|
-
|
|
102
|
-
if (value === null || value === undefined) {
|
|
103
|
-
return; // Ignorar valores nulos o indefinidos
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (Array.isArray(value)) {
|
|
107
|
-
value.forEach((item, index) => {
|
|
108
|
-
if (typeof item === 'object' && item !== null) {
|
|
109
|
-
if ('file' in item) {
|
|
110
|
-
formData.append(`${key}[${index}]`, item.file);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
formData.append(`${key}[${index}]`, JSON.stringify(item));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
formData.append(`${key}[${index}]`, item.toString());
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
else if (typeof value === 'object') {
|
|
122
|
-
// Si es un objeto (pero no un array), convertirlo a JSON
|
|
123
|
-
formData.append(key, JSON.stringify(value));
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
// Para valores primitivos (string, number, boolean)
|
|
127
|
-
formData.append(key, value.toString());
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
return formData;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function markAsTouchedWithoutEmitEvent(control: AbstractControl): void {
|
|
135
|
-
if (control instanceof FormControl) {
|
|
136
|
-
control.markAsTouched({onlySelf: true});
|
|
137
|
-
control.updateValueAndValidity({emitEvent: false});
|
|
138
|
-
}
|
|
139
|
-
else if (control instanceof FormGroup || control instanceof FormArray) {
|
|
140
|
-
Object.values(control.controls).forEach(childControl => {
|
|
141
|
-
markAsTouchedWithoutEmitEvent(childControl);
|
|
142
|
-
});
|
|
143
|
-
control.updateValueAndValidity({emitEvent: false});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import {HttpErrorResponse} from '@angular/common/http';
|
|
2
|
-
import {mensajeAlerta, mensajeToast} from './sweetalert';
|
|
3
|
-
|
|
4
|
-
export function mensajesDeError(error: HttpErrorResponse, toast = false) {
|
|
5
|
-
let msg;
|
|
6
|
-
|
|
7
|
-
if (error.error && error.error instanceof ArrayBuffer) {
|
|
8
|
-
const msgArrayBuffer = (arrayBuffer: ArrayBuffer): string => {
|
|
9
|
-
try {
|
|
10
|
-
const mensajeError = JSON.parse(new TextDecoder("utf-8").decode(arrayBuffer));
|
|
11
|
-
return mensajeError.message || 'Error desconocido';
|
|
12
|
-
} catch (parseError) {
|
|
13
|
-
console.error('Error al analizar la respuesta JSON:', parseError);
|
|
14
|
-
return 'Error al analizar la respuesta JSON';
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
msg = msgArrayBuffer(error.error);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
|
|
21
|
-
switch (error.status) {
|
|
22
|
-
case 0:
|
|
23
|
-
// msg = error.message;
|
|
24
|
-
msg = 'El servidor no responde, verifica tu conexion a la red';
|
|
25
|
-
console.log(error);
|
|
26
|
-
break;
|
|
27
|
-
case 401:
|
|
28
|
-
if (error.error && typeof error.error == 'object') {
|
|
29
|
-
if (error.error.message) {
|
|
30
|
-
msg = error.error.message;
|
|
31
|
-
}
|
|
32
|
-
else if (error.error.error) {
|
|
33
|
-
msg = error.error.error;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
msg = JSON.stringify(error.error);
|
|
37
|
-
console.log(error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else if (error.error && typeof error.error == 'string') {
|
|
41
|
-
msg = error.error;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
msg = 'Acceso no autorizado';
|
|
45
|
-
console.log(error);
|
|
46
|
-
}
|
|
47
|
-
break;
|
|
48
|
-
case 422:
|
|
49
|
-
let strEr = '';
|
|
50
|
-
|
|
51
|
-
console.log(typeof error.error.errors);
|
|
52
|
-
console.log(error.error.errors);
|
|
53
|
-
if (error.error.errors) {
|
|
54
|
-
Object.keys(error.error.errors).forEach(o => {
|
|
55
|
-
strEr += '<li>' + error.error.errors[o][0] + '</li>';
|
|
56
|
-
});
|
|
57
|
-
msg = (error.error.message ?? '') + '<ul>' + strEr + '</ul>';
|
|
58
|
-
}
|
|
59
|
-
else if (error.error.error) {
|
|
60
|
-
msg = error.error.msg;
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
case 429:
|
|
64
|
-
case 400:
|
|
65
|
-
case 500:
|
|
66
|
-
case 503:
|
|
67
|
-
msg = error.error.message;
|
|
68
|
-
break;
|
|
69
|
-
case 504:
|
|
70
|
-
msg = 'No se puede conectar al servidor. Comprueba tu conexion a la red - ' + error.statusText;
|
|
71
|
-
break;
|
|
72
|
-
default:
|
|
73
|
-
msg = error?.error?.message ?? 'Error de Sistema';
|
|
74
|
-
console.log(error);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (!msg) {
|
|
79
|
-
msg = error.statusText ?? 'Error inesperado o datos inexistentes.';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let tituloFinal = 'Error!';
|
|
83
|
-
let mensajeFinal;
|
|
84
|
-
|
|
85
|
-
if (msg.includes('Hmac::doVerify')) {
|
|
86
|
-
console.log(error, msg);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
else if (msg == 'Server Error') {
|
|
90
|
-
console.log(error, msg);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
else if (msg.includes('[IMSSP]')) {
|
|
94
|
-
mensajeFinal = 'Error en consulta de registros.';
|
|
95
|
-
}
|
|
96
|
-
else if (msg.includes('Tiempo de espera de la')) {
|
|
97
|
-
mensajeFinal = 'Hubo un error en la solicitud de datos, por favor actualice (SHIFT + F5)';
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
mensajeFinal = msg;
|
|
101
|
-
}
|
|
102
|
-
if (toast) {
|
|
103
|
-
mensajeToast('error', tituloFinal, mensajeFinal);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
mensajeAlerta('error', tituloFinal, mensajeFinal);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
throw new Error(mensajeFinal);
|
|
110
|
-
}
|
package/src/functions/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './public-api'
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import moment from 'moment';
|
|
2
|
-
import {jwtDecode} from 'jwt-decode';
|
|
3
|
-
|
|
4
|
-
export interface JwtTokenResponse {
|
|
5
|
-
access_token: string;
|
|
6
|
-
expires_in: number;
|
|
7
|
-
token_type: string;
|
|
8
|
-
user: any;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface DataSessionStorage {
|
|
12
|
-
tokenStringKey?: string;
|
|
13
|
-
changePasswordKey?: string;
|
|
14
|
-
logoUrl?: string;
|
|
15
|
-
logoLogin?: string;
|
|
16
|
-
backgroundLogin?: string;
|
|
17
|
-
favicon?: string;
|
|
18
|
-
darkMode?: string;
|
|
19
|
-
serverTimestamp?: string;
|
|
20
|
-
apiDataKey?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let dataSessionStorageKey: DataSessionStorage = {
|
|
24
|
-
tokenStringKey: 'JVSoftTkn',
|
|
25
|
-
changePasswordKey: 'chPwd',
|
|
26
|
-
logoUrl: 'logo_url',
|
|
27
|
-
logoLogin: 'login-logo',
|
|
28
|
-
backgroundLogin: 'login-background',
|
|
29
|
-
favicon: 'favicon',
|
|
30
|
-
darkMode: 'darkMode',
|
|
31
|
-
serverTimestamp: 'srvtmstp',
|
|
32
|
-
apiDataKey: 'reqDt',
|
|
33
|
-
};
|
|
34
|
-
export let localStorageKeys = dataSessionStorageKey;
|
|
35
|
-
|
|
36
|
-
export function inicializarVariablesSessionStorage(datSesion: DataSessionStorage) {
|
|
37
|
-
dataSessionStorageKey = datSesion;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function setJwtTokenData(data: string) {
|
|
41
|
-
localStorage.setItem(<string>dataSessionStorageKey.tokenStringKey, data)
|
|
42
|
-
}
|
|
43
|
-
export function jwtTokenData(key: string = <string>dataSessionStorageKey.tokenStringKey): JwtTokenResponse | null {
|
|
44
|
-
const tokenObj = localStorage.getItem(key);
|
|
45
|
-
try {
|
|
46
|
-
return JSON.parse(<string>tokenObj) as JwtTokenResponse;
|
|
47
|
-
} catch (error) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function jwtToken(key: string = <string>dataSessionStorageKey.tokenStringKey) {
|
|
53
|
-
const varJwtTokenData = jwtTokenData(key);
|
|
54
|
-
if (varJwtTokenData) {
|
|
55
|
-
return varJwtTokenData.access_token;
|
|
56
|
-
}
|
|
57
|
-
return '';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function jwtTokenExpiracion(key: string = <string>dataSessionStorageKey.tokenStringKey) {
|
|
61
|
-
const jwtStr = jwtToken(key);
|
|
62
|
-
if (!jwtStr) return null;
|
|
63
|
-
try {
|
|
64
|
-
const decodedToken: any = jwtDecode(jwtStr);
|
|
65
|
-
return decodedToken.exp ? decodedToken.exp * 1000:null; // Convertir a milisegundos
|
|
66
|
-
} catch (e) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function jwtTokenExpiracionFaltante() {
|
|
72
|
-
return Math.abs(moment().diff(jwtTokenExpiracion(), 'seconds'));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function setCambiarPwd(accion: boolean = true) {
|
|
76
|
-
localStorage.setItem(<string>dataSessionStorageKey.changePasswordKey, (accion ? 1:0).toString())
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function getCambiarPwd() {
|
|
80
|
-
const frmCambioPwd = localStorage.getItem(<string>dataSessionStorageKey.changePasswordKey);
|
|
81
|
-
if (!frmCambioPwd) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
return frmCambioPwd == '1';
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function delLocalStorage(keyElim: string[] = [
|
|
88
|
-
<string>dataSessionStorageKey.tokenStringKey,
|
|
89
|
-
<string>dataSessionStorageKey.changePasswordKey,
|
|
90
|
-
<string>dataSessionStorageKey.apiDataKey,
|
|
91
|
-
]) {
|
|
92
|
-
keyElim.forEach(key => {
|
|
93
|
-
localStorage.removeItem(key);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function getLocalStorage(key: string | undefined) {
|
|
98
|
-
return localStorage.getItem(<string>key);
|
|
99
|
-
}
|
|
100
|
-
export function setLocalStorage(key: string, value = '') {
|
|
101
|
-
localStorage.setItem(key, value.toString())
|
|
102
|
-
}
|