@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/dist/vercel/proxy.js
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
// Vercel Routing Middleware (
|
|
2
|
-
// proxy.entrypoint): the gate in front of every path of
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Vercel Routing Middleware (a studio site's proxy.ts, named in vercel.json
|
|
2
|
+
// as proxy.entrypoint): the gate in front of every path of every client's
|
|
3
|
+
// host, the review API included. There is one way in, a one-time link that
|
|
4
|
+
// Studio makes for one named person, on that person's client's host:
|
|
5
5
|
//
|
|
6
6
|
// GET /invite/<token> shows who the link is for, and uses nothing up, so
|
|
7
7
|
// a mail or chat preview that opens it costs nothing
|
|
8
8
|
// POST /invite/<token> uses the link up, sets the person's signed cookie
|
|
9
|
-
// (server/session.ts) and goes to the hub
|
|
9
|
+
// (server/session.ts) and goes to the client's hub
|
|
10
10
|
//
|
|
11
|
-
// A used, expired or unknown link is 404. Every other path needs the cookie
|
|
12
|
-
// It carries when the store last said yes;
|
|
13
|
-
// the gate asks the store again on the next
|
|
14
|
-
// a sign out everywhere or a changed access
|
|
15
|
-
// minutes. A store that does not answer is
|
|
16
|
-
// asking for a prototype that is not
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// closed (503).
|
|
21
|
-
import { next } from '@vercel/functions';
|
|
11
|
+
// A used, expired or unknown link is 404. Every other path needs the cookie,
|
|
12
|
+
// signed to the host's client. It carries when the store last said yes;
|
|
13
|
+
// after CHECK_SECONDS (5 minutes) the gate asks the store again on the next
|
|
14
|
+
// request of any kind, so a revoke, a sign out everywhere or a changed access
|
|
15
|
+
// end reaches every request within minutes. A store that does not answer is
|
|
16
|
+
// 503, never a sign out. A Client asking for a prototype that is not
|
|
17
|
+
// client-facing, its page or any file built from it under
|
|
18
|
+
// /<project>/_p/<slug>/, gets 404. Without a session a page gets the sign-in
|
|
19
|
+
// page (401), which says what to do and has no form, and anything else a
|
|
20
|
+
// plain-text 401. Without GATE_SECRET or the store the gate fails closed (503).
|
|
21
|
+
import { next, rewrite } from '@vercel/functions';
|
|
22
22
|
import { base64, sha256 } from '../core/bytes.js';
|
|
23
23
|
import { escapeHtml } from '../core/html.js';
|
|
24
|
-
import { isPrototypeSlug,
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
const
|
|
24
|
+
import { GATE_FONT, isPrototypeSlug, PROOF_PATH, routeOf } from '../core/prototype.js';
|
|
25
|
+
import { studioReview } from '../server/api.js';
|
|
26
|
+
import { hostCache, hostOf } from '../server/hosts.js';
|
|
27
|
+
import { clearedCookie, isFresh, issuePersonToken, PERSON_COOKIE, readCookie, readPersonToken, sameOrigin, sessionCookie, sessionSeconds, } from '../server/session.js';
|
|
28
|
+
export const DEFAULT_SITE_NAME = 'Prototypes';
|
|
29
29
|
// What the gate pages load before sign-in: the hub's face (the Vite plugin
|
|
30
|
-
// emits it at this fixed path) and the favicon. Nothing else.
|
|
31
|
-
export
|
|
32
|
-
const GATE_ASSETS = new Set([GATE_FONT, '/favicon.svg']);
|
|
30
|
+
// emits it at this fixed path, at the host root) and the favicon. Nothing else.
|
|
31
|
+
export { GATE_FONT };
|
|
33
32
|
// The gate pages. The CSS is a constant so its CSP hash is computed once and
|
|
34
33
|
// the pages carry no 'unsafe-inline', and they run no script at all. The gate
|
|
35
34
|
// is hub chrome, so it wears the hub's neutral system look (shell/system.css)
|
|
@@ -116,7 +115,7 @@ function wantsHtml(request) {
|
|
|
116
115
|
return dest === 'document' || dest === 'iframe';
|
|
117
116
|
return (request.headers.get('accept') ?? '').includes('text/html');
|
|
118
117
|
}
|
|
119
|
-
const isRead = (request) => request.method === 'GET' || request.method === 'HEAD';
|
|
118
|
+
export const isRead = (request) => request.method === 'GET' || request.method === 'HEAD';
|
|
120
119
|
/**
|
|
121
120
|
* Every answer the gate makes itself carries these: never cached, never
|
|
122
121
|
* indexed, no referrer. The link page alone sends a same-origin referrer, so
|
|
@@ -139,7 +138,7 @@ function gateHeaders(type, { cookie, allow, referrer = 'no-referrer', retryAfter
|
|
|
139
138
|
headers.set('retry-after', String(retryAfter));
|
|
140
139
|
return headers;
|
|
141
140
|
}
|
|
142
|
-
const plain = (request, status, text, extra = {}) => new Response(request.method === 'HEAD' ? null : text, {
|
|
141
|
+
export const plain = (request, status, text, extra = {}) => new Response(request.method === 'HEAD' ? null : text, {
|
|
143
142
|
status,
|
|
144
143
|
headers: gateHeaders('text/plain; charset=utf-8', extra),
|
|
145
144
|
});
|
|
@@ -153,12 +152,11 @@ async function page(request, status, html, text, extra = {}) {
|
|
|
153
152
|
}
|
|
154
153
|
const unavailable = (request, error) => plain(request, 503, error);
|
|
155
154
|
/** One answer for a prototype a Client may not have, whether it is internal or not there at all. */
|
|
156
|
-
const notFound = (request) => plain(request, 404, NOT_FOUND);
|
|
155
|
+
export const notFound = (request) => plain(request, 404, NOT_FOUND);
|
|
157
156
|
const NOT_FOUND = 'Not found.';
|
|
158
157
|
/** The store did not answer: a 503 that passes, so it says when to try again. */
|
|
159
|
-
const storeDown = (request) => plain(request, 503, STORE_DOWN, { retryAfter: 30 });
|
|
158
|
+
export const storeDown = (request) => plain(request, 503, STORE_DOWN, { retryAfter: 30 });
|
|
160
159
|
const STORE_DOWN = 'The review store did not answer. Try again in a minute.';
|
|
161
|
-
const NO_STORE_YET = 'Review is not set up on this site: pnpm bootstrap --vercel <project> --review.';
|
|
162
160
|
/**
|
|
163
161
|
* A store call that can fail without signing anyone out: `undefined` when the
|
|
164
162
|
* store did not answer, so the caller answers 503 and leaves the cookie alone.
|
|
@@ -172,12 +170,9 @@ async function ask(run) {
|
|
|
172
170
|
return undefined;
|
|
173
171
|
}
|
|
174
172
|
}
|
|
175
|
-
async function showLink(ctx, token) {
|
|
173
|
+
async function showLink(ctx, review, scope, token) {
|
|
176
174
|
const { siteName, request } = ctx;
|
|
177
|
-
const
|
|
178
|
-
if ('error' in setup)
|
|
179
|
-
return unavailable(request, setup.error);
|
|
180
|
-
const person = await ask(() => setup.review.peekLink(token));
|
|
175
|
+
const person = await ask(() => review.peekLink(scope, token));
|
|
181
176
|
if (person === undefined)
|
|
182
177
|
return storeDown(request);
|
|
183
178
|
return person
|
|
@@ -190,30 +185,27 @@ async function sessionFor(gate, person, at) {
|
|
|
190
185
|
const token = await issuePersonToken(gate, claim, person.accessEndsAt, at);
|
|
191
186
|
return sessionCookie(PERSON_COOKIE, token, sessionSeconds(person.accessEndsAt, at));
|
|
192
187
|
}
|
|
193
|
-
async function signInWithLink(ctx, token) {
|
|
188
|
+
async function signInWithLink(ctx, { review, gate }, scope, token) {
|
|
194
189
|
const { siteName, request, at } = ctx;
|
|
195
|
-
|
|
196
|
-
return plain(request, 403, 'Forbidden');
|
|
197
|
-
const setup = deployedReview(process.env, null, () => ctx.at);
|
|
198
|
-
if ('error' in setup)
|
|
199
|
-
return unavailable(request, setup.error);
|
|
200
|
-
const person = await ask(() => setup.review.useLink(token));
|
|
190
|
+
const person = await ask(() => review.useLink(scope, token));
|
|
201
191
|
if (person === undefined)
|
|
202
192
|
return storeDown(request);
|
|
203
193
|
if (!person)
|
|
204
194
|
return page(request, 404, usedPage(siteName), USED);
|
|
205
|
-
const headers = gateHeaders('text/plain; charset=utf-8', {
|
|
206
|
-
cookie: await sessionFor(setup.gate, person, at),
|
|
207
|
-
});
|
|
195
|
+
const headers = gateHeaders('text/plain; charset=utf-8', { cookie: await sessionFor(gate, person, at) });
|
|
208
196
|
headers.set('location', '/');
|
|
209
197
|
return new Response(null, { status: 303, headers });
|
|
210
198
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
return
|
|
216
|
-
|
|
199
|
+
/** A one-time link in `scope`: shown on a read, used on a same-origin POST. */
|
|
200
|
+
async function link(ctx, setup, scope, token) {
|
|
201
|
+
const { request } = ctx;
|
|
202
|
+
if (request.method === 'POST' && !sameOrigin(request))
|
|
203
|
+
return plain(request, 403, 'Forbidden');
|
|
204
|
+
if (request.method !== 'POST' && !isRead(request))
|
|
205
|
+
return plain(request, 405, 'Method not allowed', { allow: 'GET, HEAD, POST' });
|
|
206
|
+
return request.method === 'POST'
|
|
207
|
+
? signInWithLink(ctx, setup, scope, token)
|
|
208
|
+
: showLink(ctx, setup.review, scope, token);
|
|
217
209
|
}
|
|
218
210
|
/**
|
|
219
211
|
* No session. A page gets the sign-in page, and anything else (an asset, a
|
|
@@ -226,75 +218,147 @@ function signedOut({ siteName, request }, staleCookie) {
|
|
|
226
218
|
return plain(request, 401, SIGNED_OUT, extra);
|
|
227
219
|
return page(request, 401, signInPage(siteName), SIGNED_OUT, extra);
|
|
228
220
|
}
|
|
229
|
-
const
|
|
221
|
+
const passHeaders = (cookie) => ({
|
|
222
|
+
'cache-control': 'private, no-store',
|
|
223
|
+
...(cookie ? { 'set-cookie': cookie } : {}),
|
|
224
|
+
});
|
|
230
225
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* /_p/all.js alike, so the answer says nothing about what is there. A store
|
|
236
|
-
* that does not answer is 503. Hub paths pass with no store read.
|
|
226
|
+
* Whether a prototype is open to a Client in `scope`: client-facing, asked of
|
|
227
|
+
* the store on every request, no cache. A name that is no prototype slug
|
|
228
|
+
* (`all.js`, or '' for a path that could mean more than one file) is never
|
|
229
|
+
* open, without asking. `undefined` when the store did not answer.
|
|
237
230
|
*/
|
|
238
|
-
async function
|
|
231
|
+
async function prototypeOpen(review, scope, slug) {
|
|
239
232
|
if (!isPrototypeSlug(slug))
|
|
240
|
-
return
|
|
241
|
-
const audience = await ask(() => review.audienceOf(slug));
|
|
242
|
-
|
|
243
|
-
return storeDown(ctx.request);
|
|
244
|
-
return audience === 'client' ? null : notFound(ctx.request);
|
|
233
|
+
return false;
|
|
234
|
+
const audience = await ask(() => review.audienceOf(scope, slug));
|
|
235
|
+
return audience === undefined ? undefined : audience === 'client';
|
|
245
236
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
237
|
+
const NOT_THERE = { refused: 'not-found' };
|
|
238
|
+
const DOWN = { refused: 'store-down' };
|
|
239
|
+
/** The client `pathname` is asked of on the request's host, or why there is none: an unknown host is the plain 404. */
|
|
240
|
+
export async function findPlace(request, pathname, hosts, at) {
|
|
241
|
+
const setup = studioReview(process.env, null, () => at);
|
|
242
|
+
if ('error' in setup)
|
|
243
|
+
return { refused: 'unavailable', error: setup.error };
|
|
244
|
+
const route = routeOf(hostOf(request), pathname);
|
|
245
|
+
const client = route.host ? await ask(() => hosts(route.host, (h) => setup.review.clientOfHost(h))) : null;
|
|
246
|
+
if (client === undefined)
|
|
247
|
+
return DOWN;
|
|
248
|
+
if (!client)
|
|
249
|
+
return NOT_THERE;
|
|
250
|
+
const gate = { ...setup.keys, client: client.slug, since: client.createdAt };
|
|
251
|
+
const place = { client, gate, scope: { client: client.slug } };
|
|
252
|
+
return { review: setup.review, place, route };
|
|
252
253
|
}
|
|
253
254
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* which carries no kind, is always stale, so its first request re-issues it.
|
|
260
|
-
* Then, for anyone but Studio, the prototype boundary on a prototype's path.
|
|
255
|
+
* The project a route names, when it is the client's, and for a Client, only
|
|
256
|
+
* a client-facing prototype's files. Every other answer is the plain 404, so
|
|
257
|
+
* another client's project, a project with no build (its files and its
|
|
258
|
+
* review API alike) and an internal prototype read the same as a path that
|
|
259
|
+
* is not there.
|
|
261
260
|
*/
|
|
262
|
-
async function
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
261
|
+
async function boundary({ review, place, route }, kind) {
|
|
262
|
+
if (route.kind === 'none' || route.kind === 'link')
|
|
263
|
+
return NOT_THERE;
|
|
264
|
+
const named = route.kind === 'file' || route.kind === 'api' ? route.project : null;
|
|
265
|
+
if (named === null)
|
|
266
|
+
return null;
|
|
267
|
+
const scope = { client: place.client.slug, project: named };
|
|
268
|
+
const project = await ask(() => review.projectOf(scope));
|
|
269
|
+
if (project === undefined)
|
|
270
|
+
return DOWN;
|
|
271
|
+
if (!project || project.build === null)
|
|
272
|
+
return NOT_THERE;
|
|
273
|
+
if (route.kind !== 'file' || route.prototype === null || kind === 'studio')
|
|
274
|
+
return project;
|
|
275
|
+
const open = await prototypeOpen(review, scope, route.prototype);
|
|
276
|
+
return open === undefined ? DOWN : open ? project : NOT_THERE;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* The checks every studio request passes, in the gate and again in the files
|
|
280
|
+
* function: a session signed to this host's client (asked of the store again
|
|
281
|
+
* once its stamp is stale), then the boundary.
|
|
282
|
+
*/
|
|
283
|
+
export async function admit(found, request, at) {
|
|
284
|
+
const cookie = readCookie(request, PERSON_COOKIE);
|
|
285
|
+
const claim = await readPersonToken(found.place.gate, cookie, at);
|
|
286
|
+
if (!claim)
|
|
287
|
+
return { refused: 'signed-out', stale: cookie !== undefined };
|
|
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
|
+
}
|
|
273
297
|
const kind = current ? current.kind : claim.kind;
|
|
274
|
-
const
|
|
275
|
-
return refused
|
|
298
|
+
const project = await boundary(found, kind);
|
|
299
|
+
return project && 'refused' in project ? project : { ...found, kind, current, project };
|
|
300
|
+
}
|
|
301
|
+
/** The answer for a refusal: the same from the gate and from the files function. */
|
|
302
|
+
export function refuse(ctx, refusal) {
|
|
303
|
+
switch (refusal.refused) {
|
|
304
|
+
case 'not-found':
|
|
305
|
+
return notFound(ctx.request);
|
|
306
|
+
case 'store-down':
|
|
307
|
+
return storeDown(ctx.request);
|
|
308
|
+
case 'unavailable':
|
|
309
|
+
return unavailable(ctx.request, refusal.error);
|
|
310
|
+
case 'signed-out':
|
|
311
|
+
return signedOut(ctx, refusal.stale);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Where an admitted request goes on to: a project's file to the files
|
|
316
|
+
* function and its review API to the review function, each with the project
|
|
317
|
+
* the path named, and anything else on to the site's own files.
|
|
318
|
+
*/
|
|
319
|
+
function onward(url, route, cookie) {
|
|
320
|
+
const headers = passHeaders(cookie);
|
|
321
|
+
if (route.kind === 'file')
|
|
322
|
+
return rewrite(new URL(`/api/files?path=${encodeURIComponent(url.pathname)}`, url), { headers });
|
|
323
|
+
if (route.kind !== 'api' || route.project === null)
|
|
324
|
+
return next({ headers });
|
|
325
|
+
const to = new URL(`/api/review${url.search}`, url);
|
|
326
|
+
to.searchParams.set('project', route.project);
|
|
327
|
+
return rewrite(to, { headers });
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* The host proof `client add` asks a new client's host for (PROOF_PATH): its
|
|
331
|
+
* answer, on a GET whose ask the store holds for this host's client. Any
|
|
332
|
+
* other ask, method or store failure goes on as the hub path it is, so the
|
|
333
|
+
* path tells a caller without the ask nothing, and a host no client has
|
|
334
|
+
* never gets here (findPlace's plain 404).
|
|
335
|
+
*/
|
|
336
|
+
async function proven({ review, place, route }, request, pathname) {
|
|
337
|
+
const given = route.kind === 'hub' && request.method === 'GET' ? pathname.match(PROOF_PATH)?.[1] : undefined;
|
|
338
|
+
const answer = given ? await ask(() => review.proofAnswer(place.scope, given)) : null;
|
|
339
|
+
return answer ? plain(request, 200, answer) : null;
|
|
276
340
|
}
|
|
277
|
-
/** The middleware a
|
|
278
|
-
export function
|
|
341
|
+
/** The middleware a studio site's proxy.ts default-exports. Its sign-in page names no client (S10). */
|
|
342
|
+
export function createStudioProxy({ siteName = DEFAULT_SITE_NAME, now = () => new Date(), } = {}) {
|
|
343
|
+
const hosts = hostCache(now);
|
|
279
344
|
return async function proxy(request) {
|
|
280
|
-
const gate = readGate(process.env);
|
|
281
|
-
if (!gate)
|
|
282
|
-
return unavailable(request, 'The prototype gate is not configured.');
|
|
283
345
|
const ctx = { siteName, request, at: now() };
|
|
284
346
|
const url = new URL(request.url);
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
287
|
-
return
|
|
288
|
-
|
|
347
|
+
const found = await findPlace(request, url.pathname, hosts, ctx.at);
|
|
348
|
+
if ('refused' in found)
|
|
349
|
+
return refuse(ctx, found);
|
|
350
|
+
const proof = await proven(found, request, url.pathname);
|
|
351
|
+
if (proof)
|
|
352
|
+
return proof;
|
|
353
|
+
const { route, place } = found;
|
|
354
|
+
if (route.kind === 'link')
|
|
355
|
+
return link(ctx, { review: found.review, gate: place.gate }, place.scope, route.token);
|
|
356
|
+
if (route.kind === 'asset' && isRead(request))
|
|
289
357
|
return next();
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
// would turn a missing env var into everyone locked out, since links work once: answer 503 instead.
|
|
296
|
-
if (cookie !== undefined && gate.site === '')
|
|
297
|
-
return unavailable(request, NO_STORE_YET);
|
|
298
|
-
return signedOut(ctx, cookie !== undefined);
|
|
358
|
+
const admitted = await admit(found, request, ctx.at);
|
|
359
|
+
if ('refused' in admitted)
|
|
360
|
+
return refuse(ctx, admitted);
|
|
361
|
+
const cookie = admitted.current ? await sessionFor(place.gate, admitted.current, ctx.at) : undefined;
|
|
362
|
+
return onward(url, route, cookie);
|
|
299
363
|
};
|
|
300
364
|
}
|
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import { type InlineConfig, type PluginOption } from 'vite';
|
|
|
2
2
|
export type HubOptions = {
|
|
3
3
|
/** The project: the folder with prototypes/, kit/ and docs/. */
|
|
4
4
|
root: string;
|
|
5
|
+
/**
|
|
6
|
+
* The path the hub is served under: `/` (the default), or `/<project>/`
|
|
7
|
+
* when a studio serves the build below a client's host. Every path the hub
|
|
8
|
+
* asks for or links to starts with it.
|
|
9
|
+
*/
|
|
10
|
+
base?: string;
|
|
5
11
|
};
|
|
6
12
|
/** Every plugin the hub needs, for a project that writes its own vite.config.ts. */
|
|
7
13
|
export declare function designHub({ root }: HubOptions): PluginOption[];
|
|
@@ -12,4 +18,21 @@ export declare function designHub({ root }: HubOptions): PluginOption[];
|
|
|
12
18
|
* than drifting to the next one, because a fallback silently serves the wrong
|
|
13
19
|
* project. A build needs no port, so Vercel builds without a .env.
|
|
14
20
|
*/
|
|
15
|
-
export declare function hubConfig({ root }: HubOptions, command: 'serve' | 'build'): InlineConfig;
|
|
21
|
+
export declare function hubConfig({ root, base }: HubOptions, command: 'serve' | 'build'): InlineConfig;
|
|
22
|
+
/**
|
|
23
|
+
* A project's build below a base, as a studio serves it: what `design-hub
|
|
24
|
+
* share` uploads. `outDir` defaults to the project's `dist/`. Vite logs only
|
|
25
|
+
* warnings and errors, both to stderr, so a command's stdout stays its one
|
|
26
|
+
* JSON object.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildHub(options: HubOptions & {
|
|
29
|
+
outDir?: string;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* A studio site's build (its `build.mjs`): the client hub from
|
|
33
|
+
* `shell/studio/`, the gate's font at the host root where the gate pages ask
|
|
34
|
+
* for it, and the favicon. `root` is the studio folder; it keeps no kit, so
|
|
35
|
+
* `@kit/*` is the package's.
|
|
36
|
+
*/
|
|
37
|
+
export declare function studioConfig(root: string): InlineConfig;
|
|
38
|
+
export declare const buildStudio: (root: string) => Promise<void>;
|
package/dist/vite/plugin.js
CHANGED
|
@@ -9,7 +9,8 @@ import { readFileSync } from 'node:fs';
|
|
|
9
9
|
import { createRequire } from 'node:module';
|
|
10
10
|
import { dirname, join } from 'node:path';
|
|
11
11
|
import react from '@vitejs/plugin-react';
|
|
12
|
-
import { searchForWorkspaceRoot } from 'vite';
|
|
12
|
+
import { build, searchForWorkspaceRoot } from 'vite';
|
|
13
|
+
import { isProjectSlug } from '../core/prototype.js';
|
|
13
14
|
import { devReview } from '../server/dev.js';
|
|
14
15
|
import { devPort, readEnv } from '../server/env.js';
|
|
15
16
|
import { PACKAGE, PACKAGE_KIT, SHELL } from '../server/paths.js';
|
|
@@ -48,6 +49,12 @@ function gateFont() {
|
|
|
48
49
|
},
|
|
49
50
|
};
|
|
50
51
|
}
|
|
52
|
+
/** The base itself, or an error: `/`, or one project slug between slashes, nothing that leaves the host. */
|
|
53
|
+
function baseOf(base = '/') {
|
|
54
|
+
if (base === '/' || isProjectSlug(base.match(/^\/(.*)\/$/)?.[1]))
|
|
55
|
+
return base;
|
|
56
|
+
throw new Error(`base must be / or /<project>/ with a project slug, not ${JSON.stringify(base)}.`);
|
|
57
|
+
}
|
|
51
58
|
/** Every plugin the hub needs, for a project that writes its own vite.config.ts. */
|
|
52
59
|
export function designHub({ root }) {
|
|
53
60
|
return [
|
|
@@ -68,12 +75,13 @@ export function designHub({ root }) {
|
|
|
68
75
|
* than drifting to the next one, because a fallback silently serves the wrong
|
|
69
76
|
* project. A build needs no port, so Vercel builds without a .env.
|
|
70
77
|
*/
|
|
71
|
-
export function hubConfig({ root }, command) {
|
|
78
|
+
export function hubConfig({ root, base }, command) {
|
|
72
79
|
const port = devPort(readEnv(root));
|
|
73
80
|
if (command === 'serve' && port === undefined)
|
|
74
81
|
throw new Error('PORT is not set. `design-hub dev` claims one; a config of your own runs `design-hub bootstrap` first.');
|
|
75
82
|
return {
|
|
76
83
|
configFile: false,
|
|
84
|
+
base: baseOf(base),
|
|
77
85
|
root: SHELL,
|
|
78
86
|
publicDir: join(SHELL, 'public'),
|
|
79
87
|
envDir: root,
|
|
@@ -88,3 +96,39 @@ export function hubConfig({ root }, command) {
|
|
|
88
96
|
build: { outDir: join(root, 'dist'), emptyOutDir: true },
|
|
89
97
|
};
|
|
90
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* A project's build below a base, as a studio serves it: what `design-hub
|
|
101
|
+
* share` uploads. `outDir` defaults to the project's `dist/`. Vite logs only
|
|
102
|
+
* warnings and errors, both to stderr, so a command's stdout stays its one
|
|
103
|
+
* JSON object.
|
|
104
|
+
*/
|
|
105
|
+
export async function buildHub(options) {
|
|
106
|
+
const config = hubConfig(options, 'build');
|
|
107
|
+
await build({
|
|
108
|
+
...config,
|
|
109
|
+
logLevel: 'warn',
|
|
110
|
+
build: { ...config.build, outDir: options.outDir ?? config.build?.outDir },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A studio site's build (its `build.mjs`): the client hub from
|
|
115
|
+
* `shell/studio/`, the gate's font at the host root where the gate pages ask
|
|
116
|
+
* for it, and the favicon. `root` is the studio folder; it keeps no kit, so
|
|
117
|
+
* `@kit/*` is the package's.
|
|
118
|
+
*/
|
|
119
|
+
export function studioConfig(root) {
|
|
120
|
+
return {
|
|
121
|
+
configFile: false,
|
|
122
|
+
base: '/',
|
|
123
|
+
root: join(SHELL, 'studio'),
|
|
124
|
+
publicDir: join(SHELL, 'public'),
|
|
125
|
+
envDir: root,
|
|
126
|
+
cacheDir: join(root, 'node_modules', '.vite'),
|
|
127
|
+
plugins: [react(), kitResolver(join(root, 'kit'), PACKAGE_KIT), gateFont()],
|
|
128
|
+
resolve: { dedupe: ['react', 'react-dom'] },
|
|
129
|
+
build: { outDir: join(root, 'dist'), emptyOutDir: true },
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export const buildStudio = async (root) => {
|
|
133
|
+
await build(studioConfig(root));
|
|
134
|
+
};
|
package/kit/Artboard.tsx
CHANGED
|
@@ -8,8 +8,9 @@ import {
|
|
|
8
8
|
useState,
|
|
9
9
|
} from 'react';
|
|
10
10
|
import { FORMATS, type Format, type FormatName, sizeLabel, zoomFor } from '../core/formats.ts';
|
|
11
|
-
import { restoreDials, useDials } from './dials';
|
|
12
|
-
import {
|
|
11
|
+
import { client, restoreDials, useDials } from './dials';
|
|
12
|
+
import { pinAppearance, urlAppearance } from './prefs';
|
|
13
|
+
import { ViewScope } from './ViewTools';
|
|
13
14
|
import './artboard.css';
|
|
14
15
|
|
|
15
16
|
export { FORMAT_NAMES, FORMATS, type FormatName } from '../core/formats.ts';
|
|
@@ -54,6 +55,8 @@ function useRoom() {
|
|
|
54
55
|
return { ref, room };
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
const NO_VIEW: readonly never[] = [];
|
|
59
|
+
|
|
57
60
|
type BoardProps = { title: string; lede?: ReactNode; children: ReactNode };
|
|
58
61
|
|
|
59
62
|
/**
|
|
@@ -65,8 +68,9 @@ export function Board({ title, lede, children }: BoardProps) {
|
|
|
65
68
|
const view = useDials(
|
|
66
69
|
'Board',
|
|
67
70
|
{
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
// How a person looks at the boards, not the design: a Client's from the start. They are a board's only viewing tools.
|
|
72
|
+
zoom: client({ type: 'select', options: ZOOMS, default: 'fit' }),
|
|
73
|
+
guides: client(true),
|
|
70
74
|
},
|
|
71
75
|
{
|
|
72
76
|
hints: {
|
|
@@ -81,6 +85,13 @@ export function Board({ title, lede, children }: BoardProps) {
|
|
|
81
85
|
if (exporting) void settleForExport();
|
|
82
86
|
}, []);
|
|
83
87
|
|
|
88
|
+
// Collateral has one look: light, or the one ?theme= names, which is what export writes.
|
|
89
|
+
// A person's own dark theme never recolours a piece that ships light.
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
pinAppearance(urlAppearance() ?? 'light');
|
|
92
|
+
return () => pinAppearance(null);
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
84
95
|
if (exporting)
|
|
85
96
|
return (
|
|
86
97
|
<BoardView.Provider value={{ zoom: '100%', guides: false, room }}>
|
|
@@ -95,10 +106,12 @@ export function Board({ title, lede, children }: BoardProps) {
|
|
|
95
106
|
<h1 className="board-title">{title}</h1>
|
|
96
107
|
{lede ? <p className="board-lede">{lede}</p> : null}
|
|
97
108
|
</header>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
{/* No View panel on a board: a still file has no motion to slow and no theme to flip. */}
|
|
110
|
+
<ViewScope.Provider value={NO_VIEW}>
|
|
111
|
+
<div className="board-grid" ref={ref}>
|
|
112
|
+
{children}
|
|
113
|
+
</div>
|
|
114
|
+
</ViewScope.Provider>
|
|
102
115
|
</main>
|
|
103
116
|
</BoardView.Provider>
|
|
104
117
|
);
|
package/kit/Space.tsx
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import './space.css';
|
|
3
|
-
import { ViewTools } from './ViewTools';
|
|
3
|
+
import { type ViewTool, ViewTools } from './ViewTools';
|
|
4
4
|
|
|
5
5
|
type Props = {
|
|
6
6
|
title: string;
|
|
7
7
|
lede?: ReactNode;
|
|
8
8
|
width?: 'narrow' | 'wide' | 'full';
|
|
9
|
-
tools
|
|
9
|
+
/** The View tools: all of them, none (`false`), or only the ones that change something here. */
|
|
10
|
+
tools?: boolean | readonly ViewTool[];
|
|
10
11
|
children: ReactNode;
|
|
11
12
|
};
|
|
12
13
|
|
|
@@ -19,7 +20,7 @@ export function Space({ title, lede, width = 'wide', tools = true, children }: P
|
|
|
19
20
|
{lede ? <p className="space-lede">{lede}</p> : null}
|
|
20
21
|
</header>
|
|
21
22
|
{children}
|
|
22
|
-
{tools ? <ViewTools /> : null}
|
|
23
|
+
{tools ? <ViewTools tools={tools === true ? undefined : tools} /> : null}
|
|
23
24
|
</main>
|
|
24
25
|
);
|
|
25
26
|
}
|