Plugin
Minimal Backend Plugin
Example plugin showing manifest data and a simple register function that hooks hub events.
plugin.js — Example plugin
module.exports = {
id: 'hello-plugin',
manifest: {
pluginId: 'hello-plugin',
displayName: 'Hello Plugin',
requiredCoreVersion: '^0.1.0',
hubEvents: ['device.registered', 'room.created'],
licenseFeatures: ['hello-plugin/basic'] // requires this feature to work
},
async register(ctx) {
const { router, logger, hub, db, kv, config, license } = ctx;
// Simple route
router.get('/', (req, res) => res.send('Hello'));
// Use the KV store (key-value, per-device, TTL support)
router.post('/store/:deviceId', async (req, res) => {
await kv.set(req.params.deviceId, 'my-key', JSON.stringify(req.body));
res.json({ stored: true });
});
// Use the database adapter (supports SQLite and Postgres)
router.post('/save', async (req, res) => {
try {
await db.query('INSERT INTO my_table (data) VALUES (?)', [JSON.stringify(req.body)]);
res.json({ ok: true });
} catch (err) {
logger.error({ err }, 'db error');
res.status(500).json({ error: err.message });
}
});
// Listen to hub events
hub.on('device.registered', (payload) => {
logger.info({ payload }, 'device registered in hub');
});
hub.on('room.created', (payload) => {
logger.info({ payload }, 'room created');
});
}
};
ctx.router— Express Router (mount your routes here)ctx.logger— Pino logger instance (with redaction)ctx.hub— Event emitter for Hub lifecycle eventsctx.kv— Key-value store with TTL (per-device scoped)ctx.db— Database adapter (SQLite or Postgres)ctx.config— Plugin configuration from manifestctx.license— License checker (feature access)ctx.metrics— Metrics recorder for monitoring
{
"name": "hello-plugin",
"version": "0.1.0",
"epheme": {
"pluginId": "hello-plugin",
"displayName": "Hello Plugin",
"requiredCoreVersion": "^0.1.0",
"licenseFeatures": ["hello-plugin/basic"]
}
}