fpavon-ee-shared 1.0.60 → 1.0.62
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/dist/documentos/domain/firma/firma.interface.d.ts +4 -0
- package/dist/documentos/domain/firma/firma.interface.js +2 -0
- package/dist/documentos/infrastructure/index.d.ts +1 -0
- package/dist/documentos/infrastructure/index.js +1 -0
- package/dist/documentos/infrastructure/services/firmaService.d.ts +8 -0
- package/dist/documentos/infrastructure/services/firmaService.js +41 -0
- package/documentos/domain/firma/firma.interface.ts +3 -0
- package/documentos/infrastructure/index.ts +2 -1
- package/documentos/infrastructure/services/firmaService.ts +33 -0
- package/package.json +1 -1
- package/readme.md +200 -0
- package/dist/documentos/application/streamConversor.js +0 -14
- package/dist/infrastructure/fileServer/fileServer.connection.d.ts +0 -8
- package/dist/infrastructure/fileServer/fileServer.connection.js +0 -94
- package/dist/infrastructure/middlewares/middleware.deslogueo.d.ts +0 -0
- package/dist/infrastructure/middlewares/middleware.deslogueo.js +0 -1
|
@@ -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;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './repository';
|
|
1
|
+
export * from './repository';
|
|
2
|
+
export * from './services/firmaService';
|
|
@@ -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
package/readme.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# 📦 Publicación de paquetes en npm (con 2FA)
|
|
2
|
+
|
|
3
|
+
Este documento explica cómo publicar paquetes en npm cuando la cuenta tiene **autenticación en dos factores (2FA)** habilitada, incluyendo el flujo completo de trabajo.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# 🚀 Flujo completo para publicar una nueva versión
|
|
8
|
+
|
|
9
|
+
## 1. ✏️ Actualizar versión
|
|
10
|
+
|
|
11
|
+
Modificar la versión actual por la nueva en `package.json`:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"version": "1.0.62"
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
📌 Seguir semver:
|
|
20
|
+
|
|
21
|
+
* `patch` → fixes (1.0.61 → 1.0.62)
|
|
22
|
+
* `minor` → features (1.0.x → 1.1.0)
|
|
23
|
+
* `major` → breaking changes
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 2. 📤 Subir cambios al repositorio
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
git add .
|
|
31
|
+
git commit -m "chore: bump version to 1.0.62"
|
|
32
|
+
git push
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
👉 Esto asegura trazabilidad antes de publicar
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 3. 🏗️ Build del paquete
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm run build
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
👉 Genera los archivos que realmente se publican (ej: `/dist`)
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 4. 📦 Publicar en npm
|
|
50
|
+
|
|
51
|
+
### Opción A — Con OTP
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm publish --otp=123456
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Opción B — Con token (recomendado)
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm publish
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
# 🔐 Configuración de 2FA
|
|
66
|
+
|
|
67
|
+
## Problema común
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm ERR! 403 Forbidden - Two-factor authentication required
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
👉 npm exige 2FA también al publicar
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## ✅ Soluciones
|
|
78
|
+
|
|
79
|
+
### 🥇 Usar OTP
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm publish --otp=123456
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### 🥈 Usar token con bypass 2FA (recomendado)
|
|
88
|
+
|
|
89
|
+
#### 1. Crear token
|
|
90
|
+
|
|
91
|
+
https://www.npmjs.com/settings/tokens
|
|
92
|
+
|
|
93
|
+
* Tipo: **Automation**
|
|
94
|
+
* Con **Bypass 2FA** activado
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
#### 2. Configurar en local
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm config set //registry.npmjs.org/:_authToken=TU_TOKEN
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
#### 3. Publicar
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
npm publish
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
# 🔍 Verificaciones útiles
|
|
115
|
+
|
|
116
|
+
### Usuario actual
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npm whoami
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Registry
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npm config get registry
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Debe ser:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
https://registry.npmjs.org/
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
# 🧠 Problemas comunes
|
|
137
|
+
|
|
138
|
+
### ❌ Error 404
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
Not found - PUT https://registry.npmjs.org/paquete
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
* No tienes permisos
|
|
145
|
+
* El nombre ya existe
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
### ❌ Error 403
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
2FA required
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
* Usar `--otp`
|
|
156
|
+
* o token con bypass 2FA
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
### ⚠️ Warning config
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
Unknown user config "config"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
👉 No bloquea publicación
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
# 🚀 Recomendación
|
|
171
|
+
|
|
172
|
+
👉 Usar **token con bypass 2FA**
|
|
173
|
+
Evita tener que ingresar OTP cada vez.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
# 📌 Resumen rápido
|
|
178
|
+
|
|
179
|
+
| Paso | Acción |
|
|
180
|
+
| ---- | ------------------------------- |
|
|
181
|
+
| 1 | Subir versión en `package.json` |
|
|
182
|
+
| 2 | Commit + push |
|
|
183
|
+
| 3 | `npm run build` |
|
|
184
|
+
| 4 | `npm publish` |
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
# 🛠️ Comandos clave
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
npm login
|
|
192
|
+
npm whoami
|
|
193
|
+
npm run build
|
|
194
|
+
npm publish
|
|
195
|
+
npm publish --otp=XXXXXX
|
|
196
|
+
npm config set //registry.npmjs.org/:_authToken=TOKEN
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
@@ -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;
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|