@bereasoftware/nexa 1.2.0 → 1.3.0
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.en.md +179 -335
- package/README.md +177 -22
- package/dist/bereasoftware-nexa-1.3.0.tgz +0 -0
- package/dist/nexa.cjs.js +462 -1
- package/dist/nexa.cjs.js.map +1 -1
- package/dist/nexa.es.js +1103 -890
- package/dist/nexa.es.js.map +1 -1
- package/dist/nexa.iife.js +462 -1
- package/dist/nexa.iife.js.map +1 -1
- package/dist/nexa.umd.js +462 -1
- package/dist/nexa.umd.js.map +1 -1
- package/dist/types/dev-overlay/index.d.ts +15 -0
- package/dist/types/dev-overlay/overlay.d.ts +26 -0
- package/dist/types/dev-overlay/tracker.d.ts +16 -0
- package/dist/types/dev-overlay/types.d.ts +33 -0
- package/dist/types/http-client/http-client.d.ts +51 -23
- package/dist/types/http-client/index.d.ts +2 -2
- package/dist/types/http-client/node-http-adapter.d.ts +7 -2
- package/dist/types/index.d.ts +6 -3
- package/dist/types/realtime/plugin.d.ts +5 -1
- package/dist/types/realtime/sse-client.d.ts +4 -1
- package/dist/types/realtime/websocket-client.d.ts +4 -1
- package/dist/types/types/index.d.ts +50 -44
- package/dist/types/utils/index.d.ts +7 -71
- package/package.json +31 -25
- package/dist/bereasoftware-nexa-1.2.0.tgz +0 -0
- package/dist/types/testing/index.d.ts +0 -5
- package/dist/types/testing/mock-client.d.ts +0 -152
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
+
<img src="src/assets/Logo.png" alt="Nexa Logo" />
|
|
2
3
|
<h1 align="center">@bereasoftware/nexa</h1>
|
|
3
4
|
<p align="center">
|
|
4
5
|
Un cliente HTTP moderno y type-safe que combina el poder de <code>fetch</code> con la comodidad de <code>axios</code> — construido sobre principios SOLID.
|
|
@@ -6,15 +7,16 @@
|
|
|
6
7
|
</p>
|
|
7
8
|
|
|
8
9
|
<p align="center">
|
|
9
|
-
<a href="#tests"><img src="https://img.shields.io/badge/Tests-
|
|
10
|
-
<a href="#test-coverage"><img src="https://img.shields.io/badge/Coverage-
|
|
10
|
+
<a href="#tests"><img src="https://img.shields.io/badge/Tests-213_pasando-brightgreen?style=for-the-badge" alt="Tests" /></a>
|
|
11
|
+
<a href="#test-coverage"><img src="https://img.shields.io/badge/Coverage-Ver_reporte-orange?style=for-the-badge" alt="Coverage" /></a>
|
|
11
12
|
<a href="https://www.npmjs.com/package/@bereasoftware/nexa"><img src="https://img.shields.io/npm/v/@bereasoftware/nexa?style=for-the-badge" alt="NPM Version" /></a>
|
|
12
13
|
<a href="https://bundlephobia.com/package/@bereasoftware/nexa"><img src="https://img.shields.io/bundlephobia/minzip/@bereasoftware/nexa?label=Bundle&style=for-the-badge" alt="Bundle Size" /></a>
|
|
13
14
|
<a href="https://www.npmjs.com/package/@bereasoftware/nexa"><img src="https://img.shields.io/npm/dm/@bereasoftware/nexa?style=for-the-badge" alt="NPM Downloads" /></a>
|
|
14
15
|
<img src="https://img.shields.io/badge/Node-20%2B-success?style=for-the-badge" alt="Node" />
|
|
15
|
-
<img src="https://img.shields.io/badge/TypeScript-
|
|
16
|
+
<img src="https://img.shields.io/badge/TypeScript-6.x-3178C6?style=for-the-badge" alt="TypeScript" />
|
|
16
17
|
<img src="https://img.shields.io/badge/Dependencias-Cero-brightgreen?style=for-the-badge" alt="Dependencies" />
|
|
17
18
|
<a href="LICENSE"><img src="https://img.shields.io/badge/Licencia-MIT-yellow?style=for-the-badge" alt="License" /></a>
|
|
19
|
+
<img src="https://img.shields.io/badge/Mantenimiento-Activo-success?style=for-the-badge" alt="Maintenance" />
|
|
18
20
|
<a href="https://github.com/Berea-Soft/nexa"><img src="https://img.shields.io/badge/github-Repositorio-blue?logo=github&style=for-the-badge" alt="Repository" /></a>
|
|
19
21
|
</p>
|
|
20
22
|
|
|
@@ -23,6 +25,16 @@
|
|
|
23
25
|
> - 🇪🇸 **Español** (este archivo - README.md)
|
|
24
26
|
> - 🇬🇧 **English** (README.en.md)
|
|
25
27
|
|
|
28
|
+
> 📖 **Documentación adicional:**
|
|
29
|
+
>
|
|
30
|
+
> - [Arquitectura](ARCHITECTURE.md) — Diseño del sistema
|
|
31
|
+
> - [Diseño](DESIGN.md) — Filosofía y decisiones de diseño
|
|
32
|
+
> - [Seguridad](SECURITY.md) — Política de seguridad
|
|
33
|
+
> - [Contribuir](CONTRIBUTING.md) — Guía para colaboradores
|
|
34
|
+
> - [Migración](MIGRATION.md) — Desde axios/fetch
|
|
35
|
+
> - [Soporte](SUPPORT.md) — Cómo obtener ayuda
|
|
36
|
+
> - [Skills](SKILLS.md) — Competencias del proyecto
|
|
37
|
+
|
|
26
38
|
---
|
|
27
39
|
|
|
28
40
|
## ¿Por qué Nexa?
|
|
@@ -48,18 +60,11 @@
|
|
|
48
60
|
| Validadores y transformadores | ❌ | ❌ | ✅ |
|
|
49
61
|
| Tracking de duración de respuesta | ❌ | ❌ | ✅ |
|
|
50
62
|
| Detección inteligente de tipo de respuesta | ❌ | ✅ | ✅ |
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
| Timeouts diferenciados (conexión vs respuesta) | ❌ | ❌ | ✅ |
|
|
57
|
-
| Logging de debug (modo desarrollo) | ❌ | ❌ | ✅ |
|
|
58
|
-
| WebSocket/SSE con reconexión automática | ❌ | ❌ | ✅ |
|
|
59
|
-
| Rate limiting integrado | ❌ | ❌ | ✅ |
|
|
60
|
-
| Circuit breaker para fallos en cascada | ❌ | ❌ | ✅ |
|
|
61
|
-
| Adaptadores multi-entorno (Node, Deno, Bun, Cloudflare) | ❌ | ❌ | ✅ |
|
|
62
|
-
| Tree-shakeable | ✅ | ❌ | ✅ |
|
|
63
|
+
| WebSocket/SSE con reconexión automática | ❌ | ❌ | ✅ |
|
|
64
|
+
| Rate limiting integrado | ❌ | ❌ | ✅ |
|
|
65
|
+
| Circuit breaker para fallos en cascada | ❌ | ❌ | ✅ |
|
|
66
|
+
| Tree-shakeable | ✅ | ❌ | ✅ |
|
|
67
|
+
| Dev Overlay (herramientas de desarrollo) | ❌ | ❌ | ✅ |
|
|
63
68
|
|
|
64
69
|
---
|
|
65
70
|
|
|
@@ -103,6 +108,7 @@
|
|
|
103
108
|
- [Transformadores](#transformadores)
|
|
104
109
|
- [Pipeline de Middleware](#pipeline-de-middleware)
|
|
105
110
|
- [Sistema de Plugins](#sistema-de-plugins)
|
|
111
|
+
- [Dev Overlay](#dev-overlay)
|
|
106
112
|
- [Streaming](#streaming)
|
|
107
113
|
- [Generics Tipados](#generics-tipados)
|
|
108
114
|
- [Manejo de Errores](#manejo-de-errores)
|
|
@@ -225,10 +231,12 @@ const client = createHttpClient({
|
|
|
225
231
|
| `maxConcurrent` | `number` | `0` (ilimitado) | Máximo de peticiones concurrentes |
|
|
226
232
|
| `defaultResponseType` | `ResponseType` | `'auto'` | Estrategia de parseo de respuesta por defecto |
|
|
227
233
|
| `defaultHooks` | `RequestHooks` | `{}` | Hooks de ciclo de vida por defecto para todas las peticiones |
|
|
228
|
-
| `debug` | `boolean \| 'verbose'` | `undefined` | Habilita logging de debug para requests/responses. `true` para logs básicos, `'verbose'` para logs detallados. |
|
|
229
|
-
| `logger` | `(message: string, data?: unknown) => void` | `undefined` | Función de logging personalizada. Si se proporciona, reemplaza el console.log por defecto con logging personalizado. |
|
|
230
|
-
|
|
231
|
-
|
|
234
|
+
| `debug` | `boolean \| 'verbose'` | `undefined` | Habilita logging de debug para requests/responses. `true` para logs básicos, `'verbose'` para logs detallados. |
|
|
235
|
+
| `logger` | `(message: string, data?: unknown) => void` | `undefined` | Función de logging personalizada. Si se proporciona, reemplaza el console.log por defecto con logging personalizado. |
|
|
236
|
+
|
|
237
|
+
**Nota:** Las opciones avanzadas `transformRequest`, `credentials`, `withCredentials`, `debug`, `logger`, `transport`, `nodeOptions` y `autoFormData` ya están tipadas, pero no todas están completamente integradas en el pipeline principal de `HttpClient` en esta versión. Úsalas con validación manual hasta que se cierre esa integración.
|
|
238
|
+
|
|
239
|
+
---
|
|
232
240
|
|
|
233
241
|
## Métodos HTTP
|
|
234
242
|
|
|
@@ -362,7 +370,7 @@ await client.post('/api', data, { withCredentials: true });
|
|
|
362
370
|
|
|
363
371
|
// Configuración global
|
|
364
372
|
const client = createHttpClient({
|
|
365
|
-
credentials: 'same-origin',
|
|
373
|
+
credentials: 'same-origin',
|
|
366
374
|
// o
|
|
367
375
|
withCredentials: true, // Equivalente a credentials: 'include'
|
|
368
376
|
});
|
|
@@ -1283,6 +1291,118 @@ manager.register(rateLimitPlugin);
|
|
|
1283
1291
|
|
|
1284
1292
|
---
|
|
1285
1293
|
|
|
1294
|
+
## Dev Overlay
|
|
1295
|
+
|
|
1296
|
+
Herramienta visual de desarrollo integrada para depurar y monitorear requests HTTP en tiempo real.
|
|
1297
|
+
|
|
1298
|
+
```typescript
|
|
1299
|
+
import { createHttpClient, createDevOverlay } from "@bereasoftware/nexa";
|
|
1300
|
+
|
|
1301
|
+
// Crear el Dev Overlay - aparece automáticamente
|
|
1302
|
+
const { tracker, ui } = createDevOverlay({
|
|
1303
|
+
position: "bottom-right", // top-right, top-left, bottom-left
|
|
1304
|
+
theme: "dark",
|
|
1305
|
+
maxHistory: 200,
|
|
1306
|
+
});
|
|
1307
|
+
|
|
1308
|
+
// Pasar el tracker al cliente HTTP
|
|
1309
|
+
const client = createHttpClient({
|
|
1310
|
+
baseURL: "https://api.example.com",
|
|
1311
|
+
devTracker: tracker,
|
|
1312
|
+
});
|
|
1313
|
+
|
|
1314
|
+
// ¡Listo! Todas las requests aparecerán en el overlay
|
|
1315
|
+
const result = await client.get("/users");
|
|
1316
|
+
```
|
|
1317
|
+
|
|
1318
|
+
### Características
|
|
1319
|
+
|
|
1320
|
+
- **Toggle con teclado** — Presiona `Ctrl+Shift+N` o `Cmd+Shift+N` para mostrar/ocultar
|
|
1321
|
+
- **Lista de requests** — Muestra método, status, URL, duración y badges (cache, retries)
|
|
1322
|
+
- **Métricas en tiempo real** — Total requests, promedio, throughput, éxitos y fallos
|
|
1323
|
+
- **Búsqueda y filtro** — Filtra por URL, método o status (`Ctrl+F`)
|
|
1324
|
+
- **Detalle de request** — Click en cualquier request para ver headers, body y timing
|
|
1325
|
+
- **Retry rápido** — Reejecuta la URL seleccionada con `fetch` para una verificación rápida
|
|
1326
|
+
- **Keyboard shortcuts** — `Ctrl+Shift+N` / `Cmd+Shift+N` (toggle), `Escape` (cerrar), `Ctrl+F` / `Cmd+F` (buscar)
|
|
1327
|
+
|
|
1328
|
+
### API
|
|
1329
|
+
|
|
1330
|
+
```typescript
|
|
1331
|
+
createDevOverlay(config?: DevOverlayConfig): { tracker: RequestTracker; ui: DevOverlayUI }
|
|
1332
|
+
```
|
|
1333
|
+
|
|
1334
|
+
**Opciones de configuración:**
|
|
1335
|
+
|
|
1336
|
+
| Opción | Tipo | Por defecto | Descripción |
|
|
1337
|
+
|--------|------|-------------|-------------|
|
|
1338
|
+
| `enabled` | `boolean` | `true` | Flag de configuración almacenado por el tracker para habilitar o deshabilitar el overlay desde tu flujo |
|
|
1339
|
+
| `position` | `'top-right' \| 'top-left' \| 'bottom-right' \| 'bottom-left'` | `'bottom-right'` | Posición del overlay |
|
|
1340
|
+
| `theme` | `'dark' \| 'light'` | `'dark'` | Tema visual tipado; la UI actual está optimizada para el tema oscuro |
|
|
1341
|
+
| `maxHistory` | `number` | `500` |Máximo de requests en historial |
|
|
1342
|
+
| `keyboardShortcut` | `string` | `'ctrl+shift+n'` | Atajo de teclado |
|
|
1343
|
+
|
|
1344
|
+
**Notas de comportamiento:**
|
|
1345
|
+
|
|
1346
|
+
- `createDevOverlay()` es singleton. Si lo llamas varias veces, reutiliza la misma instancia.
|
|
1347
|
+
- `theme` está tipado como `'dark' | 'light'`, pero la UI actual está diseñada principalmente para tema oscuro.
|
|
1348
|
+
- El botón de retry del panel usa `fetch()` directo para revalidación rápida; no reaplica automáticamente interceptores ni configuración avanzada del `HttpClient`.
|
|
1349
|
+
|
|
1350
|
+
**Métodos del UI:**
|
|
1351
|
+
|
|
1352
|
+
```typescript
|
|
1353
|
+
ui.show() // Mostrar overlay
|
|
1354
|
+
ui.hide() // Ocultar overlay
|
|
1355
|
+
ui.toggle() // Alternar visibilidad
|
|
1356
|
+
ui.destroy() // Desmontar el panel del DOM
|
|
1357
|
+
|
|
1358
|
+
tracker.clear() // Limpiar historial
|
|
1359
|
+
tracker.getHistory() // Obtener todos los requests
|
|
1360
|
+
tracker.getMetrics() // Obtener métricas
|
|
1361
|
+
tracker.getConfig() // Obtener configuración resuelta
|
|
1362
|
+
tracker.onChange((request) => {}) // Escuchar nuevos requests
|
|
1363
|
+
```
|
|
1364
|
+
|
|
1365
|
+
**Métodos del módulo:**
|
|
1366
|
+
|
|
1367
|
+
```typescript
|
|
1368
|
+
getDevOverlay() // Obtener { tracker, ui } actuales o null si no existen
|
|
1369
|
+
destroyDevOverlay() // Destruir la instancia singleton actual
|
|
1370
|
+
```
|
|
1371
|
+
|
|
1372
|
+
**Estructuras expuestas:**
|
|
1373
|
+
|
|
1374
|
+
```typescript
|
|
1375
|
+
type TrackedRequest = {
|
|
1376
|
+
id: string;
|
|
1377
|
+
method: string;
|
|
1378
|
+
url: string;
|
|
1379
|
+
status?: number;
|
|
1380
|
+
duration: number;
|
|
1381
|
+
timestamp: number;
|
|
1382
|
+
cached: boolean;
|
|
1383
|
+
ok: boolean;
|
|
1384
|
+
code?: string;
|
|
1385
|
+
headers: Record<string, string>;
|
|
1386
|
+
body?: unknown;
|
|
1387
|
+
responseHeaders?: Record<string, string>;
|
|
1388
|
+
retryCount: number;
|
|
1389
|
+
};
|
|
1390
|
+
|
|
1391
|
+
type DevMetrics = {
|
|
1392
|
+
totalRequests: number;
|
|
1393
|
+
successfulRequests: number;
|
|
1394
|
+
failedRequests: number;
|
|
1395
|
+
cachedRequests: number;
|
|
1396
|
+
avgDuration: number;
|
|
1397
|
+
maxDuration: number;
|
|
1398
|
+
minDuration: number;
|
|
1399
|
+
requestsPerSecond: number;
|
|
1400
|
+
slowestRequests: TrackedRequest[];
|
|
1401
|
+
};
|
|
1402
|
+
```
|
|
1403
|
+
|
|
1404
|
+
---
|
|
1405
|
+
|
|
1286
1406
|
## Streaming
|
|
1287
1407
|
|
|
1288
1408
|
Maneja archivos grandes y respuestas streaming:
|
|
@@ -1433,7 +1553,7 @@ deferred.reject(new Error("falló"));
|
|
|
1433
1553
|
|
|
1434
1554
|
### Contexto de Error Enriquecido
|
|
1435
1555
|
|
|
1436
|
-
|
|
1556
|
+
`HttpErrorDetails` incluye campos opcionales para `request`, `response` y `config`, pero en esta versión no todos los caminos de error los rellenan de forma consistente. Úsalos como metadatos opcionales, no como garantía fuerte.
|
|
1437
1557
|
|
|
1438
1558
|
```typescript
|
|
1439
1559
|
const result = await client.get('/api');
|
|
@@ -1445,7 +1565,7 @@ if (!result.ok) {
|
|
|
1445
1565
|
}
|
|
1446
1566
|
```
|
|
1447
1567
|
|
|
1448
|
-
|
|
1568
|
+
Si necesitas ese contexto en todos los errores, conviene complementarlo temporalmente con hooks o interceptores propios.
|
|
1449
1569
|
|
|
1450
1570
|
### Clase HttpError
|
|
1451
1571
|
|
|
@@ -1570,10 +1690,29 @@ npm run test:watch
|
|
|
1570
1690
|
|
|
1571
1691
|
# Test coverage
|
|
1572
1692
|
npm run test:coverage
|
|
1693
|
+
|
|
1694
|
+
# UI de tests
|
|
1695
|
+
npm run test:ui
|
|
1573
1696
|
```
|
|
1574
1697
|
|
|
1575
1698
|
Los tests usan **Vitest** (globals mode) con BDD style (`describe`/`it`/`expect`).
|
|
1576
1699
|
|
|
1700
|
+
### Linting y Formato
|
|
1701
|
+
|
|
1702
|
+
```bash
|
|
1703
|
+
# Verificar tipo
|
|
1704
|
+
npm run lint
|
|
1705
|
+
|
|
1706
|
+
# Corregir errores de estilo
|
|
1707
|
+
npm run lint:fix
|
|
1708
|
+
|
|
1709
|
+
# Formatear código
|
|
1710
|
+
npm run format
|
|
1711
|
+
|
|
1712
|
+
# Verificar formato
|
|
1713
|
+
npm run format:check
|
|
1714
|
+
```
|
|
1715
|
+
|
|
1577
1716
|
### Build
|
|
1578
1717
|
|
|
1579
1718
|
```bash
|
|
@@ -1600,6 +1739,22 @@ dist/
|
|
|
1600
1739
|
└── types/ (Tipo definitivo .d.ts)
|
|
1601
1740
|
```
|
|
1602
1741
|
|
|
1742
|
+
### Benchmark
|
|
1743
|
+
|
|
1744
|
+
```bash
|
|
1745
|
+
# Ejecutar benchmark de performance
|
|
1746
|
+
npm run benchmark
|
|
1747
|
+
```
|
|
1748
|
+
|
|
1749
|
+
### Ejemplos
|
|
1750
|
+
|
|
1751
|
+
Ver la carpeta `examples/` para ejemplos de uso con diferentes frameworks:
|
|
1752
|
+
|
|
1753
|
+
- `react-example.ts` — Uso con React
|
|
1754
|
+
- `vue-example.ts` — Uso con Vue
|
|
1755
|
+
- `svelte-example.ts` — Uso con Svelte
|
|
1756
|
+
- `node-example.ts` — Uso con Node.js
|
|
1757
|
+
|
|
1603
1758
|
### Cobertura de Tests
|
|
1604
1759
|
|
|
1605
1760
|
**Cobertura General: 71.4%** — sólida cobertura de tests unitarios con mocking HTTP
|
|
Binary file
|