fpavon-ee-shared 1.0.21 → 1.0.22
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.
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -13,18 +36,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
36
|
};
|
|
14
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
38
|
exports.obtenerUnidadPadre = exports.unidadesJoinFuncion = exports.getChildrenUnitIds = exports.getGerencia = exports.getChildrenLabelNumbers = exports.descifrarToken = exports.cifrado = exports.extraerNivel = exports.validarToken = void 0;
|
|
16
|
-
const
|
|
39
|
+
const jwt = __importStar(require("jsonwebtoken"));
|
|
17
40
|
const connection_sql_1 = require("../bd/connection.sql"); // Asegúrate de ajustar la ruta a tu configuración de base de datos
|
|
18
41
|
const axios_1 = __importDefault(require("axios"));
|
|
19
42
|
function getSecret() {
|
|
20
43
|
let secretString = process.env.SECRET;
|
|
21
44
|
if (!secretString) {
|
|
22
|
-
console.error("ERROR: La variable de entorno 'SECRET' no está configurada.");
|
|
23
45
|
throw new Error("SECRET_NOT_CONFIGURED");
|
|
24
46
|
}
|
|
25
|
-
// 1. Limpia
|
|
47
|
+
// 1. Limpia el string de cualquier carácter invisible o espacio
|
|
26
48
|
secretString = secretString.trim();
|
|
27
|
-
// 2.
|
|
49
|
+
// 2. Convierte a Buffer binario, forzando la codificación UTF-8
|
|
28
50
|
return Buffer.from(secretString, 'utf8');
|
|
29
51
|
}
|
|
30
52
|
const asyncHandlerWrapper = (req, res, next) => {
|
|
@@ -47,7 +69,7 @@ const validarToken = (req, res, next) => __awaiter(void 0, void 0, void 0, funct
|
|
|
47
69
|
token = token.replace(/['"]+/g, '');
|
|
48
70
|
console.error("token: validarToken ", token);
|
|
49
71
|
const secret = getSecret();
|
|
50
|
-
let data =
|
|
72
|
+
let data = jwt.verify(token, secret);
|
|
51
73
|
const { afiliado, idNavegador } = data;
|
|
52
74
|
// Verificar si el usuario está deslogueado
|
|
53
75
|
const queryVerificar = `SELECT logueado, idNavegador FROM Usuarios WHERE afiliado = '${data.afiliado}'`;
|
|
@@ -128,12 +150,10 @@ const extraerNivel = (data) => {
|
|
|
128
150
|
return nivel;
|
|
129
151
|
};
|
|
130
152
|
exports.extraerNivel = extraerNivel;
|
|
131
|
-
//Para generar token que se usará en el front end
|
|
132
153
|
const cifrado = (usuario) => {
|
|
133
|
-
const
|
|
154
|
+
const secretoBuffer = getSecret();
|
|
134
155
|
return new Promise((resolve, reject) => {
|
|
135
|
-
|
|
136
|
-
console.error("token: cifrado ", token);
|
|
156
|
+
jwt.sign(usuario, secretoBuffer, { expiresIn: '12h' }, (err, token) => {
|
|
137
157
|
return err ? reject("no se pudo generar el JWT") : resolve(token);
|
|
138
158
|
});
|
|
139
159
|
});
|
|
@@ -142,7 +162,7 @@ exports.cifrado = cifrado;
|
|
|
142
162
|
const descifrarToken = (token) => {
|
|
143
163
|
token = token.replace(/['"]+/g, '');
|
|
144
164
|
try {
|
|
145
|
-
let data =
|
|
165
|
+
let data = jwt.verify(token, (process.env.SECRET || ''));
|
|
146
166
|
return data;
|
|
147
167
|
}
|
|
148
168
|
catch (error) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction, RequestHandler } from 'express';
|
|
2
|
-
import jwt from 'jsonwebtoken';
|
|
2
|
+
import * as jwt from 'jsonwebtoken';
|
|
3
3
|
import { getConnection } from '../bd/connection.sql'; // Asegúrate de ajustar la ruta a tu configuración de base de datos
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
|
|
@@ -7,14 +7,13 @@ function getSecret(): Buffer {
|
|
|
7
7
|
let secretString = process.env.SECRET;
|
|
8
8
|
|
|
9
9
|
if (!secretString) {
|
|
10
|
-
console.error("ERROR: La variable de entorno 'SECRET' no está configurada.");
|
|
11
10
|
throw new Error("SECRET_NOT_CONFIGURED");
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
// 1. Limpia
|
|
13
|
+
// 1. Limpia el string de cualquier carácter invisible o espacio
|
|
15
14
|
secretString = secretString.trim();
|
|
16
15
|
|
|
17
|
-
// 2.
|
|
16
|
+
// 2. Convierte a Buffer binario, forzando la codificación UTF-8
|
|
18
17
|
return Buffer.from(secretString, 'utf8');
|
|
19
18
|
}
|
|
20
19
|
|
|
@@ -40,6 +39,9 @@ const validarToken = async (req: Request, res: Response, next: NextFunction): Pr
|
|
|
40
39
|
// Limpio el token de comillas por las dudas
|
|
41
40
|
token = token.replace(/['"]+/g, '');
|
|
42
41
|
console.error("token: validarToken ", token)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
43
45
|
|
|
44
46
|
const secret = getSecret();
|
|
45
47
|
let data: any = jwt.verify(token, secret);
|
|
@@ -138,24 +140,14 @@ export const extraerNivel = (data)=>{
|
|
|
138
140
|
|
|
139
141
|
|
|
140
142
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
export const cifrado = (usuario:any)=>{
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const secreto:any= getSecret();
|
|
147
|
-
return new Promise((resolve:any,reject:any)=>{
|
|
148
|
-
|
|
149
|
-
jwt.sign(usuario, secreto ,{expiresIn:'12h'},(err,token)=>{
|
|
150
|
-
console.error("token: cifrado ", token)
|
|
143
|
+
export const cifrado = (usuario: any) => {
|
|
144
|
+
const secretoBuffer: Buffer = getSecret();
|
|
151
145
|
|
|
152
|
-
|
|
146
|
+
return new Promise((resolve: any, reject: any) => {
|
|
147
|
+
jwt.sign(usuario, secretoBuffer, {expiresIn:'12h'}, (err, token) => {
|
|
148
|
+
return err ? reject("no se pudo generar el JWT") : resolve(token);
|
|
153
149
|
});
|
|
154
|
-
|
|
155
150
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
151
|
}
|
|
160
152
|
|
|
161
153
|
export const descifrarToken = (token:string)=>{
|