@gnpdev/rpa-tools 1.0.12 → 1.0.14
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/README.md +13 -5
- package/package.json +1 -1
- package/src/index.d.ts +17 -8
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ Crea un archivo en tu proyecto (ej. `src/lib/rpa.js`) para inicializar y exporta
|
|
|
23
23
|
// src/lib/rpa.js
|
|
24
24
|
import { createRpaTools } from '@gnpdev/rpa-tools';
|
|
25
25
|
import { Pool } from 'pg';
|
|
26
|
+
import * as dotenv from 'dotenv';
|
|
27
|
+
dotenv.config();
|
|
26
28
|
|
|
27
29
|
// 1. Configura tu pool de base de datos (usualmente ya lo tienes)
|
|
28
30
|
const pool = new Pool({
|
|
@@ -47,7 +49,14 @@ export const rpa = await createRpaTools({
|
|
|
47
49
|
}
|
|
48
50
|
})
|
|
49
51
|
|
|
52
|
+
// 3. Exporta el objeto Logger
|
|
50
53
|
export const logger = rpa.logger;
|
|
54
|
+
|
|
55
|
+
// 4. Genera el objeto de estado para cambio de Paso a paso
|
|
56
|
+
export const state = {
|
|
57
|
+
currentStep: 'Inicio'
|
|
58
|
+
};
|
|
59
|
+
|
|
51
60
|
```
|
|
52
61
|
|
|
53
62
|
## Uso en la Aplicación
|
|
@@ -104,7 +113,7 @@ Captura el estado completo del bot cuando ocurre una excepción: Screenshot (.we
|
|
|
104
113
|
|
|
105
114
|
```javascript
|
|
106
115
|
import { chromium } from 'playwright';
|
|
107
|
-
import { rpa, logger } from './lib/rpa.js';
|
|
116
|
+
import { rpa, logger, state } from './lib/rpa.js';
|
|
108
117
|
|
|
109
118
|
const browser = await chromium.launch({ headless: true });
|
|
110
119
|
const context = await browser.newContext();
|
|
@@ -118,16 +127,15 @@ const page = await context.newPage();
|
|
|
118
127
|
snapshots: true,
|
|
119
128
|
});
|
|
120
129
|
|
|
121
|
-
let currentStep = 'Inicio';
|
|
122
130
|
|
|
123
131
|
try {
|
|
124
132
|
// Lógica de tu bot...
|
|
125
133
|
await page.goto('https://example.com');
|
|
126
134
|
|
|
127
|
-
currentStep = 'Login';
|
|
135
|
+
state.currentStep = 'Login';
|
|
128
136
|
await login(page);
|
|
129
137
|
|
|
130
|
-
currentStep = 'Procesar Datos';
|
|
138
|
+
state.currentStep = 'Procesar Datos';
|
|
131
139
|
await page.click('#boton-inexistente');
|
|
132
140
|
} catch (err) {
|
|
133
141
|
// Captura automática de evidencia
|
|
@@ -135,7 +143,7 @@ try {
|
|
|
135
143
|
page,
|
|
136
144
|
context,
|
|
137
145
|
err,
|
|
138
|
-
step: currentStep
|
|
146
|
+
step: state.currentStep
|
|
139
147
|
});
|
|
140
148
|
|
|
141
149
|
logger.error({ errorId, step: currentStep }, 'Fallo crítico capturado');
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -57,6 +57,22 @@ export interface RpaTools {
|
|
|
57
57
|
*/
|
|
58
58
|
watchDebugFlag: (page: Page, pollMs?: number) => void;
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Recupera credenciales de una aplicación desde la base de datos.
|
|
62
|
+
* @param nombre - Nombre de la aplicación (ej. 'Portal CRM')
|
|
63
|
+
*/
|
|
64
|
+
getCredentials: (nombre: string) => Promise<{ usuario: string; password: string; idUsuario: string } | null>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Captura screenshot, trace y registra error en base de datos.
|
|
68
|
+
*/
|
|
69
|
+
captureError: (params: {
|
|
70
|
+
page: Page;
|
|
71
|
+
context: any;
|
|
72
|
+
err: Error;
|
|
73
|
+
step?: string;
|
|
74
|
+
}) => Promise<{ errorId: number | null; screenshotKey: string | null; traceKey: string | null }>;
|
|
75
|
+
|
|
60
76
|
/** Detiene todos los intervalos. Llamar siempre al cerrar el bot. */
|
|
61
77
|
destroy: () => void;
|
|
62
78
|
}
|
|
@@ -64,12 +80,5 @@ export interface RpaTools {
|
|
|
64
80
|
// ── Export principal ─────────────────────────────────────────────────────────
|
|
65
81
|
/**
|
|
66
82
|
* Inicializa la librería rpa-tools.
|
|
67
|
-
* Crea el cliente MinIO, verifica el bucket y retorna
|
|
68
|
-
* el logger y el watcher listos para usar.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* const rpa = await createRpaTools({ botId: 'bot-001', db: pool });
|
|
72
|
-
* rpa.watchDebugFlag(page);
|
|
73
|
-
* rpa.logger.info('Bot iniciado');
|
|
74
83
|
*/
|
|
75
|
-
export function createRpaTools(options: RpaToolsOptions): Promise<RpaTools>;
|
|
84
|
+
export function createRpaTools(options: RpaToolsOptions): Promise<RpaTools>;
|