@skillcdn/console 0.4.0 → 0.4.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/README.md +20 -2
- package/SKILLCDN.md +7 -5
- package/dist/api.d.ts +5 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +5 -4
- package/dist/api.js.map +1 -1
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +579 -45
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/format.d.ts +34 -3
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +277 -6
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +60 -7
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/plugin-check.d.ts +21 -0
- package/dist/cli/plugin-check.d.ts.map +1 -0
- package/dist/cli/plugin-check.js +374 -0
- package/dist/cli/plugin-check.js.map +1 -0
- package/dist/cli/plugin-cli.d.ts +20 -0
- package/dist/cli/plugin-cli.d.ts.map +1 -0
- package/dist/cli/plugin-cli.js +123 -0
- package/dist/cli/plugin-cli.js.map +1 -0
- package/dist/cli/plugin-init.d.ts +20 -0
- package/dist/cli/plugin-init.d.ts.map +1 -0
- package/dist/cli/plugin-init.js +74 -0
- package/dist/cli/plugin-init.js.map +1 -0
- package/dist/cli/plugin-main.d.ts +3 -0
- package/dist/cli/plugin-main.d.ts.map +1 -0
- package/dist/cli/plugin-main.js +28 -0
- package/dist/cli/plugin-main.js.map +1 -0
- package/dist/client.d.ts +109 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +67 -2
- package/dist/client.js.map +1 -1
- package/dist/compat.d.ts +1 -1
- package/dist/compat.js +2 -2
- package/dist/components/board.d.ts +8 -0
- package/dist/components/board.d.ts.map +1 -1
- package/dist/components/board.js +59 -15
- package/dist/components/board.js.map +1 -1
- package/dist/components/event-feed.d.ts +1 -1
- package/dist/components/event-feed.d.ts.map +1 -1
- package/dist/components/event-feed.js +33 -1
- package/dist/components/event-feed.js.map +1 -1
- package/dist/components/markdown.d.ts.map +1 -1
- package/dist/components/markdown.js +6 -3
- package/dist/components/markdown.js.map +1 -1
- package/dist/components/pack-connect.d.ts +3 -1
- package/dist/components/pack-connect.d.ts.map +1 -1
- package/dist/components/pack-connect.js +4 -4
- package/dist/components/pack-connect.js.map +1 -1
- package/dist/components/pack-token.d.ts +3 -1
- package/dist/components/pack-token.d.ts.map +1 -1
- package/dist/components/pack-token.js +1 -1
- package/dist/components/pack-token.js.map +1 -1
- package/dist/components/people.d.ts.map +1 -1
- package/dist/components/people.js +14 -3
- package/dist/components/people.js.map +1 -1
- package/dist/components/plugin-frame.d.ts +52 -0
- package/dist/components/plugin-frame.d.ts.map +1 -0
- package/dist/components/plugin-frame.js +314 -0
- package/dist/components/plugin-frame.js.map +1 -0
- package/dist/components/plugin-settings.d.ts +38 -0
- package/dist/components/plugin-settings.d.ts.map +1 -0
- package/dist/components/plugin-settings.js +348 -0
- package/dist/components/plugin-settings.js.map +1 -0
- package/dist/components/remote-pictures.d.ts +6 -0
- package/dist/components/remote-pictures.d.ts.map +1 -0
- package/dist/components/remote-pictures.js +8 -0
- package/dist/components/remote-pictures.js.map +1 -0
- package/dist/components/shell.d.ts +2 -0
- package/dist/components/shell.d.ts.map +1 -1
- package/dist/components/shell.js +26 -1
- package/dist/components/shell.js.map +1 -1
- package/dist/components/sign-in.d.ts.map +1 -1
- package/dist/components/sign-in.js +49 -2
- package/dist/components/sign-in.js.map +1 -1
- package/dist/components/ui.d.ts +3 -2
- package/dist/components/ui.d.ts.map +1 -1
- package/dist/components/ui.js +6 -3
- package/dist/components/ui.js.map +1 -1
- package/dist/components/workspace.d.ts +7 -1
- package/dist/components/workspace.d.ts.map +1 -1
- package/dist/components/workspace.js +1 -1
- package/dist/components/workspace.js.map +1 -1
- package/dist/console.css +384 -5
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +146 -29
- package/dist/console.js.map +1 -1
- package/dist/data.d.ts +11 -2
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +35 -21
- package/dist/data.js.map +1 -1
- package/dist/i18n/en.d.ts +163 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +174 -1
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +154 -1
- package/dist/i18n/ko.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +14 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +14 -0
- package/dist/limits.js.map +1 -1
- package/dist/plugin/args.d.ts +148 -0
- package/dist/plugin/args.d.ts.map +1 -0
- package/dist/plugin/args.js +369 -0
- package/dist/plugin/args.js.map +1 -0
- package/dist/plugin/bridge.d.ts +146 -0
- package/dist/plugin/bridge.d.ts.map +1 -0
- package/dist/plugin/bridge.js +125 -0
- package/dist/plugin/bridge.js.map +1 -0
- package/dist/plugin/capabilities.d.ts +20 -0
- package/dist/plugin/capabilities.d.ts.map +1 -0
- package/dist/plugin/capabilities.js +133 -0
- package/dist/plugin/capabilities.js.map +1 -0
- package/dist/plugin/context.d.ts +374 -0
- package/dist/plugin/context.d.ts.map +1 -0
- package/dist/plugin/context.js +2 -0
- package/dist/plugin/context.js.map +1 -0
- package/dist/plugin/define.d.ts +208 -0
- package/dist/plugin/define.d.ts.map +1 -0
- package/dist/plugin/define.js +482 -0
- package/dist/plugin/define.js.map +1 -0
- package/dist/plugin/definition-error.d.ts +11 -0
- package/dist/plugin/definition-error.d.ts.map +1 -0
- package/dist/plugin/definition-error.js +17 -0
- package/dist/plugin/definition-error.js.map +1 -0
- package/dist/plugin/limits.d.ts +67 -0
- package/dist/plugin/limits.d.ts.map +1 -0
- package/dist/plugin/limits.js +70 -0
- package/dist/plugin/limits.js.map +1 -0
- package/dist/plugin/load-worker.d.ts +7 -0
- package/dist/plugin/load-worker.d.ts.map +1 -0
- package/dist/plugin/load-worker.js +41 -0
- package/dist/plugin/load-worker.js.map +1 -0
- package/dist/plugin/load.d.ts +18 -0
- package/dist/plugin/load.d.ts.map +1 -0
- package/dist/plugin/load.js +62 -0
- package/dist/plugin/load.js.map +1 -0
- package/dist/plugin/manifest.d.ts +237 -0
- package/dist/plugin/manifest.d.ts.map +1 -0
- package/dist/plugin/manifest.js +411 -0
- package/dist/plugin/manifest.js.map +1 -0
- package/dist/plugin/refusals.d.ts +49 -0
- package/dist/plugin/refusals.d.ts.map +1 -0
- package/dist/plugin/refusals.js +79 -0
- package/dist/plugin/refusals.js.map +1 -0
- package/dist/plugin/rest-schemas.d.ts +556 -0
- package/dist/plugin/rest-schemas.d.ts.map +1 -0
- package/dist/plugin/rest-schemas.js +262 -0
- package/dist/plugin/rest-schemas.js.map +1 -0
- package/dist/plugin/sandbox.d.ts +23 -0
- package/dist/plugin/sandbox.d.ts.map +1 -0
- package/dist/plugin/sandbox.js +99 -0
- package/dist/plugin/sandbox.js.map +1 -0
- package/dist/plugin/testing.d.ts +45 -0
- package/dist/plugin/testing.d.ts.map +1 -0
- package/dist/plugin/testing.js +420 -0
- package/dist/plugin/testing.js.map +1 -0
- package/dist/plugin/web-react.d.ts +11 -0
- package/dist/plugin/web-react.d.ts.map +1 -0
- package/dist/plugin/web-react.js +34 -0
- package/dist/plugin/web-react.js.map +1 -0
- package/dist/plugin/web.d.ts +95 -0
- package/dist/plugin/web.d.ts.map +1 -0
- package/dist/plugin/web.js +245 -0
- package/dist/plugin/web.js.map +1 -0
- package/dist/plugin-nav.d.ts +29 -0
- package/dist/plugin-nav.d.ts.map +1 -0
- package/dist/plugin-nav.js +92 -0
- package/dist/plugin-nav.js.map +1 -0
- package/dist/plugin-testing.d.ts +2 -0
- package/dist/plugin-testing.d.ts.map +1 -0
- package/dist/plugin-testing.js +4 -0
- package/dist/plugin-testing.js.map +1 -0
- package/dist/plugin-web-react.d.ts +3 -0
- package/dist/plugin-web-react.d.ts.map +1 -0
- package/dist/plugin-web-react.js +3 -0
- package/dist/plugin-web-react.js.map +1 -0
- package/dist/plugin-web.d.ts +4 -0
- package/dist/plugin-web.d.ts.map +1 -0
- package/dist/plugin-web.js +5 -0
- package/dist/plugin-web.js.map +1 -0
- package/dist/plugin.d.ts +11 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +15 -0
- package/dist/plugin.js.map +1 -0
- package/dist/router.d.ts +28 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +47 -0
- package/dist/router.js.map +1 -1
- package/dist/routes.d.ts +6 -0
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +8 -0
- package/dist/routes.js.map +1 -1
- package/dist/schemas.d.ts +147 -1
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +55 -5
- package/dist/schemas.js.map +1 -1
- package/dist/tokens.d.ts +2 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +101 -0
- package/dist/tokens.js.map +1 -0
- package/dist/vocabulary.d.ts +11 -1
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +24 -0
- package/dist/vocabulary.js.map +1 -1
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +5 -2
- package/dist/web.js.map +1 -1
- package/docs/specs/cli.md +16 -9
- package/docs/specs/plugins.md +487 -0
- package/docs/specs/rest.md +25 -13
- package/package.json +21 -3
- package/skills/building-a-console/SKILL.md +25 -26
- package/skills/building-a-console/references/configuring.md +40 -0
- package/skills/building-a-console/references/the-default-console.md +1 -1
- package/skills/building-a-console/references/the-look-from-a-website.md +5 -5
- package/skills/building-a-plugin/SKILL.md +137 -0
- package/skills/deploying-a-console/SKILL.md +24 -26
- package/skills/deploying-a-console/references/access.md +13 -9
- package/skills/deploying-a-console/references/resources.md +25 -10
- package/skills/deploying-a-console/references/running-it-again.md +15 -0
- package/skills/deploying-a-console/references/sizing.md +2 -0
- package/skills/planning-the-board/SKILL.md +96 -0
- package/skills/planning-the-board/references/a-task.md +36 -0
- package/skills/planning-the-board/references/setting-up.md +44 -0
- package/skills/working-the-board/SKILL.md +43 -34
- package/skills/working-the-board/references/the-pack.md +19 -0
- package/src/api.ts +16 -0
- package/src/cli/cli.ts +736 -45
- package/src/cli/format.ts +356 -9
- package/src/cli/help.ts +71 -6
- package/src/cli/plugin-check.ts +470 -0
- package/src/cli/plugin-cli.ts +148 -0
- package/src/cli/plugin-init.ts +90 -0
- package/src/cli/plugin-main.ts +30 -0
- package/src/client.ts +324 -1
- package/src/compat.ts +2 -2
- package/src/components/board.tsx +62 -14
- package/src/components/event-feed.tsx +42 -1
- package/src/components/markdown.tsx +6 -3
- package/src/components/pack-connect.tsx +10 -7
- package/src/components/pack-token.tsx +4 -1
- package/src/components/people.tsx +17 -7
- package/src/components/plugin-frame.tsx +437 -0
- package/src/components/plugin-settings.tsx +1111 -0
- package/src/components/remote-pictures.ts +19 -0
- package/src/components/shell.tsx +82 -14
- package/src/components/sign-in.tsx +114 -13
- package/src/components/ui.tsx +6 -3
- package/src/components/workspace.tsx +18 -0
- package/src/console.tsx +309 -23
- package/src/data.ts +47 -22
- package/src/i18n/en.ts +183 -1
- package/src/i18n/ko.ts +159 -1
- package/src/index.ts +12 -0
- package/src/limits.ts +14 -0
- package/src/plugin/args.ts +526 -0
- package/src/plugin/bridge.ts +314 -0
- package/src/plugin/capabilities.ts +150 -0
- package/src/plugin/context.ts +416 -0
- package/src/plugin/define.ts +792 -0
- package/src/plugin/definition-error.ts +19 -0
- package/src/plugin/limits.ts +70 -0
- package/src/plugin/load-worker.ts +50 -0
- package/src/plugin/load.ts +82 -0
- package/src/plugin/manifest.ts +561 -0
- package/src/plugin/refusals.ts +94 -0
- package/src/plugin/rest-schemas.ts +354 -0
- package/src/plugin/sandbox.ts +123 -0
- package/src/plugin/testing.ts +612 -0
- package/src/plugin/web-react.ts +45 -0
- package/src/plugin/web.ts +403 -0
- package/src/plugin-nav.ts +132 -0
- package/src/plugin-testing.ts +10 -0
- package/src/plugin-web-react.ts +4 -0
- package/src/plugin-web.ts +35 -0
- package/src/plugin.ts +126 -0
- package/src/router.ts +73 -0
- package/src/routes.ts +9 -0
- package/src/schemas.ts +60 -4
- package/src/styles/console.css +384 -5
- package/src/tokens.ts +101 -0
- package/src/vocabulary.ts +30 -0
- package/src/web.ts +5 -2
- package/template/plugin/.gitignore +2 -0
- package/template/plugin/README.md +26 -0
- package/template/plugin/SKILLCDN.md +13 -0
- package/template/plugin/build.mjs +40 -0
- package/template/plugin/console-plugin.json +50 -0
- package/template/plugin/package.json +27 -0
- package/template/plugin/skills/__key__/SKILL.md +23 -0
- package/template/plugin/src/check.test.ts +34 -0
- package/template/plugin/src/server/index.test.ts +41 -0
- package/template/plugin/src/server/index.ts +72 -0
- package/template/plugin/src/web/index.css +51 -0
- package/template/plugin/src/web/index.ts +115 -0
- package/template/plugin/tsconfig.json +17 -0
- package/skills/working-the-board/references/setting-up.md +0 -3
- /package/skills/{working-the-board → planning-the-board}/references/project-rules.md +0 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
// The arguments of a plugin's commands and queries (docs/specs/plugins.md, "The server module"):
|
|
2
|
+
// each defined once, as data the console parses command lines against, writes help from and draws
|
|
3
|
+
// forms from, and as a type the command's `run` receives. A definer yields a plain object; what
|
|
4
|
+
// crosses from the plugin's thread to the console is exactly that object.
|
|
5
|
+
import { PluginDefinitionError } from "./definition-error.js";
|
|
6
|
+
import { MAX_PLUGIN_ABOUT_LENGTH, MAX_PLUGIN_OPTIONS } from "./limits.js";
|
|
7
|
+
import { PLUGIN_KEY_PATTERN } from "./manifest.js";
|
|
8
|
+
export const ARG_TYPES = [
|
|
9
|
+
"text",
|
|
10
|
+
"markdown",
|
|
11
|
+
"day",
|
|
12
|
+
"number",
|
|
13
|
+
"boolean",
|
|
14
|
+
"enum",
|
|
15
|
+
"person",
|
|
16
|
+
"project",
|
|
17
|
+
"record",
|
|
18
|
+
"list",
|
|
19
|
+
"file",
|
|
20
|
+
];
|
|
21
|
+
function common(options) {
|
|
22
|
+
const about = options?.about;
|
|
23
|
+
if (about !== undefined &&
|
|
24
|
+
(about.length === 0 || about.length > MAX_PLUGIN_ABOUT_LENGTH || /[\r\n]/.test(about))) {
|
|
25
|
+
throw new PluginDefinitionError([
|
|
26
|
+
`an argument's about is one line of 1 to ${MAX_PLUGIN_ABOUT_LENGTH} characters`,
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
...(about === undefined ? {} : { about }),
|
|
31
|
+
optional: (options?.optional ?? false),
|
|
32
|
+
positional: options?.positional ?? false,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function bound(name, value, integer) {
|
|
36
|
+
if (value !== undefined && (!Number.isFinite(value) || (integer && !Number.isInteger(value)))) {
|
|
37
|
+
throw new PluginDefinitionError([`${name} is not a ${integer ? "whole " : ""}number`]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** The definers: `arg.text({ max: 200 })`, `arg.day({ positional: true })`, `arg.list(arg.person())`. */
|
|
41
|
+
export const arg = {
|
|
42
|
+
/** A line of text, up to `max` characters; `secret` hides it in the event the command leaves. */
|
|
43
|
+
text(options) {
|
|
44
|
+
bound("max", options?.max, true);
|
|
45
|
+
return {
|
|
46
|
+
type: "text",
|
|
47
|
+
...common(options),
|
|
48
|
+
...(options?.max === undefined ? {} : { max: options.max }),
|
|
49
|
+
...(options?.secret === true ? { secret: true } : {}),
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
/** Markdown, with its line breaks, up to `max` characters. */
|
|
53
|
+
markdown(options) {
|
|
54
|
+
bound("max", options?.max, true);
|
|
55
|
+
return {
|
|
56
|
+
type: "markdown",
|
|
57
|
+
...common(options),
|
|
58
|
+
...(options?.max === undefined ? {} : { max: options.max }),
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
/** A day as `YYYY-MM-DD`. */
|
|
62
|
+
day(options) {
|
|
63
|
+
return { type: "day", ...common(options) };
|
|
64
|
+
},
|
|
65
|
+
/** A number, within `min` and `max`, whole where `integer`. */
|
|
66
|
+
number(options) {
|
|
67
|
+
bound("min", options?.min, false);
|
|
68
|
+
bound("max", options?.max, false);
|
|
69
|
+
if (options?.min !== undefined && options.max !== undefined && options.min > options.max) {
|
|
70
|
+
throw new PluginDefinitionError(["min is above max"]);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
type: "number",
|
|
74
|
+
...common(options),
|
|
75
|
+
...(options?.min === undefined ? {} : { min: options.min }),
|
|
76
|
+
...(options?.max === undefined ? {} : { max: options.max }),
|
|
77
|
+
...(options?.integer === true ? { integer: true } : {}),
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
/** `true` or `false`; on the command line, `--<name>` alone is `true`. */
|
|
81
|
+
boolean(options) {
|
|
82
|
+
return { type: "boolean", ...common(options) };
|
|
83
|
+
},
|
|
84
|
+
/** One of the words given. */
|
|
85
|
+
enum(values, options) {
|
|
86
|
+
if (values.length === 0 ||
|
|
87
|
+
values.length > MAX_PLUGIN_OPTIONS ||
|
|
88
|
+
new Set(values).size !== values.length) {
|
|
89
|
+
throw new PluginDefinitionError([`an enum takes 1 to ${MAX_PLUGIN_OPTIONS} different words`]);
|
|
90
|
+
}
|
|
91
|
+
for (const value of values) {
|
|
92
|
+
if (value.length === 0 || value.length > 64 || /\s/.test(value)) {
|
|
93
|
+
throw new PluginDefinitionError([
|
|
94
|
+
`the enum word "${value}" is not one word of up to 64 characters`,
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { type: "enum", ...common(options), options: [...values] };
|
|
99
|
+
},
|
|
100
|
+
/** A person: a login or `me` on the command line, resolved by the console to one the caller may see. */
|
|
101
|
+
person(options) {
|
|
102
|
+
return { type: "person", ...common(options) };
|
|
103
|
+
},
|
|
104
|
+
/** A project: a key the caller may see. */
|
|
105
|
+
project(options) {
|
|
106
|
+
return { type: "project", ...common(options) };
|
|
107
|
+
},
|
|
108
|
+
/** The id of a record of the collection named, one of this plugin's. */
|
|
109
|
+
record(collection, options) {
|
|
110
|
+
if (!PLUGIN_KEY_PATTERN.test(collection)) {
|
|
111
|
+
throw new PluginDefinitionError([
|
|
112
|
+
`arg.record names the collection "${collection}", which is not a key`,
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
return { type: "record", ...common(options), collection };
|
|
116
|
+
},
|
|
117
|
+
/** Several of the inner argument: the flag repeated, or commas between; up to `max` items. */
|
|
118
|
+
list(of, options) {
|
|
119
|
+
if (of.type === "list" || of.type === "file" || of.type === "markdown") {
|
|
120
|
+
throw new PluginDefinitionError([`a list of ${of.type} is not an argument`]);
|
|
121
|
+
}
|
|
122
|
+
if (of.optional || of.positional) {
|
|
123
|
+
throw new PluginDefinitionError([
|
|
124
|
+
"the items of a list are neither optional nor positional themselves",
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
bound("max", options?.max, true);
|
|
128
|
+
return {
|
|
129
|
+
type: "list",
|
|
130
|
+
...common(options),
|
|
131
|
+
...(options?.max === undefined ? {} : { max: options.max }),
|
|
132
|
+
of,
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
/** A file: what `--file <path>` or `-` carried, uploaded first and handed as a handle. */
|
|
136
|
+
file(options) {
|
|
137
|
+
return { type: "file", ...common(options) };
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
const DAY = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/;
|
|
141
|
+
const DEFAULT_TEXT_MAX = 2000;
|
|
142
|
+
const DEFAULT_MARKDOWN_MAX = 20_000;
|
|
143
|
+
const DEFAULT_LIST_MAX = 100;
|
|
144
|
+
/**
|
|
145
|
+
* The problem with a value for an argument, as it arrives on the wire before the console
|
|
146
|
+
* resolves it: a person is a login or `me`, a project a key, a record an id, a file a handle, each
|
|
147
|
+
* a string. Nothing when the value fits.
|
|
148
|
+
*/
|
|
149
|
+
export function argProblem(name, description, value) {
|
|
150
|
+
if (value === undefined) {
|
|
151
|
+
return description.optional ? undefined : `${name} is required`;
|
|
152
|
+
}
|
|
153
|
+
switch (description.type) {
|
|
154
|
+
case "text":
|
|
155
|
+
case "markdown": {
|
|
156
|
+
if (typeof value !== "string") {
|
|
157
|
+
return `${name} is not text`;
|
|
158
|
+
}
|
|
159
|
+
const max = description.max ?? (description.type === "text" ? DEFAULT_TEXT_MAX : DEFAULT_MARKDOWN_MAX);
|
|
160
|
+
if (value.length > max) {
|
|
161
|
+
return `${name} is over ${max} characters`;
|
|
162
|
+
}
|
|
163
|
+
if (description.type === "text" && /[\r\n]/.test(value)) {
|
|
164
|
+
return `${name} is one line`;
|
|
165
|
+
}
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
case "day":
|
|
169
|
+
return typeof value === "string" && DAY.test(value)
|
|
170
|
+
? undefined
|
|
171
|
+
: `${name} is not a day as YYYY-MM-DD`;
|
|
172
|
+
case "number": {
|
|
173
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
174
|
+
return `${name} is not a number`;
|
|
175
|
+
}
|
|
176
|
+
if (description.integer === true && !Number.isInteger(value)) {
|
|
177
|
+
return `${name} is not a whole number`;
|
|
178
|
+
}
|
|
179
|
+
if (description.min !== undefined && value < description.min) {
|
|
180
|
+
return `${name} is below ${description.min}`;
|
|
181
|
+
}
|
|
182
|
+
if (description.max !== undefined && value > description.max) {
|
|
183
|
+
return `${name} is above ${description.max}`;
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
case "boolean":
|
|
188
|
+
return typeof value === "boolean" ? undefined : `${name} is true or false`;
|
|
189
|
+
case "enum":
|
|
190
|
+
return typeof value === "string" && (description.options ?? []).includes(value)
|
|
191
|
+
? undefined
|
|
192
|
+
: `${name} is one of ${(description.options ?? []).join(", ")}`;
|
|
193
|
+
case "person":
|
|
194
|
+
case "project":
|
|
195
|
+
case "record":
|
|
196
|
+
case "file":
|
|
197
|
+
return typeof value === "string" && value.length > 0 && value.length <= 254
|
|
198
|
+
? undefined
|
|
199
|
+
: `${name} is not valid`;
|
|
200
|
+
case "list": {
|
|
201
|
+
if (!Array.isArray(value)) {
|
|
202
|
+
return `${name} is a list`;
|
|
203
|
+
}
|
|
204
|
+
const max = description.max ?? DEFAULT_LIST_MAX;
|
|
205
|
+
if (value.length > max) {
|
|
206
|
+
return `${name} has more than ${max} items`;
|
|
207
|
+
}
|
|
208
|
+
const of = description.of;
|
|
209
|
+
if (of === undefined) {
|
|
210
|
+
return `${name} has no item type`;
|
|
211
|
+
}
|
|
212
|
+
for (const [index, item] of value.entries()) {
|
|
213
|
+
const problem = argProblem(`${name}[${index}]`, of, item);
|
|
214
|
+
if (problem !== undefined) {
|
|
215
|
+
return problem;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
default:
|
|
221
|
+
return `${name} has a type the console does not know`;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/** The first problem with a set of values against their definitions, unknown names included; nothing when all fit. */
|
|
225
|
+
export function argsProblem(definitions, values) {
|
|
226
|
+
for (const name of Object.keys(values)) {
|
|
227
|
+
if (!(name in definitions)) {
|
|
228
|
+
return `${name} is not an argument of this command`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
for (const [name, description] of Object.entries(definitions)) {
|
|
232
|
+
const problem = argProblem(name, description, values[name]);
|
|
233
|
+
if (problem !== undefined) {
|
|
234
|
+
return problem;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* A word from the command line as the value an argument takes: a number read, a boolean read,
|
|
241
|
+
* a list split at commas; text as it is. Nothing the word cannot be is a problem `argProblem`
|
|
242
|
+
* then names.
|
|
243
|
+
*/
|
|
244
|
+
export function argValueFromWord(description, word) {
|
|
245
|
+
switch (description.type) {
|
|
246
|
+
case "number": {
|
|
247
|
+
const trimmed = word.trim();
|
|
248
|
+
return /^-?\d+(?:\.\d+)?$/.test(trimmed) ? Number(trimmed) : word;
|
|
249
|
+
}
|
|
250
|
+
case "boolean":
|
|
251
|
+
return word === "true" || word === "" ? true : word === "false" ? false : word;
|
|
252
|
+
case "list": {
|
|
253
|
+
const of = description.of;
|
|
254
|
+
return word
|
|
255
|
+
.split(",")
|
|
256
|
+
.map((item) => item.trim())
|
|
257
|
+
.filter((item) => item.length > 0)
|
|
258
|
+
.map((item) => (of === undefined ? item : argValueFromWord(of, item)));
|
|
259
|
+
}
|
|
260
|
+
default:
|
|
261
|
+
return word;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The words of a command line as the arguments of a command or a query, by its definitions
|
|
266
|
+
* (docs/specs/plugins.md, "The command"): the positional arguments in declaration order, one word
|
|
267
|
+
* each, among the flags, `--name value` or `--name=value`; a boolean flag alone means true; a
|
|
268
|
+
* list is a flag given again, or commas between its items; `--` ends the flags. An argument of
|
|
269
|
+
* type `file` takes the handles of the files the command uploaded, one each in declaration
|
|
270
|
+
* order, where none is named. The values are then checked with `argsProblem`.
|
|
271
|
+
*/
|
|
272
|
+
export function parseArgv(definitions, argv, files = []) {
|
|
273
|
+
const values = {};
|
|
274
|
+
const positionals = Object.entries(definitions).filter(([, description]) => description.positional);
|
|
275
|
+
let position = 0;
|
|
276
|
+
let flagsEnded = false;
|
|
277
|
+
const put = (name, description, word) => {
|
|
278
|
+
const value = argValueFromWord(description, word);
|
|
279
|
+
if (description.type === "list") {
|
|
280
|
+
const current = values[name];
|
|
281
|
+
values[name] = Array.isArray(current) ? [...current, ...value] : value;
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
if (Object.hasOwn(values, name)) {
|
|
285
|
+
return `${name} is given more than once`;
|
|
286
|
+
}
|
|
287
|
+
values[name] = value;
|
|
288
|
+
return undefined;
|
|
289
|
+
};
|
|
290
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
291
|
+
const word = argv[index] ?? "";
|
|
292
|
+
if (!flagsEnded && word === "--") {
|
|
293
|
+
flagsEnded = true;
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
if (!flagsEnded && word.startsWith("--") && word.length > 2) {
|
|
297
|
+
const equals = word.indexOf("=");
|
|
298
|
+
const name = equals < 0 ? word.slice(2) : word.slice(2, equals);
|
|
299
|
+
const description = Object.hasOwn(definitions, name) ? definitions[name] : undefined;
|
|
300
|
+
if (description === undefined) {
|
|
301
|
+
return { problem: `--${name} is not an argument of this command` };
|
|
302
|
+
}
|
|
303
|
+
let given;
|
|
304
|
+
if (equals >= 0) {
|
|
305
|
+
given = word.slice(equals + 1);
|
|
306
|
+
}
|
|
307
|
+
else if (description.type === "boolean") {
|
|
308
|
+
given = "";
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
const next = argv[index + 1];
|
|
312
|
+
if (next === undefined) {
|
|
313
|
+
return { problem: `--${name} needs a value` };
|
|
314
|
+
}
|
|
315
|
+
given = next;
|
|
316
|
+
index += 1;
|
|
317
|
+
}
|
|
318
|
+
const problem = put(name, description, given);
|
|
319
|
+
if (problem !== undefined) {
|
|
320
|
+
return { problem };
|
|
321
|
+
}
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
const slot = positionals[position];
|
|
325
|
+
if (slot === undefined) {
|
|
326
|
+
return {
|
|
327
|
+
problem: positionals.length === 0
|
|
328
|
+
? `${JSON.stringify(word)} is one word too many: the command takes no positional argument, only flags`
|
|
329
|
+
: `${JSON.stringify(word)} is one word too many: the command takes ${positionals.length} positional argument${positionals.length === 1 ? "" : "s"}`,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
const problem = put(slot[0], slot[1], word);
|
|
333
|
+
if (problem !== undefined) {
|
|
334
|
+
return { problem };
|
|
335
|
+
}
|
|
336
|
+
position += 1;
|
|
337
|
+
}
|
|
338
|
+
let taken = 0;
|
|
339
|
+
let slots = 0;
|
|
340
|
+
for (const [name, description] of Object.entries(definitions)) {
|
|
341
|
+
if (description.type !== "file") {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
slots += 1;
|
|
345
|
+
if (!Object.hasOwn(values, name) && taken < files.length) {
|
|
346
|
+
values[name] = files[taken];
|
|
347
|
+
taken += 1;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (taken < files.length) {
|
|
351
|
+
return {
|
|
352
|
+
problem: slots === 0
|
|
353
|
+
? "the command takes no file"
|
|
354
|
+
: `the command takes ${slots} file${slots === 1 ? "" : "s"}, not ${files.length}`,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
return { values };
|
|
358
|
+
}
|
|
359
|
+
/** The usage of an argument, as help prints it: `<from>` for a positional, `--to <day>` for a flag, in brackets where optional. */
|
|
360
|
+
export function argUsage(name, description) {
|
|
361
|
+
const placeholder = description.type === "list" ? `${description.of?.type ?? "item"},...` : description.type;
|
|
362
|
+
const form = description.type === "boolean" && !description.positional
|
|
363
|
+
? `--${name}`
|
|
364
|
+
: description.positional
|
|
365
|
+
? `<${name}>`
|
|
366
|
+
: `--${name} <${placeholder}>`;
|
|
367
|
+
return description.optional ? `[${form}]` : form;
|
|
368
|
+
}
|
|
369
|
+
//# sourceMappingURL=args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/plugin/args.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,kGAAkG;AAClG,gGAAgG;AAChG,0EAA0E;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,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AC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;IAC3F,MAAM,IAAI,GACR,WAAW,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,UAAU;QACvD,CAAC,CAAC,KAAK,IAAI,EAAE;QACb,CAAC,CAAC,WAAW,CAAC,UAAU;YACtB,CAAC,CAAC,IAAI,IAAI,GAAG;YACb,CAAC,CAAC,KAAK,IAAI,KAAK,WAAW,GAAG,CAAC;IACrC,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
export declare const PLUGIN_BRIDGE_VERSION = 1;
|
|
2
|
+
/** What the frame may ask the page to perform, each under `/api/v1/plugins/<key>/` and nothing else. */
|
|
3
|
+
export declare const BRIDGE_METHODS: readonly ["command", "query", "records.list", "records.get", "records.versions", "files.get", "files.put"];
|
|
4
|
+
export type BridgeMethod = (typeof BRIDGE_METHODS)[number];
|
|
5
|
+
/** The kinds of `event` a frame may subscribe to: its plugin's records changed, a command ran, the plugin emitted. */
|
|
6
|
+
export declare const BRIDGE_EVENT_KINDS: readonly ["records", "command", "plugin"];
|
|
7
|
+
export type BridgeEventKind = (typeof BRIDGE_EVENT_KINDS)[number];
|
|
8
|
+
export interface BridgePerson {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly login: string;
|
|
11
|
+
readonly name: string | null;
|
|
12
|
+
readonly language: string;
|
|
13
|
+
readonly admin: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** What the page tells the frame once it is ready: who looks, at what, in which words and colours. */
|
|
16
|
+
export interface BridgeInit {
|
|
17
|
+
readonly v: 1;
|
|
18
|
+
readonly t: "init";
|
|
19
|
+
readonly plugin: {
|
|
20
|
+
readonly key: string;
|
|
21
|
+
readonly version: string;
|
|
22
|
+
};
|
|
23
|
+
readonly page?: string;
|
|
24
|
+
readonly widget?: string;
|
|
25
|
+
readonly project: {
|
|
26
|
+
readonly key: string;
|
|
27
|
+
readonly name: string;
|
|
28
|
+
} | null;
|
|
29
|
+
readonly person: BridgePerson;
|
|
30
|
+
readonly roles: readonly string[];
|
|
31
|
+
/** What follows the page's key in the address. */
|
|
32
|
+
readonly path: string;
|
|
33
|
+
readonly language: string;
|
|
34
|
+
/** The console's computed design tokens, `--sc-*`. */
|
|
35
|
+
readonly theme: Readonly<Record<string, string>>;
|
|
36
|
+
}
|
|
37
|
+
export interface BridgeError {
|
|
38
|
+
readonly code: string;
|
|
39
|
+
readonly message: string;
|
|
40
|
+
readonly data?: unknown;
|
|
41
|
+
}
|
|
42
|
+
export interface BridgeResult {
|
|
43
|
+
readonly v: 1;
|
|
44
|
+
readonly t: "result";
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly ok: boolean;
|
|
47
|
+
readonly value?: unknown;
|
|
48
|
+
readonly error?: BridgeError;
|
|
49
|
+
}
|
|
50
|
+
export interface BridgeEvent {
|
|
51
|
+
readonly v: 1;
|
|
52
|
+
readonly t: "event";
|
|
53
|
+
readonly kind: BridgeEventKind;
|
|
54
|
+
readonly data: unknown;
|
|
55
|
+
}
|
|
56
|
+
export interface BridgeTheme {
|
|
57
|
+
readonly v: 1;
|
|
58
|
+
readonly t: "theme";
|
|
59
|
+
readonly theme: Readonly<Record<string, string>>;
|
|
60
|
+
}
|
|
61
|
+
export interface BridgePath {
|
|
62
|
+
readonly v: 1;
|
|
63
|
+
readonly t: "path";
|
|
64
|
+
readonly path: string;
|
|
65
|
+
}
|
|
66
|
+
export type BridgeToFrame = BridgeInit | BridgeResult | BridgeEvent | BridgeTheme | BridgePath;
|
|
67
|
+
export interface BridgeReady {
|
|
68
|
+
readonly v: 1;
|
|
69
|
+
readonly t: "ready";
|
|
70
|
+
}
|
|
71
|
+
export interface BridgeCall {
|
|
72
|
+
readonly v: 1;
|
|
73
|
+
readonly t: "call";
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly method: BridgeMethod;
|
|
76
|
+
readonly params: unknown;
|
|
77
|
+
}
|
|
78
|
+
export interface BridgeNavigate {
|
|
79
|
+
readonly v: 1;
|
|
80
|
+
readonly t: "navigate";
|
|
81
|
+
readonly path: string;
|
|
82
|
+
}
|
|
83
|
+
export interface BridgeResize {
|
|
84
|
+
readonly v: 1;
|
|
85
|
+
readonly t: "resize";
|
|
86
|
+
readonly height: number;
|
|
87
|
+
}
|
|
88
|
+
export interface BridgeTitle {
|
|
89
|
+
readonly v: 1;
|
|
90
|
+
readonly t: "title";
|
|
91
|
+
readonly text: string;
|
|
92
|
+
}
|
|
93
|
+
export interface BridgeDownload {
|
|
94
|
+
readonly v: 1;
|
|
95
|
+
readonly t: "download";
|
|
96
|
+
readonly id: string;
|
|
97
|
+
}
|
|
98
|
+
export interface BridgeSubscribe {
|
|
99
|
+
readonly v: 1;
|
|
100
|
+
readonly t: "subscribe";
|
|
101
|
+
readonly kinds: readonly BridgeEventKind[];
|
|
102
|
+
}
|
|
103
|
+
export type BridgeToPage = BridgeReady | BridgeCall | BridgeNavigate | BridgeResize | BridgeTitle | BridgeDownload | BridgeSubscribe;
|
|
104
|
+
/** A path of the console's, as `navigate` and `path` carry one: absolute, no scheme, no host, one line. */
|
|
105
|
+
export declare const MAX_BRIDGE_PATH_LENGTH = 2048;
|
|
106
|
+
export declare const MAX_BRIDGE_TITLE_LENGTH = 200;
|
|
107
|
+
/** True for a path the page may follow: within the console, never a URL. */
|
|
108
|
+
export declare function isBridgePath(value: unknown): value is string;
|
|
109
|
+
/** True for a message the frame may act on, as the console's page sends them. */
|
|
110
|
+
export declare function isBridgeToFrame(value: unknown): value is BridgeToFrame;
|
|
111
|
+
/** True for a message the page may act on, as a frame sends them; anything else is dropped unread. */
|
|
112
|
+
export declare function isBridgeToPage(value: unknown): value is BridgeToPage;
|
|
113
|
+
/** The result of a command as the frame receives it, the same shape the command line prints from. */
|
|
114
|
+
export interface BridgeCommandResult {
|
|
115
|
+
readonly kind: "command" | "query";
|
|
116
|
+
readonly text: string;
|
|
117
|
+
readonly data: unknown;
|
|
118
|
+
readonly waiting: string | null;
|
|
119
|
+
}
|
|
120
|
+
/** What `records.list` and `records.get` carry in `params`, as the page sends them on. */
|
|
121
|
+
export interface BridgeRecordsListParams {
|
|
122
|
+
readonly collection: string;
|
|
123
|
+
readonly where?: Readonly<Record<string, unknown>>;
|
|
124
|
+
readonly order?: string;
|
|
125
|
+
readonly limit?: number;
|
|
126
|
+
readonly after?: string;
|
|
127
|
+
readonly q?: string;
|
|
128
|
+
readonly project?: string;
|
|
129
|
+
}
|
|
130
|
+
export interface BridgeRecordsGetParams {
|
|
131
|
+
readonly collection: string;
|
|
132
|
+
readonly id: string;
|
|
133
|
+
readonly version?: number;
|
|
134
|
+
}
|
|
135
|
+
export interface BridgeFilesPutParams {
|
|
136
|
+
readonly bytes: ArrayBuffer;
|
|
137
|
+
readonly name: string;
|
|
138
|
+
readonly type: string;
|
|
139
|
+
}
|
|
140
|
+
/** What `files.get` answers: the bytes, transferred, with the file's name and type. */
|
|
141
|
+
export interface BridgeFile {
|
|
142
|
+
readonly name: string;
|
|
143
|
+
readonly type: string;
|
|
144
|
+
readonly bytes: ArrayBuffer;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/plugin/bridge.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,wGAAwG;AACxG,eAAO,MAAM,cAAc,YACzB,SAAS,EACT,OAAO,EACP,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,WAAW,CACH,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D,sHAAsH;AACtH,eAAO,MAAM,kBAAkB,YAAI,SAAS,EAAE,SAAS,EAAE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Q,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,uFAAuF;AACvF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// The messages between the console's page and a plugin's frame (docs/specs/plugins.md, "The
|
|
2
|
+
// bridge"): every message `{ v: 1, t, ... }`, the page accepting the frame's window alone, the
|
|
3
|
+
// frame the console's origin alone. The shapes and their guards, with no DOM in them, so that the
|
|
4
|
+
// page's side and the frame's side read the same words and the tests need no browser.
|
|
5
|
+
export const PLUGIN_BRIDGE_VERSION = 1;
|
|
6
|
+
/** What the frame may ask the page to perform, each under `/api/v1/plugins/<key>/` and nothing else. */
|
|
7
|
+
export const BRIDGE_METHODS = [
|
|
8
|
+
"command",
|
|
9
|
+
"query",
|
|
10
|
+
"records.list",
|
|
11
|
+
"records.get",
|
|
12
|
+
"records.versions",
|
|
13
|
+
"files.get",
|
|
14
|
+
"files.put",
|
|
15
|
+
];
|
|
16
|
+
/** The kinds of `event` a frame may subscribe to: its plugin's records changed, a command ran, the plugin emitted. */
|
|
17
|
+
export const BRIDGE_EVENT_KINDS = ["records", "command", "plugin"];
|
|
18
|
+
/** A path of the console's, as `navigate` and `path` carry one: absolute, no scheme, no host, one line. */
|
|
19
|
+
export const MAX_BRIDGE_PATH_LENGTH = 2048;
|
|
20
|
+
export const MAX_BRIDGE_TITLE_LENGTH = 200;
|
|
21
|
+
const MAX_ID_LENGTH = 128;
|
|
22
|
+
const MAX_THEME_TOKENS = 500;
|
|
23
|
+
function isRecord(value) {
|
|
24
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
function isLine(value, max) {
|
|
27
|
+
return (typeof value === "string" && value.length > 0 && value.length <= max && !/[\r\n]/.test(value));
|
|
28
|
+
}
|
|
29
|
+
/** True for a path the page may follow: within the console, never a URL. */
|
|
30
|
+
export function isBridgePath(value) {
|
|
31
|
+
return (typeof value === "string" &&
|
|
32
|
+
value.length <= MAX_BRIDGE_PATH_LENGTH &&
|
|
33
|
+
value.startsWith("/") &&
|
|
34
|
+
!value.startsWith("//") &&
|
|
35
|
+
!/[\s\\]/.test(value));
|
|
36
|
+
}
|
|
37
|
+
function isTheme(value) {
|
|
38
|
+
if (!isRecord(value)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const entries = Object.entries(value);
|
|
42
|
+
return (entries.length <= MAX_THEME_TOKENS &&
|
|
43
|
+
entries.every(([token, text]) => /^--sc-[a-z0-9-]+$/.test(token) && typeof text === "string" && text.length <= 200));
|
|
44
|
+
}
|
|
45
|
+
function isEnvelope(value) {
|
|
46
|
+
return isRecord(value) && value.v === PLUGIN_BRIDGE_VERSION && typeof value.t === "string";
|
|
47
|
+
}
|
|
48
|
+
/** True for a message the frame may act on, as the console's page sends them. */
|
|
49
|
+
export function isBridgeToFrame(value) {
|
|
50
|
+
if (!isEnvelope(value)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
switch (value.t) {
|
|
54
|
+
case "init":
|
|
55
|
+
return (isRecord(value.plugin) &&
|
|
56
|
+
isLine(value.plugin.key, 32) &&
|
|
57
|
+
isLine(value.plugin.version, 64) &&
|
|
58
|
+
(value.page === undefined || isLine(value.page, 32)) &&
|
|
59
|
+
(value.widget === undefined || isLine(value.widget, 32)) &&
|
|
60
|
+
(value.project === null ||
|
|
61
|
+
(isRecord(value.project) &&
|
|
62
|
+
isLine(value.project.key, 64) &&
|
|
63
|
+
typeof value.project.name === "string")) &&
|
|
64
|
+
isRecord(value.person) &&
|
|
65
|
+
typeof value.person.id === "string" &&
|
|
66
|
+
typeof value.person.login === "string" &&
|
|
67
|
+
(value.person.name === null || typeof value.person.name === "string") &&
|
|
68
|
+
typeof value.person.language === "string" &&
|
|
69
|
+
typeof value.person.admin === "boolean" &&
|
|
70
|
+
Array.isArray(value.roles) &&
|
|
71
|
+
value.roles.every((role) => typeof role === "string") &&
|
|
72
|
+
typeof value.path === "string" &&
|
|
73
|
+
value.path.length <= MAX_BRIDGE_PATH_LENGTH &&
|
|
74
|
+
typeof value.language === "string" &&
|
|
75
|
+
isTheme(value.theme));
|
|
76
|
+
case "result":
|
|
77
|
+
return (isLine(value.id, MAX_ID_LENGTH) &&
|
|
78
|
+
typeof value.ok === "boolean" &&
|
|
79
|
+
(value.error === undefined ||
|
|
80
|
+
(isRecord(value.error) &&
|
|
81
|
+
typeof value.error.code === "string" &&
|
|
82
|
+
typeof value.error.message === "string")));
|
|
83
|
+
case "event":
|
|
84
|
+
return (typeof value.kind === "string" &&
|
|
85
|
+
BRIDGE_EVENT_KINDS.includes(value.kind));
|
|
86
|
+
case "theme":
|
|
87
|
+
return isTheme(value.theme);
|
|
88
|
+
case "path":
|
|
89
|
+
return typeof value.path === "string" && value.path.length <= MAX_BRIDGE_PATH_LENGTH;
|
|
90
|
+
default:
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** True for a message the page may act on, as a frame sends them; anything else is dropped unread. */
|
|
95
|
+
export function isBridgeToPage(value) {
|
|
96
|
+
if (!isEnvelope(value)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
switch (value.t) {
|
|
100
|
+
case "ready":
|
|
101
|
+
return true;
|
|
102
|
+
case "call":
|
|
103
|
+
return (isLine(value.id, MAX_ID_LENGTH) &&
|
|
104
|
+
typeof value.method === "string" &&
|
|
105
|
+
BRIDGE_METHODS.includes(value.method) &&
|
|
106
|
+
isRecord(value.params));
|
|
107
|
+
case "navigate":
|
|
108
|
+
return isBridgePath(value.path);
|
|
109
|
+
case "resize":
|
|
110
|
+
return typeof value.height === "number" && Number.isFinite(value.height) && value.height >= 0;
|
|
111
|
+
case "title":
|
|
112
|
+
return (typeof value.text === "string" &&
|
|
113
|
+
value.text.length <= MAX_BRIDGE_TITLE_LENGTH &&
|
|
114
|
+
!/[\r\n]/.test(value.text));
|
|
115
|
+
case "download":
|
|
116
|
+
return isLine(value.id, MAX_ID_LENGTH);
|
|
117
|
+
case "subscribe":
|
|
118
|
+
return (Array.isArray(value.kinds) &&
|
|
119
|
+
value.kinds.length <= BRIDGE_EVENT_KINDS.length &&
|
|
120
|
+
value.kinds.every((kind) => typeof kind === "string" && BRIDGE_EVENT_KINDS.includes(kind)));
|
|
121
|
+
default:
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=bridge.js.map
|