@univ-lehavre/atlas-net
v1.0.4
Published
Network diagnostic utilities for Atlas
Maintainers
Readme
@univ-lehavre/atlas-net
Utilitaires de diagnostic réseau Atlas construits avec Effect.
About
Ce package fournit des types brandés et des fonctions de diagnostic pour tester une cible réseau: résolution DNS, ouverture TCP, négociation TLS et connectivité Internet. Il est consommé par les CLI et services qui doivent expliquer précisément les problèmes d'accès à REDCap ou à d'autres endpoints.
Features
- DNS Resolution: Verify hostname resolution
- TCP Ping: Test if a port is open and accessible
- TLS Handshake: Verify SSL/TLS certificates
- Internet Check: Quick connectivity test
- Branded Types: Typed network values with runtime validation
- Constants: Default timeouts and network configuration
Installation
pnpm add @univ-lehavre/atlas-net effectUsage
import { Effect } from 'effect';
import {
dnsResolve,
tcpPing,
tlsHandshake,
checkInternet,
Hostname,
Port,
} from '@univ-lehavre/atlas-net';
// Check Internet connectivity
const internet = await Effect.runPromise(checkInternet());
console.log(`Internet: ${internet.status}`);
// Resolve a hostname
const hostname = Hostname('example.com');
const dns = await Effect.runPromise(dnsResolve(hostname));
console.log(`DNS: ${dns.status} -> ${dns.message}`);
// Test TCP connection
const port = Port(443);
const tcp = await Effect.runPromise(tcpPing(hostname, port));
console.log(`TCP: ${tcp.status} (${tcp.latencyMs}ms)`);
// Verify TLS certificate
const tls = await Effect.runPromise(tlsHandshake(hostname, port));
console.log(`TLS: ${tls.status} - ${tls.message}`);Complete Diagnostic Pipeline
import { Effect } from 'effect';
import {
dnsResolve,
tcpPing,
tlsHandshake,
checkInternet,
Hostname,
Port,
} from '@univ-lehavre/atlas-net';
const diagnose = (host: Hostname, port: Port) =>
Effect.all([checkInternet(), dnsResolve(host), tcpPing(host, port), tlsHandshake(host, port)]);
const steps = await Effect.runPromise(diagnose(Hostname('example.com'), Port(443)));
steps.forEach((step) => {
console.log(`${step.name}: ${step.status} (${step.latencyMs}ms)`);
});Branded Types
The package provides branded types with runtime validation via Effect's Brand module.
import { Hostname, IpAddress, Port, TimeoutMs, SafeApiUrl } from '@univ-lehavre/atlas-net';
// Create validated values
const hostname = Hostname('example.com'); // Validated hostname (RFC 1123)
const ip = IpAddress('192.168.1.1'); // Validated IPv4 address
const port = Port(8080); // Validated port (1-65535)
const timeout = TimeoutMs(5000); // Validated timeout (0-600000ms)
const url = SafeApiUrl('https://api.example.com/v1/'); // Secure URLAPI
Functions
| Function | Description |
|----------|-------------|
| dnsResolve(hostname) | Resolves a hostname to an IP address |
| tcpPing(host, port, options?) | Tests TCP connectivity |
| tlsHandshake(host, port, options?) | Verifies TLS certificate |
| checkInternet(options?) | Checks Internet connectivity |
Types
| Type | Description |
|------|-------------|
| Hostname | RFC 1123 validated hostname or IP address |
| IpAddress | Validated IPv4 or IPv6 address |
| Port | Port number (1-65535) |
| TimeoutMs | Timeout in milliseconds (0-600000) |
| SafeApiUrl | Secure URL for API communication |
| DiagnosticStep | Result of a diagnostic step |
Constants
import {
DEFAULT_TCP_TIMEOUT_MS, // 3000ms
DEFAULT_TLS_TIMEOUT_MS, // 5000ms
INTERNET_CHECK_HOST, // '1.1.1.1' (Cloudflare DNS)
HTTPS_PORT, // 443
} from '@univ-lehavre/atlas-net';Documentation
Organization
This package is part of Atlas, a set of tools developed by Le Havre Normandie University to facilitate research and collaboration between researchers.
Atlas is developed as part of two projects led by Le Havre Normandie University:
- Campus Polytechnique des Territoires Maritimes et Portuaires: research and training program focused on maritime and port issues
- EUNICoast: European university alliance bringing together institutions located in European coastal areas
License
MIT
