Custom widgets
A custom widget is a static browser bundle that renders on the dashboard inside a sandboxed iframe and talks to the host only by message passing. This page covers the sandbox, the manifest, the SDK, distribution, and the gallery that browses and installs them.
The sandbox is the entire trust boundary
sandbox="allow-scripts" — allow-same-origin is deliberately withheld
sandbox allow-scripts; default-src 'none'; script-src 'self' <bundle hashes>; style-src 'unsafe-inline'; connect-src 'self'
The iframe attribute and the runtime page's own sandbox directive say the same thing, so the runtime URL opened
outside its frame (a new tab, a link) still runs in an opaque origin, without the user's session. The SDK needs
nothing more: it talks to the host only by postMessage to its parent.
Widgets are not plugins. A plugin is an in-process assembly with no runtime sandbox, which is why plugins are signed and trusted per publisher. A widget is contained by the browser, so widgets have no per-widget trust badges, certification tiers or signing.
| Rule | Detail |
|---|---|
| A widget never receives the user's token | All host communication is message passing. |
| A widget may only touch devices explicitly bound to it in the dashboard configuration | The host bridge checks every action and every subscription against those bindings. |
| The sandbox is never relaxed for preview | Preview mounts the production runtime with a flag, using the identical sandbox attribute and policy. |
| The installed runtime policy never permits inline script |
Repositories carry a trust level (trusted, shown as Verified in the API, community or local). It only drives the
warning shown at install and is not a security control. The sandbox is. A repository a resource index creates is trusted when that index is the official one
(the host's built-in official index URL) and community otherwise; each sync of the index sets it again. A repository an
administrator added before an index listed it keeps the trust level the administrator chose.
Manifest
{
"id": "energy-flow", "version": "2.1.0", "displayName": "Energy Flow",
"description": "Visualises energy flows between sources, batteries and loads.",
"category": "Energy", "tags": ["energy", "solar"], "author": "<author>",
"minBackendVersion": "1.0.0", "screenshots": ["screenshots/overview.png"],
"changelogUrl": "CHANGELOG.md", "entry": "dist/energy-flow.js",
"configSchema": { "type": "object", "properties": {
"title": { "type": "string", "default": "My Light" },
"refreshInterval": { "type": "number", "minimum": 10, "default": 60 } } },
"dataBindings": [{ "name": "mainDevice", "type": "Device", "required": true }],
"capabilities": ["realtime", "action-execute"]
}
id, version and displayName are required; everything else is optional. category accepts any string — unlisted
ones group under "Other". minBackendVersion drives a compatibility chip in the gallery. screenshots are relative
paths inside the bundle; the first is the card thumbnail.
The host generates the configuration form from configSchema (JSON Schema draft 7). Custom formats render dedicated
pickers: device-id, room-id, color, duration. Each dataBindings entry renders a picker filtered by the
capabilities it requires.
A manifest is capped at 100 entries, and every bundle file, screenshots included, at one mebibyte. The checksum covers all declared bundle bytes in declaration order. A mismatch marks the entry tampered and blocks install.
SDK
| Call | Behaviour |
|---|---|
onConfig(cb) |
Receive the configuration, bindings merged in. It is delivered once per load: when the configuration or a binding changes, the host reloads the widget, which starts again with the new values and subscribes afresh. |
subscribe(deviceId, capability, cb) |
Realtime state changes, checked against the bindings. |
callAction(deviceId, action, params) |
Write to a bound device. A write to a critical capability waits for the resident to confirm it in the host; declined, it rejects and nothing is sent. |
queryHistory(deviceId, capability, range) |
Historical telemetry. range is an optional { fromUtc?, toUtc?, limit? } window; resolves to { deviceId, fromUtc, toUtc, telemetry[], stateEvents[] }. |
log(level, message) |
Send a line to the host console. |
Every action key must be a real canonical controllable capability key. It becomes the property key on the write, and
the backend rejects anything else. params is either an object (the full property map, which is how composite writes
are expressed), a scalar (the value for action) or omitted (a bare actuation). A literal action property is never
sent on the wire.
In preview, the bridge intercepts every SDK call at the persistence boundary, blocks state mutation, and returns placeholder data so an author can check layout without hardware.
Distribution
A widget repository ships through exactly one of two channels.
| Provider | Layout | Integrity |
|---|---|---|
Oci |
Bundle files as a tar layer; the manifest lives in the registry config blob. Reference is <registry>/<repo>:<tag>. |
The layer digest. No separate signature. |
Release |
A hosted-Git release whose assets include a tar bundle plus the manifest asset reeve-widget.json (the file name the sync requires). The newest release syncs. |
The asset checksum. |
Widgets come only from repositories. There is no URL-paste import and no in-app widget authoring. A custom widget on a dashboard always points at an installation, and a stored widget that names none renders as not set up.
A repository may reference a stored credential for a private source. The token is encrypted at rest, never returned by any API, and attached only to requests whose host belongs to that repository; cross-host redirects drop the header.
On sync the bundle is pulled, extracted in memory with path-traversal and decompressed-size guards, and materialised into object storage. On install the bundle files, the manifest and the bundle list are copied into the installation, and the installed runtime and its configuration form are served from that copy, so a later sync of the repository never changes a widget that is already installed. Install copies only the files the release's bundle list names. A source carries one widget, so when a sync finds a different widget id there, the repository's cache drops the widget it served before: the gallery stops offering it, and its installations keep running their own copy.
Update (POST /api/widgets/installed/{installationId}/update, the Update button on the Installed page once an
update check found one) rewrites the installation with the release the repository lists now, the same way install
copies it, and deletes the installation's files that release no longer lists. The installation keeps its id, so every
dashboard that uses the widget shows the new release with no change to the dashboard. It is refused with 409
widget.update.not-listed when the repository's last sync did not find the widget (the installed release stays), and with 409
widget.update.up-to-date when the installation already runs the listed release. An update that fails part way can
leave files of both releases; run it again.
An installation belongs to the household. Its manifest, runtime and bundle files are served to every signed-in user,
so a widget on a shared dashboard renders for each viewer. Browsing, previewing, installing, uninstalling, updating
and update checks need the widgets.install permission, and whoever holds it sees, update-checks, updates and
uninstalls every installation, not only the ones they made. A dashboard editor (dashboards.edit) reads the
installed widgets to place them without that permission. What a widget reaches is still decided per viewer: the host
bridge acts with the viewer's own session, so a bound device that viewer may not see gives the widget nothing.
Gallery
The gallery reads the synced repository cache, not installations, so an operator sees every widget from every synced
repository including ones not yet installed. Install counts are computed at query time from the live installation
table. All gallery pages and endpoints require the widgets.install permission.
| Route | Purpose |
|---|---|
/app/widgets/gallery |
Paged card gallery with search, category, repository and compatibility filters |
/app/widgets/gallery/:repositoryId/:widgetId |
Screenshots, compatibility, manifest, preview, install |
/app/widgets/installed |
The household's installed widgets with per-row uninstall, update check and update |
| Method | Path |
|---|---|
| GET | /api/widgets/gallery and /api/widgets/gallery/{repoId}/{widgetId} |
| POST / DELETE | /api/widgets/gallery/{repoId}/{widgetId}/preview and /api/widgets/gallery/preview/{sessionId} |
| POST | /api/widgets/gallery/{repoId}/{widgetId}/install |
| GET | /api/widgets/installed |
| DELETE | /api/widgets/installed/{installationId} (permission widgets.install) |
| POST | /api/widgets/installed/{installationId}/check-updates and /api/widgets/installed/{installationId}/update |
Read by a dashboard editor (dashboards.edit) to place an installed widget: GET /api/widgets/installed/choices, each
installation's id, repository, widget id, display name (from the installation's own manifest copy) and installed version.
Served to every signed-in user, for rendering an installed widget:
| Method | Path |
|---|---|
| GET | /api/widgets/installed/{installationId}/manifest |
| GET | /api/widgets/installed/{installationId}/runtime.html and /api/widgets/installed/{installationId}/files/{fileName} |
Preview sessions live in Redis only. No installation row is written, and the iframe's file requests are served by whichever replica they reach. A session has a time-to-live that Redis enforces, so the store stays bounded even when a caller never returns, and a per-user cap evicts the oldest session when it is exceeded.
Audit events are widget.installed, widget.updated (with the versions before and after) and widget.uninstalled. Browsing the gallery, previewing and checking for updates write no row.
{ "Widgets": { "GalleryPageSize": 30, "PreviewSessionTtlMinutes": 15, "MaxPreviewSessionsPerUser": 5 } }
The values shown are the defaults. GalleryPageSize accepts 1 to 200 and PreviewSessionTtlMinutes 1 to 120.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| A widget write is rejected by the backend | The action key is not a real canonical controllable capability key. |
| A widget action or subscription silently does nothing | The device is not among the widget's dashboard data bindings. The host bridge checks every call. |
| A widget cannot be installed and is marked tampered | The bundle bytes do not match the declared checksum, which covers all declared files in declaration order. |
| A screenshot never appears | It exceeded the per-file size limit at sync time, or the path is not relative to the bundle. |
The credential header of a repository is sent only to the provider's own host.