Appearance
Module Reference
Detailed reference for each module in the shared library.
db.ts — Database
SQLite initialization and migration system.
| Export | Description |
|---|---|
db_start(db_path, config) | Create/open SQLite database, enable WAL, run migrations |
db_sensor_start(db_path) | Create/open sensor database with sensor_data table |
Migrations are loaded from server/migrations/ in development or from migration_embeds in production builds.
http.ts — HTTP Server
Bun HTTP server and WebSocket setup.
| Export | Description |
|---|---|
http_start(port, routes, ws_callbacks) | Start Bun.serve with HTTP routes and WebSocket handlers |
Handles OPTIONS preflight requests, WebSocket upgrades, and message parsing with HttpWsMessageSchema.
mqtt.ts — MQTT Client
MQTT broker client for receiving beacon and gateway data.
| Export | Description |
|---|---|
mqtt_start(config, callback) | Connect to MQTT broker, subscribe to all topics, process messages |
mqtt_status_get() | Check MQTT connection status |
mqtt_client_get() | Get the MQTT client instance |
Filters beacons by MAC prefix (BC5729, BBCBBC) and parses messages with MqttGatewayMessageSchema.
jose.ts — JWT
JWT key management, signing, and verification.
| Export | Description |
|---|---|
jose_create_keys() | Generate RS256 key pair + JWK/JWKS |
jose_create_key_pair() | Generate raw RS256 key pair |
jose_create_jwt(...) | Sign a JWT for a user |
jose_verify_jwt(req) | Verify JWT from a request's Authorization header |
jose_verify_jwt_admin(req) | Verify JWT and check admin role |
jose_create_random_key() | Generate a random key ID |
rs.ts — Response Helpers
Standard HTTP response constructors with CORS headers.
| Export | Description |
|---|---|
rs_res_ok(data) | 200 JSON response |
rs_res_bad_request(msg) | 400 response |
rs_res_unauthorized(msg) | 401 response |
rs_res_forbidden(msg) | 403 response |
rs_res_not_found(msg) | 404 response |
rs_res_cors_headers() | CORS headers for preflight |
generic.ts — Utilities
Shared utility functions.
| Export | Description |
|---|---|
beacon_validate_uuid(mac) | Validate a beacon MAC address format |
beacon_get_push_type(beacon) | Get the push notification type for a beacon |
beacon_is_pushed(beacon) | Check if a beacon has an active push state |
json_safe_parse(str) | Parse JSON without throwing (returns null on error) |
should_never_happen(msg) | Assertion that throws for impossible states |
is_dev_mode() | Check if running in development mode |
get_root_dir() | Get the project root directory |
kiss.ts — KISS API
Integration with the KISS external API for alarm/convene operations.
| Export | Description |
|---|---|
kiss_login(config) | Authenticate with the KISS API |
kiss_send(config, token, data) | Send a convene/alarm request |
zabbix.ts — Zabbix Sender
Sends monitoring data to a Zabbix server.
| Export | Description |
|---|---|
ZabbixSender class | Connects to Zabbix and sends item data |
beacon.ts — Beacon Utilities
Beacon-specific validation and formatting.
| Export | Description |
|---|---|
beacon_validate_uuid(mac) | Validate beacon MAC format |
beacon_zabbix_hostname(mac) | Generate Zabbix hostname from beacon MAC |
ip.ts — IP Utilities
IP address validation and subnet handling.
server.ts — Server Helpers
Response helpers specific to the server context.
| Export | Description |
|---|---|
getKeyId(keys) | Get key ID from JOSE keys |
addHeaders(response) | Add standard headers to responses |
client.ts — Frontend Helpers
Assertion helpers for the web frontend.
| Export | Description |
|---|---|
assert(condition, msg) | Runtime assertion |
should_never_happen(msg) | Throw for impossible states |
perf.ts — Performance
Performance measurement logging.
log.ts — Logging
Database-backed logging system.