@sdeck/plugin 0.1.0 → 0.2.0
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/bridge.d.ts +8 -2
- package/dist/bridge.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +147 -2725
- package/dist/index.js.map +8 -28
- package/dist/permissions.d.ts +31 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/plugin.d.ts +38 -10
- package/dist/plugin.d.ts.map +1 -1
- package/dist/settings.d.ts +31 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/ui.d.ts +4 -0
- package/dist/ui.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/bridge.ts +8 -2
- package/src/index.ts +12 -2
- package/src/permissions.ts +119 -0
- package/src/plugin.ts +58 -28
- package/src/settings.ts +68 -7
- package/src/ui.ts +3 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a plugin can ask to do. The user decides about each permission separately, and a plugin
|
|
3
|
+
* gets nothing it did not ask for and nothing the user did not allow.
|
|
4
|
+
*/
|
|
5
|
+
export type Permission = "network" | "filesystem" | "process" | "shell" | "input" | "clipboard" | "audio" | "environment" | "variables" | "state" | "actions" | "native";
|
|
6
|
+
/** A permission as the user reads it. */
|
|
7
|
+
export interface PermissionText {
|
|
8
|
+
name: string;
|
|
9
|
+
/** What allowing it makes possible. */
|
|
10
|
+
description: string;
|
|
11
|
+
/** Finishes "the plugin is not allowed to …". */
|
|
12
|
+
action: string;
|
|
13
|
+
/** Allowing it lets the plugin do nearly anything the user can. */
|
|
14
|
+
powerful?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Every permission, in the order the UI lists them. */
|
|
17
|
+
export declare const PERMISSION_TEXTS: Readonly<Record<Permission, PermissionText>>;
|
|
18
|
+
export declare const PERMISSIONS: readonly Permission[];
|
|
19
|
+
/** Thrown when a plugin does something the user has not allowed. The message is for the user. */
|
|
20
|
+
export declare class PermissionError extends Error {
|
|
21
|
+
readonly permission: Permission;
|
|
22
|
+
readonly name = "PermissionError";
|
|
23
|
+
/** As Node's file system reports a refused path, so libraries treat it the same way. */
|
|
24
|
+
readonly code = "EACCES";
|
|
25
|
+
constructor(
|
|
26
|
+
/** The plugin's name or id. */
|
|
27
|
+
plugin: string, permission: Permission,
|
|
28
|
+
/** What was refused, when that helps (a path, an address). */
|
|
29
|
+
detail?: string);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,YAAY,GACZ,SAAS,GACT,OAAO,GACP,OAAO,GACP,WAAW,GACX,OAAO,GACP,aAAa,GACb,WAAW,GACX,OAAO,GACP,SAAS,GACT,QAAQ,CAAC;AAEb,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAiEzE,CAAC;AAEF,eAAO,MAAM,WAAW,EAAoC,SAAS,UAAU,EAAE,CAAC;AAElF,iGAAiG;AACjG,qBAAa,eAAgB,SAAQ,KAAK;IAQtC,QAAQ,CAAC,UAAU,EAAE,UAAU;IAPjC,SAAkB,IAAI,qBAAqB;IAC3C,wFAAwF;IACxF,QAAQ,CAAC,IAAI,YAAY;IAEzB;IACE,+BAA+B;IAC/B,MAAM,EAAE,MAAM,EACL,UAAU,EAAE,UAAU;IAC/B,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,EAOhB;CACF"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -2,17 +2,12 @@ import type { SlotInfo } from "@sdeck/app";
|
|
|
2
2
|
import type { ExecSource, StateValueType } from "@sdeck/engine";
|
|
3
3
|
import type { Look, NavigateTarget } from "@sdeck/schema";
|
|
4
4
|
import type { ComponentType } from "react";
|
|
5
|
+
import { type Permission } from "./permissions.ts";
|
|
5
6
|
import { type InferSettings, type SelectOption, type SettingsSchema } from "./settings.ts";
|
|
6
7
|
/** Bumped when the plugin contract changes incompatibly. Hosts refuse plugins built for another. */
|
|
7
8
|
export declare const PLUGIN_API_VERSION = 2;
|
|
8
9
|
/** Where an action can be placed. */
|
|
9
10
|
export type SlotKind = "key" | "sensor" | "window";
|
|
10
|
-
/**
|
|
11
|
-
* What a plugin declares it does. Shown to the user before enabling it. Plugins run in the host
|
|
12
|
-
* process, so this is information, not a sandbox.
|
|
13
|
-
*/
|
|
14
|
-
export type Permission = "shell" | "process" | "filesystem" | "network" | "input" | "audio" | "clipboard";
|
|
15
|
-
export declare const PERMISSIONS: readonly Permission[];
|
|
16
11
|
/** Given to a plugin's `activate`, its actions, state providers and triggers. */
|
|
17
12
|
export interface PluginContext {
|
|
18
13
|
readonly pluginId: string;
|
|
@@ -36,11 +31,12 @@ export interface PluginContext {
|
|
|
36
31
|
/** Live state: `set` publishes `<namespace>.<id>`, `get` reads any key (`system.cpu`). */
|
|
37
32
|
readonly state: {
|
|
38
33
|
set(id: string, value: unknown): void;
|
|
34
|
+
/** Keys of other plugins need the `state` permission. */
|
|
39
35
|
get(key: string): unknown;
|
|
40
36
|
};
|
|
41
37
|
/** Emits `<namespace>:<event>` on the event bus (workflows can trigger on it). */
|
|
42
38
|
emit(event: string, payload?: unknown): void;
|
|
43
|
-
/** Global user variables. */
|
|
39
|
+
/** Global user variables. Needs the `variables` permission. */
|
|
44
40
|
readonly vars: {
|
|
45
41
|
get(name: string): unknown;
|
|
46
42
|
set(name: string, value: unknown): void;
|
|
@@ -48,12 +44,17 @@ export interface PluginContext {
|
|
|
48
44
|
}
|
|
49
45
|
/** How a plugin's status reads: fine, needing attention, or failing. */
|
|
50
46
|
export type StatusLevel = "ok" | "info" | "error";
|
|
51
|
-
/** Something the user can run from the plugin's
|
|
47
|
+
/** Something the user can run from the plugin's settings (sign in, reconnect). */
|
|
52
48
|
export interface PluginCommand {
|
|
53
49
|
/** Unique within the plugin. */
|
|
54
50
|
id: string;
|
|
55
51
|
name: string;
|
|
56
52
|
description?: string;
|
|
53
|
+
/**
|
|
54
|
+
* What it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
55
|
+
* Without them it is refused.
|
|
56
|
+
*/
|
|
57
|
+
permissions?: readonly Permission[];
|
|
57
58
|
/** What it returns, if a string, is opened in the user's browser. Throw to fail. */
|
|
58
59
|
run(context: PluginContext): unknown | Promise<unknown>;
|
|
59
60
|
}
|
|
@@ -178,9 +179,19 @@ export interface ActionDef<S extends SettingsSchema = SettingsSchema> {
|
|
|
178
179
|
slots?: readonly SlotKind[];
|
|
179
180
|
/** Settings shown in the UI, as a form. */
|
|
180
181
|
settings?: S;
|
|
182
|
+
/**
|
|
183
|
+
* What it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
184
|
+
* Without them it cannot run or draw itself.
|
|
185
|
+
*/
|
|
186
|
+
permissions?: readonly Permission[];
|
|
187
|
+
/**
|
|
188
|
+
* It only shows something. It is offered for buttons, but not as a step of a workflow or
|
|
189
|
+
* gesture, and needs no `run`.
|
|
190
|
+
*/
|
|
191
|
+
display?: boolean;
|
|
181
192
|
/**
|
|
182
193
|
* Does the work, without drawing anything: it can run from a key, a trigger or a workflow.
|
|
183
|
-
* Throw to fail. An action needs `run`, `component`, or both
|
|
194
|
+
* Throw to fail. An action needs `run`, `component`, or both, unless it is `display`.
|
|
184
195
|
*/
|
|
185
196
|
run?(context: RunContext<S>): RunResult | void | Promise<RunResult | void>;
|
|
186
197
|
/**
|
|
@@ -202,6 +213,8 @@ export interface Action {
|
|
|
202
213
|
readonly icon?: string;
|
|
203
214
|
readonly slots: readonly SlotKind[];
|
|
204
215
|
readonly settings: SettingsSchema;
|
|
216
|
+
readonly permissions?: readonly Permission[];
|
|
217
|
+
readonly display?: boolean;
|
|
205
218
|
readonly run?: RunFn;
|
|
206
219
|
readonly component?: ComponentType<ActionProps>;
|
|
207
220
|
readonly look?: (settings: Record<string, unknown>) => Look;
|
|
@@ -214,6 +227,11 @@ export interface StateDef {
|
|
|
214
227
|
type: StateValueType;
|
|
215
228
|
unit?: string;
|
|
216
229
|
description?: string;
|
|
230
|
+
/**
|
|
231
|
+
* What reading it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
232
|
+
* Without them it has no value.
|
|
233
|
+
*/
|
|
234
|
+
permissions?: readonly Permission[];
|
|
217
235
|
/** Read every `everyMs` while something shows or waits on the value. */
|
|
218
236
|
poll?: {
|
|
219
237
|
everyMs: number;
|
|
@@ -235,6 +253,11 @@ export interface TriggerDef<S extends SettingsSchema = SettingsSchema> {
|
|
|
235
253
|
name: string;
|
|
236
254
|
description?: string;
|
|
237
255
|
settings?: S;
|
|
256
|
+
/**
|
|
257
|
+
* What it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
258
|
+
* Without them it never fires.
|
|
259
|
+
*/
|
|
260
|
+
permissions?: readonly Permission[];
|
|
238
261
|
/** Starts watching; returns a function that stops. */
|
|
239
262
|
subscribe(context: TriggerContext<S>): (() => void) | void;
|
|
240
263
|
}
|
|
@@ -243,6 +266,7 @@ export interface Trigger {
|
|
|
243
266
|
readonly name: string;
|
|
244
267
|
readonly description?: string;
|
|
245
268
|
readonly settings: SettingsSchema;
|
|
269
|
+
readonly permissions?: readonly Permission[];
|
|
246
270
|
readonly subscribe: (context: TriggerContext) => (() => void) | undefined;
|
|
247
271
|
}
|
|
248
272
|
/**
|
|
@@ -267,10 +291,14 @@ export interface PluginDef {
|
|
|
267
291
|
state?: readonly StateDef[];
|
|
268
292
|
triggers?: readonly Trigger[];
|
|
269
293
|
optionSources?: Readonly<Record<string, OptionSource>>;
|
|
294
|
+
/**
|
|
295
|
+
* Everything the plugin asks to be allowed to do. The user decides about each one, and can
|
|
296
|
+
* change their mind at any time: handle being refused. What is not listed is never allowed.
|
|
297
|
+
*/
|
|
270
298
|
permissions?: readonly Permission[];
|
|
271
299
|
/** The plugin's own settings (a server address, a token), shown on its page. */
|
|
272
300
|
settings?: SettingsSchema;
|
|
273
|
-
/** Buttons
|
|
301
|
+
/** Buttons in the plugin's settings. */
|
|
274
302
|
commands?: readonly PluginCommand[];
|
|
275
303
|
/**
|
|
276
304
|
* How to set the plugin up, step by step, shown after it is installed. Without it, Studio asks
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAEvB,oGAAoG;AACpG,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC,qCAAqC;AACrC,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnD
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3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,MAAM,EAAE,CAyHpD"}
|
package/dist/settings.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ interface FieldBase {
|
|
|
8
8
|
label: string;
|
|
9
9
|
/** Help text under the field. */
|
|
10
10
|
description?: string;
|
|
11
|
+
/**
|
|
12
|
+
* It only changes how the button looks. It is asked for on a button, but not in a step of a
|
|
13
|
+
* workflow or gesture, where nothing is drawn.
|
|
14
|
+
*/
|
|
15
|
+
appearance?: boolean;
|
|
11
16
|
/**
|
|
12
17
|
* Shown only while other fields have these values: `{ to: "page" }` or
|
|
13
18
|
* `{ mode: ["a", "b"] }`. Hidden fields keep their value.
|
|
@@ -79,23 +84,46 @@ export interface ImageField extends FieldBase {
|
|
|
79
84
|
type: "image";
|
|
80
85
|
default?: string;
|
|
81
86
|
}
|
|
82
|
-
|
|
87
|
+
/** A named set the user made of options, from a `groups` field. */
|
|
88
|
+
export interface OptionGroup {
|
|
89
|
+
/** Stays the same when the group is renamed; refer to the group by it. */
|
|
90
|
+
id: string;
|
|
91
|
+
name: string;
|
|
92
|
+
/** The chosen options' values. */
|
|
93
|
+
members: readonly string[];
|
|
94
|
+
}
|
|
95
|
+
/** Named sets of options the user puts together (rooms of lights), only for a plugin's own settings. */
|
|
96
|
+
export interface GroupsField extends FieldBase {
|
|
97
|
+
type: "groups";
|
|
98
|
+
/** The plugin's `optionSources` entry that lists what a group can contain. */
|
|
99
|
+
source: string;
|
|
100
|
+
/** What a group contains, for the form, e.g. `lights` (default: `items`). */
|
|
101
|
+
noun?: string;
|
|
102
|
+
default?: readonly OptionGroup[];
|
|
103
|
+
}
|
|
104
|
+
export type SettingField = TextField | NumberField | BooleanField | ColorField | SelectField | PageField | ImageField | GroupsField | SecretField;
|
|
83
105
|
export type SettingsSchema = Readonly<Record<string, SettingField>>;
|
|
84
106
|
/** The value type of one field. */
|
|
85
|
-
export type FieldValue<F extends SettingField> = F extends NumberField ? number : F extends BooleanField ? boolean : F extends SelectField ? F extends {
|
|
107
|
+
export type FieldValue<F extends SettingField> = F extends NumberField ? number : F extends BooleanField ? boolean : F extends GroupsField ? readonly OptionGroup[] : F extends SelectField ? F extends {
|
|
86
108
|
source: string;
|
|
87
109
|
} ? string : F["options"][number]["value"] : string;
|
|
110
|
+
/** A value of any field. */
|
|
111
|
+
export type SettingValue = Primitive | readonly OptionGroup[];
|
|
88
112
|
/** The settings object an action receives for a schema. */
|
|
89
113
|
export type InferSettings<S extends SettingsSchema> = {
|
|
90
114
|
-readonly [K in keyof S]: FieldValue<S[K]>;
|
|
91
115
|
};
|
|
92
116
|
/** The value a field takes when nothing (valid) is stored. */
|
|
93
|
-
export declare function defaultValue(field: SettingField):
|
|
117
|
+
export declare function defaultValue(field: SettingField): SettingValue;
|
|
118
|
+
/** The valid groups in a stored value, or `undefined` if it isn't a list. */
|
|
119
|
+
export declare function optionGroups(value: unknown): OptionGroup[] | undefined;
|
|
94
120
|
/**
|
|
95
121
|
* Stored settings, made safe: every field of `schema` is present and of the right type (invalid
|
|
96
122
|
* or missing values get the default, numbers are clamped), and unknown keys are dropped.
|
|
97
123
|
*/
|
|
98
124
|
export declare function resolveSettings<S extends SettingsSchema>(schema: S, stored: Readonly<Record<string, unknown>> | undefined): InferSettings<S>;
|
|
125
|
+
/** The fields that change what an action does, without those for how its button looks. */
|
|
126
|
+
export declare function behaviorFields(schema: SettingsSchema): SettingsSchema;
|
|
99
127
|
/** Whether `field` is shown for these (resolved) settings. */
|
|
100
128
|
export declare function isFieldVisible(field: SettingField, settings: Readonly<Record<string, unknown>>): boolean;
|
|
101
129
|
/**
|
package/dist/settings.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,UAAU,SAAS;IACjB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,iCAA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0CV"}
|
package/dist/ui.d.ts
ADDED
package/dist/ui.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdeck/plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "SDK for sdeck plugins: actions that run headless or draw with React, live state, triggers and option sources.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"test": "bun test"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sdeck/app": "0.
|
|
29
|
-
"@sdeck/engine": "0.
|
|
30
|
-
"@sdeck/schema": "0.
|
|
28
|
+
"@sdeck/app": "0.2.0",
|
|
29
|
+
"@sdeck/engine": "0.2.0",
|
|
30
|
+
"@sdeck/schema": "0.2.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": ">=19.3"
|
package/src/bridge.ts
CHANGED
|
@@ -75,7 +75,10 @@ function useWatched<T>(paths: readonly string[], read: () => T): T {
|
|
|
75
75
|
return useSyncExternalStore(subscribe, snapshot);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* The value of an expression (`system.cpu > 80`, `vars.mode`), kept up to date. Values the plugin
|
|
80
|
+
* is not allowed to read (`state`, `variables`) are missing.
|
|
81
|
+
*/
|
|
79
82
|
export function useExpression(source: string): unknown {
|
|
80
83
|
const bridge = useBridge();
|
|
81
84
|
const expression = useMemo(() => compile(source), [source]);
|
|
@@ -111,7 +114,10 @@ export function useVariable(name: string): [unknown, (value: unknown) => void] {
|
|
|
111
114
|
return [value, set];
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Runs an action from a component (`run("@sdeck/plugin-system", "open", {...})`).
|
|
119
|
+
* Other plugins' actions need the `actions` permission.
|
|
120
|
+
*/
|
|
115
121
|
export function useRunAction(): HostBridge["run"] {
|
|
116
122
|
return useBridge().run;
|
|
117
123
|
}
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,13 @@ export {
|
|
|
29
29
|
parseManifest,
|
|
30
30
|
SUPPORTED_API_VERSIONS,
|
|
31
31
|
} from "./manifest.ts";
|
|
32
|
+
export {
|
|
33
|
+
PERMISSION_TEXTS,
|
|
34
|
+
PERMISSIONS,
|
|
35
|
+
type Permission,
|
|
36
|
+
PermissionError,
|
|
37
|
+
type PermissionText,
|
|
38
|
+
} from "./permissions.ts";
|
|
32
39
|
export {
|
|
33
40
|
type Action,
|
|
34
41
|
type ActionDef,
|
|
@@ -42,8 +49,6 @@ export {
|
|
|
42
49
|
type Onboarding,
|
|
43
50
|
type OnboardingStep,
|
|
44
51
|
type OptionSource,
|
|
45
|
-
PERMISSIONS,
|
|
46
|
-
type Permission,
|
|
47
52
|
PLUGIN_API_VERSION,
|
|
48
53
|
type PluginCommand,
|
|
49
54
|
type PluginContext,
|
|
@@ -63,14 +68,18 @@ export {
|
|
|
63
68
|
} from "./plugin.ts";
|
|
64
69
|
export {
|
|
65
70
|
type BooleanField,
|
|
71
|
+
behaviorFields,
|
|
66
72
|
type ColorField,
|
|
67
73
|
checkSchema,
|
|
68
74
|
defaultValue,
|
|
69
75
|
type FieldValue,
|
|
76
|
+
type GroupsField,
|
|
70
77
|
type ImageField,
|
|
71
78
|
type InferSettings,
|
|
72
79
|
isFieldVisible,
|
|
73
80
|
type NumberField,
|
|
81
|
+
type OptionGroup,
|
|
82
|
+
optionGroups,
|
|
74
83
|
type PageField,
|
|
75
84
|
resolveSettings,
|
|
76
85
|
type SecretField,
|
|
@@ -78,6 +87,7 @@ export {
|
|
|
78
87
|
type SelectOption,
|
|
79
88
|
type SettingField,
|
|
80
89
|
type SettingsSchema,
|
|
90
|
+
type SettingValue,
|
|
81
91
|
type TextField,
|
|
82
92
|
} from "./settings.ts";
|
|
83
93
|
export { Shared } from "./shared.ts";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a plugin can ask to do. The user decides about each permission separately, and a plugin
|
|
3
|
+
* gets nothing it did not ask for and nothing the user did not allow.
|
|
4
|
+
*/
|
|
5
|
+
export type Permission =
|
|
6
|
+
| "network"
|
|
7
|
+
| "filesystem"
|
|
8
|
+
| "process"
|
|
9
|
+
| "shell"
|
|
10
|
+
| "input"
|
|
11
|
+
| "clipboard"
|
|
12
|
+
| "audio"
|
|
13
|
+
| "environment"
|
|
14
|
+
| "variables"
|
|
15
|
+
| "state"
|
|
16
|
+
| "actions"
|
|
17
|
+
| "native";
|
|
18
|
+
|
|
19
|
+
/** A permission as the user reads it. */
|
|
20
|
+
export interface PermissionText {
|
|
21
|
+
name: string;
|
|
22
|
+
/** What allowing it makes possible. */
|
|
23
|
+
description: string;
|
|
24
|
+
/** Finishes "the plugin is not allowed to …". */
|
|
25
|
+
action: string;
|
|
26
|
+
/** Allowing it lets the plugin do nearly anything the user can. */
|
|
27
|
+
powerful?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Every permission, in the order the UI lists them. */
|
|
31
|
+
export const PERMISSION_TEXTS: Readonly<Record<Permission, PermissionText>> = {
|
|
32
|
+
network: {
|
|
33
|
+
name: "Network",
|
|
34
|
+
description: "Connect to the internet and to devices on your network.",
|
|
35
|
+
action: "use the network",
|
|
36
|
+
},
|
|
37
|
+
filesystem: {
|
|
38
|
+
name: "Files",
|
|
39
|
+
description: "Read and change your files. Its own data folder is always allowed.",
|
|
40
|
+
action: "use files outside its own folder",
|
|
41
|
+
},
|
|
42
|
+
process: {
|
|
43
|
+
name: "Start programs",
|
|
44
|
+
description: "Open apps and run programs that are installed on this computer.",
|
|
45
|
+
action: "start programs",
|
|
46
|
+
powerful: true,
|
|
47
|
+
},
|
|
48
|
+
shell: {
|
|
49
|
+
name: "Run commands",
|
|
50
|
+
description: "Run any command line. Commands can do everything you can.",
|
|
51
|
+
action: "run commands",
|
|
52
|
+
powerful: true,
|
|
53
|
+
},
|
|
54
|
+
input: {
|
|
55
|
+
name: "Keyboard and mouse",
|
|
56
|
+
description: "Press keys, type text and control media playback.",
|
|
57
|
+
action: "press keys",
|
|
58
|
+
},
|
|
59
|
+
clipboard: {
|
|
60
|
+
name: "Clipboard",
|
|
61
|
+
description: "Read and change what you copied.",
|
|
62
|
+
action: "use the clipboard",
|
|
63
|
+
},
|
|
64
|
+
audio: {
|
|
65
|
+
name: "Sound",
|
|
66
|
+
description: "Change volumes, mute apps and switch audio devices.",
|
|
67
|
+
action: "control sound",
|
|
68
|
+
},
|
|
69
|
+
environment: {
|
|
70
|
+
name: "Environment variables",
|
|
71
|
+
description: "Read environment variables, which can contain keys and tokens.",
|
|
72
|
+
action: "read environment variables",
|
|
73
|
+
},
|
|
74
|
+
variables: {
|
|
75
|
+
name: "Your variables",
|
|
76
|
+
description: "Read and change the variables your workflows use.",
|
|
77
|
+
action: "use your variables",
|
|
78
|
+
},
|
|
79
|
+
state: {
|
|
80
|
+
name: "Other plugins' values",
|
|
81
|
+
description: "Read live values from other plugins, such as the app in front.",
|
|
82
|
+
action: "read other plugins' values",
|
|
83
|
+
},
|
|
84
|
+
actions: {
|
|
85
|
+
name: "Other plugins' actions",
|
|
86
|
+
description: "Run actions of other plugins, with the permissions those have.",
|
|
87
|
+
action: "run other plugins' actions",
|
|
88
|
+
powerful: true,
|
|
89
|
+
},
|
|
90
|
+
native: {
|
|
91
|
+
name: "Native code",
|
|
92
|
+
description: "Load compiled code, which sdeck cannot limit in any way.",
|
|
93
|
+
action: "load native code",
|
|
94
|
+
powerful: true,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const PERMISSIONS = Object.keys(PERMISSION_TEXTS) as readonly Permission[];
|
|
99
|
+
|
|
100
|
+
/** Thrown when a plugin does something the user has not allowed. The message is for the user. */
|
|
101
|
+
export class PermissionError extends Error {
|
|
102
|
+
override readonly name = "PermissionError";
|
|
103
|
+
/** As Node's file system reports a refused path, so libraries treat it the same way. */
|
|
104
|
+
readonly code = "EACCES";
|
|
105
|
+
|
|
106
|
+
constructor(
|
|
107
|
+
/** The plugin's name or id. */
|
|
108
|
+
plugin: string,
|
|
109
|
+
readonly permission: Permission,
|
|
110
|
+
/** What was refused, when that helps (a path, an address). */
|
|
111
|
+
detail?: string,
|
|
112
|
+
) {
|
|
113
|
+
const { name, action } = PERMISSION_TEXTS[permission];
|
|
114
|
+
super(
|
|
115
|
+
`${plugin} is not allowed to ${action}${detail ? ` (${detail})` : ""}. ` +
|
|
116
|
+
`Allow "${name}" in the plugin's permissions.`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|