@milesroxas/design-hub 0.11.1 → 0.12.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 +4 -2
- package/core/prototype.test.ts +52 -0
- package/core/prototype.ts +59 -0
- package/core/review/model.ts +32 -3
- package/core/review/service.test.ts +240 -0
- package/core/review/service.ts +281 -50
- package/core/review/store.ts +10 -4
- package/dist/core/prototype.d.ts +50 -0
- package/dist/core/prototype.js +38 -0
- package/dist/core/review/model.d.ts +25 -1
- package/dist/core/review/model.js +18 -2
- package/dist/core/review/service.d.ts +98 -16
- package/dist/core/review/service.js +254 -45
- package/dist/core/review/store.d.ts +10 -4
- package/dist/scripts/client.d.ts +3 -3
- package/dist/scripts/client.js +52 -66
- package/dist/scripts/lib/dns.d.ts +32 -0
- package/dist/scripts/lib/dns.js +69 -1
- package/dist/scripts/lib/fake-host.d.ts +34 -9
- package/dist/scripts/lib/fake-host.js +7 -4
- package/dist/scripts/lib/review.d.ts +5 -2
- package/dist/scripts/lib/review.js +8 -2
- package/dist/scripts/lib/studios.d.ts +3 -1
- package/dist/scripts/lib/studios.js +2 -0
- package/dist/scripts/people.d.ts +8 -5
- package/dist/scripts/people.js +152 -41
- package/dist/scripts/share.js +1 -1
- package/dist/scripts/studio.d.ts +3 -3
- package/dist/scripts/studio.js +100 -10
- package/dist/server/api.d.ts +6 -8
- package/dist/server/api.js +129 -42
- package/dist/server/hosts.d.ts +3 -3
- package/dist/server/hosts.js +10 -10
- package/dist/server/session.d.ts +7 -0
- package/dist/server/session.js +8 -1
- package/dist/vercel/proxy.d.ts +7 -3
- package/dist/vercel/proxy.js +215 -49
- package/dist/vite/plugin.d.ts +6 -2
- package/dist/vite/plugin.js +21 -3
- package/package.json +1 -1
- package/shell/Index.tsx +29 -0
- package/shell/review/People.tsx +80 -61
- package/shell/review/Review.tsx +49 -1
- package/shell/review/ThreadCard.tsx +13 -1
- package/shell/review/client.ts +56 -22
- package/shell/review/review.css +1 -0
- package/shell/review/unsent.test.ts +63 -0
- package/shell/review/unsent.ts +64 -0
- package/shell/review/view.ts +22 -6
- package/shell/studio/ClientHub.tsx +9 -36
- package/shell/studio/StudioHub.tsx +293 -0
- package/shell/studio/hub.css +80 -5
- package/shell/studio/page.tsx +57 -0
- package/shell/studio/studio.html +14 -0
- package/shell/studio/studio.tsx +19 -0
- package/skills/miles-deploy/SKILL.md +16 -6
- package/skills/miles-design-hub/SKILL.md +3 -3
- package/skills/miles-review/SKILL.md +1 -1
- package/templates/studio/README.md +32 -13
- package/templates/studio/package.json +1 -1
|
@@ -13,7 +13,7 @@ import { base64url, hex, sha256 } from '../bytes.js';
|
|
|
13
13
|
import { controlField, readMarks } from '../controls.js';
|
|
14
14
|
import { isBuildId } from '../files.js';
|
|
15
15
|
import { hostName, isClientSlug, isProjectSlug, isPrototypeSlug } from '../prototype.js';
|
|
16
|
-
import { accessEnd, authorOf, checkAccess, checkAnchor, checkAudience, checkBody, checkClientInput, checkControl, checkPersonInput, checkProjectInput, checkPrototypeAudience, checkStates, checkTriage, checkViewAs, DEFAULT_ACCESS, HOST_SECONDS, hasAccess, isProfile, isRoot, isStudioClient, LINK_DAYS, LOCAL_CLIENT, readClient, readComment, readProject, } from './model.js';
|
|
16
|
+
import { accessEnd, authorOf, checkAccess, checkAnchor, checkAudience, checkBody, checkClientInput, checkControl, checkPersonInput, checkProjectInput, checkPrototypeAudience, checkStates, checkTriage, checkViewAs, DEFAULT_ACCESS, HANDOFF_SECONDS, HOST_SECONDS, hasAccess, isAdded, isProfile, isRoot, isStudioClient, LINK_DAYS, LOCAL_CLIENT, readClient, readComment, readProject, STUDIO_SITE, } from './model.js';
|
|
17
17
|
import { audienceFor, can, inScope, viewOf, visibleTo } from './policy.js';
|
|
18
18
|
import { keyOf, sweepPrefix } from './store.js';
|
|
19
19
|
export class ReviewError extends Error {
|
|
@@ -59,6 +59,8 @@ const NO_PROTOTYPE = 'No such prototype.';
|
|
|
59
59
|
const NO_CLIENT = 'No such client.';
|
|
60
60
|
export const NO_PROJECT = 'No such project.';
|
|
61
61
|
const homeOf = ({ client }) => (client === null ? 'studio' : { client });
|
|
62
|
+
/** Whether a person may be signed in where `at` is: in the client's scope, or Studio on the studio's host. */
|
|
63
|
+
const reaches = (p, at) => at === STUDIO_SITE ? p.kind === 'studio' && p.client === null : inScope(p, at);
|
|
62
64
|
export function createReview(kv, overrides = {}) {
|
|
63
65
|
const deps = { ...defaults, ...overrides };
|
|
64
66
|
const now = () => deps.now().toISOString();
|
|
@@ -197,12 +199,17 @@ export function createReview(kv, overrides = {}) {
|
|
|
197
199
|
if (JSON.parse(json).person === p.id)
|
|
198
200
|
await kv.hdel(links, hash);
|
|
199
201
|
}
|
|
200
|
-
/**
|
|
201
|
-
|
|
202
|
+
/**
|
|
203
|
+
* The link a token names where `at` reaches: a client's scope finds its
|
|
204
|
+
* own client's links and the studio's; the studio's own host only the
|
|
205
|
+
* studio's. Null for a malformed or unknown token.
|
|
206
|
+
*/
|
|
207
|
+
async function findLink(at, token) {
|
|
202
208
|
if (!LINK_TOKEN.test(token))
|
|
203
209
|
return null;
|
|
204
210
|
const hash = await linkKey(token);
|
|
205
|
-
|
|
211
|
+
const homes = at === STUDIO_SITE ? ['studio'] : [at, 'studio'];
|
|
212
|
+
for (const home of homes) {
|
|
206
213
|
const link = parse(await kv.hget(keyOf(home, 'links'), hash));
|
|
207
214
|
if (link)
|
|
208
215
|
return { home, hash, link };
|
|
@@ -210,11 +217,11 @@ export function createReview(kv, overrides = {}) {
|
|
|
210
217
|
return null;
|
|
211
218
|
}
|
|
212
219
|
/** The person a current link signs in, while they may sign in here. */
|
|
213
|
-
async function linkPerson(
|
|
220
|
+
async function linkPerson(at, { home, link }) {
|
|
214
221
|
if (link.expiresAt <= now())
|
|
215
222
|
return null;
|
|
216
223
|
const p = await personAt(home, link.person);
|
|
217
|
-
return active(p) &&
|
|
224
|
+
return active(p) && reaches(p, at) ? p : null;
|
|
218
225
|
}
|
|
219
226
|
async function studioDefault() {
|
|
220
227
|
const stored = await kv.hget(keyOf('studio', 'settings'), 'access');
|
|
@@ -227,10 +234,14 @@ export function createReview(kv, overrides = {}) {
|
|
|
227
234
|
}
|
|
228
235
|
/** A new Studio person, with no link yet; their records live with the studio. */
|
|
229
236
|
async function newStudioPerson(input) {
|
|
230
|
-
const { access, ...fields } = valid(checkPersonInput({ ...input, kind: 'studio' }));
|
|
237
|
+
const { access, team, ...fields } = valid(checkPersonInput({ ...input, kind: 'studio' }));
|
|
238
|
+
// The studio's first person names the studio's team: there is no one to take it from.
|
|
239
|
+
if (!team)
|
|
240
|
+
throw new ReviewError('invalid', 'Name the team.', ['team: required']);
|
|
231
241
|
const p = {
|
|
232
242
|
id: newId(),
|
|
233
243
|
...fields,
|
|
244
|
+
team,
|
|
234
245
|
client: null,
|
|
235
246
|
email: null,
|
|
236
247
|
accessEndsAt: accessEnd(access ?? 'open', deps.now()),
|
|
@@ -284,6 +295,28 @@ export function createReview(kv, overrides = {}) {
|
|
|
284
295
|
throw new ReviewError('not_found', NO_CLIENT);
|
|
285
296
|
return scope.client;
|
|
286
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* The first check of an op on people, where `at` is: in a client's scope,
|
|
300
|
+
* as `allow` checks every op there; on the studio's own host, Studio, over
|
|
301
|
+
* the studio's own people alone.
|
|
302
|
+
*/
|
|
303
|
+
async function allowPeople(at, actor) {
|
|
304
|
+
if (at !== STUDIO_SITE)
|
|
305
|
+
return allow(at, actor, 'people', NO_PERSON);
|
|
306
|
+
allowStudio(actor);
|
|
307
|
+
return actor;
|
|
308
|
+
}
|
|
309
|
+
/** Someone `at` reaches: a Client of the scope's client or a Studio person; on the studio's host, Studio only. */
|
|
310
|
+
const personHere = (at, id) => at === STUDIO_SITE ? personAt('studio', id) : person(at, id);
|
|
311
|
+
/**
|
|
312
|
+
* A client the studio's own host may act for: a studio client's slug, its
|
|
313
|
+
* record there and not archived, added (provenAt), on a host name. Else
|
|
314
|
+
* null, whatever the reason, so each reads as an unknown client.
|
|
315
|
+
*/
|
|
316
|
+
async function openable(slug) {
|
|
317
|
+
const c = isStudioClient(slug) ? await clientAt(slug) : null;
|
|
318
|
+
return c && c.archivedAt === null && isAdded(c) && hostName(c.host) === c.host ? c : null;
|
|
319
|
+
}
|
|
287
320
|
/** Someone Studio can still give a link to. */
|
|
288
321
|
async function needActive(scope, id) {
|
|
289
322
|
const p = await needPerson(scope, id);
|
|
@@ -294,7 +327,7 @@ export function createReview(kv, overrides = {}) {
|
|
|
294
327
|
return p;
|
|
295
328
|
}
|
|
296
329
|
async function needPerson(scope, id) {
|
|
297
|
-
const p = await
|
|
330
|
+
const p = await personHere(scope, id);
|
|
298
331
|
if (!p)
|
|
299
332
|
throw new ReviewError('not_found', NO_PERSON);
|
|
300
333
|
return p;
|
|
@@ -376,6 +409,36 @@ export function createReview(kv, overrides = {}) {
|
|
|
376
409
|
return p?.client === client && p.slug === project ? p : null;
|
|
377
410
|
};
|
|
378
411
|
const saveProject = (p) => kv.hset(keyOf({ client: p.client }, 'projects'), p.slug, JSON.stringify(p));
|
|
412
|
+
/** Every well-formed project of a client, by name, built or not. */
|
|
413
|
+
const projectsOf = async (client) => Object.values(await kv.hgetall(keyOf({ client }, 'projects')))
|
|
414
|
+
.map(readProject)
|
|
415
|
+
.filter((p) => p?.client === client)
|
|
416
|
+
.sort((a, b) => a.name.localeCompare(b.name) || a.slug.localeCompare(b.slug));
|
|
417
|
+
/**
|
|
418
|
+
* What a host serves: null for a host no client has, an archived client,
|
|
419
|
+
* or records that disagree, so an unknown host is never a scope; the
|
|
420
|
+
* studio's own host when its entry names it (setStudioHost).
|
|
421
|
+
*/
|
|
422
|
+
async function siteOfHost(host) {
|
|
423
|
+
const name = hostName(host);
|
|
424
|
+
if (!name)
|
|
425
|
+
return null;
|
|
426
|
+
const slug = await kv.hget(keyOf('studio', 'hosts'), name);
|
|
427
|
+
if (slug === STUDIO_SITE)
|
|
428
|
+
return STUDIO_SITE;
|
|
429
|
+
const c = isClientSlug(slug) ? await clientAt(slug) : null;
|
|
430
|
+
return c && c.host === name && c.archivedAt === null ? c : null;
|
|
431
|
+
}
|
|
432
|
+
/** A stored handoff that is still good, or null for one past its time or not well formed. */
|
|
433
|
+
function readHandoff(json) {
|
|
434
|
+
const h = safeParse(json);
|
|
435
|
+
if (!h || typeof h.person !== 'string' || typeof h.expiresAt !== 'string' || h.expiresAt <= now())
|
|
436
|
+
return null;
|
|
437
|
+
const project = h.project ?? null;
|
|
438
|
+
return project === null || isProjectSlug(project)
|
|
439
|
+
? { person: h.person, project, expiresAt: h.expiresAt }
|
|
440
|
+
: null;
|
|
441
|
+
}
|
|
379
442
|
return {
|
|
380
443
|
person,
|
|
381
444
|
/**
|
|
@@ -384,23 +447,161 @@ export function createReview(kv, overrides = {}) {
|
|
|
384
447
|
* records that disagree, so an unknown host is never a scope.
|
|
385
448
|
*/
|
|
386
449
|
async clientOfHost(host) {
|
|
387
|
-
const
|
|
388
|
-
|
|
450
|
+
const site = await siteOfHost(host);
|
|
451
|
+
return site === STUDIO_SITE ? null : site;
|
|
452
|
+
},
|
|
453
|
+
/**
|
|
454
|
+
* What a host serves, asked by the gate and the studio's functions with
|
|
455
|
+
* no actor: a client (as clientOfHost), the studio's own host, or null.
|
|
456
|
+
*/
|
|
457
|
+
siteOfHost,
|
|
458
|
+
/**
|
|
459
|
+
* Whether the studio's own host has answered its proof (endStudioProof):
|
|
460
|
+
* from then on commands leave it be, and its owner has had a link there.
|
|
461
|
+
* Studio only.
|
|
462
|
+
*/
|
|
463
|
+
async studioHostProven(actor) {
|
|
464
|
+
allowStudio(actor);
|
|
465
|
+
return (await kv.hget(keyOf('studio', 'settings'), 'hostProvenAt')) !== null;
|
|
466
|
+
},
|
|
467
|
+
/**
|
|
468
|
+
* A new proof for the studio's own host, in place of any before it, as
|
|
469
|
+
* startProof is for a client's: only the gate reading this store answers
|
|
470
|
+
* its ask there. Studio only.
|
|
471
|
+
*/
|
|
472
|
+
async startStudioProof(actor) {
|
|
473
|
+
allowStudio(actor);
|
|
474
|
+
const ask = base64url(deps.random(32));
|
|
475
|
+
const answer = base64url(deps.random(32));
|
|
476
|
+
const key = keyOf('studio', 'proof');
|
|
477
|
+
await kv.del(key);
|
|
478
|
+
await kv.hset(key, await linkKey(ask), answer);
|
|
479
|
+
return { ask, answer };
|
|
480
|
+
},
|
|
481
|
+
/** Ends the studio host's proof once it answered, marking the host proven; the mark goes on first. Studio only. */
|
|
482
|
+
async endStudioProof(actor) {
|
|
483
|
+
allowStudio(actor);
|
|
484
|
+
await kv.hsetnx(keyOf('studio', 'settings'), 'hostProvenAt', now());
|
|
485
|
+
await kv.del(keyOf('studio', 'proof'));
|
|
486
|
+
},
|
|
487
|
+
/** The answer to the studio host's proof, asked by the gate on that host with no actor: null for any other ask. */
|
|
488
|
+
async studioProofAnswer(ask) {
|
|
489
|
+
if (typeof ask !== 'string' || !LINK_TOKEN.test(ask))
|
|
389
490
|
return null;
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
491
|
+
return kv.hget(keyOf('studio', 'proof'), await linkKey(ask));
|
|
492
|
+
},
|
|
493
|
+
/**
|
|
494
|
+
* Makes `host` the studio's own host (`studio.<apex>`), where Studio
|
|
495
|
+
* signs in and sees every client. Refused for a host a client has, or
|
|
496
|
+
* one that is not a host name. Safe to run again. Studio only.
|
|
497
|
+
*/
|
|
498
|
+
async setStudioHost(actor, host) {
|
|
499
|
+
allowStudio(actor);
|
|
500
|
+
if (hostName(host) !== host)
|
|
501
|
+
throw new ReviewError('invalid', 'Some fields are not valid.', ['host: a host name in lower case']);
|
|
502
|
+
const hosts = keyOf('studio', 'hosts');
|
|
503
|
+
if (await kv.hsetnx(hosts, host, STUDIO_SITE))
|
|
504
|
+
return 'added';
|
|
505
|
+
if ((await kv.hget(hosts, host)) === STUDIO_SITE)
|
|
506
|
+
return 'kept';
|
|
507
|
+
throw new ReviewError('invalid', 'That host already serves a client.', ['host: the studio’s own']);
|
|
508
|
+
},
|
|
509
|
+
/**
|
|
510
|
+
* Every client record the studio has, by name, each with all its
|
|
511
|
+
* projects by name, archived ones too (an archive that stopped part way).
|
|
512
|
+
* The studio's own view, for its hub and `client list`. Studio only.
|
|
513
|
+
*/
|
|
514
|
+
async listClients(actor) {
|
|
515
|
+
allowStudio(actor);
|
|
516
|
+
const records = Object.entries(await kv.hgetall(keyOf('studio', 'clients')))
|
|
517
|
+
.map(([slug, json]) => ({ slug, c: readClient(json) }))
|
|
518
|
+
.filter((r) => r.c?.slug === r.slug)
|
|
519
|
+
.map((r) => r.c)
|
|
520
|
+
.sort((a, b) => a.name.localeCompare(b.name) || a.slug.localeCompare(b.slug));
|
|
521
|
+
return Promise.all(records.map(async (client) => ({ client, projects: await projectsOf(client.slug) })));
|
|
522
|
+
},
|
|
523
|
+
/**
|
|
524
|
+
* The client an op on the studio's own host names, for its people: known,
|
|
525
|
+
* not archived and added, as a handoff checks it (openable). Anything
|
|
526
|
+
* else is not found, an unknown client's answer. Studio only.
|
|
527
|
+
*/
|
|
528
|
+
async studioClient(actor, slug) {
|
|
529
|
+
allowStudio(actor);
|
|
530
|
+
const c = await openable(slug);
|
|
531
|
+
if (!c)
|
|
532
|
+
throw new ReviewError('not_found', NO_CLIENT);
|
|
533
|
+
return c;
|
|
534
|
+
},
|
|
535
|
+
/**
|
|
536
|
+
* A handoff: the actor, a Studio person signed in on the studio's host,
|
|
537
|
+
* opens one client's hub, or one of its projects with a build, on the
|
|
538
|
+
* client's host. Answers the host from the client's record and a new
|
|
539
|
+
* token, which the host claims once within HANDOFF_SECONDS (claimHandoff).
|
|
540
|
+
* A client archived, gone or still being added (no provenAt), a project
|
|
541
|
+
* it does not have or has not built, and a host that is no host name are
|
|
542
|
+
* all not found. The store keeps the token as its hash. Studio only.
|
|
543
|
+
*/
|
|
544
|
+
async startHandoff(actor, input) {
|
|
545
|
+
allowStudio(actor);
|
|
546
|
+
const c = await openable(input.client);
|
|
547
|
+
if (!c)
|
|
548
|
+
throw new ReviewError('not_found', NO_CLIENT);
|
|
549
|
+
const project = input.project ?? null;
|
|
550
|
+
if (project !== null) {
|
|
551
|
+
const p = isProjectSlug(project) ? await projectAt({ client: c.slug, project }) : null;
|
|
552
|
+
if (!p?.build)
|
|
553
|
+
throw new ReviewError('not_found', NO_PROJECT);
|
|
554
|
+
}
|
|
555
|
+
const key = keyOf({ client: c.slug }, 'handoffs');
|
|
556
|
+
// Handoffs nobody claimed go as new ones are made, so the record never grows past a few.
|
|
557
|
+
for (const [hash, json] of Object.entries(await kv.hgetall(key)))
|
|
558
|
+
if (!readHandoff(json))
|
|
559
|
+
await kv.hdel(key, hash);
|
|
560
|
+
const token = base64url(deps.random(32));
|
|
561
|
+
const handoff = {
|
|
562
|
+
person: actor.id,
|
|
563
|
+
project: project,
|
|
564
|
+
expiresAt: new Date(deps.now().getTime() + HANDOFF_SECONDS * 1000).toISOString(),
|
|
565
|
+
};
|
|
566
|
+
await kv.hset(key, await linkKey(token), JSON.stringify(handoff));
|
|
567
|
+
return { host: c.host, token };
|
|
568
|
+
},
|
|
569
|
+
/**
|
|
570
|
+
* Claims a handoff on the scope's client's host, asked by the gate with
|
|
571
|
+
* no actor: the Studio person it was made for and the project to open
|
|
572
|
+
* (null for the client's hub), or null. Only a handoff made for this
|
|
573
|
+
* client is found; one past HANDOFF_SECONDS, one for a client no longer
|
|
574
|
+
* added, or a person who may no longer sign in is null. The delete is
|
|
575
|
+
* the claim, as useLink's, so of two requests with one token only one
|
|
576
|
+
* gets a person; every check comes before it.
|
|
577
|
+
*/
|
|
578
|
+
async claimHandoff(scope, token) {
|
|
579
|
+
if (!isStudioClient(scope.client) || typeof token !== 'string' || !LINK_TOKEN.test(token))
|
|
580
|
+
return null;
|
|
581
|
+
const key = keyOf({ client: scope.client }, 'handoffs');
|
|
582
|
+
const hash = await linkKey(token);
|
|
583
|
+
const handoff = readHandoff(await kv.hget(key, hash));
|
|
584
|
+
if (!handoff)
|
|
585
|
+
return null;
|
|
586
|
+
const { project } = handoff;
|
|
587
|
+
const c = await clientAt(scope.client);
|
|
588
|
+
if (!c || c.archivedAt !== null || !isAdded(c))
|
|
589
|
+
return null;
|
|
590
|
+
const p = await personAt('studio', handoff.person);
|
|
591
|
+
if (!active(p))
|
|
592
|
+
return null;
|
|
593
|
+
if ((await kv.hdel(key, hash)) !== 1)
|
|
594
|
+
return null;
|
|
595
|
+
// A revoke or sign out everywhere can land between the check and the claim: read again.
|
|
596
|
+
const after = await personAt('studio', p.id);
|
|
597
|
+
return active(after) && after.epoch === p.epoch ? { person: after, project } : null;
|
|
393
598
|
},
|
|
394
599
|
/** One project of the scope's client, asked with no actor: null when the client has none by that name. */
|
|
395
600
|
projectOf: projectAt,
|
|
396
601
|
/** Every project of the scope's client that has a build to open, by name. */
|
|
397
602
|
async listProjects(scope, actor) {
|
|
398
603
|
await allow(scope, actor, 'read', NO_PROJECT);
|
|
399
|
-
|
|
400
|
-
return stored
|
|
401
|
-
.map(readProject)
|
|
402
|
-
.filter((p) => p?.client === scope.client && p.build !== null)
|
|
403
|
-
.sort((a, b) => a.name.localeCompare(b.name) || a.slug.localeCompare(b.slug));
|
|
604
|
+
return (await projectsOf(scope.client)).filter((p) => p.build !== null);
|
|
404
605
|
},
|
|
405
606
|
/**
|
|
406
607
|
* A new client and its host. Studio only. The slug and the host are each
|
|
@@ -659,31 +860,38 @@ export function createReview(kv, overrides = {}) {
|
|
|
659
860
|
if (isBuildId(build) && build !== live)
|
|
660
861
|
await kv.hdel(keyOf(scope, 'builds'), build);
|
|
661
862
|
},
|
|
662
|
-
/** The person a signed session names, if they still may sign in with it, here. */
|
|
663
|
-
async sessionPerson(
|
|
664
|
-
const p = await person(
|
|
665
|
-
return active(p) && p.epoch === epoch &&
|
|
863
|
+
/** The person a signed session names, if they still may sign in with it, here: in a client's scope, or Studio on the studio's host. */
|
|
864
|
+
async sessionPerson(at, id, epoch) {
|
|
865
|
+
const p = at === STUDIO_SITE ? await personAt('studio', id) : await person(at, id);
|
|
866
|
+
return active(p) && p.epoch === epoch && reaches(p, at) ? p : null;
|
|
666
867
|
},
|
|
667
|
-
/** The scope's Clients and every Studio person. */
|
|
668
|
-
async listPeople(
|
|
669
|
-
await
|
|
670
|
-
const all = [...(await peopleAt('studio')), ...(await peopleAt(
|
|
868
|
+
/** The scope's Clients and every Studio person; on the studio's own host, the Studio people alone. */
|
|
869
|
+
async listPeople(at, actor) {
|
|
870
|
+
await allowPeople(at, actor);
|
|
871
|
+
const all = [...(await peopleAt('studio')), ...(at === STUDIO_SITE ? [] : await peopleAt(at))];
|
|
671
872
|
return all.sort((a, b) => a.team.localeCompare(b.team) || a.name.localeCompare(b.name));
|
|
672
873
|
},
|
|
673
874
|
/**
|
|
674
875
|
* A new person and their first link: a Client of the scope's client, or a
|
|
675
|
-
* Studio person
|
|
676
|
-
* Studio is open-ended.
|
|
876
|
+
* Studio person; on the studio's own host, a Studio person only. Without
|
|
877
|
+
* an access length, a Client gets the default and Studio is open-ended.
|
|
878
|
+
* Without a team, a Studio person gets the studio's, which every Studio
|
|
879
|
+
* person carries, so the adder's; a Client gets their client's name.
|
|
677
880
|
*/
|
|
678
|
-
async addPerson(
|
|
679
|
-
await
|
|
680
|
-
const { access, ...fields } = valid(checkPersonInput(input));
|
|
881
|
+
async addPerson(at, actor, input) {
|
|
882
|
+
const by = await allowPeople(at, actor);
|
|
883
|
+
const { access, team, ...fields } = valid(checkPersonInput(input));
|
|
884
|
+
// A Client belongs to one client: the studio's own host names none.
|
|
885
|
+
const scope = fields.kind === 'studio' ? null : at;
|
|
886
|
+
if (scope === STUDIO_SITE)
|
|
887
|
+
throw new ReviewError('invalid', 'Some fields are not valid.', ['kind: studio here']);
|
|
681
888
|
// S13: the person's own length, else (a Client) the client's default, then the studio's, then 3m.
|
|
682
|
-
const length = access ?? (
|
|
889
|
+
const length = access ?? (scope ? await readDefault(scope) : 'open');
|
|
683
890
|
const p = {
|
|
684
891
|
id: newId(),
|
|
685
892
|
...fields,
|
|
686
|
-
|
|
893
|
+
team: team ?? (scope ? ((await clientAt(scope.client))?.name ?? 'Client') : by.team),
|
|
894
|
+
client: scope ? scope.client : null,
|
|
687
895
|
email: null,
|
|
688
896
|
accessEndsAt: accessEnd(length, deps.now()),
|
|
689
897
|
createdAt: now(),
|
|
@@ -695,13 +903,13 @@ export function createReview(kv, overrides = {}) {
|
|
|
695
903
|
},
|
|
696
904
|
/** Another one-time link, for another device. Their sessions and other unused links stay. */
|
|
697
905
|
async newLink(scope, actor, id) {
|
|
698
|
-
await
|
|
906
|
+
await allowPeople(scope, actor);
|
|
699
907
|
const p = await needActive(scope, id);
|
|
700
908
|
return { person: p, token: await issueLink(p) };
|
|
701
909
|
},
|
|
702
910
|
/** Ends every session they hold and every unused link, and gives one new link. */
|
|
703
911
|
async signOutEverywhere(scope, actor, id) {
|
|
704
|
-
await
|
|
912
|
+
await allowPeople(scope, actor);
|
|
705
913
|
const p = await needActive(scope, id);
|
|
706
914
|
// The epoch first: a failure after it has still ended every session. Atomic, so two at once raise it twice.
|
|
707
915
|
const next = { ...p, epoch: await kv.hincrby(keyOf(homeOf(p), 'epochs'), id, 1) };
|
|
@@ -709,7 +917,7 @@ export function createReview(kv, overrides = {}) {
|
|
|
709
917
|
return { person: next, token: await issueLink(next) };
|
|
710
918
|
},
|
|
711
919
|
async revoke(scope, actor, id) {
|
|
712
|
-
const by = await
|
|
920
|
+
const by = await allowPeople(scope, actor);
|
|
713
921
|
if (by.id === id)
|
|
714
922
|
throw new ReviewError('invalid', 'You cannot revoke yourself.');
|
|
715
923
|
const p = await needPerson(scope, id);
|
|
@@ -724,7 +932,7 @@ export function createReview(kv, overrides = {}) {
|
|
|
724
932
|
},
|
|
725
933
|
/** Sets one person's access length, counted from now. Their sessions follow at the gate's next check, within five minutes. */
|
|
726
934
|
async setAccess(scope, actor, id, access) {
|
|
727
|
-
await
|
|
935
|
+
await allowPeople(scope, actor);
|
|
728
936
|
const length = valid(checkAccess(access));
|
|
729
937
|
const p = await needPerson(scope, id);
|
|
730
938
|
if (p.revokedAt)
|
|
@@ -762,7 +970,7 @@ export function createReview(kv, overrides = {}) {
|
|
|
762
970
|
allowStudio(actor);
|
|
763
971
|
return newStudioPerson(input);
|
|
764
972
|
},
|
|
765
|
-
/** Another one-time link for a Studio person: it signs in one device, on whichever client host it is opened. Studio only. */
|
|
973
|
+
/** Another one-time link for a Studio person: it signs in one device, on the studio's host or whichever client host it is opened. Studio only. */
|
|
766
974
|
async newStudioLink(actor, id) {
|
|
767
975
|
allowStudio(actor);
|
|
768
976
|
const p = await personAt('studio', id);
|
|
@@ -784,21 +992,22 @@ export function createReview(kv, overrides = {}) {
|
|
|
784
992
|
return length;
|
|
785
993
|
},
|
|
786
994
|
/** Who a link signs in here, without using it: mail and chat previews open links too. */
|
|
787
|
-
async peekLink(
|
|
788
|
-
const found = await findLink(
|
|
789
|
-
return found ? linkPerson(
|
|
995
|
+
async peekLink(at, token) {
|
|
996
|
+
const found = await findLink(at, token);
|
|
997
|
+
return found ? linkPerson(at, found) : null;
|
|
790
998
|
},
|
|
791
999
|
/**
|
|
792
1000
|
* Uses a link up and returns who it signs in. The delete is the claim: of
|
|
793
1001
|
* two requests with one token, only the one whose delete removed the link
|
|
794
1002
|
* gets a person, so a link signs in one device at most. Who it signs in is
|
|
795
1003
|
* read and checked first, so the delete is the last store call. Only a
|
|
796
|
-
* link of the scope's client, or a Studio person's, is found at all
|
|
1004
|
+
* link of the scope's client, or a Studio person's, is found at all; on
|
|
1005
|
+
* the studio's own host, only a Studio person's.
|
|
797
1006
|
*/
|
|
798
|
-
async useLink(
|
|
799
|
-
const found = await findLink(
|
|
1007
|
+
async useLink(at, token) {
|
|
1008
|
+
const found = await findLink(at, token);
|
|
800
1009
|
// Every read and check comes before the delete, so a store failure before it leaves the link usable.
|
|
801
|
-
const p = found && (await linkPerson(
|
|
1010
|
+
const p = found && (await linkPerson(at, found));
|
|
802
1011
|
if (!found || !p)
|
|
803
1012
|
return null;
|
|
804
1013
|
if ((await kv.hdel(keyOf(found.home, 'links'), found.hash)) !== 1)
|
|
@@ -24,15 +24,19 @@ export interface KV {
|
|
|
24
24
|
/**
|
|
25
25
|
* The studio's own records: Studio people (profile, revocation, epoch and
|
|
26
26
|
* links, as a client's below) and `settings`, one field each: `access` is the
|
|
27
|
-
* default access length
|
|
27
|
+
* default access length, `hostProvenAt` when the studio's own host first
|
|
28
|
+
* answered its proof. `proof`: while a command waits for the studio's own
|
|
29
|
+
* host, one field, hex(sha256(ask)) to the answer the gate gives there.
|
|
30
|
+
* `mark`, one field, `id`: the id of the one studio
|
|
28
31
|
* this database serves (its studio.json `id`), set once by `studio create`
|
|
29
32
|
* and checked by every command before it acts (server/mark.ts). No other
|
|
30
33
|
* key names a studio, so two studios on one database would be one studio.
|
|
31
34
|
*/
|
|
32
|
-
type StudioName = 'people' | 'revoked' | 'epochs' | 'links' | 'settings' | 'mark';
|
|
35
|
+
type StudioName = 'people' | 'revoked' | 'epochs' | 'links' | 'settings' | 'mark' | 'proof';
|
|
33
36
|
/**
|
|
34
37
|
* The studio's clients, outside every scope: `clients`, a client's slug to
|
|
35
|
-
* its Client; `hosts`, a host name to the slug of the client it serves
|
|
38
|
+
* its Client; `hosts`, a host name to the slug of the client it serves, or
|
|
39
|
+
* to `studio` (STUDIO_SITE) for the studio's own host, which no client slug is;
|
|
36
40
|
* `claims`, one counter per slug (`client:<slug>`) and per host
|
|
37
41
|
* (`host:<host>`), raised by HINCRBY when a client is added: whoever raised
|
|
38
42
|
* it to 1 holds it, so two adds at once never both get one. Archiving a
|
|
@@ -51,9 +55,11 @@ type DirectoryName = 'clients' | 'hosts' | 'claims' | 'held';
|
|
|
51
55
|
* `projects`: the client's projects, a slug to its Project. `proof`: while
|
|
52
56
|
* `client add` waits for the client's host, one field, hex(sha256(ask)) to
|
|
53
57
|
* the answer the gate gives for that ask (PROOF_PATH in prototype.ts).
|
|
58
|
+
* `handoffs`: Studio opening this client from the studio's host,
|
|
59
|
+
* hex(sha256(token)) to a Handoff, deleted when the client's host claims it.
|
|
54
60
|
*/
|
|
55
61
|
type ClientName = 'people' | 'revoked' | 'epochs' | 'links';
|
|
56
|
-
type ClientOnlyName = 'projects' | 'proof';
|
|
62
|
+
type ClientOnlyName = 'projects' | 'proof' | 'handoffs';
|
|
57
63
|
/**
|
|
58
64
|
* A project's records. `audiences`: which prototypes are client-facing,
|
|
59
65
|
* field `<slug>`, value `client`; only client-facing is stored, internal is
|
package/dist/scripts/client.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { type Args } from './lib/cli.ts';
|
|
|
3
3
|
import { type StudioDeps } from './lib/studio-deps.ts';
|
|
4
4
|
export declare const spec: {
|
|
5
5
|
readonly name: 'client';
|
|
6
|
-
readonly summary: 'Add a client to a studio with its host and first sign-in
|
|
6
|
+
readonly summary: 'Add a client to a studio with its host and its first person’s sign-in link, archive one, list them, or set how long its people keep access.';
|
|
7
7
|
readonly positionals: [{
|
|
8
8
|
readonly name: 'action';
|
|
9
9
|
readonly required: true;
|
|
10
|
-
readonly description: 'add <slug>: the client, its host and its first
|
|
10
|
+
readonly description: 'add <slug>: the client, its host and its first person’s link (Studio opens it from studio.<apex>). list: every client, with its host, state and project count. archive <slug>: remove it, its people, projects, comments and files, then its DNS record (only one this studio made) and its host on the site; run it again to finish one that stopped part way. An archived slug or host can be added again two minutes later. access [slug]: read or set (--access) the client’s default access length; without a slug, the studio’s.';
|
|
11
11
|
}, {
|
|
12
12
|
readonly name: 'slug';
|
|
13
13
|
readonly description: 'The client, kebab-case; never studio, www, api or site.';
|
|
@@ -39,7 +39,7 @@ export declare const spec: {
|
|
|
39
39
|
readonly description: 'For access: 3m, 6m or open; with a slug, studio hands the client back to the studio’s default. A person’s own length wins over both.';
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
readonly output: 'add: { ok, client, host, dns, links: { client
|
|
42
|
+
readonly output: 'add: { ok, client, host, dns, links: { client }, notice?, next }. list: { ok, clients: [{ slug, name, host, state: added | waiting | archived, projects }] } (waiting: its add has not finished; archived: its archive has not finished). archive: { ok, client, host, domain: removed | absent | wildcard | kept (another client has the host) | unknown, files, dns?: { removed, left, fix? } | { record, fix } }. access: { ok, client?, access, default }';
|
|
43
43
|
};
|
|
44
44
|
export declare function run({ positionals: [action, slug], flags }: Args<typeof spec>, deps: StudioDeps): Promise<Record<string, unknown>>;
|
|
45
45
|
export declare const main: (args: Args<typeof spec>) => Promise<Record<string, unknown>>;
|