@milesroxas/design-hub 0.6.0 → 0.6.2
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 +3 -3
- package/core/review/model.ts +12 -8
- package/core/review/policy.test.ts +60 -0
- package/core/review/policy.ts +13 -9
- package/core/review/service.test.ts +84 -44
- package/core/review/store.ts +11 -5
- package/dist/core/review/model.d.ts +6 -5
- package/dist/core/review/model.js +10 -6
- package/dist/core/review/policy.d.ts +4 -1
- package/dist/core/review/policy.js +4 -4
- package/dist/core/review/store.d.ts +3 -4
- package/dist/core/review/store.js +10 -5
- package/dist/scripts/bootstrap.js +1 -1
- package/dist/scripts/lib/review.js +3 -3
- package/dist/scripts/people.d.ts +4 -4
- package/dist/scripts/people.js +8 -8
- package/dist/scripts/share.js +1 -1
- package/dist/server/api.js +1 -1
- package/dist/server/dev.js +3 -3
- package/dist/server/local.d.ts +2 -2
- package/dist/server/local.js +4 -4
- package/kit/dials.css +9 -8
- package/kit/dials.tsx +39 -20
- package/kit/ui/Menu.tsx +14 -4
- package/kit/ui/ui.css +16 -3
- package/package.json +1 -1
- package/shell/review/Bar.tsx +5 -4
- package/shell/review/People.tsx +21 -15
- package/shell/review/Review.tsx +2 -1
- package/shell/review/ThreadCard.tsx +24 -21
- package/shell/review/client.ts +4 -4
- package/shell/review/review.css +7 -1
- package/skills/miles-deploy/SKILL.md +4 -4
- package/skills/miles-design-hub/SKILL.md +1 -1
- package/skills/miles-review/SKILL.md +2 -2
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ A speculation rule in `shell/index.html` prefetches a prototype's page when its
|
|
|
64
64
|
|
|
65
65
|
## The walkthrough
|
|
66
66
|
|
|
67
|
-
`/guide/<feature>/` is `docs/sprints/<feature>/guide.md`, rendered for reviewers who have the password but not the repo; `/guide/` alone opens the only guide, or lists them. The registry plugin lists the guides, so a new feature's walkthrough appears the moment the file exists (`design-hub guide <feature>` starts one from `templates/guide.md`). The Markdown stays the one source: a Vite plugin (`vite/markdown.ts`, the `?doc` import) compiles it at build time with `marked`, so nothing is parsed in the browser. It turns the first H1 into the title, every H2 and H3 into the contents rail, each image into a figure with its pixel size (no layout shift, lazy below the first), and `> [!NOTE]` quotes into callouts. A paragraph that starts `Controls → …` renders as a click path. Links to other Markdown files lose their href, since nothing serves them. The page reads at 16px on a 680px measure; screenshots and tables take the full 960px column, because a 1440px shot at 680px is unreadable. Two raw values: a screenshot wears a 1px inset outline at 10% (black on light, white on dark) and a callout a 6% ring (8% on dark), alphas rather than tokens because they composite on any surface the page is set on. The slug `guide` is the hub's (`design-hub new guide` refuses it). The page's **Open the prototype** button goes to the feature's sprint prototype, and every prototype of the feature answers with **Open the walkthrough** as the last row of Controls, under every group, in a new tab, so a reviewer reads and clicks side by side. A sheet inside the product was rejected: it would be modal over the thing under review, and testing aids never sit in the product chrome.
|
|
67
|
+
`/guide/<feature>/` is `docs/sprints/<feature>/guide.md`, rendered for reviewers who have the password but not the repo; `/guide/` alone opens the only guide, or lists them. The registry plugin lists the guides, so a new feature's walkthrough appears the moment the file exists (`design-hub guide <feature>` starts one from `templates/guide.md`). The Markdown stays the one source: a Vite plugin (`vite/markdown.ts`, the `?doc` import) compiles it at build time with `marked`, so nothing is parsed in the browser. It turns the first H1 into the title, every H2 and H3 into the contents rail, each image into a figure with its pixel size (no layout shift, lazy below the first), and `> [!NOTE]` quotes into callouts. A paragraph that starts `Controls → …` renders as a click path. Links to other Markdown files lose their href, since nothing serves them. The page reads at 16px on a 680px measure; screenshots and tables take the full 960px column, because a 1440px shot at 680px is unreadable. Two raw values: a screenshot wears a 1px inset outline at 10% (black on light, white on dark) and a callout a 6% ring (8% on dark), alphas rather than tokens because they composite on any surface the page is set on. The slug `guide` is the hub's (`design-hub new guide` refuses it). The page's **Open the prototype** button goes to the feature's sprint prototype, and every prototype of the feature answers with **Open the walkthrough** as the last row of Controls, under every group, in a new tab, so a reviewer reads and clicks side by side. Above it, on every prototype, **All prototypes** goes back to `/` in the same tab. A sheet inside the product was rejected: it would be modal over the thing under review, and testing aids never sit in the product chrome.
|
|
68
68
|
|
|
69
69
|
## Deploying, and the password
|
|
70
70
|
|
|
@@ -74,8 +74,8 @@ The middleware reads two environment variables, set in the Vercel project for Pr
|
|
|
74
74
|
|
|
75
75
|
## Comments and people
|
|
76
76
|
|
|
77
|
-
The password opens the site to view. To comment, a person needs their own invite link, made by
|
|
77
|
+
The password opens the site to view. To comment, a person needs their own invite link, made by Studio in the review panel's People tab or with `design-hub people invite`. Opening it shows who it is for and asks them to continue; the continue is a POST, so a mail scanner that opens every link never uses the invite. It sets a second signed cookie naming that person and their epoch, a counter a new link or a revoke bumps, which ends every session they hold on their next page load. The store keeps only a hash of each invite token, so a read of the store signs nobody in. A link lasts 14 days.
|
|
78
78
|
|
|
79
|
-
The panel (`shell/review/`) mounts on every prototype page in its own React root, so a prototype that throws never takes it down. A comment carries the prototype, the URL, every dial panel's values (`snapshotDials`), and the element it was pinned to as a selector path with an offset; Show state reopens the URL and sets the dials back. Pins draw over their elements and below the Controls panel. The API is one endpoint, `/api/review` (`server/api.ts`, reached on Vercel through the project's one-line `api/review.ts`, which also bundles the project's `checks.json` so triage runs on its thresholds): queries by GET, commands by POST with a JSON body, same-origin only. The rules (who may
|
|
79
|
+
The panel (`shell/review/`) mounts on every prototype page in its own React root, so a prototype that throws never takes it down. A comment carries the prototype, the URL, every dial panel's values (`snapshotDials`), and the element it was pinned to as a selector path with an offset; Show state reopens the URL and sets the dials back. Pins draw over their elements and below the Controls panel. The API is one endpoint, `/api/review` (`server/api.ts`, reached on Vercel through the project's one-line `api/review.ts`, which also bundles the project's `checks.json` so triage runs on its thresholds): queries by GET, commands by POST with a JSON body, same-origin only. The rules (who may delete, what a valid comment is) live once, in `core/review/`, behind a small storage port: Upstash Redis over REST when deployed, a file in `.design-hub/review.json` under `design-hub dev`, where whoever runs the server is a local Studio person.
|
|
80
80
|
|
|
81
81
|
`design-hub dev` serves the prototypes open, with the review panel on the local store. The gate is covered by `pnpm test` (`vercel/proxy.test.ts`, against an in-memory Upstash); `vercel dev` in a project runs it for real.
|
package/core/review/model.ts
CHANGED
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
|
|
7
7
|
import { SLUG } from '../feature.ts';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
export
|
|
9
|
+
/** Which side a person is on: the studio that makes the work, or the client it is for. */
|
|
10
|
+
export const PERSON_KINDS = ['studio', 'client'] as const;
|
|
11
|
+
export type PersonKind = (typeof PERSON_KINDS)[number];
|
|
11
12
|
|
|
12
13
|
/** How a comment is triaged: something broken, a design opinion, or the words. */
|
|
13
14
|
export const KINDS = ['bug', 'taste', 'copy'] as const;
|
|
14
15
|
export type Kind = (typeof KINDS)[number];
|
|
15
16
|
|
|
16
|
-
/** How long an invite link signs its person in before
|
|
17
|
+
/** How long an invite link signs its person in before Studio must issue a new one. */
|
|
17
18
|
export const INVITE_DAYS = 14;
|
|
18
19
|
|
|
19
20
|
export const LIMITS = {
|
|
@@ -32,7 +33,7 @@ export type Person = {
|
|
|
32
33
|
name: string;
|
|
33
34
|
/** The group a person belongs to, shown beside their name: the studio, or the client's company. */
|
|
34
35
|
team: string;
|
|
35
|
-
|
|
36
|
+
kind: PersonKind;
|
|
36
37
|
createdAt: string;
|
|
37
38
|
revokedAt: string | null;
|
|
38
39
|
/** Bumped on revoke and on a new invite, which signs out every session signed with the old one. */
|
|
@@ -99,14 +100,17 @@ const text = (v: unknown, path: string, max: number, problems: string[]): string
|
|
|
99
100
|
const fraction = (v: unknown) => typeof v === 'number' && Number.isFinite(v) && v >= 0 && v <= 1;
|
|
100
101
|
const size = (v: unknown) => typeof v === 'number' && Number.isFinite(v) && v >= 0 && v < 100_000;
|
|
101
102
|
|
|
102
|
-
export function checkPersonInput(input: unknown): Checked<Pick<Person, 'name' | 'team' | '
|
|
103
|
+
export function checkPersonInput(input: unknown): Checked<Pick<Person, 'name' | 'team' | 'kind'>> {
|
|
103
104
|
const i = (input ?? {}) as Record<string, unknown>;
|
|
104
105
|
const problems: string[] = [];
|
|
105
106
|
const name = text(i.name, 'name', LIMITS.name, problems);
|
|
106
107
|
const team = text(i.team, 'team', LIMITS.team, problems);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
// Most people invited are on the client's side; Studio is the deliberate choice.
|
|
109
|
+
const kind = i.kind ?? 'client';
|
|
110
|
+
if (!PERSON_KINDS.includes(kind as PersonKind)) problems.push(`kind: one of ${PERSON_KINDS.join(', ')}`);
|
|
111
|
+
return problems.length
|
|
112
|
+
? { ok: false, problems }
|
|
113
|
+
: { ok: true, value: { name, team, kind: kind as PersonKind } };
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
export function checkBody(body: unknown): Checked<string> {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import type { Comment, Person, PersonKind } from './model.ts';
|
|
4
|
+
import { type Action, can } from './policy.ts';
|
|
5
|
+
|
|
6
|
+
const person = (id: string, kind: PersonKind, revokedAt: string | null = null): Person => ({
|
|
7
|
+
id,
|
|
8
|
+
name: id,
|
|
9
|
+
team: kind === 'studio' ? 'Studio' : 'Acme',
|
|
10
|
+
kind,
|
|
11
|
+
createdAt: '',
|
|
12
|
+
revokedAt,
|
|
13
|
+
epoch: 0,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const thread = (author: string): Comment => ({
|
|
17
|
+
id: 'c',
|
|
18
|
+
thread: 'c',
|
|
19
|
+
author: { id: author, name: author, team: 'Acme' },
|
|
20
|
+
body: 'x',
|
|
21
|
+
createdAt: '',
|
|
22
|
+
editedAt: null,
|
|
23
|
+
anchor: null,
|
|
24
|
+
status: 'open',
|
|
25
|
+
resolvedBy: null,
|
|
26
|
+
triage: null,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// The rule table, one row per action: [Studio own, Studio other's, Client own, Client other's].
|
|
30
|
+
const TABLE: [Action, boolean, boolean, boolean, boolean][] = [
|
|
31
|
+
['read', true, true, true, true],
|
|
32
|
+
['comment', true, true, true, true],
|
|
33
|
+
['edit', true, false, true, false],
|
|
34
|
+
['resolve', true, true, true, true],
|
|
35
|
+
['delete', true, true, true, false],
|
|
36
|
+
['triage', true, true, false, false],
|
|
37
|
+
['people', true, true, false, false],
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const studio = person('s', 'studio');
|
|
41
|
+
const client = person('c', 'client');
|
|
42
|
+
|
|
43
|
+
for (const [action, studioOwn, studioOther, clientOwn, clientOther] of TABLE) {
|
|
44
|
+
test(`${action}: Studio and Client, own and another's`, () => {
|
|
45
|
+
assert.equal(can(studio, action, thread(studio.id)), studioOwn, 'Studio, own');
|
|
46
|
+
assert.equal(can(studio, action, thread('someone')), studioOther, "Studio, another's");
|
|
47
|
+
assert.equal(can(client, action, thread(client.id)), clientOwn, 'Client, own');
|
|
48
|
+
assert.equal(can(client, action, thread('someone')), clientOther, "Client, another's");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test(`${action}: nobody signed in and a revoked person may not`, () => {
|
|
52
|
+
for (const kind of ['studio', 'client'] as const) {
|
|
53
|
+
const gone = person('r', kind, '2030-01-01T00:00:00Z');
|
|
54
|
+
assert.equal(can(gone, action, thread(gone.id)), false, `revoked ${kind}, own`);
|
|
55
|
+
assert.equal(can(gone, action, thread('someone')), false, `revoked ${kind}, another's`);
|
|
56
|
+
}
|
|
57
|
+
assert.equal(can(null, action, thread('someone')), false, 'null');
|
|
58
|
+
assert.equal(can(null, action), false, 'null, no subject');
|
|
59
|
+
});
|
|
60
|
+
}
|
package/core/review/policy.ts
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
// Who may do what.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Who may do what. Studio runs the review: it invites and revokes people,
|
|
2
|
+
// deletes any comment and corrects triage. A Client comments, replies, edits
|
|
3
|
+
// and deletes what they wrote, and resolves or reopens any thread, because
|
|
4
|
+
// clients work alongside others in their own organisation. A revoked person,
|
|
5
|
+
// or a visitor with only the shared password, may do nothing here.
|
|
5
6
|
import type { Comment, Person } from './model.ts';
|
|
6
7
|
|
|
7
8
|
export type Action = 'read' | 'comment' | 'edit' | 'delete' | 'resolve' | 'triage' | 'people';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
/** Only what the rules read, so the browser's signed-in person (no epoch) is checked by the same rules. */
|
|
11
|
+
type Actor = Pick<Person, 'id' | 'kind' | 'revokedAt'>;
|
|
12
|
+
|
|
13
|
+
export function can(actor: Actor | null, action: Action, subject?: Comment): boolean {
|
|
10
14
|
if (!actor || actor.revokedAt) return false;
|
|
11
|
-
const
|
|
15
|
+
const studio = actor.kind === 'studio';
|
|
12
16
|
const own = subject?.author.id === actor.id;
|
|
13
17
|
switch (action) {
|
|
14
18
|
case 'read':
|
|
15
19
|
case 'comment':
|
|
20
|
+
case 'resolve':
|
|
16
21
|
return true;
|
|
17
22
|
case 'edit':
|
|
18
23
|
return own;
|
|
19
24
|
case 'delete':
|
|
20
|
-
|
|
21
|
-
return own || editor;
|
|
25
|
+
return own || studio;
|
|
22
26
|
case 'triage':
|
|
23
27
|
case 'people':
|
|
24
|
-
return
|
|
28
|
+
return studio;
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
|
|
|
2
2
|
import { beforeEach, test } from 'node:test';
|
|
3
3
|
import type { Anchor, Person } from './model.ts';
|
|
4
4
|
import { createReview, type Review, ReviewError } from './service.ts';
|
|
5
|
-
import { memoryKV } from './store.ts';
|
|
5
|
+
import { KEY, memoryKV } from './store.ts';
|
|
6
6
|
|
|
7
7
|
const anchor: Anchor = {
|
|
8
8
|
prototype: 'sample-list',
|
|
@@ -16,9 +16,9 @@ const anchor: Anchor = {
|
|
|
16
16
|
|
|
17
17
|
let clock = 0;
|
|
18
18
|
let review: Review;
|
|
19
|
-
let
|
|
20
|
-
let
|
|
21
|
-
let
|
|
19
|
+
let studio: Person;
|
|
20
|
+
let client: Person;
|
|
21
|
+
let clientToken: string;
|
|
22
22
|
|
|
23
23
|
const rejects = (p: Promise<unknown>, code: string) =>
|
|
24
24
|
assert.rejects(p, (e: unknown) => e instanceof ReviewError && e.code === code);
|
|
@@ -35,71 +35,111 @@ beforeEach(async () => {
|
|
|
35
35
|
id: 'cli',
|
|
36
36
|
name: 'CLI',
|
|
37
37
|
team: 'Studio',
|
|
38
|
-
|
|
38
|
+
kind: 'studio',
|
|
39
39
|
createdAt: '',
|
|
40
40
|
revokedAt: null,
|
|
41
41
|
epoch: 0,
|
|
42
42
|
} as Person;
|
|
43
|
-
|
|
44
|
-
const r = await review.invite(
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
studio = (await review.invite(root, { name: 'Ed', team: 'Studio', kind: 'studio' })).person;
|
|
44
|
+
const r = await review.invite(studio, { name: 'Rae', team: 'Acme' });
|
|
45
|
+
client = r.person;
|
|
46
|
+
clientToken = r.token;
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test('an invite signs its person in until it is reissued or revoked', async () => {
|
|
50
|
-
assert.equal((await review.acceptInvite(
|
|
51
|
-
const { token } = await review.reissue(
|
|
52
|
-
assert.equal(await review.acceptInvite(
|
|
50
|
+
assert.equal((await review.acceptInvite(clientToken))?.id, client.id);
|
|
51
|
+
const { token } = await review.reissue(studio, client.id);
|
|
52
|
+
assert.equal(await review.acceptInvite(clientToken), null);
|
|
53
53
|
assert.equal((await review.acceptInvite(token))?.epoch, 1);
|
|
54
|
-
await review.revoke(
|
|
54
|
+
await review.revoke(studio, client.id);
|
|
55
55
|
assert.equal(await review.acceptInvite(token), null);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
test('a reissue or revoke ends every session signed with the old epoch', async () => {
|
|
59
|
-
assert.ok(await review.sessionPerson(
|
|
60
|
-
await review.reissue(
|
|
61
|
-
assert.equal(await review.sessionPerson(
|
|
62
|
-
assert.ok(await review.sessionPerson(
|
|
63
|
-
await review.revoke(
|
|
64
|
-
assert.equal(await review.sessionPerson(
|
|
59
|
+
assert.ok(await review.sessionPerson(client.id, 0));
|
|
60
|
+
await review.reissue(studio, client.id);
|
|
61
|
+
assert.equal(await review.sessionPerson(client.id, 0), null);
|
|
62
|
+
assert.ok(await review.sessionPerson(client.id, 1));
|
|
63
|
+
await review.revoke(studio, client.id);
|
|
64
|
+
assert.equal(await review.sessionPerson(client.id, 2), null);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
test('an invite expires', async () => {
|
|
68
68
|
clock += 15 * 86_400_000;
|
|
69
|
-
assert.equal(await review.acceptInvite(
|
|
69
|
+
assert.equal(await review.acceptInvite(clientToken), null);
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
test('only
|
|
73
|
-
await rejects(review.invite(
|
|
72
|
+
test('only Studio manages people, and nobody revokes themselves', async () => {
|
|
73
|
+
await rejects(review.invite(client, { name: 'X', team: 'Acme' }), 'forbidden');
|
|
74
|
+
await rejects(review.listPeople(client), 'forbidden');
|
|
74
75
|
await rejects(review.listPeople(null), 'unauthorized');
|
|
75
|
-
await rejects(review.revoke(
|
|
76
|
+
await rejects(review.revoke(studio, studio.id), 'invalid');
|
|
76
77
|
assert.deepEqual(
|
|
77
|
-
(await review.listPeople(
|
|
78
|
+
(await review.listPeople(studio)).map((p) => p.name),
|
|
78
79
|
['Rae', 'Ed'],
|
|
79
80
|
);
|
|
80
81
|
});
|
|
81
82
|
|
|
82
83
|
test('a comment, its replies, resolving and deleting the thread', async () => {
|
|
83
|
-
const root = await review.add(
|
|
84
|
+
const root = await review.add(client, { body: ' Row height jumps on empty ', anchor });
|
|
84
85
|
assert.equal(root.body, 'Row height jumps on empty');
|
|
85
|
-
await review.reply(
|
|
86
|
-
assert.equal((await review.listComments(
|
|
87
|
-
const done = await review.resolve(
|
|
88
|
-
assert.equal(done.resolvedBy?.id,
|
|
89
|
-
assert.deepEqual((await review.remove(
|
|
90
|
-
assert.deepEqual(await review.listComments(
|
|
86
|
+
await review.reply(studio, { prototype: 'sample-list', thread: root.id, body: 'Fixed in v2' });
|
|
87
|
+
assert.equal((await review.listComments(client, 'sample-list')).length, 2);
|
|
88
|
+
const done = await review.resolve(client, { prototype: 'sample-list', id: root.id, resolved: true });
|
|
89
|
+
assert.equal(done.resolvedBy?.id, client.id);
|
|
90
|
+
assert.deepEqual((await review.remove(client, { prototype: 'sample-list', id: root.id })).length, 2);
|
|
91
|
+
assert.deepEqual(await review.listComments(studio, 'sample-list'), []);
|
|
91
92
|
});
|
|
92
93
|
|
|
93
|
-
test('
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
test('a new person is a Client unless named Studio, and any other kind is invalid', async () => {
|
|
95
|
+
assert.equal(client.kind, 'client');
|
|
96
|
+
assert.equal(studio.kind, 'studio');
|
|
97
|
+
await rejects(review.invite(studio, { name: 'X', team: 'Acme', kind: 'editor' }), 'invalid');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('a Client resolves and reopens anyone’s thread, but deletes only their own', async () => {
|
|
101
|
+
const c = await review.add(studio, { body: 'Spacing off', anchor });
|
|
102
|
+
const other = (await review.invite(studio, { name: 'Oz', team: 'Acme' })).person;
|
|
103
|
+
const done = await review.resolve(other, { prototype: 'sample-list', id: c.id, resolved: true });
|
|
104
|
+
assert.equal(done.resolvedBy?.id, other.id);
|
|
105
|
+
const open = await review.resolve(client, { prototype: 'sample-list', id: c.id, resolved: false });
|
|
106
|
+
assert.equal(open.status, 'open');
|
|
107
|
+
await rejects(review.remove(client, { prototype: 'sample-list', id: c.id }), 'forbidden');
|
|
108
|
+
const reply = await review.reply(other, { prototype: 'sample-list', thread: c.id, body: 'Agreed' });
|
|
109
|
+
await rejects(review.remove(client, { prototype: 'sample-list', id: reply.id }), 'forbidden');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('Studio resolves and deletes anyone’s thread', async () => {
|
|
113
|
+
const c = await review.add(client, { body: 'Wrong icon', anchor });
|
|
114
|
+
const done = await review.resolve(studio, { prototype: 'sample-list', id: c.id, resolved: true });
|
|
115
|
+
assert.equal(done.resolvedBy?.id, studio.id);
|
|
116
|
+
assert.deepEqual(await review.remove(studio, { prototype: 'sample-list', id: c.id }), [c.id]);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('records under the old key prefix are never read', async () => {
|
|
120
|
+
const old: Person = { ...client, id: 'old', name: 'Old' };
|
|
121
|
+
const kv = memoryKV({
|
|
122
|
+
hashes: {
|
|
123
|
+
'hub:people': { old: JSON.stringify(old) },
|
|
124
|
+
'hub:comments:sample-list': { x: JSON.stringify({ id: 'x', thread: 'x' }) },
|
|
125
|
+
},
|
|
126
|
+
sets: { 'hub:prototypes': ['sample-list'] },
|
|
127
|
+
});
|
|
128
|
+
const fresh = createReview(kv);
|
|
129
|
+
assert.ok(KEY.people.startsWith('hub2:'));
|
|
130
|
+
assert.equal(await fresh.person('old'), null);
|
|
131
|
+
assert.deepEqual(await fresh.allComments(), []);
|
|
132
|
+
assert.equal(await fresh.locate('x'), null);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('people edit only their own words; Studio triages anything', async () => {
|
|
136
|
+
const c = await review.add(client, { body: 'Typo in header', anchor });
|
|
137
|
+
await rejects(review.edit(studio, { prototype: 'sample-list', id: c.id, body: 'x' }), 'forbidden');
|
|
98
138
|
await rejects(
|
|
99
|
-
review.retriage(
|
|
139
|
+
review.retriage(client, { prototype: 'sample-list', id: c.id, triage: { kind: 'copy' } }),
|
|
100
140
|
'forbidden',
|
|
101
141
|
);
|
|
102
|
-
const t = await review.retriage(
|
|
142
|
+
const t = await review.retriage(studio, {
|
|
103
143
|
prototype: 'sample-list',
|
|
104
144
|
id: c.id,
|
|
105
145
|
triage: { kind: 'copy', state: 'Empty' },
|
|
@@ -107,7 +147,7 @@ test('people edit only their own words; editors resolve and triage anything', as
|
|
|
107
147
|
});
|
|
108
148
|
assert.deepEqual(t.triage, { kind: 'copy', state: 'Empty', by: 'person', confidence: null });
|
|
109
149
|
await rejects(
|
|
110
|
-
review.retriage(
|
|
150
|
+
review.retriage(studio, {
|
|
111
151
|
prototype: 'sample-list',
|
|
112
152
|
id: c.id,
|
|
113
153
|
triage: { state: 'Nope' },
|
|
@@ -118,14 +158,14 @@ test('people edit only their own words; editors resolve and triage anything', as
|
|
|
118
158
|
});
|
|
119
159
|
|
|
120
160
|
test('a revoked person and a password-only visitor can do nothing', async () => {
|
|
121
|
-
const gone = await review.revoke(
|
|
161
|
+
const gone = await review.revoke(studio, client.id);
|
|
122
162
|
await rejects(review.add(gone, { body: 'x', anchor }), 'forbidden');
|
|
123
163
|
await rejects(review.add(null, { body: 'x', anchor }), 'unauthorized');
|
|
124
164
|
});
|
|
125
165
|
|
|
126
166
|
test('bad input names every problem', async () => {
|
|
127
167
|
await assert.rejects(
|
|
128
|
-
review.add(
|
|
168
|
+
review.add(client, { body: '', anchor: { ...anchor, url: 'x', offset: { x: 2, y: 0 } } }),
|
|
129
169
|
(e: unknown) => {
|
|
130
170
|
assert.ok(e instanceof ReviewError);
|
|
131
171
|
assert.deepEqual(
|
|
@@ -145,7 +185,7 @@ test('triage runs on add, and a failing triager never loses the comment', async
|
|
|
145
185
|
return { kind: 'bug', state: states[0] ?? null, by: 'jev', confidence: 0.9 };
|
|
146
186
|
},
|
|
147
187
|
});
|
|
148
|
-
const c = await triaged.add(
|
|
188
|
+
const c = await triaged.add(client, {
|
|
149
189
|
body: 'Broken',
|
|
150
190
|
anchor,
|
|
151
191
|
states: ['Empty', 'Empty', ' Real list '],
|
|
@@ -153,11 +193,11 @@ test('triage runs on add, and a failing triager never loses the comment', async
|
|
|
153
193
|
assert.deepEqual(seen, [['Empty', 'Real list']]);
|
|
154
194
|
assert.equal(c.triage?.kind, 'bug');
|
|
155
195
|
const failing = createReview(memoryKV(), { triage: async () => Promise.reject(new Error('down')) });
|
|
156
|
-
assert.equal((await failing.add(
|
|
196
|
+
assert.equal((await failing.add(client, { body: 'Still saved', anchor })).triage, null);
|
|
157
197
|
});
|
|
158
198
|
|
|
159
199
|
test('locate finds a comment by id alone', async () => {
|
|
160
|
-
const c = await review.add(
|
|
200
|
+
const c = await review.add(client, { body: 'Here', anchor });
|
|
161
201
|
assert.equal((await review.locate(c.id))?.prototype, 'sample-list');
|
|
162
202
|
assert.equal(await review.locate('nope'), null);
|
|
163
203
|
});
|
package/core/review/store.ts
CHANGED
|
@@ -12,12 +12,18 @@ export interface KV {
|
|
|
12
12
|
smembers(key: string): Promise<string[]>;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Every key the hub writes starts here, so a shared Redis never mixes it with
|
|
17
|
+
* another app's data. Bumped when the stored shapes change without a
|
|
18
|
+
* migration: records under an older prefix are simply never read.
|
|
19
|
+
*/
|
|
20
|
+
const PREFIX = 'hub2:';
|
|
21
|
+
|
|
16
22
|
export const KEY = {
|
|
17
|
-
people:
|
|
18
|
-
invites:
|
|
19
|
-
prototypes:
|
|
20
|
-
comments: (prototype: string) =>
|
|
23
|
+
people: `${PREFIX}people`,
|
|
24
|
+
invites: `${PREFIX}invites`,
|
|
25
|
+
prototypes: `${PREFIX}prototypes`,
|
|
26
|
+
comments: (prototype: string) => `${PREFIX}comments:${prototype}`,
|
|
21
27
|
} as const;
|
|
22
28
|
|
|
23
29
|
export type Snapshot = { hashes: Record<string, Record<string, string>>; sets: Record<string, string[]> };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
/** Which side a person is on: the studio that makes the work, or the client it is for. */
|
|
2
|
+
export declare const PERSON_KINDS: readonly ['studio', 'client'];
|
|
3
|
+
export type PersonKind = (typeof PERSON_KINDS)[number];
|
|
3
4
|
/** How a comment is triaged: something broken, a design opinion, or the words. */
|
|
4
5
|
export declare const KINDS: readonly ['bug', 'taste', 'copy'];
|
|
5
6
|
export type Kind = (typeof KINDS)[number];
|
|
6
|
-
/** How long an invite link signs its person in before
|
|
7
|
+
/** How long an invite link signs its person in before Studio must issue a new one. */
|
|
7
8
|
export declare const INVITE_DAYS = 14;
|
|
8
9
|
export declare const LIMITS: {
|
|
9
10
|
readonly name: 80;
|
|
@@ -20,7 +21,7 @@ export type Person = {
|
|
|
20
21
|
name: string;
|
|
21
22
|
/** The group a person belongs to, shown beside their name: the studio, or the client's company. */
|
|
22
23
|
team: string;
|
|
23
|
-
|
|
24
|
+
kind: PersonKind;
|
|
24
25
|
createdAt: string;
|
|
25
26
|
revokedAt: string | null;
|
|
26
27
|
/** Bumped on revoke and on a new invite, which signs out every session signed with the old one. */
|
|
@@ -77,7 +78,7 @@ export type Checked<T> = {
|
|
|
77
78
|
ok: false;
|
|
78
79
|
problems: string[];
|
|
79
80
|
};
|
|
80
|
-
export declare function checkPersonInput(input: unknown): Checked<Pick<Person, 'name' | 'team' | '
|
|
81
|
+
export declare function checkPersonInput(input: unknown): Checked<Pick<Person, 'name' | 'team' | 'kind'>>;
|
|
81
82
|
export declare function checkBody(body: unknown): Checked<string>;
|
|
82
83
|
export declare function checkAnchor(input: unknown): Checked<Anchor>;
|
|
83
84
|
/** The README states a client offers for triage: trimmed, capped, de-duplicated. */
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
// enforced by the service, whichever adapter (Vercel, Vite dev, the CLI)
|
|
5
5
|
// calls it.
|
|
6
6
|
import { SLUG } from '../feature.js';
|
|
7
|
-
|
|
7
|
+
/** Which side a person is on: the studio that makes the work, or the client it is for. */
|
|
8
|
+
export const PERSON_KINDS = ['studio', 'client'];
|
|
8
9
|
/** How a comment is triaged: something broken, a design opinion, or the words. */
|
|
9
10
|
export const KINDS = ['bug', 'taste', 'copy'];
|
|
10
|
-
/** How long an invite link signs its person in before
|
|
11
|
+
/** How long an invite link signs its person in before Studio must issue a new one. */
|
|
11
12
|
export const INVITE_DAYS = 14;
|
|
12
13
|
export const LIMITS = {
|
|
13
14
|
name: 80,
|
|
@@ -38,10 +39,13 @@ export function checkPersonInput(input) {
|
|
|
38
39
|
const problems = [];
|
|
39
40
|
const name = text(i.name, 'name', LIMITS.name, problems);
|
|
40
41
|
const team = text(i.team, 'team', LIMITS.team, problems);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
// Most people invited are on the client's side; Studio is the deliberate choice.
|
|
43
|
+
const kind = i.kind ?? 'client';
|
|
44
|
+
if (!PERSON_KINDS.includes(kind))
|
|
45
|
+
problems.push(`kind: one of ${PERSON_KINDS.join(', ')}`);
|
|
46
|
+
return problems.length
|
|
47
|
+
? { ok: false, problems }
|
|
48
|
+
: { ok: true, value: { name, team, kind: kind } };
|
|
45
49
|
}
|
|
46
50
|
export function checkBody(body) {
|
|
47
51
|
const problems = [];
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { Comment, Person } from './model.ts';
|
|
2
2
|
export type Action = 'read' | 'comment' | 'edit' | 'delete' | 'resolve' | 'triage' | 'people';
|
|
3
|
-
|
|
3
|
+
/** Only what the rules read, so the browser's signed-in person (no epoch) is checked by the same rules. */
|
|
4
|
+
type Actor = Pick<Person, 'id' | 'kind' | 'revokedAt'>;
|
|
5
|
+
export declare function can(actor: Actor | null, action: Action, subject?: Comment): boolean;
|
|
6
|
+
export {};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export function can(actor, action, subject) {
|
|
2
2
|
if (!actor || actor.revokedAt)
|
|
3
3
|
return false;
|
|
4
|
-
const
|
|
4
|
+
const studio = actor.kind === 'studio';
|
|
5
5
|
const own = subject?.author.id === actor.id;
|
|
6
6
|
switch (action) {
|
|
7
7
|
case 'read':
|
|
8
8
|
case 'comment':
|
|
9
|
+
case 'resolve':
|
|
9
10
|
return true;
|
|
10
11
|
case 'edit':
|
|
11
12
|
return own;
|
|
12
13
|
case 'delete':
|
|
13
|
-
|
|
14
|
-
return own || editor;
|
|
14
|
+
return own || studio;
|
|
15
15
|
case 'triage':
|
|
16
16
|
case 'people':
|
|
17
|
-
return
|
|
17
|
+
return studio;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -6,11 +6,10 @@ export interface KV {
|
|
|
6
6
|
sadd(key: string, member: string): Promise<void>;
|
|
7
7
|
smembers(key: string): Promise<string[]>;
|
|
8
8
|
}
|
|
9
|
-
/** Every key the hub writes starts here, so a shared Redis never mixes it with another app's data. */
|
|
10
9
|
export declare const KEY: {
|
|
11
|
-
readonly people:
|
|
12
|
-
readonly invites:
|
|
13
|
-
readonly prototypes:
|
|
10
|
+
readonly people: "hub2:people";
|
|
11
|
+
readonly invites: "hub2:invites";
|
|
12
|
+
readonly prototypes: "hub2:prototypes";
|
|
14
13
|
readonly comments: (prototype: string) => string;
|
|
15
14
|
};
|
|
16
15
|
export type Snapshot = {
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
// and set operations. Production is Upstash Redis over REST
|
|
3
3
|
// (server/upstash.ts); dev and tests use the in-memory store below, which
|
|
4
4
|
// the dev server persists to a file (server/file-kv.ts).
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Every key the hub writes starts here, so a shared Redis never mixes it with
|
|
7
|
+
* another app's data. Bumped when the stored shapes change without a
|
|
8
|
+
* migration: records under an older prefix are simply never read.
|
|
9
|
+
*/
|
|
10
|
+
const PREFIX = 'hub2:';
|
|
6
11
|
export const KEY = {
|
|
7
|
-
people:
|
|
8
|
-
invites:
|
|
9
|
-
prototypes:
|
|
10
|
-
comments: (prototype) =>
|
|
12
|
+
people: `${PREFIX}people`,
|
|
13
|
+
invites: `${PREFIX}invites`,
|
|
14
|
+
prototypes: `${PREFIX}prototypes`,
|
|
15
|
+
comments: (prototype) => `${PREFIX}comments:${prototype}`,
|
|
11
16
|
};
|
|
12
17
|
export function memoryKV(initial = { hashes: {}, sets: {} }, onChange) {
|
|
13
18
|
const hashes = new Map(Object.entries(initial.hashes).map(([k, v]) => [k, new Map(Object.entries(v))]));
|
|
@@ -366,7 +366,7 @@ function setUpVercel(project, flags, env, typesafeKey, warnings) {
|
|
|
366
366
|
};
|
|
367
367
|
if (!flags.review)
|
|
368
368
|
return result;
|
|
369
|
-
warnings.push('Run design-hub share so the new env reaches the site; then design-hub people invite --name "<you>" --
|
|
369
|
+
warnings.push('Run design-hub share so the new env reaches the site; then design-hub people invite --name "<you>" --kind studio --site <url>.');
|
|
370
370
|
return { ...result, review: provisionReview(project, flags.team, warnings) };
|
|
371
371
|
}
|
|
372
372
|
function envIgnored(warnings) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
// The review service from the command line: the deployed store when its
|
|
3
3
|
// credentials are in .env (`design-hub bootstrap --review` puts them there), else
|
|
4
|
-
// the local one the dev server uses. The CLI acts as
|
|
4
|
+
// the local one the dev server uses. The CLI acts as Studio, because
|
|
5
5
|
// whoever holds the store's credentials can already do anything to it.
|
|
6
6
|
import { createReview } from '../../core/review/service.js';
|
|
7
7
|
import { jevTriager } from '../../core/review/triage.js';
|
|
8
8
|
import { checks } from '../../server/checks.js';
|
|
9
9
|
import { readEnv } from '../../server/env.js';
|
|
10
10
|
import { fileKV } from '../../server/file-kv.js';
|
|
11
|
-
import { LOCAL_STORE,
|
|
11
|
+
import { LOCAL_STORE, localStudio } from '../../server/local.js';
|
|
12
12
|
import { ROOT } from '../../server/paths.js';
|
|
13
13
|
import { storeConfig, upstashKV } from '../../server/upstash.js';
|
|
14
14
|
export function cliReview(local) {
|
|
@@ -19,4 +19,4 @@ export function cliReview(local) {
|
|
|
19
19
|
? { review: createReview(upstashKV(config), { triage }), store: 'deployed' }
|
|
20
20
|
: { review: createReview(fileKV(LOCAL_STORE), { triage }), store: 'local' };
|
|
21
21
|
}
|
|
22
|
-
export const cliActor = () =>
|
|
22
|
+
export const cliActor = () => localStudio('cli', 'CLI');
|
package/dist/scripts/people.d.ts
CHANGED
|
@@ -19,11 +19,11 @@ export declare const spec: {
|
|
|
19
19
|
readonly type: 'string';
|
|
20
20
|
readonly description: "For invite: the studio, or the client's company.";
|
|
21
21
|
};
|
|
22
|
-
readonly
|
|
22
|
+
readonly kind: {
|
|
23
23
|
readonly type: 'string';
|
|
24
|
-
readonly default: '
|
|
25
|
-
readonly choices: readonly ["
|
|
26
|
-
readonly description: '
|
|
24
|
+
readonly default: 'client';
|
|
25
|
+
readonly choices: readonly ["studio", "client"];
|
|
26
|
+
readonly description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts and invites.';
|
|
27
27
|
};
|
|
28
28
|
readonly site: {
|
|
29
29
|
readonly type: 'string';
|