@milesroxas/design-hub 0.6.1 → 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 CHANGED
@@ -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 an editor 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.
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 resolve, 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 editor.
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.
@@ -6,14 +6,15 @@
6
6
 
7
7
  import { SLUG } from '../feature.ts';
8
8
 
9
- export const ROLES = ['editor', 'reviewer'] as const;
10
- export type Role = (typeof ROLES)[number];
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 an editor must issue a new one. */
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
- role: Role;
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' | 'role'>> {
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
- const role = i.role ?? 'reviewer';
108
- if (!ROLES.includes(role as Role)) problems.push(`role: one of ${ROLES.join(', ')}`);
109
- return problems.length ? { ok: false, problems } : { ok: true, value: { name, team, role: role as Role } };
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
+ }
@@ -1,26 +1,30 @@
1
- // Who may do what. Editors run the review: they invite and revoke people,
2
- // resolve any thread and correct triage. Reviewers comment, reply, and edit
3
- // or delete what they wrote, and resolve threads they started. A revoked
4
- // person, or a visitor with only the shared password, may do nothing here.
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
- export function can(actor: Person | null, action: Action, subject?: Comment): boolean {
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 editor = actor.role === 'editor';
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
- case 'resolve':
21
- return own || editor;
25
+ return own || studio;
22
26
  case 'triage':
23
27
  case 'people':
24
- return editor;
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 editor: Person;
20
- let reviewer: Person;
21
- let reviewerToken: string;
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
- role: 'editor',
38
+ kind: 'studio',
39
39
  createdAt: '',
40
40
  revokedAt: null,
41
41
  epoch: 0,
42
42
  } as Person;
43
- editor = (await review.invite(root, { name: 'Ed', team: 'Studio', role: 'editor' })).person;
44
- const r = await review.invite(editor, { name: 'Rae', team: 'Acme' });
45
- reviewer = r.person;
46
- reviewerToken = r.token;
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(reviewerToken))?.id, reviewer.id);
51
- const { token } = await review.reissue(editor, reviewer.id);
52
- assert.equal(await review.acceptInvite(reviewerToken), null);
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(editor, reviewer.id);
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(reviewer.id, 0));
60
- await review.reissue(editor, reviewer.id);
61
- assert.equal(await review.sessionPerson(reviewer.id, 0), null);
62
- assert.ok(await review.sessionPerson(reviewer.id, 1));
63
- await review.revoke(editor, reviewer.id);
64
- assert.equal(await review.sessionPerson(reviewer.id, 2), null);
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(reviewerToken), null);
69
+ assert.equal(await review.acceptInvite(clientToken), null);
70
70
  });
71
71
 
72
- test('only editors manage people, and nobody revokes themselves', async () => {
73
- await rejects(review.invite(reviewer, { name: 'X', team: 'Acme' }), 'forbidden');
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(editor, editor.id), 'invalid');
76
+ await rejects(review.revoke(studio, studio.id), 'invalid');
76
77
  assert.deepEqual(
77
- (await review.listPeople(editor)).map((p) => p.name),
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(reviewer, { body: ' Row height jumps on empty ', anchor });
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(editor, { prototype: 'sample-list', thread: root.id, body: 'Fixed in v2' });
86
- assert.equal((await review.listComments(reviewer, 'sample-list')).length, 2);
87
- const done = await review.resolve(reviewer, { prototype: 'sample-list', id: root.id, resolved: true });
88
- assert.equal(done.resolvedBy?.id, reviewer.id);
89
- assert.deepEqual((await review.remove(reviewer, { prototype: 'sample-list', id: root.id })).length, 2);
90
- assert.deepEqual(await review.listComments(editor, 'sample-list'), []);
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('people edit only their own words; editors resolve and triage anything', async () => {
94
- const c = await review.add(reviewer, { body: 'Typo in header', anchor });
95
- await rejects(review.edit(editor, { prototype: 'sample-list', id: c.id, body: 'x' }), 'forbidden');
96
- const other = (await review.invite(editor, { name: 'Oz', team: 'Acme' })).person;
97
- await rejects(review.resolve(other, { prototype: 'sample-list', id: c.id, resolved: true }), 'forbidden');
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(reviewer, { prototype: 'sample-list', id: c.id, triage: { kind: 'copy' } }),
139
+ review.retriage(client, { prototype: 'sample-list', id: c.id, triage: { kind: 'copy' } }),
100
140
  'forbidden',
101
141
  );
102
- const t = await review.retriage(editor, {
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(editor, {
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(editor, reviewer.id);
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(reviewer, { body: '', anchor: { ...anchor, url: 'x', offset: { x: 2, y: 0 } } }),
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(reviewer, {
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(reviewer, { body: 'Still saved', anchor })).triage, null);
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(reviewer, { body: 'Here', anchor });
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
  });
@@ -12,12 +12,18 @@ export interface KV {
12
12
  smembers(key: string): Promise<string[]>;
13
13
  }
14
14
 
15
- /** Every key the hub writes starts here, so a shared Redis never mixes it with another app's data. */
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: 'hub:people',
18
- invites: 'hub:invites',
19
- prototypes: 'hub:prototypes',
20
- comments: (prototype: string) => `hub:comments:${prototype}`,
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
- export declare const ROLES: readonly ['editor', 'reviewer'];
2
- export type Role = (typeof ROLES)[number];
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 an editor must issue a new one. */
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
- role: Role;
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' | 'role'>>;
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
- export const ROLES = ['editor', 'reviewer'];
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 an editor must issue a new one. */
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
- const role = i.role ?? 'reviewer';
42
- if (!ROLES.includes(role))
43
- problems.push(`role: one of ${ROLES.join(', ')}`);
44
- return problems.length ? { ok: false, problems } : { ok: true, value: { name, team, role: role } };
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
- export declare function can(actor: Person | null, action: Action, subject?: Comment): boolean;
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 editor = actor.role === 'editor';
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
- case 'resolve':
14
- return own || editor;
14
+ return own || studio;
15
15
  case 'triage':
16
16
  case 'people':
17
- return editor;
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: 'hub:people';
12
- readonly invites: 'hub:invites';
13
- readonly prototypes: 'hub: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
- /** Every key the hub writes starts here, so a shared Redis never mixes it with another app's data. */
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: 'hub:people',
8
- invites: 'hub:invites',
9
- prototypes: 'hub:prototypes',
10
- comments: (prototype) => `hub: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>" --role editor --site <url>.');
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 an editor, because
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, localEditor } from '../../server/local.js';
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 = () => localEditor('cli', 'CLI');
22
+ export const cliActor = () => localStudio('cli', 'CLI');
@@ -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 role: {
22
+ readonly kind: {
23
23
  readonly type: 'string';
24
- readonly default: 'reviewer';
25
- readonly choices: readonly ["editor", "reviewer"];
26
- readonly description: 'reviewer comments; editor also resolves, sorts and invites.';
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';
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  /// <reference types="node" />
3
- // The people who comment on the deployed prototypes. The first editor is
4
- // invited from here; after that, editors invite from the People tab.
5
- import { ROLES } from '../core/review/model.js';
3
+ // The people who comment on the deployed prototypes. The first Studio person
4
+ // is invited from here; after that, Studio invites from the People tab.
5
+ import { PERSON_KINDS } from '../core/review/model.js';
6
6
  import { CliError } from './lib/cli.js';
7
7
  import { cliActor, cliReview } from './lib/review.js';
8
8
  export const spec = {
@@ -18,11 +18,11 @@ export const spec = {
18
18
  flags: {
19
19
  name: { type: 'string', description: 'For invite: their name as it shows on comments.' },
20
20
  team: { type: 'string', description: "For invite: the studio, or the client's company." },
21
- role: {
21
+ kind: {
22
22
  type: 'string',
23
- default: 'reviewer',
24
- choices: ROLES,
25
- description: 'reviewer comments; editor also resolves, sorts and invites.',
23
+ default: 'client',
24
+ choices: PERSON_KINDS,
25
+ description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts and invites.',
26
26
  },
27
27
  site: { type: 'string', description: 'The deployed URL, so the invite link prints whole.' },
28
28
  local: {
@@ -54,7 +54,7 @@ export async function main({ positionals: [action = 'list', id], flags }) {
54
54
  const { person, token } = await review.invite(actor, {
55
55
  name: flags.name,
56
56
  team: flags.team,
57
- role: flags.role,
57
+ kind: flags.kind,
58
58
  });
59
59
  return { store, person: strip(person), ...linkFor(token, flags.site) };
60
60
  }
@@ -156,7 +156,7 @@ function handover(url) {
156
156
  share: { url, password: env.GATE_PASSWORD ?? null, open: opens() },
157
157
  review,
158
158
  next: review === 'on'
159
- ? `Send the handover (miles-deploy). First share with comments: design-hub people invite --name "<user>" --role editor --site ${url}.`
159
+ ? `Send the handover (miles-deploy). First share with comments: design-hub people invite --name "<user>" --kind studio --site ${url}.`
160
160
  : 'Send the handover (miles-deploy). Never send GATE_SECRET.',
161
161
  };
162
162
  }
@@ -62,7 +62,7 @@ async function command(op, b, { review, actor }) {
62
62
  case 'comment.triage':
63
63
  return { comment: await review.retriage(actor, { ...at(), triage: b.triage, states: b.states }) };
64
64
  case 'people.invite':
65
- return link(await review.invite(actor, { name: b.name, team: b.team, role: b.role }));
65
+ return link(await review.invite(actor, { name: b.name, team: b.team, kind: b.kind }));
66
66
  case 'people.reissue':
67
67
  return link(await review.reissue(actor, str(b.id)));
68
68
  case 'people.revoke':
@@ -5,7 +5,7 @@ import { API_PATH, handleReview } from './api.js';
5
5
  import { checks } from './checks.js';
6
6
  import { readEnv } from './env.js';
7
7
  import { fileKV } from './file-kv.js';
8
- import { LOCAL_STORE, localEditor } from './local.js';
8
+ import { LOCAL_STORE, localStudio } from './local.js';
9
9
  import { ROOT } from './paths.js';
10
10
  // Connect strips the mount path from req.url; originalUrl keeps the query the handler reads.
11
11
  async function toRequest(req) {
@@ -40,8 +40,8 @@ export function devReview() {
40
40
  const review = createReview(kv, {
41
41
  triage: jevTriager(readEnv(ROOT).TYPESAFE_API_KEY ?? '', checks),
42
42
  });
43
- const actor = localEditor();
44
- // The local editor is in the people list like anyone else, so the people panel shows them.
43
+ const actor = localStudio();
44
+ // The local Studio person is in the people list like anyone else, so the people panel shows them.
45
45
  void kv.hset(KEY.people, actor.id, JSON.stringify(actor));
46
46
  server.middlewares.use(API_PATH, (req, res, nextMiddleware) => {
47
47
  toRequest(req)
@@ -1,4 +1,4 @@
1
1
  import type { Person } from '../core/review/model.ts';
2
2
  export declare const LOCAL_STORE: string;
3
- /** Whoever runs this machine's dev server or CLI: an editor, because they hold the store itself. */
4
- export declare const localEditor: (id?: string, team?: string) => Person;
3
+ /** Whoever runs this machine's dev server or CLI: Studio, because they hold the store itself. */
4
+ export declare const localStudio: (id?: string, team?: string) => Person;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  // The review store and identity on this machine, shared by the dev server
3
- // and the CLI: .design-hub/review.json, and a local editor named from git.
3
+ // and the CLI: .design-hub/review.json, and a local Studio person named from git.
4
4
  import { execFileSync } from 'node:child_process';
5
5
  import { join } from 'node:path';
6
6
  import { STATE_DIR } from './paths.js';
@@ -13,12 +13,12 @@ function gitName() {
13
13
  return '';
14
14
  }
15
15
  }
16
- /** Whoever runs this machine's dev server or CLI: an editor, because they hold the store itself. */
17
- export const localEditor = (id = 'local', team = 'Local') => ({
16
+ /** Whoever runs this machine's dev server or CLI: Studio, because they hold the store itself. */
17
+ export const localStudio = (id = 'local', team = 'Local') => ({
18
18
  id,
19
19
  name: gitName() || 'You',
20
20
  team,
21
- role: 'editor',
21
+ kind: 'studio',
22
22
  createdAt: new Date(0).toISOString(),
23
23
  revokedAt: null,
24
24
  epoch: 0,
package/kit/ui/Menu.tsx CHANGED
@@ -327,6 +327,8 @@ function MenuRow({
327
327
  disabled={item.disabled}
328
328
  data-label={item.label}
329
329
  onClick={() => onPick(item)}
330
+ // The pointer takes the highlight from the keyboard, so one row is lit, never two.
331
+ onPointerMove={(e) => e.currentTarget.focus({ preventScroll: true })}
330
332
  >
331
333
  {item.icon ? (
332
334
  <span className="menu-glyph">
@@ -347,7 +349,11 @@ function MenuRow({
347
349
  );
348
350
  }
349
351
 
350
- export type SelectOption = { value: string; label: string };
352
+ /** `desc` is a second, quieter line in the list; the closed control shows the label alone. */
353
+ const selectValueClass = (set: boolean, picked: boolean) =>
354
+ ['select-value', !set && 'is-placeholder', picked && 'is-picked'].filter(Boolean).join(' ');
355
+
356
+ export type SelectOption = { value: string; label: string; desc?: string };
351
357
 
352
358
  export function Select({
353
359
  value,
@@ -371,17 +377,21 @@ export function Select({
371
377
  'aria-label'?: string;
372
378
  }) {
373
379
  const valueId = useId();
380
+ // Set on the first pick, so the value settles in when it changes and not when the control mounts.
381
+ const picked = useRef(false);
374
382
  const current = options.find((o) => o.value === value);
375
383
  const menu = useMenu({
376
384
  role: 'listbox',
377
385
  align: 'start',
378
- items: options.map((o) => ({ label: o.label, value: o.value })),
386
+ items: options.map((o) => ({ label: o.label, value: o.value, desc: o.desc })),
379
387
  selected: value ?? undefined,
380
388
  label: ariaLabel,
381
389
  className: menuClassName,
382
390
  width: (trigger) => Math.max(trigger.offsetWidth, width || 0),
383
391
  onSelect: (v) => {
384
- if (v != null && v !== value) onChange(v);
392
+ if (v == null || v === value) return;
393
+ picked.current = true;
394
+ onChange(v);
385
395
  },
386
396
  });
387
397
  return (
@@ -399,7 +409,7 @@ export function Select({
399
409
  if (!menu.isOpen) menu.open();
400
410
  }}
401
411
  >
402
- <span id={valueId} className={current ? 'select-value' : 'select-value is-placeholder'}>
412
+ <span key={value} id={valueId} className={selectValueClass(!!current, picked.current)}>
403
413
  {current ? current.label : placeholder}
404
414
  </span>
405
415
  <Icon name="chevron-down" size={20} className="select-chevron" />
package/kit/ui/ui.css CHANGED
@@ -60,9 +60,13 @@ body.has-overlay { overflow: hidden; }
60
60
  .search { position: relative; }
61
61
  .search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--fg-quaternary); }
62
62
  .search .input { padding-left: 32px; }
63
- .select { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; text-align: left; }
63
+ /* The value starts where an input's text does. The right padding puts the chevron's ink over the check in the list below. */
64
+ .select { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; padding-right: 10px; cursor: pointer; text-align: left; }
64
65
  .select-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
65
66
  .select-value.is-placeholder { color: var(--text-placeholder); }
67
+ /* A picked value settles in from just below: the control answers the choice the menu took away. */
68
+ .select-value.is-picked { animation: select-pick var(--dur-menu) var(--ease-out); }
69
+ @keyframes select-pick { from { opacity: 0; transform: translateY(3px); } }
66
70
  .select { transition: border-color var(--dur-hover) var(--ease-hover), background-color var(--dur-hover) var(--ease-hover); }
67
71
  .select-chevron { color: var(--fg-quaternary); transition: transform var(--dur-menu) var(--ease-out); }
68
72
  @media (hover: hover) and (pointer: fine) { .select:hover:not([aria-expanded="true"]) { background: var(--button-secondary-bg_hover); } }
@@ -155,8 +159,12 @@ body.has-overlay { overflow: hidden; }
155
159
  .menu-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); border: 0; background: transparent; text-align: left; cursor: pointer; width: 100%; color: var(--text-primary); position: relative; --press-dur: var(--dur-press-out); transition: transform var(--press-dur) var(--ease-out), background-color var(--dur-hover) var(--ease-hover); }
156
160
  .menu-item:focus-visible, .menu-item.has-open, .menu-item.is-pressed { background: var(--bg-primary_hover); box-shadow: none; }
157
161
  @media (hover: hover) and (pointer: fine) { .menu-item:hover { background: var(--bg-primary_hover); box-shadow: none; } .menu-item:hover .menu-glyph { color: var(--fg-secondary); } }
162
+ /* The highlight lands at once and fades behind the pointer: a row answers before the hand settles. */
163
+ .menu-item:is(:hover, :focus-visible) { transition-duration: var(--press-dur), 0ms; }
158
164
  .menu-item.is-pressed { --press-dur: var(--dur-press-in); transform: scale(0.995); }
159
165
  .menu-item[disabled] { color: var(--text-disabled); cursor: not-allowed; }
166
+ /* A select's list sits under its control: 1px less padding puts each label under the value. */
167
+ .menu[role="listbox"] .menu-item { padding-inline: 9px; }
160
168
  /* A menu row is a finger's target where the pointer is one. */
161
169
  @media (pointer: coarse) { .menu-item { min-height: 44px; } }
162
170
  .menu-glyph { color: var(--fg-quaternary); display: grid; place-items: center; }
@@ -164,9 +172,13 @@ body.has-overlay { overflow: hidden; }
164
172
  .menu-item.is-danger { color: var(--text-error-primary); }
165
173
  .menu-item.is-danger .menu-glyph { color: var(--fg-error-primary); }
166
174
  .menu-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
175
+ /* One weight in every state, so choosing a row never reflows it: the check says which is chosen. */
167
176
  .menu-label { font-weight: 500; }
168
- .menu-item.is-selected .menu-label { font-weight: 600; }
169
- .menu-desc { color: var(--text-tertiary); font-size: 12px; line-height: 18px; }
177
+ .menu-desc { color: var(--text-tertiary); font-size: 12px; line-height: 16px; text-wrap: pretty; }
178
+ /* A row with a second line: its glyph and check sit on the label's line, not between the two. */
179
+ .menu-item:has(.menu-desc) { align-items: flex-start; }
180
+ .menu-item:has(.menu-desc) .menu-text { gap: 2px; }
181
+ .menu-item:has(.menu-desc) :is(.menu-glyph, .menu-check, .menu-chevron) { height: 1lh; }
170
182
  .menu-keys { display: flex; gap: 4px; margin-left: auto; flex: none; }
171
183
  .kbd { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border: 1px solid var(--border-secondary); border-radius: var(--radius-xs); font: 500 12px/18px var(--font); color: var(--text-tertiary); }
172
184
  .kbd:has(.icon) { padding: 0; color: var(--fg-quaternary); }
@@ -230,6 +242,7 @@ body.has-overlay { overflow: hidden; }
230
242
  /* ---------- motion gates ---------- */
231
243
  :root[data-motion="reduce"] :is(.btn, .btn .icon, .select, .select-chevron, .menu-item) { transition-duration: 0ms; }
232
244
  :root[data-motion="reduce"] .menu-item.is-pressed { transform: none; }
245
+ :root[data-motion="reduce"] .select-value.is-picked { animation: none; }
233
246
  :root[data-motion="reduce"] :is(.menu, .menu[data-side], .menu.is-open, .dialog, .overlay.is-open .dialog) { transform: none; transition: opacity 160ms var(--ease-hover); }
234
247
  :root[data-motion="reduce"] :is(.sheet, .overlay.is-open .sheet) { transform: none; transition: opacity 160ms var(--ease-hover); }
235
248
  :root[data-motion="reduce"] .overlay-sheet:not(.is-open) .sheet { opacity: 0; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milesroxas/design-hub",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the password gate, the kit, and the design-hub CLI. A project installs it and keeps only its prototypes, kit materials and docs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -16,7 +16,8 @@ type Props = {
16
16
  onScope: (scope: Scope) => void;
17
17
  resolved: boolean;
18
18
  resolvedCount: number;
19
- editor: boolean;
19
+ /** Studio only: the People entry in ⋯. */
20
+ canManagePeople: boolean;
20
21
  error: string | null;
21
22
  onStep: (by: number) => void;
22
23
  onResolved: () => void;
@@ -26,7 +27,7 @@ type Props = {
26
27
  onDismissError: () => void;
27
28
  };
28
29
 
29
- function moreItems(resolved: boolean, resolvedCount: number, editor: boolean): MenuEntry[] {
30
+ function moreItems(resolved: boolean, resolvedCount: number, canManagePeople: boolean): MenuEntry[] {
30
31
  return [
31
32
  {
32
33
  label: resolved ? 'Hide resolved' : 'Show resolved',
@@ -35,7 +36,7 @@ function moreItems(resolved: boolean, resolvedCount: number, editor: boolean): M
35
36
  icon: 'check-circle',
36
37
  disabled: !resolvedCount && !resolved,
37
38
  },
38
- ...(editor
39
+ ...(canManagePeople
39
40
  ? [{ label: 'People', desc: 'Who can comment', value: 'people', icon: 'users-01' as const }]
40
41
  : []),
41
42
  { label: 'Hide comments', desc: 'Tuck the button into the edge', value: 'hide', icon: 'chevron-right' },
@@ -119,7 +120,7 @@ export function Bar(p: Props) {
119
120
  label: 'Comment options',
120
121
  width: 264,
121
122
  align: 'end',
122
- items: moreItems(p.resolved, p.resolvedCount, p.editor),
123
+ items: moreItems(p.resolved, p.resolvedCount, p.canManagePeople),
123
124
  onSelect: (v) => actions[v ?? '']?.(),
124
125
  });
125
126
  return (
@@ -1,22 +1,28 @@
1
- // The People card, for editors: invite someone, hand over their link, and see
1
+ // The People card, for Studio: invite someone, hand over their link, and see
2
2
  // who can comment.
3
3
  import { Button, Select } from '@kit/ui';
4
4
  import { type FormEvent, useId, useRef, useState } from 'react';
5
- import { INVITE_DAYS, LIMITS, type Role } from '../../core/review/model';
5
+ import { INVITE_DAYS, LIMITS, type PersonKind } from '../../core/review/model';
6
6
  import { Action } from './Card';
7
7
  import { act, type Me, type ReviewStore } from './client';
8
8
 
9
9
  type Link = { name: string; href: string };
10
10
 
11
- const ROLES: { value: Role; label: string }[] = [
12
- { value: 'reviewer', label: 'Reviewer: comments and replies' },
13
- { value: 'editor', label: 'Editor: also resolves, sorts and invites' },
11
+ const KIND_NAMES: Record<PersonKind, string> = { studio: 'Studio', client: 'Client' };
12
+
13
+ const KIND_OPTIONS: { value: PersonKind; label: string; desc: string }[] = [
14
+ { value: 'client', label: KIND_NAMES.client, desc: 'Comments, replies and resolves any thread' },
15
+ {
16
+ value: 'studio',
17
+ label: KIND_NAMES.studio,
18
+ desc: 'Also sorts, deletes any comment and invites',
19
+ },
14
20
  ];
15
21
 
16
22
  function InviteForm({ store, onLink }: { store: ReviewStore; onLink: (link: Link) => void }) {
17
- const [role, setRole] = useState<Role>('reviewer');
23
+ const [kind, setKind] = useState<PersonKind>('client');
18
24
  const [busy, setBusy] = useState(false);
19
- const roleLabel = useId();
25
+ const kindLabel = useId();
20
26
  const invite = (e: FormEvent<HTMLFormElement>) => {
21
27
  e.preventDefault();
22
28
  const form = e.currentTarget;
@@ -25,7 +31,7 @@ function InviteForm({ store, onLink }: { store: ReviewStore; onLink: (link: Link
25
31
  setBusy(true);
26
32
  act(
27
33
  store
28
- .invite(name, String(f.get('team') ?? ''), role)
34
+ .invite(name, String(f.get('team') ?? ''), kind)
29
35
  .then((href) => {
30
36
  onLink({ name, href });
31
37
  form.reset();
@@ -58,15 +64,15 @@ function InviteForm({ store, onLink }: { store: ReviewStore; onLink: (link: Link
58
64
  />
59
65
  </label>
60
66
  <div className="field">
61
- <span id={roleLabel} className="field-label">
62
- Role
67
+ <span id={kindLabel} className="field-label">
68
+ Kind
63
69
  </span>
64
70
  <Select
65
- labelId={roleLabel}
71
+ labelId={kindLabel}
66
72
  menuClassName="rv-menu"
67
- value={role}
68
- options={ROLES}
69
- onChange={(next) => setRole(next as Role)}
73
+ value={kind}
74
+ options={KIND_OPTIONS}
75
+ onChange={(next) => setKind(next as PersonKind)}
70
76
  />
71
77
  </div>
72
78
  <Button type="submit" kind="primary" size={null} label="Create invite link" busy={busy} />
@@ -154,7 +160,7 @@ export function People({ store, me, people }: { store: ReviewStore; me: Me | nul
154
160
  <div className="rv-person">
155
161
  <strong>{p.name}</strong>
156
162
  <span className="rv-muted">
157
- {p.team} · {p.role}
163
+ {p.team} · {KIND_NAMES[p.kind]}
158
164
  {p.revokedAt && ' · revoked'}
159
165
  </span>
160
166
  </div>
@@ -8,6 +8,7 @@ import { areCommentsHidden, setCommentsHidden } from '@kit/prefs';
8
8
  import { Button } from '@kit/ui';
9
9
  import { type Dispatch, useEffect, useMemo, useReducer, useState } from 'react';
10
10
  import { type Anchor, type Comment, isRoot } from '../../core/review/model';
11
+ import { can } from '../../core/review/policy';
11
12
  import { captureAnchor, currentUrl, openAnchor, pinPoint, resumeAnchor } from './anchor';
12
13
  import { Bar } from './Bar';
13
14
  import { Card } from './Card';
@@ -264,7 +265,7 @@ function ModeBar({
264
265
  }}
265
266
  resolved={v.resolved}
266
267
  resolvedCount={roots.filter((c) => c.status === 'resolved').length}
267
- editor={s.me?.role === 'editor'}
268
+ canManagePeople={can(s.me, 'people')}
268
269
  error={s.error}
269
270
  onResolved={() => dispatch({ type: 'resolved' })}
270
271
  onPeople={() => {
@@ -7,6 +7,7 @@ import { Icon } from '@kit/Icon';
7
7
  import { Button, type MenuEntry, useMenu } from '@kit/ui';
8
8
  import { type KeyboardEvent, useEffect, useState } from 'react';
9
9
  import { type Comment, KINDS, type Kind, LIMITS } from '../../core/review/model';
10
+ import { can } from '../../core/review/policy';
10
11
  import { Action, Card } from './Card';
11
12
  import { act, type Me, type ReviewStore } from './client';
12
13
  import { Field, useTextBox } from './Field';
@@ -172,7 +173,7 @@ function Entry({
172
173
  <div className="rv-msg-main">
173
174
  <EntryHead
174
175
  comment={comment}
175
- canEdit={me?.id === comment.author.id && !editing}
176
+ canEdit={can(me, 'edit', comment) && !editing}
176
177
  onEdit={() => setEditing(true)}
177
178
  />
178
179
  {editing ? (
@@ -203,19 +204,19 @@ function tagsOf(root: Comment): string[] {
203
204
 
204
205
  type TriageChange = { kind: string | null; state: string | null };
205
206
 
206
- /** Kind and state as checked choices, for editors; then the thread's rarer actions. */
207
+ /** Kind and state as checked choices, for Studio; then the thread's rarer actions. */
207
208
  function menuItems(
208
209
  root: Comment,
209
210
  states: string[],
210
- editor: boolean,
211
- canClose: boolean,
211
+ canTriage: boolean,
212
+ canDelete: boolean,
212
213
  show: boolean,
213
214
  ): MenuEntry[] {
214
215
  const { kind = null, state = null } = root.triage ?? {};
215
216
  const stateItems: MenuEntry[] = states.length
216
217
  ? [{ heading: 'State' }, ...states.map((s) => ({ label: s, value: `state:${s}`, checked: state === s }))]
217
218
  : [];
218
- const triage: MenuEntry[] = editor
219
+ const triage: MenuEntry[] = canTriage
219
220
  ? [
220
221
  { heading: 'Kind' },
221
222
  ...KINDS.map((k) => ({ label: KIND_LABEL[k], value: `kind:${k}`, checked: kind === k })),
@@ -226,7 +227,7 @@ function menuItems(
226
227
  return [
227
228
  ...triage,
228
229
  ...(show ? [{ label: 'Show its state', value: 'show', icon: 'clock-rewind' as const }] : []),
229
- ...(canClose
230
+ ...(canDelete
230
231
  ? [{ label: 'Delete thread', value: 'delete', icon: 'trash-01' as const, danger: true }]
231
232
  : []),
232
233
  ];
@@ -246,20 +247,20 @@ function ThreadMenu({
246
247
  store,
247
248
  root,
248
249
  states,
249
- editor,
250
- canClose,
250
+ canTriage,
251
+ canDelete,
251
252
  onShow,
252
253
  onDelete,
253
254
  }: {
254
255
  store: ReviewStore;
255
256
  root: Comment;
256
257
  states: string[];
257
- editor: boolean;
258
- canClose: boolean;
258
+ canTriage: boolean;
259
+ canDelete: boolean;
259
260
  onShow?: () => void;
260
261
  onDelete: () => void;
261
262
  }) {
262
- const items = menuItems(root, states, editor, canClose, !!onShow);
263
+ const items = menuItems(root, states, canTriage, canDelete, !!onShow);
263
264
  const menu = useMenu({
264
265
  className: 'rv-menu',
265
266
  label: 'Thread options',
@@ -382,8 +383,9 @@ type HeadProps = {
382
383
  index: number;
383
384
  total: number;
384
385
  states: string[];
385
- editor: boolean;
386
- canClose: boolean;
386
+ canResolve: boolean;
387
+ canTriage: boolean;
388
+ canDelete: boolean;
387
389
  onStep: (by: number) => void;
388
390
  onClose: () => void;
389
391
  onShow?: () => void;
@@ -398,8 +400,9 @@ function ThreadHead({
398
400
  index,
399
401
  total,
400
402
  states,
401
- editor,
402
- canClose,
403
+ canResolve,
404
+ canTriage,
405
+ canDelete,
403
406
  onStep,
404
407
  onClose,
405
408
  onShow,
@@ -412,13 +415,13 @@ function ThreadHead({
412
415
  </span>
413
416
  <span className="rv-about rv-ellipsis">{about(root)}</span>
414
417
  <Stepper index={index} total={total} onStep={onStep} />
415
- {canClose && <ResolveButton store={store} root={root} />}
418
+ {canResolve && <ResolveButton store={store} root={root} />}
416
419
  <ThreadMenu
417
420
  store={store}
418
421
  root={root}
419
422
  states={states}
420
- editor={editor}
421
- canClose={canClose}
423
+ canTriage={canTriage}
424
+ canDelete={canDelete}
422
425
  onShow={onShow}
423
426
  onDelete={onDelete}
424
427
  />
@@ -462,7 +465,6 @@ export function ThreadCard({
462
465
  onShow?: () => void;
463
466
  }) {
464
467
  const [confirming, setConfirming] = useState(false);
465
- const editor = me?.role === 'editor';
466
468
  const resolved = root.status === 'resolved';
467
469
  return (
468
470
  <Card
@@ -478,8 +480,9 @@ export function ThreadCard({
478
480
  index={index}
479
481
  total={total}
480
482
  states={states}
481
- editor={editor}
482
- canClose={editor || me?.id === root.author.id}
483
+ canResolve={can(me, 'resolve', root)}
484
+ canTriage={can(me, 'triage')}
485
+ canDelete={can(me, 'delete', root)}
483
486
  onStep={onStep}
484
487
  onClose={onClose}
485
488
  onShow={onShow}
@@ -1,9 +1,9 @@
1
1
  // The review UI's one store: who is signed in, this prototype's comments and,
2
- // for editors, the people. Components read it with useSyncExternalStore and
2
+ // for Studio, the people. Components read it with useSyncExternalStore and
3
3
  // call its actions; every call goes to /api/review (server/api.ts), and each
4
4
  // answer is merged in place, so a write never refetches the list.
5
5
  import { useSyncExternalStore } from 'react';
6
- import type { Anchor, Comment, Person, Role } from '../../core/review/model';
6
+ import type { Anchor, Comment, Person, PersonKind } from '../../core/review/model';
7
7
 
8
8
  export type Me = Omit<Person, 'epoch'>;
9
9
  /** off: this site has no review store, so the UI stays out of the way. */
@@ -144,9 +144,9 @@ export function createReviewStore(prototype: string) {
144
144
  }),
145
145
 
146
146
  loadPeople: () => attempt(async () => set({ people: (await call<{ people: Me[] }>('people')).people })),
147
- invite: (name: string, team: string, role: Role) =>
147
+ invite: (name: string, team: string, kind: PersonKind) =>
148
148
  attempt(async () => {
149
- const r = await call<{ person: Me; link: string }>('people.invite', { name, team, role });
149
+ const r = await call<{ person: Me; link: string }>('people.invite', { name, team, kind });
150
150
  mergePerson(r.person);
151
151
  return new URL(r.link, location.origin).href;
152
152
  }),
@@ -89,6 +89,9 @@
89
89
  .rv .btn-label { line-height: 18px; }
90
90
  .rv .input,
91
91
  .rv .select { height: 32px; padding: 0 10px; }
92
+ /* A 32px control carries a 16px chevron, the check's size and stroke, with its ink over the check in the list below. */
93
+ .rv .select { padding-right: 9px; }
94
+ .rv .select-chevron { width: 16px; height: 16px; }
92
95
  .rv .field-label { color: var(--harness-fg-muted); font-weight: 400; }
93
96
  /* A 32px control reaches 44px for a finger. */
94
97
  @media (pointer: coarse) {
@@ -96,7 +99,10 @@
96
99
  .rv .btn::before { content: ''; position: absolute; inset: -6px -2px; }
97
100
  }
98
101
 
99
- .menu.rv-menu { z-index: calc(var(--rv-z) + 2); }
102
+ /* On the dark material the raised shadow already draws the edge as one ring: a border beside it doubles the line. */
103
+ .menu.rv-menu { z-index: calc(var(--rv-z) + 2); border: 0; }
104
+ .rv-menu .menu-item:has(.menu-desc) { padding: 8px; }
105
+ .rv-menu[role="listbox"] .menu-item { padding-inline: 7px; }
100
106
  .rv-menu .menu-item { padding: 6px 8px; min-height: 32px; }
101
107
  .rv-menu .menu-header { padding: 8px 8px 2px; }
102
108
  .rv-menu .menu-header:not(:first-child) { margin-top: 4px; }
@@ -56,17 +56,17 @@ Signed in, it prints `signedIn: true` and the account. Signed out, it starts the
56
56
 
57
57
  ## Comments
58
58
 
59
- Ask the user once whether reviewers should comment on the link; ask before the first deploy, so one `bootstrap` carries `--review`. If yes, `--review [--typesafe-key <key>]` adds Upstash Redis to the project through the Vercel Marketplace and copies the store's credentials into `.env`. The first time on a team it can stop on the Marketplace terms. Send the user the message in its `fix` as written: it links that team's terms page, names the one product to pick (**Upstash for Redis**, Redis Compatible Database) when Vercel lists several, and tells them not to create a database there, since the rerun creates the store and connects it. Rerun when they say it is done; if `stderr` shows another cause, show it to them instead. With TypeSafe on, comments are sorted by kind and state as they arrive. `pnpm share` after it, so the env reaches the site, then invite the first editor:
59
+ Ask the user once whether reviewers should comment on the link; ask before the first deploy, so one `bootstrap` carries `--review`. If yes, `--review [--typesafe-key <key>]` adds Upstash Redis to the project through the Vercel Marketplace and copies the store's credentials into `.env`. The first time on a team it can stop on the Marketplace terms. Send the user the message in its `fix` as written: it links that team's terms page, names the one product to pick (**Upstash for Redis**, Redis Compatible Database) when Vercel lists several, and tells them not to create a database there, since the rerun creates the store and connects it. Rerun when they say it is done; if `stderr` shows another cause, show it to them instead. With TypeSafe on, comments are sorted by kind and state as they arrive. `pnpm share` after it, so the env reaches the site, then invite the first Studio person:
60
60
 
61
61
  ```bash
62
- pnpm people invite --name "<user>" --team "<studio>" --role editor --site <share.url>
62
+ pnpm people invite --name "<user>" --team "<studio>" --kind studio --site <share.url>
63
63
  ```
64
64
 
65
- Send them the link; from then on, editors invite reviewers from the People tab. `miles-review` owns working from the comments.
65
+ Send them the link; from then on, Studio invites everyone else from the People tab. `miles-review` owns working from the comments.
66
66
 
67
67
  ## Rotating access
68
68
 
69
- - **A reviewer leaves:** revoke them in the People tab, or `pnpm people revoke <id>`. Their sessions end on their next page load.
69
+ - **Someone leaves:** revoke them in the People tab, or `pnpm people revoke <id>`. Their sessions end on their next page load.
70
70
  - **The shared password leaked:** `pnpm bootstrap --vercel <project> --gate-password <new>`, then `pnpm share`. Every password visitor signs in again; invited people are not affected.
71
71
 
72
72
  ## Security, never weakened for a prototype
@@ -90,7 +90,7 @@ The user does nothing in a terminal here; each step that needs them is one link
90
90
  2. `vercel teams ls`; with more than one team, ask which with the question tool (personal account first when it is listed).
91
91
  3. `pnpm --dir <path> bootstrap --vercel <name> --team <team-slug>`, plus `--review` for comments. It links the project, connects the GitHub repo, sets the password and turns Vercel's own login off. A first `--review` on a team can stop on the Marketplace terms: send the user the message in `fix` as written (it names **Upstash for Redis** as the product to pick), then rerun.
92
92
  4. `pnpm --dir <path> share --cli`. `--cli` uploads the folder, since the setup may have left files uncommitted; later deploys push `main`. On `ok: false`, follow `stage` and `fix` (the pre-flight steps are in `miles-deploy`).
93
- 5. With comments: `pnpm --dir <path> people invite --name "<user>" --role editor --site <share.url>`.
93
+ 5. With comments: `pnpm --dir <path> people invite --name "<user>" --kind studio --site <share.url>`.
94
94
 
95
95
  Give the user `share.url`, `share.password` and the invite link in the closing message, and say the link shows the samples until the first feature replaces them.
96
96
 
@@ -28,9 +28,9 @@ Each comment is pinned to a prototype, its state (the URL and every dial value)
28
28
 
29
29
  ## People
30
30
 
31
- - **Editors** resolve any thread, sort comments and invite people. **Reviewers** comment, reply, and resolve or delete their own. Give a client's stakeholders the reviewer role; editors are the studio.
31
+ - Every person is **Studio** or **Client**. Both comment, reply, edit their own words, and resolve or reopen any thread. Studio also deletes any comment, sorts comments and invites people; a Client deletes only their own. The studio's team are Studio; everyone on the client's side is Client, the default.
32
32
  - **Team** is the company: `Studio`, or the client's name. It shows beside every name, so a reviewer reads who said what.
33
- - The first editor comes from `pnpm people invite --name <n> --team <t> --role editor --site <url>`; after that, editors invite from the People tab.
33
+ - The first Studio person comes from `pnpm people invite --name <n> --team <t> --kind studio --site <url>`; after that, Studio invites from the People tab.
34
34
  - A link works for 14 days. `pnpm people reissue <id>` replaces it and signs that person out everywhere; `revoke` ends their access on their next page load.
35
35
  - Never paste an invite link into a commit, a document, a ticket or a comment. Why: anyone holding it signs in as that person.
36
36