@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
package/dist/meetings/item.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { queryFieldsOf } from "@wirecat/cli-base/query";
|
|
2
2
|
import { isoTime, reference } from "@wirecat/cli-base/standards";
|
|
3
3
|
import * as v from "valibot";
|
|
4
|
+
import { MEETING_CALL_DIRECTIONS } from "./model.js";
|
|
4
5
|
import { formatMeetingReference } from "./reference.js";
|
|
5
6
|
const text = v.string();
|
|
6
7
|
const count = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
@@ -14,6 +15,17 @@ export const meetingIssuesOf = (metadata) => {
|
|
|
14
15
|
const listed = metadata?.issues;
|
|
15
16
|
return Array.isArray(listed) ? MEETING_ISSUES.filter((issue) => listed.includes(issue)) : [];
|
|
16
17
|
};
|
|
18
|
+
// Typed by name: inferred, every entity map that holds a meeting grows too long for the compiler.
|
|
19
|
+
/** A phone call's fields, which a phone-line source sets; a meeting has none. */
|
|
20
|
+
export const meetingCall = v.strictObject({
|
|
21
|
+
direction: v.nullable(v.picklist(MEETING_CALL_DIRECTIONS)),
|
|
22
|
+
manager: v.nullable(v.strictObject({ name: v.nullable(text), person: v.nullable(reference) })),
|
|
23
|
+
client_phone: v.nullable(text),
|
|
24
|
+
});
|
|
25
|
+
/** A call's fields as answers give them; `undefined` for a meeting, so its answer has no `call`. */
|
|
26
|
+
export const meetingCallItem = (row) => row.direction == null && row.clientPhone == null
|
|
27
|
+
? undefined
|
|
28
|
+
: { direction: row.direction ?? null, manager: row.manager ?? null, client_phone: row.clientPhone ?? null };
|
|
17
29
|
const meetingEntries = {
|
|
18
30
|
ref: reference,
|
|
19
31
|
id: v.pipe(v.string(), v.minLength(1)),
|
|
@@ -31,6 +43,8 @@ const meetingEntries = {
|
|
|
31
43
|
duration_ms: v.nullable(count),
|
|
32
44
|
timezone: v.optional(v.nullable(text)),
|
|
33
45
|
participants_count: v.nullable(count),
|
|
46
|
+
/** Present only on a phone call. */
|
|
47
|
+
call: v.optional(meetingCall),
|
|
34
48
|
/** Present only when something about this meeting is doubtful. */
|
|
35
49
|
issues: v.optional(v.array(v.picklist(MEETING_ISSUES))),
|
|
36
50
|
/**
|
|
@@ -49,6 +63,7 @@ const MEETING_UNTRUSTED = ["title", "description", "location"];
|
|
|
49
63
|
const iso = (ms) => (ms === null ? null : new Date(ms).toISOString());
|
|
50
64
|
export const meetingItem = (row, owner) => {
|
|
51
65
|
const issues = meetingIssuesOf(row.metadata);
|
|
66
|
+
const call = meetingCallItem(row);
|
|
52
67
|
return {
|
|
53
68
|
ref: formatMeetingReference({ type: "meeting", accountId: row.accountId, meetingId: row.id }),
|
|
54
69
|
id: String(row.id),
|
|
@@ -64,6 +79,7 @@ export const meetingItem = (row, owner) => {
|
|
|
64
79
|
duration_ms: row.durationMs,
|
|
65
80
|
timezone: row.timezone,
|
|
66
81
|
participants_count: row.participantsCount,
|
|
82
|
+
...(call ? { call } : {}),
|
|
67
83
|
...(issues.length ? { issues } : {}),
|
|
68
84
|
untrusted: [...MEETING_UNTRUSTED],
|
|
69
85
|
created_at: new Date(row.createdAt).toISOString(),
|
package/dist/meetings/model.d.ts
CHANGED
|
@@ -47,6 +47,15 @@ export interface MeetingSeries extends RecordTimes {
|
|
|
47
47
|
metadata: Metadata;
|
|
48
48
|
deletedAt: number | null;
|
|
49
49
|
}
|
|
50
|
+
/** Which way a phone call went: the owner's side took it (`in`) or made it (`out`). */
|
|
51
|
+
export declare const MEETING_CALL_DIRECTIONS: readonly ["in", "out"];
|
|
52
|
+
export type MeetingCallDirection = (typeof MEETING_CALL_DIRECTIONS)[number];
|
|
53
|
+
/** Who took or made a phone call for the owner: the participant its source marked with the role `manager`. */
|
|
54
|
+
export interface CallManager {
|
|
55
|
+
name: string | null;
|
|
56
|
+
/** `person:<uid>` of the person that participant's identity is linked to. */
|
|
57
|
+
person: string | null;
|
|
58
|
+
}
|
|
50
59
|
export interface Meeting extends RecordTimes {
|
|
51
60
|
id: number;
|
|
52
61
|
accountId: number;
|
|
@@ -65,6 +74,12 @@ export interface Meeting extends RecordTimes {
|
|
|
65
74
|
participantsCount: number | null;
|
|
66
75
|
metadata: Metadata;
|
|
67
76
|
deletedAt: number | null;
|
|
77
|
+
/** A phone call's direction, as a phone-line source sets it; absent or null for a meeting. */
|
|
78
|
+
direction?: MeetingCallDirection | null;
|
|
79
|
+
/** A phone call's other side, as the source wrote the number. */
|
|
80
|
+
clientPhone?: string | null;
|
|
81
|
+
/** Read only: on a call, the participant with the role `manager`. */
|
|
82
|
+
manager?: CallManager | null;
|
|
68
83
|
}
|
|
69
84
|
export interface Participant extends RecordTimes {
|
|
70
85
|
id: number;
|
|
@@ -182,6 +197,14 @@ export interface Occurrence {
|
|
|
182
197
|
endedAt: string | null;
|
|
183
198
|
}
|
|
184
199
|
export interface SourceMeeting {
|
|
200
|
+
/**
|
|
201
|
+
* A phone call's fields, which a phone-line source sets so every line shows the same columns: the direction and
|
|
202
|
+
* the other side's number. The participant who took or made it for the owner is the one with the role `manager`.
|
|
203
|
+
*/
|
|
204
|
+
call?: {
|
|
205
|
+
direction?: MeetingCallDirection | null;
|
|
206
|
+
clientPhone?: string | null;
|
|
207
|
+
};
|
|
185
208
|
description?: string | null;
|
|
186
209
|
location?: string | null;
|
|
187
210
|
joinUrl?: string | null;
|
package/dist/meetings/model.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
/** Which way a phone call went: the owner's side took it (`in`) or made it (`out`). */
|
|
2
|
+
export const MEETING_CALL_DIRECTIONS = ["in", "out"];
|
package/dist/meetings/pull.js
CHANGED
|
@@ -44,6 +44,7 @@ export const sourceMeetingInput = (m, accountId, participantsCount, kept) => {
|
|
|
44
44
|
timezone: m.timezone ?? kept?.timezone ?? null,
|
|
45
45
|
hostIdentityId: kept?.hostIdentityId ?? null,
|
|
46
46
|
...(count === undefined ? {} : { participantsCount: count }),
|
|
47
|
+
...(m.call ? { direction: m.call.direction ?? null, clientPhone: m.call.clientPhone ?? null } : {}),
|
|
47
48
|
metadata,
|
|
48
49
|
deletedAt: null,
|
|
49
50
|
};
|
package/dist/meetings/store.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export interface MeetingDocument {
|
|
|
57
57
|
export interface ChatInput extends Omit<NewRecord<ChatLine>, "meetingId" | "senderParticipantId"> {
|
|
58
58
|
senderParticipantPosition: number | null;
|
|
59
59
|
}
|
|
60
|
-
export interface MeetingInput extends Omit<NewRecord<Meeting>, "meetingSeriesId" | "eventId" | "participantsCount"> {
|
|
60
|
+
export interface MeetingInput extends Omit<NewRecord<Meeting>, "meetingSeriesId" | "eventId" | "participantsCount" | "manager"> {
|
|
61
61
|
/** Left out when the participants could not be read, so the stored count stays. */
|
|
62
62
|
participantsCount?: number | null;
|
|
63
63
|
series?: Omit<NewRecord<MeetingSeries>, "accountId" | "eventSeriesId">;
|
package/dist/oauth/storage.js
CHANGED
|
@@ -27,7 +27,9 @@ const previousOf = (raw) => {
|
|
|
27
27
|
const defined = (value) => Object.fromEntries(Object.entries(value).filter(([, field]) => field !== undefined));
|
|
28
28
|
export const oauthAccount = (providerId, profile) => {
|
|
29
29
|
if (!profile.trim())
|
|
30
|
-
throw new CliError("validation_error", "name a profile: a sign-in always belongs to one"
|
|
30
|
+
throw new CliError("validation_error", "name a profile: a sign-in always belongs to one", {
|
|
31
|
+
reason: "profile.missing",
|
|
32
|
+
});
|
|
31
33
|
return `oauth:${providerId}:${profile}`;
|
|
32
34
|
};
|
|
33
35
|
/** The entry every new sign-in writes: account `oauth:<provider>:<profile>` under the CLI's own service. */
|
|
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
|
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
}) => Promise<{
|
|
16
16
|
items: ({
|
|
17
|
-
error?: undefined;
|
|
18
17
|
chatId: string;
|
|
19
18
|
tags: import("../domain/channel-tags.js").ChannelTagMatch[];
|
|
20
19
|
algorithm: string;
|
|
21
20
|
fetchedAt: string | null;
|
|
22
21
|
source: string;
|
|
22
|
+
error?: undefined;
|
|
23
23
|
} | {
|
|
24
24
|
tags?: undefined;
|
|
25
25
|
algorithm?: undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type MeetingCallItem } from "../meetings/index.js";
|
|
1
2
|
import type { MessageStore, StoredAccount } from "../store/store.js";
|
|
2
3
|
/** A recorded meeting or call some of the people took part in, as the meeting source stored it. */
|
|
3
4
|
export interface PersonMeeting {
|
|
@@ -18,6 +19,8 @@ export interface PersonMeeting {
|
|
|
18
19
|
event: string | null;
|
|
19
20
|
/** `person:<uid>` of each one asked about who took part. */
|
|
20
21
|
people: string[];
|
|
22
|
+
/** A phone call's direction, manager and other side's number; absent on a meeting. */
|
|
23
|
+
call?: MeetingCallItem;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* The newest recorded meetings of these people in `accounts`, each once, newest first, and how many there are;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatMeetingReference } from "../meetings/index.js";
|
|
1
|
+
import { formatMeetingReference, meetingCallItem } from "../meetings/index.js";
|
|
2
2
|
const SCAN = 1000;
|
|
3
3
|
/**
|
|
4
4
|
* The newest recorded meetings of these people in `accounts`, each once, newest first, and how many there are;
|
|
@@ -41,6 +41,7 @@ export const personMeetings = async (store, people, accounts, { limit = 10, sinc
|
|
|
41
41
|
continue;
|
|
42
42
|
const transcripts = await store.meetings.transcripts({ accountId, meetingId, limit: 1 });
|
|
43
43
|
const account = byId.get(accountId);
|
|
44
|
+
const call = meetingCallItem(meeting);
|
|
44
45
|
items.push({
|
|
45
46
|
ref: formatMeetingReference({ type: "meeting", accountId, meetingId }),
|
|
46
47
|
meetingId,
|
|
@@ -51,6 +52,7 @@ export const personMeetings = async (store, people, accounts, { limit = 10, sinc
|
|
|
51
52
|
hasTranscript: transcripts.items.length > 0,
|
|
52
53
|
event: meeting.eventId === null ? null : `event:${meeting.eventId}`,
|
|
53
54
|
people: who,
|
|
55
|
+
...(call ? { call } : {}),
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
return { items, total: newest.length, hasMore: cut || newest.length > limit };
|
|
@@ -7,7 +7,7 @@ export declare const LINK_PURPOSE = "work";
|
|
|
7
7
|
/** The purposes a host's config lists; core knows only the built-in ones and takes the rest as given. */
|
|
8
8
|
export interface PurposeConfig {
|
|
9
9
|
purposes: readonly string[];
|
|
10
|
-
/** Read when no `--
|
|
10
|
+
/** Read when no `--purposes` is given. */
|
|
11
11
|
defaults: readonly string[];
|
|
12
12
|
/** A project's own defaults, by its key or `project:<id>`. */
|
|
13
13
|
projects?: Readonly<Record<string, readonly string[]>>;
|
|
@@ -9,7 +9,7 @@ export const BUILT_IN_PURPOSE_CONFIG = { purposes: BUILT_IN_PURPOSES, defaults:
|
|
|
9
9
|
const unknown = (asked, config) => {
|
|
10
10
|
const wrong = asked.filter((one) => !config.purposes.includes(one));
|
|
11
11
|
if (wrong.length)
|
|
12
|
-
throw new CliError("validation_error", `unknown purpose ${wrong.join(", ")}; the configured ones are ${config.purposes.join(", ")}, or all`, { param: "
|
|
12
|
+
throw new CliError("validation_error", `unknown purpose ${wrong.join(", ")}; the configured ones are ${config.purposes.join(", ")}, or all`, { param: "purposes", purposes: [...config.purposes] });
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* The purposes a run reads: the asked ones, each checked against the config's list, else the project's own defaults,
|
|
@@ -19,7 +19,7 @@ export const purposesOf = (asked, config = BUILT_IN_PURPOSE_CONFIG, project) =>
|
|
|
19
19
|
const words = (asked ?? []).map((one) => one.trim()).filter(Boolean);
|
|
20
20
|
if (words.includes("all")) {
|
|
21
21
|
if (words.length > 1)
|
|
22
|
-
throw new CliError("validation_error", "--
|
|
22
|
+
throw new CliError("validation_error", "--purposes all reads every purpose; give it alone");
|
|
23
23
|
return "all";
|
|
24
24
|
}
|
|
25
25
|
if (words.length) {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import type { Setup } from "./define.js";
|
|
3
|
+
import { type Block, type ChoiceBlock, type Condition, type InputBlock, type Step, type Value } from "./document.js";
|
|
4
|
+
export type Field = InputBlock | ChoiceBlock;
|
|
5
|
+
/** A run's outcome on the path, as `result` conditions read it. */
|
|
6
|
+
export type Outcome = {
|
|
7
|
+
outcome: "ok";
|
|
8
|
+
} | {
|
|
9
|
+
outcome: "error";
|
|
10
|
+
code: string;
|
|
11
|
+
};
|
|
12
|
+
/** The current settings (by setting name) and which secrets are kept (by secret name), when a profile is edited. */
|
|
13
|
+
export type Current = Readonly<Record<string, Value | {
|
|
14
|
+
set: true;
|
|
15
|
+
}>>;
|
|
16
|
+
export interface Known {
|
|
17
|
+
field: (id: string) => unknown;
|
|
18
|
+
result: (name: string) => Outcome | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare const holds: (condition: Condition, known: Known) => boolean;
|
|
21
|
+
/** The inputs shown now: a block whose `when` fails hides itself and, for a group, everything in it. */
|
|
22
|
+
export declare const visibleFields: (blocks: readonly Block[] | undefined, known: Known) => Field[];
|
|
23
|
+
export declare const nextOf: (step: Step, known: Known) => string | undefined;
|
|
24
|
+
export interface FieldCheck {
|
|
25
|
+
value?: Value;
|
|
26
|
+
problem?: string;
|
|
27
|
+
}
|
|
28
|
+
/** One answer against its input and its setting's own schema; an empty answer takes the current value or the default. */
|
|
29
|
+
export declare const checkField: (field: Field, raw: unknown, { current, settingSchema }: {
|
|
30
|
+
current?: Current;
|
|
31
|
+
settingSchema: (key: string) => v.GenericSchema | undefined;
|
|
32
|
+
}) => FieldCheck;
|
|
33
|
+
export interface InputProblem {
|
|
34
|
+
input: string;
|
|
35
|
+
setting: string | null;
|
|
36
|
+
message: string;
|
|
37
|
+
}
|
|
38
|
+
export interface PathAnswers {
|
|
39
|
+
/** The steps visited, in order. */
|
|
40
|
+
path: string[];
|
|
41
|
+
/** Where the walk stopped: a run step, a done step, or the first step with a problem. */
|
|
42
|
+
at: string;
|
|
43
|
+
stopped: "run" | "done" | "problem" | "stuck";
|
|
44
|
+
kept: Record<string, Value>;
|
|
45
|
+
/** Answers on steps not visited, or inputs hidden on them: never checked, never saved. */
|
|
46
|
+
dropped: string[];
|
|
47
|
+
errors: InputProblem[];
|
|
48
|
+
settings: Record<string, Value>;
|
|
49
|
+
secrets: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The owner's answers along the path they lead to, from `start` to the first run or done step. Only inputs shown on a
|
|
53
|
+
* visited step count; everything else is dropped, so an answer on a branch the owner left is never saved.
|
|
54
|
+
*/
|
|
55
|
+
export declare const walk: (setup: Setup, answers: Readonly<Record<string, unknown>>, { current, results }?: {
|
|
56
|
+
current?: Current;
|
|
57
|
+
results?: Readonly<Record<string, Outcome>>;
|
|
58
|
+
}) => PathAnswers;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { SETUP_LIMITS, } from "./document.js";
|
|
3
|
+
export const holds = (condition, known) => {
|
|
4
|
+
if ("all" in condition)
|
|
5
|
+
return condition.all.every((one) => holds(one, known));
|
|
6
|
+
if ("any" in condition)
|
|
7
|
+
return condition.any.some((one) => holds(one, known));
|
|
8
|
+
if ("not" in condition)
|
|
9
|
+
return !holds(condition.not, known);
|
|
10
|
+
if ("result" in condition) {
|
|
11
|
+
const outcome = known.result(condition.result);
|
|
12
|
+
if (!outcome)
|
|
13
|
+
return false;
|
|
14
|
+
return "is" in condition
|
|
15
|
+
? outcome.outcome === "ok"
|
|
16
|
+
: outcome.outcome === "error" && outcome.code === condition.error;
|
|
17
|
+
}
|
|
18
|
+
const value = known.field(condition.field);
|
|
19
|
+
if ("set" in condition)
|
|
20
|
+
return (value !== undefined) === condition.set;
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
return false;
|
|
23
|
+
if ("in" in condition)
|
|
24
|
+
return condition.in.includes(value);
|
|
25
|
+
return value === condition.is;
|
|
26
|
+
};
|
|
27
|
+
/** The inputs shown now: a block whose `when` fails hides itself and, for a group, everything in it. */
|
|
28
|
+
export const visibleFields = (blocks = [], known) => blocks.flatMap((block) => {
|
|
29
|
+
if (block.when && !holds(block.when, known))
|
|
30
|
+
return [];
|
|
31
|
+
if (block.type === "group")
|
|
32
|
+
return visibleFields(block.blocks, known);
|
|
33
|
+
return block.type === "input" || block.type === "choice" ? [block] : [];
|
|
34
|
+
});
|
|
35
|
+
export const nextOf = (step, known) => {
|
|
36
|
+
if (typeof step.next === "string")
|
|
37
|
+
return step.next;
|
|
38
|
+
return step.next?.find((edge) => !edge.when || holds(edge.when, known))?.to;
|
|
39
|
+
};
|
|
40
|
+
const blank = (value) => value === undefined || value === null || value === "";
|
|
41
|
+
const strings = (value) => Array.isArray(value) && value.every((one) => typeof one === "string");
|
|
42
|
+
/** The kind's own shape; a setting's schema then has the final word. */
|
|
43
|
+
const shapeProblem = (field, value) => {
|
|
44
|
+
const choices = field.options?.map((option) => option.value);
|
|
45
|
+
const kind = field.type === "choice" ? "select" : field.input;
|
|
46
|
+
const counted = (list) => {
|
|
47
|
+
if (field.type === "input" && field.min !== undefined && list.length < field.min)
|
|
48
|
+
return `needs at least ${field.min}`;
|
|
49
|
+
if (field.type === "input" && field.max !== undefined && list.length > field.max)
|
|
50
|
+
return `takes at most ${field.max}`;
|
|
51
|
+
return undefined;
|
|
52
|
+
};
|
|
53
|
+
switch (kind) {
|
|
54
|
+
case "select":
|
|
55
|
+
return typeof value === "string" && (!choices || choices.includes(value))
|
|
56
|
+
? undefined
|
|
57
|
+
: `has to be one of: ${choices?.join(", ")}`;
|
|
58
|
+
case "multiselect":
|
|
59
|
+
if (!strings(value) || (choices && value.some((one) => !choices.includes(one))))
|
|
60
|
+
return `has to be a list of: ${choices?.join(", ")}`;
|
|
61
|
+
return counted(value);
|
|
62
|
+
case "countries":
|
|
63
|
+
if (!strings(value) || value.some((one) => !/^[A-Za-z]{2}$/.test(one)))
|
|
64
|
+
return "has to be a list of two-letter country codes";
|
|
65
|
+
return counted(value);
|
|
66
|
+
case "toggle":
|
|
67
|
+
return typeof value === "boolean" ? undefined : "has to be true or false";
|
|
68
|
+
case "number":
|
|
69
|
+
return typeof value === "number" && Number.isFinite(value) ? undefined : "has to be a number";
|
|
70
|
+
case "port":
|
|
71
|
+
return Number.isInteger(value) && value >= 1 && value <= 65535
|
|
72
|
+
? undefined
|
|
73
|
+
: "has to be a port number, 1 to 65535";
|
|
74
|
+
default:
|
|
75
|
+
return typeof value === "string" ? undefined : "has to be text";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
/** One answer against its input and its setting's own schema; an empty answer takes the current value or the default. */
|
|
79
|
+
export const checkField = (field, raw, { current = {}, settingSchema }) => {
|
|
80
|
+
const bound = field.setting ?? (field.type === "input" ? field.secret : undefined);
|
|
81
|
+
if (blank(raw)) {
|
|
82
|
+
if (field.default !== undefined && (bound === undefined || current[bound] === undefined))
|
|
83
|
+
return { value: field.default };
|
|
84
|
+
// A toggle left alone is an answer of its own: the setting keeps its default.
|
|
85
|
+
const toggle = field.type === "input" && field.input === "toggle";
|
|
86
|
+
if (field.optional || toggle || (bound !== undefined && current[bound] !== undefined))
|
|
87
|
+
return {};
|
|
88
|
+
return { problem: "is needed" };
|
|
89
|
+
}
|
|
90
|
+
const shape = shapeProblem(field, raw);
|
|
91
|
+
if (shape)
|
|
92
|
+
return { problem: shape };
|
|
93
|
+
const schema = field.setting === undefined ? undefined : settingSchema(field.setting);
|
|
94
|
+
if (schema) {
|
|
95
|
+
const parsed = v.safeParse(schema, raw);
|
|
96
|
+
if (!parsed.success)
|
|
97
|
+
return { problem: parsed.issues[0]?.message ?? "is not valid" };
|
|
98
|
+
}
|
|
99
|
+
return { value: raw };
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* The owner's answers along the path they lead to, from `start` to the first run or done step. Only inputs shown on a
|
|
103
|
+
* visited step count; everything else is dropped, so an answer on a branch the owner left is never saved.
|
|
104
|
+
*/
|
|
105
|
+
export const walk = (setup, answers, { current = {}, results = {} } = {}) => {
|
|
106
|
+
const { document, definition } = setup;
|
|
107
|
+
const settingSchema = definition.configuration.settingSchema;
|
|
108
|
+
const fields = new Map();
|
|
109
|
+
const kept = {};
|
|
110
|
+
const known = {
|
|
111
|
+
field: (id) => {
|
|
112
|
+
if (Object.hasOwn(kept, id))
|
|
113
|
+
return kept[id];
|
|
114
|
+
const field = fields.get(id);
|
|
115
|
+
if (!field)
|
|
116
|
+
return undefined;
|
|
117
|
+
if (!blank(answers[id]))
|
|
118
|
+
return answers[id];
|
|
119
|
+
return field.setting === undefined ? undefined : current[field.setting];
|
|
120
|
+
},
|
|
121
|
+
result: (name) => results[name],
|
|
122
|
+
};
|
|
123
|
+
const result = {
|
|
124
|
+
path: [],
|
|
125
|
+
at: document.start,
|
|
126
|
+
stopped: "stuck",
|
|
127
|
+
kept,
|
|
128
|
+
dropped: [],
|
|
129
|
+
errors: [],
|
|
130
|
+
settings: {},
|
|
131
|
+
secrets: {},
|
|
132
|
+
};
|
|
133
|
+
const bound = new Map();
|
|
134
|
+
let at = document.start;
|
|
135
|
+
for (let moves = 0; at !== undefined && moves < SETUP_LIMITS.transitions; moves++) {
|
|
136
|
+
const step = document.steps[at];
|
|
137
|
+
if (!step)
|
|
138
|
+
break;
|
|
139
|
+
result.path.push(at);
|
|
140
|
+
result.at = at;
|
|
141
|
+
if (step.kind === "run" || step.kind === "done") {
|
|
142
|
+
result.stopped = step.kind;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
// A field's answer can show another field of the same step: read until what is shown stops changing.
|
|
146
|
+
const before = result.errors.length;
|
|
147
|
+
let shown = [];
|
|
148
|
+
for (let round = 0; round < 5; round++) {
|
|
149
|
+
const now = visibleFields(step.blocks, known);
|
|
150
|
+
for (const field of now)
|
|
151
|
+
fields.set(field.id, field);
|
|
152
|
+
if (now.length === shown.length && now.every((field, index) => field === shown[index]))
|
|
153
|
+
break;
|
|
154
|
+
shown = now;
|
|
155
|
+
}
|
|
156
|
+
for (const field of shown) {
|
|
157
|
+
const checked = checkField(field, answers[field.id], { current, settingSchema });
|
|
158
|
+
const name = field.setting ?? (field.type === "input" ? field.secret : undefined);
|
|
159
|
+
if (checked.problem) {
|
|
160
|
+
result.errors.push({ input: field.id, setting: field.setting ?? null, message: checked.problem });
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (name !== undefined && bound.has(name) && bound.get(name) !== field.id) {
|
|
164
|
+
result.errors.push({
|
|
165
|
+
input: field.id,
|
|
166
|
+
setting: field.setting ?? null,
|
|
167
|
+
message: `${name} is already answered by ${bound.get(name)} on this path`,
|
|
168
|
+
});
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (checked.value === undefined)
|
|
172
|
+
continue;
|
|
173
|
+
kept[field.id] = checked.value;
|
|
174
|
+
if (name !== undefined)
|
|
175
|
+
bound.set(name, field.id);
|
|
176
|
+
}
|
|
177
|
+
if (result.errors.length > before) {
|
|
178
|
+
result.stopped = "problem";
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
at = nextOf(step, known);
|
|
182
|
+
}
|
|
183
|
+
for (const field of fields.values()) {
|
|
184
|
+
const value = kept[field.id];
|
|
185
|
+
if (value === undefined)
|
|
186
|
+
continue;
|
|
187
|
+
if (field.setting !== undefined)
|
|
188
|
+
result.settings[field.setting] = value;
|
|
189
|
+
else if (field.type === "input" && field.secret !== undefined && typeof value === "string")
|
|
190
|
+
result.secrets[field.secret] = value;
|
|
191
|
+
}
|
|
192
|
+
result.dropped = Object.keys(answers).filter((id) => !Object.hasOwn(kept, id));
|
|
193
|
+
return result;
|
|
194
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { OwnerOnlySettings } from "../cli/config-command.js";
|
|
3
|
+
import type { Configuration, Settings } from "../cli/settings.js";
|
|
4
|
+
import type { AppIdentity } from "../ports/app.js";
|
|
5
|
+
import type { SignInSteps } from "../terminal/sign-in-steps.js";
|
|
6
|
+
import { type Asset, type Block, type SetupDocument, type Step, type Texts, type Value } from "./document.js";
|
|
7
|
+
export interface SetupCheckInput {
|
|
8
|
+
command: Command;
|
|
9
|
+
profile: string;
|
|
10
|
+
/** The profile's settings with the answers' settings laid over `configured`: what the file would hold. */
|
|
11
|
+
settings: Settings;
|
|
12
|
+
/** The secrets the path's inputs gave, by name. None is kept yet. */
|
|
13
|
+
secrets: Readonly<Record<string, string>>;
|
|
14
|
+
answers: Readonly<Record<string, Value>>;
|
|
15
|
+
/** The sign-in events (`progress`, `needs`…) Desktop reads on stderr. */
|
|
16
|
+
steps: SignInSteps;
|
|
17
|
+
}
|
|
18
|
+
/** The CLI's own proof that the answers work, as its `session start` checks. A throw saves nothing. */
|
|
19
|
+
export type SetupCheck = (input: SetupCheckInput) => Promise<Record<string, unknown> | undefined>;
|
|
20
|
+
export interface SetupDefinition {
|
|
21
|
+
app: AppIdentity;
|
|
22
|
+
configuration: Pick<Configuration, "allSettings" | "settingSchema" | "resolveSettings" | "changeSetting">;
|
|
23
|
+
requires?: string[];
|
|
24
|
+
start: string;
|
|
25
|
+
steps: Record<string, Step>;
|
|
26
|
+
assets?: Record<string, Asset>;
|
|
27
|
+
texts: {
|
|
28
|
+
en: Texts;
|
|
29
|
+
} & Record<string, Texts>;
|
|
30
|
+
check?: SetupCheck;
|
|
31
|
+
/** The same list `configCommand` takes: settings an agent's run may not change, so a flow cannot either. */
|
|
32
|
+
ownerOnly?: OwnerOnlySettings;
|
|
33
|
+
}
|
|
34
|
+
export interface Setup {
|
|
35
|
+
readonly app: AppIdentity;
|
|
36
|
+
readonly document: SetupDocument;
|
|
37
|
+
readonly definition: SetupDefinition;
|
|
38
|
+
}
|
|
39
|
+
export interface ProblemOptions {
|
|
40
|
+
/** The settings the CLI declares; left out, a bound setting is not checked. */
|
|
41
|
+
settings?: readonly string[];
|
|
42
|
+
/** Only what cli-core v1 builds: known types, roles and classes, run action `apply`, no `options_from`. */
|
|
43
|
+
v1?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Every block of a step, groups opened, with how deep each sits. */
|
|
46
|
+
export declare const blocksOf: (blocks?: readonly Block[], depth?: number) => {
|
|
47
|
+
block: Block;
|
|
48
|
+
depth: number;
|
|
49
|
+
}[];
|
|
50
|
+
export declare const targetsOf: (step: Step) => string[];
|
|
51
|
+
/**
|
|
52
|
+
* What is wrong with a setup document, each as one line: the schema first, then what a schema cannot say — every step
|
|
53
|
+
* reachable, every target there, each text in English, each input bound once, the limits.
|
|
54
|
+
*/
|
|
55
|
+
export declare const setupProblems: (document: unknown, { settings, v1 }?: ProblemOptions) => string[];
|
|
56
|
+
/**
|
|
57
|
+
* A CLI's connection flow, built and checked once: a wrong flow throws here, so the CLI's own tests fail before it
|
|
58
|
+
* ships. Asset files are checked by `setupFileProblems`, from those tests, never at start.
|
|
59
|
+
*/
|
|
60
|
+
export declare const defineSetup: (definition: SetupDefinition) => Setup;
|