index ↓
config
client.config Read-only settings the companion app holds for the active webapp. get and list read them,
onChanged reports every write.
requests
you ask, the daemon answers. await the tagged result and check .ok
get(ConfigGet): Promise<TypedRequestResult<ConfigGetReply, never>>
push form: onGet (subscribe instead of awaiting)
Returns one config value for the active webapp.
const res = await client.config.get({ key: '...' });
if (res.ok) {
console.log(res.response.key);
} type Result =
| { ok: true; response: ConfigGetReply }
| { ok: false; kind: 'domain'; error: never }
| { ok: false; kind: 'protocol'; error: WireError }; list(): Promise<TypedRequestResult<ConfigListReply, never>>
push form: onList (subscribe instead of awaiting)
Returns every config value set for the active webapp.
const res = await client.config.list();
if (res.ok) {
console.log(res.response.entries);
} type Result =
| { ok: true; response: ConfigListReply }
| { ok: false; kind: 'domain'; error: never }
| { ok: false; kind: 'protocol'; error: WireError }; events
the daemon pushes these unprompted. subscribing returns an unsubscribe function
onChanged(handler: (ConfigChanged) => void): () => void
const off = client.config.onChanged((configChanged) => {
console.log(configChanged.key);
});
// call off() to unsubscribe types
shapes referenced above, as the sdk types them
type ConfigChanged = {
key: string;
value?: string; // Null when the entry was deleted.
}; Returns one config value for the active webapp.
type ConfigGet = {
key: string;
}; type ConfigGetReply = {
key: string;
value?: string; // Null when the key is unset.
}; type ConfigListReply = {
entries: ConfigEntry[];
}; value is always a string. Parse it by the field's kind; a boolean is "true" or "false".
type ConfigEntry = {
key: string;
value: string;
};