@sola-air-ui/relay
v2.0.0
Published
Sola Relay — local data proxy that keeps credentials on-device and streams live data to Sola components
Maintainers
Readme
@sola-air-ui/relay
A local data proxy for Sola AIR's createData/$data primitive. It keeps database credentials on your own machine (or server) instead of shipping them to the browser, and answers Sola components' queries over a local HTTP endpoint.
Install
npm install @sola-air-ui/relayConfigure
The relay reads sola-relay.json from the directory you start it in. Each entry under connections is a name you choose plus its settings:
{
"connections": {
"postgres-primary": { "type": "postgres", "connectionString": "postgres://user:pass@localhost:5432/mydb" },
"orders-db": { "type": "mysql", "host": "localhost", "user": "reader", "password": "…", "database": "shop" }
}
}postgres settings go to pg's Pool, and mysql settings to mysql2's createPool. Give the relay a read-only database user.
Run
npx sola-relay --port 4040--port is the only option (default 4040). The relay serves POST /api/query, GET /api/schema?source=… and GET /api/status, which lists each connection and whether it connected.
Supported data sources
- PostgreSQL (via
pg) - MySQL (via
mysql2) - Google Sheets (
type: "sheet"with asheetId): reads a sheet that is shared publicly, as CSV. - REST table API (
type: "rest-table"): reads, and can update, records through a table-style JSON API. Settings:host(a hostname such asrecords.example.com, or a full URL),table(default table name), and eithertokenorusernameandpassword. Each can come from the environment instead:REST_TABLE_HOST,REST_TABLE_BEARER_TOKEN,REST_TABLE_USERNAME,REST_TABLE_PASSWORD. Queries passtable,query,fieldsandlimitoptions.
Upgrading from 1.x
2.0.0 renames the table connector. Change type from the old vendor-named type (or its short alias) to rest-table, put a full hostname or URL in host, and rename the SN_* environment variables to the REST_TABLE_* names above. A bare instance name no longer gets a vendor domain added. SQL and Google Sheets connections are unchanged.
Usage from a component
<script>
let customers = $data('postgres-primary:customers', { refresh: '30s' });
</script>
<Table rows={() => customers().data} />The source is connection:table. postgres-primary is a name from sola-relay.json, and customers is a table in that database (schema.table works too). Connection names may use letters, digits, _ and -. Table names must be plain identifiers, because they go into the query. With no :table, the connection name is used as the table name. refresh re-runs the query on that interval.
Security note
- SQL connections run a single read-only
SELECT; anything else gets a 400. - Every query is appended to
sola-relay-audit.login the working directory. - The relay has no authentication of its own. Run it somewhere trusted (your dev machine, or a backend service you control), and never expose its port to the public internet without your own auth layer in front of it.
