@kiosko/sdk 0.1.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.d.ts +1 -0
- package/dist/context.js +1 -0
- package/dist/http.d.ts +55 -0
- package/dist/http.js +118 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/plugin.d.ts +208 -2
- package/dist/plugin.js +7 -0
- package/dist/schema.d.ts +17 -1
- package/dist/schema.js +4 -4
- package/dist/semver.d.ts +25 -0
- package/dist/semver.js +115 -0
- package/dist/system.d.ts +35 -0
- package/dist/system.js +80 -0
- package/dist/testing.d.ts +86 -0
- package/dist/testing.js +149 -0
- package/package.json +6 -1
- package/src/context.ts +2 -1
- package/src/http.ts +136 -0
- package/src/index.ts +3 -0
- package/src/plugin.ts +206 -2
- package/src/schema.ts +19 -4
- package/src/semver.ts +105 -0
- package/src/system.ts +87 -0
- package/src/testing.ts +192 -0
package/dist/context.d.ts
CHANGED
package/dist/context.js
CHANGED
|
@@ -17,6 +17,7 @@ export function createBaseContext(o) {
|
|
|
17
17
|
fmt: createFormatters({ locale, timeFormat: o.timeFormat ?? 'auto', now: o.now }),
|
|
18
18
|
log: o.log ?? (() => undefined),
|
|
19
19
|
dataDir: o.dataDir ?? '',
|
|
20
|
+
cacheDir: o.cacheDir ?? o.dataDir ?? '',
|
|
20
21
|
...(o.location ? { location: o.location } : {}),
|
|
21
22
|
workday: o.workday ?? DEFAULT_WORKDAY,
|
|
22
23
|
};
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small HTTP client for sources and fetches, so every plugin talks to
|
|
3
|
+
* APIs the same polite way:
|
|
4
|
+
*
|
|
5
|
+
* const http = createHttp({ agent: 'kiosko-plugin-weather/1.2.0' });
|
|
6
|
+
* const { data } = await http.json<Forecast>(url, { signal: ctx.signal });
|
|
7
|
+
*
|
|
8
|
+
* - Conditional requests: it remembers each URL's ETag / Last-Modified and
|
|
9
|
+
* body; a 304 gives the body it had, without downloading it again.
|
|
10
|
+
* - Rate limits: a 429 or 503 with `Retry-After` (or GitHub's
|
|
11
|
+
* `X-RateLimit-Reset`) throws an `HttpError` with `retryAt`, and until
|
|
12
|
+
* then calls to that host fail at once without contacting it.
|
|
13
|
+
* - The caller's `signal` (Kiosko aborts it after the source's timeout).
|
|
14
|
+
* - A User-Agent naming the plugin and Kiosko, never the person.
|
|
15
|
+
*/
|
|
16
|
+
export declare class HttpError extends Error {
|
|
17
|
+
readonly status: number;
|
|
18
|
+
readonly url: string;
|
|
19
|
+
/** When the server says to come back (rate limits), epoch ms. */
|
|
20
|
+
readonly retryAt?: number;
|
|
21
|
+
constructor(message: string, o: {
|
|
22
|
+
status: number;
|
|
23
|
+
url: string;
|
|
24
|
+
retryAt?: number;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export interface HttpRequest {
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
method?: string;
|
|
31
|
+
body?: string;
|
|
32
|
+
/** Don't use or keep the conditional-request cache for this call. */
|
|
33
|
+
noCache?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface HttpResponse<T> {
|
|
36
|
+
data: T;
|
|
37
|
+
status: number;
|
|
38
|
+
/** False when the server said "not modified" and the remembered body was returned. */
|
|
39
|
+
fresh: boolean;
|
|
40
|
+
headers: Headers;
|
|
41
|
+
}
|
|
42
|
+
export interface HttpClient {
|
|
43
|
+
json<T = unknown>(url: string, req?: HttpRequest): Promise<HttpResponse<T>>;
|
|
44
|
+
text(url: string, req?: HttpRequest): Promise<HttpResponse<string>>;
|
|
45
|
+
/** Until when a host is resting because it rate-limited us (epoch ms), if it is. */
|
|
46
|
+
resting(url: string): number | undefined;
|
|
47
|
+
}
|
|
48
|
+
/** How long to wait from the response's own words, if it says: `Retry-After` (seconds or a date) or `X-RateLimit-Reset` (epoch seconds). */
|
|
49
|
+
export declare function retryAtOf(headers: Headers, now: number): number | undefined;
|
|
50
|
+
export declare function createHttp(o?: {
|
|
51
|
+
agent?: string;
|
|
52
|
+
fetch?: typeof fetch;
|
|
53
|
+
now?: () => number;
|
|
54
|
+
maxCached?: number;
|
|
55
|
+
}): HttpClient;
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small HTTP client for sources and fetches, so every plugin talks to
|
|
3
|
+
* APIs the same polite way:
|
|
4
|
+
*
|
|
5
|
+
* const http = createHttp({ agent: 'kiosko-plugin-weather/1.2.0' });
|
|
6
|
+
* const { data } = await http.json<Forecast>(url, { signal: ctx.signal });
|
|
7
|
+
*
|
|
8
|
+
* - Conditional requests: it remembers each URL's ETag / Last-Modified and
|
|
9
|
+
* body; a 304 gives the body it had, without downloading it again.
|
|
10
|
+
* - Rate limits: a 429 or 503 with `Retry-After` (or GitHub's
|
|
11
|
+
* `X-RateLimit-Reset`) throws an `HttpError` with `retryAt`, and until
|
|
12
|
+
* then calls to that host fail at once without contacting it.
|
|
13
|
+
* - The caller's `signal` (Kiosko aborts it after the source's timeout).
|
|
14
|
+
* - A User-Agent naming the plugin and Kiosko, never the person.
|
|
15
|
+
*/
|
|
16
|
+
export class HttpError extends Error {
|
|
17
|
+
status;
|
|
18
|
+
url;
|
|
19
|
+
/** When the server says to come back (rate limits), epoch ms. */
|
|
20
|
+
retryAt;
|
|
21
|
+
constructor(message, o) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'HttpError';
|
|
24
|
+
this.status = o.status;
|
|
25
|
+
this.url = o.url;
|
|
26
|
+
if (o.retryAt !== undefined)
|
|
27
|
+
this.retryAt = o.retryAt;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** How long to wait from the response's own words, if it says: `Retry-After` (seconds or a date) or `X-RateLimit-Reset` (epoch seconds). */
|
|
31
|
+
export function retryAtOf(headers, now) {
|
|
32
|
+
const ra = headers.get('retry-after');
|
|
33
|
+
if (ra) {
|
|
34
|
+
const s = Number(ra);
|
|
35
|
+
if (Number.isFinite(s))
|
|
36
|
+
return now + Math.max(0, s) * 1000;
|
|
37
|
+
const at = Date.parse(ra);
|
|
38
|
+
if (Number.isFinite(at))
|
|
39
|
+
return at;
|
|
40
|
+
}
|
|
41
|
+
const reset = Number(headers.get('x-ratelimit-reset'));
|
|
42
|
+
if (headers.get('x-ratelimit-remaining') === '0' && Number.isFinite(reset) && reset > 0)
|
|
43
|
+
return reset * 1000;
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const hostOf = (url) => {
|
|
47
|
+
try {
|
|
48
|
+
return new URL(url).host;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return url;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export function createHttp(o = {}) {
|
|
55
|
+
const doFetch = o.fetch ?? fetch;
|
|
56
|
+
const now = o.now ?? Date.now;
|
|
57
|
+
const agent = `${o.agent ? `${o.agent} ` : ''}Kiosko (+https://kioskolcd.dev)`;
|
|
58
|
+
const cache = new Map();
|
|
59
|
+
const rest = new Map();
|
|
60
|
+
const max = o.maxCached ?? 200;
|
|
61
|
+
async function request(url, req = {}) {
|
|
62
|
+
const host = hostOf(url);
|
|
63
|
+
const until = rest.get(host);
|
|
64
|
+
if (until !== undefined) {
|
|
65
|
+
if (until > now())
|
|
66
|
+
throw new HttpError(`${host} asked to wait until ${new Date(until).toISOString()}`, { status: 429, url, retryAt: until });
|
|
67
|
+
rest.delete(host);
|
|
68
|
+
}
|
|
69
|
+
const method = req.method ?? 'GET';
|
|
70
|
+
const cacheable = method === 'GET' && !req.noCache;
|
|
71
|
+
const hit = cacheable ? cache.get(url) : undefined;
|
|
72
|
+
const headers = { 'User-Agent': agent, ...req.headers };
|
|
73
|
+
if (hit?.etag)
|
|
74
|
+
headers['If-None-Match'] = hit.etag;
|
|
75
|
+
if (hit?.modified)
|
|
76
|
+
headers['If-Modified-Since'] = hit.modified;
|
|
77
|
+
const res = await doFetch(url, { method, headers, ...(req.body !== undefined ? { body: req.body } : {}), ...(req.signal ? { signal: req.signal } : {}) });
|
|
78
|
+
if (res.status === 304 && hit)
|
|
79
|
+
return { data: hit.body, status: 304, fresh: false, headers: res.headers };
|
|
80
|
+
const retryAt = retryAtOf(res.headers, now());
|
|
81
|
+
if (res.status === 429 || res.status === 503 || (res.status === 403 && retryAt !== undefined)) {
|
|
82
|
+
const at = retryAt ?? now() + 60_000;
|
|
83
|
+
rest.set(host, at);
|
|
84
|
+
throw new HttpError(`HTTP ${res.status} from ${host}: rate-limited until ${new Date(at).toISOString()}`, { status: res.status, url, retryAt: at });
|
|
85
|
+
}
|
|
86
|
+
if (!res.ok)
|
|
87
|
+
throw new HttpError(`HTTP ${res.status} from ${host}`, { status: res.status, url });
|
|
88
|
+
const body = await res.text();
|
|
89
|
+
if (cacheable) {
|
|
90
|
+
const etag = res.headers.get('etag') ?? undefined;
|
|
91
|
+
const modified = res.headers.get('last-modified') ?? undefined;
|
|
92
|
+
if (etag || modified) {
|
|
93
|
+
cache.delete(url);
|
|
94
|
+
cache.set(url, { ...(etag ? { etag } : {}), ...(modified ? { modified } : {}), body });
|
|
95
|
+
// Oldest out first.
|
|
96
|
+
while (cache.size > max)
|
|
97
|
+
cache.delete(cache.keys().next().value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { data: body, status: res.status, fresh: true, headers: res.headers };
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
text: request,
|
|
104
|
+
async json(url, req) {
|
|
105
|
+
const r = await request(url, { ...req, headers: { Accept: 'application/json', ...req?.headers } });
|
|
106
|
+
try {
|
|
107
|
+
return { ...r, data: JSON.parse(r.data) };
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
throw new HttpError(`not JSON from ${hostOf(url)}`, { status: r.status, url });
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
resting(url) {
|
|
114
|
+
const at = rest.get(hostOf(url));
|
|
115
|
+
return at !== undefined && at > now() ? at : undefined;
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/plugin.d.ts
CHANGED
|
@@ -72,8 +72,15 @@ export interface BaseContext {
|
|
|
72
72
|
*/
|
|
73
73
|
fmt: Formatters;
|
|
74
74
|
log: Logger;
|
|
75
|
-
/** Where the plugin may keep files (
|
|
75
|
+
/** Where the plugin may keep files that must survive a reboot (settings, history). Created on demand. */
|
|
76
76
|
dataDir: string;
|
|
77
|
+
/**
|
|
78
|
+
* Where the plugin keeps what can be fetched again (downloads, feed copies,
|
|
79
|
+
* photos, tiles). It is RAM (tmpfs), so the constant rewriting never wears
|
|
80
|
+
* the SSD, and it is empty after a reboot. Created on demand. Falls back to
|
|
81
|
+
* `dataDir` where there is no tmpfs. Use this, not `dataDir`, for caches.
|
|
82
|
+
*/
|
|
83
|
+
cacheDir: string;
|
|
77
84
|
/**
|
|
78
85
|
* The user's place, if set in Settings (weather, sun, earthquakes…). Use it
|
|
79
86
|
* by default; offer a place of your own only where a second one makes sense
|
|
@@ -120,9 +127,84 @@ export interface RenderContext<O, D> extends BaseContext, StateContext<O, D> {
|
|
|
120
127
|
canvas: CanvasApi;
|
|
121
128
|
/** The widget is drawn in the editor (gallery thumbnail or live preview) and not on the panel. */
|
|
122
129
|
preview: boolean;
|
|
123
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* Set while an animation of this widget is being painted (see
|
|
132
|
+
* `WidgetDefinition.animation`): which frame this call must draw. Without
|
|
133
|
+
* it, paint the widget at rest. The first and the last frame of an
|
|
134
|
+
* animation should look exactly like the still one.
|
|
135
|
+
*/
|
|
136
|
+
anim?: AnimationFrame;
|
|
137
|
+
/** Index of the frame being painted while an animation runs (`anim.i`). */
|
|
124
138
|
frame?: number;
|
|
125
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* A short animation a widget asks the runtime to play inside its own tile: a
|
|
142
|
+
* cat's tail flick, a tile sliding in. The runtime plans it (when, one at a
|
|
143
|
+
* time per screen), paints every frame by calling `render` with `ctx.anim`
|
|
144
|
+
* before playing, sends them at `fps` (never above the screen's `maxFps`) and
|
|
145
|
+
* finishes with a real still repaint.
|
|
146
|
+
*/
|
|
147
|
+
export interface AnimationPlan {
|
|
148
|
+
/** What it is (`tail`, `walk`…): for the log and for `render`, which receives it in `ctx.anim.plan`. */
|
|
149
|
+
id: string;
|
|
150
|
+
/** Frames, counting the first and the last (those are the still picture and are not sent). At least 3. */
|
|
151
|
+
frames: number;
|
|
152
|
+
/** Frames per second it was designed for. The screen's `maxFps` caps it. */
|
|
153
|
+
fps: number;
|
|
154
|
+
/** Whatever `render` needs to draw it (who does what). Plain data: it is not interpreted. */
|
|
155
|
+
params?: unknown;
|
|
156
|
+
/**
|
|
157
|
+
* `false`: new data doesn't cut it short (something that must be seen to
|
|
158
|
+
* the end). Default `true`: a data change cancels it and the screen is
|
|
159
|
+
* repainted with the new data.
|
|
160
|
+
*/
|
|
161
|
+
interruptible?: boolean;
|
|
162
|
+
/** Stay still at `at` (0..1 of the animation) for `ms` (a long task being shown), or until interrupted. */
|
|
163
|
+
hold?: {
|
|
164
|
+
at: number;
|
|
165
|
+
ms: number;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/** The frame `render` must paint (see `RenderContext.anim`). */
|
|
169
|
+
export interface AnimationFrame {
|
|
170
|
+
plan: AnimationPlan;
|
|
171
|
+
/** Frame number, 0..plan.frames-1. */
|
|
172
|
+
i: number;
|
|
173
|
+
/** Progress, 0..1: `i / (frames - 1)`. 0 and 1 are the still picture. */
|
|
174
|
+
t: number;
|
|
175
|
+
}
|
|
176
|
+
/** What `WidgetDefinition.animationEnded` is told. */
|
|
177
|
+
export interface AnimationEndContext<O, D> extends BaseContext {
|
|
178
|
+
options: O;
|
|
179
|
+
/** The animation that has just ended. */
|
|
180
|
+
plan: AnimationPlan;
|
|
181
|
+
/**
|
|
182
|
+
* `true` if it played to its last frame; `false` if it was cut short (new
|
|
183
|
+
* data, the screen went away) or never got to play.
|
|
184
|
+
*/
|
|
185
|
+
completed: boolean;
|
|
186
|
+
/** The widget's data when it started. */
|
|
187
|
+
data: D | undefined;
|
|
188
|
+
}
|
|
189
|
+
/** What `WidgetDefinition.animation` is asked with. */
|
|
190
|
+
export interface AnimationContext<O, D> extends StateContext<O, D> {
|
|
191
|
+
/** Where the widget paints (the same `box` its `render` gets), to decide with the layout it will have. */
|
|
192
|
+
box: Box;
|
|
193
|
+
/**
|
|
194
|
+
* Why it is asked: `idle`, every now and then while nothing else happens
|
|
195
|
+
* (see `animationGap`), or `data`, because this instance's data just changed
|
|
196
|
+
* or one of its sources did (see `prev`) and a reaction may be due, like a
|
|
197
|
+
* cat walking to its new spot.
|
|
198
|
+
*/
|
|
199
|
+
trigger: 'idle' | 'data';
|
|
200
|
+
/** What the widget had before the change, for `trigger: 'data'`: its own data and its sources. */
|
|
201
|
+
prev?: {
|
|
202
|
+
data: D | undefined;
|
|
203
|
+
sources: Record<string, unknown>;
|
|
204
|
+
};
|
|
205
|
+
/** Random numbers in [0, 1). Use these and not `Math.random`, so tests can seed them. */
|
|
206
|
+
rnd: () => number;
|
|
207
|
+
}
|
|
126
208
|
/**
|
|
127
209
|
* When the widget must be repainted even though its data didn't change: a
|
|
128
210
|
* clock every second, a countdown every minute. Fewer repaints are fewer
|
|
@@ -173,6 +255,29 @@ export interface WidgetDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
173
255
|
timeoutMs?: number;
|
|
174
256
|
/** Paint. Synchronous and fast: load images in `fetch` and paint them here. */
|
|
175
257
|
render: (g: Graphics, ctx: RenderContext<Infer<OF>, D>) => void;
|
|
258
|
+
/**
|
|
259
|
+
* Asks for a short animation inside the tile, or `null` for none. The
|
|
260
|
+
* runtime calls it only while this widget is the one shown, the screen has
|
|
261
|
+
* room for another animation (several widgets may ask: they wait their turn,
|
|
262
|
+
* and how many play together is up to the runtime) and its `animationGap` /
|
|
263
|
+
* `animationCooldownMs` allow it. It must be cheap and decide from the data alone; the drawing goes in
|
|
264
|
+
* `render`, which gets `ctx.anim` for every frame. Every frame costs USB
|
|
265
|
+
* time: keep them few and short.
|
|
266
|
+
*/
|
|
267
|
+
animation?: (ctx: AnimationContext<Infer<OF>, D>) => AnimationPlan | null;
|
|
268
|
+
/**
|
|
269
|
+
* Called when an animation of this widget ends, whether it played through
|
|
270
|
+
* or not (see `completed`): to remember what it did, like a trophy for
|
|
271
|
+
* a set that got built. Synchronous and quick; keep files under `dataDir`.
|
|
272
|
+
*/
|
|
273
|
+
animationEnded?: (ctx: AnimationEndContext<Infer<OF>, D>) => void;
|
|
274
|
+
/** How long to wait between the `idle` questions of `animation`, a random time in the range. Default 20-60 s. */
|
|
275
|
+
animationGap?: {
|
|
276
|
+
minMs: number;
|
|
277
|
+
maxMs: number;
|
|
278
|
+
};
|
|
279
|
+
/** Minimum time from the end of an animation to the next one asked because of a data change. Default 0. */
|
|
280
|
+
animationCooldownMs?: number;
|
|
176
281
|
/** Also a function, when the cadence depends on the options or the data (a carousel every `rotateMs`). */
|
|
177
282
|
redraw?: Redraw | ((ctx: StateContext<Infer<OF>, D>) => Redraw);
|
|
178
283
|
/** Has nothing to show right now (nothing playing, no rain): skipped in its cell's rotation. */
|
|
@@ -258,6 +363,25 @@ export interface SourceDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
258
363
|
now: number;
|
|
259
364
|
locale: string;
|
|
260
365
|
}) => D;
|
|
366
|
+
/**
|
|
367
|
+
* Named lists of values for the editor to offer in options, made from
|
|
368
|
+
* this source's latest data (or its demo data before there is any): the
|
|
369
|
+
* entities of a Home Assistant, the calendars read, the repos seen. A
|
|
370
|
+
* field asks for one with `choices: { source: 'plugin/source', list }`.
|
|
371
|
+
* Plain and quick: they run when the editor opens a form.
|
|
372
|
+
*/
|
|
373
|
+
choices?: Record<string, (data: D, ctx: {
|
|
374
|
+
locale: string;
|
|
375
|
+
t: (text: Localized) => string;
|
|
376
|
+
}) => Choice[]>;
|
|
377
|
+
}
|
|
378
|
+
/** One value the editor offers for an option (see `SourceDefinition.choices`). */
|
|
379
|
+
export interface Choice {
|
|
380
|
+
value: string;
|
|
381
|
+
/** What the person sees, when it isn't the value itself (`Living room` for `sensor.living_room`). */
|
|
382
|
+
label?: string;
|
|
383
|
+
/** Heading to group it under (`Sensors`, `Lights`). */
|
|
384
|
+
group?: string;
|
|
261
385
|
}
|
|
262
386
|
export interface InterludePlayer {
|
|
263
387
|
/** Number of frames. */
|
|
@@ -293,6 +417,62 @@ export interface InterludeDefinition<OF extends ObjectField<any> = ObjectField<a
|
|
|
293
417
|
options: Infer<OF>;
|
|
294
418
|
}) => boolean;
|
|
295
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* The version of the plugin API this Kiosko speaks. A plugin says which
|
|
422
|
+
* versions it was written for in `PluginDefinition.sdk` (and in its
|
|
423
|
+
* package.json, `"kiosko": { "sdk": "^0.2.0" }`, so it can be refused before
|
|
424
|
+
* it runs); the registry compares them with `satisfies`.
|
|
425
|
+
*/
|
|
426
|
+
export declare const SDK_VERSION = "0.2.2";
|
|
427
|
+
/**
|
|
428
|
+
* What a plugin does on the machine, declared for the person who installs
|
|
429
|
+
* it: the Plugins page and the plugin store show it next to the plugin. It
|
|
430
|
+
* is a promise, not (yet) a fence: plugins run with the user's rights. Keep
|
|
431
|
+
* it honest and small; options with a `risk` (see `Risk`) are listed apart.
|
|
432
|
+
*/
|
|
433
|
+
export interface Permissions {
|
|
434
|
+
/**
|
|
435
|
+
* Hosts it contacts on its own: exact names (`api.github.com`,
|
|
436
|
+
* `*.open-meteo.com`), `user` for the hosts the user types in its options
|
|
437
|
+
* (a feed, a Home Assistant), `lan` for the local network.
|
|
438
|
+
*/
|
|
439
|
+
network?: string[];
|
|
440
|
+
/** Programs it runs (`nvidia-smi`, `pactl`, `ssh`); `user` for a command the user configures. */
|
|
441
|
+
exec?: string[];
|
|
442
|
+
/** Files or folders it reads or writes besides its own `dataDir`/`cacheDir` (`~/.aimonitor/sessions`); `user` for paths the user configures. */
|
|
443
|
+
files?: string[];
|
|
444
|
+
/** Hardware or system services it talks to: `usb`, `audio` (whether the microphone is in use), `mpris` (what is playing), `bluetooth`… */
|
|
445
|
+
devices?: string[];
|
|
446
|
+
}
|
|
447
|
+
/** One tile of a page template, in fractions of the page (0..1). */
|
|
448
|
+
export interface TemplateTile {
|
|
449
|
+
x: number;
|
|
450
|
+
y: number;
|
|
451
|
+
w: number;
|
|
452
|
+
h: number;
|
|
453
|
+
/** Widget types, stacked; a bare id (`clock`) is this plugin's own. With options: `['clock', { showDate: true }]`. */
|
|
454
|
+
widgets: (string | [string, Record<string, unknown>])[];
|
|
455
|
+
chrome?: 'card' | 'bare';
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* A starting layout the editor offers under "New page", made of this
|
|
459
|
+
* plugin's widgets (and others', if installed: tiles whose widgets are all
|
|
460
|
+
* missing are left out).
|
|
461
|
+
*/
|
|
462
|
+
export interface PageTemplate {
|
|
463
|
+
/** Unique inside the plugin. */
|
|
464
|
+
id: string;
|
|
465
|
+
name: Localized;
|
|
466
|
+
/** An icon of the editor (Lucide name). */
|
|
467
|
+
icon?: string;
|
|
468
|
+
/** For strips and wide panels. */
|
|
469
|
+
wide: TemplateTile[];
|
|
470
|
+
/** For square-ish panels; defaults to `wide`. */
|
|
471
|
+
square?: TemplateTile[];
|
|
472
|
+
/** For portrait panels; defaults to `wide` turned a quarter (columns become bands). */
|
|
473
|
+
tall?: TemplateTile[];
|
|
474
|
+
}
|
|
475
|
+
export type Platform = 'linux' | 'darwin' | 'win32';
|
|
296
476
|
export interface PluginDefinition {
|
|
297
477
|
/** npm-like id: lowercase, digits and dashes. Stable: configs refer to it. */
|
|
298
478
|
id: string;
|
|
@@ -301,11 +481,37 @@ export interface PluginDefinition {
|
|
|
301
481
|
description?: Localized;
|
|
302
482
|
author?: string;
|
|
303
483
|
homepage?: string;
|
|
484
|
+
/** Where its code lives (a git URL): the store links to it. */
|
|
485
|
+
repository?: string;
|
|
304
486
|
license?: string;
|
|
305
487
|
icon?: string;
|
|
488
|
+
/**
|
|
489
|
+
* The plugin API versions it works with, as an npm range (`^0.2.0`).
|
|
490
|
+
* Without it, any Kiosko is assumed to fit. Put the same in package.json
|
|
491
|
+
* (`"kiosko": { "sdk": … }`) so an incompatible plugin is refused before
|
|
492
|
+
* its code runs.
|
|
493
|
+
*/
|
|
494
|
+
sdk?: string;
|
|
495
|
+
/** What it does on the machine (see `Permissions`). */
|
|
496
|
+
permissions?: Permissions;
|
|
497
|
+
/**
|
|
498
|
+
* Sources or widgets of other plugins it needs (`agents/sessions`): the
|
|
499
|
+
* editor says which are missing and offers to install their plugins.
|
|
500
|
+
*/
|
|
501
|
+
requires?: string[];
|
|
502
|
+
/**
|
|
503
|
+
* Sources or widgets of other plugins it uses when they are there, and
|
|
504
|
+
* does without otherwise (the weather in a corner): never asked for, only
|
|
505
|
+
* mentioned.
|
|
506
|
+
*/
|
|
507
|
+
optional?: string[];
|
|
508
|
+
/** The operating systems it works on. Omitted: all. Also npm's `os` in package.json. */
|
|
509
|
+
platforms?: Platform[];
|
|
306
510
|
widgets?: WidgetDefinition<any, any>[];
|
|
307
511
|
sources?: SourceDefinition<any, any>[];
|
|
308
512
|
interludes?: InterludeDefinition<any>[];
|
|
513
|
+
/** Page layouts the editor offers, built from its widgets (see `PageTemplate`). */
|
|
514
|
+
templates?: PageTemplate[];
|
|
309
515
|
}
|
|
310
516
|
export declare function defineWidget<OF extends ObjectField<any> = ObjectField<{}>, D = undefined>(w: WidgetDefinition<OF, D>): WidgetDefinition<OF, D>;
|
|
311
517
|
export declare function defineSource<OF extends ObjectField<any> = ObjectField<{}>, D = unknown>(s: SourceDefinition<OF, D>): SourceDefinition<OF, D>;
|
package/dist/plugin.js
CHANGED
|
@@ -9,6 +9,13 @@ export const CATEGORIES = [
|
|
|
9
9
|
{ id: 'scene', label: { en: 'Scenes', es: 'Escenas' } },
|
|
10
10
|
{ id: 'fun', label: { en: 'Fun', es: 'Diversión' } },
|
|
11
11
|
];
|
|
12
|
+
/**
|
|
13
|
+
* The version of the plugin API this Kiosko speaks. A plugin says which
|
|
14
|
+
* versions it was written for in `PluginDefinition.sdk` (and in its
|
|
15
|
+
* package.json, `"kiosko": { "sdk": "^0.2.0" }`, so it can be refused before
|
|
16
|
+
* it runs); the registry compares them with `satisfies`.
|
|
17
|
+
*/
|
|
18
|
+
export const SDK_VERSION = '0.2.2';
|
|
12
19
|
/* Identity helpers: they only exist so TypeScript infers option and data types. */
|
|
13
20
|
export function defineWidget(w) {
|
|
14
21
|
return w;
|
package/dist/schema.d.ts
CHANGED
|
@@ -35,9 +35,23 @@ interface Common<T> {
|
|
|
35
35
|
/** See `Risk`. Exported as `x-risk`; `kiosko config import` lists these values before applying a config. */
|
|
36
36
|
risk?: Risk | readonly Risk[];
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Where the editor finds values to offer for a text field: a named list of
|
|
40
|
+
* a source (see `SourceDefinition.choices`), computed from its live data,
|
|
41
|
+
* e.g. the entities of the user's Home Assistant. The field stays free
|
|
42
|
+
* text: a value that isn't in the list is kept.
|
|
43
|
+
*/
|
|
44
|
+
export interface ChoicesRef {
|
|
45
|
+
/** `plugin/source`. */
|
|
46
|
+
source: string;
|
|
47
|
+
/** The name of the list in that source's `choices`. */
|
|
48
|
+
list: string;
|
|
49
|
+
}
|
|
38
50
|
export interface StringField extends Common<string> {
|
|
39
51
|
kind: 'string';
|
|
40
52
|
placeholder?: string;
|
|
53
|
+
/** Values to offer, from a source's live data (see `ChoicesRef`). */
|
|
54
|
+
choices?: ChoicesRef;
|
|
41
55
|
multiline?: boolean;
|
|
42
56
|
/** Tokens, URLs with credentials…: masked in the editor and never logged. */
|
|
43
57
|
secret?: boolean;
|
|
@@ -116,7 +130,9 @@ export declare const t: {
|
|
|
116
130
|
* `repos`, `calendars`, `people`) and give it a `label`; the `help`
|
|
117
131
|
* explaining the patterns comes with it.
|
|
118
132
|
*/
|
|
119
|
-
filter: (o?: Opts<ListField<StringField>, "item">
|
|
133
|
+
filter: ({ choices, ...o }?: Opts<ListField<StringField>, "item"> & {
|
|
134
|
+
choices?: ChoicesRef;
|
|
135
|
+
}) => ListField<StringField>;
|
|
120
136
|
};
|
|
121
137
|
/** The help every `t.filter()` field carries unless it brings its own. */
|
|
122
138
|
export declare const FILTER_HELP: Localized;
|
package/dist/schema.js
CHANGED
|
@@ -28,9 +28,9 @@ export const t = {
|
|
|
28
28
|
* `repos`, `calendars`, `people`) and give it a `label`; the `help`
|
|
29
29
|
* explaining the patterns comes with it.
|
|
30
30
|
*/
|
|
31
|
-
filter: (o = {}) => ({
|
|
31
|
+
filter: ({ choices, ...o } = {}) => ({
|
|
32
32
|
kind: 'list',
|
|
33
|
-
item: { kind: 'string', default: '', placeholder: 'name, group/*, !old-*' },
|
|
33
|
+
item: { kind: 'string', default: '', placeholder: 'name, group/*, !old-*', ...(choices ? { choices } : {}) },
|
|
34
34
|
default: [],
|
|
35
35
|
filter: true,
|
|
36
36
|
help: FILTER_HELP,
|
|
@@ -144,7 +144,7 @@ export function toJsonSchema(f) {
|
|
|
144
144
|
};
|
|
145
145
|
switch (f.kind) {
|
|
146
146
|
case 'string':
|
|
147
|
-
return { ...base, type: 'string', ...(f.format === 'date' ? { format: 'date' } : {}), ...(f.maxLength ? { maxLength: f.maxLength } : {}), 'x-ui': { ...ui, secret: f.secret, multiline: f.multiline, placeholder: f.placeholder, format: f.format } };
|
|
147
|
+
return { ...base, type: 'string', ...(f.format === 'date' ? { format: 'date' } : {}), ...(f.maxLength ? { maxLength: f.maxLength } : {}), 'x-ui': { ...ui, secret: f.secret, multiline: f.multiline, placeholder: f.placeholder, format: f.format, choices: f.choices } };
|
|
148
148
|
case 'color':
|
|
149
149
|
return { ...base, type: 'string', 'x-ui': { ...ui, widget: 'color' } };
|
|
150
150
|
case 'number':
|
|
@@ -154,7 +154,7 @@ export function toJsonSchema(f) {
|
|
|
154
154
|
case 'enum':
|
|
155
155
|
return { ...base, type: 'string', enum: [...f.values], 'x-ui': { ...ui, labels: f.labels } };
|
|
156
156
|
case 'list':
|
|
157
|
-
return { ...base, type: 'array', items: toJsonSchema(f.item), maxItems: f.max, ...(f.filter ? { 'x-ui': { ...ui, widget: 'filter' }, 'x-filter': true } : {}) };
|
|
157
|
+
return { ...base, type: 'array', items: toJsonSchema(f.item), maxItems: f.max, ...(f.filter ? { 'x-ui': { ...ui, widget: 'filter', choices: f.item.kind === 'string' ? f.item.choices : undefined }, 'x-filter': true } : {}) };
|
|
158
158
|
case 'map':
|
|
159
159
|
return { ...base, type: 'object', additionalProperties: { type: 'string' } };
|
|
160
160
|
case 'object':
|
package/dist/semver.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Just enough semver to say whether a plugin fits this Kiosko: versions
|
|
3
|
+
* `1.2.3` (a pre-release such as `1.2.3-beta.1` sorts before its release),
|
|
4
|
+
* and ranges as npm writes them in package.json:
|
|
5
|
+
*
|
|
6
|
+
* ^0.2.0 >=0.2.0 <0.3.0 (caret: the left-most non-zero part is fixed)
|
|
7
|
+
* ~0.2.1 >=0.2.1 <0.3.0
|
|
8
|
+
* 0.2 · 0.2.x · * wildcards
|
|
9
|
+
* >=0.2.0 <1 comparators, space-separated (all must hold)
|
|
10
|
+
* ^0.2 || ^1 alternatives
|
|
11
|
+
*
|
|
12
|
+
* No dependencies, so the registry can check a plugin before running it.
|
|
13
|
+
*/
|
|
14
|
+
type V = [number, number, number, string];
|
|
15
|
+
/** `1.2.3` → its parts; null when it isn't a version. */
|
|
16
|
+
export declare function parseVersion(s: string): V | null;
|
|
17
|
+
/** -1, 0 or 1. A pre-release sorts before the release of the same numbers. */
|
|
18
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
19
|
+
/**
|
|
20
|
+
* Whether `version` is in `range`. A pre-release only matches a range that
|
|
21
|
+
* names a pre-release of the same numbers (npm's rule), so `0.3.0-beta` does
|
|
22
|
+
* not quietly satisfy `^0.2`. An unreadable range or version is `false`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function satisfies(version: string, range: string): boolean;
|
|
25
|
+
export {};
|