@wirecat/cli-core 0.673.0 → 0.674.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/CHANGELOG.md +50 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/config-command.d.ts +6 -0
- package/dist/cli/config-command.js +1 -1
- package/dist/cli/first-run.js +2 -1
- package/dist/cli/help/sections.js +1 -0
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/messenger/projects-command.js +12 -4
- package/dist/cli/project-evidence.js +1 -1
- package/dist/cli/project-status.js +1 -1
- package/dist/cli/settings.d.ts +1 -0
- package/dist/cli/settings.js +6 -3
- package/dist/cli/setup-command.d.ts +4 -0
- package/dist/cli/setup-command.js +394 -0
- package/dist/cli/shared-command-exports.d.ts +6 -0
- package/dist/cli/shared-command-exports.js +2 -0
- package/dist/cli/unknown-profile.js +1 -1
- package/dist/crm/cli/index.js +1 -0
- package/dist/entities/recorded-meeting.d.ts +2 -0
- package/dist/entities/recorded-meeting.js +3 -0
- package/dist/errors/reasons.js +7 -0
- package/dist/kit/index.d.ts +1 -0
- package/dist/kit/index.js +1 -0
- package/dist/meetings/answers.d.ts +1 -0
- package/dist/meetings/index.d.ts +3 -2
- package/dist/meetings/index.js +2 -1
- package/dist/meetings/item.d.ts +17 -1
- package/dist/meetings/item.js +16 -0
- package/dist/meetings/model.d.ts +23 -0
- package/dist/meetings/model.js +2 -1
- package/dist/meetings/pull.js +1 -0
- package/dist/meetings/store.d.ts +1 -1
- package/dist/oauth/storage.js +3 -1
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/person-meetings.d.ts +3 -0
- package/dist/services/person-meetings.js +3 -1
- package/dist/services/project-purposes.d.ts +1 -1
- package/dist/services/project-purposes.js +2 -2
- package/dist/setup/answers.d.ts +58 -0
- package/dist/setup/answers.js +194 -0
- package/dist/setup/define.d.ts +60 -0
- package/dist/setup/define.js +214 -0
- package/dist/setup/document.d.ts +205 -0
- package/dist/setup/document.js +215 -0
- package/dist/setup/files.d.ts +6 -0
- package/dist/setup/files.js +46 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/people.d.ts +14 -0
- package/dist/store/people.js +8 -1
- package/dist/store/sqlite/facts.d.ts +28 -4
- package/dist/store/sqlite/facts.js +56 -6
- package/dist/store/sqlite/identity-rekey.d.ts +46 -0
- package/dist/store/sqlite/identity-rekey.js +191 -0
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/meeting-reads.js +1 -1
- package/dist/store/sqlite/meeting-values.d.ts +2 -1
- package/dist/store/sqlite/meeting-values.js +23 -1
- package/dist/store/sqlite/meetings.js +10 -3
- package/dist/store/sqlite/migrations.generated.js +9 -0
- package/dist/store/sqlite/note-search.js +2 -2
- package/dist/store/sqlite/notes.d.ts +3 -1
- package/dist/store/sqlite/notes.js +8 -6
- package/dist/store/sqlite/schema.d.ts +153 -0
- package/dist/store/sqlite/schema.js +12 -0
- package/dist/store/sqlite/things.d.ts +2 -0
- package/dist/store/sqlite/things.js +5 -0
- package/dist/terminal/sign-in-steps.d.ts +12 -1
- package/dist/terminal/sign-in-steps.js +3 -3
- package/package.json +2 -2
- package/parity.json +3 -3
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { BLOCK_ROLES, BLOCK_TYPES, BUILT_IN_ACTIONS, DISPLAY_CLASSES, INPUT_KINDS, SETUP_FORMAT, SETUP_LIMITS, SETUP_VERSION, setupDocumentSchema, } from "./document.js";
|
|
3
|
+
const KNOWN_FEATURES = new Set([
|
|
4
|
+
"run",
|
|
5
|
+
...BLOCK_TYPES.map((type) => `block.${type}`),
|
|
6
|
+
...INPUT_KINDS.map((kind) => `input.${kind}`),
|
|
7
|
+
...DISPLAY_CLASSES.map((name) => `class.${name}`),
|
|
8
|
+
]);
|
|
9
|
+
const CLASSES = new Set(DISPLAY_CLASSES);
|
|
10
|
+
const TYPES = new Set(BLOCK_TYPES);
|
|
11
|
+
const ACTIONS = new Set(BUILT_IN_ACTIONS);
|
|
12
|
+
// The file's permission table is the owner's, set with `config set`; a flow never writes it.
|
|
13
|
+
const NEVER_BOUND = new Set(["permissions"]);
|
|
14
|
+
const conditionDepth = (condition) => {
|
|
15
|
+
const inner = "all" in condition ? condition.all : "any" in condition ? condition.any : "not" in condition ? [condition.not] : [];
|
|
16
|
+
return 1 + inner.reduce((deepest, one) => Math.max(deepest, conditionDepth(one)), 0);
|
|
17
|
+
};
|
|
18
|
+
const conditionsIn = (condition) => "all" in condition
|
|
19
|
+
? condition.all.flatMap(conditionsIn)
|
|
20
|
+
: "any" in condition
|
|
21
|
+
? condition.any.flatMap(conditionsIn)
|
|
22
|
+
: "not" in condition
|
|
23
|
+
? conditionsIn(condition.not)
|
|
24
|
+
: [condition];
|
|
25
|
+
/** Every block of a step, groups opened, with how deep each sits. */
|
|
26
|
+
export const blocksOf = (blocks = [], depth = 1) => blocks.flatMap((block) => [{ block, depth }, ...(block.type === "group" ? blocksOf(block.blocks, depth + 1) : [])]);
|
|
27
|
+
export const targetsOf = (step) => step.next === undefined ? [] : typeof step.next === "string" ? [step.next] : step.next.map(({ to }) => to);
|
|
28
|
+
const textIdsOf = (block) => {
|
|
29
|
+
const own = [block.fallback];
|
|
30
|
+
switch (block.type) {
|
|
31
|
+
case "text":
|
|
32
|
+
case "heading":
|
|
33
|
+
case "note":
|
|
34
|
+
return [...own, block.text];
|
|
35
|
+
case "image":
|
|
36
|
+
return [...own, block.alt, block.caption];
|
|
37
|
+
case "input":
|
|
38
|
+
case "choice":
|
|
39
|
+
return [
|
|
40
|
+
...own,
|
|
41
|
+
block.label,
|
|
42
|
+
block.hint,
|
|
43
|
+
"placeholder" in block ? block.placeholder : undefined,
|
|
44
|
+
...(block.options ?? []).flatMap((option) => [option.label, option.hint]),
|
|
45
|
+
];
|
|
46
|
+
case "group":
|
|
47
|
+
return [...own, block.title];
|
|
48
|
+
case "link":
|
|
49
|
+
return [...own, block.text];
|
|
50
|
+
case "requirement":
|
|
51
|
+
return [...own, block.text, block.fix];
|
|
52
|
+
default:
|
|
53
|
+
return own;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* What is wrong with a setup document, each as one line: the schema first, then what a schema cannot say — every step
|
|
58
|
+
* reachable, every target there, each text in English, each input bound once, the limits.
|
|
59
|
+
*/
|
|
60
|
+
export const setupProblems = (document, { settings, v1 = false } = {}) => {
|
|
61
|
+
const parsed = v.safeParse(setupDocumentSchema, document);
|
|
62
|
+
if (!parsed.success)
|
|
63
|
+
return parsed.issues.map((issue) => `${v.getDotPath(issue) ?? "document"}: ${issue.message}`);
|
|
64
|
+
const doc = parsed.output;
|
|
65
|
+
const problems = [];
|
|
66
|
+
const add = (where, what) => problems.push(`${where}: ${what}`);
|
|
67
|
+
const bytes = Buffer.byteLength(JSON.stringify(doc));
|
|
68
|
+
if (bytes > SETUP_LIMITS.bytes)
|
|
69
|
+
add("document", `is ${bytes} bytes, over ${SETUP_LIMITS.bytes}`);
|
|
70
|
+
const steps = Object.entries(doc.steps);
|
|
71
|
+
if (!doc.steps[doc.start])
|
|
72
|
+
add("start", `names no step: ${doc.start}`);
|
|
73
|
+
const inputs = new Map();
|
|
74
|
+
const results = new Set();
|
|
75
|
+
for (const [id, step] of steps)
|
|
76
|
+
if (step.kind === "run")
|
|
77
|
+
results.add(step.result ?? id);
|
|
78
|
+
const conditions = [];
|
|
79
|
+
const texts = new Set();
|
|
80
|
+
const en = new Set(Object.keys(doc.texts.en));
|
|
81
|
+
for (const [id, step] of steps) {
|
|
82
|
+
const at = `steps.${id}`;
|
|
83
|
+
texts.add(step.title);
|
|
84
|
+
const kind = step.kind ?? "form";
|
|
85
|
+
for (const target of targetsOf(step))
|
|
86
|
+
if (!doc.steps[target])
|
|
87
|
+
add(`${at}.next`, `names no step: ${target}`);
|
|
88
|
+
if (Array.isArray(step.next)) {
|
|
89
|
+
step.next.forEach((edge, index) => {
|
|
90
|
+
if (edge.when)
|
|
91
|
+
conditions.push([`${at}.next.${index}.when`, edge.when]);
|
|
92
|
+
});
|
|
93
|
+
if (step.next.at(-1)?.when)
|
|
94
|
+
add(`${at}.next`, "the last edge has a condition, so the flow can stop on none");
|
|
95
|
+
}
|
|
96
|
+
if (kind === "done" && step.next !== undefined)
|
|
97
|
+
add(at, "a done step ends the flow and has no next");
|
|
98
|
+
if (kind !== "done" && step.next === undefined)
|
|
99
|
+
add(at, "has no next; only a done step ends the flow");
|
|
100
|
+
if (kind === "run" && !step.action)
|
|
101
|
+
add(at, "a run step names its action");
|
|
102
|
+
if (kind !== "run" && (step.action || step.asks))
|
|
103
|
+
add(at, "action and asks belong to a run step");
|
|
104
|
+
if (v1 && step.action && !ACTIONS.has(step.action))
|
|
105
|
+
add(`${at}.action`, `${step.action} is not built in; v1 runs only ${BUILT_IN_ACTIONS.join(", ")}`);
|
|
106
|
+
for (const ask of Object.values(step.asks ?? {}))
|
|
107
|
+
texts.add(ask.label);
|
|
108
|
+
for (const { block, depth } of blocksOf(step.blocks)) {
|
|
109
|
+
const where = `${at}.blocks${block.id ? ` (${block.id})` : ` (${block.type})`}`;
|
|
110
|
+
if (depth > SETUP_LIMITS.depth)
|
|
111
|
+
add(where, `groups nest deeper than ${SETUP_LIMITS.depth}`);
|
|
112
|
+
if (block.when)
|
|
113
|
+
conditions.push([where, block.when]);
|
|
114
|
+
for (const text of textIdsOf(block))
|
|
115
|
+
if (text)
|
|
116
|
+
texts.add(text);
|
|
117
|
+
if (!TYPES.has(block.type)) {
|
|
118
|
+
if (v1)
|
|
119
|
+
add(where, `${block.type} is no block type of v1`);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (v1 && block.role !== undefined && !BLOCK_ROLES[block.type]?.includes(block.role))
|
|
123
|
+
add(where, `role ${block.role} is not one of ${block.type}'s: ${(BLOCK_ROLES[block.type] ?? []).join(", ") || "none"}`);
|
|
124
|
+
if (v1)
|
|
125
|
+
for (const name of block.class ?? [])
|
|
126
|
+
if (!CLASSES.has(name))
|
|
127
|
+
add(where, `class ${name} is not reserved`);
|
|
128
|
+
if (block.type === "image" && !doc.assets?.[block.asset])
|
|
129
|
+
add(where, `asset ${block.asset} is not in assets`);
|
|
130
|
+
if (block.type !== "input" && block.type !== "choice")
|
|
131
|
+
continue;
|
|
132
|
+
if (inputs.has(block.id))
|
|
133
|
+
add(where, `input id ${block.id} is used twice`);
|
|
134
|
+
inputs.set(block.id, block);
|
|
135
|
+
if (kind === "done")
|
|
136
|
+
add(where, "a done step has no inputs");
|
|
137
|
+
const secret = block.type === "input" ? block.secret : undefined;
|
|
138
|
+
if (block.type === "input" && (block.setting === undefined) === (secret === undefined))
|
|
139
|
+
add(where, "an input binds exactly one of setting or secret");
|
|
140
|
+
if (secret !== undefined && !/^[a-z]/.test(secret))
|
|
141
|
+
add(where, `secret ${secret} is kept, so it starts with a letter`);
|
|
142
|
+
if (block.type === "input" && block.input === "password" && secret === undefined)
|
|
143
|
+
add(where, "a password input binds a secret");
|
|
144
|
+
if (block.type === "input" && ["select", "multiselect"].includes(block.input) && !block.options?.length)
|
|
145
|
+
add(where, `a ${block.input} input lists its options`);
|
|
146
|
+
if (v1 && block.type === "input" && block.options_from)
|
|
147
|
+
add(where, "options_from is reserved, not in v1");
|
|
148
|
+
if (block.setting !== undefined) {
|
|
149
|
+
if (NEVER_BOUND.has(block.setting))
|
|
150
|
+
add(where, `${block.setting} is the owner's to set, never a flow's`);
|
|
151
|
+
else if (settings && !settings.includes(block.setting))
|
|
152
|
+
add(where, `setting ${block.setting} is not in the CLI's configuration`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
for (const [where, condition] of conditions) {
|
|
157
|
+
if (conditionDepth(condition) > SETUP_LIMITS.depth)
|
|
158
|
+
add(where, `conditions nest deeper than ${SETUP_LIMITS.depth}`);
|
|
159
|
+
for (const one of conditionsIn(condition)) {
|
|
160
|
+
if ("field" in one && !inputs.has(one.field))
|
|
161
|
+
add(where, `field ${one.field} is no input's id`);
|
|
162
|
+
if ("result" in one && !results.has(one.result))
|
|
163
|
+
add(where, `result ${one.result} is no run step's`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const reached = new Set();
|
|
167
|
+
const queue = doc.steps[doc.start] ? [doc.start] : [];
|
|
168
|
+
for (let at = queue.shift(); at !== undefined; at = queue.shift()) {
|
|
169
|
+
if (reached.has(at))
|
|
170
|
+
continue;
|
|
171
|
+
reached.add(at);
|
|
172
|
+
const step = doc.steps[at];
|
|
173
|
+
for (const target of step ? targetsOf(step) : [])
|
|
174
|
+
if (doc.steps[target])
|
|
175
|
+
queue.push(target);
|
|
176
|
+
}
|
|
177
|
+
for (const [id] of steps)
|
|
178
|
+
if (!reached.has(id))
|
|
179
|
+
add(`steps.${id}`, `cannot be reached from ${doc.start}`);
|
|
180
|
+
for (const text of texts)
|
|
181
|
+
if (!en.has(text))
|
|
182
|
+
add("texts.en", `has no ${text}`);
|
|
183
|
+
for (const [language, entries] of Object.entries(doc.texts))
|
|
184
|
+
for (const text of Object.keys(entries))
|
|
185
|
+
if (!en.has(text))
|
|
186
|
+
add(`texts.${language}`, `${text} is not in en`);
|
|
187
|
+
if (v1)
|
|
188
|
+
for (const feature of doc.requires ?? [])
|
|
189
|
+
if (!KNOWN_FEATURES.has(feature))
|
|
190
|
+
add("requires", `${feature} is unknown`);
|
|
191
|
+
return problems;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* A CLI's connection flow, built and checked once: a wrong flow throws here, so the CLI's own tests fail before it
|
|
195
|
+
* ships. Asset files are checked by `setupFileProblems`, from those tests, never at start.
|
|
196
|
+
*/
|
|
197
|
+
export const defineSetup = (definition) => {
|
|
198
|
+
const { app, requires, start, steps, assets, texts } = definition;
|
|
199
|
+
const document = {
|
|
200
|
+
format: SETUP_FORMAT,
|
|
201
|
+
version: SETUP_VERSION,
|
|
202
|
+
tool: app.command,
|
|
203
|
+
toolVersion: app.version,
|
|
204
|
+
...(requires ? { requires } : {}),
|
|
205
|
+
start,
|
|
206
|
+
steps,
|
|
207
|
+
...(assets ? { assets } : {}),
|
|
208
|
+
texts,
|
|
209
|
+
};
|
|
210
|
+
const problems = setupProblems(document, { settings: definition.configuration.allSettings, v1: true });
|
|
211
|
+
if (problems.length > 0)
|
|
212
|
+
throw new Error(`${app.command}'s setup flow is wrong:\n${problems.join("\n")}`);
|
|
213
|
+
return { app, document, definition };
|
|
214
|
+
};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* The WireCat setup format, version 1: a CLI's connection flow as data, which WireCat Desktop draws, the terminal asks
|
|
4
|
+
* and the docs render. Desktop treats the document as untrusted input, so this schema is the contract it copies
|
|
5
|
+
* (`test/fixtures/setup-v1/`). Unknown keys pass everywhere but in conditions: a newer CLI may add an optional key,
|
|
6
|
+
* and an older renderer ignores it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SETUP_FORMAT = "wirecat.setup";
|
|
9
|
+
export declare const SETUP_VERSION = 1;
|
|
10
|
+
export declare const SETUP_LIMITS: {
|
|
11
|
+
readonly bytes: number;
|
|
12
|
+
readonly steps: 60;
|
|
13
|
+
/** Groups inside groups, and conditions inside conditions. */
|
|
14
|
+
readonly depth: 8;
|
|
15
|
+
readonly transitions: 100;
|
|
16
|
+
readonly imageBytes: number;
|
|
17
|
+
};
|
|
18
|
+
export declare const SETUP_PATTERNS: {
|
|
19
|
+
readonly step: RegExp;
|
|
20
|
+
readonly input: RegExp;
|
|
21
|
+
readonly text: RegExp;
|
|
22
|
+
readonly action: RegExp;
|
|
23
|
+
readonly setting: RegExp;
|
|
24
|
+
/** `2fa` is asked mid-run and never kept; a kept secret starts with a letter, as the keyring entry wants. */
|
|
25
|
+
readonly secret: RegExp;
|
|
26
|
+
readonly feature: RegExp;
|
|
27
|
+
readonly name: RegExp;
|
|
28
|
+
readonly param: RegExp;
|
|
29
|
+
readonly language: RegExp;
|
|
30
|
+
/** Relative to the package root; no segment starts with a dot, so `..` cannot climb out. */
|
|
31
|
+
readonly file: RegExp;
|
|
32
|
+
readonly href: RegExp;
|
|
33
|
+
};
|
|
34
|
+
export declare const BLOCK_TYPES: readonly ["text", "heading", "note", "image", "code", "input", "choice", "group", "link", "requirement", "divider"];
|
|
35
|
+
export type BlockType = (typeof BLOCK_TYPES)[number];
|
|
36
|
+
export declare const INPUT_KINDS: readonly ["text", "number", "port", "toggle", "password", "file", "folder", "select", "multiselect", "countries", "timezone"];
|
|
37
|
+
export type InputKind = (typeof INPUT_KINDS)[number];
|
|
38
|
+
export declare const STEP_KINDS: readonly ["form", "run", "done"];
|
|
39
|
+
/** What a block is; how it is laid out is `class`. A role a renderer does not know is drawn as the default. */
|
|
40
|
+
export declare const BLOCK_ROLES: Partial<Record<BlockType, readonly string[]>>;
|
|
41
|
+
/** The reserved display classes. Desktop maps each to its own design tokens; any other name is ignored. */
|
|
42
|
+
export declare const DISPLAY_CLASSES: readonly ["w-auto", "w-1/3", "w-1/2", "w-2/3", "w-full", "w-narrow", "h-sm", "h-md", "h-lg", "h-xl", "grow-1", "grow-2", "grow-3", "grow-4", "mt-none", "mt-sm", "mt-md", "mt-lg", "mb-none", "mb-sm", "mb-md", "mb-lg", "gap-sm", "gap-md", "gap-lg", "start", "center", "end", "text-sm", "text-lg", "muted", "strong", "mono", "raised", "outlined", "accent", "first", "last", "hide-narrow", "hide-wide", "cols-2", "cols-3"];
|
|
43
|
+
/** The run actions cli-core runs itself. A tool's own (`oauth`, `qr`) are reserved in the format, not built in v1. */
|
|
44
|
+
export declare const BUILT_IN_ACTIONS: readonly ["apply"];
|
|
45
|
+
export type Condition = {
|
|
46
|
+
field: string;
|
|
47
|
+
is: string | number | boolean;
|
|
48
|
+
} | {
|
|
49
|
+
field: string;
|
|
50
|
+
in: (string | number)[];
|
|
51
|
+
} | {
|
|
52
|
+
field: string;
|
|
53
|
+
set: boolean;
|
|
54
|
+
} | {
|
|
55
|
+
result: string;
|
|
56
|
+
is: "ok";
|
|
57
|
+
} | {
|
|
58
|
+
result: string;
|
|
59
|
+
error: string;
|
|
60
|
+
} | {
|
|
61
|
+
all: Condition[];
|
|
62
|
+
} | {
|
|
63
|
+
any: Condition[];
|
|
64
|
+
} | {
|
|
65
|
+
not: Condition;
|
|
66
|
+
};
|
|
67
|
+
export type Value = string | number | boolean | string[];
|
|
68
|
+
interface BlockBase {
|
|
69
|
+
id?: string;
|
|
70
|
+
when?: Condition;
|
|
71
|
+
role?: string;
|
|
72
|
+
class?: string[];
|
|
73
|
+
/** A text an older renderer shows in place of a block type it does not know. */
|
|
74
|
+
fallback?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface Option {
|
|
77
|
+
value: string;
|
|
78
|
+
label: string;
|
|
79
|
+
hint?: string;
|
|
80
|
+
icon?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface TextBlock extends BlockBase {
|
|
83
|
+
type: "text";
|
|
84
|
+
text: string;
|
|
85
|
+
params?: Record<string, string>;
|
|
86
|
+
}
|
|
87
|
+
export interface HeadingBlock extends BlockBase {
|
|
88
|
+
type: "heading";
|
|
89
|
+
text: string;
|
|
90
|
+
level?: 2 | 3;
|
|
91
|
+
params?: Record<string, string>;
|
|
92
|
+
}
|
|
93
|
+
export interface NoteBlock extends BlockBase {
|
|
94
|
+
type: "note";
|
|
95
|
+
text: string;
|
|
96
|
+
params?: Record<string, string>;
|
|
97
|
+
}
|
|
98
|
+
export interface ImageBlock extends BlockBase {
|
|
99
|
+
type: "image";
|
|
100
|
+
asset: string;
|
|
101
|
+
alt: string;
|
|
102
|
+
caption?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface CodeBlock extends BlockBase {
|
|
105
|
+
type: "code";
|
|
106
|
+
code: string;
|
|
107
|
+
copy?: boolean;
|
|
108
|
+
language?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface InputBlock extends BlockBase {
|
|
111
|
+
type: "input";
|
|
112
|
+
id: string;
|
|
113
|
+
setting?: string;
|
|
114
|
+
secret?: string;
|
|
115
|
+
input: InputKind;
|
|
116
|
+
label: string;
|
|
117
|
+
hint?: string;
|
|
118
|
+
placeholder?: string;
|
|
119
|
+
optional?: boolean;
|
|
120
|
+
default?: Value;
|
|
121
|
+
multiline?: boolean;
|
|
122
|
+
min?: number;
|
|
123
|
+
max?: number;
|
|
124
|
+
accept?: string[];
|
|
125
|
+
options?: Option[];
|
|
126
|
+
/** Reserved: a run action whose result lists the options. Not in v1. */
|
|
127
|
+
options_from?: string;
|
|
128
|
+
/** The setting's JSON Schema; `setup show` adds it, an author never writes it. */
|
|
129
|
+
schema?: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
export interface ChoiceBlock extends BlockBase {
|
|
132
|
+
type: "choice";
|
|
133
|
+
id: string;
|
|
134
|
+
setting?: string;
|
|
135
|
+
label?: string;
|
|
136
|
+
hint?: string;
|
|
137
|
+
options: Option[];
|
|
138
|
+
optional?: boolean;
|
|
139
|
+
default?: string;
|
|
140
|
+
schema?: Record<string, unknown>;
|
|
141
|
+
}
|
|
142
|
+
export interface GroupBlock extends BlockBase {
|
|
143
|
+
type: "group";
|
|
144
|
+
blocks: Block[];
|
|
145
|
+
title?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface LinkBlock extends BlockBase {
|
|
148
|
+
type: "link";
|
|
149
|
+
href: string;
|
|
150
|
+
text: string;
|
|
151
|
+
}
|
|
152
|
+
export interface RequirementBlock extends BlockBase {
|
|
153
|
+
type: "requirement";
|
|
154
|
+
check: string;
|
|
155
|
+
text: string;
|
|
156
|
+
fix?: string;
|
|
157
|
+
}
|
|
158
|
+
export interface DividerBlock extends BlockBase {
|
|
159
|
+
type: "divider";
|
|
160
|
+
}
|
|
161
|
+
export type Block = TextBlock | HeadingBlock | NoteBlock | ImageBlock | CodeBlock | InputBlock | ChoiceBlock | GroupBlock | LinkBlock | RequirementBlock | DividerBlock;
|
|
162
|
+
export interface Edge {
|
|
163
|
+
when?: Condition;
|
|
164
|
+
to: string;
|
|
165
|
+
}
|
|
166
|
+
export interface Step {
|
|
167
|
+
title: string;
|
|
168
|
+
kind?: (typeof STEP_KINDS)[number];
|
|
169
|
+
blocks?: Block[];
|
|
170
|
+
next?: string | Edge[];
|
|
171
|
+
back?: boolean;
|
|
172
|
+
/** A run step's action: `apply` in v1. */
|
|
173
|
+
action?: string;
|
|
174
|
+
/** A run's `needs` event kind → the input shown for it mid-run. */
|
|
175
|
+
asks?: Record<string, InputBlock>;
|
|
176
|
+
/** The name `result` conditions read this run's outcome under; the step id when left out. */
|
|
177
|
+
result?: string;
|
|
178
|
+
}
|
|
179
|
+
export interface Asset {
|
|
180
|
+
file: string;
|
|
181
|
+
width?: number;
|
|
182
|
+
height?: number;
|
|
183
|
+
}
|
|
184
|
+
export type Texts = Record<string, string>;
|
|
185
|
+
export interface SetupDocument {
|
|
186
|
+
format: typeof SETUP_FORMAT;
|
|
187
|
+
version: typeof SETUP_VERSION;
|
|
188
|
+
tool: string;
|
|
189
|
+
toolVersion?: string;
|
|
190
|
+
requires?: string[];
|
|
191
|
+
start: string;
|
|
192
|
+
steps: Record<string, Step>;
|
|
193
|
+
assets?: Record<string, Asset>;
|
|
194
|
+
texts: {
|
|
195
|
+
en: Texts;
|
|
196
|
+
} & Record<string, Texts>;
|
|
197
|
+
/** Only with a profile: its current settings; a secret is `{ set: true }`, never its value. */
|
|
198
|
+
values?: Record<string, Value | {
|
|
199
|
+
set: true;
|
|
200
|
+
}>;
|
|
201
|
+
}
|
|
202
|
+
export declare const setupDocumentSchema: v.GenericSchema<SetupDocument>;
|
|
203
|
+
/** The document's JSON Schema (draft-07), the one Desktop checks a description against. */
|
|
204
|
+
export declare const setupJsonSchema: () => Record<string, unknown>;
|
|
205
|
+
export {};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
/**
|
|
4
|
+
* The WireCat setup format, version 1: a CLI's connection flow as data, which WireCat Desktop draws, the terminal asks
|
|
5
|
+
* and the docs render. Desktop treats the document as untrusted input, so this schema is the contract it copies
|
|
6
|
+
* (`test/fixtures/setup-v1/`). Unknown keys pass everywhere but in conditions: a newer CLI may add an optional key,
|
|
7
|
+
* and an older renderer ignores it.
|
|
8
|
+
*/
|
|
9
|
+
export const SETUP_FORMAT = "wirecat.setup";
|
|
10
|
+
export const SETUP_VERSION = 1;
|
|
11
|
+
export const SETUP_LIMITS = {
|
|
12
|
+
bytes: 256 * 1024,
|
|
13
|
+
steps: 60,
|
|
14
|
+
/** Groups inside groups, and conditions inside conditions. */
|
|
15
|
+
depth: 8,
|
|
16
|
+
transitions: 100,
|
|
17
|
+
imageBytes: 2 * 1024 * 1024,
|
|
18
|
+
};
|
|
19
|
+
// No lookahead anywhere: Desktop checks these patterns in Rust, whose regex has none.
|
|
20
|
+
export const SETUP_PATTERNS = {
|
|
21
|
+
step: /^[a-z][a-z0-9-]{0,47}$/,
|
|
22
|
+
input: /^[a-z][a-z0-9_-]{0,47}$/,
|
|
23
|
+
text: /^[a-z][a-z0-9_.-]{0,95}$/,
|
|
24
|
+
action: /^[a-z][a-z0-9-]{0,31}$/,
|
|
25
|
+
setting: /^[a-z][a-z0-9_]{0,63}$/,
|
|
26
|
+
/** `2fa` is asked mid-run and never kept; a kept secret starts with a letter, as the keyring entry wants. */
|
|
27
|
+
secret: /^[a-z0-9][a-z0-9-]{0,31}$/,
|
|
28
|
+
feature: /^[a-z][a-z0-9_./-]{0,63}$/,
|
|
29
|
+
name: /^[a-z][a-z0-9/-]{0,31}$/,
|
|
30
|
+
param: /^[a-z][a-z0-9_]{0,31}$/,
|
|
31
|
+
language: /^[a-z]{2}(-[A-Z]{2})?$/,
|
|
32
|
+
/** Relative to the package root; no segment starts with a dot, so `..` cannot climb out. */
|
|
33
|
+
file: /^[A-Za-z0-9_-][A-Za-z0-9._-]*(\/[A-Za-z0-9_-][A-Za-z0-9._-]*)*\.(png|jpe?g|webp)$/,
|
|
34
|
+
href: /^https:\/\/[^\s"<>]{1,2000}$/,
|
|
35
|
+
};
|
|
36
|
+
export const BLOCK_TYPES = [
|
|
37
|
+
"text",
|
|
38
|
+
"heading",
|
|
39
|
+
"note",
|
|
40
|
+
"image",
|
|
41
|
+
"code",
|
|
42
|
+
"input",
|
|
43
|
+
"choice",
|
|
44
|
+
"group",
|
|
45
|
+
"link",
|
|
46
|
+
"requirement",
|
|
47
|
+
"divider",
|
|
48
|
+
];
|
|
49
|
+
export const INPUT_KINDS = [
|
|
50
|
+
"text",
|
|
51
|
+
"number",
|
|
52
|
+
"port",
|
|
53
|
+
"toggle",
|
|
54
|
+
"password",
|
|
55
|
+
"file",
|
|
56
|
+
"folder",
|
|
57
|
+
"select",
|
|
58
|
+
"multiselect",
|
|
59
|
+
"countries",
|
|
60
|
+
"timezone",
|
|
61
|
+
];
|
|
62
|
+
export const STEP_KINDS = ["form", "run", "done"];
|
|
63
|
+
/** What a block is; how it is laid out is `class`. A role a renderer does not know is drawn as the default. */
|
|
64
|
+
export const BLOCK_ROLES = {
|
|
65
|
+
note: ["tip", "info", "warning", "danger", "success"],
|
|
66
|
+
group: ["card", "details", "row"],
|
|
67
|
+
link: ["button", "inline"],
|
|
68
|
+
};
|
|
69
|
+
/** The reserved display classes. Desktop maps each to its own design tokens; any other name is ignored. */
|
|
70
|
+
export const DISPLAY_CLASSES = [
|
|
71
|
+
...["w-auto", "w-1/3", "w-1/2", "w-2/3", "w-full", "w-narrow"],
|
|
72
|
+
...["h-sm", "h-md", "h-lg", "h-xl"],
|
|
73
|
+
...["grow-1", "grow-2", "grow-3", "grow-4"],
|
|
74
|
+
...["mt-none", "mt-sm", "mt-md", "mt-lg", "mb-none", "mb-sm", "mb-md", "mb-lg", "gap-sm", "gap-md", "gap-lg"],
|
|
75
|
+
...["start", "center", "end"],
|
|
76
|
+
...["text-sm", "text-lg", "muted", "strong", "mono"],
|
|
77
|
+
...["raised", "outlined", "accent"],
|
|
78
|
+
...["first", "last"],
|
|
79
|
+
...["hide-narrow", "hide-wide"],
|
|
80
|
+
...["cols-2", "cols-3"],
|
|
81
|
+
];
|
|
82
|
+
/** The run actions cli-core runs itself. A tool's own (`oauth`, `qr`) are reserved in the format, not built in v1. */
|
|
83
|
+
export const BUILT_IN_ACTIONS = ["apply"];
|
|
84
|
+
const pattern = (regex, what) => v.pipe(v.string(), v.regex(regex, `has to be ${what}`));
|
|
85
|
+
const textId = pattern(SETUP_PATTERNS.text, "a text id");
|
|
86
|
+
const stepId = pattern(SETUP_PATTERNS.step, "a step id");
|
|
87
|
+
const inputId = pattern(SETUP_PATTERNS.input, "an input id");
|
|
88
|
+
const action = pattern(SETUP_PATTERNS.action, "an action name");
|
|
89
|
+
const name = pattern(SETUP_PATTERNS.name, "a name");
|
|
90
|
+
const params = v.optional(v.record(pattern(SETUP_PATTERNS.param, "a parameter name"), v.pipe(v.string(), v.maxLength(200))));
|
|
91
|
+
const value = v.union([v.string(), v.number(), v.boolean(), v.array(v.string())]);
|
|
92
|
+
const CONDITION = v.union([
|
|
93
|
+
v.strictObject({ field: inputId, is: v.union([v.string(), v.number(), v.boolean()]) }),
|
|
94
|
+
v.strictObject({ field: inputId, in: v.array(v.union([v.string(), v.number()])) }),
|
|
95
|
+
v.strictObject({ field: inputId, set: v.boolean() }),
|
|
96
|
+
v.strictObject({ result: stepId, is: v.literal("ok") }),
|
|
97
|
+
v.strictObject({ result: stepId, error: pattern(/^[a-z][a-z0-9_]{0,63}$/, "an error code") }),
|
|
98
|
+
v.strictObject({ all: v.array(v.lazy(() => CONDITION)) }),
|
|
99
|
+
v.strictObject({ any: v.array(v.lazy(() => CONDITION)) }),
|
|
100
|
+
v.strictObject({ not: v.lazy(() => CONDITION) }),
|
|
101
|
+
]);
|
|
102
|
+
const base = {
|
|
103
|
+
id: v.optional(inputId),
|
|
104
|
+
when: v.optional(v.lazy(() => CONDITION)),
|
|
105
|
+
role: v.optional(name),
|
|
106
|
+
class: v.optional(v.array(name)),
|
|
107
|
+
fallback: v.optional(textId),
|
|
108
|
+
};
|
|
109
|
+
const OPTION = v.looseObject({ value: v.string(), label: textId, hint: v.optional(textId), icon: v.optional(name) });
|
|
110
|
+
const INPUT = v.looseObject({
|
|
111
|
+
...base,
|
|
112
|
+
type: v.literal("input"),
|
|
113
|
+
id: inputId,
|
|
114
|
+
setting: v.optional(pattern(SETUP_PATTERNS.setting, "a setting name")),
|
|
115
|
+
secret: v.optional(pattern(SETUP_PATTERNS.secret, "a secret name")),
|
|
116
|
+
input: v.picklist(INPUT_KINDS),
|
|
117
|
+
label: textId,
|
|
118
|
+
hint: v.optional(textId),
|
|
119
|
+
placeholder: v.optional(textId),
|
|
120
|
+
optional: v.optional(v.boolean()),
|
|
121
|
+
default: v.optional(value),
|
|
122
|
+
multiline: v.optional(v.boolean()),
|
|
123
|
+
min: v.optional(v.number()),
|
|
124
|
+
max: v.optional(v.number()),
|
|
125
|
+
accept: v.optional(v.array(pattern(/^\.[a-z0-9]{1,10}$/, "an extension such as .csv"))),
|
|
126
|
+
options: v.optional(v.array(OPTION)),
|
|
127
|
+
options_from: v.optional(action),
|
|
128
|
+
schema: v.optional(v.record(v.string(), v.unknown())),
|
|
129
|
+
});
|
|
130
|
+
const KNOWN_BLOCK = v.variant("type", [
|
|
131
|
+
v.looseObject({ ...base, type: v.literal("text"), text: textId, params }),
|
|
132
|
+
v.looseObject({ ...base, type: v.literal("heading"), text: textId, level: v.optional(v.picklist([2, 3])), params }),
|
|
133
|
+
v.looseObject({ ...base, type: v.literal("note"), text: textId, params }),
|
|
134
|
+
v.looseObject({ ...base, type: v.literal("image"), asset: stepId, alt: textId, caption: v.optional(textId) }),
|
|
135
|
+
v.looseObject({
|
|
136
|
+
...base,
|
|
137
|
+
type: v.literal("code"),
|
|
138
|
+
code: v.pipe(v.string(), v.maxLength(4000)),
|
|
139
|
+
copy: v.optional(v.boolean()),
|
|
140
|
+
language: v.optional(name),
|
|
141
|
+
}),
|
|
142
|
+
INPUT,
|
|
143
|
+
v.looseObject({
|
|
144
|
+
...base,
|
|
145
|
+
type: v.literal("choice"),
|
|
146
|
+
id: inputId,
|
|
147
|
+
setting: v.optional(pattern(SETUP_PATTERNS.setting, "a setting name")),
|
|
148
|
+
label: v.optional(textId),
|
|
149
|
+
hint: v.optional(textId),
|
|
150
|
+
options: v.pipe(v.array(OPTION), v.minLength(1)),
|
|
151
|
+
optional: v.optional(v.boolean()),
|
|
152
|
+
default: v.optional(v.string()),
|
|
153
|
+
schema: v.optional(v.record(v.string(), v.unknown())),
|
|
154
|
+
}),
|
|
155
|
+
v.looseObject({
|
|
156
|
+
...base,
|
|
157
|
+
type: v.literal("group"),
|
|
158
|
+
blocks: v.array(v.lazy(() => BLOCK)),
|
|
159
|
+
title: v.optional(textId),
|
|
160
|
+
}),
|
|
161
|
+
v.looseObject({
|
|
162
|
+
...base,
|
|
163
|
+
type: v.literal("link"),
|
|
164
|
+
href: pattern(SETUP_PATTERNS.href, "an https link"),
|
|
165
|
+
text: textId,
|
|
166
|
+
}),
|
|
167
|
+
v.looseObject({ ...base, type: v.literal("requirement"), check: action, text: textId, fix: v.optional(textId) }),
|
|
168
|
+
v.looseObject({ ...base, type: v.literal("divider") }),
|
|
169
|
+
]);
|
|
170
|
+
const NOT_KNOWN = v.check((type) => !BLOCK_TYPES.includes(type), "is a known block type, written wrongly");
|
|
171
|
+
const UNKNOWN_TYPE = v.pipe(name, NOT_KNOWN);
|
|
172
|
+
/** A block type from a newer format: kept, so an older renderer shows its `fallback` and goes on. */
|
|
173
|
+
const UNKNOWN_BLOCK = v.looseObject({ ...base, type: UNKNOWN_TYPE });
|
|
174
|
+
const BLOCK = v.union([KNOWN_BLOCK, UNKNOWN_BLOCK]);
|
|
175
|
+
const EDGE = v.looseObject({ when: v.optional(CONDITION), to: stepId });
|
|
176
|
+
const STEP = v.looseObject({
|
|
177
|
+
title: textId,
|
|
178
|
+
kind: v.optional(v.picklist(STEP_KINDS)),
|
|
179
|
+
blocks: v.optional(v.array(BLOCK)),
|
|
180
|
+
next: v.optional(v.union([stepId, v.array(EDGE)])),
|
|
181
|
+
back: v.optional(v.boolean()),
|
|
182
|
+
action: v.optional(action),
|
|
183
|
+
asks: v.optional(v.record(name, INPUT)),
|
|
184
|
+
result: v.optional(stepId),
|
|
185
|
+
});
|
|
186
|
+
const TEXTS = v.record(textId, v.pipe(v.string(), v.maxLength(4000)));
|
|
187
|
+
export const setupDocumentSchema = v.looseObject({
|
|
188
|
+
format: v.literal(SETUP_FORMAT),
|
|
189
|
+
version: v.literal(SETUP_VERSION),
|
|
190
|
+
tool: pattern(/^[a-z][a-z0-9-]{0,31}$/, "the CLI's command"),
|
|
191
|
+
toolVersion: v.optional(pattern(/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/, "a version")),
|
|
192
|
+
requires: v.optional(v.array(pattern(SETUP_PATTERNS.feature, "a feature name"))),
|
|
193
|
+
start: stepId,
|
|
194
|
+
steps: v.pipe(v.record(stepId, STEP), v.maxEntries(SETUP_LIMITS.steps)),
|
|
195
|
+
assets: v.optional(v.record(stepId, v.looseObject({
|
|
196
|
+
file: pattern(SETUP_PATTERNS.file, "a PNG, JPEG or WebP file inside the package"),
|
|
197
|
+
width: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),
|
|
198
|
+
height: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),
|
|
199
|
+
}))),
|
|
200
|
+
texts: v.objectWithRest({ en: TEXTS }, TEXTS),
|
|
201
|
+
values: v.optional(v.record(v.string(), v.union([value, v.strictObject({ set: v.literal(true) })]))),
|
|
202
|
+
});
|
|
203
|
+
/** The document's JSON Schema (draft-07), the one Desktop checks a description against. */
|
|
204
|
+
export const setupJsonSchema = () => {
|
|
205
|
+
const schema = toJsonSchema(setupDocumentSchema, {
|
|
206
|
+
errorMode: "ignore",
|
|
207
|
+
definitions: { block: BLOCK, condition: CONDITION },
|
|
208
|
+
// `v.check` has no JSON Schema form; without this an unknown-type branch would take a broken known block.
|
|
209
|
+
overrideAction: ({ valibotAction, jsonSchema }) => valibotAction === NOT_KNOWN ? { ...jsonSchema, not: { enum: [...BLOCK_TYPES] } } : undefined,
|
|
210
|
+
});
|
|
211
|
+
return {
|
|
212
|
+
title: "WireCat setup document, version 1",
|
|
213
|
+
...schema,
|
|
214
|
+
};
|
|
215
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Setup } from "./define.js";
|
|
2
|
+
/**
|
|
3
|
+
* What is wrong with the flow's image files, from the package root: each exists inside it (links followed), is a PNG,
|
|
4
|
+
* JPEG or WebP by its first bytes, never SVG, and is at most 2 MB. For the CLI's own test, never at start.
|
|
5
|
+
*/
|
|
6
|
+
export declare const setupFileProblems: (setup: Setup, packageRoot: string | URL) => string[];
|