@milesroxas/design-hub 0.8.1 → 0.10.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 +7 -2
- package/core/controls.test.ts +176 -0
- package/core/controls.ts +195 -0
- package/core/prototype.test.ts +83 -0
- package/core/prototype.ts +84 -0
- package/core/review/model.ts +32 -0
- package/core/review/policy.test.ts +4 -2
- package/core/review/policy.ts +4 -2
- package/core/review/service.test.ts +223 -4
- package/core/review/service.ts +111 -2
- package/core/review/store.ts +13 -0
- package/dist/core/controls.d.ts +55 -0
- package/dist/core/controls.js +174 -0
- package/dist/core/prototype.d.ts +35 -0
- package/dist/core/prototype.js +84 -0
- package/dist/core/review/model.d.ts +13 -0
- package/dist/core/review/model.js +27 -0
- package/dist/core/review/policy.d.ts +1 -1
- package/dist/core/review/policy.js +1 -0
- package/dist/core/review/service.d.ts +50 -1
- package/dist/core/review/service.js +97 -3
- package/dist/core/review/store.d.ts +13 -0
- package/dist/core/review/store.js +13 -0
- package/dist/scripts/guard.d.ts +11 -0
- package/dist/scripts/guard.js +44 -0
- package/dist/scripts/lib/cdp.js +6 -1
- package/dist/scripts/lib/export-smoke.d.ts +18 -0
- package/dist/scripts/lib/export-smoke.js +73 -0
- package/dist/scripts/lib/rules.d.ts +1 -0
- package/dist/scripts/lib/rules.js +1 -0
- package/dist/scripts/new.js +5 -2
- package/dist/scripts/release-check.d.ts +5 -3
- package/dist/scripts/release-check.js +17 -4
- package/dist/scripts/share.d.ts +2 -2
- package/dist/server/api.js +21 -0
- package/dist/server/session.d.ts +5 -1
- package/dist/server/session.js +39 -21
- package/dist/vercel/proxy.js +44 -8
- package/dist/vite/boundary.d.ts +93 -0
- package/dist/vite/boundary.js +218 -0
- package/dist/vite/css-boundary.d.ts +39 -0
- package/dist/vite/css-boundary.js +167 -0
- package/dist/vite/kit.js +15 -6
- package/dist/vite/leaks.d.ts +37 -0
- package/dist/vite/leaks.js +331 -0
- package/dist/vite/plugin.js +2 -1
- package/dist/vite/registry.d.ts +15 -4
- package/dist/vite/registry.js +531 -27
- package/dist/vite/settle.d.ts +27 -0
- package/dist/vite/settle.js +185 -0
- package/kit/Artboard.tsx +21 -8
- package/kit/Space.tsx +4 -3
- package/kit/Variants.tsx +193 -65
- package/kit/ViewTools.tsx +77 -11
- package/kit/audience.ts +85 -0
- package/kit/dials.css +59 -0
- package/kit/dials.tsx +272 -35
- package/kit/harness.css +34 -0
- package/kit/prefs.ts +23 -1
- package/package.json +5 -4
- package/shell/ClientViewNote.tsx +46 -0
- package/shell/Guide.tsx +17 -2
- package/shell/Index.tsx +257 -25
- package/shell/audience.test.ts +63 -0
- package/shell/audience.ts +47 -0
- package/shell/controls.ts +26 -0
- package/shell/hub.ts +36 -0
- package/shell/main.tsx +51 -5
- package/shell/registry.ts +28 -7
- package/shell/registry.virtual.d.ts +12 -4
- package/shell/review/client.ts +16 -4
- package/shell/review/review.css +2 -2
- package/shell/shell.css +54 -3
- package/shell/system.css +5 -0
- package/skills/miles-brand/SKILL.md +11 -1
- package/skills/miles-deploy/SKILL.md +19 -0
- package/skills/miles-new-feature/SKILL.md +1 -1
- package/skills/miles-prototype/SKILL.md +48 -2
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Which of a prototype's controls a Client gets: its dials and its variants.
|
|
2
|
+
// Pure, so the server, the kit and the tests read one set of rules.
|
|
3
|
+
//
|
|
4
|
+
// A dial is internal until marked client-facing. It is marked in two places:
|
|
5
|
+
// in code, with `client(...)` around the dial where it is declared, which is
|
|
6
|
+
// where it starts; and in the hub, by Studio, which is stored per deployed
|
|
7
|
+
// site and overrules the code either way. A variant is marked only in the
|
|
8
|
+
// hub. The View tools are never asked about: they are always a Client's.
|
|
9
|
+
//
|
|
10
|
+
// The mark decides what a Client's panel draws and nothing else. A prototype's
|
|
11
|
+
// code is one file a Client's browser loads, so an internal dial's name, range
|
|
12
|
+
// and default are still in it; its value stays at the default.
|
|
13
|
+
export const CONTROL_KINDS = ['dial', 'variant'];
|
|
14
|
+
export const NO_MARKS = { dials: {}, variants: [] };
|
|
15
|
+
const MAX_ID = 200;
|
|
16
|
+
/** A dial's or a variant's name as the store keeps it: one line of text, trimmed, at most 200 characters. */
|
|
17
|
+
export const isControlId = (v) => typeof v === 'string' &&
|
|
18
|
+
v.length > 0 &&
|
|
19
|
+
v.length <= MAX_ID &&
|
|
20
|
+
v.trim() === v &&
|
|
21
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what is refused
|
|
22
|
+
!/[\u0000-\u001f\u007f]/.test(v);
|
|
23
|
+
/** A dial is named by its panel and its key, a folder's dial by the keys down to it: `Review/density`, `Card/shadow.blur`. */
|
|
24
|
+
export const dialId = (panel, path) => `${panel}/${path.join('.')}`;
|
|
25
|
+
/** The store's field for one control. */
|
|
26
|
+
export const controlField = (kind, id) => `${kind}:${id}`;
|
|
27
|
+
/** The marks in a prototype's stored fields. A field or a value that is not one of ours is left out, so it reads as unmarked. */
|
|
28
|
+
export function readMarks(fields) {
|
|
29
|
+
const dials = {};
|
|
30
|
+
const variants = [];
|
|
31
|
+
for (const [field, value] of Object.entries(fields)) {
|
|
32
|
+
const at = field.indexOf(':');
|
|
33
|
+
const [kind, id] = [field.slice(0, at), field.slice(at + 1)];
|
|
34
|
+
if (!isControlId(id))
|
|
35
|
+
continue;
|
|
36
|
+
if (kind === 'dial' && (value === 'client' || value === 'internal'))
|
|
37
|
+
dials[id] = value;
|
|
38
|
+
if (kind === 'variant' && value === 'client')
|
|
39
|
+
variants.push(id);
|
|
40
|
+
}
|
|
41
|
+
return { dials, variants: variants.sort() };
|
|
42
|
+
}
|
|
43
|
+
/** The marks after one control is switched. */
|
|
44
|
+
export function withMark(marks, kind, id, audience) {
|
|
45
|
+
if (kind === 'dial')
|
|
46
|
+
return { ...marks, dials: { ...marks.dials, [id]: audience } };
|
|
47
|
+
const rest = marks.variants.filter((v) => v !== id);
|
|
48
|
+
return { ...marks, variants: audience === 'client' ? [...rest, id].sort() : rest };
|
|
49
|
+
}
|
|
50
|
+
/** Who a dial is for: the hub's mark when Studio set one, else what the code says, else internal. */
|
|
51
|
+
export const dialAudience = (marks, id, inCode) => marks.dials[id] ?? inCode;
|
|
52
|
+
/**
|
|
53
|
+
* The variants a Client gets, in the order the prototype declares them. One
|
|
54
|
+
* is no picker. None marked is still one: the first, so a page is never empty.
|
|
55
|
+
*/
|
|
56
|
+
export function clientVariants(names, marks) {
|
|
57
|
+
const kept = names.filter((n) => marks.variants.includes(n));
|
|
58
|
+
return kept.length ? kept : names.slice(0, 1);
|
|
59
|
+
}
|
|
60
|
+
const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
61
|
+
const isMarked = (v) => isRecord(v) && '__client' in v;
|
|
62
|
+
const isFolder = (v) => isRecord(v) && !('type' in v);
|
|
63
|
+
/** DialKit's own key for a folder that starts closed: not a dial. */
|
|
64
|
+
const SETTING = '_collapsed';
|
|
65
|
+
/**
|
|
66
|
+
* Marks a dial client-facing where it is declared, or a folder and every dial
|
|
67
|
+
* in it. Typed as the dial itself, so the values a prototype reads keep their types.
|
|
68
|
+
*/
|
|
69
|
+
export const client = (dial) => ({ __client: dial });
|
|
70
|
+
/** A config as DialKit takes it (every `client()` unwrapped) and the dials in it. */
|
|
71
|
+
export function readConfig(panel, config) {
|
|
72
|
+
const dials = [];
|
|
73
|
+
const walk = (node, path, inherited) => {
|
|
74
|
+
const out = {};
|
|
75
|
+
for (const [key, raw] of Object.entries(node)) {
|
|
76
|
+
if (key === SETTING) {
|
|
77
|
+
out[key] = raw;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const inCode = isMarked(raw) ? 'client' : inherited;
|
|
81
|
+
const value = isMarked(raw) ? raw.__client : raw;
|
|
82
|
+
const at = [...path, key];
|
|
83
|
+
if (isFolder(value))
|
|
84
|
+
out[key] = walk(value, at, inCode);
|
|
85
|
+
else {
|
|
86
|
+
out[key] = value;
|
|
87
|
+
dials.push({ id: dialId(panel, at), path: at, inCode });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
};
|
|
92
|
+
return { config: walk(config, [], 'internal'), dials };
|
|
93
|
+
}
|
|
94
|
+
/** The part of an unwrapped config whose dials `shown` keeps. A folder with none left goes with them. */
|
|
95
|
+
export function keepDials(panel, config, shown) {
|
|
96
|
+
const walk = (node, path) => {
|
|
97
|
+
const out = {};
|
|
98
|
+
for (const [key, value] of Object.entries(node)) {
|
|
99
|
+
if (key === SETTING)
|
|
100
|
+
continue;
|
|
101
|
+
const at = [...path, key];
|
|
102
|
+
if (isFolder(value)) {
|
|
103
|
+
const inner = walk(value, at);
|
|
104
|
+
if (Object.keys(inner).length)
|
|
105
|
+
out[key] = SETTING in value ? { ...inner, [SETTING]: value[SETTING] } : inner;
|
|
106
|
+
}
|
|
107
|
+
else if (shown(dialId(panel, at)))
|
|
108
|
+
out[key] = value;
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
};
|
|
112
|
+
return walk(config, []);
|
|
113
|
+
}
|
|
114
|
+
const finite = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
115
|
+
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
116
|
+
/** A slider's starting value: its first number, kept inside a range that is given. */
|
|
117
|
+
function sliderDefault(value) {
|
|
118
|
+
const seed = finite(value[0]) ? value[0] : 0;
|
|
119
|
+
if (!finite(value[1]) || !finite(value[2]))
|
|
120
|
+
return seed;
|
|
121
|
+
const [min, max] = value[1] <= value[2] ? [value[1], value[2]] : [value[2], value[1]];
|
|
122
|
+
return clamp(seed, min, min === max ? min + 1 : max);
|
|
123
|
+
}
|
|
124
|
+
const firstOption = (options) => {
|
|
125
|
+
const first = Array.isArray(options) ? options[0] : undefined;
|
|
126
|
+
if (first === undefined)
|
|
127
|
+
return '';
|
|
128
|
+
return typeof first === 'string' ? first : first.value;
|
|
129
|
+
};
|
|
130
|
+
/** One axis of a pad: `[default, min, max, step?]`, the default snapped to the step as DialKit snaps it. */
|
|
131
|
+
function padAxis(axis) {
|
|
132
|
+
const [initial, min, max, given] = (Array.isArray(axis) ? axis : [0, -1, 1, 0.01]);
|
|
133
|
+
const step = given ?? (max - min) / 200;
|
|
134
|
+
const at = clamp(initial, min, max);
|
|
135
|
+
if (at === min || at === max)
|
|
136
|
+
return at;
|
|
137
|
+
return clamp(Number((min + Math.round((at - min) / step) * step).toPrecision(12)), min, max);
|
|
138
|
+
}
|
|
139
|
+
/** By `type`: what DialKit starts each kind of dial at when its config names no default. */
|
|
140
|
+
const TYPED = {
|
|
141
|
+
select: (v) => v.default ?? firstOption(v.options),
|
|
142
|
+
color: (v) => v.default ?? '#000000',
|
|
143
|
+
image: (v) => v.default ?? firstOption(v.options ?? []),
|
|
144
|
+
text: (v) => v.default ?? '',
|
|
145
|
+
pad: (v) => ({ x: padAxis(v.x), y: padAxis(v.y) }),
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* What a dial reads when nobody can move it: the value DialKit would start it
|
|
149
|
+
* at. A test holds this equal to DialKit's own for every kind of dial.
|
|
150
|
+
*/
|
|
151
|
+
export function defaultOf(dial) {
|
|
152
|
+
if (Array.isArray(dial))
|
|
153
|
+
return sliderDefault(dial);
|
|
154
|
+
if (!isRecord(dial) || typeof dial.type !== 'string')
|
|
155
|
+
return dial;
|
|
156
|
+
const typed = TYPED[dial.type];
|
|
157
|
+
return typed ? typed(dial) : dial;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The values a prototype reads: DialKit's for the dials it drew, the default
|
|
161
|
+
* for every dial it did not, in the shape of the whole config.
|
|
162
|
+
*/
|
|
163
|
+
export function withDefaults(config, values) {
|
|
164
|
+
const out = {};
|
|
165
|
+
for (const [key, dial] of Object.entries(config)) {
|
|
166
|
+
if (key === SETTING)
|
|
167
|
+
continue;
|
|
168
|
+
if (isFolder(dial))
|
|
169
|
+
out[key] = withDefaults(dial, isRecord(values[key]) ? values[key] : {});
|
|
170
|
+
else
|
|
171
|
+
out[key] = key in values ? values[key] : defaultOf(dial);
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First path segments the hub owns, never a prototype: the walkthroughs,
|
|
3
|
+
* the review API, and the shared bundle.
|
|
4
|
+
*/
|
|
5
|
+
export declare const RESERVED: readonly ['guide', 'api', 'assets'];
|
|
6
|
+
/**
|
|
7
|
+
* Everything built from `prototypes/<slug>/` lands under `/_p/<slug>/`, and
|
|
8
|
+
* Studio's list of every slug at `/_p/all.js`. `_p` can never be a slug: SLUG
|
|
9
|
+
* has no underscore.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PROTOTYPE_DIR = "_p";
|
|
12
|
+
export declare const ALL_FILE = "_p/all.js";
|
|
13
|
+
export declare const entryFile: (slug: string) => string;
|
|
14
|
+
/** Whether `name` can be a prototype's folder: kebab-case and not one of the hub's own paths. */
|
|
15
|
+
export declare const isPrototypeSlug: (name: unknown) => name is string;
|
|
16
|
+
/**
|
|
17
|
+
* Which prototype a request path belongs to, for the gate: the name a
|
|
18
|
+
* prototype path carries, or null for a hub path (`/`, or a first segment in
|
|
19
|
+
* HUB_ROOT). The first segment, decoded, must be one of those, `_p`, or a
|
|
20
|
+
* prototype slug; anything else (`_P`, `_p;x`, `_p.`, a full-width `_p`)
|
|
21
|
+
* belongs to `''`, refused like an internal prototype. A path under `/_p/`
|
|
22
|
+
* always belongs to one, so its name may be no slug at all (`all.js`), which
|
|
23
|
+
* no audience makes client-facing. A path that could mean more than one file
|
|
24
|
+
* belongs to `''` too.
|
|
25
|
+
*/
|
|
26
|
+
export declare function prototypeOfPath(pathname: string): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Whether a built prototype's entry is there for this person, asked with a
|
|
29
|
+
* HEAD before it is imported. Not there: a 404 (the gate's answer for a
|
|
30
|
+
* prototype this person may not open, or none at all), or a 200 that is not
|
|
31
|
+
* JavaScript (the host's page for an entry that was never built). Any other
|
|
32
|
+
* answer (401, 500, 503) is an error, never "not there", so an outage never
|
|
33
|
+
* reads as nothing shared.
|
|
34
|
+
*/
|
|
35
|
+
export declare function probeEntry(path: string, fetcher: typeof fetch): Promise<boolean>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// What a prototype's slug may be, and where the files built from it live.
|
|
2
|
+
// One rule for the registry's scan, `design-hub new` and the gate, so a
|
|
3
|
+
// folder the hub lists is always a path the gate knows how to refuse.
|
|
4
|
+
import { SLUG } from './feature.js';
|
|
5
|
+
/**
|
|
6
|
+
* First path segments the hub owns, never a prototype: the walkthroughs,
|
|
7
|
+
* the review API, and the shared bundle.
|
|
8
|
+
*/
|
|
9
|
+
export const RESERVED = ['guide', 'api', 'assets'];
|
|
10
|
+
/**
|
|
11
|
+
* Everything built from `prototypes/<slug>/` lands under `/_p/<slug>/`, and
|
|
12
|
+
* Studio's list of every slug at `/_p/all.js`. `_p` can never be a slug: SLUG
|
|
13
|
+
* has no underscore.
|
|
14
|
+
*/
|
|
15
|
+
export const PROTOTYPE_DIR = '_p';
|
|
16
|
+
export const ALL_FILE = `${PROTOTYPE_DIR}/all.js`;
|
|
17
|
+
export const entryFile = (slug) => `${PROTOTYPE_DIR}/${slug}/entry.js`;
|
|
18
|
+
/** Whether `name` can be a prototype's folder: kebab-case and not one of the hub's own paths. */
|
|
19
|
+
export const isPrototypeSlug = (name) => typeof name === 'string' && SLUG.test(name) && !RESERVED.includes(name);
|
|
20
|
+
/**
|
|
21
|
+
* A path's segments as a file server might read them, or null when the path
|
|
22
|
+
* could mean more than one file: it does not decode, still holds a `%` after
|
|
23
|
+
* decoding (`%255F`), holds a backslash, a `.` or `..` segment, or an empty
|
|
24
|
+
* segment other than the last. The gate refuses those to a Client rather than
|
|
25
|
+
* guess how the server resolves them. An encoded space or letter decodes and passes.
|
|
26
|
+
*/
|
|
27
|
+
function segments(pathname) {
|
|
28
|
+
let decoded;
|
|
29
|
+
try {
|
|
30
|
+
decoded = decodeURIComponent(pathname);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (/[%\\]/.test(decoded))
|
|
36
|
+
return null;
|
|
37
|
+
const parts = decoded.split('/').slice(1);
|
|
38
|
+
if (parts.at(-1) === '')
|
|
39
|
+
parts.pop();
|
|
40
|
+
return parts.some((p) => p === '' || p === '.' || p === '..') ? null : parts;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The first path segments that are the hub's own, for anyone signed in: the
|
|
44
|
+
* reserved routes, the gate's font folder, and the files the hub serves at
|
|
45
|
+
* the top (shell/index.html, shell/public/favicon.svg).
|
|
46
|
+
*/
|
|
47
|
+
const HUB_ROOT = [...RESERVED, '_gate', 'index.html', 'favicon.svg'];
|
|
48
|
+
/**
|
|
49
|
+
* Which prototype a request path belongs to, for the gate: the name a
|
|
50
|
+
* prototype path carries, or null for a hub path (`/`, or a first segment in
|
|
51
|
+
* HUB_ROOT). The first segment, decoded, must be one of those, `_p`, or a
|
|
52
|
+
* prototype slug; anything else (`_P`, `_p;x`, `_p.`, a full-width `_p`)
|
|
53
|
+
* belongs to `''`, refused like an internal prototype. A path under `/_p/`
|
|
54
|
+
* always belongs to one, so its name may be no slug at all (`all.js`), which
|
|
55
|
+
* no audience makes client-facing. A path that could mean more than one file
|
|
56
|
+
* belongs to `''` too.
|
|
57
|
+
*/
|
|
58
|
+
export function prototypeOfPath(pathname) {
|
|
59
|
+
const parts = segments(pathname);
|
|
60
|
+
if (!parts)
|
|
61
|
+
return '';
|
|
62
|
+
const [first, second] = parts;
|
|
63
|
+
if (first === undefined || HUB_ROOT.includes(first))
|
|
64
|
+
return null;
|
|
65
|
+
if (first === PROTOTYPE_DIR)
|
|
66
|
+
return second ?? '';
|
|
67
|
+
return isPrototypeSlug(first) ? first : '';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Whether a built prototype's entry is there for this person, asked with a
|
|
71
|
+
* HEAD before it is imported. Not there: a 404 (the gate's answer for a
|
|
72
|
+
* prototype this person may not open, or none at all), or a 200 that is not
|
|
73
|
+
* JavaScript (the host's page for an entry that was never built). Any other
|
|
74
|
+
* answer (401, 500, 503) is an error, never "not there", so an outage never
|
|
75
|
+
* reads as nothing shared.
|
|
76
|
+
*/
|
|
77
|
+
export async function probeEntry(path, fetcher) {
|
|
78
|
+
const head = await fetcher(path, { method: 'HEAD', credentials: 'same-origin' });
|
|
79
|
+
if (head.status === 404)
|
|
80
|
+
return false;
|
|
81
|
+
if (head.status !== 200)
|
|
82
|
+
throw new Error(`${path} answered ${head.status}.`);
|
|
83
|
+
return /javascript/.test(head.headers.get('content-type') ?? '');
|
|
84
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ControlKind } from '../controls.ts';
|
|
1
2
|
/** Which side a person is on: the studio that makes the work, or the client it is for. */
|
|
2
3
|
export declare const PERSON_KINDS: readonly ['studio', 'client'];
|
|
3
4
|
export type PersonKind = (typeof PERSON_KINDS)[number];
|
|
@@ -140,6 +141,18 @@ export type PersonInput = Pick<Person, 'name' | 'team' | 'kind'> & {
|
|
|
140
141
|
export declare function checkPersonInput(input: unknown): Checked<PersonInput>;
|
|
141
142
|
/** A new thread's audience as asked: one of AUDIENCES, or null when none is given. */
|
|
142
143
|
export declare function checkAudience(input: unknown): Checked<Audience | null>;
|
|
144
|
+
/** A prototype's audience as Studio sets it: one of AUDIENCES, required. */
|
|
145
|
+
export declare function checkPrototypeAudience(input: unknown): Checked<Audience>;
|
|
146
|
+
/** One control's mark as Studio sets it: which kind, its id, and who it is for. */
|
|
147
|
+
export declare function checkControl(input: {
|
|
148
|
+
kind: unknown;
|
|
149
|
+
id: unknown;
|
|
150
|
+
audience: unknown;
|
|
151
|
+
}): Checked<{
|
|
152
|
+
kind: ControlKind;
|
|
153
|
+
id: string;
|
|
154
|
+
audience: Audience;
|
|
155
|
+
}>;
|
|
143
156
|
/** Whose view of the comments is asked for: a person kind, or null for the caller's own. */
|
|
144
157
|
export declare function checkViewAs(input: unknown): Checked<PersonKind | null>;
|
|
145
158
|
export declare function checkBody(body: unknown): Checked<string>;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Pure: no I/O, no environment. Every limit and rule lives here once and is
|
|
4
4
|
// enforced by the service, whichever adapter (Vercel, Vite dev, the CLI)
|
|
5
5
|
// calls it.
|
|
6
|
+
import { CONTROL_KINDS, isControlId } from '../controls.js';
|
|
6
7
|
import { SLUG } from '../feature.js';
|
|
7
8
|
/** Which side a person is on: the studio that makes the work, or the client it is for. */
|
|
8
9
|
export const PERSON_KINDS = ['studio', 'client'];
|
|
@@ -140,6 +141,32 @@ export function checkAudience(input) {
|
|
|
140
141
|
? { ok: true, value: input }
|
|
141
142
|
: { ok: false, problems: [`audience: one of ${AUDIENCES.join(', ')}`] };
|
|
142
143
|
}
|
|
144
|
+
/** A prototype's audience as Studio sets it: one of AUDIENCES, required. */
|
|
145
|
+
export function checkPrototypeAudience(input) {
|
|
146
|
+
return AUDIENCES.includes(input)
|
|
147
|
+
? { ok: true, value: input }
|
|
148
|
+
: { ok: false, problems: [`audience: one of ${AUDIENCES.join(', ')}`] };
|
|
149
|
+
}
|
|
150
|
+
/** One control's mark as Studio sets it: which kind, its id, and who it is for. */
|
|
151
|
+
export function checkControl(input) {
|
|
152
|
+
const problems = [];
|
|
153
|
+
if (!CONTROL_KINDS.includes(input.kind))
|
|
154
|
+
problems.push(`kind: one of ${CONTROL_KINDS.join(', ')}`);
|
|
155
|
+
if (!isControlId(input.id))
|
|
156
|
+
problems.push('id: the control’s name, one line of at most 200 characters');
|
|
157
|
+
if (!AUDIENCES.includes(input.audience))
|
|
158
|
+
problems.push(`audience: one of ${AUDIENCES.join(', ')}`);
|
|
159
|
+
return problems.length
|
|
160
|
+
? { ok: false, problems }
|
|
161
|
+
: {
|
|
162
|
+
ok: true,
|
|
163
|
+
value: {
|
|
164
|
+
kind: input.kind,
|
|
165
|
+
id: input.id,
|
|
166
|
+
audience: input.audience,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
143
170
|
/** Whose view of the comments is asked for: a person kind, or null for the caller's own. */
|
|
144
171
|
export function checkViewAs(input) {
|
|
145
172
|
if (input === undefined || input === null)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Audience, Comment, Person, PersonKind } from './model.ts';
|
|
2
|
-
export type Action = 'read' | 'comment' | 'edit' | 'delete' | 'resolve' | 'triage' | 'people';
|
|
2
|
+
export type Action = 'read' | 'comment' | 'edit' | 'delete' | 'resolve' | 'triage' | 'people' | 'audience';
|
|
3
3
|
/** Only what the rules read, so the browser's signed-in person (no epoch) is checked by the same rules. */
|
|
4
4
|
type Actor = Pick<Person, 'id' | 'kind' | 'revokedAt'>;
|
|
5
5
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ControlKind, type Marks } from '../controls.ts';
|
|
2
|
+
import { type Access, type Audience, type Comment, type Person, type PersonKind, type Triage } from './model.ts';
|
|
2
3
|
import { type KV } from './store.ts';
|
|
3
4
|
export type ErrorCode = 'unauthorized' | 'forbidden' | 'not_found' | 'invalid';
|
|
4
5
|
export declare class ReviewError extends Error {
|
|
@@ -98,6 +99,54 @@ export declare function createReview(kv: KV, overrides?: Partial<Deps>): {
|
|
|
98
99
|
triage?: unknown;
|
|
99
100
|
states?: unknown;
|
|
100
101
|
}): Promise<Comment>;
|
|
102
|
+
/**
|
|
103
|
+
* Marks a prototype client-facing or internal. Only client-facing is
|
|
104
|
+
* stored, so internal deletes the field and a prototype nobody marked is
|
|
105
|
+
* internal. Studio only.
|
|
106
|
+
*/
|
|
107
|
+
setAudience(actor: Person | null, prototype: unknown, audience: unknown): Promise<Audience>;
|
|
108
|
+
/**
|
|
109
|
+
* What Studio marked on a prototype's dials and variants, with the view
|
|
110
|
+
* the actor gets. A Client reads the marks too: their page needs a dial
|
|
111
|
+
* Studio switched back to internal as much as one it shared, and the
|
|
112
|
+
* names are in the prototype's own code already. An internal prototype
|
|
113
|
+
* has none for a Client, as it has no comments.
|
|
114
|
+
*/
|
|
115
|
+
controlsOf(actor: Person | null, prototype: unknown): Promise<{
|
|
116
|
+
view: PersonKind;
|
|
117
|
+
} & Marks>;
|
|
118
|
+
/**
|
|
119
|
+
* Marks one dial or one variant client-facing or internal. A dial's mark
|
|
120
|
+
* is stored either way, because it overrules what the code says; a
|
|
121
|
+
* variant's internal is the field's absence. Studio only. The server
|
|
122
|
+
* keeps no list of a prototype's controls, so any well-formed id is taken.
|
|
123
|
+
*/
|
|
124
|
+
setControl(actor: Person | null, input: {
|
|
125
|
+
prototype: unknown;
|
|
126
|
+
kind: unknown;
|
|
127
|
+
id: unknown;
|
|
128
|
+
audience: unknown;
|
|
129
|
+
}): Promise<{
|
|
130
|
+
kind: ControlKind;
|
|
131
|
+
id: string;
|
|
132
|
+
audience: Audience;
|
|
133
|
+
}>;
|
|
134
|
+
/**
|
|
135
|
+
* Who a prototype is for, asked by the gate with no actor. Absent, or any
|
|
136
|
+
* value but `client`, is internal; a name that cannot be a prototype is
|
|
137
|
+
* internal without asking the store.
|
|
138
|
+
*/
|
|
139
|
+
audienceOf(prototype: string): Promise<Audience>;
|
|
140
|
+
/**
|
|
141
|
+
* What the index is built from: the view the actor gets (Client view for
|
|
142
|
+
* Studio with `viewAs: 'client'`) and every client-facing slug. The
|
|
143
|
+
* server keeps no list of internal ones: Studio's view reads the build's
|
|
144
|
+
* own list, which the gate refuses to a Client.
|
|
145
|
+
*/
|
|
146
|
+
visiblePrototypes(actor: Person | null, viewAs?: unknown): Promise<{
|
|
147
|
+
view: PersonKind;
|
|
148
|
+
clientFacing: string[];
|
|
149
|
+
}>;
|
|
101
150
|
/** Where a comment lives, for the CLI, which has an id and no prototype; null when the actor may not see it. */
|
|
102
151
|
locate(actor: Person | null, id: string): Promise<{
|
|
103
152
|
prototype: string;
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
// person, per comment), so two people commenting at once never collide;
|
|
6
6
|
// two edits of the same comment at once keep the last.
|
|
7
7
|
import { base64url, hex, sha256 } from '../bytes.js';
|
|
8
|
-
import {
|
|
8
|
+
import { controlField, readMarks } from '../controls.js';
|
|
9
|
+
import { isPrototypeSlug } from '../prototype.js';
|
|
10
|
+
import { accessEnd, authorOf, checkAccess, checkAnchor, checkAudience, checkBody, checkControl, checkPersonInput, checkPrototypeAudience, checkStates, checkTriage, checkViewAs, DEFAULT_ACCESS, hasAccess, isProfile, isRoot, LINK_DAYS, readComment, } from './model.js';
|
|
9
11
|
import { audienceFor, can, viewOf, visibleTo } from './policy.js';
|
|
10
12
|
import { KEY } from './store.js';
|
|
11
13
|
export class ReviewError extends Error {
|
|
@@ -159,11 +161,20 @@ export function createReview(kv, overrides = {}) {
|
|
|
159
161
|
return json === null ? null : readComment(json);
|
|
160
162
|
};
|
|
161
163
|
const saveComment = (prototype, c) => kv.hset(KEY.comments(prototype), c.id, JSON.stringify(c));
|
|
164
|
+
const isClientFacing = async (prototype) => isPrototypeSlug(prototype) && (await kv.hget(KEY.audiences, prototype)) === 'client';
|
|
165
|
+
/**
|
|
166
|
+
* Whether a view reaches a prototype's comments at all. A Client's view
|
|
167
|
+
* reaches only a client-facing prototype: on any other, every op answers
|
|
168
|
+
* as if it had no comments, so no answer confirms an internal slug.
|
|
169
|
+
*/
|
|
170
|
+
const reachable = async (view, prototype) => view === 'studio' || (await isClientFacing(prototype));
|
|
162
171
|
/**
|
|
163
172
|
* A comment and its thread's root, if `actor` may see both; else null. A
|
|
164
173
|
* reply whose root is gone is not there either.
|
|
165
174
|
*/
|
|
166
175
|
async function seen(actor, prototype, id) {
|
|
176
|
+
if (!(await reachable(viewOf(actor), prototype)))
|
|
177
|
+
return null;
|
|
167
178
|
const comment = await commentAt(prototype, id);
|
|
168
179
|
if (!comment)
|
|
169
180
|
return null;
|
|
@@ -307,13 +318,19 @@ export function createReview(kv, overrides = {}) {
|
|
|
307
318
|
async listComments(actor, prototype, viewAs) {
|
|
308
319
|
allow(actor, 'read');
|
|
309
320
|
const view = viewOf(actor, valid(checkViewAs(viewAs)));
|
|
321
|
+
if (!(await reachable(view, prototype)))
|
|
322
|
+
return [];
|
|
310
323
|
return visibleTo(view, await commentsOf(prototype));
|
|
311
324
|
},
|
|
312
325
|
/** Every comment on every prototype the actor may see, for the CLI (which acts as Studio). */
|
|
313
326
|
async allComments(actor) {
|
|
314
327
|
allow(actor, 'read');
|
|
315
|
-
const
|
|
316
|
-
|
|
328
|
+
const view = viewOf(actor);
|
|
329
|
+
const prototypes = [];
|
|
330
|
+
for (const p of await kv.smembers(KEY.prototypes))
|
|
331
|
+
if (await reachable(view, p))
|
|
332
|
+
prototypes.push(p);
|
|
333
|
+
return visibleTo(view, (await Promise.all(prototypes.map(commentsOf))).flat());
|
|
317
334
|
},
|
|
318
335
|
/**
|
|
319
336
|
* A new thread. A Client's is client-facing whatever the input says;
|
|
@@ -323,6 +340,9 @@ export function createReview(kv, overrides = {}) {
|
|
|
323
340
|
async add(actor, input) {
|
|
324
341
|
allow(actor, 'comment');
|
|
325
342
|
const [body, anchor, asked] = validAll(checkBody(input.body), checkAnchor(input.anchor), checkAudience(input.audience));
|
|
343
|
+
// A Client's thread on a prototype that is not client-facing: the answer an unknown id gets.
|
|
344
|
+
if (!(await reachable(viewOf(actor), anchor.prototype)))
|
|
345
|
+
throw new ReviewError('not_found', 'No such comment.');
|
|
326
346
|
const id = newId();
|
|
327
347
|
const triage = deps.triage
|
|
328
348
|
? await deps
|
|
@@ -407,6 +427,80 @@ export function createReview(kv, overrides = {}) {
|
|
|
407
427
|
await saveComment(input.prototype, next);
|
|
408
428
|
return next;
|
|
409
429
|
},
|
|
430
|
+
/**
|
|
431
|
+
* Marks a prototype client-facing or internal. Only client-facing is
|
|
432
|
+
* stored, so internal deletes the field and a prototype nobody marked is
|
|
433
|
+
* internal. Studio only.
|
|
434
|
+
*/
|
|
435
|
+
async setAudience(actor, prototype, audience) {
|
|
436
|
+
allow(actor, 'audience');
|
|
437
|
+
const [slug, value] = validAll(isPrototypeSlug(prototype)
|
|
438
|
+
? { ok: true, value: prototype }
|
|
439
|
+
: { ok: false, problems: ['prototype: a prototype slug'] }, checkPrototypeAudience(audience));
|
|
440
|
+
if (value === 'client')
|
|
441
|
+
await kv.hset(KEY.audiences, slug, 'client');
|
|
442
|
+
else
|
|
443
|
+
await kv.hdel(KEY.audiences, slug);
|
|
444
|
+
return value;
|
|
445
|
+
},
|
|
446
|
+
/**
|
|
447
|
+
* What Studio marked on a prototype's dials and variants, with the view
|
|
448
|
+
* the actor gets. A Client reads the marks too: their page needs a dial
|
|
449
|
+
* Studio switched back to internal as much as one it shared, and the
|
|
450
|
+
* names are in the prototype's own code already. An internal prototype
|
|
451
|
+
* has none for a Client, as it has no comments.
|
|
452
|
+
*/
|
|
453
|
+
async controlsOf(actor, prototype) {
|
|
454
|
+
allow(actor, 'read');
|
|
455
|
+
if (!isPrototypeSlug(prototype))
|
|
456
|
+
throw new ReviewError('invalid', 'Some fields are not valid.', ['prototype: a prototype slug']);
|
|
457
|
+
const view = viewOf(actor);
|
|
458
|
+
if (!(await reachable(view, prototype)))
|
|
459
|
+
throw new ReviewError('not_found', 'No such prototype.');
|
|
460
|
+
return { view, ...readMarks(await kv.hgetall(KEY.controls(prototype))) };
|
|
461
|
+
},
|
|
462
|
+
/**
|
|
463
|
+
* Marks one dial or one variant client-facing or internal. A dial's mark
|
|
464
|
+
* is stored either way, because it overrules what the code says; a
|
|
465
|
+
* variant's internal is the field's absence. Studio only. The server
|
|
466
|
+
* keeps no list of a prototype's controls, so any well-formed id is taken.
|
|
467
|
+
*/
|
|
468
|
+
async setControl(actor, input) {
|
|
469
|
+
allow(actor, 'audience');
|
|
470
|
+
const [slug, mark] = validAll(isPrototypeSlug(input.prototype)
|
|
471
|
+
? { ok: true, value: input.prototype }
|
|
472
|
+
: { ok: false, problems: ['prototype: a prototype slug'] }, checkControl(input));
|
|
473
|
+
const field = controlField(mark.kind, mark.id);
|
|
474
|
+
if (mark.kind === 'variant' && mark.audience === 'internal')
|
|
475
|
+
await kv.hdel(KEY.controls(slug), field);
|
|
476
|
+
else
|
|
477
|
+
await kv.hset(KEY.controls(slug), field, mark.audience);
|
|
478
|
+
return mark;
|
|
479
|
+
},
|
|
480
|
+
/**
|
|
481
|
+
* Who a prototype is for, asked by the gate with no actor. Absent, or any
|
|
482
|
+
* value but `client`, is internal; a name that cannot be a prototype is
|
|
483
|
+
* internal without asking the store.
|
|
484
|
+
*/
|
|
485
|
+
async audienceOf(prototype) {
|
|
486
|
+
return (await isClientFacing(prototype)) ? 'client' : 'internal';
|
|
487
|
+
},
|
|
488
|
+
/**
|
|
489
|
+
* What the index is built from: the view the actor gets (Client view for
|
|
490
|
+
* Studio with `viewAs: 'client'`) and every client-facing slug. The
|
|
491
|
+
* server keeps no list of internal ones: Studio's view reads the build's
|
|
492
|
+
* own list, which the gate refuses to a Client.
|
|
493
|
+
*/
|
|
494
|
+
async visiblePrototypes(actor, viewAs) {
|
|
495
|
+
allow(actor, 'read');
|
|
496
|
+
const view = viewOf(actor, valid(checkViewAs(viewAs)));
|
|
497
|
+
const all = await kv.hgetall(KEY.audiences);
|
|
498
|
+
const clientFacing = Object.entries(all)
|
|
499
|
+
.filter(([slug, value]) => value === 'client' && isPrototypeSlug(slug))
|
|
500
|
+
.map(([slug]) => slug)
|
|
501
|
+
.sort();
|
|
502
|
+
return { view, clientFacing };
|
|
503
|
+
},
|
|
410
504
|
/** Where a comment lives, for the CLI, which has an id and no prototype; null when the actor may not see it. */
|
|
411
505
|
async locate(actor, id) {
|
|
412
506
|
allow(actor, 'read');
|
|
@@ -21,12 +21,25 @@ export declare const KEY: {
|
|
|
21
21
|
/** Project settings, one field each: `access` is the default access length. */
|
|
22
22
|
readonly settings: "hub3:settings";
|
|
23
23
|
readonly prototypes: "hub3:prototypes";
|
|
24
|
+
/**
|
|
25
|
+
* Which prototypes are client-facing: field `<slug>`, value `client`. Only
|
|
26
|
+
* client-facing is stored; internal is the field's absence, and any other
|
|
27
|
+
* value reads as internal too.
|
|
28
|
+
*/
|
|
29
|
+
readonly audiences: "hub3:audiences";
|
|
24
30
|
/**
|
|
25
31
|
* The last thread number given on each prototype, only ever raised by HINCRBY: field
|
|
26
32
|
* `<prototype>` counts client-facing threads, `<prototype>:internal` internal ones.
|
|
27
33
|
*/
|
|
28
34
|
readonly counters: "hub3:counters";
|
|
29
35
|
readonly comments: (prototype: string) => string;
|
|
36
|
+
/**
|
|
37
|
+
* What Studio marked on one prototype's controls (core/controls.ts): field
|
|
38
|
+
* `dial:<id>` is `client` or `internal`, overruling the code either way;
|
|
39
|
+
* field `variant:<name>` is `client`, and internal is its absence. One
|
|
40
|
+
* field per control, so two people marking at once never undo each other.
|
|
41
|
+
*/
|
|
42
|
+
readonly controls: (prototype: string) => string;
|
|
30
43
|
};
|
|
31
44
|
export type Snapshot = {
|
|
32
45
|
hashes: Record<string, Record<string, string>>;
|
|
@@ -20,12 +20,25 @@ export const KEY = {
|
|
|
20
20
|
/** Project settings, one field each: `access` is the default access length. */
|
|
21
21
|
settings: `${PREFIX}settings`,
|
|
22
22
|
prototypes: `${PREFIX}prototypes`,
|
|
23
|
+
/**
|
|
24
|
+
* Which prototypes are client-facing: field `<slug>`, value `client`. Only
|
|
25
|
+
* client-facing is stored; internal is the field's absence, and any other
|
|
26
|
+
* value reads as internal too.
|
|
27
|
+
*/
|
|
28
|
+
audiences: `${PREFIX}audiences`,
|
|
23
29
|
/**
|
|
24
30
|
* The last thread number given on each prototype, only ever raised by HINCRBY: field
|
|
25
31
|
* `<prototype>` counts client-facing threads, `<prototype>:internal` internal ones.
|
|
26
32
|
*/
|
|
27
33
|
counters: `${PREFIX}counters`,
|
|
28
34
|
comments: (prototype) => `${PREFIX}comments:${prototype}`,
|
|
35
|
+
/**
|
|
36
|
+
* What Studio marked on one prototype's controls (core/controls.ts): field
|
|
37
|
+
* `dial:<id>` is `client` or `internal`, overruling the code either way;
|
|
38
|
+
* field `variant:<name>` is `client`, and internal is its absence. One
|
|
39
|
+
* field per control, so two people marking at once never undo each other.
|
|
40
|
+
*/
|
|
41
|
+
controls: (prototype) => `${PREFIX}controls:${prototype}`,
|
|
29
42
|
};
|
|
30
43
|
export function memoryKV(initial = { hashes: {}, sets: {} }, onChange) {
|
|
31
44
|
const hashes = new Map(Object.entries(initial.hashes).map(([k, v]) => [k, new Map(Object.entries(v))]));
|
package/dist/scripts/guard.d.ts
CHANGED
|
@@ -30,6 +30,17 @@ export type Finding = {
|
|
|
30
30
|
};
|
|
31
31
|
/** The feature folder a file belongs to, or null for anything outside prototypes/<slug>/. */
|
|
32
32
|
export declare function featureOf(file: string): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Whether a prototype stands on a Board: brand collateral, written to still
|
|
35
|
+
* files. Read from the change itself, else from the feature's own index.tsx,
|
|
36
|
+
* so its stylesheet is judged by what its markup stands on.
|
|
37
|
+
*/
|
|
38
|
+
export declare function standsOnBoard(change: Change, feature: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The View tools are set by what a prototype stands on, never by hand: the
|
|
41
|
+
* shells and Space mount them, and a Board has none.
|
|
42
|
+
*/
|
|
43
|
+
export declare function viewFindings(change: Change, board: boolean): Finding[];
|
|
33
44
|
export declare function codeFindings(change: Change): Finding[];
|
|
34
45
|
export declare function readmeStates(feature: string): string[];
|
|
35
46
|
export declare function jevFindings(change: Change, feature: string, ask?: typeof judge): Promise<Finding[]>;
|