@univ-lehavre/atlas-net ​
Network diagnostic utilities for Atlas, built with Effect.
About ​
This package provides typed and functional network diagnostic tools for Atlas applications. It is used by CLI tools to verify connectivity to REDCap servers and other services.
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 ​
bash
pnpm add @univ-lehavre/atlas-net effectUsage ​
typescript
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 ​
typescript
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.
typescript
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 ​
typescript
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
See ​
README.md for full documentation
Interfaces ​
| Interface | Description |
|---|---|
| DiagnosticResult | Aggregated result of multiple diagnostic steps. |
| DiagnosticStep | Result of a single diagnostic step. |
| TcpPingOptions | Options for TCP ping operation. |
| TlsHandshakeOptions | Options for TLS handshake operation. |
Type Aliases ​
| Type Alias | Description |
|---|---|
| DiagnosticStatus | Status of a diagnostic step. |
| Host | Union type for host parameter. Accepts either a Hostname or IpAddress branded type. Used in function signatures that accept both hostnames and IP addresses. |
| Hostname | Branded type for hostnames. Validates according to RFC 1123. Also accepts valid IP addresses. |
| IpAddress | Branded type for IP addresses. Accepts valid IPv4 (e.g., '192.168.1.1') or IPv6 (e.g., '::1') addresses. |
| Port | Branded type for port numbers. Valid range: 1 to 65535. |
| SafeApiUrl | Branded type for safe API URLs. |
| TimeoutMs | Branded type for timeout values in milliseconds. Valid range: 0 to 600000 (10 minutes). |
Variables ​
| Variable | Description |
|---|---|
| DEFAULT_INTERNET_CHECK_TIMEOUT_MS | Default timeout for internet connectivity checks in milliseconds. |
| DEFAULT_TCP_TIMEOUT_MS | Default timeout for TCP connections in milliseconds. |
| DEFAULT_TLS_TIMEOUT_MS | Default timeout for TLS handshakes in milliseconds. |
| Hostname | Constructor for Hostname branded type with validation. |
| HTTPS_PORT | Standard HTTPS port. |
| INTERNET_CHECK_HOST | Host used for internet connectivity checks (Cloudflare DNS). |
| IpAddress | Constructor for IpAddress branded type with validation. |
| Port | Constructor for Port branded type with validation. |
| SafeApiUrl | Constructor for SafeApiUrl branded type with validation. |
| TimeoutMs | Constructor for TimeoutMs branded type with validation. |
Functions ​
| Function | Description |
|---|---|
| checkInternet | Checks basic internet connectivity by pinging Cloudflare's DNS server. |
| dnsResolve | Resolves a hostname to an IP address using DNS lookup. |
| tcpPing | Tests TCP connectivity to a host and port. |
| tlsHandshake | Tests TLS/SSL connectivity and validates the server certificate. |
References ​
HostnameType ​
Renames and re-exports Hostname
IpAddressType ​
Renames and re-exports IpAddress
PortType ​
Renames and re-exports Port
SafeApiUrlType ​
Renames and re-exports SafeApiUrl
TimeoutMsType ​
Renames and re-exports TimeoutMs