fpavon-ee-shared 1.0.7 → 1.0.8

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,4 @@
1
- export declare const validarToken: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1
+ export declare const validarToken: (req: Request, res: Response, next: NextFunction) => void;
2
2
  export declare const extraerNivel: (data: any) => number;
3
3
  export declare const cifrado: (usuario: any) => Promise<unknown>;
4
4
  export declare const descifrarToken: (token: string) => any;
@@ -16,7 +16,10 @@ exports.obtenerUnidadPadre = exports.unidadesJoinFuncion = exports.getChildrenUn
16
16
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
17
  const connection_sql_1 = require("../bd/connection.sql"); // Asegúrate de ajustar la ruta a tu configuración de base de datos
18
18
  const axios_1 = __importDefault(require("axios"));
19
- const validarToken = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const asyncMiddlewareWrapper = (fn) => (req, res, next) => {
20
+ Promise.resolve(fn(req, res, next)).catch(next);
21
+ };
22
+ exports.validarToken = asyncMiddlewareWrapper((req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
20
23
  try {
21
24
  const bearerHeader = req.header('Authorization') || "";
22
25
  if (bearerHeader !== "") {
@@ -91,8 +94,7 @@ const validarToken = (req, res, next) => __awaiter(void 0, void 0, void 0, funct
91
94
  res.status(401).json({ status: false, mensaje: "token inválido" });
92
95
  return; // Terminar ejecución pero sin retornar res
93
96
  }
94
- });
95
- exports.validarToken = validarToken;
97
+ }));
96
98
  const extraerNivel = (data) => {
97
99
  let nivel = 0;
98
100
  data.forEach(element => {
@@ -3,7 +3,11 @@ import 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
 
6
- export const validarToken = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
6
+ const asyncMiddlewareWrapper = (fn) => (req: Request, res: Response, next: NextFunction) => {
7
+ Promise.resolve(fn(req, res, next)).catch(next);
8
+ };
9
+
10
+ export const validarToken = asyncMiddlewareWrapper(async (req: Request, res: Response, next: NextFunction): Promise<void> => {
7
11
  try {
8
12
  const bearerHeader = req.header('Authorization') || "";
9
13
 
@@ -87,7 +91,7 @@ export const validarToken = async (req: Request, res: Response, next: NextFuncti
87
91
  res.status(401).json({ status: false, mensaje: "token inválido" });
88
92
  return; // Terminar ejecución pero sin retornar res
89
93
  }
90
- };
94
+ })
91
95
 
92
96
 
93
97
  export const extraerNivel = (data)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fpavon-ee-shared",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Carpeta compartida entre servicios de Expediente Electronio",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",