@milesroxas/design-hub 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/core/controls.test.ts +176 -0
- package/core/controls.ts +195 -0
- package/core/files.test.ts +76 -0
- package/core/files.ts +131 -0
- package/core/prototype.test.ts +124 -7
- package/core/prototype.ts +133 -24
- package/core/review/model.ts +144 -2
- package/core/review/policy.test.ts +79 -22
- package/core/review/policy.ts +36 -8
- package/core/review/service.test.ts +1525 -322
- package/core/review/service.ts +810 -183
- package/core/review/store.test.ts +91 -0
- package/core/review/store.ts +143 -26
- package/dist/core/controls.d.ts +55 -0
- package/dist/core/controls.js +174 -0
- package/dist/core/files.d.ts +39 -0
- package/dist/core/files.js +107 -0
- package/dist/core/prototype.d.ts +61 -12
- package/dist/core/prototype.js +105 -26
- package/dist/core/review/model.d.ts +87 -2
- package/dist/core/review/model.js +97 -1
- package/dist/core/review/policy.d.ts +11 -4
- package/dist/core/review/policy.js +14 -2
- package/dist/core/review/service.d.ts +222 -43
- package/dist/core/review/service.js +727 -182
- package/dist/core/review/store.d.ts +84 -24
- package/dist/core/review/store.js +66 -26
- package/dist/scripts/bootstrap.d.ts +4 -34
- package/dist/scripts/bootstrap.js +9 -244
- package/dist/scripts/cli.js +6 -0
- package/dist/scripts/client.d.ts +45 -0
- package/dist/scripts/client.js +320 -0
- package/dist/scripts/commands.js +6 -0
- package/dist/scripts/comments.d.ts +8 -26
- package/dist/scripts/comments.js +27 -14
- package/dist/scripts/guard.d.ts +11 -0
- package/dist/scripts/guard.js +44 -0
- package/dist/scripts/lib/builds.d.ts +40 -0
- package/dist/scripts/lib/builds.js +198 -0
- package/dist/scripts/lib/cli.js +3 -1
- package/dist/scripts/lib/deploy.d.ts +6 -90
- package/dist/scripts/lib/deploy.js +24 -137
- package/dist/scripts/lib/dns.d.ts +49 -0
- package/dist/scripts/lib/dns.js +141 -0
- package/dist/scripts/lib/fake-host.d.ts +168 -0
- package/dist/scripts/lib/fake-host.js +244 -0
- package/dist/scripts/lib/host.d.ts +87 -0
- package/dist/scripts/lib/host.js +362 -0
- package/dist/scripts/lib/linked.d.ts +51 -0
- package/dist/scripts/lib/linked.js +124 -0
- package/dist/scripts/lib/names.d.ts +35 -0
- package/dist/scripts/lib/names.js +77 -0
- package/dist/scripts/lib/review.d.ts +23 -2
- package/dist/scripts/lib/review.js +32 -15
- package/dist/scripts/lib/rules.d.ts +1 -0
- package/dist/scripts/lib/rules.js +1 -0
- package/dist/scripts/lib/studio-deps.d.ts +35 -0
- package/dist/scripts/lib/studio-deps.js +79 -0
- package/dist/scripts/lib/studios.d.ts +70 -0
- package/dist/scripts/lib/studios.js +187 -0
- package/dist/scripts/lib/update.d.ts +33 -0
- package/dist/scripts/lib/update.js +40 -0
- package/dist/scripts/lib/vercel.d.ts +1 -23
- package/dist/scripts/lib/vercel.js +6 -81
- package/dist/scripts/people.d.ts +7 -11
- package/dist/scripts/people.js +51 -46
- package/dist/scripts/preflight.d.ts +8 -1
- package/dist/scripts/preflight.js +36 -19
- package/dist/scripts/project.d.ts +86 -0
- package/dist/scripts/project.js +141 -0
- package/dist/scripts/share.d.ts +105 -30
- package/dist/scripts/share.js +82 -154
- package/dist/scripts/skills.d.ts +18 -2
- package/dist/scripts/skills.js +22 -3
- package/dist/scripts/studio.d.ts +75 -0
- package/dist/scripts/studio.js +401 -0
- package/dist/scripts/upgrade.d.ts +10 -2
- package/dist/scripts/upgrade.js +44 -14
- package/dist/server/api.d.ts +22 -11
- package/dist/server/api.js +125 -44
- package/dist/server/blob.d.ts +10 -0
- package/dist/server/blob.js +53 -0
- package/dist/server/checks.js +2 -2
- package/dist/server/dev.js +4 -4
- package/dist/server/env.d.ts +2 -0
- package/dist/server/env.js +9 -0
- package/dist/server/fake-upstash.js +52 -3
- package/dist/server/hosts.d.ts +11 -0
- package/dist/server/hosts.js +31 -0
- package/dist/server/local.d.ts +7 -1
- package/dist/server/local.js +10 -1
- package/dist/server/mark.d.ts +41 -0
- package/dist/server/mark.js +111 -0
- package/dist/server/session.d.ts +17 -9
- package/dist/server/session.js +22 -45
- package/dist/server/upstash.js +20 -0
- package/dist/vercel/files.d.ts +11 -0
- package/dist/vercel/files.js +68 -0
- package/dist/vercel/index.d.ts +4 -3
- package/dist/vercel/index.js +12 -8
- package/dist/vercel/proxy.d.ts +69 -4
- package/dist/vercel/proxy.js +171 -107
- package/dist/vite/plugin.d.ts +24 -1
- package/dist/vite/plugin.js +46 -2
- package/kit/Artboard.tsx +21 -8
- package/kit/Space.tsx +4 -3
- package/kit/Variants.tsx +193 -65
- package/kit/ViewTools.tsx +77 -11
- package/kit/audience.ts +85 -0
- package/kit/dials.css +59 -0
- package/kit/dials.tsx +272 -35
- package/kit/harness.css +34 -0
- package/kit/prefs.ts +23 -1
- package/package.json +3 -2
- package/shell/ClientViewNote.tsx +31 -3
- package/shell/Guide.tsx +11 -5
- package/shell/Index.tsx +32 -10
- package/shell/Notice.tsx +1 -1
- package/shell/controls.ts +26 -0
- package/shell/hub.ts +5 -1
- package/shell/main.tsx +33 -6
- package/shell/review/Review.tsx +2 -2
- package/shell/review/ThreadCard.tsx +5 -5
- package/shell/review/client.ts +28 -11
- package/shell/review/view.test.ts +19 -0
- package/shell/review/view.ts +25 -0
- package/shell/shell.css +8 -0
- package/shell/studio/ClientHub.tsx +98 -0
- package/shell/studio/hub.css +48 -0
- package/shell/studio/index.html +14 -0
- package/shell/studio/main.tsx +17 -0
- package/skills/miles-brand/SKILL.md +11 -1
- package/skills/miles-deploy/SKILL.md +121 -64
- package/skills/miles-design-hub/SKILL.md +11 -9
- package/skills/miles-prototype/SKILL.md +34 -1
- package/skills/miles-review/SKILL.md +5 -7
- package/skills/miles-worktrees/SKILL.md +3 -3
- package/templates/conductor/settings.toml +1 -1
- package/templates/studio/.env.example +9 -0
- package/templates/studio/.vercelignore +5 -0
- package/templates/studio/README.md +84 -0
- package/templates/studio/_gitignore +7 -0
- package/templates/studio/api/files.ts +4 -0
- package/templates/studio/api/review.ts +4 -0
- package/templates/studio/build.mjs +4 -0
- package/templates/studio/package.json +16 -0
- package/templates/studio/proxy.ts +4 -0
- package/templates/studio/studio.json +9 -0
- package/templates/studio/vercel.json +27 -0
package/core/review/model.ts
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
// enforced by the service, whichever adapter (Vercel, Vite dev, the CLI)
|
|
5
5
|
// calls it.
|
|
6
6
|
|
|
7
|
+
import { CONTROL_KINDS, type ControlKind, isControlId } from '../controls.ts';
|
|
7
8
|
import { SLUG } from '../feature.ts';
|
|
9
|
+
import { isBuildId } from '../files.ts';
|
|
10
|
+
import { hostName, isClientSlug, isProjectSlug } from '../prototype.ts';
|
|
8
11
|
|
|
9
12
|
/** Which side a person is on: the studio that makes the work, or the client it is for. */
|
|
10
13
|
export const PERSON_KINDS = ['studio', 'client'] as const;
|
|
@@ -32,6 +35,11 @@ export const ACCESS = ['3m', '6m', 'open'] as const;
|
|
|
32
35
|
export type Access = (typeof ACCESS)[number];
|
|
33
36
|
/** The project default when none is set. */
|
|
34
37
|
export const DEFAULT_ACCESS: Access = '3m';
|
|
38
|
+
/**
|
|
39
|
+
* How long a studio site's instance keeps a host's answer (server/hosts.ts):
|
|
40
|
+
* archiving a client, or adding one, takes effect on every instance within it.
|
|
41
|
+
*/
|
|
42
|
+
export const HOST_SECONDS = 60;
|
|
35
43
|
|
|
36
44
|
const ACCESS_MONTHS: Record<Exclude<Access, 'open'>, number> = { '3m': 3, '6m': 6 };
|
|
37
45
|
|
|
@@ -65,6 +73,11 @@ export type Person = {
|
|
|
65
73
|
/** The group a person belongs to, shown beside their name: the studio, or the client's company. */
|
|
66
74
|
team: string;
|
|
67
75
|
kind: PersonKind;
|
|
76
|
+
/**
|
|
77
|
+
* The client a Client belongs to, or null for Studio, who works in every
|
|
78
|
+
* client. Never stored in the profile: it is where the person's records live.
|
|
79
|
+
*/
|
|
80
|
+
client: string | null;
|
|
68
81
|
/** Always null until email sign-in exists. */
|
|
69
82
|
email: string | null;
|
|
70
83
|
/** When their access ends (ISO time), or null for open-ended. Their sessions end with it. */
|
|
@@ -75,6 +88,55 @@ export type Person = {
|
|
|
75
88
|
epoch: number;
|
|
76
89
|
};
|
|
77
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Where an op runs: one client, and one of its projects for anything about
|
|
93
|
+
* prototypes and comments. Every service method takes one, every store key is
|
|
94
|
+
* built from one (store.ts), and a Client acts only inside their own client.
|
|
95
|
+
*/
|
|
96
|
+
export type Scope = { client: string; project?: string };
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The one client of this machine's own store, which `design-hub dev` and
|
|
100
|
+
* `--local` commands use (LOCAL_SCOPE in server/local.ts). It has no record
|
|
101
|
+
* and is never added or archived, so ops in it need none (`allow` in
|
|
102
|
+
* service.ts), and no studio may add a client by this name.
|
|
103
|
+
*/
|
|
104
|
+
export const LOCAL_CLIENT = 'site';
|
|
105
|
+
|
|
106
|
+
/** A slug a studio's client can have: a client slug, and never the local store's. */
|
|
107
|
+
export const isStudioClient = (slug: unknown): slug is string => isClientSlug(slug) && slug !== LOCAL_CLIENT;
|
|
108
|
+
/** What a slug that cannot be a studio's client is told. */
|
|
109
|
+
export const STUDIO_CLIENT_SLUG = 'slug: kebab-case, and not studio, www, api or site';
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A client of the studio: one host (`<client>.<apex>`, or a codename below
|
|
113
|
+
* the apex), every project of it, its Client people. An archived client's
|
|
114
|
+
* host is the plain 404. `access` is its default access length, unused until
|
|
115
|
+
* clients set one. `provenAt` is when its host proved it is this studio's
|
|
116
|
+
* site (endProof in service.ts); until then the client is still being added
|
|
117
|
+
* (isAdded).
|
|
118
|
+
*/
|
|
119
|
+
export type Client = {
|
|
120
|
+
slug: string;
|
|
121
|
+
host: string;
|
|
122
|
+
name: string;
|
|
123
|
+
access: Access | null;
|
|
124
|
+
createdAt: string;
|
|
125
|
+
archivedAt: string | null;
|
|
126
|
+
provenAt: string | null;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Whether a client has finished being added: its host has proved it is this
|
|
131
|
+
* studio's site. A record with no such mark is still being added, whatever
|
|
132
|
+
* became of its proof, so nothing of a project and no sign-in link goes to
|
|
133
|
+
* its host, and `client add` with the same flags finishes it.
|
|
134
|
+
*/
|
|
135
|
+
export const isAdded = (client: Client): boolean => client.provenAt !== null;
|
|
136
|
+
|
|
137
|
+
/** A project of one client, served at `/<slug>/` on its host from the build `build` points at, or not at all while it is null. */
|
|
138
|
+
export type Project = { slug: string; client: string; name: string; build: string | null; createdAt: string };
|
|
139
|
+
|
|
78
140
|
/** A one-time sign-in link, stored under the hash of its token and deleted when used. */
|
|
79
141
|
export type Link = { person: string; expiresAt: string };
|
|
80
142
|
|
|
@@ -162,8 +224,11 @@ const PROFILE_RULES: [string, (v: unknown) => boolean][] = [
|
|
|
162
224
|
['createdAt', isText],
|
|
163
225
|
];
|
|
164
226
|
|
|
165
|
-
/**
|
|
166
|
-
export
|
|
227
|
+
/** What a person's profile record holds: everything but revocation, epoch and client, which live elsewhere. */
|
|
228
|
+
export type Profile = Omit<Person, 'revokedAt' | 'epoch' | 'client'>;
|
|
229
|
+
|
|
230
|
+
/** Whether a stored profile is well formed. */
|
|
231
|
+
export function isProfile(v: unknown): v is Profile {
|
|
167
232
|
if (!v || typeof v !== 'object' || Array.isArray(v)) return false;
|
|
168
233
|
const o = v as Record<string, unknown>;
|
|
169
234
|
return PROFILE_RULES.every(([key, ok]) => ok(o[key]));
|
|
@@ -226,6 +291,59 @@ export function checkPersonInput(input: unknown): Checked<PersonInput> {
|
|
|
226
291
|
: { ok: true, value: { name, team, kind: kind as PersonKind, access: access as Access | null } };
|
|
227
292
|
}
|
|
228
293
|
|
|
294
|
+
export type ClientInput = Pick<Client, 'slug' | 'host' | 'name'>;
|
|
295
|
+
|
|
296
|
+
/** A new client: a client slug, the host name it is served on (lower case), and its name. */
|
|
297
|
+
export function checkClientInput(input: unknown): Checked<ClientInput> {
|
|
298
|
+
const i = (input ?? {}) as Record<string, unknown>;
|
|
299
|
+
const problems: string[] = [];
|
|
300
|
+
const name = text(i.name, 'name', LIMITS.name, problems);
|
|
301
|
+
if (!isStudioClient(i.slug)) problems.push(STUDIO_CLIENT_SLUG);
|
|
302
|
+
const host = typeof i.host === 'string' ? hostName(i.host) : '';
|
|
303
|
+
if (!host || host !== i.host) problems.push('host: a host name in lower case, such as acme.example.com');
|
|
304
|
+
return problems.length
|
|
305
|
+
? { ok: false, problems }
|
|
306
|
+
: { ok: true, value: { slug: i.slug as string, host, name } };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export type ProjectInput = Pick<Project, 'slug' | 'name'>;
|
|
310
|
+
|
|
311
|
+
/** A new project: a project slug (never a path the gate answers itself) and its name. */
|
|
312
|
+
export function checkProjectInput(input: unknown): Checked<ProjectInput> {
|
|
313
|
+
const i = (input ?? {}) as Record<string, unknown>;
|
|
314
|
+
const problems: string[] = [];
|
|
315
|
+
const name = text(i.name, 'name', LIMITS.name, problems);
|
|
316
|
+
if (!isProjectSlug(i.slug)) problems.push('slug: kebab-case, and not a path the hub answers itself');
|
|
317
|
+
return problems.length ? { ok: false, problems } : { ok: true, value: { slug: i.slug as string, name } };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
321
|
+
!!v && typeof v === 'object' && !Array.isArray(v);
|
|
322
|
+
|
|
323
|
+
/** A stored client, or null for anything that is not a well-formed one. */
|
|
324
|
+
export function readClient(json: string | null): Client | null {
|
|
325
|
+
const c = safeJson(json);
|
|
326
|
+
if (!isRecord(c) || !isClientSlug(c.slug) || typeof c.host !== 'string' || !isText(c.name)) return null;
|
|
327
|
+
if (!isText(c.createdAt) || !isTextOrNull(c.archivedAt) || !isTextOrNull(c.provenAt)) return null;
|
|
328
|
+
return c as Client;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** A stored project, or null for anything that is not a well-formed one. */
|
|
332
|
+
export function readProject(json: string | null): Project | null {
|
|
333
|
+
const p = safeJson(json);
|
|
334
|
+
if (!isRecord(p) || !isProjectSlug(p.slug) || !isClientSlug(p.client) || !isText(p.name)) return null;
|
|
335
|
+
if (!isText(p.createdAt) || !(p.build === null || isBuildId(p.build))) return null;
|
|
336
|
+
return p as Project;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function safeJson(json: string | null): unknown {
|
|
340
|
+
try {
|
|
341
|
+
return json === null ? null : JSON.parse(json);
|
|
342
|
+
} catch {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
229
347
|
/** A new thread's audience as asked: one of AUDIENCES, or null when none is given. */
|
|
230
348
|
export function checkAudience(input: unknown): Checked<Audience | null> {
|
|
231
349
|
if (input === undefined || input === null) return { ok: true, value: null };
|
|
@@ -241,6 +359,30 @@ export function checkPrototypeAudience(input: unknown): Checked<Audience> {
|
|
|
241
359
|
: { ok: false, problems: [`audience: one of ${AUDIENCES.join(', ')}`] };
|
|
242
360
|
}
|
|
243
361
|
|
|
362
|
+
/** One control's mark as Studio sets it: which kind, its id, and who it is for. */
|
|
363
|
+
export function checkControl(input: {
|
|
364
|
+
kind: unknown;
|
|
365
|
+
id: unknown;
|
|
366
|
+
audience: unknown;
|
|
367
|
+
}): Checked<{ kind: ControlKind; id: string; audience: Audience }> {
|
|
368
|
+
const problems: string[] = [];
|
|
369
|
+
if (!CONTROL_KINDS.includes(input.kind as ControlKind))
|
|
370
|
+
problems.push(`kind: one of ${CONTROL_KINDS.join(', ')}`);
|
|
371
|
+
if (!isControlId(input.id)) problems.push('id: the control’s name, one line of at most 200 characters');
|
|
372
|
+
if (!AUDIENCES.includes(input.audience as Audience))
|
|
373
|
+
problems.push(`audience: one of ${AUDIENCES.join(', ')}`);
|
|
374
|
+
return problems.length
|
|
375
|
+
? { ok: false, problems }
|
|
376
|
+
: {
|
|
377
|
+
ok: true,
|
|
378
|
+
value: {
|
|
379
|
+
kind: input.kind as ControlKind,
|
|
380
|
+
id: input.id as string,
|
|
381
|
+
audience: input.audience as Audience,
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
244
386
|
/** Whose view of the comments is asked for: a person kind, or null for the caller's own. */
|
|
245
387
|
export function checkViewAs(input: unknown): Checked<PersonKind | null> {
|
|
246
388
|
if (input === undefined || input === null) return { ok: true, value: null };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import { test } from 'node:test';
|
|
3
|
-
import type { Audience, Comment, Person, PersonKind } from './model.ts';
|
|
4
|
-
import { type Action, audienceFor, can, viewOf, visibleTo } from './policy.ts';
|
|
3
|
+
import type { Audience, Comment, Person, PersonKind, Scope } from './model.ts';
|
|
4
|
+
import { type Action, audienceFor, can, inScope, viewOf, visibleTo } from './policy.ts';
|
|
5
5
|
|
|
6
6
|
const person = (id: string, kind: PersonKind, revokedAt: string | null = null): Person => ({
|
|
7
7
|
id,
|
|
8
8
|
name: id,
|
|
9
9
|
team: kind === 'studio' ? 'Studio' : 'Acme',
|
|
10
10
|
kind,
|
|
11
|
+
client: kind === 'studio' ? null : 'acme',
|
|
11
12
|
email: null,
|
|
12
13
|
accessEndsAt: null,
|
|
13
14
|
createdAt: '',
|
|
@@ -50,57 +51,113 @@ const TABLE: [Action, Audience, boolean, boolean, boolean, boolean][] = [
|
|
|
50
51
|
['people', 'internal', true, true, false, false],
|
|
51
52
|
['audience', 'client', true, true, false, false],
|
|
52
53
|
['audience', 'internal', true, true, false, false],
|
|
54
|
+
['setup', 'client', true, true, false, false],
|
|
55
|
+
['setup', 'internal', true, true, false, false],
|
|
53
56
|
];
|
|
54
57
|
|
|
58
|
+
/** Where the table runs: the Client's own client. */
|
|
59
|
+
const A: Scope = { client: 'acme', project: 'rebrand' };
|
|
60
|
+
/** Another client's: the service answers anything here as not found. */
|
|
61
|
+
const B: Scope = { client: 'bravo', project: 'launch' };
|
|
62
|
+
|
|
55
63
|
const studio = person('s', 'studio');
|
|
56
64
|
const client = person('c', 'client');
|
|
57
65
|
|
|
58
66
|
for (const [action, audience, studioOwn, studioOther, clientOwn, clientOther] of TABLE) {
|
|
59
67
|
test(`${action} on a ${audience} thread: Studio and Client, own and another's`, () => {
|
|
60
|
-
assert.equal(can(studio, action, thread(studio.id, audience)), studioOwn, 'Studio, own');
|
|
61
|
-
assert.equal(can(studio, action, thread('someone', audience)), studioOther, "Studio, another's");
|
|
62
|
-
assert.equal(can(client, action, thread(client.id, audience)), clientOwn, 'Client, own');
|
|
63
|
-
assert.equal(can(client, action, thread('someone', audience)), clientOther, "Client, another's");
|
|
68
|
+
assert.equal(can(studio, A, action, thread(studio.id, audience)), studioOwn, 'Studio, own');
|
|
69
|
+
assert.equal(can(studio, A, action, thread('someone', audience)), studioOther, "Studio, another's");
|
|
70
|
+
assert.equal(can(client, A, action, thread(client.id, audience)), clientOwn, 'Client, own');
|
|
71
|
+
assert.equal(can(client, A, action, thread('someone', audience)), clientOther, "Client, another's");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test(`${action} on a ${audience} thread in another client’s scope: Studio as anywhere, a Client never`, () => {
|
|
75
|
+
assert.equal(can(studio, B, action, thread(studio.id, audience)), studioOwn, 'Studio, own');
|
|
76
|
+
assert.equal(can(studio, B, action, thread('someone', audience)), studioOther, "Studio, another's");
|
|
77
|
+
assert.equal(can(client, B, action, thread(client.id, audience)), false, 'Client, own');
|
|
78
|
+
assert.equal(can(client, B, action, thread('someone', audience)), false, "Client, another's");
|
|
79
|
+
assert.equal(can(client, B, action), false, 'Client, no thread');
|
|
64
80
|
});
|
|
65
81
|
|
|
66
82
|
test(`${action} on a ${audience} thread: nobody signed in and a revoked person may not`, () => {
|
|
67
83
|
for (const kind of ['studio', 'client'] as const) {
|
|
68
84
|
const gone = person('r', kind, '2030-01-01T00:00:00Z');
|
|
69
|
-
assert.equal(can(gone, action, thread(gone.id, audience)), false, `revoked ${kind}, own`);
|
|
70
|
-
assert.equal(can(gone, action, thread('someone', audience)), false, `revoked ${kind}, another's`);
|
|
85
|
+
assert.equal(can(gone, A, action, thread(gone.id, audience)), false, `revoked ${kind}, own`);
|
|
86
|
+
assert.equal(can(gone, A, action, thread('someone', audience)), false, `revoked ${kind}, another's`);
|
|
71
87
|
}
|
|
72
|
-
assert.equal(can(null, action, thread('someone', audience)), false, 'null');
|
|
73
|
-
assert.equal(can(null, action), false, 'null, no subject');
|
|
88
|
+
assert.equal(can(null, A, action, thread('someone', audience)), false, 'null');
|
|
89
|
+
assert.equal(can(null, A, action), false, 'null, no subject');
|
|
74
90
|
});
|
|
75
91
|
}
|
|
76
92
|
|
|
93
|
+
// The scope rows: who an op in a scope belongs to at all.
|
|
94
|
+
const SCOPES: [string, Pick<Person, 'kind' | 'client'>, Scope, boolean][] = [
|
|
95
|
+
['Studio, in a client', { kind: 'studio', client: null }, A, true],
|
|
96
|
+
['Studio, in another client', { kind: 'studio', client: null }, B, true],
|
|
97
|
+
['Studio, in a client with no project', { kind: 'studio', client: null }, { client: 'bravo' }, true],
|
|
98
|
+
['a Client, in their own client', { kind: 'client', client: 'acme' }, A, true],
|
|
99
|
+
[
|
|
100
|
+
'a Client, in another project of it',
|
|
101
|
+
{ kind: 'client', client: 'acme' },
|
|
102
|
+
{ client: 'acme', project: 'x' },
|
|
103
|
+
true,
|
|
104
|
+
],
|
|
105
|
+
['a Client, in another client', { kind: 'client', client: 'acme' }, B, false],
|
|
106
|
+
['a Client, in a client spelled otherwise', { kind: 'client', client: 'acme' }, { client: 'Acme' }, false],
|
|
107
|
+
['Studio that names a client', { kind: 'studio', client: 'acme' }, A, false],
|
|
108
|
+
['a Client with no client', { kind: 'client', client: null }, A, false],
|
|
109
|
+
// A scope that names no client is nobody's, a Client who names none included.
|
|
110
|
+
['Studio, in a scope with an empty client', { kind: 'studio', client: null }, { client: '' }, false],
|
|
111
|
+
[
|
|
112
|
+
'a Client with no client, in a scope with none',
|
|
113
|
+
{ kind: 'client', client: undefined as unknown as null },
|
|
114
|
+
{} as Scope,
|
|
115
|
+
false,
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
'a Client with a null client, in a scope with a null one',
|
|
119
|
+
{ kind: 'client', client: null },
|
|
120
|
+
{ client: null } as unknown as Scope,
|
|
121
|
+
false,
|
|
122
|
+
],
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
for (const [who, actor, scope, inside] of SCOPES)
|
|
126
|
+
test(`inScope: ${who} is ${inside ? 'in' : 'out of'} scope`, () => {
|
|
127
|
+
assert.equal(inScope(actor, scope), inside);
|
|
128
|
+
// can() asks inScope first, so out of scope nothing is allowed, whatever the action.
|
|
129
|
+
if (!inside)
|
|
130
|
+
for (const action of ['read', 'comment', 'resolve', 'people'] as const)
|
|
131
|
+
assert.equal(can({ ...studio, ...actor }, scope, action), false, action);
|
|
132
|
+
});
|
|
133
|
+
|
|
77
134
|
test('with no thread, both kinds read and start one; only Studio triages, manages people and sets a prototype’s audience', () => {
|
|
78
135
|
for (const action of ['read', 'comment'] as const) {
|
|
79
|
-
assert.equal(can(studio, action), true);
|
|
80
|
-
assert.equal(can(client, action), true);
|
|
136
|
+
assert.equal(can(studio, A, action), true);
|
|
137
|
+
assert.equal(can(client, A, action), true);
|
|
81
138
|
}
|
|
82
139
|
for (const action of ['triage', 'people', 'audience'] as const) {
|
|
83
|
-
assert.equal(can(studio, action), true);
|
|
84
|
-
assert.equal(can(client, action), false);
|
|
140
|
+
assert.equal(can(studio, A, action), true);
|
|
141
|
+
assert.equal(can(client, A, action), false);
|
|
85
142
|
}
|
|
86
143
|
});
|
|
87
144
|
|
|
88
145
|
test('a reply is judged by its own author, and inside its thread’s audience', () => {
|
|
89
146
|
const root = thread(studio.id, 'client');
|
|
90
147
|
const mine = comment('r', 'c', client.id, 'client');
|
|
91
|
-
assert.equal(can(client, 'edit', root, mine), true);
|
|
92
|
-
assert.equal(can(client, 'delete', root, mine), true);
|
|
93
|
-
assert.equal(can(studio, 'edit', root, mine), false);
|
|
94
|
-
assert.equal(can(studio, 'delete', root, mine), true);
|
|
148
|
+
assert.equal(can(client, A, 'edit', root, mine), true);
|
|
149
|
+
assert.equal(can(client, A, 'delete', root, mine), true);
|
|
150
|
+
assert.equal(can(studio, A, 'edit', root, mine), false);
|
|
151
|
+
assert.equal(can(studio, A, 'delete', root, mine), true);
|
|
95
152
|
// A client-facing reply in an internal thread, or an internal reply in a client-facing one: never a Client's.
|
|
96
|
-
assert.equal(can(client, 'edit', thread(studio.id, 'internal'), mine), false);
|
|
97
|
-
assert.equal(can(client, 'read', root, comment('r', 'c', client.id, 'internal')), false);
|
|
153
|
+
assert.equal(can(client, A, 'edit', thread(studio.id, 'internal'), mine), false);
|
|
154
|
+
assert.equal(can(client, A, 'read', root, comment('r', 'c', client.id, 'internal')), false);
|
|
98
155
|
});
|
|
99
156
|
|
|
100
157
|
test('a record without an audience is internal to the rules', () => {
|
|
101
158
|
const legacy = { ...thread(client.id), audience: undefined } as unknown as Comment;
|
|
102
|
-
assert.equal(can(client, 'read', legacy), false);
|
|
103
|
-
assert.equal(can(studio, 'read', legacy), true);
|
|
159
|
+
assert.equal(can(client, A, 'read', legacy), false);
|
|
160
|
+
assert.equal(can(studio, A, 'read', legacy), true);
|
|
104
161
|
assert.deepEqual(visibleTo('client', [legacy]), []);
|
|
105
162
|
});
|
|
106
163
|
|
package/core/review/policy.ts
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
// Who may do what. Studio runs the review: it adds and revokes people,
|
|
2
|
-
// deletes any comment, corrects triage
|
|
3
|
-
// client-facing. A Client comments, replies, edits
|
|
2
|
+
// deletes any comment, corrects triage, sets which prototypes are
|
|
3
|
+
// client-facing, and sets up clients, their projects and their builds. A Client comments, replies, edits
|
|
4
4
|
// and deletes what they wrote, and resolves or reopens any client-facing
|
|
5
5
|
// thread, because clients work alongside others in their own organisation.
|
|
6
6
|
// An internal thread does not exist for a Client: every action on one is
|
|
7
7
|
// refused. A revoked person, or a visitor who is not signed in, may do
|
|
8
|
-
// nothing here.
|
|
9
|
-
|
|
8
|
+
// nothing here. Nor may anyone outside the op's scope: a Client works only in
|
|
9
|
+
// their own client, and the service answers anything outside it as not found.
|
|
10
|
+
import type { Audience, Comment, Person, PersonKind, Scope } from './model.ts';
|
|
10
11
|
|
|
11
|
-
export type Action =
|
|
12
|
+
export type Action =
|
|
13
|
+
| 'read'
|
|
14
|
+
| 'comment'
|
|
15
|
+
| 'edit'
|
|
16
|
+
| 'delete'
|
|
17
|
+
| 'resolve'
|
|
18
|
+
| 'triage'
|
|
19
|
+
| 'people'
|
|
20
|
+
| 'audience'
|
|
21
|
+
| 'setup';
|
|
12
22
|
|
|
13
23
|
/** Only what the rules read, so the browser's signed-in person (no epoch) is checked by the same rules. */
|
|
14
|
-
type Actor = Pick<Person, 'id' | 'kind' | 'revokedAt'>;
|
|
24
|
+
type Actor = Pick<Person, 'id' | 'kind' | 'revokedAt' | 'client'>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Whether an op in `scope` is the actor's at all: Studio works in every
|
|
28
|
+
* client, a Client only in their own. A person whose kind and client
|
|
29
|
+
* disagree (Studio with a client, a Client with none) is in no scope, and
|
|
30
|
+
* so is every op on a scope that names no client: it fails closed here.
|
|
31
|
+
*/
|
|
32
|
+
export function inScope(actor: Pick<Person, 'kind' | 'client'>, scope: Scope): boolean {
|
|
33
|
+
if (typeof scope.client !== 'string' || scope.client === '') return false;
|
|
34
|
+
return actor.kind === 'studio' ? actor.client === null : actor.client === scope.client;
|
|
35
|
+
}
|
|
15
36
|
|
|
16
37
|
/** Whether a comment reaches a Client. Only the exact value counts, so a record without one stays inside. */
|
|
17
38
|
const clientFacing = (c: Pick<Comment, 'audience'>) => c.audience === 'client';
|
|
@@ -21,8 +42,14 @@ const clientFacing = (c: Pick<Comment, 'audience'>) => c.audience === 'client';
|
|
|
21
42
|
* reply (edit or delete one); without `subject`, the root is the subject.
|
|
22
43
|
* Without a root, the action is on no thread: listing, or a new thread.
|
|
23
44
|
*/
|
|
24
|
-
export function can(
|
|
25
|
-
|
|
45
|
+
export function can(
|
|
46
|
+
actor: Actor | null,
|
|
47
|
+
scope: Scope,
|
|
48
|
+
action: Action,
|
|
49
|
+
root?: Comment,
|
|
50
|
+
subject?: Comment,
|
|
51
|
+
): boolean {
|
|
52
|
+
if (!actor || actor.revokedAt || !inScope(actor, scope)) return false;
|
|
26
53
|
const studio = actor.kind === 'studio';
|
|
27
54
|
if (!studio && [root, subject].some((c) => c && !clientFacing(c))) return false;
|
|
28
55
|
const own = (subject ?? root)?.author.id === actor.id;
|
|
@@ -38,6 +65,7 @@ export function can(actor: Actor | null, action: Action, root?: Comment, subject
|
|
|
38
65
|
case 'triage':
|
|
39
66
|
case 'people':
|
|
40
67
|
case 'audience':
|
|
68
|
+
case 'setup':
|
|
41
69
|
return studio;
|
|
42
70
|
}
|
|
43
71
|
}
|