@action-state-group/capsule-viewer 0.12.0 → 0.14.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/README.md +6 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +3 -0
- package/dist/browser.js.map +1 -1
- package/dist/compliance-view.d.ts +6 -0
- package/dist/compliance-view.js +21 -3
- package/dist/compliance-view.js.map +1 -1
- package/dist/contract-report-wording.d.ts +6 -2
- package/dist/contract-report-wording.js +57 -6
- package/dist/contract-report-wording.js.map +1 -1
- package/dist/contract-report.d.ts +3 -2
- package/dist/contract-report.js +5 -2
- package/dist/contract-report.js.map +1 -1
- package/dist/core-strip.d.ts +1 -1
- package/dist/core-strip.js +80 -25
- package/dist/core-strip.js.map +1 -1
- package/dist/evidence-graph-view.d.ts +2 -2
- package/dist/evidence-graph-view.js +16 -10
- package/dist/evidence-graph-view.js.map +1 -1
- package/dist/evidence-graph.iife.js +3576 -560
- package/dist/generic-report-view.d.ts +36 -0
- package/dist/generic-report-view.js +304 -0
- package/dist/generic-report-view.js.map +1 -0
- package/dist/history-view.d.ts +290 -0
- package/dist/history-view.iife.js +1278 -0
- package/dist/history-view.iife.js.sha256 +1 -0
- package/dist/history-view.js +940 -0
- package/dist/history-view.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/outcome-report-view.js +41 -5
- package/dist/outcome-report-view.js.map +1 -1
- package/dist/report-front-styles.js +1 -0
- package/dist/report-front-styles.js.map +1 -1
- package/dist/report-levels.d.ts +37 -4
- package/dist/report-levels.js +127 -8
- package/dist/report-levels.js.map +1 -1
- package/dist/viewer-build.js +2 -2
- package/dist/wording/contract-report-eu-ai-act.en.json +4 -0
- package/dist/wording/contract-report-generic.en.json +460 -0
- package/dist/wording/contract-report-outcomes.en.json +6 -0
- package/dist/wording/history-view.en.json +147 -0
- package/package.json +6 -2
|
@@ -0,0 +1,940 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* The History view (docs/design/history-view.md, capsule-viewer#247): one
|
|
4
|
+
* History page for Muse's private History, the mesh-llm console's saved
|
|
5
|
+
* History page and the Goose History card, on the actionstate-muse#203
|
|
6
|
+
* anatomy.
|
|
7
|
+
*
|
|
8
|
+
* The view draws; it never fetches and never verifies. Its caller passes a
|
|
9
|
+
* `history-view/v0` object built from what the caller itself checked, and
|
|
10
|
+
* the view decides the layout, the words and which slots may fill. Unknown
|
|
11
|
+
* members are refused, so a caller cannot pass words or a "filled" flag.
|
|
12
|
+
*
|
|
13
|
+
* The page is built once as an element tree and written two ways: as HTML
|
|
14
|
+
* text (`historyViewHtml`, for static pages) and as DOM (`renderHistoryView`,
|
|
15
|
+
* for scripted pages), so both are the same page. Caller text is only ever
|
|
16
|
+
* text: it never goes in an attribute and is never parsed as HTML.
|
|
17
|
+
*/
|
|
18
|
+
import PACK from "./wording/history-view.en.json" with { type: "json" };
|
|
19
|
+
export const HISTORY_VIEW = "history-view/v0";
|
|
20
|
+
/** The view's check ids (design note §3). Words for each are `check.<id>`. */
|
|
21
|
+
export const HISTORY_CHECK_IDS = [
|
|
22
|
+
"readable",
|
|
23
|
+
"refusal",
|
|
24
|
+
"artifact_digest",
|
|
25
|
+
"card_digest",
|
|
26
|
+
"checkpoint_signatures",
|
|
27
|
+
"checkpoint_chain",
|
|
28
|
+
"consistency",
|
|
29
|
+
"anchor",
|
|
30
|
+
"period_counts",
|
|
31
|
+
"envelope_signature",
|
|
32
|
+
"key_is_node",
|
|
33
|
+
"reply_bound",
|
|
34
|
+
"witness",
|
|
35
|
+
"second_signature",
|
|
36
|
+
"deal_report",
|
|
37
|
+
];
|
|
38
|
+
/** Checks whose failure is drawn in its chip or row slot, never as the page's verdict. */
|
|
39
|
+
const SLOT_CHECKS = new Set([
|
|
40
|
+
"witness",
|
|
41
|
+
"second_signature",
|
|
42
|
+
]);
|
|
43
|
+
const BASE = PACK.entries;
|
|
44
|
+
/** The view's wording pack, as shipped (neutral words only). */
|
|
45
|
+
export const HISTORY_VIEW_WORDING = PACK;
|
|
46
|
+
/** A refused input: every reason the view found. */
|
|
47
|
+
export class HistoryViewRefused extends Error {
|
|
48
|
+
reasons;
|
|
49
|
+
constructor(reasons) {
|
|
50
|
+
super(`history-view refused: ${reasons.join("; ")}`);
|
|
51
|
+
this.name = "HistoryViewRefused";
|
|
52
|
+
this.reasons = reasons;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const TOKEN = /^[a-z0-9 _.-]*$/u;
|
|
56
|
+
function el(tag, attrs, ...children) {
|
|
57
|
+
const pairs = Object.entries(attrs ?? {});
|
|
58
|
+
for (const [name, value] of pairs)
|
|
59
|
+
if (!TOKEN.test(name) || !TOKEN.test(value))
|
|
60
|
+
throw new Error(`history-view: attribute ${name}=${value} is not a view token`);
|
|
61
|
+
return {
|
|
62
|
+
tag,
|
|
63
|
+
attrs: pairs,
|
|
64
|
+
children: children.filter((c) => c !== null && c !== false),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function escapeText(text) {
|
|
68
|
+
return text.replace(/[&<> ]/gu, (c) => c === "&" ? "&" : c === "<" ? "<" : c === ">" ? ">" : " ");
|
|
69
|
+
}
|
|
70
|
+
/** The tree as HTML, by the HTML fragment serialization rules. */
|
|
71
|
+
export function serializeHistoryElement(node) {
|
|
72
|
+
if (typeof node === "string")
|
|
73
|
+
return escapeText(node);
|
|
74
|
+
const attrs = node.attrs.map(([n, v]) => ` ${n}="${v}"`).join("");
|
|
75
|
+
return `<${node.tag}${attrs}>${node.children.map(serializeHistoryElement).join("")}</${node.tag}>`;
|
|
76
|
+
}
|
|
77
|
+
/** The tree as DOM, text set as text nodes only. */
|
|
78
|
+
export function historyElementToDom(node, doc) {
|
|
79
|
+
if (typeof node === "string")
|
|
80
|
+
return doc.createTextNode(node);
|
|
81
|
+
const out = doc.createElement(node.tag);
|
|
82
|
+
for (const [n, v] of node.attrs)
|
|
83
|
+
out.setAttribute(n, v);
|
|
84
|
+
for (const child of node.children)
|
|
85
|
+
out.appendChild(historyElementToDom(child, doc));
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
class Reader {
|
|
89
|
+
reasons = [];
|
|
90
|
+
refuse(path, why) {
|
|
91
|
+
this.reasons.push(`${path}: ${why}`);
|
|
92
|
+
}
|
|
93
|
+
object(v, path, allowed, required) {
|
|
94
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) {
|
|
95
|
+
this.refuse(path, "is not an object");
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const o = v;
|
|
99
|
+
for (const k of Object.keys(o))
|
|
100
|
+
if (!allowed.includes(k))
|
|
101
|
+
this.refuse(`${path}.${k}`, "is not a member of history-view/v0");
|
|
102
|
+
for (const k of required)
|
|
103
|
+
if (!(k in o))
|
|
104
|
+
this.refuse(`${path}.${k}`, "is missing");
|
|
105
|
+
return o;
|
|
106
|
+
}
|
|
107
|
+
string(v, path, max = 2000) {
|
|
108
|
+
if (typeof v !== "string" || v.length === 0 || v.length > max) {
|
|
109
|
+
this.refuse(path, `is not a string of 1 to ${max} characters`);
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
return v;
|
|
113
|
+
}
|
|
114
|
+
oneOf(v, path, values) {
|
|
115
|
+
if (typeof v !== "string" || !values.includes(v)) {
|
|
116
|
+
this.refuse(path, `is not one of ${values.join(", ")}`);
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
return v;
|
|
120
|
+
}
|
|
121
|
+
bool(v, path) {
|
|
122
|
+
if (typeof v !== "boolean") {
|
|
123
|
+
this.refuse(path, "is not true or false");
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
return v;
|
|
127
|
+
}
|
|
128
|
+
count(v, path) {
|
|
129
|
+
if (typeof v !== "number" || !Number.isSafeInteger(v) || v < 0) {
|
|
130
|
+
this.refuse(path, "is not a whole number of 0 or more");
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
return v;
|
|
134
|
+
}
|
|
135
|
+
time(v, path) {
|
|
136
|
+
const s = this.string(v, path, 64);
|
|
137
|
+
if (s === undefined)
|
|
138
|
+
return undefined;
|
|
139
|
+
const t = parseInstant(s);
|
|
140
|
+
if (t === undefined)
|
|
141
|
+
this.refuse(path, "is not an RFC 3339 time");
|
|
142
|
+
return t;
|
|
143
|
+
}
|
|
144
|
+
date(v, path) {
|
|
145
|
+
const s = this.string(v, path, 64);
|
|
146
|
+
if (s === undefined)
|
|
147
|
+
return undefined;
|
|
148
|
+
const t = /^\d{4}-\d{2}-\d{2}$/u.test(s)
|
|
149
|
+
? parseInstant(`${s}T00:00:00Z`)
|
|
150
|
+
: parseInstant(s);
|
|
151
|
+
if (t === undefined)
|
|
152
|
+
this.refuse(path, "is not a date (YYYY-MM-DD) or an RFC 3339 time");
|
|
153
|
+
return t;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function parseInstant(s) {
|
|
157
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?([Zz]|[+-]\d{2}:\d{2})$/u.exec(s);
|
|
158
|
+
if (!m)
|
|
159
|
+
return undefined;
|
|
160
|
+
const [, y, mo, d, h, mi, se, frac = "", zone = "Z"] = m;
|
|
161
|
+
const month = Number(mo);
|
|
162
|
+
const day = Number(d);
|
|
163
|
+
if (month < 1 ||
|
|
164
|
+
month > 12 ||
|
|
165
|
+
day < 1 ||
|
|
166
|
+
day > 31 ||
|
|
167
|
+
Number(h) > 23 ||
|
|
168
|
+
Number(mi) > 59 ||
|
|
169
|
+
Number(se) > 59)
|
|
170
|
+
return undefined;
|
|
171
|
+
let ms = Date.UTC(Number(y), month - 1, day, Number(h), Number(mi), Number(se));
|
|
172
|
+
if (new Date(ms).getUTCDate() !== day)
|
|
173
|
+
return undefined;
|
|
174
|
+
if (zone !== "Z" && zone !== "z") {
|
|
175
|
+
const sign = zone.startsWith("-") ? -1 : 1;
|
|
176
|
+
ms -=
|
|
177
|
+
sign *
|
|
178
|
+
(Number(zone.slice(1, 3)) * 60 + Number(zone.slice(4, 6))) *
|
|
179
|
+
60_000;
|
|
180
|
+
}
|
|
181
|
+
return { ms, fraction: frac };
|
|
182
|
+
}
|
|
183
|
+
const MONTHS = [
|
|
184
|
+
"Jan",
|
|
185
|
+
"Feb",
|
|
186
|
+
"Mar",
|
|
187
|
+
"Apr",
|
|
188
|
+
"May",
|
|
189
|
+
"Jun",
|
|
190
|
+
"Jul",
|
|
191
|
+
"Aug",
|
|
192
|
+
"Sep",
|
|
193
|
+
"Oct",
|
|
194
|
+
"Nov",
|
|
195
|
+
"Dec",
|
|
196
|
+
];
|
|
197
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
198
|
+
function dateOf(t) {
|
|
199
|
+
const d = new Date(t.ms);
|
|
200
|
+
return `${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}, ${d.getUTCFullYear()}`;
|
|
201
|
+
}
|
|
202
|
+
function minuteOf(t) {
|
|
203
|
+
const d = new Date(t.ms);
|
|
204
|
+
return `${dateOf(t)}, ${two(d.getUTCHours())}:${two(d.getUTCMinutes())} UTC`;
|
|
205
|
+
}
|
|
206
|
+
function shortMinuteOf(t) {
|
|
207
|
+
const d = new Date(t.ms);
|
|
208
|
+
return `${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}, ${two(d.getUTCHours())}:${two(d.getUTCMinutes())} UTC`;
|
|
209
|
+
}
|
|
210
|
+
function secondOf(t, withFraction) {
|
|
211
|
+
const d = new Date(t.ms);
|
|
212
|
+
const frac = withFraction && t.fraction ? `.${t.fraction}` : "";
|
|
213
|
+
return `${dateOf(t)}, ${two(d.getUTCHours())}:${two(d.getUTCMinutes())}:${two(d.getUTCSeconds())}${frac} UTC`;
|
|
214
|
+
}
|
|
215
|
+
const PLACEHOLDER = /\{([a-z_]+)\}/gu;
|
|
216
|
+
function placeholders(text) {
|
|
217
|
+
return [...text.matchAll(PLACEHOLDER)].map((m) => m[1] ?? "").sort();
|
|
218
|
+
}
|
|
219
|
+
function readOverlay(r, v) {
|
|
220
|
+
const o = r.object(v, "overlay", ["id", "entries"], ["id", "entries"]);
|
|
221
|
+
if (!o)
|
|
222
|
+
return {};
|
|
223
|
+
r.string(o["id"], "overlay.id", 200);
|
|
224
|
+
const e = r.object(o["entries"], "overlay.entries", Object.keys(BASE), []);
|
|
225
|
+
const out = {};
|
|
226
|
+
if (!e)
|
|
227
|
+
return out;
|
|
228
|
+
for (const [k, text] of Object.entries(e)) {
|
|
229
|
+
const base = BASE[k];
|
|
230
|
+
const s = r.string(text, `overlay.entries.${k}`);
|
|
231
|
+
if (base === undefined || s === undefined)
|
|
232
|
+
continue;
|
|
233
|
+
if (placeholders(base).join(",") !== placeholders(s).join(","))
|
|
234
|
+
r.refuse(`overlay.entries.${k}`, `must use the placeholders ${JSON.stringify(placeholders(base))}`);
|
|
235
|
+
else
|
|
236
|
+
out[k] = s;
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
function readSlot(r, v, path, needBy) {
|
|
241
|
+
const o = r.object(v, path, ["state", "by", "at", "through"], ["state"]);
|
|
242
|
+
const state = o
|
|
243
|
+
? (r.oneOf(o["state"], `${path}.state`, [
|
|
244
|
+
"passed",
|
|
245
|
+
"failed",
|
|
246
|
+
"none",
|
|
247
|
+
"not_checked",
|
|
248
|
+
]) ?? "not_checked")
|
|
249
|
+
: "not_checked";
|
|
250
|
+
const by = o && "by" in o ? r.string(o["by"], `${path}.by`, 200) : undefined;
|
|
251
|
+
const at = o && "at" in o ? r.time(o["at"], `${path}.at`) : undefined;
|
|
252
|
+
let through;
|
|
253
|
+
if (o && "through" in o) {
|
|
254
|
+
const t = r.object(o["through"], `${path}.through`, ["k", "n"], ["k", "n"]);
|
|
255
|
+
const k = t ? r.count(t["k"], `${path}.through.k`) : undefined;
|
|
256
|
+
const n = t ? r.count(t["n"], `${path}.through.n`) : undefined;
|
|
257
|
+
if (k !== undefined && n !== undefined) {
|
|
258
|
+
if (k > n || n === 0)
|
|
259
|
+
r.refuse(`${path}.through`, "k must be at most n, and n more than 0");
|
|
260
|
+
else
|
|
261
|
+
through = { k, n };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (state === "passed") {
|
|
265
|
+
if (!o || !("at" in o))
|
|
266
|
+
r.refuse(path, "a passed slot needs at");
|
|
267
|
+
if (needBy && !(o && "by" in o))
|
|
268
|
+
r.refuse(path, "a passed second-signature slot needs by");
|
|
269
|
+
}
|
|
270
|
+
return { state, by, at, through };
|
|
271
|
+
}
|
|
272
|
+
const EPOCH = { ms: 0, fraction: "" };
|
|
273
|
+
function readRow(r, v, path, kind) {
|
|
274
|
+
if (kind === "checkpoint") {
|
|
275
|
+
const o = r.object(v, path, [
|
|
276
|
+
"kind",
|
|
277
|
+
"cut_at",
|
|
278
|
+
"log_size",
|
|
279
|
+
"anchor",
|
|
280
|
+
"signature",
|
|
281
|
+
"witness",
|
|
282
|
+
"second_signature",
|
|
283
|
+
], [
|
|
284
|
+
"kind",
|
|
285
|
+
"cut_at",
|
|
286
|
+
"log_size",
|
|
287
|
+
"anchor",
|
|
288
|
+
"signature",
|
|
289
|
+
"witness",
|
|
290
|
+
"second_signature",
|
|
291
|
+
]);
|
|
292
|
+
if (!o)
|
|
293
|
+
return undefined;
|
|
294
|
+
if (o["kind"] !== "checkpoint")
|
|
295
|
+
r.refuse(`${path}.kind`, "must be the page's kind, checkpoint");
|
|
296
|
+
return {
|
|
297
|
+
kind,
|
|
298
|
+
cut: r.time(o["cut_at"], `${path}.cut_at`) ?? EPOCH,
|
|
299
|
+
logSize: r.count(o["log_size"], `${path}.log_size`) ?? 0,
|
|
300
|
+
anchor: r.string(o["anchor"], `${path}.anchor`, 200) ?? "",
|
|
301
|
+
signature: r.oneOf(o["signature"], `${path}.signature`, [
|
|
302
|
+
"pass",
|
|
303
|
+
"fail",
|
|
304
|
+
"not_run",
|
|
305
|
+
]) ?? "not_run",
|
|
306
|
+
witness: readSlot(r, o["witness"], `${path}.witness`, false),
|
|
307
|
+
second: readSlot(r, o["second_signature"], `${path}.second_signature`, true),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
const o = r.object(v, path, [
|
|
311
|
+
"kind",
|
|
312
|
+
"asked",
|
|
313
|
+
"outcome",
|
|
314
|
+
"money",
|
|
315
|
+
"opened_at",
|
|
316
|
+
"last_at",
|
|
317
|
+
"record",
|
|
318
|
+
"witness",
|
|
319
|
+
"second_signature",
|
|
320
|
+
], [
|
|
321
|
+
"kind",
|
|
322
|
+
"asked",
|
|
323
|
+
"outcome",
|
|
324
|
+
"opened_at",
|
|
325
|
+
"last_at",
|
|
326
|
+
"record",
|
|
327
|
+
"witness",
|
|
328
|
+
"second_signature",
|
|
329
|
+
]);
|
|
330
|
+
if (!o)
|
|
331
|
+
return undefined;
|
|
332
|
+
if (o["kind"] !== "deal")
|
|
333
|
+
r.refuse(`${path}.kind`, "must be the page's kind, deal");
|
|
334
|
+
return {
|
|
335
|
+
kind,
|
|
336
|
+
asked: r.string(o["asked"], `${path}.asked`) ?? "",
|
|
337
|
+
outcome: r.string(o["outcome"], `${path}.outcome`, 200) ?? "",
|
|
338
|
+
money: "money" in o ? r.string(o["money"], `${path}.money`, 200) : undefined,
|
|
339
|
+
opened: r.time(o["opened_at"], `${path}.opened_at`) ?? EPOCH,
|
|
340
|
+
last: r.time(o["last_at"], `${path}.last_at`) ?? EPOCH,
|
|
341
|
+
record: r.string(o["record"], `${path}.record`, 200) ?? "",
|
|
342
|
+
witness: readSlot(r, o["witness"], `${path}.witness`, false),
|
|
343
|
+
second: readSlot(r, o["second_signature"], `${path}.second_signature`, true),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
// --- the page --------------------------------------------------------------
|
|
347
|
+
const TOP = [
|
|
348
|
+
"view",
|
|
349
|
+
"kind",
|
|
350
|
+
"surface",
|
|
351
|
+
"reader",
|
|
352
|
+
"holder",
|
|
353
|
+
"audience",
|
|
354
|
+
"built_at",
|
|
355
|
+
"checked",
|
|
356
|
+
"outcome",
|
|
357
|
+
"picked",
|
|
358
|
+
"rows",
|
|
359
|
+
"checks",
|
|
360
|
+
"periods",
|
|
361
|
+
"sharing",
|
|
362
|
+
"signer_directory",
|
|
363
|
+
"period",
|
|
364
|
+
];
|
|
365
|
+
/**
|
|
366
|
+
* The History view's element tree for `input`, or every reason it is
|
|
367
|
+
* refused. `overlay` is a product caller's words (surface `product` only).
|
|
368
|
+
*/
|
|
369
|
+
export function buildHistoryView(input, overlay) {
|
|
370
|
+
const r = new Reader();
|
|
371
|
+
const o = r.object(input, "input", TOP, [
|
|
372
|
+
"view",
|
|
373
|
+
"kind",
|
|
374
|
+
"surface",
|
|
375
|
+
"reader",
|
|
376
|
+
"holder",
|
|
377
|
+
"audience",
|
|
378
|
+
"built_at",
|
|
379
|
+
"checked",
|
|
380
|
+
"rows",
|
|
381
|
+
"checks",
|
|
382
|
+
]);
|
|
383
|
+
if (!o)
|
|
384
|
+
return { ok: false, reasons: r.reasons };
|
|
385
|
+
if (o["view"] !== HISTORY_VIEW)
|
|
386
|
+
r.refuse("input.view", `is not ${HISTORY_VIEW}`);
|
|
387
|
+
const kind = r.oneOf(o["kind"], "input.kind", ["checkpoint", "deal"]) ??
|
|
388
|
+
"checkpoint";
|
|
389
|
+
const surface = r.oneOf(o["surface"], "input.surface", ["neutral", "product"]) ??
|
|
390
|
+
"neutral";
|
|
391
|
+
const reader = r.oneOf(o["reader"], "input.reader", ["owner", "recipient"]) ??
|
|
392
|
+
"recipient";
|
|
393
|
+
let words = {};
|
|
394
|
+
if (overlay !== undefined) {
|
|
395
|
+
if (surface !== "product")
|
|
396
|
+
r.refuse("overlay", "a neutral page takes no overlay");
|
|
397
|
+
else
|
|
398
|
+
words = readOverlay(r, overlay);
|
|
399
|
+
}
|
|
400
|
+
const ho = r.object(o["holder"], "input.holder", ["node", "name", "stream"], []);
|
|
401
|
+
const node = ho && "node" in ho
|
|
402
|
+
? r.string(ho["node"], "input.holder.node", 200)
|
|
403
|
+
: undefined;
|
|
404
|
+
const name = ho && "name" in ho
|
|
405
|
+
? r.string(ho["name"], "input.holder.name", 200)
|
|
406
|
+
: undefined;
|
|
407
|
+
const stream = ho && "stream" in ho
|
|
408
|
+
? r.string(ho["stream"], "input.holder.stream", 200)
|
|
409
|
+
: undefined;
|
|
410
|
+
if (kind === "checkpoint" && node === undefined && ho)
|
|
411
|
+
r.refuse("input.holder.node", "is missing (a checkpoint page names its node)");
|
|
412
|
+
const au = r.object(o["audience"], "input.audience", ["kind", "for"], ["kind"]);
|
|
413
|
+
const audienceKind = au
|
|
414
|
+
? (r.oneOf(au["kind"], "input.audience.kind", [
|
|
415
|
+
"private",
|
|
416
|
+
"shared",
|
|
417
|
+
"anyone",
|
|
418
|
+
]) ?? "anyone")
|
|
419
|
+
: "anyone";
|
|
420
|
+
const audienceFor = audienceKind === "shared" && au
|
|
421
|
+
? r.string(au["for"], "input.audience.for", 200)
|
|
422
|
+
: undefined;
|
|
423
|
+
if (audienceKind !== "shared" && au && "for" in au)
|
|
424
|
+
r.refuse("input.audience.for", "is only for a shared audience");
|
|
425
|
+
const built = r.time(o["built_at"], "input.built_at") ?? EPOCH;
|
|
426
|
+
const ck = r.object(o["checked"], "input.checked", ["where", "by"], ["where", "by"]);
|
|
427
|
+
const where = ck
|
|
428
|
+
? (r.oneOf(ck["where"], "input.checked.where", [
|
|
429
|
+
"page",
|
|
430
|
+
"builder",
|
|
431
|
+
]) ?? "builder")
|
|
432
|
+
: "builder";
|
|
433
|
+
const checkedBy = ck
|
|
434
|
+
? (r.string(ck["by"], "input.checked.by", 200) ?? "")
|
|
435
|
+
: "";
|
|
436
|
+
let outcome = "answered";
|
|
437
|
+
let refusedReason;
|
|
438
|
+
if ("outcome" in o) {
|
|
439
|
+
if (kind !== "checkpoint")
|
|
440
|
+
r.refuse("input.outcome", "is only for a checkpoint page");
|
|
441
|
+
const oc = r.object(o["outcome"], "input.outcome", ["kind", "reason"], ["kind"]);
|
|
442
|
+
if (oc) {
|
|
443
|
+
outcome =
|
|
444
|
+
r.oneOf(oc["kind"], "input.outcome.kind", [
|
|
445
|
+
"answered",
|
|
446
|
+
"refused",
|
|
447
|
+
"unreadable",
|
|
448
|
+
]) ?? "answered";
|
|
449
|
+
if (outcome === "refused")
|
|
450
|
+
refusedReason = r.string(oc["reason"], "input.outcome.reason", 200);
|
|
451
|
+
else if ("reason" in oc)
|
|
452
|
+
r.refuse("input.outcome.reason", "is only for a refused answer");
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const picked = "picked" in o ? r.bool(o["picked"], "input.picked") === true : false;
|
|
456
|
+
if (picked && kind !== "deal")
|
|
457
|
+
r.refuse("input.picked", "is only for a deal page");
|
|
458
|
+
if (kind === "deal" && reader === "recipient" && name === undefined)
|
|
459
|
+
r.refuse("input.holder.name", "is missing (a deal page shown to someone else names whose it is)");
|
|
460
|
+
else if (picked && name === undefined)
|
|
461
|
+
r.refuse("input.holder.name", "is missing (a picked selection names who picked it)");
|
|
462
|
+
const rows = [];
|
|
463
|
+
if (Array.isArray(o["rows"])) {
|
|
464
|
+
if (o["rows"].length > 10_000)
|
|
465
|
+
r.refuse("input.rows", "has more than 10000 rows");
|
|
466
|
+
o["rows"].forEach((row, i) => {
|
|
467
|
+
const read = readRow(r, row, `input.rows[${i}]`, kind);
|
|
468
|
+
if (read)
|
|
469
|
+
rows.push(read);
|
|
470
|
+
});
|
|
471
|
+
if (outcome !== "answered" && o["rows"].length > 0)
|
|
472
|
+
r.refuse("input.rows", "must be empty unless the node answered");
|
|
473
|
+
}
|
|
474
|
+
else
|
|
475
|
+
r.refuse("input.rows", "is not a list");
|
|
476
|
+
const checks = [];
|
|
477
|
+
if (Array.isArray(o["checks"])) {
|
|
478
|
+
o["checks"].forEach((c, i) => {
|
|
479
|
+
const path = `input.checks[${i}]`;
|
|
480
|
+
const co = r.object(c, path, ["id", "status", "values"], ["id", "status"]);
|
|
481
|
+
if (!co)
|
|
482
|
+
return;
|
|
483
|
+
const id = r.oneOf(co["id"], `${path}.id`, HISTORY_CHECK_IDS);
|
|
484
|
+
const status = r.oneOf(co["status"], `${path}.status`, [
|
|
485
|
+
"pass",
|
|
486
|
+
"fail",
|
|
487
|
+
"not_run",
|
|
488
|
+
]);
|
|
489
|
+
if ("values" in co) {
|
|
490
|
+
const vo = r.object(co["values"], `${path}.values`, [], []);
|
|
491
|
+
if (vo && Object.keys(vo).length > 0)
|
|
492
|
+
r.refuse(`${path}.values`, "names a placeholder the check's words do not have");
|
|
493
|
+
}
|
|
494
|
+
if (id && checks.some((x) => x.id === id))
|
|
495
|
+
r.refuse(`${path}.id`, "is listed twice");
|
|
496
|
+
if (id && status)
|
|
497
|
+
checks.push({ id, status });
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
else
|
|
501
|
+
r.refuse("input.checks", "is not a list");
|
|
502
|
+
const periods = [];
|
|
503
|
+
if ("periods" in o) {
|
|
504
|
+
if (kind !== "checkpoint")
|
|
505
|
+
r.refuse("input.periods", "is only for a checkpoint page");
|
|
506
|
+
if (Array.isArray(o["periods"]))
|
|
507
|
+
o["periods"].forEach((p, i) => {
|
|
508
|
+
const path = `input.periods[${i}]`;
|
|
509
|
+
const po = r.object(p, path, ["from", "to", "cells"], ["from", "to", "cells"]);
|
|
510
|
+
if (!po)
|
|
511
|
+
return;
|
|
512
|
+
const from = r.date(po["from"], `${path}.from`);
|
|
513
|
+
const to = r.date(po["to"], `${path}.to`);
|
|
514
|
+
const cells = [];
|
|
515
|
+
if (Array.isArray(po["cells"]))
|
|
516
|
+
po["cells"].forEach((c, j) => {
|
|
517
|
+
const co = r.object(c, `${path}.cells[${j}]`, ["what", "value", "withheld"], ["what"]);
|
|
518
|
+
const what = co
|
|
519
|
+
? r.string(co["what"], `${path}.cells[${j}].what`, 200)
|
|
520
|
+
: undefined;
|
|
521
|
+
const withheld = co !== null && "withheld" in co;
|
|
522
|
+
if (withheld && co["withheld"] !== true)
|
|
523
|
+
r.refuse(`${path}.cells[${j}].withheld`, "is not true");
|
|
524
|
+
if (co && withheld === "value" in co)
|
|
525
|
+
r.refuse(`${path}.cells[${j}]`, "carries either a value or withheld: true");
|
|
526
|
+
const value = co && "value" in co
|
|
527
|
+
? r.string(co["value"], `${path}.cells[${j}].value`, 40)
|
|
528
|
+
: undefined;
|
|
529
|
+
if (what !== undefined)
|
|
530
|
+
cells.push({ what, value });
|
|
531
|
+
});
|
|
532
|
+
else
|
|
533
|
+
r.refuse(`${path}.cells`, "is not a list");
|
|
534
|
+
if (from && to)
|
|
535
|
+
periods.push({ from, to, cells });
|
|
536
|
+
});
|
|
537
|
+
else
|
|
538
|
+
r.refuse("input.periods", "is not a list");
|
|
539
|
+
}
|
|
540
|
+
let sharing;
|
|
541
|
+
if (kind === "checkpoint" && !("sharing" in o))
|
|
542
|
+
r.refuse("input.sharing", "is missing (a checkpoint page says what its node shares)");
|
|
543
|
+
if ("sharing" in o) {
|
|
544
|
+
if (kind !== "checkpoint")
|
|
545
|
+
r.refuse("input.sharing", "is only for a checkpoint page");
|
|
546
|
+
const keys = [
|
|
547
|
+
"standard_history",
|
|
548
|
+
"history_segments",
|
|
549
|
+
"record_at_completion",
|
|
550
|
+
"adjudications",
|
|
551
|
+
"exchange_corroboration",
|
|
552
|
+
"adjudicate_differing_twins",
|
|
553
|
+
"witnesses",
|
|
554
|
+
];
|
|
555
|
+
const so = r.object(o["sharing"], "input.sharing", keys, keys.slice(0, 5));
|
|
556
|
+
if (so) {
|
|
557
|
+
let witnesses;
|
|
558
|
+
if ("witnesses" in so) {
|
|
559
|
+
witnesses = [];
|
|
560
|
+
if (Array.isArray(so["witnesses"]))
|
|
561
|
+
for (const [i, w] of so["witnesses"].entries()) {
|
|
562
|
+
const s = r.string(w, `input.sharing.witnesses[${i}]`, 300);
|
|
563
|
+
if (s !== undefined)
|
|
564
|
+
witnesses.push(s);
|
|
565
|
+
}
|
|
566
|
+
else
|
|
567
|
+
r.refuse("input.sharing.witnesses", "is not a list");
|
|
568
|
+
}
|
|
569
|
+
const twins = "adjudicate_differing_twins" in so
|
|
570
|
+
? r.bool(so["adjudicate_differing_twins"], "input.sharing.adjudicate_differing_twins")
|
|
571
|
+
: undefined;
|
|
572
|
+
const s = {
|
|
573
|
+
standard_history: r.bool(so["standard_history"], "input.sharing.standard_history"),
|
|
574
|
+
history_segments: r.oneOf(so["history_segments"], "input.sharing.history_segments", ["off", "counterparties", "peers"]),
|
|
575
|
+
record_at_completion: r.oneOf(so["record_at_completion"], "input.sharing.record_at_completion", ["counterparty", "off"]),
|
|
576
|
+
adjudications: r.oneOf(so["adjudications"], "input.sharing.adjudications", ["deliver_to_subjects", "off"]),
|
|
577
|
+
exchange_corroboration: r.bool(so["exchange_corroboration"], "input.sharing.exchange_corroboration"),
|
|
578
|
+
};
|
|
579
|
+
if (Object.values(s).every((x) => x !== undefined))
|
|
580
|
+
sharing = {
|
|
581
|
+
...s,
|
|
582
|
+
...(twins !== undefined ? { adjudicate_differing_twins: twins } : {}),
|
|
583
|
+
...(witnesses !== undefined ? { witnesses } : {}),
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
let directory;
|
|
588
|
+
if ("signer_directory" in o) {
|
|
589
|
+
if (kind !== "deal")
|
|
590
|
+
r.refuse("input.signer_directory", "is only for a deal page");
|
|
591
|
+
directory = r.string(o["signer_directory"], "input.signer_directory", 300);
|
|
592
|
+
if (directory !== undefined && !directory.startsWith("https://"))
|
|
593
|
+
r.refuse("input.signer_directory", "is not an https:// address");
|
|
594
|
+
}
|
|
595
|
+
let period;
|
|
596
|
+
if ("period" in o) {
|
|
597
|
+
const po = r.object(o["period"], "input.period", ["from", "to"], ["from", "to"]);
|
|
598
|
+
const from = po ? r.date(po["from"], "input.period.from") : undefined;
|
|
599
|
+
const to = po ? r.date(po["to"], "input.period.to") : undefined;
|
|
600
|
+
if (from && to)
|
|
601
|
+
period = { from, to };
|
|
602
|
+
}
|
|
603
|
+
if (r.reasons.length > 0)
|
|
604
|
+
return { ok: false, reasons: r.reasons };
|
|
605
|
+
const say = (key, values = {}) => {
|
|
606
|
+
const text = words[key] ?? BASE[key];
|
|
607
|
+
if (text === undefined)
|
|
608
|
+
throw new Error(`history-view: no words for ${key}`);
|
|
609
|
+
return text.replace(PLACEHOLDER, (_, p) => {
|
|
610
|
+
const v = values[p];
|
|
611
|
+
if (v === undefined)
|
|
612
|
+
throw new Error(`history-view: ${key} needs {${p}}`);
|
|
613
|
+
return v;
|
|
614
|
+
});
|
|
615
|
+
};
|
|
616
|
+
const plural = (key, n, values = {}) => say(`${key}.${n === 1 ? "one" : "other"}`, { n: String(n), ...values });
|
|
617
|
+
const short = (id) => (id.length > 12 ? id.slice(0, 12) : id);
|
|
618
|
+
// One verdict for the page (design note §4).
|
|
619
|
+
const failedCheck = checks.some((c) => c.status === "fail" && !SLOT_CHECKS.has(c.id));
|
|
620
|
+
const failedRow = rows.some((x) => x.kind === "checkpoint" && x.signature === "fail");
|
|
621
|
+
const failed = failedCheck || failedRow;
|
|
622
|
+
const allPass = rows.length > 0 &&
|
|
623
|
+
rows.every((x) => x.kind !== "checkpoint" || x.signature === "pass") &&
|
|
624
|
+
checks
|
|
625
|
+
.filter((c) => !SLOT_CHECKS.has(c.id) && c.status !== "not_run")
|
|
626
|
+
.every((c) => c.status === "pass") &&
|
|
627
|
+
(kind === "deal" ||
|
|
628
|
+
checks.some((c) => c.id === "checkpoint_signatures" && c.status === "pass"));
|
|
629
|
+
// "Every signature" only when the answer's own signature and the node's key
|
|
630
|
+
// were checked too; otherwise the verdict names only what passed.
|
|
631
|
+
const passed = (id) => checks.some((c) => c.id === id && c.status === "pass");
|
|
632
|
+
const everySignature = allPass && passed("envelope_signature") && passed("key_is_node");
|
|
633
|
+
const verdictKey = everySignature ? "verdict.pass.all" : "verdict.pass";
|
|
634
|
+
const chipKey = everySignature
|
|
635
|
+
? "chip.signatures.pass.all"
|
|
636
|
+
: "chip.signatures.pass";
|
|
637
|
+
const statusOf = (id) => checks.find((c) => c.id === id)?.status;
|
|
638
|
+
const dealRecorded = statusOf("deal_report") === "pass";
|
|
639
|
+
const witnessFailed = statusOf("witness") === "fail";
|
|
640
|
+
const secondFailed = statusOf("second_signature") === "fail";
|
|
641
|
+
// The seal's first lines say how the records are locked; only checks that
|
|
642
|
+
// passed may say it.
|
|
643
|
+
const lockChecked = kind === "checkpoint"
|
|
644
|
+
? statusOf("checkpoint_signatures") === "pass" &&
|
|
645
|
+
statusOf("checkpoint_chain") === "pass" &&
|
|
646
|
+
statusOf("consistency") === "pass"
|
|
647
|
+
: dealRecorded;
|
|
648
|
+
// Header.
|
|
649
|
+
let title;
|
|
650
|
+
if (kind === "checkpoint")
|
|
651
|
+
title =
|
|
652
|
+
stream !== undefined
|
|
653
|
+
? say("header.title.stream", { node: short(node ?? ""), stream })
|
|
654
|
+
: say("header.title.node", { node: short(node ?? "") });
|
|
655
|
+
else if (reader === "owner")
|
|
656
|
+
title = say("header.title.owner");
|
|
657
|
+
else
|
|
658
|
+
title =
|
|
659
|
+
audienceKind === "shared"
|
|
660
|
+
? say("header.title.shared", { name: name ?? "" })
|
|
661
|
+
: say("header.title.person", { name: name ?? "" });
|
|
662
|
+
const badge = audienceKind === "private"
|
|
663
|
+
? say("badge.private")
|
|
664
|
+
: audienceKind === "shared"
|
|
665
|
+
? say("badge.shared", { who: audienceFor ?? "" })
|
|
666
|
+
: say("badge.anyone");
|
|
667
|
+
const header = el("header", { class: "cvh-header", "data-history": "header" }, el("h1", { class: "cvh-title" }, title), node !== undefined
|
|
668
|
+
? el("details", { class: "cvh-proof" }, el("summary", null, say("proof.node", { id: short(node) })), el("code", null, node))
|
|
669
|
+
: null, period
|
|
670
|
+
? el("p", { class: "cvh-scope" }, say("scope.period", {
|
|
671
|
+
from: dateOf(period.from),
|
|
672
|
+
to: dateOf(period.to),
|
|
673
|
+
}))
|
|
674
|
+
: null, el("p", { class: "cvh-badge", "data-audience": audienceKind }, badge), el("p", { class: "cvh-built" }, say(reader === "owner" ? "built.owner" : "built.recipient", {
|
|
675
|
+
at: minuteOf(built),
|
|
676
|
+
})));
|
|
677
|
+
// Hero.
|
|
678
|
+
const heroLines = [];
|
|
679
|
+
let drawRows = false;
|
|
680
|
+
if (outcome === "refused") {
|
|
681
|
+
heroLines.push(say("hero.refused"));
|
|
682
|
+
if (refusedReason !== undefined)
|
|
683
|
+
heroLines.push(say("hero.refused.reason", { reason: refusedReason }));
|
|
684
|
+
}
|
|
685
|
+
else if (outcome === "unreadable")
|
|
686
|
+
heroLines.push(say("hero.unreadable"));
|
|
687
|
+
else if (failed)
|
|
688
|
+
heroLines.push(say("hero.failed"));
|
|
689
|
+
else if (rows.length === 0)
|
|
690
|
+
heroLines.push(say(kind === "checkpoint" ? "hero.none.checkpoints" : "hero.none.deals"));
|
|
691
|
+
else {
|
|
692
|
+
drawRows = true;
|
|
693
|
+
if (kind === "checkpoint") {
|
|
694
|
+
const cps = rows;
|
|
695
|
+
const last = cps.reduce((a, b) => (b.cut.ms > a.cut.ms ? b : a));
|
|
696
|
+
const entries = Math.max(...cps.map((c) => c.logSize));
|
|
697
|
+
heroLines.push(plural("hero.checkpoints", cps.length, {
|
|
698
|
+
entries: plural("hero.entries", entries),
|
|
699
|
+
at: shortMinuteOf(last.cut),
|
|
700
|
+
verdict: say(allPass ? verdictKey : "verdict.unchecked"),
|
|
701
|
+
}));
|
|
702
|
+
}
|
|
703
|
+
else
|
|
704
|
+
heroLines.push(picked
|
|
705
|
+
? plural("hero.deals.picked", rows.length, { name: name ?? "" })
|
|
706
|
+
: plural("hero.deals", rows.length));
|
|
707
|
+
}
|
|
708
|
+
const hero = el("section", { class: "cvh-hero", "data-history": "hero" }, ...heroLines.map((line, i) => el("p", { class: i === 0 ? "cvh-hero-line" : "cvh-hero-note" }, line)));
|
|
709
|
+
// Chips.
|
|
710
|
+
let chips = null;
|
|
711
|
+
if (drawRows) {
|
|
712
|
+
const stamped = rows.filter((x) => x.witness.state === "passed").length;
|
|
713
|
+
const stampChip = witnessFailed
|
|
714
|
+
? say("chip.timestamped.failed")
|
|
715
|
+
: stamped === 0 && rows.some((x) => x.witness.state === "not_checked")
|
|
716
|
+
? say("chip.timestamped.unchecked")
|
|
717
|
+
: stamped === 0
|
|
718
|
+
? say("chip.timestamped.none")
|
|
719
|
+
: stamped === rows.length
|
|
720
|
+
? say("chip.timestamped.all", { n: String(rows.length) })
|
|
721
|
+
: say("chip.timestamped.some", {
|
|
722
|
+
k: String(stamped),
|
|
723
|
+
n: String(rows.length),
|
|
724
|
+
});
|
|
725
|
+
const items = [];
|
|
726
|
+
if (kind === "checkpoint") {
|
|
727
|
+
items.push(say(allPass ? chipKey : "chip.signatures.unchecked"), stampChip);
|
|
728
|
+
const first = rows.reduce((a, b) => b.cut.ms < a.cut.ms ? b : a);
|
|
729
|
+
items.push(say("chip.started", { date: dateOf(first.cut) }));
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
if (dealRecorded)
|
|
733
|
+
items.push(say("chip.recorded"));
|
|
734
|
+
items.push(stampChip);
|
|
735
|
+
}
|
|
736
|
+
chips = el("ul", { class: "cvh-chips", "data-history": "chips" }, ...items.map((t) => el("li", { class: "cvh-chip" }, t)));
|
|
737
|
+
}
|
|
738
|
+
// Rows.
|
|
739
|
+
const slotLine = (s, second) => {
|
|
740
|
+
if (s.state === "passed") {
|
|
741
|
+
const at = s.at ? minuteOf(s.at) : "";
|
|
742
|
+
let line = second
|
|
743
|
+
? say("slot.second.by", { by: s.by ?? "", at })
|
|
744
|
+
: s.by !== undefined
|
|
745
|
+
? say("slot.timestamped.by", { at, by: s.by })
|
|
746
|
+
: say("slot.timestamped.at", { at });
|
|
747
|
+
if (s.through && s.through.k < s.through.n)
|
|
748
|
+
line += ` · ${say("slot.part", { k: String(s.through.k), n: String(s.through.n) })}`;
|
|
749
|
+
return line;
|
|
750
|
+
}
|
|
751
|
+
if (s.state === "failed")
|
|
752
|
+
return say("slot.failed");
|
|
753
|
+
if (s.state === "none")
|
|
754
|
+
return say(second ? "slot.second.none" : "slot.timestamped.none");
|
|
755
|
+
return say("slot.unchecked");
|
|
756
|
+
};
|
|
757
|
+
const stamp = (nameKey, filled, state, line) => el("li", {
|
|
758
|
+
class: "cvh-stamp",
|
|
759
|
+
"data-filled": filled ? "yes" : "no",
|
|
760
|
+
"data-state": state,
|
|
761
|
+
}, el("span", { class: "cvh-stamp-name" }, say(nameKey)), line !== null ? el("span", { class: "cvh-stamp-line" }, line) : null);
|
|
762
|
+
const slotStamps = (row) => [
|
|
763
|
+
stamp("stamp.timestamped", row.witness.state === "passed", row.witness.state, slotLine(row.witness, false)),
|
|
764
|
+
stamp("stamp.second", row.second.state === "passed", row.second.state, slotLine(row.second, true)),
|
|
765
|
+
];
|
|
766
|
+
const proof = (key, id) => el("details", { class: "cvh-proof" }, el("summary", null, say(key, { id: short(id) })), el("code", null, id));
|
|
767
|
+
let rowList = null;
|
|
768
|
+
if (drawRows) {
|
|
769
|
+
const seconds = new Map();
|
|
770
|
+
if (kind === "checkpoint")
|
|
771
|
+
for (const x of rows)
|
|
772
|
+
seconds.set(Math.floor(x.cut.ms / 1000), (seconds.get(Math.floor(x.cut.ms / 1000)) ?? 0) + 1);
|
|
773
|
+
const items = rows.map((x) => {
|
|
774
|
+
if (x.kind === "checkpoint") {
|
|
775
|
+
const tie = (seconds.get(Math.floor(x.cut.ms / 1000)) ?? 0) > 1;
|
|
776
|
+
return el("li", { class: "cvh-row", "data-history": "row" }, el("p", { class: "cvh-row-title" }, say("row.cut", { at: secondOf(x.cut, tie) })), el("p", { class: "cvh-row-detail" }, plural("row.entries", x.logSize)), proof("proof.checkpoint", x.anchor), el("ul", { class: "cvh-stamps" }, stamp("stamp.recorded", x.signature === "pass", x.signature, x.signature === "pass" ? null : say("stamp.signature.unchecked")), ...slotStamps(x)));
|
|
777
|
+
}
|
|
778
|
+
const detail = [
|
|
779
|
+
x.outcome,
|
|
780
|
+
...(x.money !== undefined ? [x.money] : []),
|
|
781
|
+
say("row.opened", { at: minuteOf(x.opened) }),
|
|
782
|
+
say("row.last", { at: minuteOf(x.last) }),
|
|
783
|
+
].join(" · ");
|
|
784
|
+
return el("li", { class: "cvh-row", "data-history": "row" }, el("p", { class: "cvh-row-title" }, x.asked), el("p", { class: "cvh-row-detail" }, detail), proof("proof.record", x.record), el("ul", { class: "cvh-stamps" }, dealRecorded
|
|
785
|
+
? stamp("stamp.recorded", true, "passed", null)
|
|
786
|
+
: stamp("stamp.recorded", false, "not_checked", say("slot.unchecked")), ...slotStamps(x)));
|
|
787
|
+
});
|
|
788
|
+
rowList = el("section", { class: "cvh-rows-block" }, el("h2", null, say(kind === "checkpoint"
|
|
789
|
+
? "rows.heading.checkpoints"
|
|
790
|
+
: "rows.heading.deals")), el("ol", { class: "cvh-rows", "data-history": "rows" }, ...items));
|
|
791
|
+
}
|
|
792
|
+
const periodBlock = drawRows && periods.length > 0
|
|
793
|
+
? el("section", { class: "cvh-periods", "data-history": "periods" }, el("h2", null, say("periods.heading")), el("ul", null, ...periods.map((p) => el("li", null, el("p", null, say("periods.row", {
|
|
794
|
+
from: dateOf(p.from),
|
|
795
|
+
to: dateOf(p.to),
|
|
796
|
+
})), el("ul", null, ...p.cells.map((c) => el("li", null, c.value === undefined
|
|
797
|
+
? say("periods.cell.withheld", { what: c.what })
|
|
798
|
+
: say("periods.cell", { what: c.what, value: c.value }))))))))
|
|
799
|
+
: null;
|
|
800
|
+
const callout = outcome === "answered" && !failed
|
|
801
|
+
? el("aside", { class: "cvh-callout", "data-history": "does-not-show" }, el("h2", null, say("callout.heading")), el("p", null, kind === "checkpoint"
|
|
802
|
+
? say("callout.checkpoints")
|
|
803
|
+
: picked
|
|
804
|
+
? say("callout.deals.picked", { name: name ?? "" })
|
|
805
|
+
: say("callout.deals")))
|
|
806
|
+
: null;
|
|
807
|
+
let shares = null;
|
|
808
|
+
if (sharing) {
|
|
809
|
+
const lines = [say("shares.summary")];
|
|
810
|
+
lines.push(say(sharing.standard_history ? "shares.standard.on" : "shares.standard.off"));
|
|
811
|
+
if (sharing.history_segments === "counterparties")
|
|
812
|
+
lines.push(say("shares.segments.counterparties"));
|
|
813
|
+
else if (sharing.history_segments === "peers")
|
|
814
|
+
lines.push(say("shares.segments.peers"));
|
|
815
|
+
else
|
|
816
|
+
lines.push(sharing.record_at_completion === "counterparty"
|
|
817
|
+
? `${say("shares.segments.off")} ${say("shares.segments.off.sealed")}`
|
|
818
|
+
: say("shares.segments.off"));
|
|
819
|
+
if (sharing.exchange_corroboration)
|
|
820
|
+
lines.push(say("shares.corroboration.on"));
|
|
821
|
+
lines.push(say(sharing.record_at_completion === "counterparty"
|
|
822
|
+
? "shares.completion.on"
|
|
823
|
+
: "shares.completion.off"));
|
|
824
|
+
lines.push(say(sharing.adjudications === "deliver_to_subjects"
|
|
825
|
+
? "shares.adjudications.on"
|
|
826
|
+
: "shares.adjudications.off"));
|
|
827
|
+
if (sharing.adjudicate_differing_twins === undefined)
|
|
828
|
+
lines.push(say("shares.twins.unstated"));
|
|
829
|
+
else if (sharing.adjudicate_differing_twins)
|
|
830
|
+
lines.push(say("shares.twins.on"));
|
|
831
|
+
if (sharing.witnesses === undefined)
|
|
832
|
+
lines.push(say("shares.witnesses.unstated"));
|
|
833
|
+
else
|
|
834
|
+
lines.push(sharing.witnesses.length > 0
|
|
835
|
+
? say("shares.witnesses", { witnesses: sharing.witnesses.join(", ") })
|
|
836
|
+
: say("shares.witnesses.none"));
|
|
837
|
+
lines.push(say("shares.never"));
|
|
838
|
+
shares = el("section", { class: "cvh-shares", "data-history": "shares" }, el("h2", null, say("shares.heading")), el("ul", null, ...lines.map((l) => el("li", null, l))), el("p", { class: "cvh-note" }, say("shares.as_of", { at: minuteOf(built) })));
|
|
839
|
+
}
|
|
840
|
+
let seal = null;
|
|
841
|
+
{
|
|
842
|
+
const states = drawRows ? rows.map((x) => x.second.state) : [];
|
|
843
|
+
const sealState = secondFailed || states.some((s) => s === "failed")
|
|
844
|
+
? "failed"
|
|
845
|
+
: states.length === 0 || states.some((s) => s === "not_checked")
|
|
846
|
+
? "not_checked"
|
|
847
|
+
: states.every((s) => s === "none")
|
|
848
|
+
? "none"
|
|
849
|
+
: "mixed";
|
|
850
|
+
const sealLine = sealState === "failed"
|
|
851
|
+
? say("slot.failed")
|
|
852
|
+
: sealState === "none"
|
|
853
|
+
? say("slot.second.none")
|
|
854
|
+
: sealState === "not_checked"
|
|
855
|
+
? say("slot.unchecked")
|
|
856
|
+
: say("seal.second.rows");
|
|
857
|
+
seal = el("section", { class: "cvh-seal", "data-history": "seal" }, drawRows && lockChecked
|
|
858
|
+
? el("p", { class: "cvh-seal-title" }, say("seal.title"))
|
|
859
|
+
: null, drawRows && lockChecked
|
|
860
|
+
? el("p", null, say(kind === "checkpoint" ? "seal.checkpoints" : "seal.deals"))
|
|
861
|
+
: drawRows
|
|
862
|
+
? el("p", null, say("seal.unchecked"))
|
|
863
|
+
: null, el("p", {
|
|
864
|
+
class: "cvh-seal-slot",
|
|
865
|
+
"data-filled": "no",
|
|
866
|
+
"data-state": sealState,
|
|
867
|
+
}, el("span", { class: "cvh-stamp-name" }, say("seal.second.label")), el("span", { class: "cvh-stamp-line" }, sealLine)), directory !== undefined
|
|
868
|
+
? el("p", { class: "cvh-note", "data-history": "directory" }, say("seal.directory", { directory }))
|
|
869
|
+
: null);
|
|
870
|
+
}
|
|
871
|
+
const checkedAttrs = {
|
|
872
|
+
class: "cvh-checked",
|
|
873
|
+
"data-history": "checked",
|
|
874
|
+
};
|
|
875
|
+
if (failed || outcome !== "answered")
|
|
876
|
+
checkedAttrs["open"] = "";
|
|
877
|
+
const panel = el("details", checkedAttrs, el("summary", null, say("checked.heading")), el("ul", null, ...checks.map((c) => el("li", { class: "cvh-check", "data-status": c.status }, say("check.line", {
|
|
878
|
+
status: say(`status.${c.status}`),
|
|
879
|
+
name: say(`check.${c.id}`),
|
|
880
|
+
})))), el("p", { class: "cvh-note" }, where === "page"
|
|
881
|
+
? say("checked.where.page", { by: checkedBy })
|
|
882
|
+
: say("checked.where.builder", { at: minuteOf(built), by: checkedBy })));
|
|
883
|
+
const tree = el("section", {
|
|
884
|
+
class: "cv-history",
|
|
885
|
+
"data-history": "view",
|
|
886
|
+
"data-kind": kind,
|
|
887
|
+
"data-surface": surface,
|
|
888
|
+
"data-verdict": failed ? "failed" : allPass ? "pass" : "unchecked",
|
|
889
|
+
}, header, el("div", { class: "cvh-main" }, hero, chips, rowList, periodBlock), el("div", { class: "cvh-side" }, callout, shares, seal, panel));
|
|
890
|
+
return { ok: true, tree };
|
|
891
|
+
}
|
|
892
|
+
/** The History view as HTML text; throws HistoryViewRefused on a refused input. */
|
|
893
|
+
export function historyViewHtml(input, overlay) {
|
|
894
|
+
const built = buildHistoryView(input, overlay);
|
|
895
|
+
if (!built.ok)
|
|
896
|
+
throw new HistoryViewRefused(built.reasons);
|
|
897
|
+
return serializeHistoryElement(built.tree);
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Draws the History view into `container`, replacing what it holds. A
|
|
901
|
+
* refused input draws one visible refusal line and returns false.
|
|
902
|
+
*/
|
|
903
|
+
export function renderHistoryView(input, container, overlay) {
|
|
904
|
+
const doc = container.ownerDocument;
|
|
905
|
+
const built = buildHistoryView(input, overlay);
|
|
906
|
+
const node = built.ok
|
|
907
|
+
? historyElementToDom(built.tree, doc)
|
|
908
|
+
: historyElementToDom(el("p", { class: "cvh-refused", "data-history": "refused" }, (BASE["refused"] ?? "").replace("{reasons}", () => built.reasons.join("; "))), doc);
|
|
909
|
+
container.replaceChildren(node);
|
|
910
|
+
return built.ok;
|
|
911
|
+
}
|
|
912
|
+
/** The view's stylesheet: one column under 900px, two above, and print. */
|
|
913
|
+
export const historyViewStyles = `.cv-history{--cvh-ink:#1f2733;--cvh-slate:#6b7482;--cvh-line:#e3ded3;--cvh-cream:#f6f2ea;--cvh-navy:#232f42;--cvh-ok:#2e7d5b;--cvh-bad:#b5462f;font:16px/1.45 system-ui,sans-serif;color:var(--cvh-ink);max-width:1120px;margin:0 auto;padding:16px;display:grid;gap:16px}
|
|
914
|
+
.cv-history h1{font-size:22px;margin:0}.cv-history h2{font-size:15px;margin:0 0 8px;color:var(--cvh-navy)}
|
|
915
|
+
.cvh-header p{margin:4px 0}.cvh-badge{display:inline-block;border:1px solid var(--cvh-line);border-radius:6px;padding:2px 8px;font-size:12px;font-weight:700;letter-spacing:.02em}
|
|
916
|
+
.cvh-badge[data-audience=private]{background:#fbefd9;border-color:#e8a33d}.cvh-built,.cvh-note{color:var(--cvh-slate);font-size:13px}
|
|
917
|
+
.cvh-hero-line{font-size:20px;font-weight:700;margin:0}.cvh-hero-note{margin:6px 0 0;color:var(--cvh-slate)}
|
|
918
|
+
.cvh-chips{list-style:none;padding:0;margin:0;display:flex;flex-wrap:wrap;gap:8px}.cvh-chip{background:var(--cvh-cream);border-radius:999px;padding:3px 10px;font-size:13px}
|
|
919
|
+
.cvh-rows{list-style:none;padding:0;margin:0}.cvh-row{border:1px solid var(--cvh-line);border-radius:10px;padding:10px 12px;margin:0 0 10px}
|
|
920
|
+
.cvh-row p{margin:0 0 4px}.cvh-row-title{font-weight:700}.cvh-row-detail{color:var(--cvh-slate);font-size:14px}
|
|
921
|
+
.cvh-proof summary{cursor:pointer;font-size:13px;color:var(--cvh-slate)}.cvh-proof code{font-size:12px;word-break:break-all}
|
|
922
|
+
.cvh-stamps{list-style:none;padding:0;margin:8px 0 0;display:flex;flex-wrap:wrap;gap:8px}
|
|
923
|
+
.cvh-stamp,.cvh-seal-slot{border:2px solid var(--cvh-navy);border-radius:999px;padding:2px 10px;font-size:12px;color:var(--cvh-navy)}
|
|
924
|
+
.cvh-stamp[data-filled=no],.cvh-seal-slot[data-filled=no]{border-style:dotted;border-color:#9aa1ab;color:var(--cvh-slate)}
|
|
925
|
+
.cvh-stamp[data-state=failed]{border-color:var(--cvh-bad);color:var(--cvh-bad)}
|
|
926
|
+
.cvh-stamp-name{font-weight:800}.cvh-stamp-line{margin-left:6px}
|
|
927
|
+
.cvh-callout,.cvh-shares,.cvh-seal,.cvh-periods{border:1px solid var(--cvh-line);border-radius:10px;padding:12px}
|
|
928
|
+
.cvh-callout{background:var(--cvh-cream)}.cvh-callout p,.cvh-seal p{margin:0 0 6px}.cvh-shares ul,.cvh-periods ul{margin:0;padding-left:18px}
|
|
929
|
+
.cvh-seal-title{font-weight:700}.cvh-checked summary{cursor:pointer;font-weight:700;color:var(--cvh-navy)}
|
|
930
|
+
.cvh-check[data-status=fail]{color:var(--cvh-bad)}.cvh-check[data-status=pass]{color:var(--cvh-ok)}
|
|
931
|
+
.cvh-main,.cvh-side{display:grid;gap:16px;align-content:start}.cvh-refused{border:1px solid var(--cvh-bad);color:var(--cvh-bad);padding:8px 12px;border-radius:8px}
|
|
932
|
+
@media (min-width:900px){.cv-history{grid-template-columns:minmax(0,3fr) minmax(0,2fr)}.cvh-header{grid-column:1/-1}}
|
|
933
|
+
@media print{.cv-history{max-width:none;grid-template-columns:1fr}.cvh-proof code{display:block}}
|
|
934
|
+
`;
|
|
935
|
+
/** A whole static page (no script) holding the History view; throws HistoryViewRefused. */
|
|
936
|
+
export function historyViewDocument(input, overlay, title = "History") {
|
|
937
|
+
const body = historyViewHtml(input, overlay);
|
|
938
|
+
return `<!doctype html>\n<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escapeText(title)}</title><style>${historyViewStyles}</style></head><body>${body}</body></html>\n`;
|
|
939
|
+
}
|
|
940
|
+
//# sourceMappingURL=history-view.js.map
|