fpavon-ee-shared 1.0.60 → 1.0.61

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.
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ export interface IFirmaService {
3
+ firmarDocumento(blob: Buffer): Promise<Buffer>;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import { IFirmaService } from "../../domain/firma/firma.interface";
3
+ export declare class FirmaService implements IFirmaService {
4
+ private baseUrl;
5
+ private apiKey;
6
+ constructor(baseUrl: string, apiKey: string);
7
+ firmarDocumento(blob: Buffer): Promise<Buffer>;
8
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FirmaService = void 0;
13
+ class FirmaService {
14
+ constructor(baseUrl, apiKey) {
15
+ this.baseUrl = baseUrl;
16
+ this.apiKey = apiKey;
17
+ }
18
+ firmarDocumento(blob) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const base64 = blob.toString('base64');
21
+ const response = yield fetch(`${this.baseUrl}/api/sign`, {
22
+ method: 'POST',
23
+ headers: {
24
+ 'Content-Type': 'application/json',
25
+ 'X-API-Key': this.apiKey,
26
+ },
27
+ body: JSON.stringify({
28
+ pdfBase64: base64,
29
+ appName: 'expedientes-electronicos',
30
+ reason: 'Firma de documento',
31
+ }),
32
+ });
33
+ const data = yield response.json();
34
+ if (!data.success) {
35
+ throw new Error(data.error);
36
+ }
37
+ return Buffer.from(data.signedPdfBase64, 'base64');
38
+ });
39
+ }
40
+ }
41
+ exports.FirmaService = FirmaService;
@@ -0,0 +1,3 @@
1
+ export interface IFirmaService {
2
+ firmarDocumento(blob: Buffer): Promise<Buffer>;
3
+ }
@@ -0,0 +1,33 @@
1
+ import { IFirmaService } from "../../domain/firma/firma.interface";
2
+
3
+ export class FirmaService implements IFirmaService {
4
+ constructor(
5
+ private baseUrl: string,
6
+ private apiKey: string
7
+ ) {}
8
+
9
+ async firmarDocumento(blob: Buffer): Promise<Buffer> {
10
+ const base64 = blob.toString('base64');
11
+
12
+ const response = await fetch(`${this.baseUrl}/api/sign`, {
13
+ method: 'POST',
14
+ headers: {
15
+ 'Content-Type': 'application/json',
16
+ 'X-API-Key': this.apiKey,
17
+ },
18
+ body: JSON.stringify({
19
+ pdfBase64: base64,
20
+ appName: 'expedientes-electronicos',
21
+ reason: 'Firma de documento',
22
+ }),
23
+ });
24
+
25
+ const data = await response.json();
26
+
27
+ if (!data.success) {
28
+ throw new Error(data.error);
29
+ }
30
+
31
+ return Buffer.from(data.signedPdfBase64, 'base64');
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fpavon-ee-shared",
3
- "version": "1.0.60",
3
+ "version": "1.0.61",
4
4
  "description": "Carpeta compartida entre servicios de Expediente Electronico",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertFileToStream = convertFileToStream;
4
- const fs_1 = require("fs");
5
- function convertFileToStream(file) {
6
- console.log(`[MULTI-DOC] Convirtiendo file a stream: ${file.originalFilename || 'unknown'}`);
7
- // Caso 1: File tiene path (multiparty)
8
- if (file.path && typeof file.path === 'string') {
9
- console.log(`[MULTI-DOC] Usando path del file: ${file.path}`);
10
- return (0, fs_1.createReadStream)(file.path, {
11
- highWaterMark: 128 * 1024 // Buffer más pequeño para múltiples archivos
12
- });
13
- }
14
- }
@@ -1,8 +0,0 @@
1
- export declare class FtpConnection {
2
- private client;
3
- constructor();
4
- connect(host: string, user: string, password: string): Promise<void>;
5
- uploadFile(localPath: string, remotePath: string): Promise<void>;
6
- downloadFile(remotePath: string, localPath: string): Promise<void>;
7
- disconnect(): void;
8
- }
@@ -1,94 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.FtpConnection = void 0;
27
- const fs = __importStar(require("fs"));
28
- class FtpConnection {
29
- constructor() {
30
- let Client = require('ftp');
31
- this.client = new Client();
32
- this.client.on('error', (err) => {
33
- console.error('Error en la conexión FTP:', err);
34
- });
35
- }
36
- connect(host, user, password) {
37
- return new Promise((resolve, reject) => {
38
- this.client.on('ready', () => {
39
- console.log('Conexión FTP exitosa');
40
- this.client.list((err, list) => {
41
- if (err)
42
- throw err;
43
- // console.log(list);
44
- this.client.end();
45
- });
46
- resolve();
47
- });
48
- this.client.connect({
49
- host: host,
50
- user: user,
51
- password: password
52
- });
53
- });
54
- }
55
- uploadFile(localPath, remotePath) {
56
- return new Promise((resolve, reject) => {
57
- this.client.put(localPath, remotePath, (err) => {
58
- if (err) {
59
- console.error('Error al subir el archivo:', err);
60
- reject(err);
61
- }
62
- else {
63
- console.log('Archivo subido exitosamente');
64
- resolve();
65
- }
66
- });
67
- });
68
- }
69
- downloadFile(remotePath, localPath) {
70
- console.log('Descargando..');
71
- return new Promise((resolve, reject) => {
72
- this.client.get(remotePath, function (err, stream) {
73
- if (err) {
74
- console.error('Error al descargar el archivo:');
75
- reject(err);
76
- return;
77
- }
78
- stream.once('close', () => {
79
- console.log('Archivo descargado exitosamente');
80
- stream.pipe(fs.createWriteStream(localPath));
81
- resolve();
82
- });
83
- stream.once('end', () => {
84
- console.log('La conexión se cerró sin errores.');
85
- resolve();
86
- });
87
- });
88
- });
89
- }
90
- disconnect() {
91
- this.client.end();
92
- }
93
- }
94
- exports.FtpConnection = FtpConnection;
@@ -1 +0,0 @@
1
- "use strict";