@capybara-hq/plugin-sdk 0.1.0-rc.11 → 0.1.0-rc.12
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/config-ui.d.ts +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/theme.d.ts +1 -1
- package/dist/theme.js +1 -1
- package/package.json +1 -1
package/dist/config-ui.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ import type { LocalizedName } from "./plugin-package.js";
|
|
|
10
10
|
export type JsonSchema = Record<string, unknown>;
|
|
11
11
|
/** The input widget of a field. */
|
|
12
12
|
export type ConfigWidget = "text" | "textarea" | "url" | "number" | "select" | "radio" | "switch" | "checkbox" | "tristate" | "tags" | "json";
|
|
13
|
+
/** How a channel connection receives events: a long connection (default) or webhooks. */
|
|
14
|
+
export type ChannelInboundMode = "long_connection" | "webhook";
|
|
15
|
+
/** Every channel inbound mode, in the order forms list them. */
|
|
16
|
+
export declare const CHANNEL_INBOUND_MODES: readonly ChannelInboundMode[];
|
|
13
17
|
/** A labelled value of an enum (or boolean) field. */
|
|
14
18
|
export interface ConfigUiOption {
|
|
15
19
|
value: string | number | boolean;
|
|
@@ -73,6 +77,13 @@ export interface ConfigUiHints {
|
|
|
73
77
|
sections?: ConfigUiSection[];
|
|
74
78
|
/** Root only: localized messages for custom issues (`params: { ui: key }`). */
|
|
75
79
|
messages?: Record<string, LocalizedName>;
|
|
80
|
+
/**
|
|
81
|
+
* Channel connection config only, top-level fields only: the inbound modes the field belongs to.
|
|
82
|
+
* Forms draw it only in those modes and require it there; the kernel refuses a connection whose
|
|
83
|
+
* mode requires it without a value (channel inbound mode fields spec §2, §3). The zod schema keeps
|
|
84
|
+
* the field optional, since the other modes do not use it.
|
|
85
|
+
*/
|
|
86
|
+
inboundModes?: ChannelInboundMode[];
|
|
76
87
|
}
|
|
77
88
|
/** Limits of config UI hints and of the JSON Schemas a plugin package carries. */
|
|
78
89
|
export declare const CONFIG_UI_LIMITS: {
|
|
@@ -129,3 +140,14 @@ export interface ConfigUiProblem {
|
|
|
129
140
|
* problem (empty = valid); never throws. Problem paths are dot paths of the node holding the hint.
|
|
130
141
|
*/
|
|
131
142
|
export declare function validateConfigUi(schema: JsonSchema, level: "deployment" | "org" | "connection"): ConfigUiProblem[];
|
|
143
|
+
/**
|
|
144
|
+
* The top-level fields of a connection config's JSON Schema ({@link configJsonSchema}) that carry
|
|
145
|
+
* an `inboundModes` hint, with their modes (unknown modes dropped). Pure; fields without the hint
|
|
146
|
+
* belong to every mode and are not listed.
|
|
147
|
+
*/
|
|
148
|
+
export declare function inboundModeFields(schema: JsonSchema): Record<string, ChannelInboundMode[]>;
|
|
149
|
+
/**
|
|
150
|
+
* The fields `mode` requires ({@link inboundModeFields}) for which `has(field)` is false, in schema
|
|
151
|
+
* order: what the kernel refuses on a channel connection create or config / mode change.
|
|
152
|
+
*/
|
|
153
|
+
export declare function missingInboundModeFields(schema: JsonSchema, mode: ChannelInboundMode, has: (field: string) => boolean): string[];
|
package/dist/config-ui.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/** Every channel inbound mode, in the order forms list them. */
|
|
3
|
+
export const CHANNEL_INBOUND_MODES = ["long_connection", "webhook"];
|
|
2
4
|
/** Limits of config UI hints and of the JSON Schemas a plugin package carries. */
|
|
3
5
|
export const CONFIG_UI_LIMITS = {
|
|
4
6
|
/** Characters per language of a `label` (also `unit`, `item.addLabel`). */
|
|
@@ -163,9 +165,18 @@ const HINT_KEYS = new Set([
|
|
|
163
165
|
"secrets",
|
|
164
166
|
"sections",
|
|
165
167
|
"messages",
|
|
168
|
+
"inboundModes",
|
|
166
169
|
]);
|
|
167
170
|
/** The only hints a secret node may carry. */
|
|
168
|
-
const SECRET_HINT_KEYS = new Set([
|
|
171
|
+
const SECRET_HINT_KEYS = new Set([
|
|
172
|
+
"label",
|
|
173
|
+
"help",
|
|
174
|
+
"placeholder",
|
|
175
|
+
"order",
|
|
176
|
+
"section",
|
|
177
|
+
"advanced",
|
|
178
|
+
"inboundModes",
|
|
179
|
+
]);
|
|
169
180
|
const ITEM_KEYS = new Set(["title", "subtitle", "addLabel", "reorder"]);
|
|
170
181
|
const utf8Bytes = (s) => new TextEncoder().encode(s).length;
|
|
171
182
|
/** The JSON types a node accepts (`type`, a type list, or the branches of a nullable `anyOf`). */
|
|
@@ -326,7 +337,7 @@ export function validateConfigUi(schema, level) {
|
|
|
326
337
|
if (!isObj(raw))
|
|
327
338
|
report("x-ui must be an object");
|
|
328
339
|
else
|
|
329
|
-
checkHints(raw, node, isRoot, report, text);
|
|
340
|
+
checkHints(raw, node, isRoot, depth, report, text);
|
|
330
341
|
}
|
|
331
342
|
const shape = shapeOf(node);
|
|
332
343
|
const props = shape.properties;
|
|
@@ -343,7 +354,7 @@ export function validateConfigUi(schema, level) {
|
|
|
343
354
|
visit(shape.additionalProperties, path === "" ? "additionalProperties" : `${path}.additionalProperties`, false, depth + 1);
|
|
344
355
|
}
|
|
345
356
|
};
|
|
346
|
-
const checkHints = (h, node, isRoot, report, text) => {
|
|
357
|
+
const checkHints = (h, node, isRoot, depth, report, text) => {
|
|
347
358
|
const shape = shapeOf(node);
|
|
348
359
|
const types = typesOf(node);
|
|
349
360
|
const isArray = types.has("array");
|
|
@@ -356,7 +367,7 @@ export function validateConfigUi(schema, level) {
|
|
|
356
367
|
if (node["x-secret"] === true) {
|
|
357
368
|
const bad = Object.keys(h).filter((k) => HINT_KEYS.has(k) && !SECRET_HINT_KEYS.has(k));
|
|
358
369
|
if (bad.length > 0) {
|
|
359
|
-
report(`a secret field allows only label, help, placeholder, order, section and
|
|
370
|
+
report(`a secret field allows only label, help, placeholder, order, section, advanced and inboundModes hints, not ${bad.join(", ")}`);
|
|
360
371
|
}
|
|
361
372
|
}
|
|
362
373
|
text(h.label, "label", L.labelChars);
|
|
@@ -369,6 +380,28 @@ export function validateConfigUi(schema, level) {
|
|
|
369
380
|
if (h.advanced !== undefined && typeof h.advanced !== "boolean") {
|
|
370
381
|
report("advanced must be a boolean");
|
|
371
382
|
}
|
|
383
|
+
if (h.inboundModes !== undefined) {
|
|
384
|
+
const modes = h.inboundModes;
|
|
385
|
+
if (level !== "connection") {
|
|
386
|
+
report(`inboundModes is only allowed at the connection level, not ${level}`);
|
|
387
|
+
}
|
|
388
|
+
else if (depth !== 1) {
|
|
389
|
+
report("inboundModes is only allowed on a top-level field of the config");
|
|
390
|
+
}
|
|
391
|
+
else if (!Array.isArray(modes) || modes.length === 0) {
|
|
392
|
+
report("inboundModes must be a non-empty array");
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
modes.forEach((m, i) => {
|
|
396
|
+
if (!CHANNEL_INBOUND_MODES.includes(m)) {
|
|
397
|
+
report(`inboundModes[${i}] must be one of ${CHANNEL_INBOUND_MODES.join(", ")}`);
|
|
398
|
+
}
|
|
399
|
+
else if (modes.indexOf(m) !== i) {
|
|
400
|
+
report(`inboundModes[${i}] "${String(m)}" is listed twice`);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
372
405
|
if (h.section !== undefined) {
|
|
373
406
|
if (typeof h.section !== "string" || !sectionIds.has(h.section)) {
|
|
374
407
|
report(`section "${String(h.section)}" is not an id of the root's sections`);
|
|
@@ -600,3 +633,30 @@ export function validateConfigUi(schema, level) {
|
|
|
600
633
|
}
|
|
601
634
|
return problems;
|
|
602
635
|
}
|
|
636
|
+
/**
|
|
637
|
+
* The top-level fields of a connection config's JSON Schema ({@link configJsonSchema}) that carry
|
|
638
|
+
* an `inboundModes` hint, with their modes (unknown modes dropped). Pure; fields without the hint
|
|
639
|
+
* belong to every mode and are not listed.
|
|
640
|
+
*/
|
|
641
|
+
export function inboundModeFields(schema) {
|
|
642
|
+
const out = {};
|
|
643
|
+
for (const [key, node] of Object.entries(properties(schema))) {
|
|
644
|
+
const hints = isObj(node) ? node["x-ui"] : undefined;
|
|
645
|
+
const modes = isObj(hints) ? hints.inboundModes : undefined;
|
|
646
|
+
if (!Array.isArray(modes))
|
|
647
|
+
continue;
|
|
648
|
+
const known = CHANNEL_INBOUND_MODES.filter((m) => modes.includes(m));
|
|
649
|
+
if (known.length > 0)
|
|
650
|
+
out[key] = known;
|
|
651
|
+
}
|
|
652
|
+
return out;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* The fields `mode` requires ({@link inboundModeFields}) for which `has(field)` is false, in schema
|
|
656
|
+
* order: what the kernel refuses on a channel connection create or config / mode change.
|
|
657
|
+
*/
|
|
658
|
+
export function missingInboundModeFields(schema, mode, has) {
|
|
659
|
+
return Object.entries(inboundModeFields(schema))
|
|
660
|
+
.filter(([key, modes]) => modes.includes(mode) && !has(key))
|
|
661
|
+
.map(([key]) => key);
|
|
662
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/theme.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export interface ParseThemeOptions {
|
|
|
108
108
|
*/
|
|
109
109
|
readability?: boolean;
|
|
110
110
|
}
|
|
111
|
-
/** `themes/
|
|
111
|
+
/** `themes/neon-grid.json` → `neon-grid`. */
|
|
112
112
|
export declare function themeIdOf(path: string): string;
|
|
113
113
|
/**
|
|
114
114
|
* The zod schema of a theme file's shape (strict objects). Token names and values are only
|
package/dist/theme.js
CHANGED
|
@@ -42,7 +42,7 @@ export const THEME_LIMITS = {
|
|
|
42
42
|
/** Characters of the wordmark. */
|
|
43
43
|
wordmark: 24,
|
|
44
44
|
};
|
|
45
|
-
/** `themes/
|
|
45
|
+
/** `themes/neon-grid.json` → `neon-grid`. */
|
|
46
46
|
export function themeIdOf(path) {
|
|
47
47
|
return (path.split("/").pop() ?? "").replace(/\.json$/, "");
|
|
48
48
|
}
|