@open-conduit/sdk 7.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.d.ts +145 -0
- package/dist/actions.js +281 -0
- package/dist/actiontest.d.ts +80 -0
- package/dist/actiontest.js +190 -0
- package/dist/artifactstore.d.ts +133 -0
- package/dist/artifactstore.js +364 -0
- package/dist/backup.d.ts +99 -0
- package/dist/backup.js +178 -0
- package/dist/containertest.d.ts +71 -0
- package/dist/containertest.js +294 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +37 -0
- package/dist/executor.d.ts +374 -0
- package/dist/executor.js +556 -0
- package/dist/executortest.d.ts +183 -0
- package/dist/executortest.js +534 -0
- package/dist/extension.d.ts +496 -1
- package/dist/extension.js +1152 -4
- package/dist/feed.d.ts +20 -0
- package/dist/feed.js +88 -0
- package/dist/forward.d.ts +38 -0
- package/dist/forward.js +163 -0
- package/dist/forwardca.d.ts +21 -0
- package/dist/forwardca.js +144 -0
- package/dist/hooks.d.ts +108 -0
- package/dist/hooks.js +13 -0
- package/dist/host.d.ts +166 -2
- package/dist/host.js +235 -2
- package/dist/index.d.ts +27 -3
- package/dist/index.js +14 -2
- package/dist/probe.d.ts +61 -0
- package/dist/probe.js +92 -0
- package/dist/providertest.d.ts +59 -0
- package/dist/providertest.js +168 -0
- package/dist/resources.d.ts +208 -0
- package/dist/resources.js +303 -0
- package/dist/sandbox.d.ts +84 -0
- package/dist/sandbox.js +85 -0
- package/dist/setup.d.ts +145 -0
- package/dist/setup.js +179 -0
- package/dist/setuptest.d.ts +90 -0
- package/dist/setuptest.js +319 -0
- package/dist/storetest.d.ts +64 -0
- package/dist/storetest.js +740 -0
- package/dist/telemetry.d.ts +86 -0
- package/dist/telemetry.js +46 -0
- package/dist/testing.d.ts +591 -2
- package/dist/testing.js +1460 -6
- package/dist/toolbelt.d.ts +91 -0
- package/dist/toolbelt.js +216 -0
- package/dist/tunnel.d.ts +62 -0
- package/dist/tunnel.js +93 -0
- package/dist/wire.d.ts +4060 -348
- package/dist/wire.js +1583 -0
- package/package.json +1 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { Context } from "./extension.js";
|
|
2
|
+
import type { Action, ActionTarget, Annotation, Caller, Event, PageDecl, Panel as WirePanel, Wording, Work, WorkActParams } from "./wire.js";
|
|
3
|
+
export type { Action, ActionTarget, Annotation, Wording };
|
|
4
|
+
/** Who invokes an action, as kind and ID (extension.Caller). */
|
|
5
|
+
export type ActionCaller = Caller;
|
|
6
|
+
/** The operator at this host's own terminal or web view (extension.LocalOperator). */
|
|
7
|
+
export declare const LocalOperator: ActionCaller;
|
|
8
|
+
/** One invocation of an action. input is what the person gave: a choice, text, or a secret's name. */
|
|
9
|
+
export interface ActionCall {
|
|
10
|
+
target: ActionTarget;
|
|
11
|
+
action: string;
|
|
12
|
+
input: string;
|
|
13
|
+
caller: ActionCaller;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* An authorised invocation: the one Event the host accepts under
|
|
17
|
+
* core.action, of a family the extension declares. It carries only a type,
|
|
18
|
+
* a correlation key (in the extension's own source namespace) and data;
|
|
19
|
+
* the host assigns the rest. message, when set, is shown to the caller.
|
|
20
|
+
*/
|
|
21
|
+
export interface ActionPlan {
|
|
22
|
+
event: Pick<Event, "type" | "correlation_key" | "data">;
|
|
23
|
+
message?: string;
|
|
24
|
+
}
|
|
25
|
+
/** The states of a request (extension.Request*). */
|
|
26
|
+
export declare const RequestState: {
|
|
27
|
+
readonly Open: "open";
|
|
28
|
+
readonly Answered: "answered";
|
|
29
|
+
readonly Refused: "refused";
|
|
30
|
+
readonly Expired: "expired";
|
|
31
|
+
readonly Withdrawn: "withdrawn";
|
|
32
|
+
};
|
|
33
|
+
export type RequestState = (typeof RequestState)[keyof typeof RequestState];
|
|
34
|
+
/** The tones a worded choice may take (extension.Tone*). */
|
|
35
|
+
export declare const Tone: {
|
|
36
|
+
readonly Affirm: "affirm";
|
|
37
|
+
readonly Danger: "danger";
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* One request a person is asked to decide (extension.Request): open until
|
|
41
|
+
* it is answered, refused, expires or is withdrawn. An open one names the
|
|
42
|
+
* action that answers it (offered on the same target now), and only a
|
|
43
|
+
* settled one says who settled it and when.
|
|
44
|
+
*/
|
|
45
|
+
export interface RequestInfo {
|
|
46
|
+
id: string;
|
|
47
|
+
label: string;
|
|
48
|
+
detail?: string;
|
|
49
|
+
action?: string;
|
|
50
|
+
responders?: string[];
|
|
51
|
+
state: RequestState;
|
|
52
|
+
by?: string;
|
|
53
|
+
settledAt?: Date;
|
|
54
|
+
wording?: Wording;
|
|
55
|
+
}
|
|
56
|
+
/** One line of a panel's conversation; at is when it was said. */
|
|
57
|
+
export interface PanelMessage {
|
|
58
|
+
from: "operator" | "participant" | "note";
|
|
59
|
+
label?: string;
|
|
60
|
+
text: string;
|
|
61
|
+
at?: Date;
|
|
62
|
+
choices?: string[];
|
|
63
|
+
chosen?: string;
|
|
64
|
+
}
|
|
65
|
+
/** A panel section as a handler writes it: the wire's, with Dates for times. */
|
|
66
|
+
export type PanelSection = Omit<WirePanel["sections"][number], "messages"> & {
|
|
67
|
+
messages?: PanelMessage[];
|
|
68
|
+
};
|
|
69
|
+
/** One panel on a target (extension.Panel). */
|
|
70
|
+
export interface Panel {
|
|
71
|
+
id: string;
|
|
72
|
+
title: string;
|
|
73
|
+
sections: PanelSection[];
|
|
74
|
+
}
|
|
75
|
+
export interface ActionsSpec {
|
|
76
|
+
/** The actions available on the target now; none where nothing is outstanding. */
|
|
77
|
+
list?: (target: ActionTarget, ctx: Context) => Action[] | Promise<Action[]>;
|
|
78
|
+
/** Authorises one invocation, or throws OperationError to refuse it. */
|
|
79
|
+
act?: (call: ActionCall, ctx: Context) => ActionPlan | Promise<ActionPlan>;
|
|
80
|
+
/** The requests the actions answer on the target, open and settled. */
|
|
81
|
+
requests?: (target: ActionTarget, ctx: Context) => RequestInfo[] | Promise<RequestInfo[]>;
|
|
82
|
+
/** The panels to show on the target now; none where there is nothing to say. */
|
|
83
|
+
panels?: (target: ActionTarget, ctx: Context) => Panel[] | Promise<Panel[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Some actions ask a person for a secret (Action.secret), which the host
|
|
86
|
+
* takes privately and passes to act by name. Without it, a listing that
|
|
87
|
+
* offers one is refused, as the host refuses it.
|
|
88
|
+
*/
|
|
89
|
+
secretActions?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* On a scope the extension goes by the name of the first of its entries
|
|
92
|
+
* there rather than its own, as an action's delivery and an annotation's
|
|
93
|
+
* source. It needs an entry type.
|
|
94
|
+
*/
|
|
95
|
+
entryNamed?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** @internal The served form of an ActionsSpec. */
|
|
98
|
+
export interface ActionsHandler {
|
|
99
|
+
list?: (p: ActionTarget, ctx: Context) => Promise<unknown>;
|
|
100
|
+
act?: (p: WorkActParams, ctx: Context) => Promise<unknown>;
|
|
101
|
+
requests?: (p: ActionTarget, ctx: Context) => Promise<unknown>;
|
|
102
|
+
panels?: (p: ActionTarget, ctx: Context) => Promise<unknown>;
|
|
103
|
+
}
|
|
104
|
+
/** @internal */
|
|
105
|
+
export declare function actionsHandler(spec: ActionsSpec): ActionsHandler;
|
|
106
|
+
/** Panel limits (extension.MaxPanel*): a panel over them is not shown. */
|
|
107
|
+
export declare const PanelLimits: {
|
|
108
|
+
readonly panels: 4;
|
|
109
|
+
readonly sections: 16;
|
|
110
|
+
readonly fields: 32;
|
|
111
|
+
readonly links: 16;
|
|
112
|
+
readonly columns: 8;
|
|
113
|
+
readonly rows: 100;
|
|
114
|
+
readonly title: 200;
|
|
115
|
+
readonly value: 2048;
|
|
116
|
+
readonly text: 8192;
|
|
117
|
+
readonly messages: 200;
|
|
118
|
+
readonly choices: 16;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Why a panel can't be shown, or undefined (extension.Panel.Validate): the
|
|
122
|
+
* host shows no panel over its limits, and never truncates one into
|
|
123
|
+
* something the extension didn't say.
|
|
124
|
+
*/
|
|
125
|
+
export declare function panelProblem(p: Panel): string | undefined;
|
|
126
|
+
/** A page the extension contributes to the operator's web view (extension.Page). */
|
|
127
|
+
export interface PageSpec {
|
|
128
|
+
/** One line, at most 60 bytes. */
|
|
129
|
+
title: string;
|
|
130
|
+
summary?: string;
|
|
131
|
+
/** The extension entry type whose scopes offer the page; its entry provides every action named here. */
|
|
132
|
+
entry: string;
|
|
133
|
+
/** The kind of the Work a session is. */
|
|
134
|
+
workKind: string;
|
|
135
|
+
/** The action on the scope that starts a session. */
|
|
136
|
+
start: string;
|
|
137
|
+
/** The actions on the session the message box sends, the first offered winning. */
|
|
138
|
+
compose?: string[];
|
|
139
|
+
/** The route handler whose binding's grants the operator may turn on when starting. */
|
|
140
|
+
route?: string;
|
|
141
|
+
}
|
|
142
|
+
/** The page's declaration, or throws why it can't be offered (extension.Page.Validate). */
|
|
143
|
+
export declare function pageDecl(id: string, p: PageSpec): PageDecl;
|
|
144
|
+
/** Annotates a Work: name/value lines shown on its view (manifest annotate). */
|
|
145
|
+
export type AnnotateFn = (work: Work, ctx: Context) => Annotation[] | Promise<Annotation[]>;
|
package/dist/actions.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// Actions, requests, panels, annotations and pages: what an extension
|
|
2
|
+
// shows and offers a person on the scope and Work pages of every operator
|
|
3
|
+
// view, as protocol/sdk serves sdk.Extension's Actions, Act, Requests,
|
|
4
|
+
// Panels and Annotate.
|
|
5
|
+
//
|
|
6
|
+
// An action is offered on a target (a scope, or a Work in it) while list
|
|
7
|
+
// names it, and invoking it is act's decision: it authorises one call by
|
|
8
|
+
// returning the one Event the host accepts under core.action, or refuses
|
|
9
|
+
// with an OperationError, whose code and message reach the caller. A panel
|
|
10
|
+
// is a constrained document core renders, so no extension code runs in
|
|
11
|
+
// the browser; its buttons name actions, which the host shows only while
|
|
12
|
+
// list offers them on the same target and invokes through the action
|
|
13
|
+
// path, so a panel confers no authority of its own. list, requests and
|
|
14
|
+
// panels are called on every view refresh and must not write state.
|
|
15
|
+
import { Code, ProtocolError } from "./errors.js";
|
|
16
|
+
/** The operator at this host's own terminal or web view (extension.LocalOperator). */
|
|
17
|
+
export const LocalOperator = { kind: "operator", id: "local" };
|
|
18
|
+
/** The states of a request (extension.Request*). */
|
|
19
|
+
export const RequestState = {
|
|
20
|
+
Open: "open",
|
|
21
|
+
Answered: "answered",
|
|
22
|
+
Refused: "refused",
|
|
23
|
+
Expired: "expired",
|
|
24
|
+
Withdrawn: "withdrawn",
|
|
25
|
+
};
|
|
26
|
+
/** The tones a worded choice may take (extension.Tone*). */
|
|
27
|
+
export const Tone = { Affirm: "affirm", Danger: "danger" };
|
|
28
|
+
/** @internal */
|
|
29
|
+
export function actionsHandler(spec) {
|
|
30
|
+
const out = {};
|
|
31
|
+
const { list, act, requests, panels } = spec;
|
|
32
|
+
if (list !== undefined)
|
|
33
|
+
out.list = async (target, ctx) => {
|
|
34
|
+
const actions = await list(target, ctx);
|
|
35
|
+
for (const a of actions)
|
|
36
|
+
if (a.secret && !spec.secretActions)
|
|
37
|
+
throw new ProtocolError(Code.Internal, `action ${a.id} asks for a secret, but the extension doesn't declare secretActions`);
|
|
38
|
+
return actions.length > 0 ? { actions: actions.map(action) } : {};
|
|
39
|
+
};
|
|
40
|
+
if (act !== undefined)
|
|
41
|
+
out.act = async (p, ctx) => {
|
|
42
|
+
const plan = await act({
|
|
43
|
+
target: p.target,
|
|
44
|
+
action: p.action,
|
|
45
|
+
input: p.input ?? "",
|
|
46
|
+
caller: p.caller,
|
|
47
|
+
}, ctx);
|
|
48
|
+
const e = plan.event;
|
|
49
|
+
// Only what a plan may carry crosses: the host assigns the rest.
|
|
50
|
+
return {
|
|
51
|
+
event: {
|
|
52
|
+
type: e.type,
|
|
53
|
+
...(e.correlation_key ? { correlation_key: e.correlation_key } : {}),
|
|
54
|
+
...(e.data === undefined ? {} : { data: e.data }),
|
|
55
|
+
},
|
|
56
|
+
...(plan.message ? { message: plan.message } : {}),
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
if (requests !== undefined)
|
|
60
|
+
out.requests = async (target, ctx) => {
|
|
61
|
+
const rs = await requests(target, ctx);
|
|
62
|
+
return rs.length > 0 ? { requests: rs.map(wireRequest) } : {};
|
|
63
|
+
};
|
|
64
|
+
if (panels !== undefined)
|
|
65
|
+
out.panels = async (target, ctx) => {
|
|
66
|
+
const ps = await panels(target, ctx);
|
|
67
|
+
return ps.length > 0 ? { panels: ps.map(wirePanel) } : {};
|
|
68
|
+
};
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
function action(a) {
|
|
72
|
+
return {
|
|
73
|
+
id: a.id,
|
|
74
|
+
label: a.label,
|
|
75
|
+
...(a.prompt ? { prompt: a.prompt } : {}),
|
|
76
|
+
...(a.choices?.length ? { choices: [...a.choices] } : {}),
|
|
77
|
+
...(a.detail ? { detail: a.detail } : {}),
|
|
78
|
+
...(a.awaited ? { awaited: true } : {}),
|
|
79
|
+
...(a.secret ? { secret: a.secret } : {}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function time(d, what) {
|
|
83
|
+
if (d === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
if (!(d instanceof Date) || Number.isNaN(d.getTime()))
|
|
86
|
+
throw new ProtocolError(Code.Internal, `${what} is not a valid Date`);
|
|
87
|
+
return d.toISOString();
|
|
88
|
+
}
|
|
89
|
+
function wireRequest(r) {
|
|
90
|
+
const settled = time(r.settledAt, `request ${r.id}'s settledAt`);
|
|
91
|
+
return {
|
|
92
|
+
id: r.id,
|
|
93
|
+
label: r.label,
|
|
94
|
+
...(r.detail ? { detail: r.detail } : {}),
|
|
95
|
+
...(r.action ? { action: r.action } : {}),
|
|
96
|
+
...(r.responders?.length ? { responders: [...r.responders] } : {}),
|
|
97
|
+
state: r.state,
|
|
98
|
+
...(r.by ? { by: r.by } : {}),
|
|
99
|
+
...(settled ? { settled_at: settled } : {}),
|
|
100
|
+
...(r.wording ? { wording: r.wording } : {}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function wirePanel(p) {
|
|
104
|
+
return {
|
|
105
|
+
id: p.id,
|
|
106
|
+
title: p.title,
|
|
107
|
+
sections: p.sections.map((s) => {
|
|
108
|
+
const { messages, ...rest } = s;
|
|
109
|
+
if (messages === undefined)
|
|
110
|
+
return rest;
|
|
111
|
+
return {
|
|
112
|
+
...rest,
|
|
113
|
+
messages: messages.map((m) => {
|
|
114
|
+
const { at, ...line } = m;
|
|
115
|
+
const when = time(at, `panel ${p.id}'s message time`);
|
|
116
|
+
return when ? { ...line, at: when } : line;
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
}),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** Panel limits (extension.MaxPanel*): a panel over them is not shown. */
|
|
123
|
+
export const PanelLimits = {
|
|
124
|
+
panels: 4,
|
|
125
|
+
sections: 16,
|
|
126
|
+
fields: 32,
|
|
127
|
+
links: 16,
|
|
128
|
+
columns: 8,
|
|
129
|
+
rows: 100,
|
|
130
|
+
title: 200,
|
|
131
|
+
value: 2048,
|
|
132
|
+
text: 8192,
|
|
133
|
+
messages: 200,
|
|
134
|
+
choices: 16,
|
|
135
|
+
};
|
|
136
|
+
const panelId = /^[a-z][a-z0-9_]{0,63}$/;
|
|
137
|
+
const bytes = (s) => Buffer.byteLength(s, "utf8");
|
|
138
|
+
/** text checks one string of a panel or page (extension's text and line). */
|
|
139
|
+
function text(what, s, limit, required, oneLine = false) {
|
|
140
|
+
const v = s ?? "";
|
|
141
|
+
if (required && v.trim() === "")
|
|
142
|
+
return `${what} is required`;
|
|
143
|
+
if (bytes(v) > limit)
|
|
144
|
+
return `${what} is longer than ${limit} bytes`;
|
|
145
|
+
for (const ch of v) {
|
|
146
|
+
const c = ch.codePointAt(0);
|
|
147
|
+
if (c >= 0xd800 && c <= 0xdfff)
|
|
148
|
+
return `${what} is not UTF-8`;
|
|
149
|
+
if (oneLine && (c === 0x0a || c === 0x09))
|
|
150
|
+
return `${what} is not one line`;
|
|
151
|
+
if ((c < 0x20 && c !== 0x0a && c !== 0x09) || c === 0x7f)
|
|
152
|
+
return `${what} has a control character`;
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
function httpURL(s) {
|
|
157
|
+
if (bytes(s) > PanelLimits.value)
|
|
158
|
+
return false;
|
|
159
|
+
try {
|
|
160
|
+
const u = new URL(s);
|
|
161
|
+
return (u.protocol === "http:" || u.protocol === "https:") && u.host !== "";
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Why a panel can't be shown, or undefined (extension.Panel.Validate): the
|
|
169
|
+
* host shows no panel over its limits, and never truncates one into
|
|
170
|
+
* something the extension didn't say.
|
|
171
|
+
*/
|
|
172
|
+
export function panelProblem(p) {
|
|
173
|
+
if (!panelId.test(p.id))
|
|
174
|
+
return `panel id "${p.id}" is not [a-z][a-z0-9_]*`;
|
|
175
|
+
const title = text("title", p.title, PanelLimits.title, true);
|
|
176
|
+
if (title)
|
|
177
|
+
return title;
|
|
178
|
+
if (p.sections.length === 0 || p.sections.length > PanelLimits.sections)
|
|
179
|
+
return `panel ${p.id} has ${p.sections.length} sections, want 1 to ${PanelLimits.sections}`;
|
|
180
|
+
for (const [i, s] of p.sections.entries()) {
|
|
181
|
+
const bad = sectionProblem(s);
|
|
182
|
+
if (bad)
|
|
183
|
+
return `panel ${p.id} section ${i + 1}: ${bad}`;
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
function sectionProblem(s) {
|
|
188
|
+
if (!s.title &&
|
|
189
|
+
!s.text &&
|
|
190
|
+
!s.fields?.length &&
|
|
191
|
+
s.table === undefined &&
|
|
192
|
+
!s.messages?.length &&
|
|
193
|
+
!s.links?.length &&
|
|
194
|
+
!s.actions?.length)
|
|
195
|
+
return "empty section";
|
|
196
|
+
const checks = [
|
|
197
|
+
text("title", s.title, PanelLimits.title, false),
|
|
198
|
+
text("text", s.text, PanelLimits.text, false),
|
|
199
|
+
];
|
|
200
|
+
const fields = s.fields ?? [];
|
|
201
|
+
if (fields.length > PanelLimits.fields)
|
|
202
|
+
return `more than ${PanelLimits.fields} fields`;
|
|
203
|
+
for (const f of fields)
|
|
204
|
+
checks.push(text("field name", f.name, PanelLimits.title, true), text("field value", f.value, PanelLimits.value, false));
|
|
205
|
+
const table = s.table;
|
|
206
|
+
if (table !== undefined) {
|
|
207
|
+
const rows = table.rows ?? [];
|
|
208
|
+
if (table.columns.length === 0 ||
|
|
209
|
+
table.columns.length > PanelLimits.columns ||
|
|
210
|
+
rows.length > PanelLimits.rows)
|
|
211
|
+
return `table must have 1 to ${PanelLimits.columns} columns and at most ${PanelLimits.rows} rows`;
|
|
212
|
+
for (const c of table.columns)
|
|
213
|
+
checks.push(text("column", c, PanelLimits.title, false));
|
|
214
|
+
for (const r of rows) {
|
|
215
|
+
if (r.length !== table.columns.length)
|
|
216
|
+
return `table row has ${r.length} cells for ${table.columns.length} columns`;
|
|
217
|
+
for (const c of r)
|
|
218
|
+
checks.push(text("cell", c, PanelLimits.value, false));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const messages = s.messages ?? [];
|
|
222
|
+
if (messages.length > PanelLimits.messages)
|
|
223
|
+
return `more than ${PanelLimits.messages} messages`;
|
|
224
|
+
for (const m of messages) {
|
|
225
|
+
if (!["operator", "participant", "agent", "note"].includes(m.from))
|
|
226
|
+
return `message from "${m.from}" is not operator, participant or note`;
|
|
227
|
+
checks.push(text("message label", m.label, PanelLimits.title, false, true), text("message", m.text, PanelLimits.text, true));
|
|
228
|
+
if ((m.choices?.length ?? 0) > PanelLimits.choices)
|
|
229
|
+
return `message has more than ${PanelLimits.choices} choices`;
|
|
230
|
+
for (const c of m.choices ?? [])
|
|
231
|
+
checks.push(text("choice", c, PanelLimits.title, true, true));
|
|
232
|
+
checks.push(text("chosen", m.chosen, PanelLimits.title, false, true));
|
|
233
|
+
}
|
|
234
|
+
const links = s.links ?? [];
|
|
235
|
+
if (links.length > PanelLimits.links)
|
|
236
|
+
return `more than ${PanelLimits.links} links`;
|
|
237
|
+
for (const l of links) {
|
|
238
|
+
checks.push(text("link label", l.label, PanelLimits.title, true));
|
|
239
|
+
if (!httpURL(l.url))
|
|
240
|
+
return `link "${l.url}" is not an http or https URL`;
|
|
241
|
+
}
|
|
242
|
+
const seen = new Set();
|
|
243
|
+
for (const a of s.actions ?? []) {
|
|
244
|
+
if (!panelId.test(a) || seen.has(a))
|
|
245
|
+
return `action "${a}" is not an action id, or repeats`;
|
|
246
|
+
seen.add(a);
|
|
247
|
+
}
|
|
248
|
+
return checks.find((c) => c !== undefined);
|
|
249
|
+
}
|
|
250
|
+
const pageId = /^[a-z][a-z0-9_-]{0,31}$/;
|
|
251
|
+
/** The page's declaration, or throws why it can't be offered (extension.Page.Validate). */
|
|
252
|
+
export function pageDecl(id, p) {
|
|
253
|
+
const refuse = (why) => {
|
|
254
|
+
throw new Error(`sdk: page ${id}: ${why}`);
|
|
255
|
+
};
|
|
256
|
+
if (!pageId.test(id))
|
|
257
|
+
refuse(`page id "${id}" is not [a-z][a-z0-9_-]*`);
|
|
258
|
+
const bad = text("page title", p.title, 60, true, true) ??
|
|
259
|
+
text("page summary", p.summary, 400, false);
|
|
260
|
+
if (bad)
|
|
261
|
+
refuse(bad);
|
|
262
|
+
if (!p.entry || !p.workKind)
|
|
263
|
+
refuse("it needs an entry type and a work kind");
|
|
264
|
+
if (!panelId.test(p.start))
|
|
265
|
+
refuse(`start "${p.start}" is not an action id`);
|
|
266
|
+
if ((p.compose?.length ?? 0) > 4)
|
|
267
|
+
refuse("more than 4 compose actions");
|
|
268
|
+
for (const a of p.compose ?? [])
|
|
269
|
+
if (!panelId.test(a))
|
|
270
|
+
refuse(`compose "${a}" is not an action id`);
|
|
271
|
+
return {
|
|
272
|
+
id,
|
|
273
|
+
title: p.title,
|
|
274
|
+
...(p.summary ? { summary: p.summary } : {}),
|
|
275
|
+
entry: p.entry,
|
|
276
|
+
work_kind: p.workKind,
|
|
277
|
+
start: p.start,
|
|
278
|
+
...(p.compose?.length ? { compose: [...p.compose] } : {}),
|
|
279
|
+
...(p.route ? { route: p.route } : {}),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type ActionCaller, type ActionPlan, type Panel, type RequestInfo } from "./actions.js";
|
|
2
|
+
import type { Action, ActionTarget, Scope, Work } from "./wire.js";
|
|
3
|
+
/** An extension's actions, requests and panels as the host reaches them. */
|
|
4
|
+
export interface TestActionProvider {
|
|
5
|
+
actions(target: ActionTarget): Promise<Action[]>;
|
|
6
|
+
/** One invocation's plan, or the OperationError it was refused with. */
|
|
7
|
+
invoke(call: {
|
|
8
|
+
target: ActionTarget;
|
|
9
|
+
action: string;
|
|
10
|
+
input?: string;
|
|
11
|
+
caller: ActionCaller;
|
|
12
|
+
}): Promise<ActionPlan>;
|
|
13
|
+
requests(target: ActionTarget): Promise<RequestInfo[]>;
|
|
14
|
+
panels(target: ActionTarget): Promise<Panel[]>;
|
|
15
|
+
}
|
|
16
|
+
/** A scope as the host sends it in a target (state.scope's shape), for tests. */
|
|
17
|
+
export declare function testScope(id: string, o?: Partial<Scope>): Scope;
|
|
18
|
+
/** A Work as the host sends it, for tests: of kind in scope, its context data data. */
|
|
19
|
+
export declare function testWork(id: string, o?: Partial<Work> & {
|
|
20
|
+
data?: unknown;
|
|
21
|
+
}): Work;
|
|
22
|
+
/**
|
|
23
|
+
* The action contract (conformance.ActionFixture): action is offered on
|
|
24
|
+
* available and not on unavailable; caller may invoke it, stranger may
|
|
25
|
+
* not; input is valid and badInput, when set, refused; eventType is the
|
|
26
|
+
* family a granted invocation produces.
|
|
27
|
+
*/
|
|
28
|
+
export interface ActionFixture {
|
|
29
|
+
provider: TestActionProvider;
|
|
30
|
+
available: ActionTarget;
|
|
31
|
+
unavailable: ActionTarget;
|
|
32
|
+
action: string;
|
|
33
|
+
input: string;
|
|
34
|
+
badInput?: string;
|
|
35
|
+
caller: ActionCaller;
|
|
36
|
+
stranger: ActionCaller;
|
|
37
|
+
eventType: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks, as conformance.CheckActions does: listing is well formed and
|
|
41
|
+
* offers the action only where it is available; a granted invocation plans
|
|
42
|
+
* one Event of the expected family, the same each time, so a replay is
|
|
43
|
+
* safe; and an unavailable target, a caller it doesn't recognise, invalid
|
|
44
|
+
* input and an unknown action are each refused with an OperationError of
|
|
45
|
+
* an authored code, so the host accepts no Event.
|
|
46
|
+
*/
|
|
47
|
+
export declare function checkActions(f: ActionFixture): Promise<void>;
|
|
48
|
+
/** The panel contract (conformance.PanelFixture): panels show on shown and not on hidden. */
|
|
49
|
+
export interface PanelFixture {
|
|
50
|
+
provider: TestActionProvider;
|
|
51
|
+
shown: ActionTarget;
|
|
52
|
+
hidden: ActionTarget;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Checks, as conformance.CheckPanels does: on shown, 1 to PanelLimits.panels
|
|
56
|
+
* panels, each within the document limits (panelProblem) with a unique
|
|
57
|
+
* ID, every button naming an action listed on the same target, the same
|
|
58
|
+
* panels each time; and none on hidden.
|
|
59
|
+
*/
|
|
60
|
+
export declare function checkPanels(f: PanelFixture): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* The request contract (conformance.RequestFixture): answerable has an
|
|
63
|
+
* open request one of its offered actions answers now; others are more
|
|
64
|
+
* targets the rules hold on (one settled, one with nothing outstanding).
|
|
65
|
+
*/
|
|
66
|
+
export interface RequestFixture {
|
|
67
|
+
provider: TestActionProvider;
|
|
68
|
+
answerable: ActionTarget;
|
|
69
|
+
others: ActionTarget[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Checks, as conformance.CheckRequests does, on every target: each request
|
|
73
|
+
* has an ID unique on the target and a label, a known state, and who and
|
|
74
|
+
* when only once settled; its wording is an approval or a question, not
|
|
75
|
+
* both, each choice worded once, toned affirm, danger or not at all, and
|
|
76
|
+
* one of its action's choices; its action is named only while it is open,
|
|
77
|
+
* offered on the target now, and by no other request. answerable reports
|
|
78
|
+
* an open request with its action.
|
|
79
|
+
*/
|
|
80
|
+
export declare function checkRequests(f: RequestFixture): Promise<void>;
|