fpavon-ee-shared 1.0.26 → 1.0.28

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,11 +1,7 @@
1
1
  const fs = require('fs');
2
2
  import { PDFDocument, rgb, StandardFonts } from 'pdf-lib';
3
- import * as crypto from 'crypto';
4
3
  import moment from 'moment';
5
- import PDFMerger from 'pdf-merger-js';
6
- import SignPDF from '../domain/SignPDF';
7
4
  import axios from 'axios';
8
- import path from "node:path";
9
5
  import FormData from 'form-data';
10
6
 
11
7
 
@@ -34,27 +30,6 @@ export async function obtenerFirmasDocumento(uuid: string): Promise<any[]> {
34
30
  }
35
31
  }
36
32
 
37
- export async function firmarDocumento(documento: Buffer, firma: any, usuario: any, clave:any): Promise<Buffer> {
38
-
39
- const bytes = await addSignPage(usuario);
40
- // Crear un PDF con la firma digital y el documento original
41
- var merger = new PDFMerger();
42
- await merger.add(documento);
43
- await merger.add(await Buffer.from(bytes))
44
-
45
- const documentoFirmado = await merger.saveAsBuffer();
46
- // const documentoFirmado = bytes;
47
-
48
- // return documentoFirmado;
49
- const pdfBuffer = new SignPDF(
50
- documentoFirmado,
51
- path.resolve(firma.path)
52
- );
53
-
54
- const signedDocs = await pdfBuffer.signPDF(clave);
55
- return signedDocs;
56
- }
57
-
58
33
  export async function firmarDocumento2(token:string, uuid:any, firma: any, clave:any, x1:any, y1:any, page:any): Promise<string> {
59
34
  let form = new FormData;
60
35
  console.log("UUID: ", uuid);
@@ -1,4 +1,2 @@
1
- /// <reference types="node" />
2
1
  export declare function obtenerFirmasDocumento(uuid: string): Promise<any[]>;
3
- export declare function firmarDocumento(documento: Buffer, firma: any, usuario: any, clave: any): Promise<Buffer>;
4
2
  export declare function firmarDocumento2(token: string, uuid: any, firma: any, clave: any, x1: any, y1: any, page: any): Promise<string>;
@@ -12,14 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.firmarDocumento2 = exports.firmarDocumento = exports.obtenerFirmasDocumento = void 0;
15
+ exports.firmarDocumento2 = exports.obtenerFirmasDocumento = void 0;
16
16
  const fs = require('fs');
17
17
  const pdf_lib_1 = require("pdf-lib");
18
18
  const moment_1 = __importDefault(require("moment"));
19
- const pdf_merger_js_1 = __importDefault(require("pdf-merger-js"));
20
- const SignPDF_1 = __importDefault(require("../domain/SignPDF"));
21
19
  const axios_1 = __importDefault(require("axios"));
22
- const node_path_1 = __importDefault(require("node:path"));
23
20
  const form_data_1 = __importDefault(require("form-data"));
24
21
  function obtenerFirmasDocumento(uuid) {
25
22
  var _a;
@@ -51,22 +48,6 @@ function obtenerFirmasDocumento(uuid) {
51
48
  });
52
49
  }
53
50
  exports.obtenerFirmasDocumento = obtenerFirmasDocumento;
54
- function firmarDocumento(documento, firma, usuario, clave) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const bytes = yield addSignPage(usuario);
57
- // Crear un PDF con la firma digital y el documento original
58
- var merger = new pdf_merger_js_1.default();
59
- yield merger.add(documento);
60
- yield merger.add(yield Buffer.from(bytes));
61
- const documentoFirmado = yield merger.saveAsBuffer();
62
- // const documentoFirmado = bytes;
63
- // return documentoFirmado;
64
- const pdfBuffer = new SignPDF_1.default(documentoFirmado, node_path_1.default.resolve(firma.path));
65
- const signedDocs = yield pdfBuffer.signPDF(clave);
66
- return signedDocs;
67
- });
68
- }
69
- exports.firmarDocumento = firmarDocumento;
70
51
  function firmarDocumento2(token, uuid, firma, clave, x1, y1, page) {
71
52
  return __awaiter(this, void 0, void 0, function* () {
72
53
  let form = new form_data_1.default;
@@ -2,5 +2,5 @@ import { FlujosUseCase } from "../../application/flujos.useCase";
2
2
  export declare class FlujosController {
3
3
  private readonly flujosUseCase;
4
4
  constructor(flujosUseCase: FlujosUseCase);
5
- getFlujoByModulo: (req: Request, res: Response) => Promise<void>;
5
+ getFlujoByModulo: (req: ExRequest, res: ExResponse, next: NextFunction) => Promise<void>;
6
6
  }
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // En FlujosController.ts
2
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
5
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -13,7 +14,9 @@ exports.FlujosController = void 0;
13
14
  class FlujosController {
14
15
  constructor(flujosUseCase) {
15
16
  this.flujosUseCase = flujosUseCase;
16
- this.getFlujoByModulo = (req, res) => __awaiter(this, void 0, void 0, function* () {
17
+ // 3. Modifica la firma para usar los tipos renombrados e incluir next
18
+ this.getFlujoByModulo = (req, res, next // Aunque no se usa, asegura la compatibilidad con el tipo RequestHandler
19
+ ) => __awaiter(this, void 0, void 0, function* () {
17
20
  try {
18
21
  const modulo = req.params.modulo;
19
22
  const flujo = yield this.flujosUseCase.getFlujoByModulo(modulo);
@@ -25,6 +28,7 @@ class FlujosController {
25
28
  }
26
29
  }
27
30
  catch (error) {
31
+ // Si usas un async wrapper, puedes quitar el try/catch y hacer: next(error)
28
32
  console.error("FlujosController.getFlujoByModulo", error);
29
33
  res.status(500).send('Error interno del servidor al obtener el flujo por módulo');
30
34
  }
@@ -14,37 +14,5 @@ const flujo = dependency_injection_1.default.get('EE.Flujos.infrastructure.Flujo
14
14
  /**
15
15
  * Routes
16
16
  */
17
- /**
18
- * @openapi
19
- * /caratulas:
20
- * post:
21
- * summary: Crea una nueva caratula y genera el pdf del formulario correspondiente
22
- * description: Crea una nueva caratula y genera el pdf del formulario correspondiente
23
- * operationId: post caratulas
24
- * tags:
25
- * - Tramites
26
- * requestBody:
27
- * description: Marcadores del pdf a generar y metadatos de una caratula.
28
- * required: true
29
- * content:
30
- * application/json:
31
- * type: object
32
- * schema:
33
- * properties:
34
- * marcadores:
35
- * type: object
36
- * caratula:
37
- * type: object
38
- * responses:
39
- * '200':
40
- * content-disposition: attachment;
41
- * description: Se creo una nueva caratula.
42
- * '400':
43
- * description: Error
44
- * '500':
45
- * description: Error interno
46
- * security:
47
- * - Authentication: []
48
- */
49
17
  route.get('/flujo/:modulo', middleware_auth_1.validarToken, flujo.getFlujoByModulo);
50
18
  exports.default = route;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { ExpedienteElectronico } from '../domain/expediente-electronico.class';
3
2
  import { IExpedienteElectronicoRepository } from '../domain/expediente-electronico.repository';
4
3
  export declare class ExpedienteElectronicoUseCase {
@@ -40,5 +39,5 @@ export declare class ExpedienteElectronicoUseCase {
40
39
  leerNotaUseCase: (idExpediente: any, usuario: any) => Promise<ExpedienteElectronico>;
41
40
  getAllUnidades: () => Promise<string[]>;
42
41
  getUnidadesByUnidad: (unidad: string) => Promise<string[]>;
43
- firmarDocumentoUseCase: (documento: any, usuario: any, firma: any, clave: any) => Promise<Buffer>;
42
+ firmarDocumentoUseCase: (documento: any, usuario: any, firma: any, clave: any) => Promise<string>;
44
43
  }
@@ -1,27 +1,4 @@
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
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -38,7 +15,6 @@ const pagination_sql_1 = require("../../infrastructure/bd/pagination.sql");
38
15
  const middleware_auth_1 = require("../../infrastructure/middlewares/middleware.auth");
39
16
  const notas_class_1 = require("../domain/value-object/notas.class");
40
17
  const axios = require('axios');
41
- const fs = __importStar(require("fs"));
42
18
  class ExpedienteElectronicoUseCase {
43
19
  constructor(expedienteRepo) {
44
20
  this.expedienteRepo = expedienteRepo;
@@ -163,8 +139,8 @@ class ExpedienteElectronicoUseCase {
163
139
  return unidades;
164
140
  });
165
141
  this.firmarDocumentoUseCase = (documento, usuario, firma, clave) => __awaiter(this, void 0, void 0, function* () {
166
- let buffer = fs.readFileSync(documento.path);
167
- return yield (0, digitalSignature_useCase_1.firmarDocumento)(buffer, usuario, firma, clave);
142
+ let buffer = "";
143
+ return yield (0, digitalSignature_useCase_1.firmarDocumento2)(buffer, usuario, firma, clave, 0, 0, 1);
168
144
  });
169
145
  }
170
146
  }
@@ -1,21 +1,35 @@
1
- import { Request, Response, response } from "express";
1
+ // En FlujosController.ts
2
+
3
+ // 1. Importa y usa NextFunction.
4
+ // 2. Renombra Request y Response para forzar a TS a no usar los globales.
5
+ import {
6
+ Request as ExRequest,
7
+ Response as ExResponse,
8
+ NextFunction
9
+ } from "express";
2
10
  import { FlujosUseCase } from "../../application/flujos.useCase";
3
11
 
4
- export class FlujosController{
5
- constructor(private readonly flujosUseCase: FlujosUseCase){}
12
+ export class FlujosController {
13
+     constructor(private readonly flujosUseCase: FlujosUseCase) {}
6
14
 
7
- public getFlujoByModulo = async (req: Request, res: Response): Promise<void> => {
8
- try {
9
- const modulo: string = req.params.modulo;
10
- const flujo = await this.flujosUseCase.getFlujoByModulo(modulo);
11
- if (flujo) {
12
- res.status(200).json(flujo);
13
- } else {
14
- res.status(404).send('Flujo no encontrado para el módulo especificado');
15
- }
16
- } catch (error) {
17
- console.error("FlujosController.getFlujoByModulo", error);
18
- res.status(500).send('Error interno del servidor al obtener el flujo por módulo');
19
- }
20
- };
21
- }
15
+     // 3. Modifica la firma para usar los tipos renombrados e incluir next
16
+     public getFlujoByModulo = async (
17
+ req: ExRequest,
18
+ res: ExResponse,
19
+ next: NextFunction // Aunque no se usa, asegura la compatibilidad con el tipo RequestHandler
20
+ ): Promise<void> => {
21
+         try {
22
+             const modulo: string = req.params.modulo;
23
+             const flujo = await this.flujosUseCase.getFlujoByModulo(modulo);
24
+             if (flujo) {
25
+                 res.status(200).json(flujo);
26
+             } else {
27
+                 res.status(404).send('Flujo no encontrado para el módulo especificado');
28
+             }
29
+         } catch (error) {
30
+             // Si usas un async wrapper, puedes quitar el try/catch y hacer: next(error)
31
+             console.error("FlujosController.getFlujoByModulo", error);
32
+             res.status(500).send('Error interno del servidor al obtener el flujo por módulo');
33
+         }
34
+     };
35
+ }
@@ -14,38 +14,6 @@ const route = Router()
14
14
  /**
15
15
  * Routes
16
16
  */
17
- /**
18
- * @openapi
19
- * /caratulas:
20
- * post:
21
- * summary: Crea una nueva caratula y genera el pdf del formulario correspondiente
22
- * description: Crea una nueva caratula y genera el pdf del formulario correspondiente
23
- * operationId: post caratulas
24
- * tags:
25
- * - Tramites
26
- * requestBody:
27
- * description: Marcadores del pdf a generar y metadatos de una caratula.
28
- * required: true
29
- * content:
30
- * application/json:
31
- * type: object
32
- * schema:
33
- * properties:
34
- * marcadores:
35
- * type: object
36
- * caratula:
37
- * type: object
38
- * responses:
39
- * '200':
40
- * content-disposition: attachment;
41
- * description: Se creo una nueva caratula.
42
- * '400':
43
- * description: Error
44
- * '500':
45
- * description: Error interno
46
- * security:
47
- * - Authentication: []
48
- */
49
17
  route.get('/flujo/:modulo', validarToken, flujo.getFlujoByModulo);
50
18
 
51
19
 
@@ -1,4 +1,4 @@
1
- import { firmarDocumento, firmarDocumento2 } from '../../digitalSignature/application/digitalSignature.useCase';
1
+ import { firmarDocumento2 } from '../../digitalSignature/application/digitalSignature.useCase';
2
2
  import { getPagination } from '../../infrastructure/bd/pagination.sql';
3
3
  import { getChildrenLabelNumbers } from '../../infrastructure/middlewares/middleware.auth';
4
4
  import { ExpedienteElectronico } from '../domain/expediente-electronico.class';
@@ -147,8 +147,8 @@ export class ExpedienteElectronicoUseCase{
147
147
  }
148
148
 
149
149
  public firmarDocumentoUseCase = async (documento, usuario, firma, clave) => {
150
- let buffer = fs.readFileSync(documento.path);
151
- return await firmarDocumento(buffer, usuario, firma, clave);
150
+ let buffer = "";
151
+ return await firmarDocumento2(buffer, usuario, firma, clave, 0, 0, 1);
152
152
  }
153
153
 
154
154
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fpavon-ee-shared",
3
- "version": "1.0.26",
4
- "description": "Carpeta compartida entre servicios de Expediente Electronio",
3
+ "version": "1.0.28",
4
+ "description": "Carpeta compartida entre servicios de Expediente Electronico",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
@@ -28,7 +28,6 @@
28
28
  "node-schedule": "^2.1.1",
29
29
  "node-signpdf": "^3.0.0",
30
30
  "pdf-lib": "^1.17.1",
31
- "pdf-merger-js": "^5.1.1",
32
31
  "socket.io-client": "^4.7.4",
33
32
  "stream-buffers": "^3.0.3",
34
33
  "swagger-jsdoc": "^6.2.8",