thomas-fetch
v1.0.1
Published
Cliente HTTP universal para APIs thomas/encrypted con protocolo E2E
Maintainers
Readme
thomas-fetch
Cliente HTTP universal para el protocolo thomas/encrypted E2E.
Abstrae el cifrado/descifrado de peticiones y respuestas en una API equivalente a axios o fetch, pero con protocolo E2E personalizado.
Depende de thomas-encryptation para toda la lógica criptográfica.
Instalación (local)
"thomas-fetch": "file:../thomas-fetch",
"thomas-encryptation": "file:../thomas-encryptation"Uso
createThomasClient (recomendado)
import { createThomasClient } from 'thomas-fetch';
const api = createThomasClient({
publicKey: '-----BEGIN PUBLIC KEY-----\n...', // Clave pública RSA del servidor
baseUrl: 'https://api.fibextelecom.com',
headers: { Authorization: `Bearer ${token}` }, // opcional
});
// POST / PUT / PATCH — cifra el body, descifra la respuesta automáticamente
const user = await api.post('/api/users', { name: 'Steven' });
const item = await api.put('/api/items/1', { status: 'active' });
const update = await api.patch('/api/items/1', { name: 'Nuevo' });
// GET — cifra la respuesta vía header X-Thomas-Response-Key
const config = await api.get('/api/config');
// Control total de opciones por petición
const result = await api.send('/api/upload', payload, {
method: 'POST',
signal: abortController.signal,
headers: { 'X-Custom': 'value' },
});fetchThomas (función directa)
import { fetchThomas } from 'thomas-fetch';
const result = await fetchThomas(
'https://api.example.com/api/users',
{ name: 'Steven', email: '[email protected]' },
{ publicKey: '-----BEGIN PUBLIC KEY-----\n...' },
);Compatibilidad
| Entorno | Soporte | |---|---| | Browser moderno | ✅ | | Node.js ≥ 18 | ✅ | | Cloudflare Workers | ✅ | | Vercel / Netlify Edge | ✅ | | Deno | ✅ |
Dependencias
thomas-encryptation— core criptográfico (local)
