@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
package/dist/vercel/proxy.js
CHANGED
|
@@ -8,8 +8,11 @@
|
|
|
8
8
|
// POST /invite/<token> uses the link up, sets the person's signed cookie
|
|
9
9
|
// (server/session.ts) and goes to the client's hub
|
|
10
10
|
//
|
|
11
|
-
// A used, expired or unknown link is 404.
|
|
12
|
-
//
|
|
11
|
+
// A used, expired or unknown link is 404. Studio has its own host as well,
|
|
12
|
+
// `studio.<apex>`, where only a Studio person's link and cookie hold, and
|
|
13
|
+
// from which a Studio person opens any client with a one-time handoff that
|
|
14
|
+
// the client's host claims (`/_gate/handoff/<token>`). Every other path needs
|
|
15
|
+
// the cookie, signed to the host's client. It carries when the store last said yes;
|
|
13
16
|
// after CHECK_SECONDS (5 minutes) the gate asks the store again on the next
|
|
14
17
|
// request of any kind, so a revoke, a sign out everywhere or a changed access
|
|
15
18
|
// end reaches every request within minutes. A store that does not answer is
|
|
@@ -21,10 +24,12 @@
|
|
|
21
24
|
import { next, rewrite } from '@vercel/functions';
|
|
22
25
|
import { base64, sha256 } from '../core/bytes.js';
|
|
23
26
|
import { escapeHtml } from '../core/html.js';
|
|
24
|
-
import { GATE_FONT, isPrototypeSlug, PROOF_PATH, routeOf } from '../core/prototype.js';
|
|
27
|
+
import { GATE_FONT, handoffPath, hostName, isPrototypeSlug, PROOF_PATH, routeOf, STUDIO_PAGE, studioRouteOf, } from '../core/prototype.js';
|
|
28
|
+
import { STUDIO_SITE, } from '../core/review/model.js';
|
|
29
|
+
import { ReviewError } from '../core/review/service.js';
|
|
25
30
|
import { studioReview } from '../server/api.js';
|
|
26
31
|
import { hostCache, hostOf } from '../server/hosts.js';
|
|
27
|
-
import { clearedCookie, isFresh, issuePersonToken, PERSON_COOKIE, readCookie, readPersonToken, sameOrigin, sessionCookie, sessionSeconds, } from '../server/session.js';
|
|
32
|
+
import { clearedCookie, isFresh, issuePersonToken, PERSON_COOKIE, readCookie, readPersonToken, sameOrigin, sessionCookie, sessionSeconds, studioGate, } from '../server/session.js';
|
|
28
33
|
export const DEFAULT_SITE_NAME = 'Prototypes';
|
|
29
34
|
// What the gate pages load before sign-in: the hub's face (the Vite plugin
|
|
30
35
|
// emits it at this fixed path, at the host root) and the favicon. Nothing else.
|
|
@@ -85,17 +90,24 @@ const linkPage = (siteName, person) => shell(siteName, 'link', `<p>This link sig
|
|
|
85
90
|
<p>It works once. For another device, ask the studio for a new link.</p>
|
|
86
91
|
<form method="post"><button class="go" type="submit" autofocus>Continue</button></form>`);
|
|
87
92
|
// Someone who opens their link again on a device it already signed in gets
|
|
88
|
-
// here too, so the page offers the way in as well
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
<a
|
|
93
|
+
// here too, so the page offers the way in as well: the prototypes on a
|
|
94
|
+
// client's host, the list of clients on the studio's own.
|
|
95
|
+
const usedPage = (siteName, home = 'prototypes') => shell(siteName, 'used', `<p>This link has been used, has expired or was removed. Each link signs in one device, then stops working.</p>
|
|
96
|
+
<p>Ask the studio for a new one. If this device is already signed in, open the ${home}.</p>
|
|
97
|
+
<a class="go" href="/">Open the ${home}</a>`);
|
|
98
|
+
/**
|
|
99
|
+
* On the studio's own host, after Open: why the client did not open, and the
|
|
100
|
+
* way back to the clients. Only a Studio person signed in there meets it.
|
|
101
|
+
*/
|
|
102
|
+
const stoppedPage = (siteName, why) => shell(siteName, 'stopped', `<p>${escapeHtml(why)}</p>\n<a class="go" href="/">Back to the clients</a>`);
|
|
92
103
|
const SIGNED_OUT = 'Sign in with the link the studio sent you.';
|
|
93
104
|
const USED = 'This link has been used, has expired or was removed.';
|
|
94
105
|
const OPEN_IN_BROWSER = 'Open this link in a browser to sign in.';
|
|
95
106
|
const PREVIEWS = {
|
|
96
107
|
'sign-in': signInPage,
|
|
97
108
|
link: (siteName) => linkPage(siteName, { name: 'Rae Chen', team: 'Acme' }),
|
|
98
|
-
used: usedPage,
|
|
109
|
+
used: (siteName) => usedPage(siteName),
|
|
110
|
+
stopped: (siteName) => stoppedPage(siteName, NOT_OPENED),
|
|
99
111
|
};
|
|
100
112
|
// `design-hub dev` has no gate; the Vite plugin serves this at /_gate/ (?page=link or ?page=used) so the pages can be reviewed.
|
|
101
113
|
export async function gatePreview(page, siteName = DEFAULT_SITE_NAME) {
|
|
@@ -170,14 +182,20 @@ async function ask(run) {
|
|
|
170
182
|
return undefined;
|
|
171
183
|
}
|
|
172
184
|
}
|
|
173
|
-
|
|
185
|
+
/**
|
|
186
|
+
* What a link that signs nobody in here answers, on any host: the used page,
|
|
187
|
+
* 404, its way in the host's own `/`. On the studio's own host only Studio
|
|
188
|
+
* links are looked up, so a Client's link there reads as an unknown one.
|
|
189
|
+
*/
|
|
190
|
+
const noLink = ({ siteName, request }, at) => page(request, 404, usedPage(siteName, at === STUDIO_SITE ? 'clients' : 'prototypes'), USED);
|
|
191
|
+
async function showLink(ctx, review, at, token) {
|
|
174
192
|
const { siteName, request } = ctx;
|
|
175
|
-
const person = await ask(() => review.peekLink(
|
|
193
|
+
const person = await ask(() => review.peekLink(at, token));
|
|
176
194
|
if (person === undefined)
|
|
177
195
|
return storeDown(request);
|
|
178
196
|
return person
|
|
179
197
|
? page(request, 200, linkPage(siteName, person), OPEN_IN_BROWSER, { referrer: 'same-origin' })
|
|
180
|
-
:
|
|
198
|
+
: noLink(ctx, at);
|
|
181
199
|
}
|
|
182
200
|
/** The cookie for someone the store just said yes to, lasting to their access end. */
|
|
183
201
|
async function sessionFor(gate, person, at) {
|
|
@@ -185,27 +203,31 @@ async function sessionFor(gate, person, at) {
|
|
|
185
203
|
const token = await issuePersonToken(gate, claim, person.accessEndsAt, at);
|
|
186
204
|
return sessionCookie(PERSON_COOKIE, token, sessionSeconds(person.accessEndsAt, at));
|
|
187
205
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const
|
|
206
|
+
/** A 303 to `location` on this host, setting `cookie`: where a link or a handoff sends the person it signed in. */
|
|
207
|
+
function signedIn(cookie, location) {
|
|
208
|
+
const headers = gateHeaders('text/plain; charset=utf-8', { cookie });
|
|
209
|
+
headers.set('location', location);
|
|
210
|
+
return new Response(null, { status: 303, headers });
|
|
211
|
+
}
|
|
212
|
+
async function signInWithLink(ctx, { review, gate }, at, token) {
|
|
213
|
+
const { request } = ctx;
|
|
214
|
+
const person = await ask(() => review.useLink(at, token));
|
|
191
215
|
if (person === undefined)
|
|
192
216
|
return storeDown(request);
|
|
193
217
|
if (!person)
|
|
194
|
-
return
|
|
195
|
-
|
|
196
|
-
headers.set('location', '/');
|
|
197
|
-
return new Response(null, { status: 303, headers });
|
|
218
|
+
return noLink(ctx, at);
|
|
219
|
+
return signedIn(await sessionFor(gate, person, ctx.at), '/');
|
|
198
220
|
}
|
|
199
|
-
/** A one-time link
|
|
200
|
-
async function link(ctx, setup,
|
|
221
|
+
/** A one-time link where `at` reaches: shown on a read, used on a same-origin POST. */
|
|
222
|
+
async function link(ctx, setup, at, token) {
|
|
201
223
|
const { request } = ctx;
|
|
202
224
|
if (request.method === 'POST' && !sameOrigin(request))
|
|
203
225
|
return plain(request, 403, 'Forbidden');
|
|
204
226
|
if (request.method !== 'POST' && !isRead(request))
|
|
205
227
|
return plain(request, 405, 'Method not allowed', { allow: 'GET, HEAD, POST' });
|
|
206
228
|
return request.method === 'POST'
|
|
207
|
-
? signInWithLink(ctx, setup,
|
|
208
|
-
: showLink(ctx, setup.review,
|
|
229
|
+
? signInWithLink(ctx, setup, at, token)
|
|
230
|
+
: showLink(ctx, setup.review, at, token);
|
|
209
231
|
}
|
|
210
232
|
/**
|
|
211
233
|
* No session. A page gets the sign-in page, and anything else (an asset, a
|
|
@@ -236,20 +258,35 @@ async function prototypeOpen(review, scope, slug) {
|
|
|
236
258
|
}
|
|
237
259
|
const NOT_THERE = { refused: 'not-found' };
|
|
238
260
|
const DOWN = { refused: 'store-down' };
|
|
239
|
-
/**
|
|
240
|
-
|
|
261
|
+
/** What the request's host serves, or why nothing: a site not set up, a store that did not answer, or the plain 404. */
|
|
262
|
+
async function lookUp(request, hosts, at) {
|
|
241
263
|
const setup = studioReview(process.env, null, () => at);
|
|
242
264
|
if ('error' in setup)
|
|
243
265
|
return { refused: 'unavailable', error: setup.error };
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
266
|
+
const host = hostName(hostOf(request));
|
|
267
|
+
const site = host ? await ask(() => hosts(host, (h) => setup.review.siteOfHost(h))) : null;
|
|
268
|
+
if (site === undefined)
|
|
247
269
|
return DOWN;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
270
|
+
return site ? { review: setup.review, keys: setup.keys, site } : NOT_THERE;
|
|
271
|
+
}
|
|
272
|
+
/** A client's host: its gate and scope, and where `pathname` goes on it. */
|
|
273
|
+
function placeOf({ review, keys }, client, request, pathname) {
|
|
274
|
+
const gate = { ...keys, client: client.slug, since: client.createdAt };
|
|
251
275
|
const place = { client, gate, scope: { client: client.slug } };
|
|
252
|
-
return { review
|
|
276
|
+
return { review, place, route: routeOf(hostOf(request), pathname) };
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* The client `pathname` is asked of on the request's host, or why there is
|
|
280
|
+
* none: an unknown host is the plain 404, and so is the studio's own host,
|
|
281
|
+
* which serves no client's anything.
|
|
282
|
+
*/
|
|
283
|
+
export async function findPlace(request, pathname, hosts, at) {
|
|
284
|
+
const looked = await lookUp(request, hosts, at);
|
|
285
|
+
if ('refused' in looked)
|
|
286
|
+
return looked;
|
|
287
|
+
if (looked.site === STUDIO_SITE)
|
|
288
|
+
return NOT_THERE;
|
|
289
|
+
return placeOf(looked, looked.site, request, pathname);
|
|
253
290
|
}
|
|
254
291
|
/**
|
|
255
292
|
* The project a route names, when it is the client's, and for a Client, only
|
|
@@ -259,7 +296,7 @@ export async function findPlace(request, pathname, hosts, at) {
|
|
|
259
296
|
* is not there.
|
|
260
297
|
*/
|
|
261
298
|
async function boundary({ review, place, route }, kind) {
|
|
262
|
-
if (route.kind === 'none' || route.kind === 'link')
|
|
299
|
+
if (route.kind === 'none' || route.kind === 'link' || route.kind === 'handoff')
|
|
263
300
|
return NOT_THERE;
|
|
264
301
|
const named = route.kind === 'file' || route.kind === 'api' ? route.project : null;
|
|
265
302
|
if (named === null)
|
|
@@ -275,25 +312,33 @@ async function boundary({ review, place, route }, kind) {
|
|
|
275
312
|
const open = await prototypeOpen(review, scope, route.prototype);
|
|
276
313
|
return open === undefined ? DOWN : open ? project : NOT_THERE;
|
|
277
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* The session a request's cookie carries where `at` is, signed to `gate`'s
|
|
317
|
+
* client, and asked of the store again once its stamp is stale. On the
|
|
318
|
+
* studio's own host only a Studio person's holds.
|
|
319
|
+
*/
|
|
320
|
+
async function session(review, gate, at, request, time) {
|
|
321
|
+
const cookie = readCookie(request, PERSON_COOKIE);
|
|
322
|
+
const claim = await readPersonToken(gate, cookie, time);
|
|
323
|
+
if (!claim || (at === STUDIO_SITE && claim.kind !== 'studio'))
|
|
324
|
+
return { refused: 'signed-out', stale: cookie !== undefined };
|
|
325
|
+
if (isFresh(claim, time))
|
|
326
|
+
return { claim, current: null };
|
|
327
|
+
const asked = await ask(() => review.sessionPerson(at, claim.id, claim.epoch));
|
|
328
|
+
if (asked === undefined)
|
|
329
|
+
return DOWN;
|
|
330
|
+
return asked ? { claim, current: asked } : { refused: 'signed-out', stale: true };
|
|
331
|
+
}
|
|
278
332
|
/**
|
|
279
333
|
* The checks every studio request passes, in the gate and again in the files
|
|
280
334
|
* function: a session signed to this host's client (asked of the store again
|
|
281
335
|
* once its stamp is stale), then the boundary.
|
|
282
336
|
*/
|
|
283
337
|
export async function admit(found, request, at) {
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
let current = null;
|
|
289
|
-
if (!isFresh(claim, at)) {
|
|
290
|
-
const asked = await ask(() => found.review.sessionPerson(found.place.scope, claim.id, claim.epoch));
|
|
291
|
-
if (asked === undefined)
|
|
292
|
-
return DOWN;
|
|
293
|
-
if (!asked)
|
|
294
|
-
return { refused: 'signed-out', stale: true };
|
|
295
|
-
current = asked;
|
|
296
|
-
}
|
|
338
|
+
const held = await session(found.review, found.place.gate, found.place.scope, request, at);
|
|
339
|
+
if ('refused' in held)
|
|
340
|
+
return held;
|
|
341
|
+
const { claim, current } = held;
|
|
297
342
|
const kind = current ? current.kind : claim.kind;
|
|
298
343
|
const project = await boundary(found, kind);
|
|
299
344
|
return project && 'refused' in project ? project : { ...found, kind, current, project };
|
|
@@ -338,21 +383,142 @@ async function proven({ review, place, route }, request, pathname) {
|
|
|
338
383
|
const answer = given ? await ask(() => review.proofAnswer(place.scope, given)) : null;
|
|
339
384
|
return answer ? plain(request, 200, answer) : null;
|
|
340
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* A handoff's claim on a client's host (`/_gate/handoff/<token>`), a GET the
|
|
388
|
+
* studio's host redirected here: the store gives up the handoff once, only
|
|
389
|
+
* when it was made for this host's client and is not past its minute, and
|
|
390
|
+
* the gate sets this host's own cookie for the Studio person it names. It
|
|
391
|
+
* goes on to the client's hub, or to the project the handoff named, a path
|
|
392
|
+
* built here from the stored slug, never from the request. Anything else is
|
|
393
|
+
* a used link's answer; nothing is used up by a HEAD or a POST.
|
|
394
|
+
*/
|
|
395
|
+
async function openHandoff(ctx, { review, place }, token) {
|
|
396
|
+
const { request, siteName } = ctx;
|
|
397
|
+
if (request.method !== 'GET')
|
|
398
|
+
return plain(request, 405, 'Method not allowed', { allow: 'GET' });
|
|
399
|
+
const claimed = await ask(() => review.claimHandoff(place.scope, token));
|
|
400
|
+
if (claimed === undefined)
|
|
401
|
+
return storeDown(request);
|
|
402
|
+
if (!claimed)
|
|
403
|
+
return page(request, 404, usedPage(siteName), USED);
|
|
404
|
+
const to = claimed.project ? `/${claimed.project}/` : '/';
|
|
405
|
+
return signedIn(await sessionFor(place.gate, claimed.person, ctx.at), to);
|
|
406
|
+
}
|
|
407
|
+
const NOT_OPENED = 'This client or project cannot be opened now. It may still be waiting for its address, or it was archived or is not shared yet.';
|
|
408
|
+
const PICK_A_CLIENT = 'Open a client from the list of clients.';
|
|
409
|
+
/** A handoff that did not start, for a browser the stopped page, for anything else its text. */
|
|
410
|
+
const stopped = (ctx, status, why, extra = {}) => page(ctx.request, status, stoppedPage(ctx.siteName, why), why, extra);
|
|
411
|
+
/** Form bodies the studio hub sends: two slugs, never more than this. */
|
|
412
|
+
const MAX_FORM_BYTES = 1024;
|
|
413
|
+
/** The client and project a handoff is asked for, from a same-origin form POST; null for anything else. */
|
|
414
|
+
async function handoffAsked(request) {
|
|
415
|
+
const type = request.headers.get('content-type') ?? '';
|
|
416
|
+
if (!type.startsWith('application/x-www-form-urlencoded'))
|
|
417
|
+
return null;
|
|
418
|
+
const text = await request.text();
|
|
419
|
+
if (text.length > MAX_FORM_BYTES)
|
|
420
|
+
return null;
|
|
421
|
+
const form = new URLSearchParams(text);
|
|
422
|
+
return { client: form.get('client') ?? '', project: form.get('project') || null };
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* A handoff asked for on the studio's own host (POST /_gate/handoff): the
|
|
426
|
+
* Studio person is read from the store, whatever the cookie's stamp says,
|
|
427
|
+
* the service writes a one-time handoff for that one client, and the answer
|
|
428
|
+
* sends the browser to the client's host to claim it. The address is the
|
|
429
|
+
* client's stored host and the token, never text the request sent; a client
|
|
430
|
+
* still being added, archived or unknown, or a project it has not built, is
|
|
431
|
+
* the plain 404.
|
|
432
|
+
*/
|
|
433
|
+
async function startHandoff(ctx, review, { claim }) {
|
|
434
|
+
const { request } = ctx;
|
|
435
|
+
if (request.method !== 'POST')
|
|
436
|
+
return plain(request, 405, 'Method not allowed', { allow: 'POST' });
|
|
437
|
+
if (!sameOrigin(request))
|
|
438
|
+
return plain(request, 403, 'Forbidden');
|
|
439
|
+
const asked = await handoffAsked(request);
|
|
440
|
+
if (!asked)
|
|
441
|
+
return stopped(ctx, 400, PICK_A_CLIENT);
|
|
442
|
+
const person = await ask(() => review.sessionPerson(STUDIO_SITE, claim.id, claim.epoch));
|
|
443
|
+
if (person === undefined)
|
|
444
|
+
return stopped(ctx, 503, STORE_DOWN, { retryAfter: 30 });
|
|
445
|
+
if (!person)
|
|
446
|
+
return page(request, 401, signInPage(ctx.siteName), SIGNED_OUT, { cookie: clearedCookie(PERSON_COOKIE) });
|
|
447
|
+
let made;
|
|
448
|
+
try {
|
|
449
|
+
made = await review.startHandoff(person, asked);
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
if (error instanceof ReviewError)
|
|
453
|
+
return stopped(ctx, 404, NOT_OPENED);
|
|
454
|
+
console.error('[gate]', error);
|
|
455
|
+
return stopped(ctx, 503, STORE_DOWN, { retryAfter: 30 });
|
|
456
|
+
}
|
|
457
|
+
const headers = gateHeaders('text/plain; charset=utf-8', {});
|
|
458
|
+
headers.set('location', `https://${made.host}${handoffPath(made.token)}`);
|
|
459
|
+
return new Response(null, { status: 303, headers });
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* The host proof `studio create` and `studio deploy` ask the studio's own
|
|
463
|
+
* host for: its answer, on a GET whose ask the store holds. Any other ask,
|
|
464
|
+
* method or store failure is the plain 404 every unknown path there gets.
|
|
465
|
+
*/
|
|
466
|
+
async function studioProof(ctx, review, given) {
|
|
467
|
+
const { request } = ctx;
|
|
468
|
+
const answer = request.method === 'GET' ? await ask(() => review.studioProofAnswer(given)) : null;
|
|
469
|
+
return answer ? plain(request, 200, answer) : notFound(request);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* The studio's own host (`studio.<apex>`): Studio signs in here with a
|
|
473
|
+
* Studio person's link, and nobody else gets in. Its session is signed to
|
|
474
|
+
* `studio`, so a client host's cookie never holds here, and a Client's
|
|
475
|
+
* cookie answers the sign-in page a client host shows, word for word; a
|
|
476
|
+
* Client's link reads as an unknown one (the used page). Its host proof
|
|
477
|
+
* is answered before any session. Signed in, `/` is the studio hub and `/api/review` its data (the
|
|
478
|
+
* review function checks the session again), and a POST to /_gate/handoff
|
|
479
|
+
* opens a client. Everything else is the plain 404, every path a client's
|
|
480
|
+
* host answers included.
|
|
481
|
+
*/
|
|
482
|
+
async function studioHost(ctx, { review, keys }, url) {
|
|
483
|
+
const { request } = ctx;
|
|
484
|
+
const where = studioRouteOf(url.pathname);
|
|
485
|
+
const gate = studioGate(keys);
|
|
486
|
+
if (where.kind === 'none')
|
|
487
|
+
return notFound(request);
|
|
488
|
+
if (where.kind === 'link')
|
|
489
|
+
return link(ctx, { review, gate }, STUDIO_SITE, where.token);
|
|
490
|
+
if (where.kind === 'proof')
|
|
491
|
+
return studioProof(ctx, review, where.ask);
|
|
492
|
+
if (where.kind === 'asset' && isRead(request))
|
|
493
|
+
return next();
|
|
494
|
+
const held = await session(review, gate, STUDIO_SITE, request, ctx.at);
|
|
495
|
+
if ('refused' in held)
|
|
496
|
+
return refuse(ctx, held);
|
|
497
|
+
if (where.kind === 'handoff')
|
|
498
|
+
return startHandoff(ctx, review, held);
|
|
499
|
+
const headers = passHeaders(held.current ? await sessionFor(gate, held.current, ctx.at) : undefined);
|
|
500
|
+
return where.kind === 'page' ? rewrite(new URL(STUDIO_PAGE, url), { headers }) : next({ headers });
|
|
501
|
+
}
|
|
341
502
|
/** The middleware a studio site's proxy.ts default-exports. Its sign-in page names no client (S10). */
|
|
342
503
|
export function createStudioProxy({ siteName = DEFAULT_SITE_NAME, now = () => new Date(), } = {}) {
|
|
343
504
|
const hosts = hostCache(now);
|
|
344
505
|
return async function proxy(request) {
|
|
345
506
|
const ctx = { siteName, request, at: now() };
|
|
346
507
|
const url = new URL(request.url);
|
|
347
|
-
const
|
|
348
|
-
if ('refused' in
|
|
349
|
-
return refuse(ctx,
|
|
508
|
+
const looked = await lookUp(request, hosts, ctx.at);
|
|
509
|
+
if ('refused' in looked)
|
|
510
|
+
return refuse(ctx, looked);
|
|
511
|
+
if (looked.site === STUDIO_SITE)
|
|
512
|
+
return studioHost(ctx, looked, url);
|
|
513
|
+
const found = placeOf(looked, looked.site, request, url.pathname);
|
|
350
514
|
const proof = await proven(found, request, url.pathname);
|
|
351
515
|
if (proof)
|
|
352
516
|
return proof;
|
|
353
517
|
const { route, place } = found;
|
|
354
518
|
if (route.kind === 'link')
|
|
355
519
|
return link(ctx, { review: found.review, gate: place.gate }, place.scope, route.token);
|
|
520
|
+
if (route.kind === 'handoff')
|
|
521
|
+
return openHandoff(ctx, found, route.token);
|
|
356
522
|
if (route.kind === 'asset' && isRead(request))
|
|
357
523
|
return next();
|
|
358
524
|
const admitted = await admit(found, request, ctx.at);
|
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -31,8 +31,12 @@ export declare function buildHub(options: HubOptions & {
|
|
|
31
31
|
/**
|
|
32
32
|
* A studio site's build (its `build.mjs`): the client hub from
|
|
33
33
|
* `shell/studio/`, the gate's font at the host root where the gate pages ask
|
|
34
|
-
* for it, and the favicon
|
|
35
|
-
*
|
|
34
|
+
* for it, and the favicon; then, beside them, the studio hub
|
|
35
|
+
* (`shell/studio/studio.html`), its page at STUDIO_PAGE and its bundle
|
|
36
|
+
* below STUDIO_DIR, which only the studio's own host serves. `root` is the
|
|
37
|
+
* studio folder; it keeps no kit, so `@kit/*` is the package's.
|
|
36
38
|
*/
|
|
37
39
|
export declare function studioConfig(root: string): InlineConfig;
|
|
40
|
+
/** The studio hub's build, after studioConfig's into the same `dist/`: its own page and bundle, nothing shared with the client hub's. */
|
|
41
|
+
export declare function studioHubConfig(root: string): InlineConfig;
|
|
38
42
|
export declare const buildStudio: (root: string) => Promise<void>;
|
package/dist/vite/plugin.js
CHANGED
|
@@ -10,7 +10,7 @@ import { createRequire } from 'node:module';
|
|
|
10
10
|
import { dirname, join } from 'node:path';
|
|
11
11
|
import react from '@vitejs/plugin-react';
|
|
12
12
|
import { build, searchForWorkspaceRoot } from 'vite';
|
|
13
|
-
import { isProjectSlug } from '../core/prototype.js';
|
|
13
|
+
import { isProjectSlug, STUDIO_DIR, STUDIO_PAGE } from '../core/prototype.js';
|
|
14
14
|
import { devReview } from '../server/dev.js';
|
|
15
15
|
import { devPort, readEnv } from '../server/env.js';
|
|
16
16
|
import { PACKAGE, PACKAGE_KIT, SHELL } from '../server/paths.js';
|
|
@@ -113,8 +113,10 @@ export async function buildHub(options) {
|
|
|
113
113
|
/**
|
|
114
114
|
* A studio site's build (its `build.mjs`): the client hub from
|
|
115
115
|
* `shell/studio/`, the gate's font at the host root where the gate pages ask
|
|
116
|
-
* for it, and the favicon
|
|
117
|
-
*
|
|
116
|
+
* for it, and the favicon; then, beside them, the studio hub
|
|
117
|
+
* (`shell/studio/studio.html`), its page at STUDIO_PAGE and its bundle
|
|
118
|
+
* below STUDIO_DIR, which only the studio's own host serves. `root` is the
|
|
119
|
+
* studio folder; it keeps no kit, so `@kit/*` is the package's.
|
|
118
120
|
*/
|
|
119
121
|
export function studioConfig(root) {
|
|
120
122
|
return {
|
|
@@ -129,6 +131,22 @@ export function studioConfig(root) {
|
|
|
129
131
|
build: { outDir: join(root, 'dist'), emptyOutDir: true },
|
|
130
132
|
};
|
|
131
133
|
}
|
|
134
|
+
/** The studio hub's build, after studioConfig's into the same `dist/`: its own page and bundle, nothing shared with the client hub's. */
|
|
135
|
+
export function studioHubConfig(root) {
|
|
136
|
+
const config = studioConfig(root);
|
|
137
|
+
return {
|
|
138
|
+
...config,
|
|
139
|
+
publicDir: false,
|
|
140
|
+
plugins: [react(), kitResolver(join(root, 'kit'), PACKAGE_KIT)],
|
|
141
|
+
build: {
|
|
142
|
+
outDir: join(root, 'dist'),
|
|
143
|
+
emptyOutDir: false,
|
|
144
|
+
assetsDir: STUDIO_DIR,
|
|
145
|
+
rollupOptions: { input: join(SHELL, 'studio', STUDIO_PAGE.slice(1)) },
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
132
149
|
export const buildStudio = async (root) => {
|
|
133
150
|
await build(studioConfig(root));
|
|
151
|
+
await build(studioHubConfig(root));
|
|
134
152
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milesroxas/design-hub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the sign-in 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": {
|
package/shell/Index.tsx
CHANGED
|
@@ -245,6 +245,8 @@ function LoadFailed({ loaded }: { loaded: Extract<Loaded, { status: 'error' }> }
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
function IndexHead({ children }: { children?: ReactNode }) {
|
|
248
|
+
// Tested in place, so a base `/` build drops the branch and keeps its bytes.
|
|
249
|
+
if (import.meta.env.BASE_URL !== '/') return <BasedHead>{children}</BasedHead>;
|
|
248
250
|
return (
|
|
249
251
|
<header className="index-head">
|
|
250
252
|
<div className="index-head-row">
|
|
@@ -258,6 +260,33 @@ function IndexHead({ children }: { children?: ReactNode }) {
|
|
|
258
260
|
);
|
|
259
261
|
}
|
|
260
262
|
|
|
263
|
+
/**
|
|
264
|
+
* The head of a project's hub under its base (`/<project>/`): the way back
|
|
265
|
+
* to the client's hub at the host root, then the head as at `/`. Styled
|
|
266
|
+
* inline, from kit/ui's button, so the hub's stylesheet stays as it was.
|
|
267
|
+
*/
|
|
268
|
+
function BasedHead({ children }: { children?: ReactNode }) {
|
|
269
|
+
return (
|
|
270
|
+
<header className="index-head">
|
|
271
|
+
<a
|
|
272
|
+
className="btn btn-tertiary btn-sm"
|
|
273
|
+
href="/"
|
|
274
|
+
style={{ alignSelf: 'flex-start', height: 44, marginInlineStart: -10 }}
|
|
275
|
+
>
|
|
276
|
+
<Icon name="arrow-left" size={16} />
|
|
277
|
+
<span className="btn-label">All projects</span>
|
|
278
|
+
</a>
|
|
279
|
+
<div className="index-head-row">
|
|
280
|
+
<h1>Prototypes</h1>
|
|
281
|
+
{children}
|
|
282
|
+
</div>
|
|
283
|
+
<p className="index-voice">
|
|
284
|
+
High-fidelity sketches in code, made as we sprint on features and improve the product.
|
|
285
|
+
</p>
|
|
286
|
+
</header>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
261
290
|
/** Studio's audience controls, outside Client view: the client-facing slugs and the switch. */
|
|
262
291
|
type AudienceControls = {
|
|
263
292
|
clientFacing: string[];
|